Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
Paul Gortmaker | 211ed86 | 2012-05-10 17:14:35 -0400 | [diff] [blame] | 3 | * NET3: Support for 802.2 demultiplexing off Ethernet |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 17 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
| 25 | static int p8022_request(struct datalink_proto *dl, struct sk_buff *skb, |
Jakub Kicinski | 2ef6db7 | 2021-10-12 08:58:37 -0700 | [diff] [blame] | 26 | const unsigned char *dest) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | { |
| 28 | llc_build_and_send_ui_pkt(dl->sap, skb, dest, dl->sap->laddr.lsap); |
| 29 | return 0; |
| 30 | } |
| 31 | |
| 32 | struct datalink_proto *register_8022_client(unsigned char type, |
| 33 | int (*func)(struct sk_buff *skb, |
| 34 | struct net_device *dev, |
David S. Miller | f2ccd8fa | 2005-08-09 19:34:12 -0700 | [diff] [blame] | 35 | struct packet_type *pt, |
| 36 | struct net_device *orig_dev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | { |
| 38 | struct datalink_proto *proto; |
| 39 | |
| 40 | proto = kmalloc(sizeof(*proto), GFP_ATOMIC); |
| 41 | if (proto) { |
| 42 | proto->type[0] = type; |
| 43 | proto->header_length = 3; |
| 44 | proto->request = p8022_request; |
| 45 | proto->sap = llc_sap_open(type, func); |
| 46 | if (!proto->sap) { |
| 47 | kfree(proto); |
| 48 | proto = NULL; |
| 49 | } |
| 50 | } |
| 51 | return proto; |
| 52 | } |
| 53 | |
| 54 | void unregister_8022_client(struct datalink_proto *proto) |
| 55 | { |
Arnaldo Carvalho de Melo | 6e2144b | 2005-09-22 04:43:05 -0300 | [diff] [blame] | 56 | llc_sap_put(proto->sap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | kfree(proto); |
| 58 | } |
| 59 | |
| 60 | EXPORT_SYMBOL(register_8022_client); |
| 61 | EXPORT_SYMBOL(unregister_8022_client); |
| 62 | |
| 63 | MODULE_LICENSE("GPL"); |