[NET]: Convert link modification to new netlink api
[linux-2.6/kmemtrace.git] / net / decnet / dn_dev.c
blob632c5a90b5895b5f983bac43c5b3efbc5e863f24
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/rtnetlink.h>
42 #include <linux/sysctl.h>
43 #include <linux/notifier.h>
44 #include <asm/uaccess.h>
45 #include <asm/system.h>
46 #include <net/neighbour.h>
47 #include <net/dst.h>
48 #include <net/flow.h>
49 #include <net/dn.h>
50 #include <net/dn_dev.h>
51 #include <net/dn_route.h>
52 #include <net/dn_neigh.h>
53 #include <net/dn_fib.h>
55 #define DN_IFREQ_SIZE (sizeof(struct ifreq) - sizeof(struct sockaddr) + sizeof(struct sockaddr_dn))
57 static char dn_rt_all_end_mcast[ETH_ALEN] = {0xAB,0x00,0x00,0x04,0x00,0x00};
58 static char dn_rt_all_rt_mcast[ETH_ALEN] = {0xAB,0x00,0x00,0x03,0x00,0x00};
59 static char dn_hiord[ETH_ALEN] = {0xAA,0x00,0x04,0x00,0x00,0x00};
60 static unsigned char dn_eco_version[3] = {0x02,0x00,0x00};
62 extern struct neigh_table dn_neigh_table;
65 * decnet_address is kept in network order.
67 __le16 decnet_address = 0;
69 static DEFINE_RWLOCK(dndev_lock);
70 static struct net_device *decnet_default_device;
71 static BLOCKING_NOTIFIER_HEAD(dnaddr_chain);
73 static struct dn_dev *dn_dev_create(struct net_device *dev, int *err);
74 static void dn_dev_delete(struct net_device *dev);
75 static void rtmsg_ifa(int event, struct dn_ifaddr *ifa);
77 static int dn_eth_up(struct net_device *);
78 static void dn_eth_down(struct net_device *);
79 static void dn_send_brd_hello(struct net_device *dev, struct dn_ifaddr *ifa);
80 static void dn_send_ptp_hello(struct net_device *dev, struct dn_ifaddr *ifa);
82 static struct dn_dev_parms dn_dev_list[] = {
84 .type = ARPHRD_ETHER, /* Ethernet */
85 .mode = DN_DEV_BCAST,
86 .state = DN_DEV_S_RU,
87 .t2 = 1,
88 .t3 = 10,
89 .name = "ethernet",
90 .ctl_name = NET_DECNET_CONF_ETHER,
91 .up = dn_eth_up,
92 .down = dn_eth_down,
93 .timer3 = dn_send_brd_hello,
96 .type = ARPHRD_IPGRE, /* DECnet tunneled over GRE in IP */
97 .mode = DN_DEV_BCAST,
98 .state = DN_DEV_S_RU,
99 .t2 = 1,
100 .t3 = 10,
101 .name = "ipgre",
102 .ctl_name = NET_DECNET_CONF_GRE,
103 .timer3 = dn_send_brd_hello,
105 #if 0
107 .type = ARPHRD_X25, /* Bog standard X.25 */
108 .mode = DN_DEV_UCAST,
109 .state = DN_DEV_S_DS,
110 .t2 = 1,
111 .t3 = 120,
112 .name = "x25",
113 .ctl_name = NET_DECNET_CONF_X25,
114 .timer3 = dn_send_ptp_hello,
116 #endif
117 #if 0
119 .type = ARPHRD_PPP, /* DECnet over PPP */
120 .mode = DN_DEV_BCAST,
121 .state = DN_DEV_S_RU,
122 .t2 = 1,
123 .t3 = 10,
124 .name = "ppp",
125 .ctl_name = NET_DECNET_CONF_PPP,
126 .timer3 = dn_send_brd_hello,
128 #endif
130 .type = ARPHRD_DDCMP, /* DECnet over DDCMP */
131 .mode = DN_DEV_UCAST,
132 .state = DN_DEV_S_DS,
133 .t2 = 1,
134 .t3 = 120,
135 .name = "ddcmp",
136 .ctl_name = NET_DECNET_CONF_DDCMP,
137 .timer3 = dn_send_ptp_hello,
140 .type = ARPHRD_LOOPBACK, /* Loopback interface - always last */
141 .mode = DN_DEV_BCAST,
142 .state = DN_DEV_S_RU,
143 .t2 = 1,
144 .t3 = 10,
145 .name = "loopback",
146 .ctl_name = NET_DECNET_CONF_LOOPBACK,
147 .timer3 = dn_send_brd_hello,
151 #define DN_DEV_LIST_SIZE (sizeof(dn_dev_list)/sizeof(struct dn_dev_parms))
153 #define DN_DEV_PARMS_OFFSET(x) ((int) ((char *) &((struct dn_dev_parms *)0)->x))
155 #ifdef CONFIG_SYSCTL
157 static int min_t2[] = { 1 };
158 static int max_t2[] = { 60 }; /* No max specified, but this seems sensible */
159 static int min_t3[] = { 1 };
160 static int max_t3[] = { 8191 }; /* Must fit in 16 bits when multiplied by BCT3MULT or T3MULT */
162 static int min_priority[1];
163 static int max_priority[] = { 127 }; /* From DECnet spec */
165 static int dn_forwarding_proc(ctl_table *, int, struct file *,
166 void __user *, size_t *, loff_t *);
167 static int dn_forwarding_sysctl(ctl_table *table, int __user *name, int nlen,
168 void __user *oldval, size_t __user *oldlenp,
169 void __user *newval, size_t newlen,
170 void **context);
172 static struct dn_dev_sysctl_table {
173 struct ctl_table_header *sysctl_header;
174 ctl_table dn_dev_vars[5];
175 ctl_table dn_dev_dev[2];
176 ctl_table dn_dev_conf_dir[2];
177 ctl_table dn_dev_proto_dir[2];
178 ctl_table dn_dev_root_dir[2];
179 } dn_dev_sysctl = {
180 NULL,
183 .ctl_name = NET_DECNET_CONF_DEV_FORWARDING,
184 .procname = "forwarding",
185 .data = (void *)DN_DEV_PARMS_OFFSET(forwarding),
186 .maxlen = sizeof(int),
187 .mode = 0644,
188 .proc_handler = dn_forwarding_proc,
189 .strategy = dn_forwarding_sysctl,
192 .ctl_name = NET_DECNET_CONF_DEV_PRIORITY,
193 .procname = "priority",
194 .data = (void *)DN_DEV_PARMS_OFFSET(priority),
195 .maxlen = sizeof(int),
196 .mode = 0644,
197 .proc_handler = proc_dointvec_minmax,
198 .strategy = sysctl_intvec,
199 .extra1 = &min_priority,
200 .extra2 = &max_priority
203 .ctl_name = NET_DECNET_CONF_DEV_T2,
204 .procname = "t2",
205 .data = (void *)DN_DEV_PARMS_OFFSET(t2),
206 .maxlen = sizeof(int),
207 .mode = 0644,
208 .proc_handler = proc_dointvec_minmax,
209 .strategy = sysctl_intvec,
210 .extra1 = &min_t2,
211 .extra2 = &max_t2
214 .ctl_name = NET_DECNET_CONF_DEV_T3,
215 .procname = "t3",
216 .data = (void *)DN_DEV_PARMS_OFFSET(t3),
217 .maxlen = sizeof(int),
218 .mode = 0644,
219 .proc_handler = proc_dointvec_minmax,
220 .strategy = sysctl_intvec,
221 .extra1 = &min_t3,
222 .extra2 = &max_t3
227 .ctl_name = 0,
228 .procname = "",
229 .mode = 0555,
230 .child = dn_dev_sysctl.dn_dev_vars
231 }, {0}},
233 .ctl_name = NET_DECNET_CONF,
234 .procname = "conf",
235 .mode = 0555,
236 .child = dn_dev_sysctl.dn_dev_dev
237 }, {0}},
239 .ctl_name = NET_DECNET,
240 .procname = "decnet",
241 .mode = 0555,
242 .child = dn_dev_sysctl.dn_dev_conf_dir
243 }, {0}},
245 .ctl_name = CTL_NET,
246 .procname = "net",
247 .mode = 0555,
248 .child = dn_dev_sysctl.dn_dev_proto_dir
249 }, {0}}
252 static void dn_dev_sysctl_register(struct net_device *dev, struct dn_dev_parms *parms)
254 struct dn_dev_sysctl_table *t;
255 int i;
257 t = kmalloc(sizeof(*t), GFP_KERNEL);
258 if (t == NULL)
259 return;
261 memcpy(t, &dn_dev_sysctl, sizeof(*t));
263 for(i = 0; i < ARRAY_SIZE(t->dn_dev_vars) - 1; i++) {
264 long offset = (long)t->dn_dev_vars[i].data;
265 t->dn_dev_vars[i].data = ((char *)parms) + offset;
266 t->dn_dev_vars[i].de = NULL;
269 if (dev) {
270 t->dn_dev_dev[0].procname = dev->name;
271 t->dn_dev_dev[0].ctl_name = dev->ifindex;
272 } else {
273 t->dn_dev_dev[0].procname = parms->name;
274 t->dn_dev_dev[0].ctl_name = parms->ctl_name;
277 t->dn_dev_dev[0].child = t->dn_dev_vars;
278 t->dn_dev_dev[0].de = NULL;
279 t->dn_dev_conf_dir[0].child = t->dn_dev_dev;
280 t->dn_dev_conf_dir[0].de = NULL;
281 t->dn_dev_proto_dir[0].child = t->dn_dev_conf_dir;
282 t->dn_dev_proto_dir[0].de = NULL;
283 t->dn_dev_root_dir[0].child = t->dn_dev_proto_dir;
284 t->dn_dev_root_dir[0].de = NULL;
285 t->dn_dev_vars[0].extra1 = (void *)dev;
287 t->sysctl_header = register_sysctl_table(t->dn_dev_root_dir, 0);
288 if (t->sysctl_header == NULL)
289 kfree(t);
290 else
291 parms->sysctl = t;
294 static void dn_dev_sysctl_unregister(struct dn_dev_parms *parms)
296 if (parms->sysctl) {
297 struct dn_dev_sysctl_table *t = parms->sysctl;
298 parms->sysctl = NULL;
299 unregister_sysctl_table(t->sysctl_header);
300 kfree(t);
304 static int dn_forwarding_proc(ctl_table *table, int write,
305 struct file *filep,
306 void __user *buffer,
307 size_t *lenp, loff_t *ppos)
309 #ifdef CONFIG_DECNET_ROUTER
310 struct net_device *dev = table->extra1;
311 struct dn_dev *dn_db;
312 int err;
313 int tmp, old;
315 if (table->extra1 == NULL)
316 return -EINVAL;
318 dn_db = dev->dn_ptr;
319 old = dn_db->parms.forwarding;
321 err = proc_dointvec(table, write, filep, buffer, lenp, ppos);
323 if ((err >= 0) && write) {
324 if (dn_db->parms.forwarding < 0)
325 dn_db->parms.forwarding = 0;
326 if (dn_db->parms.forwarding > 2)
327 dn_db->parms.forwarding = 2;
329 * What an ugly hack this is... its works, just. It
330 * would be nice if sysctl/proc were just that little
331 * bit more flexible so I don't have to write a special
332 * routine, or suffer hacks like this - SJW
334 tmp = dn_db->parms.forwarding;
335 dn_db->parms.forwarding = old;
336 if (dn_db->parms.down)
337 dn_db->parms.down(dev);
338 dn_db->parms.forwarding = tmp;
339 if (dn_db->parms.up)
340 dn_db->parms.up(dev);
343 return err;
344 #else
345 return -EINVAL;
346 #endif
349 static int dn_forwarding_sysctl(ctl_table *table, int __user *name, int nlen,
350 void __user *oldval, size_t __user *oldlenp,
351 void __user *newval, size_t newlen,
352 void **context)
354 #ifdef CONFIG_DECNET_ROUTER
355 struct net_device *dev = table->extra1;
356 struct dn_dev *dn_db;
357 int value;
359 if (table->extra1 == NULL)
360 return -EINVAL;
362 dn_db = dev->dn_ptr;
364 if (newval && newlen) {
365 if (newlen != sizeof(int))
366 return -EINVAL;
368 if (get_user(value, (int __user *)newval))
369 return -EFAULT;
370 if (value < 0)
371 return -EINVAL;
372 if (value > 2)
373 return -EINVAL;
375 if (dn_db->parms.down)
376 dn_db->parms.down(dev);
377 dn_db->parms.forwarding = value;
378 if (dn_db->parms.up)
379 dn_db->parms.up(dev);
382 return 0;
383 #else
384 return -EINVAL;
385 #endif
388 #else /* CONFIG_SYSCTL */
389 static void dn_dev_sysctl_unregister(struct dn_dev_parms *parms)
392 static void dn_dev_sysctl_register(struct net_device *dev, struct dn_dev_parms *parms)
396 #endif /* CONFIG_SYSCTL */
398 static inline __u16 mtu2blksize(struct net_device *dev)
400 u32 blksize = dev->mtu;
401 if (blksize > 0xffff)
402 blksize = 0xffff;
404 if (dev->type == ARPHRD_ETHER ||
405 dev->type == ARPHRD_PPP ||
406 dev->type == ARPHRD_IPGRE ||
407 dev->type == ARPHRD_LOOPBACK)
408 blksize -= 2;
410 return (__u16)blksize;
413 static struct dn_ifaddr *dn_dev_alloc_ifa(void)
415 struct dn_ifaddr *ifa;
417 ifa = kzalloc(sizeof(*ifa), GFP_KERNEL);
419 return ifa;
422 static __inline__ void dn_dev_free_ifa(struct dn_ifaddr *ifa)
424 kfree(ifa);
427 static void dn_dev_del_ifa(struct dn_dev *dn_db, struct dn_ifaddr **ifap, int destroy)
429 struct dn_ifaddr *ifa1 = *ifap;
430 unsigned char mac_addr[6];
431 struct net_device *dev = dn_db->dev;
433 ASSERT_RTNL();
435 *ifap = ifa1->ifa_next;
437 if (dn_db->dev->type == ARPHRD_ETHER) {
438 if (ifa1->ifa_local != dn_eth2dn(dev->dev_addr)) {
439 dn_dn2eth(mac_addr, ifa1->ifa_local);
440 dev_mc_delete(dev, mac_addr, ETH_ALEN, 0);
444 rtmsg_ifa(RTM_DELADDR, ifa1);
445 blocking_notifier_call_chain(&dnaddr_chain, NETDEV_DOWN, ifa1);
446 if (destroy) {
447 dn_dev_free_ifa(ifa1);
449 if (dn_db->ifa_list == NULL)
450 dn_dev_delete(dn_db->dev);
454 static int dn_dev_insert_ifa(struct dn_dev *dn_db, struct dn_ifaddr *ifa)
456 struct net_device *dev = dn_db->dev;
457 struct dn_ifaddr *ifa1;
458 unsigned char mac_addr[6];
460 ASSERT_RTNL();
462 /* Check for duplicates */
463 for(ifa1 = dn_db->ifa_list; ifa1; ifa1 = ifa1->ifa_next) {
464 if (ifa1->ifa_local == ifa->ifa_local)
465 return -EEXIST;
468 if (dev->type == ARPHRD_ETHER) {
469 if (ifa->ifa_local != dn_eth2dn(dev->dev_addr)) {
470 dn_dn2eth(mac_addr, ifa->ifa_local);
471 dev_mc_add(dev, mac_addr, ETH_ALEN, 0);
472 dev_mc_upload(dev);
476 ifa->ifa_next = dn_db->ifa_list;
477 dn_db->ifa_list = ifa;
479 rtmsg_ifa(RTM_NEWADDR, ifa);
480 blocking_notifier_call_chain(&dnaddr_chain, NETDEV_UP, ifa);
482 return 0;
485 static int dn_dev_set_ifa(struct net_device *dev, struct dn_ifaddr *ifa)
487 struct dn_dev *dn_db = dev->dn_ptr;
488 int rv;
490 if (dn_db == NULL) {
491 int err;
492 dn_db = dn_dev_create(dev, &err);
493 if (dn_db == NULL)
494 return err;
497 ifa->ifa_dev = dn_db;
499 if (dev->flags & IFF_LOOPBACK)
500 ifa->ifa_scope = RT_SCOPE_HOST;
502 rv = dn_dev_insert_ifa(dn_db, ifa);
503 if (rv)
504 dn_dev_free_ifa(ifa);
505 return rv;
509 int dn_dev_ioctl(unsigned int cmd, void __user *arg)
511 char buffer[DN_IFREQ_SIZE];
512 struct ifreq *ifr = (struct ifreq *)buffer;
513 struct sockaddr_dn *sdn = (struct sockaddr_dn *)&ifr->ifr_addr;
514 struct dn_dev *dn_db;
515 struct net_device *dev;
516 struct dn_ifaddr *ifa = NULL, **ifap = NULL;
517 int ret = 0;
519 if (copy_from_user(ifr, arg, DN_IFREQ_SIZE))
520 return -EFAULT;
521 ifr->ifr_name[IFNAMSIZ-1] = 0;
523 #ifdef CONFIG_KMOD
524 dev_load(ifr->ifr_name);
525 #endif
527 switch(cmd) {
528 case SIOCGIFADDR:
529 break;
530 case SIOCSIFADDR:
531 if (!capable(CAP_NET_ADMIN))
532 return -EACCES;
533 if (sdn->sdn_family != AF_DECnet)
534 return -EINVAL;
535 break;
536 default:
537 return -EINVAL;
540 rtnl_lock();
542 if ((dev = __dev_get_by_name(ifr->ifr_name)) == NULL) {
543 ret = -ENODEV;
544 goto done;
547 if ((dn_db = dev->dn_ptr) != NULL) {
548 for (ifap = &dn_db->ifa_list; (ifa=*ifap) != NULL; ifap = &ifa->ifa_next)
549 if (strcmp(ifr->ifr_name, ifa->ifa_label) == 0)
550 break;
553 if (ifa == NULL && cmd != SIOCSIFADDR) {
554 ret = -EADDRNOTAVAIL;
555 goto done;
558 switch(cmd) {
559 case SIOCGIFADDR:
560 *((__le16 *)sdn->sdn_nodeaddr) = ifa->ifa_local;
561 goto rarok;
563 case SIOCSIFADDR:
564 if (!ifa) {
565 if ((ifa = dn_dev_alloc_ifa()) == NULL) {
566 ret = -ENOBUFS;
567 break;
569 memcpy(ifa->ifa_label, dev->name, IFNAMSIZ);
570 } else {
571 if (ifa->ifa_local == dn_saddr2dn(sdn))
572 break;
573 dn_dev_del_ifa(dn_db, ifap, 0);
576 ifa->ifa_local = ifa->ifa_address = dn_saddr2dn(sdn);
578 ret = dn_dev_set_ifa(dev, ifa);
580 done:
581 rtnl_unlock();
583 return ret;
584 rarok:
585 if (copy_to_user(arg, ifr, DN_IFREQ_SIZE))
586 ret = -EFAULT;
587 goto done;
590 struct net_device *dn_dev_get_default(void)
592 struct net_device *dev;
593 read_lock(&dndev_lock);
594 dev = decnet_default_device;
595 if (dev) {
596 if (dev->dn_ptr)
597 dev_hold(dev);
598 else
599 dev = NULL;
601 read_unlock(&dndev_lock);
602 return dev;
605 int dn_dev_set_default(struct net_device *dev, int force)
607 struct net_device *old = NULL;
608 int rv = -EBUSY;
609 if (!dev->dn_ptr)
610 return -ENODEV;
611 write_lock(&dndev_lock);
612 if (force || decnet_default_device == NULL) {
613 old = decnet_default_device;
614 decnet_default_device = dev;
615 rv = 0;
617 write_unlock(&dndev_lock);
618 if (old)
619 dev_put(old);
620 return rv;
623 static void dn_dev_check_default(struct net_device *dev)
625 write_lock(&dndev_lock);
626 if (dev == decnet_default_device) {
627 decnet_default_device = NULL;
628 } else {
629 dev = NULL;
631 write_unlock(&dndev_lock);
632 if (dev)
633 dev_put(dev);
636 static struct dn_dev *dn_dev_by_index(int ifindex)
638 struct net_device *dev;
639 struct dn_dev *dn_dev = NULL;
640 dev = dev_get_by_index(ifindex);
641 if (dev) {
642 dn_dev = dev->dn_ptr;
643 dev_put(dev);
646 return dn_dev;
649 static int dn_dev_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
651 struct rtattr **rta = arg;
652 struct dn_dev *dn_db;
653 struct ifaddrmsg *ifm = NLMSG_DATA(nlh);
654 struct dn_ifaddr *ifa, **ifap;
656 if ((dn_db = dn_dev_by_index(ifm->ifa_index)) == NULL)
657 return -EADDRNOTAVAIL;
659 for(ifap = &dn_db->ifa_list; (ifa=*ifap) != NULL; ifap = &ifa->ifa_next) {
660 void *tmp = rta[IFA_LOCAL-1];
661 if ((tmp && memcmp(RTA_DATA(tmp), &ifa->ifa_local, 2)) ||
662 (rta[IFA_LABEL-1] && rtattr_strcmp(rta[IFA_LABEL-1], ifa->ifa_label)))
663 continue;
665 dn_dev_del_ifa(dn_db, ifap, 1);
666 return 0;
669 return -EADDRNOTAVAIL;
672 static int dn_dev_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
674 struct rtattr **rta = arg;
675 struct net_device *dev;
676 struct dn_dev *dn_db;
677 struct ifaddrmsg *ifm = NLMSG_DATA(nlh);
678 struct dn_ifaddr *ifa;
679 int rv;
681 if (rta[IFA_LOCAL-1] == NULL)
682 return -EINVAL;
684 if ((dev = __dev_get_by_index(ifm->ifa_index)) == NULL)
685 return -ENODEV;
687 if ((dn_db = dev->dn_ptr) == NULL) {
688 int err;
689 dn_db = dn_dev_create(dev, &err);
690 if (!dn_db)
691 return err;
694 if ((ifa = dn_dev_alloc_ifa()) == NULL)
695 return -ENOBUFS;
697 if (!rta[IFA_ADDRESS - 1])
698 rta[IFA_ADDRESS - 1] = rta[IFA_LOCAL - 1];
699 memcpy(&ifa->ifa_local, RTA_DATA(rta[IFA_LOCAL-1]), 2);
700 memcpy(&ifa->ifa_address, RTA_DATA(rta[IFA_ADDRESS-1]), 2);
701 ifa->ifa_flags = ifm->ifa_flags;
702 ifa->ifa_scope = ifm->ifa_scope;
703 ifa->ifa_dev = dn_db;
704 if (rta[IFA_LABEL-1])
705 rtattr_strlcpy(ifa->ifa_label, rta[IFA_LABEL-1], IFNAMSIZ);
706 else
707 memcpy(ifa->ifa_label, dev->name, IFNAMSIZ);
709 rv = dn_dev_insert_ifa(dn_db, ifa);
710 if (rv)
711 dn_dev_free_ifa(ifa);
712 return rv;
715 static int dn_dev_fill_ifaddr(struct sk_buff *skb, struct dn_ifaddr *ifa,
716 u32 pid, u32 seq, int event, unsigned int flags)
718 struct ifaddrmsg *ifm;
719 struct nlmsghdr *nlh;
720 unsigned char *b = skb->tail;
722 nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*ifm), flags);
723 ifm = NLMSG_DATA(nlh);
725 ifm->ifa_family = AF_DECnet;
726 ifm->ifa_prefixlen = 16;
727 ifm->ifa_flags = ifa->ifa_flags | IFA_F_PERMANENT;
728 ifm->ifa_scope = ifa->ifa_scope;
729 ifm->ifa_index = ifa->ifa_dev->dev->ifindex;
730 if (ifa->ifa_address)
731 RTA_PUT(skb, IFA_ADDRESS, 2, &ifa->ifa_address);
732 if (ifa->ifa_local)
733 RTA_PUT(skb, IFA_LOCAL, 2, &ifa->ifa_local);
734 if (ifa->ifa_label[0])
735 RTA_PUT(skb, IFA_LABEL, IFNAMSIZ, &ifa->ifa_label);
736 nlh->nlmsg_len = skb->tail - b;
737 return skb->len;
739 nlmsg_failure:
740 rtattr_failure:
741 skb_trim(skb, b - skb->data);
742 return -1;
745 static void rtmsg_ifa(int event, struct dn_ifaddr *ifa)
747 struct sk_buff *skb;
748 int size = NLMSG_SPACE(sizeof(struct ifaddrmsg)+128);
750 skb = alloc_skb(size, GFP_KERNEL);
751 if (!skb) {
752 netlink_set_err(rtnl, 0, RTNLGRP_DECnet_IFADDR, ENOBUFS);
753 return;
755 if (dn_dev_fill_ifaddr(skb, ifa, 0, 0, event, 0) < 0) {
756 kfree_skb(skb);
757 netlink_set_err(rtnl, 0, RTNLGRP_DECnet_IFADDR, EINVAL);
758 return;
760 NETLINK_CB(skb).dst_group = RTNLGRP_DECnet_IFADDR;
761 netlink_broadcast(rtnl, skb, 0, RTNLGRP_DECnet_IFADDR, GFP_KERNEL);
764 static int dn_dev_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
766 int idx, dn_idx;
767 int s_idx, s_dn_idx;
768 struct net_device *dev;
769 struct dn_dev *dn_db;
770 struct dn_ifaddr *ifa;
772 s_idx = cb->args[0];
773 s_dn_idx = dn_idx = cb->args[1];
774 read_lock(&dev_base_lock);
775 for(dev = dev_base, idx = 0; dev; dev = dev->next, idx++) {
776 if (idx < s_idx)
777 continue;
778 if (idx > s_idx)
779 s_dn_idx = 0;
780 if ((dn_db = dev->dn_ptr) == NULL)
781 continue;
783 for(ifa = dn_db->ifa_list, dn_idx = 0; ifa; ifa = ifa->ifa_next, dn_idx++) {
784 if (dn_idx < s_dn_idx)
785 continue;
787 if (dn_dev_fill_ifaddr(skb, ifa,
788 NETLINK_CB(cb->skb).pid,
789 cb->nlh->nlmsg_seq,
790 RTM_NEWADDR,
791 NLM_F_MULTI) <= 0)
792 goto done;
795 done:
796 read_unlock(&dev_base_lock);
797 cb->args[0] = idx;
798 cb->args[1] = dn_idx;
800 return skb->len;
803 static int dn_dev_get_first(struct net_device *dev, __le16 *addr)
805 struct dn_dev *dn_db = (struct dn_dev *)dev->dn_ptr;
806 struct dn_ifaddr *ifa;
807 int rv = -ENODEV;
808 if (dn_db == NULL)
809 goto out;
810 ifa = dn_db->ifa_list;
811 if (ifa != NULL) {
812 *addr = ifa->ifa_local;
813 rv = 0;
815 out:
816 return rv;
820 * Find a default address to bind to.
822 * This is one of those areas where the initial VMS concepts don't really
823 * map onto the Linux concepts, and since we introduced multiple addresses
824 * per interface we have to cope with slightly odd ways of finding out what
825 * "our address" really is. Mostly it's not a problem; for this we just guess
826 * a sensible default. Eventually the routing code will take care of all the
827 * nasties for us I hope.
829 int dn_dev_bind_default(__le16 *addr)
831 struct net_device *dev;
832 int rv;
833 dev = dn_dev_get_default();
834 last_chance:
835 if (dev) {
836 read_lock(&dev_base_lock);
837 rv = dn_dev_get_first(dev, addr);
838 read_unlock(&dev_base_lock);
839 dev_put(dev);
840 if (rv == 0 || dev == &loopback_dev)
841 return rv;
843 dev = &loopback_dev;
844 dev_hold(dev);
845 goto last_chance;
848 static void dn_send_endnode_hello(struct net_device *dev, struct dn_ifaddr *ifa)
850 struct endnode_hello_message *msg;
851 struct sk_buff *skb = NULL;
852 __le16 *pktlen;
853 struct dn_dev *dn_db = (struct dn_dev *)dev->dn_ptr;
855 if ((skb = dn_alloc_skb(NULL, sizeof(*msg), GFP_ATOMIC)) == NULL)
856 return;
858 skb->dev = dev;
860 msg = (struct endnode_hello_message *)skb_put(skb,sizeof(*msg));
862 msg->msgflg = 0x0D;
863 memcpy(msg->tiver, dn_eco_version, 3);
864 dn_dn2eth(msg->id, ifa->ifa_local);
865 msg->iinfo = DN_RT_INFO_ENDN;
866 msg->blksize = dn_htons(mtu2blksize(dev));
867 msg->area = 0x00;
868 memset(msg->seed, 0, 8);
869 memcpy(msg->neighbor, dn_hiord, ETH_ALEN);
871 if (dn_db->router) {
872 struct dn_neigh *dn = (struct dn_neigh *)dn_db->router;
873 dn_dn2eth(msg->neighbor, dn->addr);
876 msg->timer = dn_htons((unsigned short)dn_db->parms.t3);
877 msg->mpd = 0x00;
878 msg->datalen = 0x02;
879 memset(msg->data, 0xAA, 2);
881 pktlen = (__le16 *)skb_push(skb,2);
882 *pktlen = dn_htons(skb->len - 2);
884 skb->nh.raw = skb->data;
886 dn_rt_finish_output(skb, dn_rt_all_rt_mcast, msg->id);
890 #define DRDELAY (5 * HZ)
892 static int dn_am_i_a_router(struct dn_neigh *dn, struct dn_dev *dn_db, struct dn_ifaddr *ifa)
894 /* First check time since device went up */
895 if ((jiffies - dn_db->uptime) < DRDELAY)
896 return 0;
898 /* If there is no router, then yes... */
899 if (!dn_db->router)
900 return 1;
902 /* otherwise only if we have a higher priority or.. */
903 if (dn->priority < dn_db->parms.priority)
904 return 1;
906 /* if we have equal priority and a higher node number */
907 if (dn->priority != dn_db->parms.priority)
908 return 0;
910 if (dn_ntohs(dn->addr) < dn_ntohs(ifa->ifa_local))
911 return 1;
913 return 0;
916 static void dn_send_router_hello(struct net_device *dev, struct dn_ifaddr *ifa)
918 int n;
919 struct dn_dev *dn_db = dev->dn_ptr;
920 struct dn_neigh *dn = (struct dn_neigh *)dn_db->router;
921 struct sk_buff *skb;
922 size_t size;
923 unsigned char *ptr;
924 unsigned char *i1, *i2;
925 __le16 *pktlen;
926 char *src;
928 if (mtu2blksize(dev) < (26 + 7))
929 return;
931 n = mtu2blksize(dev) - 26;
932 n /= 7;
934 if (n > 32)
935 n = 32;
937 size = 2 + 26 + 7 * n;
939 if ((skb = dn_alloc_skb(NULL, size, GFP_ATOMIC)) == NULL)
940 return;
942 skb->dev = dev;
943 ptr = skb_put(skb, size);
945 *ptr++ = DN_RT_PKT_CNTL | DN_RT_PKT_ERTH;
946 *ptr++ = 2; /* ECO */
947 *ptr++ = 0;
948 *ptr++ = 0;
949 dn_dn2eth(ptr, ifa->ifa_local);
950 src = ptr;
951 ptr += ETH_ALEN;
952 *ptr++ = dn_db->parms.forwarding == 1 ?
953 DN_RT_INFO_L1RT : DN_RT_INFO_L2RT;
954 *((__le16 *)ptr) = dn_htons(mtu2blksize(dev));
955 ptr += 2;
956 *ptr++ = dn_db->parms.priority; /* Priority */
957 *ptr++ = 0; /* Area: Reserved */
958 *((__le16 *)ptr) = dn_htons((unsigned short)dn_db->parms.t3);
959 ptr += 2;
960 *ptr++ = 0; /* MPD: Reserved */
961 i1 = ptr++;
962 memset(ptr, 0, 7); /* Name: Reserved */
963 ptr += 7;
964 i2 = ptr++;
966 n = dn_neigh_elist(dev, ptr, n);
968 *i2 = 7 * n;
969 *i1 = 8 + *i2;
971 skb_trim(skb, (27 + *i2));
973 pktlen = (__le16 *)skb_push(skb, 2);
974 *pktlen = dn_htons(skb->len - 2);
976 skb->nh.raw = skb->data;
978 if (dn_am_i_a_router(dn, dn_db, ifa)) {
979 struct sk_buff *skb2 = skb_copy(skb, GFP_ATOMIC);
980 if (skb2) {
981 dn_rt_finish_output(skb2, dn_rt_all_end_mcast, src);
985 dn_rt_finish_output(skb, dn_rt_all_rt_mcast, src);
988 static void dn_send_brd_hello(struct net_device *dev, struct dn_ifaddr *ifa)
990 struct dn_dev *dn_db = (struct dn_dev *)dev->dn_ptr;
992 if (dn_db->parms.forwarding == 0)
993 dn_send_endnode_hello(dev, ifa);
994 else
995 dn_send_router_hello(dev, ifa);
998 static void dn_send_ptp_hello(struct net_device *dev, struct dn_ifaddr *ifa)
1000 int tdlen = 16;
1001 int size = dev->hard_header_len + 2 + 4 + tdlen;
1002 struct sk_buff *skb = dn_alloc_skb(NULL, size, GFP_ATOMIC);
1003 int i;
1004 unsigned char *ptr;
1005 char src[ETH_ALEN];
1007 if (skb == NULL)
1008 return ;
1010 skb->dev = dev;
1011 skb_push(skb, dev->hard_header_len);
1012 ptr = skb_put(skb, 2 + 4 + tdlen);
1014 *ptr++ = DN_RT_PKT_HELO;
1015 *((__le16 *)ptr) = ifa->ifa_local;
1016 ptr += 2;
1017 *ptr++ = tdlen;
1019 for(i = 0; i < tdlen; i++)
1020 *ptr++ = 0252;
1022 dn_dn2eth(src, ifa->ifa_local);
1023 dn_rt_finish_output(skb, dn_rt_all_rt_mcast, src);
1026 static int dn_eth_up(struct net_device *dev)
1028 struct dn_dev *dn_db = dev->dn_ptr;
1030 if (dn_db->parms.forwarding == 0)
1031 dev_mc_add(dev, dn_rt_all_end_mcast, ETH_ALEN, 0);
1032 else
1033 dev_mc_add(dev, dn_rt_all_rt_mcast, ETH_ALEN, 0);
1035 dev_mc_upload(dev);
1037 dn_db->use_long = 1;
1039 return 0;
1042 static void dn_eth_down(struct net_device *dev)
1044 struct dn_dev *dn_db = dev->dn_ptr;
1046 if (dn_db->parms.forwarding == 0)
1047 dev_mc_delete(dev, dn_rt_all_end_mcast, ETH_ALEN, 0);
1048 else
1049 dev_mc_delete(dev, dn_rt_all_rt_mcast, ETH_ALEN, 0);
1052 static void dn_dev_set_timer(struct net_device *dev);
1054 static void dn_dev_timer_func(unsigned long arg)
1056 struct net_device *dev = (struct net_device *)arg;
1057 struct dn_dev *dn_db = dev->dn_ptr;
1058 struct dn_ifaddr *ifa;
1060 if (dn_db->t3 <= dn_db->parms.t2) {
1061 if (dn_db->parms.timer3) {
1062 for(ifa = dn_db->ifa_list; ifa; ifa = ifa->ifa_next) {
1063 if (!(ifa->ifa_flags & IFA_F_SECONDARY))
1064 dn_db->parms.timer3(dev, ifa);
1067 dn_db->t3 = dn_db->parms.t3;
1068 } else {
1069 dn_db->t3 -= dn_db->parms.t2;
1072 dn_dev_set_timer(dev);
1075 static void dn_dev_set_timer(struct net_device *dev)
1077 struct dn_dev *dn_db = dev->dn_ptr;
1079 if (dn_db->parms.t2 > dn_db->parms.t3)
1080 dn_db->parms.t2 = dn_db->parms.t3;
1082 dn_db->timer.data = (unsigned long)dev;
1083 dn_db->timer.function = dn_dev_timer_func;
1084 dn_db->timer.expires = jiffies + (dn_db->parms.t2 * HZ);
1086 add_timer(&dn_db->timer);
1089 struct dn_dev *dn_dev_create(struct net_device *dev, int *err)
1091 int i;
1092 struct dn_dev_parms *p = dn_dev_list;
1093 struct dn_dev *dn_db;
1095 for(i = 0; i < DN_DEV_LIST_SIZE; i++, p++) {
1096 if (p->type == dev->type)
1097 break;
1100 *err = -ENODEV;
1101 if (i == DN_DEV_LIST_SIZE)
1102 return NULL;
1104 *err = -ENOBUFS;
1105 if ((dn_db = kzalloc(sizeof(struct dn_dev), GFP_ATOMIC)) == NULL)
1106 return NULL;
1108 memcpy(&dn_db->parms, p, sizeof(struct dn_dev_parms));
1109 smp_wmb();
1110 dev->dn_ptr = dn_db;
1111 dn_db->dev = dev;
1112 init_timer(&dn_db->timer);
1114 dn_db->uptime = jiffies;
1115 if (dn_db->parms.up) {
1116 if (dn_db->parms.up(dev) < 0) {
1117 dev->dn_ptr = NULL;
1118 kfree(dn_db);
1119 return NULL;
1123 dn_db->neigh_parms = neigh_parms_alloc(dev, &dn_neigh_table);
1125 dn_dev_sysctl_register(dev, &dn_db->parms);
1127 dn_dev_set_timer(dev);
1129 *err = 0;
1130 return dn_db;
1135 * This processes a device up event. We only start up
1136 * the loopback device & ethernet devices with correct
1137 * MAC addreses automatically. Others must be started
1138 * specifically.
1140 * FIXME: How should we configure the loopback address ? If we could dispense
1141 * with using decnet_address here and for autobind, it will be one less thing
1142 * for users to worry about setting up.
1145 void dn_dev_up(struct net_device *dev)
1147 struct dn_ifaddr *ifa;
1148 __le16 addr = decnet_address;
1149 int maybe_default = 0;
1150 struct dn_dev *dn_db = (struct dn_dev *)dev->dn_ptr;
1152 if ((dev->type != ARPHRD_ETHER) && (dev->type != ARPHRD_LOOPBACK))
1153 return;
1156 * Need to ensure that loopback device has a dn_db attached to it
1157 * to allow creation of neighbours against it, even though it might
1158 * not have a local address of its own. Might as well do the same for
1159 * all autoconfigured interfaces.
1161 if (dn_db == NULL) {
1162 int err;
1163 dn_db = dn_dev_create(dev, &err);
1164 if (dn_db == NULL)
1165 return;
1168 if (dev->type == ARPHRD_ETHER) {
1169 if (memcmp(dev->dev_addr, dn_hiord, 4) != 0)
1170 return;
1171 addr = dn_eth2dn(dev->dev_addr);
1172 maybe_default = 1;
1175 if (addr == 0)
1176 return;
1178 if ((ifa = dn_dev_alloc_ifa()) == NULL)
1179 return;
1181 ifa->ifa_local = ifa->ifa_address = addr;
1182 ifa->ifa_flags = 0;
1183 ifa->ifa_scope = RT_SCOPE_UNIVERSE;
1184 strcpy(ifa->ifa_label, dev->name);
1186 dn_dev_set_ifa(dev, ifa);
1189 * Automagically set the default device to the first automatically
1190 * configured ethernet card in the system.
1192 if (maybe_default) {
1193 dev_hold(dev);
1194 if (dn_dev_set_default(dev, 0))
1195 dev_put(dev);
1199 static void dn_dev_delete(struct net_device *dev)
1201 struct dn_dev *dn_db = dev->dn_ptr;
1203 if (dn_db == NULL)
1204 return;
1206 del_timer_sync(&dn_db->timer);
1207 dn_dev_sysctl_unregister(&dn_db->parms);
1208 dn_dev_check_default(dev);
1209 neigh_ifdown(&dn_neigh_table, dev);
1211 if (dn_db->parms.down)
1212 dn_db->parms.down(dev);
1214 dev->dn_ptr = NULL;
1216 neigh_parms_release(&dn_neigh_table, dn_db->neigh_parms);
1217 neigh_ifdown(&dn_neigh_table, dev);
1219 if (dn_db->router)
1220 neigh_release(dn_db->router);
1221 if (dn_db->peer)
1222 neigh_release(dn_db->peer);
1224 kfree(dn_db);
1227 void dn_dev_down(struct net_device *dev)
1229 struct dn_dev *dn_db = dev->dn_ptr;
1230 struct dn_ifaddr *ifa;
1232 if (dn_db == NULL)
1233 return;
1235 while((ifa = dn_db->ifa_list) != NULL) {
1236 dn_dev_del_ifa(dn_db, &dn_db->ifa_list, 0);
1237 dn_dev_free_ifa(ifa);
1240 dn_dev_delete(dev);
1243 void dn_dev_init_pkt(struct sk_buff *skb)
1245 return;
1248 void dn_dev_veri_pkt(struct sk_buff *skb)
1250 return;
1253 void dn_dev_hello(struct sk_buff *skb)
1255 return;
1258 void dn_dev_devices_off(void)
1260 struct net_device *dev;
1262 rtnl_lock();
1263 for(dev = dev_base; dev; dev = dev->next)
1264 dn_dev_down(dev);
1265 rtnl_unlock();
1269 void dn_dev_devices_on(void)
1271 struct net_device *dev;
1273 rtnl_lock();
1274 for(dev = dev_base; dev; dev = dev->next) {
1275 if (dev->flags & IFF_UP)
1276 dn_dev_up(dev);
1278 rtnl_unlock();
1281 int register_dnaddr_notifier(struct notifier_block *nb)
1283 return blocking_notifier_chain_register(&dnaddr_chain, nb);
1286 int unregister_dnaddr_notifier(struct notifier_block *nb)
1288 return blocking_notifier_chain_unregister(&dnaddr_chain, nb);
1291 #ifdef CONFIG_PROC_FS
1292 static inline struct net_device *dn_dev_get_next(struct seq_file *seq, struct net_device *dev)
1294 do {
1295 dev = dev->next;
1296 } while(dev && !dev->dn_ptr);
1298 return dev;
1301 static struct net_device *dn_dev_get_idx(struct seq_file *seq, loff_t pos)
1303 struct net_device *dev;
1305 dev = dev_base;
1306 if (dev && !dev->dn_ptr)
1307 dev = dn_dev_get_next(seq, dev);
1308 if (pos) {
1309 while(dev && (dev = dn_dev_get_next(seq, dev)))
1310 --pos;
1312 return dev;
1315 static void *dn_dev_seq_start(struct seq_file *seq, loff_t *pos)
1317 if (*pos) {
1318 struct net_device *dev;
1319 read_lock(&dev_base_lock);
1320 dev = dn_dev_get_idx(seq, *pos - 1);
1321 if (dev == NULL)
1322 read_unlock(&dev_base_lock);
1323 return dev;
1325 return SEQ_START_TOKEN;
1328 static void *dn_dev_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1330 struct net_device *dev = v;
1331 loff_t one = 1;
1333 if (v == SEQ_START_TOKEN) {
1334 dev = dn_dev_seq_start(seq, &one);
1335 } else {
1336 dev = dn_dev_get_next(seq, dev);
1337 if (dev == NULL)
1338 read_unlock(&dev_base_lock);
1340 ++*pos;
1341 return dev;
1344 static void dn_dev_seq_stop(struct seq_file *seq, void *v)
1346 if (v && v != SEQ_START_TOKEN)
1347 read_unlock(&dev_base_lock);
1350 static char *dn_type2asc(char type)
1352 switch(type) {
1353 case DN_DEV_BCAST:
1354 return "B";
1355 case DN_DEV_UCAST:
1356 return "U";
1357 case DN_DEV_MPOINT:
1358 return "M";
1361 return "?";
1364 static int dn_dev_seq_show(struct seq_file *seq, void *v)
1366 if (v == SEQ_START_TOKEN)
1367 seq_puts(seq, "Name Flags T1 Timer1 T3 Timer3 BlkSize Pri State DevType Router Peer\n");
1368 else {
1369 struct net_device *dev = v;
1370 char peer_buf[DN_ASCBUF_LEN];
1371 char router_buf[DN_ASCBUF_LEN];
1372 struct dn_dev *dn_db = dev->dn_ptr;
1374 seq_printf(seq, "%-8s %1s %04u %04u %04lu %04lu"
1375 " %04hu %03d %02x %-10s %-7s %-7s\n",
1376 dev->name ? dev->name : "???",
1377 dn_type2asc(dn_db->parms.mode),
1378 0, 0,
1379 dn_db->t3, dn_db->parms.t3,
1380 mtu2blksize(dev),
1381 dn_db->parms.priority,
1382 dn_db->parms.state, dn_db->parms.name,
1383 dn_db->router ? dn_addr2asc(dn_ntohs(*(__le16 *)dn_db->router->primary_key), router_buf) : "",
1384 dn_db->peer ? dn_addr2asc(dn_ntohs(*(__le16 *)dn_db->peer->primary_key), peer_buf) : "");
1386 return 0;
1389 static struct seq_operations dn_dev_seq_ops = {
1390 .start = dn_dev_seq_start,
1391 .next = dn_dev_seq_next,
1392 .stop = dn_dev_seq_stop,
1393 .show = dn_dev_seq_show,
1396 static int dn_dev_seq_open(struct inode *inode, struct file *file)
1398 return seq_open(file, &dn_dev_seq_ops);
1401 static struct file_operations dn_dev_seq_fops = {
1402 .owner = THIS_MODULE,
1403 .open = dn_dev_seq_open,
1404 .read = seq_read,
1405 .llseek = seq_lseek,
1406 .release = seq_release,
1409 #endif /* CONFIG_PROC_FS */
1411 static struct rtnetlink_link dnet_rtnetlink_table[RTM_NR_MSGTYPES] =
1413 [RTM_NEWADDR - RTM_BASE] = { .doit = dn_dev_rtm_newaddr, },
1414 [RTM_DELADDR - RTM_BASE] = { .doit = dn_dev_rtm_deladdr, },
1415 [RTM_GETADDR - RTM_BASE] = { .dumpit = dn_dev_dump_ifaddr, },
1416 #ifdef CONFIG_DECNET_ROUTER
1417 [RTM_NEWROUTE - RTM_BASE] = { .doit = dn_fib_rtm_newroute, },
1418 [RTM_DELROUTE - RTM_BASE] = { .doit = dn_fib_rtm_delroute, },
1419 [RTM_GETROUTE - RTM_BASE] = { .doit = dn_cache_getroute,
1420 .dumpit = dn_fib_dump, },
1421 [RTM_NEWRULE - RTM_BASE] = { .doit = dn_fib_rtm_newrule, },
1422 [RTM_DELRULE - RTM_BASE] = { .doit = dn_fib_rtm_delrule, },
1423 [RTM_GETRULE - RTM_BASE] = { .dumpit = dn_fib_dump_rules, },
1424 #else
1425 [RTM_GETROUTE - RTM_BASE] = { .doit = dn_cache_getroute,
1426 .dumpit = dn_cache_dump, },
1427 #endif
1431 static int __initdata addr[2];
1432 module_param_array(addr, int, NULL, 0444);
1433 MODULE_PARM_DESC(addr, "The DECnet address of this machine: area,node");
1435 void __init dn_dev_init(void)
1437 if (addr[0] > 63 || addr[0] < 0) {
1438 printk(KERN_ERR "DECnet: Area must be between 0 and 63");
1439 return;
1442 if (addr[1] > 1023 || addr[1] < 0) {
1443 printk(KERN_ERR "DECnet: Node must be between 0 and 1023");
1444 return;
1447 decnet_address = dn_htons((addr[0] << 10) | addr[1]);
1449 dn_dev_devices_on();
1451 rtnetlink_links[PF_DECnet] = dnet_rtnetlink_table;
1453 proc_net_fops_create("decnet_dev", S_IRUGO, &dn_dev_seq_fops);
1455 #ifdef CONFIG_SYSCTL
1457 int i;
1458 for(i = 0; i < DN_DEV_LIST_SIZE; i++)
1459 dn_dev_sysctl_register(NULL, &dn_dev_list[i]);
1461 #endif /* CONFIG_SYSCTL */
1464 void __exit dn_dev_cleanup(void)
1466 rtnetlink_links[PF_DECnet] = NULL;
1468 #ifdef CONFIG_SYSCTL
1470 int i;
1471 for(i = 0; i < DN_DEV_LIST_SIZE; i++)
1472 dn_dev_sysctl_unregister(&dn_dev_list[i]);
1474 #endif /* CONFIG_SYSCTL */
1476 proc_net_remove("decnet_dev");
1478 dn_dev_devices_off();