decnet: add RTNL lock when reading address list
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / net / decnet / dn_dev.c
blob5790d660bc7d8de4997f21beba90344beacfef43
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/net_namespace.h>
46 #include <net/neighbour.h>
47 #include <net/dst.h>
48 #include <net/flow.h>
49 #include <net/fib_rules.h>
50 #include <net/netlink.h>
51 #include <net/dn.h>
52 #include <net/dn_dev.h>
53 #include <net/dn_route.h>
54 #include <net/dn_neigh.h>
55 #include <net/dn_fib.h>
57 #define DN_IFREQ_SIZE (sizeof(struct ifreq) - sizeof(struct sockaddr) + sizeof(struct sockaddr_dn))
59 static char dn_rt_all_end_mcast[ETH_ALEN] = {0xAB,0x00,0x00,0x04,0x00,0x00};
60 static char dn_rt_all_rt_mcast[ETH_ALEN] = {0xAB,0x00,0x00,0x03,0x00,0x00};
61 static char dn_hiord[ETH_ALEN] = {0xAA,0x00,0x04,0x00,0x00,0x00};
62 static unsigned char dn_eco_version[3] = {0x02,0x00,0x00};
64 extern struct neigh_table dn_neigh_table;
67 * decnet_address is kept in network order.
69 __le16 decnet_address = 0;
71 static DEFINE_RWLOCK(dndev_lock);
72 static struct net_device *decnet_default_device;
73 static BLOCKING_NOTIFIER_HEAD(dnaddr_chain);
75 static struct dn_dev *dn_dev_create(struct net_device *dev, int *err);
76 static void dn_dev_delete(struct net_device *dev);
77 static void dn_ifaddr_notify(int event, struct dn_ifaddr *ifa);
79 static int dn_eth_up(struct net_device *);
80 static void dn_eth_down(struct net_device *);
81 static void dn_send_brd_hello(struct net_device *dev, struct dn_ifaddr *ifa);
82 static void dn_send_ptp_hello(struct net_device *dev, struct dn_ifaddr *ifa);
84 static struct dn_dev_parms dn_dev_list[] = {
86 .type = ARPHRD_ETHER, /* Ethernet */
87 .mode = DN_DEV_BCAST,
88 .state = DN_DEV_S_RU,
89 .t2 = 1,
90 .t3 = 10,
91 .name = "ethernet",
92 .ctl_name = NET_DECNET_CONF_ETHER,
93 .up = dn_eth_up,
94 .down = dn_eth_down,
95 .timer3 = dn_send_brd_hello,
98 .type = ARPHRD_IPGRE, /* DECnet tunneled over GRE in IP */
99 .mode = DN_DEV_BCAST,
100 .state = DN_DEV_S_RU,
101 .t2 = 1,
102 .t3 = 10,
103 .name = "ipgre",
104 .ctl_name = NET_DECNET_CONF_GRE,
105 .timer3 = dn_send_brd_hello,
107 #if 0
109 .type = ARPHRD_X25, /* Bog standard X.25 */
110 .mode = DN_DEV_UCAST,
111 .state = DN_DEV_S_DS,
112 .t2 = 1,
113 .t3 = 120,
114 .name = "x25",
115 .ctl_name = NET_DECNET_CONF_X25,
116 .timer3 = dn_send_ptp_hello,
118 #endif
119 #if 0
121 .type = ARPHRD_PPP, /* DECnet over PPP */
122 .mode = DN_DEV_BCAST,
123 .state = DN_DEV_S_RU,
124 .t2 = 1,
125 .t3 = 10,
126 .name = "ppp",
127 .ctl_name = NET_DECNET_CONF_PPP,
128 .timer3 = dn_send_brd_hello,
130 #endif
132 .type = ARPHRD_DDCMP, /* DECnet over DDCMP */
133 .mode = DN_DEV_UCAST,
134 .state = DN_DEV_S_DS,
135 .t2 = 1,
136 .t3 = 120,
137 .name = "ddcmp",
138 .ctl_name = NET_DECNET_CONF_DDCMP,
139 .timer3 = dn_send_ptp_hello,
142 .type = ARPHRD_LOOPBACK, /* Loopback interface - always last */
143 .mode = DN_DEV_BCAST,
144 .state = DN_DEV_S_RU,
145 .t2 = 1,
146 .t3 = 10,
147 .name = "loopback",
148 .ctl_name = NET_DECNET_CONF_LOOPBACK,
149 .timer3 = dn_send_brd_hello,
153 #define DN_DEV_LIST_SIZE ARRAY_SIZE(dn_dev_list)
155 #define DN_DEV_PARMS_OFFSET(x) offsetof(struct dn_dev_parms, x)
157 #ifdef CONFIG_SYSCTL
159 static int min_t2[] = { 1 };
160 static int max_t2[] = { 60 }; /* No max specified, but this seems sensible */
161 static int min_t3[] = { 1 };
162 static int max_t3[] = { 8191 }; /* Must fit in 16 bits when multiplied by BCT3MULT or T3MULT */
164 static int min_priority[1];
165 static int max_priority[] = { 127 }; /* From DECnet spec */
167 static int dn_forwarding_proc(ctl_table *, int,
168 void __user *, size_t *, loff_t *);
169 static int dn_forwarding_sysctl(ctl_table *table,
170 void __user *oldval, size_t __user *oldlenp,
171 void __user *newval, size_t newlen);
173 static struct dn_dev_sysctl_table {
174 struct ctl_table_header *sysctl_header;
175 ctl_table dn_dev_vars[5];
176 } dn_dev_sysctl = {
177 NULL,
180 .ctl_name = NET_DECNET_CONF_DEV_FORWARDING,
181 .procname = "forwarding",
182 .data = (void *)DN_DEV_PARMS_OFFSET(forwarding),
183 .maxlen = sizeof(int),
184 .mode = 0644,
185 .proc_handler = dn_forwarding_proc,
186 .strategy = dn_forwarding_sysctl,
189 .ctl_name = NET_DECNET_CONF_DEV_PRIORITY,
190 .procname = "priority",
191 .data = (void *)DN_DEV_PARMS_OFFSET(priority),
192 .maxlen = sizeof(int),
193 .mode = 0644,
194 .proc_handler = proc_dointvec_minmax,
195 .strategy = sysctl_intvec,
196 .extra1 = &min_priority,
197 .extra2 = &max_priority
200 .ctl_name = NET_DECNET_CONF_DEV_T2,
201 .procname = "t2",
202 .data = (void *)DN_DEV_PARMS_OFFSET(t2),
203 .maxlen = sizeof(int),
204 .mode = 0644,
205 .proc_handler = proc_dointvec_minmax,
206 .strategy = sysctl_intvec,
207 .extra1 = &min_t2,
208 .extra2 = &max_t2
211 .ctl_name = NET_DECNET_CONF_DEV_T3,
212 .procname = "t3",
213 .data = (void *)DN_DEV_PARMS_OFFSET(t3),
214 .maxlen = sizeof(int),
215 .mode = 0644,
216 .proc_handler = proc_dointvec_minmax,
217 .strategy = sysctl_intvec,
218 .extra1 = &min_t3,
219 .extra2 = &max_t3
225 static void dn_dev_sysctl_register(struct net_device *dev, struct dn_dev_parms *parms)
227 struct dn_dev_sysctl_table *t;
228 int i;
230 #define DN_CTL_PATH_DEV 3
232 struct ctl_path dn_ctl_path[] = {
233 { .procname = "net", .ctl_name = CTL_NET, },
234 { .procname = "decnet", .ctl_name = NET_DECNET, },
235 { .procname = "conf", .ctl_name = NET_DECNET_CONF, },
236 { /* to be set */ },
237 { },
240 t = kmemdup(&dn_dev_sysctl, sizeof(*t), GFP_KERNEL);
241 if (t == NULL)
242 return;
244 for(i = 0; i < ARRAY_SIZE(t->dn_dev_vars) - 1; i++) {
245 long offset = (long)t->dn_dev_vars[i].data;
246 t->dn_dev_vars[i].data = ((char *)parms) + offset;
249 if (dev) {
250 dn_ctl_path[DN_CTL_PATH_DEV].procname = dev->name;
251 dn_ctl_path[DN_CTL_PATH_DEV].ctl_name = dev->ifindex;
252 } else {
253 dn_ctl_path[DN_CTL_PATH_DEV].procname = parms->name;
254 dn_ctl_path[DN_CTL_PATH_DEV].ctl_name = parms->ctl_name;
257 t->dn_dev_vars[0].extra1 = (void *)dev;
259 t->sysctl_header = register_sysctl_paths(dn_ctl_path, t->dn_dev_vars);
260 if (t->sysctl_header == NULL)
261 kfree(t);
262 else
263 parms->sysctl = t;
266 static void dn_dev_sysctl_unregister(struct dn_dev_parms *parms)
268 if (parms->sysctl) {
269 struct dn_dev_sysctl_table *t = parms->sysctl;
270 parms->sysctl = NULL;
271 unregister_sysctl_table(t->sysctl_header);
272 kfree(t);
276 static int dn_forwarding_proc(ctl_table *table, int write,
277 void __user *buffer,
278 size_t *lenp, loff_t *ppos)
280 #ifdef CONFIG_DECNET_ROUTER
281 struct net_device *dev = table->extra1;
282 struct dn_dev *dn_db;
283 int err;
284 int tmp, old;
286 if (table->extra1 == NULL)
287 return -EINVAL;
289 dn_db = dev->dn_ptr;
290 old = dn_db->parms.forwarding;
292 err = proc_dointvec(table, write, buffer, lenp, ppos);
294 if ((err >= 0) && write) {
295 if (dn_db->parms.forwarding < 0)
296 dn_db->parms.forwarding = 0;
297 if (dn_db->parms.forwarding > 2)
298 dn_db->parms.forwarding = 2;
300 * What an ugly hack this is... its works, just. It
301 * would be nice if sysctl/proc were just that little
302 * bit more flexible so I don't have to write a special
303 * routine, or suffer hacks like this - SJW
305 tmp = dn_db->parms.forwarding;
306 dn_db->parms.forwarding = old;
307 if (dn_db->parms.down)
308 dn_db->parms.down(dev);
309 dn_db->parms.forwarding = tmp;
310 if (dn_db->parms.up)
311 dn_db->parms.up(dev);
314 return err;
315 #else
316 return -EINVAL;
317 #endif
320 static int dn_forwarding_sysctl(ctl_table *table,
321 void __user *oldval, size_t __user *oldlenp,
322 void __user *newval, size_t newlen)
324 #ifdef CONFIG_DECNET_ROUTER
325 struct net_device *dev = table->extra1;
326 struct dn_dev *dn_db;
327 int value;
329 if (table->extra1 == NULL)
330 return -EINVAL;
332 dn_db = dev->dn_ptr;
334 if (newval && newlen) {
335 if (newlen != sizeof(int))
336 return -EINVAL;
338 if (get_user(value, (int __user *)newval))
339 return -EFAULT;
340 if (value < 0)
341 return -EINVAL;
342 if (value > 2)
343 return -EINVAL;
345 if (dn_db->parms.down)
346 dn_db->parms.down(dev);
347 dn_db->parms.forwarding = value;
348 if (dn_db->parms.up)
349 dn_db->parms.up(dev);
352 return 0;
353 #else
354 return -EINVAL;
355 #endif
358 #else /* CONFIG_SYSCTL */
359 static void dn_dev_sysctl_unregister(struct dn_dev_parms *parms)
362 static void dn_dev_sysctl_register(struct net_device *dev, struct dn_dev_parms *parms)
366 #endif /* CONFIG_SYSCTL */
368 static inline __u16 mtu2blksize(struct net_device *dev)
370 u32 blksize = dev->mtu;
371 if (blksize > 0xffff)
372 blksize = 0xffff;
374 if (dev->type == ARPHRD_ETHER ||
375 dev->type == ARPHRD_PPP ||
376 dev->type == ARPHRD_IPGRE ||
377 dev->type == ARPHRD_LOOPBACK)
378 blksize -= 2;
380 return (__u16)blksize;
383 static struct dn_ifaddr *dn_dev_alloc_ifa(void)
385 struct dn_ifaddr *ifa;
387 ifa = kzalloc(sizeof(*ifa), GFP_KERNEL);
389 return ifa;
392 static __inline__ void dn_dev_free_ifa(struct dn_ifaddr *ifa)
394 kfree(ifa);
397 static void dn_dev_del_ifa(struct dn_dev *dn_db, struct dn_ifaddr **ifap, int destroy)
399 struct dn_ifaddr *ifa1 = *ifap;
400 unsigned char mac_addr[6];
401 struct net_device *dev = dn_db->dev;
403 ASSERT_RTNL();
405 *ifap = ifa1->ifa_next;
407 if (dn_db->dev->type == ARPHRD_ETHER) {
408 if (ifa1->ifa_local != dn_eth2dn(dev->dev_addr)) {
409 dn_dn2eth(mac_addr, ifa1->ifa_local);
410 dev_mc_delete(dev, mac_addr, ETH_ALEN, 0);
414 dn_ifaddr_notify(RTM_DELADDR, ifa1);
415 blocking_notifier_call_chain(&dnaddr_chain, NETDEV_DOWN, ifa1);
416 if (destroy) {
417 dn_dev_free_ifa(ifa1);
419 if (dn_db->ifa_list == NULL)
420 dn_dev_delete(dn_db->dev);
424 static int dn_dev_insert_ifa(struct dn_dev *dn_db, struct dn_ifaddr *ifa)
426 struct net_device *dev = dn_db->dev;
427 struct dn_ifaddr *ifa1;
428 unsigned char mac_addr[6];
430 ASSERT_RTNL();
432 /* Check for duplicates */
433 for(ifa1 = dn_db->ifa_list; ifa1; ifa1 = ifa1->ifa_next) {
434 if (ifa1->ifa_local == ifa->ifa_local)
435 return -EEXIST;
438 if (dev->type == ARPHRD_ETHER) {
439 if (ifa->ifa_local != dn_eth2dn(dev->dev_addr)) {
440 dn_dn2eth(mac_addr, ifa->ifa_local);
441 dev_mc_add(dev, mac_addr, ETH_ALEN, 0);
445 ifa->ifa_next = dn_db->ifa_list;
446 dn_db->ifa_list = ifa;
448 dn_ifaddr_notify(RTM_NEWADDR, ifa);
449 blocking_notifier_call_chain(&dnaddr_chain, NETDEV_UP, ifa);
451 return 0;
454 static int dn_dev_set_ifa(struct net_device *dev, struct dn_ifaddr *ifa)
456 struct dn_dev *dn_db = dev->dn_ptr;
457 int rv;
459 if (dn_db == NULL) {
460 int err;
461 dn_db = dn_dev_create(dev, &err);
462 if (dn_db == NULL)
463 return err;
466 ifa->ifa_dev = dn_db;
468 if (dev->flags & IFF_LOOPBACK)
469 ifa->ifa_scope = RT_SCOPE_HOST;
471 rv = dn_dev_insert_ifa(dn_db, ifa);
472 if (rv)
473 dn_dev_free_ifa(ifa);
474 return rv;
478 int dn_dev_ioctl(unsigned int cmd, void __user *arg)
480 char buffer[DN_IFREQ_SIZE];
481 struct ifreq *ifr = (struct ifreq *)buffer;
482 struct sockaddr_dn *sdn = (struct sockaddr_dn *)&ifr->ifr_addr;
483 struct dn_dev *dn_db;
484 struct net_device *dev;
485 struct dn_ifaddr *ifa = NULL, **ifap = NULL;
486 int ret = 0;
488 if (copy_from_user(ifr, arg, DN_IFREQ_SIZE))
489 return -EFAULT;
490 ifr->ifr_name[IFNAMSIZ-1] = 0;
492 dev_load(&init_net, ifr->ifr_name);
494 switch(cmd) {
495 case SIOCGIFADDR:
496 break;
497 case SIOCSIFADDR:
498 if (!capable(CAP_NET_ADMIN))
499 return -EACCES;
500 if (sdn->sdn_family != AF_DECnet)
501 return -EINVAL;
502 break;
503 default:
504 return -EINVAL;
507 rtnl_lock();
509 if ((dev = __dev_get_by_name(&init_net, ifr->ifr_name)) == NULL) {
510 ret = -ENODEV;
511 goto done;
514 if ((dn_db = dev->dn_ptr) != NULL) {
515 for (ifap = &dn_db->ifa_list; (ifa=*ifap) != NULL; ifap = &ifa->ifa_next)
516 if (strcmp(ifr->ifr_name, ifa->ifa_label) == 0)
517 break;
520 if (ifa == NULL && cmd != SIOCSIFADDR) {
521 ret = -EADDRNOTAVAIL;
522 goto done;
525 switch(cmd) {
526 case SIOCGIFADDR:
527 *((__le16 *)sdn->sdn_nodeaddr) = ifa->ifa_local;
528 goto rarok;
530 case SIOCSIFADDR:
531 if (!ifa) {
532 if ((ifa = dn_dev_alloc_ifa()) == NULL) {
533 ret = -ENOBUFS;
534 break;
536 memcpy(ifa->ifa_label, dev->name, IFNAMSIZ);
537 } else {
538 if (ifa->ifa_local == dn_saddr2dn(sdn))
539 break;
540 dn_dev_del_ifa(dn_db, ifap, 0);
543 ifa->ifa_local = ifa->ifa_address = dn_saddr2dn(sdn);
545 ret = dn_dev_set_ifa(dev, ifa);
547 done:
548 rtnl_unlock();
550 return ret;
551 rarok:
552 if (copy_to_user(arg, ifr, DN_IFREQ_SIZE))
553 ret = -EFAULT;
554 goto done;
557 struct net_device *dn_dev_get_default(void)
559 struct net_device *dev;
560 read_lock(&dndev_lock);
561 dev = decnet_default_device;
562 if (dev) {
563 if (dev->dn_ptr)
564 dev_hold(dev);
565 else
566 dev = NULL;
568 read_unlock(&dndev_lock);
569 return dev;
572 int dn_dev_set_default(struct net_device *dev, int force)
574 struct net_device *old = NULL;
575 int rv = -EBUSY;
576 if (!dev->dn_ptr)
577 return -ENODEV;
578 write_lock(&dndev_lock);
579 if (force || decnet_default_device == NULL) {
580 old = decnet_default_device;
581 decnet_default_device = dev;
582 rv = 0;
584 write_unlock(&dndev_lock);
585 if (old)
586 dev_put(old);
587 return rv;
590 static void dn_dev_check_default(struct net_device *dev)
592 write_lock(&dndev_lock);
593 if (dev == decnet_default_device) {
594 decnet_default_device = NULL;
595 } else {
596 dev = NULL;
598 write_unlock(&dndev_lock);
599 if (dev)
600 dev_put(dev);
604 * Called with RTNL
606 static struct dn_dev *dn_dev_by_index(int ifindex)
608 struct net_device *dev;
609 struct dn_dev *dn_dev = NULL;
611 dev = __dev_get_by_index(&init_net, ifindex);
612 if (dev)
613 dn_dev = dev->dn_ptr;
615 return dn_dev;
618 static const struct nla_policy dn_ifa_policy[IFA_MAX+1] = {
619 [IFA_ADDRESS] = { .type = NLA_U16 },
620 [IFA_LOCAL] = { .type = NLA_U16 },
621 [IFA_LABEL] = { .type = NLA_STRING,
622 .len = IFNAMSIZ - 1 },
625 static int dn_nl_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
627 struct net *net = sock_net(skb->sk);
628 struct nlattr *tb[IFA_MAX+1];
629 struct dn_dev *dn_db;
630 struct ifaddrmsg *ifm;
631 struct dn_ifaddr *ifa, **ifap;
632 int err = -EINVAL;
634 if (net != &init_net)
635 goto errout;
637 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, dn_ifa_policy);
638 if (err < 0)
639 goto errout;
641 err = -ENODEV;
642 ifm = nlmsg_data(nlh);
643 if ((dn_db = dn_dev_by_index(ifm->ifa_index)) == NULL)
644 goto errout;
646 err = -EADDRNOTAVAIL;
647 for (ifap = &dn_db->ifa_list; (ifa = *ifap); ifap = &ifa->ifa_next) {
648 if (tb[IFA_LOCAL] &&
649 nla_memcmp(tb[IFA_LOCAL], &ifa->ifa_local, 2))
650 continue;
652 if (tb[IFA_LABEL] && nla_strcmp(tb[IFA_LABEL], ifa->ifa_label))
653 continue;
655 dn_dev_del_ifa(dn_db, ifap, 1);
656 return 0;
659 errout:
660 return err;
663 static int dn_nl_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
665 struct net *net = sock_net(skb->sk);
666 struct nlattr *tb[IFA_MAX+1];
667 struct net_device *dev;
668 struct dn_dev *dn_db;
669 struct ifaddrmsg *ifm;
670 struct dn_ifaddr *ifa;
671 int err;
673 if (net != &init_net)
674 return -EINVAL;
676 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, dn_ifa_policy);
677 if (err < 0)
678 return err;
680 if (tb[IFA_LOCAL] == NULL)
681 return -EINVAL;
683 ifm = nlmsg_data(nlh);
684 if ((dev = __dev_get_by_index(&init_net, ifm->ifa_index)) == NULL)
685 return -ENODEV;
687 if ((dn_db = dev->dn_ptr) == NULL) {
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 (tb[IFA_ADDRESS] == NULL)
697 tb[IFA_ADDRESS] = tb[IFA_LOCAL];
699 ifa->ifa_local = nla_get_le16(tb[IFA_LOCAL]);
700 ifa->ifa_address = nla_get_le16(tb[IFA_ADDRESS]);
701 ifa->ifa_flags = ifm->ifa_flags;
702 ifa->ifa_scope = ifm->ifa_scope;
703 ifa->ifa_dev = dn_db;
705 if (tb[IFA_LABEL])
706 nla_strlcpy(ifa->ifa_label, tb[IFA_LABEL], IFNAMSIZ);
707 else
708 memcpy(ifa->ifa_label, dev->name, IFNAMSIZ);
710 err = dn_dev_insert_ifa(dn_db, ifa);
711 if (err)
712 dn_dev_free_ifa(ifa);
714 return err;
717 static inline size_t dn_ifaddr_nlmsg_size(void)
719 return NLMSG_ALIGN(sizeof(struct ifaddrmsg))
720 + nla_total_size(IFNAMSIZ) /* IFA_LABEL */
721 + nla_total_size(2) /* IFA_ADDRESS */
722 + nla_total_size(2); /* IFA_LOCAL */
725 static int dn_nl_fill_ifaddr(struct sk_buff *skb, struct dn_ifaddr *ifa,
726 u32 pid, u32 seq, int event, unsigned int flags)
728 struct ifaddrmsg *ifm;
729 struct nlmsghdr *nlh;
731 nlh = nlmsg_put(skb, pid, seq, event, sizeof(*ifm), flags);
732 if (nlh == NULL)
733 return -EMSGSIZE;
735 ifm = nlmsg_data(nlh);
736 ifm->ifa_family = AF_DECnet;
737 ifm->ifa_prefixlen = 16;
738 ifm->ifa_flags = ifa->ifa_flags | IFA_F_PERMANENT;
739 ifm->ifa_scope = ifa->ifa_scope;
740 ifm->ifa_index = ifa->ifa_dev->dev->ifindex;
742 if (ifa->ifa_address)
743 NLA_PUT_LE16(skb, IFA_ADDRESS, ifa->ifa_address);
744 if (ifa->ifa_local)
745 NLA_PUT_LE16(skb, IFA_LOCAL, ifa->ifa_local);
746 if (ifa->ifa_label[0])
747 NLA_PUT_STRING(skb, IFA_LABEL, ifa->ifa_label);
749 return nlmsg_end(skb, nlh);
751 nla_put_failure:
752 nlmsg_cancel(skb, nlh);
753 return -EMSGSIZE;
756 static void dn_ifaddr_notify(int event, struct dn_ifaddr *ifa)
758 struct sk_buff *skb;
759 int err = -ENOBUFS;
761 skb = alloc_skb(dn_ifaddr_nlmsg_size(), GFP_KERNEL);
762 if (skb == NULL)
763 goto errout;
765 err = dn_nl_fill_ifaddr(skb, ifa, 0, 0, event, 0);
766 if (err < 0) {
767 /* -EMSGSIZE implies BUG in dn_ifaddr_nlmsg_size() */
768 WARN_ON(err == -EMSGSIZE);
769 kfree_skb(skb);
770 goto errout;
772 rtnl_notify(skb, &init_net, 0, RTNLGRP_DECnet_IFADDR, NULL, GFP_KERNEL);
773 return;
774 errout:
775 if (err < 0)
776 rtnl_set_sk_err(&init_net, RTNLGRP_DECnet_IFADDR, err);
779 static int dn_nl_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
781 struct net *net = sock_net(skb->sk);
782 int idx, dn_idx = 0, skip_ndevs, skip_naddr;
783 struct net_device *dev;
784 struct dn_dev *dn_db;
785 struct dn_ifaddr *ifa;
787 if (net != &init_net)
788 return 0;
790 skip_ndevs = cb->args[0];
791 skip_naddr = cb->args[1];
793 idx = 0;
794 for_each_netdev(&init_net, dev) {
795 if (idx < skip_ndevs)
796 goto cont;
797 else if (idx > skip_ndevs) {
798 /* Only skip over addresses for first dev dumped
799 * in this iteration (idx == skip_ndevs) */
800 skip_naddr = 0;
803 if ((dn_db = dev->dn_ptr) == NULL)
804 goto cont;
806 for (ifa = dn_db->ifa_list, dn_idx = 0; ifa;
807 ifa = ifa->ifa_next, dn_idx++) {
808 if (dn_idx < skip_naddr)
809 continue;
811 if (dn_nl_fill_ifaddr(skb, ifa, NETLINK_CB(cb->skb).pid,
812 cb->nlh->nlmsg_seq, RTM_NEWADDR,
813 NLM_F_MULTI) < 0)
814 goto done;
816 cont:
817 idx++;
819 done:
820 cb->args[0] = idx;
821 cb->args[1] = dn_idx;
823 return skb->len;
826 static int dn_dev_get_first(struct net_device *dev, __le16 *addr)
828 struct dn_dev *dn_db = (struct dn_dev *)dev->dn_ptr;
829 struct dn_ifaddr *ifa;
830 int rv = -ENODEV;
832 if (dn_db == NULL)
833 goto out;
835 rtnl_lock();
836 ifa = dn_db->ifa_list;
837 if (ifa != NULL) {
838 *addr = ifa->ifa_local;
839 rv = 0;
841 rtnl_unlock();
842 out:
843 return rv;
847 * Find a default address to bind to.
849 * This is one of those areas where the initial VMS concepts don't really
850 * map onto the Linux concepts, and since we introduced multiple addresses
851 * per interface we have to cope with slightly odd ways of finding out what
852 * "our address" really is. Mostly it's not a problem; for this we just guess
853 * a sensible default. Eventually the routing code will take care of all the
854 * nasties for us I hope.
856 int dn_dev_bind_default(__le16 *addr)
858 struct net_device *dev;
859 int rv;
860 dev = dn_dev_get_default();
861 last_chance:
862 if (dev) {
863 rv = dn_dev_get_first(dev, addr);
864 dev_put(dev);
865 if (rv == 0 || dev == init_net.loopback_dev)
866 return rv;
868 dev = init_net.loopback_dev;
869 dev_hold(dev);
870 goto last_chance;
873 static void dn_send_endnode_hello(struct net_device *dev, struct dn_ifaddr *ifa)
875 struct endnode_hello_message *msg;
876 struct sk_buff *skb = NULL;
877 __le16 *pktlen;
878 struct dn_dev *dn_db = (struct dn_dev *)dev->dn_ptr;
880 if ((skb = dn_alloc_skb(NULL, sizeof(*msg), GFP_ATOMIC)) == NULL)
881 return;
883 skb->dev = dev;
885 msg = (struct endnode_hello_message *)skb_put(skb,sizeof(*msg));
887 msg->msgflg = 0x0D;
888 memcpy(msg->tiver, dn_eco_version, 3);
889 dn_dn2eth(msg->id, ifa->ifa_local);
890 msg->iinfo = DN_RT_INFO_ENDN;
891 msg->blksize = cpu_to_le16(mtu2blksize(dev));
892 msg->area = 0x00;
893 memset(msg->seed, 0, 8);
894 memcpy(msg->neighbor, dn_hiord, ETH_ALEN);
896 if (dn_db->router) {
897 struct dn_neigh *dn = (struct dn_neigh *)dn_db->router;
898 dn_dn2eth(msg->neighbor, dn->addr);
901 msg->timer = cpu_to_le16((unsigned short)dn_db->parms.t3);
902 msg->mpd = 0x00;
903 msg->datalen = 0x02;
904 memset(msg->data, 0xAA, 2);
906 pktlen = (__le16 *)skb_push(skb,2);
907 *pktlen = cpu_to_le16(skb->len - 2);
909 skb_reset_network_header(skb);
911 dn_rt_finish_output(skb, dn_rt_all_rt_mcast, msg->id);
915 #define DRDELAY (5 * HZ)
917 static int dn_am_i_a_router(struct dn_neigh *dn, struct dn_dev *dn_db, struct dn_ifaddr *ifa)
919 /* First check time since device went up */
920 if ((jiffies - dn_db->uptime) < DRDELAY)
921 return 0;
923 /* If there is no router, then yes... */
924 if (!dn_db->router)
925 return 1;
927 /* otherwise only if we have a higher priority or.. */
928 if (dn->priority < dn_db->parms.priority)
929 return 1;
931 /* if we have equal priority and a higher node number */
932 if (dn->priority != dn_db->parms.priority)
933 return 0;
935 if (le16_to_cpu(dn->addr) < le16_to_cpu(ifa->ifa_local))
936 return 1;
938 return 0;
941 static void dn_send_router_hello(struct net_device *dev, struct dn_ifaddr *ifa)
943 int n;
944 struct dn_dev *dn_db = dev->dn_ptr;
945 struct dn_neigh *dn = (struct dn_neigh *)dn_db->router;
946 struct sk_buff *skb;
947 size_t size;
948 unsigned char *ptr;
949 unsigned char *i1, *i2;
950 __le16 *pktlen;
951 char *src;
953 if (mtu2blksize(dev) < (26 + 7))
954 return;
956 n = mtu2blksize(dev) - 26;
957 n /= 7;
959 if (n > 32)
960 n = 32;
962 size = 2 + 26 + 7 * n;
964 if ((skb = dn_alloc_skb(NULL, size, GFP_ATOMIC)) == NULL)
965 return;
967 skb->dev = dev;
968 ptr = skb_put(skb, size);
970 *ptr++ = DN_RT_PKT_CNTL | DN_RT_PKT_ERTH;
971 *ptr++ = 2; /* ECO */
972 *ptr++ = 0;
973 *ptr++ = 0;
974 dn_dn2eth(ptr, ifa->ifa_local);
975 src = ptr;
976 ptr += ETH_ALEN;
977 *ptr++ = dn_db->parms.forwarding == 1 ?
978 DN_RT_INFO_L1RT : DN_RT_INFO_L2RT;
979 *((__le16 *)ptr) = cpu_to_le16(mtu2blksize(dev));
980 ptr += 2;
981 *ptr++ = dn_db->parms.priority; /* Priority */
982 *ptr++ = 0; /* Area: Reserved */
983 *((__le16 *)ptr) = cpu_to_le16((unsigned short)dn_db->parms.t3);
984 ptr += 2;
985 *ptr++ = 0; /* MPD: Reserved */
986 i1 = ptr++;
987 memset(ptr, 0, 7); /* Name: Reserved */
988 ptr += 7;
989 i2 = ptr++;
991 n = dn_neigh_elist(dev, ptr, n);
993 *i2 = 7 * n;
994 *i1 = 8 + *i2;
996 skb_trim(skb, (27 + *i2));
998 pktlen = (__le16 *)skb_push(skb, 2);
999 *pktlen = cpu_to_le16(skb->len - 2);
1001 skb_reset_network_header(skb);
1003 if (dn_am_i_a_router(dn, dn_db, ifa)) {
1004 struct sk_buff *skb2 = skb_copy(skb, GFP_ATOMIC);
1005 if (skb2) {
1006 dn_rt_finish_output(skb2, dn_rt_all_end_mcast, src);
1010 dn_rt_finish_output(skb, dn_rt_all_rt_mcast, src);
1013 static void dn_send_brd_hello(struct net_device *dev, struct dn_ifaddr *ifa)
1015 struct dn_dev *dn_db = (struct dn_dev *)dev->dn_ptr;
1017 if (dn_db->parms.forwarding == 0)
1018 dn_send_endnode_hello(dev, ifa);
1019 else
1020 dn_send_router_hello(dev, ifa);
1023 static void dn_send_ptp_hello(struct net_device *dev, struct dn_ifaddr *ifa)
1025 int tdlen = 16;
1026 int size = dev->hard_header_len + 2 + 4 + tdlen;
1027 struct sk_buff *skb = dn_alloc_skb(NULL, size, GFP_ATOMIC);
1028 int i;
1029 unsigned char *ptr;
1030 char src[ETH_ALEN];
1032 if (skb == NULL)
1033 return ;
1035 skb->dev = dev;
1036 skb_push(skb, dev->hard_header_len);
1037 ptr = skb_put(skb, 2 + 4 + tdlen);
1039 *ptr++ = DN_RT_PKT_HELO;
1040 *((__le16 *)ptr) = ifa->ifa_local;
1041 ptr += 2;
1042 *ptr++ = tdlen;
1044 for(i = 0; i < tdlen; i++)
1045 *ptr++ = 0252;
1047 dn_dn2eth(src, ifa->ifa_local);
1048 dn_rt_finish_output(skb, dn_rt_all_rt_mcast, src);
1051 static int dn_eth_up(struct net_device *dev)
1053 struct dn_dev *dn_db = dev->dn_ptr;
1055 if (dn_db->parms.forwarding == 0)
1056 dev_mc_add(dev, dn_rt_all_end_mcast, ETH_ALEN, 0);
1057 else
1058 dev_mc_add(dev, dn_rt_all_rt_mcast, ETH_ALEN, 0);
1060 dn_db->use_long = 1;
1062 return 0;
1065 static void dn_eth_down(struct net_device *dev)
1067 struct dn_dev *dn_db = dev->dn_ptr;
1069 if (dn_db->parms.forwarding == 0)
1070 dev_mc_delete(dev, dn_rt_all_end_mcast, ETH_ALEN, 0);
1071 else
1072 dev_mc_delete(dev, dn_rt_all_rt_mcast, ETH_ALEN, 0);
1075 static void dn_dev_set_timer(struct net_device *dev);
1077 static void dn_dev_timer_func(unsigned long arg)
1079 struct net_device *dev = (struct net_device *)arg;
1080 struct dn_dev *dn_db = dev->dn_ptr;
1081 struct dn_ifaddr *ifa;
1083 if (dn_db->t3 <= dn_db->parms.t2) {
1084 if (dn_db->parms.timer3) {
1085 for(ifa = dn_db->ifa_list; ifa; ifa = ifa->ifa_next) {
1086 if (!(ifa->ifa_flags & IFA_F_SECONDARY))
1087 dn_db->parms.timer3(dev, ifa);
1090 dn_db->t3 = dn_db->parms.t3;
1091 } else {
1092 dn_db->t3 -= dn_db->parms.t2;
1095 dn_dev_set_timer(dev);
1098 static void dn_dev_set_timer(struct net_device *dev)
1100 struct dn_dev *dn_db = dev->dn_ptr;
1102 if (dn_db->parms.t2 > dn_db->parms.t3)
1103 dn_db->parms.t2 = dn_db->parms.t3;
1105 dn_db->timer.data = (unsigned long)dev;
1106 dn_db->timer.function = dn_dev_timer_func;
1107 dn_db->timer.expires = jiffies + (dn_db->parms.t2 * HZ);
1109 add_timer(&dn_db->timer);
1112 static struct dn_dev *dn_dev_create(struct net_device *dev, int *err)
1114 int i;
1115 struct dn_dev_parms *p = dn_dev_list;
1116 struct dn_dev *dn_db;
1118 for(i = 0; i < DN_DEV_LIST_SIZE; i++, p++) {
1119 if (p->type == dev->type)
1120 break;
1123 *err = -ENODEV;
1124 if (i == DN_DEV_LIST_SIZE)
1125 return NULL;
1127 *err = -ENOBUFS;
1128 if ((dn_db = kzalloc(sizeof(struct dn_dev), GFP_ATOMIC)) == NULL)
1129 return NULL;
1131 memcpy(&dn_db->parms, p, sizeof(struct dn_dev_parms));
1132 smp_wmb();
1133 dev->dn_ptr = dn_db;
1134 dn_db->dev = dev;
1135 init_timer(&dn_db->timer);
1137 dn_db->uptime = jiffies;
1139 dn_db->neigh_parms = neigh_parms_alloc(dev, &dn_neigh_table);
1140 if (!dn_db->neigh_parms) {
1141 dev->dn_ptr = NULL;
1142 kfree(dn_db);
1143 return NULL;
1146 if (dn_db->parms.up) {
1147 if (dn_db->parms.up(dev) < 0) {
1148 neigh_parms_release(&dn_neigh_table, dn_db->neigh_parms);
1149 dev->dn_ptr = NULL;
1150 kfree(dn_db);
1151 return NULL;
1155 dn_dev_sysctl_register(dev, &dn_db->parms);
1157 dn_dev_set_timer(dev);
1159 *err = 0;
1160 return dn_db;
1165 * This processes a device up event. We only start up
1166 * the loopback device & ethernet devices with correct
1167 * MAC addreses automatically. Others must be started
1168 * specifically.
1170 * FIXME: How should we configure the loopback address ? If we could dispense
1171 * with using decnet_address here and for autobind, it will be one less thing
1172 * for users to worry about setting up.
1175 void dn_dev_up(struct net_device *dev)
1177 struct dn_ifaddr *ifa;
1178 __le16 addr = decnet_address;
1179 int maybe_default = 0;
1180 struct dn_dev *dn_db = (struct dn_dev *)dev->dn_ptr;
1182 if ((dev->type != ARPHRD_ETHER) && (dev->type != ARPHRD_LOOPBACK))
1183 return;
1186 * Need to ensure that loopback device has a dn_db attached to it
1187 * to allow creation of neighbours against it, even though it might
1188 * not have a local address of its own. Might as well do the same for
1189 * all autoconfigured interfaces.
1191 if (dn_db == NULL) {
1192 int err;
1193 dn_db = dn_dev_create(dev, &err);
1194 if (dn_db == NULL)
1195 return;
1198 if (dev->type == ARPHRD_ETHER) {
1199 if (memcmp(dev->dev_addr, dn_hiord, 4) != 0)
1200 return;
1201 addr = dn_eth2dn(dev->dev_addr);
1202 maybe_default = 1;
1205 if (addr == 0)
1206 return;
1208 if ((ifa = dn_dev_alloc_ifa()) == NULL)
1209 return;
1211 ifa->ifa_local = ifa->ifa_address = addr;
1212 ifa->ifa_flags = 0;
1213 ifa->ifa_scope = RT_SCOPE_UNIVERSE;
1214 strcpy(ifa->ifa_label, dev->name);
1216 dn_dev_set_ifa(dev, ifa);
1219 * Automagically set the default device to the first automatically
1220 * configured ethernet card in the system.
1222 if (maybe_default) {
1223 dev_hold(dev);
1224 if (dn_dev_set_default(dev, 0))
1225 dev_put(dev);
1229 static void dn_dev_delete(struct net_device *dev)
1231 struct dn_dev *dn_db = dev->dn_ptr;
1233 if (dn_db == NULL)
1234 return;
1236 del_timer_sync(&dn_db->timer);
1237 dn_dev_sysctl_unregister(&dn_db->parms);
1238 dn_dev_check_default(dev);
1239 neigh_ifdown(&dn_neigh_table, dev);
1241 if (dn_db->parms.down)
1242 dn_db->parms.down(dev);
1244 dev->dn_ptr = NULL;
1246 neigh_parms_release(&dn_neigh_table, dn_db->neigh_parms);
1247 neigh_ifdown(&dn_neigh_table, dev);
1249 if (dn_db->router)
1250 neigh_release(dn_db->router);
1251 if (dn_db->peer)
1252 neigh_release(dn_db->peer);
1254 kfree(dn_db);
1257 void dn_dev_down(struct net_device *dev)
1259 struct dn_dev *dn_db = dev->dn_ptr;
1260 struct dn_ifaddr *ifa;
1262 if (dn_db == NULL)
1263 return;
1265 while((ifa = dn_db->ifa_list) != NULL) {
1266 dn_dev_del_ifa(dn_db, &dn_db->ifa_list, 0);
1267 dn_dev_free_ifa(ifa);
1270 dn_dev_delete(dev);
1273 void dn_dev_init_pkt(struct sk_buff *skb)
1275 return;
1278 void dn_dev_veri_pkt(struct sk_buff *skb)
1280 return;
1283 void dn_dev_hello(struct sk_buff *skb)
1285 return;
1288 void dn_dev_devices_off(void)
1290 struct net_device *dev;
1292 rtnl_lock();
1293 for_each_netdev(&init_net, dev)
1294 dn_dev_down(dev);
1295 rtnl_unlock();
1299 void dn_dev_devices_on(void)
1301 struct net_device *dev;
1303 rtnl_lock();
1304 for_each_netdev(&init_net, dev) {
1305 if (dev->flags & IFF_UP)
1306 dn_dev_up(dev);
1308 rtnl_unlock();
1311 int register_dnaddr_notifier(struct notifier_block *nb)
1313 return blocking_notifier_chain_register(&dnaddr_chain, nb);
1316 int unregister_dnaddr_notifier(struct notifier_block *nb)
1318 return blocking_notifier_chain_unregister(&dnaddr_chain, nb);
1321 #ifdef CONFIG_PROC_FS
1322 static inline int is_dn_dev(struct net_device *dev)
1324 return dev->dn_ptr != NULL;
1327 static void *dn_dev_seq_start(struct seq_file *seq, loff_t *pos)
1328 __acquires(rcu)
1330 int i;
1331 struct net_device *dev;
1333 rcu_read_lock();
1335 if (*pos == 0)
1336 return SEQ_START_TOKEN;
1338 i = 1;
1339 for_each_netdev_rcu(&init_net, dev) {
1340 if (!is_dn_dev(dev))
1341 continue;
1343 if (i++ == *pos)
1344 return dev;
1347 return NULL;
1350 static void *dn_dev_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1352 struct net_device *dev;
1354 ++*pos;
1356 dev = (struct net_device *)v;
1357 if (v == SEQ_START_TOKEN)
1358 dev = net_device_entry(&init_net.dev_base_head);
1360 for_each_netdev_continue_rcu(&init_net, dev) {
1361 if (!is_dn_dev(dev))
1362 continue;
1364 return dev;
1367 return NULL;
1370 static void dn_dev_seq_stop(struct seq_file *seq, void *v)
1371 __releases(rcu)
1373 rcu_read_unlock();
1376 static char *dn_type2asc(char type)
1378 switch(type) {
1379 case DN_DEV_BCAST:
1380 return "B";
1381 case DN_DEV_UCAST:
1382 return "U";
1383 case DN_DEV_MPOINT:
1384 return "M";
1387 return "?";
1390 static int dn_dev_seq_show(struct seq_file *seq, void *v)
1392 if (v == SEQ_START_TOKEN)
1393 seq_puts(seq, "Name Flags T1 Timer1 T3 Timer3 BlkSize Pri State DevType Router Peer\n");
1394 else {
1395 struct net_device *dev = v;
1396 char peer_buf[DN_ASCBUF_LEN];
1397 char router_buf[DN_ASCBUF_LEN];
1398 struct dn_dev *dn_db = dev->dn_ptr;
1400 seq_printf(seq, "%-8s %1s %04u %04u %04lu %04lu"
1401 " %04hu %03d %02x %-10s %-7s %-7s\n",
1402 dev->name ? dev->name : "???",
1403 dn_type2asc(dn_db->parms.mode),
1404 0, 0,
1405 dn_db->t3, dn_db->parms.t3,
1406 mtu2blksize(dev),
1407 dn_db->parms.priority,
1408 dn_db->parms.state, dn_db->parms.name,
1409 dn_db->router ? dn_addr2asc(le16_to_cpu(*(__le16 *)dn_db->router->primary_key), router_buf) : "",
1410 dn_db->peer ? dn_addr2asc(le16_to_cpu(*(__le16 *)dn_db->peer->primary_key), peer_buf) : "");
1412 return 0;
1415 static const struct seq_operations dn_dev_seq_ops = {
1416 .start = dn_dev_seq_start,
1417 .next = dn_dev_seq_next,
1418 .stop = dn_dev_seq_stop,
1419 .show = dn_dev_seq_show,
1422 static int dn_dev_seq_open(struct inode *inode, struct file *file)
1424 return seq_open(file, &dn_dev_seq_ops);
1427 static const struct file_operations dn_dev_seq_fops = {
1428 .owner = THIS_MODULE,
1429 .open = dn_dev_seq_open,
1430 .read = seq_read,
1431 .llseek = seq_lseek,
1432 .release = seq_release,
1435 #endif /* CONFIG_PROC_FS */
1437 static int addr[2];
1438 module_param_array(addr, int, NULL, 0444);
1439 MODULE_PARM_DESC(addr, "The DECnet address of this machine: area,node");
1441 void __init dn_dev_init(void)
1443 if (addr[0] > 63 || addr[0] < 0) {
1444 printk(KERN_ERR "DECnet: Area must be between 0 and 63");
1445 return;
1448 if (addr[1] > 1023 || addr[1] < 0) {
1449 printk(KERN_ERR "DECnet: Node must be between 0 and 1023");
1450 return;
1453 decnet_address = cpu_to_le16((addr[0] << 10) | addr[1]);
1455 dn_dev_devices_on();
1457 rtnl_register(PF_DECnet, RTM_NEWADDR, dn_nl_newaddr, NULL);
1458 rtnl_register(PF_DECnet, RTM_DELADDR, dn_nl_deladdr, NULL);
1459 rtnl_register(PF_DECnet, RTM_GETADDR, NULL, dn_nl_dump_ifaddr);
1461 proc_net_fops_create(&init_net, "decnet_dev", S_IRUGO, &dn_dev_seq_fops);
1463 #ifdef CONFIG_SYSCTL
1465 int i;
1466 for(i = 0; i < DN_DEV_LIST_SIZE; i++)
1467 dn_dev_sysctl_register(NULL, &dn_dev_list[i]);
1469 #endif /* CONFIG_SYSCTL */
1472 void __exit dn_dev_cleanup(void)
1474 #ifdef CONFIG_SYSCTL
1476 int i;
1477 for(i = 0; i < DN_DEV_LIST_SIZE; i++)
1478 dn_dev_sysctl_unregister(&dn_dev_list[i]);
1480 #endif /* CONFIG_SYSCTL */
1482 proc_net_remove(&init_net, "decnet_dev");
1484 dn_dev_devices_off();