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

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