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/compiler.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 const 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 __be16
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
, struct sockaddr_llc
*addr
)
93 u8 rc
= LLC_PDU_LEN_U
;
95 if (addr
->sllc_test
|| addr
->sllc_xid
)
97 else if (sk
->sk_type
== SOCK_STREAM
)
103 * llc_ui_send_data - send data via reliable llc2 connection
104 * @sk: Connection the socket is using.
105 * @skb: Data the user wishes to send.
106 * @addr: Source and destination fields provided by the user.
107 * @noblock: can we block waiting for data?
109 * Send data via reliable llc2 connection.
110 * Returns 0 upon success, non-zero if action did not succeed.
112 static int llc_ui_send_data(struct sock
* sk
, struct sk_buff
*skb
, int noblock
)
114 struct llc_sock
* llc
= llc_sk(sk
);
117 if (unlikely(llc_data_accept_state(llc
->state
) ||
118 llc
->remote_busy_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 sock_graft(sk
, sock
);
132 sk
->sk_type
= sock
->type
;
133 sock
->ops
= &llc_ui_ops
;
136 static struct proto llc_proto
= {
138 .owner
= THIS_MODULE
,
139 .obj_size
= sizeof(struct llc_sock
),
143 * llc_ui_create - alloc and init a new llc_ui socket
144 * @sock: Socket to initialize and attach allocated sk to.
147 * Allocate and initialize a new llc_ui socket, validate the user wants a
148 * socket type we have available.
149 * Returns 0 upon success, negative upon failure.
151 static int llc_ui_create(struct net
*net
, struct socket
*sock
, int protocol
)
154 int rc
= -ESOCKTNOSUPPORT
;
156 if (!capable(CAP_NET_RAW
))
159 if (net
!= &init_net
)
160 return -EAFNOSUPPORT
;
162 if (likely(sock
->type
== SOCK_DGRAM
|| sock
->type
== SOCK_STREAM
)) {
164 sk
= llc_sk_alloc(net
, PF_LLC
, GFP_KERNEL
, &llc_proto
);
167 llc_ui_sk_init(sock
, sk
);
174 * llc_ui_release - shutdown socket
175 * @sock: Socket to release.
177 * Shutdown and deallocate an existing socket.
179 static int llc_ui_release(struct socket
*sock
)
181 struct sock
*sk
= sock
->sk
;
182 struct llc_sock
*llc
;
184 if (unlikely(sk
== NULL
))
189 dprintk("%s: closing local(%02X) remote(%02X)\n", __func__
,
190 llc
->laddr
.lsap
, llc
->daddr
.lsap
);
191 if (!llc_send_disc(sk
))
192 llc_ui_wait_for_disc(sk
, sk
->sk_rcvtimeo
);
193 if (!sock_flag(sk
, SOCK_ZAPPED
)) {
194 llc_sap_put(llc
->sap
);
195 llc_sap_remove_socket(llc
->sap
, sk
);
207 * llc_ui_autoport - provide dynamically allocate SAP number
209 * Provide the caller with a dynamically allocated SAP number according
210 * to the rules that are set in this function. Returns: 0, upon failure,
211 * SAP number otherwise.
213 static int llc_ui_autoport(void)
218 while (tries
< LLC_SAP_DYN_TRIES
) {
219 for (i
= llc_ui_sap_last_autoport
;
220 i
< LLC_SAP_DYN_STOP
; i
+= 2) {
221 sap
= llc_sap_find(i
);
223 llc_ui_sap_last_autoport
= i
+ 2;
228 llc_ui_sap_last_autoport
= LLC_SAP_DYN_START
;
237 * llc_ui_autobind - automatically bind a socket to a sap
238 * @sock: socket to bind
239 * @addr: address to connect to
241 * Used by llc_ui_connect and llc_ui_sendmsg when the user hasn't
242 * specifically used llc_ui_bind to bind to an specific address/sap
244 * Returns: 0 upon success, negative otherwise.
246 static int llc_ui_autobind(struct socket
*sock
, struct sockaddr_llc
*addr
)
248 struct sock
*sk
= sock
->sk
;
249 struct llc_sock
*llc
= llc_sk(sk
);
253 if (!sock_flag(sk
, SOCK_ZAPPED
))
256 llc
->dev
= dev_getfirstbyhwtype(&init_net
, addr
->sllc_arphrd
);
260 llc
->laddr
.lsap
= llc_ui_autoport();
261 if (!llc
->laddr
.lsap
)
263 rc
= -EBUSY
; /* some other network layer is using the sap */
264 sap
= llc_sap_open(llc
->laddr
.lsap
, NULL
);
267 memcpy(llc
->laddr
.mac
, llc
->dev
->dev_addr
, IFHWADDRLEN
);
268 memcpy(&llc
->addr
, addr
, sizeof(llc
->addr
));
269 /* assign new connection to its SAP */
270 llc_sap_add_socket(sap
, sk
);
271 sock_reset_flag(sk
, SOCK_ZAPPED
);
278 * llc_ui_bind - bind a socket to a specific address.
279 * @sock: Socket to bind an address to.
280 * @uaddr: Address the user wants the socket bound to.
281 * @addrlen: Length of the uaddr structure.
283 * Bind a socket to a specific address. For llc a user is able to bind to
284 * a specific sap only or mac + sap.
285 * If the user desires to bind to a specific mac + sap, it is possible to
286 * have multiple sap connections via multiple macs.
287 * Bind and autobind for that matter must enforce the correct sap usage
288 * otherwise all hell will break loose.
289 * Returns: 0 upon success, negative otherwise.
291 static int llc_ui_bind(struct socket
*sock
, struct sockaddr
*uaddr
, int addrlen
)
293 struct sockaddr_llc
*addr
= (struct sockaddr_llc
*)uaddr
;
294 struct sock
*sk
= sock
->sk
;
295 struct llc_sock
*llc
= llc_sk(sk
);
299 dprintk("%s: binding %02X\n", __func__
, addr
->sllc_sap
);
300 if (unlikely(!sock_flag(sk
, SOCK_ZAPPED
) || addrlen
!= sizeof(*addr
)))
303 if (unlikely(addr
->sllc_family
!= AF_LLC
))
307 llc
->dev
= dev_getbyhwaddr(&init_net
, addr
->sllc_arphrd
, addr
->sllc_mac
);
311 if (!addr
->sllc_sap
) {
313 addr
->sllc_sap
= llc_ui_autoport();
317 sap
= llc_sap_find(addr
->sllc_sap
);
319 sap
= llc_sap_open(addr
->sllc_sap
, NULL
);
320 rc
= -EBUSY
; /* some other network layer is using the sap */
325 struct llc_addr laddr
, daddr
;
328 memset(&laddr
, 0, sizeof(laddr
));
329 memset(&daddr
, 0, sizeof(daddr
));
331 * FIXME: check if the address is multicast,
332 * only SOCK_DGRAM can do this.
334 memcpy(laddr
.mac
, addr
->sllc_mac
, IFHWADDRLEN
);
335 laddr
.lsap
= addr
->sllc_sap
;
336 rc
= -EADDRINUSE
; /* mac + sap clash. */
337 ask
= llc_lookup_established(sap
, &daddr
, &laddr
);
343 llc
->laddr
.lsap
= addr
->sllc_sap
;
344 memcpy(llc
->laddr
.mac
, addr
->sllc_mac
, IFHWADDRLEN
);
345 memcpy(&llc
->addr
, addr
, sizeof(llc
->addr
));
346 /* assign new connection to its SAP */
347 llc_sap_add_socket(sap
, sk
);
348 sock_reset_flag(sk
, SOCK_ZAPPED
);
357 * llc_ui_shutdown - shutdown a connect llc2 socket.
358 * @sock: Socket to shutdown.
359 * @how: What part of the socket to shutdown.
361 * Shutdown a connected llc2 socket. Currently this function only supports
362 * shutting down both sends and receives (2), we could probably make this
363 * function such that a user can shutdown only half the connection but not
365 * Returns: 0 upon success, negative otherwise.
367 static int llc_ui_shutdown(struct socket
*sock
, int how
)
369 struct sock
*sk
= sock
->sk
;
373 if (unlikely(sk
->sk_state
!= TCP_ESTABLISHED
))
378 rc
= llc_send_disc(sk
);
380 rc
= llc_ui_wait_for_disc(sk
, sk
->sk_rcvtimeo
);
381 /* Wake up anyone sleeping in poll */
382 sk
->sk_state_change(sk
);
389 * llc_ui_connect - Connect to a remote llc2 mac + sap.
390 * @sock: Socket which will be connected to the remote destination.
391 * @uaddr: Remote and possibly the local address of the new connection.
392 * @addrlen: Size of uaddr structure.
393 * @flags: Operational flags specified by the user.
395 * Connect to a remote llc2 mac + sap. The caller must specify the
396 * destination mac and address to connect to. If the user hasn't previously
397 * called bind(2) with a smac the address of the first interface of the
398 * specified arp type will be used.
399 * This function will autobind if user did not previously call bind.
400 * Returns: 0 upon success, negative otherwise.
402 static int llc_ui_connect(struct socket
*sock
, struct sockaddr
*uaddr
,
403 int addrlen
, int flags
)
405 struct sock
*sk
= sock
->sk
;
406 struct llc_sock
*llc
= llc_sk(sk
);
407 struct sockaddr_llc
*addr
= (struct sockaddr_llc
*)uaddr
;
411 if (unlikely(addrlen
!= sizeof(*addr
)))
414 if (unlikely(addr
->sllc_family
!= AF_LLC
))
416 if (unlikely(sk
->sk_type
!= SOCK_STREAM
))
419 if (unlikely(sock
->state
== SS_CONNECTING
))
421 /* bind connection to sap if user hasn't done it. */
422 if (sock_flag(sk
, SOCK_ZAPPED
)) {
423 /* bind to sap with null dev, exclusive */
424 rc
= llc_ui_autobind(sock
, addr
);
428 llc
->daddr
.lsap
= addr
->sllc_sap
;
429 memcpy(llc
->daddr
.mac
, addr
->sllc_mac
, IFHWADDRLEN
);
430 sock
->state
= SS_CONNECTING
;
431 sk
->sk_state
= TCP_SYN_SENT
;
432 llc
->link
= llc_ui_next_link_no(llc
->sap
->laddr
.lsap
);
433 rc
= llc_establish_connection(sk
, llc
->dev
->dev_addr
,
434 addr
->sllc_mac
, addr
->sllc_sap
);
436 dprintk("%s: llc_ui_send_conn failed :-(\n", __func__
);
437 sock
->state
= SS_UNCONNECTED
;
438 sk
->sk_state
= TCP_CLOSE
;
442 if (sk
->sk_state
== TCP_SYN_SENT
) {
443 const long timeo
= sock_sndtimeo(sk
, flags
& O_NONBLOCK
);
445 if (!timeo
|| !llc_ui_wait_for_conn(sk
, timeo
))
448 rc
= sock_intr_errno(timeo
);
449 if (signal_pending(current
))
453 if (sk
->sk_state
== TCP_CLOSE
)
456 sock
->state
= SS_CONNECTED
;
462 rc
= sock_error(sk
) ? : -ECONNABORTED
;
463 sock
->state
= SS_UNCONNECTED
;
468 * llc_ui_listen - allow a normal socket to accept incoming connections
469 * @sock: Socket to allow incoming connections on.
470 * @backlog: Number of connections to queue.
472 * Allow a normal socket to accept incoming connections.
473 * Returns 0 upon success, negative otherwise.
475 static int llc_ui_listen(struct socket
*sock
, int backlog
)
477 struct sock
*sk
= sock
->sk
;
481 if (unlikely(sock
->state
!= SS_UNCONNECTED
))
484 if (unlikely(sk
->sk_type
!= SOCK_STREAM
))
487 if (sock_flag(sk
, SOCK_ZAPPED
))
490 if (!(unsigned)backlog
) /* BSDism */
492 sk
->sk_max_ack_backlog
= backlog
;
493 if (sk
->sk_state
!= TCP_LISTEN
) {
494 sk
->sk_ack_backlog
= 0;
495 sk
->sk_state
= TCP_LISTEN
;
497 sk
->sk_socket
->flags
|= __SO_ACCEPTCON
;
503 static int llc_ui_wait_for_disc(struct sock
*sk
, long timeout
)
509 prepare_to_wait(sk
->sk_sleep
, &wait
, TASK_INTERRUPTIBLE
);
510 if (sk_wait_event(sk
, &timeout
, sk
->sk_state
== TCP_CLOSE
))
513 if (signal_pending(current
))
520 finish_wait(sk
->sk_sleep
, &wait
);
524 static int llc_ui_wait_for_conn(struct sock
*sk
, long timeout
)
529 prepare_to_wait(sk
->sk_sleep
, &wait
, TASK_INTERRUPTIBLE
);
530 if (sk_wait_event(sk
, &timeout
, sk
->sk_state
!= TCP_SYN_SENT
))
532 if (signal_pending(current
) || !timeout
)
535 finish_wait(sk
->sk_sleep
, &wait
);
539 static int llc_ui_wait_for_busy_core(struct sock
*sk
, long timeout
)
542 struct llc_sock
*llc
= llc_sk(sk
);
546 prepare_to_wait(sk
->sk_sleep
, &wait
, TASK_INTERRUPTIBLE
);
548 if (sk_wait_event(sk
, &timeout
,
549 (sk
->sk_shutdown
& RCV_SHUTDOWN
) ||
550 (!llc_data_accept_state(llc
->state
) &&
551 !llc
->remote_busy_flag
&&
555 if (signal_pending(current
))
561 finish_wait(sk
->sk_sleep
, &wait
);
565 static int llc_wait_data(struct sock
*sk
, long timeo
)
571 * POSIX 1003.1g mandates this order.
577 if (sk
->sk_shutdown
& RCV_SHUTDOWN
)
582 rc
= sock_intr_errno(timeo
);
583 if (signal_pending(current
))
586 if (sk_wait_data(sk
, &timeo
))
593 * llc_ui_accept - accept a new incoming connection.
594 * @sock: Socket which connections arrive on.
595 * @newsock: Socket to move incoming connection to.
596 * @flags: User specified operational flags.
598 * Accept a new incoming connection.
599 * Returns 0 upon success, negative otherwise.
601 static int llc_ui_accept(struct socket
*sock
, struct socket
*newsock
, int flags
)
603 struct sock
*sk
= sock
->sk
, *newsk
;
604 struct llc_sock
*llc
, *newllc
;
606 int rc
= -EOPNOTSUPP
;
608 dprintk("%s: accepting on %02X\n", __func__
,
609 llc_sk(sk
)->laddr
.lsap
);
611 if (unlikely(sk
->sk_type
!= SOCK_STREAM
))
614 if (unlikely(sock
->state
!= SS_UNCONNECTED
||
615 sk
->sk_state
!= TCP_LISTEN
))
617 /* wait for a connection to arrive. */
618 if (skb_queue_empty(&sk
->sk_receive_queue
)) {
619 rc
= llc_wait_data(sk
, sk
->sk_rcvtimeo
);
623 dprintk("%s: got a new connection on %02X\n", __func__
,
624 llc_sk(sk
)->laddr
.lsap
);
625 skb
= skb_dequeue(&sk
->sk_receive_queue
);
631 /* attach connection to a new socket. */
632 llc_ui_sk_init(newsock
, newsk
);
633 sock_reset_flag(newsk
, SOCK_ZAPPED
);
634 newsk
->sk_state
= TCP_ESTABLISHED
;
635 newsock
->state
= SS_CONNECTED
;
637 newllc
= llc_sk(newsk
);
638 memcpy(&newllc
->addr
, &llc
->addr
, sizeof(newllc
->addr
));
639 newllc
->link
= llc_ui_next_link_no(newllc
->laddr
.lsap
);
641 /* put original socket back into a clean listen state. */
642 sk
->sk_state
= TCP_LISTEN
;
643 sk
->sk_ack_backlog
--;
644 dprintk("%s: ok success on %02X, client on %02X\n", __func__
,
645 llc_sk(sk
)->addr
.sllc_sap
, newllc
->daddr
.lsap
);
654 * llc_ui_recvmsg - copy received data to the socket user.
655 * @sock: Socket to copy data from.
656 * @msg: Various user space related information.
657 * @len: Size of user buffer.
658 * @flags: User specified flags.
660 * Copy received data to the socket user.
661 * Returns non-negative upon success, negative otherwise.
663 static int llc_ui_recvmsg(struct kiocb
*iocb
, struct socket
*sock
,
664 struct msghdr
*msg
, size_t len
, int flags
)
666 struct sockaddr_llc
*uaddr
= (struct sockaddr_llc
*)msg
->msg_name
;
667 const int nonblock
= flags
& MSG_DONTWAIT
;
668 struct sk_buff
*skb
= NULL
;
669 struct sock
*sk
= sock
->sk
;
670 struct llc_sock
*llc
= llc_sk(sk
);
675 int target
; /* Read at least this many bytes */
680 if (unlikely(sk
->sk_type
== SOCK_STREAM
&& sk
->sk_state
== TCP_LISTEN
))
683 timeo
= sock_rcvtimeo(sk
, nonblock
);
685 seq
= &llc
->copied_seq
;
686 if (flags
& MSG_PEEK
) {
687 peek_seq
= llc
->copied_seq
;
691 target
= sock_rcvlowat(sk
, flags
& MSG_WAITALL
, len
);
698 * We need to check signals first, to get correct SIGURG
699 * handling. FIXME: Need to check this doesn't impact 1003.1g
700 * and move it down to the bottom of the loop
702 if (signal_pending(current
)) {
705 copied
= timeo
? sock_intr_errno(timeo
) : -EAGAIN
;
709 /* Next get a buffer. */
711 skb
= skb_peek(&sk
->sk_receive_queue
);
716 /* Well, if we have backlog, try to process it now yet. */
718 if (copied
>= target
&& !sk
->sk_backlog
.tail
)
723 sk
->sk_state
== TCP_CLOSE
||
724 (sk
->sk_shutdown
& RCV_SHUTDOWN
) ||
729 if (sock_flag(sk
, SOCK_DONE
))
733 copied
= sock_error(sk
);
736 if (sk
->sk_shutdown
& RCV_SHUTDOWN
)
739 if (sk
->sk_type
== SOCK_STREAM
&& sk
->sk_state
== TCP_CLOSE
) {
740 if (!sock_flag(sk
, SOCK_DONE
)) {
742 * This occurs when user tries to read
743 * from never connected socket.
756 if (copied
>= target
) { /* Do not sleep, just process backlog. */
760 sk_wait_data(sk
, &timeo
);
762 if ((flags
& MSG_PEEK
) && peek_seq
!= llc
->copied_seq
) {
764 printk(KERN_DEBUG
"LLC(%s:%d): Application "
765 "bug, race in MSG_PEEK.\n",
766 current
->comm
, task_pid_nr(current
));
767 peek_seq
= llc
->copied_seq
;
771 /* Ok so how much can we use? */
772 used
= skb
->len
- offset
;
776 if (!(flags
& MSG_TRUNC
)) {
777 int rc
= skb_copy_datagram_iovec(skb
, offset
,
780 /* Exception. Bailout! */
791 if (!(flags
& MSG_PEEK
)) {
792 sk_eat_skb(sk
, skb
, 0);
796 /* For non stream protcols we get one packet per recvmsg call */
797 if (sk
->sk_type
!= SOCK_STREAM
)
801 if (used
+ offset
< skb
->len
)
809 if (uaddr
!= NULL
&& skb
!= NULL
) {
810 memcpy(uaddr
, llc_ui_skb_cb(skb
), sizeof(*uaddr
));
811 msg
->msg_namelen
= sizeof(*uaddr
);
817 * llc_ui_sendmsg - Transmit data provided by the socket user.
818 * @sock: Socket to transmit data from.
819 * @msg: Various user related information.
820 * @len: Length of data to transmit.
822 * Transmit data provided by the socket user.
823 * Returns non-negative upon success, negative otherwise.
825 static int llc_ui_sendmsg(struct kiocb
*iocb
, struct socket
*sock
,
826 struct msghdr
*msg
, size_t len
)
828 struct sock
*sk
= sock
->sk
;
829 struct llc_sock
*llc
= llc_sk(sk
);
830 struct sockaddr_llc
*addr
= (struct sockaddr_llc
*)msg
->msg_name
;
831 int flags
= msg
->msg_flags
;
832 int noblock
= flags
& MSG_DONTWAIT
;
835 int rc
= -EINVAL
, copied
= 0, hdrlen
;
837 dprintk("%s: sending from %02X to %02X\n", __func__
,
838 llc
->laddr
.lsap
, llc
->daddr
.lsap
);
841 if (msg
->msg_namelen
< sizeof(*addr
))
844 if (llc_ui_addr_null(&llc
->addr
))
848 /* must bind connection to sap if user hasn't done it. */
849 if (sock_flag(sk
, SOCK_ZAPPED
)) {
850 /* bind to sap with null dev, exclusive. */
851 rc
= llc_ui_autobind(sock
, addr
);
855 hdrlen
= llc
->dev
->hard_header_len
+ llc_ui_header_len(sk
, addr
);
857 if (size
> llc
->dev
->mtu
)
858 size
= llc
->dev
->mtu
;
859 copied
= size
- hdrlen
;
861 skb
= sock_alloc_send_skb(sk
, size
, noblock
, &rc
);
866 skb
->protocol
= llc_proto_type(addr
->sllc_arphrd
);
867 skb_reserve(skb
, hdrlen
);
868 rc
= memcpy_fromiovec(skb_put(skb
, copied
), msg
->msg_iov
, copied
);
871 if (sk
->sk_type
== SOCK_DGRAM
|| addr
->sllc_ua
) {
872 llc_build_and_send_ui_pkt(llc
->sap
, skb
, addr
->sllc_mac
,
876 if (addr
->sllc_test
) {
877 llc_build_and_send_test_pkt(llc
->sap
, skb
, addr
->sllc_mac
,
881 if (addr
->sllc_xid
) {
882 llc_build_and_send_xid_pkt(llc
->sap
, skb
, addr
->sllc_mac
,
887 if (!(sk
->sk_type
== SOCK_STREAM
&& !addr
->sllc_ua
))
889 rc
= llc_ui_send_data(sk
, skb
, noblock
);
894 dprintk("%s: failed sending from %02X to %02X: %d\n",
895 __func__
, llc
->laddr
.lsap
, llc
->daddr
.lsap
, rc
);
898 return rc
? : copied
;
902 * llc_ui_getname - return the address info of a socket
903 * @sock: Socket to get address of.
904 * @uaddr: Address structure to return information.
905 * @uaddrlen: Length of address structure.
906 * @peer: Does user want local or remote address information.
908 * Return the address information of a socket.
910 static int llc_ui_getname(struct socket
*sock
, struct sockaddr
*uaddr
,
911 int *uaddrlen
, int peer
)
913 struct sockaddr_llc sllc
;
914 struct sock
*sk
= sock
->sk
;
915 struct llc_sock
*llc
= llc_sk(sk
);
919 if (sock_flag(sk
, SOCK_ZAPPED
))
921 *uaddrlen
= sizeof(sllc
);
922 memset(uaddr
, 0, *uaddrlen
);
925 if (sk
->sk_state
!= TCP_ESTABLISHED
)
928 sllc
.sllc_arphrd
= llc
->dev
->type
;
929 sllc
.sllc_sap
= llc
->daddr
.lsap
;
930 memcpy(&sllc
.sllc_mac
, &llc
->daddr
.mac
, IFHWADDRLEN
);
935 sllc
.sllc_sap
= llc
->sap
->laddr
.lsap
;
938 sllc
.sllc_arphrd
= llc
->dev
->type
;
939 memcpy(&sllc
.sllc_mac
, &llc
->dev
->dev_addr
,
944 sllc
.sllc_family
= AF_LLC
;
945 memcpy(uaddr
, &sllc
, sizeof(sllc
));
952 * llc_ui_ioctl - io controls for PF_LLC
953 * @sock: Socket to get/set info
955 * @arg: optional argument for cmd
957 * get/set info on llc sockets
959 static int llc_ui_ioctl(struct socket
*sock
, unsigned int cmd
,
966 * llc_ui_setsockopt - set various connection specific parameters.
967 * @sock: Socket to set options on.
968 * @level: Socket level user is requesting operations on.
969 * @optname: Operation name.
970 * @optval User provided operation data.
971 * @optlen: Length of optval.
973 * Set various connection specific parameters.
975 static int llc_ui_setsockopt(struct socket
*sock
, int level
, int optname
,
976 char __user
*optval
, int optlen
)
978 struct sock
*sk
= sock
->sk
;
979 struct llc_sock
*llc
= llc_sk(sk
);
980 int rc
= -EINVAL
, opt
;
983 if (unlikely(level
!= SOL_LLC
|| optlen
!= sizeof(int)))
985 rc
= get_user(opt
, (int __user
*)optval
);
991 if (opt
> LLC_OPT_MAX_RETRY
)
996 if (opt
> LLC_OPT_MAX_SIZE
)
1000 case LLC_OPT_ACK_TMR_EXP
:
1001 if (opt
> LLC_OPT_MAX_ACK_TMR_EXP
)
1003 llc
->ack_timer
.expire
= opt
* HZ
;
1005 case LLC_OPT_P_TMR_EXP
:
1006 if (opt
> LLC_OPT_MAX_P_TMR_EXP
)
1008 llc
->pf_cycle_timer
.expire
= opt
* HZ
;
1010 case LLC_OPT_REJ_TMR_EXP
:
1011 if (opt
> LLC_OPT_MAX_REJ_TMR_EXP
)
1013 llc
->rej_sent_timer
.expire
= opt
* HZ
;
1015 case LLC_OPT_BUSY_TMR_EXP
:
1016 if (opt
> LLC_OPT_MAX_BUSY_TMR_EXP
)
1018 llc
->busy_state_timer
.expire
= opt
* HZ
;
1020 case LLC_OPT_TX_WIN
:
1021 if (opt
> LLC_OPT_MAX_WIN
)
1025 case LLC_OPT_RX_WIN
:
1026 if (opt
> LLC_OPT_MAX_WIN
)
1041 * llc_ui_getsockopt - get connection specific socket info
1042 * @sock: Socket to get information from.
1043 * @level: Socket level user is requesting operations on.
1044 * @optname: Operation name.
1045 * @optval: Variable to return operation data in.
1046 * @optlen: Length of optval.
1048 * Get connection specific socket information.
1050 static int llc_ui_getsockopt(struct socket
*sock
, int level
, int optname
,
1051 char __user
*optval
, int __user
*optlen
)
1053 struct sock
*sk
= sock
->sk
;
1054 struct llc_sock
*llc
= llc_sk(sk
);
1055 int val
= 0, len
= 0, rc
= -EINVAL
;
1058 if (unlikely(level
!= SOL_LLC
))
1060 rc
= get_user(len
, optlen
);
1064 if (len
!= sizeof(int))
1068 val
= llc
->n2
; break;
1070 val
= llc
->n1
; break;
1071 case LLC_OPT_ACK_TMR_EXP
:
1072 val
= llc
->ack_timer
.expire
/ HZ
; break;
1073 case LLC_OPT_P_TMR_EXP
:
1074 val
= llc
->pf_cycle_timer
.expire
/ HZ
; break;
1075 case LLC_OPT_REJ_TMR_EXP
:
1076 val
= llc
->rej_sent_timer
.expire
/ HZ
; break;
1077 case LLC_OPT_BUSY_TMR_EXP
:
1078 val
= llc
->busy_state_timer
.expire
/ HZ
; break;
1079 case LLC_OPT_TX_WIN
:
1080 val
= llc
->k
; break;
1081 case LLC_OPT_RX_WIN
:
1082 val
= llc
->rw
; break;
1088 if (put_user(len
, optlen
) || copy_to_user(optval
, &val
, len
))
1095 static struct net_proto_family llc_ui_family_ops
= {
1097 .create
= llc_ui_create
,
1098 .owner
= THIS_MODULE
,
1101 static const struct proto_ops llc_ui_ops
= {
1103 .owner
= THIS_MODULE
,
1104 .release
= llc_ui_release
,
1105 .bind
= llc_ui_bind
,
1106 .connect
= llc_ui_connect
,
1107 .socketpair
= sock_no_socketpair
,
1108 .accept
= llc_ui_accept
,
1109 .getname
= llc_ui_getname
,
1110 .poll
= datagram_poll
,
1111 .ioctl
= llc_ui_ioctl
,
1112 .listen
= llc_ui_listen
,
1113 .shutdown
= llc_ui_shutdown
,
1114 .setsockopt
= llc_ui_setsockopt
,
1115 .getsockopt
= llc_ui_getsockopt
,
1116 .sendmsg
= llc_ui_sendmsg
,
1117 .recvmsg
= llc_ui_recvmsg
,
1118 .mmap
= sock_no_mmap
,
1119 .sendpage
= sock_no_sendpage
,
1122 static char llc_proc_err_msg
[] __initdata
=
1123 KERN_CRIT
"LLC: Unable to register the proc_fs entries\n";
1124 static char llc_sysctl_err_msg
[] __initdata
=
1125 KERN_CRIT
"LLC: Unable to register the sysctl entries\n";
1126 static char llc_sock_err_msg
[] __initdata
=
1127 KERN_CRIT
"LLC: Unable to register the network family\n";
1129 static int __init
llc2_init(void)
1131 int rc
= proto_register(&llc_proto
, 0);
1136 llc_build_offset_table();
1138 llc_ui_sap_last_autoport
= LLC_SAP_DYN_START
;
1139 rc
= llc_proc_init();
1141 printk(llc_proc_err_msg
);
1142 goto out_unregister_llc_proto
;
1144 rc
= llc_sysctl_init();
1146 printk(llc_sysctl_err_msg
);
1149 rc
= sock_register(&llc_ui_family_ops
);
1151 printk(llc_sock_err_msg
);
1154 llc_add_pack(LLC_DEST_SAP
, llc_sap_handler
);
1155 llc_add_pack(LLC_DEST_CONN
, llc_conn_handler
);
1162 out_unregister_llc_proto
:
1163 proto_unregister(&llc_proto
);
1167 static void __exit
llc2_exit(void)
1170 llc_remove_pack(LLC_DEST_SAP
);
1171 llc_remove_pack(LLC_DEST_CONN
);
1172 sock_unregister(PF_LLC
);
1175 proto_unregister(&llc_proto
);
1178 module_init(llc2_init
);
1179 module_exit(llc2_exit
);
1181 MODULE_LICENSE("GPL");
1182 MODULE_AUTHOR("Procom 1997, Jay Schullist 2001, Arnaldo C. Melo 2001-2003");
1183 MODULE_DESCRIPTION("IEEE 802.2 PF_LLC support");
1184 MODULE_ALIAS_NETPROTO(PF_LLC
);