root/net/inet/psnap.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. find_snap_client
  2. snap_rcv
  3. snap_datalink_header
  4. snap_proto_init
  5. register_snap_client

   1 /*
   2  *      SNAP data link layer. Derived from 802.2
   3  *
   4  *              Alan Cox <Alan.Cox@linux.org>, from the 802.2 layer by Greg Page.
   5  *              Merged in additions from Greg Page's psnap.c.
   6  *
   7  *              This program is free software; you can redistribute it and/or
   8  *              modify it under the terms of the GNU General Public License
   9  *              as published by the Free Software Foundation; either version
  10  *              2 of the License, or (at your option) any later version.
  11  */
  12  
  13 #include <linux/netdevice.h>
  14 #include <linux/skbuff.h>
  15 #include "datalink.h"
  16 #include "p8022.h"
  17 #include "psnap.h"
  18 #include <linux/mm.h>
  19 #include <linux/in.h>
  20 
  21 static struct datalink_proto *snap_list = NULL;
  22 static struct datalink_proto *snap_dl = NULL;           /* 802.2 DL for SNAP */
  23 
  24 /*
  25  *      Find a snap client by matching the 5 bytes.
  26  */
  27  
  28 static struct datalink_proto *find_snap_client(unsigned char *desc)
     /* [previous][next][first][last][top][bottom][index][help] */
  29 {
  30         struct datalink_proto   *proto;
  31 
  32         for (proto = snap_list; proto != NULL && memcmp(proto->type, desc, 5) ; proto = proto->next);
  33         return proto;
  34 }
  35 
  36 /*
  37  *      A SNAP packet has arrived
  38  */
  39  
  40 int snap_rcv(struct sk_buff *skb, struct device *dev, struct packet_type *pt)
     /* [previous][next][first][last][top][bottom][index][help] */
  41 {
  42         static struct packet_type psnap_packet_type = 
  43         {
  44                 0,      
  45                 NULL,           /* All Devices */
  46                 snap_rcv,
  47                 NULL,
  48                 NULL,
  49         };
  50         
  51         struct datalink_proto   *proto;
  52 
  53         proto = find_snap_client(skb->h.raw);
  54         if (proto != NULL) 
  55         {
  56                 /*
  57                  *      Pass the frame on.
  58                  */
  59                  
  60                 skb->h.raw += 5;
  61                 skb->len -= 5;
  62                 if (psnap_packet_type.type == 0)
  63                         psnap_packet_type.type=htons(ETH_P_SNAP);
  64                 return proto->rcvfunc(skb, dev, &psnap_packet_type);
  65         }
  66         skb->sk = NULL;
  67         kfree_skb(skb, FREE_READ);
  68         return 0;
  69 }
  70 
  71 /*
  72  *      Put a SNAP header on a frame and pass to 802.2
  73  */
  74  
  75 static void snap_datalink_header(struct datalink_proto *dl, struct sk_buff *skb, unsigned char *dest_node)
     /* [previous][next][first][last][top][bottom][index][help] */
  76 {
  77         struct device   *dev = skb->dev;
  78         unsigned char   *rawp;
  79 
  80         rawp = skb->data + snap_dl->header_length+dev->hard_header_len;
  81         memcpy(rawp,dl->type,5);
  82         skb->h.raw = rawp+5;
  83         snap_dl->datalink_header(snap_dl, skb, dest_node);
  84 }
  85 
  86 /*
  87  *      Set up the SNAP layer
  88  */
  89  
  90 void snap_proto_init(struct net_proto *pro)
     /* [previous][next][first][last][top][bottom][index][help] */
  91 {
  92         snap_dl=register_8022_client(0xAA, snap_rcv);
  93         if(snap_dl==NULL)
  94                 printk("SNAP - unable to register with 802.2\n");
  95 }
  96         
  97 /*
  98  *      Register SNAP clients. We don't yet use this for IP or IPX.
  99  */
 100  
 101 struct datalink_proto *register_snap_client(unsigned char *desc, int (*rcvfunc)(struct sk_buff *, struct device *, struct packet_type *))
     /* [previous][next][first][last][top][bottom][index][help] */
 102 {
 103         struct datalink_proto   *proto;
 104 
 105         if (find_snap_client(desc) != NULL)
 106                 return NULL;
 107 
 108         proto = (struct datalink_proto *) kmalloc(sizeof(*proto), GFP_ATOMIC);
 109         if (proto != NULL) 
 110         {
 111                 memcpy(proto->type, desc,5);
 112                 proto->type_len = 5;
 113                 proto->rcvfunc = rcvfunc;
 114                 proto->header_length = 5+snap_dl->header_length;
 115                 proto->datalink_header = snap_datalink_header;
 116                 proto->string_name = "SNAP";
 117                 proto->next = snap_list;
 118                 snap_list = proto;
 119         }
 120 
 121         return proto;
 122 }
 123 

/* [previous][next][first][last][top][bottom][index][help] */