2 * af_llc.c - LLC User Interface SAPs
4 * Functions in this module are implementation of socket based llc
5 * communications for the Linux operating system. Support of llc class
6 * one and class two is provided via SOCK_DGRAM and SOCK_STREAM
9 * An llc2 connection is (mac + sap), only one llc2 sap connection
10 * is allowed per mac. Though one sap may have multiple mac + sap
13 * Copyright (c) 2001 by Jay Schulist <jschlst@samba.org>
14 * 2002-2003 by Arnaldo Carvalho de Melo <acme@conectiva.com.br>
16 * This program can be redistributed or modified under the terms of the
17 * GNU General Public License as published by the Free Software Foundation.
18 * This program is distributed without any warranty or implied warranty
19 * of merchantability or fitness for a particular purpose.
21 * See the GNU General Public License for more details.
23 #include <linux/config.h>
24 #include <linux/compiler.h>
25 #include <linux/kernel.h>
26 #include <linux/module.h>
27 #include <linux/rtnetlink.h>
28 #include <linux/init.h>
30 #include <net/llc_sap.h>
31 #include <net/llc_pdu.h>
32 #include <net/llc_conn.h>
33 #include <net/tcp_states.h>
35 /* remember: uninitialized global data is zeroed because its in .bss */
36 static u16 llc_ui_sap_last_autoport
= LLC_SAP_DYN_START
;
37 static u16 llc_ui_sap_link_no_max
[256];
38 static struct sockaddr_llc llc_ui_addrnull
;
39 static struct proto_ops llc_ui_ops
;
41 static int llc_ui_wait_for_conn(struct sock
*sk
, long timeout
);
42 static int llc_ui_wait_for_disc(struct sock
*sk
, long timeout
);
43 static int llc_ui_wait_for_busy_core(struct sock
*sk
, long timeout
);
46 #define dprintk(args...) printk(KERN_DEBUG args)
48 #define dprintk(args...)
52 * llc_ui_next_link_no - return the next unused link number for a sap
53 * @sap: Address of sap to get link number from.
55 * Return the next unused link number for a given sap.
57 static __inline__ u16
llc_ui_next_link_no(int sap
)
59 return llc_ui_sap_link_no_max
[sap
]++;
63 * llc_proto_type - return eth protocol for ARP header type
64 * @arphrd: ARP header type.
66 * Given an ARP header type return the corresponding ethernet protocol.
68 static __inline__ u16
llc_proto_type(u16 arphrd
)
70 return arphrd
== ARPHRD_IEEE802_TR
?
71 htons(ETH_P_TR_802_2
) : htons(ETH_P_802_2
);
75 * llc_ui_addr_null - determines if a address structure is null
76 * @addr: Address to test if null.
78 static __inline__ u8
llc_ui_addr_null(struct sockaddr_llc
*addr
)
80 return !memcmp(addr
, &llc_ui_addrnull
, sizeof(*addr
));
84 * llc_ui_header_len - return length of llc header based on operation
85 * @sk: Socket which contains a valid llc socket type.
86 * @addr: Complete sockaddr_llc structure received from the user.
88 * Provide the length of the llc header depending on what kind of
89 * operation the user would like to perform and the type of socket.
90 * Returns the correct llc header length.
92 static __inline__ u8
llc_ui_header_len(struct sock
*sk
,
93 struct sockaddr_llc
*addr
)
95 u8 rc
= LLC_PDU_LEN_U
;
97 if (addr
->sllc_test
|| addr
->sllc_xid
)
99 else if (sk
->sk_type
== SOCK_STREAM
)
105 * llc_ui_send_data - send data via reliable llc2 connection
106 * @sk: Connection the socket is using.
107 * @skb: Data the user wishes to send.
108 * @addr: Source and destination fields provided by the user.
109 * @noblock: can we block waiting for data?
111 * Send data via reliable llc2 connection.
112 * Returns 0 upon success, non-zero if action did not succeed.
114 static int llc_ui_send_data(struct sock
* sk
, struct sk_buff
*skb
, int noblock
)
116 struct llc_sock
* llc
= llc_sk(sk
);
119 if (unlikely(llc_data_accept_state(llc
->state
) ||
120 llc
->remote_busy_flag
||
122 long timeout
= sock_sndtimeo(sk
, noblock
);
124 rc
= llc_ui_wait_for_busy_core(sk
, timeout
);
127 rc
= llc_build_and_send_pkt(sk
, skb
);
131 static void llc_ui_sk_init(struct socket
*sock
, struct sock
*sk
)
133 sk
->sk_type
= sock
->type
;
134 sk
->sk_sleep
= &sock
->wait
;
135 sk
->sk_socket
= sock
;
137 sock
->ops
= &llc_ui_ops
;
140 static struct proto llc_proto
= {
142 .owner
= THIS_MODULE
,
143 .obj_size
= sizeof(struct llc_sock
),
147 * llc_ui_create - alloc and init a new llc_ui socket
148 * @sock: Socket to initialize and attach allocated sk to.
151 * Allocate and initialize a new llc_ui socket, validate the user wants a
152 * socket type we have available.
153 * Returns 0 upon success, negative upon failure.
155 static int llc_ui_create(struct socket
*sock
, int protocol
)
158 int rc
= -ESOCKTNOSUPPORT
;
160 if (likely(sock
->type
== SOCK_DGRAM
|| sock
->type
== SOCK_STREAM
)) {
162 sk
= llc_sk_alloc(PF_LLC
, GFP_KERNEL
, &llc_proto
);
165 llc_ui_sk_init(sock
, sk
);
172 * llc_ui_release - shutdown socket
173 * @sock: Socket to release.
175 * Shutdown and deallocate an existing socket.
177 static int llc_ui_release(struct socket
*sock
)
179 struct sock
*sk
= sock
->sk
;
180 struct llc_sock
*llc
;
182 if (unlikely(sk
== NULL
))
187 dprintk("%s: closing local(%02X) remote(%02X)\n", __FUNCTION__
,
188 llc
->laddr
.lsap
, llc
->daddr
.lsap
);
189 if (!llc_send_disc(sk
))
190 llc_ui_wait_for_disc(sk
, sk
->sk_rcvtimeo
);
191 if (!sock_flag(sk
, SOCK_ZAPPED
))
192 llc_sap_remove_socket(llc
->sap
, sk
);
203 * llc_ui_autoport - provide dynamically allocate SAP number
205 * Provide the caller with a dynamically allocated SAP number according
206 * to the rules that are set in this function. Returns: 0, upon failure,
207 * SAP number otherwise.
209 static int llc_ui_autoport(void)
214 while (tries
< LLC_SAP_DYN_TRIES
) {
215 for (i
= llc_ui_sap_last_autoport
;
216 i
< LLC_SAP_DYN_STOP
; i
+= 2) {
217 sap
= llc_sap_find(i
);
219 llc_ui_sap_last_autoport
= i
+ 2;
224 llc_ui_sap_last_autoport
= LLC_SAP_DYN_START
;
233 * llc_ui_autobind - automatically bind a socket to a sap
234 * @sock: socket to bind
235 * @addr: address to connect to
237 * Used by llc_ui_connect and llc_ui_sendmsg when the user hasn't
238 * specifically used llc_ui_bind to bind to an specific address/sap
240 * Returns: 0 upon success, negative otherwise.
242 static int llc_ui_autobind(struct socket
*sock
, struct sockaddr_llc
*addr
)
244 struct sock
*sk
= sock
->sk
;
245 struct llc_sock
*llc
= llc_sk(sk
);
249 if (!sock_flag(sk
, SOCK_ZAPPED
))
252 llc
->dev
= dev_getfirstbyhwtype(addr
->sllc_arphrd
);
256 llc
->laddr
.lsap
= llc_ui_autoport();
257 if (!llc
->laddr
.lsap
)
259 rc
= -EBUSY
; /* some other network layer is using the sap */
260 sap
= llc_sap_open(llc
->laddr
.lsap
, NULL
);
263 memcpy(llc
->laddr
.mac
, llc
->dev
->dev_addr
, IFHWADDRLEN
);
264 memcpy(&llc
->addr
, addr
, sizeof(llc
->addr
));
265 /* assign new connection to its SAP */
266 llc_sap_add_socket(sap
, sk
);
267 sock_reset_flag(sk
, SOCK_ZAPPED
);
274 * llc_ui_bind - bind a socket to a specific address.
275 * @sock: Socket to bind an address to.
276 * @uaddr: Address the user wants the socket bound to.
277 * @addrlen: Length of the uaddr structure.
279 * Bind a socket to a specific address. For llc a user is able to bind to
280 * a specific sap only or mac + sap.
281 * If the user desires to bind to a specific mac + sap, it is possible to
282 * have multiple sap connections via multiple macs.
283 * Bind and autobind for that matter must enforce the correct sap usage
284 * otherwise all hell will break loose.
285 * Returns: 0 upon success, negative otherwise.
287 static int llc_ui_bind(struct socket
*sock
, struct sockaddr
*uaddr
, int addrlen
)
289 struct sockaddr_llc
*addr
= (struct sockaddr_llc
*)uaddr
;
290 struct sock
*sk
= sock
->sk
;
291 struct llc_sock
*llc
= llc_sk(sk
);
295 dprintk("%s: binding %02X\n", __FUNCTION__
, addr
->sllc_sap
);
296 if (unlikely(!sock_flag(sk
, SOCK_ZAPPED
) || addrlen
!= sizeof(*addr
)))
299 if (unlikely(addr
->sllc_family
!= AF_LLC
))
303 llc
->dev
= dev_getbyhwaddr(addr
->sllc_arphrd
, addr
->sllc_mac
);
307 if (!addr
->sllc_sap
) {
309 addr
->sllc_sap
= llc_ui_autoport();
313 sap
= llc_sap_find(addr
->sllc_sap
);
315 sap
= llc_sap_open(addr
->sllc_sap
, NULL
);
316 rc
= -EBUSY
; /* some other network layer is using the sap */
321 struct llc_addr laddr
, daddr
;
324 memset(&laddr
, 0, sizeof(laddr
));
325 memset(&daddr
, 0, sizeof(daddr
));
327 * FIXME: check if the the address is multicast,
328 * only SOCK_DGRAM can do this.
330 memcpy(laddr
.mac
, addr
->sllc_mac
, IFHWADDRLEN
);
331 laddr
.lsap
= addr
->sllc_sap
;
332 rc
= -EADDRINUSE
; /* mac + sap clash. */
333 ask
= llc_lookup_established(sap
, &daddr
, &laddr
);
339 llc
->laddr
.lsap
= addr
->sllc_sap
;
340 memcpy(llc
->laddr
.mac
, addr
->sllc_mac
, IFHWADDRLEN
);
341 memcpy(&llc
->addr
, addr
, sizeof(llc
->addr
));
342 /* assign new connection to its SAP */
343 llc_sap_add_socket(sap
, sk
);
344 sock_reset_flag(sk
, SOCK_ZAPPED
);
353 * llc_ui_shutdown - shutdown a connect llc2 socket.
354 * @sock: Socket to shutdown.
355 * @how: What part of the socket to shutdown.
357 * Shutdown a connected llc2 socket. Currently this function only supports
358 * shutting down both sends and receives (2), we could probably make this
359 * function such that a user can shutdown only half the connection but not
361 * Returns: 0 upon success, negative otherwise.
363 static int llc_ui_shutdown(struct socket
*sock
, int how
)
365 struct sock
*sk
= sock
->sk
;
369 if (unlikely(sk
->sk_state
!= TCP_ESTABLISHED
))
374 rc
= llc_send_disc(sk
);
376 rc
= llc_ui_wait_for_disc(sk
, sk
->sk_rcvtimeo
);
377 /* Wake up anyone sleeping in poll */
378 sk
->sk_state_change(sk
);
385 * llc_ui_connect - Connect to a remote llc2 mac + sap.
386 * @sock: Socket which will be connected to the remote destination.
387 * @uaddr: Remote and possibly the local address of the new connection.
388 * @addrlen: Size of uaddr structure.
389 * @flags: Operational flags specified by the user.
391 * Connect to a remote llc2 mac + sap. The caller must specify the
392 * destination mac and address to connect to. If the user hasn't previously
393 * called bind(2) with a smac the address of the first interface of the
394 * specified arp type will be used.
395 * This function will autobind if user did not previously call bind.
396 * Returns: 0 upon success, negative otherwise.
398 static int llc_ui_connect(struct socket
*sock
, struct sockaddr
*uaddr
,
399 int addrlen
, int flags
)
401 struct sock
*sk
= sock
->sk
;
402 struct llc_sock
*llc
= llc_sk(sk
);
403 struct sockaddr_llc
*addr
= (struct sockaddr_llc
*)uaddr
;
407 if (unlikely(addrlen
!= sizeof(*addr
)))
410 if (unlikely(addr
->sllc_family
!= AF_LLC
))
412 if (unlikely(sk
->sk_type
!= SOCK_STREAM
))
415 if (unlikely(sock
->state
== SS_CONNECTING
))
417 /* bind connection to sap if user hasn't done it. */
418 if (sock_flag(sk
, SOCK_ZAPPED
)) {
419 /* bind to sap with null dev, exclusive */
420 rc
= llc_ui_autobind(sock
, addr
);
424 llc
->daddr
.lsap
= addr
->sllc_sap
;
425 memcpy(llc
->daddr
.mac
, addr
->sllc_mac
, IFHWADDRLEN
);
426 sock
->state
= SS_CONNECTING
;
427 sk
->sk_state
= TCP_SYN_SENT
;
428 llc
->link
= llc_ui_next_link_no(llc
->sap
->laddr
.lsap
);
429 rc
= llc_establish_connection(sk
, llc
->dev
->dev_addr
,
430 addr
->sllc_mac
, addr
->sllc_sap
);
432 dprintk("%s: llc_ui_send_conn failed :-(\n", __FUNCTION__
);
433 sock
->state
= SS_UNCONNECTED
;
434 sk
->sk_state
= TCP_CLOSE
;
438 if (sk
->sk_state
== TCP_SYN_SENT
) {
439 const long timeo
= sock_sndtimeo(sk
, flags
& O_NONBLOCK
);
441 if (!timeo
|| !llc_ui_wait_for_conn(sk
, timeo
))
444 rc
= sock_intr_errno(timeo
);
445 if (signal_pending(current
))
449 if (sk
->sk_state
== TCP_CLOSE
)
452 sock
->state
= SS_CONNECTED
;
458 rc
= sock_error(sk
) ? : -ECONNABORTED
;
459 sock
->state
= SS_UNCONNECTED
;
464 * llc_ui_listen - allow a normal socket to accept incoming connections
465 * @sock: Socket to allow incoming connections on.
466 * @backlog: Number of connections to queue.
468 * Allow a normal socket to accept incoming connections.
469 * Returns 0 upon success, negative otherwise.
471 static int llc_ui_listen(struct socket
*sock
, int backlog
)
473 struct sock
*sk
= sock
->sk
;
477 if (unlikely(sock
->state
!= SS_UNCONNECTED
))
480 if (unlikely(sk
->sk_type
!= SOCK_STREAM
))
483 if (sock_flag(sk
, SOCK_ZAPPED
))
486 if (!(unsigned)backlog
) /* BSDism */
488 sk
->sk_max_ack_backlog
= backlog
;
489 if (sk
->sk_state
!= TCP_LISTEN
) {
490 sk
->sk_ack_backlog
= 0;
491 sk
->sk_state
= TCP_LISTEN
;
493 sk
->sk_socket
->flags
|= __SO_ACCEPTCON
;
499 static int llc_ui_wait_for_disc(struct sock
*sk
, long timeout
)
505 prepare_to_wait(sk
->sk_sleep
, &wait
, TASK_INTERRUPTIBLE
);
506 if (sk_wait_event(sk
, &timeout
, sk
->sk_state
== TCP_CLOSE
))
509 if (signal_pending(current
))
516 finish_wait(sk
->sk_sleep
, &wait
);
520 static int llc_ui_wait_for_conn(struct sock
*sk
, long timeout
)
525 prepare_to_wait(sk
->sk_sleep
, &wait
, TASK_INTERRUPTIBLE
);
526 if (sk_wait_event(sk
, &timeout
, sk
->sk_state
!= TCP_SYN_SENT
))
528 if (signal_pending(current
) || !timeout
)
531 finish_wait(sk
->sk_sleep
, &wait
);
535 static int llc_ui_wait_for_busy_core(struct sock
*sk
, long timeout
)
538 struct llc_sock
*llc
= llc_sk(sk
);
542 prepare_to_wait(sk
->sk_sleep
, &wait
, TASK_INTERRUPTIBLE
);
544 if (sk_wait_event(sk
, &timeout
,
545 (sk
->sk_shutdown
& RCV_SHUTDOWN
) ||
546 (!llc_data_accept_state(llc
->state
) &&
547 !llc
->remote_busy_flag
&&
551 if (signal_pending(current
))
557 finish_wait(sk
->sk_sleep
, &wait
);
561 static int llc_wait_data(struct sock
*sk
, long timeo
)
567 * POSIX 1003.1g mandates this order.
574 if (sk
->sk_shutdown
& RCV_SHUTDOWN
)
579 rc
= sock_intr_errno(timeo
);
580 if (signal_pending(current
))
583 if (sk_wait_data(sk
, &timeo
))
590 * llc_ui_accept - accept a new incoming connection.
591 * @sock: Socket which connections arrive on.
592 * @newsock: Socket to move incoming connection to.
593 * @flags: User specified operational flags.
595 * Accept a new incoming connection.
596 * Returns 0 upon success, negative otherwise.
598 static int llc_ui_accept(struct socket
*sock
, struct socket
*newsock
, int flags
)
600 struct sock
*sk
= sock
->sk
, *newsk
;
601 struct llc_sock
*llc
, *newllc
;
603 int rc
= -EOPNOTSUPP
;
605 dprintk("%s: accepting on %02X\n", __FUNCTION__
,
606 llc_sk(sk
)->laddr
.lsap
);
608 if (unlikely(sk
->sk_type
!= SOCK_STREAM
))
611 if (unlikely(sock
->state
!= SS_UNCONNECTED
||
612 sk
->sk_state
!= TCP_LISTEN
))
614 /* wait for a connection to arrive. */
615 if (skb_queue_empty(&sk
->sk_receive_queue
)) {
616 rc
= llc_wait_data(sk
, sk
->sk_rcvtimeo
);
620 dprintk("%s: got a new connection on %02X\n", __FUNCTION__
,
621 llc_sk(sk
)->laddr
.lsap
);
622 skb
= skb_dequeue(&sk
->sk_receive_queue
);
628 /* attach connection to a new socket. */
629 llc_ui_sk_init(newsock
, newsk
);
630 sock_reset_flag(newsk
, SOCK_ZAPPED
);
631 newsk
->sk_state
= TCP_ESTABLISHED
;
632 newsock
->state
= SS_CONNECTED
;
634 newllc
= llc_sk(newsk
);
635 memcpy(&newllc
->addr
, &llc
->addr
, sizeof(newllc
->addr
));
636 newllc
->link
= llc_ui_next_link_no(newllc
->laddr
.lsap
);
638 /* put original socket back into a clean listen state. */
639 sk
->sk_state
= TCP_LISTEN
;
640 sk
->sk_ack_backlog
--;
641 dprintk("%s: ok success on %02X, client on %02X\n", __FUNCTION__
,
642 llc_sk(sk
)->addr
.sllc_sap
, newllc
->daddr
.lsap
);
651 * llc_ui_recvmsg - copy received data to the socket user.
652 * @sock: Socket to copy data from.
653 * @msg: Various user space related information.
654 * @len: Size of user buffer.
655 * @flags: User specified flags.
657 * Copy received data to the socket user.
658 * Returns non-negative upon success, negative otherwise.
660 static int llc_ui_recvmsg(struct kiocb
*iocb
, struct socket
*sock
,
661 struct msghdr
*msg
, size_t len
, int flags
)
663 struct sockaddr_llc
*uaddr
= (struct sockaddr_llc
*)msg
->msg_name
;
664 const int nonblock
= flags
& MSG_DONTWAIT
;
665 struct sk_buff
*skb
= NULL
;
666 struct sock
*sk
= sock
->sk
;
667 struct llc_sock
*llc
= llc_sk(sk
);
672 int target
; /* Read at least this many bytes */
677 if (sk
->sk_state
== TCP_LISTEN
)
680 timeo
= sock_rcvtimeo(sk
, nonblock
);
682 seq
= &llc
->copied_seq
;
683 if (flags
& MSG_PEEK
) {
684 peek_seq
= llc
->copied_seq
;
688 target
= sock_rcvlowat(sk
, flags
& MSG_WAITALL
, len
);
695 * We need to check signals first, to get correct SIGURG
696 * handling. FIXME: Need to check this doesn't impact 1003.1g
697 * and move it down to the bottom of the loop
699 if (signal_pending(current
)) {
702 copied
= timeo
? sock_intr_errno(timeo
) : -EAGAIN
;
706 /* Next get a buffer. */
708 skb
= skb_peek(&sk
->sk_receive_queue
);
713 /* Well, if we have backlog, try to process it now yet. */
715 if (copied
>= target
&& !sk
->sk_backlog
.tail
)
720 sk
->sk_state
== TCP_CLOSE
||
721 (sk
->sk_shutdown
& RCV_SHUTDOWN
) ||
726 if (sock_flag(sk
, SOCK_DONE
))
730 copied
= sock_error(sk
);
733 if (sk
->sk_shutdown
& RCV_SHUTDOWN
)
736 if (sk
->sk_state
== TCP_CLOSE
) {
737 if (!sock_flag(sk
, SOCK_DONE
)) {
739 * This occurs when user tries to read
740 * from never connected socket.
753 if (copied
>= target
) { /* Do not sleep, just process backlog. */
757 sk_wait_data(sk
, &timeo
);
759 if ((flags
& MSG_PEEK
) && peek_seq
!= llc
->copied_seq
) {
761 printk(KERN_DEBUG
"LLC(%s:%d): Application "
762 "bug, race in MSG_PEEK.\n",
763 current
->comm
, current
->pid
);
764 peek_seq
= llc
->copied_seq
;
768 /* Ok so how much can we use? */
769 used
= skb
->len
- offset
;
773 if (!(flags
& MSG_TRUNC
)) {
774 int rc
= skb_copy_datagram_iovec(skb
, offset
,
777 /* Exception. Bailout! */
788 if (used
+ offset
< skb
->len
)
791 if (!(flags
& MSG_PEEK
)) {
798 * According to UNIX98, msg_name/msg_namelen are ignored
799 * on connected socket. -ANK
800 * But... af_llc still doesn't have separate sets of methods for
801 * SOCK_DGRAM and SOCK_STREAM :-( So we have to do this test, will
802 * eventually fix this tho :-) -acme
804 if (sk
->sk_type
== SOCK_DGRAM
)
810 if (uaddr
!= NULL
&& skb
!= NULL
) {
811 memcpy(uaddr
, llc_ui_skb_cb(skb
), sizeof(*uaddr
));
812 msg
->msg_namelen
= sizeof(*uaddr
);
818 * llc_ui_sendmsg - Transmit data provided by the socket user.
819 * @sock: Socket to transmit data from.
820 * @msg: Various user related information.
821 * @len: Length of data to transmit.
823 * Transmit data provided by the socket user.
824 * Returns non-negative upon success, negative otherwise.
826 static int llc_ui_sendmsg(struct kiocb
*iocb
, struct socket
*sock
,
827 struct msghdr
*msg
, size_t len
)
829 struct sock
*sk
= sock
->sk
;
830 struct llc_sock
*llc
= llc_sk(sk
);
831 struct sockaddr_llc
*addr
= (struct sockaddr_llc
*)msg
->msg_name
;
832 int flags
= msg
->msg_flags
;
833 int noblock
= flags
& MSG_DONTWAIT
;
836 int rc
= -EINVAL
, copied
= 0, hdrlen
;
838 dprintk("%s: sending from %02X to %02X\n", __FUNCTION__
,
839 llc
->laddr
.lsap
, llc
->daddr
.lsap
);
842 if (msg
->msg_namelen
< sizeof(*addr
))
845 if (llc_ui_addr_null(&llc
->addr
))
849 /* must bind connection to sap if user hasn't done it. */
850 if (sock_flag(sk
, SOCK_ZAPPED
)) {
851 /* bind to sap with null dev, exclusive. */
852 rc
= llc_ui_autobind(sock
, addr
);
856 hdrlen
= llc
->dev
->hard_header_len
+ llc_ui_header_len(sk
, addr
);
858 if (size
> llc
->dev
->mtu
)
859 size
= llc
->dev
->mtu
;
860 copied
= size
- hdrlen
;
862 skb
= sock_alloc_send_skb(sk
, size
, noblock
, &rc
);
867 skb
->protocol
= llc_proto_type(addr
->sllc_arphrd
);
868 skb_reserve(skb
, hdrlen
);
869 rc
= memcpy_fromiovec(skb_put(skb
, copied
), msg
->msg_iov
, copied
);
872 if (sk
->sk_type
== SOCK_DGRAM
|| addr
->sllc_ua
) {
873 llc_build_and_send_ui_pkt(llc
->sap
, skb
, addr
->sllc_mac
,
877 if (addr
->sllc_test
) {
878 llc_build_and_send_test_pkt(llc
->sap
, skb
, addr
->sllc_mac
,
882 if (addr
->sllc_xid
) {
883 llc_build_and_send_xid_pkt(llc
->sap
, skb
, addr
->sllc_mac
,
888 if (!(sk
->sk_type
== SOCK_STREAM
&& !addr
->sllc_ua
))
890 rc
= llc_ui_send_data(sk
, skb
, noblock
);
895 dprintk("%s: failed sending from %02X to %02X: %d\n",
896 __FUNCTION__
, llc
->laddr
.lsap
, llc
->daddr
.lsap
, rc
);
899 return rc
? : copied
;
903 * llc_ui_getname - return the address info of a socket
904 * @sock: Socket to get address of.
905 * @uaddr: Address structure to return information.
906 * @uaddrlen: Length of address structure.
907 * @peer: Does user want local or remote address information.
909 * Return the address information of a socket.
911 static int llc_ui_getname(struct socket
*sock
, struct sockaddr
*uaddr
,
912 int *uaddrlen
, int peer
)
914 struct sockaddr_llc sllc
;
915 struct sock
*sk
= sock
->sk
;
916 struct llc_sock
*llc
= llc_sk(sk
);
920 if (sock_flag(sk
, SOCK_ZAPPED
))
922 *uaddrlen
= sizeof(sllc
);
923 memset(uaddr
, 0, *uaddrlen
);
926 if (sk
->sk_state
!= TCP_ESTABLISHED
)
929 sllc
.sllc_arphrd
= llc
->dev
->type
;
930 sllc
.sllc_sap
= llc
->daddr
.lsap
;
931 memcpy(&sllc
.sllc_mac
, &llc
->daddr
.mac
, IFHWADDRLEN
);
936 sllc
.sllc_sap
= llc
->sap
->laddr
.lsap
;
939 sllc
.sllc_arphrd
= llc
->dev
->type
;
940 memcpy(&sllc
.sllc_mac
, &llc
->dev
->dev_addr
,
945 sllc
.sllc_family
= AF_LLC
;
946 memcpy(uaddr
, &sllc
, sizeof(sllc
));
953 * llc_ui_ioctl - io controls for PF_LLC
954 * @sock: Socket to get/set info
956 * @arg: optional argument for cmd
958 * get/set info on llc sockets
960 static int llc_ui_ioctl(struct socket
*sock
, unsigned int cmd
,
963 return dev_ioctl(cmd
, (void __user
*)arg
);
967 * llc_ui_setsockopt - set various connection specific parameters.
968 * @sock: Socket to set options on.
969 * @level: Socket level user is requesting operations on.
970 * @optname: Operation name.
971 * @optval User provided operation data.
972 * @optlen: Length of optval.
974 * Set various connection specific parameters.
976 static int llc_ui_setsockopt(struct socket
*sock
, int level
, int optname
,
977 char __user
*optval
, int optlen
)
979 struct sock
*sk
= sock
->sk
;
980 struct llc_sock
*llc
= llc_sk(sk
);
981 int rc
= -EINVAL
, opt
;
984 if (unlikely(level
!= SOL_LLC
|| optlen
!= sizeof(int)))
986 rc
= get_user(opt
, (int __user
*)optval
);
992 if (opt
> LLC_OPT_MAX_RETRY
)
997 if (opt
> LLC_OPT_MAX_SIZE
)
1001 case LLC_OPT_ACK_TMR_EXP
:
1002 if (opt
> LLC_OPT_MAX_ACK_TMR_EXP
)
1004 llc
->ack_timer
.expire
= opt
* HZ
;
1006 case LLC_OPT_P_TMR_EXP
:
1007 if (opt
> LLC_OPT_MAX_P_TMR_EXP
)
1009 llc
->pf_cycle_timer
.expire
= opt
* HZ
;
1011 case LLC_OPT_REJ_TMR_EXP
:
1012 if (opt
> LLC_OPT_MAX_REJ_TMR_EXP
)
1014 llc
->rej_sent_timer
.expire
= opt
* HZ
;
1016 case LLC_OPT_BUSY_TMR_EXP
:
1017 if (opt
> LLC_OPT_MAX_BUSY_TMR_EXP
)
1019 llc
->busy_state_timer
.expire
= opt
* HZ
;
1021 case LLC_OPT_TX_WIN
:
1022 if (opt
> LLC_OPT_MAX_WIN
)
1026 case LLC_OPT_RX_WIN
:
1027 if (opt
> LLC_OPT_MAX_WIN
)
1042 * llc_ui_getsockopt - get connection specific socket info
1043 * @sock: Socket to get information from.
1044 * @level: Socket level user is requesting operations on.
1045 * @optname: Operation name.
1046 * @optval: Variable to return operation data in.
1047 * @optlen: Length of optval.
1049 * Get connection specific socket information.
1051 static int llc_ui_getsockopt(struct socket
*sock
, int level
, int optname
,
1052 char __user
*optval
, int __user
*optlen
)
1054 struct sock
*sk
= sock
->sk
;
1055 struct llc_sock
*llc
= llc_sk(sk
);
1056 int val
= 0, len
= 0, rc
= -EINVAL
;
1059 if (unlikely(level
!= SOL_LLC
))
1061 rc
= get_user(len
, optlen
);
1065 if (len
!= sizeof(int))
1069 val
= llc
->n2
; break;
1071 val
= llc
->n1
; break;
1072 case LLC_OPT_ACK_TMR_EXP
:
1073 val
= llc
->ack_timer
.expire
/ HZ
; break;
1074 case LLC_OPT_P_TMR_EXP
:
1075 val
= llc
->pf_cycle_timer
.expire
/ HZ
; break;
1076 case LLC_OPT_REJ_TMR_EXP
:
1077 val
= llc
->rej_sent_timer
.expire
/ HZ
; break;
1078 case LLC_OPT_BUSY_TMR_EXP
:
1079 val
= llc
->busy_state_timer
.expire
/ HZ
; break;
1080 case LLC_OPT_TX_WIN
:
1081 val
= llc
->k
; break;
1082 case LLC_OPT_RX_WIN
:
1083 val
= llc
->rw
; break;
1089 if (put_user(len
, optlen
) || copy_to_user(optval
, &val
, len
))
1096 static struct net_proto_family llc_ui_family_ops
= {
1098 .create
= llc_ui_create
,
1099 .owner
= THIS_MODULE
,
1102 static struct proto_ops llc_ui_ops
= {
1104 .owner
= THIS_MODULE
,
1105 .release
= llc_ui_release
,
1106 .bind
= llc_ui_bind
,
1107 .connect
= llc_ui_connect
,
1108 .socketpair
= sock_no_socketpair
,
1109 .accept
= llc_ui_accept
,
1110 .getname
= llc_ui_getname
,
1111 .poll
= datagram_poll
,
1112 .ioctl
= llc_ui_ioctl
,
1113 .listen
= llc_ui_listen
,
1114 .shutdown
= llc_ui_shutdown
,
1115 .setsockopt
= llc_ui_setsockopt
,
1116 .getsockopt
= llc_ui_getsockopt
,
1117 .sendmsg
= llc_ui_sendmsg
,
1118 .recvmsg
= llc_ui_recvmsg
,
1119 .mmap
= sock_no_mmap
,
1120 .sendpage
= sock_no_sendpage
,
1123 static char llc_proc_err_msg
[] __initdata
=
1124 KERN_CRIT
"LLC: Unable to register the proc_fs entries\n";
1125 static char llc_sysctl_err_msg
[] __initdata
=
1126 KERN_CRIT
"LLC: Unable to register the sysctl entries\n";
1127 static char llc_sock_err_msg
[] __initdata
=
1128 KERN_CRIT
"LLC: Unable to register the network family\n";
1130 static int __init
llc2_init(void)
1132 int rc
= proto_register(&llc_proto
, 0);
1137 llc_build_offset_table();
1139 llc_ui_sap_last_autoport
= LLC_SAP_DYN_START
;
1140 rc
= llc_proc_init();
1142 printk(llc_proc_err_msg
);
1143 goto out_unregister_llc_proto
;
1145 rc
= llc_sysctl_init();
1147 printk(llc_sysctl_err_msg
);
1150 rc
= sock_register(&llc_ui_family_ops
);
1152 printk(llc_sock_err_msg
);
1155 llc_add_pack(LLC_DEST_SAP
, llc_sap_handler
);
1156 llc_add_pack(LLC_DEST_CONN
, llc_conn_handler
);
1163 out_unregister_llc_proto
:
1164 proto_unregister(&llc_proto
);
1168 static void __exit
llc2_exit(void)
1171 llc_remove_pack(LLC_DEST_SAP
);
1172 llc_remove_pack(LLC_DEST_CONN
);
1173 sock_unregister(PF_LLC
);
1176 proto_unregister(&llc_proto
);
1179 module_init(llc2_init
);
1180 module_exit(llc2_exit
);
1182 MODULE_LICENSE("GPL");
1183 MODULE_AUTHOR("Procom 1997, Jay Schullist 2001, Arnaldo C. Melo 2001-2003");
1184 MODULE_DESCRIPTION("IEEE 802.2 PF_LLC support");
1185 MODULE_ALIAS_NETPROTO(PF_LLC
);