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