[RTNETLINK]: Add nested compat attribute
[safe/jmp/linux-2.6] / 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/errno.h>
20 #include <linux/module.h>
21 #include <linux/types.h>
22 #include <linux/socket.h>
23 #include <linux/kernel.h>
24 #include <linux/timer.h>
25 #include <linux/string.h>
26 #include <linux/sockios.h>
27 #include <linux/net.h>
28 #include <linux/fcntl.h>
29 #include <linux/mm.h>
30 #include <linux/slab.h>
31 #include <linux/interrupt.h>
32 #include <linux/capability.h>
33 #include <linux/skbuff.h>
34 #include <linux/init.h>
35 #include <linux/security.h>
36 #include <linux/mutex.h>
37 #include <linux/if_addr.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/fib_rules.h>
53 #include <net/rtnetlink.h>
54
55 struct rtnl_link
56 {
57         rtnl_doit_func          doit;
58         rtnl_dumpit_func        dumpit;
59 };
60
61 static DEFINE_MUTEX(rtnl_mutex);
62 static struct sock *rtnl;
63
64 void rtnl_lock(void)
65 {
66         mutex_lock(&rtnl_mutex);
67 }
68
69 void __rtnl_unlock(void)
70 {
71         mutex_unlock(&rtnl_mutex);
72 }
73
74 void rtnl_unlock(void)
75 {
76         mutex_unlock(&rtnl_mutex);
77         if (rtnl && rtnl->sk_receive_queue.qlen)
78                 rtnl->sk_data_ready(rtnl, 0);
79         netdev_run_todo();
80 }
81
82 int rtnl_trylock(void)
83 {
84         return mutex_trylock(&rtnl_mutex);
85 }
86
87 int rtattr_parse(struct rtattr *tb[], int maxattr, struct rtattr *rta, int len)
88 {
89         memset(tb, 0, sizeof(struct rtattr*)*maxattr);
90
91         while (RTA_OK(rta, len)) {
92                 unsigned flavor = rta->rta_type;
93                 if (flavor && flavor <= maxattr)
94                         tb[flavor-1] = rta;
95                 rta = RTA_NEXT(rta, len);
96         }
97         return 0;
98 }
99
100 int rtattr_parse_nested_compat(struct rtattr *tb[], int maxattr,
101                                struct rtattr *rta, void **data, int len)
102 {
103         if (RTA_PAYLOAD(rta) < len)
104                 return -1;
105         *data = RTA_DATA(rta);
106
107         if (RTA_PAYLOAD(rta) >= RTA_ALIGN(len) + sizeof(struct rtattr)) {
108                 rta = RTA_DATA(rta) + RTA_ALIGN(len);
109                 return rtattr_parse_nested(tb, maxattr, rta);
110         }
111         memset(tb, 0, sizeof(struct rtattr *) * maxattr);
112         return 0;
113 }
114
115 static struct rtnl_link *rtnl_msg_handlers[NPROTO];
116
117 static inline int rtm_msgindex(int msgtype)
118 {
119         int msgindex = msgtype - RTM_BASE;
120
121         /*
122          * msgindex < 0 implies someone tried to register a netlink
123          * control code. msgindex >= RTM_NR_MSGTYPES may indicate that
124          * the message type has not been added to linux/rtnetlink.h
125          */
126         BUG_ON(msgindex < 0 || msgindex >= RTM_NR_MSGTYPES);
127
128         return msgindex;
129 }
130
131 static rtnl_doit_func rtnl_get_doit(int protocol, int msgindex)
132 {
133         struct rtnl_link *tab;
134
135         tab = rtnl_msg_handlers[protocol];
136         if (tab == NULL || tab[msgindex].doit == NULL)
137                 tab = rtnl_msg_handlers[PF_UNSPEC];
138
139         return tab ? tab[msgindex].doit : NULL;
140 }
141
142 static rtnl_dumpit_func rtnl_get_dumpit(int protocol, int msgindex)
143 {
144         struct rtnl_link *tab;
145
146         tab = rtnl_msg_handlers[protocol];
147         if (tab == NULL || tab[msgindex].dumpit == NULL)
148                 tab = rtnl_msg_handlers[PF_UNSPEC];
149
150         return tab ? tab[msgindex].dumpit : NULL;
151 }
152
153 /**
154  * __rtnl_register - Register a rtnetlink message type
155  * @protocol: Protocol family or PF_UNSPEC
156  * @msgtype: rtnetlink message type
157  * @doit: Function pointer called for each request message
158  * @dumpit: Function pointer called for each dump request (NLM_F_DUMP) message
159  *
160  * Registers the specified function pointers (at least one of them has
161  * to be non-NULL) to be called whenever a request message for the
162  * specified protocol family and message type is received.
163  *
164  * The special protocol family PF_UNSPEC may be used to define fallback
165  * function pointers for the case when no entry for the specific protocol
166  * family exists.
167  *
168  * Returns 0 on success or a negative error code.
169  */
170 int __rtnl_register(int protocol, int msgtype,
171                     rtnl_doit_func doit, rtnl_dumpit_func dumpit)
172 {
173         struct rtnl_link *tab;
174         int msgindex;
175
176         BUG_ON(protocol < 0 || protocol >= NPROTO);
177         msgindex = rtm_msgindex(msgtype);
178
179         tab = rtnl_msg_handlers[protocol];
180         if (tab == NULL) {
181                 tab = kcalloc(RTM_NR_MSGTYPES, sizeof(*tab), GFP_KERNEL);
182                 if (tab == NULL)
183                         return -ENOBUFS;
184
185                 rtnl_msg_handlers[protocol] = tab;
186         }
187
188         if (doit)
189                 tab[msgindex].doit = doit;
190
191         if (dumpit)
192                 tab[msgindex].dumpit = dumpit;
193
194         return 0;
195 }
196
197 EXPORT_SYMBOL_GPL(__rtnl_register);
198
199 /**
200  * rtnl_register - Register a rtnetlink message type
201  *
202  * Identical to __rtnl_register() but panics on failure. This is useful
203  * as failure of this function is very unlikely, it can only happen due
204  * to lack of memory when allocating the chain to store all message
205  * handlers for a protocol. Meant for use in init functions where lack
206  * of memory implies no sense in continueing.
207  */
208 void rtnl_register(int protocol, int msgtype,
209                    rtnl_doit_func doit, rtnl_dumpit_func dumpit)
210 {
211         if (__rtnl_register(protocol, msgtype, doit, dumpit) < 0)
212                 panic("Unable to register rtnetlink message handler, "
213                       "protocol = %d, message type = %d\n",
214                       protocol, msgtype);
215 }
216
217 EXPORT_SYMBOL_GPL(rtnl_register);
218
219 /**
220  * rtnl_unregister - Unregister a rtnetlink message type
221  * @protocol: Protocol family or PF_UNSPEC
222  * @msgtype: rtnetlink message type
223  *
224  * Returns 0 on success or a negative error code.
225  */
226 int rtnl_unregister(int protocol, int msgtype)
227 {
228         int msgindex;
229
230         BUG_ON(protocol < 0 || protocol >= NPROTO);
231         msgindex = rtm_msgindex(msgtype);
232
233         if (rtnl_msg_handlers[protocol] == NULL)
234                 return -ENOENT;
235
236         rtnl_msg_handlers[protocol][msgindex].doit = NULL;
237         rtnl_msg_handlers[protocol][msgindex].dumpit = NULL;
238
239         return 0;
240 }
241
242 EXPORT_SYMBOL_GPL(rtnl_unregister);
243
244 /**
245  * rtnl_unregister_all - Unregister all rtnetlink message type of a protocol
246  * @protocol : Protocol family or PF_UNSPEC
247  *
248  * Identical to calling rtnl_unregster() for all registered message types
249  * of a certain protocol family.
250  */
251 void rtnl_unregister_all(int protocol)
252 {
253         BUG_ON(protocol < 0 || protocol >= NPROTO);
254
255         kfree(rtnl_msg_handlers[protocol]);
256         rtnl_msg_handlers[protocol] = NULL;
257 }
258
259 EXPORT_SYMBOL_GPL(rtnl_unregister_all);
260
261 static LIST_HEAD(link_ops);
262
263 /**
264  * __rtnl_link_register - Register rtnl_link_ops with rtnetlink.
265  * @ops: struct rtnl_link_ops * to register
266  *
267  * The caller must hold the rtnl_mutex. This function should be used
268  * by drivers that create devices during module initialization. It
269  * must be called before registering the devices.
270  *
271  * Returns 0 on success or a negative error code.
272  */
273 int __rtnl_link_register(struct rtnl_link_ops *ops)
274 {
275         list_add_tail(&ops->list, &link_ops);
276         return 0;
277 }
278
279 EXPORT_SYMBOL_GPL(__rtnl_link_register);
280
281 /**
282  * rtnl_link_register - Register rtnl_link_ops with rtnetlink.
283  * @ops: struct rtnl_link_ops * to register
284  *
285  * Returns 0 on success or a negative error code.
286  */
287 int rtnl_link_register(struct rtnl_link_ops *ops)
288 {
289         int err;
290
291         rtnl_lock();
292         err = __rtnl_link_register(ops);
293         rtnl_unlock();
294         return err;
295 }
296
297 EXPORT_SYMBOL_GPL(rtnl_link_register);
298
299 /**
300  * __rtnl_link_unregister - Unregister rtnl_link_ops from rtnetlink.
301  * @ops: struct rtnl_link_ops * to unregister
302  *
303  * The caller must hold the rtnl_mutex. This function should be used
304  * by drivers that unregister devices during module unloading. It must
305  * be called after unregistering the devices.
306  */
307 void __rtnl_link_unregister(struct rtnl_link_ops *ops)
308 {
309         list_del(&ops->list);
310 }
311
312 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
313
314 /**
315  * rtnl_link_unregister - Unregister rtnl_link_ops from rtnetlink.
316  * @ops: struct rtnl_link_ops * to unregister
317  */
318 void rtnl_link_unregister(struct rtnl_link_ops *ops)
319 {
320         rtnl_lock();
321         __rtnl_link_unregister(ops);
322         rtnl_unlock();
323 }
324
325 EXPORT_SYMBOL_GPL(rtnl_link_unregister);
326
327 static const struct rtnl_link_ops *rtnl_link_ops_get(const char *kind)
328 {
329         const struct rtnl_link_ops *ops;
330
331         list_for_each_entry(ops, &link_ops, list) {
332                 if (!strcmp(ops->kind, kind))
333                         return ops;
334         }
335         return NULL;
336 }
337
338 static size_t rtnl_link_get_size(const struct net_device *dev)
339 {
340         const struct rtnl_link_ops *ops = dev->rtnl_link_ops;
341         size_t size;
342
343         if (!ops)
344                 return 0;
345
346         size = nlmsg_total_size(sizeof(struct nlattr)) + /* IFLA_LINKINFO */
347                nlmsg_total_size(strlen(ops->kind) + 1);  /* IFLA_INFO_KIND */
348
349         if (ops->get_size)
350                 /* IFLA_INFO_DATA + nested data */
351                 size += nlmsg_total_size(sizeof(struct nlattr)) +
352                         ops->get_size(dev);
353
354         if (ops->get_xstats_size)
355                 size += ops->get_xstats_size(dev);      /* IFLA_INFO_XSTATS */
356
357         return size;
358 }
359
360 static int rtnl_link_fill(struct sk_buff *skb, const struct net_device *dev)
361 {
362         const struct rtnl_link_ops *ops = dev->rtnl_link_ops;
363         struct nlattr *linkinfo, *data;
364         int err = -EMSGSIZE;
365
366         linkinfo = nla_nest_start(skb, IFLA_LINKINFO);
367         if (linkinfo == NULL)
368                 goto out;
369
370         if (nla_put_string(skb, IFLA_INFO_KIND, ops->kind) < 0)
371                 goto err_cancel_link;
372         if (ops->fill_xstats) {
373                 err = ops->fill_xstats(skb, dev);
374                 if (err < 0)
375                         goto err_cancel_link;
376         }
377         if (ops->fill_info) {
378                 data = nla_nest_start(skb, IFLA_INFO_DATA);
379                 if (data == NULL)
380                         goto err_cancel_link;
381                 err = ops->fill_info(skb, dev);
382                 if (err < 0)
383                         goto err_cancel_data;
384                 nla_nest_end(skb, data);
385         }
386
387         nla_nest_end(skb, linkinfo);
388         return 0;
389
390 err_cancel_data:
391         nla_nest_cancel(skb, data);
392 err_cancel_link:
393         nla_nest_cancel(skb, linkinfo);
394 out:
395         return err;
396 }
397
398 static const int rtm_min[RTM_NR_FAMILIES] =
399 {
400         [RTM_FAM(RTM_NEWLINK)]      = NLMSG_LENGTH(sizeof(struct ifinfomsg)),
401         [RTM_FAM(RTM_NEWADDR)]      = NLMSG_LENGTH(sizeof(struct ifaddrmsg)),
402         [RTM_FAM(RTM_NEWROUTE)]     = NLMSG_LENGTH(sizeof(struct rtmsg)),
403         [RTM_FAM(RTM_NEWRULE)]      = NLMSG_LENGTH(sizeof(struct fib_rule_hdr)),
404         [RTM_FAM(RTM_NEWQDISC)]     = NLMSG_LENGTH(sizeof(struct tcmsg)),
405         [RTM_FAM(RTM_NEWTCLASS)]    = NLMSG_LENGTH(sizeof(struct tcmsg)),
406         [RTM_FAM(RTM_NEWTFILTER)]   = NLMSG_LENGTH(sizeof(struct tcmsg)),
407         [RTM_FAM(RTM_NEWACTION)]    = NLMSG_LENGTH(sizeof(struct tcamsg)),
408         [RTM_FAM(RTM_GETMULTICAST)] = NLMSG_LENGTH(sizeof(struct rtgenmsg)),
409         [RTM_FAM(RTM_GETANYCAST)]   = NLMSG_LENGTH(sizeof(struct rtgenmsg)),
410 };
411
412 static const int rta_max[RTM_NR_FAMILIES] =
413 {
414         [RTM_FAM(RTM_NEWLINK)]      = IFLA_MAX,
415         [RTM_FAM(RTM_NEWADDR)]      = IFA_MAX,
416         [RTM_FAM(RTM_NEWROUTE)]     = RTA_MAX,
417         [RTM_FAM(RTM_NEWRULE)]      = FRA_MAX,
418         [RTM_FAM(RTM_NEWQDISC)]     = TCA_MAX,
419         [RTM_FAM(RTM_NEWTCLASS)]    = TCA_MAX,
420         [RTM_FAM(RTM_NEWTFILTER)]   = TCA_MAX,
421         [RTM_FAM(RTM_NEWACTION)]    = TCAA_MAX,
422 };
423
424 void __rta_fill(struct sk_buff *skb, int attrtype, int attrlen, const void *data)
425 {
426         struct rtattr *rta;
427         int size = RTA_LENGTH(attrlen);
428
429         rta = (struct rtattr*)skb_put(skb, RTA_ALIGN(size));
430         rta->rta_type = attrtype;
431         rta->rta_len = size;
432         memcpy(RTA_DATA(rta), data, attrlen);
433         memset(RTA_DATA(rta) + attrlen, 0, RTA_ALIGN(size) - size);
434 }
435
436 size_t rtattr_strlcpy(char *dest, const struct rtattr *rta, size_t size)
437 {
438         size_t ret = RTA_PAYLOAD(rta);
439         char *src = RTA_DATA(rta);
440
441         if (ret > 0 && src[ret - 1] == '\0')
442                 ret--;
443         if (size > 0) {
444                 size_t len = (ret >= size) ? size - 1 : ret;
445                 memset(dest, 0, size);
446                 memcpy(dest, src, len);
447         }
448         return ret;
449 }
450
451 int rtnetlink_send(struct sk_buff *skb, u32 pid, unsigned group, int echo)
452 {
453         int err = 0;
454
455         NETLINK_CB(skb).dst_group = group;
456         if (echo)
457                 atomic_inc(&skb->users);
458         netlink_broadcast(rtnl, skb, pid, group, GFP_KERNEL);
459         if (echo)
460                 err = netlink_unicast(rtnl, skb, pid, MSG_DONTWAIT);
461         return err;
462 }
463
464 int rtnl_unicast(struct sk_buff *skb, u32 pid)
465 {
466         return nlmsg_unicast(rtnl, skb, pid);
467 }
468
469 int rtnl_notify(struct sk_buff *skb, u32 pid, u32 group,
470                 struct nlmsghdr *nlh, gfp_t flags)
471 {
472         int report = 0;
473
474         if (nlh)
475                 report = nlmsg_report(nlh);
476
477         return nlmsg_notify(rtnl, skb, pid, group, report, flags);
478 }
479
480 void rtnl_set_sk_err(u32 group, int error)
481 {
482         netlink_set_err(rtnl, 0, group, error);
483 }
484
485 int rtnetlink_put_metrics(struct sk_buff *skb, u32 *metrics)
486 {
487         struct nlattr *mx;
488         int i, valid = 0;
489
490         mx = nla_nest_start(skb, RTA_METRICS);
491         if (mx == NULL)
492                 return -ENOBUFS;
493
494         for (i = 0; i < RTAX_MAX; i++) {
495                 if (metrics[i]) {
496                         valid++;
497                         NLA_PUT_U32(skb, i+1, metrics[i]);
498                 }
499         }
500
501         if (!valid) {
502                 nla_nest_cancel(skb, mx);
503                 return 0;
504         }
505
506         return nla_nest_end(skb, mx);
507
508 nla_put_failure:
509         return nla_nest_cancel(skb, mx);
510 }
511
512 int rtnl_put_cacheinfo(struct sk_buff *skb, struct dst_entry *dst, u32 id,
513                        u32 ts, u32 tsage, long expires, u32 error)
514 {
515         struct rta_cacheinfo ci = {
516                 .rta_lastuse = jiffies_to_clock_t(jiffies - dst->lastuse),
517                 .rta_used = dst->__use,
518                 .rta_clntref = atomic_read(&(dst->__refcnt)),
519                 .rta_error = error,
520                 .rta_id =  id,
521                 .rta_ts = ts,
522                 .rta_tsage = tsage,
523         };
524
525         if (expires)
526                 ci.rta_expires = jiffies_to_clock_t(expires);
527
528         return nla_put(skb, RTA_CACHEINFO, sizeof(ci), &ci);
529 }
530
531 EXPORT_SYMBOL_GPL(rtnl_put_cacheinfo);
532
533 static void set_operstate(struct net_device *dev, unsigned char transition)
534 {
535         unsigned char operstate = dev->operstate;
536
537         switch(transition) {
538         case IF_OPER_UP:
539                 if ((operstate == IF_OPER_DORMANT ||
540                      operstate == IF_OPER_UNKNOWN) &&
541                     !netif_dormant(dev))
542                         operstate = IF_OPER_UP;
543                 break;
544
545         case IF_OPER_DORMANT:
546                 if (operstate == IF_OPER_UP ||
547                     operstate == IF_OPER_UNKNOWN)
548                         operstate = IF_OPER_DORMANT;
549                 break;
550         }
551
552         if (dev->operstate != operstate) {
553                 write_lock_bh(&dev_base_lock);
554                 dev->operstate = operstate;
555                 write_unlock_bh(&dev_base_lock);
556                 netdev_state_change(dev);
557         }
558 }
559
560 static void copy_rtnl_link_stats(struct rtnl_link_stats *a,
561                                  struct net_device_stats *b)
562 {
563         a->rx_packets = b->rx_packets;
564         a->tx_packets = b->tx_packets;
565         a->rx_bytes = b->rx_bytes;
566         a->tx_bytes = b->tx_bytes;
567         a->rx_errors = b->rx_errors;
568         a->tx_errors = b->tx_errors;
569         a->rx_dropped = b->rx_dropped;
570         a->tx_dropped = b->tx_dropped;
571
572         a->multicast = b->multicast;
573         a->collisions = b->collisions;
574
575         a->rx_length_errors = b->rx_length_errors;
576         a->rx_over_errors = b->rx_over_errors;
577         a->rx_crc_errors = b->rx_crc_errors;
578         a->rx_frame_errors = b->rx_frame_errors;
579         a->rx_fifo_errors = b->rx_fifo_errors;
580         a->rx_missed_errors = b->rx_missed_errors;
581
582         a->tx_aborted_errors = b->tx_aborted_errors;
583         a->tx_carrier_errors = b->tx_carrier_errors;
584         a->tx_fifo_errors = b->tx_fifo_errors;
585         a->tx_heartbeat_errors = b->tx_heartbeat_errors;
586         a->tx_window_errors = b->tx_window_errors;
587
588         a->rx_compressed = b->rx_compressed;
589         a->tx_compressed = b->tx_compressed;
590 };
591
592 static inline size_t if_nlmsg_size(const struct net_device *dev)
593 {
594         return NLMSG_ALIGN(sizeof(struct ifinfomsg))
595                + nla_total_size(IFNAMSIZ) /* IFLA_IFNAME */
596                + nla_total_size(IFNAMSIZ) /* IFLA_QDISC */
597                + nla_total_size(sizeof(struct rtnl_link_ifmap))
598                + nla_total_size(sizeof(struct rtnl_link_stats))
599                + nla_total_size(MAX_ADDR_LEN) /* IFLA_ADDRESS */
600                + nla_total_size(MAX_ADDR_LEN) /* IFLA_BROADCAST */
601                + nla_total_size(4) /* IFLA_TXQLEN */
602                + nla_total_size(4) /* IFLA_WEIGHT */
603                + nla_total_size(4) /* IFLA_MTU */
604                + nla_total_size(4) /* IFLA_LINK */
605                + nla_total_size(4) /* IFLA_MASTER */
606                + nla_total_size(1) /* IFLA_OPERSTATE */
607                + nla_total_size(1) /* IFLA_LINKMODE */
608                + rtnl_link_get_size(dev); /* IFLA_LINKINFO */
609 }
610
611 static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
612                             int type, u32 pid, u32 seq, u32 change,
613                             unsigned int flags)
614 {
615         struct ifinfomsg *ifm;
616         struct nlmsghdr *nlh;
617
618         nlh = nlmsg_put(skb, pid, seq, type, sizeof(*ifm), flags);
619         if (nlh == NULL)
620                 return -EMSGSIZE;
621
622         ifm = nlmsg_data(nlh);
623         ifm->ifi_family = AF_UNSPEC;
624         ifm->__ifi_pad = 0;
625         ifm->ifi_type = dev->type;
626         ifm->ifi_index = dev->ifindex;
627         ifm->ifi_flags = dev_get_flags(dev);
628         ifm->ifi_change = change;
629
630         NLA_PUT_STRING(skb, IFLA_IFNAME, dev->name);
631         NLA_PUT_U32(skb, IFLA_TXQLEN, dev->tx_queue_len);
632         NLA_PUT_U32(skb, IFLA_WEIGHT, dev->weight);
633         NLA_PUT_U8(skb, IFLA_OPERSTATE,
634                    netif_running(dev) ? dev->operstate : IF_OPER_DOWN);
635         NLA_PUT_U8(skb, IFLA_LINKMODE, dev->link_mode);
636         NLA_PUT_U32(skb, IFLA_MTU, dev->mtu);
637
638         if (dev->ifindex != dev->iflink)
639                 NLA_PUT_U32(skb, IFLA_LINK, dev->iflink);
640
641         if (dev->master)
642                 NLA_PUT_U32(skb, IFLA_MASTER, dev->master->ifindex);
643
644         if (dev->qdisc_sleeping)
645                 NLA_PUT_STRING(skb, IFLA_QDISC, dev->qdisc_sleeping->ops->id);
646
647         if (1) {
648                 struct rtnl_link_ifmap map = {
649                         .mem_start   = dev->mem_start,
650                         .mem_end     = dev->mem_end,
651                         .base_addr   = dev->base_addr,
652                         .irq         = dev->irq,
653                         .dma         = dev->dma,
654                         .port        = dev->if_port,
655                 };
656                 NLA_PUT(skb, IFLA_MAP, sizeof(map), &map);
657         }
658
659         if (dev->addr_len) {
660                 NLA_PUT(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr);
661                 NLA_PUT(skb, IFLA_BROADCAST, dev->addr_len, dev->broadcast);
662         }
663
664         if (dev->get_stats) {
665                 struct net_device_stats *stats = dev->get_stats(dev);
666                 if (stats) {
667                         struct nlattr *attr;
668
669                         attr = nla_reserve(skb, IFLA_STATS,
670                                            sizeof(struct rtnl_link_stats));
671                         if (attr == NULL)
672                                 goto nla_put_failure;
673
674                         copy_rtnl_link_stats(nla_data(attr), stats);
675                 }
676         }
677
678         if (dev->rtnl_link_ops) {
679                 if (rtnl_link_fill(skb, dev) < 0)
680                         goto nla_put_failure;
681         }
682
683         return nlmsg_end(skb, nlh);
684
685 nla_put_failure:
686         nlmsg_cancel(skb, nlh);
687         return -EMSGSIZE;
688 }
689
690 static int rtnl_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
691 {
692         int idx;
693         int s_idx = cb->args[0];
694         struct net_device *dev;
695
696         idx = 0;
697         for_each_netdev(dev) {
698                 if (idx < s_idx)
699                         goto cont;
700                 if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
701                                      NETLINK_CB(cb->skb).pid,
702                                      cb->nlh->nlmsg_seq, 0, NLM_F_MULTI) <= 0)
703                         break;
704 cont:
705                 idx++;
706         }
707         cb->args[0] = idx;
708
709         return skb->len;
710 }
711
712 static const struct nla_policy ifla_policy[IFLA_MAX+1] = {
713         [IFLA_IFNAME]           = { .type = NLA_STRING, .len = IFNAMSIZ-1 },
714         [IFLA_ADDRESS]          = { .type = NLA_BINARY, .len = MAX_ADDR_LEN },
715         [IFLA_BROADCAST]        = { .type = NLA_BINARY, .len = MAX_ADDR_LEN },
716         [IFLA_MAP]              = { .len = sizeof(struct rtnl_link_ifmap) },
717         [IFLA_MTU]              = { .type = NLA_U32 },
718         [IFLA_TXQLEN]           = { .type = NLA_U32 },
719         [IFLA_WEIGHT]           = { .type = NLA_U32 },
720         [IFLA_OPERSTATE]        = { .type = NLA_U8 },
721         [IFLA_LINKMODE]         = { .type = NLA_U8 },
722 };
723
724 static const struct nla_policy ifla_info_policy[IFLA_INFO_MAX+1] = {
725         [IFLA_INFO_KIND]        = { .type = NLA_STRING },
726         [IFLA_INFO_DATA]        = { .type = NLA_NESTED },
727 };
728
729 static int do_setlink(struct net_device *dev, struct ifinfomsg *ifm,
730                       struct nlattr **tb, char *ifname, int modified)
731 {
732         int send_addr_notify = 0;
733         int err;
734
735         if (tb[IFLA_MAP]) {
736                 struct rtnl_link_ifmap *u_map;
737                 struct ifmap k_map;
738
739                 if (!dev->set_config) {
740                         err = -EOPNOTSUPP;
741                         goto errout;
742                 }
743
744                 if (!netif_device_present(dev)) {
745                         err = -ENODEV;
746                         goto errout;
747                 }
748
749                 u_map = nla_data(tb[IFLA_MAP]);
750                 k_map.mem_start = (unsigned long) u_map->mem_start;
751                 k_map.mem_end = (unsigned long) u_map->mem_end;
752                 k_map.base_addr = (unsigned short) u_map->base_addr;
753                 k_map.irq = (unsigned char) u_map->irq;
754                 k_map.dma = (unsigned char) u_map->dma;
755                 k_map.port = (unsigned char) u_map->port;
756
757                 err = dev->set_config(dev, &k_map);
758                 if (err < 0)
759                         goto errout;
760
761                 modified = 1;
762         }
763
764         if (tb[IFLA_ADDRESS]) {
765                 struct sockaddr *sa;
766                 int len;
767
768                 if (!dev->set_mac_address) {
769                         err = -EOPNOTSUPP;
770                         goto errout;
771                 }
772
773                 if (!netif_device_present(dev)) {
774                         err = -ENODEV;
775                         goto errout;
776                 }
777
778                 len = sizeof(sa_family_t) + dev->addr_len;
779                 sa = kmalloc(len, GFP_KERNEL);
780                 if (!sa) {
781                         err = -ENOMEM;
782                         goto errout;
783                 }
784                 sa->sa_family = dev->type;
785                 memcpy(sa->sa_data, nla_data(tb[IFLA_ADDRESS]),
786                        dev->addr_len);
787                 err = dev->set_mac_address(dev, sa);
788                 kfree(sa);
789                 if (err)
790                         goto errout;
791                 send_addr_notify = 1;
792                 modified = 1;
793         }
794
795         if (tb[IFLA_MTU]) {
796                 err = dev_set_mtu(dev, nla_get_u32(tb[IFLA_MTU]));
797                 if (err < 0)
798                         goto errout;
799                 modified = 1;
800         }
801
802         /*
803          * Interface selected by interface index but interface
804          * name provided implies that a name change has been
805          * requested.
806          */
807         if (ifm->ifi_index > 0 && ifname[0]) {
808                 err = dev_change_name(dev, ifname);
809                 if (err < 0)
810                         goto errout;
811                 modified = 1;
812         }
813
814         if (tb[IFLA_BROADCAST]) {
815                 nla_memcpy(dev->broadcast, tb[IFLA_BROADCAST], dev->addr_len);
816                 send_addr_notify = 1;
817         }
818
819         if (ifm->ifi_flags || ifm->ifi_change) {
820                 unsigned int flags = ifm->ifi_flags;
821
822                 /* bugwards compatibility: ifi_change == 0 is treated as ~0 */
823                 if (ifm->ifi_change)
824                         flags = (flags & ifm->ifi_change) |
825                                 (dev->flags & ~ifm->ifi_change);
826                 dev_change_flags(dev, flags);
827         }
828
829         if (tb[IFLA_TXQLEN])
830                 dev->tx_queue_len = nla_get_u32(tb[IFLA_TXQLEN]);
831
832         if (tb[IFLA_WEIGHT])
833                 dev->weight = nla_get_u32(tb[IFLA_WEIGHT]);
834
835         if (tb[IFLA_OPERSTATE])
836                 set_operstate(dev, nla_get_u8(tb[IFLA_OPERSTATE]));
837
838         if (tb[IFLA_LINKMODE]) {
839                 write_lock_bh(&dev_base_lock);
840                 dev->link_mode = nla_get_u8(tb[IFLA_LINKMODE]);
841                 write_unlock_bh(&dev_base_lock);
842         }
843
844         err = 0;
845
846 errout:
847         if (err < 0 && modified && net_ratelimit())
848                 printk(KERN_WARNING "A link change request failed with "
849                        "some changes comitted already. Interface %s may "
850                        "have been left with an inconsistent configuration, "
851                        "please check.\n", dev->name);
852
853         if (send_addr_notify)
854                 call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
855         return err;
856 }
857
858 static int rtnl_setlink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
859 {
860         struct ifinfomsg *ifm;
861         struct net_device *dev;
862         int err;
863         struct nlattr *tb[IFLA_MAX+1];
864         char ifname[IFNAMSIZ];
865
866         err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFLA_MAX, ifla_policy);
867         if (err < 0)
868                 goto errout;
869
870         if (tb[IFLA_IFNAME])
871                 nla_strlcpy(ifname, tb[IFLA_IFNAME], IFNAMSIZ);
872         else
873                 ifname[0] = '\0';
874
875         err = -EINVAL;
876         ifm = nlmsg_data(nlh);
877         if (ifm->ifi_index > 0)
878                 dev = dev_get_by_index(ifm->ifi_index);
879         else if (tb[IFLA_IFNAME])
880                 dev = dev_get_by_name(ifname);
881         else
882                 goto errout;
883
884         if (dev == NULL) {
885                 err = -ENODEV;
886                 goto errout;
887         }
888
889         if (tb[IFLA_ADDRESS] &&
890             nla_len(tb[IFLA_ADDRESS]) < dev->addr_len)
891                 goto errout_dev;
892
893         if (tb[IFLA_BROADCAST] &&
894             nla_len(tb[IFLA_BROADCAST]) < dev->addr_len)
895                 goto errout_dev;
896
897         err = do_setlink(dev, ifm, tb, ifname, 0);
898 errout_dev:
899         dev_put(dev);
900 errout:
901         return err;
902 }
903
904 static int rtnl_dellink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
905 {
906         const struct rtnl_link_ops *ops;
907         struct net_device *dev;
908         struct ifinfomsg *ifm;
909         char ifname[IFNAMSIZ];
910         struct nlattr *tb[IFLA_MAX+1];
911         int err;
912
913         err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFLA_MAX, ifla_policy);
914         if (err < 0)
915                 return err;
916
917         if (tb[IFLA_IFNAME])
918                 nla_strlcpy(ifname, tb[IFLA_IFNAME], IFNAMSIZ);
919
920         ifm = nlmsg_data(nlh);
921         if (ifm->ifi_index > 0)
922                 dev = __dev_get_by_index(ifm->ifi_index);
923         else if (tb[IFLA_IFNAME])
924                 dev = __dev_get_by_name(ifname);
925         else
926                 return -EINVAL;
927
928         if (!dev)
929                 return -ENODEV;
930
931         ops = dev->rtnl_link_ops;
932         if (!ops)
933                 return -EOPNOTSUPP;
934
935         ops->dellink(dev);
936         return 0;
937 }
938
939 static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
940 {
941         const struct rtnl_link_ops *ops;
942         struct net_device *dev;
943         struct ifinfomsg *ifm;
944         char kind[MODULE_NAME_LEN];
945         char ifname[IFNAMSIZ];
946         struct nlattr *tb[IFLA_MAX+1];
947         struct nlattr *linkinfo[IFLA_INFO_MAX+1];
948         int err;
949
950 replay:
951         err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFLA_MAX, ifla_policy);
952         if (err < 0)
953                 return err;
954
955         if (tb[IFLA_IFNAME])
956                 nla_strlcpy(ifname, tb[IFLA_IFNAME], IFNAMSIZ);
957         else
958                 ifname[0] = '\0';
959
960         ifm = nlmsg_data(nlh);
961         if (ifm->ifi_index > 0)
962                 dev = __dev_get_by_index(ifm->ifi_index);
963         else if (ifname[0])
964                 dev = __dev_get_by_name(ifname);
965         else
966                 dev = NULL;
967
968         if (tb[IFLA_LINKINFO]) {
969                 err = nla_parse_nested(linkinfo, IFLA_INFO_MAX,
970                                        tb[IFLA_LINKINFO], ifla_info_policy);
971                 if (err < 0)
972                         return err;
973         } else
974                 memset(linkinfo, 0, sizeof(linkinfo));
975
976         if (linkinfo[IFLA_INFO_KIND]) {
977                 nla_strlcpy(kind, linkinfo[IFLA_INFO_KIND], sizeof(kind));
978                 ops = rtnl_link_ops_get(kind);
979         } else {
980                 kind[0] = '\0';
981                 ops = NULL;
982         }
983
984         if (1) {
985                 struct nlattr *attr[ops ? ops->maxtype + 1 : 0], **data = NULL;
986
987                 if (ops) {
988                         if (ops->maxtype && linkinfo[IFLA_INFO_DATA]) {
989                                 err = nla_parse_nested(attr, ops->maxtype,
990                                                        linkinfo[IFLA_INFO_DATA],
991                                                        ops->policy);
992                                 if (err < 0)
993                                         return err;
994                                 data = attr;
995                         }
996                         if (ops->validate) {
997                                 err = ops->validate(tb, data);
998                                 if (err < 0)
999                                         return err;
1000                         }
1001                 }
1002
1003                 if (dev) {
1004                         int modified = 0;
1005
1006                         if (nlh->nlmsg_flags & NLM_F_EXCL)
1007                                 return -EEXIST;
1008                         if (nlh->nlmsg_flags & NLM_F_REPLACE)
1009                                 return -EOPNOTSUPP;
1010
1011                         if (linkinfo[IFLA_INFO_DATA]) {
1012                                 if (!ops || ops != dev->rtnl_link_ops ||
1013                                     !ops->changelink)
1014                                         return -EOPNOTSUPP;
1015
1016                                 err = ops->changelink(dev, tb, data);
1017                                 if (err < 0)
1018                                         return err;
1019                                 modified = 1;
1020                         }
1021
1022                         return do_setlink(dev, ifm, tb, ifname, modified);
1023                 }
1024
1025                 if (!(nlh->nlmsg_flags & NLM_F_CREATE))
1026                         return -ENODEV;
1027
1028                 if (ifm->ifi_index || ifm->ifi_flags || ifm->ifi_change)
1029                         return -EOPNOTSUPP;
1030                 if (tb[IFLA_ADDRESS] || tb[IFLA_BROADCAST] || tb[IFLA_MAP] ||
1031                     tb[IFLA_MASTER] || tb[IFLA_PROTINFO])
1032                         return -EOPNOTSUPP;
1033
1034                 if (!ops) {
1035 #ifdef CONFIG_KMOD
1036                         if (kind[0]) {
1037                                 __rtnl_unlock();
1038                                 request_module("rtnl-link-%s", kind);
1039                                 rtnl_lock();
1040                                 ops = rtnl_link_ops_get(kind);
1041                                 if (ops)
1042                                         goto replay;
1043                         }
1044 #endif
1045                         return -EOPNOTSUPP;
1046                 }
1047
1048                 if (!ifname[0])
1049                         snprintf(ifname, IFNAMSIZ, "%s%%d", ops->kind);
1050                 dev = alloc_netdev(ops->priv_size, ifname, ops->setup);
1051                 if (!dev)
1052                         return -ENOMEM;
1053
1054                 if (strchr(dev->name, '%')) {
1055                         err = dev_alloc_name(dev, dev->name);
1056                         if (err < 0)
1057                                 goto err_free;
1058                 }
1059                 dev->rtnl_link_ops = ops;
1060
1061                 if (tb[IFLA_MTU])
1062                         dev->mtu = nla_get_u32(tb[IFLA_MTU]);
1063                 if (tb[IFLA_TXQLEN])
1064                         dev->tx_queue_len = nla_get_u32(tb[IFLA_TXQLEN]);
1065                 if (tb[IFLA_WEIGHT])
1066                         dev->weight = nla_get_u32(tb[IFLA_WEIGHT]);
1067                 if (tb[IFLA_OPERSTATE])
1068                         set_operstate(dev, nla_get_u8(tb[IFLA_OPERSTATE]));
1069                 if (tb[IFLA_LINKMODE])
1070                         dev->link_mode = nla_get_u8(tb[IFLA_LINKMODE]);
1071
1072                 err = ops->newlink(dev, tb, data);
1073 err_free:
1074                 if (err < 0)
1075                         free_netdev(dev);
1076                 return err;
1077         }
1078 }
1079
1080 static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
1081 {
1082         struct ifinfomsg *ifm;
1083         struct nlattr *tb[IFLA_MAX+1];
1084         struct net_device *dev = NULL;
1085         struct sk_buff *nskb;
1086         int err;
1087
1088         err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFLA_MAX, ifla_policy);
1089         if (err < 0)
1090                 return err;
1091
1092         ifm = nlmsg_data(nlh);
1093         if (ifm->ifi_index > 0) {
1094                 dev = dev_get_by_index(ifm->ifi_index);
1095                 if (dev == NULL)
1096                         return -ENODEV;
1097         } else
1098                 return -EINVAL;
1099
1100         nskb = nlmsg_new(if_nlmsg_size(dev), GFP_KERNEL);
1101         if (nskb == NULL) {
1102                 err = -ENOBUFS;
1103                 goto errout;
1104         }
1105
1106         err = rtnl_fill_ifinfo(nskb, dev, RTM_NEWLINK, NETLINK_CB(skb).pid,
1107                                nlh->nlmsg_seq, 0, 0);
1108         if (err < 0) {
1109                 /* -EMSGSIZE implies BUG in if_nlmsg_size */
1110                 WARN_ON(err == -EMSGSIZE);
1111                 kfree_skb(nskb);
1112                 goto errout;
1113         }
1114         err = rtnl_unicast(nskb, NETLINK_CB(skb).pid);
1115 errout:
1116         dev_put(dev);
1117
1118         return err;
1119 }
1120
1121 static int rtnl_dump_all(struct sk_buff *skb, struct netlink_callback *cb)
1122 {
1123         int idx;
1124         int s_idx = cb->family;
1125
1126         if (s_idx == 0)
1127                 s_idx = 1;
1128         for (idx=1; idx<NPROTO; idx++) {
1129                 int type = cb->nlh->nlmsg_type-RTM_BASE;
1130                 if (idx < s_idx || idx == PF_PACKET)
1131                         continue;
1132                 if (rtnl_msg_handlers[idx] == NULL ||
1133                     rtnl_msg_handlers[idx][type].dumpit == NULL)
1134                         continue;
1135                 if (idx > s_idx)
1136                         memset(&cb->args[0], 0, sizeof(cb->args));
1137                 if (rtnl_msg_handlers[idx][type].dumpit(skb, cb))
1138                         break;
1139         }
1140         cb->family = idx;
1141
1142         return skb->len;
1143 }
1144
1145 void rtmsg_ifinfo(int type, struct net_device *dev, unsigned change)
1146 {
1147         struct sk_buff *skb;
1148         int err = -ENOBUFS;
1149
1150         skb = nlmsg_new(if_nlmsg_size(dev), GFP_KERNEL);
1151         if (skb == NULL)
1152                 goto errout;
1153
1154         err = rtnl_fill_ifinfo(skb, dev, type, 0, 0, change, 0);
1155         if (err < 0) {
1156                 /* -EMSGSIZE implies BUG in if_nlmsg_size() */
1157                 WARN_ON(err == -EMSGSIZE);
1158                 kfree_skb(skb);
1159                 goto errout;
1160         }
1161         err = rtnl_notify(skb, 0, RTNLGRP_LINK, NULL, GFP_KERNEL);
1162 errout:
1163         if (err < 0)
1164                 rtnl_set_sk_err(RTNLGRP_LINK, err);
1165 }
1166
1167 /* Protected by RTNL sempahore.  */
1168 static struct rtattr **rta_buf;
1169 static int rtattr_max;
1170
1171 /* Process one rtnetlink message. */
1172
1173 static int rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
1174 {
1175         rtnl_doit_func doit;
1176         int sz_idx, kind;
1177         int min_len;
1178         int family;
1179         int type;
1180         int err;
1181
1182         type = nlh->nlmsg_type;
1183         if (type > RTM_MAX)
1184                 return -EOPNOTSUPP;
1185
1186         type -= RTM_BASE;
1187
1188         /* All the messages must have at least 1 byte length */
1189         if (nlh->nlmsg_len < NLMSG_LENGTH(sizeof(struct rtgenmsg)))
1190                 return 0;
1191
1192         family = ((struct rtgenmsg*)NLMSG_DATA(nlh))->rtgen_family;
1193         if (family >= NPROTO)
1194                 return -EAFNOSUPPORT;
1195
1196         sz_idx = type>>2;
1197         kind = type&3;
1198
1199         if (kind != 2 && security_netlink_recv(skb, CAP_NET_ADMIN))
1200                 return -EPERM;
1201
1202         if (kind == 2 && nlh->nlmsg_flags&NLM_F_DUMP) {
1203                 rtnl_dumpit_func dumpit;
1204
1205                 dumpit = rtnl_get_dumpit(family, type);
1206                 if (dumpit == NULL)
1207                         return -EOPNOTSUPP;
1208
1209                 __rtnl_unlock();
1210                 err = netlink_dump_start(rtnl, skb, nlh, dumpit, NULL);
1211                 rtnl_lock();
1212                 return err;
1213         }
1214
1215         memset(rta_buf, 0, (rtattr_max * sizeof(struct rtattr *)));
1216
1217         min_len = rtm_min[sz_idx];
1218         if (nlh->nlmsg_len < min_len)
1219                 return -EINVAL;
1220
1221         if (nlh->nlmsg_len > min_len) {
1222                 int attrlen = nlh->nlmsg_len - NLMSG_ALIGN(min_len);
1223                 struct rtattr *attr = (void*)nlh + NLMSG_ALIGN(min_len);
1224
1225                 while (RTA_OK(attr, attrlen)) {
1226                         unsigned flavor = attr->rta_type;
1227                         if (flavor) {
1228                                 if (flavor > rta_max[sz_idx])
1229                                         return -EINVAL;
1230                                 rta_buf[flavor-1] = attr;
1231                         }
1232                         attr = RTA_NEXT(attr, attrlen);
1233                 }
1234         }
1235
1236         doit = rtnl_get_doit(family, type);
1237         if (doit == NULL)
1238                 return -EOPNOTSUPP;
1239
1240         return doit(skb, nlh, (void *)&rta_buf[0]);
1241 }
1242
1243 static void rtnetlink_rcv(struct sock *sk, int len)
1244 {
1245         unsigned int qlen = 0;
1246
1247         do {
1248                 mutex_lock(&rtnl_mutex);
1249                 netlink_run_queue(sk, &qlen, &rtnetlink_rcv_msg);
1250                 mutex_unlock(&rtnl_mutex);
1251
1252                 netdev_run_todo();
1253         } while (qlen);
1254 }
1255
1256 static int rtnetlink_event(struct notifier_block *this, unsigned long event, void *ptr)
1257 {
1258         struct net_device *dev = ptr;
1259         switch (event) {
1260         case NETDEV_UNREGISTER:
1261                 rtmsg_ifinfo(RTM_DELLINK, dev, ~0U);
1262                 break;
1263         case NETDEV_REGISTER:
1264                 rtmsg_ifinfo(RTM_NEWLINK, dev, ~0U);
1265                 break;
1266         case NETDEV_UP:
1267         case NETDEV_DOWN:
1268                 rtmsg_ifinfo(RTM_NEWLINK, dev, IFF_UP|IFF_RUNNING);
1269                 break;
1270         case NETDEV_CHANGE:
1271         case NETDEV_GOING_DOWN:
1272                 break;
1273         default:
1274                 rtmsg_ifinfo(RTM_NEWLINK, dev, 0);
1275                 break;
1276         }
1277         return NOTIFY_DONE;
1278 }
1279
1280 static struct notifier_block rtnetlink_dev_notifier = {
1281         .notifier_call  = rtnetlink_event,
1282 };
1283
1284 void __init rtnetlink_init(void)
1285 {
1286         int i;
1287
1288         rtattr_max = 0;
1289         for (i = 0; i < ARRAY_SIZE(rta_max); i++)
1290                 if (rta_max[i] > rtattr_max)
1291                         rtattr_max = rta_max[i];
1292         rta_buf = kmalloc(rtattr_max * sizeof(struct rtattr *), GFP_KERNEL);
1293         if (!rta_buf)
1294                 panic("rtnetlink_init: cannot allocate rta_buf\n");
1295
1296         rtnl = netlink_kernel_create(NETLINK_ROUTE, RTNLGRP_MAX, rtnetlink_rcv,
1297                                      &rtnl_mutex, THIS_MODULE);
1298         if (rtnl == NULL)
1299                 panic("rtnetlink_init: cannot initialize rtnetlink\n");
1300         netlink_set_nonroot(NETLINK_ROUTE, NL_NONROOT_RECV);
1301         register_netdevice_notifier(&rtnetlink_dev_notifier);
1302
1303         rtnl_register(PF_UNSPEC, RTM_GETLINK, rtnl_getlink, rtnl_dump_ifinfo);
1304         rtnl_register(PF_UNSPEC, RTM_SETLINK, rtnl_setlink, NULL);
1305         rtnl_register(PF_UNSPEC, RTM_NEWLINK, rtnl_newlink, NULL);
1306         rtnl_register(PF_UNSPEC, RTM_DELLINK, rtnl_dellink, NULL);
1307
1308         rtnl_register(PF_UNSPEC, RTM_GETADDR, NULL, rtnl_dump_all);
1309         rtnl_register(PF_UNSPEC, RTM_GETROUTE, NULL, rtnl_dump_all);
1310 }
1311
1312 EXPORT_SYMBOL(__rta_fill);
1313 EXPORT_SYMBOL(rtattr_strlcpy);
1314 EXPORT_SYMBOL(rtattr_parse);
1315 EXPORT_SYMBOL(rtattr_parse_nested_compat);
1316 EXPORT_SYMBOL(rtnetlink_put_metrics);
1317 EXPORT_SYMBOL(rtnl_lock);
1318 EXPORT_SYMBOL(rtnl_trylock);
1319 EXPORT_SYMBOL(rtnl_unlock);
1320 EXPORT_SYMBOL(rtnl_unicast);
1321 EXPORT_SYMBOL(rtnl_notify);
1322 EXPORT_SYMBOL(rtnl_set_sk_err);