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
22 #include <linux/config.h>
23 #include <linux/net.h>
24 #include <linux/netdevice.h>
25 #include <linux/proc_fs.h>
26 #include <linux/timer.h>
27 #include <linux/string.h>
28 #include <linux/if_arp.h>
29 #include <linux/if_ether.h>
30 #include <linux/init.h>
31 #include <linux/skbuff.h>
32 #include <linux/rtnetlink.h>
33 #include <linux/sysctl.h>
34 #include <asm/uaccess.h>
35 #include <net/neighbour.h>
38 #include <net/dn_dev.h>
39 #include <net/dn_route.h>
40 #include <net/dn_neigh.h>
41 #include <net/dn_fib.h>
43 #define DN_IFREQ_SIZE (sizeof(struct ifreq) - sizeof(struct sockaddr) + sizeof(struct sockaddr_dn))
45 static char dn_rt_all_end_mcast
[ETH_ALEN
] = {0xAB,0x00,0x00,0x04,0x00,0x00};
46 static char dn_rt_all_rt_mcast
[ETH_ALEN
] = {0xAB,0x00,0x00,0x03,0x00,0x00};
47 static char dn_hiord
[ETH_ALEN
] = {0xAA,0x00,0x04,0x00,0x00,0x00};
48 static unsigned char dn_eco_version
[3] = {0x02,0x00,0x00};
50 extern struct neigh_table dn_neigh_table
;
52 struct net_device
*decnet_default_device
= NULL
;
54 static struct dn_dev
*dn_dev_create(struct net_device
*dev
, int *err
);
55 static void dn_dev_delete(struct net_device
*dev
);
56 #ifdef CONFIG_RTNETLINK
57 static void rtmsg_ifa(int event
, struct dn_ifaddr
*ifa
);
60 static int dn_eth_up(struct net_device
*);
61 static void dn_send_brd_hello(struct net_device
*dev
);
62 static void dn_send_ptp_hello(struct net_device
*dev
);
64 static struct dn_dev_parms dn_dev_list
[] = {
66 ARPHRD_ETHER
, /* Ethernet */
76 NET_DECNET_CONF_ETHER
,
84 ARPHRD_IPGRE
, /* DECnet tunneled over GRE in IP */
103 ARPHRD_X25
, /* Bog standard X.25 */
123 ARPHRD_PPP
, /* DECnet over PPP */
143 ARPHRD_DDCMP
, /* DECnet over DDCMP */
153 NET_DECNET_CONF_DDCMP
,
162 ARPHRD_LOOPBACK
, /* Loopback interface - always last */
172 NET_DECNET_CONF_LOOPBACK
,
181 #define DN_DEV_LIST_SIZE (sizeof(dn_dev_list)/sizeof(struct dn_dev_parms))
183 #define DN_DEV_PARMS_OFFSET(x) ((int) ((char *) &((struct dn_dev_parms *)0)->x))
187 static int min_t2
[] = { 1 };
188 static int max_t2
[] = { 60 }; /* No max specified, but this seems sensible */
189 static int min_t3
[] = { 1 };
190 static int max_t3
[] = { 8191 }; /* Must fit in 16 bits when multiplied by BCT3MULT or T3MULT */
191 #ifdef CONFIG_DECNET_ROUTER
192 static int min_t1
[] = { 1 };
193 static int max_t1
[] = { 8191 }; /* No max specified, so made it the same as t3 */
194 static int min_cost
[] = { 0 };
195 static int max_cost
[] = { 25 }; /* From DECnet spec */
196 static int min_priority
[] = { 0 };
197 static int max_priority
[] = { 127 }; /* From DECnet spec */
198 #endif /* CONFIG_DECNET_ROUTER */
200 static struct dn_dev_sysctl_table
{
201 struct ctl_table_header
*sysctl_header
;
202 #ifdef CONFIG_DECNET_ROUTER
203 ctl_table dn_dev_vars
[6];
205 ctl_table dn_dev_vars
[3];
207 ctl_table dn_dev_dev
[2];
208 ctl_table dn_dev_conf_dir
[2];
209 ctl_table dn_dev_proto_dir
[2];
210 ctl_table dn_dev_root_dir
[2];
214 #ifdef CONFIG_DECNET_ROUTER
215 {NET_DECNET_CONF_DEV_COST
, "cost", (void *)DN_DEV_PARMS_OFFSET(cost
),
216 sizeof(int), 0644, NULL
,
217 proc_dointvec_minmax
, sysctl_intvec
,
218 NULL
, &min_cost
, &max_cost
},
219 {NET_DECNET_CONF_DEV_PRIORITY
, "priority", (void *)DN_DEV_PARMS_OFFSET(priority
),
220 sizeof(int), 0644, NULL
,
221 proc_dointvec_minmax
, sysctl_intvec
,
222 NULL
, &min_priority
, &max_priority
},
223 {NET_DECNET_CONF_DEV_T1
, "t1", (void *)DN_DEV_PARMS_OFFSET(t1
),
224 sizeof(int), 0644, NULL
,
225 proc_dointvec_minmax
, sysctl_intvec
,
226 NULL
, &min_t1
, &max_t1
},
228 {NET_DECNET_CONF_DEV_T2
, "t2", (void *)DN_DEV_PARMS_OFFSET(t2
),
229 sizeof(int), 0644, NULL
,
230 proc_dointvec_minmax
, sysctl_intvec
,
231 NULL
, &min_t2
, &max_t2
},
232 {NET_DECNET_CONF_DEV_T3
, "t3", (void *)DN_DEV_PARMS_OFFSET(t3
),
233 sizeof(int), 0644, NULL
,
234 proc_dointvec_minmax
, sysctl_intvec
,
235 NULL
, &min_t3
, &max_t3
},
238 {{0, "", NULL
, 0, 0555, dn_dev_sysctl
.dn_dev_vars
}, {0}},
239 {{NET_DECNET_CONF
, "conf", NULL
, 0, 0555, dn_dev_sysctl
.dn_dev_dev
}, {0}},
240 {{NET_DECNET
, "decnet", NULL
, 0, 0555, dn_dev_sysctl
.dn_dev_conf_dir
}, {0}},
241 {{CTL_NET
, "net", NULL
, 0, 0555, dn_dev_sysctl
.dn_dev_proto_dir
}, {0}}
244 static void dn_dev_sysctl_register(struct net_device
*dev
, struct dn_dev_parms
*parms
)
246 struct dn_dev_sysctl_table
*t
;
249 t
= kmalloc(sizeof(*t
), GFP_KERNEL
);
253 memcpy(t
, &dn_dev_sysctl
, sizeof(*t
));
255 for(i
= 0; i
< (sizeof(t
->dn_dev_vars
)/sizeof(t
->dn_dev_vars
[0]) - 1); i
++) {
256 long offset
= (long)t
->dn_dev_vars
[i
].data
;
257 t
->dn_dev_vars
[i
].data
= ((char *)parms
) + offset
;
258 t
->dn_dev_vars
[i
].de
= NULL
;
262 t
->dn_dev_dev
[0].procname
= dev
->name
;
263 t
->dn_dev_dev
[0].ctl_name
= dev
->ifindex
;
265 t
->dn_dev_dev
[0].procname
= parms
->name
;
266 t
->dn_dev_dev
[0].ctl_name
= parms
->ctl_name
;
269 t
->dn_dev_dev
[0].child
= t
->dn_dev_vars
;
270 t
->dn_dev_dev
[0].de
= NULL
;
271 t
->dn_dev_conf_dir
[0].child
= t
->dn_dev_dev
;
272 t
->dn_dev_conf_dir
[0].de
= NULL
;
273 t
->dn_dev_proto_dir
[0].child
= t
->dn_dev_conf_dir
;
274 t
->dn_dev_proto_dir
[0].de
= NULL
;
275 t
->dn_dev_root_dir
[0].child
= t
->dn_dev_proto_dir
;
276 t
->dn_dev_root_dir
[0].de
= NULL
;
278 t
->sysctl_header
= register_sysctl_table(t
->dn_dev_root_dir
, 0);
279 if (t
->sysctl_header
== NULL
)
285 static void dn_dev_sysctl_unregister(struct dn_dev_parms
*parms
)
288 struct dn_dev_sysctl_table
*t
= parms
->sysctl
;
289 parms
->sysctl
= NULL
;
290 unregister_sysctl_table(t
->sysctl_header
);
296 static struct dn_ifaddr
*dn_dev_alloc_ifa(void)
298 struct dn_ifaddr
*ifa
;
300 ifa
= kmalloc(sizeof(*ifa
), GFP_KERNEL
);
303 memset(ifa
, 0, sizeof(*ifa
));
309 static __inline__
void dn_dev_free_ifa(struct dn_ifaddr
*ifa
)
311 kfree_s(ifa
, sizeof(*ifa
));
314 static void dn_dev_del_ifa(struct dn_dev
*dn_db
, struct dn_ifaddr
**ifap
, int destroy
)
316 struct dn_ifaddr
*ifa1
= *ifap
;
318 *ifap
= ifa1
->ifa_next
;
320 #ifdef CONFIG_RTNETLINK
321 rtmsg_ifa(RTM_DELADDR
, ifa1
);
322 #endif /* CONFIG_RTNETLINK */
325 dn_dev_free_ifa(ifa1
);
327 if (dn_db
->ifa_list
== NULL
)
328 dn_dev_delete(dn_db
->dev
);
332 static int dn_dev_insert_ifa(struct dn_dev
*dn_db
, struct dn_ifaddr
*ifa
)
335 * FIXME: Duplicate check here.
338 ifa
->ifa_next
= dn_db
->ifa_list
;
339 dn_db
->ifa_list
= ifa
;
341 #ifdef CONFIG_RTNETLINK
342 rtmsg_ifa(RTM_NEWADDR
, ifa
);
343 #endif /* CONFIG_RTNETLINK */
348 static int dn_dev_set_ifa(struct net_device
*dev
, struct dn_ifaddr
*ifa
)
350 struct dn_dev
*dn_db
= dev
->dn_ptr
;
354 dn_db
= dn_dev_create(dev
, &err
);
359 ifa
->ifa_dev
= dn_db
;
361 if (dev
->flags
& IFF_LOOPBACK
)
362 ifa
->ifa_scope
= RT_SCOPE_HOST
;
364 return dn_dev_insert_ifa(dn_db
, ifa
);
367 static struct dn_dev
*dn_dev_by_index(int ifindex
)
369 struct net_device
*dev
;
370 struct dn_dev
*dn_dev
= NULL
;
371 dev
= dev_get_by_index(ifindex
);
373 dn_dev
= dev
->dn_ptr
;
381 int dn_dev_ioctl(unsigned int cmd
, void *arg
)
383 char buffer
[DN_IFREQ_SIZE
];
384 struct ifreq
*ifr
= (struct ifreq
*)buffer
;
385 struct sockaddr_dn
*sdn
= (struct sockaddr_dn
*)&ifr
->ifr_addr
;
386 struct dn_dev
*dn_db
;
387 struct net_device
*dev
;
388 struct dn_ifaddr
*ifa
= NULL
, **ifap
= NULL
;
392 if (copy_from_user(ifr
, arg
, DN_IFREQ_SIZE
))
394 ifr
->ifr_name
[IFNAMSIZ
-1] = 0;
397 dev_load(ifr
->ifr_name
);
404 if (!capable(CAP_NET_ADMIN
))
406 if (sdn
->sdn_family
!= AF_DECnet
)
415 if ((dev
= __dev_get_by_name(ifr
->ifr_name
)) == NULL
) {
420 if ((dn_db
= dev
->dn_ptr
) != NULL
) {
421 for (ifap
= &dn_db
->ifa_list
; (ifa
=*ifap
) != NULL
; ifap
= &ifa
->ifa_next
)
422 if (strcmp(ifr
->ifr_name
, ifa
->ifa_label
) == 0)
426 if (ifa
== NULL
&& cmd
!= SIOCSIFADDR
) {
427 ret
= -EADDRNOTAVAIL
;
433 *((dn_address
*)sdn
->sdn_nodeaddr
) = ifa
->ifa_local
;
438 if ((ifa
= dn_dev_alloc_ifa()) == NULL
) {
442 memcpy(ifa
->ifa_label
, dev
->name
, IFNAMSIZ
);
444 if (ifa
->ifa_local
== dn_saddr2dn(sdn
))
446 dn_dev_del_ifa(dn_db
, ifap
, 0);
449 ifa
->ifa_local
= dn_saddr2dn(sdn
);
451 ret
= dn_dev_set_ifa(dev
, ifa
);
459 if (copy_to_user(arg
, ifr
, DN_IFREQ_SIZE
))
465 #ifdef CONFIG_RTNETLINK
467 static int dn_dev_rtm_deladdr(struct sk_buff
*skb
, struct nlmsghdr
*nlh
, void *arg
)
469 struct rtattr
**rta
= arg
;
470 struct dn_dev
*dn_db
;
471 struct ifaddrmsg
*ifm
= NLMSG_DATA(nlh
);
472 struct dn_ifaddr
*ifa
, **ifap
;
474 if ((dn_db
= dn_dev_by_index(ifm
->ifa_index
)) == NULL
)
475 return -EADDRNOTAVAIL
;
477 for(ifap
= &dn_db
->ifa_list
; (ifa
=*ifap
) != NULL
; ifap
= &ifa
->ifa_next
) {
478 void *tmp
= rta
[IFA_LOCAL
-1];
479 if ((tmp
&& memcmp(RTA_DATA(tmp
), &ifa
->ifa_local
, 2)) ||
480 (rta
[IFA_LABEL
-1] && strcmp(RTA_DATA(rta
[IFA_LABEL
-1]), ifa
->ifa_label
)))
483 dn_dev_del_ifa(dn_db
, ifap
, 1);
487 return -EADDRNOTAVAIL
;
490 static int dn_dev_rtm_newaddr(struct sk_buff
*skb
, struct nlmsghdr
*nlh
, void *arg
)
492 struct rtattr
**rta
= arg
;
493 struct net_device
*dev
;
494 struct dn_dev
*dn_db
;
495 struct ifaddrmsg
*ifm
= NLMSG_DATA(nlh
);
496 struct dn_ifaddr
*ifa
;
498 if (rta
[IFA_LOCAL
-1] == NULL
)
501 if ((dev
= __dev_get_by_index(ifm
->ifa_index
)) == NULL
)
504 if ((dn_db
= dev
->dn_ptr
) == NULL
) {
506 dn_db
= dn_dev_create(dev
, &err
);
511 if ((ifa
= dn_dev_alloc_ifa()) == NULL
)
514 memcpy(&ifa
->ifa_local
, RTA_DATA(rta
[IFA_LOCAL
-1]), 2);
515 ifa
->ifa_flags
= ifm
->ifa_flags
;
516 ifa
->ifa_scope
= ifm
->ifa_scope
;
517 ifa
->ifa_dev
= dn_db
;
518 if (rta
[IFA_LABEL
-1])
519 memcpy(ifa
->ifa_label
, RTA_DATA(rta
[IFA_LABEL
-1]), IFNAMSIZ
);
521 memcpy(ifa
->ifa_label
, dev
->name
, IFNAMSIZ
);
523 return dn_dev_insert_ifa(dn_db
, ifa
);
526 static int dn_dev_fill_ifaddr(struct sk_buff
*skb
, struct dn_ifaddr
*ifa
,
527 u32 pid
, u32 seq
, int event
)
529 struct ifaddrmsg
*ifm
;
530 struct nlmsghdr
*nlh
;
531 unsigned char *b
= skb
->tail
;
533 nlh
= NLMSG_PUT(skb
, pid
, seq
, event
, sizeof(*ifm
));
534 ifm
= NLMSG_DATA(nlh
);
536 ifm
->ifa_family
= AF_DECnet
;
537 ifm
->ifa_prefixlen
= 16;
538 ifm
->ifa_flags
= ifa
->ifa_flags
| IFA_F_PERMANENT
;
539 ifm
->ifa_scope
= ifa
->ifa_scope
;
540 ifm
->ifa_index
= ifa
->ifa_dev
->dev
->ifindex
;
541 RTA_PUT(skb
, IFA_LOCAL
, 2, &ifa
->ifa_local
);
542 if (ifa
->ifa_label
[0])
543 RTA_PUT(skb
, IFA_LABEL
, IFNAMSIZ
, &ifa
->ifa_label
);
544 nlh
->nlmsg_len
= skb
->tail
- b
;
549 skb_trim(skb
, b
- skb
->data
);
553 static void rtmsg_ifa(int event
, struct dn_ifaddr
*ifa
)
556 int size
= NLMSG_SPACE(sizeof(struct ifaddrmsg
)+128);
558 skb
= alloc_skb(size
, GFP_KERNEL
);
560 netlink_set_err(rtnl
, 0, RTMGRP_DECnet_IFADDR
, ENOBUFS
);
563 if (dn_dev_fill_ifaddr(skb
, ifa
, 0, 0, event
) < 0) {
565 netlink_set_err(rtnl
, 0, RTMGRP_DECnet_IFADDR
, EINVAL
);
568 NETLINK_CB(skb
).dst_groups
= RTMGRP_DECnet_IFADDR
;
569 netlink_broadcast(rtnl
, skb
, 0, RTMGRP_DECnet_IFADDR
, GFP_KERNEL
);
572 static int dn_dev_fill_ifinfo(struct sk_buff
*skb
, struct net_device
*dev
,
573 int type
, u32 pid
, u32 seq
)
576 struct nlmsghdr
*nlh
;
577 unsigned char *b
= skb
->tail
;
578 struct dn_dev
*dn_db
= (struct dn_dev
*)dev
->dn_ptr
;
579 unsigned char priority
= dn_db
->parms
.priority
;
580 unsigned short cost
= dn_db
->parms
.cost
;
582 nlh
= NLMSG_PUT(skb
, pid
, seq
, type
, sizeof(*r
));
583 if (pid
) nlh
->nlmsg_flags
|= NLM_F_MULTI
;
586 r
->ifi_family
= AF_DECnet
;
587 r
->ifi_type
= dev
->type
;
588 r
->ifi_index
= dev
->ifindex
;
589 r
->ifi_flags
= dev
->flags
;
592 RTA_PUT(skb
, IFLA_IFNAME
, strlen(dev
->name
)+1, dev
->name
);
593 RTA_PUT(skb
, IFLA_COST
, sizeof(unsigned short), &cost
);
594 RTA_PUT(skb
, IFLA_PRIORITY
, sizeof(unsigned char), &priority
);
596 nlh
->nlmsg_len
= skb
->tail
- b
;
601 skb_trim(skb
, b
- skb
->data
);
605 static int dn_dev_dump_ifaddr(struct sk_buff
*skb
, struct netlink_callback
*cb
)
609 struct net_device
*dev
;
610 struct dn_dev
*dn_db
;
611 struct dn_ifaddr
*ifa
;
614 s_dn_idx
= dn_idx
= cb
->args
[1];
615 read_lock(&dev_base_lock
);
616 for(dev
= dev_base
, idx
= 0; dev
; dev
= dev
->next
) {
617 if ((dn_db
= dev
->dn_ptr
) == NULL
)
624 if ((dn_db
= dev
->dn_ptr
) == NULL
)
627 for(ifa
= dn_db
->ifa_list
, dn_idx
= 0; ifa
; ifa
= ifa
->ifa_next
, dn_idx
++) {
628 if (dn_idx
< s_dn_idx
)
631 if (dn_dev_fill_ifaddr(skb
, ifa
, NETLINK_CB(cb
->skb
).pid
, cb
->nlh
->nlmsg_seq
, RTM_NEWADDR
) <= 0)
636 read_unlock(&dev_base_lock
);
638 cb
->args
[1] = dn_idx
;
643 static int dn_dev_dump_ifinfo(struct sk_buff
*skb
, struct netlink_callback
*cb
)
646 int s_idx
= cb
->args
[0];
647 struct net_device
*dev
;
649 read_lock(&dev_base_lock
);
650 for(dev
=dev_base
, idx
=0; dev
; dev
= dev
->next
) {
656 if (dn_dev_fill_ifinfo(skb
, dev
, RTM_NEWLINK
, NETLINK_CB(cb
->skb
).pid
, cb
->nlh
->nlmsg_seq
) <= 0)
659 read_unlock(&dev_base_lock
);
665 static void dn_dev_ifinfo(int type
, struct net_device
*dev
)
668 int size
= NLMSG_GOODSIZE
;
670 skb
= alloc_skb(size
, GFP_KERNEL
);
674 if (dn_dev_fill_ifinfo(skb
, dev
, type
, 0, 0) < 0) {
679 NETLINK_CB(skb
).dst_groups
= RTMGRP_LINK
;
680 netlink_broadcast(rtnl
, skb
, 0, NETLINK_CB(skb
).dst_groups
, GFP_KERNEL
);
682 #endif /* CONFIG_RTNETLINK */
684 static void dn_send_endnode_hello(struct net_device
*dev
)
686 struct endnode_hello_message
*msg
;
687 struct sk_buff
*skb
= NULL
;
688 unsigned short int *pktlen
;
689 struct dn_dev
*dn_db
= (struct dn_dev
*)dev
->dn_ptr
;
691 if ((skb
= dn_alloc_skb(NULL
, sizeof(*msg
), GFP_ATOMIC
)) == NULL
)
696 msg
= (struct endnode_hello_message
*)skb_put(skb
,sizeof(*msg
));
699 memcpy(msg
->tiver
, dn_eco_version
, 3);
700 memcpy(msg
->id
, decnet_ether_address
, 6);
701 msg
->iinfo
= DN_RT_INFO_ENDN
;
702 msg
->blksize
= dn_htons(dn_db
->parms
.blksize
);
704 memset(msg
->seed
, 0, 8);
705 memcpy(msg
->neighbor
, dn_hiord
, ETH_ALEN
);
708 struct dn_neigh
*dn
= (struct dn_neigh
*)dn_db
->router
;
709 dn_dn2eth(msg
->neighbor
, dn
->addr
);
712 msg
->timer
= dn_htons((unsigned short)dn_db
->parms
.t3
);
715 memset(msg
->data
, 0xAA, 2);
717 pktlen
= (unsigned short *)skb_push(skb
,2);
718 *pktlen
= dn_htons(skb
->len
- 2);
720 skb
->nh
.raw
= skb
->data
;
722 dn_rt_finish_output(skb
, dn_rt_all_rt_mcast
);
726 #ifdef CONFIG_DECNET_ROUTER
728 #define DRDELAY (5 * HZ)
730 static int dn_am_i_a_router(struct dn_neigh
*dn
, struct dn_dev
*dn_db
)
732 /* First check time since device went up */
733 if ((jiffies
- dn_db
->uptime
) < DRDELAY
)
736 /* If there is no router, then yes... */
740 /* otherwise only if we have a higher priority or.. */
741 if (dn
->priority
< dn_db
->parms
.priority
)
744 /* if we have equal priority and a higher node number */
745 if (dn
->priority
!= dn_db
->parms
.priority
)
748 if (dn_ntohs(dn
->addr
) < dn_ntohs(decnet_address
))
754 static void dn_send_router_hello(struct net_device
*dev
)
757 struct dn_dev
*dn_db
= dev
->dn_ptr
;
758 struct dn_neigh
*dn
= (struct dn_neigh
*)dn_db
->router
;
762 unsigned char *i1
, *i2
;
763 unsigned short *pktlen
;
765 if (dn_db
->parms
.blksize
< (26 + 7))
768 n
= dn_db
->parms
.blksize
- 26;
774 size
= 2 + 26 + 7 * n
;
776 if ((skb
= dn_alloc_skb(NULL
, size
, GFP_ATOMIC
)) == NULL
)
780 ptr
= skb_put(skb
, size
);
782 *ptr
++ = DN_RT_PKT_CNTL
| DN_RT_PKT_ERTH
;
783 *ptr
++ = 2; /* ECO */
786 memcpy(ptr
, decnet_ether_address
, ETH_ALEN
);
788 *ptr
++ = (unsigned char)decnet_node_type
;
789 *((unsigned short *)ptr
) = dn_htons(dn_db
->parms
.blksize
);
791 *ptr
++ = 0; /* Priority */
792 *ptr
++ = 0; /* Area: Reserved */
793 *((unsigned short *)ptr
) = dn_htons((unsigned short)dn_db
->parms
.t3
);
795 *ptr
++ = 0; /* MPD: Reserved */
797 memset(ptr
, 0, 7); /* Name: Reserved */
800 n
= dn_neigh_elist(dev
, ptr
, n
);
805 skb_trim(skb
, (26 + *i2
));
807 pktlen
= (unsigned short *)skb_push(skb
, 2);
808 *pktlen
= dn_htons(skb
->len
- 2);
810 skb
->nh
.raw
= skb
->data
;
812 if (dn_am_i_a_router(dn
, dn_db
)) {
813 struct sk_buff
*skb2
= skb_copy(skb
, GFP_ATOMIC
);
815 dn_rt_finish_output(skb2
, dn_rt_all_end_mcast
);
819 dn_rt_finish_output(skb
, dn_rt_all_rt_mcast
);
822 static void dn_send_brd_hello(struct net_device
*dev
)
824 if (decnet_node_type
== DN_RT_INFO_ENDN
)
825 dn_send_endnode_hello(dev
);
827 dn_send_router_hello(dev
);
830 static void dn_send_brd_hello(struct net_device
*dev
)
832 dn_send_endnode_hello(dev
);
836 static void dn_send_ptp_hello(struct net_device
*dev
)
839 int size
= dev
->hard_header_len
+ 2 + 4 + tdlen
;
840 struct sk_buff
*skb
= dn_alloc_skb(NULL
, size
, GFP_ATOMIC
);
841 /* struct dn_dev *dn_db = dev->dn_ptr; */
849 skb_push(skb
, dev
->hard_header_len
);
850 ptr
= skb_put(skb
, 2 + 4 + tdlen
);
852 *ptr
++ = DN_RT_PKT_HELO
;
853 *((dn_address
*)ptr
) = decnet_address
;
857 for(i
= 0; i
< tdlen
; i
++)
862 struct dn_neigh
*dn
= (struct dn_neigh
*)dn_db
->router
;
863 if (memcmp(dn
->addr
, decnet_ether_address
, ETH_ALEN
) == 0) {
864 struct sk_buff
*skb2
= skb_clone(skb
, GFP_ATOMIC
);
865 dn_rt_finish_output(skb2
, dn_rt_all_end_mcast
);
870 dn_rt_finish_output(skb
, dn_rt_all_rt_mcast
);
873 static int dn_eth_up(struct net_device
*dev
)
875 struct dn_dev
*dn_db
= dev
->dn_ptr
;
877 if (decnet_node_type
== DN_RT_INFO_ENDN
)
878 dev_mc_add(dev
, dn_rt_all_end_mcast
, ETH_ALEN
, 0);
880 if (decnet_node_type
== DN_RT_INFO_L1RT
|| decnet_node_type
== DN_RT_INFO_L2RT
)
881 dev_mc_add(dev
, dn_rt_all_rt_mcast
, ETH_ALEN
, 0);
890 static void dn_dev_set_timer(struct net_device
*dev
);
892 static void dn_dev_timer_func(unsigned long arg
)
894 struct net_device
*dev
= (struct net_device
*)arg
;
895 struct dn_dev
*dn_db
= dev
->dn_ptr
;
897 #ifdef CONFIG_DECNET_ROUTER
898 if (decnet_node_type
== DN_RT_INFO_L1RT
|| decnet_node_type
== DN_RT_INFO_L2RT
) {
899 if (dn_db
->t1
<= dn_db
->parms
.t2
) {
900 if (dn_db
->parms
.timer1
)
901 dn_db
->parms
.timer1(dev
);
902 dn_db
->t1
= dn_db
->parms
.t1
;
904 dn_db
->t1
-= dn_db
->parms
.t2
;
907 #endif /* CONFIG_DECNET_ROUTER */
909 if (dn_db
->t3
<= dn_db
->parms
.t2
) {
910 if (dn_db
->parms
.timer3
)
911 dn_db
->parms
.timer3(dev
);
912 dn_db
->t3
= dn_db
->parms
.t3
;
914 dn_db
->t3
-= dn_db
->parms
.t2
;
917 dn_dev_set_timer(dev
);
920 static void dn_dev_set_timer(struct net_device
*dev
)
922 struct dn_dev
*dn_db
= dev
->dn_ptr
;
924 #ifdef CONFIG_DECNET_ROUTER
925 if (dn_db
->parms
.t2
> dn_db
->parms
.t1
)
926 dn_db
->parms
.t2
= dn_db
->parms
.t1
;
929 if (dn_db
->parms
.t2
> dn_db
->parms
.t3
)
930 dn_db
->parms
.t2
= dn_db
->parms
.t3
;
932 dn_db
->timer
.data
= (unsigned long)dev
;
933 dn_db
->timer
.function
= dn_dev_timer_func
;
934 dn_db
->timer
.expires
= jiffies
+ (dn_db
->parms
.t2
* HZ
);
936 add_timer(&dn_db
->timer
);
939 struct dn_dev
*dn_dev_create(struct net_device
*dev
, int *err
)
942 struct dn_dev_parms
*p
= dn_dev_list
;
943 struct dn_dev
*dn_db
;
945 for(i
= 0; i
< DN_DEV_LIST_SIZE
; i
++, p
++) {
946 if (p
->type
== dev
->type
)
951 if (i
== DN_DEV_LIST_SIZE
)
955 if ((dn_db
= kmalloc(sizeof(struct dn_dev
), GFP_ATOMIC
)) == NULL
)
958 memset(dn_db
, 0, sizeof(struct dn_dev
));
959 memcpy(&dn_db
->parms
, p
, sizeof(struct dn_dev_parms
));
962 init_timer(&dn_db
->timer
);
964 memcpy(dn_db
->addr
, decnet_ether_address
, ETH_ALEN
); /* To go... */
966 dn_db
->uptime
= jiffies
;
967 if (dn_db
->parms
.up
) {
968 if (dn_db
->parms
.up(dev
) < 0) {
975 dn_db
->neigh_parms
= neigh_parms_alloc(dev
, &dn_neigh_table
);
976 /* dn_db->neigh_parms->neigh_setup = dn_db->parms.neigh_setup; */
978 dn_dev_sysctl_register(dev
, &dn_db
->parms
);
980 dn_dev_set_timer(dev
);
982 #ifdef CONFIG_RTNETLINK
983 dn_dev_ifinfo(RTM_NEWLINK
, dev
);
992 * This processes a device up event. We only start up
993 * the loopback device & ethernet devices with correct
994 * MAC addreses automatically. Others must be started
997 void dn_dev_up(struct net_device
*dev
)
999 struct dn_ifaddr
*ifa
;
1001 if ((dev
->type
!= ARPHRD_ETHER
) && (dev
->type
!= ARPHRD_LOOPBACK
))
1004 if (dev
->type
== ARPHRD_ETHER
)
1005 if (memcmp(dev
->dev_addr
, decnet_ether_address
, ETH_ALEN
) != 0)
1008 if ((ifa
= dn_dev_alloc_ifa()) == NULL
)
1011 ifa
->ifa_local
= decnet_address
;
1013 ifa
->ifa_scope
= RT_SCOPE_UNIVERSE
;
1014 strcpy(ifa
->ifa_label
, dev
->name
);
1016 dn_dev_set_ifa(dev
, ifa
);
1019 static void dn_dev_delete(struct net_device
*dev
)
1021 struct dn_dev
*dn_db
= dev
->dn_ptr
;
1026 del_timer(&dn_db
->timer
);
1029 #ifdef CONFIG_RTNETLINK
1030 dn_dev_ifinfo(RTM_DELLINK
, dev
);
1033 dn_dev_sysctl_unregister(&dn_db
->parms
);
1035 neigh_ifdown(&dn_neigh_table
, dev
);
1037 if (dev
== decnet_default_device
)
1038 decnet_default_device
= NULL
;
1040 if (dn_db
->parms
.down
)
1041 dn_db
->parms
.down(dev
);
1045 neigh_parms_release(&dn_neigh_table
, dn_db
->neigh_parms
);
1048 neigh_release(dn_db
->router
);
1050 neigh_release(dn_db
->peer
);
1055 void dn_dev_down(struct net_device
*dev
)
1057 struct dn_dev
*dn_db
= dev
->dn_ptr
;
1058 struct dn_ifaddr
*ifa
;
1063 while((ifa
= dn_db
->ifa_list
) != NULL
) {
1064 dn_dev_del_ifa(dn_db
, &dn_db
->ifa_list
, 0);
1065 dn_dev_free_ifa(ifa
);
1071 void dn_dev_init_pkt(struct sk_buff
*skb
)
1076 void dn_dev_veri_pkt(struct sk_buff
*skb
)
1081 void dn_dev_hello(struct sk_buff
*skb
)
1086 void dn_dev_devices_off(void)
1088 struct net_device
*dev
;
1090 for(dev
= dev_base
; dev
; dev
= dev
->next
)
1095 void dn_dev_devices_on(void)
1097 struct net_device
*dev
;
1099 for(dev
= dev_base
; dev
; dev
= dev
->next
) {
1100 if (dev
->flags
& IFF_UP
)
1106 #ifdef CONFIG_DECNET_SIOCGIFCONF
1108 * Now we support multiple addresses per interface.
1109 * Since we don't want to break existing code, you have to enable
1110 * it as a compile time option. Probably you should use the
1111 * rtnetlink interface instead.
1113 int dnet_gifconf(struct net_device
*dev
, char *buf
, int len
)
1115 struct dn_dev
*dn_db
= (struct dn_dev
*)dev
->dn_ptr
;
1116 struct dn_ifaddr
*ifa
;
1117 struct ifreq
*ifr
= (struct ifreq
*)buf
;
1120 if ((dn_db
== NULL
) || ((ifa
= dn_db
->ifa_list
) == NULL
))
1123 for(; ifa
; ifa
= ifa
->ifa_next
) {
1125 done
+= sizeof(DN_IFREQ_SIZE
);
1128 if (len
< DN_IFREQ_SIZE
)
1130 memset(ifr
, 0, DN_IFREQ_SIZE
);
1133 strcpy(ifr
->ifr_name
, ifa
->ifa_label
);
1135 strcpy(ifr
->ifr_name
, dev
->name
);
1137 (*(struct sockaddr_dn
*) &ifr
->ifr_addr
).sdn_family
= AF_DECnet
;
1138 (*(struct sockaddr_dn
*) &ifr
->ifr_addr
).sdn_add
.a_len
= 2;
1139 (*(dn_address
*)(*(struct sockaddr_dn
*) &ifr
->ifr_addr
).sdn_add
.a_addr
) = ifa
->ifa_local
;
1141 ifr
= (struct ifreq
*)((char *)ifr
+ DN_IFREQ_SIZE
);
1142 len
-= DN_IFREQ_SIZE
;
1143 done
+= DN_IFREQ_SIZE
;
1148 #endif /* CONFIG_DECNET_SIOCGIFCONF */
1151 #ifdef CONFIG_PROC_FS
1153 static char *dn_type2asc(char type
)
1167 static int decnet_dev_get_info(char *buffer
, char **start
, off_t offset
, int length
, int dummy
)
1169 struct dn_dev
*dn_db
;
1170 struct net_device
*dev
;
1174 char peer_buf
[DN_ASCBUF_LEN
];
1175 char router_buf
[DN_ASCBUF_LEN
];
1178 len
+= sprintf(buffer
, "Name Flags T1 Timer1 T3 Timer3 BlkSize Pri State DevType Router Peer\n");
1180 read_lock(&dev_base_lock
);
1181 for (dev
= dev_base
; dev
; dev
= dev
->next
) {
1182 if ((dn_db
= (struct dn_dev
*)dev
->dn_ptr
) == NULL
)
1185 len
+= sprintf(buffer
+ len
, "%-8s %1s %04lu %04lu %04lu %04lu %04hu %03d %02x %-10s %-7s %-7s\n",
1186 dev
->name
? dev
->name
: "???",
1187 dn_type2asc(dn_db
->parms
.mode
),
1188 dn_db
->t1
, dn_db
->parms
.t1
,
1189 dn_db
->t3
, dn_db
->parms
.t3
,
1190 dn_db
->parms
.blksize
,
1191 dn_db
->parms
.priority
,
1192 dn_db
->parms
.state
, dn_db
->parms
.name
,
1193 dn_db
->router
? dn_addr2asc(dn_eth2dn(dn_db
->router
->primary_key
), router_buf
) : "",
1194 dn_db
->peer
? dn_addr2asc(dn_eth2dn(dn_db
->peer
->primary_key
), peer_buf
) : "");
1203 if (pos
> offset
+ length
)
1207 read_unlock(&dev_base_lock
);
1209 *start
= buffer
+ (offset
- begin
);
1210 len
-= (offset
- begin
);
1212 if (len
> length
) len
= length
;
1217 #endif /* CONFIG_PROC_FS */
1219 #ifdef CONFIG_RTNETLINK
1220 static struct rtnetlink_link dnet_rtnetlink_table
[RTM_MAX
-RTM_BASE
+1] =
1224 { NULL
, dn_dev_dump_ifinfo
, },
1227 { dn_dev_rtm_newaddr
, NULL
, },
1228 { dn_dev_rtm_deladdr
, NULL
, },
1229 { NULL
, dn_dev_dump_ifaddr
, },
1231 #ifdef CONFIG_DECNET_ROUTER
1232 { dn_fib_rtm_newroute
, NULL
, },
1233 { dn_fib_rtm_delroute
, NULL
, },
1234 { dn_cache_getroute
, dn_fib_dump
, },
1239 { dn_cache_getroute
, dn_cache_dump
, },
1252 #endif /* CONFIG_RTNETLINK */
1254 void __init
dn_dev_init(void)
1257 dn_dev_devices_on();
1258 #ifdef CONFIG_DECNET_SIOCGIFCONF
1259 register_gifconf(PF_DECnet
, dnet_gifconf
);
1260 #endif /* CONFIG_DECNET_SIOCGIFCONF */
1262 #ifdef CONFIG_RTNETLINK
1263 rtnetlink_links
[PF_DECnet
] = dnet_rtnetlink_table
;
1264 #endif /* CONFIG_RTNETLINK */
1266 #ifdef CONFIG_PROC_FS
1267 proc_net_create("decnet_dev", 0, decnet_dev_get_info
);
1268 #endif /* CONFIG_PROC_FS */
1270 #ifdef CONFIG_SYSCTL
1273 for(i
= 0; i
< DN_DEV_LIST_SIZE
; i
++)
1274 dn_dev_sysctl_register(NULL
, &dn_dev_list
[i
]);
1276 #endif /* CONFIG_SYSCTL */
1279 #if defined(CONFIG_DECNET_MODULE)
1280 void dn_dev_cleanup(void)
1282 #ifdef CONFIG_RTNETLINK
1283 rtnetlink_links
[PF_DECnet
] = NULL
;
1284 #endif /* CONFIG_RTNETLINK */
1286 #ifdef CONFIG_DECNET_SIOCGIFCONF
1287 unregister_gifconf(PF_DECnet
);
1288 #endif /* CONFIG_DECNET_SIOCGIFCONF */
1290 #ifdef CONFIG_SYSCTL
1293 for(i
= 0; i
< DN_DEV_LIST_SIZE
; i
++)
1294 dn_dev_sysctl_unregister(&dn_dev_list
[i
]);
1296 #endif /* CONFIG_SYSCTL */
1298 #ifdef CONFIG_PROC_FS
1299 proc_net_remove("decnet_dev");
1300 #endif /* CONFIG_PROC_FS */
1302 dn_dev_devices_off();
1304 #endif /* CONFIG_DECNET_MODULE */