1#ifndef LLC_H
2#define LLC_H
3
4
5
6
7
8
9
10
11
12
13
14
15#include <linux/if.h>
16#include <linux/if_ether.h>
17#include <linux/list.h>
18#include <linux/spinlock.h>
19#include <linux/rculist_nulls.h>
20#include <linux/hash.h>
21#include <linux/jhash.h>
22
23#include <linux/atomic.h>
24
25struct net_device;
26struct packet_type;
27struct sk_buff;
28
29struct 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
37#define LLC_SK_DEV_HASH_BITS 6
38#define LLC_SK_DEV_HASH_ENTRIES (1<<LLC_SK_DEV_HASH_BITS)
39
40#define LLC_SK_LADDR_HASH_BITS 6
41#define LLC_SK_LADDR_HASH_ENTRIES (1<<LLC_SK_LADDR_HASH_BITS)
42
43
44
45
46
47
48
49
50
51
52
53
54struct llc_sap {
55 unsigned char state;
56 unsigned char p_bit;
57 unsigned char f_bit;
58 atomic_t refcnt;
59 int (*rcv_func)(struct sk_buff *skb,
60 struct net_device *dev,
61 struct packet_type *pt,
62 struct net_device *orig_dev);
63 struct llc_addr laddr;
64 struct list_head node;
65 spinlock_t sk_lock;
66 int sk_count;
67 struct hlist_nulls_head sk_laddr_hash[LLC_SK_LADDR_HASH_ENTRIES];
68 struct hlist_head sk_dev_hash[LLC_SK_DEV_HASH_ENTRIES];
69};
70
71static inline
72struct hlist_head *llc_sk_dev_hash(struct llc_sap *sap, int ifindex)
73{
74 return &sap->sk_dev_hash[ifindex % LLC_SK_DEV_HASH_ENTRIES];
75}
76
77static inline
78u32 llc_sk_laddr_hashfn(struct llc_sap *sap, const struct llc_addr *laddr)
79{
80 return hash_32(jhash(laddr->mac, sizeof(laddr->mac), 0),
81 LLC_SK_LADDR_HASH_BITS);
82}
83
84static inline
85struct hlist_nulls_head *llc_sk_laddr_hash(struct llc_sap *sap,
86 const struct llc_addr *laddr)
87{
88 return &sap->sk_laddr_hash[llc_sk_laddr_hashfn(sap, laddr)];
89}
90
91#define LLC_DEST_INVALID 0
92#define LLC_DEST_SAP 1
93#define LLC_DEST_CONN 2
94
95extern struct list_head llc_sap_list;
96extern spinlock_t llc_sap_list_lock;
97
98extern int llc_rcv(struct sk_buff *skb, struct net_device *dev,
99 struct packet_type *pt, struct net_device *orig_dev);
100
101extern int llc_mac_hdr_init(struct sk_buff *skb,
102 const unsigned char *sa, const unsigned char *da);
103
104extern void llc_add_pack(int type, void (*handler)(struct llc_sap *sap,
105 struct sk_buff *skb));
106extern void llc_remove_pack(int type);
107
108extern void llc_set_station_handler(void (*handler)(struct sk_buff *skb));
109
110extern 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));
115static inline void llc_sap_hold(struct llc_sap *sap)
116{
117 atomic_inc(&sap->refcnt);
118}
119
120extern void llc_sap_close(struct llc_sap *sap);
121
122static inline void llc_sap_put(struct llc_sap *sap)
123{
124 if (atomic_dec_and_test(&sap->refcnt))
125 llc_sap_close(sap);
126}
127
128extern struct llc_sap *llc_sap_find(unsigned char sap_value);
129
130extern int llc_build_and_send_ui_pkt(struct llc_sap *sap, struct sk_buff *skb,
131 unsigned char *dmac, unsigned char dsap);
132
133extern void llc_sap_handler(struct llc_sap *sap, struct sk_buff *skb);
134extern void llc_conn_handler(struct llc_sap *sap, struct sk_buff *skb);
135
136extern void llc_station_init(void);
137extern void llc_station_exit(void);
138
139#ifdef CONFIG_PROC_FS
140extern int llc_proc_init(void);
141extern void llc_proc_exit(void);
142#else
143#define llc_proc_init() (0)
144#define llc_proc_exit() do { } while(0)
145#endif
146#ifdef CONFIG_SYSCTL
147extern int llc_sysctl_init(void);
148extern void llc_sysctl_exit(void);
149
150extern int sysctl_llc2_ack_timeout;
151extern int sysctl_llc2_busy_timeout;
152extern int sysctl_llc2_p_timeout;
153extern int sysctl_llc2_rej_timeout;
154extern int sysctl_llc_station_ack_timeout;
155#else
156#define llc_sysctl_init() (0)
157#define llc_sysctl_exit() do { } while(0)
158#endif
159#endif
160