16 #include <linux/capability.h>
17 #include <linux/module.h>
18 #include <linux/errno.h>
19 #include <linux/types.h>
20 #include <linux/socket.h>
22 #include <linux/kernel.h>
23 #include <linux/sched.h>
25 #include <linux/string.h>
27 #include <linux/net.h>
28 #include <linux/slab.h>
31 #include <linux/netdevice.h>
32 #include <linux/if_arp.h>
35 #include <asm/uaccess.h>
36 #include <linux/fcntl.h>
42 #include <linux/stat.h>
43 #include <linux/netfilter.h>
44 #include <linux/sysctl.h>
57 static const struct proto_ops ax25_proto_ops;
59 static void ax25_free_sock(
struct sock *
sk)
67 static void ax25_cb_del(
ax25_cb *ax25)
70 spin_lock_bh(&ax25_list_lock);
72 spin_unlock_bh(&ax25_list_lock);
86 if ((ax25_dev = ax25_dev_ax25dev(dev)) ==
NULL)
89 spin_lock_bh(&ax25_list_lock);
94 spin_unlock_bh(&ax25_list_lock);
96 spin_lock_bh(&ax25_list_lock);
108 spin_unlock_bh(&ax25_list_lock);
119 if (!net_eq(dev_net(dev), &
init_net))
131 ax25_kill_by_device(dev);
196 s->
sk->sk_type == type) {
257 s->
sk->sk_protocol == proto &&
277 static void ax25_destroy_timer(
unsigned long data)
313 if (skb->
sk != ax25->
sk) {
318 sock_orphan(skb->
sk);
333 if (sk_has_allocations(ax25->
sk)) {
336 (
unsigned long)ax25);
354 static int ax25_ctl_ioctl(
const unsigned int cmd,
void __user *
arg)
375 digi.ndigi = ax25_ctl.digi_count;
376 for (k = 0; k < digi.ndigi; k++)
377 digi.calls[k] = ax25_ctl.digi_addr[k];
382 switch (ax25_ctl.cmd) {
385 #ifdef CONFIG_AX25_DAMA_SLAVE
394 if (ax25_ctl.arg < 1 || ax25_ctl.arg > 7)
397 if (ax25_ctl.arg < 1 || ax25_ctl.arg > 63)
400 ax25->
window = ax25_ctl.arg;
404 if (ax25_ctl.arg < 1 || ax25_ctl.arg >
ULONG_MAX /
HZ)
406 ax25->
rtt = (ax25_ctl.arg *
HZ) / 2;
407 ax25->
t1 = ax25_ctl.arg *
HZ;
411 if (ax25_ctl.arg < 1 || ax25_ctl.arg >
ULONG_MAX /
HZ)
413 ax25->
t2 = ax25_ctl.arg *
HZ;
417 if (ax25_ctl.arg < 1 || ax25_ctl.arg > 31)
420 ax25->
n2 = ax25_ctl.arg;
426 ax25->
t3 = ax25_ctl.arg *
HZ;
433 ax25->
idle = ax25_ctl.arg * 60 *
HZ;
437 if (ax25_ctl.arg < 16 || ax25_ctl.arg > 65535)
439 ax25->
paclen = ax25_ctl.arg;
455 static void ax25_fillin_cb_from_dev(
ax25_cb *ax25, ax25_dev *ax25_dev)
484 ax25_fillin_cb_from_dev(ax25, ax25_dev);
540 static int ax25_setsockopt(
struct socket *
sock,
int level,
int optname,
541 char __user *optval,
unsigned int optlen)
543 struct sock *sk = sock->
sk;
553 if (optlen <
sizeof(
unsigned int))
556 if (
get_user(opt, (
unsigned int __user *)optval))
565 if (opt < 1 || opt > 7) {
570 if (opt < 1 || opt > 63) {
583 ax25->
rtt = (opt *
HZ) >> 1;
596 if (opt < 1 || opt > 31) {
616 ax25->
idle = opt * 60 *
HZ;
640 if (opt < 16 || opt > 65535) {
669 ax25->
ax25_dev = ax25_dev_ax25dev(dev);
682 static int ax25_getsockopt(
struct socket *sock,
int level,
int optname,
683 char __user *optval,
int __user *optlen)
685 struct sock *sk = sock->
sk;
702 valptr = (
void *) &val;
703 length =
min_t(
unsigned int, maxlen,
sizeof(
int));
730 val = ax25->
idle / (60 *
HZ);
757 strlcpy(devname, ax25_dev->
dev->name,
sizeof(devname));
758 length =
strlen(devname) + 1;
764 valptr = (
void *) devname;
781 struct sock *sk = sock->
sk;
802 static struct proto ax25_proto = {
805 .obj_size =
sizeof(
struct sock),
817 switch (sock->
type) {
819 if (protocol == 0 || protocol ==
PF_AX25)
841 #ifdef CONFIG_NETROM_MODULE
847 #ifdef CONFIG_ROSE_MODULE
876 sock->
ops = &ax25_proto_ops;
917 sock_copy_flags(sk, osk);
926 ax25->
t1 = oax25->
t1;
927 ax25->
t2 = oax25->
t2;
928 ax25->
t3 = oax25->
t3;
929 ax25->
n2 = oax25->
n2;
954 static int ax25_release(
struct socket *sock)
956 struct sock *sk = sock->
sk;
968 switch (ax25->
state) {
1001 #ifdef CONFIG_AX25_DAMA_SLAVE
1002 case AX25_PROTO_DAMA_SLAVE:
1042 struct sock *sk = sock->
sk;
1044 ax25_dev *ax25_dev =
NULL;
1102 if (ax25_dev !=
NULL)
1121 struct sock *sk = sock->
sk;
1125 int ct = 0, err = 0;
1152 switch (sk->sk_state) {
1198 while (ct < fsa->
fsa_ax25.sax25_ndigis) {
1264 #ifdef CONFIG_AX25_DAMA_SLAVE
1265 case AX25_PROTO_DAMA_SLAVE:
1294 if (!signal_pending(
current)) {
1312 err = sock_error(sk);
1325 static int ax25_accept(
struct socket *sock,
struct socket *newsock,
int flags)
1336 if ((sk = sock->
sk) ==
NULL)
1360 if (flags & O_NONBLOCK) {
1364 if (!signal_pending(
current)) {
1379 sock_graft(newsk, newsock);
1392 static int ax25_getname(
struct socket *sock,
struct sockaddr *uaddr,
1393 int *uaddr_len,
int peer)
1396 struct sock *sk = sock->
sk;
1397 unsigned char ndigi,
i;
1401 memset(fsa, 0,
sizeof(*fsa));
1416 fsa->
fsa_ax25.sax25_ndigis = ndigi;
1417 for (i = 0; i < ndigi; i++)
1444 struct sock *sk = sock->
sk;
1512 while (ct < usax->sax25_ndigis) {
1513 dtmp.repeated[
ct] = 0;
1518 dtmp.lastrepeat = 0;
1554 skb_reserve(skb,
size - len);
1563 skb_reset_network_header(skb);
1592 skb_set_transport_header(skb, lv);
1594 *skb_transport_header(skb) =
AX25_UI;
1607 static int ax25_recvmsg(
struct kiocb *iocb,
struct socket *sock,
1610 struct sock *sk = sock->
sk;
1634 skb_reset_transport_header(skb);
1637 if (copied > size) {
1648 const unsigned char *
mac = skb_mac_header(skb);
1663 for (ct = 0; ct < digi.
ndigi; ct++)
1678 static int ax25_shutdown(
struct socket *sk,
int how)
1684 static int ax25_ioctl(
struct socket *sock,
unsigned int cmd,
unsigned long arg)
1686 struct sock *sk = sock->
sk;
1695 amount = sk->
sk_sndbuf - sk_wmem_alloc_get(sk);
1698 res =
put_user(amount, (
int __user *)argp);
1708 res =
put_user(amount, (
int __user *) argp);
1738 if (
get_user(amount, (
long __user *)argp)) {
1766 res = ax25_ctl_ioctl(cmd, argp);
1774 ax25_info.
t1 = ax25->
t1 /
HZ;
1775 ax25_info.t2 = ax25->
t2 /
HZ;
1776 ax25_info.t3 = ax25->
t3 /
HZ;
1777 ax25_info.idle = ax25->
idle / (60 *
HZ);
1778 ax25_info.n2 = ax25->
n2;
1783 ax25_info.n2count = ax25->
n2count;
1784 ax25_info.state = ax25->
state;
1785 ax25_info.rcv_q = sk_rmem_alloc_get(sk);
1786 ax25_info.snd_q = sk_wmem_alloc_get(sk);
1787 ax25_info.vs = ax25->
vs;
1788 ax25_info.vr = ax25->
vr;
1789 ax25_info.va = ax25->
va;
1790 ax25_info.vs_max = ax25->
vs;
1791 ax25_info.paclen = ax25->
paclen;
1792 ax25_info.window = ax25->
window;
1796 static int warned = 0;
1854 #ifdef CONFIG_PROC_FS
1856 static void *ax25_info_start(
struct seq_file *seq, loff_t *
pos)
1859 spin_lock_bh(&ax25_list_lock);
1863 static void *ax25_info_next(
struct seq_file *seq,
void *
v, loff_t *
pos)
1868 static void ax25_info_stop(
struct seq_file *seq,
void *
v)
1871 spin_unlock_bh(&ax25_list_lock);
1874 static int ax25_info_show(
struct seq_file *seq,
void *
v)
1888 ax25->
ax25_dev ==
NULL?
"???" : ax25->ax25_dev->dev->name,
1889 ax2asc(buf, &ax25->source_addr),
1890 ax25->iamdigi?
"*":
"");
1893 for (k=0; (ax25->digipeat !=
NULL) && (k < ax25->digipeat->ndigi); k++) {
1895 ax2asc(buf, &ax25->digipeat->calls[k]),
1896 ax25->digipeat->repeated[k]?
"*":
"");
1899 seq_printf(seq,
" %d %d %d %d %lu %lu %lu %lu %lu %lu %lu %lu %d %d %lu %d %d",
1901 ax25->vs, ax25->vr, ax25->va,
1906 ax25->idle / (60 * HZ),
1907 ax25->n2count, ax25->n2,
1912 if (ax25->sk !=
NULL) {
1914 sk_wmem_alloc_get(ax25->sk),
1915 sk_rmem_alloc_get(ax25->sk),
1924 .
start = ax25_info_start,
1925 .next = ax25_info_next,
1926 .stop = ax25_info_stop,
1927 .show = ax25_info_show,
1932 return seq_open(file, &ax25_info_seqops);
1937 .open = ax25_info_open,
1947 .create = ax25_create,
1951 static const struct proto_ops ax25_proto_ops = {
1954 .release = ax25_release,
1956 .connect = ax25_connect,
1958 .accept = ax25_accept,
1959 .getname = ax25_getname,
1961 .ioctl = ax25_ioctl,
1962 .listen = ax25_listen,
1963 .shutdown = ax25_shutdown,
1964 .setsockopt = ax25_setsockopt,
1965 .getsockopt = ax25_getsockopt,
1966 .sendmsg = ax25_sendmsg,
1967 .recvmsg = ax25_recvmsg,
1981 .notifier_call =ax25_device_event,
1984 static int __init ax25_init(
void)
2009 static void __exit ax25_exit(
void)