Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef LLC_H |
| 2 | #define LLC_H |
| 3 | /* |
| 4 | * Copyright (c) 1997 by Procom Technology, Inc. |
| 5 | * 2001-2003 by Arnaldo Carvalho de Melo <acme@conectiva.com.br> |
| 6 | * |
| 7 | * This program can be redistributed or modified under the terms of the |
| 8 | * GNU General Public License as published by the Free Software Foundation. |
| 9 | * This program is distributed without any warranty or implied warranty |
| 10 | * of merchantability or fitness for a particular purpose. |
| 11 | * |
| 12 | * See the GNU General Public License for more details. |
| 13 | */ |
| 14 | |
| 15 | #include <linux/if.h> |
| 16 | #include <linux/if_ether.h> |
| 17 | #include <linux/list.h> |
| 18 | #include <linux/spinlock.h> |
Octavian Purdila | b76f5a8 | 2009-12-26 11:51:02 +0000 | [diff] [blame] | 19 | #include <linux/rculist_nulls.h> |
Octavian Purdila | 52d58ae | 2009-12-26 11:51:05 +0000 | [diff] [blame] | 20 | #include <linux/hash.h> |
| 21 | #include <linux/jhash.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 23 | #include <linux/atomic.h> |
Arnaldo Carvalho de Melo | 6e2144b | 2005-09-22 04:43:05 -0300 | [diff] [blame] | 24 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | struct net_device; |
| 26 | struct packet_type; |
| 27 | struct sk_buff; |
| 28 | |
| 29 | struct llc_addr { |
| 30 | unsigned char lsap; |
| 31 | unsigned char mac[IFHWADDRLEN]; |
| 32 | }; |
| 33 | |
| 34 | #define LLC_SAP_STATE_INACTIVE 1 |
| 35 | #define LLC_SAP_STATE_ACTIVE 2 |
| 36 | |
Octavian Purdila | 6d2e3ea | 2009-12-26 11:51:04 +0000 | [diff] [blame] | 37 | #define LLC_SK_DEV_HASH_BITS 6 |
| 38 | #define LLC_SK_DEV_HASH_ENTRIES (1<<LLC_SK_DEV_HASH_BITS) |
| 39 | |
Octavian Purdila | 52d58ae | 2009-12-26 11:51:05 +0000 | [diff] [blame] | 40 | #define LLC_SK_LADDR_HASH_BITS 6 |
| 41 | #define LLC_SK_LADDR_HASH_ENTRIES (1<<LLC_SK_LADDR_HASH_BITS) |
| 42 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | /** |
| 44 | * struct llc_sap - Defines the SAP component |
| 45 | * |
| 46 | * @station - station this sap belongs to |
| 47 | * @state - sap state |
| 48 | * @p_bit - only lowest-order bit used |
| 49 | * @f_bit - only lowest-order bit used |
| 50 | * @laddr - SAP value in this 'lsap' |
| 51 | * @node - entry in station sap_list |
| 52 | * @sk_list - LLC sockets this one manages |
| 53 | */ |
| 54 | struct llc_sap { |
| 55 | unsigned char state; |
| 56 | unsigned char p_bit; |
| 57 | unsigned char f_bit; |
Arnaldo Carvalho de Melo | 6e2144b | 2005-09-22 04:43:05 -0300 | [diff] [blame] | 58 | atomic_t refcnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | int (*rcv_func)(struct sk_buff *skb, |
| 60 | struct net_device *dev, |
David S. Miller | f2ccd8f | 2005-08-09 19:34:12 -0700 | [diff] [blame] | 61 | struct packet_type *pt, |
| 62 | struct net_device *orig_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | struct llc_addr laddr; |
| 64 | struct list_head node; |
Octavian Purdila | b76f5a8 | 2009-12-26 11:51:02 +0000 | [diff] [blame] | 65 | spinlock_t sk_lock; |
Octavian Purdila | 52d58ae | 2009-12-26 11:51:05 +0000 | [diff] [blame] | 66 | int sk_count; |
| 67 | struct hlist_nulls_head sk_laddr_hash[LLC_SK_LADDR_HASH_ENTRIES]; |
Octavian Purdila | 6d2e3ea | 2009-12-26 11:51:04 +0000 | [diff] [blame] | 68 | struct hlist_head sk_dev_hash[LLC_SK_DEV_HASH_ENTRIES]; |
Cong Wang | 7228cb8 | 2018-09-11 11:42:06 -0700 | [diff] [blame] | 69 | struct rcu_head rcu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | }; |
| 71 | |
Octavian Purdila | 6d2e3ea | 2009-12-26 11:51:04 +0000 | [diff] [blame] | 72 | static inline |
| 73 | struct hlist_head *llc_sk_dev_hash(struct llc_sap *sap, int ifindex) |
| 74 | { |
| 75 | return &sap->sk_dev_hash[ifindex % LLC_SK_DEV_HASH_ENTRIES]; |
| 76 | } |
| 77 | |
Octavian Purdila | 52d58ae | 2009-12-26 11:51:05 +0000 | [diff] [blame] | 78 | static inline |
| 79 | u32 llc_sk_laddr_hashfn(struct llc_sap *sap, const struct llc_addr *laddr) |
| 80 | { |
| 81 | return hash_32(jhash(laddr->mac, sizeof(laddr->mac), 0), |
| 82 | LLC_SK_LADDR_HASH_BITS); |
| 83 | } |
| 84 | |
| 85 | static inline |
| 86 | struct hlist_nulls_head *llc_sk_laddr_hash(struct llc_sap *sap, |
| 87 | const struct llc_addr *laddr) |
| 88 | { |
| 89 | return &sap->sk_laddr_hash[llc_sk_laddr_hashfn(sap, laddr)]; |
| 90 | } |
Octavian Purdila | 6d2e3ea | 2009-12-26 11:51:04 +0000 | [diff] [blame] | 91 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | #define LLC_DEST_INVALID 0 /* Invalid LLC PDU type */ |
| 93 | #define LLC_DEST_SAP 1 /* Type 1 goes here */ |
| 94 | #define LLC_DEST_CONN 2 /* Type 2 goes here */ |
| 95 | |
| 96 | extern struct list_head llc_sap_list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
Joe Perches | bf3c710 | 2013-09-21 10:22:45 -0700 | [diff] [blame] | 98 | int llc_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, |
| 99 | struct net_device *orig_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
Joe Perches | bf3c710 | 2013-09-21 10:22:45 -0700 | [diff] [blame] | 101 | int llc_mac_hdr_init(struct sk_buff *skb, const unsigned char *sa, |
| 102 | const unsigned char *da); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
Joe Perches | bf3c710 | 2013-09-21 10:22:45 -0700 | [diff] [blame] | 104 | void llc_add_pack(int type, |
| 105 | void (*handler)(struct llc_sap *sap, struct sk_buff *skb)); |
| 106 | void llc_remove_pack(int type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
Joe Perches | bf3c710 | 2013-09-21 10:22:45 -0700 | [diff] [blame] | 108 | void llc_set_station_handler(void (*handler)(struct sk_buff *skb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
Joe Perches | bf3c710 | 2013-09-21 10:22:45 -0700 | [diff] [blame] | 110 | struct llc_sap *llc_sap_open(unsigned char lsap, |
| 111 | int (*rcv)(struct sk_buff *skb, |
| 112 | struct net_device *dev, |
| 113 | struct packet_type *pt, |
| 114 | struct net_device *orig_dev)); |
Arnaldo Carvalho de Melo | 6e2144b | 2005-09-22 04:43:05 -0300 | [diff] [blame] | 115 | static inline void llc_sap_hold(struct llc_sap *sap) |
| 116 | { |
| 117 | atomic_inc(&sap->refcnt); |
| 118 | } |
| 119 | |
Cong Wang | 2ff9f08 | 2018-08-07 12:41:38 -0700 | [diff] [blame] | 120 | static inline bool llc_sap_hold_safe(struct llc_sap *sap) |
| 121 | { |
| 122 | return atomic_inc_not_zero(&sap->refcnt); |
| 123 | } |
| 124 | |
Joe Perches | bf3c710 | 2013-09-21 10:22:45 -0700 | [diff] [blame] | 125 | void llc_sap_close(struct llc_sap *sap); |
Arnaldo Carvalho de Melo | 2928c19 | 2005-09-22 05:14:33 -0300 | [diff] [blame] | 126 | |
Arnaldo Carvalho de Melo | 6e2144b | 2005-09-22 04:43:05 -0300 | [diff] [blame] | 127 | static inline void llc_sap_put(struct llc_sap *sap) |
| 128 | { |
Arnaldo Carvalho de Melo | 6e2144b | 2005-09-22 04:43:05 -0300 | [diff] [blame] | 129 | if (atomic_dec_and_test(&sap->refcnt)) |
| 130 | llc_sap_close(sap); |
| 131 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
Joe Perches | bf3c710 | 2013-09-21 10:22:45 -0700 | [diff] [blame] | 133 | struct llc_sap *llc_sap_find(unsigned char sap_value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | |
Joe Perches | bf3c710 | 2013-09-21 10:22:45 -0700 | [diff] [blame] | 135 | int llc_build_and_send_ui_pkt(struct llc_sap *sap, struct sk_buff *skb, |
| 136 | unsigned char *dmac, unsigned char dsap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
Joe Perches | bf3c710 | 2013-09-21 10:22:45 -0700 | [diff] [blame] | 138 | void llc_sap_handler(struct llc_sap *sap, struct sk_buff *skb); |
| 139 | void llc_conn_handler(struct llc_sap *sap, struct sk_buff *skb); |
Arnaldo Carvalho de Melo | 2928c19 | 2005-09-22 05:14:33 -0300 | [diff] [blame] | 140 | |
Joe Perches | bf3c710 | 2013-09-21 10:22:45 -0700 | [diff] [blame] | 141 | void llc_station_init(void); |
| 142 | void llc_station_exit(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | |
| 144 | #ifdef CONFIG_PROC_FS |
Joe Perches | bf3c710 | 2013-09-21 10:22:45 -0700 | [diff] [blame] | 145 | int llc_proc_init(void); |
| 146 | void llc_proc_exit(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | #else |
| 148 | #define llc_proc_init() (0) |
| 149 | #define llc_proc_exit() do { } while(0) |
| 150 | #endif /* CONFIG_PROC_FS */ |
Arnaldo Carvalho de Melo | 590232a | 2005-09-22 04:30:44 -0300 | [diff] [blame] | 151 | #ifdef CONFIG_SYSCTL |
Joe Perches | bf3c710 | 2013-09-21 10:22:45 -0700 | [diff] [blame] | 152 | int llc_sysctl_init(void); |
| 153 | void llc_sysctl_exit(void); |
Arnaldo Carvalho de Melo | 2928c19 | 2005-09-22 05:14:33 -0300 | [diff] [blame] | 154 | |
| 155 | extern int sysctl_llc2_ack_timeout; |
| 156 | extern int sysctl_llc2_busy_timeout; |
| 157 | extern int sysctl_llc2_p_timeout; |
| 158 | extern int sysctl_llc2_rej_timeout; |
Arnaldo Carvalho de Melo | 590232a | 2005-09-22 04:30:44 -0300 | [diff] [blame] | 159 | #else |
| 160 | #define llc_sysctl_init() (0) |
| 161 | #define llc_sysctl_exit() do { } while(0) |
| 162 | #endif /* CONFIG_SYSCTL */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | #endif /* LLC_H */ |