[PATCH] w1: Userspace communication protocol over connector.
[linux-2.6/verdex.git] / net / decnet / dn_dev.c
bloba26ff9f44576fffb0c20dd7725a463c291db989e
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/config.h>
28 #include <linux/capability.h>
29 #include <linux/module.h>
30 #include <linux/moduleparam.h>
31 #include <linux/init.h>
32 #include <linux/net.h>
33 #include <linux/netdevice.h>
34 #include <linux/proc_fs.h>
35 #include <linux/seq_file.h>
36 #include <linux/timer.h>
37 #include <linux/string.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 = kmalloc(sizeof(*ifa), GFP_KERNEL);
419 if (ifa) {
420 memset(ifa, 0, sizeof(*ifa));
423 return ifa;
426 static __inline__ void dn_dev_free_ifa(struct dn_ifaddr *ifa)
428 kfree(ifa);
431 static void dn_dev_del_ifa(struct dn_dev *dn_db, struct dn_ifaddr **ifap, int destroy)
433 struct dn_ifaddr *ifa1 = *ifap;
434 unsigned char mac_addr[6];
435 struct net_device *dev = dn_db->dev;
437 ASSERT_RTNL();
439 *ifap = ifa1->ifa_next;
441 if (dn_db->dev->type == ARPHRD_ETHER) {
442 if (ifa1->ifa_local != dn_eth2dn(dev->dev_addr)) {
443 dn_dn2eth(mac_addr, ifa1->ifa_local);
444 dev_mc_delete(dev, mac_addr, ETH_ALEN, 0);
448 rtmsg_ifa(RTM_DELADDR, ifa1);
449 blocking_notifier_call_chain(&dnaddr_chain, NETDEV_DOWN, ifa1);
450 if (destroy) {
451 dn_dev_free_ifa(ifa1);
453 if (dn_db->ifa_list == NULL)
454 dn_dev_delete(dn_db->dev);
458 static int dn_dev_insert_ifa(struct dn_dev *dn_db, struct dn_ifaddr *ifa)
460 struct net_device *dev = dn_db->dev;
461 struct dn_ifaddr *ifa1;
462 unsigned char mac_addr[6];
464 ASSERT_RTNL();
466 /* Check for duplicates */
467 for(ifa1 = dn_db->ifa_list; ifa1; ifa1 = ifa1->ifa_next) {
468 if (ifa1->ifa_local == ifa->ifa_local)
469 return -EEXIST;
472 if (dev->type == ARPHRD_ETHER) {
473 if (ifa->ifa_local != dn_eth2dn(dev->dev_addr)) {
474 dn_dn2eth(mac_addr, ifa->ifa_local);
475 dev_mc_add(dev, mac_addr, ETH_ALEN, 0);
476 dev_mc_upload(dev);
480 ifa->ifa_next = dn_db->ifa_list;
481 dn_db->ifa_list = ifa;
483 rtmsg_ifa(RTM_NEWADDR, ifa);
484 blocking_notifier_call_chain(&dnaddr_chain, NETDEV_UP, ifa);
486 return 0;
489 static int dn_dev_set_ifa(struct net_device *dev, struct dn_ifaddr *ifa)
491 struct dn_dev *dn_db = dev->dn_ptr;
492 int rv;
494 if (dn_db == NULL) {
495 int err;
496 dn_db = dn_dev_create(dev, &err);
497 if (dn_db == NULL)
498 return err;
501 ifa->ifa_dev = dn_db;
503 if (dev->flags & IFF_LOOPBACK)
504 ifa->ifa_scope = RT_SCOPE_HOST;
506 rv = dn_dev_insert_ifa(dn_db, ifa);
507 if (rv)
508 dn_dev_free_ifa(ifa);
509 return rv;
513 int dn_dev_ioctl(unsigned int cmd, void __user *arg)
515 char buffer[DN_IFREQ_SIZE];
516 struct ifreq *ifr = (struct ifreq *)buffer;
517 struct sockaddr_dn *sdn = (struct sockaddr_dn *)&ifr->ifr_addr;
518 struct dn_dev *dn_db;
519 struct net_device *dev;
520 struct dn_ifaddr *ifa = NULL, **ifap = NULL;
521 int ret = 0;
523 if (copy_from_user(ifr, arg, DN_IFREQ_SIZE))
524 return -EFAULT;
525 ifr->ifr_name[IFNAMSIZ-1] = 0;
527 #ifdef CONFIG_KMOD
528 dev_load(ifr->ifr_name);
529 #endif
531 switch(cmd) {
532 case SIOCGIFADDR:
533 break;
534 case SIOCSIFADDR:
535 if (!capable(CAP_NET_ADMIN))
536 return -EACCES;
537 if (sdn->sdn_family != AF_DECnet)
538 return -EINVAL;
539 break;
540 default:
541 return -EINVAL;
544 rtnl_lock();
546 if ((dev = __dev_get_by_name(ifr->ifr_name)) == NULL) {
547 ret = -ENODEV;
548 goto done;
551 if ((dn_db = dev->dn_ptr) != NULL) {
552 for (ifap = &dn_db->ifa_list; (ifa=*ifap) != NULL; ifap = &ifa->ifa_next)
553 if (strcmp(ifr->ifr_name, ifa->ifa_label) == 0)
554 break;
557 if (ifa == NULL && cmd != SIOCSIFADDR) {
558 ret = -EADDRNOTAVAIL;
559 goto done;
562 switch(cmd) {
563 case SIOCGIFADDR:
564 *((__le16 *)sdn->sdn_nodeaddr) = ifa->ifa_local;
565 goto rarok;
567 case SIOCSIFADDR:
568 if (!ifa) {
569 if ((ifa = dn_dev_alloc_ifa()) == NULL) {
570 ret = -ENOBUFS;
571 break;
573 memcpy(ifa->ifa_label, dev->name, IFNAMSIZ);
574 } else {
575 if (ifa->ifa_local == dn_saddr2dn(sdn))
576 break;
577 dn_dev_del_ifa(dn_db, ifap, 0);
580 ifa->ifa_local = ifa->ifa_address = dn_saddr2dn(sdn);
582 ret = dn_dev_set_ifa(dev, ifa);
584 done:
585 rtnl_unlock();
587 return ret;
588 rarok:
589 if (copy_to_user(arg, ifr, DN_IFREQ_SIZE))
590 ret = -EFAULT;
591 goto done;
594 struct net_device *dn_dev_get_default(void)
596 struct net_device *dev;
597 read_lock(&dndev_lock);
598 dev = decnet_default_device;
599 if (dev) {
600 if (dev->dn_ptr)
601 dev_hold(dev);
602 else
603 dev = NULL;
605 read_unlock(&dndev_lock);
606 return dev;
609 int dn_dev_set_default(struct net_device *dev, int force)
611 struct net_device *old = NULL;
612 int rv = -EBUSY;
613 if (!dev->dn_ptr)
614 return -ENODEV;
615 write_lock(&dndev_lock);
616 if (force || decnet_default_device == NULL) {
617 old = decnet_default_device;
618 decnet_default_device = dev;
619 rv = 0;
621 write_unlock(&dndev_lock);
622 if (old)
623 dev_put(old);
624 return rv;
627 static void dn_dev_check_default(struct net_device *dev)
629 write_lock(&dndev_lock);
630 if (dev == decnet_default_device) {
631 decnet_default_device = NULL;
632 } else {
633 dev = NULL;
635 write_unlock(&dndev_lock);
636 if (dev)
637 dev_put(dev);
640 static struct dn_dev *dn_dev_by_index(int ifindex)
642 struct net_device *dev;
643 struct dn_dev *dn_dev = NULL;
644 dev = dev_get_by_index(ifindex);
645 if (dev) {
646 dn_dev = dev->dn_ptr;
647 dev_put(dev);
650 return dn_dev;
653 static int dn_dev_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
655 struct rtattr **rta = arg;
656 struct dn_dev *dn_db;
657 struct ifaddrmsg *ifm = NLMSG_DATA(nlh);
658 struct dn_ifaddr *ifa, **ifap;
660 if ((dn_db = dn_dev_by_index(ifm->ifa_index)) == NULL)
661 return -EADDRNOTAVAIL;
663 for(ifap = &dn_db->ifa_list; (ifa=*ifap) != NULL; ifap = &ifa->ifa_next) {
664 void *tmp = rta[IFA_LOCAL-1];
665 if ((tmp && memcmp(RTA_DATA(tmp), &ifa->ifa_local, 2)) ||
666 (rta[IFA_LABEL-1] && rtattr_strcmp(rta[IFA_LABEL-1], ifa->ifa_label)))
667 continue;
669 dn_dev_del_ifa(dn_db, ifap, 1);
670 return 0;
673 return -EADDRNOTAVAIL;
676 static int dn_dev_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
678 struct rtattr **rta = arg;
679 struct net_device *dev;
680 struct dn_dev *dn_db;
681 struct ifaddrmsg *ifm = NLMSG_DATA(nlh);
682 struct dn_ifaddr *ifa;
683 int rv;
685 if (rta[IFA_LOCAL-1] == NULL)
686 return -EINVAL;
688 if ((dev = __dev_get_by_index(ifm->ifa_index)) == NULL)
689 return -ENODEV;
691 if ((dn_db = dev->dn_ptr) == NULL) {
692 int err;
693 dn_db = dn_dev_create(dev, &err);
694 if (!dn_db)
695 return err;
698 if ((ifa = dn_dev_alloc_ifa()) == NULL)
699 return -ENOBUFS;
701 if (!rta[IFA_ADDRESS - 1])
702 rta[IFA_ADDRESS - 1] = rta[IFA_LOCAL - 1];
703 memcpy(&ifa->ifa_local, RTA_DATA(rta[IFA_LOCAL-1]), 2);
704 memcpy(&ifa->ifa_address, RTA_DATA(rta[IFA_ADDRESS-1]), 2);
705 ifa->ifa_flags = ifm->ifa_flags;
706 ifa->ifa_scope = ifm->ifa_scope;
707 ifa->ifa_dev = dn_db;
708 if (rta[IFA_LABEL-1])
709 rtattr_strlcpy(ifa->ifa_label, rta[IFA_LABEL-1], IFNAMSIZ);
710 else
711 memcpy(ifa->ifa_label, dev->name, IFNAMSIZ);
713 rv = dn_dev_insert_ifa(dn_db, ifa);
714 if (rv)
715 dn_dev_free_ifa(ifa);
716 return rv;
719 static int dn_dev_fill_ifaddr(struct sk_buff *skb, struct dn_ifaddr *ifa,
720 u32 pid, u32 seq, int event, unsigned int flags)
722 struct ifaddrmsg *ifm;
723 struct nlmsghdr *nlh;
724 unsigned char *b = skb->tail;
726 nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*ifm), flags);
727 ifm = NLMSG_DATA(nlh);
729 ifm->ifa_family = AF_DECnet;
730 ifm->ifa_prefixlen = 16;
731 ifm->ifa_flags = ifa->ifa_flags | IFA_F_PERMANENT;
732 ifm->ifa_scope = ifa->ifa_scope;
733 ifm->ifa_index = ifa->ifa_dev->dev->ifindex;
734 if (ifa->ifa_address)
735 RTA_PUT(skb, IFA_ADDRESS, 2, &ifa->ifa_address);
736 if (ifa->ifa_local)
737 RTA_PUT(skb, IFA_LOCAL, 2, &ifa->ifa_local);
738 if (ifa->ifa_label[0])
739 RTA_PUT(skb, IFA_LABEL, IFNAMSIZ, &ifa->ifa_label);
740 nlh->nlmsg_len = skb->tail - b;
741 return skb->len;
743 nlmsg_failure:
744 rtattr_failure:
745 skb_trim(skb, b - skb->data);
746 return -1;
749 static void rtmsg_ifa(int event, struct dn_ifaddr *ifa)
751 struct sk_buff *skb;
752 int size = NLMSG_SPACE(sizeof(struct ifaddrmsg)+128);
754 skb = alloc_skb(size, GFP_KERNEL);
755 if (!skb) {
756 netlink_set_err(rtnl, 0, RTNLGRP_DECnet_IFADDR, ENOBUFS);
757 return;
759 if (dn_dev_fill_ifaddr(skb, ifa, 0, 0, event, 0) < 0) {
760 kfree_skb(skb);
761 netlink_set_err(rtnl, 0, RTNLGRP_DECnet_IFADDR, EINVAL);
762 return;
764 NETLINK_CB(skb).dst_group = RTNLGRP_DECnet_IFADDR;
765 netlink_broadcast(rtnl, skb, 0, RTNLGRP_DECnet_IFADDR, GFP_KERNEL);
768 static int dn_dev_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
770 int idx, dn_idx;
771 int s_idx, s_dn_idx;
772 struct net_device *dev;
773 struct dn_dev *dn_db;
774 struct dn_ifaddr *ifa;
776 s_idx = cb->args[0];
777 s_dn_idx = dn_idx = cb->args[1];
778 read_lock(&dev_base_lock);
779 for(dev = dev_base, idx = 0; dev; dev = dev->next, idx++) {
780 if (idx < s_idx)
781 continue;
782 if (idx > s_idx)
783 s_dn_idx = 0;
784 if ((dn_db = dev->dn_ptr) == NULL)
785 continue;
787 for(ifa = dn_db->ifa_list, dn_idx = 0; ifa; ifa = ifa->ifa_next, dn_idx++) {
788 if (dn_idx < s_dn_idx)
789 continue;
791 if (dn_dev_fill_ifaddr(skb, ifa,
792 NETLINK_CB(cb->skb).pid,
793 cb->nlh->nlmsg_seq,
794 RTM_NEWADDR,
795 NLM_F_MULTI) <= 0)
796 goto done;
799 done:
800 read_unlock(&dev_base_lock);
801 cb->args[0] = idx;
802 cb->args[1] = dn_idx;
804 return skb->len;
807 static int dn_dev_get_first(struct net_device *dev, __le16 *addr)
809 struct dn_dev *dn_db = (struct dn_dev *)dev->dn_ptr;
810 struct dn_ifaddr *ifa;
811 int rv = -ENODEV;
812 if (dn_db == NULL)
813 goto out;
814 ifa = dn_db->ifa_list;
815 if (ifa != NULL) {
816 *addr = ifa->ifa_local;
817 rv = 0;
819 out:
820 return rv;
824 * Find a default address to bind to.
826 * This is one of those areas where the initial VMS concepts don't really
827 * map onto the Linux concepts, and since we introduced multiple addresses
828 * per interface we have to cope with slightly odd ways of finding out what
829 * "our address" really is. Mostly it's not a problem; for this we just guess
830 * a sensible default. Eventually the routing code will take care of all the
831 * nasties for us I hope.
833 int dn_dev_bind_default(__le16 *addr)
835 struct net_device *dev;
836 int rv;
837 dev = dn_dev_get_default();
838 last_chance:
839 if (dev) {
840 read_lock(&dev_base_lock);
841 rv = dn_dev_get_first(dev, addr);
842 read_unlock(&dev_base_lock);
843 dev_put(dev);
844 if (rv == 0 || dev == &loopback_dev)
845 return rv;
847 dev = &loopback_dev;
848 dev_hold(dev);
849 goto last_chance;
852 static void dn_send_endnode_hello(struct net_device *dev, struct dn_ifaddr *ifa)
854 struct endnode_hello_message *msg;
855 struct sk_buff *skb = NULL;
856 __le16 *pktlen;
857 struct dn_dev *dn_db = (struct dn_dev *)dev->dn_ptr;
859 if ((skb = dn_alloc_skb(NULL, sizeof(*msg), GFP_ATOMIC)) == NULL)
860 return;
862 skb->dev = dev;
864 msg = (struct endnode_hello_message *)skb_put(skb,sizeof(*msg));
866 msg->msgflg = 0x0D;
867 memcpy(msg->tiver, dn_eco_version, 3);
868 dn_dn2eth(msg->id, ifa->ifa_local);
869 msg->iinfo = DN_RT_INFO_ENDN;
870 msg->blksize = dn_htons(mtu2blksize(dev));
871 msg->area = 0x00;
872 memset(msg->seed, 0, 8);
873 memcpy(msg->neighbor, dn_hiord, ETH_ALEN);
875 if (dn_db->router) {
876 struct dn_neigh *dn = (struct dn_neigh *)dn_db->router;
877 dn_dn2eth(msg->neighbor, dn->addr);
880 msg->timer = dn_htons((unsigned short)dn_db->parms.t3);
881 msg->mpd = 0x00;
882 msg->datalen = 0x02;
883 memset(msg->data, 0xAA, 2);
885 pktlen = (__le16 *)skb_push(skb,2);
886 *pktlen = dn_htons(skb->len - 2);
888 skb->nh.raw = skb->data;
890 dn_rt_finish_output(skb, dn_rt_all_rt_mcast, msg->id);
894 #define DRDELAY (5 * HZ)
896 static int dn_am_i_a_router(struct dn_neigh *dn, struct dn_dev *dn_db, struct dn_ifaddr *ifa)
898 /* First check time since device went up */
899 if ((jiffies - dn_db->uptime) < DRDELAY)
900 return 0;
902 /* If there is no router, then yes... */
903 if (!dn_db->router)
904 return 1;
906 /* otherwise only if we have a higher priority or.. */
907 if (dn->priority < dn_db->parms.priority)
908 return 1;
910 /* if we have equal priority and a higher node number */
911 if (dn->priority != dn_db->parms.priority)
912 return 0;
914 if (dn_ntohs(dn->addr) < dn_ntohs(ifa->ifa_local))
915 return 1;
917 return 0;
920 static void dn_send_router_hello(struct net_device *dev, struct dn_ifaddr *ifa)
922 int n;
923 struct dn_dev *dn_db = dev->dn_ptr;
924 struct dn_neigh *dn = (struct dn_neigh *)dn_db->router;
925 struct sk_buff *skb;
926 size_t size;
927 unsigned char *ptr;
928 unsigned char *i1, *i2;
929 __le16 *pktlen;
930 char *src;
932 if (mtu2blksize(dev) < (26 + 7))
933 return;
935 n = mtu2blksize(dev) - 26;
936 n /= 7;
938 if (n > 32)
939 n = 32;
941 size = 2 + 26 + 7 * n;
943 if ((skb = dn_alloc_skb(NULL, size, GFP_ATOMIC)) == NULL)
944 return;
946 skb->dev = dev;
947 ptr = skb_put(skb, size);
949 *ptr++ = DN_RT_PKT_CNTL | DN_RT_PKT_ERTH;
950 *ptr++ = 2; /* ECO */
951 *ptr++ = 0;
952 *ptr++ = 0;
953 dn_dn2eth(ptr, ifa->ifa_local);
954 src = ptr;
955 ptr += ETH_ALEN;
956 *ptr++ = dn_db->parms.forwarding == 1 ?
957 DN_RT_INFO_L1RT : DN_RT_INFO_L2RT;
958 *((__le16 *)ptr) = dn_htons(mtu2blksize(dev));
959 ptr += 2;
960 *ptr++ = dn_db->parms.priority; /* Priority */
961 *ptr++ = 0; /* Area: Reserved */
962 *((__le16 *)ptr) = dn_htons((unsigned short)dn_db->parms.t3);
963 ptr += 2;
964 *ptr++ = 0; /* MPD: Reserved */
965 i1 = ptr++;
966 memset(ptr, 0, 7); /* Name: Reserved */
967 ptr += 7;
968 i2 = ptr++;
970 n = dn_neigh_elist(dev, ptr, n);
972 *i2 = 7 * n;
973 *i1 = 8 + *i2;
975 skb_trim(skb, (27 + *i2));
977 pktlen = (__le16 *)skb_push(skb, 2);
978 *pktlen = dn_htons(skb->len - 2);
980 skb->nh.raw = skb->data;
982 if (dn_am_i_a_router(dn, dn_db, ifa)) {
983 struct sk_buff *skb2 = skb_copy(skb, GFP_ATOMIC);
984 if (skb2) {
985 dn_rt_finish_output(skb2, dn_rt_all_end_mcast, src);
989 dn_rt_finish_output(skb, dn_rt_all_rt_mcast, src);
992 static void dn_send_brd_hello(struct net_device *dev, struct dn_ifaddr *ifa)
994 struct dn_dev *dn_db = (struct dn_dev *)dev->dn_ptr;
996 if (dn_db->parms.forwarding == 0)
997 dn_send_endnode_hello(dev, ifa);
998 else
999 dn_send_router_hello(dev, ifa);
1002 static void dn_send_ptp_hello(struct net_device *dev, struct dn_ifaddr *ifa)
1004 int tdlen = 16;
1005 int size = dev->hard_header_len + 2 + 4 + tdlen;
1006 struct sk_buff *skb = dn_alloc_skb(NULL, size, GFP_ATOMIC);
1007 int i;
1008 unsigned char *ptr;
1009 char src[ETH_ALEN];
1011 if (skb == NULL)
1012 return ;
1014 skb->dev = dev;
1015 skb_push(skb, dev->hard_header_len);
1016 ptr = skb_put(skb, 2 + 4 + tdlen);
1018 *ptr++ = DN_RT_PKT_HELO;
1019 *((__le16 *)ptr) = ifa->ifa_local;
1020 ptr += 2;
1021 *ptr++ = tdlen;
1023 for(i = 0; i < tdlen; i++)
1024 *ptr++ = 0252;
1026 dn_dn2eth(src, ifa->ifa_local);
1027 dn_rt_finish_output(skb, dn_rt_all_rt_mcast, src);
1030 static int dn_eth_up(struct net_device *dev)
1032 struct dn_dev *dn_db = dev->dn_ptr;
1034 if (dn_db->parms.forwarding == 0)
1035 dev_mc_add(dev, dn_rt_all_end_mcast, ETH_ALEN, 0);
1036 else
1037 dev_mc_add(dev, dn_rt_all_rt_mcast, ETH_ALEN, 0);
1039 dev_mc_upload(dev);
1041 dn_db->use_long = 1;
1043 return 0;
1046 static void dn_eth_down(struct net_device *dev)
1048 struct dn_dev *dn_db = dev->dn_ptr;
1050 if (dn_db->parms.forwarding == 0)
1051 dev_mc_delete(dev, dn_rt_all_end_mcast, ETH_ALEN, 0);
1052 else
1053 dev_mc_delete(dev, dn_rt_all_rt_mcast, ETH_ALEN, 0);
1056 static void dn_dev_set_timer(struct net_device *dev);
1058 static void dn_dev_timer_func(unsigned long arg)
1060 struct net_device *dev = (struct net_device *)arg;
1061 struct dn_dev *dn_db = dev->dn_ptr;
1062 struct dn_ifaddr *ifa;
1064 if (dn_db->t3 <= dn_db->parms.t2) {
1065 if (dn_db->parms.timer3) {
1066 for(ifa = dn_db->ifa_list; ifa; ifa = ifa->ifa_next) {
1067 if (!(ifa->ifa_flags & IFA_F_SECONDARY))
1068 dn_db->parms.timer3(dev, ifa);
1071 dn_db->t3 = dn_db->parms.t3;
1072 } else {
1073 dn_db->t3 -= dn_db->parms.t2;
1076 dn_dev_set_timer(dev);
1079 static void dn_dev_set_timer(struct net_device *dev)
1081 struct dn_dev *dn_db = dev->dn_ptr;
1083 if (dn_db->parms.t2 > dn_db->parms.t3)
1084 dn_db->parms.t2 = dn_db->parms.t3;
1086 dn_db->timer.data = (unsigned long)dev;
1087 dn_db->timer.function = dn_dev_timer_func;
1088 dn_db->timer.expires = jiffies + (dn_db->parms.t2 * HZ);
1090 add_timer(&dn_db->timer);
1093 struct dn_dev *dn_dev_create(struct net_device *dev, int *err)
1095 int i;
1096 struct dn_dev_parms *p = dn_dev_list;
1097 struct dn_dev *dn_db;
1099 for(i = 0; i < DN_DEV_LIST_SIZE; i++, p++) {
1100 if (p->type == dev->type)
1101 break;
1104 *err = -ENODEV;
1105 if (i == DN_DEV_LIST_SIZE)
1106 return NULL;
1108 *err = -ENOBUFS;
1109 if ((dn_db = kmalloc(sizeof(struct dn_dev), GFP_ATOMIC)) == NULL)
1110 return NULL;
1112 memset(dn_db, 0, sizeof(struct dn_dev));
1113 memcpy(&dn_db->parms, p, sizeof(struct dn_dev_parms));
1114 smp_wmb();
1115 dev->dn_ptr = dn_db;
1116 dn_db->dev = dev;
1117 init_timer(&dn_db->timer);
1119 dn_db->uptime = jiffies;
1120 if (dn_db->parms.up) {
1121 if (dn_db->parms.up(dev) < 0) {
1122 dev->dn_ptr = NULL;
1123 kfree(dn_db);
1124 return NULL;
1128 dn_db->neigh_parms = neigh_parms_alloc(dev, &dn_neigh_table);
1130 dn_dev_sysctl_register(dev, &dn_db->parms);
1132 dn_dev_set_timer(dev);
1134 *err = 0;
1135 return dn_db;
1140 * This processes a device up event. We only start up
1141 * the loopback device & ethernet devices with correct
1142 * MAC addreses automatically. Others must be started
1143 * specifically.
1145 * FIXME: How should we configure the loopback address ? If we could dispense
1146 * with using decnet_address here and for autobind, it will be one less thing
1147 * for users to worry about setting up.
1150 void dn_dev_up(struct net_device *dev)
1152 struct dn_ifaddr *ifa;
1153 __le16 addr = decnet_address;
1154 int maybe_default = 0;
1155 struct dn_dev *dn_db = (struct dn_dev *)dev->dn_ptr;
1157 if ((dev->type != ARPHRD_ETHER) && (dev->type != ARPHRD_LOOPBACK))
1158 return;
1161 * Need to ensure that loopback device has a dn_db attached to it
1162 * to allow creation of neighbours against it, even though it might
1163 * not have a local address of its own. Might as well do the same for
1164 * all autoconfigured interfaces.
1166 if (dn_db == NULL) {
1167 int err;
1168 dn_db = dn_dev_create(dev, &err);
1169 if (dn_db == NULL)
1170 return;
1173 if (dev->type == ARPHRD_ETHER) {
1174 if (memcmp(dev->dev_addr, dn_hiord, 4) != 0)
1175 return;
1176 addr = dn_eth2dn(dev->dev_addr);
1177 maybe_default = 1;
1180 if (addr == 0)
1181 return;
1183 if ((ifa = dn_dev_alloc_ifa()) == NULL)
1184 return;
1186 ifa->ifa_local = ifa->ifa_address = addr;
1187 ifa->ifa_flags = 0;
1188 ifa->ifa_scope = RT_SCOPE_UNIVERSE;
1189 strcpy(ifa->ifa_label, dev->name);
1191 dn_dev_set_ifa(dev, ifa);
1194 * Automagically set the default device to the first automatically
1195 * configured ethernet card in the system.
1197 if (maybe_default) {
1198 dev_hold(dev);
1199 if (dn_dev_set_default(dev, 0))
1200 dev_put(dev);
1204 static void dn_dev_delete(struct net_device *dev)
1206 struct dn_dev *dn_db = dev->dn_ptr;
1208 if (dn_db == NULL)
1209 return;
1211 del_timer_sync(&dn_db->timer);
1212 dn_dev_sysctl_unregister(&dn_db->parms);
1213 dn_dev_check_default(dev);
1214 neigh_ifdown(&dn_neigh_table, dev);
1216 if (dn_db->parms.down)
1217 dn_db->parms.down(dev);
1219 dev->dn_ptr = NULL;
1221 neigh_parms_release(&dn_neigh_table, dn_db->neigh_parms);
1222 neigh_ifdown(&dn_neigh_table, dev);
1224 if (dn_db->router)
1225 neigh_release(dn_db->router);
1226 if (dn_db->peer)
1227 neigh_release(dn_db->peer);
1229 kfree(dn_db);
1232 void dn_dev_down(struct net_device *dev)
1234 struct dn_dev *dn_db = dev->dn_ptr;
1235 struct dn_ifaddr *ifa;
1237 if (dn_db == NULL)
1238 return;
1240 while((ifa = dn_db->ifa_list) != NULL) {
1241 dn_dev_del_ifa(dn_db, &dn_db->ifa_list, 0);
1242 dn_dev_free_ifa(ifa);
1245 dn_dev_delete(dev);
1248 void dn_dev_init_pkt(struct sk_buff *skb)
1250 return;
1253 void dn_dev_veri_pkt(struct sk_buff *skb)
1255 return;
1258 void dn_dev_hello(struct sk_buff *skb)
1260 return;
1263 void dn_dev_devices_off(void)
1265 struct net_device *dev;
1267 rtnl_lock();
1268 for(dev = dev_base; dev; dev = dev->next)
1269 dn_dev_down(dev);
1270 rtnl_unlock();
1274 void dn_dev_devices_on(void)
1276 struct net_device *dev;
1278 rtnl_lock();
1279 for(dev = dev_base; dev; dev = dev->next) {
1280 if (dev->flags & IFF_UP)
1281 dn_dev_up(dev);
1283 rtnl_unlock();
1286 int register_dnaddr_notifier(struct notifier_block *nb)
1288 return blocking_notifier_chain_register(&dnaddr_chain, nb);
1291 int unregister_dnaddr_notifier(struct notifier_block *nb)
1293 return blocking_notifier_chain_unregister(&dnaddr_chain, nb);
1296 #ifdef CONFIG_PROC_FS
1297 static inline struct net_device *dn_dev_get_next(struct seq_file *seq, struct net_device *dev)
1299 do {
1300 dev = dev->next;
1301 } while(dev && !dev->dn_ptr);
1303 return dev;
1306 static struct net_device *dn_dev_get_idx(struct seq_file *seq, loff_t pos)
1308 struct net_device *dev;
1310 dev = dev_base;
1311 if (dev && !dev->dn_ptr)
1312 dev = dn_dev_get_next(seq, dev);
1313 if (pos) {
1314 while(dev && (dev = dn_dev_get_next(seq, dev)))
1315 --pos;
1317 return dev;
1320 static void *dn_dev_seq_start(struct seq_file *seq, loff_t *pos)
1322 if (*pos) {
1323 struct net_device *dev;
1324 read_lock(&dev_base_lock);
1325 dev = dn_dev_get_idx(seq, *pos - 1);
1326 if (dev == NULL)
1327 read_unlock(&dev_base_lock);
1328 return dev;
1330 return SEQ_START_TOKEN;
1333 static void *dn_dev_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1335 struct net_device *dev = v;
1336 loff_t one = 1;
1338 if (v == SEQ_START_TOKEN) {
1339 dev = dn_dev_seq_start(seq, &one);
1340 } else {
1341 dev = dn_dev_get_next(seq, dev);
1342 if (dev == NULL)
1343 read_unlock(&dev_base_lock);
1345 ++*pos;
1346 return dev;
1349 static void dn_dev_seq_stop(struct seq_file *seq, void *v)
1351 if (v && v != SEQ_START_TOKEN)
1352 read_unlock(&dev_base_lock);
1355 static char *dn_type2asc(char type)
1357 switch(type) {
1358 case DN_DEV_BCAST:
1359 return "B";
1360 case DN_DEV_UCAST:
1361 return "U";
1362 case DN_DEV_MPOINT:
1363 return "M";
1366 return "?";
1369 static int dn_dev_seq_show(struct seq_file *seq, void *v)
1371 if (v == SEQ_START_TOKEN)
1372 seq_puts(seq, "Name Flags T1 Timer1 T3 Timer3 BlkSize Pri State DevType Router Peer\n");
1373 else {
1374 struct net_device *dev = v;
1375 char peer_buf[DN_ASCBUF_LEN];
1376 char router_buf[DN_ASCBUF_LEN];
1377 struct dn_dev *dn_db = dev->dn_ptr;
1379 seq_printf(seq, "%-8s %1s %04u %04u %04lu %04lu"
1380 " %04hu %03d %02x %-10s %-7s %-7s\n",
1381 dev->name ? dev->name : "???",
1382 dn_type2asc(dn_db->parms.mode),
1383 0, 0,
1384 dn_db->t3, dn_db->parms.t3,
1385 mtu2blksize(dev),
1386 dn_db->parms.priority,
1387 dn_db->parms.state, dn_db->parms.name,
1388 dn_db->router ? dn_addr2asc(dn_ntohs(*(__le16 *)dn_db->router->primary_key), router_buf) : "",
1389 dn_db->peer ? dn_addr2asc(dn_ntohs(*(__le16 *)dn_db->peer->primary_key), peer_buf) : "");
1391 return 0;
1394 static struct seq_operations dn_dev_seq_ops = {
1395 .start = dn_dev_seq_start,
1396 .next = dn_dev_seq_next,
1397 .stop = dn_dev_seq_stop,
1398 .show = dn_dev_seq_show,
1401 static int dn_dev_seq_open(struct inode *inode, struct file *file)
1403 return seq_open(file, &dn_dev_seq_ops);
1406 static struct file_operations dn_dev_seq_fops = {
1407 .owner = THIS_MODULE,
1408 .open = dn_dev_seq_open,
1409 .read = seq_read,
1410 .llseek = seq_lseek,
1411 .release = seq_release,
1414 #endif /* CONFIG_PROC_FS */
1416 static struct rtnetlink_link dnet_rtnetlink_table[RTM_NR_MSGTYPES] =
1418 [RTM_NEWADDR - RTM_BASE] = { .doit = dn_dev_rtm_newaddr, },
1419 [RTM_DELADDR - RTM_BASE] = { .doit = dn_dev_rtm_deladdr, },
1420 [RTM_GETADDR - RTM_BASE] = { .dumpit = dn_dev_dump_ifaddr, },
1421 #ifdef CONFIG_DECNET_ROUTER
1422 [RTM_NEWROUTE - RTM_BASE] = { .doit = dn_fib_rtm_newroute, },
1423 [RTM_DELROUTE - RTM_BASE] = { .doit = dn_fib_rtm_delroute, },
1424 [RTM_GETROUTE - RTM_BASE] = { .doit = dn_cache_getroute,
1425 .dumpit = dn_fib_dump, },
1426 [RTM_NEWRULE - RTM_BASE] = { .doit = dn_fib_rtm_newrule, },
1427 [RTM_DELRULE - RTM_BASE] = { .doit = dn_fib_rtm_delrule, },
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();