i386: Reserve the right performance counter for the Intel PerfMon NMI watchdog
[usb.git] / net / decnet / af_decnet.c
blobed76d4aab4a9dd241295463795ce373a7a317833
2 /*
3 * DECnet An implementation of the DECnet protocol suite for the LINUX
4 * operating system. DECnet is implemented using the BSD Socket
5 * interface as the means of communication with the user level.
7 * DECnet Socket Layer Interface
9 * Authors: Eduardo Marcelo Serrat <emserrat@geocities.com>
10 * Patrick Caulfield <patrick@pandh.demon.co.uk>
12 * Changes:
13 * Steve Whitehouse: Copied from Eduardo Serrat and Patrick Caulfield's
14 * version of the code. Original copyright preserved
15 * below.
16 * Steve Whitehouse: Some bug fixes, cleaning up some code to make it
17 * compatible with my routing layer.
18 * Steve Whitehouse: Merging changes from Eduardo Serrat and Patrick
19 * Caulfield.
20 * Steve Whitehouse: Further bug fixes, checking module code still works
21 * with new routing layer.
22 * Steve Whitehouse: Additional set/get_sockopt() calls.
23 * Steve Whitehouse: Fixed TIOCINQ ioctl to be same as Eduardo's new
24 * code.
25 * Steve Whitehouse: recvmsg() changed to try and behave in a POSIX like
26 * way. Didn't manage it entirely, but its better.
27 * Steve Whitehouse: ditto for sendmsg().
28 * Steve Whitehouse: A selection of bug fixes to various things.
29 * Steve Whitehouse: Added TIOCOUTQ ioctl.
30 * Steve Whitehouse: Fixes to username2sockaddr & sockaddr2username.
31 * Steve Whitehouse: Fixes to connect() error returns.
32 * Patrick Caulfield: Fixes to delayed acceptance logic.
33 * David S. Miller: New socket locking
34 * Steve Whitehouse: Socket list hashing/locking
35 * Arnaldo C. Melo: use capable, not suser
36 * Steve Whitehouse: Removed unused code. Fix to use sk->allocation
37 * when required.
38 * Patrick Caulfield: /proc/net/decnet now has object name/number
39 * Steve Whitehouse: Fixed local port allocation, hashed sk list
40 * Matthew Wilcox: Fixes for dn_ioctl()
41 * Steve Whitehouse: New connect/accept logic to allow timeouts and
42 * prepare for sendpage etc.
46 /******************************************************************************
47 (c) 1995-1998 E.M. Serrat emserrat@geocities.com
49 This program is free software; you can redistribute it and/or modify
50 it under the terms of the GNU General Public License as published by
51 the Free Software Foundation; either version 2 of the License, or
52 any later version.
54 This program is distributed in the hope that it will be useful,
55 but WITHOUT ANY WARRANTY; without even the implied warranty of
56 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
57 GNU General Public License for more details.
59 HISTORY:
61 Version Kernel Date Author/Comments
62 ------- ------ ---- ---------------
63 Version 0.0.1 2.0.30 01-dic-97 Eduardo Marcelo Serrat
64 (emserrat@geocities.com)
66 First Development of DECnet Socket La-
67 yer for Linux. Only supports outgoing
68 connections.
70 Version 0.0.2 2.1.105 20-jun-98 Patrick J. Caulfield
71 (patrick@pandh.demon.co.uk)
73 Port to new kernel development version.
75 Version 0.0.3 2.1.106 25-jun-98 Eduardo Marcelo Serrat
76 (emserrat@geocities.com)
78 Added support for incoming connections
79 so we can start developing server apps
80 on Linux.
82 Module Support
83 Version 0.0.4 2.1.109 21-jul-98 Eduardo Marcelo Serrat
84 (emserrat@geocities.com)
86 Added support for X11R6.4. Now we can
87 use DECnet transport for X on Linux!!!
89 Version 0.0.5 2.1.110 01-aug-98 Eduardo Marcelo Serrat
90 (emserrat@geocities.com)
91 Removed bugs on flow control
92 Removed bugs on incoming accessdata
93 order
95 Version 0.0.6 2.1.110 07-aug-98 Eduardo Marcelo Serrat
96 dn_recvmsg fixes
98 Patrick J. Caulfield
99 dn_bind fixes
100 *******************************************************************************/
102 #include <linux/module.h>
103 #include <linux/errno.h>
104 #include <linux/types.h>
105 #include <linux/slab.h>
106 #include <linux/socket.h>
107 #include <linux/in.h>
108 #include <linux/kernel.h>
109 #include <linux/sched.h>
110 #include <linux/timer.h>
111 #include <linux/string.h>
112 #include <linux/sockios.h>
113 #include <linux/net.h>
114 #include <linux/netdevice.h>
115 #include <linux/inet.h>
116 #include <linux/route.h>
117 #include <linux/netfilter.h>
118 #include <linux/seq_file.h>
119 #include <net/sock.h>
120 #include <net/tcp_states.h>
121 #include <net/flow.h>
122 #include <asm/system.h>
123 #include <asm/ioctls.h>
124 #include <linux/capability.h>
125 #include <linux/mm.h>
126 #include <linux/interrupt.h>
127 #include <linux/proc_fs.h>
128 #include <linux/stat.h>
129 #include <linux/init.h>
130 #include <linux/poll.h>
131 #include <net/neighbour.h>
132 #include <net/dst.h>
133 #include <net/fib_rules.h>
134 #include <net/dn.h>
135 #include <net/dn_nsp.h>
136 #include <net/dn_dev.h>
137 #include <net/dn_route.h>
138 #include <net/dn_fib.h>
139 #include <net/dn_neigh.h>
141 struct dn_sock {
142 struct sock sk;
143 struct dn_scp scp;
146 static void dn_keepalive(struct sock *sk);
148 #define DN_SK_HASH_SHIFT 8
149 #define DN_SK_HASH_SIZE (1 << DN_SK_HASH_SHIFT)
150 #define DN_SK_HASH_MASK (DN_SK_HASH_SIZE - 1)
153 static const struct proto_ops dn_proto_ops;
154 static DEFINE_RWLOCK(dn_hash_lock);
155 static struct hlist_head dn_sk_hash[DN_SK_HASH_SIZE];
156 static struct hlist_head dn_wild_sk;
157 static atomic_t decnet_memory_allocated;
159 static int __dn_setsockopt(struct socket *sock, int level, int optname, char __user *optval, int optlen, int flags);
160 static int __dn_getsockopt(struct socket *sock, int level, int optname, char __user *optval, int __user *optlen, int flags);
162 static struct hlist_head *dn_find_list(struct sock *sk)
164 struct dn_scp *scp = DN_SK(sk);
166 if (scp->addr.sdn_flags & SDF_WILD)
167 return hlist_empty(&dn_wild_sk) ? &dn_wild_sk : NULL;
169 return &dn_sk_hash[dn_ntohs(scp->addrloc) & DN_SK_HASH_MASK];
173 * Valid ports are those greater than zero and not already in use.
175 static int check_port(__le16 port)
177 struct sock *sk;
178 struct hlist_node *node;
180 if (port == 0)
181 return -1;
183 sk_for_each(sk, node, &dn_sk_hash[dn_ntohs(port) & DN_SK_HASH_MASK]) {
184 struct dn_scp *scp = DN_SK(sk);
185 if (scp->addrloc == port)
186 return -1;
188 return 0;
191 static unsigned short port_alloc(struct sock *sk)
193 struct dn_scp *scp = DN_SK(sk);
194 static unsigned short port = 0x2000;
195 unsigned short i_port = port;
197 while(check_port(dn_htons(++port)) != 0) {
198 if (port == i_port)
199 return 0;
202 scp->addrloc = dn_htons(port);
204 return 1;
208 * Since this is only ever called from user
209 * level, we don't need a write_lock() version
210 * of this.
212 static int dn_hash_sock(struct sock *sk)
214 struct dn_scp *scp = DN_SK(sk);
215 struct hlist_head *list;
216 int rv = -EUSERS;
218 BUG_ON(sk_hashed(sk));
220 write_lock_bh(&dn_hash_lock);
222 if (!scp->addrloc && !port_alloc(sk))
223 goto out;
225 rv = -EADDRINUSE;
226 if ((list = dn_find_list(sk)) == NULL)
227 goto out;
229 sk_add_node(sk, list);
230 rv = 0;
231 out:
232 write_unlock_bh(&dn_hash_lock);
233 return rv;
236 static void dn_unhash_sock(struct sock *sk)
238 write_lock(&dn_hash_lock);
239 sk_del_node_init(sk);
240 write_unlock(&dn_hash_lock);
243 static void dn_unhash_sock_bh(struct sock *sk)
245 write_lock_bh(&dn_hash_lock);
246 sk_del_node_init(sk);
247 write_unlock_bh(&dn_hash_lock);
250 static struct hlist_head *listen_hash(struct sockaddr_dn *addr)
252 int i;
253 unsigned hash = addr->sdn_objnum;
255 if (hash == 0) {
256 hash = addr->sdn_objnamel;
257 for(i = 0; i < dn_ntohs(addr->sdn_objnamel); i++) {
258 hash ^= addr->sdn_objname[i];
259 hash ^= (hash << 3);
263 return &dn_sk_hash[hash & DN_SK_HASH_MASK];
267 * Called to transform a socket from bound (i.e. with a local address)
268 * into a listening socket (doesn't need a local port number) and rehashes
269 * based upon the object name/number.
271 static void dn_rehash_sock(struct sock *sk)
273 struct hlist_head *list;
274 struct dn_scp *scp = DN_SK(sk);
276 if (scp->addr.sdn_flags & SDF_WILD)
277 return;
279 write_lock_bh(&dn_hash_lock);
280 sk_del_node_init(sk);
281 DN_SK(sk)->addrloc = 0;
282 list = listen_hash(&DN_SK(sk)->addr);
283 sk_add_node(sk, list);
284 write_unlock_bh(&dn_hash_lock);
287 int dn_sockaddr2username(struct sockaddr_dn *sdn, unsigned char *buf, unsigned char type)
289 int len = 2;
291 *buf++ = type;
293 switch(type) {
294 case 0:
295 *buf++ = sdn->sdn_objnum;
296 break;
297 case 1:
298 *buf++ = 0;
299 *buf++ = dn_ntohs(sdn->sdn_objnamel);
300 memcpy(buf, sdn->sdn_objname, dn_ntohs(sdn->sdn_objnamel));
301 len = 3 + dn_ntohs(sdn->sdn_objnamel);
302 break;
303 case 2:
304 memset(buf, 0, 5);
305 buf += 5;
306 *buf++ = dn_ntohs(sdn->sdn_objnamel);
307 memcpy(buf, sdn->sdn_objname, dn_ntohs(sdn->sdn_objnamel));
308 len = 7 + dn_ntohs(sdn->sdn_objnamel);
309 break;
312 return len;
316 * On reception of usernames, we handle types 1 and 0 for destination
317 * addresses only. Types 2 and 4 are used for source addresses, but the
318 * UIC, GIC are ignored and they are both treated the same way. Type 3
319 * is never used as I've no idea what its purpose might be or what its
320 * format is.
322 int dn_username2sockaddr(unsigned char *data, int len, struct sockaddr_dn *sdn, unsigned char *fmt)
324 unsigned char type;
325 int size = len;
326 int namel = 12;
328 sdn->sdn_objnum = 0;
329 sdn->sdn_objnamel = dn_htons(0);
330 memset(sdn->sdn_objname, 0, DN_MAXOBJL);
332 if (len < 2)
333 return -1;
335 len -= 2;
336 *fmt = *data++;
337 type = *data++;
339 switch(*fmt) {
340 case 0:
341 sdn->sdn_objnum = type;
342 return 2;
343 case 1:
344 namel = 16;
345 break;
346 case 2:
347 len -= 4;
348 data += 4;
349 break;
350 case 4:
351 len -= 8;
352 data += 8;
353 break;
354 default:
355 return -1;
358 len -= 1;
360 if (len < 0)
361 return -1;
363 sdn->sdn_objnamel = dn_htons(*data++);
364 len -= dn_ntohs(sdn->sdn_objnamel);
366 if ((len < 0) || (dn_ntohs(sdn->sdn_objnamel) > namel))
367 return -1;
369 memcpy(sdn->sdn_objname, data, dn_ntohs(sdn->sdn_objnamel));
371 return size - len;
374 struct sock *dn_sklist_find_listener(struct sockaddr_dn *addr)
376 struct hlist_head *list = listen_hash(addr);
377 struct hlist_node *node;
378 struct sock *sk;
380 read_lock(&dn_hash_lock);
381 sk_for_each(sk, node, list) {
382 struct dn_scp *scp = DN_SK(sk);
383 if (sk->sk_state != TCP_LISTEN)
384 continue;
385 if (scp->addr.sdn_objnum) {
386 if (scp->addr.sdn_objnum != addr->sdn_objnum)
387 continue;
388 } else {
389 if (addr->sdn_objnum)
390 continue;
391 if (scp->addr.sdn_objnamel != addr->sdn_objnamel)
392 continue;
393 if (memcmp(scp->addr.sdn_objname, addr->sdn_objname, dn_ntohs(addr->sdn_objnamel)) != 0)
394 continue;
396 sock_hold(sk);
397 read_unlock(&dn_hash_lock);
398 return sk;
401 sk = sk_head(&dn_wild_sk);
402 if (sk) {
403 if (sk->sk_state == TCP_LISTEN)
404 sock_hold(sk);
405 else
406 sk = NULL;
409 read_unlock(&dn_hash_lock);
410 return sk;
413 struct sock *dn_find_by_skb(struct sk_buff *skb)
415 struct dn_skb_cb *cb = DN_SKB_CB(skb);
416 struct sock *sk;
417 struct hlist_node *node;
418 struct dn_scp *scp;
420 read_lock(&dn_hash_lock);
421 sk_for_each(sk, node, &dn_sk_hash[dn_ntohs(cb->dst_port) & DN_SK_HASH_MASK]) {
422 scp = DN_SK(sk);
423 if (cb->src != dn_saddr2dn(&scp->peer))
424 continue;
425 if (cb->dst_port != scp->addrloc)
426 continue;
427 if (scp->addrrem && (cb->src_port != scp->addrrem))
428 continue;
429 sock_hold(sk);
430 goto found;
432 sk = NULL;
433 found:
434 read_unlock(&dn_hash_lock);
435 return sk;
440 static void dn_destruct(struct sock *sk)
442 struct dn_scp *scp = DN_SK(sk);
444 skb_queue_purge(&scp->data_xmit_queue);
445 skb_queue_purge(&scp->other_xmit_queue);
446 skb_queue_purge(&scp->other_receive_queue);
448 dst_release(xchg(&sk->sk_dst_cache, NULL));
451 static int dn_memory_pressure;
453 static void dn_enter_memory_pressure(void)
455 if (!dn_memory_pressure) {
456 dn_memory_pressure = 1;
460 static struct proto dn_proto = {
461 .name = "NSP",
462 .owner = THIS_MODULE,
463 .enter_memory_pressure = dn_enter_memory_pressure,
464 .memory_pressure = &dn_memory_pressure,
465 .memory_allocated = &decnet_memory_allocated,
466 .sysctl_mem = sysctl_decnet_mem,
467 .sysctl_wmem = sysctl_decnet_wmem,
468 .sysctl_rmem = sysctl_decnet_rmem,
469 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
470 .obj_size = sizeof(struct dn_sock),
473 static struct sock *dn_alloc_sock(struct socket *sock, gfp_t gfp)
475 struct dn_scp *scp;
476 struct sock *sk = sk_alloc(PF_DECnet, gfp, &dn_proto, 1);
478 if (!sk)
479 goto out;
481 if (sock)
482 sock->ops = &dn_proto_ops;
483 sock_init_data(sock, sk);
485 sk->sk_backlog_rcv = dn_nsp_backlog_rcv;
486 sk->sk_destruct = dn_destruct;
487 sk->sk_no_check = 1;
488 sk->sk_family = PF_DECnet;
489 sk->sk_protocol = 0;
490 sk->sk_allocation = gfp;
491 sk->sk_sndbuf = sysctl_decnet_wmem[1];
492 sk->sk_rcvbuf = sysctl_decnet_rmem[1];
494 /* Initialization of DECnet Session Control Port */
495 scp = DN_SK(sk);
496 scp->state = DN_O; /* Open */
497 scp->numdat = 1; /* Next data seg to tx */
498 scp->numoth = 1; /* Next oth data to tx */
499 scp->ackxmt_dat = 0; /* Last data seg ack'ed */
500 scp->ackxmt_oth = 0; /* Last oth data ack'ed */
501 scp->ackrcv_dat = 0; /* Highest data ack recv*/
502 scp->ackrcv_oth = 0; /* Last oth data ack rec*/
503 scp->flowrem_sw = DN_SEND;
504 scp->flowloc_sw = DN_SEND;
505 scp->flowrem_dat = 0;
506 scp->flowrem_oth = 1;
507 scp->flowloc_dat = 0;
508 scp->flowloc_oth = 1;
509 scp->services_rem = 0;
510 scp->services_loc = 1 | NSP_FC_NONE;
511 scp->info_rem = 0;
512 scp->info_loc = 0x03; /* NSP version 4.1 */
513 scp->segsize_rem = 230 - DN_MAX_NSP_DATA_HEADER; /* Default: Updated by remote segsize */
514 scp->nonagle = 0;
515 scp->multi_ireq = 1;
516 scp->accept_mode = ACC_IMMED;
517 scp->addr.sdn_family = AF_DECnet;
518 scp->peer.sdn_family = AF_DECnet;
519 scp->accessdata.acc_accl = 5;
520 memcpy(scp->accessdata.acc_acc, "LINUX", 5);
522 scp->max_window = NSP_MAX_WINDOW;
523 scp->snd_window = NSP_MIN_WINDOW;
524 scp->nsp_srtt = NSP_INITIAL_SRTT;
525 scp->nsp_rttvar = NSP_INITIAL_RTTVAR;
526 scp->nsp_rxtshift = 0;
528 skb_queue_head_init(&scp->data_xmit_queue);
529 skb_queue_head_init(&scp->other_xmit_queue);
530 skb_queue_head_init(&scp->other_receive_queue);
532 scp->persist = 0;
533 scp->persist_fxn = NULL;
534 scp->keepalive = 10 * HZ;
535 scp->keepalive_fxn = dn_keepalive;
537 init_timer(&scp->delack_timer);
538 scp->delack_pending = 0;
539 scp->delack_fxn = dn_nsp_delayed_ack;
541 dn_start_slow_timer(sk);
542 out:
543 return sk;
547 * Keepalive timer.
548 * FIXME: Should respond to SO_KEEPALIVE etc.
550 static void dn_keepalive(struct sock *sk)
552 struct dn_scp *scp = DN_SK(sk);
555 * By checking the other_data transmit queue is empty
556 * we are double checking that we are not sending too
557 * many of these keepalive frames.
559 if (skb_queue_empty(&scp->other_xmit_queue))
560 dn_nsp_send_link(sk, DN_NOCHANGE, 0);
565 * Timer for shutdown/destroyed sockets.
566 * When socket is dead & no packets have been sent for a
567 * certain amount of time, they are removed by this
568 * routine. Also takes care of sending out DI & DC
569 * frames at correct times.
571 int dn_destroy_timer(struct sock *sk)
573 struct dn_scp *scp = DN_SK(sk);
575 scp->persist = dn_nsp_persist(sk);
577 switch(scp->state) {
578 case DN_DI:
579 dn_nsp_send_disc(sk, NSP_DISCINIT, 0, GFP_ATOMIC);
580 if (scp->nsp_rxtshift >= decnet_di_count)
581 scp->state = DN_CN;
582 return 0;
584 case DN_DR:
585 dn_nsp_send_disc(sk, NSP_DISCINIT, 0, GFP_ATOMIC);
586 if (scp->nsp_rxtshift >= decnet_dr_count)
587 scp->state = DN_DRC;
588 return 0;
590 case DN_DN:
591 if (scp->nsp_rxtshift < decnet_dn_count) {
592 /* printk(KERN_DEBUG "dn_destroy_timer: DN\n"); */
593 dn_nsp_send_disc(sk, NSP_DISCCONF, NSP_REASON_DC, GFP_ATOMIC);
594 return 0;
598 scp->persist = (HZ * decnet_time_wait);
600 if (sk->sk_socket)
601 return 0;
603 if ((jiffies - scp->stamp) >= (HZ * decnet_time_wait)) {
604 dn_unhash_sock(sk);
605 sock_put(sk);
606 return 1;
609 return 0;
612 static void dn_destroy_sock(struct sock *sk)
614 struct dn_scp *scp = DN_SK(sk);
616 scp->nsp_rxtshift = 0; /* reset back off */
618 if (sk->sk_socket) {
619 if (sk->sk_socket->state != SS_UNCONNECTED)
620 sk->sk_socket->state = SS_DISCONNECTING;
623 sk->sk_state = TCP_CLOSE;
625 switch(scp->state) {
626 case DN_DN:
627 dn_nsp_send_disc(sk, NSP_DISCCONF, NSP_REASON_DC,
628 sk->sk_allocation);
629 scp->persist_fxn = dn_destroy_timer;
630 scp->persist = dn_nsp_persist(sk);
631 break;
632 case DN_CR:
633 scp->state = DN_DR;
634 goto disc_reject;
635 case DN_RUN:
636 scp->state = DN_DI;
637 case DN_DI:
638 case DN_DR:
639 disc_reject:
640 dn_nsp_send_disc(sk, NSP_DISCINIT, 0, sk->sk_allocation);
641 case DN_NC:
642 case DN_NR:
643 case DN_RJ:
644 case DN_DIC:
645 case DN_CN:
646 case DN_DRC:
647 case DN_CI:
648 case DN_CD:
649 scp->persist_fxn = dn_destroy_timer;
650 scp->persist = dn_nsp_persist(sk);
651 break;
652 default:
653 printk(KERN_DEBUG "DECnet: dn_destroy_sock passed socket in invalid state\n");
654 case DN_O:
655 dn_stop_slow_timer(sk);
657 dn_unhash_sock_bh(sk);
658 sock_put(sk);
660 break;
664 char *dn_addr2asc(__u16 addr, char *buf)
666 unsigned short node, area;
668 node = addr & 0x03ff;
669 area = addr >> 10;
670 sprintf(buf, "%hd.%hd", area, node);
672 return buf;
677 static int dn_create(struct socket *sock, int protocol)
679 struct sock *sk;
681 switch(sock->type) {
682 case SOCK_SEQPACKET:
683 if (protocol != DNPROTO_NSP)
684 return -EPROTONOSUPPORT;
685 break;
686 case SOCK_STREAM:
687 break;
688 default:
689 return -ESOCKTNOSUPPORT;
693 if ((sk = dn_alloc_sock(sock, GFP_KERNEL)) == NULL)
694 return -ENOBUFS;
696 sk->sk_protocol = protocol;
698 return 0;
702 static int
703 dn_release(struct socket *sock)
705 struct sock *sk = sock->sk;
707 if (sk) {
708 sock_orphan(sk);
709 sock_hold(sk);
710 lock_sock(sk);
711 dn_destroy_sock(sk);
712 release_sock(sk);
713 sock_put(sk);
716 return 0;
719 static int dn_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
721 struct sock *sk = sock->sk;
722 struct dn_scp *scp = DN_SK(sk);
723 struct sockaddr_dn *saddr = (struct sockaddr_dn *)uaddr;
724 struct net_device *dev, *ldev;
725 int rv;
727 if (addr_len != sizeof(struct sockaddr_dn))
728 return -EINVAL;
730 if (saddr->sdn_family != AF_DECnet)
731 return -EINVAL;
733 if (dn_ntohs(saddr->sdn_nodeaddrl) && (dn_ntohs(saddr->sdn_nodeaddrl) != 2))
734 return -EINVAL;
736 if (dn_ntohs(saddr->sdn_objnamel) > DN_MAXOBJL)
737 return -EINVAL;
739 if (saddr->sdn_flags & ~SDF_WILD)
740 return -EINVAL;
742 if (!capable(CAP_NET_BIND_SERVICE) && (saddr->sdn_objnum ||
743 (saddr->sdn_flags & SDF_WILD)))
744 return -EACCES;
746 if (!(saddr->sdn_flags & SDF_WILD)) {
747 if (dn_ntohs(saddr->sdn_nodeaddrl)) {
748 read_lock(&dev_base_lock);
749 ldev = NULL;
750 for_each_netdev(dev) {
751 if (!dev->dn_ptr)
752 continue;
753 if (dn_dev_islocal(dev, dn_saddr2dn(saddr))) {
754 ldev = dev;
755 break;
758 read_unlock(&dev_base_lock);
759 if (ldev == NULL)
760 return -EADDRNOTAVAIL;
764 rv = -EINVAL;
765 lock_sock(sk);
766 if (sock_flag(sk, SOCK_ZAPPED)) {
767 memcpy(&scp->addr, saddr, addr_len);
768 sock_reset_flag(sk, SOCK_ZAPPED);
770 rv = dn_hash_sock(sk);
771 if (rv)
772 sock_set_flag(sk, SOCK_ZAPPED);
774 release_sock(sk);
776 return rv;
780 static int dn_auto_bind(struct socket *sock)
782 struct sock *sk = sock->sk;
783 struct dn_scp *scp = DN_SK(sk);
784 int rv;
786 sock_reset_flag(sk, SOCK_ZAPPED);
788 scp->addr.sdn_flags = 0;
789 scp->addr.sdn_objnum = 0;
792 * This stuff is to keep compatibility with Eduardo's
793 * patch. I hope I can dispense with it shortly...
795 if ((scp->accessdata.acc_accl != 0) &&
796 (scp->accessdata.acc_accl <= 12)) {
798 scp->addr.sdn_objnamel = dn_htons(scp->accessdata.acc_accl);
799 memcpy(scp->addr.sdn_objname, scp->accessdata.acc_acc, dn_ntohs(scp->addr.sdn_objnamel));
801 scp->accessdata.acc_accl = 0;
802 memset(scp->accessdata.acc_acc, 0, 40);
804 /* End of compatibility stuff */
806 scp->addr.sdn_add.a_len = dn_htons(2);
807 rv = dn_dev_bind_default((__le16 *)scp->addr.sdn_add.a_addr);
808 if (rv == 0) {
809 rv = dn_hash_sock(sk);
810 if (rv)
811 sock_set_flag(sk, SOCK_ZAPPED);
814 return rv;
817 static int dn_confirm_accept(struct sock *sk, long *timeo, gfp_t allocation)
819 struct dn_scp *scp = DN_SK(sk);
820 DEFINE_WAIT(wait);
821 int err;
823 if (scp->state != DN_CR)
824 return -EINVAL;
826 scp->state = DN_CC;
827 scp->segsize_loc = dst_metric(__sk_dst_get(sk), RTAX_ADVMSS);
828 dn_send_conn_conf(sk, allocation);
830 prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
831 for(;;) {
832 release_sock(sk);
833 if (scp->state == DN_CC)
834 *timeo = schedule_timeout(*timeo);
835 lock_sock(sk);
836 err = 0;
837 if (scp->state == DN_RUN)
838 break;
839 err = sock_error(sk);
840 if (err)
841 break;
842 err = sock_intr_errno(*timeo);
843 if (signal_pending(current))
844 break;
845 err = -EAGAIN;
846 if (!*timeo)
847 break;
848 prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
850 finish_wait(sk->sk_sleep, &wait);
851 if (err == 0) {
852 sk->sk_socket->state = SS_CONNECTED;
853 } else if (scp->state != DN_CC) {
854 sk->sk_socket->state = SS_UNCONNECTED;
856 return err;
859 static int dn_wait_run(struct sock *sk, long *timeo)
861 struct dn_scp *scp = DN_SK(sk);
862 DEFINE_WAIT(wait);
863 int err = 0;
865 if (scp->state == DN_RUN)
866 goto out;
868 if (!*timeo)
869 return -EALREADY;
871 prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
872 for(;;) {
873 release_sock(sk);
874 if (scp->state == DN_CI || scp->state == DN_CC)
875 *timeo = schedule_timeout(*timeo);
876 lock_sock(sk);
877 err = 0;
878 if (scp->state == DN_RUN)
879 break;
880 err = sock_error(sk);
881 if (err)
882 break;
883 err = sock_intr_errno(*timeo);
884 if (signal_pending(current))
885 break;
886 err = -ETIMEDOUT;
887 if (!*timeo)
888 break;
889 prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
891 finish_wait(sk->sk_sleep, &wait);
892 out:
893 if (err == 0) {
894 sk->sk_socket->state = SS_CONNECTED;
895 } else if (scp->state != DN_CI && scp->state != DN_CC) {
896 sk->sk_socket->state = SS_UNCONNECTED;
898 return err;
901 static int __dn_connect(struct sock *sk, struct sockaddr_dn *addr, int addrlen, long *timeo, int flags)
903 struct socket *sock = sk->sk_socket;
904 struct dn_scp *scp = DN_SK(sk);
905 int err = -EISCONN;
906 struct flowi fl;
908 if (sock->state == SS_CONNECTED)
909 goto out;
911 if (sock->state == SS_CONNECTING) {
912 err = 0;
913 if (scp->state == DN_RUN) {
914 sock->state = SS_CONNECTED;
915 goto out;
917 err = -ECONNREFUSED;
918 if (scp->state != DN_CI && scp->state != DN_CC) {
919 sock->state = SS_UNCONNECTED;
920 goto out;
922 return dn_wait_run(sk, timeo);
925 err = -EINVAL;
926 if (scp->state != DN_O)
927 goto out;
929 if (addr == NULL || addrlen != sizeof(struct sockaddr_dn))
930 goto out;
931 if (addr->sdn_family != AF_DECnet)
932 goto out;
933 if (addr->sdn_flags & SDF_WILD)
934 goto out;
936 if (sock_flag(sk, SOCK_ZAPPED)) {
937 err = dn_auto_bind(sk->sk_socket);
938 if (err)
939 goto out;
942 memcpy(&scp->peer, addr, sizeof(struct sockaddr_dn));
944 err = -EHOSTUNREACH;
945 memset(&fl, 0, sizeof(fl));
946 fl.oif = sk->sk_bound_dev_if;
947 fl.fld_dst = dn_saddr2dn(&scp->peer);
948 fl.fld_src = dn_saddr2dn(&scp->addr);
949 dn_sk_ports_copy(&fl, scp);
950 fl.proto = DNPROTO_NSP;
951 if (dn_route_output_sock(&sk->sk_dst_cache, &fl, sk, flags) < 0)
952 goto out;
953 sk->sk_route_caps = sk->sk_dst_cache->dev->features;
954 sock->state = SS_CONNECTING;
955 scp->state = DN_CI;
956 scp->segsize_loc = dst_metric(sk->sk_dst_cache, RTAX_ADVMSS);
958 dn_nsp_send_conninit(sk, NSP_CI);
959 err = -EINPROGRESS;
960 if (*timeo) {
961 err = dn_wait_run(sk, timeo);
963 out:
964 return err;
967 static int dn_connect(struct socket *sock, struct sockaddr *uaddr, int addrlen, int flags)
969 struct sockaddr_dn *addr = (struct sockaddr_dn *)uaddr;
970 struct sock *sk = sock->sk;
971 int err;
972 long timeo = sock_sndtimeo(sk, flags & O_NONBLOCK);
974 lock_sock(sk);
975 err = __dn_connect(sk, addr, addrlen, &timeo, 0);
976 release_sock(sk);
978 return err;
981 static inline int dn_check_state(struct sock *sk, struct sockaddr_dn *addr, int addrlen, long *timeo, int flags)
983 struct dn_scp *scp = DN_SK(sk);
985 switch(scp->state) {
986 case DN_RUN:
987 return 0;
988 case DN_CR:
989 return dn_confirm_accept(sk, timeo, sk->sk_allocation);
990 case DN_CI:
991 case DN_CC:
992 return dn_wait_run(sk, timeo);
993 case DN_O:
994 return __dn_connect(sk, addr, addrlen, timeo, flags);
997 return -EINVAL;
1001 static void dn_access_copy(struct sk_buff *skb, struct accessdata_dn *acc)
1003 unsigned char *ptr = skb->data;
1005 acc->acc_userl = *ptr++;
1006 memcpy(&acc->acc_user, ptr, acc->acc_userl);
1007 ptr += acc->acc_userl;
1009 acc->acc_passl = *ptr++;
1010 memcpy(&acc->acc_pass, ptr, acc->acc_passl);
1011 ptr += acc->acc_passl;
1013 acc->acc_accl = *ptr++;
1014 memcpy(&acc->acc_acc, ptr, acc->acc_accl);
1016 skb_pull(skb, acc->acc_accl + acc->acc_passl + acc->acc_userl + 3);
1020 static void dn_user_copy(struct sk_buff *skb, struct optdata_dn *opt)
1022 unsigned char *ptr = skb->data;
1023 u16 len = *ptr++; /* yes, it's 8bit on the wire */
1025 BUG_ON(len > 16); /* we've checked the contents earlier */
1026 opt->opt_optl = dn_htons(len);
1027 opt->opt_status = 0;
1028 memcpy(opt->opt_data, ptr, len);
1029 skb_pull(skb, len + 1);
1032 static struct sk_buff *dn_wait_for_connect(struct sock *sk, long *timeo)
1034 DEFINE_WAIT(wait);
1035 struct sk_buff *skb = NULL;
1036 int err = 0;
1038 prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
1039 for(;;) {
1040 release_sock(sk);
1041 skb = skb_dequeue(&sk->sk_receive_queue);
1042 if (skb == NULL) {
1043 *timeo = schedule_timeout(*timeo);
1044 skb = skb_dequeue(&sk->sk_receive_queue);
1046 lock_sock(sk);
1047 if (skb != NULL)
1048 break;
1049 err = -EINVAL;
1050 if (sk->sk_state != TCP_LISTEN)
1051 break;
1052 err = sock_intr_errno(*timeo);
1053 if (signal_pending(current))
1054 break;
1055 err = -EAGAIN;
1056 if (!*timeo)
1057 break;
1058 prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
1060 finish_wait(sk->sk_sleep, &wait);
1062 return skb == NULL ? ERR_PTR(err) : skb;
1065 static int dn_accept(struct socket *sock, struct socket *newsock, int flags)
1067 struct sock *sk = sock->sk, *newsk;
1068 struct sk_buff *skb = NULL;
1069 struct dn_skb_cb *cb;
1070 unsigned char menuver;
1071 int err = 0;
1072 unsigned char type;
1073 long timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK);
1075 lock_sock(sk);
1077 if (sk->sk_state != TCP_LISTEN || DN_SK(sk)->state != DN_O) {
1078 release_sock(sk);
1079 return -EINVAL;
1082 skb = skb_dequeue(&sk->sk_receive_queue);
1083 if (skb == NULL) {
1084 skb = dn_wait_for_connect(sk, &timeo);
1085 if (IS_ERR(skb)) {
1086 release_sock(sk);
1087 return PTR_ERR(skb);
1091 cb = DN_SKB_CB(skb);
1092 sk->sk_ack_backlog--;
1093 newsk = dn_alloc_sock(newsock, sk->sk_allocation);
1094 if (newsk == NULL) {
1095 release_sock(sk);
1096 kfree_skb(skb);
1097 return -ENOBUFS;
1099 release_sock(sk);
1101 dst_release(xchg(&newsk->sk_dst_cache, skb->dst));
1102 skb->dst = NULL;
1104 DN_SK(newsk)->state = DN_CR;
1105 DN_SK(newsk)->addrrem = cb->src_port;
1106 DN_SK(newsk)->services_rem = cb->services;
1107 DN_SK(newsk)->info_rem = cb->info;
1108 DN_SK(newsk)->segsize_rem = cb->segsize;
1109 DN_SK(newsk)->accept_mode = DN_SK(sk)->accept_mode;
1111 if (DN_SK(newsk)->segsize_rem < 230)
1112 DN_SK(newsk)->segsize_rem = 230;
1114 if ((DN_SK(newsk)->services_rem & NSP_FC_MASK) == NSP_FC_NONE)
1115 DN_SK(newsk)->max_window = decnet_no_fc_max_cwnd;
1117 newsk->sk_state = TCP_LISTEN;
1118 memcpy(&(DN_SK(newsk)->addr), &(DN_SK(sk)->addr), sizeof(struct sockaddr_dn));
1121 * If we are listening on a wild socket, we don't want
1122 * the newly created socket on the wrong hash queue.
1124 DN_SK(newsk)->addr.sdn_flags &= ~SDF_WILD;
1126 skb_pull(skb, dn_username2sockaddr(skb->data, skb->len, &(DN_SK(newsk)->addr), &type));
1127 skb_pull(skb, dn_username2sockaddr(skb->data, skb->len, &(DN_SK(newsk)->peer), &type));
1128 *(__le16 *)(DN_SK(newsk)->peer.sdn_add.a_addr) = cb->src;
1129 *(__le16 *)(DN_SK(newsk)->addr.sdn_add.a_addr) = cb->dst;
1131 menuver = *skb->data;
1132 skb_pull(skb, 1);
1134 if (menuver & DN_MENUVER_ACC)
1135 dn_access_copy(skb, &(DN_SK(newsk)->accessdata));
1137 if (menuver & DN_MENUVER_USR)
1138 dn_user_copy(skb, &(DN_SK(newsk)->conndata_in));
1140 if (menuver & DN_MENUVER_PRX)
1141 DN_SK(newsk)->peer.sdn_flags |= SDF_PROXY;
1143 if (menuver & DN_MENUVER_UIC)
1144 DN_SK(newsk)->peer.sdn_flags |= SDF_UICPROXY;
1146 kfree_skb(skb);
1148 memcpy(&(DN_SK(newsk)->conndata_out), &(DN_SK(sk)->conndata_out),
1149 sizeof(struct optdata_dn));
1150 memcpy(&(DN_SK(newsk)->discdata_out), &(DN_SK(sk)->discdata_out),
1151 sizeof(struct optdata_dn));
1153 lock_sock(newsk);
1154 err = dn_hash_sock(newsk);
1155 if (err == 0) {
1156 sock_reset_flag(newsk, SOCK_ZAPPED);
1157 dn_send_conn_ack(newsk);
1160 * Here we use sk->sk_allocation since although the conn conf is
1161 * for the newsk, the context is the old socket.
1163 if (DN_SK(newsk)->accept_mode == ACC_IMMED)
1164 err = dn_confirm_accept(newsk, &timeo,
1165 sk->sk_allocation);
1167 release_sock(newsk);
1168 return err;
1172 static int dn_getname(struct socket *sock, struct sockaddr *uaddr,int *uaddr_len,int peer)
1174 struct sockaddr_dn *sa = (struct sockaddr_dn *)uaddr;
1175 struct sock *sk = sock->sk;
1176 struct dn_scp *scp = DN_SK(sk);
1178 *uaddr_len = sizeof(struct sockaddr_dn);
1180 lock_sock(sk);
1182 if (peer) {
1183 if ((sock->state != SS_CONNECTED &&
1184 sock->state != SS_CONNECTING) &&
1185 scp->accept_mode == ACC_IMMED) {
1186 release_sock(sk);
1187 return -ENOTCONN;
1190 memcpy(sa, &scp->peer, sizeof(struct sockaddr_dn));
1191 } else {
1192 memcpy(sa, &scp->addr, sizeof(struct sockaddr_dn));
1195 release_sock(sk);
1197 return 0;
1201 static unsigned int dn_poll(struct file *file, struct socket *sock, poll_table *wait)
1203 struct sock *sk = sock->sk;
1204 struct dn_scp *scp = DN_SK(sk);
1205 int mask = datagram_poll(file, sock, wait);
1207 if (!skb_queue_empty(&scp->other_receive_queue))
1208 mask |= POLLRDBAND;
1210 return mask;
1213 static int dn_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1215 struct sock *sk = sock->sk;
1216 struct dn_scp *scp = DN_SK(sk);
1217 int err = -EOPNOTSUPP;
1218 long amount = 0;
1219 struct sk_buff *skb;
1220 int val;
1222 switch(cmd)
1224 case SIOCGIFADDR:
1225 case SIOCSIFADDR:
1226 return dn_dev_ioctl(cmd, (void __user *)arg);
1228 case SIOCATMARK:
1229 lock_sock(sk);
1230 val = !skb_queue_empty(&scp->other_receive_queue);
1231 if (scp->state != DN_RUN)
1232 val = -ENOTCONN;
1233 release_sock(sk);
1234 return val;
1236 case TIOCOUTQ:
1237 amount = sk->sk_sndbuf - atomic_read(&sk->sk_wmem_alloc);
1238 if (amount < 0)
1239 amount = 0;
1240 err = put_user(amount, (int __user *)arg);
1241 break;
1243 case TIOCINQ:
1244 lock_sock(sk);
1245 if ((skb = skb_peek(&scp->other_receive_queue)) != NULL) {
1246 amount = skb->len;
1247 } else {
1248 struct sk_buff *skb = sk->sk_receive_queue.next;
1249 for(;;) {
1250 if (skb ==
1251 (struct sk_buff *)&sk->sk_receive_queue)
1252 break;
1253 amount += skb->len;
1254 skb = skb->next;
1257 release_sock(sk);
1258 err = put_user(amount, (int __user *)arg);
1259 break;
1261 default:
1262 err = -ENOIOCTLCMD;
1263 break;
1266 return err;
1269 static int dn_listen(struct socket *sock, int backlog)
1271 struct sock *sk = sock->sk;
1272 int err = -EINVAL;
1274 lock_sock(sk);
1276 if (sock_flag(sk, SOCK_ZAPPED))
1277 goto out;
1279 if ((DN_SK(sk)->state != DN_O) || (sk->sk_state == TCP_LISTEN))
1280 goto out;
1282 sk->sk_max_ack_backlog = backlog;
1283 sk->sk_ack_backlog = 0;
1284 sk->sk_state = TCP_LISTEN;
1285 err = 0;
1286 dn_rehash_sock(sk);
1288 out:
1289 release_sock(sk);
1291 return err;
1295 static int dn_shutdown(struct socket *sock, int how)
1297 struct sock *sk = sock->sk;
1298 struct dn_scp *scp = DN_SK(sk);
1299 int err = -ENOTCONN;
1301 lock_sock(sk);
1303 if (sock->state == SS_UNCONNECTED)
1304 goto out;
1306 err = 0;
1307 if (sock->state == SS_DISCONNECTING)
1308 goto out;
1310 err = -EINVAL;
1311 if (scp->state == DN_O)
1312 goto out;
1314 if (how != SHUTDOWN_MASK)
1315 goto out;
1317 sk->sk_shutdown = how;
1318 dn_destroy_sock(sk);
1319 err = 0;
1321 out:
1322 release_sock(sk);
1324 return err;
1327 static int dn_setsockopt(struct socket *sock, int level, int optname, char __user *optval, int optlen)
1329 struct sock *sk = sock->sk;
1330 int err;
1332 lock_sock(sk);
1333 err = __dn_setsockopt(sock, level, optname, optval, optlen, 0);
1334 release_sock(sk);
1336 return err;
1339 static int __dn_setsockopt(struct socket *sock, int level,int optname, char __user *optval, int optlen, int flags)
1341 struct sock *sk = sock->sk;
1342 struct dn_scp *scp = DN_SK(sk);
1343 long timeo;
1344 union {
1345 struct optdata_dn opt;
1346 struct accessdata_dn acc;
1347 int mode;
1348 unsigned long win;
1349 int val;
1350 unsigned char services;
1351 unsigned char info;
1352 } u;
1353 int err;
1355 if (optlen && !optval)
1356 return -EINVAL;
1358 if (optlen > sizeof(u))
1359 return -EINVAL;
1361 if (copy_from_user(&u, optval, optlen))
1362 return -EFAULT;
1364 switch(optname) {
1365 case DSO_CONDATA:
1366 if (sock->state == SS_CONNECTED)
1367 return -EISCONN;
1368 if ((scp->state != DN_O) && (scp->state != DN_CR))
1369 return -EINVAL;
1371 if (optlen != sizeof(struct optdata_dn))
1372 return -EINVAL;
1374 if (dn_ntohs(u.opt.opt_optl) > 16)
1375 return -EINVAL;
1377 memcpy(&scp->conndata_out, &u.opt, optlen);
1378 break;
1380 case DSO_DISDATA:
1381 if (sock->state != SS_CONNECTED && scp->accept_mode == ACC_IMMED)
1382 return -ENOTCONN;
1384 if (optlen != sizeof(struct optdata_dn))
1385 return -EINVAL;
1387 if (dn_ntohs(u.opt.opt_optl) > 16)
1388 return -EINVAL;
1390 memcpy(&scp->discdata_out, &u.opt, optlen);
1391 break;
1393 case DSO_CONACCESS:
1394 if (sock->state == SS_CONNECTED)
1395 return -EISCONN;
1396 if (scp->state != DN_O)
1397 return -EINVAL;
1399 if (optlen != sizeof(struct accessdata_dn))
1400 return -EINVAL;
1402 if ((u.acc.acc_accl > DN_MAXACCL) ||
1403 (u.acc.acc_passl > DN_MAXACCL) ||
1404 (u.acc.acc_userl > DN_MAXACCL))
1405 return -EINVAL;
1407 memcpy(&scp->accessdata, &u.acc, optlen);
1408 break;
1410 case DSO_ACCEPTMODE:
1411 if (sock->state == SS_CONNECTED)
1412 return -EISCONN;
1413 if (scp->state != DN_O)
1414 return -EINVAL;
1416 if (optlen != sizeof(int))
1417 return -EINVAL;
1419 if ((u.mode != ACC_IMMED) && (u.mode != ACC_DEFER))
1420 return -EINVAL;
1422 scp->accept_mode = (unsigned char)u.mode;
1423 break;
1425 case DSO_CONACCEPT:
1427 if (scp->state != DN_CR)
1428 return -EINVAL;
1429 timeo = sock_rcvtimeo(sk, 0);
1430 err = dn_confirm_accept(sk, &timeo, sk->sk_allocation);
1431 return err;
1433 case DSO_CONREJECT:
1435 if (scp->state != DN_CR)
1436 return -EINVAL;
1438 scp->state = DN_DR;
1439 sk->sk_shutdown = SHUTDOWN_MASK;
1440 dn_nsp_send_disc(sk, 0x38, 0, sk->sk_allocation);
1441 break;
1443 default:
1444 #ifdef CONFIG_NETFILTER
1445 return nf_setsockopt(sk, PF_DECnet, optname, optval, optlen);
1446 #endif
1447 case DSO_LINKINFO:
1448 case DSO_STREAM:
1449 case DSO_SEQPACKET:
1450 return -ENOPROTOOPT;
1452 case DSO_MAXWINDOW:
1453 if (optlen != sizeof(unsigned long))
1454 return -EINVAL;
1455 if (u.win > NSP_MAX_WINDOW)
1456 u.win = NSP_MAX_WINDOW;
1457 if (u.win == 0)
1458 return -EINVAL;
1459 scp->max_window = u.win;
1460 if (scp->snd_window > u.win)
1461 scp->snd_window = u.win;
1462 break;
1464 case DSO_NODELAY:
1465 if (optlen != sizeof(int))
1466 return -EINVAL;
1467 if (scp->nonagle == 2)
1468 return -EINVAL;
1469 scp->nonagle = (u.val == 0) ? 0 : 1;
1470 /* if (scp->nonagle == 1) { Push pending frames } */
1471 break;
1473 case DSO_CORK:
1474 if (optlen != sizeof(int))
1475 return -EINVAL;
1476 if (scp->nonagle == 1)
1477 return -EINVAL;
1478 scp->nonagle = (u.val == 0) ? 0 : 2;
1479 /* if (scp->nonagle == 0) { Push pending frames } */
1480 break;
1482 case DSO_SERVICES:
1483 if (optlen != sizeof(unsigned char))
1484 return -EINVAL;
1485 if ((u.services & ~NSP_FC_MASK) != 0x01)
1486 return -EINVAL;
1487 if ((u.services & NSP_FC_MASK) == NSP_FC_MASK)
1488 return -EINVAL;
1489 scp->services_loc = u.services;
1490 break;
1492 case DSO_INFO:
1493 if (optlen != sizeof(unsigned char))
1494 return -EINVAL;
1495 if (u.info & 0xfc)
1496 return -EINVAL;
1497 scp->info_loc = u.info;
1498 break;
1501 return 0;
1504 static int dn_getsockopt(struct socket *sock, int level, int optname, char __user *optval, int __user *optlen)
1506 struct sock *sk = sock->sk;
1507 int err;
1509 lock_sock(sk);
1510 err = __dn_getsockopt(sock, level, optname, optval, optlen, 0);
1511 release_sock(sk);
1513 return err;
1516 static int __dn_getsockopt(struct socket *sock, int level,int optname, char __user *optval,int __user *optlen, int flags)
1518 struct sock *sk = sock->sk;
1519 struct dn_scp *scp = DN_SK(sk);
1520 struct linkinfo_dn link;
1521 unsigned int r_len;
1522 void *r_data = NULL;
1523 unsigned int val;
1525 if(get_user(r_len , optlen))
1526 return -EFAULT;
1528 switch(optname) {
1529 case DSO_CONDATA:
1530 if (r_len > sizeof(struct optdata_dn))
1531 r_len = sizeof(struct optdata_dn);
1532 r_data = &scp->conndata_in;
1533 break;
1535 case DSO_DISDATA:
1536 if (r_len > sizeof(struct optdata_dn))
1537 r_len = sizeof(struct optdata_dn);
1538 r_data = &scp->discdata_in;
1539 break;
1541 case DSO_CONACCESS:
1542 if (r_len > sizeof(struct accessdata_dn))
1543 r_len = sizeof(struct accessdata_dn);
1544 r_data = &scp->accessdata;
1545 break;
1547 case DSO_ACCEPTMODE:
1548 if (r_len > sizeof(unsigned char))
1549 r_len = sizeof(unsigned char);
1550 r_data = &scp->accept_mode;
1551 break;
1553 case DSO_LINKINFO:
1554 if (r_len > sizeof(struct linkinfo_dn))
1555 r_len = sizeof(struct linkinfo_dn);
1557 switch(sock->state) {
1558 case SS_CONNECTING:
1559 link.idn_linkstate = LL_CONNECTING;
1560 break;
1561 case SS_DISCONNECTING:
1562 link.idn_linkstate = LL_DISCONNECTING;
1563 break;
1564 case SS_CONNECTED:
1565 link.idn_linkstate = LL_RUNNING;
1566 break;
1567 default:
1568 link.idn_linkstate = LL_INACTIVE;
1571 link.idn_segsize = scp->segsize_rem;
1572 r_data = &link;
1573 break;
1575 default:
1576 #ifdef CONFIG_NETFILTER
1578 int val, len;
1580 if(get_user(len, optlen))
1581 return -EFAULT;
1583 val = nf_getsockopt(sk, PF_DECnet, optname,
1584 optval, &len);
1585 if (val >= 0)
1586 val = put_user(len, optlen);
1587 return val;
1589 #endif
1590 case DSO_STREAM:
1591 case DSO_SEQPACKET:
1592 case DSO_CONACCEPT:
1593 case DSO_CONREJECT:
1594 return -ENOPROTOOPT;
1596 case DSO_MAXWINDOW:
1597 if (r_len > sizeof(unsigned long))
1598 r_len = sizeof(unsigned long);
1599 r_data = &scp->max_window;
1600 break;
1602 case DSO_NODELAY:
1603 if (r_len > sizeof(int))
1604 r_len = sizeof(int);
1605 val = (scp->nonagle == 1);
1606 r_data = &val;
1607 break;
1609 case DSO_CORK:
1610 if (r_len > sizeof(int))
1611 r_len = sizeof(int);
1612 val = (scp->nonagle == 2);
1613 r_data = &val;
1614 break;
1616 case DSO_SERVICES:
1617 if (r_len > sizeof(unsigned char))
1618 r_len = sizeof(unsigned char);
1619 r_data = &scp->services_rem;
1620 break;
1622 case DSO_INFO:
1623 if (r_len > sizeof(unsigned char))
1624 r_len = sizeof(unsigned char);
1625 r_data = &scp->info_rem;
1626 break;
1629 if (r_data) {
1630 if (copy_to_user(optval, r_data, r_len))
1631 return -EFAULT;
1632 if (put_user(r_len, optlen))
1633 return -EFAULT;
1636 return 0;
1640 static int dn_data_ready(struct sock *sk, struct sk_buff_head *q, int flags, int target)
1642 struct sk_buff *skb = q->next;
1643 int len = 0;
1645 if (flags & MSG_OOB)
1646 return !skb_queue_empty(q) ? 1 : 0;
1648 while(skb != (struct sk_buff *)q) {
1649 struct dn_skb_cb *cb = DN_SKB_CB(skb);
1650 len += skb->len;
1652 if (cb->nsp_flags & 0x40) {
1653 /* SOCK_SEQPACKET reads to EOM */
1654 if (sk->sk_type == SOCK_SEQPACKET)
1655 return 1;
1656 /* so does SOCK_STREAM unless WAITALL is specified */
1657 if (!(flags & MSG_WAITALL))
1658 return 1;
1661 /* minimum data length for read exceeded */
1662 if (len >= target)
1663 return 1;
1665 skb = skb->next;
1668 return 0;
1672 static int dn_recvmsg(struct kiocb *iocb, struct socket *sock,
1673 struct msghdr *msg, size_t size, int flags)
1675 struct sock *sk = sock->sk;
1676 struct dn_scp *scp = DN_SK(sk);
1677 struct sk_buff_head *queue = &sk->sk_receive_queue;
1678 size_t target = size > 1 ? 1 : 0;
1679 size_t copied = 0;
1680 int rv = 0;
1681 struct sk_buff *skb, *nskb;
1682 struct dn_skb_cb *cb = NULL;
1683 unsigned char eor = 0;
1684 long timeo = sock_rcvtimeo(sk, flags & MSG_DONTWAIT);
1686 lock_sock(sk);
1688 if (sock_flag(sk, SOCK_ZAPPED)) {
1689 rv = -EADDRNOTAVAIL;
1690 goto out;
1693 if (sk->sk_shutdown & RCV_SHUTDOWN) {
1694 rv = 0;
1695 goto out;
1698 rv = dn_check_state(sk, NULL, 0, &timeo, flags);
1699 if (rv)
1700 goto out;
1702 if (flags & ~(MSG_CMSG_COMPAT|MSG_PEEK|MSG_OOB|MSG_WAITALL|MSG_DONTWAIT|MSG_NOSIGNAL)) {
1703 rv = -EOPNOTSUPP;
1704 goto out;
1707 if (flags & MSG_OOB)
1708 queue = &scp->other_receive_queue;
1710 if (flags & MSG_WAITALL)
1711 target = size;
1715 * See if there is data ready to read, sleep if there isn't
1717 for(;;) {
1718 if (sk->sk_err)
1719 goto out;
1721 if (!skb_queue_empty(&scp->other_receive_queue)) {
1722 if (!(flags & MSG_OOB)) {
1723 msg->msg_flags |= MSG_OOB;
1724 if (!scp->other_report) {
1725 scp->other_report = 1;
1726 goto out;
1731 if (scp->state != DN_RUN)
1732 goto out;
1734 if (signal_pending(current)) {
1735 rv = sock_intr_errno(timeo);
1736 goto out;
1739 if (dn_data_ready(sk, queue, flags, target))
1740 break;
1742 if (flags & MSG_DONTWAIT) {
1743 rv = -EWOULDBLOCK;
1744 goto out;
1747 set_bit(SOCK_ASYNC_WAITDATA, &sock->flags);
1748 SOCK_SLEEP_PRE(sk)
1750 if (!dn_data_ready(sk, queue, flags, target))
1751 schedule();
1753 SOCK_SLEEP_POST(sk)
1754 clear_bit(SOCK_ASYNC_WAITDATA, &sock->flags);
1757 for(skb = queue->next; skb != (struct sk_buff *)queue; skb = nskb) {
1758 unsigned int chunk = skb->len;
1759 cb = DN_SKB_CB(skb);
1761 if ((chunk + copied) > size)
1762 chunk = size - copied;
1764 if (memcpy_toiovec(msg->msg_iov, skb->data, chunk)) {
1765 rv = -EFAULT;
1766 break;
1768 copied += chunk;
1770 if (!(flags & MSG_PEEK))
1771 skb_pull(skb, chunk);
1773 eor = cb->nsp_flags & 0x40;
1774 nskb = skb->next;
1776 if (skb->len == 0) {
1777 skb_unlink(skb, queue);
1778 kfree_skb(skb);
1780 * N.B. Don't refer to skb or cb after this point
1781 * in loop.
1783 if ((scp->flowloc_sw == DN_DONTSEND) && !dn_congested(sk)) {
1784 scp->flowloc_sw = DN_SEND;
1785 dn_nsp_send_link(sk, DN_SEND, 0);
1789 if (eor) {
1790 if (sk->sk_type == SOCK_SEQPACKET)
1791 break;
1792 if (!(flags & MSG_WAITALL))
1793 break;
1796 if (flags & MSG_OOB)
1797 break;
1799 if (copied >= target)
1800 break;
1803 rv = copied;
1806 if (eor && (sk->sk_type == SOCK_SEQPACKET))
1807 msg->msg_flags |= MSG_EOR;
1809 out:
1810 if (rv == 0)
1811 rv = (flags & MSG_PEEK) ? -sk->sk_err : sock_error(sk);
1813 if ((rv >= 0) && msg->msg_name) {
1814 memcpy(msg->msg_name, &scp->peer, sizeof(struct sockaddr_dn));
1815 msg->msg_namelen = sizeof(struct sockaddr_dn);
1818 release_sock(sk);
1820 return rv;
1824 static inline int dn_queue_too_long(struct dn_scp *scp, struct sk_buff_head *queue, int flags)
1826 unsigned char fctype = scp->services_rem & NSP_FC_MASK;
1827 if (skb_queue_len(queue) >= scp->snd_window)
1828 return 1;
1829 if (fctype != NSP_FC_NONE) {
1830 if (flags & MSG_OOB) {
1831 if (scp->flowrem_oth == 0)
1832 return 1;
1833 } else {
1834 if (scp->flowrem_dat == 0)
1835 return 1;
1838 return 0;
1842 * The DECnet spec requires that the "routing layer" accepts packets which
1843 * are at least 230 bytes in size. This excludes any headers which the NSP
1844 * layer might add, so we always assume that we'll be using the maximal
1845 * length header on data packets. The variation in length is due to the
1846 * inclusion (or not) of the two 16 bit acknowledgement fields so it doesn't
1847 * make much practical difference.
1849 unsigned dn_mss_from_pmtu(struct net_device *dev, int mtu)
1851 unsigned mss = 230 - DN_MAX_NSP_DATA_HEADER;
1852 if (dev) {
1853 struct dn_dev *dn_db = dev->dn_ptr;
1854 mtu -= LL_RESERVED_SPACE(dev);
1855 if (dn_db->use_long)
1856 mtu -= 21;
1857 else
1858 mtu -= 6;
1859 mtu -= DN_MAX_NSP_DATA_HEADER;
1860 } else {
1862 * 21 = long header, 16 = guess at MAC header length
1864 mtu -= (21 + DN_MAX_NSP_DATA_HEADER + 16);
1866 if (mtu > mss)
1867 mss = mtu;
1868 return mss;
1871 static inline unsigned int dn_current_mss(struct sock *sk, int flags)
1873 struct dst_entry *dst = __sk_dst_get(sk);
1874 struct dn_scp *scp = DN_SK(sk);
1875 int mss_now = min_t(int, scp->segsize_loc, scp->segsize_rem);
1877 /* Other data messages are limited to 16 bytes per packet */
1878 if (flags & MSG_OOB)
1879 return 16;
1881 /* This works out the maximum size of segment we can send out */
1882 if (dst) {
1883 u32 mtu = dst_mtu(dst);
1884 mss_now = min_t(int, dn_mss_from_pmtu(dst->dev, mtu), mss_now);
1887 return mss_now;
1891 * N.B. We get the timeout wrong here, but then we always did get it
1892 * wrong before and this is another step along the road to correcting
1893 * it. It ought to get updated each time we pass through the routine,
1894 * but in practise it probably doesn't matter too much for now.
1896 static inline struct sk_buff *dn_alloc_send_pskb(struct sock *sk,
1897 unsigned long datalen, int noblock,
1898 int *errcode)
1900 struct sk_buff *skb = sock_alloc_send_skb(sk, datalen,
1901 noblock, errcode);
1902 if (skb) {
1903 skb->protocol = __constant_htons(ETH_P_DNA_RT);
1904 skb->pkt_type = PACKET_OUTGOING;
1906 return skb;
1909 static int dn_sendmsg(struct kiocb *iocb, struct socket *sock,
1910 struct msghdr *msg, size_t size)
1912 struct sock *sk = sock->sk;
1913 struct dn_scp *scp = DN_SK(sk);
1914 size_t mss;
1915 struct sk_buff_head *queue = &scp->data_xmit_queue;
1916 int flags = msg->msg_flags;
1917 int err = 0;
1918 size_t sent = 0;
1919 int addr_len = msg->msg_namelen;
1920 struct sockaddr_dn *addr = (struct sockaddr_dn *)msg->msg_name;
1921 struct sk_buff *skb = NULL;
1922 struct dn_skb_cb *cb;
1923 size_t len;
1924 unsigned char fctype;
1925 long timeo;
1927 if (flags & ~(MSG_TRYHARD|MSG_OOB|MSG_DONTWAIT|MSG_EOR|MSG_NOSIGNAL|MSG_MORE|MSG_CMSG_COMPAT))
1928 return -EOPNOTSUPP;
1930 if (addr_len && (addr_len != sizeof(struct sockaddr_dn)))
1931 return -EINVAL;
1933 lock_sock(sk);
1934 timeo = sock_sndtimeo(sk, flags & MSG_DONTWAIT);
1936 * The only difference between stream sockets and sequenced packet
1937 * sockets is that the stream sockets always behave as if MSG_EOR
1938 * has been set.
1940 if (sock->type == SOCK_STREAM) {
1941 if (flags & MSG_EOR) {
1942 err = -EINVAL;
1943 goto out;
1945 flags |= MSG_EOR;
1949 err = dn_check_state(sk, addr, addr_len, &timeo, flags);
1950 if (err)
1951 goto out_err;
1953 if (sk->sk_shutdown & SEND_SHUTDOWN) {
1954 err = -EPIPE;
1955 if (!(flags & MSG_NOSIGNAL))
1956 send_sig(SIGPIPE, current, 0);
1957 goto out_err;
1960 if ((flags & MSG_TRYHARD) && sk->sk_dst_cache)
1961 dst_negative_advice(&sk->sk_dst_cache);
1963 mss = scp->segsize_rem;
1964 fctype = scp->services_rem & NSP_FC_MASK;
1966 mss = dn_current_mss(sk, flags);
1968 if (flags & MSG_OOB) {
1969 queue = &scp->other_xmit_queue;
1970 if (size > mss) {
1971 err = -EMSGSIZE;
1972 goto out;
1976 scp->persist_fxn = dn_nsp_xmit_timeout;
1978 while(sent < size) {
1979 err = sock_error(sk);
1980 if (err)
1981 goto out;
1983 if (signal_pending(current)) {
1984 err = sock_intr_errno(timeo);
1985 goto out;
1989 * Calculate size that we wish to send.
1991 len = size - sent;
1993 if (len > mss)
1994 len = mss;
1997 * Wait for queue size to go down below the window
1998 * size.
2000 if (dn_queue_too_long(scp, queue, flags)) {
2001 if (flags & MSG_DONTWAIT) {
2002 err = -EWOULDBLOCK;
2003 goto out;
2006 SOCK_SLEEP_PRE(sk)
2008 if (dn_queue_too_long(scp, queue, flags))
2009 schedule();
2011 SOCK_SLEEP_POST(sk)
2013 continue;
2017 * Get a suitably sized skb.
2018 * 64 is a bit of a hack really, but its larger than any
2019 * link-layer headers and has served us well as a good
2020 * guess as to their real length.
2022 skb = dn_alloc_send_pskb(sk, len + 64 + DN_MAX_NSP_DATA_HEADER,
2023 flags & MSG_DONTWAIT, &err);
2025 if (err)
2026 break;
2028 if (!skb)
2029 continue;
2031 cb = DN_SKB_CB(skb);
2033 skb_reserve(skb, 64 + DN_MAX_NSP_DATA_HEADER);
2035 if (memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len)) {
2036 err = -EFAULT;
2037 goto out;
2040 if (flags & MSG_OOB) {
2041 cb->nsp_flags = 0x30;
2042 if (fctype != NSP_FC_NONE)
2043 scp->flowrem_oth--;
2044 } else {
2045 cb->nsp_flags = 0x00;
2046 if (scp->seg_total == 0)
2047 cb->nsp_flags |= 0x20;
2049 scp->seg_total += len;
2051 if (((sent + len) == size) && (flags & MSG_EOR)) {
2052 cb->nsp_flags |= 0x40;
2053 scp->seg_total = 0;
2054 if (fctype == NSP_FC_SCMC)
2055 scp->flowrem_dat--;
2057 if (fctype == NSP_FC_SRC)
2058 scp->flowrem_dat--;
2061 sent += len;
2062 dn_nsp_queue_xmit(sk, skb, sk->sk_allocation, flags & MSG_OOB);
2063 skb = NULL;
2065 scp->persist = dn_nsp_persist(sk);
2068 out:
2070 if (skb)
2071 kfree_skb(skb);
2073 release_sock(sk);
2075 return sent ? sent : err;
2077 out_err:
2078 err = sk_stream_error(sk, flags, err);
2079 release_sock(sk);
2080 return err;
2083 static int dn_device_event(struct notifier_block *this, unsigned long event,
2084 void *ptr)
2086 struct net_device *dev = (struct net_device *)ptr;
2088 switch(event) {
2089 case NETDEV_UP:
2090 dn_dev_up(dev);
2091 break;
2092 case NETDEV_DOWN:
2093 dn_dev_down(dev);
2094 break;
2095 default:
2096 break;
2099 return NOTIFY_DONE;
2102 static struct notifier_block dn_dev_notifier = {
2103 .notifier_call = dn_device_event,
2106 extern int dn_route_rcv(struct sk_buff *, struct net_device *, struct packet_type *, struct net_device *);
2108 static struct packet_type dn_dix_packet_type = {
2109 .type = __constant_htons(ETH_P_DNA_RT),
2110 .dev = NULL, /* All devices */
2111 .func = dn_route_rcv,
2114 #ifdef CONFIG_PROC_FS
2115 struct dn_iter_state {
2116 int bucket;
2119 static struct sock *dn_socket_get_first(struct seq_file *seq)
2121 struct dn_iter_state *state = seq->private;
2122 struct sock *n = NULL;
2124 for(state->bucket = 0;
2125 state->bucket < DN_SK_HASH_SIZE;
2126 ++state->bucket) {
2127 n = sk_head(&dn_sk_hash[state->bucket]);
2128 if (n)
2129 break;
2132 return n;
2135 static struct sock *dn_socket_get_next(struct seq_file *seq,
2136 struct sock *n)
2138 struct dn_iter_state *state = seq->private;
2140 n = sk_next(n);
2141 try_again:
2142 if (n)
2143 goto out;
2144 if (++state->bucket >= DN_SK_HASH_SIZE)
2145 goto out;
2146 n = sk_head(&dn_sk_hash[state->bucket]);
2147 goto try_again;
2148 out:
2149 return n;
2152 static struct sock *socket_get_idx(struct seq_file *seq, loff_t *pos)
2154 struct sock *sk = dn_socket_get_first(seq);
2156 if (sk) {
2157 while(*pos && (sk = dn_socket_get_next(seq, sk)))
2158 --*pos;
2160 return *pos ? NULL : sk;
2163 static void *dn_socket_get_idx(struct seq_file *seq, loff_t pos)
2165 void *rc;
2166 read_lock_bh(&dn_hash_lock);
2167 rc = socket_get_idx(seq, &pos);
2168 if (!rc) {
2169 read_unlock_bh(&dn_hash_lock);
2171 return rc;
2174 static void *dn_socket_seq_start(struct seq_file *seq, loff_t *pos)
2176 return *pos ? dn_socket_get_idx(seq, *pos - 1) : SEQ_START_TOKEN;
2179 static void *dn_socket_seq_next(struct seq_file *seq, void *v, loff_t *pos)
2181 void *rc;
2183 if (v == SEQ_START_TOKEN) {
2184 rc = dn_socket_get_idx(seq, 0);
2185 goto out;
2188 rc = dn_socket_get_next(seq, v);
2189 if (rc)
2190 goto out;
2191 read_unlock_bh(&dn_hash_lock);
2192 out:
2193 ++*pos;
2194 return rc;
2197 static void dn_socket_seq_stop(struct seq_file *seq, void *v)
2199 if (v && v != SEQ_START_TOKEN)
2200 read_unlock_bh(&dn_hash_lock);
2203 #define IS_NOT_PRINTABLE(x) ((x) < 32 || (x) > 126)
2205 static void dn_printable_object(struct sockaddr_dn *dn, unsigned char *buf)
2207 int i;
2209 switch (dn_ntohs(dn->sdn_objnamel)) {
2210 case 0:
2211 sprintf(buf, "%d", dn->sdn_objnum);
2212 break;
2213 default:
2214 for (i = 0; i < dn_ntohs(dn->sdn_objnamel); i++) {
2215 buf[i] = dn->sdn_objname[i];
2216 if (IS_NOT_PRINTABLE(buf[i]))
2217 buf[i] = '.';
2219 buf[i] = 0;
2223 static char *dn_state2asc(unsigned char state)
2225 switch(state) {
2226 case DN_O:
2227 return "OPEN";
2228 case DN_CR:
2229 return " CR";
2230 case DN_DR:
2231 return " DR";
2232 case DN_DRC:
2233 return " DRC";
2234 case DN_CC:
2235 return " CC";
2236 case DN_CI:
2237 return " CI";
2238 case DN_NR:
2239 return " NR";
2240 case DN_NC:
2241 return " NC";
2242 case DN_CD:
2243 return " CD";
2244 case DN_RJ:
2245 return " RJ";
2246 case DN_RUN:
2247 return " RUN";
2248 case DN_DI:
2249 return " DI";
2250 case DN_DIC:
2251 return " DIC";
2252 case DN_DN:
2253 return " DN";
2254 case DN_CL:
2255 return " CL";
2256 case DN_CN:
2257 return " CN";
2260 return "????";
2263 static inline void dn_socket_format_entry(struct seq_file *seq, struct sock *sk)
2265 struct dn_scp *scp = DN_SK(sk);
2266 char buf1[DN_ASCBUF_LEN];
2267 char buf2[DN_ASCBUF_LEN];
2268 char local_object[DN_MAXOBJL+3];
2269 char remote_object[DN_MAXOBJL+3];
2271 dn_printable_object(&scp->addr, local_object);
2272 dn_printable_object(&scp->peer, remote_object);
2274 seq_printf(seq,
2275 "%6s/%04X %04d:%04d %04d:%04d %01d %-16s "
2276 "%6s/%04X %04d:%04d %04d:%04d %01d %-16s %4s %s\n",
2277 dn_addr2asc(dn_ntohs(dn_saddr2dn(&scp->addr)), buf1),
2278 scp->addrloc,
2279 scp->numdat,
2280 scp->numoth,
2281 scp->ackxmt_dat,
2282 scp->ackxmt_oth,
2283 scp->flowloc_sw,
2284 local_object,
2285 dn_addr2asc(dn_ntohs(dn_saddr2dn(&scp->peer)), buf2),
2286 scp->addrrem,
2287 scp->numdat_rcv,
2288 scp->numoth_rcv,
2289 scp->ackrcv_dat,
2290 scp->ackrcv_oth,
2291 scp->flowrem_sw,
2292 remote_object,
2293 dn_state2asc(scp->state),
2294 ((scp->accept_mode == ACC_IMMED) ? "IMMED" : "DEFER"));
2297 static int dn_socket_seq_show(struct seq_file *seq, void *v)
2299 if (v == SEQ_START_TOKEN) {
2300 seq_puts(seq, "Local Remote\n");
2301 } else {
2302 dn_socket_format_entry(seq, v);
2304 return 0;
2307 static const struct seq_operations dn_socket_seq_ops = {
2308 .start = dn_socket_seq_start,
2309 .next = dn_socket_seq_next,
2310 .stop = dn_socket_seq_stop,
2311 .show = dn_socket_seq_show,
2314 static int dn_socket_seq_open(struct inode *inode, struct file *file)
2316 struct seq_file *seq;
2317 int rc = -ENOMEM;
2318 struct dn_iter_state *s = kmalloc(sizeof(*s), GFP_KERNEL);
2320 if (!s)
2321 goto out;
2323 rc = seq_open(file, &dn_socket_seq_ops);
2324 if (rc)
2325 goto out_kfree;
2327 seq = file->private_data;
2328 seq->private = s;
2329 memset(s, 0, sizeof(*s));
2330 out:
2331 return rc;
2332 out_kfree:
2333 kfree(s);
2334 goto out;
2337 static const struct file_operations dn_socket_seq_fops = {
2338 .owner = THIS_MODULE,
2339 .open = dn_socket_seq_open,
2340 .read = seq_read,
2341 .llseek = seq_lseek,
2342 .release = seq_release_private,
2344 #endif
2346 static struct net_proto_family dn_family_ops = {
2347 .family = AF_DECnet,
2348 .create = dn_create,
2349 .owner = THIS_MODULE,
2352 static const struct proto_ops dn_proto_ops = {
2353 .family = AF_DECnet,
2354 .owner = THIS_MODULE,
2355 .release = dn_release,
2356 .bind = dn_bind,
2357 .connect = dn_connect,
2358 .socketpair = sock_no_socketpair,
2359 .accept = dn_accept,
2360 .getname = dn_getname,
2361 .poll = dn_poll,
2362 .ioctl = dn_ioctl,
2363 .listen = dn_listen,
2364 .shutdown = dn_shutdown,
2365 .setsockopt = dn_setsockopt,
2366 .getsockopt = dn_getsockopt,
2367 .sendmsg = dn_sendmsg,
2368 .recvmsg = dn_recvmsg,
2369 .mmap = sock_no_mmap,
2370 .sendpage = sock_no_sendpage,
2373 void dn_register_sysctl(void);
2374 void dn_unregister_sysctl(void);
2376 MODULE_DESCRIPTION("The Linux DECnet Network Protocol");
2377 MODULE_AUTHOR("Linux DECnet Project Team");
2378 MODULE_LICENSE("GPL");
2379 MODULE_ALIAS_NETPROTO(PF_DECnet);
2381 static char banner[] __initdata = KERN_INFO "NET4: DECnet for Linux: V.2.5.68s (C) 1995-2003 Linux DECnet Project Team\n";
2383 static int __init decnet_init(void)
2385 int rc;
2387 printk(banner);
2389 rc = proto_register(&dn_proto, 1);
2390 if (rc != 0)
2391 goto out;
2393 dn_neigh_init();
2394 dn_dev_init();
2395 dn_route_init();
2396 dn_fib_init();
2398 sock_register(&dn_family_ops);
2399 dev_add_pack(&dn_dix_packet_type);
2400 register_netdevice_notifier(&dn_dev_notifier);
2402 proc_net_fops_create("decnet", S_IRUGO, &dn_socket_seq_fops);
2403 dn_register_sysctl();
2404 out:
2405 return rc;
2408 module_init(decnet_init);
2411 * Prevent DECnet module unloading until its fixed properly.
2412 * Requires an audit of the code to check for memory leaks and
2413 * initialisation problems etc.
2415 #if 0
2416 static void __exit decnet_exit(void)
2418 sock_unregister(AF_DECnet);
2419 rtnl_unregister_all(PF_DECnet);
2420 dev_remove_pack(&dn_dix_packet_type);
2422 dn_unregister_sysctl();
2424 unregister_netdevice_notifier(&dn_dev_notifier);
2426 dn_route_cleanup();
2427 dn_dev_cleanup();
2428 dn_neigh_cleanup();
2429 dn_fib_cleanup();
2431 proc_net_remove("decnet");
2433 proto_unregister(&dn_proto);
2435 module_exit(decnet_exit);
2436 #endif