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>
13 * Steve Whitehouse: Copied from Eduardo Serrat and Patrick Caulfield's
14 * version of the code. Original copyright preserved
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
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
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
38 /******************************************************************************
39 (c) 1995-1998 E.M. Serrat emserrat@geocities.com
41 This program is free software; you can redistribute it and/or modify
42 it under the terms of the GNU General Public License as published by
43 the Free Software Foundation; either version 2 of the License, or
46 This program is distributed in the hope that it will be useful,
47 but WITHOUT ANY WARRANTY; without even the implied warranty of
48 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
49 GNU General Public License for more details.
53 Version Kernel Date Author/Comments
54 ------- ------ ---- ---------------
55 Version 0.0.1 2.0.30 01-dic-97 Eduardo Marcelo Serrat
56 (emserrat@geocities.com)
58 First Development of DECnet Socket La-
59 yer for Linux. Only supports outgoing
62 Version 0.0.2 2.1.105 20-jun-98 Patrick J. Caulfield
63 (patrick@pandh.demon.co.uk)
65 Port to new kernel development version.
67 Version 0.0.3 2.1.106 25-jun-98 Eduardo Marcelo Serrat
68 (emserrat@geocities.com)
70 Added support for incoming connections
71 so we can start developing server apps
75 Version 0.0.4 2.1.109 21-jul-98 Eduardo Marcelo Serrat
76 (emserrat@geocities.com)
78 Added support for X11R6.4. Now we can
79 use DECnet transport for X on Linux!!!
81 Version 0.0.5 2.1.110 01-aug-98 Eduardo Marcelo Serrat
82 (emserrat@geocities.com)
83 Removed bugs on flow control
84 Removed bugs on incoming accessdata
87 Version 0.0.6 2.1.110 07-aug-98 Eduardo Marcelo Serrat
92 *******************************************************************************/
94 #include <linux/config.h>
95 #include <linux/module.h>
96 #include <linux/errno.h>
97 #include <linux/types.h>
98 #include <linux/socket.h>
100 #include <linux/kernel.h>
101 #include <linux/sched.h>
102 #include <linux/timer.h>
103 #include <linux/string.h>
104 #include <linux/sockios.h>
105 #include <linux/net.h>
106 #include <linux/netdevice.h>
107 #include <linux/inet.h>
108 #include <linux/route.h>
109 #include <net/sock.h>
110 #include <asm/segment.h>
111 #include <asm/system.h>
112 #include <linux/mm.h>
113 #include <linux/interrupt.h>
114 #include <linux/proc_fs.h>
115 #include <linux/stat.h>
116 #include <linux/init.h>
117 #include <linux/poll.h>
118 #include <net/neighbour.h>
121 #include <net/dn_nsp.h>
122 #include <net/dn_dev.h>
123 #include <net/dn_route.h>
124 #include <net/dn_fib.h>
125 #include <net/dn_raw.h>
126 #include <net/dn_neigh.h>
128 #define MAX(a,b) ((a)>(b)?(a):(b))
130 static void dn_keepalive(struct sock
*sk
);
133 * decnet_address is kept in network order, decnet_ether_address is kept
134 * as a string of bytes.
136 dn_address decnet_address
= 0;
137 unsigned char decnet_ether_address
[ETH_ALEN
] = { 0xAA, 0x00, 0x04, 0x00, 0x00, 0x00 };
138 int decnet_node_type
= DN_RT_INFO_ENDN
;
140 static struct proto_ops dn_proto_ops
;
141 rwlock_t dn_hash_lock
= RW_LOCK_UNLOCKED
;
142 static struct sock
*dn_sklist
= NULL
;
143 static struct sock
*dn_wild_sk
= NULL
;
145 static int __dn_setsockopt(struct socket
*sock
, int level
, int optname
, char *optval
, int optlen
, int flags
);
146 static int __dn_getsockopt(struct socket
*sock
, int level
, int optname
, char *optval
, int *optlen
, int flags
);
148 static struct sock
**dn_find_list(struct sock
*sk
)
150 struct dn_scp
*scp
= &sk
->protinfo
.dn
;
152 if (scp
->addr
.sdn_flags
& SDF_WILD
)
153 return dn_wild_sk
? NULL
: &dn_wild_sk
;
158 static unsigned short port_alloc(struct sock
*sk
)
160 struct dn_scp
*scp
= &sk
->protinfo
.dn
;
161 static unsigned short port
= 0x2000;
166 scp
->addrloc
= port
++;
172 * Since this is only ever called from user
173 * level, we don't need a write_lock() version
176 static int dn_hash_sock(struct sock
*sk
)
178 struct dn_scp
*scp
= &sk
->protinfo
.dn
;
182 write_lock_bh(&dn_hash_lock
);
184 if (!scp
->addrloc
&& !port_alloc(sk
))
188 if ((skp
= dn_find_list(sk
)) == NULL
)
196 write_unlock_bh(&dn_hash_lock
);
200 static void dn_unhash_sock(struct sock
*sk
)
202 struct sock
**skp
= sk
->pprev
;
207 write_lock(&dn_hash_lock
);
209 skp
= &((*skp
)->next
);
211 write_unlock(&dn_hash_lock
);
217 static void dn_unhash_sock_bh(struct sock
*sk
)
219 struct sock
**skp
= sk
->pprev
;
224 write_lock_bh(&dn_hash_lock
);
226 skp
= &((*skp
)->next
);
228 write_unlock_bh(&dn_hash_lock
);
235 int dn_sockaddr2username(struct sockaddr_dn
*sdn
, unsigned char *buf
, unsigned char type
)
243 *buf
++ = sdn
->sdn_objnum
;
247 *buf
++ = dn_ntohs(sdn
->sdn_objnamel
);
248 memcpy(buf
, sdn
->sdn_objname
, dn_ntohs(sdn
->sdn_objnamel
));
249 len
= 3 + dn_ntohs(sdn
->sdn_objnamel
);
254 *buf
++ = dn_ntohs(sdn
->sdn_objnamel
);
255 memcpy(buf
, sdn
->sdn_objname
, dn_ntohs(sdn
->sdn_objnamel
));
256 len
= 7 + dn_ntohs(sdn
->sdn_objnamel
);
264 * On reception of usernames, we handle types 1 and 0 for destination
265 * addresses only. Types 2 and 4 are used for source addresses, but the
266 * UIC, GIC are ignored and they are both treated the same way. Type 3
267 * is never used as I've no idea what its purpose might be or what its
270 int dn_username2sockaddr(unsigned char *data
, int len
, struct sockaddr_dn
*sdn
, unsigned char *fmt
)
277 sdn
->sdn_objnamel
= dn_htons(0);
278 memset(sdn
->sdn_objname
, 0, DN_MAXOBJL
);
289 sdn
->sdn_objnum
= dn_htons(type
);
311 sdn
->sdn_objnamel
= dn_htons(*data
++);
312 len
-= dn_ntohs(sdn
->sdn_objnamel
);
314 if ((len
< 0) || (dn_ntohs(sdn
->sdn_objnamel
) > namel
))
317 memcpy(sdn
->sdn_objname
, data
, dn_ntohs(sdn
->sdn_objnamel
));
322 struct sock
*dn_sklist_find_listener(struct sockaddr_dn
*addr
)
326 read_lock(&dn_hash_lock
);
327 for(sk
= dn_sklist
; sk
!= NULL
; sk
= sk
->next
) {
328 struct dn_scp
*scp
= &sk
->protinfo
.dn
;
329 if (sk
->state
!= TCP_LISTEN
)
331 if (scp
->addr
.sdn_objnum
) {
332 if (scp
->addr
.sdn_objnum
!= addr
->sdn_objnum
)
335 if (addr
->sdn_objnum
)
337 if (scp
->addr
.sdn_objnamel
!= addr
->sdn_objnamel
)
339 if (memcmp(scp
->addr
.sdn_objname
, addr
->sdn_objname
, dn_ntohs(addr
->sdn_objnamel
)) != 0)
343 read_unlock(&dn_hash_lock
);
347 if (dn_wild_sk
&& (dn_wild_sk
->state
== TCP_LISTEN
))
348 sock_hold((sk
= dn_wild_sk
));
350 read_unlock(&dn_hash_lock
);
354 struct sock
*dn_find_by_skb(struct sk_buff
*skb
)
356 struct dn_skb_cb
*cb
= (struct dn_skb_cb
*)skb
->cb
;
360 read_lock(&dn_hash_lock
);
361 for(sk
= dn_sklist
; sk
!= NULL
; sk
= sk
->next
) {
362 scp
= &sk
->protinfo
.dn
;
363 if (cb
->src
!= dn_saddr2dn(&scp
->peer
))
365 if (cb
->dst_port
!= scp
->addrloc
)
367 if (scp
->addrrem
&& (cb
->src_port
!= scp
->addrrem
))
375 read_unlock(&dn_hash_lock
);
382 static void dn_destruct(struct sock
*sk
)
384 struct dn_scp
*scp
= &sk
->protinfo
.dn
;
386 skb_queue_purge(&scp
->data_xmit_queue
);
387 skb_queue_purge(&scp
->other_xmit_queue
);
388 skb_queue_purge(&scp
->other_receive_queue
);
390 dst_release(xchg(&sk
->dst_cache
, NULL
));
395 struct sock
*dn_alloc_sock(struct socket
*sock
, int flags
)
400 if ((sk
= sk_alloc(PF_DECnet
, flags
, 1)) == NULL
)
404 #ifdef CONFIG_DECNET_RAW
405 if (sock
->type
== SOCK_RAW
)
406 sock
->ops
= &dn_raw_proto_ops
;
408 #endif /* CONFIG_DECNET_RAW */
409 sock
->ops
= &dn_proto_ops
;
411 sock_init_data(sock
,sk
);
412 scp
= &sk
->protinfo
.dn
;
414 sk
->backlog_rcv
= dn_nsp_backlog_rcv
;
415 sk
->destruct
= dn_destruct
;
417 sk
->family
= PF_DECnet
;
420 /* Initialization of DECnet Session Control Port */
421 scp
->state
= DN_O
; /* Open */
422 scp
->numdat
= 1; /* Next data seg to tx */
423 scp
->numoth
= 1; /* Next oth data to tx */
424 scp
->ackxmt_dat
= 0; /* Last data seg ack'ed */
425 scp
->ackxmt_oth
= 0; /* Last oth data ack'ed */
426 scp
->ackrcv_dat
= 0; /* Highest data ack recv*/
427 scp
->ackrcv_oth
= 0; /* Last oth data ack rec*/
428 scp
->flowrem_sw
= DN_SEND
;
429 scp
->flowloc_sw
= DN_SEND
;
430 scp
->accept_mode
= ACC_IMMED
;
431 scp
->addr
.sdn_family
= AF_DECnet
;
432 scp
->peer
.sdn_family
= AF_DECnet
;
433 scp
->accessdata
.acc_accl
= 5;
434 memcpy(scp
->accessdata
.acc_acc
, "LINUX", 5);
437 scp
->snd_window
= NSP_MIN_WINDOW
;
438 scp
->nsp_srtt
= NSP_INITIAL_SRTT
;
439 scp
->nsp_rttvar
= NSP_INITIAL_RTTVAR
;
440 scp
->nsp_rxtshift
= 0;
442 skb_queue_head_init(&scp
->data_xmit_queue
);
443 skb_queue_head_init(&scp
->other_xmit_queue
);
444 skb_queue_head_init(&scp
->other_receive_queue
);
447 scp
->persist_fxn
= NULL
;
448 scp
->keepalive
= 10 * HZ
;
449 scp
->keepalive_fxn
= dn_keepalive
;
451 init_timer(&scp
->delack_timer
);
452 scp
->delack_pending
= 0;
453 scp
->delack_fxn
= dn_nsp_delayed_ack
;
455 dn_start_slow_timer(sk
);
466 * FIXME: Should respond to SO_KEEPALIVE etc.
468 static void dn_keepalive(struct sock
*sk
)
470 struct dn_scp
*scp
= &sk
->protinfo
.dn
;
473 * By checking the other_data transmit queue is empty
474 * we are double checking that we are not sending too
475 * many of these keepalive frames.
477 if (skb_queue_len(&scp
->other_xmit_queue
) == 0)
478 dn_nsp_send_lnk(sk
, DN_NOCHANGE
);
483 * Timer for shutdown/destroyed sockets.
484 * When socket is dead & no packets have been sent for a
485 * certain amount of time, they are removed by this
486 * routine. Also takes care of sending out DI & DC
487 * frames at correct times. This is called by both
488 * socket level and interrupt driven code.
490 static int dn_destroy_timer(struct sock
*sk
)
492 struct dn_scp
*scp
= &sk
->protinfo
.dn
;
494 scp
->persist
= dn_nsp_persist(sk
);
498 dn_send_disc(sk
, NSP_DISCINIT
, 0);
499 if (scp
->nsp_rxtshift
>= decnet_di_count
)
504 dn_send_disc(sk
, NSP_DISCINIT
, 0);
505 if (scp
->nsp_rxtshift
>= decnet_dr_count
)
510 if (scp
->nsp_rxtshift
< decnet_dn_count
) {
511 /* printk(KERN_DEBUG "dn_destroy_timer: DN\n"); */
512 dn_send_disc(sk
, NSP_DISCCONF
, NSP_REASON_DC
);
517 scp
->persist
= (HZ
* decnet_time_wait
);
522 dn_stop_fast_timer(sk
); /* unlikely, but possible that this is runninng */
523 if ((jiffies
- scp
->stamp
) >= (HZ
* decnet_time_wait
)) {
532 void dn_destroy_sock(struct sock
*sk
)
534 struct dn_scp
*scp
= &sk
->protinfo
.dn
;
540 scp
->nsp_rxtshift
= 0; /* reset back off */
543 if (sk
->socket
->state
!= SS_UNCONNECTED
)
544 sk
->socket
->state
= SS_DISCONNECTING
;
547 sk
->state
= TCP_CLOSE
;
551 dn_send_disc(sk
, NSP_DISCCONF
, NSP_REASON_DC
);
552 scp
->persist_fxn
= dn_destroy_timer
;
553 scp
->persist
= dn_nsp_persist(sk
);
564 dn_send_disc(sk
, NSP_DISCINIT
, 0);
572 scp
->persist_fxn
= dn_destroy_timer
;
573 scp
->persist
= dn_nsp_persist(sk
);
576 printk(KERN_DEBUG
"DECnet: dn_destroy_sock passed socket in invalid state\n");
578 dn_stop_fast_timer(sk
);
579 dn_stop_slow_timer(sk
);
581 dn_unhash_sock_bh(sk
);
588 char *dn_addr2asc(dn_address addr
, char *buf
)
590 unsigned short node
, area
;
592 node
= addr
& 0x03ff;
594 sprintf(buf
, "%hd.%hd", area
, node
);
600 static char *dn_state2asc(unsigned char state
)
640 static int dn_create(struct socket
*sock
, int protocol
)
646 if (protocol
!= DNPROTO_NSP
)
647 return -EPROTONOSUPPORT
;
651 #ifdef CONFIG_DECNET_RAW
653 if ((protocol
!= DNPROTO_NSP
) &&
654 (protocol
!= DNPROTO_ROU
))
655 return -EPROTONOSUPPORT
;
657 #endif /* CONFIG_DECNET_RAW */
659 return -ESOCKTNOSUPPORT
;
663 if ((sk
= dn_alloc_sock(sock
, GFP_KERNEL
)) == NULL
)
666 sk
->protocol
= protocol
;
673 dn_release(struct socket
*sock
)
675 struct sock
*sk
= sock
->sk
;
688 static int dn_bind(struct socket
*sock
, struct sockaddr
*uaddr
, int addr_len
)
690 struct sock
*sk
= sock
->sk
;
691 struct dn_scp
*scp
= &sk
->protinfo
.dn
;
692 struct sockaddr_dn
*saddr
= (struct sockaddr_dn
*)uaddr
;
693 struct net_device
*dev
;
699 if (addr_len
!= sizeof(struct sockaddr_dn
))
702 if (saddr
->sdn_family
!= AF_DECnet
)
705 if (dn_ntohs(saddr
->sdn_nodeaddrl
) && (dn_ntohs(saddr
->sdn_nodeaddrl
) != 2))
708 if (saddr
->sdn_objnum
&& !suser())
711 if (dn_ntohs(saddr
->sdn_objnamel
) > DN_MAXOBJL
)
714 if (saddr
->sdn_flags
& ~SDF_WILD
)
717 if (saddr
->sdn_flags
& SDF_WILD
) {
721 if (dn_ntohs(saddr
->sdn_nodeaddrl
)) {
722 read_lock(&dev_base_lock
);
723 for(dev
= dev_base
; dev
; dev
= dev
->next
) {
726 if (dn_dev_islocal(dev
, dn_saddr2dn(saddr
)))
729 read_unlock(&dev_base_lock
);
731 return -EADDRNOTAVAIL
;
736 memcpy(&scp
->addr
, saddr
, addr_len
);
739 if ((rv
= dn_hash_sock(sk
)) == 0)
749 static int dn_auto_bind(struct socket
*sock
)
751 struct sock
*sk
= sock
->sk
;
752 struct dn_scp
*scp
= &sk
->protinfo
.dn
;
756 scp
->addr
.sdn_flags
= 0;
757 scp
->addr
.sdn_objnum
= 0;
760 * This stuff is to keep compatibility with Eduardo's
761 * patch. I hope I can dispense with it shortly...
763 if ((scp
->accessdata
.acc_accl
!= 0) &&
764 (scp
->accessdata
.acc_accl
<= 12)) {
766 scp
->addr
.sdn_objnamel
= dn_htons(scp
->accessdata
.acc_accl
);
767 memcpy(scp
->addr
.sdn_objname
, scp
->accessdata
.acc_acc
, dn_ntohs(scp
->addr
.sdn_objnamel
));
769 scp
->accessdata
.acc_accl
= 0;
770 memset(scp
->accessdata
.acc_acc
, 0, 40);
773 scp
->addr
.sdn_add
.a_len
= dn_htons(2);
774 *(dn_address
*)scp
->addr
.sdn_add
.a_addr
= decnet_address
;
782 static int dn_connect(struct socket
*sock
, struct sockaddr
*uaddr
, int addr_len
, int flags
)
784 struct sockaddr_dn
*addr
= (struct sockaddr_dn
*)uaddr
;
785 struct sock
*sk
= sock
->sk
;
786 struct dn_scp
*scp
= &sk
->protinfo
.dn
;
791 if (sock
->state
== SS_CONNECTED
)
794 if (sock
->state
== SS_CONNECTING
) {
796 if (sk
->state
== TCP_ESTABLISHED
)
800 if (sk
->state
== TCP_CLOSE
)
805 if (sk
->protinfo
.dn
.state
!= DN_O
)
808 if (addr_len
!= sizeof(struct sockaddr_dn
))
811 if (addr
->sdn_family
!= AF_DECnet
)
814 if (addr
->sdn_flags
& SDF_WILD
)
817 err
= -EADDRNOTAVAIL
;
818 if (sk
->zapped
&& (err
= dn_auto_bind(sock
)))
821 memcpy(&scp
->peer
, addr
, addr_len
);
824 if (dn_route_output(&sk
->dst_cache
, dn_saddr2dn(&scp
->peer
), dn_saddr2dn(&scp
->addr
), 0) < 0)
827 sk
->state
= TCP_SYN_SENT
;
828 sock
->state
= SS_CONNECTING
;
829 sk
->protinfo
.dn
.state
= DN_CI
;
831 dn_nsp_send_conninit(sk
, NSP_CI
);
834 if ((sk
->state
== TCP_SYN_SENT
) && (flags
& O_NONBLOCK
))
837 while(sk
->state
== TCP_SYN_SENT
) {
840 if (signal_pending(current
))
843 if ((err
= sock_error(sk
)) != 0) {
844 sock
->state
= SS_UNCONNECTED
;
850 if (sk
->state
== TCP_SYN_SENT
)
856 if (sk
->state
!= TCP_ESTABLISHED
) {
857 sock
->state
= SS_UNCONNECTED
;
858 err
= sock_error(sk
);
863 sock
->state
= SS_CONNECTED
;
870 static int dn_access_copy(struct sk_buff
*skb
, struct accessdata_dn
*acc
)
872 unsigned char *ptr
= skb
->data
;
874 acc
->acc_userl
= *ptr
++;
875 memcpy(&acc
->acc_user
, ptr
, acc
->acc_userl
);
876 ptr
+= acc
->acc_userl
;
878 acc
->acc_passl
= *ptr
++;
879 memcpy(&acc
->acc_pass
, ptr
, acc
->acc_passl
);
880 ptr
+= acc
->acc_passl
;
882 acc
->acc_accl
= *ptr
++;
883 memcpy(&acc
->acc_acc
, ptr
, acc
->acc_accl
);
885 skb_pull(skb
, acc
->acc_accl
+ acc
->acc_passl
+ acc
->acc_userl
+ 3);
890 static int dn_user_copy(struct sk_buff
*skb
, struct optdata_dn
*opt
)
892 unsigned char *ptr
= skb
->data
;
894 opt
->opt_optl
= *ptr
++;
896 memcpy(opt
->opt_data
, ptr
, opt
->opt_optl
);
897 skb_pull(skb
, opt
->opt_optl
+ 1);
904 * This is here for use in the sockopt() call as well as
905 * in accept(). Must be called with a locked socket.
907 static int dn_wait_accept(struct socket
*sock
, int flags
)
909 struct sock
*sk
= sock
->sk
;
911 while(sk
->state
== TCP_LISTEN
) {
912 if (flags
& O_NONBLOCK
) {
918 if (sk
->state
== TCP_LISTEN
)
923 if (signal_pending(current
))
924 return -ERESTARTSYS
; /* But of course you don't! */
927 if ((sk
->protinfo
.dn
.state
!= DN_RUN
) && (sk
->protinfo
.dn
.state
!= DN_DRC
)) {
928 sock
->state
= SS_UNCONNECTED
;
929 return sock_error(sk
);
932 sock
->state
= SS_CONNECTED
;
938 static int dn_accept(struct socket
*sock
, struct socket
*newsock
, int flags
)
940 struct sock
*sk
= sock
->sk
, *newsk
;
941 struct sk_buff
*skb
= NULL
;
942 struct dn_skb_cb
*cb
;
943 unsigned char menuver
;
949 if (sk
->state
!= TCP_LISTEN
) {
954 if (sk
->protinfo
.dn
.state
!= DN_O
) {
961 if ((skb
= skb_dequeue(&sk
->receive_queue
)) == NULL
)
963 if (flags
& O_NONBLOCK
)
971 if (!skb_peek(&sk
->receive_queue
))
976 if (signal_pending(current
))
982 } while (skb
== NULL
);
984 cb
= (struct dn_skb_cb
*)skb
->cb
;
986 if ((newsk
= dn_alloc_sock(newsock
, GFP_KERNEL
)) == NULL
) {
994 dst_release(xchg(&newsk
->dst_cache
, skb
->dst
));
997 newsk
->protinfo
.dn
.state
= DN_CR
;
998 newsk
->protinfo
.dn
.addrrem
= cb
->src_port
;
999 newsk
->protinfo
.dn
.mss
= cb
->segsize
;
1000 newsk
->protinfo
.dn
.accept_mode
= sk
->protinfo
.dn
.accept_mode
;
1002 if (newsk
->protinfo
.dn
.mss
< 230)
1003 newsk
->protinfo
.dn
.mss
= 230;
1005 newsk
->state
= TCP_LISTEN
;
1008 memcpy(&newsk
->protinfo
.dn
.addr
, &sk
->protinfo
.dn
.addr
, sizeof(struct sockaddr_dn
));
1010 skb_pull(skb
, dn_username2sockaddr(skb
->data
, skb
->len
, &newsk
->protinfo
.dn
.addr
, &type
));
1011 skb_pull(skb
, dn_username2sockaddr(skb
->data
, skb
->len
, &newsk
->protinfo
.dn
.peer
, &type
));
1012 *(dn_address
*)newsk
->protinfo
.dn
.peer
.sdn_add
.a_addr
= cb
->src
;
1013 *(dn_address
*)newsk
->protinfo
.dn
.addr
.sdn_add
.a_addr
= cb
->dst
;
1015 menuver
= *skb
->data
;
1018 if (menuver
& DN_MENUVER_ACC
)
1019 dn_access_copy(skb
, &newsk
->protinfo
.dn
.accessdata
);
1021 if (menuver
& DN_MENUVER_USR
)
1022 dn_user_copy(skb
, &newsk
->protinfo
.dn
.conndata_in
);
1024 if (menuver
& DN_MENUVER_PRX
)
1025 newsk
->protinfo
.dn
.peer
.sdn_flags
|= SDF_PROXY
;
1027 if (menuver
& DN_MENUVER_UIC
)
1028 newsk
->protinfo
.dn
.peer
.sdn_flags
|= SDF_UICPROXY
;
1032 memcpy(&newsk
->protinfo
.dn
.conndata_out
, &sk
->protinfo
.dn
.conndata_out
,
1033 sizeof(struct optdata_dn
));
1034 memcpy(&newsk
->protinfo
.dn
.discdata_out
, &sk
->protinfo
.dn
.discdata_out
,
1035 sizeof(struct optdata_dn
));
1038 dn_hash_sock(newsk
);
1040 dn_send_conn_ack(newsk
);
1042 if (newsk
->protinfo
.dn
.accept_mode
== ACC_IMMED
) {
1043 newsk
->protinfo
.dn
.state
= DN_CC
;
1044 dn_send_conn_conf(newsk
);
1045 err
= dn_wait_accept(newsock
, flags
);
1048 release_sock(newsk
);
1053 static int dn_getname(struct socket
*sock
, struct sockaddr
*uaddr
,int *uaddr_len
,int peer
)
1055 struct sockaddr_dn
*sa
= (struct sockaddr_dn
*)uaddr
;
1056 struct sock
*sk
= sock
->sk
;
1057 struct dn_scp
*scp
= &sk
->protinfo
.dn
;
1059 *uaddr_len
= sizeof(struct sockaddr_dn
);
1064 if (sock
->state
!= SS_CONNECTED
&& scp
->accept_mode
== ACC_IMMED
)
1067 memcpy(sa
, &scp
->peer
, sizeof(struct sockaddr_dn
));
1069 memcpy(sa
, &scp
->addr
, sizeof(struct sockaddr_dn
));
1078 static unsigned int dn_poll(struct file
*file
, struct socket
*sock
, poll_table
*wait
)
1080 struct sock
*sk
= sock
->sk
;
1081 struct dn_scp
*scp
= &sk
->protinfo
.dn
;
1082 int mask
= datagram_poll(file
, sock
, wait
);
1084 if (skb_queue_len(&scp
->other_receive_queue
))
1090 static int dn_ioctl(struct socket
*sock
, unsigned int cmd
, unsigned long arg
)
1092 struct sock
*sk
= sock
->sk
;
1093 int err
= -EOPNOTSUPP
;
1094 unsigned long amount
= 0;
1095 struct sk_buff
*skb
;
1098 struct dn_naddr dnaddr
;
1104 return dn_dev_ioctl(cmd
, (void *)arg
);
1106 #ifdef CONFIG_DECNET_ROUTER
1109 return dn_fib_ioctl(sock
, cmd
, arg
);
1110 #endif /* CONFIG_DECNET_ROUTER */
1114 if (!suser()) return -EPERM
;
1116 if ((err
= copy_from_user(devname
, ioarg
->devname
, 5)) != 0)
1118 if ((err
= copy_from_user(addr
, ioarg
->exec_addr
, 6)) != 0)
1120 if ((dev
= dev_get(devname
)) == NULL
) {
1124 if (dev
->dn_ptr
== NULL
) {
1129 dn_dev_devices_off();
1131 decnet_default_device
= dev
;
1132 memcpy(decnet_ether_address
, addr
, ETH_ALEN
);
1133 decnet_address
= dn_htons(dn_eth2dn(decnet_ether_address
));
1135 dn_dev_devices_on();
1140 if (decnet_default_device
)
1141 strcpy(devname
, decnet_default_device
->name
);
1143 memset(devname
, 0, 6);
1145 if ((err
= copy_to_user(ioarg
->devname
, devname
, 5)) != 0)
1148 if ((err
= copy_to_user(ioarg
->exec_addr
, decnet_ether_address
, 6)) != 0)
1161 if ((err
= copy_from_user(&dnaddr
, (void *)arg
, sizeof(struct dn_naddr
))) != 0)
1164 if (dnaddr
.a_len
!= ETH_ALEN
) {
1169 dn_dev_devices_off();
1171 memcpy(decnet_ether_address
, dnaddr
.a_addr
, ETH_ALEN
);
1172 decnet_address
= dn_htons(dn_eth2dn(decnet_ether_address
));
1174 dn_dev_devices_on();
1178 dnaddr
.a_len
= ETH_ALEN
;
1179 memcpy(dnaddr
.a_addr
, decnet_ether_address
, ETH_ALEN
);
1181 if ((err
= copy_to_user((void *)arg
, &dnaddr
, sizeof(struct dn_naddr
))) != 0)
1192 dn_dev_devices_off();
1194 decnet_address
= (unsigned short)arg
;
1195 dn_dn2eth(decnet_ether_address
, dn_ntohs(decnet_address
));
1197 dn_dev_devices_on();
1202 if ((err
= put_user(decnet_address
, (unsigned short *)arg
)) != 0)
1207 case SIOCGIFBRDADDR
:
1208 return dev_ioctl(cmd
,(void *)arg
);
1211 amount
= sk
->sndbuf
- atomic_read(&sk
->wmem_alloc
);
1214 err
= put_user(amount
, (int *)arg
);
1219 if ((skb
= skb_peek(&sk
->receive_queue
)) != NULL
)
1222 err
= put_user(amount
, (int *)arg
);
1229 static int dn_listen(struct socket
*sock
, int backlog
)
1231 struct sock
*sk
= sock
->sk
;
1239 if ((sk
->protinfo
.dn
.state
!= DN_O
) || (sk
->state
== TCP_LISTEN
))
1242 sk
->max_ack_backlog
= backlog
;
1243 sk
->ack_backlog
= 0;
1244 sk
->state
= TCP_LISTEN
;
1254 static int dn_shutdown(struct socket
*sock
, int how
)
1256 struct sock
*sk
= sock
->sk
;
1257 struct dn_scp
*scp
= &sk
->protinfo
.dn
;
1258 int err
= -ENOTCONN
;
1262 if (sock
->state
== SS_UNCONNECTED
)
1266 if (sock
->state
== SS_DISCONNECTING
)
1270 if (scp
->state
== DN_O
)
1273 if (how
!= SHUTDOWN_MASK
)
1278 dn_destroy_sock(sk
);
1287 static int dn_setsockopt(struct socket
*sock
, int level
, int optname
, char *optval
, int optlen
)
1289 struct sock
*sk
= sock
->sk
;
1293 err
= __dn_setsockopt(sock
, level
, optname
, optval
, optlen
, 0);
1299 static int __dn_setsockopt(struct socket
*sock
, int level
,int optname
, char *optval
, int optlen
, int flags
)
1301 struct sock
*sk
= sock
->sk
;
1302 struct dn_scp
*scp
= &sk
->protinfo
.dn
;
1303 struct optdata_dn opt
;
1304 struct accessdata_dn acc
;
1305 #ifdef CONFIG_DECNET_FW
1306 char tmp_fw
[MAX(sizeof(struct dn_fwtest
),sizeof(struct dn_fwnew
))];
1310 if (optlen
&& !optval
)
1315 if (sock
->state
== SS_CONNECTED
)
1317 if ((scp
->state
!= DN_O
) && (scp
->state
!= DN_CR
))
1320 if (optlen
!= sizeof(struct optdata_dn
))
1323 if (copy_from_user(&opt
, optval
, optlen
))
1326 if (opt
.opt_optl
> 16)
1329 memcpy(&scp
->conndata_out
, &opt
, sizeof(struct optdata_dn
));
1333 if (sock
->state
!= SS_CONNECTED
&& sk
->protinfo
.dn
.accept_mode
== ACC_IMMED
)
1336 if (optlen
!= sizeof(struct optdata_dn
))
1339 if (copy_from_user(&opt
, optval
, sizeof(struct optdata_dn
)))
1342 if (opt
.opt_optl
> 16)
1345 memcpy(&scp
->discdata_out
, &opt
, sizeof(struct optdata_dn
));
1349 if (sock
->state
== SS_CONNECTED
)
1351 if (scp
->state
!= DN_O
)
1354 if (optlen
!= sizeof(struct accessdata_dn
))
1357 if (copy_from_user(&acc
, optval
, sizeof(struct accessdata_dn
)))
1360 if ((acc
.acc_accl
> DN_MAXACCL
) ||
1361 (acc
.acc_passl
> DN_MAXACCL
) ||
1362 (acc
.acc_userl
> DN_MAXACCL
))
1365 memcpy(&scp
->accessdata
, &acc
, sizeof(struct accessdata_dn
));
1368 case DSO_ACCEPTMODE
:
1369 if (sock
->state
== SS_CONNECTED
)
1371 if (scp
->state
!= DN_O
)
1374 if (optlen
!= sizeof(int))
1380 if (get_user(mode
, optval
))
1382 if ((mode
!= ACC_IMMED
) && (mode
!= ACC_DEFER
))
1385 scp
->accept_mode
= (unsigned char)mode
;
1391 if (scp
->state
!= DN_CR
)
1395 dn_send_conn_conf(sk
);
1396 err
= dn_wait_accept(sock
, sock
->file
->f_flags
);
1401 if (scp
->state
!= DN_CR
)
1405 sk
->shutdown
= SHUTDOWN_MASK
;
1406 dn_send_disc(sk
, 0x38, 0);
1409 #ifdef CONFIG_DECNET_FW
1413 case DN_FW_DELETE_NUM
:
1418 case DN_FW_CREATECHAIN
:
1419 case DN_FW_DELETECHAIN
:
1422 if (!capable(CAP_NET_ADMIN
))
1424 if ((optlen
> sizeof(tmp_fw
)) || (optlen
< 1))
1426 if (copy_from_user(&tmp_fw
, optval
, optlen
))
1428 err
= dn_fw_ctl(optname
, &tmp_fw
, optlen
);
1429 return -err
; /* -0 is 0 after all */
1442 static int dn_getsockopt(struct socket
*sock
, int level
, int optname
, char *optval
, int *optlen
)
1444 struct sock
*sk
= sock
->sk
;
1448 err
= __dn_getsockopt(sock
, level
, optname
, optval
, optlen
, 0);
1454 static int __dn_getsockopt(struct socket
*sock
, int level
,int optname
, char *optval
,int *optlen
, int flags
)
1456 struct sock
*sk
= sock
->sk
;
1457 struct dn_scp
*scp
= &sk
->protinfo
.dn
;
1458 struct linkinfo_dn link
;
1459 int mode
= scp
->accept_mode
;
1463 if (*optlen
!= sizeof(struct optdata_dn
))
1466 if (copy_to_user(optval
, &scp
->conndata_in
, sizeof(struct optdata_dn
)))
1471 if (*optlen
!= sizeof(struct optdata_dn
))
1474 if (copy_to_user(optval
, &scp
->discdata_in
, sizeof(struct optdata_dn
)))
1480 if (*optlen
!= sizeof(struct accessdata_dn
))
1483 if (copy_to_user(optval
, &scp
->accessdata
, sizeof(struct accessdata_dn
)))
1487 case DSO_ACCEPTMODE
:
1488 if (put_user(mode
, optval
))
1493 if (*optlen
!= sizeof(struct linkinfo_dn
))
1496 switch(sock
->state
) {
1498 link
.idn_linkstate
= LL_CONNECTING
;
1500 case SS_DISCONNECTING
:
1501 link
.idn_linkstate
= LL_DISCONNECTING
;
1504 link
.idn_linkstate
= LL_RUNNING
;
1507 link
.idn_linkstate
= LL_INACTIVE
;
1510 link
.idn_segsize
= scp
->mss
;
1512 if (copy_to_user(optval
, &link
, sizeof(struct linkinfo_dn
)))
1529 * Used by send/recvmsg to wait until the socket is connected
1530 * before passing data.
1532 static int dn_wait_run(struct sock
*sk
, int flags
)
1534 struct dn_scp
*scp
= &sk
->protinfo
.dn
;
1537 switch(scp
->state
) {
1543 dn_send_conn_conf(sk
);
1544 return dn_wait_accept(sk
->socket
, (flags
& MSG_DONTWAIT
) ? O_NONBLOCK
: 0);
1552 if (flags
& MSG_DONTWAIT
)
1553 return -EWOULDBLOCK
;
1556 if ((err
= sock_error(sk
)) != 0)
1559 if (signal_pending(current
)) {
1566 if (scp
->state
!= DN_RUN
)
1571 } while(scp
->state
!= DN_RUN
);
1577 static int dn_data_ready(struct sock
*sk
, struct sk_buff_head
*q
, int flags
, int target
)
1579 struct sk_buff
*skb
= q
->next
;
1582 if (flags
& MSG_OOB
)
1583 return skb_queue_len(q
) ? 1 : 0;
1585 while(skb
!= (struct sk_buff
*)q
) {
1586 struct dn_skb_cb
*cb
= (struct dn_skb_cb
*)skb
->cb
;
1589 if (cb
->nsp_flags
& 0x40) {
1590 /* SOCK_SEQPACKET reads to EOM */
1591 if (sk
->type
== SOCK_SEQPACKET
)
1593 /* so does SOCK_STREAM unless WAITALL is specified */
1594 if (!(flags
& MSG_WAITALL
))
1598 /* minimum data length for read exceeded */
1609 static int dn_recvmsg(struct socket
*sock
, struct msghdr
*msg
, int size
,
1610 int flags
, struct scm_cookie
*scm
)
1612 struct sock
*sk
= sock
->sk
;
1613 struct dn_scp
*scp
= &sk
->protinfo
.dn
;
1614 struct sk_buff_head
*queue
= &sk
->receive_queue
;
1615 int target
= size
> 1 ? 1 : 0;
1618 struct sk_buff
*skb
, *nskb
;
1619 struct dn_skb_cb
*cb
= NULL
;
1620 unsigned char eor
= 0;
1625 rv
= -EADDRNOTAVAIL
;
1629 if ((rv
= dn_wait_run(sk
, flags
)) != 0)
1632 if (sk
->shutdown
& RCV_SHUTDOWN
) {
1633 send_sig(SIGPIPE
, current
, 0);
1638 if (flags
& ~(MSG_PEEK
|MSG_OOB
|MSG_WAITALL
|MSG_DONTWAIT
)) {
1643 if (flags
& MSG_OOB
)
1644 queue
= &scp
->other_receive_queue
;
1646 if (flags
& MSG_WAITALL
)
1651 * See if there is data ready to read, sleep if there isn't
1657 if (skb_queue_len(&scp
->other_receive_queue
)) {
1658 if (!(flags
& MSG_OOB
)) {
1659 msg
->msg_flags
|= MSG_OOB
;
1660 if (!scp
->other_report
) {
1661 scp
->other_report
= 1;
1667 if (scp
->state
!= DN_RUN
)
1670 if (signal_pending(current
)) {
1675 if (dn_data_ready(sk
, queue
, flags
, target
))
1678 if (flags
& MSG_DONTWAIT
) {
1683 sock
->flags
|= SO_WAITDATA
;
1686 if (!dn_data_ready(sk
, queue
, flags
, target
))
1690 sock
->flags
&= ~SO_WAITDATA
;
1693 for(skb
= queue
->next
; skb
!= (struct sk_buff
*)queue
; skb
= nskb
) {
1694 int chunk
= skb
->len
;
1695 cb
= (struct dn_skb_cb
*)skb
->cb
;
1697 if ((chunk
+ copied
) > size
)
1698 chunk
= size
- copied
;
1700 if (memcpy_toiovec(msg
->msg_iov
, skb
->data
, chunk
)) {
1706 if (!(flags
& MSG_PEEK
))
1709 eor
= cb
->nsp_flags
& 0x40;
1712 if (skb
->len
== 0) {
1716 * N.B. Don't refer to skb or cb after this point
1719 if ((scp
->flowloc_sw
== DN_DONTSEND
) && !dn_congested(sk
)) {
1720 scp
->flowloc_sw
= DN_SEND
;
1721 dn_nsp_send_lnk(sk
, DN_SEND
);
1726 if (sk
->type
== SOCK_SEQPACKET
)
1728 if (!(flags
& MSG_WAITALL
))
1732 if (flags
& MSG_OOB
)
1735 if (copied
>= target
)
1741 if (eor
&& (sk
->type
== SOCK_SEQPACKET
))
1742 msg
->msg_flags
|= MSG_EOR
;
1746 rv
= (flags
& MSG_PEEK
) ? -sk
->err
: sock_error(sk
);
1748 if ((rv
>= 0) && msg
->msg_name
) {
1749 memcpy(msg
->msg_name
, &scp
->peer
, sizeof(struct sockaddr_dn
));
1750 msg
->msg_namelen
= sizeof(struct sockaddr_dn
);
1759 static int dn_sendmsg(struct socket
*sock
, struct msghdr
*msg
, int size
,
1760 struct scm_cookie
*scm
)
1762 struct sock
*sk
= sock
->sk
;
1763 struct dn_scp
*scp
= &sk
->protinfo
.dn
;
1765 int mtu
= 230 - 11; /* maximum value thats always safe */
1766 struct sk_buff_head
*queue
= &scp
->data_xmit_queue
;
1767 int flags
= msg
->msg_flags
;
1768 unsigned short numseg
= 0;
1771 int addr_len
= msg
->msg_namelen
;
1772 struct sockaddr_dn
*addr
= (struct sockaddr_dn
*)msg
->msg_name
;
1773 struct sk_buff
*skb
= NULL
;
1774 struct dn_skb_cb
*cb
;
1775 unsigned char msgflg
;
1780 if (flags
& ~(MSG_TRYHARD
|MSG_OOB
|MSG_DONTWAIT
|MSG_EOR
))
1783 if (addr_len
&& (addr_len
!= sizeof(struct sockaddr_dn
)))
1786 if (sk
->zapped
&& dn_auto_bind(sock
)) {
1787 err
= -EADDRNOTAVAIL
;
1791 if (scp
->state
== DN_O
) {
1792 if (!addr_len
|| !addr
) {
1797 if ((err
= dn_connect(sock
, (struct sockaddr
*)addr
, addr_len
, (flags
& MSG_DONTWAIT
) ? O_NONBLOCK
: 0)) < 0)
1803 if ((err
= dn_wait_run(sk
, flags
)) < 0)
1806 if (sk
->shutdown
& SEND_SHUTDOWN
) {
1807 send_sig(SIGPIPE
, current
, 0);
1812 if ((flags
& MSG_TRYHARD
) && sk
->dst_cache
)
1813 dst_negative_advice(&sk
->dst_cache
);
1815 if (sk
->dst_cache
&& sk
->dst_cache
->neighbour
) {
1816 struct dn_neigh
*dn
= (struct dn_neigh
*)sk
->dst_cache
->neighbour
;
1817 if (dn
->blksize
> 230)
1818 mtu
= dn
->blksize
- 11;
1822 * The only difference between SEQPACKET & STREAM sockets under DECnet
1823 * AFAIK is that SEQPACKET sockets set the MSG_EOR flag for the last
1824 * session control message segment.
1827 if (flags
& MSG_OOB
) {
1829 queue
= &scp
->other_xmit_queue
;
1839 scp
->persist_fxn
= dn_nsp_xmit_timeout
;
1841 while(sent
< size
) {
1842 if ((err
= sock_error(sk
) != 0))
1845 if (signal_pending(current
)) {
1851 * Calculate size that we wish to send.
1859 * Wait for queue size to go down below the window
1862 if (skb_queue_len(queue
) >= scp
->snd_window
) {
1863 if (flags
& MSG_DONTWAIT
) {
1870 if (skb_queue_len(queue
) >= scp
->snd_window
)
1879 * Get a suitably sized skb.
1881 skb
= dn_alloc_send_skb(sk
, &len
, flags
& MSG_DONTWAIT
, &err
);
1889 cb
= (struct dn_skb_cb
*)skb
->cb
;
1891 ptr
= skb_put(skb
, 9);
1893 if (memcpy_fromiovec(skb_put(skb
, len
), msg
->msg_iov
, len
)) {
1898 if (flags
& MSG_OOB
) {
1899 cb
->segnum
= scp
->numoth
++;
1900 scp
->numoth
&= 0x0fff;
1902 ack
= scp
->ackxmt_oth
| 0x8000;
1904 cb
->segnum
= scp
->numdat
++;
1905 scp
->numdat
&= 0x0fff;
1907 if (sock
->type
== SOCK_STREAM
)
1909 if (scp
->seg_size
== 0)
1912 scp
->seg_size
+= len
;
1914 if (((sent
+ len
) == size
) && (flags
& MSG_EOR
)) {
1918 ack
= scp
->ackxmt_dat
| 0x8000;
1922 *(__u16
*)ptr
= scp
->addrrem
;
1924 *(__u16
*)ptr
= scp
->addrloc
;
1926 *(__u16
*)ptr
= dn_htons(ack
);
1928 *(__u16
*)ptr
= dn_htons(cb
->segnum
);
1931 dn_nsp_queue_xmit(sk
, skb
, flags
& MSG_OOB
);
1935 scp
->persist
= dn_nsp_persist(sk
);
1945 return sent
? sent
: err
;
1948 static int dn_device_event(struct notifier_block
*this, unsigned long event
,
1951 struct net_device
*dev
= (struct net_device
*)ptr
;
1967 static struct notifier_block dn_dev_notifier
= {
1972 extern int dn_route_rcv(struct sk_buff
*, struct net_device
*, struct packet_type
*);
1974 static struct packet_type dn_dix_packet_type
=
1976 __constant_htons(ETH_P_DNA_RT
),
1977 NULL
, /* All devices */
1983 #ifdef CONFIG_PROC_FS
1985 static int dn_get_info(char *buffer
, char **start
, off_t offset
, int length
, int dummy
)
1992 char buf1
[DN_ASCBUF_LEN
];
1993 char buf2
[DN_ASCBUF_LEN
];
1995 len
+= sprintf(buffer
+ len
, "Local Remote\n");
1997 read_lock(&dn_hash_lock
);
1998 for(sk
= dn_sklist
; sk
!= NULL
; sk
= sk
->next
) {
1999 scp
= &sk
->protinfo
.dn
;
2001 len
+= sprintf(buffer
+ len
,
2002 "%6s/%04X %04d:%04d %04d:%04d %01d %6s/%04X %04d:%04d %04d:%04d %01d %4s %s\n",
2003 dn_addr2asc(dn_ntohs(dn_saddr2dn(&scp
->addr
)), buf1
),
2010 dn_addr2asc(dn_ntohs(dn_saddr2dn(&scp
->peer
)), buf2
),
2017 dn_state2asc(scp
->state
),
2018 ((scp
->accept_mode
== ACC_IMMED
) ? "IMMED" : "DEFER"));
2025 if (pos
> (offset
+ length
))
2028 read_unlock(&dn_hash_lock
);
2030 *start
= buffer
+ (offset
- begin
);
2031 len
-= (offset
- begin
);
2039 struct proc_dir_entry decnet_linkinfo
= {
2040 PROC_NET_DN_SKT
, 6, "decnet", S_IFREG
| S_IRUGO
,
2041 1, 0, 0, 0, &proc_net_inode_operations
, dn_get_info
2044 #ifdef CONFIG_DECNET_RAW
2046 extern int dn_raw_get_info(char *, char **, off_t
, int, int);
2048 struct proc_dir_entry decnet_rawinfo
= {
2049 PROC_NET_DN_RAW
, 10, "decnet_raw", S_IFREG
| S_IRUGO
,
2050 1, 0, 0, 0, &proc_net_inode_operations
, dn_raw_get_info
2053 #endif /* CONFIG_DECNET_RAW */
2054 #endif /* CONFIG_PROC_FS */
2055 static struct net_proto_family dn_family_ops
= {
2060 static struct proto_ops dn_proto_ops
= {
2081 #ifdef CONFIG_SYSCTL
2082 void dn_register_sysctl(void);
2083 void dn_unregister_sysctl(void);
2086 void __init
decnet_proto_init(struct net_proto
*pro
)
2088 sock_register(&dn_family_ops
);
2089 dev_add_pack(&dn_dix_packet_type
);
2090 register_netdevice_notifier(&dn_dev_notifier
);
2092 #ifdef CONFIG_PROC_FS
2093 proc_net_register(&decnet_linkinfo
);
2094 #ifdef CONFIG_DECNET_RAW
2095 proc_net_register(&decnet_rawinfo
);
2102 #ifdef CONFIG_DECNET_FW
2104 #endif /* CONFIG_DECNET_FW */
2106 #ifdef CONFIG_DECNET_ROUTER
2108 #endif /* CONFIG_DECNET_ROUTER */
2110 #ifdef CONFIG_SYSCTL
2111 dn_register_sysctl();
2112 #endif /* CONFIG_SYSCTL */
2113 printk(KERN_INFO
"NET4: DECnet for Linux: V.2.3.15s (C) 1995-1999 Linux DECnet Project Team\n");
2118 static int __init
decnet_setup(char *str
)
2120 unsigned short area
= simple_strtoul(str
, &str
, 0);
2121 unsigned short node
= simple_strtoul(*str
> 0 ? ++str
: str
, &str
, 0);
2122 unsigned short type
= simple_strtoul(*str
> 0 ? ++str
: str
, &str
, 0);
2124 decnet_address
= dn_htons(area
<< 10 | node
);
2125 dn_dn2eth(decnet_ether_address
, dn_ntohs(decnet_address
));
2129 printk(KERN_INFO
"Invalid DECnet node type, switching to EndNode\n");
2131 decnet_node_type
= DN_RT_INFO_ENDN
;
2133 #ifdef CONFIG_DECNET_ROUTER
2135 decnet_node_type
= DN_RT_INFO_L1RT
;
2138 decnet_node_type
= DN_RT_INFO_L2RT
;
2140 #endif /* CONFIG_DECNET_ROUTER */
2146 __setup("decnet=", decnet_setup
);
2151 MODULE_DESCRIPTION("The Linux DECnet Network Protocol");
2152 MODULE_AUTHOR("Linux DECnet Project Team");
2154 static int addr
[2] = {0, 0};
2155 #ifdef CONFIG_DECNET_ROUTER
2156 static int type
= 0;
2159 MODULE_PARM(addr
, "2i");
2160 MODULE_PARM_DESC(addr
, "The DECnet address of this machine: area,node");
2161 #ifdef CONFIG_DECNET_ROUTER
2162 MODULE_PARM(type
, "i");
2163 MODULE_PARM_DESC(type
, "The type of this DECnet node: 0=EndNode, 1,2=Router");
2166 int init_module(void)
2168 if (addr
[0] > 63 || addr
[0] < 0) {
2169 printk(KERN_ERR
"DECnet: Area must be between 0 and 63");
2173 if (addr
[1] > 1023 || addr
[1] < 0) {
2174 printk(KERN_ERR
"DECnet: Node must be between 0 and 1023");
2178 decnet_address
= dn_htons((addr
[0] << 10) | addr
[1]);
2179 dn_dn2eth(decnet_ether_address
, dn_ntohs(decnet_address
));
2181 #ifdef CONFIG_DECNET_ROUTER
2184 decnet_node_type
= DN_RT_INFO_ENDN
;
2187 decnet_node_type
= DN_RT_INFO_L1RT
;
2190 decnet_node_type
= DN_RT_INFO_L2RT
;
2193 printk(KERN_ERR
"DECnet: Node type must be between 0 and 2 inclusive\n");
2197 decnet_node_type
= DN_RT_INFO_ENDN
;
2200 decnet_proto_init(NULL
);
2205 void cleanup_module(void)
2207 #ifdef CONFIG_SYSCTL
2208 dn_unregister_sysctl();
2209 #endif /* CONFIG_SYSCTL */
2211 unregister_netdevice_notifier(&dn_dev_notifier
);
2217 #ifdef CONFIG_DECNET_FW
2218 /* dn_fw_cleanup(); */
2219 #endif /* CONFIG_DECNET_FW */
2221 #ifdef CONFIG_DECNET_ROUTER
2223 #endif /* CONFIG_DECNET_ROUTER */
2225 #ifdef CONFIG_PROC_FS
2226 proc_net_unregister(PROC_NET_DN_SKT
);
2227 #ifdef CONFIG_DECNET_RAW
2228 proc_net_unregister(PROC_NET_DN_RAW
);
2232 dev_remove_pack(&dn_dix_packet_type
);
2233 sock_unregister(AF_DECnet
);