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 - it's a user space issue now
22 * Patrick Caulfield : Fixed router hello message format
23 * Steve Whitehouse : Got rid of constant sizes for blksize for
24 * devices. All mtu based now.
27 #include <linux/capability.h>
28 #include <linux/module.h>
29 #include <linux/moduleparam.h>
30 #include <linux/init.h>
31 #include <linux/net.h>
32 #include <linux/netdevice.h>
33 #include <linux/proc_fs.h>
34 #include <linux/seq_file.h>
35 #include <linux/timer.h>
36 #include <linux/string.h>
37 #include <linux/if_addr.h>
38 #include <linux/if_arp.h>
39 #include <linux/if_ether.h>
40 #include <linux/skbuff.h>
41 #include <linux/sysctl.h>
42 #include <linux/notifier.h>
43 #include <asm/uaccess.h>
44 #include <asm/system.h>
45 #include <net/net_namespace.h>
46 #include <net/neighbour.h>
49 #include <net/fib_rules.h>
50 #include <net/netlink.h>
52 #include <net/dn_dev.h>
53 #include <net/dn_route.h>
54 #include <net/dn_neigh.h>
55 #include <net/dn_fib.h>
57 #define DN_IFREQ_SIZE (sizeof(struct ifreq) - sizeof(struct sockaddr) + sizeof(struct sockaddr_dn))
59 static char dn_rt_all_end_mcast
[ETH_ALEN
] = {0xAB,0x00,0x00,0x04,0x00,0x00};
60 static char dn_rt_all_rt_mcast
[ETH_ALEN
] = {0xAB,0x00,0x00,0x03,0x00,0x00};
61 static char dn_hiord
[ETH_ALEN
] = {0xAA,0x00,0x04,0x00,0x00,0x00};
62 static unsigned char dn_eco_version
[3] = {0x02,0x00,0x00};
64 extern struct neigh_table dn_neigh_table
;
67 * decnet_address is kept in network order.
69 __le16 decnet_address
= 0;
71 static DEFINE_RWLOCK(dndev_lock
);
72 static struct net_device
*decnet_default_device
;
73 static BLOCKING_NOTIFIER_HEAD(dnaddr_chain
);
75 static struct dn_dev
*dn_dev_create(struct net_device
*dev
, int *err
);
76 static void dn_dev_delete(struct net_device
*dev
);
77 static void dn_ifaddr_notify(int event
, struct dn_ifaddr
*ifa
);
79 static int dn_eth_up(struct net_device
*);
80 static void dn_eth_down(struct net_device
*);
81 static void dn_send_brd_hello(struct net_device
*dev
, struct dn_ifaddr
*ifa
);
82 static void dn_send_ptp_hello(struct net_device
*dev
, struct dn_ifaddr
*ifa
);
84 static struct dn_dev_parms dn_dev_list
[] = {
86 .type
= ARPHRD_ETHER
, /* Ethernet */
92 .ctl_name
= NET_DECNET_CONF_ETHER
,
95 .timer3
= dn_send_brd_hello
,
98 .type
= ARPHRD_IPGRE
, /* DECnet tunneled over GRE in IP */
100 .state
= DN_DEV_S_RU
,
104 .ctl_name
= NET_DECNET_CONF_GRE
,
105 .timer3
= dn_send_brd_hello
,
109 .type
= ARPHRD_X25
, /* Bog standard X.25 */
110 .mode
= DN_DEV_UCAST
,
111 .state
= DN_DEV_S_DS
,
115 .ctl_name
= NET_DECNET_CONF_X25
,
116 .timer3
= dn_send_ptp_hello
,
121 .type
= ARPHRD_PPP
, /* DECnet over PPP */
122 .mode
= DN_DEV_BCAST
,
123 .state
= DN_DEV_S_RU
,
127 .ctl_name
= NET_DECNET_CONF_PPP
,
128 .timer3
= dn_send_brd_hello
,
132 .type
= ARPHRD_DDCMP
, /* DECnet over DDCMP */
133 .mode
= DN_DEV_UCAST
,
134 .state
= DN_DEV_S_DS
,
138 .ctl_name
= NET_DECNET_CONF_DDCMP
,
139 .timer3
= dn_send_ptp_hello
,
142 .type
= ARPHRD_LOOPBACK
, /* Loopback interface - always last */
143 .mode
= DN_DEV_BCAST
,
144 .state
= DN_DEV_S_RU
,
148 .ctl_name
= NET_DECNET_CONF_LOOPBACK
,
149 .timer3
= dn_send_brd_hello
,
153 #define DN_DEV_LIST_SIZE ARRAY_SIZE(dn_dev_list)
155 #define DN_DEV_PARMS_OFFSET(x) offsetof(struct dn_dev_parms, x)
159 static int min_t2
[] = { 1 };
160 static int max_t2
[] = { 60 }; /* No max specified, but this seems sensible */
161 static int min_t3
[] = { 1 };
162 static int max_t3
[] = { 8191 }; /* Must fit in 16 bits when multiplied by BCT3MULT or T3MULT */
164 static int min_priority
[1];
165 static int max_priority
[] = { 127 }; /* From DECnet spec */
167 static int dn_forwarding_proc(ctl_table
*, int,
168 void __user
*, size_t *, loff_t
*);
169 static int dn_forwarding_sysctl(ctl_table
*table
,
170 void __user
*oldval
, size_t __user
*oldlenp
,
171 void __user
*newval
, size_t newlen
);
173 static struct dn_dev_sysctl_table
{
174 struct ctl_table_header
*sysctl_header
;
175 ctl_table dn_dev_vars
[5];
180 .ctl_name
= NET_DECNET_CONF_DEV_FORWARDING
,
181 .procname
= "forwarding",
182 .data
= (void *)DN_DEV_PARMS_OFFSET(forwarding
),
183 .maxlen
= sizeof(int),
185 .proc_handler
= dn_forwarding_proc
,
186 .strategy
= dn_forwarding_sysctl
,
189 .ctl_name
= NET_DECNET_CONF_DEV_PRIORITY
,
190 .procname
= "priority",
191 .data
= (void *)DN_DEV_PARMS_OFFSET(priority
),
192 .maxlen
= sizeof(int),
194 .proc_handler
= proc_dointvec_minmax
,
195 .strategy
= sysctl_intvec
,
196 .extra1
= &min_priority
,
197 .extra2
= &max_priority
200 .ctl_name
= NET_DECNET_CONF_DEV_T2
,
202 .data
= (void *)DN_DEV_PARMS_OFFSET(t2
),
203 .maxlen
= sizeof(int),
205 .proc_handler
= proc_dointvec_minmax
,
206 .strategy
= sysctl_intvec
,
211 .ctl_name
= NET_DECNET_CONF_DEV_T3
,
213 .data
= (void *)DN_DEV_PARMS_OFFSET(t3
),
214 .maxlen
= sizeof(int),
216 .proc_handler
= proc_dointvec_minmax
,
217 .strategy
= sysctl_intvec
,
225 static void dn_dev_sysctl_register(struct net_device
*dev
, struct dn_dev_parms
*parms
)
227 struct dn_dev_sysctl_table
*t
;
230 #define DN_CTL_PATH_DEV 3
232 struct ctl_path dn_ctl_path
[] = {
233 { .procname
= "net", .ctl_name
= CTL_NET
, },
234 { .procname
= "decnet", .ctl_name
= NET_DECNET
, },
235 { .procname
= "conf", .ctl_name
= NET_DECNET_CONF
, },
240 t
= kmemdup(&dn_dev_sysctl
, sizeof(*t
), GFP_KERNEL
);
244 for(i
= 0; i
< ARRAY_SIZE(t
->dn_dev_vars
) - 1; i
++) {
245 long offset
= (long)t
->dn_dev_vars
[i
].data
;
246 t
->dn_dev_vars
[i
].data
= ((char *)parms
) + offset
;
250 dn_ctl_path
[DN_CTL_PATH_DEV
].procname
= dev
->name
;
251 dn_ctl_path
[DN_CTL_PATH_DEV
].ctl_name
= dev
->ifindex
;
253 dn_ctl_path
[DN_CTL_PATH_DEV
].procname
= parms
->name
;
254 dn_ctl_path
[DN_CTL_PATH_DEV
].ctl_name
= parms
->ctl_name
;
257 t
->dn_dev_vars
[0].extra1
= (void *)dev
;
259 t
->sysctl_header
= register_sysctl_paths(dn_ctl_path
, t
->dn_dev_vars
);
260 if (t
->sysctl_header
== NULL
)
266 static void dn_dev_sysctl_unregister(struct dn_dev_parms
*parms
)
269 struct dn_dev_sysctl_table
*t
= parms
->sysctl
;
270 parms
->sysctl
= NULL
;
271 unregister_sysctl_table(t
->sysctl_header
);
276 static int dn_forwarding_proc(ctl_table
*table
, int write
,
278 size_t *lenp
, loff_t
*ppos
)
280 #ifdef CONFIG_DECNET_ROUTER
281 struct net_device
*dev
= table
->extra1
;
282 struct dn_dev
*dn_db
;
286 if (table
->extra1
== NULL
)
290 old
= dn_db
->parms
.forwarding
;
292 err
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
294 if ((err
>= 0) && write
) {
295 if (dn_db
->parms
.forwarding
< 0)
296 dn_db
->parms
.forwarding
= 0;
297 if (dn_db
->parms
.forwarding
> 2)
298 dn_db
->parms
.forwarding
= 2;
300 * What an ugly hack this is... its works, just. It
301 * would be nice if sysctl/proc were just that little
302 * bit more flexible so I don't have to write a special
303 * routine, or suffer hacks like this - SJW
305 tmp
= dn_db
->parms
.forwarding
;
306 dn_db
->parms
.forwarding
= old
;
307 if (dn_db
->parms
.down
)
308 dn_db
->parms
.down(dev
);
309 dn_db
->parms
.forwarding
= tmp
;
311 dn_db
->parms
.up(dev
);
320 static int dn_forwarding_sysctl(ctl_table
*table
,
321 void __user
*oldval
, size_t __user
*oldlenp
,
322 void __user
*newval
, size_t newlen
)
324 #ifdef CONFIG_DECNET_ROUTER
325 struct net_device
*dev
= table
->extra1
;
326 struct dn_dev
*dn_db
;
329 if (table
->extra1
== NULL
)
334 if (newval
&& newlen
) {
335 if (newlen
!= sizeof(int))
338 if (get_user(value
, (int __user
*)newval
))
345 if (dn_db
->parms
.down
)
346 dn_db
->parms
.down(dev
);
347 dn_db
->parms
.forwarding
= value
;
349 dn_db
->parms
.up(dev
);
358 #else /* CONFIG_SYSCTL */
359 static void dn_dev_sysctl_unregister(struct dn_dev_parms
*parms
)
362 static void dn_dev_sysctl_register(struct net_device
*dev
, struct dn_dev_parms
*parms
)
366 #endif /* CONFIG_SYSCTL */
368 static inline __u16
mtu2blksize(struct net_device
*dev
)
370 u32 blksize
= dev
->mtu
;
371 if (blksize
> 0xffff)
374 if (dev
->type
== ARPHRD_ETHER
||
375 dev
->type
== ARPHRD_PPP
||
376 dev
->type
== ARPHRD_IPGRE
||
377 dev
->type
== ARPHRD_LOOPBACK
)
380 return (__u16
)blksize
;
383 static struct dn_ifaddr
*dn_dev_alloc_ifa(void)
385 struct dn_ifaddr
*ifa
;
387 ifa
= kzalloc(sizeof(*ifa
), GFP_KERNEL
);
392 static __inline__
void dn_dev_free_ifa(struct dn_ifaddr
*ifa
)
397 static void dn_dev_del_ifa(struct dn_dev
*dn_db
, struct dn_ifaddr
**ifap
, int destroy
)
399 struct dn_ifaddr
*ifa1
= *ifap
;
400 unsigned char mac_addr
[6];
401 struct net_device
*dev
= dn_db
->dev
;
405 *ifap
= ifa1
->ifa_next
;
407 if (dn_db
->dev
->type
== ARPHRD_ETHER
) {
408 if (ifa1
->ifa_local
!= dn_eth2dn(dev
->dev_addr
)) {
409 dn_dn2eth(mac_addr
, ifa1
->ifa_local
);
410 dev_mc_delete(dev
, mac_addr
, ETH_ALEN
, 0);
414 dn_ifaddr_notify(RTM_DELADDR
, ifa1
);
415 blocking_notifier_call_chain(&dnaddr_chain
, NETDEV_DOWN
, ifa1
);
417 dn_dev_free_ifa(ifa1
);
419 if (dn_db
->ifa_list
== NULL
)
420 dn_dev_delete(dn_db
->dev
);
424 static int dn_dev_insert_ifa(struct dn_dev
*dn_db
, struct dn_ifaddr
*ifa
)
426 struct net_device
*dev
= dn_db
->dev
;
427 struct dn_ifaddr
*ifa1
;
428 unsigned char mac_addr
[6];
432 /* Check for duplicates */
433 for(ifa1
= dn_db
->ifa_list
; ifa1
; ifa1
= ifa1
->ifa_next
) {
434 if (ifa1
->ifa_local
== ifa
->ifa_local
)
438 if (dev
->type
== ARPHRD_ETHER
) {
439 if (ifa
->ifa_local
!= dn_eth2dn(dev
->dev_addr
)) {
440 dn_dn2eth(mac_addr
, ifa
->ifa_local
);
441 dev_mc_add(dev
, mac_addr
, ETH_ALEN
, 0);
445 ifa
->ifa_next
= dn_db
->ifa_list
;
446 dn_db
->ifa_list
= ifa
;
448 dn_ifaddr_notify(RTM_NEWADDR
, ifa
);
449 blocking_notifier_call_chain(&dnaddr_chain
, NETDEV_UP
, ifa
);
454 static int dn_dev_set_ifa(struct net_device
*dev
, struct dn_ifaddr
*ifa
)
456 struct dn_dev
*dn_db
= dev
->dn_ptr
;
461 dn_db
= dn_dev_create(dev
, &err
);
466 ifa
->ifa_dev
= dn_db
;
468 if (dev
->flags
& IFF_LOOPBACK
)
469 ifa
->ifa_scope
= RT_SCOPE_HOST
;
471 rv
= dn_dev_insert_ifa(dn_db
, ifa
);
473 dn_dev_free_ifa(ifa
);
478 int dn_dev_ioctl(unsigned int cmd
, void __user
*arg
)
480 char buffer
[DN_IFREQ_SIZE
];
481 struct ifreq
*ifr
= (struct ifreq
*)buffer
;
482 struct sockaddr_dn
*sdn
= (struct sockaddr_dn
*)&ifr
->ifr_addr
;
483 struct dn_dev
*dn_db
;
484 struct net_device
*dev
;
485 struct dn_ifaddr
*ifa
= NULL
, **ifap
= NULL
;
488 if (copy_from_user(ifr
, arg
, DN_IFREQ_SIZE
))
490 ifr
->ifr_name
[IFNAMSIZ
-1] = 0;
492 dev_load(&init_net
, ifr
->ifr_name
);
498 if (!capable(CAP_NET_ADMIN
))
500 if (sdn
->sdn_family
!= AF_DECnet
)
509 if ((dev
= __dev_get_by_name(&init_net
, ifr
->ifr_name
)) == NULL
) {
514 if ((dn_db
= dev
->dn_ptr
) != NULL
) {
515 for (ifap
= &dn_db
->ifa_list
; (ifa
=*ifap
) != NULL
; ifap
= &ifa
->ifa_next
)
516 if (strcmp(ifr
->ifr_name
, ifa
->ifa_label
) == 0)
520 if (ifa
== NULL
&& cmd
!= SIOCSIFADDR
) {
521 ret
= -EADDRNOTAVAIL
;
527 *((__le16
*)sdn
->sdn_nodeaddr
) = ifa
->ifa_local
;
532 if ((ifa
= dn_dev_alloc_ifa()) == NULL
) {
536 memcpy(ifa
->ifa_label
, dev
->name
, IFNAMSIZ
);
538 if (ifa
->ifa_local
== dn_saddr2dn(sdn
))
540 dn_dev_del_ifa(dn_db
, ifap
, 0);
543 ifa
->ifa_local
= ifa
->ifa_address
= dn_saddr2dn(sdn
);
545 ret
= dn_dev_set_ifa(dev
, ifa
);
552 if (copy_to_user(arg
, ifr
, DN_IFREQ_SIZE
))
557 struct net_device
*dn_dev_get_default(void)
559 struct net_device
*dev
;
560 read_lock(&dndev_lock
);
561 dev
= decnet_default_device
;
568 read_unlock(&dndev_lock
);
572 int dn_dev_set_default(struct net_device
*dev
, int force
)
574 struct net_device
*old
= NULL
;
578 write_lock(&dndev_lock
);
579 if (force
|| decnet_default_device
== NULL
) {
580 old
= decnet_default_device
;
581 decnet_default_device
= dev
;
584 write_unlock(&dndev_lock
);
590 static void dn_dev_check_default(struct net_device
*dev
)
592 write_lock(&dndev_lock
);
593 if (dev
== decnet_default_device
) {
594 decnet_default_device
= NULL
;
598 write_unlock(&dndev_lock
);
603 static struct dn_dev
*dn_dev_by_index(int ifindex
)
605 struct net_device
*dev
;
606 struct dn_dev
*dn_dev
= NULL
;
607 dev
= dev_get_by_index(&init_net
, ifindex
);
609 dn_dev
= dev
->dn_ptr
;
616 static const struct nla_policy dn_ifa_policy
[IFA_MAX
+1] = {
617 [IFA_ADDRESS
] = { .type
= NLA_U16
},
618 [IFA_LOCAL
] = { .type
= NLA_U16
},
619 [IFA_LABEL
] = { .type
= NLA_STRING
,
620 .len
= IFNAMSIZ
- 1 },
623 static int dn_nl_deladdr(struct sk_buff
*skb
, struct nlmsghdr
*nlh
, void *arg
)
625 struct net
*net
= sock_net(skb
->sk
);
626 struct nlattr
*tb
[IFA_MAX
+1];
627 struct dn_dev
*dn_db
;
628 struct ifaddrmsg
*ifm
;
629 struct dn_ifaddr
*ifa
, **ifap
;
632 if (net
!= &init_net
)
635 err
= nlmsg_parse(nlh
, sizeof(*ifm
), tb
, IFA_MAX
, dn_ifa_policy
);
640 ifm
= nlmsg_data(nlh
);
641 if ((dn_db
= dn_dev_by_index(ifm
->ifa_index
)) == NULL
)
644 err
= -EADDRNOTAVAIL
;
645 for (ifap
= &dn_db
->ifa_list
; (ifa
= *ifap
); ifap
= &ifa
->ifa_next
) {
647 nla_memcmp(tb
[IFA_LOCAL
], &ifa
->ifa_local
, 2))
650 if (tb
[IFA_LABEL
] && nla_strcmp(tb
[IFA_LABEL
], ifa
->ifa_label
))
653 dn_dev_del_ifa(dn_db
, ifap
, 1);
661 static int dn_nl_newaddr(struct sk_buff
*skb
, struct nlmsghdr
*nlh
, void *arg
)
663 struct net
*net
= sock_net(skb
->sk
);
664 struct nlattr
*tb
[IFA_MAX
+1];
665 struct net_device
*dev
;
666 struct dn_dev
*dn_db
;
667 struct ifaddrmsg
*ifm
;
668 struct dn_ifaddr
*ifa
;
671 if (net
!= &init_net
)
674 err
= nlmsg_parse(nlh
, sizeof(*ifm
), tb
, IFA_MAX
, dn_ifa_policy
);
678 if (tb
[IFA_LOCAL
] == NULL
)
681 ifm
= nlmsg_data(nlh
);
682 if ((dev
= __dev_get_by_index(&init_net
, ifm
->ifa_index
)) == NULL
)
685 if ((dn_db
= dev
->dn_ptr
) == NULL
) {
686 dn_db
= dn_dev_create(dev
, &err
);
691 if ((ifa
= dn_dev_alloc_ifa()) == NULL
)
694 if (tb
[IFA_ADDRESS
] == NULL
)
695 tb
[IFA_ADDRESS
] = tb
[IFA_LOCAL
];
697 ifa
->ifa_local
= nla_get_le16(tb
[IFA_LOCAL
]);
698 ifa
->ifa_address
= nla_get_le16(tb
[IFA_ADDRESS
]);
699 ifa
->ifa_flags
= ifm
->ifa_flags
;
700 ifa
->ifa_scope
= ifm
->ifa_scope
;
701 ifa
->ifa_dev
= dn_db
;
704 nla_strlcpy(ifa
->ifa_label
, tb
[IFA_LABEL
], IFNAMSIZ
);
706 memcpy(ifa
->ifa_label
, dev
->name
, IFNAMSIZ
);
708 err
= dn_dev_insert_ifa(dn_db
, ifa
);
710 dn_dev_free_ifa(ifa
);
715 static inline size_t dn_ifaddr_nlmsg_size(void)
717 return NLMSG_ALIGN(sizeof(struct ifaddrmsg
))
718 + nla_total_size(IFNAMSIZ
) /* IFA_LABEL */
719 + nla_total_size(2) /* IFA_ADDRESS */
720 + nla_total_size(2); /* IFA_LOCAL */
723 static int dn_nl_fill_ifaddr(struct sk_buff
*skb
, struct dn_ifaddr
*ifa
,
724 u32 pid
, u32 seq
, int event
, unsigned int flags
)
726 struct ifaddrmsg
*ifm
;
727 struct nlmsghdr
*nlh
;
729 nlh
= nlmsg_put(skb
, pid
, seq
, event
, sizeof(*ifm
), flags
);
733 ifm
= nlmsg_data(nlh
);
734 ifm
->ifa_family
= AF_DECnet
;
735 ifm
->ifa_prefixlen
= 16;
736 ifm
->ifa_flags
= ifa
->ifa_flags
| IFA_F_PERMANENT
;
737 ifm
->ifa_scope
= ifa
->ifa_scope
;
738 ifm
->ifa_index
= ifa
->ifa_dev
->dev
->ifindex
;
740 if (ifa
->ifa_address
)
741 NLA_PUT_LE16(skb
, IFA_ADDRESS
, ifa
->ifa_address
);
743 NLA_PUT_LE16(skb
, IFA_LOCAL
, ifa
->ifa_local
);
744 if (ifa
->ifa_label
[0])
745 NLA_PUT_STRING(skb
, IFA_LABEL
, ifa
->ifa_label
);
747 return nlmsg_end(skb
, nlh
);
750 nlmsg_cancel(skb
, nlh
);
754 static void dn_ifaddr_notify(int event
, struct dn_ifaddr
*ifa
)
759 skb
= alloc_skb(dn_ifaddr_nlmsg_size(), GFP_KERNEL
);
763 err
= dn_nl_fill_ifaddr(skb
, ifa
, 0, 0, event
, 0);
765 /* -EMSGSIZE implies BUG in dn_ifaddr_nlmsg_size() */
766 WARN_ON(err
== -EMSGSIZE
);
770 rtnl_notify(skb
, &init_net
, 0, RTNLGRP_DECnet_IFADDR
, NULL
, GFP_KERNEL
);
774 rtnl_set_sk_err(&init_net
, RTNLGRP_DECnet_IFADDR
, err
);
777 static int dn_nl_dump_ifaddr(struct sk_buff
*skb
, struct netlink_callback
*cb
)
779 struct net
*net
= sock_net(skb
->sk
);
780 int idx
, dn_idx
= 0, skip_ndevs
, skip_naddr
;
781 struct net_device
*dev
;
782 struct dn_dev
*dn_db
;
783 struct dn_ifaddr
*ifa
;
785 if (net
!= &init_net
)
788 skip_ndevs
= cb
->args
[0];
789 skip_naddr
= cb
->args
[1];
792 for_each_netdev(&init_net
, dev
) {
793 if (idx
< skip_ndevs
)
795 else if (idx
> skip_ndevs
) {
796 /* Only skip over addresses for first dev dumped
797 * in this iteration (idx == skip_ndevs) */
801 if ((dn_db
= dev
->dn_ptr
) == NULL
)
804 for (ifa
= dn_db
->ifa_list
, dn_idx
= 0; ifa
;
805 ifa
= ifa
->ifa_next
, dn_idx
++) {
806 if (dn_idx
< skip_naddr
)
809 if (dn_nl_fill_ifaddr(skb
, ifa
, NETLINK_CB(cb
->skb
).pid
,
810 cb
->nlh
->nlmsg_seq
, RTM_NEWADDR
,
819 cb
->args
[1] = dn_idx
;
824 static int dn_dev_get_first(struct net_device
*dev
, __le16
*addr
)
826 struct dn_dev
*dn_db
= (struct dn_dev
*)dev
->dn_ptr
;
827 struct dn_ifaddr
*ifa
;
831 ifa
= dn_db
->ifa_list
;
833 *addr
= ifa
->ifa_local
;
841 * Find a default address to bind to.
843 * This is one of those areas where the initial VMS concepts don't really
844 * map onto the Linux concepts, and since we introduced multiple addresses
845 * per interface we have to cope with slightly odd ways of finding out what
846 * "our address" really is. Mostly it's not a problem; for this we just guess
847 * a sensible default. Eventually the routing code will take care of all the
848 * nasties for us I hope.
850 int dn_dev_bind_default(__le16
*addr
)
852 struct net_device
*dev
;
854 dev
= dn_dev_get_default();
857 read_lock(&dev_base_lock
);
858 rv
= dn_dev_get_first(dev
, addr
);
859 read_unlock(&dev_base_lock
);
861 if (rv
== 0 || dev
== init_net
.loopback_dev
)
864 dev
= init_net
.loopback_dev
;
869 static void dn_send_endnode_hello(struct net_device
*dev
, struct dn_ifaddr
*ifa
)
871 struct endnode_hello_message
*msg
;
872 struct sk_buff
*skb
= NULL
;
874 struct dn_dev
*dn_db
= (struct dn_dev
*)dev
->dn_ptr
;
876 if ((skb
= dn_alloc_skb(NULL
, sizeof(*msg
), GFP_ATOMIC
)) == NULL
)
881 msg
= (struct endnode_hello_message
*)skb_put(skb
,sizeof(*msg
));
884 memcpy(msg
->tiver
, dn_eco_version
, 3);
885 dn_dn2eth(msg
->id
, ifa
->ifa_local
);
886 msg
->iinfo
= DN_RT_INFO_ENDN
;
887 msg
->blksize
= cpu_to_le16(mtu2blksize(dev
));
889 memset(msg
->seed
, 0, 8);
890 memcpy(msg
->neighbor
, dn_hiord
, ETH_ALEN
);
893 struct dn_neigh
*dn
= (struct dn_neigh
*)dn_db
->router
;
894 dn_dn2eth(msg
->neighbor
, dn
->addr
);
897 msg
->timer
= cpu_to_le16((unsigned short)dn_db
->parms
.t3
);
900 memset(msg
->data
, 0xAA, 2);
902 pktlen
= (__le16
*)skb_push(skb
,2);
903 *pktlen
= cpu_to_le16(skb
->len
- 2);
905 skb_reset_network_header(skb
);
907 dn_rt_finish_output(skb
, dn_rt_all_rt_mcast
, msg
->id
);
911 #define DRDELAY (5 * HZ)
913 static int dn_am_i_a_router(struct dn_neigh
*dn
, struct dn_dev
*dn_db
, struct dn_ifaddr
*ifa
)
915 /* First check time since device went up */
916 if ((jiffies
- dn_db
->uptime
) < DRDELAY
)
919 /* If there is no router, then yes... */
923 /* otherwise only if we have a higher priority or.. */
924 if (dn
->priority
< dn_db
->parms
.priority
)
927 /* if we have equal priority and a higher node number */
928 if (dn
->priority
!= dn_db
->parms
.priority
)
931 if (le16_to_cpu(dn
->addr
) < le16_to_cpu(ifa
->ifa_local
))
937 static void dn_send_router_hello(struct net_device
*dev
, struct dn_ifaddr
*ifa
)
940 struct dn_dev
*dn_db
= dev
->dn_ptr
;
941 struct dn_neigh
*dn
= (struct dn_neigh
*)dn_db
->router
;
945 unsigned char *i1
, *i2
;
949 if (mtu2blksize(dev
) < (26 + 7))
952 n
= mtu2blksize(dev
) - 26;
958 size
= 2 + 26 + 7 * n
;
960 if ((skb
= dn_alloc_skb(NULL
, size
, GFP_ATOMIC
)) == NULL
)
964 ptr
= skb_put(skb
, size
);
966 *ptr
++ = DN_RT_PKT_CNTL
| DN_RT_PKT_ERTH
;
967 *ptr
++ = 2; /* ECO */
970 dn_dn2eth(ptr
, ifa
->ifa_local
);
973 *ptr
++ = dn_db
->parms
.forwarding
== 1 ?
974 DN_RT_INFO_L1RT
: DN_RT_INFO_L2RT
;
975 *((__le16
*)ptr
) = cpu_to_le16(mtu2blksize(dev
));
977 *ptr
++ = dn_db
->parms
.priority
; /* Priority */
978 *ptr
++ = 0; /* Area: Reserved */
979 *((__le16
*)ptr
) = cpu_to_le16((unsigned short)dn_db
->parms
.t3
);
981 *ptr
++ = 0; /* MPD: Reserved */
983 memset(ptr
, 0, 7); /* Name: Reserved */
987 n
= dn_neigh_elist(dev
, ptr
, n
);
992 skb_trim(skb
, (27 + *i2
));
994 pktlen
= (__le16
*)skb_push(skb
, 2);
995 *pktlen
= cpu_to_le16(skb
->len
- 2);
997 skb_reset_network_header(skb
);
999 if (dn_am_i_a_router(dn
, dn_db
, ifa
)) {
1000 struct sk_buff
*skb2
= skb_copy(skb
, GFP_ATOMIC
);
1002 dn_rt_finish_output(skb2
, dn_rt_all_end_mcast
, src
);
1006 dn_rt_finish_output(skb
, dn_rt_all_rt_mcast
, src
);
1009 static void dn_send_brd_hello(struct net_device
*dev
, struct dn_ifaddr
*ifa
)
1011 struct dn_dev
*dn_db
= (struct dn_dev
*)dev
->dn_ptr
;
1013 if (dn_db
->parms
.forwarding
== 0)
1014 dn_send_endnode_hello(dev
, ifa
);
1016 dn_send_router_hello(dev
, ifa
);
1019 static void dn_send_ptp_hello(struct net_device
*dev
, struct dn_ifaddr
*ifa
)
1022 int size
= dev
->hard_header_len
+ 2 + 4 + tdlen
;
1023 struct sk_buff
*skb
= dn_alloc_skb(NULL
, size
, GFP_ATOMIC
);
1032 skb_push(skb
, dev
->hard_header_len
);
1033 ptr
= skb_put(skb
, 2 + 4 + tdlen
);
1035 *ptr
++ = DN_RT_PKT_HELO
;
1036 *((__le16
*)ptr
) = ifa
->ifa_local
;
1040 for(i
= 0; i
< tdlen
; i
++)
1043 dn_dn2eth(src
, ifa
->ifa_local
);
1044 dn_rt_finish_output(skb
, dn_rt_all_rt_mcast
, src
);
1047 static int dn_eth_up(struct net_device
*dev
)
1049 struct dn_dev
*dn_db
= dev
->dn_ptr
;
1051 if (dn_db
->parms
.forwarding
== 0)
1052 dev_mc_add(dev
, dn_rt_all_end_mcast
, ETH_ALEN
, 0);
1054 dev_mc_add(dev
, dn_rt_all_rt_mcast
, ETH_ALEN
, 0);
1056 dn_db
->use_long
= 1;
1061 static void dn_eth_down(struct net_device
*dev
)
1063 struct dn_dev
*dn_db
= dev
->dn_ptr
;
1065 if (dn_db
->parms
.forwarding
== 0)
1066 dev_mc_delete(dev
, dn_rt_all_end_mcast
, ETH_ALEN
, 0);
1068 dev_mc_delete(dev
, dn_rt_all_rt_mcast
, ETH_ALEN
, 0);
1071 static void dn_dev_set_timer(struct net_device
*dev
);
1073 static void dn_dev_timer_func(unsigned long arg
)
1075 struct net_device
*dev
= (struct net_device
*)arg
;
1076 struct dn_dev
*dn_db
= dev
->dn_ptr
;
1077 struct dn_ifaddr
*ifa
;
1079 if (dn_db
->t3
<= dn_db
->parms
.t2
) {
1080 if (dn_db
->parms
.timer3
) {
1081 for(ifa
= dn_db
->ifa_list
; ifa
; ifa
= ifa
->ifa_next
) {
1082 if (!(ifa
->ifa_flags
& IFA_F_SECONDARY
))
1083 dn_db
->parms
.timer3(dev
, ifa
);
1086 dn_db
->t3
= dn_db
->parms
.t3
;
1088 dn_db
->t3
-= dn_db
->parms
.t2
;
1091 dn_dev_set_timer(dev
);
1094 static void dn_dev_set_timer(struct net_device
*dev
)
1096 struct dn_dev
*dn_db
= dev
->dn_ptr
;
1098 if (dn_db
->parms
.t2
> dn_db
->parms
.t3
)
1099 dn_db
->parms
.t2
= dn_db
->parms
.t3
;
1101 dn_db
->timer
.data
= (unsigned long)dev
;
1102 dn_db
->timer
.function
= dn_dev_timer_func
;
1103 dn_db
->timer
.expires
= jiffies
+ (dn_db
->parms
.t2
* HZ
);
1105 add_timer(&dn_db
->timer
);
1108 static struct dn_dev
*dn_dev_create(struct net_device
*dev
, int *err
)
1111 struct dn_dev_parms
*p
= dn_dev_list
;
1112 struct dn_dev
*dn_db
;
1114 for(i
= 0; i
< DN_DEV_LIST_SIZE
; i
++, p
++) {
1115 if (p
->type
== dev
->type
)
1120 if (i
== DN_DEV_LIST_SIZE
)
1124 if ((dn_db
= kzalloc(sizeof(struct dn_dev
), GFP_ATOMIC
)) == NULL
)
1127 memcpy(&dn_db
->parms
, p
, sizeof(struct dn_dev_parms
));
1129 dev
->dn_ptr
= dn_db
;
1131 init_timer(&dn_db
->timer
);
1133 dn_db
->uptime
= jiffies
;
1135 dn_db
->neigh_parms
= neigh_parms_alloc(dev
, &dn_neigh_table
);
1136 if (!dn_db
->neigh_parms
) {
1142 if (dn_db
->parms
.up
) {
1143 if (dn_db
->parms
.up(dev
) < 0) {
1144 neigh_parms_release(&dn_neigh_table
, dn_db
->neigh_parms
);
1151 dn_dev_sysctl_register(dev
, &dn_db
->parms
);
1153 dn_dev_set_timer(dev
);
1161 * This processes a device up event. We only start up
1162 * the loopback device & ethernet devices with correct
1163 * MAC addreses automatically. Others must be started
1166 * FIXME: How should we configure the loopback address ? If we could dispense
1167 * with using decnet_address here and for autobind, it will be one less thing
1168 * for users to worry about setting up.
1171 void dn_dev_up(struct net_device
*dev
)
1173 struct dn_ifaddr
*ifa
;
1174 __le16 addr
= decnet_address
;
1175 int maybe_default
= 0;
1176 struct dn_dev
*dn_db
= (struct dn_dev
*)dev
->dn_ptr
;
1178 if ((dev
->type
!= ARPHRD_ETHER
) && (dev
->type
!= ARPHRD_LOOPBACK
))
1182 * Need to ensure that loopback device has a dn_db attached to it
1183 * to allow creation of neighbours against it, even though it might
1184 * not have a local address of its own. Might as well do the same for
1185 * all autoconfigured interfaces.
1187 if (dn_db
== NULL
) {
1189 dn_db
= dn_dev_create(dev
, &err
);
1194 if (dev
->type
== ARPHRD_ETHER
) {
1195 if (memcmp(dev
->dev_addr
, dn_hiord
, 4) != 0)
1197 addr
= dn_eth2dn(dev
->dev_addr
);
1204 if ((ifa
= dn_dev_alloc_ifa()) == NULL
)
1207 ifa
->ifa_local
= ifa
->ifa_address
= addr
;
1209 ifa
->ifa_scope
= RT_SCOPE_UNIVERSE
;
1210 strcpy(ifa
->ifa_label
, dev
->name
);
1212 dn_dev_set_ifa(dev
, ifa
);
1215 * Automagically set the default device to the first automatically
1216 * configured ethernet card in the system.
1218 if (maybe_default
) {
1220 if (dn_dev_set_default(dev
, 0))
1225 static void dn_dev_delete(struct net_device
*dev
)
1227 struct dn_dev
*dn_db
= dev
->dn_ptr
;
1232 del_timer_sync(&dn_db
->timer
);
1233 dn_dev_sysctl_unregister(&dn_db
->parms
);
1234 dn_dev_check_default(dev
);
1235 neigh_ifdown(&dn_neigh_table
, dev
);
1237 if (dn_db
->parms
.down
)
1238 dn_db
->parms
.down(dev
);
1242 neigh_parms_release(&dn_neigh_table
, dn_db
->neigh_parms
);
1243 neigh_ifdown(&dn_neigh_table
, dev
);
1246 neigh_release(dn_db
->router
);
1248 neigh_release(dn_db
->peer
);
1253 void dn_dev_down(struct net_device
*dev
)
1255 struct dn_dev
*dn_db
= dev
->dn_ptr
;
1256 struct dn_ifaddr
*ifa
;
1261 while((ifa
= dn_db
->ifa_list
) != NULL
) {
1262 dn_dev_del_ifa(dn_db
, &dn_db
->ifa_list
, 0);
1263 dn_dev_free_ifa(ifa
);
1269 void dn_dev_init_pkt(struct sk_buff
*skb
)
1274 void dn_dev_veri_pkt(struct sk_buff
*skb
)
1279 void dn_dev_hello(struct sk_buff
*skb
)
1284 void dn_dev_devices_off(void)
1286 struct net_device
*dev
;
1289 for_each_netdev(&init_net
, dev
)
1295 void dn_dev_devices_on(void)
1297 struct net_device
*dev
;
1300 for_each_netdev(&init_net
, dev
) {
1301 if (dev
->flags
& IFF_UP
)
1307 int register_dnaddr_notifier(struct notifier_block
*nb
)
1309 return blocking_notifier_chain_register(&dnaddr_chain
, nb
);
1312 int unregister_dnaddr_notifier(struct notifier_block
*nb
)
1314 return blocking_notifier_chain_unregister(&dnaddr_chain
, nb
);
1317 #ifdef CONFIG_PROC_FS
1318 static inline int is_dn_dev(struct net_device
*dev
)
1320 return dev
->dn_ptr
!= NULL
;
1323 static void *dn_dev_seq_start(struct seq_file
*seq
, loff_t
*pos
)
1324 __acquires(&dev_base_lock
)
1327 struct net_device
*dev
;
1329 read_lock(&dev_base_lock
);
1332 return SEQ_START_TOKEN
;
1335 for_each_netdev(&init_net
, dev
) {
1336 if (!is_dn_dev(dev
))
1346 static void *dn_dev_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
1348 struct net_device
*dev
;
1352 dev
= (struct net_device
*)v
;
1353 if (v
== SEQ_START_TOKEN
)
1354 dev
= net_device_entry(&init_net
.dev_base_head
);
1356 for_each_netdev_continue(&init_net
, dev
) {
1357 if (!is_dn_dev(dev
))
1366 static void dn_dev_seq_stop(struct seq_file
*seq
, void *v
)
1367 __releases(&dev_base_lock
)
1369 read_unlock(&dev_base_lock
);
1372 static char *dn_type2asc(char type
)
1386 static int dn_dev_seq_show(struct seq_file
*seq
, void *v
)
1388 if (v
== SEQ_START_TOKEN
)
1389 seq_puts(seq
, "Name Flags T1 Timer1 T3 Timer3 BlkSize Pri State DevType Router Peer\n");
1391 struct net_device
*dev
= v
;
1392 char peer_buf
[DN_ASCBUF_LEN
];
1393 char router_buf
[DN_ASCBUF_LEN
];
1394 struct dn_dev
*dn_db
= dev
->dn_ptr
;
1396 seq_printf(seq
, "%-8s %1s %04u %04u %04lu %04lu"
1397 " %04hu %03d %02x %-10s %-7s %-7s\n",
1398 dev
->name
? dev
->name
: "???",
1399 dn_type2asc(dn_db
->parms
.mode
),
1401 dn_db
->t3
, dn_db
->parms
.t3
,
1403 dn_db
->parms
.priority
,
1404 dn_db
->parms
.state
, dn_db
->parms
.name
,
1405 dn_db
->router
? dn_addr2asc(le16_to_cpu(*(__le16
*)dn_db
->router
->primary_key
), router_buf
) : "",
1406 dn_db
->peer
? dn_addr2asc(le16_to_cpu(*(__le16
*)dn_db
->peer
->primary_key
), peer_buf
) : "");
1411 static const struct seq_operations dn_dev_seq_ops
= {
1412 .start
= dn_dev_seq_start
,
1413 .next
= dn_dev_seq_next
,
1414 .stop
= dn_dev_seq_stop
,
1415 .show
= dn_dev_seq_show
,
1418 static int dn_dev_seq_open(struct inode
*inode
, struct file
*file
)
1420 return seq_open(file
, &dn_dev_seq_ops
);
1423 static const struct file_operations dn_dev_seq_fops
= {
1424 .owner
= THIS_MODULE
,
1425 .open
= dn_dev_seq_open
,
1427 .llseek
= seq_lseek
,
1428 .release
= seq_release
,
1431 #endif /* CONFIG_PROC_FS */
1434 module_param_array(addr
, int, NULL
, 0444);
1435 MODULE_PARM_DESC(addr
, "The DECnet address of this machine: area,node");
1437 void __init
dn_dev_init(void)
1439 if (addr
[0] > 63 || addr
[0] < 0) {
1440 printk(KERN_ERR
"DECnet: Area must be between 0 and 63");
1444 if (addr
[1] > 1023 || addr
[1] < 0) {
1445 printk(KERN_ERR
"DECnet: Node must be between 0 and 1023");
1449 decnet_address
= cpu_to_le16((addr
[0] << 10) | addr
[1]);
1451 dn_dev_devices_on();
1453 rtnl_register(PF_DECnet
, RTM_NEWADDR
, dn_nl_newaddr
, NULL
);
1454 rtnl_register(PF_DECnet
, RTM_DELADDR
, dn_nl_deladdr
, NULL
);
1455 rtnl_register(PF_DECnet
, RTM_GETADDR
, NULL
, dn_nl_dump_ifaddr
);
1457 proc_net_fops_create(&init_net
, "decnet_dev", S_IRUGO
, &dn_dev_seq_fops
);
1459 #ifdef CONFIG_SYSCTL
1462 for(i
= 0; i
< DN_DEV_LIST_SIZE
; i
++)
1463 dn_dev_sysctl_register(NULL
, &dn_dev_list
[i
]);
1465 #endif /* CONFIG_SYSCTL */
1468 void __exit
dn_dev_cleanup(void)
1470 #ifdef CONFIG_SYSCTL
1473 for(i
= 0; i
< DN_DEV_LIST_SIZE
; i
++)
1474 dn_dev_sysctl_unregister(&dn_dev_list
[i
]);
1476 #endif /* CONFIG_SYSCTL */
1478 proc_net_remove(&init_net
, "decnet_dev");
1480 dn_dev_devices_off();