linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / net / core / rtnetlink.c
1 /*
2  * INET         An implementation of the TCP/IP protocol suite for the LINUX
3  *              operating system.  INET is implemented using the  BSD Socket
4  *              interface as the means of communication with the user level.
5  *
6  *              Routing netlink socket interface: protocol independent part.
7  *
8  * Authors:     Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
9  *
10  *              This program is free software; you can redistribute it and/or
11  *              modify it under the terms of the GNU General Public License
12  *              as published by the Free Software Foundation; either version
13  *              2 of the License, or (at your option) any later version.
14  *
15  *      Fixes:
16  *      Vitaly E. Lavrov                RTA_OK arithmetics was wrong.
17  */
18
19 #include <linux/config.h>
20 #include <linux/errno.h>
21 #include <linux/module.h>
22 #include <linux/types.h>
23 #include <linux/socket.h>
24 #include <linux/kernel.h>
25 #include <linux/sched.h>
26 #include <linux/timer.h>
27 #include <linux/string.h>
28 #include <linux/sockios.h>
29 #include <linux/net.h>
30 #include <linux/fcntl.h>
31 #include <linux/mm.h>
32 #include <linux/slab.h>
33 #include <linux/interrupt.h>
34 #include <linux/capability.h>
35 #include <linux/skbuff.h>
36 #include <linux/init.h>
37 #include <linux/security.h>
38
39 #include <asm/uaccess.h>
40 #include <asm/system.h>
41 #include <asm/string.h>
42
43 #include <linux/inet.h>
44 #include <linux/netdevice.h>
45 #include <net/ip.h>
46 #include <net/protocol.h>
47 #include <net/arp.h>
48 #include <net/route.h>
49 #include <net/udp.h>
50 #include <net/sock.h>
51 #include <net/pkt_sched.h>
52 #include <net/netlink.h>
53
54 DECLARE_MUTEX(rtnl_sem);
55
56 void rtnl_lock(void)
57 {
58         rtnl_shlock();
59 }
60
61 int rtnl_lock_interruptible(void)
62 {
63         return down_interruptible(&rtnl_sem);
64 }
65  
66 void rtnl_unlock(void)
67 {
68         rtnl_shunlock();
69
70         netdev_run_todo();
71 }
72
73 int rtattr_parse(struct rtattr *tb[], int maxattr, struct rtattr *rta, int len)
74 {
75         memset(tb, 0, sizeof(struct rtattr*)*maxattr);
76
77         while (RTA_OK(rta, len)) {
78                 unsigned flavor = rta->rta_type;
79                 if (flavor && flavor <= maxattr)
80                         tb[flavor-1] = rta;
81                 rta = RTA_NEXT(rta, len);
82         }
83         return 0;
84 }
85
86 struct sock *rtnl;
87
88 struct rtnetlink_link * rtnetlink_links[NPROTO];
89
90 static const int rtm_min[RTM_NR_FAMILIES] =
91 {
92         [RTM_FAM(RTM_NEWLINK)]      = NLMSG_LENGTH(sizeof(struct ifinfomsg)),
93         [RTM_FAM(RTM_NEWADDR)]      = NLMSG_LENGTH(sizeof(struct ifaddrmsg)),
94         [RTM_FAM(RTM_NEWROUTE)]     = NLMSG_LENGTH(sizeof(struct rtmsg)),
95         [RTM_FAM(RTM_NEWNEIGH)]     = NLMSG_LENGTH(sizeof(struct ndmsg)),
96         [RTM_FAM(RTM_NEWRULE)]      = NLMSG_LENGTH(sizeof(struct rtmsg)),
97         [RTM_FAM(RTM_NEWQDISC)]     = NLMSG_LENGTH(sizeof(struct tcmsg)),
98         [RTM_FAM(RTM_NEWTCLASS)]    = NLMSG_LENGTH(sizeof(struct tcmsg)),
99         [RTM_FAM(RTM_NEWTFILTER)]   = NLMSG_LENGTH(sizeof(struct tcmsg)),
100         [RTM_FAM(RTM_NEWACTION)]    = NLMSG_LENGTH(sizeof(struct tcamsg)),
101         [RTM_FAM(RTM_NEWPREFIX)]    = NLMSG_LENGTH(sizeof(struct rtgenmsg)),
102         [RTM_FAM(RTM_GETMULTICAST)] = NLMSG_LENGTH(sizeof(struct rtgenmsg)),
103         [RTM_FAM(RTM_GETANYCAST)]   = NLMSG_LENGTH(sizeof(struct rtgenmsg)),
104         [RTM_FAM(RTM_NEWNEIGHTBL)]  = NLMSG_LENGTH(sizeof(struct ndtmsg)),
105 };
106
107 static const int rta_max[RTM_NR_FAMILIES] =
108 {
109         [RTM_FAM(RTM_NEWLINK)]      = IFLA_MAX,
110         [RTM_FAM(RTM_NEWADDR)]      = IFA_MAX,
111         [RTM_FAM(RTM_NEWROUTE)]     = RTA_MAX,
112         [RTM_FAM(RTM_NEWNEIGH)]     = NDA_MAX,
113         [RTM_FAM(RTM_NEWRULE)]      = RTA_MAX,
114         [RTM_FAM(RTM_NEWQDISC)]     = TCA_MAX,
115         [RTM_FAM(RTM_NEWTCLASS)]    = TCA_MAX,
116         [RTM_FAM(RTM_NEWTFILTER)]   = TCA_MAX,
117         [RTM_FAM(RTM_NEWACTION)]    = TCAA_MAX,
118         [RTM_FAM(RTM_NEWNEIGHTBL)]  = NDTA_MAX,
119 };
120
121 void __rta_fill(struct sk_buff *skb, int attrtype, int attrlen, const void *data)
122 {
123         struct rtattr *rta;
124         int size = RTA_LENGTH(attrlen);
125
126         rta = (struct rtattr*)skb_put(skb, RTA_ALIGN(size));
127         rta->rta_type = attrtype;
128         rta->rta_len = size;
129         memcpy(RTA_DATA(rta), data, attrlen);
130         memset(RTA_DATA(rta) + attrlen, 0, RTA_ALIGN(size) - size);
131 }
132
133 size_t rtattr_strlcpy(char *dest, const struct rtattr *rta, size_t size)
134 {
135         size_t ret = RTA_PAYLOAD(rta);
136         char *src = RTA_DATA(rta);
137
138         if (ret > 0 && src[ret - 1] == '\0')
139                 ret--;
140         if (size > 0) {
141                 size_t len = (ret >= size) ? size - 1 : ret;
142                 memset(dest, 0, size);
143                 memcpy(dest, src, len);
144         }
145         return ret;
146 }
147
148 int rtnetlink_send(struct sk_buff *skb, u32 pid, unsigned group, int echo)
149 {
150         int err = 0;
151
152         NETLINK_CB(skb).dst_group = group;
153         if (echo)
154                 atomic_inc(&skb->users);
155         netlink_broadcast(rtnl, skb, pid, group, GFP_KERNEL);
156         if (echo)
157                 err = netlink_unicast(rtnl, skb, pid, MSG_DONTWAIT);
158         return err;
159 }
160
161 int rtnetlink_put_metrics(struct sk_buff *skb, u32 *metrics)
162 {
163         struct rtattr *mx = (struct rtattr*)skb->tail;
164         int i;
165
166         RTA_PUT(skb, RTA_METRICS, 0, NULL);
167         for (i=0; i<RTAX_MAX; i++) {
168                 if (metrics[i])
169                         RTA_PUT(skb, i+1, sizeof(u32), metrics+i);
170         }
171         mx->rta_len = skb->tail - (u8*)mx;
172         if (mx->rta_len == RTA_LENGTH(0))
173                 skb_trim(skb, (u8*)mx - skb->data);
174         return 0;
175
176 rtattr_failure:
177         skb_trim(skb, (u8*)mx - skb->data);
178         return -1;
179 }
180
181
182 static int rtnetlink_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
183                                  int type, u32 pid, u32 seq, u32 change, 
184                                  unsigned int flags)
185 {
186         struct ifinfomsg *r;
187         struct nlmsghdr  *nlh;
188         unsigned char    *b = skb->tail;
189
190         nlh = NLMSG_NEW(skb, pid, seq, type, sizeof(*r), flags);
191         r = NLMSG_DATA(nlh);
192         r->ifi_family = AF_UNSPEC;
193         r->__ifi_pad = 0;
194         r->ifi_type = dev->type;
195         r->ifi_index = dev->ifindex;
196         r->ifi_flags = dev_get_flags(dev);
197         r->ifi_change = change;
198
199         RTA_PUT(skb, IFLA_IFNAME, strlen(dev->name)+1, dev->name);
200
201         if (1) {
202                 u32 txqlen = dev->tx_queue_len;
203                 RTA_PUT(skb, IFLA_TXQLEN, sizeof(txqlen), &txqlen);
204         }
205
206         if (1) {
207                 u32 weight = dev->weight;
208                 RTA_PUT(skb, IFLA_WEIGHT, sizeof(weight), &weight);
209         }
210
211         if (1) {
212                 struct rtnl_link_ifmap map = {
213                         .mem_start   = dev->mem_start,
214                         .mem_end     = dev->mem_end,
215                         .base_addr   = dev->base_addr,
216                         .irq         = dev->irq,
217                         .dma         = dev->dma,
218                         .port        = dev->if_port,
219                 };
220                 RTA_PUT(skb, IFLA_MAP, sizeof(map), &map);
221         }
222
223         if (dev->addr_len) {
224                 RTA_PUT(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr);
225                 RTA_PUT(skb, IFLA_BROADCAST, dev->addr_len, dev->broadcast);
226         }
227
228         if (1) {
229                 u32 mtu = dev->mtu;
230                 RTA_PUT(skb, IFLA_MTU, sizeof(mtu), &mtu);
231         }
232
233         if (dev->ifindex != dev->iflink) {
234                 u32 iflink = dev->iflink;
235                 RTA_PUT(skb, IFLA_LINK, sizeof(iflink), &iflink);
236         }
237
238         if (dev->qdisc_sleeping)
239                 RTA_PUT(skb, IFLA_QDISC,
240                         strlen(dev->qdisc_sleeping->ops->id) + 1,
241                         dev->qdisc_sleeping->ops->id);
242         
243         if (dev->master) {
244                 u32 master = dev->master->ifindex;
245                 RTA_PUT(skb, IFLA_MASTER, sizeof(master), &master);
246         }
247
248         if (dev->get_stats) {
249                 unsigned long *stats = (unsigned long*)dev->get_stats(dev);
250                 if (stats) {
251                         struct rtattr  *a;
252                         __u32          *s;
253                         int             i;
254                         int             n = sizeof(struct rtnl_link_stats)/4;
255
256                         a = __RTA_PUT(skb, IFLA_STATS, n*4);
257                         s = RTA_DATA(a);
258                         for (i=0; i<n; i++)
259                                 s[i] = stats[i];
260                 }
261         }
262         nlh->nlmsg_len = skb->tail - b;
263         return skb->len;
264
265 nlmsg_failure:
266 rtattr_failure:
267         skb_trim(skb, b - skb->data);
268         return -1;
269 }
270
271 static int rtnetlink_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
272 {
273         int idx;
274         int s_idx = cb->args[0];
275         struct net_device *dev;
276
277         read_lock(&dev_base_lock);
278         for (dev=dev_base, idx=0; dev; dev = dev->next, idx++) {
279                 if (idx < s_idx)
280                         continue;
281                 if (vx_info_flags(skb->sk->sk_vx_info, VXF_HIDE_NETIF, 0) &&
282                         !dev_in_nx_info(dev, skb->sk->sk_nx_info))
283                         continue;
284                 if (rtnetlink_fill_ifinfo(skb, dev, RTM_NEWLINK,
285                                           NETLINK_CB(cb->skb).pid,
286                                           cb->nlh->nlmsg_seq, 0,
287                                           NLM_F_MULTI) <= 0)
288                         break;
289         }
290         read_unlock(&dev_base_lock);
291         cb->args[0] = idx;
292
293         return skb->len;
294 }
295
296 static int do_setlink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
297 {
298         struct ifinfomsg  *ifm = NLMSG_DATA(nlh);
299         struct rtattr    **ida = arg;
300         struct net_device *dev;
301         int err, send_addr_notify = 0;
302
303         if (ifm->ifi_index >= 0)
304                 dev = dev_get_by_index(ifm->ifi_index);
305         else if (ida[IFLA_IFNAME - 1]) {
306                 char ifname[IFNAMSIZ];
307
308                 if (rtattr_strlcpy(ifname, ida[IFLA_IFNAME - 1],
309                                    IFNAMSIZ) >= IFNAMSIZ)
310                         return -EINVAL;
311                 dev = dev_get_by_name(ifname);
312         } else
313                 return -EINVAL;
314
315         if (!dev)
316                 return -ENODEV;
317
318         err = -EINVAL;
319
320         if (ifm->ifi_flags)
321                 dev_change_flags(dev, ifm->ifi_flags);
322
323         if (ida[IFLA_MAP - 1]) {
324                 struct rtnl_link_ifmap *u_map;
325                 struct ifmap k_map;
326
327                 if (!dev->set_config) {
328                         err = -EOPNOTSUPP;
329                         goto out;
330                 }
331
332                 if (!netif_device_present(dev)) {
333                         err = -ENODEV;
334                         goto out;
335                 }
336                 
337                 if (ida[IFLA_MAP - 1]->rta_len != RTA_LENGTH(sizeof(*u_map)))
338                         goto out;
339
340                 u_map = RTA_DATA(ida[IFLA_MAP - 1]);
341
342                 k_map.mem_start = (unsigned long) u_map->mem_start;
343                 k_map.mem_end = (unsigned long) u_map->mem_end;
344                 k_map.base_addr = (unsigned short) u_map->base_addr;
345                 k_map.irq = (unsigned char) u_map->irq;
346                 k_map.dma = (unsigned char) u_map->dma;
347                 k_map.port = (unsigned char) u_map->port;
348
349                 err = dev->set_config(dev, &k_map);
350
351                 if (err)
352                         goto out;
353         }
354
355         if (ida[IFLA_ADDRESS - 1]) {
356                 struct sockaddr *sa;
357                 int len;
358
359                 if (!dev->set_mac_address) {
360                         err = -EOPNOTSUPP;
361                         goto out;
362                 }
363                 if (!netif_device_present(dev)) {
364                         err = -ENODEV;
365                         goto out;
366                 }
367                 if (ida[IFLA_ADDRESS - 1]->rta_len != RTA_LENGTH(dev->addr_len))
368                         goto out;
369
370                 len = sizeof(sa_family_t) + dev->addr_len;
371                 sa = kmalloc(len, GFP_KERNEL);
372                 if (!sa) {
373                         err = -ENOMEM;
374                         goto out;
375                 }
376                 sa->sa_family = dev->type;
377                 memcpy(sa->sa_data, RTA_DATA(ida[IFLA_ADDRESS - 1]),
378                        dev->addr_len);
379                 err = dev->set_mac_address(dev, sa);
380                 kfree(sa);
381                 if (err)
382                         goto out;
383                 send_addr_notify = 1;
384         }
385
386         if (ida[IFLA_BROADCAST - 1]) {
387                 if (ida[IFLA_BROADCAST - 1]->rta_len != RTA_LENGTH(dev->addr_len))
388                         goto out;
389                 memcpy(dev->broadcast, RTA_DATA(ida[IFLA_BROADCAST - 1]),
390                        dev->addr_len);
391                 send_addr_notify = 1;
392         }
393
394         if (ida[IFLA_MTU - 1]) {
395                 if (ida[IFLA_MTU - 1]->rta_len != RTA_LENGTH(sizeof(u32)))
396                         goto out;
397                 err = dev_set_mtu(dev, *((u32 *) RTA_DATA(ida[IFLA_MTU - 1])));
398
399                 if (err)
400                         goto out;
401
402         }
403
404         if (ida[IFLA_TXQLEN - 1]) {
405                 if (ida[IFLA_TXQLEN - 1]->rta_len != RTA_LENGTH(sizeof(u32)))
406                         goto out;
407
408                 dev->tx_queue_len = *((u32 *) RTA_DATA(ida[IFLA_TXQLEN - 1]));
409         }
410
411         if (ida[IFLA_WEIGHT - 1]) {
412                 if (ida[IFLA_WEIGHT - 1]->rta_len != RTA_LENGTH(sizeof(u32)))
413                         goto out;
414
415                 dev->weight = *((u32 *) RTA_DATA(ida[IFLA_WEIGHT - 1]));
416         }
417
418         if (ifm->ifi_index >= 0 && ida[IFLA_IFNAME - 1]) {
419                 char ifname[IFNAMSIZ];
420
421                 if (rtattr_strlcpy(ifname, ida[IFLA_IFNAME - 1],
422                                    IFNAMSIZ) >= IFNAMSIZ)
423                         goto out;
424                 err = dev_change_name(dev, ifname);
425                 if (err)
426                         goto out;
427         }
428
429         err = 0;
430
431 out:
432         if (send_addr_notify)
433                 call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
434
435         dev_put(dev);
436         return err;
437 }
438
439 static int rtnetlink_dump_all(struct sk_buff *skb, struct netlink_callback *cb)
440 {
441         int idx;
442         int s_idx = cb->family;
443
444         if (s_idx == 0)
445                 s_idx = 1;
446         for (idx=1; idx<NPROTO; idx++) {
447                 int type = cb->nlh->nlmsg_type-RTM_BASE;
448                 if (idx < s_idx || idx == PF_PACKET)
449                         continue;
450                 if (rtnetlink_links[idx] == NULL ||
451                     rtnetlink_links[idx][type].dumpit == NULL)
452                         continue;
453                 if (idx > s_idx)
454                         memset(&cb->args[0], 0, sizeof(cb->args));
455                 if (rtnetlink_links[idx][type].dumpit(skb, cb))
456                         break;
457         }
458         cb->family = idx;
459
460         return skb->len;
461 }
462
463 void rtmsg_ifinfo(int type, struct net_device *dev, unsigned change)
464 {
465         struct sk_buff *skb;
466         int size = NLMSG_SPACE(sizeof(struct ifinfomsg) +
467                                sizeof(struct rtnl_link_ifmap) +
468                                sizeof(struct rtnl_link_stats) + 128);
469
470         if (vx_flags(VXF_HIDE_NETIF, 0) &&
471                 !dev_in_nx_info(dev, current->nx_info))
472                 return;
473         skb = alloc_skb(size, GFP_KERNEL);
474         if (!skb)
475                 return;
476
477         if (rtnetlink_fill_ifinfo(skb, dev, type, 0, 0, change, 0) < 0) {
478                 kfree_skb(skb);
479                 return;
480         }
481         NETLINK_CB(skb).dst_group = RTNLGRP_LINK;
482         netlink_broadcast(rtnl, skb, 0, RTNLGRP_LINK, GFP_KERNEL);
483 }
484
485 /* Protected by RTNL sempahore.  */
486 static struct rtattr **rta_buf;
487 static int rtattr_max;
488
489 /* Process one rtnetlink message. */
490
491 static __inline__ int
492 rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, int *errp)
493 {
494         struct rtnetlink_link *link;
495         struct rtnetlink_link *link_tab;
496         int sz_idx, kind;
497         int min_len;
498         int family;
499         int type;
500         int err;
501
502         /* Only requests are handled by kernel now */
503         if (!(nlh->nlmsg_flags&NLM_F_REQUEST))
504                 return 0;
505
506         type = nlh->nlmsg_type;
507
508         /* A control message: ignore them */
509         if (type < RTM_BASE)
510                 return 0;
511
512         /* Unknown message: reply with EINVAL */
513         if (type > RTM_MAX)
514                 goto err_inval;
515
516         type -= RTM_BASE;
517
518         /* All the messages must have at least 1 byte length */
519         if (nlh->nlmsg_len < NLMSG_LENGTH(sizeof(struct rtgenmsg)))
520                 return 0;
521
522         family = ((struct rtgenmsg*)NLMSG_DATA(nlh))->rtgen_family;
523         if (family >= NPROTO) {
524                 *errp = -EAFNOSUPPORT;
525                 return -1;
526         }
527
528         link_tab = rtnetlink_links[family];
529         if (link_tab == NULL)
530                 link_tab = rtnetlink_links[PF_UNSPEC];
531         link = &link_tab[type];
532
533         sz_idx = type>>2;
534         kind = type&3;
535
536         if (kind != 2 && security_netlink_recv(skb)) {
537                 *errp = -EPERM;
538                 return -1;
539         }
540
541         if (kind == 2 && nlh->nlmsg_flags&NLM_F_DUMP) {
542                 if (link->dumpit == NULL)
543                         link = &(rtnetlink_links[PF_UNSPEC][type]);
544
545                 if (link->dumpit == NULL)
546                         goto err_inval;
547
548                 if ((*errp = netlink_dump_start(rtnl, skb, nlh,
549                                                 link->dumpit, NULL)) != 0) {
550                         return -1;
551                 }
552
553                 netlink_queue_skip(nlh, skb);
554                 return -1;
555         }
556
557         memset(rta_buf, 0, (rtattr_max * sizeof(struct rtattr *)));
558
559         min_len = rtm_min[sz_idx];
560         if (nlh->nlmsg_len < min_len)
561                 goto err_inval;
562
563         if (nlh->nlmsg_len > min_len) {
564                 int attrlen = nlh->nlmsg_len - NLMSG_ALIGN(min_len);
565                 struct rtattr *attr = (void*)nlh + NLMSG_ALIGN(min_len);
566
567                 while (RTA_OK(attr, attrlen)) {
568                         unsigned flavor = attr->rta_type;
569                         if (flavor) {
570                                 if (flavor > rta_max[sz_idx])
571                                         goto err_inval;
572                                 rta_buf[flavor-1] = attr;
573                         }
574                         attr = RTA_NEXT(attr, attrlen);
575                 }
576         }
577
578         if (link->doit == NULL)
579                 link = &(rtnetlink_links[PF_UNSPEC][type]);
580         if (link->doit == NULL)
581                 goto err_inval;
582         err = link->doit(skb, nlh, (void *)&rta_buf[0]);
583
584         *errp = err;
585         return err;
586
587 err_inval:
588         *errp = -EINVAL;
589         return -1;
590 }
591
592 static void rtnetlink_rcv(struct sock *sk, int len)
593 {
594         unsigned int qlen = 0;
595
596         do {
597                 rtnl_lock();
598                 netlink_run_queue(sk, &qlen, &rtnetlink_rcv_msg);
599                 up(&rtnl_sem);
600
601                 netdev_run_todo();
602         } while (qlen);
603 }
604
605 static struct rtnetlink_link link_rtnetlink_table[RTM_NR_MSGTYPES] =
606 {
607         [RTM_GETLINK     - RTM_BASE] = { .dumpit = rtnetlink_dump_ifinfo },
608         [RTM_SETLINK     - RTM_BASE] = { .doit   = do_setlink            },
609         [RTM_GETADDR     - RTM_BASE] = { .dumpit = rtnetlink_dump_all    },
610         [RTM_GETROUTE    - RTM_BASE] = { .dumpit = rtnetlink_dump_all    },
611         [RTM_NEWNEIGH    - RTM_BASE] = { .doit   = neigh_add             },
612         [RTM_DELNEIGH    - RTM_BASE] = { .doit   = neigh_delete          },
613         [RTM_GETNEIGH    - RTM_BASE] = { .dumpit = neigh_dump_info       },
614         [RTM_GETRULE     - RTM_BASE] = { .dumpit = rtnetlink_dump_all    },
615         [RTM_GETNEIGHTBL - RTM_BASE] = { .dumpit = neightbl_dump_info    },
616         [RTM_SETNEIGHTBL - RTM_BASE] = { .doit   = neightbl_set          },
617 };
618
619 static int rtnetlink_event(struct notifier_block *this, unsigned long event, void *ptr)
620 {
621         struct net_device *dev = ptr;
622         switch (event) {
623         case NETDEV_UNREGISTER:
624                 rtmsg_ifinfo(RTM_DELLINK, dev, ~0U);
625                 break;
626         case NETDEV_REGISTER:
627                 rtmsg_ifinfo(RTM_NEWLINK, dev, ~0U);
628                 break;
629         case NETDEV_UP:
630         case NETDEV_DOWN:
631                 rtmsg_ifinfo(RTM_NEWLINK, dev, IFF_UP|IFF_RUNNING);
632                 break;
633         case NETDEV_CHANGE:
634         case NETDEV_GOING_DOWN:
635                 break;
636         default:
637                 rtmsg_ifinfo(RTM_NEWLINK, dev, 0);
638                 break;
639         }
640         return NOTIFY_DONE;
641 }
642
643 static struct notifier_block rtnetlink_dev_notifier = {
644         .notifier_call  = rtnetlink_event,
645 };
646
647 void __init rtnetlink_init(void)
648 {
649         int i;
650
651         rtattr_max = 0;
652         for (i = 0; i < ARRAY_SIZE(rta_max); i++)
653                 if (rta_max[i] > rtattr_max)
654                         rtattr_max = rta_max[i];
655         rta_buf = kmalloc(rtattr_max * sizeof(struct rtattr *), GFP_KERNEL);
656         if (!rta_buf)
657                 panic("rtnetlink_init: cannot allocate rta_buf\n");
658
659         rtnl = netlink_kernel_create(NETLINK_ROUTE, RTNLGRP_MAX, rtnetlink_rcv,
660                                      THIS_MODULE);
661         if (rtnl == NULL)
662                 panic("rtnetlink_init: cannot initialize rtnetlink\n");
663         netlink_set_nonroot(NETLINK_ROUTE, NL_NONROOT_RECV);
664         register_netdevice_notifier(&rtnetlink_dev_notifier);
665         rtnetlink_links[PF_UNSPEC] = link_rtnetlink_table;
666         rtnetlink_links[PF_PACKET] = link_rtnetlink_table;
667 }
668
669 EXPORT_SYMBOL(__rta_fill);
670 EXPORT_SYMBOL(rtattr_strlcpy);
671 EXPORT_SYMBOL(rtattr_parse);
672 EXPORT_SYMBOL(rtnetlink_links);
673 EXPORT_SYMBOL(rtnetlink_put_metrics);
674 EXPORT_SYMBOL(rtnl);
675 EXPORT_SYMBOL(rtnl_lock);
676 EXPORT_SYMBOL(rtnl_lock_interruptible);
677 EXPORT_SYMBOL(rtnl_sem);
678 EXPORT_SYMBOL(rtnl_unlock);