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--;
632 dprintk("%s: ok success on %02X, client on %02X\n", __FUNCTION__,
633 llc_sk(sk)->addr.sllc_sap, newllc->daddr.lsap);
642 * llc_ui_recvmsg - copy received data to the socket user.
643 * @sock: Socket to copy data from.
644 * @msg: Various user space related information.
645 * @size: Size of user buffer.
646 * @flags: User specified flags.
648 * Copy received data to the socket user.
649 * Returns non-negative upon success, negative otherwise.
651 static int llc_ui_recvmsg(struct kiocb *iocb, struct socket *sock,
652 struct msghdr *msg, size_t size, int flags)
654 struct sock *sk = sock->sk;
655 struct sockaddr_llc *uaddr = (struct sockaddr_llc *)msg->msg_name;
659 int noblock = flags & MSG_DONTWAIT;
661 dprintk("%s: receiving in %02X from %02X\n", __FUNCTION__,
662 llc_sk(sk)->laddr.lsap, llc_sk(sk)->daddr.lsap);
664 if (skb_queue_empty(&sk->sk_receive_queue)) {
665 rc = llc_wait_data(sk, sock_rcvtimeo(sk, noblock));
669 skb = skb_dequeue(&sk->sk_receive_queue);
670 if (!skb) /* shutdown */
675 rc = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
678 if (skb->len > copied) {
679 skb_pull(skb, copied);
680 skb_queue_head(&sk->sk_receive_queue, skb);
683 memcpy(uaddr, llc_ui_skb_cb(skb), sizeof(*uaddr));
684 msg->msg_namelen = sizeof(*uaddr);
691 return rc ? : copied;
695 * llc_ui_sendmsg - Transmit data provided by the socket user.
696 * @sock: Socket to transmit data from.
697 * @msg: Various user related information.
698 * @len: Length of data to transmit.
700 * Transmit data provided by the socket user.
701 * Returns non-negative upon success, negative otherwise.
703 static int llc_ui_sendmsg(struct kiocb *iocb, struct socket *sock,
704 struct msghdr *msg, size_t len)
706 struct sock *sk = sock->sk;
707 struct llc_sock *llc = llc_sk(sk);
708 struct sockaddr_llc *addr = (struct sockaddr_llc *)msg->msg_name;
709 int flags = msg->msg_flags;
710 int noblock = flags & MSG_DONTWAIT;
713 int rc = -EINVAL, copied = 0, hdrlen;
715 dprintk("%s: sending from %02X to %02X\n", __FUNCTION__,
716 llc->laddr.lsap, llc->daddr.lsap);
719 if (msg->msg_namelen < sizeof(*addr))
722 if (llc_ui_addr_null(&llc->addr))
726 /* must bind connection to sap if user hasn't done it. */
727 if (sock_flag(sk, SOCK_ZAPPED)) {
728 /* bind to sap with null dev, exclusive. */
729 rc = llc_ui_autobind(sock, addr);
733 hdrlen = llc->dev->hard_header_len + llc_ui_header_len(sk, addr);
735 if (size > llc->dev->mtu)
736 size = llc->dev->mtu;
737 copied = size - hdrlen;
739 skb = sock_alloc_send_skb(sk, size, noblock, &rc);
745 skb->protocol = llc_proto_type(addr->sllc_arphrd);
746 skb_reserve(skb, hdrlen);
747 rc = memcpy_fromiovec(skb_put(skb, copied), msg->msg_iov, copied);
750 if (sk->sk_type == SOCK_DGRAM || addr->sllc_ua) {
751 llc_build_and_send_ui_pkt(llc->sap, skb, addr->sllc_mac,
755 if (addr->sllc_test) {
756 llc_build_and_send_test_pkt(llc->sap, skb, addr->sllc_mac,
760 if (addr->sllc_xid) {
761 llc_build_and_send_xid_pkt(llc->sap, skb, addr->sllc_mac,
766 if (!(sk->sk_type == SOCK_STREAM && !addr->sllc_ua))
768 rc = llc_ui_send_data(sk, skb, noblock);
773 dprintk("%s: failed sending from %02X to %02X: %d\n",
774 __FUNCTION__, llc->laddr.lsap, llc->daddr.lsap, rc);
777 return rc ? : copied;
781 * llc_ui_getname - return the address info of a socket
782 * @sock: Socket to get address of.
783 * @uaddr: Address structure to return information.
784 * @uaddrlen: Length of address structure.
785 * @peer: Does user want local or remote address information.
787 * Return the address information of a socket.
789 static int llc_ui_getname(struct socket *sock, struct sockaddr *uaddr,
790 int *uaddrlen, int peer)
792 struct sockaddr_llc sllc;
793 struct sock *sk = sock->sk;
794 struct llc_sock *llc = llc_sk(sk);
798 if (sock_flag(sk, SOCK_ZAPPED))
800 *uaddrlen = sizeof(sllc);
801 memset(uaddr, 0, *uaddrlen);
804 if (sk->sk_state != TCP_ESTABLISHED)
807 sllc.sllc_arphrd = llc->dev->type;
808 sllc.sllc_sap = llc->daddr.lsap;
809 memcpy(&sllc.sllc_mac, &llc->daddr.mac, IFHWADDRLEN);
814 sllc.sllc_sap = llc->sap->laddr.lsap;
817 sllc.sllc_arphrd = llc->dev->type;
818 memcpy(&sllc.sllc_mac, &llc->dev->dev_addr,
823 sllc.sllc_family = AF_LLC;
824 memcpy(uaddr, &sllc, sizeof(sllc));
831 * llc_ui_ioctl - io controls for PF_LLC
832 * @sock: Socket to get/set info
834 * @arg: optional argument for cmd
836 * get/set info on llc sockets
838 static int llc_ui_ioctl(struct socket *sock, unsigned int cmd,
841 return dev_ioctl(cmd, (void __user *)arg);
845 * llc_ui_setsockopt - set various connection specific parameters.
846 * @sock: Socket to set options on.
847 * @level: Socket level user is requesting operations on.
848 * @optname: Operation name.
849 * @optval User provided operation data.
850 * @optlen: Length of optval.
852 * Set various connection specific parameters.
854 static int llc_ui_setsockopt(struct socket *sock, int level, int optname,
855 char __user *optval, int optlen)
857 struct sock *sk = sock->sk;
858 struct llc_sock *llc = llc_sk(sk);
859 int rc = -EINVAL, opt;
862 if (unlikely(level != SOL_LLC || optlen != sizeof(int)))
864 rc = get_user(opt, (int __user *)optval);
870 if (opt > LLC_OPT_MAX_RETRY)
875 if (opt > LLC_OPT_MAX_SIZE)
879 case LLC_OPT_ACK_TMR_EXP:
880 if (opt > LLC_OPT_MAX_ACK_TMR_EXP)
882 llc->ack_timer.expire = opt * HZ;
884 case LLC_OPT_P_TMR_EXP:
885 if (opt > LLC_OPT_MAX_P_TMR_EXP)
887 llc->pf_cycle_timer.expire = opt * HZ;
889 case LLC_OPT_REJ_TMR_EXP:
890 if (opt > LLC_OPT_MAX_REJ_TMR_EXP)
892 llc->rej_sent_timer.expire = opt * HZ;
894 case LLC_OPT_BUSY_TMR_EXP:
895 if (opt > LLC_OPT_MAX_BUSY_TMR_EXP)
897 llc->busy_state_timer.expire = opt * HZ;
900 if (opt > LLC_OPT_MAX_WIN)
905 if (opt > LLC_OPT_MAX_WIN)
920 * llc_ui_getsockopt - get connection specific socket info
921 * @sock: Socket to get information from.
922 * @level: Socket level user is requesting operations on.
923 * @optname: Operation name.
924 * @optval: Variable to return operation data in.
925 * @optlen: Length of optval.
927 * Get connection specific socket information.
929 static int llc_ui_getsockopt(struct socket *sock, int level, int optname,
930 char __user *optval, int __user *optlen)
932 struct sock *sk = sock->sk;
933 struct llc_sock *llc = llc_sk(sk);
934 int val = 0, len = 0, rc = -EINVAL;
937 if (unlikely(level != SOL_LLC))
939 rc = get_user(len, optlen);
943 if (len != sizeof(int))
947 val = llc->n2; break;
949 val = llc->n1; break;
950 case LLC_OPT_ACK_TMR_EXP:
951 val = llc->ack_timer.expire / HZ; break;
952 case LLC_OPT_P_TMR_EXP:
953 val = llc->pf_cycle_timer.expire / HZ; break;
954 case LLC_OPT_REJ_TMR_EXP:
955 val = llc->rej_sent_timer.expire / HZ; break;
956 case LLC_OPT_BUSY_TMR_EXP:
957 val = llc->busy_state_timer.expire / HZ; break;
961 val = llc->rw; break;
967 if (put_user(len, optlen) || copy_to_user(optval, &val, len))
974 static struct net_proto_family llc_ui_family_ops = {
976 .create = llc_ui_create,
977 .owner = THIS_MODULE,
980 static struct proto_ops llc_ui_ops = {
982 .owner = THIS_MODULE,
983 .release = llc_ui_release,
985 .connect = llc_ui_connect,
986 .socketpair = sock_no_socketpair,
987 .accept = llc_ui_accept,
988 .getname = llc_ui_getname,
989 .poll = datagram_poll,
990 .ioctl = llc_ui_ioctl,
991 .listen = llc_ui_listen,
992 .shutdown = llc_ui_shutdown,
993 .setsockopt = llc_ui_setsockopt,
994 .getsockopt = llc_ui_getsockopt,
995 .sendmsg = llc_ui_sendmsg,
996 .recvmsg = llc_ui_recvmsg,
997 .mmap = sock_no_mmap,
998 .sendpage = sock_no_sendpage,
1001 extern void llc_sap_handler(struct llc_sap *sap, struct sk_buff *skb);
1002 extern void llc_conn_handler(struct llc_sap *sap, struct sk_buff *skb);
1004 static char llc_proc_err_msg[] __initdata =
1005 KERN_CRIT "LLC: Unable to register the proc_fs entries\n";
1006 static char llc_sysctl_err_msg[] __initdata =
1007 KERN_CRIT "LLC: Unable to register the sysctl entries\n";
1008 static char llc_sock_err_msg[] __initdata =
1009 KERN_CRIT "LLC: Unable to register the network family\n";
1011 static int __init llc2_init(void)
1013 int rc = proto_register(&llc_proto, 0);
1018 llc_build_offset_table();
1020 llc_ui_sap_last_autoport = LLC_SAP_DYN_START;
1021 rc = llc_proc_init();
1023 printk(llc_proc_err_msg);
1024 goto out_unregister_llc_proto;
1026 rc = llc_sysctl_init();
1028 printk(llc_sysctl_err_msg);
1031 rc = sock_register(&llc_ui_family_ops);
1033 printk(llc_sock_err_msg);
1036 llc_add_pack(LLC_DEST_SAP, llc_sap_handler);
1037 llc_add_pack(LLC_DEST_CONN, llc_conn_handler);
1044 out_unregister_llc_proto:
1045 proto_unregister(&llc_proto);
1049 static void __exit llc2_exit(void)
1052 llc_remove_pack(LLC_DEST_SAP);
1053 llc_remove_pack(LLC_DEST_CONN);
1054 sock_unregister(PF_LLC);
1057 proto_unregister(&llc_proto);
1060 module_init(llc2_init);
1061 module_exit(llc2_exit);
1063 MODULE_LICENSE("GPL");
1064 MODULE_AUTHOR("Procom 1997, Jay Schullist 2001, Arnaldo C. Melo 2001-2003");
1065 MODULE_DESCRIPTION("IEEE 802.2 PF_LLC support");
1066 MODULE_ALIAS_NETPROTO(PF_LLC);