11 #include <linux/module.h>
13 #include <linux/capability.h>
14 #include <linux/errno.h>
15 #include <linux/types.h>
16 #include <linux/socket.h>
18 #include <linux/slab.h>
19 #include <linux/kernel.h>
20 #include <linux/sched.h>
22 #include <linux/string.h>
24 #include <linux/net.h>
25 #include <linux/stat.h>
28 #include <linux/netdevice.h>
29 #include <linux/if_arp.h>
33 #include <asm/uaccess.h>
34 #include <linux/fcntl.h>
47 static int nr_ndevs = 4;
62 static unsigned short circuit = 0x101;
67 static const struct proto_ops nr_proto_ops;
88 netdev_for_each_tx_queue(dev, nr_set_lockdep_one,
NULL);
94 static void nr_remove_socket(
struct sock *
sk)
96 spin_lock_bh(&nr_list_lock);
98 spin_unlock_bh(&nr_list_lock);
109 spin_lock_bh(&nr_list_lock);
113 spin_unlock_bh(&nr_list_lock);
123 if (!net_eq(dev_net(dev), &
init_net))
129 nr_kill_by_device(dev);
138 static void nr_insert_socket(
struct sock *
sk)
140 spin_lock_bh(&nr_list_lock);
141 sk_add_node(sk, &nr_list);
142 spin_unlock_bh(&nr_list_lock);
154 spin_lock_bh(&nr_list_lock);
163 spin_unlock_bh(&nr_list_lock);
170 static struct sock *nr_find_socket(
unsigned char index,
unsigned char id)
175 spin_lock_bh(&nr_list_lock);
186 spin_unlock_bh(&nr_list_lock);
193 static struct sock *nr_find_peer(
unsigned char index,
unsigned char id,
199 spin_lock_bh(&nr_list_lock);
211 spin_unlock_bh(&nr_list_lock);
218 static unsigned short nr_find_next_circuit(
void)
220 unsigned short id = circuit;
228 if (i != 0 && j != 0) {
229 if ((sk=nr_find_socket(i, j)) ==
NULL)
248 static void nr_destroy_timer(
unsigned long data)
250 struct sock *sk=(
struct sock *)data;
268 nr_remove_socket(sk);
289 if (sk_has_allocations(sk)) {
291 sk->
sk_timer.function = nr_destroy_timer;
304 char __user *optval,
unsigned int optlen)
306 struct sock *sk = sock->
sk;
313 if (optlen <
sizeof(
unsigned int))
316 if (
get_user(opt, (
unsigned int __user *)optval))
333 if (opt < 1 || opt > 31)
355 static int nr_getsockopt(
struct socket *sock,
int level,
int optname,
356 char __user *optval,
int __user *optlen)
358 struct sock *sk = sock->
sk;
390 val = nr->
idle / (60 *
HZ);
397 len =
min_t(
unsigned int, len,
sizeof(
int));
407 struct sock *sk = sock->
sk;
422 static struct proto nr_proto = {
425 .obj_size =
sizeof(
struct nr_sock),
448 sock->
ops = &nr_proto_ops;
475 static struct sock *nr_make_new(
struct sock *osk)
497 sock_copy_flags(sk, osk);
520 static int nr_release(
struct socket *sock)
522 struct sock *sk = sock->
sk;
525 if (sk ==
NULL)
return 0;
568 struct sock *sk = sock->
sk;
600 if (addr->
fsa_ax25.sax25_ndigis == 1) {
609 source = &addr->
fsa_ax25.sax25_call;
628 nr_insert_socket(sk);
637 static int nr_connect(
struct socket *sock,
struct sockaddr *uaddr,
638 int addr_len,
int flags)
640 struct sock *sk = sock->
sk;
702 nr_insert_socket(sk);
708 circuit = nr_find_next_circuit();
712 nr->
my_id = circuit % 256;
744 if (!signal_pending(
current)) {
760 err = sock_error(sk);
772 static int nr_accept(
struct socket *sock,
struct socket *newsock,
int flags)
780 if ((sk = sock->
sk) ==
NULL)
804 if (flags & O_NONBLOCK) {
808 if (!signal_pending(
current)) {
822 sock_graft(newsk, newsock);
826 sk_acceptq_removed(sk);
834 static int nr_getname(
struct socket *sock,
struct sockaddr *uaddr,
835 int *uaddr_len,
int peer)
838 struct sock *sk = sock->
sk;
870 unsigned short circuit_index, circuit_id;
871 unsigned short peer_circuit_index, peer_circuit_id;
884 circuit_index = skb->
data[15];
885 circuit_id = skb->
data[16];
886 peer_circuit_index = skb->
data[17];
887 peer_circuit_id = skb->
data[18];
888 frametype = skb->
data[19] & 0x0F;
889 flags = skb->
data[19] & 0xF0;
897 skb_reset_transport_header(skb);
912 if (circuit_index == 0 && circuit_id == 0) {
914 sk = nr_find_peer(peer_circuit_index, peer_circuit_id, src);
917 sk = nr_find_peer(circuit_index, circuit_id, src);
919 sk = nr_find_socket(circuit_index, circuit_id);
923 skb_reset_transport_header(skb);
926 nr_sk(sk)->bpqext = 1;
928 nr_sk(sk)->bpqext = 0;
949 (frametype !=
NR_RESET || flags != 0))
955 sk = nr_find_listener(dest);
959 if (sk ==
NULL || sk_acceptq_is_full(sk) ||
960 (make = nr_make_new(sk)) ==
NULL) {
967 window = skb->
data[20];
973 nr_make =
nr_sk(make);
982 circuit = nr_find_next_circuit();
986 nr_make->
my_id = circuit % 256;
991 if (window < nr_make->window)
995 if (skb->
len == 37) {
996 timeout = skb->
data[36] * 256 + skb->
data[35];
997 if (timeout * HZ < nr_make->
t1)
998 nr_make->
t1 = timeout *
HZ;
1012 sk_acceptq_added(sk);
1020 nr_insert_socket(make);
1031 struct sock *sk = sock->
sk;
1037 unsigned char *asmptr;
1095 skb_reserve(skb,
size - len);
1096 skb_reset_transport_header(skb);
1102 asmptr =
skb_push(skb, NR_TRANSPORT_LEN);
1138 static int nr_recvmsg(
struct kiocb *iocb,
struct socket *sock,
1141 struct sock *sk = sock->
sk;
1164 skb_reset_transport_header(skb);
1167 if (copied > size) {
1194 static int nr_ioctl(
struct socket *sock,
unsigned int cmd,
unsigned long arg)
1196 struct sock *sk = sock->
sk;
1205 amount = sk->
sk_sndbuf - sk_wmem_alloc_get(sk);
1209 return put_user(amount, (
int __user *)argp);
1221 return put_user(amount, (
int __user *)argp);
1262 #ifdef CONFIG_PROC_FS
1264 static void *nr_info_start(
struct seq_file *seq, loff_t *
pos)
1266 spin_lock_bh(&nr_list_lock);
1270 static void *nr_info_next(
struct seq_file *seq,
void *
v, loff_t *
pos)
1275 static void nr_info_stop(
struct seq_file *seq,
void *
v)
1277 spin_unlock_bh(&nr_list_lock);
1280 static int nr_info_show(
struct seq_file *seq,
void *
v)
1282 struct sock *s = sk_entry(v);
1285 const char *devname;
1290 "user_addr dest_node src_node dev my your st vs vr va t1 t2 t4 idle n2 wnd Snd-Q Rcv-Q inode\n");
1300 devname = dev->
name;
1305 "%-9s %-3s %02X/%02X %02X/%02X %2d %3d %3d %3d %3lu/%03lu %2lu/%02lu %3lu/%03lu %3lu/%03lu %2d/%02d %3d %5d %5d %ld\n",
1323 nr->
idle / (60 * HZ),
1327 sk_wmem_alloc_get(s),
1328 sk_rmem_alloc_get(s),
1337 .
start = nr_info_start,
1338 .next = nr_info_next,
1339 .stop = nr_info_stop,
1340 .show = nr_info_show,
1345 return seq_open(file, &nr_info_seqops);
1350 .open = nr_info_open,
1359 .create = nr_create,
1363 static const struct proto_ops nr_proto_ops = {
1366 .release = nr_release,
1368 .connect = nr_connect,
1370 .accept = nr_accept,
1371 .getname = nr_getname,
1374 .listen = nr_listen,
1376 .setsockopt = nr_setsockopt,
1377 .getsockopt = nr_getsockopt,
1378 .sendmsg = nr_sendmsg,
1379 .recvmsg = nr_recvmsg,
1385 .notifier_call = nr_device_event,
1399 static int __init nr_proto_init(
void)
1407 if (nr_ndevs > 0x7fffffff/
sizeof(
struct net_device *)) {
1408 printk(
KERN_ERR "NET/ROM: nr_proto_init - nr_ndevs parameter to large\n");
1413 if (dev_nr ==
NULL) {
1414 printk(
KERN_ERR "NET/ROM: nr_proto_init - unable to allocate device array\n");
1418 for (i = 0; i < nr_ndevs; i++) {
1425 printk(
KERN_ERR "NET/ROM: nr_proto_init - unable to allocate device structure\n");
1431 printk(
KERN_ERR "NET/ROM: nr_proto_init - unable to register network device\n");
1435 nr_set_lockdep_key(dev);
1440 printk(
KERN_ERR "NET/ROM: nr_proto_init - unable to register socket family\n");
1449 #ifdef CONFIG_SYSCTL
1477 MODULE_DESCRIPTION(
"The amateur radio NET/ROM network and transport layer protocol");
1481 static void __exit nr_exit(
void)
1492 #ifdef CONFIG_SYSCTL
1503 for (i = 0; i < nr_ndevs; i++) {