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/kernel.h>
25 #include <linux/module.h>
26 #include <linux/rtnetlink.h>
27 #include <linux/init.h>
29 #include <net/llc_sap.h>
30 #include <net/llc_pdu.h>
31 #include <net/llc_conn.h>
32 #include <net/tcp_states.h>
34 /* remember: uninitialized global data is zeroed because its in .bss */
35 static u16 llc_ui_sap_last_autoport
= LLC_SAP_DYN_START
;
36 static u16 llc_ui_sap_link_no_max
[256];
37 static struct sockaddr_llc llc_ui_addrnull
;
38 static struct proto_ops llc_ui_ops
;
40 static int llc_ui_wait_for_conn(struct sock
*sk
, long timeout
);
41 static int llc_ui_wait_for_disc(struct sock
*sk
, long timeout
);
42 static int llc_ui_wait_for_busy_core(struct sock
*sk
, long timeout
);
45 #define dprintk(args...) printk(KERN_DEBUG args)
47 #define dprintk(args...)
51 * llc_ui_next_link_no - return the next unused link number for a sap
52 * @sap: Address of sap to get link number from.
54 * Return the next unused link number for a given sap.
56 static __inline__ u16
llc_ui_next_link_no(int sap
)
58 return llc_ui_sap_link_no_max
[sap
]++;
62 * llc_proto_type - return eth protocol for ARP header type
63 * @arphrd: ARP header type.
65 * Given an ARP header type return the corresponding ethernet protocol.
67 static __inline__ u16
llc_proto_type(u16 arphrd
)
69 return arphrd
== ARPHRD_IEEE802_TR
?
70 htons(ETH_P_TR_802_2
) : htons(ETH_P_802_2
);
74 * llc_ui_addr_null - determines if a address structure is null
75 * @addr: Address to test if null.
77 static __inline__ u8
llc_ui_addr_null(struct sockaddr_llc
*addr
)
79 return !memcmp(addr
, &llc_ui_addrnull
, sizeof(*addr
));
83 * llc_ui_header_len - return length of llc header based on operation
84 * @sk: Socket which contains a valid llc socket type.
85 * @addr: Complete sockaddr_llc structure received from the user.
87 * Provide the length of the llc header depending on what kind of
88 * operation the user would like to perform and the type of socket.
89 * Returns the correct llc header length.
91 static __inline__ u8
llc_ui_header_len(struct sock
*sk
,
92 struct sockaddr_llc
*addr
)
94 u8 rc
= LLC_PDU_LEN_U
;
96 if (addr
->sllc_test
|| addr
->sllc_xid
)
98 else if (sk
->sk_type
== SOCK_STREAM
)
104 * llc_ui_send_data - send data via reliable llc2 connection
105 * @sk: Connection the socket is using.
106 * @skb: Data the user wishes to send.
107 * @addr: Source and destination fields provided by the user.
108 * @noblock: can we block waiting for data?
110 * Send data via reliable llc2 connection.
111 * Returns 0 upon success, non-zero if action did not succeed.
113 static int llc_ui_send_data(struct sock
* sk
, struct sk_buff
*skb
, int noblock
)
115 struct llc_sock
* llc
= llc_sk(sk
);
118 if (unlikely(llc_data_accept_state(llc
->state
) || llc
->p_flag
)) {
119 long timeout
= sock_sndtimeo(sk
, noblock
);
121 rc
= llc_ui_wait_for_busy_core(sk
, timeout
);
124 rc
= llc_build_and_send_pkt(sk
, skb
);
128 static void llc_ui_sk_init(struct socket
*sock
, struct sock
*sk
)
130 sk
->sk_type
= sock
->type
;
131 sk
->sk_sleep
= &sock
->wait
;
132 sk
->sk_socket
= sock
;
134 sock
->ops
= &llc_ui_ops
;
137 static struct proto llc_proto
= {
139 .owner
= THIS_MODULE
,
140 .obj_size
= sizeof(struct llc_sock
),
144 * llc_ui_create - alloc and init a new llc_ui socket
145 * @sock: Socket to initialize and attach allocated sk to.
148 * Allocate and initialize a new llc_ui socket, validate the user wants a
149 * socket type we have available.
150 * Returns 0 upon success, negative upon failure.
152 static int llc_ui_create(struct socket
*sock
, int protocol
)
155 int rc
= -ESOCKTNOSUPPORT
;
157 if (likely(sock
->type
== SOCK_DGRAM
|| sock
->type
== SOCK_STREAM
)) {
159 sk
= llc_sk_alloc(PF_LLC
, GFP_KERNEL
, &llc_proto
);
162 llc_ui_sk_init(sock
, sk
);
169 * llc_ui_release - shutdown socket
170 * @sock: Socket to release.
172 * Shutdown and deallocate an existing socket.
174 static int llc_ui_release(struct socket
*sock
)
176 struct sock
*sk
= sock
->sk
;
177 struct llc_sock
*llc
;
179 if (unlikely(sk
== NULL
))
184 dprintk("%s: closing local(%02X) remote(%02X)\n", __FUNCTION__
,
185 llc
->laddr
.lsap
, llc
->daddr
.lsap
);
186 if (!llc_send_disc(sk
))
187 llc_ui_wait_for_disc(sk
, sk
->sk_rcvtimeo
);
188 if (!sock_flag(sk
, SOCK_ZAPPED
))
189 llc_sap_remove_socket(llc
->sap
, sk
);
191 if (llc
->sap
&& hlist_empty(&llc
->sap
->sk_list
.list
)) {
192 llc_release_sockets(llc
->sap
);
193 llc_sap_close(llc
->sap
);
204 * llc_ui_autoport - provide dynamically allocate SAP number
206 * Provide the caller with a dynamically allocated SAP number according
207 * to the rules that are set in this function. Returns: 0, upon failure,
208 * SAP number otherwise.
210 static int llc_ui_autoport(void)
215 while (tries
< LLC_SAP_DYN_TRIES
) {
216 for (i
= llc_ui_sap_last_autoport
;
217 i
< LLC_SAP_DYN_STOP
; i
+= 2) {
218 sap
= llc_sap_find(i
);
220 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
))
301 if (!addr
->sllc_sap
) {
303 addr
->sllc_sap
= llc_ui_autoport();
307 sap
= llc_sap_find(addr
->sllc_sap
);
309 sap
= llc_sap_open(addr
->sllc_sap
, NULL
);
310 rc
= -EBUSY
; /* some other network layer is using the sap */
314 struct llc_addr laddr
, daddr
;
317 memset(&laddr
, 0, sizeof(laddr
));
318 memset(&daddr
, 0, sizeof(daddr
));
320 * FIXME: check if the the address is multicast,
321 * only SOCK_DGRAM can do this.
323 memcpy(laddr
.mac
, addr
->sllc_mac
, IFHWADDRLEN
);
324 laddr
.lsap
= addr
->sllc_sap
;
325 rc
= -EADDRINUSE
; /* mac + sap clash. */
326 ask
= llc_lookup_established(sap
, &daddr
, &laddr
);
332 llc
->laddr
.lsap
= addr
->sllc_sap
;
333 memcpy(llc
->laddr
.mac
, addr
->sllc_mac
, IFHWADDRLEN
);
334 memcpy(&llc
->addr
, addr
, sizeof(llc
->addr
));
335 /* assign new connection to its SAP */
336 llc_sap_add_socket(sap
, sk
);
337 sock_reset_flag(sk
, SOCK_ZAPPED
);
344 * llc_ui_shutdown - shutdown a connect llc2 socket.
345 * @sock: Socket to shutdown.
346 * @how: What part of the socket to shutdown.
348 * Shutdown a connected llc2 socket. Currently this function only supports
349 * shutting down both sends and receives (2), we could probably make this
350 * function such that a user can shutdown only half the connection but not
352 * Returns: 0 upon success, negative otherwise.
354 static int llc_ui_shutdown(struct socket
*sock
, int how
)
356 struct sock
*sk
= sock
->sk
;
360 if (unlikely(sk
->sk_state
!= TCP_ESTABLISHED
))
365 rc
= llc_send_disc(sk
);
367 rc
= llc_ui_wait_for_disc(sk
, sk
->sk_rcvtimeo
);
368 /* Wake up anyone sleeping in poll */
369 sk
->sk_state_change(sk
);
376 * llc_ui_connect - Connect to a remote llc2 mac + sap.
377 * @sock: Socket which will be connected to the remote destination.
378 * @uaddr: Remote and possibly the local address of the new connection.
379 * @addrlen: Size of uaddr structure.
380 * @flags: Operational flags specified by the user.
382 * Connect to a remote llc2 mac + sap. The caller must specify the
383 * destination mac and address to connect to. If the user hasn't previously
384 * called bind(2) with a smac the address of the first interface of the
385 * specified arp type will be used.
386 * This function will autobind if user did not previously call bind.
387 * Returns: 0 upon success, negative otherwise.
389 static int llc_ui_connect(struct socket
*sock
, struct sockaddr
*uaddr
,
390 int addrlen
, int flags
)
392 struct sock
*sk
= sock
->sk
;
393 struct llc_sock
*llc
= llc_sk(sk
);
394 struct sockaddr_llc
*addr
= (struct sockaddr_llc
*)uaddr
;
398 if (unlikely(addrlen
!= sizeof(*addr
)))
401 if (unlikely(addr
->sllc_family
!= AF_LLC
))
403 if (unlikely(sk
->sk_type
!= SOCK_STREAM
))
406 if (unlikely(sock
->state
== SS_CONNECTING
))
408 /* bind connection to sap if user hasn't done it. */
409 if (sock_flag(sk
, SOCK_ZAPPED
)) {
410 /* bind to sap with null dev, exclusive */
411 rc
= llc_ui_autobind(sock
, addr
);
414 llc
->daddr
.lsap
= addr
->sllc_sap
;
415 memcpy(llc
->daddr
.mac
, addr
->sllc_mac
, IFHWADDRLEN
);
417 sock
->state
= SS_CONNECTING
;
418 sk
->sk_state
= TCP_SYN_SENT
;
419 llc
->link
= llc_ui_next_link_no(llc
->sap
->laddr
.lsap
);
420 rc
= llc_establish_connection(sk
, llc
->dev
->dev_addr
,
421 addr
->sllc_mac
, addr
->sllc_sap
);
423 dprintk("%s: llc_ui_send_conn failed :-(\n", __FUNCTION__
);
424 sock
->state
= SS_UNCONNECTED
;
425 sk
->sk_state
= TCP_CLOSE
;
429 if (sk
->sk_state
== TCP_SYN_SENT
) {
430 const long timeo
= sock_sndtimeo(sk
, flags
& O_NONBLOCK
);
432 if (!timeo
|| !llc_ui_wait_for_conn(sk
, timeo
))
435 rc
= sock_intr_errno(timeo
);
436 if (signal_pending(current
))
440 if (sk
->sk_state
== TCP_CLOSE
)
443 sock
->state
= SS_CONNECTED
;
449 rc
= sock_error(sk
) ? : -ECONNABORTED
;
450 sock
->state
= SS_UNCONNECTED
;
455 * llc_ui_listen - allow a normal socket to accept incoming connections
456 * @sock: Socket to allow incoming connections on.
457 * @backlog: Number of connections to queue.
459 * Allow a normal socket to accept incoming connections.
460 * Returns 0 upon success, negative otherwise.
462 static int llc_ui_listen(struct socket
*sock
, int backlog
)
464 struct sock
*sk
= sock
->sk
;
468 if (unlikely(sock
->state
!= SS_UNCONNECTED
))
471 if (unlikely(sk
->sk_type
!= SOCK_STREAM
))
474 if (sock_flag(sk
, SOCK_ZAPPED
))
477 if (!(unsigned)backlog
) /* BSDism */
479 sk
->sk_max_ack_backlog
= backlog
;
480 if (sk
->sk_state
!= TCP_LISTEN
) {
481 sk
->sk_ack_backlog
= 0;
482 sk
->sk_state
= TCP_LISTEN
;
484 sk
->sk_socket
->flags
|= __SO_ACCEPTCON
;
490 static int llc_ui_wait_for_disc(struct sock
*sk
, long timeout
)
496 prepare_to_wait(sk
->sk_sleep
, &wait
, TASK_INTERRUPTIBLE
);
497 if (sk_wait_event(sk
, &timeout
, sk
->sk_state
== TCP_CLOSE
))
500 if (signal_pending(current
))
507 finish_wait(sk
->sk_sleep
, &wait
);
511 static int llc_ui_wait_for_conn(struct sock
*sk
, long timeout
)
516 prepare_to_wait(sk
->sk_sleep
, &wait
, TASK_INTERRUPTIBLE
);
517 if (sk_wait_event(sk
, &timeout
, sk
->sk_state
!= TCP_SYN_SENT
))
519 if (signal_pending(current
) || !timeout
)
522 finish_wait(sk
->sk_sleep
, &wait
);
526 static int llc_ui_wait_for_busy_core(struct sock
*sk
, long timeout
)
529 struct llc_sock
*llc
= llc_sk(sk
);
533 prepare_to_wait(sk
->sk_sleep
, &wait
, TASK_INTERRUPTIBLE
);
535 if (sk_wait_event(sk
, &timeout
,
536 (sk
->sk_shutdown
& RCV_SHUTDOWN
) ||
537 (!llc_data_accept_state(llc
->state
) &&
541 if (signal_pending(current
))
547 finish_wait(sk
->sk_sleep
, &wait
);
551 int llc_wait_data(struct sock
*sk
, long timeo
)
557 * POSIX 1003.1g mandates this order.
564 if (sk
->sk_shutdown
& RCV_SHUTDOWN
)
569 rc
= sock_intr_errno(timeo
);
570 if (signal_pending(current
))
573 if (sk_wait_data(sk
, &timeo
))
580 * llc_ui_accept - accept a new incoming connection.
581 * @sock: Socket which connections arrive on.
582 * @newsock: Socket to move incoming connection to.
583 * @flags: User specified operational flags.
585 * Accept a new incoming connection.
586 * Returns 0 upon success, negative otherwise.
588 static int llc_ui_accept(struct socket
*sock
, struct socket
*newsock
, int flags
)
590 struct sock
*sk
= sock
->sk
, *newsk
;
591 struct llc_sock
*llc
, *newllc
;
593 int rc
= -EOPNOTSUPP
;
595 dprintk("%s: accepting on %02X\n", __FUNCTION__
,
596 llc_sk(sk
)->laddr
.lsap
);
598 if (unlikely(sk
->sk_type
!= SOCK_STREAM
))
601 if (unlikely(sock
->state
!= SS_UNCONNECTED
||
602 sk
->sk_state
!= TCP_LISTEN
))
604 /* wait for a connection to arrive. */
605 if (skb_queue_empty(&sk
->sk_receive_queue
)) {
606 rc
= llc_wait_data(sk
, sk
->sk_rcvtimeo
);
610 dprintk("%s: got a new connection on %02X\n", __FUNCTION__
,
611 llc_sk(sk
)->laddr
.lsap
);
612 skb
= skb_dequeue(&sk
->sk_receive_queue
);
618 /* attach connection to a new socket. */
619 llc_ui_sk_init(newsock
, newsk
);
620 sock_reset_flag(newsk
, SOCK_ZAPPED
);
621 newsk
->sk_state
= TCP_ESTABLISHED
;
622 newsock
->state
= SS_CONNECTED
;
624 newllc
= llc_sk(newsk
);
625 memcpy(&newllc
->addr
, &llc
->addr
, sizeof(newllc
->addr
));
626 newllc
->link
= llc_ui_next_link_no(newllc
->laddr
.lsap
);
628 /* put original socket back into a clean listen state. */
629 sk
->sk_state
= TCP_LISTEN
;
630 sk
->sk_ack_backlog
--;
631 dprintk("%s: ok success on %02X, client on %02X\n", __FUNCTION__
,
632 llc_sk(sk
)->addr
.sllc_sap
, newllc
->daddr
.lsap
);
641 * llc_ui_recvmsg - copy received data to the socket user.
642 * @sock: Socket to copy data from.
643 * @msg: Various user space related information.
644 * @size: Size of user buffer.
645 * @flags: User specified flags.
647 * Copy received data to the socket user.
648 * Returns non-negative upon success, negative otherwise.
650 static int llc_ui_recvmsg(struct kiocb
*iocb
, struct socket
*sock
,
651 struct msghdr
*msg
, size_t size
, int flags
)
653 struct sock
*sk
= sock
->sk
;
654 struct sockaddr_llc
*uaddr
= (struct sockaddr_llc
*)msg
->msg_name
;
658 int noblock
= flags
& MSG_DONTWAIT
;
660 dprintk("%s: receiving in %02X from %02X\n", __FUNCTION__
,
661 llc_sk(sk
)->laddr
.lsap
, llc_sk(sk
)->daddr
.lsap
);
663 if (skb_queue_empty(&sk
->sk_receive_queue
)) {
664 rc
= llc_wait_data(sk
, sock_rcvtimeo(sk
, noblock
));
668 skb
= skb_dequeue(&sk
->sk_receive_queue
);
669 if (!skb
) /* shutdown */
674 rc
= skb_copy_datagram_iovec(skb
, 0, msg
->msg_iov
, copied
);
677 if (skb
->len
> copied
) {
678 skb_pull(skb
, copied
);
679 skb_queue_head(&sk
->sk_receive_queue
, skb
);
682 memcpy(uaddr
, llc_ui_skb_cb(skb
), sizeof(*uaddr
));
683 msg
->msg_namelen
= sizeof(*uaddr
);
690 return rc
? : copied
;
694 * llc_ui_sendmsg - Transmit data provided by the socket user.
695 * @sock: Socket to transmit data from.
696 * @msg: Various user related information.
697 * @len: Length of data to transmit.
699 * Transmit data provided by the socket user.
700 * Returns non-negative upon success, negative otherwise.
702 static int llc_ui_sendmsg(struct kiocb
*iocb
, struct socket
*sock
,
703 struct msghdr
*msg
, size_t len
)
705 struct sock
*sk
= sock
->sk
;
706 struct llc_sock
*llc
= llc_sk(sk
);
707 struct sockaddr_llc
*addr
= (struct sockaddr_llc
*)msg
->msg_name
;
708 int flags
= msg
->msg_flags
;
709 int noblock
= flags
& MSG_DONTWAIT
;
712 int rc
= -EINVAL
, copied
= 0, hdrlen
;
714 dprintk("%s: sending from %02X to %02X\n", __FUNCTION__
,
715 llc
->laddr
.lsap
, llc
->daddr
.lsap
);
718 if (msg
->msg_namelen
< sizeof(*addr
))
721 if (llc_ui_addr_null(&llc
->addr
))
725 /* must bind connection to sap if user hasn't done it. */
726 if (sock_flag(sk
, SOCK_ZAPPED
)) {
727 /* bind to sap with null dev, exclusive. */
728 rc
= llc_ui_autobind(sock
, addr
);
732 hdrlen
= llc
->dev
->hard_header_len
+ llc_ui_header_len(sk
, addr
);
734 if (size
> llc
->dev
->mtu
)
735 size
= llc
->dev
->mtu
;
736 copied
= size
- hdrlen
;
738 skb
= sock_alloc_send_skb(sk
, size
, noblock
, &rc
);
743 skb
->protocol
= llc_proto_type(addr
->sllc_arphrd
);
744 skb_reserve(skb
, hdrlen
);
745 rc
= memcpy_fromiovec(skb_put(skb
, copied
), msg
->msg_iov
, copied
);
748 if (sk
->sk_type
== SOCK_DGRAM
|| addr
->sllc_ua
) {
749 llc_build_and_send_ui_pkt(llc
->sap
, skb
, addr
->sllc_mac
,
753 if (addr
->sllc_test
) {
754 llc_build_and_send_test_pkt(llc
->sap
, skb
, addr
->sllc_mac
,
758 if (addr
->sllc_xid
) {
759 llc_build_and_send_xid_pkt(llc
->sap
, skb
, addr
->sllc_mac
,
764 if (!(sk
->sk_type
== SOCK_STREAM
&& !addr
->sllc_ua
))
766 rc
= llc_ui_send_data(sk
, skb
, noblock
);
771 dprintk("%s: failed sending from %02X to %02X: %d\n",
772 __FUNCTION__
, llc
->laddr
.lsap
, llc
->daddr
.lsap
, rc
);
775 return rc
? : copied
;
779 * llc_ui_getname - return the address info of a socket
780 * @sock: Socket to get address of.
781 * @uaddr: Address structure to return information.
782 * @uaddrlen: Length of address structure.
783 * @peer: Does user want local or remote address information.
785 * Return the address information of a socket.
787 static int llc_ui_getname(struct socket
*sock
, struct sockaddr
*uaddr
,
788 int *uaddrlen
, int peer
)
790 struct sockaddr_llc sllc
;
791 struct sock
*sk
= sock
->sk
;
792 struct llc_sock
*llc
= llc_sk(sk
);
796 if (sock_flag(sk
, SOCK_ZAPPED
))
798 *uaddrlen
= sizeof(sllc
);
799 memset(uaddr
, 0, *uaddrlen
);
802 if (sk
->sk_state
!= TCP_ESTABLISHED
)
805 sllc
.sllc_arphrd
= llc
->dev
->type
;
806 sllc
.sllc_sap
= llc
->daddr
.lsap
;
807 memcpy(&sllc
.sllc_mac
, &llc
->daddr
.mac
, IFHWADDRLEN
);
812 sllc
.sllc_sap
= llc
->sap
->laddr
.lsap
;
815 sllc
.sllc_arphrd
= llc
->dev
->type
;
816 memcpy(&sllc
.sllc_mac
, &llc
->dev
->dev_addr
,
821 sllc
.sllc_family
= AF_LLC
;
822 memcpy(uaddr
, &sllc
, sizeof(sllc
));
829 * llc_ui_ioctl - io controls for PF_LLC
830 * @sock: Socket to get/set info
832 * @arg: optional argument for cmd
834 * get/set info on llc sockets
836 static int llc_ui_ioctl(struct socket
*sock
, unsigned int cmd
,
839 return dev_ioctl(cmd
, (void __user
*)arg
);
843 * llc_ui_setsockopt - set various connection specific parameters.
844 * @sock: Socket to set options on.
845 * @level: Socket level user is requesting operations on.
846 * @optname: Operation name.
847 * @optval User provided operation data.
848 * @optlen: Length of optval.
850 * Set various connection specific parameters.
852 static int llc_ui_setsockopt(struct socket
*sock
, int level
, int optname
,
853 char __user
*optval
, int optlen
)
855 struct sock
*sk
= sock
->sk
;
856 struct llc_sock
*llc
= llc_sk(sk
);
857 int rc
= -EINVAL
, opt
;
860 if (unlikely(level
!= SOL_LLC
|| optlen
!= sizeof(int)))
862 rc
= get_user(opt
, (int __user
*)optval
);
868 if (opt
> LLC_OPT_MAX_RETRY
)
873 if (opt
> LLC_OPT_MAX_SIZE
)
877 case LLC_OPT_ACK_TMR_EXP
:
878 if (opt
> LLC_OPT_MAX_ACK_TMR_EXP
)
880 llc
->ack_timer
.expire
= opt
* HZ
;
882 case LLC_OPT_P_TMR_EXP
:
883 if (opt
> LLC_OPT_MAX_P_TMR_EXP
)
885 llc
->pf_cycle_timer
.expire
= opt
* HZ
;
887 case LLC_OPT_REJ_TMR_EXP
:
888 if (opt
> LLC_OPT_MAX_REJ_TMR_EXP
)
890 llc
->rej_sent_timer
.expire
= opt
* HZ
;
892 case LLC_OPT_BUSY_TMR_EXP
:
893 if (opt
> LLC_OPT_MAX_BUSY_TMR_EXP
)
895 llc
->busy_state_timer
.expire
= opt
* HZ
;
898 if (opt
> LLC_OPT_MAX_WIN
)
903 if (opt
> LLC_OPT_MAX_WIN
)
918 * llc_ui_getsockopt - get connection specific socket info
919 * @sock: Socket to get information from.
920 * @level: Socket level user is requesting operations on.
921 * @optname: Operation name.
922 * @optval: Variable to return operation data in.
923 * @optlen: Length of optval.
925 * Get connection specific socket information.
927 static int llc_ui_getsockopt(struct socket
*sock
, int level
, int optname
,
928 char __user
*optval
, int __user
*optlen
)
930 struct sock
*sk
= sock
->sk
;
931 struct llc_sock
*llc
= llc_sk(sk
);
932 int val
= 0, len
= 0, rc
= -EINVAL
;
935 if (unlikely(level
!= SOL_LLC
))
937 rc
= get_user(len
, optlen
);
941 if (len
!= sizeof(int))
945 val
= llc
->n2
; break;
947 val
= llc
->n1
; break;
948 case LLC_OPT_ACK_TMR_EXP
:
949 val
= llc
->ack_timer
.expire
/ HZ
; break;
950 case LLC_OPT_P_TMR_EXP
:
951 val
= llc
->pf_cycle_timer
.expire
/ HZ
; break;
952 case LLC_OPT_REJ_TMR_EXP
:
953 val
= llc
->rej_sent_timer
.expire
/ HZ
; break;
954 case LLC_OPT_BUSY_TMR_EXP
:
955 val
= llc
->busy_state_timer
.expire
/ HZ
; break;
959 val
= llc
->rw
; break;
965 if (put_user(len
, optlen
) || copy_to_user(optval
, &val
, len
))
972 static struct net_proto_family llc_ui_family_ops
= {
974 .create
= llc_ui_create
,
975 .owner
= THIS_MODULE
,
978 static struct proto_ops llc_ui_ops
= {
980 .owner
= THIS_MODULE
,
981 .release
= llc_ui_release
,
983 .connect
= llc_ui_connect
,
984 .socketpair
= sock_no_socketpair
,
985 .accept
= llc_ui_accept
,
986 .getname
= llc_ui_getname
,
987 .poll
= datagram_poll
,
988 .ioctl
= llc_ui_ioctl
,
989 .listen
= llc_ui_listen
,
990 .shutdown
= llc_ui_shutdown
,
991 .setsockopt
= llc_ui_setsockopt
,
992 .getsockopt
= llc_ui_getsockopt
,
993 .sendmsg
= llc_ui_sendmsg
,
994 .recvmsg
= llc_ui_recvmsg
,
995 .mmap
= sock_no_mmap
,
996 .sendpage
= sock_no_sendpage
,
999 extern void llc_sap_handler(struct llc_sap
*sap
, struct sk_buff
*skb
);
1000 extern void llc_conn_handler(struct llc_sap
*sap
, struct sk_buff
*skb
);
1002 static char llc_proc_err_msg
[] __initdata
=
1003 KERN_CRIT
"LLC: Unable to register the proc_fs entries\n";
1004 static char llc_sysctl_err_msg
[] __initdata
=
1005 KERN_CRIT
"LLC: Unable to register the sysctl entries\n";
1006 static char llc_sock_err_msg
[] __initdata
=
1007 KERN_CRIT
"LLC: Unable to register the network family\n";
1009 static int __init
llc2_init(void)
1011 int rc
= proto_register(&llc_proto
, 0);
1016 llc_build_offset_table();
1018 llc_ui_sap_last_autoport
= LLC_SAP_DYN_START
;
1019 rc
= llc_proc_init();
1021 printk(llc_proc_err_msg
);
1022 goto out_unregister_llc_proto
;
1024 rc
= llc_sysctl_init();
1026 printk(llc_sysctl_err_msg
);
1029 rc
= sock_register(&llc_ui_family_ops
);
1031 printk(llc_sock_err_msg
);
1034 llc_add_pack(LLC_DEST_SAP
, llc_sap_handler
);
1035 llc_add_pack(LLC_DEST_CONN
, llc_conn_handler
);
1042 out_unregister_llc_proto
:
1043 proto_unregister(&llc_proto
);
1047 static void __exit
llc2_exit(void)
1050 llc_remove_pack(LLC_DEST_SAP
);
1051 llc_remove_pack(LLC_DEST_CONN
);
1052 sock_unregister(PF_LLC
);
1055 proto_unregister(&llc_proto
);
1058 module_init(llc2_init
);
1059 module_exit(llc2_exit
);
1061 MODULE_LICENSE("GPL");
1062 MODULE_AUTHOR("Procom 1997, Jay Schullist 2001, Arnaldo C. Melo 2001-2003");
1063 MODULE_DESCRIPTION("IEEE 802.2 PF_LLC support");
1064 MODULE_ALIAS_NETPROTO(PF_LLC
);