]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
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> | |
b76f5a84 | 19 | #include <linux/rculist_nulls.h> |
52d58aef OP |
20 | #include <linux/hash.h> |
21 | #include <linux/jhash.h> | |
1da177e4 | 22 | |
60063497 | 23 | #include <linux/atomic.h> |
6e2144b7 | 24 | |
1da177e4 LT |
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 | ||
6d2e3ea2 OP |
37 | #define LLC_SK_DEV_HASH_BITS 6 |
38 | #define LLC_SK_DEV_HASH_ENTRIES (1<<LLC_SK_DEV_HASH_BITS) | |
39 | ||
52d58aef OP |
40 | #define LLC_SK_LADDR_HASH_BITS 6 |
41 | #define LLC_SK_LADDR_HASH_ENTRIES (1<<LLC_SK_LADDR_HASH_BITS) | |
42 | ||
1da177e4 LT |
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; | |
58951dde | 58 | refcount_t refcnt; |
1da177e4 LT |
59 | int (*rcv_func)(struct sk_buff *skb, |
60 | struct net_device *dev, | |
f2ccd8fa DM |
61 | struct packet_type *pt, |
62 | struct net_device *orig_dev); | |
1da177e4 LT |
63 | struct llc_addr laddr; |
64 | struct list_head node; | |
b76f5a84 | 65 | spinlock_t sk_lock; |
52d58aef OP |
66 | int sk_count; |
67 | struct hlist_nulls_head sk_laddr_hash[LLC_SK_LADDR_HASH_ENTRIES]; | |
6d2e3ea2 | 68 | struct hlist_head sk_dev_hash[LLC_SK_DEV_HASH_ENTRIES]; |
9708d2b5 | 69 | struct rcu_head rcu; |
1da177e4 LT |
70 | }; |
71 | ||
6d2e3ea2 OP |
72 | static inline |
73 | struct hlist_head *llc_sk_dev_hash(struct llc_sap *sap, int ifindex) | |
74 | { | |
5e260ecb ED |
75 | u32 bucket = hash_32(ifindex, LLC_SK_DEV_HASH_BITS); |
76 | ||
77 | return &sap->sk_dev_hash[bucket]; | |
6d2e3ea2 OP |
78 | } |
79 | ||
52d58aef OP |
80 | static inline |
81 | u32 llc_sk_laddr_hashfn(struct llc_sap *sap, const struct llc_addr *laddr) | |
82 | { | |
83 | return hash_32(jhash(laddr->mac, sizeof(laddr->mac), 0), | |
84 | LLC_SK_LADDR_HASH_BITS); | |
85 | } | |
86 | ||
87 | static inline | |
88 | struct hlist_nulls_head *llc_sk_laddr_hash(struct llc_sap *sap, | |
89 | const struct llc_addr *laddr) | |
90 | { | |
91 | return &sap->sk_laddr_hash[llc_sk_laddr_hashfn(sap, laddr)]; | |
92 | } | |
6d2e3ea2 | 93 | |
1da177e4 LT |
94 | #define LLC_DEST_INVALID 0 /* Invalid LLC PDU type */ |
95 | #define LLC_DEST_SAP 1 /* Type 1 goes here */ | |
96 | #define LLC_DEST_CONN 2 /* Type 2 goes here */ | |
97 | ||
98 | extern struct list_head llc_sap_list; | |
1da177e4 | 99 | |
bf3c710f JP |
100 | int llc_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, |
101 | struct net_device *orig_dev); | |
1da177e4 | 102 | |
bf3c710f JP |
103 | int llc_mac_hdr_init(struct sk_buff *skb, const unsigned char *sa, |
104 | const unsigned char *da); | |
1da177e4 | 105 | |
bf3c710f JP |
106 | void llc_add_pack(int type, |
107 | void (*handler)(struct llc_sap *sap, struct sk_buff *skb)); | |
108 | void llc_remove_pack(int type); | |
1da177e4 | 109 | |
bf3c710f | 110 | void llc_set_station_handler(void (*handler)(struct sk_buff *skb)); |
1da177e4 | 111 | |
bf3c710f JP |
112 | struct llc_sap *llc_sap_open(unsigned char lsap, |
113 | int (*rcv)(struct sk_buff *skb, | |
114 | struct net_device *dev, | |
115 | struct packet_type *pt, | |
116 | struct net_device *orig_dev)); | |
6e2144b7 ACM |
117 | static inline void llc_sap_hold(struct llc_sap *sap) |
118 | { | |
58951dde | 119 | refcount_inc(&sap->refcnt); |
6e2144b7 ACM |
120 | } |
121 | ||
0dcb8225 CW |
122 | static inline bool llc_sap_hold_safe(struct llc_sap *sap) |
123 | { | |
124 | return refcount_inc_not_zero(&sap->refcnt); | |
125 | } | |
126 | ||
bf3c710f | 127 | void llc_sap_close(struct llc_sap *sap); |
2928c19e | 128 | |
6e2144b7 ACM |
129 | static inline void llc_sap_put(struct llc_sap *sap) |
130 | { | |
58951dde | 131 | if (refcount_dec_and_test(&sap->refcnt)) |
6e2144b7 ACM |
132 | llc_sap_close(sap); |
133 | } | |
1da177e4 | 134 | |
bf3c710f | 135 | struct llc_sap *llc_sap_find(unsigned char sap_value); |
1da177e4 | 136 | |
bf3c710f JP |
137 | int llc_build_and_send_ui_pkt(struct llc_sap *sap, struct sk_buff *skb, |
138 | unsigned char *dmac, unsigned char dsap); | |
1da177e4 | 139 | |
bf3c710f JP |
140 | void llc_sap_handler(struct llc_sap *sap, struct sk_buff *skb); |
141 | void llc_conn_handler(struct llc_sap *sap, struct sk_buff *skb); | |
2928c19e | 142 | |
bf3c710f JP |
143 | void llc_station_init(void); |
144 | void llc_station_exit(void); | |
1da177e4 LT |
145 | |
146 | #ifdef CONFIG_PROC_FS | |
bf3c710f JP |
147 | int llc_proc_init(void); |
148 | void llc_proc_exit(void); | |
1da177e4 LT |
149 | #else |
150 | #define llc_proc_init() (0) | |
151 | #define llc_proc_exit() do { } while(0) | |
152 | #endif /* CONFIG_PROC_FS */ | |
590232a7 | 153 | #ifdef CONFIG_SYSCTL |
bf3c710f JP |
154 | int llc_sysctl_init(void); |
155 | void llc_sysctl_exit(void); | |
2928c19e ACM |
156 | |
157 | extern int sysctl_llc2_ack_timeout; | |
158 | extern int sysctl_llc2_busy_timeout; | |
159 | extern int sysctl_llc2_p_timeout; | |
160 | extern int sysctl_llc2_rej_timeout; | |
590232a7 ACM |
161 | #else |
162 | #define llc_sysctl_init() (0) | |
163 | #define llc_sysctl_exit() do { } while(0) | |
164 | #endif /* CONFIG_SYSCTL */ | |
1da177e4 | 165 | #endif /* LLC_H */ |