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) || llc->p_flag)) {
120 long 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 (likely(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;
180 if (unlikely(sk == NULL))
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);
201 * llc_ui_autoport - provide dynamically allocate SAP number
203 * Provide the caller with a dynamically allocated SAP number according
204 * to the rules that are set in this function. Returns: 0, upon failure,
205 * SAP number otherwise.
207 static int llc_ui_autoport(void)
212 while (tries < LLC_SAP_DYN_TRIES) {
213 for (i = llc_ui_sap_last_autoport;
214 i < LLC_SAP_DYN_STOP; i += 2) {
215 sap = llc_sap_find(i);
217 llc_ui_sap_last_autoport = i + 2;
222 llc_ui_sap_last_autoport = LLC_SAP_DYN_START;
231 * llc_ui_autobind - automatically bind a socket to a sap
232 * @sock: socket to bind
233 * @addr: address to connect to
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
238 * Returns: 0 upon success, negative otherwise.
240 static int llc_ui_autobind(struct socket *sock, struct sockaddr_llc *addr)
242 struct sock *sk = sock->sk;
243 struct llc_sock *llc = llc_sk(sk);
247 if (!sock_flag(sk, SOCK_ZAPPED))
250 llc->dev = dev_getfirstbyhwtype(addr->sllc_arphrd);
254 llc->laddr.lsap = llc_ui_autoport();
255 if (!llc->laddr.lsap)
257 rc = -EBUSY; /* some other network layer is using the sap */
258 sap = llc_sap_open(llc->laddr.lsap, NULL);
261 memcpy(llc->laddr.mac, llc->dev->dev_addr, IFHWADDRLEN);
262 memcpy(&llc->addr, addr, sizeof(llc->addr));
263 /* assign new connection to its SAP */
264 llc_sap_add_socket(sap, sk);
265 sock_reset_flag(sk, SOCK_ZAPPED);
272 * llc_ui_bind - bind a socket to a specific address.
273 * @sock: Socket to bind an address to.
274 * @uaddr: Address the user wants the socket bound to.
275 * @addrlen: Length of the uaddr structure.
277 * Bind a socket to a specific address. For llc a user is able to bind to
278 * a specific sap only or mac + sap.
279 * If the user desires to bind to a specific mac + sap, it is possible to
280 * have multiple sap connections via multiple macs.
281 * Bind and autobind for that matter must enforce the correct sap usage
282 * otherwise all hell will break loose.
283 * Returns: 0 upon success, negative otherwise.
285 static int llc_ui_bind(struct socket *sock, struct sockaddr *uaddr, int addrlen)
287 struct sockaddr_llc *addr = (struct sockaddr_llc *)uaddr;
288 struct sock *sk = sock->sk;
289 struct llc_sock *llc = llc_sk(sk);
293 dprintk("%s: binding %02X\n", __FUNCTION__, addr->sllc_sap);
294 if (unlikely(!sock_flag(sk, SOCK_ZAPPED) || addrlen != sizeof(*addr)))
297 if (unlikely(addr->sllc_family != AF_LLC))
301 llc->dev = dev_getbyhwaddr(addr->sllc_arphrd, addr->sllc_mac);
305 if (!addr->sllc_sap) {
307 addr->sllc_sap = llc_ui_autoport();
311 sap = llc_sap_find(addr->sllc_sap);
313 sap = llc_sap_open(addr->sllc_sap, NULL);
314 rc = -EBUSY; /* some other network layer is using the sap */
319 struct llc_addr laddr, daddr;
322 memset(&laddr, 0, sizeof(laddr));
323 memset(&daddr, 0, sizeof(daddr));
325 * FIXME: check if the the address is multicast,
326 * only SOCK_DGRAM can do this.
328 memcpy(laddr.mac, addr->sllc_mac, IFHWADDRLEN);
329 laddr.lsap = addr->sllc_sap;
330 rc = -EADDRINUSE; /* mac + sap clash. */
331 ask = llc_lookup_established(sap, &daddr, &laddr);
337 llc->laddr.lsap = addr->sllc_sap;
338 memcpy(llc->laddr.mac, addr->sllc_mac, IFHWADDRLEN);
339 memcpy(&llc->addr, addr, sizeof(llc->addr));
340 /* assign new connection to its SAP */
341 llc_sap_add_socket(sap, sk);
342 sock_reset_flag(sk, SOCK_ZAPPED);
351 * llc_ui_shutdown - shutdown a connect llc2 socket.
352 * @sock: Socket to shutdown.
353 * @how: What part of the socket to shutdown.
355 * Shutdown a connected llc2 socket. Currently this function only supports
356 * shutting down both sends and receives (2), we could probably make this
357 * function such that a user can shutdown only half the connection but not
359 * Returns: 0 upon success, negative otherwise.
361 static int llc_ui_shutdown(struct socket *sock, int how)
363 struct sock *sk = sock->sk;
367 if (unlikely(sk->sk_state != TCP_ESTABLISHED))
372 rc = llc_send_disc(sk);
374 rc = llc_ui_wait_for_disc(sk, sk->sk_rcvtimeo);
375 /* Wake up anyone sleeping in poll */
376 sk->sk_state_change(sk);
383 * llc_ui_connect - Connect to a remote llc2 mac + sap.
384 * @sock: Socket which will be connected to the remote destination.
385 * @uaddr: Remote and possibly the local address of the new connection.
386 * @addrlen: Size of uaddr structure.
387 * @flags: Operational flags specified by the user.
389 * Connect to a remote llc2 mac + sap. The caller must specify the
390 * destination mac and address to connect to. If the user hasn't previously
391 * called bind(2) with a smac the address of the first interface of the
392 * specified arp type will be used.
393 * This function will autobind if user did not previously call bind.
394 * Returns: 0 upon success, negative otherwise.
396 static int llc_ui_connect(struct socket *sock, struct sockaddr *uaddr,
397 int addrlen, int flags)
399 struct sock *sk = sock->sk;
400 struct llc_sock *llc = llc_sk(sk);
401 struct sockaddr_llc *addr = (struct sockaddr_llc *)uaddr;
405 if (unlikely(addrlen != sizeof(*addr)))
408 if (unlikely(addr->sllc_family != AF_LLC))
410 if (unlikely(sk->sk_type != SOCK_STREAM))
413 if (unlikely(sock->state == SS_CONNECTING))
415 /* bind connection to sap if user hasn't done it. */
416 if (sock_flag(sk, SOCK_ZAPPED)) {
417 /* bind to sap with null dev, exclusive */
418 rc = llc_ui_autobind(sock, addr);
421 llc->daddr.lsap = addr->sllc_sap;
422 memcpy(llc->daddr.mac, addr->sllc_mac, IFHWADDRLEN);
424 sock->state = SS_CONNECTING;
425 sk->sk_state = TCP_SYN_SENT;
426 llc->link = llc_ui_next_link_no(llc->sap->laddr.lsap);
427 rc = llc_establish_connection(sk, llc->dev->dev_addr,
428 addr->sllc_mac, addr->sllc_sap);
430 dprintk("%s: llc_ui_send_conn failed :-(\n", __FUNCTION__);
431 sock->state = SS_UNCONNECTED;
432 sk->sk_state = TCP_CLOSE;
436 if (sk->sk_state == TCP_SYN_SENT) {
437 const long timeo = sock_sndtimeo(sk, flags & O_NONBLOCK);
439 if (!timeo || !llc_ui_wait_for_conn(sk, timeo))
442 rc = sock_intr_errno(timeo);
443 if (signal_pending(current))
447 if (sk->sk_state == TCP_CLOSE)
450 sock->state = SS_CONNECTED;
456 rc = sock_error(sk) ? : -ECONNABORTED;
457 sock->state = SS_UNCONNECTED;
462 * llc_ui_listen - allow a normal socket to accept incoming connections
463 * @sock: Socket to allow incoming connections on.
464 * @backlog: Number of connections to queue.
466 * Allow a normal socket to accept incoming connections.
467 * Returns 0 upon success, negative otherwise.
469 static int llc_ui_listen(struct socket *sock, int backlog)
471 struct sock *sk = sock->sk;
475 if (unlikely(sock->state != SS_UNCONNECTED))
478 if (unlikely(sk->sk_type != SOCK_STREAM))
481 if (sock_flag(sk, SOCK_ZAPPED))
484 if (!(unsigned)backlog) /* BSDism */
486 sk->sk_max_ack_backlog = backlog;
487 if (sk->sk_state != TCP_LISTEN) {
488 sk->sk_ack_backlog = 0;
489 sk->sk_state = TCP_LISTEN;
491 sk->sk_socket->flags |= __SO_ACCEPTCON;
497 static int llc_ui_wait_for_disc(struct sock *sk, long timeout)
503 prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
504 if (sk_wait_event(sk, &timeout, sk->sk_state == TCP_CLOSE))
507 if (signal_pending(current))
514 finish_wait(sk->sk_sleep, &wait);
518 static int llc_ui_wait_for_conn(struct sock *sk, long timeout)
523 prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
524 if (sk_wait_event(sk, &timeout, sk->sk_state != TCP_SYN_SENT))
526 if (signal_pending(current) || !timeout)
529 finish_wait(sk->sk_sleep, &wait);
533 static int llc_ui_wait_for_busy_core(struct sock *sk, long timeout)
536 struct llc_sock *llc = llc_sk(sk);
540 prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
542 if (sk_wait_event(sk, &timeout,
543 (sk->sk_shutdown & RCV_SHUTDOWN) ||
544 (!llc_data_accept_state(llc->state) &&
548 if (signal_pending(current))
554 finish_wait(sk->sk_sleep, &wait);
558 int llc_wait_data(struct sock *sk, long timeo)
564 * POSIX 1003.1g mandates this order.
571 if (sk->sk_shutdown & RCV_SHUTDOWN)
576 rc = sock_intr_errno(timeo);
577 if (signal_pending(current))
580 if (sk_wait_data(sk, &timeo))
587 * llc_ui_accept - accept a new incoming connection.
588 * @sock: Socket which connections arrive on.
589 * @newsock: Socket to move incoming connection to.
590 * @flags: User specified operational flags.
592 * Accept a new incoming connection.
593 * Returns 0 upon success, negative otherwise.
595 static int llc_ui_accept(struct socket *sock, struct socket *newsock, int flags)
597 struct sock *sk = sock->sk, *newsk;
598 struct llc_sock *llc, *newllc;
600 int rc = -EOPNOTSUPP;
602 dprintk("%s: accepting on %02X\n", __FUNCTION__,
603 llc_sk(sk)->laddr.lsap);
605 if (unlikely(sk->sk_type != SOCK_STREAM))
608 if (unlikely(sock->state != SS_UNCONNECTED ||
609 sk->sk_state != TCP_LISTEN))
611 /* wait for a connection to arrive. */
612 if (skb_queue_empty(&sk->sk_receive_queue)) {
613 rc = llc_wait_data(sk, sk->sk_rcvtimeo);
617 dprintk("%s: got a new connection on %02X\n", __FUNCTION__,
618 llc_sk(sk)->laddr.lsap);
619 skb = skb_dequeue(&sk->sk_receive_queue);
625 /* attach connection to a new socket. */
626 llc_ui_sk_init(newsock, newsk);
627 sock_reset_flag(newsk, SOCK_ZAPPED);
628 newsk->sk_state = TCP_ESTABLISHED;
629 newsock->state = SS_CONNECTED;
631 newllc = llc_sk(newsk);
632 memcpy(&newllc->addr, &llc->addr, sizeof(newllc->addr));
633 newllc->link = llc_ui_next_link_no(newllc->laddr.lsap);
635 /* put original socket back into a clean listen state. */
636 sk->sk_state = TCP_LISTEN;
637 sk->sk_ack_backlog--;
638 dprintk("%s: ok success on %02X, client on %02X\n", __FUNCTION__,
639 llc_sk(sk)->addr.sllc_sap, newllc->daddr.lsap);
648 * llc_ui_recvmsg - copy received data to the socket user.
649 * @sock: Socket to copy data from.
650 * @msg: Various user space related information.
651 * @size: Size of user buffer.
652 * @flags: User specified flags.
654 * Copy received data to the socket user.
655 * Returns non-negative upon success, negative otherwise.
657 static int llc_ui_recvmsg(struct kiocb *iocb, struct socket *sock,
658 struct msghdr *msg, size_t size, int flags)
660 struct sock *sk = sock->sk;
661 struct sockaddr_llc *uaddr = (struct sockaddr_llc *)msg->msg_name;
665 int noblock = flags & MSG_DONTWAIT;
667 dprintk("%s: receiving in %02X from %02X\n", __FUNCTION__,
668 llc_sk(sk)->laddr.lsap, llc_sk(sk)->daddr.lsap);
670 if (skb_queue_empty(&sk->sk_receive_queue)) {
671 rc = llc_wait_data(sk, sock_rcvtimeo(sk, noblock));
675 skb = skb_dequeue(&sk->sk_receive_queue);
676 if (!skb) /* shutdown */
681 rc = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
684 if (skb->len > copied) {
685 skb_pull(skb, copied);
686 skb_queue_head(&sk->sk_receive_queue, skb);
689 memcpy(uaddr, llc_ui_skb_cb(skb), sizeof(*uaddr));
690 msg->msg_namelen = sizeof(*uaddr);
697 return rc ? : copied;
701 * llc_ui_sendmsg - Transmit data provided by the socket user.
702 * @sock: Socket to transmit data from.
703 * @msg: Various user related information.
704 * @len: Length of data to transmit.
706 * Transmit data provided by the socket user.
707 * Returns non-negative upon success, negative otherwise.
709 static int llc_ui_sendmsg(struct kiocb *iocb, struct socket *sock,
710 struct msghdr *msg, size_t len)
712 struct sock *sk = sock->sk;
713 struct llc_sock *llc = llc_sk(sk);
714 struct sockaddr_llc *addr = (struct sockaddr_llc *)msg->msg_name;
715 int flags = msg->msg_flags;
716 int noblock = flags & MSG_DONTWAIT;
719 int rc = -EINVAL, copied = 0, hdrlen;
721 dprintk("%s: sending from %02X to %02X\n", __FUNCTION__,
722 llc->laddr.lsap, llc->daddr.lsap);
725 if (msg->msg_namelen < sizeof(*addr))
728 if (llc_ui_addr_null(&llc->addr))
732 /* must bind connection to sap if user hasn't done it. */
733 if (sock_flag(sk, SOCK_ZAPPED)) {
734 /* bind to sap with null dev, exclusive. */
735 rc = llc_ui_autobind(sock, addr);
739 hdrlen = llc->dev->hard_header_len + llc_ui_header_len(sk, addr);
741 if (size > llc->dev->mtu)
742 size = llc->dev->mtu;
743 copied = size - hdrlen;
745 skb = sock_alloc_send_skb(sk, size, noblock, &rc);
750 skb->protocol = llc_proto_type(addr->sllc_arphrd);
751 skb_reserve(skb, hdrlen);
752 rc = memcpy_fromiovec(skb_put(skb, copied), msg->msg_iov, copied);
755 if (sk->sk_type == SOCK_DGRAM || addr->sllc_ua) {
756 llc_build_and_send_ui_pkt(llc->sap, skb, addr->sllc_mac,
760 if (addr->sllc_test) {
761 llc_build_and_send_test_pkt(llc->sap, skb, addr->sllc_mac,
765 if (addr->sllc_xid) {
766 llc_build_and_send_xid_pkt(llc->sap, skb, addr->sllc_mac,
771 if (!(sk->sk_type == SOCK_STREAM && !addr->sllc_ua))
773 rc = llc_ui_send_data(sk, skb, noblock);
778 dprintk("%s: failed sending from %02X to %02X: %d\n",
779 __FUNCTION__, llc->laddr.lsap, llc->daddr.lsap, rc);
782 return rc ? : copied;
786 * llc_ui_getname - return the address info of a socket
787 * @sock: Socket to get address of.
788 * @uaddr: Address structure to return information.
789 * @uaddrlen: Length of address structure.
790 * @peer: Does user want local or remote address information.
792 * Return the address information of a socket.
794 static int llc_ui_getname(struct socket *sock, struct sockaddr *uaddr,
795 int *uaddrlen, int peer)
797 struct sockaddr_llc sllc;
798 struct sock *sk = sock->sk;
799 struct llc_sock *llc = llc_sk(sk);
803 if (sock_flag(sk, SOCK_ZAPPED))
805 *uaddrlen = sizeof(sllc);
806 memset(uaddr, 0, *uaddrlen);
809 if (sk->sk_state != TCP_ESTABLISHED)
812 sllc.sllc_arphrd = llc->dev->type;
813 sllc.sllc_sap = llc->daddr.lsap;
814 memcpy(&sllc.sllc_mac, &llc->daddr.mac, IFHWADDRLEN);
819 sllc.sllc_sap = llc->sap->laddr.lsap;
822 sllc.sllc_arphrd = llc->dev->type;
823 memcpy(&sllc.sllc_mac, &llc->dev->dev_addr,
828 sllc.sllc_family = AF_LLC;
829 memcpy(uaddr, &sllc, sizeof(sllc));
836 * llc_ui_ioctl - io controls for PF_LLC
837 * @sock: Socket to get/set info
839 * @arg: optional argument for cmd
841 * get/set info on llc sockets
843 static int llc_ui_ioctl(struct socket *sock, unsigned int cmd,
846 return dev_ioctl(cmd, (void __user *)arg);
850 * llc_ui_setsockopt - set various connection specific parameters.
851 * @sock: Socket to set options on.
852 * @level: Socket level user is requesting operations on.
853 * @optname: Operation name.
854 * @optval User provided operation data.
855 * @optlen: Length of optval.
857 * Set various connection specific parameters.
859 static int llc_ui_setsockopt(struct socket *sock, int level, int optname,
860 char __user *optval, int optlen)
862 struct sock *sk = sock->sk;
863 struct llc_sock *llc = llc_sk(sk);
864 int rc = -EINVAL, opt;
867 if (unlikely(level != SOL_LLC || optlen != sizeof(int)))
869 rc = get_user(opt, (int __user *)optval);
875 if (opt > LLC_OPT_MAX_RETRY)
880 if (opt > LLC_OPT_MAX_SIZE)
884 case LLC_OPT_ACK_TMR_EXP:
885 if (opt > LLC_OPT_MAX_ACK_TMR_EXP)
887 llc->ack_timer.expire = opt * HZ;
889 case LLC_OPT_P_TMR_EXP:
890 if (opt > LLC_OPT_MAX_P_TMR_EXP)
892 llc->pf_cycle_timer.expire = opt * HZ;
894 case LLC_OPT_REJ_TMR_EXP:
895 if (opt > LLC_OPT_MAX_REJ_TMR_EXP)
897 llc->rej_sent_timer.expire = opt * HZ;
899 case LLC_OPT_BUSY_TMR_EXP:
900 if (opt > LLC_OPT_MAX_BUSY_TMR_EXP)
902 llc->busy_state_timer.expire = opt * HZ;
905 if (opt > LLC_OPT_MAX_WIN)
910 if (opt > LLC_OPT_MAX_WIN)
925 * llc_ui_getsockopt - get connection specific socket info
926 * @sock: Socket to get information from.
927 * @level: Socket level user is requesting operations on.
928 * @optname: Operation name.
929 * @optval: Variable to return operation data in.
930 * @optlen: Length of optval.
932 * Get connection specific socket information.
934 static int llc_ui_getsockopt(struct socket *sock, int level, int optname,
935 char __user *optval, int __user *optlen)
937 struct sock *sk = sock->sk;
938 struct llc_sock *llc = llc_sk(sk);
939 int val = 0, len = 0, rc = -EINVAL;
942 if (unlikely(level != SOL_LLC))
944 rc = get_user(len, optlen);
948 if (len != sizeof(int))
952 val = llc->n2; break;
954 val = llc->n1; break;
955 case LLC_OPT_ACK_TMR_EXP:
956 val = llc->ack_timer.expire / HZ; break;
957 case LLC_OPT_P_TMR_EXP:
958 val = llc->pf_cycle_timer.expire / HZ; break;
959 case LLC_OPT_REJ_TMR_EXP:
960 val = llc->rej_sent_timer.expire / HZ; break;
961 case LLC_OPT_BUSY_TMR_EXP:
962 val = llc->busy_state_timer.expire / HZ; break;
966 val = llc->rw; break;
972 if (put_user(len, optlen) || copy_to_user(optval, &val, len))
979 static struct net_proto_family llc_ui_family_ops = {
981 .create = llc_ui_create,
982 .owner = THIS_MODULE,
985 static struct proto_ops llc_ui_ops = {
987 .owner = THIS_MODULE,
988 .release = llc_ui_release,
990 .connect = llc_ui_connect,
991 .socketpair = sock_no_socketpair,
992 .accept = llc_ui_accept,
993 .getname = llc_ui_getname,
994 .poll = datagram_poll,
995 .ioctl = llc_ui_ioctl,
996 .listen = llc_ui_listen,
997 .shutdown = llc_ui_shutdown,
998 .setsockopt = llc_ui_setsockopt,
999 .getsockopt = llc_ui_getsockopt,
1000 .sendmsg = llc_ui_sendmsg,
1001 .recvmsg = llc_ui_recvmsg,
1002 .mmap = sock_no_mmap,
1003 .sendpage = sock_no_sendpage,
1006 extern void llc_sap_handler(struct llc_sap *sap, struct sk_buff *skb);
1007 extern void llc_conn_handler(struct llc_sap *sap, struct sk_buff *skb);
1009 static char llc_proc_err_msg[] __initdata =
1010 KERN_CRIT "LLC: Unable to register the proc_fs entries\n";
1011 static char llc_sysctl_err_msg[] __initdata =
1012 KERN_CRIT "LLC: Unable to register the sysctl entries\n";
1013 static char llc_sock_err_msg[] __initdata =
1014 KERN_CRIT "LLC: Unable to register the network family\n";
1016 static int __init llc2_init(void)
1018 int rc = proto_register(&llc_proto, 0);
1023 llc_build_offset_table();
1025 llc_ui_sap_last_autoport = LLC_SAP_DYN_START;
1026 rc = llc_proc_init();
1028 printk(llc_proc_err_msg);
1029 goto out_unregister_llc_proto;
1031 rc = llc_sysctl_init();
1033 printk(llc_sysctl_err_msg);
1036 rc = sock_register(&llc_ui_family_ops);
1038 printk(llc_sock_err_msg);
1041 llc_add_pack(LLC_DEST_SAP, llc_sap_handler);
1042 llc_add_pack(LLC_DEST_CONN, llc_conn_handler);
1049 out_unregister_llc_proto:
1050 proto_unregister(&llc_proto);
1054 static void __exit llc2_exit(void)
1057 llc_remove_pack(LLC_DEST_SAP);
1058 llc_remove_pack(LLC_DEST_CONN);
1059 sock_unregister(PF_LLC);
1062 proto_unregister(&llc_proto);
1065 module_init(llc2_init);
1066 module_exit(llc2_exit);
1068 MODULE_LICENSE("GPL");
1069 MODULE_AUTHOR("Procom 1997, Jay Schullist 2001, Arnaldo C. Melo 2001-2003");
1070 MODULE_DESCRIPTION("IEEE 802.2 PF_LLC support");
1071 MODULE_ALIAS_NETPROTO(PF_LLC);