23 #include <linux/compiler.h>
24 #include <linux/kernel.h>
25 #include <linux/module.h>
26 #include <linux/rtnetlink.h>
28 #include <linux/slab.h>
37 static u16 llc_ui_sap_link_no_max[256];
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 #define LLC_CMSG_PKTINFO 1
61 static inline u16 llc_ui_next_link_no(
int sap)
63 return llc_ui_sap_link_no_max[sap]++;
72 static inline __be16 llc_proto_type(
u16 arphrd)
83 return !
memcmp(addr, &llc_ui_addrnull,
sizeof(*addr));
115 static int llc_ui_send_data(
struct sock* sk,
struct sk_buff *
skb,
int noblock)
123 long timeout = sock_sndtimeo(sk, noblock);
125 rc = llc_ui_wait_for_busy_core(sk, timeout);
132 static void llc_ui_sk_init(
struct socket *
sock,
struct sock *sk)
134 sock_graft(sk, sock);
136 sock->
ops = &llc_ui_ops;
139 static struct proto llc_proto = {
142 .obj_size =
sizeof(
struct llc_sock),
174 llc_ui_sk_init(sock, sk);
186 static int llc_ui_release(
struct socket *sock)
188 struct sock *sk = sock->
sk;
196 dprintk(
"%s: closing local(%02X) remote(%02X)\n", __func__,
218 static int llc_ui_autoport(
void)
224 for (i = llc_ui_sap_last_autoport;
228 llc_ui_sap_last_autoport = i + 2;
253 struct sock *sk = sock->
sk;
261 if (sk->sk_bound_dev_if) {
272 llc->
laddr.lsap = llc_ui_autoport();
273 if (!llc->
laddr.lsap)
306 struct sock *sk = sock->
sk;
319 if (sk->sk_bound_dev_if) {
329 llc->
dev->dev_addr)) {
397 static int llc_ui_shutdown(
struct socket *sock,
int how)
399 struct sock *sk = sock->
sk;
432 static int llc_ui_connect(
struct socket *sock,
struct sockaddr *uaddr,
433 int addrlen,
int flags)
435 struct sock *sk = sock->
sk;
441 if (
unlikely(addrlen !=
sizeof(*addr)))
454 rc = llc_ui_autobind(sock, addr);
462 llc->
link = llc_ui_next_link_no(llc->
sap->laddr.lsap);
466 dprintk(
"%s: llc_ui_send_conn failed :-(\n", __func__);
473 const long timeo = sock_sndtimeo(sk, flags &
O_NONBLOCK);
475 if (!timeo || !llc_ui_wait_for_conn(sk, timeo))
478 rc = sock_intr_errno(timeo);
507 struct sock *sk = sock->
sk;
520 if (!(
unsigned int)backlog)
533 static int llc_ui_wait_for_disc(
struct sock *sk,
long timeout)
554 static int llc_ui_wait_for_conn(
struct sock *sk,
long timeout)
562 if (signal_pending(
current) || !timeout)
569 static int llc_ui_wait_for_busy_core(
struct sock *sk,
long timeout)
595 static int llc_wait_data(
struct sock *sk,
long timeo)
612 rc = sock_intr_errno(timeo);
629 info.lpi_ifindex = llc_sk(skb->
sk)->dev->ifindex;
630 llc_pdu_decode_dsap(skb, &
info.lpi_sap);
631 llc_pdu_decode_da(skb,
info.lpi_mac);
645 static int llc_ui_accept(
struct socket *sock,
struct socket *newsock,
int flags)
647 struct sock *sk = sock->
sk, *newsk;
652 dprintk(
"%s: accepting on %02X\n", __func__,
653 llc_sk(sk)->
laddr.lsap);
667 dprintk(
"%s: got a new connection on %02X\n", __func__,
668 llc_sk(sk)->
laddr.lsap);
676 llc_ui_sk_init(newsock, newsk);
681 newllc = llc_sk(newsk);
683 newllc->
link = llc_ui_next_link_no(newllc->
laddr.lsap);
688 dprintk(
"%s: ok success on %02X, client on %02X\n", __func__,
708 struct msghdr *msg,
size_t len,
int flags)
713 struct sock *sk = sock->
sk;
715 unsigned long cpu_flags;
728 timeo = sock_rcvtimeo(sk, nonblock);
736 target = sock_rcvlowat(sk, flags &
MSG_WAITALL, len);
750 copied = timeo ? sock_intr_errno(timeo) : -
EAGAIN;
778 copied = sock_error(sk);
801 if (copied >= target) {
807 if ((flags & MSG_PEEK) && peek_seq != llc->
copied_seq) {
839 if (!(flags & MSG_PEEK)) {
841 sk_eat_skb(sk, skb,
false);
859 if (llc_sk(sk)->cmsg_flags)
860 llc_cmsg_rcv(msg, skb);
862 if (!(flags & MSG_PEEK)) {
864 sk_eat_skb(sk, skb,
false);
881 static int llc_ui_sendmsg(
struct kiocb *iocb,
struct socket *sock,
882 struct msghdr *msg,
size_t len)
884 struct sock *sk = sock->
sk;
893 dprintk(
"%s: sending from %02X to %02X\n", __func__,
900 if (llc_ui_addr_null(&llc->
addr))
907 rc = llc_ui_autobind(sock, addr);
911 hdrlen = llc->
dev->hard_header_len + llc_ui_header_len(sk, addr);
923 skb_reserve(skb, hdrlen);
945 rc = llc_ui_send_data(sk, skb, noblock);
950 dprintk(
"%s: failed sending from %02X to %02X: %d\n",
951 __func__, llc->
laddr.lsap, llc->
daddr.lsap, rc);
954 return rc ? : copied;
966 static int llc_ui_getname(
struct socket *sock,
struct sockaddr *uaddr,
967 int *uaddrlen,
int peer)
970 struct sock *sk = sock->
sk;
974 memset(&sllc, 0,
sizeof(sllc));
978 *uaddrlen =
sizeof(sllc);
984 sllc.sllc_arphrd = llc->
dev->type;
985 sllc.sllc_sap = llc->
daddr.lsap;
991 sllc.sllc_sap = llc->
sap->laddr.lsap;
994 sllc.sllc_arphrd = llc->
dev->type;
995 memcpy(&sllc.sllc_mac, llc->
dev->dev_addr,
1000 sllc.sllc_family =
AF_LLC;
1001 memcpy(uaddr, &sllc,
sizeof(sllc));
1015 static int llc_ui_ioctl(
struct socket *sock,
unsigned int cmd,
1031 static int llc_ui_setsockopt(
struct socket *sock,
int level,
int optname,
1032 char __user *optval,
unsigned int optlen)
1034 struct sock *sk = sock->
sk;
1042 rc =
get_user(opt, (
int __user *)optval);
1113 static int llc_ui_getsockopt(
struct socket *sock,
int level,
int optname,
1114 char __user *optval,
int __user *optlen)
1116 struct sock *sk = sock->
sk;
1127 if (len !=
sizeof(
int))
1131 val = llc->
n2;
break;
1133 val = llc->
n1;
break;
1143 val = llc->
k;
break;
1145 val = llc->
rw;
break;
1163 .create = llc_ui_create,
1167 static const struct proto_ops llc_ui_ops = {
1170 .release = llc_ui_release,
1171 .bind = llc_ui_bind,
1172 .connect = llc_ui_connect,
1174 .accept = llc_ui_accept,
1175 .getname = llc_ui_getname,
1177 .ioctl = llc_ui_ioctl,
1178 .listen = llc_ui_listen,
1179 .shutdown = llc_ui_shutdown,
1180 .setsockopt = llc_ui_setsockopt,
1181 .getsockopt = llc_ui_getsockopt,
1182 .sendmsg = llc_ui_sendmsg,
1183 .recvmsg = llc_ui_recvmsg,
1188 static const char llc_proc_err_msg[]
__initconst =
1189 KERN_CRIT "LLC: Unable to register the proc_fs entries\n";
1190 static const char llc_sysctl_err_msg[] __initconst =
1191 KERN_CRIT "LLC: Unable to register the sysctl entries\n";
1192 static const char llc_sock_err_msg[] __initconst =
1193 KERN_CRIT "LLC: Unable to register the network family\n";
1195 static int __init llc2_init(
void)
1207 printk(llc_proc_err_msg);
1212 printk(llc_sysctl_err_msg);
1217 printk(llc_sock_err_msg);
1234 static void __exit llc2_exit(
void)
1249 MODULE_AUTHOR(
"Procom 1997, Jay Schullist 2001, Arnaldo C. Melo 2001-2003");