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, int timeout);
41 static int llc_ui_wait_for_disc(struct sock *sk, int timeout);
42 static int llc_ui_wait_for_data(struct sock *sk, int timeout);
43 static int llc_ui_wait_for_busy_core(struct sock *sk, int 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 (llc_data_accept_state(llc->state) || llc->p_flag) {
120 int timeout = sock_sndtimeo(sk, noblock);
122 rc = llc_ui_wait_for_busy_core(sk, timeout);
125 rc = llc_build_and_send_pkt(sk, skb);
129 static void llc_ui_sk_init(struct socket *sock, struct sock *sk)
131 sk->sk_type = sock->type;
132 sk->sk_sleep = &sock->wait;
133 sk->sk_socket = sock;
135 sock->ops = &llc_ui_ops;
138 static struct proto llc_proto = {
140 .owner = THIS_MODULE,
141 .obj_size = sizeof(struct llc_sock),
145 * llc_ui_create - alloc and init a new llc_ui socket
146 * @sock: Socket to initialize and attach allocated sk to.
149 * Allocate and initialize a new llc_ui socket, validate the user wants a
150 * socket type we have available.
151 * Returns 0 upon success, negative upon failure.
153 static int llc_ui_create(struct socket *sock, int protocol)
156 int rc = -ESOCKTNOSUPPORT;
158 if (sock->type == SOCK_DGRAM || sock->type == SOCK_STREAM) {
160 sk = llc_sk_alloc(PF_LLC, GFP_KERNEL, &llc_proto);
163 llc_ui_sk_init(sock, sk);
170 * llc_ui_release - shutdown socket
171 * @sock: Socket to release.
173 * Shutdown and deallocate an existing socket.
175 static int llc_ui_release(struct socket *sock)
177 struct sock *sk = sock->sk;
178 struct llc_sock *llc;
185 dprintk("%s: closing local(%02X) remote(%02X)\n", __FUNCTION__,
186 llc->laddr.lsap, llc->daddr.lsap);
187 if (!llc_send_disc(sk))
188 llc_ui_wait_for_disc(sk, sk->sk_rcvtimeo);
189 if (!sock_flag(sk, SOCK_ZAPPED))
190 llc_sap_remove_socket(llc->sap, sk);
192 if (llc->sap && hlist_empty(&llc->sap->sk_list.list)) {
193 llc_release_sockets(llc->sap);
194 llc_sap_close(llc->sap);
205 * llc_ui_autoport - provide dynamically allocate SAP number
207 * Provide the caller with a dynamically allocated SAP number according
208 * to the rules that are set in this function. Returns: 0, upon failure,
209 * SAP number otherwise.
211 static int llc_ui_autoport(void)
216 while (tries < LLC_SAP_DYN_TRIES) {
217 for (i = llc_ui_sap_last_autoport;
218 i < LLC_SAP_DYN_STOP; i += 2) {
219 sap = llc_sap_find(i);
221 llc_ui_sap_last_autoport = i + 2;
225 llc_ui_sap_last_autoport = LLC_SAP_DYN_START;
234 * llc_ui_autobind - automatically bind a socket to a sap
235 * @sock: socket to bind
236 * @addr: address to connect to
238 * Used by llc_ui_connect and llc_ui_sendmsg when the user hasn't
239 * specifically used llc_ui_bind to bind to an specific address/sap
241 * Returns: 0 upon success, negative otherwise.
243 static int llc_ui_autobind(struct socket *sock, struct sockaddr_llc *addr)
245 struct sock *sk = sock->sk;
246 struct llc_sock *llc = llc_sk(sk);
250 if (!sock_flag(sk, SOCK_ZAPPED))
253 llc->dev = dev_getfirstbyhwtype(addr->sllc_arphrd);
257 llc->laddr.lsap = llc_ui_autoport();
258 if (!llc->laddr.lsap)
260 rc = -EBUSY; /* some other network layer is using the sap */
261 sap = llc_sap_open(llc->laddr.lsap, NULL);
264 memcpy(llc->laddr.mac, llc->dev->dev_addr, IFHWADDRLEN);
265 memcpy(&llc->addr, addr, sizeof(llc->addr));
266 /* assign new connection to its SAP */
267 llc_sap_add_socket(sap, sk);
268 sock_reset_flag(sk, SOCK_ZAPPED);
275 * llc_ui_bind - bind a socket to a specific address.
276 * @sock: Socket to bind an address to.
277 * @uaddr: Address the user wants the socket bound to.
278 * @addrlen: Length of the uaddr structure.
280 * Bind a socket to a specific address. For llc a user is able to bind to
281 * a specific sap only or mac + sap.
282 * If the user desires to bind to a specific mac + sap, it is possible to
283 * have multiple sap connections via multiple macs.
284 * Bind and autobind for that matter must enforce the correct sap usage
285 * otherwise all hell will break loose.
286 * Returns: 0 upon success, negative otherwise.
288 static int llc_ui_bind(struct socket *sock, struct sockaddr *uaddr, int addrlen)
290 struct sockaddr_llc *addr = (struct sockaddr_llc *)uaddr;
291 struct sock *sk = sock->sk;
292 struct llc_sock *llc = llc_sk(sk);
296 dprintk("%s: binding %02X\n", __FUNCTION__, addr->sllc_sap);
297 if (!sock_flag(sk, SOCK_ZAPPED) || addrlen != sizeof(*addr))
300 if (addr->sllc_family != AF_LLC)
302 if (!addr->sllc_sap) {
304 addr->sllc_sap = llc_ui_autoport();
308 sap = llc_sap_find(addr->sllc_sap);
310 sap = llc_sap_open(addr->sllc_sap, NULL);
311 rc = -EBUSY; /* some other network layer is using the sap */
315 struct llc_addr laddr, daddr;
318 memset(&laddr, 0, sizeof(laddr));
319 memset(&daddr, 0, sizeof(daddr));
321 * FIXME: check if the the address is multicast,
322 * only SOCK_DGRAM can do this.
324 memcpy(laddr.mac, addr->sllc_mac, IFHWADDRLEN);
325 laddr.lsap = addr->sllc_sap;
326 rc = -EADDRINUSE; /* mac + sap clash. */
327 ask = llc_lookup_established(sap, &daddr, &laddr);
333 llc->laddr.lsap = addr->sllc_sap;
334 memcpy(llc->laddr.mac, addr->sllc_mac, IFHWADDRLEN);
335 memcpy(&llc->addr, addr, sizeof(llc->addr));
336 /* assign new connection to its SAP */
337 llc_sap_add_socket(sap, sk);
338 sock_reset_flag(sk, SOCK_ZAPPED);
345 * llc_ui_shutdown - shutdown a connect llc2 socket.
346 * @sock: Socket to shutdown.
347 * @how: What part of the socket to shutdown.
349 * Shutdown a connected llc2 socket. Currently this function only supports
350 * shutting down both sends and receives (2), we could probably make this
351 * function such that a user can shutdown only half the connection but not
353 * Returns: 0 upon success, negative otherwise.
355 static int llc_ui_shutdown(struct socket *sock, int how)
357 struct sock *sk = sock->sk;
361 if (sk->sk_state != TCP_ESTABLISHED)
366 rc = llc_send_disc(sk);
368 rc = llc_ui_wait_for_disc(sk, sk->sk_rcvtimeo);
369 /* Wake up anyone sleeping in poll */
370 sk->sk_state_change(sk);
377 * llc_ui_connect - Connect to a remote llc2 mac + sap.
378 * @sock: Socket which will be connected to the remote destination.
379 * @uaddr: Remote and possibly the local address of the new connection.
380 * @addrlen: Size of uaddr structure.
381 * @flags: Operational flags specified by the user.
383 * Connect to a remote llc2 mac + sap. The caller must specify the
384 * destination mac and address to connect to. If the user hasn't previously
385 * called bind(2) with a smac the address of the first interface of the
386 * specified arp type will be used.
387 * This function will autobind if user did not previously call bind.
388 * Returns: 0 upon success, negative otherwise.
390 static int llc_ui_connect(struct socket *sock, struct sockaddr *uaddr,
391 int addrlen, int flags)
393 struct sock *sk = sock->sk;
394 struct llc_sock *llc = llc_sk(sk);
395 struct sockaddr_llc *addr = (struct sockaddr_llc *)uaddr;
399 if (addrlen != sizeof(*addr))
402 if (addr->sllc_family != AF_LLC)
404 /* bind connection to sap if user hasn't done it. */
405 if (sock_flag(sk, SOCK_ZAPPED)) {
406 /* bind to sap with null dev, exclusive */
407 rc = llc_ui_autobind(sock, addr);
410 llc->daddr.lsap = addr->sllc_sap;
411 memcpy(llc->daddr.mac, addr->sllc_mac, IFHWADDRLEN);
413 if (sk->sk_type != SOCK_STREAM)
416 if (sock->state == SS_CONNECTING)
418 sock->state = SS_CONNECTING;
419 sk->sk_state = TCP_SYN_SENT;
420 llc->link = llc_ui_next_link_no(llc->sap->laddr.lsap);
421 rc = llc_establish_connection(sk, llc->dev->dev_addr,
422 addr->sllc_mac, addr->sllc_sap);
424 dprintk("%s: llc_ui_send_conn failed :-(\n", __FUNCTION__);
425 sock->state = SS_UNCONNECTED;
426 sk->sk_state = TCP_CLOSE;
429 rc = llc_ui_wait_for_conn(sk, sk->sk_rcvtimeo);
431 dprintk("%s: llc_ui_wait_for_conn failed=%d\n", __FUNCTION__, rc);
438 * llc_ui_listen - allow a normal socket to accept incoming connections
439 * @sock: Socket to allow incoming connections on.
440 * @backlog: Number of connections to queue.
442 * Allow a normal socket to accept incoming connections.
443 * Returns 0 upon success, negative otherwise.
445 static int llc_ui_listen(struct socket *sock, int backlog)
447 struct sock *sk = sock->sk;
451 if (sock->state != SS_UNCONNECTED)
454 if (sk->sk_type != SOCK_STREAM)
457 if (sock_flag(sk, SOCK_ZAPPED))
460 if (!(unsigned)backlog) /* BSDism */
462 sk->sk_max_ack_backlog = backlog;
463 if (sk->sk_state != TCP_LISTEN) {
464 sk->sk_ack_backlog = 0;
465 sk->sk_state = TCP_LISTEN;
467 sk->sk_socket->flags |= __SO_ACCEPTCON;
473 static int llc_ui_wait_for_disc(struct sock *sk, int timeout)
475 DECLARE_WAITQUEUE(wait, current);
478 add_wait_queue_exclusive(sk->sk_sleep, &wait);
480 __set_current_state(TASK_INTERRUPTIBLE);
482 if (sk->sk_state != TCP_CLOSE) {
484 timeout = schedule_timeout(timeout);
489 if (signal_pending(current))
495 __set_current_state(TASK_RUNNING);
496 remove_wait_queue(sk->sk_sleep, &wait);
500 static int llc_ui_wait_for_conn(struct sock *sk, int timeout)
502 DECLARE_WAITQUEUE(wait, current);
505 add_wait_queue_exclusive(sk->sk_sleep, &wait);
507 __set_current_state(TASK_INTERRUPTIBLE);
509 if (sk->sk_state == TCP_CLOSE)
512 if (sk->sk_state != TCP_ESTABLISHED) {
514 timeout = schedule_timeout(timeout);
519 if (signal_pending(current))
525 __set_current_state(TASK_RUNNING);
526 remove_wait_queue(sk->sk_sleep, &wait);
530 static int llc_ui_wait_for_data(struct sock *sk, int timeout)
532 DECLARE_WAITQUEUE(wait, current);
535 add_wait_queue_exclusive(sk->sk_sleep, &wait);
537 __set_current_state(TASK_INTERRUPTIBLE);
538 if (sk->sk_shutdown & RCV_SHUTDOWN)
541 * Well, if we have backlog, try to process it now.
543 if (sk->sk_backlog.tail) {
548 if (skb_queue_empty(&sk->sk_receive_queue)) {
550 timeout = schedule_timeout(timeout);
555 if (signal_pending(current))
561 __set_current_state(TASK_RUNNING);
562 remove_wait_queue(sk->sk_sleep, &wait);
566 static int llc_ui_wait_for_busy_core(struct sock *sk, int timeout)
568 DECLARE_WAITQUEUE(wait, current);
569 struct llc_sock *llc = llc_sk(sk);
572 add_wait_queue_exclusive(sk->sk_sleep, &wait);
574 dprintk("%s: looping...\n", __FUNCTION__);
575 __set_current_state(TASK_INTERRUPTIBLE);
577 if (sk->sk_shutdown & RCV_SHUTDOWN)
580 if (llc_data_accept_state(llc->state) || llc->p_flag) {
582 timeout = schedule_timeout(timeout);
587 if (signal_pending(current))
593 __set_current_state(TASK_RUNNING);
594 remove_wait_queue(sk->sk_sleep, &wait);
599 * llc_ui_accept - accept a new incoming connection.
600 * @sock: Socket which connections arrive on.
601 * @newsock: Socket to move incoming connection to.
602 * @flags: User specified operational flags.
604 * Accept a new incoming connection.
605 * Returns 0 upon success, negative otherwise.
607 static int llc_ui_accept(struct socket *sock, struct socket *newsock, int flags)
609 struct sock *sk = sock->sk, *newsk;
610 struct llc_sock *llc, *newllc;
612 int rc = -EOPNOTSUPP;
614 dprintk("%s: accepting on %02X\n", __FUNCTION__,
615 llc_sk(sk)->laddr.lsap);
617 if (sk->sk_type != SOCK_STREAM)
620 if (sock->state != SS_UNCONNECTED || sk->sk_state != TCP_LISTEN)
622 /* wait for a connection to arrive. */
623 rc = llc_ui_wait_for_data(sk, sk->sk_rcvtimeo);
626 dprintk("%s: got a new connection on %02X\n", __FUNCTION__,
627 llc_sk(sk)->laddr.lsap);
628 skb = skb_dequeue(&sk->sk_receive_queue);
634 /* attach connection to a new socket. */
635 llc_ui_sk_init(newsock, newsk);
636 sock_reset_flag(newsk, SOCK_ZAPPED);
637 newsk->sk_state = TCP_ESTABLISHED;
638 newsock->state = SS_CONNECTED;
640 newllc = llc_sk(newsk);
641 memcpy(&newllc->addr, &llc->addr, sizeof(newllc->addr));
642 newllc->link = llc_ui_next_link_no(newllc->laddr.lsap);
644 /* put original socket back into a clean listen state. */
645 sk->sk_state = TCP_LISTEN;
646 sk->sk_ack_backlog--;
648 dprintk("%s: ok success on %02X, client on %02X\n", __FUNCTION__,
649 llc_sk(sk)->addr.sllc_sap, newllc->daddr.lsap);
658 * llc_ui_recvmsg - copy received data to the socket user.
659 * @sock: Socket to copy data from.
660 * @msg: Various user space related information.
661 * @size: Size of user buffer.
662 * @flags: User specified flags.
664 * Copy received data to the socket user.
665 * Returns non-negative upon success, negative otherwise.
667 static int llc_ui_recvmsg(struct kiocb *iocb, struct socket *sock,
668 struct msghdr *msg, size_t size, int flags)
670 struct sock *sk = sock->sk;
671 struct sockaddr_llc *uaddr = (struct sockaddr_llc *)msg->msg_name;
674 int rc = -ENOMEM, timeout;
675 int noblock = flags & MSG_DONTWAIT;
677 dprintk("%s: receiving in %02X from %02X\n", __FUNCTION__,
678 llc_sk(sk)->laddr.lsap, llc_sk(sk)->daddr.lsap);
680 timeout = sock_rcvtimeo(sk, noblock);
681 rc = llc_ui_wait_for_data(sk, timeout);
683 dprintk("%s: llc_ui_wait_for_data failed recv "
684 "in %02X from %02X\n", __FUNCTION__,
685 llc_sk(sk)->laddr.lsap, llc_sk(sk)->daddr.lsap);
688 skb = skb_dequeue(&sk->sk_receive_queue);
689 if (!skb) /* shutdown */
694 rc = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
697 if (skb->len > copied) {
698 skb_pull(skb, copied);
699 skb_queue_head(&sk->sk_receive_queue, skb);
702 memcpy(uaddr, llc_ui_skb_cb(skb), sizeof(*uaddr));
703 msg->msg_namelen = sizeof(*uaddr);
710 return rc ? : copied;
714 * llc_ui_sendmsg - Transmit data provided by the socket user.
715 * @sock: Socket to transmit data from.
716 * @msg: Various user related information.
717 * @len: Length of data to transmit.
719 * Transmit data provided by the socket user.
720 * Returns non-negative upon success, negative otherwise.
722 static int llc_ui_sendmsg(struct kiocb *iocb, struct socket *sock,
723 struct msghdr *msg, size_t len)
725 struct sock *sk = sock->sk;
726 struct llc_sock *llc = llc_sk(sk);
727 struct sockaddr_llc *addr = (struct sockaddr_llc *)msg->msg_name;
728 int flags = msg->msg_flags;
729 int noblock = flags & MSG_DONTWAIT;
732 int rc = -EINVAL, copied = 0, hdrlen;
734 dprintk("%s: sending from %02X to %02X\n", __FUNCTION__,
735 llc->laddr.lsap, llc->daddr.lsap);
738 if (msg->msg_namelen < sizeof(*addr))
741 if (llc_ui_addr_null(&llc->addr))
745 /* must bind connection to sap if user hasn't done it. */
746 if (sock_flag(sk, SOCK_ZAPPED)) {
747 /* bind to sap with null dev, exclusive. */
748 rc = llc_ui_autobind(sock, addr);
752 hdrlen = llc->dev->hard_header_len + llc_ui_header_len(sk, addr);
754 if (size > llc->dev->mtu)
755 size = llc->dev->mtu;
756 copied = size - hdrlen;
758 skb = sock_alloc_send_skb(sk, size, noblock, &rc);
764 skb->protocol = llc_proto_type(addr->sllc_arphrd);
765 skb_reserve(skb, hdrlen);
766 rc = memcpy_fromiovec(skb_put(skb, copied), msg->msg_iov, copied);
769 if (sk->sk_type == SOCK_DGRAM || addr->sllc_ua) {
770 llc_build_and_send_ui_pkt(llc->sap, skb, addr->sllc_mac,
774 if (addr->sllc_test) {
775 llc_build_and_send_test_pkt(llc->sap, skb, addr->sllc_mac,
779 if (addr->sllc_xid) {
780 llc_build_and_send_xid_pkt(llc->sap, skb, addr->sllc_mac,
785 if (!(sk->sk_type == SOCK_STREAM && !addr->sllc_ua))
787 rc = llc_ui_send_data(sk, skb, noblock);
789 dprintk("%s: llc_ui_send_data failed: %d\n", __FUNCTION__, rc);
795 dprintk("%s: failed sending from %02X to %02X: %d\n",
796 __FUNCTION__, llc->laddr.lsap, llc->daddr.lsap, rc);
798 return rc ? : copied;
802 * llc_ui_getname - return the address info of a socket
803 * @sock: Socket to get address of.
804 * @uaddr: Address structure to return information.
805 * @uaddrlen: Length of address structure.
806 * @peer: Does user want local or remote address information.
808 * Return the address information of a socket.
810 static int llc_ui_getname(struct socket *sock, struct sockaddr *uaddr,
811 int *uaddrlen, int peer)
813 struct sockaddr_llc sllc;
814 struct sock *sk = sock->sk;
815 struct llc_sock *llc = llc_sk(sk);
819 if (sock_flag(sk, SOCK_ZAPPED))
821 *uaddrlen = sizeof(sllc);
822 memset(uaddr, 0, *uaddrlen);
825 if (sk->sk_state != TCP_ESTABLISHED)
828 sllc.sllc_arphrd = llc->dev->type;
829 sllc.sllc_sap = llc->daddr.lsap;
830 memcpy(&sllc.sllc_mac, &llc->daddr.mac, IFHWADDRLEN);
835 sllc.sllc_sap = llc->sap->laddr.lsap;
838 sllc.sllc_arphrd = llc->dev->type;
839 memcpy(&sllc.sllc_mac, &llc->dev->dev_addr,
844 sllc.sllc_family = AF_LLC;
845 memcpy(uaddr, &sllc, sizeof(sllc));
852 * llc_ui_ioctl - io controls for PF_LLC
853 * @sock: Socket to get/set info
855 * @arg: optional argument for cmd
857 * get/set info on llc sockets
859 static int llc_ui_ioctl(struct socket *sock, unsigned int cmd,
862 return dev_ioctl(cmd, (void __user *)arg);
866 * llc_ui_setsockopt - set various connection specific parameters.
867 * @sock: Socket to set options on.
868 * @level: Socket level user is requesting operations on.
869 * @optname: Operation name.
870 * @optval User provided operation data.
871 * @optlen: Length of optval.
873 * Set various connection specific parameters.
875 static int llc_ui_setsockopt(struct socket *sock, int level, int optname,
876 char __user *optval, int optlen)
878 struct sock *sk = sock->sk;
879 struct llc_sock *llc = llc_sk(sk);
880 int rc = -EINVAL, opt;
883 if (level != SOL_LLC || optlen != sizeof(int))
885 rc = get_user(opt, (int __user *)optval);
891 if (opt > LLC_OPT_MAX_RETRY)
896 if (opt > LLC_OPT_MAX_SIZE)
900 case LLC_OPT_ACK_TMR_EXP:
901 if (opt > LLC_OPT_MAX_ACK_TMR_EXP)
903 llc->ack_timer.expire = opt;
905 case LLC_OPT_P_TMR_EXP:
906 if (opt > LLC_OPT_MAX_P_TMR_EXP)
908 llc->pf_cycle_timer.expire = opt;
910 case LLC_OPT_REJ_TMR_EXP:
911 if (opt > LLC_OPT_MAX_REJ_TMR_EXP)
913 llc->rej_sent_timer.expire = opt;
915 case LLC_OPT_BUSY_TMR_EXP:
916 if (opt > LLC_OPT_MAX_BUSY_TMR_EXP)
918 llc->busy_state_timer.expire = opt;
921 if (opt > LLC_OPT_MAX_WIN)
926 if (opt > LLC_OPT_MAX_WIN)
941 * llc_ui_getsockopt - get connection specific socket info
942 * @sock: Socket to get information from.
943 * @level: Socket level user is requesting operations on.
944 * @optname: Operation name.
945 * @optval: Variable to return operation data in.
946 * @optlen: Length of optval.
948 * Get connection specific socket information.
950 static int llc_ui_getsockopt(struct socket *sock, int level, int optname,
951 char __user *optval, int __user *optlen)
953 struct sock *sk = sock->sk;
954 struct llc_sock *llc = llc_sk(sk);
955 int val = 0, len = 0, rc = -EINVAL;
958 if (level != SOL_LLC)
960 rc = get_user(len, optlen);
964 if (len != sizeof(int))
968 val = llc->n2; break;
970 val = llc->n1; break;
971 case LLC_OPT_ACK_TMR_EXP:
972 val = llc->ack_timer.expire; break;
973 case LLC_OPT_P_TMR_EXP:
974 val = llc->pf_cycle_timer.expire; break;
975 case LLC_OPT_REJ_TMR_EXP:
976 val = llc->rej_sent_timer.expire; break;
977 case LLC_OPT_BUSY_TMR_EXP:
978 val = llc->busy_state_timer.expire; break;
982 val = llc->rw; break;
988 if (put_user(len, optlen) || copy_to_user(optval, &val, len))
995 static struct net_proto_family llc_ui_family_ops = {
997 .create = llc_ui_create,
998 .owner = THIS_MODULE,
1001 static struct proto_ops llc_ui_ops = {
1003 .owner = THIS_MODULE,
1004 .release = llc_ui_release,
1005 .bind = llc_ui_bind,
1006 .connect = llc_ui_connect,
1007 .socketpair = sock_no_socketpair,
1008 .accept = llc_ui_accept,
1009 .getname = llc_ui_getname,
1010 .poll = datagram_poll,
1011 .ioctl = llc_ui_ioctl,
1012 .listen = llc_ui_listen,
1013 .shutdown = llc_ui_shutdown,
1014 .setsockopt = llc_ui_setsockopt,
1015 .getsockopt = llc_ui_getsockopt,
1016 .sendmsg = llc_ui_sendmsg,
1017 .recvmsg = llc_ui_recvmsg,
1018 .mmap = sock_no_mmap,
1019 .sendpage = sock_no_sendpage,
1022 extern void llc_sap_handler(struct llc_sap *sap, struct sk_buff *skb);
1023 extern void llc_conn_handler(struct llc_sap *sap, struct sk_buff *skb);
1025 static int __init llc2_init(void)
1027 int rc = proto_register(&llc_proto, 0);
1032 llc_build_offset_table();
1034 llc_ui_sap_last_autoport = LLC_SAP_DYN_START;
1035 rc = llc_proc_init();
1037 goto out_unregister_llc_proto;
1038 sock_register(&llc_ui_family_ops);
1039 llc_add_pack(LLC_DEST_SAP, llc_sap_handler);
1040 llc_add_pack(LLC_DEST_CONN, llc_conn_handler);
1043 out_unregister_llc_proto:
1044 proto_unregister(&llc_proto);
1048 static void __exit llc2_exit(void)
1051 llc_remove_pack(LLC_DEST_SAP);
1052 llc_remove_pack(LLC_DEST_CONN);
1053 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);