p8022.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * NET3: Support for 802.2 demultiplexing off Ethernet
  4. *
  5. * Demultiplex 802.2 encoded protocols. We match the entry by the
  6. * SSAP/DSAP pair and then deliver to the registered datalink that
  7. * matches. The control byte is ignored and handling of such items
  8. * is up to the routine passed the frame.
  9. *
  10. * Unlike the 802.3 datalink we have a list of 802.2 entries as
  11. * there are multiple protocols to demux. The list is currently
  12. * short (3 or 4 entries at most). The current demux assumes this.
  13. */
  14. #include <linux/module.h>
  15. #include <linux/netdevice.h>
  16. #include <linux/skbuff.h>
  17. #include <linux/slab.h>
  18. #include <net/datalink.h>
  19. #include <linux/mm.h>
  20. #include <linux/in.h>
  21. #include <linux/init.h>
  22. #include <net/llc.h>
  23. #include <net/p8022.h>
  24. static int p8022_request(struct datalink_proto *dl, struct sk_buff *skb,
  25. unsigned char *dest)
  26. {
  27. llc_build_and_send_ui_pkt(dl->sap, skb, dest, dl->sap->laddr.lsap);
  28. return 0;
  29. }
  30. struct datalink_proto *register_8022_client(unsigned char type,
  31. int (*func)(struct sk_buff *skb,
  32. struct net_device *dev,
  33. struct packet_type *pt,
  34. struct net_device *orig_dev))
  35. {
  36. struct datalink_proto *proto;
  37. proto = kmalloc(sizeof(*proto), GFP_ATOMIC);
  38. if (proto) {
  39. proto->type[0] = type;
  40. proto->header_length = 3;
  41. proto->request = p8022_request;
  42. proto->sap = llc_sap_open(type, func);
  43. if (!proto->sap) {
  44. kfree(proto);
  45. proto = NULL;
  46. }
  47. }
  48. return proto;
  49. }
  50. void unregister_8022_client(struct datalink_proto *proto)
  51. {
  52. llc_sap_put(proto->sap);
  53. kfree(proto);
  54. }
  55. EXPORT_SYMBOL(register_8022_client);
  56. EXPORT_SYMBOL(unregister_8022_client);
  57. MODULE_LICENSE("GPL");