2 * DECnet An implementation of the DECnet protocol suite for the LINUX
3 * operating system. DECnet is implemented using the BSD Socket
4 * interface as the means of communication with the user level.
8 * Authors: Steve Whitehouse <SteveW@ACM.org>
9 * Eduardo Marcelo Serrat <emserrat@geocities.com>
12 * Steve Whitehouse : Devices now see incoming frames so they
13 * can mark on who it came from.
14 * Steve Whitehouse : Fixed bug in creating neighbours. Each neighbour
15 * can now have a device specific setup func.
16 * Steve Whitehouse : Added /proc/sys/net/decnet/conf/<dev>/
17 * Steve Whitehouse : Fixed bug which sometimes killed timer
18 * Steve Whitehouse : Multiple ifaddr support
19 * Steve Whitehouse : SIOCGIFCONF is now a compile time option
20 * Steve Whitehouse : /proc/sys/net/decnet/conf/<sys>/forwarding
21 * Steve Whitehouse : Removed timer1 - its a user space issue now
24 #include <linux/config.h>
25 #include <linux/net.h>
26 #include <linux/netdevice.h>
27 #include <linux/proc_fs.h>
28 #include <linux/timer.h>
29 #include <linux/string.h>
30 #include <linux/if_arp.h>
31 #include <linux/if_ether.h>
32 #include <linux/init.h>
33 #include <linux/skbuff.h>
34 #include <linux/rtnetlink.h>
35 #include <linux/sysctl.h>
36 #include <asm/uaccess.h>
37 #include <net/neighbour.h>
40 #include <net/dn_dev.h>
41 #include <net/dn_route.h>
42 #include <net/dn_neigh.h>
43 #include <net/dn_fib.h>
45 #define DN_IFREQ_SIZE (sizeof(struct ifreq) - sizeof(struct sockaddr) + sizeof(struct sockaddr_dn))
47 static char dn_rt_all_end_mcast
[ETH_ALEN
] = {0xAB,0x00,0x00,0x04,0x00,0x00};
48 static char dn_rt_all_rt_mcast
[ETH_ALEN
] = {0xAB,0x00,0x00,0x03,0x00,0x00};
49 static char dn_hiord
[ETH_ALEN
] = {0xAA,0x00,0x04,0x00,0x00,0x00};
50 static unsigned char dn_eco_version
[3] = {0x02,0x00,0x00};
52 extern struct neigh_table dn_neigh_table
;
54 struct net_device
*decnet_default_device
= NULL
;
56 static struct dn_dev
*dn_dev_create(struct net_device
*dev
, int *err
);
57 static void dn_dev_delete(struct net_device
*dev
);
58 #ifdef CONFIG_RTNETLINK
59 static void rtmsg_ifa(int event
, struct dn_ifaddr
*ifa
);
62 static int dn_eth_up(struct net_device
*);
63 static void dn_send_brd_hello(struct net_device
*dev
);
65 static void dn_send_ptp_hello(struct net_device
*dev
);
68 static struct dn_dev_parms dn_dev_list
[] = {
70 ARPHRD_ETHER
, /* Ethernet */
79 NET_DECNET_CONF_ETHER
,
86 ARPHRD_IPGRE
, /* DECnet tunneled over GRE in IP */
103 ARPHRD_X25
, /* Bog standard X.25 */
121 ARPHRD_PPP
, /* DECnet over PPP */
139 ARPHRD_DDCMP
, /* DECnet over DDCMP */
148 NET_DECNET_CONF_DDCMP
,
156 ARPHRD_LOOPBACK
, /* Loopback interface - always last */
165 NET_DECNET_CONF_LOOPBACK
,
173 #define DN_DEV_LIST_SIZE (sizeof(dn_dev_list)/sizeof(struct dn_dev_parms))
175 #define DN_DEV_PARMS_OFFSET(x) ((int) ((char *) &((struct dn_dev_parms *)0)->x))
179 static int min_t2
[] = { 1 };
180 static int max_t2
[] = { 60 }; /* No max specified, but this seems sensible */
181 static int min_t3
[] = { 1 };
182 static int max_t3
[] = { 8191 }; /* Must fit in 16 bits when multiplied by BCT3MULT or T3MULT */
184 static int min_priority
[] = { 0 };
185 static int max_priority
[] = { 127 }; /* From DECnet spec */
187 static int dn_forwarding_proc(ctl_table
*, int, struct file
*,
189 static int dn_forwarding_sysctl(ctl_table
*table
, int *name
, int nlen
,
190 void *oldval
, size_t *oldlenp
,
191 void *newval
, size_t newlen
,
194 static struct dn_dev_sysctl_table
{
195 struct ctl_table_header
*sysctl_header
;
196 ctl_table dn_dev_vars
[5];
197 ctl_table dn_dev_dev
[2];
198 ctl_table dn_dev_conf_dir
[2];
199 ctl_table dn_dev_proto_dir
[2];
200 ctl_table dn_dev_root_dir
[2];
204 {NET_DECNET_CONF_DEV_FORWARDING
, "forwarding",
205 (void *)DN_DEV_PARMS_OFFSET(forwarding
),
206 sizeof(int), 0644, NULL
,
207 dn_forwarding_proc
, dn_forwarding_sysctl
,
209 {NET_DECNET_CONF_DEV_PRIORITY
, "priority",
210 (void *)DN_DEV_PARMS_OFFSET(priority
),
211 sizeof(int), 0644, NULL
,
212 proc_dointvec_minmax
, sysctl_intvec
,
213 NULL
, &min_priority
, &max_priority
},
214 {NET_DECNET_CONF_DEV_T2
, "t2", (void *)DN_DEV_PARMS_OFFSET(t2
),
215 sizeof(int), 0644, NULL
,
216 proc_dointvec_minmax
, sysctl_intvec
,
217 NULL
, &min_t2
, &max_t2
},
218 {NET_DECNET_CONF_DEV_T3
, "t3", (void *)DN_DEV_PARMS_OFFSET(t3
),
219 sizeof(int), 0644, NULL
,
220 proc_dointvec_minmax
, sysctl_intvec
,
221 NULL
, &min_t3
, &max_t3
},
224 {{0, "", NULL
, 0, 0555, dn_dev_sysctl
.dn_dev_vars
}, {0}},
225 {{NET_DECNET_CONF
, "conf", NULL
, 0, 0555, dn_dev_sysctl
.dn_dev_dev
}, {0}},
226 {{NET_DECNET
, "decnet", NULL
, 0, 0555, dn_dev_sysctl
.dn_dev_conf_dir
}, {0}},
227 {{CTL_NET
, "net", NULL
, 0, 0555, dn_dev_sysctl
.dn_dev_proto_dir
}, {0}}
230 static void dn_dev_sysctl_register(struct net_device
*dev
, struct dn_dev_parms
*parms
)
232 struct dn_dev_sysctl_table
*t
;
235 t
= kmalloc(sizeof(*t
), GFP_KERNEL
);
239 memcpy(t
, &dn_dev_sysctl
, sizeof(*t
));
241 for(i
= 0; i
< (sizeof(t
->dn_dev_vars
)/sizeof(t
->dn_dev_vars
[0]) - 1); i
++) {
242 long offset
= (long)t
->dn_dev_vars
[i
].data
;
243 t
->dn_dev_vars
[i
].data
= ((char *)parms
) + offset
;
244 t
->dn_dev_vars
[i
].de
= NULL
;
248 t
->dn_dev_dev
[0].procname
= dev
->name
;
249 t
->dn_dev_dev
[0].ctl_name
= dev
->ifindex
;
251 t
->dn_dev_dev
[0].procname
= parms
->name
;
252 t
->dn_dev_dev
[0].ctl_name
= parms
->ctl_name
;
255 t
->dn_dev_dev
[0].child
= t
->dn_dev_vars
;
256 t
->dn_dev_dev
[0].de
= NULL
;
257 t
->dn_dev_conf_dir
[0].child
= t
->dn_dev_dev
;
258 t
->dn_dev_conf_dir
[0].de
= NULL
;
259 t
->dn_dev_proto_dir
[0].child
= t
->dn_dev_conf_dir
;
260 t
->dn_dev_proto_dir
[0].de
= NULL
;
261 t
->dn_dev_root_dir
[0].child
= t
->dn_dev_proto_dir
;
262 t
->dn_dev_root_dir
[0].de
= NULL
;
263 t
->dn_dev_vars
[0].extra1
= (void *)dev
;
265 t
->sysctl_header
= register_sysctl_table(t
->dn_dev_root_dir
, 0);
266 if (t
->sysctl_header
== NULL
)
272 static void dn_dev_sysctl_unregister(struct dn_dev_parms
*parms
)
275 struct dn_dev_sysctl_table
*t
= parms
->sysctl
;
276 parms
->sysctl
= NULL
;
277 unregister_sysctl_table(t
->sysctl_header
);
283 static int dn_forwarding_proc(ctl_table
*table
, int write
,
285 void *buffer
, size_t *lenp
)
287 #ifdef CONFIG_DECNET_ROUTER
288 struct net_device
*dev
= table
->extra1
;
289 struct dn_dev
*dn_db
;
293 if (table
->extra1
== NULL
)
297 old
= dn_db
->parms
.forwarding
;
299 err
= proc_dointvec(table
, write
, filep
, buffer
, lenp
);
301 if ((err
>= 0) && write
) {
302 if (dn_db
->parms
.forwarding
< 0)
303 dn_db
->parms
.forwarding
= 0;
304 if (dn_db
->parms
.forwarding
> 2)
305 dn_db
->parms
.forwarding
= 2;
307 * What an ugly hack this is... its works, just. It
308 * would be nice if sysctl/proc were just that little
309 * bit more flexible so I don't have to write a special
310 * routine, or suffer hacks like this - SJW
312 tmp
= dn_db
->parms
.forwarding
;
313 dn_db
->parms
.forwarding
= old
;
314 if (dn_db
->parms
.down
)
315 dn_db
->parms
.down(dev
);
316 dn_db
->parms
.forwarding
= tmp
;
318 dn_db
->parms
.up(dev
);
327 static int dn_forwarding_sysctl(ctl_table
*table
, int *name
, int nlen
,
328 void *oldval
, size_t *oldlenp
,
329 void *newval
, size_t newlen
,
332 #ifdef CONFIG_DECNET_ROUTER
333 struct net_device
*dev
= table
->extra1
;
334 struct dn_dev
*dn_db
;
337 if (table
->extra1
== NULL
)
342 if (newval
&& newlen
) {
343 if (newlen
!= sizeof(int))
346 get_user(value
, (int *)newval
);
352 if (dn_db
->parms
.down
)
353 dn_db
->parms
.down(dev
);
354 dn_db
->parms
.forwarding
= value
;
356 dn_db
->parms
.up(dev
);
365 #else /* CONFIG_SYSCTL */
366 static void dn_dev_sysctl_unregister(struct dn_dev_parms
*parms
)
369 static void dn_dev_sysctl_register(struct net_device
*dev
, struct dn_dev_parms
*parms
)
373 #endif /* CONFIG_SYSCTL */
375 static struct dn_ifaddr
*dn_dev_alloc_ifa(void)
377 struct dn_ifaddr
*ifa
;
379 ifa
= kmalloc(sizeof(*ifa
), GFP_KERNEL
);
382 memset(ifa
, 0, sizeof(*ifa
));
388 static __inline__
void dn_dev_free_ifa(struct dn_ifaddr
*ifa
)
390 kfree_s(ifa
, sizeof(*ifa
));
393 static void dn_dev_del_ifa(struct dn_dev
*dn_db
, struct dn_ifaddr
**ifap
, int destroy
)
395 struct dn_ifaddr
*ifa1
= *ifap
;
397 *ifap
= ifa1
->ifa_next
;
399 #ifdef CONFIG_RTNETLINK
400 rtmsg_ifa(RTM_DELADDR
, ifa1
);
401 #endif /* CONFIG_RTNETLINK */
404 dn_dev_free_ifa(ifa1
);
406 if (dn_db
->ifa_list
== NULL
)
407 dn_dev_delete(dn_db
->dev
);
411 static int dn_dev_insert_ifa(struct dn_dev
*dn_db
, struct dn_ifaddr
*ifa
)
414 * FIXME: Duplicate check here.
417 ifa
->ifa_next
= dn_db
->ifa_list
;
418 dn_db
->ifa_list
= ifa
;
420 #ifdef CONFIG_RTNETLINK
421 rtmsg_ifa(RTM_NEWADDR
, ifa
);
422 #endif /* CONFIG_RTNETLINK */
427 static int dn_dev_set_ifa(struct net_device
*dev
, struct dn_ifaddr
*ifa
)
429 struct dn_dev
*dn_db
= dev
->dn_ptr
;
433 dn_db
= dn_dev_create(dev
, &err
);
438 ifa
->ifa_dev
= dn_db
;
440 if (dev
->flags
& IFF_LOOPBACK
)
441 ifa
->ifa_scope
= RT_SCOPE_HOST
;
443 return dn_dev_insert_ifa(dn_db
, ifa
);
447 int dn_dev_ioctl(unsigned int cmd
, void *arg
)
449 char buffer
[DN_IFREQ_SIZE
];
450 struct ifreq
*ifr
= (struct ifreq
*)buffer
;
451 struct sockaddr_dn
*sdn
= (struct sockaddr_dn
*)&ifr
->ifr_addr
;
452 struct dn_dev
*dn_db
;
453 struct net_device
*dev
;
454 struct dn_ifaddr
*ifa
= NULL
, **ifap
= NULL
;
458 if (copy_from_user(ifr
, arg
, DN_IFREQ_SIZE
))
460 ifr
->ifr_name
[IFNAMSIZ
-1] = 0;
463 dev_load(ifr
->ifr_name
);
470 if (!capable(CAP_NET_ADMIN
))
472 if (sdn
->sdn_family
!= AF_DECnet
)
481 if ((dev
= __dev_get_by_name(ifr
->ifr_name
)) == NULL
) {
486 if ((dn_db
= dev
->dn_ptr
) != NULL
) {
487 for (ifap
= &dn_db
->ifa_list
; (ifa
=*ifap
) != NULL
; ifap
= &ifa
->ifa_next
)
488 if (strcmp(ifr
->ifr_name
, ifa
->ifa_label
) == 0)
492 if (ifa
== NULL
&& cmd
!= SIOCSIFADDR
) {
493 ret
= -EADDRNOTAVAIL
;
499 *((dn_address
*)sdn
->sdn_nodeaddr
) = ifa
->ifa_local
;
504 if ((ifa
= dn_dev_alloc_ifa()) == NULL
) {
508 memcpy(ifa
->ifa_label
, dev
->name
, IFNAMSIZ
);
510 if (ifa
->ifa_local
== dn_saddr2dn(sdn
))
512 dn_dev_del_ifa(dn_db
, ifap
, 0);
515 ifa
->ifa_local
= dn_saddr2dn(sdn
);
517 ret
= dn_dev_set_ifa(dev
, ifa
);
525 if (copy_to_user(arg
, ifr
, DN_IFREQ_SIZE
))
531 #ifdef CONFIG_RTNETLINK
532 static struct dn_dev
*dn_dev_by_index(int ifindex
)
534 struct net_device
*dev
;
535 struct dn_dev
*dn_dev
= NULL
;
536 dev
= dev_get_by_index(ifindex
);
538 dn_dev
= dev
->dn_ptr
;
545 static int dn_dev_rtm_deladdr(struct sk_buff
*skb
, struct nlmsghdr
*nlh
, void *arg
)
547 struct rtattr
**rta
= arg
;
548 struct dn_dev
*dn_db
;
549 struct ifaddrmsg
*ifm
= NLMSG_DATA(nlh
);
550 struct dn_ifaddr
*ifa
, **ifap
;
552 if ((dn_db
= dn_dev_by_index(ifm
->ifa_index
)) == NULL
)
553 return -EADDRNOTAVAIL
;
555 for(ifap
= &dn_db
->ifa_list
; (ifa
=*ifap
) != NULL
; ifap
= &ifa
->ifa_next
) {
556 void *tmp
= rta
[IFA_LOCAL
-1];
557 if ((tmp
&& memcmp(RTA_DATA(tmp
), &ifa
->ifa_local
, 2)) ||
558 (rta
[IFA_LABEL
-1] && strcmp(RTA_DATA(rta
[IFA_LABEL
-1]), ifa
->ifa_label
)))
561 dn_dev_del_ifa(dn_db
, ifap
, 1);
565 return -EADDRNOTAVAIL
;
568 static int dn_dev_rtm_newaddr(struct sk_buff
*skb
, struct nlmsghdr
*nlh
, void *arg
)
570 struct rtattr
**rta
= arg
;
571 struct net_device
*dev
;
572 struct dn_dev
*dn_db
;
573 struct ifaddrmsg
*ifm
= NLMSG_DATA(nlh
);
574 struct dn_ifaddr
*ifa
;
576 if (rta
[IFA_LOCAL
-1] == NULL
)
579 if ((dev
= __dev_get_by_index(ifm
->ifa_index
)) == NULL
)
582 if ((dn_db
= dev
->dn_ptr
) == NULL
) {
584 dn_db
= dn_dev_create(dev
, &err
);
589 if ((ifa
= dn_dev_alloc_ifa()) == NULL
)
592 memcpy(&ifa
->ifa_local
, RTA_DATA(rta
[IFA_LOCAL
-1]), 2);
593 ifa
->ifa_flags
= ifm
->ifa_flags
;
594 ifa
->ifa_scope
= ifm
->ifa_scope
;
595 ifa
->ifa_dev
= dn_db
;
596 if (rta
[IFA_LABEL
-1])
597 memcpy(ifa
->ifa_label
, RTA_DATA(rta
[IFA_LABEL
-1]), IFNAMSIZ
);
599 memcpy(ifa
->ifa_label
, dev
->name
, IFNAMSIZ
);
601 return dn_dev_insert_ifa(dn_db
, ifa
);
604 static int dn_dev_fill_ifaddr(struct sk_buff
*skb
, struct dn_ifaddr
*ifa
,
605 u32 pid
, u32 seq
, int event
)
607 struct ifaddrmsg
*ifm
;
608 struct nlmsghdr
*nlh
;
609 unsigned char *b
= skb
->tail
;
611 nlh
= NLMSG_PUT(skb
, pid
, seq
, event
, sizeof(*ifm
));
612 ifm
= NLMSG_DATA(nlh
);
614 ifm
->ifa_family
= AF_DECnet
;
615 ifm
->ifa_prefixlen
= 16;
616 ifm
->ifa_flags
= ifa
->ifa_flags
| IFA_F_PERMANENT
;
617 ifm
->ifa_scope
= ifa
->ifa_scope
;
618 ifm
->ifa_index
= ifa
->ifa_dev
->dev
->ifindex
;
619 RTA_PUT(skb
, IFA_LOCAL
, 2, &ifa
->ifa_local
);
620 if (ifa
->ifa_label
[0])
621 RTA_PUT(skb
, IFA_LABEL
, IFNAMSIZ
, &ifa
->ifa_label
);
622 nlh
->nlmsg_len
= skb
->tail
- b
;
627 skb_trim(skb
, b
- skb
->data
);
631 static void rtmsg_ifa(int event
, struct dn_ifaddr
*ifa
)
634 int size
= NLMSG_SPACE(sizeof(struct ifaddrmsg
)+128);
636 skb
= alloc_skb(size
, GFP_KERNEL
);
638 netlink_set_err(rtnl
, 0, RTMGRP_DECnet_IFADDR
, ENOBUFS
);
641 if (dn_dev_fill_ifaddr(skb
, ifa
, 0, 0, event
) < 0) {
643 netlink_set_err(rtnl
, 0, RTMGRP_DECnet_IFADDR
, EINVAL
);
646 NETLINK_CB(skb
).dst_groups
= RTMGRP_DECnet_IFADDR
;
647 netlink_broadcast(rtnl
, skb
, 0, RTMGRP_DECnet_IFADDR
, GFP_KERNEL
);
650 static int dn_dev_dump_ifaddr(struct sk_buff
*skb
, struct netlink_callback
*cb
)
654 struct net_device
*dev
;
655 struct dn_dev
*dn_db
;
656 struct dn_ifaddr
*ifa
;
659 s_dn_idx
= dn_idx
= cb
->args
[1];
660 read_lock(&dev_base_lock
);
661 for(dev
= dev_base
, idx
= 0; dev
; dev
= dev
->next
) {
662 if ((dn_db
= dev
->dn_ptr
) == NULL
)
669 if ((dn_db
= dev
->dn_ptr
) == NULL
)
672 for(ifa
= dn_db
->ifa_list
, dn_idx
= 0; ifa
; ifa
= ifa
->ifa_next
, dn_idx
++) {
673 if (dn_idx
< s_dn_idx
)
676 if (dn_dev_fill_ifaddr(skb
, ifa
, NETLINK_CB(cb
->skb
).pid
, cb
->nlh
->nlmsg_seq
, RTM_NEWADDR
) <= 0)
681 read_unlock(&dev_base_lock
);
683 cb
->args
[1] = dn_idx
;
688 #endif /* CONFIG_RTNETLINK */
690 static void dn_send_endnode_hello(struct net_device
*dev
)
692 struct endnode_hello_message
*msg
;
693 struct sk_buff
*skb
= NULL
;
694 unsigned short int *pktlen
;
695 struct dn_dev
*dn_db
= (struct dn_dev
*)dev
->dn_ptr
;
697 if ((skb
= dn_alloc_skb(NULL
, sizeof(*msg
), GFP_ATOMIC
)) == NULL
)
702 msg
= (struct endnode_hello_message
*)skb_put(skb
,sizeof(*msg
));
705 memcpy(msg
->tiver
, dn_eco_version
, 3);
706 memcpy(msg
->id
, decnet_ether_address
, 6);
707 msg
->iinfo
= DN_RT_INFO_ENDN
;
708 msg
->blksize
= dn_htons(dn_db
->parms
.blksize
);
710 memset(msg
->seed
, 0, 8);
711 memcpy(msg
->neighbor
, dn_hiord
, ETH_ALEN
);
714 struct dn_neigh
*dn
= (struct dn_neigh
*)dn_db
->router
;
715 dn_dn2eth(msg
->neighbor
, dn
->addr
);
718 msg
->timer
= dn_htons((unsigned short)dn_db
->parms
.t3
);
721 memset(msg
->data
, 0xAA, 2);
723 pktlen
= (unsigned short *)skb_push(skb
,2);
724 *pktlen
= dn_htons(skb
->len
- 2);
726 skb
->nh
.raw
= skb
->data
;
728 dn_rt_finish_output(skb
, dn_rt_all_rt_mcast
);
732 #ifdef CONFIG_DECNET_ROUTER
734 #define DRDELAY (5 * HZ)
736 static int dn_am_i_a_router(struct dn_neigh
*dn
, struct dn_dev
*dn_db
)
738 /* First check time since device went up */
739 if ((jiffies
- dn_db
->uptime
) < DRDELAY
)
742 /* If there is no router, then yes... */
746 /* otherwise only if we have a higher priority or.. */
747 if (dn
->priority
< dn_db
->parms
.priority
)
750 /* if we have equal priority and a higher node number */
751 if (dn
->priority
!= dn_db
->parms
.priority
)
754 if (dn_ntohs(dn
->addr
) < dn_ntohs(decnet_address
))
760 static void dn_send_router_hello(struct net_device
*dev
)
763 struct dn_dev
*dn_db
= dev
->dn_ptr
;
764 struct dn_neigh
*dn
= (struct dn_neigh
*)dn_db
->router
;
768 unsigned char *i1
, *i2
;
769 unsigned short *pktlen
;
771 if (dn_db
->parms
.blksize
< (26 + 7))
774 n
= dn_db
->parms
.blksize
- 26;
780 size
= 2 + 26 + 7 * n
;
782 if ((skb
= dn_alloc_skb(NULL
, size
, GFP_ATOMIC
)) == NULL
)
786 ptr
= skb_put(skb
, size
);
788 *ptr
++ = DN_RT_PKT_CNTL
| DN_RT_PKT_ERTH
;
789 *ptr
++ = 2; /* ECO */
792 memcpy(ptr
, decnet_ether_address
, ETH_ALEN
);
794 *ptr
++ = dn_db
->parms
.forwarding
== 1 ?
795 DN_RT_INFO_L1RT
: DN_RT_INFO_L2RT
;
796 *((unsigned short *)ptr
) = dn_htons(dn_db
->parms
.blksize
);
798 *ptr
++ = 0; /* Priority */
799 *ptr
++ = 0; /* Area: Reserved */
800 *((unsigned short *)ptr
) = dn_htons((unsigned short)dn_db
->parms
.t3
);
802 *ptr
++ = 0; /* MPD: Reserved */
804 memset(ptr
, 0, 7); /* Name: Reserved */
807 n
= dn_neigh_elist(dev
, ptr
, n
);
812 skb_trim(skb
, (26 + *i2
));
814 pktlen
= (unsigned short *)skb_push(skb
, 2);
815 *pktlen
= dn_htons(skb
->len
- 2);
817 skb
->nh
.raw
= skb
->data
;
819 if (dn_am_i_a_router(dn
, dn_db
)) {
820 struct sk_buff
*skb2
= skb_copy(skb
, GFP_ATOMIC
);
822 dn_rt_finish_output(skb2
, dn_rt_all_end_mcast
);
826 dn_rt_finish_output(skb
, dn_rt_all_rt_mcast
);
829 static void dn_send_brd_hello(struct net_device
*dev
)
831 struct dn_dev
*dn_db
= (struct dn_dev
*)dev
->dn_ptr
;
833 if (dn_db
->parms
.forwarding
== 0)
834 dn_send_endnode_hello(dev
);
836 dn_send_router_hello(dev
);
839 static void dn_send_brd_hello(struct net_device
*dev
)
841 dn_send_endnode_hello(dev
);
846 static void dn_send_ptp_hello(struct net_device
*dev
)
849 int size
= dev
->hard_header_len
+ 2 + 4 + tdlen
;
850 struct sk_buff
*skb
= dn_alloc_skb(NULL
, size
, GFP_ATOMIC
);
851 struct dn_dev
*dn_db
= dev
->dn_ptr
;
854 struct dn_neigh
*dn
= (struct dn_neigh
*)dn_db
->router
;
860 skb_push(skb
, dev
->hard_header_len
);
861 ptr
= skb_put(skb
, 2 + 4 + tdlen
);
863 *ptr
++ = DN_RT_PKT_HELO
;
864 *((dn_address
*)ptr
) = decnet_address
;
868 for(i
= 0; i
< tdlen
; i
++)
871 if (dn_am_i_a_router(dn
, dn_db
)) {
872 struct sk_buff
*skb2
= skb_copy(skb
, GFP_ATOMIC
);
874 dn_rt_finish_output(skb2
, dn_rt_all_end_mcast
);
878 dn_rt_finish_output(skb
, dn_rt_all_rt_mcast
);
882 static int dn_eth_up(struct net_device
*dev
)
884 struct dn_dev
*dn_db
= dev
->dn_ptr
;
886 if (dn_db
->parms
.forwarding
== 0)
887 dev_mc_add(dev
, dn_rt_all_end_mcast
, ETH_ALEN
, 0);
889 dev_mc_add(dev
, dn_rt_all_rt_mcast
, ETH_ALEN
, 0);
898 static void dn_dev_set_timer(struct net_device
*dev
);
900 static void dn_dev_timer_func(unsigned long arg
)
902 struct net_device
*dev
= (struct net_device
*)arg
;
903 struct dn_dev
*dn_db
= dev
->dn_ptr
;
905 if (dn_db
->t3
<= dn_db
->parms
.t2
) {
906 if (dn_db
->parms
.timer3
)
907 dn_db
->parms
.timer3(dev
);
908 dn_db
->t3
= dn_db
->parms
.t3
;
910 dn_db
->t3
-= dn_db
->parms
.t2
;
913 dn_dev_set_timer(dev
);
916 static void dn_dev_set_timer(struct net_device
*dev
)
918 struct dn_dev
*dn_db
= dev
->dn_ptr
;
920 if (dn_db
->parms
.t2
> dn_db
->parms
.t3
)
921 dn_db
->parms
.t2
= dn_db
->parms
.t3
;
923 dn_db
->timer
.data
= (unsigned long)dev
;
924 dn_db
->timer
.function
= dn_dev_timer_func
;
925 dn_db
->timer
.expires
= jiffies
+ (dn_db
->parms
.t2
* HZ
);
927 add_timer(&dn_db
->timer
);
930 struct dn_dev
*dn_dev_create(struct net_device
*dev
, int *err
)
933 struct dn_dev_parms
*p
= dn_dev_list
;
934 struct dn_dev
*dn_db
;
936 for(i
= 0; i
< DN_DEV_LIST_SIZE
; i
++, p
++) {
937 if (p
->type
== dev
->type
)
942 if (i
== DN_DEV_LIST_SIZE
)
946 if ((dn_db
= kmalloc(sizeof(struct dn_dev
), GFP_ATOMIC
)) == NULL
)
949 memset(dn_db
, 0, sizeof(struct dn_dev
));
950 memcpy(&dn_db
->parms
, p
, sizeof(struct dn_dev_parms
));
953 init_timer(&dn_db
->timer
);
955 memcpy(dn_db
->addr
, decnet_ether_address
, ETH_ALEN
); /* To go... */
957 dn_db
->uptime
= jiffies
;
958 if (dn_db
->parms
.up
) {
959 if (dn_db
->parms
.up(dev
) < 0) {
966 dn_db
->neigh_parms
= neigh_parms_alloc(dev
, &dn_neigh_table
);
967 /* dn_db->neigh_parms->neigh_setup = dn_db->parms.neigh_setup; */
969 dn_dev_sysctl_register(dev
, &dn_db
->parms
);
971 dn_dev_set_timer(dev
);
979 * This processes a device up event. We only start up
980 * the loopback device & ethernet devices with correct
981 * MAC addreses automatically. Others must be started
984 void dn_dev_up(struct net_device
*dev
)
986 struct dn_ifaddr
*ifa
;
988 if ((dev
->type
!= ARPHRD_ETHER
) && (dev
->type
!= ARPHRD_LOOPBACK
))
991 if (dev
->type
== ARPHRD_ETHER
)
992 if (memcmp(dev
->dev_addr
, decnet_ether_address
, ETH_ALEN
) != 0)
995 if ((ifa
= dn_dev_alloc_ifa()) == NULL
)
998 ifa
->ifa_local
= decnet_address
;
1000 ifa
->ifa_scope
= RT_SCOPE_UNIVERSE
;
1001 strcpy(ifa
->ifa_label
, dev
->name
);
1003 dn_dev_set_ifa(dev
, ifa
);
1006 static void dn_dev_delete(struct net_device
*dev
)
1008 struct dn_dev
*dn_db
= dev
->dn_ptr
;
1013 del_timer(&dn_db
->timer
);
1016 dn_dev_sysctl_unregister(&dn_db
->parms
);
1018 neigh_ifdown(&dn_neigh_table
, dev
);
1020 if (dev
== decnet_default_device
)
1021 decnet_default_device
= NULL
;
1023 if (dn_db
->parms
.down
)
1024 dn_db
->parms
.down(dev
);
1028 neigh_parms_release(&dn_neigh_table
, dn_db
->neigh_parms
);
1031 neigh_release(dn_db
->router
);
1033 neigh_release(dn_db
->peer
);
1038 void dn_dev_down(struct net_device
*dev
)
1040 struct dn_dev
*dn_db
= dev
->dn_ptr
;
1041 struct dn_ifaddr
*ifa
;
1046 while((ifa
= dn_db
->ifa_list
) != NULL
) {
1047 dn_dev_del_ifa(dn_db
, &dn_db
->ifa_list
, 0);
1048 dn_dev_free_ifa(ifa
);
1054 void dn_dev_init_pkt(struct sk_buff
*skb
)
1059 void dn_dev_veri_pkt(struct sk_buff
*skb
)
1064 void dn_dev_hello(struct sk_buff
*skb
)
1069 void dn_dev_devices_off(void)
1071 struct net_device
*dev
;
1073 for(dev
= dev_base
; dev
; dev
= dev
->next
)
1078 void dn_dev_devices_on(void)
1080 struct net_device
*dev
;
1082 for(dev
= dev_base
; dev
; dev
= dev
->next
) {
1083 if (dev
->flags
& IFF_UP
)
1089 #ifdef CONFIG_DECNET_SIOCGIFCONF
1091 * Now we support multiple addresses per interface.
1092 * Since we don't want to break existing code, you have to enable
1093 * it as a compile time option. Probably you should use the
1094 * rtnetlink interface instead.
1096 int dnet_gifconf(struct net_device
*dev
, char *buf
, int len
)
1098 struct dn_dev
*dn_db
= (struct dn_dev
*)dev
->dn_ptr
;
1099 struct dn_ifaddr
*ifa
;
1100 struct ifreq
*ifr
= (struct ifreq
*)buf
;
1103 if ((dn_db
== NULL
) || ((ifa
= dn_db
->ifa_list
) == NULL
))
1106 for(; ifa
; ifa
= ifa
->ifa_next
) {
1108 done
+= sizeof(DN_IFREQ_SIZE
);
1111 if (len
< DN_IFREQ_SIZE
)
1113 memset(ifr
, 0, DN_IFREQ_SIZE
);
1116 strcpy(ifr
->ifr_name
, ifa
->ifa_label
);
1118 strcpy(ifr
->ifr_name
, dev
->name
);
1120 (*(struct sockaddr_dn
*) &ifr
->ifr_addr
).sdn_family
= AF_DECnet
;
1121 (*(struct sockaddr_dn
*) &ifr
->ifr_addr
).sdn_add
.a_len
= 2;
1122 (*(dn_address
*)(*(struct sockaddr_dn
*) &ifr
->ifr_addr
).sdn_add
.a_addr
) = ifa
->ifa_local
;
1124 ifr
= (struct ifreq
*)((char *)ifr
+ DN_IFREQ_SIZE
);
1125 len
-= DN_IFREQ_SIZE
;
1126 done
+= DN_IFREQ_SIZE
;
1131 #endif /* CONFIG_DECNET_SIOCGIFCONF */
1134 #ifdef CONFIG_PROC_FS
1136 static char *dn_type2asc(char type
)
1150 static int decnet_dev_get_info(char *buffer
, char **start
, off_t offset
, int length
)
1152 struct dn_dev
*dn_db
;
1153 struct net_device
*dev
;
1157 char peer_buf
[DN_ASCBUF_LEN
];
1158 char router_buf
[DN_ASCBUF_LEN
];
1161 len
+= sprintf(buffer
, "Name Flags T1 Timer1 T3 Timer3 BlkSize Pri State DevType Router Peer\n");
1163 read_lock(&dev_base_lock
);
1164 for (dev
= dev_base
; dev
; dev
= dev
->next
) {
1165 if ((dn_db
= (struct dn_dev
*)dev
->dn_ptr
) == NULL
)
1168 len
+= sprintf(buffer
+ len
, "%-8s %1s %04u %04u %04lu %04lu %04hu %03d %02x %-10s %-7s %-7s\n",
1169 dev
->name
? dev
->name
: "???",
1170 dn_type2asc(dn_db
->parms
.mode
),
1172 dn_db
->t3
, dn_db
->parms
.t3
,
1173 dn_db
->parms
.blksize
,
1174 dn_db
->parms
.priority
,
1175 dn_db
->parms
.state
, dn_db
->parms
.name
,
1176 dn_db
->router
? dn_addr2asc(dn_eth2dn(dn_db
->router
->primary_key
), router_buf
) : "",
1177 dn_db
->peer
? dn_addr2asc(dn_eth2dn(dn_db
->peer
->primary_key
), peer_buf
) : "");
1186 if (pos
> offset
+ length
)
1190 read_unlock(&dev_base_lock
);
1192 *start
= buffer
+ (offset
- begin
);
1193 len
-= (offset
- begin
);
1195 if (len
> length
) len
= length
;
1200 #endif /* CONFIG_PROC_FS */
1202 #ifdef CONFIG_RTNETLINK
1203 static struct rtnetlink_link dnet_rtnetlink_table
[RTM_MAX
-RTM_BASE
+1] =
1210 { dn_dev_rtm_newaddr
, NULL
, },
1211 { dn_dev_rtm_deladdr
, NULL
, },
1212 { NULL
, dn_dev_dump_ifaddr
, },
1215 #ifdef CONFIG_DECNET_ROUTER
1216 { dn_fib_rtm_newroute
, NULL
, },
1217 { dn_fib_rtm_delroute
, NULL
, },
1218 { dn_cache_getroute
, dn_fib_dump
, },
1223 { dn_cache_getroute
, dn_cache_dump
, },
1231 #ifdef CONFIG_DECNET_ROUTER
1232 { dn_fib_rtm_newrule
, NULL
, },
1233 { dn_fib_rtm_delrule
, NULL
, },
1234 { NULL
, dn_fib_dump_rules
, },
1243 #endif /* CONFIG_RTNETLINK */
1245 void __init
dn_dev_init(void)
1248 dn_dev_devices_on();
1249 #ifdef CONFIG_DECNET_SIOCGIFCONF
1250 register_gifconf(PF_DECnet
, dnet_gifconf
);
1251 #endif /* CONFIG_DECNET_SIOCGIFCONF */
1253 #ifdef CONFIG_RTNETLINK
1254 rtnetlink_links
[PF_DECnet
] = dnet_rtnetlink_table
;
1255 #endif /* CONFIG_RTNETLINK */
1257 #ifdef CONFIG_PROC_FS
1258 proc_net_create("decnet_dev", 0, decnet_dev_get_info
);
1259 #endif /* CONFIG_PROC_FS */
1261 #ifdef CONFIG_SYSCTL
1264 for(i
= 0; i
< DN_DEV_LIST_SIZE
; i
++)
1265 dn_dev_sysctl_register(NULL
, &dn_dev_list
[i
]);
1267 #endif /* CONFIG_SYSCTL */
1270 void __exit
dn_dev_cleanup(void)
1272 #ifdef CONFIG_RTNETLINK
1273 rtnetlink_links
[PF_DECnet
] = NULL
;
1274 #endif /* CONFIG_RTNETLINK */
1276 #ifdef CONFIG_DECNET_SIOCGIFCONF
1277 unregister_gifconf(PF_DECnet
);
1278 #endif /* CONFIG_DECNET_SIOCGIFCONF */
1280 #ifdef CONFIG_SYSCTL
1283 for(i
= 0; i
< DN_DEV_LIST_SIZE
; i
++)
1284 dn_dev_sysctl_unregister(&dn_dev_list
[i
]);
1286 #endif /* CONFIG_SYSCTL */
1288 #ifdef CONFIG_PROC_FS
1289 proc_net_remove("decnet_dev");
1290 #endif /* CONFIG_PROC_FS */
1292 dn_dev_devices_off();