blob: 890a87318014d528a78a3a9631ebdb75bf037a4b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#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 Purdilab76f5a82009-12-26 11:51:02 +000019#include <linux/rculist_nulls.h>
Octavian Purdila52d58ae2009-12-26 11:51:05 +000020#include <linux/hash.h>
21#include <linux/jhash.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
Arun Sharma600634972011-07-26 16:09:06 -070023#include <linux/atomic.h>
Arnaldo Carvalho de Melo6e2144b2005-09-22 04:43:05 -030024
Linus Torvalds1da177e2005-04-16 15:20:36 -070025struct 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
Octavian Purdila6d2e3ea2009-12-26 11:51:04 +000037#define LLC_SK_DEV_HASH_BITS 6
38#define LLC_SK_DEV_HASH_ENTRIES (1<<LLC_SK_DEV_HASH_BITS)
39
Octavian Purdila52d58ae2009-12-26 11:51:05 +000040#define LLC_SK_LADDR_HASH_BITS 6
41#define LLC_SK_LADDR_HASH_ENTRIES (1<<LLC_SK_LADDR_HASH_BITS)
42
Linus Torvalds1da177e2005-04-16 15:20:36 -070043/**
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 */
54struct llc_sap {
55 unsigned char state;
56 unsigned char p_bit;
57 unsigned char f_bit;
Reshetova, Elena58951dd2017-07-04 15:52:56 +030058 refcount_t refcnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 int (*rcv_func)(struct sk_buff *skb,
60 struct net_device *dev,
David S. Millerf2ccd8f2005-08-09 19:34:12 -070061 struct packet_type *pt,
62 struct net_device *orig_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 struct llc_addr laddr;
64 struct list_head node;
Octavian Purdilab76f5a82009-12-26 11:51:02 +000065 spinlock_t sk_lock;
Octavian Purdila52d58ae2009-12-26 11:51:05 +000066 int sk_count;
67 struct hlist_nulls_head sk_laddr_hash[LLC_SK_LADDR_HASH_ENTRIES];
Octavian Purdila6d2e3ea2009-12-26 11:51:04 +000068 struct hlist_head sk_dev_hash[LLC_SK_DEV_HASH_ENTRIES];
Linus Torvalds1da177e2005-04-16 15:20:36 -070069};
70
Octavian Purdila6d2e3ea2009-12-26 11:51:04 +000071static 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
Octavian Purdila52d58ae2009-12-26 11:51:05 +000077static 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}
Octavian Purdila6d2e3ea2009-12-26 11:51:04 +000090
Linus Torvalds1da177e2005-04-16 15:20:36 -070091#define LLC_DEST_INVALID 0 /* Invalid LLC PDU type */
92#define LLC_DEST_SAP 1 /* Type 1 goes here */
93#define LLC_DEST_CONN 2 /* Type 2 goes here */
94
95extern struct list_head llc_sap_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
Joe Perchesbf3c7102013-09-21 10:22:45 -070097int llc_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt,
98 struct net_device *orig_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
Joe Perchesbf3c7102013-09-21 10:22:45 -0700100int llc_mac_hdr_init(struct sk_buff *skb, const unsigned char *sa,
101 const unsigned char *da);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
Joe Perchesbf3c7102013-09-21 10:22:45 -0700103void llc_add_pack(int type,
104 void (*handler)(struct llc_sap *sap, struct sk_buff *skb));
105void llc_remove_pack(int type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
Joe Perchesbf3c7102013-09-21 10:22:45 -0700107void llc_set_station_handler(void (*handler)(struct sk_buff *skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Joe Perchesbf3c7102013-09-21 10:22:45 -0700109struct llc_sap *llc_sap_open(unsigned char lsap,
110 int (*rcv)(struct sk_buff *skb,
111 struct net_device *dev,
112 struct packet_type *pt,
113 struct net_device *orig_dev));
Arnaldo Carvalho de Melo6e2144b2005-09-22 04:43:05 -0300114static inline void llc_sap_hold(struct llc_sap *sap)
115{
Reshetova, Elena58951dd2017-07-04 15:52:56 +0300116 refcount_inc(&sap->refcnt);
Arnaldo Carvalho de Melo6e2144b2005-09-22 04:43:05 -0300117}
118
Cong Wang0dcb8222018-08-07 12:41:38 -0700119static inline bool llc_sap_hold_safe(struct llc_sap *sap)
120{
121 return refcount_inc_not_zero(&sap->refcnt);
122}
123
Joe Perchesbf3c7102013-09-21 10:22:45 -0700124void llc_sap_close(struct llc_sap *sap);
Arnaldo Carvalho de Melo2928c192005-09-22 05:14:33 -0300125
Arnaldo Carvalho de Melo6e2144b2005-09-22 04:43:05 -0300126static inline void llc_sap_put(struct llc_sap *sap)
127{
Reshetova, Elena58951dd2017-07-04 15:52:56 +0300128 if (refcount_dec_and_test(&sap->refcnt))
Arnaldo Carvalho de Melo6e2144b2005-09-22 04:43:05 -0300129 llc_sap_close(sap);
130}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
Joe Perchesbf3c7102013-09-21 10:22:45 -0700132struct llc_sap *llc_sap_find(unsigned char sap_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
Joe Perchesbf3c7102013-09-21 10:22:45 -0700134int llc_build_and_send_ui_pkt(struct llc_sap *sap, struct sk_buff *skb,
135 unsigned char *dmac, unsigned char dsap);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
Joe Perchesbf3c7102013-09-21 10:22:45 -0700137void llc_sap_handler(struct llc_sap *sap, struct sk_buff *skb);
138void llc_conn_handler(struct llc_sap *sap, struct sk_buff *skb);
Arnaldo Carvalho de Melo2928c192005-09-22 05:14:33 -0300139
Joe Perchesbf3c7102013-09-21 10:22:45 -0700140void llc_station_init(void);
141void llc_station_exit(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
143#ifdef CONFIG_PROC_FS
Joe Perchesbf3c7102013-09-21 10:22:45 -0700144int llc_proc_init(void);
145void llc_proc_exit(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146#else
147#define llc_proc_init() (0)
148#define llc_proc_exit() do { } while(0)
149#endif /* CONFIG_PROC_FS */
Arnaldo Carvalho de Melo590232a2005-09-22 04:30:44 -0300150#ifdef CONFIG_SYSCTL
Joe Perchesbf3c7102013-09-21 10:22:45 -0700151int llc_sysctl_init(void);
152void llc_sysctl_exit(void);
Arnaldo Carvalho de Melo2928c192005-09-22 05:14:33 -0300153
154extern int sysctl_llc2_ack_timeout;
155extern int sysctl_llc2_busy_timeout;
156extern int sysctl_llc2_p_timeout;
157extern int sysctl_llc2_rej_timeout;
Arnaldo Carvalho de Melo590232a2005-09-22 04:30:44 -0300158#else
159#define llc_sysctl_init() (0)
160#define llc_sysctl_exit() do { } while(0)
161#endif /* CONFIG_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162#endif /* LLC_H */