[DECNET] address: Calculate accurate message size for netlink notifications
[linux-2.6/mini2440.git] / net / decnet / dn_dev.c
blob2459a8d236a0509dcd17d2b689d040f736a5edec
1 /*
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.
6 * DECnet Device Layer
8 * Authors: Steve Whitehouse <SteveW@ACM.org>
9 * Eduardo Marcelo Serrat <emserrat@geocities.com>
11 * Changes:
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/neighbour.h>
46 #include <net/dst.h>
47 #include <net/flow.h>
48 #include <net/fib_rules.h>
49 #include <net/netlink.h>
50 #include <net/dn.h>
51 #include <net/dn_dev.h>
52 #include <net/dn_route.h>
53 #include <net/dn_neigh.h>
54 #include <net/dn_fib.h>
56 #define DN_IFREQ_SIZE (sizeof(struct ifreq) - sizeof(struct sockaddr) + sizeof(struct sockaddr_dn))
58 static char dn_rt_all_end_mcast[ETH_ALEN] = {0xAB,0x00,0x00,0x04,0x00,0x00};
59 static char dn_rt_all_rt_mcast[ETH_ALEN] = {0xAB,0x00,0x00,0x03,0x00,0x00};
60 static char dn_hiord[ETH_ALEN] = {0xAA,0x00,0x04,0x00,0x00,0x00};
61 static unsigned char dn_eco_version[3] = {0x02,0x00,0x00};
63 extern struct neigh_table dn_neigh_table;
66 * decnet_address is kept in network order.
68 __le16 decnet_address = 0;
70 static DEFINE_RWLOCK(dndev_lock);
71 static struct net_device *decnet_default_device;
72 static BLOCKING_NOTIFIER_HEAD(dnaddr_chain);
74 static struct dn_dev *dn_dev_create(struct net_device *dev, int *err);
75 static void dn_dev_delete(struct net_device *dev);
76 static void rtmsg_ifa(int event, struct dn_ifaddr *ifa);
78 static int dn_eth_up(struct net_device *);
79 static void dn_eth_down(struct net_device *);
80 static void dn_send_brd_hello(struct net_device *dev, struct dn_ifaddr *ifa);
81 static void dn_send_ptp_hello(struct net_device *dev, struct dn_ifaddr *ifa);
83 static struct dn_dev_parms dn_dev_list[] = {
85 .type = ARPHRD_ETHER, /* Ethernet */
86 .mode = DN_DEV_BCAST,
87 .state = DN_DEV_S_RU,
88 .t2 = 1,
89 .t3 = 10,
90 .name = "ethernet",
91 .ctl_name = NET_DECNET_CONF_ETHER,
92 .up = dn_eth_up,
93 .down = dn_eth_down,
94 .timer3 = dn_send_brd_hello,
97 .type = ARPHRD_IPGRE, /* DECnet tunneled over GRE in IP */
98 .mode = DN_DEV_BCAST,
99 .state = DN_DEV_S_RU,
100 .t2 = 1,
101 .t3 = 10,
102 .name = "ipgre",
103 .ctl_name = NET_DECNET_CONF_GRE,
104 .timer3 = dn_send_brd_hello,
106 #if 0
108 .type = ARPHRD_X25, /* Bog standard X.25 */
109 .mode = DN_DEV_UCAST,
110 .state = DN_DEV_S_DS,
111 .t2 = 1,
112 .t3 = 120,
113 .name = "x25",
114 .ctl_name = NET_DECNET_CONF_X25,
115 .timer3 = dn_send_ptp_hello,
117 #endif
118 #if 0
120 .type = ARPHRD_PPP, /* DECnet over PPP */
121 .mode = DN_DEV_BCAST,
122 .state = DN_DEV_S_RU,
123 .t2 = 1,
124 .t3 = 10,
125 .name = "ppp",
126 .ctl_name = NET_DECNET_CONF_PPP,
127 .timer3 = dn_send_brd_hello,
129 #endif
131 .type = ARPHRD_DDCMP, /* DECnet over DDCMP */
132 .mode = DN_DEV_UCAST,
133 .state = DN_DEV_S_DS,
134 .t2 = 1,
135 .t3 = 120,
136 .name = "ddcmp",
137 .ctl_name = NET_DECNET_CONF_DDCMP,
138 .timer3 = dn_send_ptp_hello,
141 .type = ARPHRD_LOOPBACK, /* Loopback interface - always last */
142 .mode = DN_DEV_BCAST,
143 .state = DN_DEV_S_RU,
144 .t2 = 1,
145 .t3 = 10,
146 .name = "loopback",
147 .ctl_name = NET_DECNET_CONF_LOOPBACK,
148 .timer3 = dn_send_brd_hello,
152 #define DN_DEV_LIST_SIZE (sizeof(dn_dev_list)/sizeof(struct dn_dev_parms))
154 #define DN_DEV_PARMS_OFFSET(x) ((int) ((char *) &((struct dn_dev_parms *)0)->x))
156 #ifdef CONFIG_SYSCTL
158 static int min_t2[] = { 1 };
159 static int max_t2[] = { 60 }; /* No max specified, but this seems sensible */
160 static int min_t3[] = { 1 };
161 static int max_t3[] = { 8191 }; /* Must fit in 16 bits when multiplied by BCT3MULT or T3MULT */
163 static int min_priority[1];
164 static int max_priority[] = { 127 }; /* From DECnet spec */
166 static int dn_forwarding_proc(ctl_table *, int, struct file *,
167 void __user *, size_t *, loff_t *);
168 static int dn_forwarding_sysctl(ctl_table *table, int __user *name, int nlen,
169 void __user *oldval, size_t __user *oldlenp,
170 void __user *newval, size_t newlen,
171 void **context);
173 static struct dn_dev_sysctl_table {
174 struct ctl_table_header *sysctl_header;
175 ctl_table dn_dev_vars[5];
176 ctl_table dn_dev_dev[2];
177 ctl_table dn_dev_conf_dir[2];
178 ctl_table dn_dev_proto_dir[2];
179 ctl_table dn_dev_root_dir[2];
180 } dn_dev_sysctl = {
181 NULL,
184 .ctl_name = NET_DECNET_CONF_DEV_FORWARDING,
185 .procname = "forwarding",
186 .data = (void *)DN_DEV_PARMS_OFFSET(forwarding),
187 .maxlen = sizeof(int),
188 .mode = 0644,
189 .proc_handler = dn_forwarding_proc,
190 .strategy = dn_forwarding_sysctl,
193 .ctl_name = NET_DECNET_CONF_DEV_PRIORITY,
194 .procname = "priority",
195 .data = (void *)DN_DEV_PARMS_OFFSET(priority),
196 .maxlen = sizeof(int),
197 .mode = 0644,
198 .proc_handler = proc_dointvec_minmax,
199 .strategy = sysctl_intvec,
200 .extra1 = &min_priority,
201 .extra2 = &max_priority
204 .ctl_name = NET_DECNET_CONF_DEV_T2,
205 .procname = "t2",
206 .data = (void *)DN_DEV_PARMS_OFFSET(t2),
207 .maxlen = sizeof(int),
208 .mode = 0644,
209 .proc_handler = proc_dointvec_minmax,
210 .strategy = sysctl_intvec,
211 .extra1 = &min_t2,
212 .extra2 = &max_t2
215 .ctl_name = NET_DECNET_CONF_DEV_T3,
216 .procname = "t3",
217 .data = (void *)DN_DEV_PARMS_OFFSET(t3),
218 .maxlen = sizeof(int),
219 .mode = 0644,
220 .proc_handler = proc_dointvec_minmax,
221 .strategy = sysctl_intvec,
222 .extra1 = &min_t3,
223 .extra2 = &max_t3
228 .ctl_name = 0,
229 .procname = "",
230 .mode = 0555,
231 .child = dn_dev_sysctl.dn_dev_vars
232 }, {0}},
234 .ctl_name = NET_DECNET_CONF,
235 .procname = "conf",
236 .mode = 0555,
237 .child = dn_dev_sysctl.dn_dev_dev
238 }, {0}},
240 .ctl_name = NET_DECNET,
241 .procname = "decnet",
242 .mode = 0555,
243 .child = dn_dev_sysctl.dn_dev_conf_dir
244 }, {0}},
246 .ctl_name = CTL_NET,
247 .procname = "net",
248 .mode = 0555,
249 .child = dn_dev_sysctl.dn_dev_proto_dir
250 }, {0}}
253 static void dn_dev_sysctl_register(struct net_device *dev, struct dn_dev_parms *parms)
255 struct dn_dev_sysctl_table *t;
256 int i;
258 t = kmemdup(&dn_dev_sysctl, sizeof(*t), GFP_KERNEL);
259 if (t == NULL)
260 return;
262 for(i = 0; i < ARRAY_SIZE(t->dn_dev_vars) - 1; i++) {
263 long offset = (long)t->dn_dev_vars[i].data;
264 t->dn_dev_vars[i].data = ((char *)parms) + offset;
265 t->dn_dev_vars[i].de = NULL;
268 if (dev) {
269 t->dn_dev_dev[0].procname = dev->name;
270 t->dn_dev_dev[0].ctl_name = dev->ifindex;
271 } else {
272 t->dn_dev_dev[0].procname = parms->name;
273 t->dn_dev_dev[0].ctl_name = parms->ctl_name;
276 t->dn_dev_dev[0].child = t->dn_dev_vars;
277 t->dn_dev_dev[0].de = NULL;
278 t->dn_dev_conf_dir[0].child = t->dn_dev_dev;
279 t->dn_dev_conf_dir[0].de = NULL;
280 t->dn_dev_proto_dir[0].child = t->dn_dev_conf_dir;
281 t->dn_dev_proto_dir[0].de = NULL;
282 t->dn_dev_root_dir[0].child = t->dn_dev_proto_dir;
283 t->dn_dev_root_dir[0].de = NULL;
284 t->dn_dev_vars[0].extra1 = (void *)dev;
286 t->sysctl_header = register_sysctl_table(t->dn_dev_root_dir, 0);
287 if (t->sysctl_header == NULL)
288 kfree(t);
289 else
290 parms->sysctl = t;
293 static void dn_dev_sysctl_unregister(struct dn_dev_parms *parms)
295 if (parms->sysctl) {
296 struct dn_dev_sysctl_table *t = parms->sysctl;
297 parms->sysctl = NULL;
298 unregister_sysctl_table(t->sysctl_header);
299 kfree(t);
303 static int dn_forwarding_proc(ctl_table *table, int write,
304 struct file *filep,
305 void __user *buffer,
306 size_t *lenp, loff_t *ppos)
308 #ifdef CONFIG_DECNET_ROUTER
309 struct net_device *dev = table->extra1;
310 struct dn_dev *dn_db;
311 int err;
312 int tmp, old;
314 if (table->extra1 == NULL)
315 return -EINVAL;
317 dn_db = dev->dn_ptr;
318 old = dn_db->parms.forwarding;
320 err = proc_dointvec(table, write, filep, buffer, lenp, ppos);
322 if ((err >= 0) && write) {
323 if (dn_db->parms.forwarding < 0)
324 dn_db->parms.forwarding = 0;
325 if (dn_db->parms.forwarding > 2)
326 dn_db->parms.forwarding = 2;
328 * What an ugly hack this is... its works, just. It
329 * would be nice if sysctl/proc were just that little
330 * bit more flexible so I don't have to write a special
331 * routine, or suffer hacks like this - SJW
333 tmp = dn_db->parms.forwarding;
334 dn_db->parms.forwarding = old;
335 if (dn_db->parms.down)
336 dn_db->parms.down(dev);
337 dn_db->parms.forwarding = tmp;
338 if (dn_db->parms.up)
339 dn_db->parms.up(dev);
342 return err;
343 #else
344 return -EINVAL;
345 #endif
348 static int dn_forwarding_sysctl(ctl_table *table, int __user *name, int nlen,
349 void __user *oldval, size_t __user *oldlenp,
350 void __user *newval, size_t newlen,
351 void **context)
353 #ifdef CONFIG_DECNET_ROUTER
354 struct net_device *dev = table->extra1;
355 struct dn_dev *dn_db;
356 int value;
358 if (table->extra1 == NULL)
359 return -EINVAL;
361 dn_db = dev->dn_ptr;
363 if (newval && newlen) {
364 if (newlen != sizeof(int))
365 return -EINVAL;
367 if (get_user(value, (int __user *)newval))
368 return -EFAULT;
369 if (value < 0)
370 return -EINVAL;
371 if (value > 2)
372 return -EINVAL;
374 if (dn_db->parms.down)
375 dn_db->parms.down(dev);
376 dn_db->parms.forwarding = value;
377 if (dn_db->parms.up)
378 dn_db->parms.up(dev);
381 return 0;
382 #else
383 return -EINVAL;
384 #endif
387 #else /* CONFIG_SYSCTL */
388 static void dn_dev_sysctl_unregister(struct dn_dev_parms *parms)
391 static void dn_dev_sysctl_register(struct net_device *dev, struct dn_dev_parms *parms)
395 #endif /* CONFIG_SYSCTL */
397 static inline __u16 mtu2blksize(struct net_device *dev)
399 u32 blksize = dev->mtu;
400 if (blksize > 0xffff)
401 blksize = 0xffff;
403 if (dev->type == ARPHRD_ETHER ||
404 dev->type == ARPHRD_PPP ||
405 dev->type == ARPHRD_IPGRE ||
406 dev->type == ARPHRD_LOOPBACK)
407 blksize -= 2;
409 return (__u16)blksize;
412 static struct dn_ifaddr *dn_dev_alloc_ifa(void)
414 struct dn_ifaddr *ifa;
416 ifa = kzalloc(sizeof(*ifa), GFP_KERNEL);
418 return ifa;
421 static __inline__ void dn_dev_free_ifa(struct dn_ifaddr *ifa)
423 kfree(ifa);
426 static void dn_dev_del_ifa(struct dn_dev *dn_db, struct dn_ifaddr **ifap, int destroy)
428 struct dn_ifaddr *ifa1 = *ifap;
429 unsigned char mac_addr[6];
430 struct net_device *dev = dn_db->dev;
432 ASSERT_RTNL();
434 *ifap = ifa1->ifa_next;
436 if (dn_db->dev->type == ARPHRD_ETHER) {
437 if (ifa1->ifa_local != dn_eth2dn(dev->dev_addr)) {
438 dn_dn2eth(mac_addr, ifa1->ifa_local);
439 dev_mc_delete(dev, mac_addr, ETH_ALEN, 0);
443 rtmsg_ifa(RTM_DELADDR, ifa1);
444 blocking_notifier_call_chain(&dnaddr_chain, NETDEV_DOWN, ifa1);
445 if (destroy) {
446 dn_dev_free_ifa(ifa1);
448 if (dn_db->ifa_list == NULL)
449 dn_dev_delete(dn_db->dev);
453 static int dn_dev_insert_ifa(struct dn_dev *dn_db, struct dn_ifaddr *ifa)
455 struct net_device *dev = dn_db->dev;
456 struct dn_ifaddr *ifa1;
457 unsigned char mac_addr[6];
459 ASSERT_RTNL();
461 /* Check for duplicates */
462 for(ifa1 = dn_db->ifa_list; ifa1; ifa1 = ifa1->ifa_next) {
463 if (ifa1->ifa_local == ifa->ifa_local)
464 return -EEXIST;
467 if (dev->type == ARPHRD_ETHER) {
468 if (ifa->ifa_local != dn_eth2dn(dev->dev_addr)) {
469 dn_dn2eth(mac_addr, ifa->ifa_local);
470 dev_mc_add(dev, mac_addr, ETH_ALEN, 0);
471 dev_mc_upload(dev);
475 ifa->ifa_next = dn_db->ifa_list;
476 dn_db->ifa_list = ifa;
478 rtmsg_ifa(RTM_NEWADDR, ifa);
479 blocking_notifier_call_chain(&dnaddr_chain, NETDEV_UP, ifa);
481 return 0;
484 static int dn_dev_set_ifa(struct net_device *dev, struct dn_ifaddr *ifa)
486 struct dn_dev *dn_db = dev->dn_ptr;
487 int rv;
489 if (dn_db == NULL) {
490 int err;
491 dn_db = dn_dev_create(dev, &err);
492 if (dn_db == NULL)
493 return err;
496 ifa->ifa_dev = dn_db;
498 if (dev->flags & IFF_LOOPBACK)
499 ifa->ifa_scope = RT_SCOPE_HOST;
501 rv = dn_dev_insert_ifa(dn_db, ifa);
502 if (rv)
503 dn_dev_free_ifa(ifa);
504 return rv;
508 int dn_dev_ioctl(unsigned int cmd, void __user *arg)
510 char buffer[DN_IFREQ_SIZE];
511 struct ifreq *ifr = (struct ifreq *)buffer;
512 struct sockaddr_dn *sdn = (struct sockaddr_dn *)&ifr->ifr_addr;
513 struct dn_dev *dn_db;
514 struct net_device *dev;
515 struct dn_ifaddr *ifa = NULL, **ifap = NULL;
516 int ret = 0;
518 if (copy_from_user(ifr, arg, DN_IFREQ_SIZE))
519 return -EFAULT;
520 ifr->ifr_name[IFNAMSIZ-1] = 0;
522 #ifdef CONFIG_KMOD
523 dev_load(ifr->ifr_name);
524 #endif
526 switch(cmd) {
527 case SIOCGIFADDR:
528 break;
529 case SIOCSIFADDR:
530 if (!capable(CAP_NET_ADMIN))
531 return -EACCES;
532 if (sdn->sdn_family != AF_DECnet)
533 return -EINVAL;
534 break;
535 default:
536 return -EINVAL;
539 rtnl_lock();
541 if ((dev = __dev_get_by_name(ifr->ifr_name)) == NULL) {
542 ret = -ENODEV;
543 goto done;
546 if ((dn_db = dev->dn_ptr) != NULL) {
547 for (ifap = &dn_db->ifa_list; (ifa=*ifap) != NULL; ifap = &ifa->ifa_next)
548 if (strcmp(ifr->ifr_name, ifa->ifa_label) == 0)
549 break;
552 if (ifa == NULL && cmd != SIOCSIFADDR) {
553 ret = -EADDRNOTAVAIL;
554 goto done;
557 switch(cmd) {
558 case SIOCGIFADDR:
559 *((__le16 *)sdn->sdn_nodeaddr) = ifa->ifa_local;
560 goto rarok;
562 case SIOCSIFADDR:
563 if (!ifa) {
564 if ((ifa = dn_dev_alloc_ifa()) == NULL) {
565 ret = -ENOBUFS;
566 break;
568 memcpy(ifa->ifa_label, dev->name, IFNAMSIZ);
569 } else {
570 if (ifa->ifa_local == dn_saddr2dn(sdn))
571 break;
572 dn_dev_del_ifa(dn_db, ifap, 0);
575 ifa->ifa_local = ifa->ifa_address = dn_saddr2dn(sdn);
577 ret = dn_dev_set_ifa(dev, ifa);
579 done:
580 rtnl_unlock();
582 return ret;
583 rarok:
584 if (copy_to_user(arg, ifr, DN_IFREQ_SIZE))
585 ret = -EFAULT;
586 goto done;
589 struct net_device *dn_dev_get_default(void)
591 struct net_device *dev;
592 read_lock(&dndev_lock);
593 dev = decnet_default_device;
594 if (dev) {
595 if (dev->dn_ptr)
596 dev_hold(dev);
597 else
598 dev = NULL;
600 read_unlock(&dndev_lock);
601 return dev;
604 int dn_dev_set_default(struct net_device *dev, int force)
606 struct net_device *old = NULL;
607 int rv = -EBUSY;
608 if (!dev->dn_ptr)
609 return -ENODEV;
610 write_lock(&dndev_lock);
611 if (force || decnet_default_device == NULL) {
612 old = decnet_default_device;
613 decnet_default_device = dev;
614 rv = 0;
616 write_unlock(&dndev_lock);
617 if (old)
618 dev_put(old);
619 return rv;
622 static void dn_dev_check_default(struct net_device *dev)
624 write_lock(&dndev_lock);
625 if (dev == decnet_default_device) {
626 decnet_default_device = NULL;
627 } else {
628 dev = NULL;
630 write_unlock(&dndev_lock);
631 if (dev)
632 dev_put(dev);
635 static struct dn_dev *dn_dev_by_index(int ifindex)
637 struct net_device *dev;
638 struct dn_dev *dn_dev = NULL;
639 dev = dev_get_by_index(ifindex);
640 if (dev) {
641 dn_dev = dev->dn_ptr;
642 dev_put(dev);
645 return dn_dev;
648 static int dn_dev_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
650 struct rtattr **rta = arg;
651 struct dn_dev *dn_db;
652 struct ifaddrmsg *ifm = NLMSG_DATA(nlh);
653 struct dn_ifaddr *ifa, **ifap;
655 if ((dn_db = dn_dev_by_index(ifm->ifa_index)) == NULL)
656 return -EADDRNOTAVAIL;
658 for(ifap = &dn_db->ifa_list; (ifa=*ifap) != NULL; ifap = &ifa->ifa_next) {
659 void *tmp = rta[IFA_LOCAL-1];
660 if ((tmp && memcmp(RTA_DATA(tmp), &ifa->ifa_local, 2)) ||
661 (rta[IFA_LABEL-1] && rtattr_strcmp(rta[IFA_LABEL-1], ifa->ifa_label)))
662 continue;
664 dn_dev_del_ifa(dn_db, ifap, 1);
665 return 0;
668 return -EADDRNOTAVAIL;
671 static int dn_dev_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
673 struct rtattr **rta = arg;
674 struct net_device *dev;
675 struct dn_dev *dn_db;
676 struct ifaddrmsg *ifm = NLMSG_DATA(nlh);
677 struct dn_ifaddr *ifa;
678 int rv;
680 if (rta[IFA_LOCAL-1] == NULL)
681 return -EINVAL;
683 if ((dev = __dev_get_by_index(ifm->ifa_index)) == NULL)
684 return -ENODEV;
686 if ((dn_db = dev->dn_ptr) == NULL) {
687 int err;
688 dn_db = dn_dev_create(dev, &err);
689 if (!dn_db)
690 return err;
693 if ((ifa = dn_dev_alloc_ifa()) == NULL)
694 return -ENOBUFS;
696 if (!rta[IFA_ADDRESS - 1])
697 rta[IFA_ADDRESS - 1] = rta[IFA_LOCAL - 1];
698 memcpy(&ifa->ifa_local, RTA_DATA(rta[IFA_LOCAL-1]), 2);
699 memcpy(&ifa->ifa_address, RTA_DATA(rta[IFA_ADDRESS-1]), 2);
700 ifa->ifa_flags = ifm->ifa_flags;
701 ifa->ifa_scope = ifm->ifa_scope;
702 ifa->ifa_dev = dn_db;
703 if (rta[IFA_LABEL-1])
704 rtattr_strlcpy(ifa->ifa_label, rta[IFA_LABEL-1], IFNAMSIZ);
705 else
706 memcpy(ifa->ifa_label, dev->name, IFNAMSIZ);
708 rv = dn_dev_insert_ifa(dn_db, ifa);
709 if (rv)
710 dn_dev_free_ifa(ifa);
711 return rv;
714 static inline size_t dn_ifaddr_nlmsg_size(void)
716 return NLMSG_ALIGN(sizeof(struct ifaddrmsg))
717 + nla_total_size(IFNAMSIZ) /* IFA_LABEL */
718 + nla_total_size(2) /* IFA_ADDRESS */
719 + nla_total_size(2); /* IFA_LOCAL */
722 static int dn_dev_fill_ifaddr(struct sk_buff *skb, struct dn_ifaddr *ifa,
723 u32 pid, u32 seq, int event, unsigned int flags)
725 struct ifaddrmsg *ifm;
726 struct nlmsghdr *nlh;
727 unsigned char *b = skb->tail;
729 nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*ifm), flags);
730 ifm = NLMSG_DATA(nlh);
732 ifm->ifa_family = AF_DECnet;
733 ifm->ifa_prefixlen = 16;
734 ifm->ifa_flags = ifa->ifa_flags | IFA_F_PERMANENT;
735 ifm->ifa_scope = ifa->ifa_scope;
736 ifm->ifa_index = ifa->ifa_dev->dev->ifindex;
737 if (ifa->ifa_address)
738 RTA_PUT(skb, IFA_ADDRESS, 2, &ifa->ifa_address);
739 if (ifa->ifa_local)
740 RTA_PUT(skb, IFA_LOCAL, 2, &ifa->ifa_local);
741 if (ifa->ifa_label[0])
742 RTA_PUT(skb, IFA_LABEL, IFNAMSIZ, &ifa->ifa_label);
743 nlh->nlmsg_len = skb->tail - b;
744 return skb->len;
746 nlmsg_failure:
747 rtattr_failure:
748 skb_trim(skb, b - skb->data);
749 return -1;
752 static void rtmsg_ifa(int event, struct dn_ifaddr *ifa)
754 struct sk_buff *skb;
755 int err = -ENOBUFS;
757 skb = alloc_skb(dn_ifaddr_nlmsg_size(), GFP_KERNEL);
758 if (skb == NULL)
759 goto errout;
761 err = dn_dev_fill_ifaddr(skb, ifa, 0, 0, event, 0);
762 /* failure implies BUG in dn_ifaddr_nlmsg_size() */
763 BUG_ON(err < 0);
765 err = rtnl_notify(skb, 0, RTNLGRP_DECnet_IFADDR, NULL, GFP_KERNEL);
766 errout:
767 if (err < 0)
768 rtnl_set_sk_err(RTNLGRP_DECnet_IFADDR, err);
771 static int dn_dev_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
773 int idx, dn_idx;
774 int s_idx, s_dn_idx;
775 struct net_device *dev;
776 struct dn_dev *dn_db;
777 struct dn_ifaddr *ifa;
779 s_idx = cb->args[0];
780 s_dn_idx = dn_idx = cb->args[1];
781 read_lock(&dev_base_lock);
782 for(dev = dev_base, idx = 0; dev; dev = dev->next, idx++) {
783 if (idx < s_idx)
784 continue;
785 if (idx > s_idx)
786 s_dn_idx = 0;
787 if ((dn_db = dev->dn_ptr) == NULL)
788 continue;
790 for(ifa = dn_db->ifa_list, dn_idx = 0; ifa; ifa = ifa->ifa_next, dn_idx++) {
791 if (dn_idx < s_dn_idx)
792 continue;
794 if (dn_dev_fill_ifaddr(skb, ifa,
795 NETLINK_CB(cb->skb).pid,
796 cb->nlh->nlmsg_seq,
797 RTM_NEWADDR,
798 NLM_F_MULTI) <= 0)
799 goto done;
802 done:
803 read_unlock(&dev_base_lock);
804 cb->args[0] = idx;
805 cb->args[1] = dn_idx;
807 return skb->len;
810 static int dn_dev_get_first(struct net_device *dev, __le16 *addr)
812 struct dn_dev *dn_db = (struct dn_dev *)dev->dn_ptr;
813 struct dn_ifaddr *ifa;
814 int rv = -ENODEV;
815 if (dn_db == NULL)
816 goto out;
817 ifa = dn_db->ifa_list;
818 if (ifa != NULL) {
819 *addr = ifa->ifa_local;
820 rv = 0;
822 out:
823 return rv;
827 * Find a default address to bind to.
829 * This is one of those areas where the initial VMS concepts don't really
830 * map onto the Linux concepts, and since we introduced multiple addresses
831 * per interface we have to cope with slightly odd ways of finding out what
832 * "our address" really is. Mostly it's not a problem; for this we just guess
833 * a sensible default. Eventually the routing code will take care of all the
834 * nasties for us I hope.
836 int dn_dev_bind_default(__le16 *addr)
838 struct net_device *dev;
839 int rv;
840 dev = dn_dev_get_default();
841 last_chance:
842 if (dev) {
843 read_lock(&dev_base_lock);
844 rv = dn_dev_get_first(dev, addr);
845 read_unlock(&dev_base_lock);
846 dev_put(dev);
847 if (rv == 0 || dev == &loopback_dev)
848 return rv;
850 dev = &loopback_dev;
851 dev_hold(dev);
852 goto last_chance;
855 static void dn_send_endnode_hello(struct net_device *dev, struct dn_ifaddr *ifa)
857 struct endnode_hello_message *msg;
858 struct sk_buff *skb = NULL;
859 __le16 *pktlen;
860 struct dn_dev *dn_db = (struct dn_dev *)dev->dn_ptr;
862 if ((skb = dn_alloc_skb(NULL, sizeof(*msg), GFP_ATOMIC)) == NULL)
863 return;
865 skb->dev = dev;
867 msg = (struct endnode_hello_message *)skb_put(skb,sizeof(*msg));
869 msg->msgflg = 0x0D;
870 memcpy(msg->tiver, dn_eco_version, 3);
871 dn_dn2eth(msg->id, ifa->ifa_local);
872 msg->iinfo = DN_RT_INFO_ENDN;
873 msg->blksize = dn_htons(mtu2blksize(dev));
874 msg->area = 0x00;
875 memset(msg->seed, 0, 8);
876 memcpy(msg->neighbor, dn_hiord, ETH_ALEN);
878 if (dn_db->router) {
879 struct dn_neigh *dn = (struct dn_neigh *)dn_db->router;
880 dn_dn2eth(msg->neighbor, dn->addr);
883 msg->timer = dn_htons((unsigned short)dn_db->parms.t3);
884 msg->mpd = 0x00;
885 msg->datalen = 0x02;
886 memset(msg->data, 0xAA, 2);
888 pktlen = (__le16 *)skb_push(skb,2);
889 *pktlen = dn_htons(skb->len - 2);
891 skb->nh.raw = skb->data;
893 dn_rt_finish_output(skb, dn_rt_all_rt_mcast, msg->id);
897 #define DRDELAY (5 * HZ)
899 static int dn_am_i_a_router(struct dn_neigh *dn, struct dn_dev *dn_db, struct dn_ifaddr *ifa)
901 /* First check time since device went up */
902 if ((jiffies - dn_db->uptime) < DRDELAY)
903 return 0;
905 /* If there is no router, then yes... */
906 if (!dn_db->router)
907 return 1;
909 /* otherwise only if we have a higher priority or.. */
910 if (dn->priority < dn_db->parms.priority)
911 return 1;
913 /* if we have equal priority and a higher node number */
914 if (dn->priority != dn_db->parms.priority)
915 return 0;
917 if (dn_ntohs(dn->addr) < dn_ntohs(ifa->ifa_local))
918 return 1;
920 return 0;
923 static void dn_send_router_hello(struct net_device *dev, struct dn_ifaddr *ifa)
925 int n;
926 struct dn_dev *dn_db = dev->dn_ptr;
927 struct dn_neigh *dn = (struct dn_neigh *)dn_db->router;
928 struct sk_buff *skb;
929 size_t size;
930 unsigned char *ptr;
931 unsigned char *i1, *i2;
932 __le16 *pktlen;
933 char *src;
935 if (mtu2blksize(dev) < (26 + 7))
936 return;
938 n = mtu2blksize(dev) - 26;
939 n /= 7;
941 if (n > 32)
942 n = 32;
944 size = 2 + 26 + 7 * n;
946 if ((skb = dn_alloc_skb(NULL, size, GFP_ATOMIC)) == NULL)
947 return;
949 skb->dev = dev;
950 ptr = skb_put(skb, size);
952 *ptr++ = DN_RT_PKT_CNTL | DN_RT_PKT_ERTH;
953 *ptr++ = 2; /* ECO */
954 *ptr++ = 0;
955 *ptr++ = 0;
956 dn_dn2eth(ptr, ifa->ifa_local);
957 src = ptr;
958 ptr += ETH_ALEN;
959 *ptr++ = dn_db->parms.forwarding == 1 ?
960 DN_RT_INFO_L1RT : DN_RT_INFO_L2RT;
961 *((__le16 *)ptr) = dn_htons(mtu2blksize(dev));
962 ptr += 2;
963 *ptr++ = dn_db->parms.priority; /* Priority */
964 *ptr++ = 0; /* Area: Reserved */
965 *((__le16 *)ptr) = dn_htons((unsigned short)dn_db->parms.t3);
966 ptr += 2;
967 *ptr++ = 0; /* MPD: Reserved */
968 i1 = ptr++;
969 memset(ptr, 0, 7); /* Name: Reserved */
970 ptr += 7;
971 i2 = ptr++;
973 n = dn_neigh_elist(dev, ptr, n);
975 *i2 = 7 * n;
976 *i1 = 8 + *i2;
978 skb_trim(skb, (27 + *i2));
980 pktlen = (__le16 *)skb_push(skb, 2);
981 *pktlen = dn_htons(skb->len - 2);
983 skb->nh.raw = skb->data;
985 if (dn_am_i_a_router(dn, dn_db, ifa)) {
986 struct sk_buff *skb2 = skb_copy(skb, GFP_ATOMIC);
987 if (skb2) {
988 dn_rt_finish_output(skb2, dn_rt_all_end_mcast, src);
992 dn_rt_finish_output(skb, dn_rt_all_rt_mcast, src);
995 static void dn_send_brd_hello(struct net_device *dev, struct dn_ifaddr *ifa)
997 struct dn_dev *dn_db = (struct dn_dev *)dev->dn_ptr;
999 if (dn_db->parms.forwarding == 0)
1000 dn_send_endnode_hello(dev, ifa);
1001 else
1002 dn_send_router_hello(dev, ifa);
1005 static void dn_send_ptp_hello(struct net_device *dev, struct dn_ifaddr *ifa)
1007 int tdlen = 16;
1008 int size = dev->hard_header_len + 2 + 4 + tdlen;
1009 struct sk_buff *skb = dn_alloc_skb(NULL, size, GFP_ATOMIC);
1010 int i;
1011 unsigned char *ptr;
1012 char src[ETH_ALEN];
1014 if (skb == NULL)
1015 return ;
1017 skb->dev = dev;
1018 skb_push(skb, dev->hard_header_len);
1019 ptr = skb_put(skb, 2 + 4 + tdlen);
1021 *ptr++ = DN_RT_PKT_HELO;
1022 *((__le16 *)ptr) = ifa->ifa_local;
1023 ptr += 2;
1024 *ptr++ = tdlen;
1026 for(i = 0; i < tdlen; i++)
1027 *ptr++ = 0252;
1029 dn_dn2eth(src, ifa->ifa_local);
1030 dn_rt_finish_output(skb, dn_rt_all_rt_mcast, src);
1033 static int dn_eth_up(struct net_device *dev)
1035 struct dn_dev *dn_db = dev->dn_ptr;
1037 if (dn_db->parms.forwarding == 0)
1038 dev_mc_add(dev, dn_rt_all_end_mcast, ETH_ALEN, 0);
1039 else
1040 dev_mc_add(dev, dn_rt_all_rt_mcast, ETH_ALEN, 0);
1042 dev_mc_upload(dev);
1044 dn_db->use_long = 1;
1046 return 0;
1049 static void dn_eth_down(struct net_device *dev)
1051 struct dn_dev *dn_db = dev->dn_ptr;
1053 if (dn_db->parms.forwarding == 0)
1054 dev_mc_delete(dev, dn_rt_all_end_mcast, ETH_ALEN, 0);
1055 else
1056 dev_mc_delete(dev, dn_rt_all_rt_mcast, ETH_ALEN, 0);
1059 static void dn_dev_set_timer(struct net_device *dev);
1061 static void dn_dev_timer_func(unsigned long arg)
1063 struct net_device *dev = (struct net_device *)arg;
1064 struct dn_dev *dn_db = dev->dn_ptr;
1065 struct dn_ifaddr *ifa;
1067 if (dn_db->t3 <= dn_db->parms.t2) {
1068 if (dn_db->parms.timer3) {
1069 for(ifa = dn_db->ifa_list; ifa; ifa = ifa->ifa_next) {
1070 if (!(ifa->ifa_flags & IFA_F_SECONDARY))
1071 dn_db->parms.timer3(dev, ifa);
1074 dn_db->t3 = dn_db->parms.t3;
1075 } else {
1076 dn_db->t3 -= dn_db->parms.t2;
1079 dn_dev_set_timer(dev);
1082 static void dn_dev_set_timer(struct net_device *dev)
1084 struct dn_dev *dn_db = dev->dn_ptr;
1086 if (dn_db->parms.t2 > dn_db->parms.t3)
1087 dn_db->parms.t2 = dn_db->parms.t3;
1089 dn_db->timer.data = (unsigned long)dev;
1090 dn_db->timer.function = dn_dev_timer_func;
1091 dn_db->timer.expires = jiffies + (dn_db->parms.t2 * HZ);
1093 add_timer(&dn_db->timer);
1096 struct dn_dev *dn_dev_create(struct net_device *dev, int *err)
1098 int i;
1099 struct dn_dev_parms *p = dn_dev_list;
1100 struct dn_dev *dn_db;
1102 for(i = 0; i < DN_DEV_LIST_SIZE; i++, p++) {
1103 if (p->type == dev->type)
1104 break;
1107 *err = -ENODEV;
1108 if (i == DN_DEV_LIST_SIZE)
1109 return NULL;
1111 *err = -ENOBUFS;
1112 if ((dn_db = kzalloc(sizeof(struct dn_dev), GFP_ATOMIC)) == NULL)
1113 return NULL;
1115 memcpy(&dn_db->parms, p, sizeof(struct dn_dev_parms));
1116 smp_wmb();
1117 dev->dn_ptr = dn_db;
1118 dn_db->dev = dev;
1119 init_timer(&dn_db->timer);
1121 dn_db->uptime = jiffies;
1122 if (dn_db->parms.up) {
1123 if (dn_db->parms.up(dev) < 0) {
1124 dev->dn_ptr = NULL;
1125 kfree(dn_db);
1126 return NULL;
1130 dn_db->neigh_parms = neigh_parms_alloc(dev, &dn_neigh_table);
1132 dn_dev_sysctl_register(dev, &dn_db->parms);
1134 dn_dev_set_timer(dev);
1136 *err = 0;
1137 return dn_db;
1142 * This processes a device up event. We only start up
1143 * the loopback device & ethernet devices with correct
1144 * MAC addreses automatically. Others must be started
1145 * specifically.
1147 * FIXME: How should we configure the loopback address ? If we could dispense
1148 * with using decnet_address here and for autobind, it will be one less thing
1149 * for users to worry about setting up.
1152 void dn_dev_up(struct net_device *dev)
1154 struct dn_ifaddr *ifa;
1155 __le16 addr = decnet_address;
1156 int maybe_default = 0;
1157 struct dn_dev *dn_db = (struct dn_dev *)dev->dn_ptr;
1159 if ((dev->type != ARPHRD_ETHER) && (dev->type != ARPHRD_LOOPBACK))
1160 return;
1163 * Need to ensure that loopback device has a dn_db attached to it
1164 * to allow creation of neighbours against it, even though it might
1165 * not have a local address of its own. Might as well do the same for
1166 * all autoconfigured interfaces.
1168 if (dn_db == NULL) {
1169 int err;
1170 dn_db = dn_dev_create(dev, &err);
1171 if (dn_db == NULL)
1172 return;
1175 if (dev->type == ARPHRD_ETHER) {
1176 if (memcmp(dev->dev_addr, dn_hiord, 4) != 0)
1177 return;
1178 addr = dn_eth2dn(dev->dev_addr);
1179 maybe_default = 1;
1182 if (addr == 0)
1183 return;
1185 if ((ifa = dn_dev_alloc_ifa()) == NULL)
1186 return;
1188 ifa->ifa_local = ifa->ifa_address = addr;
1189 ifa->ifa_flags = 0;
1190 ifa->ifa_scope = RT_SCOPE_UNIVERSE;
1191 strcpy(ifa->ifa_label, dev->name);
1193 dn_dev_set_ifa(dev, ifa);
1196 * Automagically set the default device to the first automatically
1197 * configured ethernet card in the system.
1199 if (maybe_default) {
1200 dev_hold(dev);
1201 if (dn_dev_set_default(dev, 0))
1202 dev_put(dev);
1206 static void dn_dev_delete(struct net_device *dev)
1208 struct dn_dev *dn_db = dev->dn_ptr;
1210 if (dn_db == NULL)
1211 return;
1213 del_timer_sync(&dn_db->timer);
1214 dn_dev_sysctl_unregister(&dn_db->parms);
1215 dn_dev_check_default(dev);
1216 neigh_ifdown(&dn_neigh_table, dev);
1218 if (dn_db->parms.down)
1219 dn_db->parms.down(dev);
1221 dev->dn_ptr = NULL;
1223 neigh_parms_release(&dn_neigh_table, dn_db->neigh_parms);
1224 neigh_ifdown(&dn_neigh_table, dev);
1226 if (dn_db->router)
1227 neigh_release(dn_db->router);
1228 if (dn_db->peer)
1229 neigh_release(dn_db->peer);
1231 kfree(dn_db);
1234 void dn_dev_down(struct net_device *dev)
1236 struct dn_dev *dn_db = dev->dn_ptr;
1237 struct dn_ifaddr *ifa;
1239 if (dn_db == NULL)
1240 return;
1242 while((ifa = dn_db->ifa_list) != NULL) {
1243 dn_dev_del_ifa(dn_db, &dn_db->ifa_list, 0);
1244 dn_dev_free_ifa(ifa);
1247 dn_dev_delete(dev);
1250 void dn_dev_init_pkt(struct sk_buff *skb)
1252 return;
1255 void dn_dev_veri_pkt(struct sk_buff *skb)
1257 return;
1260 void dn_dev_hello(struct sk_buff *skb)
1262 return;
1265 void dn_dev_devices_off(void)
1267 struct net_device *dev;
1269 rtnl_lock();
1270 for(dev = dev_base; dev; dev = dev->next)
1271 dn_dev_down(dev);
1272 rtnl_unlock();
1276 void dn_dev_devices_on(void)
1278 struct net_device *dev;
1280 rtnl_lock();
1281 for(dev = dev_base; dev; dev = dev->next) {
1282 if (dev->flags & IFF_UP)
1283 dn_dev_up(dev);
1285 rtnl_unlock();
1288 int register_dnaddr_notifier(struct notifier_block *nb)
1290 return blocking_notifier_chain_register(&dnaddr_chain, nb);
1293 int unregister_dnaddr_notifier(struct notifier_block *nb)
1295 return blocking_notifier_chain_unregister(&dnaddr_chain, nb);
1298 #ifdef CONFIG_PROC_FS
1299 static inline struct net_device *dn_dev_get_next(struct seq_file *seq, struct net_device *dev)
1301 do {
1302 dev = dev->next;
1303 } while(dev && !dev->dn_ptr);
1305 return dev;
1308 static struct net_device *dn_dev_get_idx(struct seq_file *seq, loff_t pos)
1310 struct net_device *dev;
1312 dev = dev_base;
1313 if (dev && !dev->dn_ptr)
1314 dev = dn_dev_get_next(seq, dev);
1315 if (pos) {
1316 while(dev && (dev = dn_dev_get_next(seq, dev)))
1317 --pos;
1319 return dev;
1322 static void *dn_dev_seq_start(struct seq_file *seq, loff_t *pos)
1324 if (*pos) {
1325 struct net_device *dev;
1326 read_lock(&dev_base_lock);
1327 dev = dn_dev_get_idx(seq, *pos - 1);
1328 if (dev == NULL)
1329 read_unlock(&dev_base_lock);
1330 return dev;
1332 return SEQ_START_TOKEN;
1335 static void *dn_dev_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1337 struct net_device *dev = v;
1338 loff_t one = 1;
1340 if (v == SEQ_START_TOKEN) {
1341 dev = dn_dev_seq_start(seq, &one);
1342 } else {
1343 dev = dn_dev_get_next(seq, dev);
1344 if (dev == NULL)
1345 read_unlock(&dev_base_lock);
1347 ++*pos;
1348 return dev;
1351 static void dn_dev_seq_stop(struct seq_file *seq, void *v)
1353 if (v && v != SEQ_START_TOKEN)
1354 read_unlock(&dev_base_lock);
1357 static char *dn_type2asc(char type)
1359 switch(type) {
1360 case DN_DEV_BCAST:
1361 return "B";
1362 case DN_DEV_UCAST:
1363 return "U";
1364 case DN_DEV_MPOINT:
1365 return "M";
1368 return "?";
1371 static int dn_dev_seq_show(struct seq_file *seq, void *v)
1373 if (v == SEQ_START_TOKEN)
1374 seq_puts(seq, "Name Flags T1 Timer1 T3 Timer3 BlkSize Pri State DevType Router Peer\n");
1375 else {
1376 struct net_device *dev = v;
1377 char peer_buf[DN_ASCBUF_LEN];
1378 char router_buf[DN_ASCBUF_LEN];
1379 struct dn_dev *dn_db = dev->dn_ptr;
1381 seq_printf(seq, "%-8s %1s %04u %04u %04lu %04lu"
1382 " %04hu %03d %02x %-10s %-7s %-7s\n",
1383 dev->name ? dev->name : "???",
1384 dn_type2asc(dn_db->parms.mode),
1385 0, 0,
1386 dn_db->t3, dn_db->parms.t3,
1387 mtu2blksize(dev),
1388 dn_db->parms.priority,
1389 dn_db->parms.state, dn_db->parms.name,
1390 dn_db->router ? dn_addr2asc(dn_ntohs(*(__le16 *)dn_db->router->primary_key), router_buf) : "",
1391 dn_db->peer ? dn_addr2asc(dn_ntohs(*(__le16 *)dn_db->peer->primary_key), peer_buf) : "");
1393 return 0;
1396 static struct seq_operations dn_dev_seq_ops = {
1397 .start = dn_dev_seq_start,
1398 .next = dn_dev_seq_next,
1399 .stop = dn_dev_seq_stop,
1400 .show = dn_dev_seq_show,
1403 static int dn_dev_seq_open(struct inode *inode, struct file *file)
1405 return seq_open(file, &dn_dev_seq_ops);
1408 static struct file_operations dn_dev_seq_fops = {
1409 .owner = THIS_MODULE,
1410 .open = dn_dev_seq_open,
1411 .read = seq_read,
1412 .llseek = seq_lseek,
1413 .release = seq_release,
1416 #endif /* CONFIG_PROC_FS */
1418 static struct rtnetlink_link dnet_rtnetlink_table[RTM_NR_MSGTYPES] =
1420 [RTM_NEWADDR - RTM_BASE] = { .doit = dn_dev_rtm_newaddr, },
1421 [RTM_DELADDR - RTM_BASE] = { .doit = dn_dev_rtm_deladdr, },
1422 [RTM_GETADDR - RTM_BASE] = { .dumpit = dn_dev_dump_ifaddr, },
1423 #ifdef CONFIG_DECNET_ROUTER
1424 [RTM_NEWROUTE - RTM_BASE] = { .doit = dn_fib_rtm_newroute, },
1425 [RTM_DELROUTE - RTM_BASE] = { .doit = dn_fib_rtm_delroute, },
1426 [RTM_GETROUTE - RTM_BASE] = { .doit = dn_cache_getroute,
1427 .dumpit = dn_fib_dump, },
1428 [RTM_GETRULE - RTM_BASE] = { .dumpit = dn_fib_dump_rules, },
1429 #else
1430 [RTM_GETROUTE - RTM_BASE] = { .doit = dn_cache_getroute,
1431 .dumpit = dn_cache_dump, },
1432 #endif
1436 static int __initdata addr[2];
1437 module_param_array(addr, int, NULL, 0444);
1438 MODULE_PARM_DESC(addr, "The DECnet address of this machine: area,node");
1440 void __init dn_dev_init(void)
1442 if (addr[0] > 63 || addr[0] < 0) {
1443 printk(KERN_ERR "DECnet: Area must be between 0 and 63");
1444 return;
1447 if (addr[1] > 1023 || addr[1] < 0) {
1448 printk(KERN_ERR "DECnet: Node must be between 0 and 1023");
1449 return;
1452 decnet_address = dn_htons((addr[0] << 10) | addr[1]);
1454 dn_dev_devices_on();
1456 rtnetlink_links[PF_DECnet] = dnet_rtnetlink_table;
1458 proc_net_fops_create("decnet_dev", S_IRUGO, &dn_dev_seq_fops);
1460 #ifdef CONFIG_SYSCTL
1462 int i;
1463 for(i = 0; i < DN_DEV_LIST_SIZE; i++)
1464 dn_dev_sysctl_register(NULL, &dn_dev_list[i]);
1466 #endif /* CONFIG_SYSCTL */
1469 void __exit dn_dev_cleanup(void)
1471 rtnetlink_links[PF_DECnet] = NULL;
1473 #ifdef CONFIG_SYSCTL
1475 int i;
1476 for(i = 0; i < DN_DEV_LIST_SIZE; i++)
1477 dn_dev_sysctl_unregister(&dn_dev_list[i]);
1479 #endif /* CONFIG_SYSCTL */
1481 proc_net_remove("decnet_dev");
1483 dn_dev_devices_off();