aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid S. Miller <davem@sunset.davemloft.net>2005-09-26 18:29:31 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2005-09-26 18:29:31 -0400
commit56e9b263242ca80a70abd8831343b268315c27dc (patch)
tree19a4fe82be6725754a1b0a25638e693d994ac86d
parent188bab3ae0ed164bc18f98be932512d777dd038b (diff)
parent8420e1b541fe92aee1d8d4d25d9e33eaca756a7b (diff)
Merge master.kernel.org:/pub/scm/linux/kernel/git/acme/llc-2.6
-rw-r--r--include/linux/sysctl.h26
-rw-r--r--include/net/llc.h30
-rw-r--r--include/net/llc_conn.h15
-rw-r--r--include/net/llc_sap.h8
-rw-r--r--net/802/p8022.c2
-rw-r--r--net/802/psnap.c2
-rw-r--r--net/802/tr.c2
-rw-r--r--net/core/dev.c2
-rw-r--r--net/llc/Makefile1
-rw-r--r--net/llc/af_llc.c501
-rw-r--r--net/llc/llc_c_ac.c271
-rw-r--r--net/llc/llc_c_ev.c157
-rw-r--r--net/llc/llc_conn.c212
-rw-r--r--net/llc/llc_core.c34
-rw-r--r--net/llc/llc_if.c11
-rw-r--r--net/llc/llc_input.c19
-rw-r--r--net/llc/llc_output.c2
-rw-r--r--net/llc/llc_proc.c2
-rw-r--r--net/llc/llc_s_ac.c16
-rw-r--r--net/llc/llc_sap.c20
-rw-r--r--net/llc/llc_station.c25
-rw-r--r--net/llc/sysctl_net_llc.c131
22 files changed, 875 insertions, 614 deletions
diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
index 3a29a9f9b451..fc8e367f671e 100644
--- a/include/linux/sysctl.h
+++ b/include/linux/sysctl.h
@@ -202,7 +202,8 @@ enum
202 NET_TR=14, 202 NET_TR=14,
203 NET_DECNET=15, 203 NET_DECNET=15,
204 NET_ECONET=16, 204 NET_ECONET=16,
205 NET_SCTP=17, 205 NET_SCTP=17,
206 NET_LLC=18,
206}; 207};
207 208
208/* /proc/sys/kernel/random */ 209/* /proc/sys/kernel/random */
@@ -522,6 +523,29 @@ enum {
522 NET_IPX_FORWARDING=2 523 NET_IPX_FORWARDING=2
523}; 524};
524 525
526/* /proc/sys/net/llc */
527enum {
528 NET_LLC2=1,
529 NET_LLC_STATION=2,
530};
531
532/* /proc/sys/net/llc/llc2 */
533enum {
534 NET_LLC2_TIMEOUT=1,
535};
536
537/* /proc/sys/net/llc/station */
538enum {
539 NET_LLC_STATION_ACK_TIMEOUT=1,
540};
541
542/* /proc/sys/net/llc/llc2/timeout */
543enum {
544 NET_LLC2_ACK_TIMEOUT=1,
545 NET_LLC2_P_TIMEOUT=2,
546 NET_LLC2_REJ_TIMEOUT=3,
547 NET_LLC2_BUSY_TIMEOUT=4,
548};
525 549
526/* /proc/sys/net/appletalk */ 550/* /proc/sys/net/appletalk */
527enum { 551enum {
diff --git a/include/net/llc.h b/include/net/llc.h
index 71769a5aeef3..1adb2ef3f6f7 100644
--- a/include/net/llc.h
+++ b/include/net/llc.h
@@ -17,6 +17,8 @@
17#include <linux/list.h> 17#include <linux/list.h>
18#include <linux/spinlock.h> 18#include <linux/spinlock.h>
19 19
20#include <asm/atomic.h>
21
20struct net_device; 22struct net_device;
21struct packet_type; 23struct packet_type;
22struct sk_buff; 24struct sk_buff;
@@ -44,6 +46,7 @@ struct llc_sap {
44 unsigned char state; 46 unsigned char state;
45 unsigned char p_bit; 47 unsigned char p_bit;
46 unsigned char f_bit; 48 unsigned char f_bit;
49 atomic_t refcnt;
47 int (*rcv_func)(struct sk_buff *skb, 50 int (*rcv_func)(struct sk_buff *skb,
48 struct net_device *dev, 51 struct net_device *dev,
49 struct packet_type *pt, 52 struct packet_type *pt,
@@ -81,13 +84,27 @@ extern struct llc_sap *llc_sap_open(unsigned char lsap,
81 struct net_device *dev, 84 struct net_device *dev,
82 struct packet_type *pt, 85 struct packet_type *pt,
83 struct net_device *orig_dev)); 86 struct net_device *orig_dev));
87static inline void llc_sap_hold(struct llc_sap *sap)
88{
89 atomic_inc(&sap->refcnt);
90}
91
84extern void llc_sap_close(struct llc_sap *sap); 92extern void llc_sap_close(struct llc_sap *sap);
85 93
94static inline void llc_sap_put(struct llc_sap *sap)
95{
96 if (atomic_dec_and_test(&sap->refcnt))
97 llc_sap_close(sap);
98}
99
86extern struct llc_sap *llc_sap_find(unsigned char sap_value); 100extern struct llc_sap *llc_sap_find(unsigned char sap_value);
87 101
88extern int llc_build_and_send_ui_pkt(struct llc_sap *sap, struct sk_buff *skb, 102extern int llc_build_and_send_ui_pkt(struct llc_sap *sap, struct sk_buff *skb,
89 unsigned char *dmac, unsigned char dsap); 103 unsigned char *dmac, unsigned char dsap);
90 104
105extern void llc_sap_handler(struct llc_sap *sap, struct sk_buff *skb);
106extern void llc_conn_handler(struct llc_sap *sap, struct sk_buff *skb);
107
91extern int llc_station_init(void); 108extern int llc_station_init(void);
92extern void llc_station_exit(void); 109extern void llc_station_exit(void);
93 110
@@ -98,4 +115,17 @@ extern void llc_proc_exit(void);
98#define llc_proc_init() (0) 115#define llc_proc_init() (0)
99#define llc_proc_exit() do { } while(0) 116#define llc_proc_exit() do { } while(0)
100#endif /* CONFIG_PROC_FS */ 117#endif /* CONFIG_PROC_FS */
118#ifdef CONFIG_SYSCTL
119extern int llc_sysctl_init(void);
120extern void llc_sysctl_exit(void);
121
122extern int sysctl_llc2_ack_timeout;
123extern int sysctl_llc2_busy_timeout;
124extern int sysctl_llc2_p_timeout;
125extern int sysctl_llc2_rej_timeout;
126extern int sysctl_llc_station_ack_timeout;
127#else
128#define llc_sysctl_init() (0)
129#define llc_sysctl_exit() do { } while(0)
130#endif /* CONFIG_SYSCTL */
101#endif /* LLC_H */ 131#endif /* LLC_H */
diff --git a/include/net/llc_conn.h b/include/net/llc_conn.h
index 8ad3bc2c23d7..54852ff6033b 100644
--- a/include/net/llc_conn.h
+++ b/include/net/llc_conn.h
@@ -19,14 +19,14 @@
19#define LLC_EVENT 1 19#define LLC_EVENT 1
20#define LLC_PACKET 2 20#define LLC_PACKET 2
21 21
22#define LLC_P_TIME 2 22#define LLC2_P_TIME 2
23#define LLC_ACK_TIME 1 23#define LLC2_ACK_TIME 1
24#define LLC_REJ_TIME 3 24#define LLC2_REJ_TIME 3
25#define LLC_BUSY_TIME 3 25#define LLC2_BUSY_TIME 3
26 26
27struct llc_timer { 27struct llc_timer {
28 struct timer_list timer; 28 struct timer_list timer;
29 u16 expire; /* timer expire time */ 29 unsigned long expire; /* timer expire time */
30}; 30};
31 31
32struct llc_sock { 32struct llc_sock {
@@ -38,6 +38,7 @@ struct llc_sock {
38 struct llc_addr laddr; /* lsap/mac pair */ 38 struct llc_addr laddr; /* lsap/mac pair */
39 struct llc_addr daddr; /* dsap/mac pair */ 39 struct llc_addr daddr; /* dsap/mac pair */
40 struct net_device *dev; /* device to send to remote */ 40 struct net_device *dev; /* device to send to remote */
41 u32 copied_seq; /* head of yet unread data */
41 u8 retry_count; /* number of retries */ 42 u8 retry_count; /* number of retries */
42 u8 ack_must_be_send; 43 u8 ack_must_be_send;
43 u8 first_pdu_Ns; 44 u8 first_pdu_Ns;
@@ -92,7 +93,8 @@ static __inline__ char llc_backlog_type(struct sk_buff *skb)
92 return skb->cb[sizeof(skb->cb) - 1]; 93 return skb->cb[sizeof(skb->cb) - 1];
93} 94}
94 95
95extern struct sock *llc_sk_alloc(int family, int priority, struct proto *prot); 96extern struct sock *llc_sk_alloc(int family, unsigned int __nocast priority,
97 struct proto *prot);
96extern void llc_sk_free(struct sock *sk); 98extern void llc_sk_free(struct sock *sk);
97 99
98extern void llc_sk_reset(struct sock *sk); 100extern void llc_sk_reset(struct sock *sk);
@@ -115,5 +117,4 @@ extern void llc_sap_remove_socket(struct llc_sap *sap, struct sock *sk);
115 117
116extern u8 llc_data_accept_state(u8 state); 118extern u8 llc_data_accept_state(u8 state);
117extern void llc_build_offset_table(void); 119extern void llc_build_offset_table(void);
118extern int llc_release_sockets(struct llc_sap *sap);
119#endif /* LLC_CONN_H */ 120#endif /* LLC_CONN_H */
diff --git a/include/net/llc_sap.h b/include/net/llc_sap.h
index 353baaa627f3..2c56dbece729 100644
--- a/include/net/llc_sap.h
+++ b/include/net/llc_sap.h
@@ -12,11 +12,15 @@
12 * See the GNU General Public License for more details. 12 * See the GNU General Public License for more details.
13 */ 13 */
14struct llc_sap; 14struct llc_sap;
15struct net_device;
15struct sk_buff; 16struct sk_buff;
17struct sock;
16 18
17extern void llc_sap_rtn_pdu(struct llc_sap *sap, struct sk_buff *skb); 19extern void llc_sap_rtn_pdu(struct llc_sap *sap, struct sk_buff *skb);
18extern void llc_save_primitive(struct sk_buff* skb, unsigned char prim); 20extern void llc_save_primitive(struct sock *sk, struct sk_buff* skb,
19extern struct sk_buff *llc_alloc_frame(void); 21 unsigned char prim);
22extern struct sk_buff *llc_alloc_frame(struct sock *sk,
23 struct net_device *dev);
20 24
21extern void llc_build_and_send_test_pkt(struct llc_sap *sap, 25extern void llc_build_and_send_test_pkt(struct llc_sap *sap,
22 struct sk_buff *skb, 26 struct sk_buff *skb,
diff --git a/net/802/p8022.c b/net/802/p8022.c
index b24817c63ca8..2530f35241cd 100644
--- a/net/802/p8022.c
+++ b/net/802/p8022.c
@@ -56,7 +56,7 @@ struct datalink_proto *register_8022_client(unsigned char type,
56 56
57void unregister_8022_client(struct datalink_proto *proto) 57void unregister_8022_client(struct datalink_proto *proto)
58{ 58{
59 llc_sap_close(proto->sap); 59 llc_sap_put(proto->sap);
60 kfree(proto); 60 kfree(proto);
61} 61}
62 62
diff --git a/net/802/psnap.c b/net/802/psnap.c
index ab80b1fab53c..4d638944d933 100644
--- a/net/802/psnap.c
+++ b/net/802/psnap.c
@@ -106,7 +106,7 @@ module_init(snap_init);
106 106
107static void __exit snap_exit(void) 107static void __exit snap_exit(void)
108{ 108{
109 llc_sap_close(snap_sap); 109 llc_sap_put(snap_sap);
110} 110}
111 111
112module_exit(snap_exit); 112module_exit(snap_exit);
diff --git a/net/802/tr.c b/net/802/tr.c
index 1bb7dc1b85cd..1eaa3d19d8bf 100644
--- a/net/802/tr.c
+++ b/net/802/tr.c
@@ -238,7 +238,7 @@ unsigned short tr_type_trans(struct sk_buff *skb, struct net_device *dev)
238 return trllc->ethertype; 238 return trllc->ethertype;
239 } 239 }
240 240
241 return ntohs(ETH_P_802_2); 241 return ntohs(ETH_P_TR_802_2);
242} 242}
243 243
244/* 244/*
diff --git a/net/core/dev.c b/net/core/dev.c
index c01511e3d0c1..37c881070963 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -574,6 +574,8 @@ struct net_device *dev_getbyhwaddr(unsigned short type, char *ha)
574 return dev; 574 return dev;
575} 575}
576 576
577EXPORT_SYMBOL(dev_getbyhwaddr);
578
577struct net_device *dev_getfirstbyhwtype(unsigned short type) 579struct net_device *dev_getfirstbyhwtype(unsigned short type)
578{ 580{
579 struct net_device *dev; 581 struct net_device *dev;
diff --git a/net/llc/Makefile b/net/llc/Makefile
index 5ebd4ed2bd42..4e260cff3c5d 100644
--- a/net/llc/Makefile
+++ b/net/llc/Makefile
@@ -22,3 +22,4 @@ llc2-y := llc_if.o llc_c_ev.o llc_c_ac.o llc_conn.o llc_c_st.o llc_pdu.o \
22 llc_sap.o llc_s_ac.o llc_s_ev.o llc_s_st.o af_llc.o llc_station.o 22 llc_sap.o llc_s_ac.o llc_s_ev.o llc_s_st.o af_llc.o llc_station.o
23 23
24llc2-$(CONFIG_PROC_FS) += llc_proc.o 24llc2-$(CONFIG_PROC_FS) += llc_proc.o
25llc2-$(CONFIG_SYSCTL) += sysctl_net_llc.o
diff --git a/net/llc/af_llc.c b/net/llc/af_llc.c
index 66f55e514b56..59d02cbbeb9e 100644
--- a/net/llc/af_llc.c
+++ b/net/llc/af_llc.c
@@ -21,6 +21,7 @@
21 * See the GNU General Public License for more details. 21 * See the GNU General Public License for more details.
22 */ 22 */
23#include <linux/config.h> 23#include <linux/config.h>
24#include <linux/compiler.h>
24#include <linux/kernel.h> 25#include <linux/kernel.h>
25#include <linux/module.h> 26#include <linux/module.h>
26#include <linux/rtnetlink.h> 27#include <linux/rtnetlink.h>
@@ -37,10 +38,9 @@ static u16 llc_ui_sap_link_no_max[256];
37static struct sockaddr_llc llc_ui_addrnull; 38static struct sockaddr_llc llc_ui_addrnull;
38static struct proto_ops llc_ui_ops; 39static struct proto_ops llc_ui_ops;
39 40
40static int llc_ui_wait_for_conn(struct sock *sk, int timeout); 41static int llc_ui_wait_for_conn(struct sock *sk, long timeout);
41static int llc_ui_wait_for_disc(struct sock *sk, int timeout); 42static int llc_ui_wait_for_disc(struct sock *sk, long timeout);
42static int llc_ui_wait_for_data(struct sock *sk, int timeout); 43static int llc_ui_wait_for_busy_core(struct sock *sk, long timeout);
43static int llc_ui_wait_for_busy_core(struct sock *sk, int timeout);
44 44
45#if 0 45#if 0
46#define dprintk(args...) printk(KERN_DEBUG args) 46#define dprintk(args...) printk(KERN_DEBUG args)
@@ -116,12 +116,12 @@ static int llc_ui_send_data(struct sock* sk, struct sk_buff *skb, int noblock)
116 struct llc_sock* llc = llc_sk(sk); 116 struct llc_sock* llc = llc_sk(sk);
117 int rc = 0; 117 int rc = 0;
118 118
119 if (llc_data_accept_state(llc->state) || llc->p_flag) { 119 if (unlikely(llc_data_accept_state(llc->state) || llc->p_flag)) {
120 int timeout = sock_sndtimeo(sk, noblock); 120 long timeout = sock_sndtimeo(sk, noblock);
121 121
122 rc = llc_ui_wait_for_busy_core(sk, timeout); 122 rc = llc_ui_wait_for_busy_core(sk, timeout);
123 } 123 }
124 if (!rc) 124 if (unlikely(!rc))
125 rc = llc_build_and_send_pkt(sk, skb); 125 rc = llc_build_and_send_pkt(sk, skb);
126 return rc; 126 return rc;
127} 127}
@@ -155,7 +155,7 @@ static int llc_ui_create(struct socket *sock, int protocol)
155 struct sock *sk; 155 struct sock *sk;
156 int rc = -ESOCKTNOSUPPORT; 156 int rc = -ESOCKTNOSUPPORT;
157 157
158 if (sock->type == SOCK_DGRAM || sock->type == SOCK_STREAM) { 158 if (likely(sock->type == SOCK_DGRAM || sock->type == SOCK_STREAM)) {
159 rc = -ENOMEM; 159 rc = -ENOMEM;
160 sk = llc_sk_alloc(PF_LLC, GFP_KERNEL, &llc_proto); 160 sk = llc_sk_alloc(PF_LLC, GFP_KERNEL, &llc_proto);
161 if (sk) { 161 if (sk) {
@@ -177,7 +177,7 @@ static int llc_ui_release(struct socket *sock)
177 struct sock *sk = sock->sk; 177 struct sock *sk = sock->sk;
178 struct llc_sock *llc; 178 struct llc_sock *llc;
179 179
180 if (!sk) 180 if (unlikely(sk == NULL))
181 goto out; 181 goto out;
182 sock_hold(sk); 182 sock_hold(sk);
183 lock_sock(sk); 183 lock_sock(sk);
@@ -189,10 +189,6 @@ static int llc_ui_release(struct socket *sock)
189 if (!sock_flag(sk, SOCK_ZAPPED)) 189 if (!sock_flag(sk, SOCK_ZAPPED))
190 llc_sap_remove_socket(llc->sap, sk); 190 llc_sap_remove_socket(llc->sap, sk);
191 release_sock(sk); 191 release_sock(sk);
192 if (llc->sap && hlist_empty(&llc->sap->sk_list.list)) {
193 llc_release_sockets(llc->sap);
194 llc_sap_close(llc->sap);
195 }
196 if (llc->dev) 192 if (llc->dev)
197 dev_put(llc->dev); 193 dev_put(llc->dev);
198 sock_put(sk); 194 sock_put(sk);
@@ -221,6 +217,7 @@ static int llc_ui_autoport(void)
221 llc_ui_sap_last_autoport = i + 2; 217 llc_ui_sap_last_autoport = i + 2;
222 goto out; 218 goto out;
223 } 219 }
220 llc_sap_put(sap);
224 } 221 }
225 llc_ui_sap_last_autoport = LLC_SAP_DYN_START; 222 llc_ui_sap_last_autoport = LLC_SAP_DYN_START;
226 tries++; 223 tries++;
@@ -231,20 +228,13 @@ out:
231} 228}
232 229
233/** 230/**
234 * llc_ui_autobind - Bind a socket to a specific address. 231 * llc_ui_autobind - automatically bind a socket to a sap
235 * @sk: Socket to bind an address to. 232 * @sock: socket to bind
236 * @addr: Address the user wants the socket bound to. 233 * @addr: address to connect to
234 *
235 * Used by llc_ui_connect and llc_ui_sendmsg when the user hasn't
236 * specifically used llc_ui_bind to bind to an specific address/sap
237 * 237 *
238 * Bind a socket to a specific address. For llc a user is able to bind to
239 * a specific sap only or mac + sap. If the user only specifies a sap and
240 * a null dmac (all zeros) the user is attempting to bind to an entire
241 * sap. This will stop anyone else on the local system from using that
242 * sap. If someone else has a mac + sap open the bind to null + sap will
243 * fail.
244 * If the user desires to bind to a specific mac + sap, it is possible to
245 * have multiple sap connections via multiple macs.
246 * Bind and autobind for that matter must enforce the correct sap usage
247 * otherwise all hell will break loose.
248 * Returns: 0 upon success, negative otherwise. 238 * Returns: 0 upon success, negative otherwise.
249 */ 239 */
250static int llc_ui_autobind(struct socket *sock, struct sockaddr_llc *addr) 240static int llc_ui_autobind(struct socket *sock, struct sockaddr_llc *addr)
@@ -285,11 +275,7 @@ out:
285 * @addrlen: Length of the uaddr structure. 275 * @addrlen: Length of the uaddr structure.
286 * 276 *
287 * Bind a socket to a specific address. For llc a user is able to bind to 277 * Bind a socket to a specific address. For llc a user is able to bind to
288 * a specific sap only or mac + sap. If the user only specifies a sap and 278 * a specific sap only or mac + sap.
289 * a null dmac (all zeros) the user is attempting to bind to an entire
290 * sap. This will stop anyone else on the local system from using that
291 * sap. If someone else has a mac + sap open the bind to null + sap will
292 * fail.
293 * If the user desires to bind to a specific mac + sap, it is possible to 279 * If the user desires to bind to a specific mac + sap, it is possible to
294 * have multiple sap connections via multiple macs. 280 * have multiple sap connections via multiple macs.
295 * Bind and autobind for that matter must enforce the correct sap usage 281 * Bind and autobind for that matter must enforce the correct sap usage
@@ -305,10 +291,16 @@ static int llc_ui_bind(struct socket *sock, struct sockaddr *uaddr, int addrlen)
305 int rc = -EINVAL; 291 int rc = -EINVAL;
306 292
307 dprintk("%s: binding %02X\n", __FUNCTION__, addr->sllc_sap); 293 dprintk("%s: binding %02X\n", __FUNCTION__, addr->sllc_sap);
308 if (!sock_flag(sk, SOCK_ZAPPED) || addrlen != sizeof(*addr)) 294 if (unlikely(!sock_flag(sk, SOCK_ZAPPED) || addrlen != sizeof(*addr)))
309 goto out; 295 goto out;
310 rc = -EAFNOSUPPORT; 296 rc = -EAFNOSUPPORT;
311 if (addr->sllc_family != AF_LLC) 297 if (unlikely(addr->sllc_family != AF_LLC))
298 goto out;
299 rc = -ENODEV;
300 rtnl_lock();
301 llc->dev = dev_getbyhwaddr(addr->sllc_arphrd, addr->sllc_mac);
302 rtnl_unlock();
303 if (!llc->dev)
312 goto out; 304 goto out;
313 if (!addr->sllc_sap) { 305 if (!addr->sllc_sap) {
314 rc = -EUSERS; 306 rc = -EUSERS;
@@ -322,6 +314,7 @@ static int llc_ui_bind(struct socket *sock, struct sockaddr *uaddr, int addrlen)
322 rc = -EBUSY; /* some other network layer is using the sap */ 314 rc = -EBUSY; /* some other network layer is using the sap */
323 if (!sap) 315 if (!sap)
324 goto out; 316 goto out;
317 llc_sap_hold(sap);
325 } else { 318 } else {
326 struct llc_addr laddr, daddr; 319 struct llc_addr laddr, daddr;
327 struct sock *ask; 320 struct sock *ask;
@@ -338,7 +331,7 @@ static int llc_ui_bind(struct socket *sock, struct sockaddr *uaddr, int addrlen)
338 ask = llc_lookup_established(sap, &daddr, &laddr); 331 ask = llc_lookup_established(sap, &daddr, &laddr);
339 if (ask) { 332 if (ask) {
340 sock_put(ask); 333 sock_put(ask);
341 goto out; 334 goto out_put;
342 } 335 }
343 } 336 }
344 llc->laddr.lsap = addr->sllc_sap; 337 llc->laddr.lsap = addr->sllc_sap;
@@ -348,6 +341,8 @@ static int llc_ui_bind(struct socket *sock, struct sockaddr *uaddr, int addrlen)
348 llc_sap_add_socket(sap, sk); 341 llc_sap_add_socket(sap, sk);
349 sock_reset_flag(sk, SOCK_ZAPPED); 342 sock_reset_flag(sk, SOCK_ZAPPED);
350 rc = 0; 343 rc = 0;
344out_put:
345 llc_sap_put(sap);
351out: 346out:
352 return rc; 347 return rc;
353} 348}
@@ -369,7 +364,7 @@ static int llc_ui_shutdown(struct socket *sock, int how)
369 int rc = -ENOTCONN; 364 int rc = -ENOTCONN;
370 365
371 lock_sock(sk); 366 lock_sock(sk);
372 if (sk->sk_state != TCP_ESTABLISHED) 367 if (unlikely(sk->sk_state != TCP_ESTABLISHED))
373 goto out; 368 goto out;
374 rc = -EINVAL; 369 rc = -EINVAL;
375 if (how != 2) 370 if (how != 2)
@@ -404,14 +399,18 @@ static int llc_ui_connect(struct socket *sock, struct sockaddr *uaddr,
404 struct sock *sk = sock->sk; 399 struct sock *sk = sock->sk;
405 struct llc_sock *llc = llc_sk(sk); 400 struct llc_sock *llc = llc_sk(sk);
406 struct sockaddr_llc *addr = (struct sockaddr_llc *)uaddr; 401 struct sockaddr_llc *addr = (struct sockaddr_llc *)uaddr;
407 struct net_device *dev;
408 int rc = -EINVAL; 402 int rc = -EINVAL;
409 403
410 lock_sock(sk); 404 lock_sock(sk);
411 if (addrlen != sizeof(*addr)) 405 if (unlikely(addrlen != sizeof(*addr)))
412 goto out; 406 goto out;
413 rc = -EAFNOSUPPORT; 407 rc = -EAFNOSUPPORT;
414 if (addr->sllc_family != AF_LLC) 408 if (unlikely(addr->sllc_family != AF_LLC))
409 goto out;
410 if (unlikely(sk->sk_type != SOCK_STREAM))
411 goto out;
412 rc = -EALREADY;
413 if (unlikely(sock->state == SS_CONNECTING))
415 goto out; 414 goto out;
416 /* bind connection to sap if user hasn't done it. */ 415 /* bind connection to sap if user hasn't done it. */
417 if (sock_flag(sk, SOCK_ZAPPED)) { 416 if (sock_flag(sk, SOCK_ZAPPED)) {
@@ -419,19 +418,13 @@ static int llc_ui_connect(struct socket *sock, struct sockaddr *uaddr,
419 rc = llc_ui_autobind(sock, addr); 418 rc = llc_ui_autobind(sock, addr);
420 if (rc) 419 if (rc)
421 goto out; 420 goto out;
422 llc->daddr.lsap = addr->sllc_sap;
423 memcpy(llc->daddr.mac, addr->sllc_mac, IFHWADDRLEN);
424 } 421 }
425 dev = llc->dev; 422 llc->daddr.lsap = addr->sllc_sap;
426 if (sk->sk_type != SOCK_STREAM) 423 memcpy(llc->daddr.mac, addr->sllc_mac, IFHWADDRLEN);
427 goto out;
428 rc = -EALREADY;
429 if (sock->state == SS_CONNECTING)
430 goto out;
431 sock->state = SS_CONNECTING; 424 sock->state = SS_CONNECTING;
432 sk->sk_state = TCP_SYN_SENT; 425 sk->sk_state = TCP_SYN_SENT;
433 llc->link = llc_ui_next_link_no(llc->sap->laddr.lsap); 426 llc->link = llc_ui_next_link_no(llc->sap->laddr.lsap);
434 rc = llc_establish_connection(sk, dev->dev_addr, 427 rc = llc_establish_connection(sk, llc->dev->dev_addr,
435 addr->sllc_mac, addr->sllc_sap); 428 addr->sllc_mac, addr->sllc_sap);
436 if (rc) { 429 if (rc) {
437 dprintk("%s: llc_ui_send_conn failed :-(\n", __FUNCTION__); 430 dprintk("%s: llc_ui_send_conn failed :-(\n", __FUNCTION__);
@@ -439,12 +432,30 @@ static int llc_ui_connect(struct socket *sock, struct sockaddr *uaddr,
439 sk->sk_state = TCP_CLOSE; 432 sk->sk_state = TCP_CLOSE;
440 goto out; 433 goto out;
441 } 434 }
442 rc = llc_ui_wait_for_conn(sk, sk->sk_rcvtimeo); 435
443 if (rc) 436 if (sk->sk_state == TCP_SYN_SENT) {
444 dprintk("%s: llc_ui_wait_for_conn failed=%d\n", __FUNCTION__, rc); 437 const long timeo = sock_sndtimeo(sk, flags & O_NONBLOCK);
438
439 if (!timeo || !llc_ui_wait_for_conn(sk, timeo))
440 goto out;
441
442 rc = sock_intr_errno(timeo);
443 if (signal_pending(current))
444 goto out;
445 }
446
447 if (sk->sk_state == TCP_CLOSE)
448 goto sock_error;
449
450 sock->state = SS_CONNECTED;
451 rc = 0;
445out: 452out:
446 release_sock(sk); 453 release_sock(sk);
447 return rc; 454 return rc;
455sock_error:
456 rc = sock_error(sk) ? : -ECONNABORTED;
457 sock->state = SS_UNCONNECTED;
458 goto out;
448} 459}
449 460
450/** 461/**
@@ -461,10 +472,10 @@ static int llc_ui_listen(struct socket *sock, int backlog)
461 int rc = -EINVAL; 472 int rc = -EINVAL;
462 473
463 lock_sock(sk); 474 lock_sock(sk);
464 if (sock->state != SS_UNCONNECTED) 475 if (unlikely(sock->state != SS_UNCONNECTED))
465 goto out; 476 goto out;
466 rc = -EOPNOTSUPP; 477 rc = -EOPNOTSUPP;
467 if (sk->sk_type != SOCK_STREAM) 478 if (unlikely(sk->sk_type != SOCK_STREAM))
468 goto out; 479 goto out;
469 rc = -EAGAIN; 480 rc = -EAGAIN;
470 if (sock_flag(sk, SOCK_ZAPPED)) 481 if (sock_flag(sk, SOCK_ZAPPED))
@@ -483,20 +494,14 @@ out:
483 return rc; 494 return rc;
484} 495}
485 496
486static int llc_ui_wait_for_disc(struct sock *sk, int timeout) 497static int llc_ui_wait_for_disc(struct sock *sk, long timeout)
487{ 498{
488 DECLARE_WAITQUEUE(wait, current); 499 DEFINE_WAIT(wait);
489 int rc; 500 int rc = 0;
490 501
491 add_wait_queue_exclusive(sk->sk_sleep, &wait); 502 while (1) {
492 for (;;) { 503 prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
493 __set_current_state(TASK_INTERRUPTIBLE); 504 if (sk_wait_event(sk, &timeout, sk->sk_state == TCP_CLOSE))
494 rc = 0;
495 if (sk->sk_state != TCP_CLOSE) {
496 release_sock(sk);
497 timeout = schedule_timeout(timeout);
498 lock_sock(sk);
499 } else
500 break; 505 break;
501 rc = -ERESTARTSYS; 506 rc = -ERESTARTSYS;
502 if (signal_pending(current)) 507 if (signal_pending(current))
@@ -504,65 +509,40 @@ static int llc_ui_wait_for_disc(struct sock *sk, int timeout)
504 rc = -EAGAIN; 509 rc = -EAGAIN;
505 if (!timeout) 510 if (!timeout)
506 break; 511 break;
512 rc = 0;
507 } 513 }
508 __set_current_state(TASK_RUNNING); 514 finish_wait(sk->sk_sleep, &wait);
509 remove_wait_queue(sk->sk_sleep, &wait);
510 return rc; 515 return rc;
511} 516}
512 517
513static int llc_ui_wait_for_conn(struct sock *sk, int timeout) 518static int llc_ui_wait_for_conn(struct sock *sk, long timeout)
514{ 519{
515 DECLARE_WAITQUEUE(wait, current); 520 DEFINE_WAIT(wait);
516 int rc;
517 521
518 add_wait_queue_exclusive(sk->sk_sleep, &wait); 522 while (1) {
519 for (;;) { 523 prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
520 __set_current_state(TASK_INTERRUPTIBLE); 524 if (sk_wait_event(sk, &timeout, sk->sk_state != TCP_SYN_SENT))
521 rc = -EAGAIN;
522 if (sk->sk_state == TCP_CLOSE)
523 break;
524 rc = 0;
525 if (sk->sk_state != TCP_ESTABLISHED) {
526 release_sock(sk);
527 timeout = schedule_timeout(timeout);
528 lock_sock(sk);
529 } else
530 break; 525 break;
531 rc = -ERESTARTSYS; 526 if (signal_pending(current) || !timeout)
532 if (signal_pending(current))
533 break;
534 rc = -EAGAIN;
535 if (!timeout)
536 break; 527 break;
537 } 528 }
538 __set_current_state(TASK_RUNNING); 529 finish_wait(sk->sk_sleep, &wait);
539 remove_wait_queue(sk->sk_sleep, &wait); 530 return timeout;
540 return rc;
541} 531}
542 532
543static int llc_ui_wait_for_data(struct sock *sk, int timeout) 533static int llc_ui_wait_for_busy_core(struct sock *sk, long timeout)
544{ 534{
545 DECLARE_WAITQUEUE(wait, current); 535 DEFINE_WAIT(wait);
546 int rc = 0; 536 struct llc_sock *llc = llc_sk(sk);
537 int rc;
547 538
548 add_wait_queue_exclusive(sk->sk_sleep, &wait); 539 while (1) {
549 for (;;) { 540 prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
550 __set_current_state(TASK_INTERRUPTIBLE);
551 if (sk->sk_shutdown & RCV_SHUTDOWN)
552 break;
553 /*
554 * Well, if we have backlog, try to process it now.
555 */
556 if (sk->sk_backlog.tail) {
557 release_sock(sk);
558 lock_sock(sk);
559 }
560 rc = 0; 541 rc = 0;
561 if (skb_queue_empty(&sk->sk_receive_queue)) { 542 if (sk_wait_event(sk, &timeout,
562 release_sock(sk); 543 (sk->sk_shutdown & RCV_SHUTDOWN) ||
563 timeout = schedule_timeout(timeout); 544 (!llc_data_accept_state(llc->state) &&
564 lock_sock(sk); 545 !llc->p_flag)))
565 } else
566 break; 546 break;
567 rc = -ERESTARTSYS; 547 rc = -ERESTARTSYS;
568 if (signal_pending(current)) 548 if (signal_pending(current))
@@ -571,40 +551,35 @@ static int llc_ui_wait_for_data(struct sock *sk, int timeout)
571 if (!timeout) 551 if (!timeout)
572 break; 552 break;
573 } 553 }
574 __set_current_state(TASK_RUNNING); 554 finish_wait(sk->sk_sleep, &wait);
575 remove_wait_queue(sk->sk_sleep, &wait);
576 return rc; 555 return rc;
577} 556}
578 557
579static int llc_ui_wait_for_busy_core(struct sock *sk, int timeout) 558static int llc_wait_data(struct sock *sk, long timeo)
580{ 559{
581 DECLARE_WAITQUEUE(wait, current);
582 struct llc_sock *llc = llc_sk(sk);
583 int rc; 560 int rc;
584 561
585 add_wait_queue_exclusive(sk->sk_sleep, &wait); 562 while (1) {
586 for (;;) { 563 /*
587 dprintk("%s: looping...\n", __FUNCTION__); 564 * POSIX 1003.1g mandates this order.
588 __set_current_state(TASK_INTERRUPTIBLE); 565 */
589 rc = -ENOTCONN; 566 if (sk->sk_err) {
590 if (sk->sk_shutdown & RCV_SHUTDOWN) 567 rc = sock_error(sk);
591 break; 568 break;
569 }
592 rc = 0; 570 rc = 0;
593 if (llc_data_accept_state(llc->state) || llc->p_flag) { 571 if (sk->sk_shutdown & RCV_SHUTDOWN)
594 release_sock(sk);
595 timeout = schedule_timeout(timeout);
596 lock_sock(sk);
597 } else
598 break; 572 break;
599 rc = -ERESTARTSYS; 573 rc = -EAGAIN;
574 if (!timeo)
575 break;
576 rc = sock_intr_errno(timeo);
600 if (signal_pending(current)) 577 if (signal_pending(current))
601 break; 578 break;
602 rc = -EAGAIN; 579 rc = 0;
603 if (!timeout) 580 if (sk_wait_data(sk, &timeo))
604 break; 581 break;
605 } 582 }
606 __set_current_state(TASK_RUNNING);
607 remove_wait_queue(sk->sk_sleep, &wait);
608 return rc; 583 return rc;
609} 584}
610 585
@@ -627,15 +602,18 @@ static int llc_ui_accept(struct socket *sock, struct socket *newsock, int flags)
627 dprintk("%s: accepting on %02X\n", __FUNCTION__, 602 dprintk("%s: accepting on %02X\n", __FUNCTION__,
628 llc_sk(sk)->laddr.lsap); 603 llc_sk(sk)->laddr.lsap);
629 lock_sock(sk); 604 lock_sock(sk);
630 if (sk->sk_type != SOCK_STREAM) 605 if (unlikely(sk->sk_type != SOCK_STREAM))
631 goto out; 606 goto out;
632 rc = -EINVAL; 607 rc = -EINVAL;
633 if (sock->state != SS_UNCONNECTED || sk->sk_state != TCP_LISTEN) 608 if (unlikely(sock->state != SS_UNCONNECTED ||
609 sk->sk_state != TCP_LISTEN))
634 goto out; 610 goto out;
635 /* wait for a connection to arrive. */ 611 /* wait for a connection to arrive. */
636 rc = llc_ui_wait_for_data(sk, sk->sk_rcvtimeo); 612 if (skb_queue_empty(&sk->sk_receive_queue)) {
637 if (rc) 613 rc = llc_wait_data(sk, sk->sk_rcvtimeo);
638 goto out; 614 if (rc)
615 goto out;
616 }
639 dprintk("%s: got a new connection on %02X\n", __FUNCTION__, 617 dprintk("%s: got a new connection on %02X\n", __FUNCTION__,
640 llc_sk(sk)->laddr.lsap); 618 llc_sk(sk)->laddr.lsap);
641 skb = skb_dequeue(&sk->sk_receive_queue); 619 skb = skb_dequeue(&sk->sk_receive_queue);
@@ -657,7 +635,6 @@ static int llc_ui_accept(struct socket *sock, struct socket *newsock, int flags)
657 /* put original socket back into a clean listen state. */ 635 /* put original socket back into a clean listen state. */
658 sk->sk_state = TCP_LISTEN; 636 sk->sk_state = TCP_LISTEN;
659 sk->sk_ack_backlog--; 637 sk->sk_ack_backlog--;
660 skb->sk = NULL;
661 dprintk("%s: ok success on %02X, client on %02X\n", __FUNCTION__, 638 dprintk("%s: ok success on %02X, client on %02X\n", __FUNCTION__,
662 llc_sk(sk)->addr.sllc_sap, newllc->daddr.lsap); 639 llc_sk(sk)->addr.sllc_sap, newllc->daddr.lsap);
663frees: 640frees:
@@ -671,56 +648,167 @@ out:
671 * llc_ui_recvmsg - copy received data to the socket user. 648 * llc_ui_recvmsg - copy received data to the socket user.
672 * @sock: Socket to copy data from. 649 * @sock: Socket to copy data from.
673 * @msg: Various user space related information. 650 * @msg: Various user space related information.
674 * @size: Size of user buffer. 651 * @len: Size of user buffer.
675 * @flags: User specified flags. 652 * @flags: User specified flags.
676 * 653 *
677 * Copy received data to the socket user. 654 * Copy received data to the socket user.
678 * Returns non-negative upon success, negative otherwise. 655 * Returns non-negative upon success, negative otherwise.
679 */ 656 */
680static int llc_ui_recvmsg(struct kiocb *iocb, struct socket *sock, 657static int llc_ui_recvmsg(struct kiocb *iocb, struct socket *sock,
681 struct msghdr *msg, size_t size, int flags) 658 struct msghdr *msg, size_t len, int flags)
682{ 659{
683 struct sock *sk = sock->sk;
684 struct sockaddr_llc *uaddr = (struct sockaddr_llc *)msg->msg_name; 660 struct sockaddr_llc *uaddr = (struct sockaddr_llc *)msg->msg_name;
685 struct sk_buff *skb; 661 const int nonblock = flags & MSG_DONTWAIT;
662 struct sk_buff *skb = NULL;
663 struct sock *sk = sock->sk;
664 struct llc_sock *llc = llc_sk(sk);
686 size_t copied = 0; 665 size_t copied = 0;
687 int rc = -ENOMEM, timeout; 666 u32 peek_seq = 0;
688 int noblock = flags & MSG_DONTWAIT; 667 u32 *seq;
668 unsigned long used;
669 int target; /* Read at least this many bytes */
670 long timeo;
689 671
690 dprintk("%s: receiving in %02X from %02X\n", __FUNCTION__,
691 llc_sk(sk)->laddr.lsap, llc_sk(sk)->daddr.lsap);
692 lock_sock(sk); 672 lock_sock(sk);
693 timeout = sock_rcvtimeo(sk, noblock); 673 copied = -ENOTCONN;
694 rc = llc_ui_wait_for_data(sk, timeout); 674 if (sk->sk_state == TCP_LISTEN)
695 if (rc) {
696 dprintk("%s: llc_ui_wait_for_data failed recv "
697 "in %02X from %02X\n", __FUNCTION__,
698 llc_sk(sk)->laddr.lsap, llc_sk(sk)->daddr.lsap);
699 goto out; 675 goto out;
700 } 676
701 skb = skb_dequeue(&sk->sk_receive_queue); 677 timeo = sock_rcvtimeo(sk, nonblock);
702 if (!skb) /* shutdown */ 678
703 goto out; 679 seq = &llc->copied_seq;
704 copied = skb->len; 680 if (flags & MSG_PEEK) {
705 if (copied > size) 681 peek_seq = llc->copied_seq;
706 copied = size; 682 seq = &peek_seq;
707 rc = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied); 683 }
708 if (rc) 684
709 goto dgram_free; 685 target = sock_rcvlowat(sk, flags & MSG_WAITALL, len);
710 if (skb->len > copied) { 686 copied = 0;
711 skb_pull(skb, copied); 687
712 skb_queue_head(&sk->sk_receive_queue, skb); 688 do {
713 } 689 u32 offset;
714 if (uaddr) 690
715 memcpy(uaddr, llc_ui_skb_cb(skb), sizeof(*uaddr)); 691 /*
716 msg->msg_namelen = sizeof(*uaddr); 692 * We need to check signals first, to get correct SIGURG
717 if (!skb->next) { 693 * handling. FIXME: Need to check this doesn't impact 1003.1g
718dgram_free: 694 * and move it down to the bottom of the loop
719 kfree_skb(skb); 695 */
720 } 696 if (signal_pending(current)) {
697 if (copied)
698 break;
699 copied = timeo ? sock_intr_errno(timeo) : -EAGAIN;
700 break;
701 }
702
703 /* Next get a buffer. */
704
705 skb = skb_peek(&sk->sk_receive_queue);
706 if (skb) {
707 offset = *seq;
708 goto found_ok_skb;
709 }
710 /* Well, if we have backlog, try to process it now yet. */
711
712 if (copied >= target && !sk->sk_backlog.tail)
713 break;
714
715 if (copied) {
716 if (sk->sk_err ||
717 sk->sk_state == TCP_CLOSE ||
718 (sk->sk_shutdown & RCV_SHUTDOWN) ||
719 !timeo ||
720 (flags & MSG_PEEK))
721 break;
722 } else {
723 if (sock_flag(sk, SOCK_DONE))
724 break;
725
726 if (sk->sk_err) {
727 copied = sock_error(sk);
728 break;
729 }
730 if (sk->sk_shutdown & RCV_SHUTDOWN)
731 break;
732
733 if (sk->sk_state == TCP_CLOSE) {
734 if (!sock_flag(sk, SOCK_DONE)) {
735 /*
736 * This occurs when user tries to read
737 * from never connected socket.
738 */
739 copied = -ENOTCONN;
740 break;
741 }
742 break;
743 }
744 if (!timeo) {
745 copied = -EAGAIN;
746 break;
747 }
748 }
749
750 if (copied >= target) { /* Do not sleep, just process backlog. */
751 release_sock(sk);
752 lock_sock(sk);
753 } else
754 sk_wait_data(sk, &timeo);
755
756 if ((flags & MSG_PEEK) && peek_seq != llc->copied_seq) {
757 if (net_ratelimit())
758 printk(KERN_DEBUG "LLC(%s:%d): Application "
759 "bug, race in MSG_PEEK.\n",
760 current->comm, current->pid);
761 peek_seq = llc->copied_seq;
762 }
763 continue;
764 found_ok_skb:
765 /* Ok so how much can we use? */
766 used = skb->len - offset;
767 if (len < used)
768 used = len;
769
770 if (!(flags & MSG_TRUNC)) {
771 int rc = skb_copy_datagram_iovec(skb, offset,
772 msg->msg_iov, used);
773 if (rc) {
774 /* Exception. Bailout! */
775 if (!copied)
776 copied = -EFAULT;
777 break;
778 }
779 }
780
781 *seq += used;
782 copied += used;
783 len -= used;
784
785 if (used + offset < skb->len)
786 continue;
787
788 if (!(flags & MSG_PEEK)) {
789 sk_eat_skb(sk, skb);
790 *seq = 0;
791 }
792 } while (len > 0);
793
794 /*
795 * According to UNIX98, msg_name/msg_namelen are ignored
796 * on connected socket. -ANK
797 * But... af_llc still doesn't have separate sets of methods for
798 * SOCK_DGRAM and SOCK_STREAM :-( So we have to do this test, will
799 * eventually fix this tho :-) -acme
800 */
801 if (sk->sk_type == SOCK_DGRAM)
802 goto copy_uaddr;
721out: 803out:
722 release_sock(sk); 804 release_sock(sk);
723 return rc ? : copied; 805 return copied;
806copy_uaddr:
807 if (uaddr != NULL && skb != NULL) {
808 memcpy(uaddr, llc_ui_skb_cb(skb), sizeof(*uaddr));
809 msg->msg_namelen = sizeof(*uaddr);
810 }
811 goto out;
724} 812}
725 813
726/** 814/**
@@ -740,7 +828,6 @@ static int llc_ui_sendmsg(struct kiocb *iocb, struct socket *sock,
740 struct sockaddr_llc *addr = (struct sockaddr_llc *)msg->msg_name; 828 struct sockaddr_llc *addr = (struct sockaddr_llc *)msg->msg_name;
741 int flags = msg->msg_flags; 829 int flags = msg->msg_flags;
742 int noblock = flags & MSG_DONTWAIT; 830 int noblock = flags & MSG_DONTWAIT;
743 struct net_device *dev;
744 struct sk_buff *skb; 831 struct sk_buff *skb;
745 size_t size = 0; 832 size_t size = 0;
746 int rc = -EINVAL, copied = 0, hdrlen; 833 int rc = -EINVAL, copied = 0, hdrlen;
@@ -763,19 +850,17 @@ static int llc_ui_sendmsg(struct kiocb *iocb, struct socket *sock,
763 if (rc) 850 if (rc)
764 goto release; 851 goto release;
765 } 852 }
766 dev = llc->dev; 853 hdrlen = llc->dev->hard_header_len + llc_ui_header_len(sk, addr);
767 hdrlen = dev->hard_header_len + llc_ui_header_len(sk, addr);
768 size = hdrlen + len; 854 size = hdrlen + len;
769 if (size > dev->mtu) 855 if (size > llc->dev->mtu)
770 size = dev->mtu; 856 size = llc->dev->mtu;
771 copied = size - hdrlen; 857 copied = size - hdrlen;
772 release_sock(sk); 858 release_sock(sk);
773 skb = sock_alloc_send_skb(sk, size, noblock, &rc); 859 skb = sock_alloc_send_skb(sk, size, noblock, &rc);
774 lock_sock(sk); 860 lock_sock(sk);
775 if (!skb) 861 if (!skb)
776 goto release; 862 goto release;
777 skb->sk = sk; 863 skb->dev = llc->dev;
778 skb->dev = dev;
779 skb->protocol = llc_proto_type(addr->sllc_arphrd); 864 skb->protocol = llc_proto_type(addr->sllc_arphrd);
780 skb_reserve(skb, hdrlen); 865 skb_reserve(skb, hdrlen);
781 rc = memcpy_fromiovec(skb_put(skb, copied), msg->msg_iov, copied); 866 rc = memcpy_fromiovec(skb_put(skb, copied), msg->msg_iov, copied);
@@ -800,15 +885,13 @@ static int llc_ui_sendmsg(struct kiocb *iocb, struct socket *sock,
800 if (!(sk->sk_type == SOCK_STREAM && !addr->sllc_ua)) 885 if (!(sk->sk_type == SOCK_STREAM && !addr->sllc_ua))
801 goto out; 886 goto out;
802 rc = llc_ui_send_data(sk, skb, noblock); 887 rc = llc_ui_send_data(sk, skb, noblock);
803 if (rc)
804 dprintk("%s: llc_ui_send_data failed: %d\n", __FUNCTION__, rc);
805out: 888out:
806 if (rc) 889 if (rc) {
807 kfree_skb(skb); 890 kfree_skb(skb);
808release: 891release:
809 if (rc)
810 dprintk("%s: failed sending from %02X to %02X: %d\n", 892 dprintk("%s: failed sending from %02X to %02X: %d\n",
811 __FUNCTION__, llc->laddr.lsap, llc->daddr.lsap, rc); 893 __FUNCTION__, llc->laddr.lsap, llc->daddr.lsap, rc);
894 }
812 release_sock(sk); 895 release_sock(sk);
813 return rc ? : copied; 896 return rc ? : copied;
814} 897}
@@ -895,7 +978,7 @@ static int llc_ui_setsockopt(struct socket *sock, int level, int optname,
895 int rc = -EINVAL, opt; 978 int rc = -EINVAL, opt;
896 979
897 lock_sock(sk); 980 lock_sock(sk);
898 if (level != SOL_LLC || optlen != sizeof(int)) 981 if (unlikely(level != SOL_LLC || optlen != sizeof(int)))
899 goto out; 982 goto out;
900 rc = get_user(opt, (int __user *)optval); 983 rc = get_user(opt, (int __user *)optval);
901 if (rc) 984 if (rc)
@@ -915,22 +998,22 @@ static int llc_ui_setsockopt(struct socket *sock, int level, int optname,
915 case LLC_OPT_ACK_TMR_EXP: 998 case LLC_OPT_ACK_TMR_EXP:
916 if (opt > LLC_OPT_MAX_ACK_TMR_EXP) 999 if (opt > LLC_OPT_MAX_ACK_TMR_EXP)
917 goto out; 1000 goto out;
918 llc->ack_timer.expire = opt; 1001 llc->ack_timer.expire = opt * HZ;
919 break; 1002 break;
920 case LLC_OPT_P_TMR_EXP: 1003 case LLC_OPT_P_TMR_EXP:
921 if (opt > LLC_OPT_MAX_P_TMR_EXP) 1004 if (opt > LLC_OPT_MAX_P_TMR_EXP)
922 goto out; 1005 goto out;
923 llc->pf_cycle_timer.expire = opt; 1006 llc->pf_cycle_timer.expire = opt * HZ;
924 break; 1007 break;
925 case LLC_OPT_REJ_TMR_EXP: 1008 case LLC_OPT_REJ_TMR_EXP:
926 if (opt > LLC_OPT_MAX_REJ_TMR_EXP) 1009 if (opt > LLC_OPT_MAX_REJ_TMR_EXP)
927 goto out; 1010 goto out;
928 llc->rej_sent_timer.expire = opt; 1011 llc->rej_sent_timer.expire = opt * HZ;
929 break; 1012 break;
930 case LLC_OPT_BUSY_TMR_EXP: 1013 case LLC_OPT_BUSY_TMR_EXP:
931 if (opt > LLC_OPT_MAX_BUSY_TMR_EXP) 1014 if (opt > LLC_OPT_MAX_BUSY_TMR_EXP)
932 goto out; 1015 goto out;
933 llc->busy_state_timer.expire = opt; 1016 llc->busy_state_timer.expire = opt * HZ;
934 break; 1017 break;
935 case LLC_OPT_TX_WIN: 1018 case LLC_OPT_TX_WIN:
936 if (opt > LLC_OPT_MAX_WIN) 1019 if (opt > LLC_OPT_MAX_WIN)
@@ -970,7 +1053,7 @@ static int llc_ui_getsockopt(struct socket *sock, int level, int optname,
970 int val = 0, len = 0, rc = -EINVAL; 1053 int val = 0, len = 0, rc = -EINVAL;
971 1054
972 lock_sock(sk); 1055 lock_sock(sk);
973 if (level != SOL_LLC) 1056 if (unlikely(level != SOL_LLC))
974 goto out; 1057 goto out;
975 rc = get_user(len, optlen); 1058 rc = get_user(len, optlen);
976 if (rc) 1059 if (rc)
@@ -980,17 +1063,17 @@ static int llc_ui_getsockopt(struct socket *sock, int level, int optname,
980 goto out; 1063 goto out;
981 switch (optname) { 1064 switch (optname) {
982 case LLC_OPT_RETRY: 1065 case LLC_OPT_RETRY:
983 val = llc->n2; break; 1066 val = llc->n2; break;
984 case LLC_OPT_SIZE: 1067 case LLC_OPT_SIZE:
985 val = llc->n1; break; 1068 val = llc->n1; break;
986 case LLC_OPT_ACK_TMR_EXP: 1069 case LLC_OPT_ACK_TMR_EXP:
987 val = llc->ack_timer.expire; break; 1070 val = llc->ack_timer.expire / HZ; break;
988 case LLC_OPT_P_TMR_EXP: 1071 case LLC_OPT_P_TMR_EXP:
989 val = llc->pf_cycle_timer.expire; break; 1072 val = llc->pf_cycle_timer.expire / HZ; break;
990 case LLC_OPT_REJ_TMR_EXP: 1073 case LLC_OPT_REJ_TMR_EXP:
991 val = llc->rej_sent_timer.expire; break; 1074 val = llc->rej_sent_timer.expire / HZ; break;
992 case LLC_OPT_BUSY_TMR_EXP: 1075 case LLC_OPT_BUSY_TMR_EXP:
993 val = llc->busy_state_timer.expire; break; 1076 val = llc->busy_state_timer.expire / HZ; break;
994 case LLC_OPT_TX_WIN: 1077 case LLC_OPT_TX_WIN:
995 val = llc->k; break; 1078 val = llc->k; break;
996 case LLC_OPT_RX_WIN: 1079 case LLC_OPT_RX_WIN:
@@ -1034,8 +1117,12 @@ static struct proto_ops llc_ui_ops = {
1034 .sendpage = sock_no_sendpage, 1117 .sendpage = sock_no_sendpage,
1035}; 1118};
1036 1119
1037extern void llc_sap_handler(struct llc_sap *sap, struct sk_buff *skb); 1120static char llc_proc_err_msg[] __initdata =
1038extern void llc_conn_handler(struct llc_sap *sap, struct sk_buff *skb); 1121 KERN_CRIT "LLC: Unable to register the proc_fs entries\n";
1122static char llc_sysctl_err_msg[] __initdata =
1123 KERN_CRIT "LLC: Unable to register the sysctl entries\n";
1124static char llc_sock_err_msg[] __initdata =
1125 KERN_CRIT "LLC: Unable to register the network family\n";
1039 1126
1040static int __init llc2_init(void) 1127static int __init llc2_init(void)
1041{ 1128{
@@ -1048,13 +1135,28 @@ static int __init llc2_init(void)
1048 llc_station_init(); 1135 llc_station_init();
1049 llc_ui_sap_last_autoport = LLC_SAP_DYN_START; 1136 llc_ui_sap_last_autoport = LLC_SAP_DYN_START;
1050 rc = llc_proc_init(); 1137 rc = llc_proc_init();
1051 if (rc != 0) 1138 if (rc != 0) {
1139 printk(llc_proc_err_msg);
1052 goto out_unregister_llc_proto; 1140 goto out_unregister_llc_proto;
1053 sock_register(&llc_ui_family_ops); 1141 }
1142 rc = llc_sysctl_init();
1143 if (rc) {
1144 printk(llc_sysctl_err_msg);
1145 goto out_proc;
1146 }
1147 rc = sock_register(&llc_ui_family_ops);
1148 if (rc) {
1149 printk(llc_sock_err_msg);
1150 goto out_sysctl;
1151 }
1054 llc_add_pack(LLC_DEST_SAP, llc_sap_handler); 1152 llc_add_pack(LLC_DEST_SAP, llc_sap_handler);
1055 llc_add_pack(LLC_DEST_CONN, llc_conn_handler); 1153 llc_add_pack(LLC_DEST_CONN, llc_conn_handler);
1056out: 1154out:
1057 return rc; 1155 return rc;
1156out_sysctl:
1157 llc_sysctl_exit();
1158out_proc:
1159 llc_proc_exit();
1058out_unregister_llc_proto: 1160out_unregister_llc_proto:
1059 proto_unregister(&llc_proto); 1161 proto_unregister(&llc_proto);
1060 goto out; 1162 goto out;
@@ -1067,6 +1169,7 @@ static void __exit llc2_exit(void)
1067 llc_remove_pack(LLC_DEST_CONN); 1169 llc_remove_pack(LLC_DEST_CONN);
1068 sock_unregister(PF_LLC); 1170 sock_unregister(PF_LLC);
1069 llc_proc_exit(); 1171 llc_proc_exit();
1172 llc_sysctl_exit();
1070 proto_unregister(&llc_proto); 1173 proto_unregister(&llc_proto);
1071} 1174}
1072 1175
diff --git a/net/llc/llc_c_ac.c b/net/llc/llc_c_ac.c
index b218be4c10ec..b0bcfb1f12dd 100644
--- a/net/llc/llc_c_ac.c
+++ b/net/llc/llc_c_ac.c
@@ -60,23 +60,10 @@ int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb)
60 60
61int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb) 61int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb)
62{ 62{
63 int rc = -ENOTCONN; 63 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
64 u8 dsap;
65 struct llc_sap *sap;
66
67 llc_pdu_decode_dsap(skb, &dsap);
68 sap = llc_sap_find(dsap);
69 if (sap) {
70 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
71 struct llc_sock *llc = llc_sk(sk);
72 64
73 llc_pdu_decode_sa(skb, llc->daddr.mac); 65 ev->ind_prim = LLC_CONN_PRIM;
74 llc_pdu_decode_da(skb, llc->laddr.mac); 66 return 0;
75 llc->dev = skb->dev;
76 ev->ind_prim = LLC_CONN_PRIM;
77 rc = 0;
78 }
79 return rc;
80} 67}
81 68
82int llc_conn_ac_conn_confirm(struct sock *sk, struct sk_buff *skb) 69int llc_conn_ac_conn_confirm(struct sock *sk, struct sk_buff *skb)
@@ -120,10 +107,8 @@ int llc_conn_ac_disc_ind(struct sock *sk, struct sk_buff *skb)
120 reason = LLC_DISC_REASON_RX_DISC_CMD_PDU; 107 reason = LLC_DISC_REASON_RX_DISC_CMD_PDU;
121 } else if (ev->type == LLC_CONN_EV_TYPE_ACK_TMR) 108 } else if (ev->type == LLC_CONN_EV_TYPE_ACK_TMR)
122 reason = LLC_DISC_REASON_ACK_TMR_EXP; 109 reason = LLC_DISC_REASON_ACK_TMR_EXP;
123 else { 110 else
124 reason = 0;
125 rc = -EINVAL; 111 rc = -EINVAL;
126 }
127 if (!rc) { 112 if (!rc) {
128 ev->reason = reason; 113 ev->reason = reason;
129 ev->ind_prim = LLC_DISC_PRIM; 114 ev->ind_prim = LLC_DISC_PRIM;
@@ -160,9 +145,6 @@ int llc_conn_ac_rst_ind(struct sock *sk, struct sk_buff *skb)
160 LLC_U_PDU_CMD(pdu) == LLC_2_PDU_CMD_SABME) { 145 LLC_U_PDU_CMD(pdu) == LLC_2_PDU_CMD_SABME) {
161 reason = LLC_RESET_REASON_REMOTE; 146 reason = LLC_RESET_REASON_REMOTE;
162 rc = 0; 147 rc = 0;
163 } else {
164 reason = 0;
165 rc = 1;
166 } 148 }
167 break; 149 break;
168 case LLC_CONN_EV_TYPE_ACK_TMR: 150 case LLC_CONN_EV_TYPE_ACK_TMR:
@@ -172,8 +154,7 @@ int llc_conn_ac_rst_ind(struct sock *sk, struct sk_buff *skb)
172 if (llc->retry_count > llc->n2) { 154 if (llc->retry_count > llc->n2) {
173 reason = LLC_RESET_REASON_LOCAL; 155 reason = LLC_RESET_REASON_LOCAL;
174 rc = 0; 156 rc = 0;
175 } else 157 }
176 rc = 1;
177 break; 158 break;
178 } 159 }
179 if (!rc) { 160 if (!rc) {
@@ -217,18 +198,17 @@ int llc_conn_ac_stop_rej_tmr_if_data_flag_eq_2(struct sock *sk,
217int llc_conn_ac_send_disc_cmd_p_set_x(struct sock *sk, struct sk_buff *skb) 198int llc_conn_ac_send_disc_cmd_p_set_x(struct sock *sk, struct sk_buff *skb)
218{ 199{
219 int rc = -ENOBUFS; 200 int rc = -ENOBUFS;
220 struct sk_buff *nskb = llc_alloc_frame(); 201 struct llc_sock *llc = llc_sk(sk);
202 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
221 203
222 if (nskb) { 204 if (nskb) {
223 struct llc_sock *llc = llc_sk(sk);
224 struct llc_sap *sap = llc->sap; 205 struct llc_sap *sap = llc->sap;
225 206
226 nskb->dev = llc->dev;
227 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, 207 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
228 llc->daddr.lsap, LLC_PDU_CMD); 208 llc->daddr.lsap, LLC_PDU_CMD);
229 llc_pdu_init_as_disc_cmd(nskb, 1); 209 llc_pdu_init_as_disc_cmd(nskb, 1);
230 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); 210 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
231 if (rc) 211 if (unlikely(rc))
232 goto free; 212 goto free;
233 llc_conn_send_pdu(sk, nskb); 213 llc_conn_send_pdu(sk, nskb);
234 llc_conn_ac_set_p_flag_1(sk, skb); 214 llc_conn_ac_set_p_flag_1(sk, skb);
@@ -243,20 +223,19 @@ free:
243int llc_conn_ac_send_dm_rsp_f_set_p(struct sock *sk, struct sk_buff *skb) 223int llc_conn_ac_send_dm_rsp_f_set_p(struct sock *sk, struct sk_buff *skb)
244{ 224{
245 int rc = -ENOBUFS; 225 int rc = -ENOBUFS;
246 struct sk_buff *nskb = llc_alloc_frame(); 226 struct llc_sock *llc = llc_sk(sk);
227 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
247 228
248 if (nskb) { 229 if (nskb) {
249 struct llc_sock *llc = llc_sk(sk);
250 struct llc_sap *sap = llc->sap; 230 struct llc_sap *sap = llc->sap;
251 u8 f_bit; 231 u8 f_bit;
252 232
253 nskb->dev = llc->dev;
254 llc_pdu_decode_pf_bit(skb, &f_bit); 233 llc_pdu_decode_pf_bit(skb, &f_bit);
255 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, 234 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
256 llc->daddr.lsap, LLC_PDU_RSP); 235 llc->daddr.lsap, LLC_PDU_RSP);
257 llc_pdu_init_as_dm_rsp(nskb, f_bit); 236 llc_pdu_init_as_dm_rsp(nskb, f_bit);
258 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); 237 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
259 if (rc) 238 if (unlikely(rc))
260 goto free; 239 goto free;
261 llc_conn_send_pdu(sk, nskb); 240 llc_conn_send_pdu(sk, nskb);
262 } 241 }
@@ -270,19 +249,17 @@ free:
270int llc_conn_ac_send_dm_rsp_f_set_1(struct sock *sk, struct sk_buff *skb) 249int llc_conn_ac_send_dm_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
271{ 250{
272 int rc = -ENOBUFS; 251 int rc = -ENOBUFS;
273 struct sk_buff *nskb = llc_alloc_frame(); 252 struct llc_sock *llc = llc_sk(sk);
253 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
274 254
275 if (nskb) { 255 if (nskb) {
276 struct llc_sock *llc = llc_sk(sk);
277 struct llc_sap *sap = llc->sap; 256 struct llc_sap *sap = llc->sap;
278 u8 f_bit = 1;
279 257
280 nskb->dev = llc->dev;
281 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, 258 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
282 llc->daddr.lsap, LLC_PDU_RSP); 259 llc->daddr.lsap, LLC_PDU_RSP);
283 llc_pdu_init_as_dm_rsp(nskb, f_bit); 260 llc_pdu_init_as_dm_rsp(nskb, 1);
284 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); 261 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
285 if (rc) 262 if (unlikely(rc))
286 goto free; 263 goto free;
287 llc_conn_send_pdu(sk, nskb); 264 llc_conn_send_pdu(sk, nskb);
288 } 265 }
@@ -306,17 +283,16 @@ int llc_conn_ac_send_frmr_rsp_f_set_x(struct sock *sk, struct sk_buff *skb)
306 llc_pdu_decode_pf_bit(skb, &f_bit); 283 llc_pdu_decode_pf_bit(skb, &f_bit);
307 else 284 else
308 f_bit = 0; 285 f_bit = 0;
309 nskb = llc_alloc_frame(); 286 nskb = llc_alloc_frame(sk, llc->dev);
310 if (nskb) { 287 if (nskb) {
311 struct llc_sap *sap = llc->sap; 288 struct llc_sap *sap = llc->sap;
312 289
313 nskb->dev = llc->dev;
314 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, 290 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
315 llc->daddr.lsap, LLC_PDU_RSP); 291 llc->daddr.lsap, LLC_PDU_RSP);
316 llc_pdu_init_as_frmr_rsp(nskb, pdu, f_bit, llc->vS, 292 llc_pdu_init_as_frmr_rsp(nskb, pdu, f_bit, llc->vS,
317 llc->vR, INCORRECT); 293 llc->vR, INCORRECT);
318 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); 294 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
319 if (rc) 295 if (unlikely(rc))
320 goto free; 296 goto free;
321 llc_conn_send_pdu(sk, nskb); 297 llc_conn_send_pdu(sk, nskb);
322 } 298 }
@@ -330,21 +306,19 @@ free:
330int llc_conn_ac_resend_frmr_rsp_f_set_0(struct sock *sk, struct sk_buff *skb) 306int llc_conn_ac_resend_frmr_rsp_f_set_0(struct sock *sk, struct sk_buff *skb)
331{ 307{
332 int rc = -ENOBUFS; 308 int rc = -ENOBUFS;
333 struct sk_buff *nskb = llc_alloc_frame(); 309 struct llc_sock *llc = llc_sk(sk);
310 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
334 311
335 if (nskb) { 312 if (nskb) {
336 u8 f_bit = 0;
337 struct llc_sock *llc = llc_sk(sk);
338 struct llc_sap *sap = llc->sap; 313 struct llc_sap *sap = llc->sap;
339 struct llc_pdu_sn *pdu = (struct llc_pdu_sn *)&llc->rx_pdu_hdr; 314 struct llc_pdu_sn *pdu = (struct llc_pdu_sn *)&llc->rx_pdu_hdr;
340 315
341 nskb->dev = llc->dev;
342 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, 316 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
343 llc->daddr.lsap, LLC_PDU_RSP); 317 llc->daddr.lsap, LLC_PDU_RSP);
344 llc_pdu_init_as_frmr_rsp(nskb, pdu, f_bit, llc->vS, 318 llc_pdu_init_as_frmr_rsp(nskb, pdu, 0, llc->vS,
345 llc->vR, INCORRECT); 319 llc->vR, INCORRECT);
346 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); 320 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
347 if (rc) 321 if (unlikely(rc))
348 goto free; 322 goto free;
349 llc_conn_send_pdu(sk, nskb); 323 llc_conn_send_pdu(sk, nskb);
350 } 324 }
@@ -360,21 +334,20 @@ int llc_conn_ac_resend_frmr_rsp_f_set_p(struct sock *sk, struct sk_buff *skb)
360 u8 f_bit; 334 u8 f_bit;
361 int rc = -ENOBUFS; 335 int rc = -ENOBUFS;
362 struct sk_buff *nskb; 336 struct sk_buff *nskb;
337 struct llc_sock *llc = llc_sk(sk);
363 338
364 llc_pdu_decode_pf_bit(skb, &f_bit); 339 llc_pdu_decode_pf_bit(skb, &f_bit);
365 nskb = llc_alloc_frame(); 340 nskb = llc_alloc_frame(sk, llc->dev);
366 if (nskb) { 341 if (nskb) {
367 struct llc_sock *llc = llc_sk(sk);
368 struct llc_sap *sap = llc->sap; 342 struct llc_sap *sap = llc->sap;
369 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); 343 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
370 344
371 nskb->dev = llc->dev;
372 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, 345 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
373 llc->daddr.lsap, LLC_PDU_RSP); 346 llc->daddr.lsap, LLC_PDU_RSP);
374 llc_pdu_init_as_frmr_rsp(nskb, pdu, f_bit, llc->vS, 347 llc_pdu_init_as_frmr_rsp(nskb, pdu, f_bit, llc->vS,
375 llc->vR, INCORRECT); 348 llc->vR, INCORRECT);
376 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); 349 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
377 if (rc) 350 if (unlikely(rc))
378 goto free; 351 goto free;
379 llc_conn_send_pdu(sk, nskb); 352 llc_conn_send_pdu(sk, nskb);
380 } 353 }
@@ -395,7 +368,7 @@ int llc_conn_ac_send_i_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
395 llc->daddr.lsap, LLC_PDU_CMD); 368 llc->daddr.lsap, LLC_PDU_CMD);
396 llc_pdu_init_as_i_cmd(skb, 1, llc->vS, llc->vR); 369 llc_pdu_init_as_i_cmd(skb, 1, llc->vS, llc->vR);
397 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac); 370 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
398 if (!rc) { 371 if (likely(!rc)) {
399 llc_conn_send_pdu(sk, skb); 372 llc_conn_send_pdu(sk, skb);
400 llc_conn_ac_inc_vs_by_1(sk, skb); 373 llc_conn_ac_inc_vs_by_1(sk, skb);
401 } 374 }
@@ -412,7 +385,7 @@ static int llc_conn_ac_send_i_cmd_p_set_0(struct sock *sk, struct sk_buff *skb)
412 llc->daddr.lsap, LLC_PDU_CMD); 385 llc->daddr.lsap, LLC_PDU_CMD);
413 llc_pdu_init_as_i_cmd(skb, 0, llc->vS, llc->vR); 386 llc_pdu_init_as_i_cmd(skb, 0, llc->vS, llc->vR);
414 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac); 387 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
415 if (!rc) { 388 if (likely(!rc)) {
416 llc_conn_send_pdu(sk, skb); 389 llc_conn_send_pdu(sk, skb);
417 llc_conn_ac_inc_vs_by_1(sk, skb); 390 llc_conn_ac_inc_vs_by_1(sk, skb);
418 } 391 }
@@ -429,7 +402,7 @@ int llc_conn_ac_send_i_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
429 llc->daddr.lsap, LLC_PDU_CMD); 402 llc->daddr.lsap, LLC_PDU_CMD);
430 llc_pdu_init_as_i_cmd(skb, 0, llc->vS, llc->vR); 403 llc_pdu_init_as_i_cmd(skb, 0, llc->vS, llc->vR);
431 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac); 404 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
432 if (!rc) { 405 if (likely(!rc)) {
433 llc_conn_send_pdu(sk, skb); 406 llc_conn_send_pdu(sk, skb);
434 llc_conn_ac_inc_vs_by_1(sk, skb); 407 llc_conn_ac_inc_vs_by_1(sk, skb);
435 } 408 }
@@ -451,18 +424,17 @@ int llc_conn_ac_resend_i_xxx_x_set_0_or_send_rr(struct sock *sk,
451 u8 nr; 424 u8 nr;
452 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); 425 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
453 int rc = -ENOBUFS; 426 int rc = -ENOBUFS;
454 struct sk_buff *nskb = llc_alloc_frame(); 427 struct llc_sock *llc = llc_sk(sk);
428 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
455 429
456 if (nskb) { 430 if (nskb) {
457 struct llc_sock *llc = llc_sk(sk);
458 struct llc_sap *sap = llc->sap; 431 struct llc_sap *sap = llc->sap;
459 432
460 nskb->dev = llc->dev;
461 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, 433 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
462 llc->daddr.lsap, LLC_PDU_RSP); 434 llc->daddr.lsap, LLC_PDU_RSP);
463 llc_pdu_init_as_rr_rsp(nskb, 0, llc->vR); 435 llc_pdu_init_as_rr_rsp(nskb, 0, llc->vR);
464 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); 436 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
465 if (!rc) 437 if (likely(!rc))
466 llc_conn_send_pdu(sk, nskb); 438 llc_conn_send_pdu(sk, nskb);
467 else 439 else
468 kfree_skb(skb); 440 kfree_skb(skb);
@@ -487,18 +459,17 @@ int llc_conn_ac_resend_i_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
487int llc_conn_ac_send_rej_cmd_p_set_1(struct sock *sk, struct sk_buff *skb) 459int llc_conn_ac_send_rej_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
488{ 460{
489 int rc = -ENOBUFS; 461 int rc = -ENOBUFS;
490 struct sk_buff *nskb = llc_alloc_frame(); 462 struct llc_sock *llc = llc_sk(sk);
463 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
491 464
492 if (nskb) { 465 if (nskb) {
493 struct llc_sock *llc = llc_sk(sk);
494 struct llc_sap *sap = llc->sap; 466 struct llc_sap *sap = llc->sap;
495 467
496 nskb->dev = llc->dev;
497 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, 468 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
498 llc->daddr.lsap, LLC_PDU_CMD); 469 llc->daddr.lsap, LLC_PDU_CMD);
499 llc_pdu_init_as_rej_cmd(nskb, 1, llc->vR); 470 llc_pdu_init_as_rej_cmd(nskb, 1, llc->vR);
500 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); 471 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
501 if (rc) 472 if (unlikely(rc))
502 goto free; 473 goto free;
503 llc_conn_send_pdu(sk, nskb); 474 llc_conn_send_pdu(sk, nskb);
504 } 475 }
@@ -512,19 +483,17 @@ free:
512int llc_conn_ac_send_rej_rsp_f_set_1(struct sock *sk, struct sk_buff *skb) 483int llc_conn_ac_send_rej_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
513{ 484{
514 int rc = -ENOBUFS; 485 int rc = -ENOBUFS;
515 struct sk_buff *nskb = llc_alloc_frame(); 486 struct llc_sock *llc = llc_sk(sk);
487 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
516 488
517 if (nskb) { 489 if (nskb) {
518 u8 f_bit = 1;
519 struct llc_sock *llc = llc_sk(sk);
520 struct llc_sap *sap = llc->sap; 490 struct llc_sap *sap = llc->sap;
521 491
522 nskb->dev = llc->dev;
523 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, 492 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
524 llc->daddr.lsap, LLC_PDU_RSP); 493 llc->daddr.lsap, LLC_PDU_RSP);
525 llc_pdu_init_as_rej_rsp(nskb, f_bit, llc->vR); 494 llc_pdu_init_as_rej_rsp(nskb, 1, llc->vR);
526 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); 495 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
527 if (rc) 496 if (unlikely(rc))
528 goto free; 497 goto free;
529 llc_conn_send_pdu(sk, nskb); 498 llc_conn_send_pdu(sk, nskb);
530 } 499 }
@@ -538,19 +507,17 @@ free:
538int llc_conn_ac_send_rej_xxx_x_set_0(struct sock *sk, struct sk_buff *skb) 507int llc_conn_ac_send_rej_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
539{ 508{
540 int rc = -ENOBUFS; 509 int rc = -ENOBUFS;
541 struct sk_buff *nskb = llc_alloc_frame(); 510 struct llc_sock *llc = llc_sk(sk);
511 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
542 512
543 if (nskb) { 513 if (nskb) {
544 struct llc_sock *llc = llc_sk(sk);
545 struct llc_sap *sap = llc->sap; 514 struct llc_sap *sap = llc->sap;
546 u8 f_bit = 0;
547 515
548 nskb->dev = llc->dev;
549 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, 516 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
550 llc->daddr.lsap, LLC_PDU_RSP); 517 llc->daddr.lsap, LLC_PDU_RSP);
551 llc_pdu_init_as_rej_rsp(nskb, f_bit, llc->vR); 518 llc_pdu_init_as_rej_rsp(nskb, 0, llc->vR);
552 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); 519 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
553 if (rc) 520 if (unlikely(rc))
554 goto free; 521 goto free;
555 llc_conn_send_pdu(sk, nskb); 522 llc_conn_send_pdu(sk, nskb);
556 } 523 }
@@ -564,18 +531,17 @@ free:
564int llc_conn_ac_send_rnr_cmd_p_set_1(struct sock *sk, struct sk_buff *skb) 531int llc_conn_ac_send_rnr_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
565{ 532{
566 int rc = -ENOBUFS; 533 int rc = -ENOBUFS;
567 struct sk_buff *nskb = llc_alloc_frame(); 534 struct llc_sock *llc = llc_sk(sk);
535 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
568 536
569 if (nskb) { 537 if (nskb) {
570 struct llc_sock *llc = llc_sk(sk);
571 struct llc_sap *sap = llc->sap; 538 struct llc_sap *sap = llc->sap;
572 539
573 nskb->dev = llc->dev;
574 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, 540 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
575 llc->daddr.lsap, LLC_PDU_CMD); 541 llc->daddr.lsap, LLC_PDU_CMD);
576 llc_pdu_init_as_rnr_cmd(nskb, 1, llc->vR); 542 llc_pdu_init_as_rnr_cmd(nskb, 1, llc->vR);
577 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); 543 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
578 if (rc) 544 if (unlikely(rc))
579 goto free; 545 goto free;
580 llc_conn_send_pdu(sk, nskb); 546 llc_conn_send_pdu(sk, nskb);
581 } 547 }
@@ -589,19 +555,17 @@ free:
589int llc_conn_ac_send_rnr_rsp_f_set_1(struct sock *sk, struct sk_buff *skb) 555int llc_conn_ac_send_rnr_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
590{ 556{
591 int rc = -ENOBUFS; 557 int rc = -ENOBUFS;
592 struct sk_buff *nskb = llc_alloc_frame(); 558 struct llc_sock *llc = llc_sk(sk);
559 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
593 560
594 if (nskb) { 561 if (nskb) {
595 struct llc_sock *llc = llc_sk(sk);
596 struct llc_sap *sap = llc->sap; 562 struct llc_sap *sap = llc->sap;
597 u8 f_bit = 1;
598 563
599 nskb->dev = llc->dev;
600 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, 564 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
601 llc->daddr.lsap, LLC_PDU_RSP); 565 llc->daddr.lsap, LLC_PDU_RSP);
602 llc_pdu_init_as_rnr_rsp(nskb, f_bit, llc->vR); 566 llc_pdu_init_as_rnr_rsp(nskb, 1, llc->vR);
603 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); 567 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
604 if (rc) 568 if (unlikely(rc))
605 goto free; 569 goto free;
606 llc_conn_send_pdu(sk, nskb); 570 llc_conn_send_pdu(sk, nskb);
607 } 571 }
@@ -615,19 +579,17 @@ free:
615int llc_conn_ac_send_rnr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb) 579int llc_conn_ac_send_rnr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
616{ 580{
617 int rc = -ENOBUFS; 581 int rc = -ENOBUFS;
618 struct sk_buff *nskb = llc_alloc_frame(); 582 struct llc_sock *llc = llc_sk(sk);
583 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
619 584
620 if (nskb) { 585 if (nskb) {
621 u8 f_bit = 0;
622 struct llc_sock *llc = llc_sk(sk);
623 struct llc_sap *sap = llc->sap; 586 struct llc_sap *sap = llc->sap;
624 587
625 nskb->dev = llc->dev;
626 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, 588 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
627 llc->daddr.lsap, LLC_PDU_RSP); 589 llc->daddr.lsap, LLC_PDU_RSP);
628 llc_pdu_init_as_rnr_rsp(nskb, f_bit, llc->vR); 590 llc_pdu_init_as_rnr_rsp(nskb, 0, llc->vR);
629 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); 591 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
630 if (rc) 592 if (unlikely(rc))
631 goto free; 593 goto free;
632 llc_conn_send_pdu(sk, nskb); 594 llc_conn_send_pdu(sk, nskb);
633 } 595 }
@@ -645,7 +607,7 @@ int llc_conn_ac_set_remote_busy(struct sock *sk, struct sk_buff *skb)
645 if (!llc->remote_busy_flag) { 607 if (!llc->remote_busy_flag) {
646 llc->remote_busy_flag = 1; 608 llc->remote_busy_flag = 1;
647 mod_timer(&llc->busy_state_timer.timer, 609 mod_timer(&llc->busy_state_timer.timer,
648 jiffies + llc->busy_state_timer.expire * HZ); 610 jiffies + llc->busy_state_timer.expire);
649 } 611 }
650 return 0; 612 return 0;
651} 613}
@@ -653,18 +615,17 @@ int llc_conn_ac_set_remote_busy(struct sock *sk, struct sk_buff *skb)
653int llc_conn_ac_opt_send_rnr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb) 615int llc_conn_ac_opt_send_rnr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
654{ 616{
655 int rc = -ENOBUFS; 617 int rc = -ENOBUFS;
656 struct sk_buff *nskb = llc_alloc_frame(); 618 struct llc_sock *llc = llc_sk(sk);
619 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
657 620
658 if (nskb) { 621 if (nskb) {
659 struct llc_sock *llc = llc_sk(sk);
660 struct llc_sap *sap = llc->sap; 622 struct llc_sap *sap = llc->sap;
661 623
662 nskb->dev = llc->dev;
663 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, 624 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
664 llc->daddr.lsap, LLC_PDU_RSP); 625 llc->daddr.lsap, LLC_PDU_RSP);
665 llc_pdu_init_as_rnr_rsp(nskb, 0, llc->vR); 626 llc_pdu_init_as_rnr_rsp(nskb, 0, llc->vR);
666 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); 627 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
667 if (rc) 628 if (unlikely(rc))
668 goto free; 629 goto free;
669 llc_conn_send_pdu(sk, nskb); 630 llc_conn_send_pdu(sk, nskb);
670 } 631 }
@@ -678,18 +639,17 @@ free:
678int llc_conn_ac_send_rr_cmd_p_set_1(struct sock *sk, struct sk_buff *skb) 639int llc_conn_ac_send_rr_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
679{ 640{
680 int rc = -ENOBUFS; 641 int rc = -ENOBUFS;
681 struct sk_buff *nskb = llc_alloc_frame(); 642 struct llc_sock *llc = llc_sk(sk);
643 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
682 644
683 if (nskb) { 645 if (nskb) {
684 struct llc_sock *llc = llc_sk(sk);
685 struct llc_sap *sap = llc->sap; 646 struct llc_sap *sap = llc->sap;
686 647
687 nskb->dev = llc->dev;
688 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, 648 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
689 llc->daddr.lsap, LLC_PDU_CMD); 649 llc->daddr.lsap, LLC_PDU_CMD);
690 llc_pdu_init_as_rr_cmd(nskb, 1, llc->vR); 650 llc_pdu_init_as_rr_cmd(nskb, 1, llc->vR);
691 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); 651 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
692 if (rc) 652 if (unlikely(rc))
693 goto free; 653 goto free;
694 llc_conn_send_pdu(sk, nskb); 654 llc_conn_send_pdu(sk, nskb);
695 } 655 }
@@ -703,19 +663,18 @@ free:
703int llc_conn_ac_send_rr_rsp_f_set_1(struct sock *sk, struct sk_buff *skb) 663int llc_conn_ac_send_rr_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
704{ 664{
705 int rc = -ENOBUFS; 665 int rc = -ENOBUFS;
706 struct sk_buff *nskb = llc_alloc_frame(); 666 struct llc_sock *llc = llc_sk(sk);
667 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
707 668
708 if (nskb) { 669 if (nskb) {
709 struct llc_sock *llc = llc_sk(sk);
710 struct llc_sap *sap = llc->sap; 670 struct llc_sap *sap = llc->sap;
711 u8 f_bit = 1; 671 u8 f_bit = 1;
712 672
713 nskb->dev = llc->dev;
714 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, 673 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
715 llc->daddr.lsap, LLC_PDU_RSP); 674 llc->daddr.lsap, LLC_PDU_RSP);
716 llc_pdu_init_as_rr_rsp(nskb, f_bit, llc->vR); 675 llc_pdu_init_as_rr_rsp(nskb, f_bit, llc->vR);
717 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); 676 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
718 if (rc) 677 if (unlikely(rc))
719 goto free; 678 goto free;
720 llc_conn_send_pdu(sk, nskb); 679 llc_conn_send_pdu(sk, nskb);
721 } 680 }
@@ -729,19 +688,17 @@ free:
729int llc_conn_ac_send_ack_rsp_f_set_1(struct sock *sk, struct sk_buff *skb) 688int llc_conn_ac_send_ack_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
730{ 689{
731 int rc = -ENOBUFS; 690 int rc = -ENOBUFS;
732 struct sk_buff *nskb = llc_alloc_frame(); 691 struct llc_sock *llc = llc_sk(sk);
692 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
733 693
734 if (nskb) { 694 if (nskb) {
735 struct llc_sock *llc = llc_sk(sk);
736 struct llc_sap *sap = llc->sap; 695 struct llc_sap *sap = llc->sap;
737 u8 f_bit = 1;
738 696
739 nskb->dev = llc->dev;
740 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, 697 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
741 llc->daddr.lsap, LLC_PDU_RSP); 698 llc->daddr.lsap, LLC_PDU_RSP);
742 llc_pdu_init_as_rr_rsp(nskb, f_bit, llc->vR); 699 llc_pdu_init_as_rr_rsp(nskb, 1, llc->vR);
743 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); 700 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
744 if (rc) 701 if (unlikely(rc))
745 goto free; 702 goto free;
746 llc_conn_send_pdu(sk, nskb); 703 llc_conn_send_pdu(sk, nskb);
747 } 704 }
@@ -755,18 +712,17 @@ free:
755int llc_conn_ac_send_rr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb) 712int llc_conn_ac_send_rr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
756{ 713{
757 int rc = -ENOBUFS; 714 int rc = -ENOBUFS;
758 struct sk_buff *nskb = llc_alloc_frame(); 715 struct llc_sock *llc = llc_sk(sk);
716 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
759 717
760 if (nskb) { 718 if (nskb) {
761 struct llc_sock *llc = llc_sk(sk);
762 struct llc_sap *sap = llc->sap; 719 struct llc_sap *sap = llc->sap;
763 720
764 nskb->dev = llc->dev;
765 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, 721 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
766 llc->daddr.lsap, LLC_PDU_RSP); 722 llc->daddr.lsap, LLC_PDU_RSP);
767 llc_pdu_init_as_rr_rsp(nskb, 0, llc->vR); 723 llc_pdu_init_as_rr_rsp(nskb, 0, llc->vR);
768 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); 724 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
769 if (rc) 725 if (unlikely(rc))
770 goto free; 726 goto free;
771 llc_conn_send_pdu(sk, nskb); 727 llc_conn_send_pdu(sk, nskb);
772 } 728 }
@@ -780,18 +736,17 @@ free:
780int llc_conn_ac_send_ack_xxx_x_set_0(struct sock *sk, struct sk_buff *skb) 736int llc_conn_ac_send_ack_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
781{ 737{
782 int rc = -ENOBUFS; 738 int rc = -ENOBUFS;
783 struct sk_buff *nskb = llc_alloc_frame(); 739 struct llc_sock *llc = llc_sk(sk);
740 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
784 741
785 if (nskb) { 742 if (nskb) {
786 struct llc_sock *llc = llc_sk(sk);
787 struct llc_sap *sap = llc->sap; 743 struct llc_sap *sap = llc->sap;
788 744
789 nskb->dev = llc->dev;
790 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, 745 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
791 llc->daddr.lsap, LLC_PDU_RSP); 746 llc->daddr.lsap, LLC_PDU_RSP);
792 llc_pdu_init_as_rr_rsp(nskb, 0, llc->vR); 747 llc_pdu_init_as_rr_rsp(nskb, 0, llc->vR);
793 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); 748 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
794 if (rc) 749 if (unlikely(rc))
795 goto free; 750 goto free;
796 llc_conn_send_pdu(sk, nskb); 751 llc_conn_send_pdu(sk, nskb);
797 } 752 }
@@ -815,8 +770,8 @@ void llc_conn_set_p_flag(struct sock *sk, u8 value)
815int llc_conn_ac_send_sabme_cmd_p_set_x(struct sock *sk, struct sk_buff *skb) 770int llc_conn_ac_send_sabme_cmd_p_set_x(struct sock *sk, struct sk_buff *skb)
816{ 771{
817 int rc = -ENOBUFS; 772 int rc = -ENOBUFS;
818 struct sk_buff *nskb = llc_alloc_frame();
819 struct llc_sock *llc = llc_sk(sk); 773 struct llc_sock *llc = llc_sk(sk);
774 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
820 775
821 if (nskb) { 776 if (nskb) {
822 struct llc_sap *sap = llc->sap; 777 struct llc_sap *sap = llc->sap;
@@ -824,12 +779,11 @@ int llc_conn_ac_send_sabme_cmd_p_set_x(struct sock *sk, struct sk_buff *skb)
824 779
825 if (llc->dev->flags & IFF_LOOPBACK) 780 if (llc->dev->flags & IFF_LOOPBACK)
826 dmac = llc->dev->dev_addr; 781 dmac = llc->dev->dev_addr;
827 nskb->dev = llc->dev;
828 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, 782 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
829 llc->daddr.lsap, LLC_PDU_CMD); 783 llc->daddr.lsap, LLC_PDU_CMD);
830 llc_pdu_init_as_sabme_cmd(nskb, 1); 784 llc_pdu_init_as_sabme_cmd(nskb, 1);
831 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, dmac); 785 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, dmac);
832 if (rc) 786 if (unlikely(rc))
833 goto free; 787 goto free;
834 llc_conn_send_pdu(sk, nskb); 788 llc_conn_send_pdu(sk, nskb);
835 llc_conn_set_p_flag(sk, 1); 789 llc_conn_set_p_flag(sk, 1);
@@ -845,11 +799,11 @@ int llc_conn_ac_send_ua_rsp_f_set_p(struct sock *sk, struct sk_buff *skb)
845{ 799{
846 u8 f_bit; 800 u8 f_bit;
847 int rc = -ENOBUFS; 801 int rc = -ENOBUFS;
848 struct sk_buff *nskb = llc_alloc_frame(); 802 struct llc_sock *llc = llc_sk(sk);
803 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
849 804
850 llc_pdu_decode_pf_bit(skb, &f_bit); 805 llc_pdu_decode_pf_bit(skb, &f_bit);
851 if (nskb) { 806 if (nskb) {
852 struct llc_sock *llc = llc_sk(sk);
853 struct llc_sap *sap = llc->sap; 807 struct llc_sap *sap = llc->sap;
854 808
855 nskb->dev = llc->dev; 809 nskb->dev = llc->dev;
@@ -857,7 +811,7 @@ int llc_conn_ac_send_ua_rsp_f_set_p(struct sock *sk, struct sk_buff *skb)
857 llc->daddr.lsap, LLC_PDU_RSP); 811 llc->daddr.lsap, LLC_PDU_RSP);
858 llc_pdu_init_as_ua_rsp(nskb, f_bit); 812 llc_pdu_init_as_ua_rsp(nskb, f_bit);
859 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); 813 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
860 if (rc) 814 if (unlikely(rc))
861 goto free; 815 goto free;
862 llc_conn_send_pdu(sk, nskb); 816 llc_conn_send_pdu(sk, nskb);
863 } 817 }
@@ -886,7 +840,7 @@ int llc_conn_ac_start_p_timer(struct sock *sk, struct sk_buff *skb)
886 840
887 llc_conn_set_p_flag(sk, 1); 841 llc_conn_set_p_flag(sk, 1);
888 mod_timer(&llc->pf_cycle_timer.timer, 842 mod_timer(&llc->pf_cycle_timer.timer,
889 jiffies + llc->pf_cycle_timer.expire * HZ); 843 jiffies + llc->pf_cycle_timer.expire);
890 return 0; 844 return 0;
891} 845}
892 846
@@ -957,7 +911,7 @@ static int llc_conn_ac_send_i_rsp_f_set_ackpf(struct sock *sk,
957 llc->daddr.lsap, LLC_PDU_RSP); 911 llc->daddr.lsap, LLC_PDU_RSP);
958 llc_pdu_init_as_i_cmd(skb, llc->ack_pf, llc->vS, llc->vR); 912 llc_pdu_init_as_i_cmd(skb, llc->ack_pf, llc->vS, llc->vR);
959 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac); 913 rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
960 if (!rc) { 914 if (likely(!rc)) {
961 llc_conn_send_pdu(sk, skb); 915 llc_conn_send_pdu(sk, skb);
962 llc_conn_ac_inc_vs_by_1(sk, skb); 916 llc_conn_ac_inc_vs_by_1(sk, skb);
963 } 917 }
@@ -1001,18 +955,17 @@ static int llc_conn_ac_send_rr_rsp_f_set_ackpf(struct sock *sk,
1001 struct sk_buff *skb) 955 struct sk_buff *skb)
1002{ 956{
1003 int rc = -ENOBUFS; 957 int rc = -ENOBUFS;
1004 struct sk_buff *nskb = llc_alloc_frame(); 958 struct llc_sock *llc = llc_sk(sk);
959 struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
1005 960
1006 if (nskb) { 961 if (nskb) {
1007 struct llc_sock *llc = llc_sk(sk);
1008 struct llc_sap *sap = llc->sap; 962 struct llc_sap *sap = llc->sap;
1009 963
1010 nskb->dev = llc->dev;
1011 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap, 964 llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
1012 llc->daddr.lsap, LLC_PDU_RSP); 965 llc->daddr.lsap, LLC_PDU_RSP);
1013 llc_pdu_init_as_rr_rsp(nskb, llc->ack_pf, llc->vR); 966 llc_pdu_init_as_rr_rsp(nskb, llc->ack_pf, llc->vR);
1014 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac); 967 rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
1015 if (rc) 968 if (unlikely(rc))
1016 goto free; 969 goto free;
1017 llc_conn_send_pdu(sk, nskb); 970 llc_conn_send_pdu(sk, nskb);
1018 } 971 }
@@ -1165,7 +1118,7 @@ int llc_conn_ac_start_ack_timer(struct sock *sk, struct sk_buff *skb)
1165{ 1118{
1166 struct llc_sock *llc = llc_sk(sk); 1119 struct llc_sock *llc = llc_sk(sk);
1167 1120
1168 mod_timer(&llc->ack_timer.timer, jiffies + llc->ack_timer.expire * HZ); 1121 mod_timer(&llc->ack_timer.timer, jiffies + llc->ack_timer.expire);
1169 return 0; 1122 return 0;
1170} 1123}
1171 1124
@@ -1174,7 +1127,7 @@ int llc_conn_ac_start_rej_timer(struct sock *sk, struct sk_buff *skb)
1174 struct llc_sock *llc = llc_sk(sk); 1127 struct llc_sock *llc = llc_sk(sk);
1175 1128
1176 mod_timer(&llc->rej_sent_timer.timer, 1129 mod_timer(&llc->rej_sent_timer.timer,
1177 jiffies + llc->rej_sent_timer.expire * HZ); 1130 jiffies + llc->rej_sent_timer.expire);
1178 return 0; 1131 return 0;
1179} 1132}
1180 1133
@@ -1185,7 +1138,7 @@ int llc_conn_ac_start_ack_tmr_if_not_running(struct sock *sk,
1185 1138
1186 if (!timer_pending(&llc->ack_timer.timer)) 1139 if (!timer_pending(&llc->ack_timer.timer))
1187 mod_timer(&llc->ack_timer.timer, 1140 mod_timer(&llc->ack_timer.timer,
1188 jiffies + llc->ack_timer.expire * HZ); 1141 jiffies + llc->ack_timer.expire);
1189 return 0; 1142 return 0;
1190} 1143}
1191 1144
@@ -1233,7 +1186,7 @@ int llc_conn_ac_upd_nr_received(struct sock *sk, struct sk_buff *skb)
1233 } 1186 }
1234 if (unacked) 1187 if (unacked)
1235 mod_timer(&llc->ack_timer.timer, 1188 mod_timer(&llc->ack_timer.timer,
1236 jiffies + llc->ack_timer.expire * HZ); 1189 jiffies + llc->ack_timer.expire);
1237 } else if (llc->failed_data_req) { 1190 } else if (llc->failed_data_req) {
1238 u8 f_bit; 1191 u8 f_bit;
1239 1192
@@ -1354,13 +1307,13 @@ int llc_conn_ac_set_vs_nr(struct sock *sk, struct sk_buff *skb)
1354 return 0; 1307 return 0;
1355} 1308}
1356 1309
1357int llc_conn_ac_inc_vs_by_1(struct sock *sk, struct sk_buff *skb) 1310static int llc_conn_ac_inc_vs_by_1(struct sock *sk, struct sk_buff *skb)
1358{ 1311{
1359 llc_sk(sk)->vS = (llc_sk(sk)->vS + 1) % 128; 1312 llc_sk(sk)->vS = (llc_sk(sk)->vS + 1) % 128;
1360 return 0; 1313 return 0;
1361} 1314}
1362 1315
1363void llc_conn_pf_cycle_tmr_cb(unsigned long timeout_data) 1316static void llc_conn_tmr_common_cb(unsigned long timeout_data, u8 type)
1364{ 1317{
1365 struct sock *sk = (struct sock *)timeout_data; 1318 struct sock *sk = (struct sock *)timeout_data;
1366 struct sk_buff *skb = alloc_skb(0, GFP_ATOMIC); 1319 struct sk_buff *skb = alloc_skb(0, GFP_ATOMIC);
@@ -1369,59 +1322,31 @@ void llc_conn_pf_cycle_tmr_cb(unsigned long timeout_data)
1369 if (skb) { 1322 if (skb) {
1370 struct llc_conn_state_ev *ev = llc_conn_ev(skb); 1323 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
1371 1324
1372 skb->sk = sk; 1325 skb_set_owner_r(skb, sk);
1373 ev->type = LLC_CONN_EV_TYPE_P_TMR; 1326 ev->type = type;
1374 llc_process_tmr_ev(sk, skb); 1327 llc_process_tmr_ev(sk, skb);
1375 } 1328 }
1376 bh_unlock_sock(sk); 1329 bh_unlock_sock(sk);
1377} 1330}
1378 1331
1379void llc_conn_busy_tmr_cb(unsigned long timeout_data) 1332void llc_conn_pf_cycle_tmr_cb(unsigned long timeout_data)
1380{ 1333{
1381 struct sock *sk = (struct sock *)timeout_data; 1334 llc_conn_tmr_common_cb(timeout_data, LLC_CONN_EV_TYPE_P_TMR);
1382 struct sk_buff *skb = alloc_skb(0, GFP_ATOMIC); 1335}
1383
1384 bh_lock_sock(sk);
1385 if (skb) {
1386 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
1387 1336
1388 skb->sk = sk; 1337void llc_conn_busy_tmr_cb(unsigned long timeout_data)
1389 ev->type = LLC_CONN_EV_TYPE_BUSY_TMR; 1338{
1390 llc_process_tmr_ev(sk, skb); 1339 llc_conn_tmr_common_cb(timeout_data, LLC_CONN_EV_TYPE_BUSY_TMR);
1391 }
1392 bh_unlock_sock(sk);
1393} 1340}
1394 1341
1395void llc_conn_ack_tmr_cb(unsigned long timeout_data) 1342void llc_conn_ack_tmr_cb(unsigned long timeout_data)
1396{ 1343{
1397 struct sock* sk = (struct sock *)timeout_data; 1344 llc_conn_tmr_common_cb(timeout_data, LLC_CONN_EV_TYPE_ACK_TMR);
1398 struct sk_buff *skb = alloc_skb(0, GFP_ATOMIC);
1399
1400 bh_lock_sock(sk);
1401 if (skb) {
1402 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
1403
1404 skb->sk = sk;
1405 ev->type = LLC_CONN_EV_TYPE_ACK_TMR;
1406 llc_process_tmr_ev(sk, skb);
1407 }
1408 bh_unlock_sock(sk);
1409} 1345}
1410 1346
1411void llc_conn_rej_tmr_cb(unsigned long timeout_data) 1347void llc_conn_rej_tmr_cb(unsigned long timeout_data)
1412{ 1348{
1413 struct sock *sk = (struct sock *)timeout_data; 1349 llc_conn_tmr_common_cb(timeout_data, LLC_CONN_EV_TYPE_REJ_TMR);
1414 struct sk_buff *skb = alloc_skb(0, GFP_ATOMIC);
1415
1416 bh_lock_sock(sk);
1417 if (skb) {
1418 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
1419
1420 skb->sk = sk;
1421 ev->type = LLC_CONN_EV_TYPE_REJ_TMR;
1422 llc_process_tmr_ev(sk, skb);
1423 }
1424 bh_unlock_sock(sk);
1425} 1350}
1426 1351
1427int llc_conn_ac_rst_vs(struct sock *sk, struct sk_buff *skb) 1352int llc_conn_ac_rst_vs(struct sock *sk, struct sk_buff *skb)
diff --git a/net/llc/llc_c_ev.c b/net/llc/llc_c_ev.c
index d5bdb53a348f..c5deda246614 100644
--- a/net/llc/llc_c_ev.c
+++ b/net/llc/llc_c_ev.c
@@ -37,6 +37,7 @@
37#include <net/llc_conn.h> 37#include <net/llc_conn.h>
38#include <net/llc_sap.h> 38#include <net/llc_sap.h>
39#include <net/sock.h> 39#include <net/sock.h>
40#include <net/llc_c_ac.h>
40#include <net/llc_c_ev.h> 41#include <net/llc_c_ev.h>
41#include <net/llc_pdu.h> 42#include <net/llc_pdu.h>
42 43
@@ -46,8 +47,6 @@
46#define dprintk(args...) 47#define dprintk(args...)
47#endif 48#endif
48 49
49extern u16 llc_circular_between(u8 a, u8 b, u8 c);
50
51/** 50/**
52 * llc_util_ns_inside_rx_window - check if sequence number is in rx window 51 * llc_util_ns_inside_rx_window - check if sequence number is in rx window
53 * @ns: sequence number of received pdu. 52 * @ns: sequence number of received pdu.
@@ -99,7 +98,7 @@ out:
99 98
100int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb) 99int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb)
101{ 100{
102 struct llc_conn_state_ev *ev = llc_conn_ev(skb); 101 const struct llc_conn_state_ev *ev = llc_conn_ev(skb);
103 102
104 return ev->prim == LLC_CONN_PRIM && 103 return ev->prim == LLC_CONN_PRIM &&
105 ev->prim_type == LLC_PRIM_TYPE_REQ ? 0 : 1; 104 ev->prim_type == LLC_PRIM_TYPE_REQ ? 0 : 1;
@@ -107,7 +106,7 @@ int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb)
107 106
108int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb) 107int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb)
109{ 108{
110 struct llc_conn_state_ev *ev = llc_conn_ev(skb); 109 const struct llc_conn_state_ev *ev = llc_conn_ev(skb);
111 110
112 return ev->prim == LLC_DATA_PRIM && 111 return ev->prim == LLC_DATA_PRIM &&
113 ev->prim_type == LLC_PRIM_TYPE_REQ ? 0 : 1; 112 ev->prim_type == LLC_PRIM_TYPE_REQ ? 0 : 1;
@@ -115,7 +114,7 @@ int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb)
115 114
116int llc_conn_ev_disc_req(struct sock *sk, struct sk_buff *skb) 115int llc_conn_ev_disc_req(struct sock *sk, struct sk_buff *skb)
117{ 116{
118 struct llc_conn_state_ev *ev = llc_conn_ev(skb); 117 const struct llc_conn_state_ev *ev = llc_conn_ev(skb);
119 118
120 return ev->prim == LLC_DISC_PRIM && 119 return ev->prim == LLC_DISC_PRIM &&
121 ev->prim_type == LLC_PRIM_TYPE_REQ ? 0 : 1; 120 ev->prim_type == LLC_PRIM_TYPE_REQ ? 0 : 1;
@@ -123,7 +122,7 @@ int llc_conn_ev_disc_req(struct sock *sk, struct sk_buff *skb)
123 122
124int llc_conn_ev_rst_req(struct sock *sk, struct sk_buff *skb) 123int llc_conn_ev_rst_req(struct sock *sk, struct sk_buff *skb)
125{ 124{
126 struct llc_conn_state_ev *ev = llc_conn_ev(skb); 125 const struct llc_conn_state_ev *ev = llc_conn_ev(skb);
127 126
128 return ev->prim == LLC_RESET_PRIM && 127 return ev->prim == LLC_RESET_PRIM &&
129 ev->prim_type == LLC_PRIM_TYPE_REQ ? 0 : 1; 128 ev->prim_type == LLC_PRIM_TYPE_REQ ? 0 : 1;
@@ -131,7 +130,7 @@ int llc_conn_ev_rst_req(struct sock *sk, struct sk_buff *skb)
131 130
132int llc_conn_ev_local_busy_detected(struct sock *sk, struct sk_buff *skb) 131int llc_conn_ev_local_busy_detected(struct sock *sk, struct sk_buff *skb)
133{ 132{
134 struct llc_conn_state_ev *ev = llc_conn_ev(skb); 133 const struct llc_conn_state_ev *ev = llc_conn_ev(skb);
135 134
136 return ev->type == LLC_CONN_EV_TYPE_SIMPLE && 135 return ev->type == LLC_CONN_EV_TYPE_SIMPLE &&
137 ev->prim_type == LLC_CONN_EV_LOCAL_BUSY_DETECTED ? 0 : 1; 136 ev->prim_type == LLC_CONN_EV_LOCAL_BUSY_DETECTED ? 0 : 1;
@@ -139,7 +138,7 @@ int llc_conn_ev_local_busy_detected(struct sock *sk, struct sk_buff *skb)
139 138
140int llc_conn_ev_local_busy_cleared(struct sock *sk, struct sk_buff *skb) 139int llc_conn_ev_local_busy_cleared(struct sock *sk, struct sk_buff *skb)
141{ 140{
142 struct llc_conn_state_ev *ev = llc_conn_ev(skb); 141 const struct llc_conn_state_ev *ev = llc_conn_ev(skb);
143 142
144 return ev->type == LLC_CONN_EV_TYPE_SIMPLE && 143 return ev->type == LLC_CONN_EV_TYPE_SIMPLE &&
145 ev->prim_type == LLC_CONN_EV_LOCAL_BUSY_CLEARED ? 0 : 1; 144 ev->prim_type == LLC_CONN_EV_LOCAL_BUSY_CLEARED ? 0 : 1;
@@ -152,7 +151,7 @@ int llc_conn_ev_rx_bad_pdu(struct sock *sk, struct sk_buff *skb)
152 151
153int llc_conn_ev_rx_disc_cmd_pbit_set_x(struct sock *sk, struct sk_buff *skb) 152int llc_conn_ev_rx_disc_cmd_pbit_set_x(struct sock *sk, struct sk_buff *skb)
154{ 153{
155 struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); 154 const struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
156 155
157 return LLC_PDU_IS_CMD(pdu) && LLC_PDU_TYPE_IS_U(pdu) && 156 return LLC_PDU_IS_CMD(pdu) && LLC_PDU_TYPE_IS_U(pdu) &&
158 LLC_U_PDU_CMD(pdu) == LLC_2_PDU_CMD_DISC ? 0 : 1; 157 LLC_U_PDU_CMD(pdu) == LLC_2_PDU_CMD_DISC ? 0 : 1;
@@ -160,7 +159,7 @@ int llc_conn_ev_rx_disc_cmd_pbit_set_x(struct sock *sk, struct sk_buff *skb)
160 159
161int llc_conn_ev_rx_dm_rsp_fbit_set_x(struct sock *sk, struct sk_buff *skb) 160int llc_conn_ev_rx_dm_rsp_fbit_set_x(struct sock *sk, struct sk_buff *skb)
162{ 161{
163 struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); 162 const struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
164 163
165 return LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_U(pdu) && 164 return LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_U(pdu) &&
166 LLC_U_PDU_RSP(pdu) == LLC_2_PDU_RSP_DM ? 0 : 1; 165 LLC_U_PDU_RSP(pdu) == LLC_2_PDU_RSP_DM ? 0 : 1;
@@ -168,7 +167,7 @@ int llc_conn_ev_rx_dm_rsp_fbit_set_x(struct sock *sk, struct sk_buff *skb)
168 167
169int llc_conn_ev_rx_frmr_rsp_fbit_set_x(struct sock *sk, struct sk_buff *skb) 168int llc_conn_ev_rx_frmr_rsp_fbit_set_x(struct sock *sk, struct sk_buff *skb)
170{ 169{
171 struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); 170 const struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
172 171
173 return LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_U(pdu) && 172 return LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_U(pdu) &&
174 LLC_U_PDU_RSP(pdu) == LLC_2_PDU_RSP_FRMR ? 0 : 1; 173 LLC_U_PDU_RSP(pdu) == LLC_2_PDU_RSP_FRMR ? 0 : 1;
@@ -176,7 +175,7 @@ int llc_conn_ev_rx_frmr_rsp_fbit_set_x(struct sock *sk, struct sk_buff *skb)
176 175
177int llc_conn_ev_rx_i_cmd_pbit_set_0(struct sock *sk, struct sk_buff *skb) 176int llc_conn_ev_rx_i_cmd_pbit_set_0(struct sock *sk, struct sk_buff *skb)
178{ 177{
179 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); 178 const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
180 179
181 return llc_conn_space(sk, skb) && 180 return llc_conn_space(sk, skb) &&
182 LLC_PDU_IS_CMD(pdu) && LLC_PDU_TYPE_IS_I(pdu) && 181 LLC_PDU_IS_CMD(pdu) && LLC_PDU_TYPE_IS_I(pdu) &&
@@ -186,7 +185,7 @@ int llc_conn_ev_rx_i_cmd_pbit_set_0(struct sock *sk, struct sk_buff *skb)
186 185
187int llc_conn_ev_rx_i_cmd_pbit_set_1(struct sock *sk, struct sk_buff *skb) 186int llc_conn_ev_rx_i_cmd_pbit_set_1(struct sock *sk, struct sk_buff *skb)
188{ 187{
189 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); 188 const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
190 189
191 return llc_conn_space(sk, skb) && 190 return llc_conn_space(sk, skb) &&
192 LLC_PDU_IS_CMD(pdu) && LLC_PDU_TYPE_IS_I(pdu) && 191 LLC_PDU_IS_CMD(pdu) && LLC_PDU_TYPE_IS_I(pdu) &&
@@ -197,9 +196,9 @@ int llc_conn_ev_rx_i_cmd_pbit_set_1(struct sock *sk, struct sk_buff *skb)
197int llc_conn_ev_rx_i_cmd_pbit_set_0_unexpd_ns(struct sock *sk, 196int llc_conn_ev_rx_i_cmd_pbit_set_0_unexpd_ns(struct sock *sk,
198 struct sk_buff *skb) 197 struct sk_buff *skb)
199{ 198{
200 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); 199 const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
201 u8 vr = llc_sk(sk)->vR; 200 const u8 vr = llc_sk(sk)->vR;
202 u8 ns = LLC_I_GET_NS(pdu); 201 const u8 ns = LLC_I_GET_NS(pdu);
203 202
204 return LLC_PDU_IS_CMD(pdu) && LLC_PDU_TYPE_IS_I(pdu) && 203 return LLC_PDU_IS_CMD(pdu) && LLC_PDU_TYPE_IS_I(pdu) &&
205 LLC_I_PF_IS_0(pdu) && ns != vr && 204 LLC_I_PF_IS_0(pdu) && ns != vr &&
@@ -209,9 +208,9 @@ int llc_conn_ev_rx_i_cmd_pbit_set_0_unexpd_ns(struct sock *sk,
209int llc_conn_ev_rx_i_cmd_pbit_set_1_unexpd_ns(struct sock *sk, 208int llc_conn_ev_rx_i_cmd_pbit_set_1_unexpd_ns(struct sock *sk,
210 struct sk_buff *skb) 209 struct sk_buff *skb)
211{ 210{
212 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); 211 const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
213 u8 vr = llc_sk(sk)->vR; 212 const u8 vr = llc_sk(sk)->vR;
214 u8 ns = LLC_I_GET_NS(pdu); 213 const u8 ns = LLC_I_GET_NS(pdu);
215 214
216 return LLC_PDU_IS_CMD(pdu) && LLC_PDU_TYPE_IS_I(pdu) && 215 return LLC_PDU_IS_CMD(pdu) && LLC_PDU_TYPE_IS_I(pdu) &&
217 LLC_I_PF_IS_1(pdu) && ns != vr && 216 LLC_I_PF_IS_1(pdu) && ns != vr &&
@@ -221,10 +220,11 @@ int llc_conn_ev_rx_i_cmd_pbit_set_1_unexpd_ns(struct sock *sk,
221int llc_conn_ev_rx_i_cmd_pbit_set_x_inval_ns(struct sock *sk, 220int llc_conn_ev_rx_i_cmd_pbit_set_x_inval_ns(struct sock *sk,
222 struct sk_buff *skb) 221 struct sk_buff *skb)
223{ 222{
224 struct llc_pdu_sn * pdu = llc_pdu_sn_hdr(skb); 223 const struct llc_pdu_sn * pdu = llc_pdu_sn_hdr(skb);
225 u8 vr = llc_sk(sk)->vR; 224 const u8 vr = llc_sk(sk)->vR;
226 u8 ns = LLC_I_GET_NS(pdu); 225 const u8 ns = LLC_I_GET_NS(pdu);
227 u16 rc = LLC_PDU_IS_CMD(pdu) && LLC_PDU_TYPE_IS_I(pdu) && ns != vr && 226 const u16 rc = LLC_PDU_IS_CMD(pdu) && LLC_PDU_TYPE_IS_I(pdu) &&
227 ns != vr &&
228 llc_util_ns_inside_rx_window(ns, vr, llc_sk(sk)->rw) ? 0 : 1; 228 llc_util_ns_inside_rx_window(ns, vr, llc_sk(sk)->rw) ? 0 : 1;
229 if (!rc) 229 if (!rc)
230 dprintk("%s: matched, state=%d, ns=%d, vr=%d\n", 230 dprintk("%s: matched, state=%d, ns=%d, vr=%d\n",
@@ -234,7 +234,7 @@ int llc_conn_ev_rx_i_cmd_pbit_set_x_inval_ns(struct sock *sk,
234 234
235int llc_conn_ev_rx_i_rsp_fbit_set_0(struct sock *sk, struct sk_buff *skb) 235int llc_conn_ev_rx_i_rsp_fbit_set_0(struct sock *sk, struct sk_buff *skb)
236{ 236{
237 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); 237 const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
238 238
239 return llc_conn_space(sk, skb) && 239 return llc_conn_space(sk, skb) &&
240 LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_I(pdu) && 240 LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_I(pdu) &&
@@ -244,7 +244,7 @@ int llc_conn_ev_rx_i_rsp_fbit_set_0(struct sock *sk, struct sk_buff *skb)
244 244
245int llc_conn_ev_rx_i_rsp_fbit_set_1(struct sock *sk, struct sk_buff *skb) 245int llc_conn_ev_rx_i_rsp_fbit_set_1(struct sock *sk, struct sk_buff *skb)
246{ 246{
247 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); 247 const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
248 248
249 return LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_I(pdu) && 249 return LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_I(pdu) &&
250 LLC_I_PF_IS_1(pdu) && 250 LLC_I_PF_IS_1(pdu) &&
@@ -253,7 +253,7 @@ int llc_conn_ev_rx_i_rsp_fbit_set_1(struct sock *sk, struct sk_buff *skb)
253 253
254int llc_conn_ev_rx_i_rsp_fbit_set_x(struct sock *sk, struct sk_buff *skb) 254int llc_conn_ev_rx_i_rsp_fbit_set_x(struct sock *sk, struct sk_buff *skb)
255{ 255{
256 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); 256 const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
257 257
258 return llc_conn_space(sk, skb) && 258 return llc_conn_space(sk, skb) &&
259 LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_I(pdu) && 259 LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_I(pdu) &&
@@ -263,9 +263,9 @@ int llc_conn_ev_rx_i_rsp_fbit_set_x(struct sock *sk, struct sk_buff *skb)
263int llc_conn_ev_rx_i_rsp_fbit_set_0_unexpd_ns(struct sock *sk, 263int llc_conn_ev_rx_i_rsp_fbit_set_0_unexpd_ns(struct sock *sk,
264 struct sk_buff *skb) 264 struct sk_buff *skb)
265{ 265{
266 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); 266 const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
267 u8 vr = llc_sk(sk)->vR; 267 const u8 vr = llc_sk(sk)->vR;
268 u8 ns = LLC_I_GET_NS(pdu); 268 const u8 ns = LLC_I_GET_NS(pdu);
269 269
270 return LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_I(pdu) && 270 return LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_I(pdu) &&
271 LLC_I_PF_IS_0(pdu) && ns != vr && 271 LLC_I_PF_IS_0(pdu) && ns != vr &&
@@ -275,9 +275,9 @@ int llc_conn_ev_rx_i_rsp_fbit_set_0_unexpd_ns(struct sock *sk,
275int llc_conn_ev_rx_i_rsp_fbit_set_1_unexpd_ns(struct sock *sk, 275int llc_conn_ev_rx_i_rsp_fbit_set_1_unexpd_ns(struct sock *sk,
276 struct sk_buff *skb) 276 struct sk_buff *skb)
277{ 277{
278 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); 278 const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
279 u8 vr = llc_sk(sk)->vR; 279 const u8 vr = llc_sk(sk)->vR;
280 u8 ns = LLC_I_GET_NS(pdu); 280 const u8 ns = LLC_I_GET_NS(pdu);
281 281
282 return LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_I(pdu) && 282 return LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_I(pdu) &&
283 LLC_I_PF_IS_1(pdu) && ns != vr && 283 LLC_I_PF_IS_1(pdu) && ns != vr &&
@@ -287,9 +287,9 @@ int llc_conn_ev_rx_i_rsp_fbit_set_1_unexpd_ns(struct sock *sk,
287int llc_conn_ev_rx_i_rsp_fbit_set_x_unexpd_ns(struct sock *sk, 287int llc_conn_ev_rx_i_rsp_fbit_set_x_unexpd_ns(struct sock *sk,
288 struct sk_buff *skb) 288 struct sk_buff *skb)
289{ 289{
290 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); 290 const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
291 u8 vr = llc_sk(sk)->vR; 291 const u8 vr = llc_sk(sk)->vR;
292 u8 ns = LLC_I_GET_NS(pdu); 292 const u8 ns = LLC_I_GET_NS(pdu);
293 293
294 return LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_I(pdu) && ns != vr && 294 return LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_I(pdu) && ns != vr &&
295 !llc_util_ns_inside_rx_window(ns, vr, llc_sk(sk)->rw) ? 0 : 1; 295 !llc_util_ns_inside_rx_window(ns, vr, llc_sk(sk)->rw) ? 0 : 1;
@@ -298,10 +298,11 @@ int llc_conn_ev_rx_i_rsp_fbit_set_x_unexpd_ns(struct sock *sk,
298int llc_conn_ev_rx_i_rsp_fbit_set_x_inval_ns(struct sock *sk, 298int llc_conn_ev_rx_i_rsp_fbit_set_x_inval_ns(struct sock *sk,
299 struct sk_buff *skb) 299 struct sk_buff *skb)
300{ 300{
301 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); 301 const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
302 u8 vr = llc_sk(sk)->vR; 302 const u8 vr = llc_sk(sk)->vR;
303 u8 ns = LLC_I_GET_NS(pdu); 303 const u8 ns = LLC_I_GET_NS(pdu);
304 u16 rc = LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_I(pdu) && ns != vr && 304 const u16 rc = LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_I(pdu) &&
305 ns != vr &&
305 llc_util_ns_inside_rx_window(ns, vr, llc_sk(sk)->rw) ? 0 : 1; 306 llc_util_ns_inside_rx_window(ns, vr, llc_sk(sk)->rw) ? 0 : 1;
306 if (!rc) 307 if (!rc)
307 dprintk("%s: matched, state=%d, ns=%d, vr=%d\n", 308 dprintk("%s: matched, state=%d, ns=%d, vr=%d\n",
@@ -311,7 +312,7 @@ int llc_conn_ev_rx_i_rsp_fbit_set_x_inval_ns(struct sock *sk,
311 312
312int llc_conn_ev_rx_rej_cmd_pbit_set_0(struct sock *sk, struct sk_buff *skb) 313int llc_conn_ev_rx_rej_cmd_pbit_set_0(struct sock *sk, struct sk_buff *skb)
313{ 314{
314 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); 315 const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
315 316
316 return LLC_PDU_IS_CMD(pdu) && LLC_PDU_TYPE_IS_S(pdu) && 317 return LLC_PDU_IS_CMD(pdu) && LLC_PDU_TYPE_IS_S(pdu) &&
317 LLC_S_PF_IS_0(pdu) && 318 LLC_S_PF_IS_0(pdu) &&
@@ -320,7 +321,7 @@ int llc_conn_ev_rx_rej_cmd_pbit_set_0(struct sock *sk, struct sk_buff *skb)
320 321
321int llc_conn_ev_rx_rej_cmd_pbit_set_1(struct sock *sk, struct sk_buff *skb) 322int llc_conn_ev_rx_rej_cmd_pbit_set_1(struct sock *sk, struct sk_buff *skb)
322{ 323{
323 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); 324 const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
324 325
325 return LLC_PDU_IS_CMD(pdu) && LLC_PDU_TYPE_IS_S(pdu) && 326 return LLC_PDU_IS_CMD(pdu) && LLC_PDU_TYPE_IS_S(pdu) &&
326 LLC_S_PF_IS_1(pdu) && 327 LLC_S_PF_IS_1(pdu) &&
@@ -329,7 +330,7 @@ int llc_conn_ev_rx_rej_cmd_pbit_set_1(struct sock *sk, struct sk_buff *skb)
329 330
330int llc_conn_ev_rx_rej_rsp_fbit_set_0(struct sock *sk, struct sk_buff *skb) 331int llc_conn_ev_rx_rej_rsp_fbit_set_0(struct sock *sk, struct sk_buff *skb)
331{ 332{
332 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); 333 const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
333 334
334 return LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_S(pdu) && 335 return LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_S(pdu) &&
335 LLC_S_PF_IS_0(pdu) && 336 LLC_S_PF_IS_0(pdu) &&
@@ -338,7 +339,7 @@ int llc_conn_ev_rx_rej_rsp_fbit_set_0(struct sock *sk, struct sk_buff *skb)
338 339
339int llc_conn_ev_rx_rej_rsp_fbit_set_1(struct sock *sk, struct sk_buff *skb) 340int llc_conn_ev_rx_rej_rsp_fbit_set_1(struct sock *sk, struct sk_buff *skb)
340{ 341{
341 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); 342 const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
342 343
343 return LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_S(pdu) && 344 return LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_S(pdu) &&
344 LLC_S_PF_IS_1(pdu) && 345 LLC_S_PF_IS_1(pdu) &&
@@ -347,7 +348,7 @@ int llc_conn_ev_rx_rej_rsp_fbit_set_1(struct sock *sk, struct sk_buff *skb)
347 348
348int llc_conn_ev_rx_rej_rsp_fbit_set_x(struct sock *sk, struct sk_buff *skb) 349int llc_conn_ev_rx_rej_rsp_fbit_set_x(struct sock *sk, struct sk_buff *skb)
349{ 350{
350 struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); 351 const struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
351 352
352 return LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_S(pdu) && 353 return LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_S(pdu) &&
353 LLC_S_PDU_RSP(pdu) == LLC_2_PDU_RSP_REJ ? 0 : 1; 354 LLC_S_PDU_RSP(pdu) == LLC_2_PDU_RSP_REJ ? 0 : 1;
@@ -355,7 +356,7 @@ int llc_conn_ev_rx_rej_rsp_fbit_set_x(struct sock *sk, struct sk_buff *skb)
355 356
356int llc_conn_ev_rx_rnr_cmd_pbit_set_0(struct sock *sk, struct sk_buff *skb) 357int llc_conn_ev_rx_rnr_cmd_pbit_set_0(struct sock *sk, struct sk_buff *skb)
357{ 358{
358 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); 359 const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
359 360
360 return LLC_PDU_IS_CMD(pdu) && LLC_PDU_TYPE_IS_S(pdu) && 361 return LLC_PDU_IS_CMD(pdu) && LLC_PDU_TYPE_IS_S(pdu) &&
361 LLC_S_PF_IS_0(pdu) && 362 LLC_S_PF_IS_0(pdu) &&
@@ -364,7 +365,7 @@ int llc_conn_ev_rx_rnr_cmd_pbit_set_0(struct sock *sk, struct sk_buff *skb)
364 365
365int llc_conn_ev_rx_rnr_cmd_pbit_set_1(struct sock *sk, struct sk_buff *skb) 366int llc_conn_ev_rx_rnr_cmd_pbit_set_1(struct sock *sk, struct sk_buff *skb)
366{ 367{
367 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); 368 const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
368 369
369 return LLC_PDU_IS_CMD(pdu) && LLC_PDU_TYPE_IS_S(pdu) && 370 return LLC_PDU_IS_CMD(pdu) && LLC_PDU_TYPE_IS_S(pdu) &&
370 LLC_S_PF_IS_1(pdu) && 371 LLC_S_PF_IS_1(pdu) &&
@@ -373,7 +374,7 @@ int llc_conn_ev_rx_rnr_cmd_pbit_set_1(struct sock *sk, struct sk_buff *skb)
373 374
374int llc_conn_ev_rx_rnr_rsp_fbit_set_0(struct sock *sk, struct sk_buff *skb) 375int llc_conn_ev_rx_rnr_rsp_fbit_set_0(struct sock *sk, struct sk_buff *skb)
375{ 376{
376 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); 377 const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
377 378
378 return LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_S(pdu) && 379 return LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_S(pdu) &&
379 LLC_S_PF_IS_0(pdu) && 380 LLC_S_PF_IS_0(pdu) &&
@@ -382,7 +383,7 @@ int llc_conn_ev_rx_rnr_rsp_fbit_set_0(struct sock *sk, struct sk_buff *skb)
382 383
383int llc_conn_ev_rx_rnr_rsp_fbit_set_1(struct sock *sk, struct sk_buff *skb) 384int llc_conn_ev_rx_rnr_rsp_fbit_set_1(struct sock *sk, struct sk_buff *skb)
384{ 385{
385 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); 386 const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
386 387
387 return LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_S(pdu) && 388 return LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_S(pdu) &&
388 LLC_S_PF_IS_1(pdu) && 389 LLC_S_PF_IS_1(pdu) &&
@@ -391,7 +392,7 @@ int llc_conn_ev_rx_rnr_rsp_fbit_set_1(struct sock *sk, struct sk_buff *skb)
391 392
392int llc_conn_ev_rx_rr_cmd_pbit_set_0(struct sock *sk, struct sk_buff *skb) 393int llc_conn_ev_rx_rr_cmd_pbit_set_0(struct sock *sk, struct sk_buff *skb)
393{ 394{
394 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); 395 const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
395 396
396 return LLC_PDU_IS_CMD(pdu) && LLC_PDU_TYPE_IS_S(pdu) && 397 return LLC_PDU_IS_CMD(pdu) && LLC_PDU_TYPE_IS_S(pdu) &&
397 LLC_S_PF_IS_0(pdu) && 398 LLC_S_PF_IS_0(pdu) &&
@@ -400,7 +401,7 @@ int llc_conn_ev_rx_rr_cmd_pbit_set_0(struct sock *sk, struct sk_buff *skb)
400 401
401int llc_conn_ev_rx_rr_cmd_pbit_set_1(struct sock *sk, struct sk_buff *skb) 402int llc_conn_ev_rx_rr_cmd_pbit_set_1(struct sock *sk, struct sk_buff *skb)
402{ 403{
403 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); 404 const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
404 405
405 return LLC_PDU_IS_CMD(pdu) && LLC_PDU_TYPE_IS_S(pdu) && 406 return LLC_PDU_IS_CMD(pdu) && LLC_PDU_TYPE_IS_S(pdu) &&
406 LLC_S_PF_IS_1(pdu) && 407 LLC_S_PF_IS_1(pdu) &&
@@ -409,7 +410,7 @@ int llc_conn_ev_rx_rr_cmd_pbit_set_1(struct sock *sk, struct sk_buff *skb)
409 410
410int llc_conn_ev_rx_rr_rsp_fbit_set_0(struct sock *sk, struct sk_buff *skb) 411int llc_conn_ev_rx_rr_rsp_fbit_set_0(struct sock *sk, struct sk_buff *skb)
411{ 412{
412 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); 413 const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
413 414
414 return llc_conn_space(sk, skb) && 415 return llc_conn_space(sk, skb) &&
415 LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_S(pdu) && 416 LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_S(pdu) &&
@@ -419,7 +420,7 @@ int llc_conn_ev_rx_rr_rsp_fbit_set_0(struct sock *sk, struct sk_buff *skb)
419 420
420int llc_conn_ev_rx_rr_rsp_fbit_set_1(struct sock *sk, struct sk_buff *skb) 421int llc_conn_ev_rx_rr_rsp_fbit_set_1(struct sock *sk, struct sk_buff *skb)
421{ 422{
422 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); 423 const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
423 424
424 return llc_conn_space(sk, skb) && 425 return llc_conn_space(sk, skb) &&
425 LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_S(pdu) && 426 LLC_PDU_IS_RSP(pdu) && LLC_PDU_TYPE_IS_S(pdu) &&
@@ -429,7 +430,7 @@ int llc_conn_ev_rx_rr_rsp_fbit_set_1(struct sock *sk, struct sk_buff *skb)
429 430
430int llc_conn_ev_rx_sabme_cmd_pbit_set_x(struct sock *sk, struct sk_buff *skb) 431int llc_conn_ev_rx_sabme_cmd_pbit_set_x(struct sock *sk, struct sk_buff *skb)
431{ 432{
432 struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); 433 const struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
433 434
434 return LLC_PDU_IS_CMD(pdu) && LLC_PDU_TYPE_IS_U(pdu) && 435 return LLC_PDU_IS_CMD(pdu) && LLC_PDU_TYPE_IS_U(pdu) &&
435 LLC_U_PDU_CMD(pdu) == LLC_2_PDU_CMD_SABME ? 0 : 1; 436 LLC_U_PDU_CMD(pdu) == LLC_2_PDU_CMD_SABME ? 0 : 1;
@@ -446,7 +447,7 @@ int llc_conn_ev_rx_ua_rsp_fbit_set_x(struct sock *sk, struct sk_buff *skb)
446int llc_conn_ev_rx_xxx_cmd_pbit_set_1(struct sock *sk, struct sk_buff *skb) 447int llc_conn_ev_rx_xxx_cmd_pbit_set_1(struct sock *sk, struct sk_buff *skb)
447{ 448{
448 u16 rc = 1; 449 u16 rc = 1;
449 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); 450 const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
450 451
451 if (LLC_PDU_IS_CMD(pdu)) { 452 if (LLC_PDU_IS_CMD(pdu)) {
452 if (LLC_PDU_TYPE_IS_I(pdu) || LLC_PDU_TYPE_IS_S(pdu)) { 453 if (LLC_PDU_TYPE_IS_I(pdu) || LLC_PDU_TYPE_IS_S(pdu)) {
@@ -461,7 +462,7 @@ int llc_conn_ev_rx_xxx_cmd_pbit_set_1(struct sock *sk, struct sk_buff *skb)
461int llc_conn_ev_rx_xxx_cmd_pbit_set_x(struct sock *sk, struct sk_buff *skb) 462int llc_conn_ev_rx_xxx_cmd_pbit_set_x(struct sock *sk, struct sk_buff *skb)
462{ 463{
463 u16 rc = 1; 464 u16 rc = 1;
464 struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); 465 const struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
465 466
466 if (LLC_PDU_IS_CMD(pdu)) { 467 if (LLC_PDU_IS_CMD(pdu)) {
467 if (LLC_PDU_TYPE_IS_I(pdu) || LLC_PDU_TYPE_IS_S(pdu)) 468 if (LLC_PDU_TYPE_IS_I(pdu) || LLC_PDU_TYPE_IS_S(pdu))
@@ -477,32 +478,10 @@ int llc_conn_ev_rx_xxx_cmd_pbit_set_x(struct sock *sk, struct sk_buff *skb)
477 return rc; 478 return rc;
478} 479}
479 480
480int llc_conn_ev_rx_xxx_rsp_fbit_set_1(struct sock *sk, struct sk_buff *skb)
481{
482 u16 rc = 1;
483 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
484
485 if (LLC_PDU_IS_RSP(pdu)) {
486 if (LLC_PDU_TYPE_IS_I(pdu) || LLC_PDU_TYPE_IS_S(pdu)) {
487 if (LLC_I_PF_IS_1(pdu))
488 rc = 0;
489 } else if (LLC_PDU_TYPE_IS_U(pdu))
490 switch (LLC_U_PDU_RSP(pdu)) {
491 case LLC_2_PDU_RSP_UA:
492 case LLC_2_PDU_RSP_DM:
493 case LLC_2_PDU_RSP_FRMR:
494 if (LLC_U_PF_IS_1(pdu))
495 rc = 0;
496 break;
497 }
498 }
499 return rc;
500}
501
502int llc_conn_ev_rx_xxx_rsp_fbit_set_x(struct sock *sk, struct sk_buff *skb) 481int llc_conn_ev_rx_xxx_rsp_fbit_set_x(struct sock *sk, struct sk_buff *skb)
503{ 482{
504 u16 rc = 1; 483 u16 rc = 1;
505 struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb); 484 const struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
506 485
507 if (LLC_PDU_IS_RSP(pdu)) { 486 if (LLC_PDU_IS_RSP(pdu)) {
508 if (LLC_PDU_TYPE_IS_I(pdu) || LLC_PDU_TYPE_IS_S(pdu)) 487 if (LLC_PDU_TYPE_IS_I(pdu) || LLC_PDU_TYPE_IS_S(pdu))
@@ -524,9 +503,9 @@ int llc_conn_ev_rx_zzz_cmd_pbit_set_x_inval_nr(struct sock *sk,
524 struct sk_buff *skb) 503 struct sk_buff *skb)
525{ 504{
526 u16 rc = 1; 505 u16 rc = 1;
527 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); 506 const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
528 u8 vs = llc_sk(sk)->vS; 507 const u8 vs = llc_sk(sk)->vS;
529 u8 nr = LLC_I_GET_NR(pdu); 508 const u8 nr = LLC_I_GET_NR(pdu);
530 509
531 if (LLC_PDU_IS_CMD(pdu) && 510 if (LLC_PDU_IS_CMD(pdu) &&
532 (LLC_PDU_TYPE_IS_I(pdu) || LLC_PDU_TYPE_IS_S(pdu)) && 511 (LLC_PDU_TYPE_IS_I(pdu) || LLC_PDU_TYPE_IS_S(pdu)) &&
@@ -542,9 +521,9 @@ int llc_conn_ev_rx_zzz_rsp_fbit_set_x_inval_nr(struct sock *sk,
542 struct sk_buff *skb) 521 struct sk_buff *skb)
543{ 522{
544 u16 rc = 1; 523 u16 rc = 1;
545 struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb); 524 const struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
546 u8 vs = llc_sk(sk)->vS; 525 const u8 vs = llc_sk(sk)->vS;
547 u8 nr = LLC_I_GET_NR(pdu); 526 const u8 nr = LLC_I_GET_NR(pdu);
548 527
549 if (LLC_PDU_IS_RSP(pdu) && 528 if (LLC_PDU_IS_RSP(pdu) &&
550 (LLC_PDU_TYPE_IS_I(pdu) || LLC_PDU_TYPE_IS_S(pdu)) && 529 (LLC_PDU_TYPE_IS_I(pdu) || LLC_PDU_TYPE_IS_S(pdu)) &&
@@ -563,28 +542,28 @@ int llc_conn_ev_rx_any_frame(struct sock *sk, struct sk_buff *skb)
563 542
564int llc_conn_ev_p_tmr_exp(struct sock *sk, struct sk_buff *skb) 543int llc_conn_ev_p_tmr_exp(struct sock *sk, struct sk_buff *skb)
565{ 544{
566 struct llc_conn_state_ev *ev = llc_conn_ev(skb); 545 const struct llc_conn_state_ev *ev = llc_conn_ev(skb);
567 546
568 return ev->type != LLC_CONN_EV_TYPE_P_TMR; 547 return ev->type != LLC_CONN_EV_TYPE_P_TMR;
569} 548}
570 549
571int llc_conn_ev_ack_tmr_exp(struct sock *sk, struct sk_buff *skb) 550int llc_conn_ev_ack_tmr_exp(struct sock *sk, struct sk_buff *skb)
572{ 551{
573 struct llc_conn_state_ev *ev = llc_conn_ev(skb); 552 const struct llc_conn_state_ev *ev = llc_conn_ev(skb);
574 553
575 return ev->type != LLC_CONN_EV_TYPE_ACK_TMR; 554 return ev->type != LLC_CONN_EV_TYPE_ACK_TMR;
576} 555}
577 556
578int llc_conn_ev_rej_tmr_exp(struct sock *sk, struct sk_buff *skb) 557int llc_conn_ev_rej_tmr_exp(struct sock *sk, struct sk_buff *skb)
579{ 558{
580 struct llc_conn_state_ev *ev = llc_conn_ev(skb); 559 const struct llc_conn_state_ev *ev = llc_conn_ev(skb);
581 560
582 return ev->type != LLC_CONN_EV_TYPE_REJ_TMR; 561 return ev->type != LLC_CONN_EV_TYPE_REJ_TMR;
583} 562}
584 563
585int llc_conn_ev_busy_tmr_exp(struct sock *sk, struct sk_buff *skb) 564int llc_conn_ev_busy_tmr_exp(struct sock *sk, struct sk_buff *skb)
586{ 565{
587 struct llc_conn_state_ev *ev = llc_conn_ev(skb); 566 const struct llc_conn_state_ev *ev = llc_conn_ev(skb);
588 567
589 return ev->type != LLC_CONN_EV_TYPE_BUSY_TMR; 568 return ev->type != LLC_CONN_EV_TYPE_BUSY_TMR;
590} 569}
@@ -596,7 +575,7 @@ int llc_conn_ev_init_p_f_cycle(struct sock *sk, struct sk_buff *skb)
596 575
597int llc_conn_ev_tx_buffer_full(struct sock *sk, struct sk_buff *skb) 576int llc_conn_ev_tx_buffer_full(struct sock *sk, struct sk_buff *skb)
598{ 577{
599 struct llc_conn_state_ev *ev = llc_conn_ev(skb); 578 const struct llc_conn_state_ev *ev = llc_conn_ev(skb);
600 579
601 return ev->type == LLC_CONN_EV_TYPE_SIMPLE && 580 return ev->type == LLC_CONN_EV_TYPE_SIMPLE &&
602 ev->prim_type == LLC_CONN_EV_TX_BUFF_FULL ? 0 : 1; 581 ev->prim_type == LLC_CONN_EV_TX_BUFF_FULL ? 0 : 1;
diff --git a/net/llc/llc_conn.c b/net/llc/llc_conn.c
index 4c644bc70eae..042b24a8ca4c 100644
--- a/net/llc/llc_conn.c
+++ b/net/llc/llc_conn.c
@@ -40,6 +40,11 @@ static struct llc_conn_state_trans *llc_qualify_conn_ev(struct sock *sk,
40/* Offset table on connection states transition diagram */ 40/* Offset table on connection states transition diagram */
41static int llc_offset_table[NBR_CONN_STATES][NBR_CONN_EV]; 41static int llc_offset_table[NBR_CONN_STATES][NBR_CONN_EV];
42 42
43int sysctl_llc2_ack_timeout = LLC2_ACK_TIME * HZ;
44int sysctl_llc2_p_timeout = LLC2_P_TIME * HZ;
45int sysctl_llc2_rej_timeout = LLC2_REJ_TIME * HZ;
46int sysctl_llc2_busy_timeout = LLC2_BUSY_TIME * HZ;
47
43/** 48/**
44 * llc_conn_state_process - sends event to connection state machine 49 * llc_conn_state_process - sends event to connection state machine
45 * @sk: connection 50 * @sk: connection
@@ -53,7 +58,7 @@ static int llc_offset_table[NBR_CONN_STATES][NBR_CONN_EV];
53int llc_conn_state_process(struct sock *sk, struct sk_buff *skb) 58int llc_conn_state_process(struct sock *sk, struct sk_buff *skb)
54{ 59{
55 int rc; 60 int rc;
56 struct llc_sock *llc = llc_sk(sk); 61 struct llc_sock *llc = llc_sk(skb->sk);
57 struct llc_conn_state_ev *ev = llc_conn_ev(skb); 62 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
58 63
59 /* 64 /*
@@ -63,13 +68,16 @@ int llc_conn_state_process(struct sock *sk, struct sk_buff *skb)
63 */ 68 */
64 skb_get(skb); 69 skb_get(skb);
65 ev->ind_prim = ev->cfm_prim = 0; 70 ev->ind_prim = ev->cfm_prim = 0;
66 rc = llc_conn_service(sk, skb); /* sending event to state machine */ 71 /*
67 if (rc) { 72 * Send event to state machine
73 */
74 rc = llc_conn_service(skb->sk, skb);
75 if (unlikely(rc != 0)) {
68 printk(KERN_ERR "%s: llc_conn_service failed\n", __FUNCTION__); 76 printk(KERN_ERR "%s: llc_conn_service failed\n", __FUNCTION__);
69 goto out_kfree_skb; 77 goto out_kfree_skb;
70 } 78 }
71 79
72 if (!ev->ind_prim && !ev->cfm_prim) { 80 if (unlikely(!ev->ind_prim && !ev->cfm_prim)) {
73 /* indicate or confirm not required */ 81 /* indicate or confirm not required */
74 /* XXX this is not very pretty, perhaps we should store 82 /* XXX this is not very pretty, perhaps we should store
75 * XXX indicate/confirm-needed state in the llc_conn_state_ev 83 * XXX indicate/confirm-needed state in the llc_conn_state_ev
@@ -80,13 +88,13 @@ int llc_conn_state_process(struct sock *sk, struct sk_buff *skb)
80 goto out_skb_put; 88 goto out_skb_put;
81 } 89 }
82 90
83 if (ev->ind_prim && ev->cfm_prim) /* Paranoia */ 91 if (unlikely(ev->ind_prim && ev->cfm_prim)) /* Paranoia */
84 skb_get(skb); 92 skb_get(skb);
85 93
86 switch (ev->ind_prim) { 94 switch (ev->ind_prim) {
87 case LLC_DATA_PRIM: 95 case LLC_DATA_PRIM:
88 llc_save_primitive(skb, LLC_DATA_PRIM); 96 llc_save_primitive(sk, skb, LLC_DATA_PRIM);
89 if (sock_queue_rcv_skb(sk, skb)) { 97 if (unlikely(sock_queue_rcv_skb(sk, skb))) {
90 /* 98 /*
91 * shouldn't happen 99 * shouldn't happen
92 */ 100 */
@@ -95,13 +103,14 @@ int llc_conn_state_process(struct sock *sk, struct sk_buff *skb)
95 kfree_skb(skb); 103 kfree_skb(skb);
96 } 104 }
97 break; 105 break;
98 case LLC_CONN_PRIM: { 106 case LLC_CONN_PRIM:
99 struct sock *parent = skb->sk; 107 /*
100 108 * Can't be sock_queue_rcv_skb, because we have to leave the
101 skb->sk = sk; 109 * skb->sk pointing to the newly created struct sock in
102 skb_queue_tail(&parent->sk_receive_queue, skb); 110 * llc_conn_handler. -acme
103 sk->sk_state_change(parent); 111 */
104 } 112 skb_queue_tail(&sk->sk_receive_queue, skb);
113 sk->sk_state_change(sk);
105 break; 114 break;
106 case LLC_DISC_PRIM: 115 case LLC_DISC_PRIM:
107 sock_hold(sk); 116 sock_hold(sk);
@@ -111,8 +120,8 @@ int llc_conn_state_process(struct sock *sk, struct sk_buff *skb)
111 sk->sk_socket->state = SS_UNCONNECTED; 120 sk->sk_socket->state = SS_UNCONNECTED;
112 sk->sk_state = TCP_CLOSE; 121 sk->sk_state = TCP_CLOSE;
113 if (!sock_flag(sk, SOCK_DEAD)) { 122 if (!sock_flag(sk, SOCK_DEAD)) {
114 sk->sk_state_change(sk);
115 sock_set_flag(sk, SOCK_DEAD); 123 sock_set_flag(sk, SOCK_DEAD);
124 sk->sk_state_change(sk);
116 } 125 }
117 } 126 }
118 kfree_skb(skb); 127 kfree_skb(skb);
@@ -465,7 +474,7 @@ static int llc_exec_conn_trans_actions(struct sock *sk,
465} 474}
466 475
467/** 476/**
468 * llc_lookup_established - Finds connection for the remote/local sap/mac 477 * __llc_lookup_established - Finds connection for the remote/local sap/mac
469 * @sap: SAP 478 * @sap: SAP
470 * @daddr: address of remote LLC (MAC + SAP) 479 * @daddr: address of remote LLC (MAC + SAP)
471 * @laddr: address of local LLC (MAC + SAP) 480 * @laddr: address of local LLC (MAC + SAP)
@@ -473,14 +482,16 @@ static int llc_exec_conn_trans_actions(struct sock *sk,
473 * Search connection list of the SAP and finds connection using the remote 482 * Search connection list of the SAP and finds connection using the remote
474 * mac, remote sap, local mac, and local sap. Returns pointer for 483 * mac, remote sap, local mac, and local sap. Returns pointer for
475 * connection found, %NULL otherwise. 484 * connection found, %NULL otherwise.
485 * Caller has to make sure local_bh is disabled.
476 */ 486 */
477struct sock *llc_lookup_established(struct llc_sap *sap, struct llc_addr *daddr, 487static struct sock *__llc_lookup_established(struct llc_sap *sap,
478 struct llc_addr *laddr) 488 struct llc_addr *daddr,
489 struct llc_addr *laddr)
479{ 490{
480 struct sock *rc; 491 struct sock *rc;
481 struct hlist_node *node; 492 struct hlist_node *node;
482 493
483 read_lock_bh(&sap->sk_list.lock); 494 read_lock(&sap->sk_list.lock);
484 sk_for_each(rc, node, &sap->sk_list.list) { 495 sk_for_each(rc, node, &sap->sk_list.list) {
485 struct llc_sock *llc = llc_sk(rc); 496 struct llc_sock *llc = llc_sk(rc);
486 497
@@ -494,10 +505,22 @@ struct sock *llc_lookup_established(struct llc_sap *sap, struct llc_addr *daddr,
494 } 505 }
495 rc = NULL; 506 rc = NULL;
496found: 507found:
497 read_unlock_bh(&sap->sk_list.lock); 508 read_unlock(&sap->sk_list.lock);
498 return rc; 509 return rc;
499} 510}
500 511
512struct sock *llc_lookup_established(struct llc_sap *sap,
513 struct llc_addr *daddr,
514 struct llc_addr *laddr)
515{
516 struct sock *sk;
517
518 local_bh_disable();
519 sk = __llc_lookup_established(sap, daddr, laddr);
520 local_bh_enable();
521 return sk;
522}
523
501/** 524/**
502 * llc_lookup_listener - Finds listener for local MAC + SAP 525 * llc_lookup_listener - Finds listener for local MAC + SAP
503 * @sap: SAP 526 * @sap: SAP
@@ -506,6 +529,7 @@ found:
506 * Search connection list of the SAP and finds connection listening on 529 * Search connection list of the SAP and finds connection listening on
507 * local mac, and local sap. Returns pointer for parent socket found, 530 * local mac, and local sap. Returns pointer for parent socket found,
508 * %NULL otherwise. 531 * %NULL otherwise.
532 * Caller has to make sure local_bh is disabled.
509 */ 533 */
510static struct sock *llc_lookup_listener(struct llc_sap *sap, 534static struct sock *llc_lookup_listener(struct llc_sap *sap,
511 struct llc_addr *laddr) 535 struct llc_addr *laddr)
@@ -513,7 +537,7 @@ static struct sock *llc_lookup_listener(struct llc_sap *sap,
513 struct sock *rc; 537 struct sock *rc;
514 struct hlist_node *node; 538 struct hlist_node *node;
515 539
516 read_lock_bh(&sap->sk_list.lock); 540 read_lock(&sap->sk_list.lock);
517 sk_for_each(rc, node, &sap->sk_list.list) { 541 sk_for_each(rc, node, &sap->sk_list.list) {
518 struct llc_sock *llc = llc_sk(rc); 542 struct llc_sock *llc = llc_sk(rc);
519 543
@@ -527,10 +551,19 @@ static struct sock *llc_lookup_listener(struct llc_sap *sap,
527 } 551 }
528 rc = NULL; 552 rc = NULL;
529found: 553found:
530 read_unlock_bh(&sap->sk_list.lock); 554 read_unlock(&sap->sk_list.lock);
531 return rc; 555 return rc;
532} 556}
533 557
558static struct sock *__llc_lookup(struct llc_sap *sap,
559 struct llc_addr *daddr,
560 struct llc_addr *laddr)
561{
562 struct sock *sk = __llc_lookup_established(sap, daddr, laddr);
563
564 return sk ? : llc_lookup_listener(sap, laddr);
565}
566
534/** 567/**
535 * llc_data_accept_state - designates if in this state data can be sent. 568 * llc_data_accept_state - designates if in this state data can be sent.
536 * @state: state of connection. 569 * @state: state of connection.
@@ -544,14 +577,14 @@ u8 llc_data_accept_state(u8 state)
544} 577}
545 578
546/** 579/**
547 * find_next_offset - finds offset for next category of transitions 580 * llc_find_next_offset - finds offset for next category of transitions
548 * @state: state table. 581 * @state: state table.
549 * @offset: start offset. 582 * @offset: start offset.
550 * 583 *
551 * Finds offset of next category of transitions in transition table. 584 * Finds offset of next category of transitions in transition table.
552 * Returns the start index of next category. 585 * Returns the start index of next category.
553 */ 586 */
554static u16 find_next_offset(struct llc_conn_state *state, u16 offset) 587static u16 __init llc_find_next_offset(struct llc_conn_state *state, u16 offset)
555{ 588{
556 u16 cnt = 0; 589 u16 cnt = 0;
557 struct llc_conn_state_trans **next_trans; 590 struct llc_conn_state_trans **next_trans;
@@ -578,8 +611,8 @@ void __init llc_build_offset_table(void)
578 next_offset = 0; 611 next_offset = 0;
579 for (ev_type = 0; ev_type < NBR_CONN_EV; ev_type++) { 612 for (ev_type = 0; ev_type < NBR_CONN_EV; ev_type++) {
580 llc_offset_table[state][ev_type] = next_offset; 613 llc_offset_table[state][ev_type] = next_offset;
581 next_offset += find_next_offset(curr_state, 614 next_offset += llc_find_next_offset(curr_state,
582 next_offset) + 1; 615 next_offset) + 1;
583 } 616 }
584 } 617 }
585} 618}
@@ -623,6 +656,7 @@ static int llc_find_offset(int state, int ev_type)
623 */ 656 */
624void llc_sap_add_socket(struct llc_sap *sap, struct sock *sk) 657void llc_sap_add_socket(struct llc_sap *sap, struct sock *sk)
625{ 658{
659 llc_sap_hold(sap);
626 write_lock_bh(&sap->sk_list.lock); 660 write_lock_bh(&sap->sk_list.lock);
627 llc_sk(sk)->sap = sap; 661 llc_sk(sk)->sap = sap;
628 sk_add_node(sk, &sap->sk_list.list); 662 sk_add_node(sk, &sap->sk_list.list);
@@ -642,6 +676,7 @@ void llc_sap_remove_socket(struct llc_sap *sap, struct sock *sk)
642 write_lock_bh(&sap->sk_list.lock); 676 write_lock_bh(&sap->sk_list.lock);
643 sk_del_node_init(sk); 677 sk_del_node_init(sk);
644 write_unlock_bh(&sap->sk_list.lock); 678 write_unlock_bh(&sap->sk_list.lock);
679 llc_sap_put(sap);
645} 680}
646 681
647/** 682/**
@@ -654,15 +689,34 @@ void llc_sap_remove_socket(struct llc_sap *sap, struct sock *sk)
654static int llc_conn_rcv(struct sock* sk, struct sk_buff *skb) 689static int llc_conn_rcv(struct sock* sk, struct sk_buff *skb)
655{ 690{
656 struct llc_conn_state_ev *ev = llc_conn_ev(skb); 691 struct llc_conn_state_ev *ev = llc_conn_ev(skb);
657 struct llc_sock *llc = llc_sk(sk);
658 692
659 if (!llc->dev)
660 llc->dev = skb->dev;
661 ev->type = LLC_CONN_EV_TYPE_PDU; 693 ev->type = LLC_CONN_EV_TYPE_PDU;
662 ev->reason = 0; 694 ev->reason = 0;
663 return llc_conn_state_process(sk, skb); 695 return llc_conn_state_process(sk, skb);
664} 696}
665 697
698static struct sock *llc_create_incoming_sock(struct sock *sk,
699 struct net_device *dev,
700 struct llc_addr *saddr,
701 struct llc_addr *daddr)
702{
703 struct sock *newsk = llc_sk_alloc(sk->sk_family, GFP_ATOMIC,
704 sk->sk_prot);
705 struct llc_sock *newllc, *llc = llc_sk(sk);
706
707 if (!newsk)
708 goto out;
709 newllc = llc_sk(newsk);
710 memcpy(&newllc->laddr, daddr, sizeof(newllc->laddr));
711 memcpy(&newllc->daddr, saddr, sizeof(newllc->daddr));
712 newllc->dev = dev;
713 dev_hold(dev);
714 llc_sap_add_socket(llc->sap, newsk);
715 llc_sap_hold(llc->sap);
716out:
717 return newsk;
718}
719
666void llc_conn_handler(struct llc_sap *sap, struct sk_buff *skb) 720void llc_conn_handler(struct llc_sap *sap, struct sk_buff *skb)
667{ 721{
668 struct llc_addr saddr, daddr; 722 struct llc_addr saddr, daddr;
@@ -673,35 +727,35 @@ void llc_conn_handler(struct llc_sap *sap, struct sk_buff *skb)
673 llc_pdu_decode_da(skb, daddr.mac); 727 llc_pdu_decode_da(skb, daddr.mac);
674 llc_pdu_decode_dsap(skb, &daddr.lsap); 728 llc_pdu_decode_dsap(skb, &daddr.lsap);
675 729
676 sk = llc_lookup_established(sap, &saddr, &daddr); 730 sk = __llc_lookup(sap, &saddr, &daddr);
677 if (!sk) { 731 if (!sk)
732 goto drop;
733
734 bh_lock_sock(sk);
735 /*
736 * This has to be done here and not at the upper layer ->accept
737 * method because of the way the PROCOM state machine works:
738 * it needs to set several state variables (see, for instance,
739 * llc_adm_actions_2 in net/llc/llc_c_st.c) and send a packet to
740 * the originator of the new connection, and this state has to be
741 * in the newly created struct sock private area. -acme
742 */
743 if (unlikely(sk->sk_state == TCP_LISTEN)) {
744 struct sock *newsk = llc_create_incoming_sock(sk, skb->dev,
745 &saddr, &daddr);
746 if (!newsk)
747 goto drop_unlock;
748 skb_set_owner_r(skb, newsk);
749 } else {
678 /* 750 /*
679 * Didn't find an active connection; verify if there 751 * Can't be skb_set_owner_r, this will be done at the
680 * is a listening socket for this llc addr 752 * llc_conn_state_process function, later on, when we will use
753 * skb_queue_rcv_skb to send it to upper layers, this is
754 * another trick required to cope with how the PROCOM state
755 * machine works. -acme
681 */ 756 */
682 struct llc_sock *llc;
683 struct sock *parent = llc_lookup_listener(sap, &daddr);
684
685 if (!parent) {
686 dprintk("llc_lookup_listener failed!\n");
687 goto drop;
688 }
689
690 sk = llc_sk_alloc(parent->sk_family, GFP_ATOMIC, parent->sk_prot);
691 if (!sk) {
692 sock_put(parent);
693 goto drop;
694 }
695 llc = llc_sk(sk);
696 memcpy(&llc->laddr, &daddr, sizeof(llc->laddr));
697 memcpy(&llc->daddr, &saddr, sizeof(llc->daddr));
698 llc_sap_add_socket(sap, sk);
699 sock_hold(sk);
700 sock_put(parent);
701 skb->sk = parent;
702 } else
703 skb->sk = sk; 757 skb->sk = sk;
704 bh_lock_sock(sk); 758 }
705 if (!sock_owned_by_user(sk)) 759 if (!sock_owned_by_user(sk))
706 llc_conn_rcv(sk, skb); 760 llc_conn_rcv(sk, skb);
707 else { 761 else {
@@ -709,11 +763,16 @@ void llc_conn_handler(struct llc_sap *sap, struct sk_buff *skb)
709 llc_set_backlog_type(skb, LLC_PACKET); 763 llc_set_backlog_type(skb, LLC_PACKET);
710 sk_add_backlog(sk, skb); 764 sk_add_backlog(sk, skb);
711 } 765 }
766out:
712 bh_unlock_sock(sk); 767 bh_unlock_sock(sk);
713 sock_put(sk); 768 sock_put(sk);
714 return; 769 return;
715drop: 770drop:
716 kfree_skb(skb); 771 kfree_skb(skb);
772 return;
773drop_unlock:
774 kfree_skb(skb);
775 goto out;
717} 776}
718 777
719#undef LLC_REFCNT_DEBUG 778#undef LLC_REFCNT_DEBUG
@@ -722,32 +781,6 @@ static atomic_t llc_sock_nr;
722#endif 781#endif
723 782
724/** 783/**
725 * llc_release_sockets - releases all sockets in a sap
726 * @sap: sap to release its sockets
727 *
728 * Releases all connections of a sap. Returns 0 if all actions complete
729 * successfully, nonzero otherwise
730 */
731int llc_release_sockets(struct llc_sap *sap)
732{
733 int rc = 0;
734 struct sock *sk;
735 struct hlist_node *node;
736
737 write_lock_bh(&sap->sk_list.lock);
738
739 sk_for_each(sk, node, &sap->sk_list.list) {
740 llc_sk(sk)->state = LLC_CONN_STATE_TEMP;
741
742 if (llc_send_disc(sk))
743 rc = 1;
744 }
745
746 write_unlock_bh(&sap->sk_list.lock);
747 return rc;
748}
749
750/**
751 * llc_backlog_rcv - Processes rx frames and expired timers. 784 * llc_backlog_rcv - Processes rx frames and expired timers.
752 * @sk: LLC sock (p8022 connection) 785 * @sk: LLC sock (p8022 connection)
753 * @skb: queued rx frame or event 786 * @skb: queued rx frame or event
@@ -762,14 +795,14 @@ static int llc_backlog_rcv(struct sock *sk, struct sk_buff *skb)
762 int rc = 0; 795 int rc = 0;
763 struct llc_sock *llc = llc_sk(sk); 796 struct llc_sock *llc = llc_sk(sk);
764 797
765 if (llc_backlog_type(skb) == LLC_PACKET) { 798 if (likely(llc_backlog_type(skb) == LLC_PACKET)) {
766 if (llc->state > 1) /* not closed */ 799 if (likely(llc->state > 1)) /* not closed */
767 rc = llc_conn_rcv(sk, skb); 800 rc = llc_conn_rcv(sk, skb);
768 else 801 else
769 goto out_kfree_skb; 802 goto out_kfree_skb;
770 } else if (llc_backlog_type(skb) == LLC_EVENT) { 803 } else if (llc_backlog_type(skb) == LLC_EVENT) {
771 /* timer expiration event */ 804 /* timer expiration event */
772 if (llc->state > 1) /* not closed */ 805 if (likely(llc->state > 1)) /* not closed */
773 rc = llc_conn_state_process(sk, skb); 806 rc = llc_conn_state_process(sk, skb);
774 else 807 else
775 goto out_kfree_skb; 808 goto out_kfree_skb;
@@ -799,22 +832,22 @@ static void llc_sk_init(struct sock* sk)
799 llc->dec_step = llc->connect_step = 1; 832 llc->dec_step = llc->connect_step = 1;
800 833
801 init_timer(&llc->ack_timer.timer); 834 init_timer(&llc->ack_timer.timer);
802 llc->ack_timer.expire = LLC_ACK_TIME; 835 llc->ack_timer.expire = sysctl_llc2_ack_timeout;
803 llc->ack_timer.timer.data = (unsigned long)sk; 836 llc->ack_timer.timer.data = (unsigned long)sk;
804 llc->ack_timer.timer.function = llc_conn_ack_tmr_cb; 837 llc->ack_timer.timer.function = llc_conn_ack_tmr_cb;
805 838
806 init_timer(&llc->pf_cycle_timer.timer); 839 init_timer(&llc->pf_cycle_timer.timer);
807 llc->pf_cycle_timer.expire = LLC_P_TIME; 840 llc->pf_cycle_timer.expire = sysctl_llc2_p_timeout;
808 llc->pf_cycle_timer.timer.data = (unsigned long)sk; 841 llc->pf_cycle_timer.timer.data = (unsigned long)sk;
809 llc->pf_cycle_timer.timer.function = llc_conn_pf_cycle_tmr_cb; 842 llc->pf_cycle_timer.timer.function = llc_conn_pf_cycle_tmr_cb;
810 843
811 init_timer(&llc->rej_sent_timer.timer); 844 init_timer(&llc->rej_sent_timer.timer);
812 llc->rej_sent_timer.expire = LLC_REJ_TIME; 845 llc->rej_sent_timer.expire = sysctl_llc2_rej_timeout;
813 llc->rej_sent_timer.timer.data = (unsigned long)sk; 846 llc->rej_sent_timer.timer.data = (unsigned long)sk;
814 llc->rej_sent_timer.timer.function = llc_conn_rej_tmr_cb; 847 llc->rej_sent_timer.timer.function = llc_conn_rej_tmr_cb;
815 848
816 init_timer(&llc->busy_state_timer.timer); 849 init_timer(&llc->busy_state_timer.timer);
817 llc->busy_state_timer.expire = LLC_BUSY_TIME; 850 llc->busy_state_timer.expire = sysctl_llc2_busy_timeout;
818 llc->busy_state_timer.timer.data = (unsigned long)sk; 851 llc->busy_state_timer.timer.data = (unsigned long)sk;
819 llc->busy_state_timer.timer.function = llc_conn_busy_tmr_cb; 852 llc->busy_state_timer.timer.function = llc_conn_busy_tmr_cb;
820 853
@@ -834,7 +867,8 @@ static void llc_sk_init(struct sock* sk)
834 * Allocates a LLC sock and initializes it. Returns the new LLC sock 867 * Allocates a LLC sock and initializes it. Returns the new LLC sock
835 * or %NULL if there's no memory available for one 868 * or %NULL if there's no memory available for one
836 */ 869 */
837struct sock *llc_sk_alloc(int family, int priority, struct proto *prot) 870struct sock *llc_sk_alloc(int family, unsigned int __nocast priority,
871 struct proto *prot)
838{ 872{
839 struct sock *sk = sk_alloc(family, priority, prot, 1); 873 struct sock *sk = sk_alloc(family, priority, prot, 1);
840 874
diff --git a/net/llc/llc_core.c b/net/llc/llc_core.c
index 9727455bf0e7..ab0fcd32fd84 100644
--- a/net/llc/llc_core.c
+++ b/net/llc/llc_core.c
@@ -40,6 +40,7 @@ static struct llc_sap *llc_sap_alloc(void)
40 sap->state = LLC_SAP_STATE_ACTIVE; 40 sap->state = LLC_SAP_STATE_ACTIVE;
41 memcpy(sap->laddr.mac, llc_station_mac_sa, ETH_ALEN); 41 memcpy(sap->laddr.mac, llc_station_mac_sa, ETH_ALEN);
42 rwlock_init(&sap->sk_list.lock); 42 rwlock_init(&sap->sk_list.lock);
43 atomic_set(&sap->refcnt, 1);
43 } 44 }
44 return sap; 45 return sap;
45} 46}
@@ -52,9 +53,7 @@ static struct llc_sap *llc_sap_alloc(void)
52 */ 53 */
53static void llc_add_sap(struct llc_sap *sap) 54static void llc_add_sap(struct llc_sap *sap)
54{ 55{
55 write_lock_bh(&llc_sap_list_lock);
56 list_add_tail(&sap->node, &llc_sap_list); 56 list_add_tail(&sap->node, &llc_sap_list);
57 write_unlock_bh(&llc_sap_list_lock);
58} 57}
59 58
60/** 59/**
@@ -70,11 +69,25 @@ static void llc_del_sap(struct llc_sap *sap)
70 write_unlock_bh(&llc_sap_list_lock); 69 write_unlock_bh(&llc_sap_list_lock);
71} 70}
72 71
72static struct llc_sap *__llc_sap_find(unsigned char sap_value)
73{
74 struct llc_sap* sap;
75
76 list_for_each_entry(sap, &llc_sap_list, node)
77 if (sap->laddr.lsap == sap_value)
78 goto out;
79 sap = NULL;
80out:
81 return sap;
82}
83
73/** 84/**
74 * llc_sap_find - searchs a SAP in station 85 * llc_sap_find - searchs a SAP in station
75 * @sap_value: sap to be found 86 * @sap_value: sap to be found
76 * 87 *
77 * Searchs for a sap in the sap list of the LLC's station upon the sap ID. 88 * Searchs for a sap in the sap list of the LLC's station upon the sap ID.
89 * If the sap is found it will be refcounted and the user will have to do
90 * a llc_sap_put after use.
78 * Returns the sap or %NULL if not found. 91 * Returns the sap or %NULL if not found.
79 */ 92 */
80struct llc_sap *llc_sap_find(unsigned char sap_value) 93struct llc_sap *llc_sap_find(unsigned char sap_value)
@@ -82,11 +95,9 @@ struct llc_sap *llc_sap_find(unsigned char sap_value)
82 struct llc_sap* sap; 95 struct llc_sap* sap;
83 96
84 read_lock_bh(&llc_sap_list_lock); 97 read_lock_bh(&llc_sap_list_lock);
85 list_for_each_entry(sap, &llc_sap_list, node) 98 sap = __llc_sap_find(sap_value);
86 if (sap->laddr.lsap == sap_value) 99 if (sap)
87 goto out; 100 llc_sap_hold(sap);
88 sap = NULL;
89out:
90 read_unlock_bh(&llc_sap_list_lock); 101 read_unlock_bh(&llc_sap_list_lock);
91 return sap; 102 return sap;
92} 103}
@@ -106,19 +117,20 @@ struct llc_sap *llc_sap_open(unsigned char lsap,
106 struct packet_type *pt, 117 struct packet_type *pt,
107 struct net_device *orig_dev)) 118 struct net_device *orig_dev))
108{ 119{
109 struct llc_sap *sap = llc_sap_find(lsap); 120 struct llc_sap *sap = NULL;
110 121
111 if (sap) { /* SAP already exists */ 122 write_lock_bh(&llc_sap_list_lock);
112 sap = NULL; 123 if (__llc_sap_find(lsap)) /* SAP already exists */
113 goto out; 124 goto out;
114 }
115 sap = llc_sap_alloc(); 125 sap = llc_sap_alloc();
116 if (!sap) 126 if (!sap)
117 goto out; 127 goto out;
118 sap->laddr.lsap = lsap; 128 sap->laddr.lsap = lsap;
119 sap->rcv_func = func; 129 sap->rcv_func = func;
130 llc_sap_hold(sap);
120 llc_add_sap(sap); 131 llc_add_sap(sap);
121out: 132out:
133 write_unlock_bh(&llc_sap_list_lock);
122 return sap; 134 return sap;
123} 135}
124 136
diff --git a/net/llc/llc_if.c b/net/llc/llc_if.c
index 0f84f66018e4..ba90f7f0801a 100644
--- a/net/llc/llc_if.c
+++ b/net/llc/llc_if.c
@@ -47,14 +47,11 @@ int llc_build_and_send_pkt(struct sock *sk, struct sk_buff *skb)
47 int rc = -ECONNABORTED; 47 int rc = -ECONNABORTED;
48 struct llc_sock *llc = llc_sk(sk); 48 struct llc_sock *llc = llc_sk(sk);
49 49
50 if (llc->state == LLC_CONN_STATE_ADM) 50 if (unlikely(llc->state == LLC_CONN_STATE_ADM))
51 goto out; 51 goto out;
52 rc = -EBUSY; 52 rc = -EBUSY;
53 if (llc_data_accept_state(llc->state)) { /* data_conn_refuse */ 53 if (unlikely(llc_data_accept_state(llc->state) || /* data_conn_refuse */
54 llc->failed_data_req = 1; 54 llc->p_flag)) {
55 goto out;
56 }
57 if (llc->p_flag) {
58 llc->failed_data_req = 1; 55 llc->failed_data_req = 1;
59 goto out; 56 goto out;
60 } 57 }
@@ -110,6 +107,7 @@ int llc_establish_connection(struct sock *sk, u8 *lmac, u8 *dmac, u8 dsap)
110 ev->type = LLC_CONN_EV_TYPE_PRIM; 107 ev->type = LLC_CONN_EV_TYPE_PRIM;
111 ev->prim = LLC_CONN_PRIM; 108 ev->prim = LLC_CONN_PRIM;
112 ev->prim_type = LLC_PRIM_TYPE_REQ; 109 ev->prim_type = LLC_PRIM_TYPE_REQ;
110 skb_set_owner_w(skb, sk);
113 rc = llc_conn_state_process(sk, skb); 111 rc = llc_conn_state_process(sk, skb);
114 } 112 }
115out_put: 113out_put:
@@ -144,6 +142,7 @@ int llc_send_disc(struct sock *sk)
144 skb = alloc_skb(0, GFP_ATOMIC); 142 skb = alloc_skb(0, GFP_ATOMIC);
145 if (!skb) 143 if (!skb)
146 goto out; 144 goto out;
145 skb_set_owner_w(skb, sk);
147 sk->sk_state = TCP_CLOSING; 146 sk->sk_state = TCP_CLOSING;
148 ev = llc_conn_ev(skb); 147 ev = llc_conn_ev(skb);
149 ev->type = LLC_CONN_EV_TYPE_PRIM; 148 ev->type = LLC_CONN_EV_TYPE_PRIM;
diff --git a/net/llc/llc_input.c b/net/llc/llc_input.c
index 13b46240b7a1..8f3addf0724c 100644
--- a/net/llc/llc_input.c
+++ b/net/llc/llc_input.c
@@ -99,15 +99,19 @@ out:
99static inline int llc_fixup_skb(struct sk_buff *skb) 99static inline int llc_fixup_skb(struct sk_buff *skb)
100{ 100{
101 u8 llc_len = 2; 101 u8 llc_len = 2;
102 struct llc_pdu_sn *pdu; 102 struct llc_pdu_un *pdu;
103 103
104 if (!pskb_may_pull(skb, sizeof(*pdu))) 104 if (unlikely(!pskb_may_pull(skb, sizeof(*pdu))))
105 return 0; 105 return 0;
106 106
107 pdu = (struct llc_pdu_sn *)skb->data; 107 pdu = (struct llc_pdu_un *)skb->data;
108 if ((pdu->ctrl_1 & LLC_PDU_TYPE_MASK) == LLC_PDU_TYPE_U) 108 if ((pdu->ctrl_1 & LLC_PDU_TYPE_MASK) == LLC_PDU_TYPE_U)
109 llc_len = 1; 109 llc_len = 1;
110 llc_len += 2; 110 llc_len += 2;
111
112 if (unlikely(!pskb_may_pull(skb, llc_len)))
113 return 0;
114
111 skb->h.raw += llc_len; 115 skb->h.raw += llc_len;
112 skb_pull(skb, llc_len); 116 skb_pull(skb, llc_len);
113 if (skb->protocol == htons(ETH_P_802_2)) { 117 if (skb->protocol == htons(ETH_P_802_2)) {
@@ -166,17 +170,22 @@ int llc_rcv(struct sk_buff *skb, struct net_device *dev,
166 */ 170 */
167 if (sap->rcv_func) { 171 if (sap->rcv_func) {
168 sap->rcv_func(skb, dev, pt, orig_dev); 172 sap->rcv_func(skb, dev, pt, orig_dev);
169 goto out; 173 goto out_put;
170 } 174 }
171 dest = llc_pdu_type(skb); 175 dest = llc_pdu_type(skb);
172 if (unlikely(!dest || !llc_type_handlers[dest - 1])) 176 if (unlikely(!dest || !llc_type_handlers[dest - 1]))
173 goto drop; 177 goto drop_put;
174 llc_type_handlers[dest - 1](sap, skb); 178 llc_type_handlers[dest - 1](sap, skb);
179out_put:
180 llc_sap_put(sap);
175out: 181out:
176 return 0; 182 return 0;
177drop: 183drop:
178 kfree_skb(skb); 184 kfree_skb(skb);
179 goto out; 185 goto out;
186drop_put:
187 kfree_skb(skb);
188 goto out_put;
180handle_station: 189handle_station:
181 if (!llc_station_handler) 190 if (!llc_station_handler)
182 goto drop; 191 goto drop;
diff --git a/net/llc/llc_output.c b/net/llc/llc_output.c
index ab5784cf163e..b4d55b6abb67 100644
--- a/net/llc/llc_output.c
+++ b/net/llc/llc_output.c
@@ -98,7 +98,7 @@ int llc_build_and_send_ui_pkt(struct llc_sap *sap, struct sk_buff *skb,
98 dsap, LLC_PDU_CMD); 98 dsap, LLC_PDU_CMD);
99 llc_pdu_init_as_ui_cmd(skb); 99 llc_pdu_init_as_ui_cmd(skb);
100 rc = llc_mac_hdr_init(skb, skb->dev->dev_addr, dmac); 100 rc = llc_mac_hdr_init(skb, skb->dev->dev_addr, dmac);
101 if (!rc) 101 if (likely(!rc))
102 rc = dev_queue_xmit(skb); 102 rc = dev_queue_xmit(skb);
103 return rc; 103 return rc;
104} 104}
diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
index 36e8db3fa1a2..bd531cb235a7 100644
--- a/net/llc/llc_proc.c
+++ b/net/llc/llc_proc.c
@@ -134,7 +134,7 @@ static int llc_seq_socket_show(struct seq_file *seq, void *v)
134 llc_ui_format_mac(seq, llc->daddr.mac); 134 llc_ui_format_mac(seq, llc->daddr.mac);
135 seq_printf(seq, "@%02X %8d %8d %2d %3d %4d\n", llc->daddr.lsap, 135 seq_printf(seq, "@%02X %8d %8d %2d %3d %4d\n", llc->daddr.lsap,
136 atomic_read(&sk->sk_wmem_alloc), 136 atomic_read(&sk->sk_wmem_alloc),
137 atomic_read(&sk->sk_rmem_alloc), 137 atomic_read(&sk->sk_rmem_alloc) - llc->copied_seq,
138 sk->sk_state, 138 sk->sk_state,
139 sk->sk_socket ? SOCK_INODE(sk->sk_socket)->i_uid : -1, 139 sk->sk_socket ? SOCK_INODE(sk->sk_socket)->i_uid : -1,
140 llc->link); 140 llc->link);
diff --git a/net/llc/llc_s_ac.c b/net/llc/llc_s_ac.c
index ed8ba7de6122..bb3580fb8cfe 100644
--- a/net/llc/llc_s_ac.c
+++ b/net/llc/llc_s_ac.c
@@ -58,7 +58,7 @@ int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb)
58 ev->daddr.lsap, LLC_PDU_CMD); 58 ev->daddr.lsap, LLC_PDU_CMD);
59 llc_pdu_init_as_ui_cmd(skb); 59 llc_pdu_init_as_ui_cmd(skb);
60 rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac); 60 rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac);
61 if (!rc) 61 if (likely(!rc))
62 rc = dev_queue_xmit(skb); 62 rc = dev_queue_xmit(skb);
63 return rc; 63 return rc;
64} 64}
@@ -81,7 +81,7 @@ int llc_sap_action_send_xid_c(struct llc_sap *sap, struct sk_buff *skb)
81 ev->daddr.lsap, LLC_PDU_CMD); 81 ev->daddr.lsap, LLC_PDU_CMD);
82 llc_pdu_init_as_xid_cmd(skb, LLC_XID_NULL_CLASS_2, 0); 82 llc_pdu_init_as_xid_cmd(skb, LLC_XID_NULL_CLASS_2, 0);
83 rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac); 83 rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac);
84 if (!rc) 84 if (likely(!rc))
85 rc = dev_queue_xmit(skb); 85 rc = dev_queue_xmit(skb);
86 return rc; 86 return rc;
87} 87}
@@ -103,15 +103,14 @@ int llc_sap_action_send_xid_r(struct llc_sap *sap, struct sk_buff *skb)
103 llc_pdu_decode_sa(skb, mac_da); 103 llc_pdu_decode_sa(skb, mac_da);
104 llc_pdu_decode_da(skb, mac_sa); 104 llc_pdu_decode_da(skb, mac_sa);
105 llc_pdu_decode_ssap(skb, &dsap); 105 llc_pdu_decode_ssap(skb, &dsap);
106 nskb = llc_alloc_frame(); 106 nskb = llc_alloc_frame(NULL, skb->dev);
107 if (!nskb) 107 if (!nskb)
108 goto out; 108 goto out;
109 nskb->dev = skb->dev;
110 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, dsap, 109 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, dsap,
111 LLC_PDU_RSP); 110 LLC_PDU_RSP);
112 llc_pdu_init_as_xid_rsp(nskb, LLC_XID_NULL_CLASS_2, 0); 111 llc_pdu_init_as_xid_rsp(nskb, LLC_XID_NULL_CLASS_2, 0);
113 rc = llc_mac_hdr_init(nskb, mac_sa, mac_da); 112 rc = llc_mac_hdr_init(nskb, mac_sa, mac_da);
114 if (!rc) 113 if (likely(!rc))
115 rc = dev_queue_xmit(nskb); 114 rc = dev_queue_xmit(nskb);
116out: 115out:
117 return rc; 116 return rc;
@@ -135,7 +134,7 @@ int llc_sap_action_send_test_c(struct llc_sap *sap, struct sk_buff *skb)
135 ev->daddr.lsap, LLC_PDU_CMD); 134 ev->daddr.lsap, LLC_PDU_CMD);
136 llc_pdu_init_as_test_cmd(skb); 135 llc_pdu_init_as_test_cmd(skb);
137 rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac); 136 rc = llc_mac_hdr_init(skb, ev->saddr.mac, ev->daddr.mac);
138 if (!rc) 137 if (likely(!rc))
139 rc = dev_queue_xmit(skb); 138 rc = dev_queue_xmit(skb);
140 return rc; 139 return rc;
141} 140}
@@ -149,15 +148,14 @@ int llc_sap_action_send_test_r(struct llc_sap *sap, struct sk_buff *skb)
149 llc_pdu_decode_sa(skb, mac_da); 148 llc_pdu_decode_sa(skb, mac_da);
150 llc_pdu_decode_da(skb, mac_sa); 149 llc_pdu_decode_da(skb, mac_sa);
151 llc_pdu_decode_ssap(skb, &dsap); 150 llc_pdu_decode_ssap(skb, &dsap);
152 nskb = llc_alloc_frame(); 151 nskb = llc_alloc_frame(NULL, skb->dev);
153 if (!nskb) 152 if (!nskb)
154 goto out; 153 goto out;
155 nskb->dev = skb->dev;
156 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, dsap, 154 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap, dsap,
157 LLC_PDU_RSP); 155 LLC_PDU_RSP);
158 llc_pdu_init_as_test_rsp(nskb, skb); 156 llc_pdu_init_as_test_rsp(nskb, skb);
159 rc = llc_mac_hdr_init(nskb, mac_sa, mac_da); 157 rc = llc_mac_hdr_init(nskb, mac_sa, mac_da);
160 if (!rc) 158 if (likely(!rc))
161 rc = dev_queue_xmit(nskb); 159 rc = dev_queue_xmit(nskb);
162out: 160out:
163 return rc; 161 return rc;
diff --git a/net/llc/llc_sap.c b/net/llc/llc_sap.c
index 34228ef14985..4029ceee9b91 100644
--- a/net/llc/llc_sap.c
+++ b/net/llc/llc_sap.c
@@ -26,11 +26,12 @@
26 26
27/** 27/**
28 * llc_alloc_frame - allocates sk_buff for frame 28 * llc_alloc_frame - allocates sk_buff for frame
29 * @dev: network device this skb will be sent over
29 * 30 *
30 * Allocates an sk_buff for frame and initializes sk_buff fields. 31 * Allocates an sk_buff for frame and initializes sk_buff fields.
31 * Returns allocated skb or %NULL when out of memory. 32 * Returns allocated skb or %NULL when out of memory.
32 */ 33 */
33struct sk_buff *llc_alloc_frame(void) 34struct sk_buff *llc_alloc_frame(struct sock *sk, struct net_device *dev)
34{ 35{
35 struct sk_buff *skb = alloc_skb(128, GFP_ATOMIC); 36 struct sk_buff *skb = alloc_skb(128, GFP_ATOMIC);
36 37
@@ -38,18 +39,23 @@ struct sk_buff *llc_alloc_frame(void)
38 skb_reserve(skb, 50); 39 skb_reserve(skb, 50);
39 skb->nh.raw = skb->h.raw = skb->data; 40 skb->nh.raw = skb->h.raw = skb->data;
40 skb->protocol = htons(ETH_P_802_2); 41 skb->protocol = htons(ETH_P_802_2);
41 skb->dev = dev_base->next; 42 skb->dev = dev;
42 skb->mac.raw = skb->head; 43 skb->mac.raw = skb->head;
44 if (sk != NULL)
45 skb_set_owner_w(skb, sk);
43 } 46 }
44 return skb; 47 return skb;
45} 48}
46 49
47void llc_save_primitive(struct sk_buff* skb, u8 prim) 50void llc_save_primitive(struct sock *sk, struct sk_buff* skb, u8 prim)
48{ 51{
49 struct sockaddr_llc *addr = llc_ui_skb_cb(skb); 52 struct sockaddr_llc *addr;
50 53
54 if (skb->sk->sk_type == SOCK_STREAM) /* See UNIX98 */
55 return;
51 /* save primitive for use by the user. */ 56 /* save primitive for use by the user. */
52 addr->sllc_family = skb->sk->sk_family; 57 addr = llc_ui_skb_cb(skb);
58 addr->sllc_family = sk->sk_family;
53 addr->sllc_arphrd = skb->dev->type; 59 addr->sllc_arphrd = skb->dev->type;
54 addr->sllc_test = prim == LLC_TEST_PRIM; 60 addr->sllc_test = prim == LLC_TEST_PRIM;
55 addr->sllc_xid = prim == LLC_XID_PRIM; 61 addr->sllc_xid = prim == LLC_XID_PRIM;
@@ -189,7 +195,7 @@ static void llc_sap_state_process(struct llc_sap *sap, struct sk_buff *skb)
189 if (skb->sk->sk_state == TCP_LISTEN) 195 if (skb->sk->sk_state == TCP_LISTEN)
190 kfree_skb(skb); 196 kfree_skb(skb);
191 else { 197 else {
192 llc_save_primitive(skb, ev->prim); 198 llc_save_primitive(skb->sk, skb, ev->prim);
193 199
194 /* queue skb to the user. */ 200 /* queue skb to the user. */
195 if (sock_queue_rcv_skb(skb->sk, skb)) 201 if (sock_queue_rcv_skb(skb->sk, skb))
@@ -308,7 +314,7 @@ void llc_sap_handler(struct llc_sap *sap, struct sk_buff *skb)
308 314
309 sk = llc_lookup_dgram(sap, &laddr); 315 sk = llc_lookup_dgram(sap, &laddr);
310 if (sk) { 316 if (sk) {
311 skb->sk = sk; 317 skb_set_owner_r(skb, sk);
312 llc_sap_rcv(sap, skb); 318 llc_sap_rcv(sap, skb);
313 sock_put(sk); 319 sock_put(sk);
314 } else 320 } else
diff --git a/net/llc/llc_station.c b/net/llc/llc_station.c
index 8fe48a24bad5..f37dbf8ef126 100644
--- a/net/llc/llc_station.c
+++ b/net/llc/llc_station.c
@@ -50,6 +50,10 @@ struct llc_station {
50 struct sk_buff_head mac_pdu_q; 50 struct sk_buff_head mac_pdu_q;
51}; 51};
52 52
53#define LLC_STATION_ACK_TIME (3 * HZ)
54
55int sysctl_llc_station_ack_timeout = LLC_STATION_ACK_TIME;
56
53/* Types of events (possible values in 'ev->type') */ 57/* Types of events (possible values in 'ev->type') */
54#define LLC_STATION_EV_TYPE_SIMPLE 1 58#define LLC_STATION_EV_TYPE_SIMPLE 1
55#define LLC_STATION_EV_TYPE_CONDITION 2 59#define LLC_STATION_EV_TYPE_CONDITION 2
@@ -218,7 +222,8 @@ static void llc_station_send_pdu(struct sk_buff *skb)
218 222
219static int llc_station_ac_start_ack_timer(struct sk_buff *skb) 223static int llc_station_ac_start_ack_timer(struct sk_buff *skb)
220{ 224{
221 mod_timer(&llc_main_station.ack_timer, jiffies + LLC_ACK_TIME * HZ); 225 mod_timer(&llc_main_station.ack_timer,
226 jiffies + sysctl_llc_station_ack_timeout);
222 return 0; 227 return 0;
223} 228}
224 229
@@ -249,14 +254,14 @@ static int llc_station_ac_inc_xid_r_cnt_by_1(struct sk_buff *skb)
249static int llc_station_ac_send_null_dsap_xid_c(struct sk_buff *skb) 254static int llc_station_ac_send_null_dsap_xid_c(struct sk_buff *skb)
250{ 255{
251 int rc = 1; 256 int rc = 1;
252 struct sk_buff *nskb = llc_alloc_frame(); 257 struct sk_buff *nskb = llc_alloc_frame(NULL, skb->dev);
253 258
254 if (!nskb) 259 if (!nskb)
255 goto out; 260 goto out;
256 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, 0, 0, LLC_PDU_CMD); 261 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, 0, 0, LLC_PDU_CMD);
257 llc_pdu_init_as_xid_cmd(nskb, LLC_XID_NULL_CLASS_2, 127); 262 llc_pdu_init_as_xid_cmd(nskb, LLC_XID_NULL_CLASS_2, 127);
258 rc = llc_mac_hdr_init(nskb, llc_station_mac_sa, llc_station_mac_sa); 263 rc = llc_mac_hdr_init(nskb, llc_station_mac_sa, llc_station_mac_sa);
259 if (rc) 264 if (unlikely(rc))
260 goto free; 265 goto free;
261 llc_station_send_pdu(nskb); 266 llc_station_send_pdu(nskb);
262out: 267out:
@@ -270,18 +275,17 @@ static int llc_station_ac_send_xid_r(struct sk_buff *skb)
270{ 275{
271 u8 mac_da[ETH_ALEN], dsap; 276 u8 mac_da[ETH_ALEN], dsap;
272 int rc = 1; 277 int rc = 1;
273 struct sk_buff* nskb = llc_alloc_frame(); 278 struct sk_buff* nskb = llc_alloc_frame(NULL, skb->dev);
274 279
275 if (!nskb) 280 if (!nskb)
276 goto out; 281 goto out;
277 rc = 0; 282 rc = 0;
278 nskb->dev = skb->dev;
279 llc_pdu_decode_sa(skb, mac_da); 283 llc_pdu_decode_sa(skb, mac_da);
280 llc_pdu_decode_ssap(skb, &dsap); 284 llc_pdu_decode_ssap(skb, &dsap);
281 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, 0, dsap, LLC_PDU_RSP); 285 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, 0, dsap, LLC_PDU_RSP);
282 llc_pdu_init_as_xid_rsp(nskb, LLC_XID_NULL_CLASS_2, 127); 286 llc_pdu_init_as_xid_rsp(nskb, LLC_XID_NULL_CLASS_2, 127);
283 rc = llc_mac_hdr_init(nskb, llc_station_mac_sa, mac_da); 287 rc = llc_mac_hdr_init(nskb, llc_station_mac_sa, mac_da);
284 if (rc) 288 if (unlikely(rc))
285 goto free; 289 goto free;
286 llc_station_send_pdu(nskb); 290 llc_station_send_pdu(nskb);
287out: 291out:
@@ -295,18 +299,17 @@ static int llc_station_ac_send_test_r(struct sk_buff *skb)
295{ 299{
296 u8 mac_da[ETH_ALEN], dsap; 300 u8 mac_da[ETH_ALEN], dsap;
297 int rc = 1; 301 int rc = 1;
298 struct sk_buff *nskb = llc_alloc_frame(); 302 struct sk_buff *nskb = llc_alloc_frame(NULL, skb->dev);
299 303
300 if (!nskb) 304 if (!nskb)
301 goto out; 305 goto out;
302 rc = 0; 306 rc = 0;
303 nskb->dev = skb->dev;
304 llc_pdu_decode_sa(skb, mac_da); 307 llc_pdu_decode_sa(skb, mac_da);
305 llc_pdu_decode_ssap(skb, &dsap); 308 llc_pdu_decode_ssap(skb, &dsap);
306 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, 0, dsap, LLC_PDU_RSP); 309 llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, 0, dsap, LLC_PDU_RSP);
307 llc_pdu_init_as_test_rsp(nskb, skb); 310 llc_pdu_init_as_test_rsp(nskb, skb);
308 rc = llc_mac_hdr_init(nskb, llc_station_mac_sa, mac_da); 311 rc = llc_mac_hdr_init(nskb, llc_station_mac_sa, mac_da);
309 if (rc) 312 if (unlikely(rc))
310 goto free; 313 goto free;
311 llc_station_send_pdu(nskb); 314 llc_station_send_pdu(nskb);
312out: 315out:
@@ -689,7 +692,8 @@ int __init llc_station_init(void)
689 init_timer(&llc_main_station.ack_timer); 692 init_timer(&llc_main_station.ack_timer);
690 llc_main_station.ack_timer.data = (unsigned long)&llc_main_station; 693 llc_main_station.ack_timer.data = (unsigned long)&llc_main_station;
691 llc_main_station.ack_timer.function = llc_station_ack_tmr_cb; 694 llc_main_station.ack_timer.function = llc_station_ack_tmr_cb;
692 695 llc_main_station.ack_timer.expires = jiffies +
696 sysctl_llc_station_ack_timeout;
693 skb = alloc_skb(0, GFP_ATOMIC); 697 skb = alloc_skb(0, GFP_ATOMIC);
694 if (!skb) 698 if (!skb)
695 goto out; 699 goto out;
@@ -697,7 +701,6 @@ int __init llc_station_init(void)
697 llc_set_station_handler(llc_station_rcv); 701 llc_set_station_handler(llc_station_rcv);
698 ev = llc_station_ev(skb); 702 ev = llc_station_ev(skb);
699 memset(ev, 0, sizeof(*ev)); 703 memset(ev, 0, sizeof(*ev));
700 llc_main_station.ack_timer.expires = jiffies + 3 * HZ;
701 llc_main_station.maximum_retry = 1; 704 llc_main_station.maximum_retry = 1;
702 llc_main_station.state = LLC_STATION_STATE_DOWN; 705 llc_main_station.state = LLC_STATION_STATE_DOWN;
703 ev->type = LLC_STATION_EV_TYPE_SIMPLE; 706 ev->type = LLC_STATION_EV_TYPE_SIMPLE;
diff --git a/net/llc/sysctl_net_llc.c b/net/llc/sysctl_net_llc.c
new file mode 100644
index 000000000000..d1eaddb13633
--- /dev/null
+++ b/net/llc/sysctl_net_llc.c
@@ -0,0 +1,131 @@
1/*
2 * sysctl_net_llc.c: sysctl interface to LLC net subsystem.
3 *
4 * Arnaldo Carvalho de Melo <acme@conectiva.com.br>
5 */
6
7#include <linux/config.h>
8#include <linux/mm.h>
9#include <linux/init.h>
10#include <linux/sysctl.h>
11#include <net/llc.h>
12
13#ifndef CONFIG_SYSCTL
14#error This file should not be compiled without CONFIG_SYSCTL defined
15#endif
16
17static struct ctl_table llc2_timeout_table[] = {
18 {
19 .ctl_name = NET_LLC2_ACK_TIMEOUT,
20 .procname = "ack",
21 .data = &sysctl_llc2_ack_timeout,
22 .maxlen = sizeof(long),
23 .mode = 0644,
24 .proc_handler = &proc_dointvec_jiffies,
25 .strategy = &sysctl_jiffies,
26 },
27 {
28 .ctl_name = NET_LLC2_BUSY_TIMEOUT,
29 .procname = "busy",
30 .data = &sysctl_llc2_busy_timeout,
31 .maxlen = sizeof(long),
32 .mode = 0644,
33 .proc_handler = &proc_dointvec_jiffies,
34 .strategy = &sysctl_jiffies,
35 },
36 {
37 .ctl_name = NET_LLC2_P_TIMEOUT,
38 .procname = "p",
39 .data = &sysctl_llc2_p_timeout,
40 .maxlen = sizeof(long),
41 .mode = 0644,
42 .proc_handler = &proc_dointvec_jiffies,
43 .strategy = &sysctl_jiffies,
44 },
45 {
46 .ctl_name = NET_LLC2_REJ_TIMEOUT,
47 .procname = "rej",
48 .data = &sysctl_llc2_rej_timeout,
49 .maxlen = sizeof(long),
50 .mode = 0644,
51 .proc_handler = &proc_dointvec_jiffies,
52 .strategy = &sysctl_jiffies,
53 },
54 { 0 },
55};
56
57static struct ctl_table llc_station_table[] = {
58 {
59 .ctl_name = NET_LLC_STATION_ACK_TIMEOUT,
60 .procname = "ack_timeout",
61 .data = &sysctl_llc_station_ack_timeout,
62 .maxlen = sizeof(long),
63 .mode = 0644,
64 .proc_handler = &proc_dointvec_jiffies,
65 .strategy = &sysctl_jiffies,
66 },
67 { 0 },
68};
69
70static struct ctl_table llc2_dir_timeout_table[] = {
71 {
72 .ctl_name = NET_LLC2,
73 .procname = "timeout",
74 .mode = 0555,
75 .child = llc2_timeout_table,
76 },
77 { 0 },
78};
79
80static struct ctl_table llc_table[] = {
81 {
82 .ctl_name = NET_LLC2,
83 .procname = "llc2",
84 .mode = 0555,
85 .child = llc2_dir_timeout_table,
86 },
87 {
88 .ctl_name = NET_LLC_STATION,
89 .procname = "station",
90 .mode = 0555,
91 .child = llc_station_table,
92 },
93 { 0 },
94};
95
96static struct ctl_table llc_dir_table[] = {
97 {
98 .ctl_name = NET_LLC,
99 .procname = "llc",
100 .mode = 0555,
101 .child = llc_table,
102 },
103 { 0 },
104};
105
106static struct ctl_table llc_root_table[] = {
107 {
108 .ctl_name = CTL_NET,
109 .procname = "net",
110 .mode = 0555,
111 .child = llc_dir_table,
112 },
113 { 0 },
114};
115
116static struct ctl_table_header *llc_table_header;
117
118int __init llc_sysctl_init(void)
119{
120 llc_table_header = register_sysctl_table(llc_root_table, 1);
121
122 return llc_table_header ? 0 : -ENOMEM;
123}
124
125void llc_sysctl_exit(void)
126{
127 if (llc_table_header) {
128 unregister_sysctl_table(llc_table_header);
129 llc_table_header = NULL;
130 }
131}