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 const 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, 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) ||
119 llc->remote_busy_flag ||
121 long timeout = sock_sndtimeo(sk, noblock);
123 rc = llc_ui_wait_for_busy_core(sk, timeout);
126 rc = llc_build_and_send_pkt(sk, skb);
130 static void llc_ui_sk_init(struct socket *sock, struct sock *sk)
132 sk->sk_type = sock->type;
133 sk->sk_sleep = &sock->wait;
134 sk->sk_socket = sock;
136 sock->ops = &llc_ui_ops;
139 static struct proto llc_proto = {
141 .owner = THIS_MODULE,
142 .obj_size = sizeof(struct llc_sock),
146 * llc_ui_create - alloc and init a new llc_ui socket
147 * @sock: Socket to initialize and attach allocated sk to.
150 * Allocate and initialize a new llc_ui socket, validate the user wants a
151 * socket type we have available.
152 * Returns 0 upon success, negative upon failure.
154 static int llc_ui_create(struct socket *sock, int protocol)
157 int rc = -ESOCKTNOSUPPORT;
159 if (likely(sock->type == SOCK_DGRAM || sock->type == SOCK_STREAM)) {
161 sk = llc_sk_alloc(PF_LLC, GFP_KERNEL, &llc_proto);
164 llc_ui_sk_init(sock, sk);
171 * llc_ui_release - shutdown socket
172 * @sock: Socket to release.
174 * Shutdown and deallocate an existing socket.
176 static int llc_ui_release(struct socket *sock)
178 struct sock *sk = sock->sk;
179 struct llc_sock *llc;
181 if (unlikely(sk == NULL))
186 dprintk("%s: closing local(%02X) remote(%02X)\n", __FUNCTION__,
187 llc->laddr.lsap, llc->daddr.lsap);
188 if (!llc_send_disc(sk))
189 llc_ui_wait_for_disc(sk, sk->sk_rcvtimeo);
190 if (!sock_flag(sk, SOCK_ZAPPED))
191 llc_sap_remove_socket(llc->sap, sk);
202 * llc_ui_autoport - provide dynamically allocate SAP number
204 * Provide the caller with a dynamically allocated SAP number according
205 * to the rules that are set in this function. Returns: 0, upon failure,
206 * SAP number otherwise.
208 static int llc_ui_autoport(void)
213 while (tries < LLC_SAP_DYN_TRIES) {
214 for (i = llc_ui_sap_last_autoport;
215 i < LLC_SAP_DYN_STOP; i += 2) {
216 sap = llc_sap_find(i);
218 llc_ui_sap_last_autoport = i + 2;
223 llc_ui_sap_last_autoport = LLC_SAP_DYN_START;
232 * llc_ui_autobind - automatically bind a socket to a sap
233 * @sock: socket to bind
234 * @addr: address to connect to
236 * Used by llc_ui_connect and llc_ui_sendmsg when the user hasn't
237 * specifically used llc_ui_bind to bind to an specific address/sap
239 * Returns: 0 upon success, negative otherwise.
241 static int llc_ui_autobind(struct socket *sock, struct sockaddr_llc *addr)
243 struct sock *sk = sock->sk;
244 struct llc_sock *llc = llc_sk(sk);
248 if (!sock_flag(sk, SOCK_ZAPPED))
251 llc->dev = dev_getfirstbyhwtype(addr->sllc_arphrd);
255 llc->laddr.lsap = llc_ui_autoport();
256 if (!llc->laddr.lsap)
258 rc = -EBUSY; /* some other network layer is using the sap */
259 sap = llc_sap_open(llc->laddr.lsap, NULL);
262 memcpy(llc->laddr.mac, llc->dev->dev_addr, IFHWADDRLEN);
263 memcpy(&llc->addr, addr, sizeof(llc->addr));
264 /* assign new connection to its SAP */
265 llc_sap_add_socket(sap, sk);
266 sock_reset_flag(sk, SOCK_ZAPPED);
273 * llc_ui_bind - bind a socket to a specific address.
274 * @sock: Socket to bind an address to.
275 * @uaddr: Address the user wants the socket bound to.
276 * @addrlen: Length of the uaddr structure.
278 * Bind a socket to a specific address. For llc a user is able to bind to
279 * a specific sap only or mac + sap.
280 * If the user desires to bind to a specific mac + sap, it is possible to
281 * have multiple sap connections via multiple macs.
282 * Bind and autobind for that matter must enforce the correct sap usage
283 * otherwise all hell will break loose.
284 * Returns: 0 upon success, negative otherwise.
286 static int llc_ui_bind(struct socket *sock, struct sockaddr *uaddr, int addrlen)
288 struct sockaddr_llc *addr = (struct sockaddr_llc *)uaddr;
289 struct sock *sk = sock->sk;
290 struct llc_sock *llc = llc_sk(sk);
294 dprintk("%s: binding %02X\n", __FUNCTION__, addr->sllc_sap);
295 if (unlikely(!sock_flag(sk, SOCK_ZAPPED) || addrlen != sizeof(*addr)))
298 if (unlikely(addr->sllc_family != AF_LLC))
302 llc->dev = dev_getbyhwaddr(addr->sllc_arphrd, addr->sllc_mac);
306 if (!addr->sllc_sap) {
308 addr->sllc_sap = llc_ui_autoport();
312 sap = llc_sap_find(addr->sllc_sap);
314 sap = llc_sap_open(addr->sllc_sap, NULL);
315 rc = -EBUSY; /* some other network layer is using the sap */
320 struct llc_addr laddr, daddr;
323 memset(&laddr, 0, sizeof(laddr));
324 memset(&daddr, 0, sizeof(daddr));
326 * FIXME: check if the the address is multicast,
327 * only SOCK_DGRAM can do this.
329 memcpy(laddr.mac, addr->sllc_mac, IFHWADDRLEN);
330 laddr.lsap = addr->sllc_sap;
331 rc = -EADDRINUSE; /* mac + sap clash. */
332 ask = llc_lookup_established(sap, &daddr, &laddr);
338 llc->laddr.lsap = addr->sllc_sap;
339 memcpy(llc->laddr.mac, addr->sllc_mac, IFHWADDRLEN);
340 memcpy(&llc->addr, addr, sizeof(llc->addr));
341 /* assign new connection to its SAP */
342 llc_sap_add_socket(sap, sk);
343 sock_reset_flag(sk, SOCK_ZAPPED);
352 * llc_ui_shutdown - shutdown a connect llc2 socket.
353 * @sock: Socket to shutdown.
354 * @how: What part of the socket to shutdown.
356 * Shutdown a connected llc2 socket. Currently this function only supports
357 * shutting down both sends and receives (2), we could probably make this
358 * function such that a user can shutdown only half the connection but not
360 * Returns: 0 upon success, negative otherwise.
362 static int llc_ui_shutdown(struct socket *sock, int how)
364 struct sock *sk = sock->sk;
368 if (unlikely(sk->sk_state != TCP_ESTABLISHED))
373 rc = llc_send_disc(sk);
375 rc = llc_ui_wait_for_disc(sk, sk->sk_rcvtimeo);
376 /* Wake up anyone sleeping in poll */
377 sk->sk_state_change(sk);
384 * llc_ui_connect - Connect to a remote llc2 mac + sap.
385 * @sock: Socket which will be connected to the remote destination.
386 * @uaddr: Remote and possibly the local address of the new connection.
387 * @addrlen: Size of uaddr structure.
388 * @flags: Operational flags specified by the user.
390 * Connect to a remote llc2 mac + sap. The caller must specify the
391 * destination mac and address to connect to. If the user hasn't previously
392 * called bind(2) with a smac the address of the first interface of the
393 * specified arp type will be used.
394 * This function will autobind if user did not previously call bind.
395 * Returns: 0 upon success, negative otherwise.
397 static int llc_ui_connect(struct socket *sock, struct sockaddr *uaddr,
398 int addrlen, int flags)
400 struct sock *sk = sock->sk;
401 struct llc_sock *llc = llc_sk(sk);
402 struct sockaddr_llc *addr = (struct sockaddr_llc *)uaddr;
406 if (unlikely(addrlen != sizeof(*addr)))
409 if (unlikely(addr->sllc_family != AF_LLC))
411 if (unlikely(sk->sk_type != SOCK_STREAM))
414 if (unlikely(sock->state == SS_CONNECTING))
416 /* bind connection to sap if user hasn't done it. */
417 if (sock_flag(sk, SOCK_ZAPPED)) {
418 /* bind to sap with null dev, exclusive */
419 rc = llc_ui_autobind(sock, addr);
423 llc->daddr.lsap = addr->sllc_sap;
424 memcpy(llc->daddr.mac, addr->sllc_mac, IFHWADDRLEN);
425 sock->state = SS_CONNECTING;
426 sk->sk_state = TCP_SYN_SENT;
427 llc->link = llc_ui_next_link_no(llc->sap->laddr.lsap);
428 rc = llc_establish_connection(sk, llc->dev->dev_addr,
429 addr->sllc_mac, addr->sllc_sap);
431 dprintk("%s: llc_ui_send_conn failed :-(\n", __FUNCTION__);
432 sock->state = SS_UNCONNECTED;
433 sk->sk_state = TCP_CLOSE;
437 if (sk->sk_state == TCP_SYN_SENT) {
438 const long timeo = sock_sndtimeo(sk, flags & O_NONBLOCK);
440 if (!timeo || !llc_ui_wait_for_conn(sk, timeo))
443 rc = sock_intr_errno(timeo);
444 if (signal_pending(current))
448 if (sk->sk_state == TCP_CLOSE)
451 sock->state = SS_CONNECTED;
457 rc = sock_error(sk) ? : -ECONNABORTED;
458 sock->state = SS_UNCONNECTED;
463 * llc_ui_listen - allow a normal socket to accept incoming connections
464 * @sock: Socket to allow incoming connections on.
465 * @backlog: Number of connections to queue.
467 * Allow a normal socket to accept incoming connections.
468 * Returns 0 upon success, negative otherwise.
470 static int llc_ui_listen(struct socket *sock, int backlog)
472 struct sock *sk = sock->sk;
476 if (unlikely(sock->state != SS_UNCONNECTED))
479 if (unlikely(sk->sk_type != SOCK_STREAM))
482 if (sock_flag(sk, SOCK_ZAPPED))
485 if (!(unsigned)backlog) /* BSDism */
487 sk->sk_max_ack_backlog = backlog;
488 if (sk->sk_state != TCP_LISTEN) {
489 sk->sk_ack_backlog = 0;
490 sk->sk_state = TCP_LISTEN;
492 sk->sk_socket->flags |= __SO_ACCEPTCON;
498 static int llc_ui_wait_for_disc(struct sock *sk, long timeout)
504 prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
505 if (sk_wait_event(sk, &timeout, sk->sk_state == TCP_CLOSE))
508 if (signal_pending(current))
515 finish_wait(sk->sk_sleep, &wait);
519 static int llc_ui_wait_for_conn(struct sock *sk, long timeout)
524 prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
525 if (sk_wait_event(sk, &timeout, sk->sk_state != TCP_SYN_SENT))
527 if (signal_pending(current) || !timeout)
530 finish_wait(sk->sk_sleep, &wait);
534 static int llc_ui_wait_for_busy_core(struct sock *sk, long timeout)
537 struct llc_sock *llc = llc_sk(sk);
541 prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
543 if (sk_wait_event(sk, &timeout,
544 (sk->sk_shutdown & RCV_SHUTDOWN) ||
545 (!llc_data_accept_state(llc->state) &&
546 !llc->remote_busy_flag &&
550 if (signal_pending(current))
556 finish_wait(sk->sk_sleep, &wait);
560 static int llc_wait_data(struct sock *sk, long timeo)
566 * POSIX 1003.1g mandates this order.
572 if (sk->sk_shutdown & RCV_SHUTDOWN)
577 rc = sock_intr_errno(timeo);
578 if (signal_pending(current))
581 if (sk_wait_data(sk, &timeo))
588 * llc_ui_accept - accept a new incoming connection.
589 * @sock: Socket which connections arrive on.
590 * @newsock: Socket to move incoming connection to.
591 * @flags: User specified operational flags.
593 * Accept a new incoming connection.
594 * Returns 0 upon success, negative otherwise.
596 static int llc_ui_accept(struct socket *sock, struct socket *newsock, int flags)
598 struct sock *sk = sock->sk, *newsk;
599 struct llc_sock *llc, *newllc;
601 int rc = -EOPNOTSUPP;
603 dprintk("%s: accepting on %02X\n", __FUNCTION__,
604 llc_sk(sk)->laddr.lsap);
606 if (unlikely(sk->sk_type != SOCK_STREAM))
609 if (unlikely(sock->state != SS_UNCONNECTED ||
610 sk->sk_state != TCP_LISTEN))
612 /* wait for a connection to arrive. */
613 if (skb_queue_empty(&sk->sk_receive_queue)) {
614 rc = llc_wait_data(sk, sk->sk_rcvtimeo);
618 dprintk("%s: got a new connection on %02X\n", __FUNCTION__,
619 llc_sk(sk)->laddr.lsap);
620 skb = skb_dequeue(&sk->sk_receive_queue);
626 /* attach connection to a new socket. */
627 llc_ui_sk_init(newsock, newsk);
628 sock_reset_flag(newsk, SOCK_ZAPPED);
629 newsk->sk_state = TCP_ESTABLISHED;
630 newsock->state = SS_CONNECTED;
632 newllc = llc_sk(newsk);
633 memcpy(&newllc->addr, &llc->addr, sizeof(newllc->addr));
634 newllc->link = llc_ui_next_link_no(newllc->laddr.lsap);
636 /* put original socket back into a clean listen state. */
637 sk->sk_state = TCP_LISTEN;
638 sk->sk_ack_backlog--;
639 dprintk("%s: ok success on %02X, client on %02X\n", __FUNCTION__,
640 llc_sk(sk)->addr.sllc_sap, newllc->daddr.lsap);
649 * llc_ui_recvmsg - copy received data to the socket user.
650 * @sock: Socket to copy data from.
651 * @msg: Various user space related information.
652 * @len: Size of user buffer.
653 * @flags: User specified flags.
655 * Copy received data to the socket user.
656 * Returns non-negative upon success, negative otherwise.
658 static int llc_ui_recvmsg(struct kiocb *iocb, struct socket *sock,
659 struct msghdr *msg, size_t len, int flags)
661 struct sockaddr_llc *uaddr = (struct sockaddr_llc *)msg->msg_name;
662 const int nonblock = flags & MSG_DONTWAIT;
663 struct sk_buff *skb = NULL;
664 struct sock *sk = sock->sk;
665 struct llc_sock *llc = llc_sk(sk);
670 int target; /* Read at least this many bytes */
675 if (sk->sk_state == TCP_LISTEN)
678 timeo = sock_rcvtimeo(sk, nonblock);
680 seq = &llc->copied_seq;
681 if (flags & MSG_PEEK) {
682 peek_seq = llc->copied_seq;
686 target = sock_rcvlowat(sk, flags & MSG_WAITALL, len);
693 * We need to check signals first, to get correct SIGURG
694 * handling. FIXME: Need to check this doesn't impact 1003.1g
695 * and move it down to the bottom of the loop
697 if (signal_pending(current)) {
700 copied = timeo ? sock_intr_errno(timeo) : -EAGAIN;
704 /* Next get a buffer. */
706 skb = skb_peek(&sk->sk_receive_queue);
711 /* Well, if we have backlog, try to process it now yet. */
713 if (copied >= target && !sk->sk_backlog.tail)
718 sk->sk_state == TCP_CLOSE ||
719 (sk->sk_shutdown & RCV_SHUTDOWN) ||
724 if (sock_flag(sk, SOCK_DONE))
728 copied = sock_error(sk);
731 if (sk->sk_shutdown & RCV_SHUTDOWN)
734 if (sk->sk_state == TCP_CLOSE) {
735 if (!sock_flag(sk, SOCK_DONE)) {
737 * This occurs when user tries to read
738 * from never connected socket.
751 if (copied >= target) { /* Do not sleep, just process backlog. */
755 sk_wait_data(sk, &timeo);
757 if ((flags & MSG_PEEK) && peek_seq != llc->copied_seq) {
759 printk(KERN_DEBUG "LLC(%s:%d): Application "
760 "bug, race in MSG_PEEK.\n",
761 current->comm, current->pid);
762 peek_seq = llc->copied_seq;
766 /* Ok so how much can we use? */
767 used = skb->len - offset;
771 if (!(flags & MSG_TRUNC)) {
772 int rc = skb_copy_datagram_iovec(skb, offset,
775 /* Exception. Bailout! */
786 if (used + offset < skb->len)
789 if (!(flags & MSG_PEEK)) {
796 * According to UNIX98, msg_name/msg_namelen are ignored
797 * on connected socket. -ANK
798 * But... af_llc still doesn't have separate sets of methods for
799 * SOCK_DGRAM and SOCK_STREAM :-( So we have to do this test, will
800 * eventually fix this tho :-) -acme
802 if (sk->sk_type == SOCK_DGRAM)
808 if (uaddr != NULL && skb != NULL) {
809 memcpy(uaddr, llc_ui_skb_cb(skb), sizeof(*uaddr));
810 msg->msg_namelen = sizeof(*uaddr);
816 * llc_ui_sendmsg - Transmit data provided by the socket user.
817 * @sock: Socket to transmit data from.
818 * @msg: Various user related information.
819 * @len: Length of data to transmit.
821 * Transmit data provided by the socket user.
822 * Returns non-negative upon success, negative otherwise.
824 static int llc_ui_sendmsg(struct kiocb *iocb, struct socket *sock,
825 struct msghdr *msg, size_t len)
827 struct sock *sk = sock->sk;
828 struct llc_sock *llc = llc_sk(sk);
829 struct sockaddr_llc *addr = (struct sockaddr_llc *)msg->msg_name;
830 int flags = msg->msg_flags;
831 int noblock = flags & MSG_DONTWAIT;
834 int rc = -EINVAL, copied = 0, hdrlen;
836 dprintk("%s: sending from %02X to %02X\n", __FUNCTION__,
837 llc->laddr.lsap, llc->daddr.lsap);
840 if (msg->msg_namelen < sizeof(*addr))
843 if (llc_ui_addr_null(&llc->addr))
847 /* must bind connection to sap if user hasn't done it. */
848 if (sock_flag(sk, SOCK_ZAPPED)) {
849 /* bind to sap with null dev, exclusive. */
850 rc = llc_ui_autobind(sock, addr);
854 hdrlen = llc->dev->hard_header_len + llc_ui_header_len(sk, addr);
856 if (size > llc->dev->mtu)
857 size = llc->dev->mtu;
858 copied = size - hdrlen;
860 skb = sock_alloc_send_skb(sk, size, noblock, &rc);
865 skb->protocol = llc_proto_type(addr->sllc_arphrd);
866 skb_reserve(skb, hdrlen);
867 rc = memcpy_fromiovec(skb_put(skb, copied), msg->msg_iov, copied);
870 if (sk->sk_type == SOCK_DGRAM || addr->sllc_ua) {
871 llc_build_and_send_ui_pkt(llc->sap, skb, addr->sllc_mac,
875 if (addr->sllc_test) {
876 llc_build_and_send_test_pkt(llc->sap, skb, addr->sllc_mac,
880 if (addr->sllc_xid) {
881 llc_build_and_send_xid_pkt(llc->sap, skb, addr->sllc_mac,
886 if (!(sk->sk_type == SOCK_STREAM && !addr->sllc_ua))
888 rc = llc_ui_send_data(sk, skb, noblock);
893 dprintk("%s: failed sending from %02X to %02X: %d\n",
894 __FUNCTION__, llc->laddr.lsap, llc->daddr.lsap, rc);
897 return rc ? : copied;
901 * llc_ui_getname - return the address info of a socket
902 * @sock: Socket to get address of.
903 * @uaddr: Address structure to return information.
904 * @uaddrlen: Length of address structure.
905 * @peer: Does user want local or remote address information.
907 * Return the address information of a socket.
909 static int llc_ui_getname(struct socket *sock, struct sockaddr *uaddr,
910 int *uaddrlen, int peer)
912 struct sockaddr_llc sllc;
913 struct sock *sk = sock->sk;
914 struct llc_sock *llc = llc_sk(sk);
918 if (sock_flag(sk, SOCK_ZAPPED))
920 *uaddrlen = sizeof(sllc);
921 memset(uaddr, 0, *uaddrlen);
924 if (sk->sk_state != TCP_ESTABLISHED)
927 sllc.sllc_arphrd = llc->dev->type;
928 sllc.sllc_sap = llc->daddr.lsap;
929 memcpy(&sllc.sllc_mac, &llc->daddr.mac, IFHWADDRLEN);
934 sllc.sllc_sap = llc->sap->laddr.lsap;
937 sllc.sllc_arphrd = llc->dev->type;
938 memcpy(&sllc.sllc_mac, &llc->dev->dev_addr,
943 sllc.sllc_family = AF_LLC;
944 memcpy(uaddr, &sllc, sizeof(sllc));
951 * llc_ui_ioctl - io controls for PF_LLC
952 * @sock: Socket to get/set info
954 * @arg: optional argument for cmd
956 * get/set info on llc sockets
958 static int llc_ui_ioctl(struct socket *sock, unsigned int cmd,
965 * llc_ui_setsockopt - set various connection specific parameters.
966 * @sock: Socket to set options on.
967 * @level: Socket level user is requesting operations on.
968 * @optname: Operation name.
969 * @optval User provided operation data.
970 * @optlen: Length of optval.
972 * Set various connection specific parameters.
974 static int llc_ui_setsockopt(struct socket *sock, int level, int optname,
975 char __user *optval, int optlen)
977 struct sock *sk = sock->sk;
978 struct llc_sock *llc = llc_sk(sk);
979 int rc = -EINVAL, opt;
982 if (unlikely(level != SOL_LLC || optlen != sizeof(int)))
984 rc = get_user(opt, (int __user *)optval);
990 if (opt > LLC_OPT_MAX_RETRY)
995 if (opt > LLC_OPT_MAX_SIZE)
999 case LLC_OPT_ACK_TMR_EXP:
1000 if (opt > LLC_OPT_MAX_ACK_TMR_EXP)
1002 llc->ack_timer.expire = opt * HZ;
1004 case LLC_OPT_P_TMR_EXP:
1005 if (opt > LLC_OPT_MAX_P_TMR_EXP)
1007 llc->pf_cycle_timer.expire = opt * HZ;
1009 case LLC_OPT_REJ_TMR_EXP:
1010 if (opt > LLC_OPT_MAX_REJ_TMR_EXP)
1012 llc->rej_sent_timer.expire = opt * HZ;
1014 case LLC_OPT_BUSY_TMR_EXP:
1015 if (opt > LLC_OPT_MAX_BUSY_TMR_EXP)
1017 llc->busy_state_timer.expire = opt * HZ;
1019 case LLC_OPT_TX_WIN:
1020 if (opt > LLC_OPT_MAX_WIN)
1024 case LLC_OPT_RX_WIN:
1025 if (opt > LLC_OPT_MAX_WIN)
1040 * llc_ui_getsockopt - get connection specific socket info
1041 * @sock: Socket to get information from.
1042 * @level: Socket level user is requesting operations on.
1043 * @optname: Operation name.
1044 * @optval: Variable to return operation data in.
1045 * @optlen: Length of optval.
1047 * Get connection specific socket information.
1049 static int llc_ui_getsockopt(struct socket *sock, int level, int optname,
1050 char __user *optval, int __user *optlen)
1052 struct sock *sk = sock->sk;
1053 struct llc_sock *llc = llc_sk(sk);
1054 int val = 0, len = 0, rc = -EINVAL;
1057 if (unlikely(level != SOL_LLC))
1059 rc = get_user(len, optlen);
1063 if (len != sizeof(int))
1067 val = llc->n2; break;
1069 val = llc->n1; break;
1070 case LLC_OPT_ACK_TMR_EXP:
1071 val = llc->ack_timer.expire / HZ; break;
1072 case LLC_OPT_P_TMR_EXP:
1073 val = llc->pf_cycle_timer.expire / HZ; break;
1074 case LLC_OPT_REJ_TMR_EXP:
1075 val = llc->rej_sent_timer.expire / HZ; break;
1076 case LLC_OPT_BUSY_TMR_EXP:
1077 val = llc->busy_state_timer.expire / HZ; break;
1078 case LLC_OPT_TX_WIN:
1079 val = llc->k; break;
1080 case LLC_OPT_RX_WIN:
1081 val = llc->rw; break;
1087 if (put_user(len, optlen) || copy_to_user(optval, &val, len))
1094 static struct net_proto_family llc_ui_family_ops = {
1096 .create = llc_ui_create,
1097 .owner = THIS_MODULE,
1100 static const struct proto_ops llc_ui_ops = {
1102 .owner = THIS_MODULE,
1103 .release = llc_ui_release,
1104 .bind = llc_ui_bind,
1105 .connect = llc_ui_connect,
1106 .socketpair = sock_no_socketpair,
1107 .accept = llc_ui_accept,
1108 .getname = llc_ui_getname,
1109 .poll = datagram_poll,
1110 .ioctl = llc_ui_ioctl,
1111 .listen = llc_ui_listen,
1112 .shutdown = llc_ui_shutdown,
1113 .setsockopt = llc_ui_setsockopt,
1114 .getsockopt = llc_ui_getsockopt,
1115 .sendmsg = llc_ui_sendmsg,
1116 .recvmsg = llc_ui_recvmsg,
1117 .mmap = sock_no_mmap,
1118 .sendpage = sock_no_sendpage,
1121 static char llc_proc_err_msg[] __initdata =
1122 KERN_CRIT "LLC: Unable to register the proc_fs entries\n";
1123 static char llc_sysctl_err_msg[] __initdata =
1124 KERN_CRIT "LLC: Unable to register the sysctl entries\n";
1125 static char llc_sock_err_msg[] __initdata =
1126 KERN_CRIT "LLC: Unable to register the network family\n";
1128 static int __init llc2_init(void)
1130 int rc = proto_register(&llc_proto, 0);
1135 llc_build_offset_table();
1137 llc_ui_sap_last_autoport = LLC_SAP_DYN_START;
1138 rc = llc_proc_init();
1140 printk(llc_proc_err_msg);
1141 goto out_unregister_llc_proto;
1143 rc = llc_sysctl_init();
1145 printk(llc_sysctl_err_msg);
1148 rc = sock_register(&llc_ui_family_ops);
1150 printk(llc_sock_err_msg);
1153 llc_add_pack(LLC_DEST_SAP, llc_sap_handler);
1154 llc_add_pack(LLC_DEST_CONN, llc_conn_handler);
1161 out_unregister_llc_proto:
1162 proto_unregister(&llc_proto);
1166 static void __exit llc2_exit(void)
1169 llc_remove_pack(LLC_DEST_SAP);
1170 llc_remove_pack(LLC_DEST_CONN);
1171 sock_unregister(PF_LLC);
1174 proto_unregister(&llc_proto);
1177 module_init(llc2_init);
1178 module_exit(llc2_exit);
1180 MODULE_LICENSE("GPL");
1181 MODULE_AUTHOR("Procom 1997, Jay Schullist 2001, Arnaldo C. Melo 2001-2003");
1182 MODULE_DESCRIPTION("IEEE 802.2 PF_LLC support");
1183 MODULE_ALIAS_NETPROTO(PF_LLC);