blob: b76f8fa3fc64f2f2df1cf3d0419b562b30262e51 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/errno.h>
20#include <linux/module.h>
21#include <linux/types.h>
22#include <linux/socket.h>
23#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#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>
Stephen Hemminger6756ae42006-03-20 22:23:58 -080036#include <linux/mutex.h>
Thomas Graf18237302006-08-04 23:04:54 -070037#include <linux/if_addr.h>
Williams, Mitch Aebc08a62010-02-10 01:44:05 +000038#include <linux/pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
40#include <asm/uaccess.h>
41#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
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>
Thomas Graf14c0b972006-08-04 03:38:38 -070052#include <net/fib_rules.h>
Thomas Grafe2849862007-03-22 11:48:11 -070053#include <net/rtnetlink.h>
Johannes Berg30ffee82009-07-10 09:51:35 +000054#include <net/net_namespace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Eric Dumazete0d087a2009-11-07 01:26:17 -080056struct rtnl_link {
Thomas Grafe2849862007-03-22 11:48:11 -070057 rtnl_doit_func doit;
58 rtnl_dumpit_func dumpit;
Greg Rosec7ac8672011-06-10 01:27:09 +000059 rtnl_calcit_func calcit;
Thomas Grafe2849862007-03-22 11:48:11 -070060};
61
Stephen Hemminger6756ae42006-03-20 22:23:58 -080062static DEFINE_MUTEX(rtnl_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64void rtnl_lock(void)
65{
Stephen Hemminger6756ae42006-03-20 22:23:58 -080066 mutex_lock(&rtnl_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067}
Eric Dumazete0d087a2009-11-07 01:26:17 -080068EXPORT_SYMBOL(rtnl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Stephen Hemminger6756ae42006-03-20 22:23:58 -080070void __rtnl_unlock(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070071{
Stephen Hemminger6756ae42006-03-20 22:23:58 -080072 mutex_unlock(&rtnl_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073}
Stephen Hemminger6756ae42006-03-20 22:23:58 -080074
Linus Torvalds1da177e2005-04-16 15:20:36 -070075void rtnl_unlock(void)
76{
Herbert Xu58ec3b42008-10-07 15:50:03 -070077 /* This fellow will unlock it for us. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 netdev_run_todo();
79}
Eric Dumazete0d087a2009-11-07 01:26:17 -080080EXPORT_SYMBOL(rtnl_unlock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
Stephen Hemminger6756ae42006-03-20 22:23:58 -080082int rtnl_trylock(void)
83{
84 return mutex_trylock(&rtnl_mutex);
85}
Eric Dumazete0d087a2009-11-07 01:26:17 -080086EXPORT_SYMBOL(rtnl_trylock);
Stephen Hemminger6756ae42006-03-20 22:23:58 -080087
Patrick McHardyc9c10142008-04-23 22:10:48 -070088int rtnl_is_locked(void)
89{
90 return mutex_is_locked(&rtnl_mutex);
91}
Eric Dumazete0d087a2009-11-07 01:26:17 -080092EXPORT_SYMBOL(rtnl_is_locked);
Patrick McHardyc9c10142008-04-23 22:10:48 -070093
Paul E. McKenneya898def2010-02-22 17:04:49 -080094#ifdef CONFIG_PROVE_LOCKING
95int lockdep_rtnl_is_held(void)
96{
97 return lockdep_is_held(&rtnl_mutex);
98}
99EXPORT_SYMBOL(lockdep_rtnl_is_held);
100#endif /* #ifdef CONFIG_PROVE_LOCKING */
101
Patrick McHardy25239ce2010-04-26 16:02:05 +0200102static struct rtnl_link *rtnl_msg_handlers[RTNL_FAMILY_MAX + 1];
Thomas Grafe2849862007-03-22 11:48:11 -0700103
104static inline int rtm_msgindex(int msgtype)
105{
106 int msgindex = msgtype - RTM_BASE;
107
108 /*
109 * msgindex < 0 implies someone tried to register a netlink
110 * control code. msgindex >= RTM_NR_MSGTYPES may indicate that
111 * the message type has not been added to linux/rtnetlink.h
112 */
113 BUG_ON(msgindex < 0 || msgindex >= RTM_NR_MSGTYPES);
114
115 return msgindex;
116}
117
118static rtnl_doit_func rtnl_get_doit(int protocol, int msgindex)
119{
120 struct rtnl_link *tab;
121
Patrick McHardy25239ce2010-04-26 16:02:05 +0200122 if (protocol <= RTNL_FAMILY_MAX)
Patrick McHardy0f87b1d2010-04-13 05:03:17 +0000123 tab = rtnl_msg_handlers[protocol];
124 else
125 tab = NULL;
126
Thomas Graf51057f22007-03-22 21:41:06 -0700127 if (tab == NULL || tab[msgindex].doit == NULL)
Thomas Grafe2849862007-03-22 11:48:11 -0700128 tab = rtnl_msg_handlers[PF_UNSPEC];
129
Thomas Graf51057f22007-03-22 21:41:06 -0700130 return tab ? tab[msgindex].doit : NULL;
Thomas Grafe2849862007-03-22 11:48:11 -0700131}
132
133static rtnl_dumpit_func rtnl_get_dumpit(int protocol, int msgindex)
134{
135 struct rtnl_link *tab;
136
Patrick McHardy25239ce2010-04-26 16:02:05 +0200137 if (protocol <= RTNL_FAMILY_MAX)
Patrick McHardy0f87b1d2010-04-13 05:03:17 +0000138 tab = rtnl_msg_handlers[protocol];
139 else
140 tab = NULL;
141
Thomas Graf51057f22007-03-22 21:41:06 -0700142 if (tab == NULL || tab[msgindex].dumpit == NULL)
Thomas Grafe2849862007-03-22 11:48:11 -0700143 tab = rtnl_msg_handlers[PF_UNSPEC];
144
Thomas Graf51057f22007-03-22 21:41:06 -0700145 return tab ? tab[msgindex].dumpit : NULL;
Thomas Grafe2849862007-03-22 11:48:11 -0700146}
147
Greg Rosec7ac8672011-06-10 01:27:09 +0000148static rtnl_calcit_func rtnl_get_calcit(int protocol, int msgindex)
149{
150 struct rtnl_link *tab;
151
152 if (protocol <= RTNL_FAMILY_MAX)
153 tab = rtnl_msg_handlers[protocol];
154 else
155 tab = NULL;
156
157 if (tab == NULL || tab[msgindex].calcit == NULL)
158 tab = rtnl_msg_handlers[PF_UNSPEC];
159
160 return tab ? tab[msgindex].calcit : NULL;
161}
162
Thomas Grafe2849862007-03-22 11:48:11 -0700163/**
164 * __rtnl_register - Register a rtnetlink message type
165 * @protocol: Protocol family or PF_UNSPEC
166 * @msgtype: rtnetlink message type
167 * @doit: Function pointer called for each request message
168 * @dumpit: Function pointer called for each dump request (NLM_F_DUMP) message
Greg Rosec7ac8672011-06-10 01:27:09 +0000169 * @calcit: Function pointer to calc size of dump message
Thomas Grafe2849862007-03-22 11:48:11 -0700170 *
171 * Registers the specified function pointers (at least one of them has
172 * to be non-NULL) to be called whenever a request message for the
173 * specified protocol family and message type is received.
174 *
175 * The special protocol family PF_UNSPEC may be used to define fallback
176 * function pointers for the case when no entry for the specific protocol
177 * family exists.
178 *
179 * Returns 0 on success or a negative error code.
180 */
181int __rtnl_register(int protocol, int msgtype,
Greg Rosec7ac8672011-06-10 01:27:09 +0000182 rtnl_doit_func doit, rtnl_dumpit_func dumpit,
183 rtnl_calcit_func calcit)
Thomas Grafe2849862007-03-22 11:48:11 -0700184{
185 struct rtnl_link *tab;
186 int msgindex;
187
Patrick McHardy25239ce2010-04-26 16:02:05 +0200188 BUG_ON(protocol < 0 || protocol > RTNL_FAMILY_MAX);
Thomas Grafe2849862007-03-22 11:48:11 -0700189 msgindex = rtm_msgindex(msgtype);
190
191 tab = rtnl_msg_handlers[protocol];
192 if (tab == NULL) {
193 tab = kcalloc(RTM_NR_MSGTYPES, sizeof(*tab), GFP_KERNEL);
194 if (tab == NULL)
195 return -ENOBUFS;
196
197 rtnl_msg_handlers[protocol] = tab;
198 }
199
200 if (doit)
201 tab[msgindex].doit = doit;
202
203 if (dumpit)
204 tab[msgindex].dumpit = dumpit;
205
Greg Rosec7ac8672011-06-10 01:27:09 +0000206 if (calcit)
207 tab[msgindex].calcit = calcit;
208
Thomas Grafe2849862007-03-22 11:48:11 -0700209 return 0;
210}
Thomas Grafe2849862007-03-22 11:48:11 -0700211EXPORT_SYMBOL_GPL(__rtnl_register);
212
213/**
214 * rtnl_register - Register a rtnetlink message type
215 *
216 * Identical to __rtnl_register() but panics on failure. This is useful
217 * as failure of this function is very unlikely, it can only happen due
218 * to lack of memory when allocating the chain to store all message
219 * handlers for a protocol. Meant for use in init functions where lack
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300220 * of memory implies no sense in continuing.
Thomas Grafe2849862007-03-22 11:48:11 -0700221 */
222void rtnl_register(int protocol, int msgtype,
Greg Rosec7ac8672011-06-10 01:27:09 +0000223 rtnl_doit_func doit, rtnl_dumpit_func dumpit,
224 rtnl_calcit_func calcit)
Thomas Grafe2849862007-03-22 11:48:11 -0700225{
Greg Rosec7ac8672011-06-10 01:27:09 +0000226 if (__rtnl_register(protocol, msgtype, doit, dumpit, calcit) < 0)
Thomas Grafe2849862007-03-22 11:48:11 -0700227 panic("Unable to register rtnetlink message handler, "
228 "protocol = %d, message type = %d\n",
229 protocol, msgtype);
230}
Thomas Grafe2849862007-03-22 11:48:11 -0700231EXPORT_SYMBOL_GPL(rtnl_register);
232
233/**
234 * rtnl_unregister - Unregister a rtnetlink message type
235 * @protocol: Protocol family or PF_UNSPEC
236 * @msgtype: rtnetlink message type
237 *
238 * Returns 0 on success or a negative error code.
239 */
240int rtnl_unregister(int protocol, int msgtype)
241{
242 int msgindex;
243
Patrick McHardy25239ce2010-04-26 16:02:05 +0200244 BUG_ON(protocol < 0 || protocol > RTNL_FAMILY_MAX);
Thomas Grafe2849862007-03-22 11:48:11 -0700245 msgindex = rtm_msgindex(msgtype);
246
247 if (rtnl_msg_handlers[protocol] == NULL)
248 return -ENOENT;
249
250 rtnl_msg_handlers[protocol][msgindex].doit = NULL;
251 rtnl_msg_handlers[protocol][msgindex].dumpit = NULL;
252
253 return 0;
254}
Thomas Grafe2849862007-03-22 11:48:11 -0700255EXPORT_SYMBOL_GPL(rtnl_unregister);
256
257/**
258 * rtnl_unregister_all - Unregister all rtnetlink message type of a protocol
259 * @protocol : Protocol family or PF_UNSPEC
260 *
261 * Identical to calling rtnl_unregster() for all registered message types
262 * of a certain protocol family.
263 */
264void rtnl_unregister_all(int protocol)
265{
Patrick McHardy25239ce2010-04-26 16:02:05 +0200266 BUG_ON(protocol < 0 || protocol > RTNL_FAMILY_MAX);
Thomas Grafe2849862007-03-22 11:48:11 -0700267
268 kfree(rtnl_msg_handlers[protocol]);
269 rtnl_msg_handlers[protocol] = NULL;
270}
Thomas Grafe2849862007-03-22 11:48:11 -0700271EXPORT_SYMBOL_GPL(rtnl_unregister_all);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
Patrick McHardy38f7b872007-06-13 12:03:51 -0700273static LIST_HEAD(link_ops);
274
Eric Dumazetc63044f2011-12-13 11:38:00 +0000275static const struct rtnl_link_ops *rtnl_link_ops_get(const char *kind)
276{
277 const struct rtnl_link_ops *ops;
278
279 list_for_each_entry(ops, &link_ops, list) {
280 if (!strcmp(ops->kind, kind))
281 return ops;
282 }
283 return NULL;
284}
285
Patrick McHardy38f7b872007-06-13 12:03:51 -0700286/**
287 * __rtnl_link_register - Register rtnl_link_ops with rtnetlink.
288 * @ops: struct rtnl_link_ops * to register
289 *
290 * The caller must hold the rtnl_mutex. This function should be used
291 * by drivers that create devices during module initialization. It
292 * must be called before registering the devices.
293 *
294 * Returns 0 on success or a negative error code.
295 */
296int __rtnl_link_register(struct rtnl_link_ops *ops)
297{
Eric Dumazetc63044f2011-12-13 11:38:00 +0000298 if (rtnl_link_ops_get(ops->kind))
299 return -EEXIST;
300
Patrick McHardy2d85cba2007-07-11 19:42:13 -0700301 if (!ops->dellink)
Eric Dumazet23289a32009-10-27 07:06:36 +0000302 ops->dellink = unregister_netdevice_queue;
Patrick McHardy2d85cba2007-07-11 19:42:13 -0700303
Patrick McHardy38f7b872007-06-13 12:03:51 -0700304 list_add_tail(&ops->list, &link_ops);
305 return 0;
306}
Patrick McHardy38f7b872007-06-13 12:03:51 -0700307EXPORT_SYMBOL_GPL(__rtnl_link_register);
308
309/**
310 * rtnl_link_register - Register rtnl_link_ops with rtnetlink.
311 * @ops: struct rtnl_link_ops * to register
312 *
313 * Returns 0 on success or a negative error code.
314 */
315int rtnl_link_register(struct rtnl_link_ops *ops)
316{
317 int err;
318
319 rtnl_lock();
320 err = __rtnl_link_register(ops);
321 rtnl_unlock();
322 return err;
323}
Patrick McHardy38f7b872007-06-13 12:03:51 -0700324EXPORT_SYMBOL_GPL(rtnl_link_register);
325
Pavel Emelyanov669f87b2008-04-16 00:46:52 -0700326static void __rtnl_kill_links(struct net *net, struct rtnl_link_ops *ops)
327{
328 struct net_device *dev;
Eric Dumazet23289a32009-10-27 07:06:36 +0000329 LIST_HEAD(list_kill);
330
Pavel Emelyanov669f87b2008-04-16 00:46:52 -0700331 for_each_netdev(net, dev) {
Eric Dumazet23289a32009-10-27 07:06:36 +0000332 if (dev->rtnl_link_ops == ops)
333 ops->dellink(dev, &list_kill);
Pavel Emelyanov669f87b2008-04-16 00:46:52 -0700334 }
Eric Dumazet23289a32009-10-27 07:06:36 +0000335 unregister_netdevice_many(&list_kill);
Pavel Emelyanov669f87b2008-04-16 00:46:52 -0700336}
337
Patrick McHardy38f7b872007-06-13 12:03:51 -0700338/**
339 * __rtnl_link_unregister - Unregister rtnl_link_ops from rtnetlink.
340 * @ops: struct rtnl_link_ops * to unregister
341 *
Patrick McHardy2d85cba2007-07-11 19:42:13 -0700342 * The caller must hold the rtnl_mutex.
Patrick McHardy38f7b872007-06-13 12:03:51 -0700343 */
344void __rtnl_link_unregister(struct rtnl_link_ops *ops)
345{
Eric W. Biederman881d9662007-09-17 11:56:21 -0700346 struct net *net;
Patrick McHardy2d85cba2007-07-11 19:42:13 -0700347
Eric W. Biederman881d9662007-09-17 11:56:21 -0700348 for_each_net(net) {
Pavel Emelyanov669f87b2008-04-16 00:46:52 -0700349 __rtnl_kill_links(net, ops);
Patrick McHardy2d85cba2007-07-11 19:42:13 -0700350 }
Patrick McHardy38f7b872007-06-13 12:03:51 -0700351 list_del(&ops->list);
352}
Patrick McHardy38f7b872007-06-13 12:03:51 -0700353EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
354
355/**
356 * rtnl_link_unregister - Unregister rtnl_link_ops from rtnetlink.
357 * @ops: struct rtnl_link_ops * to unregister
358 */
359void rtnl_link_unregister(struct rtnl_link_ops *ops)
360{
361 rtnl_lock();
362 __rtnl_link_unregister(ops);
363 rtnl_unlock();
364}
Patrick McHardy38f7b872007-06-13 12:03:51 -0700365EXPORT_SYMBOL_GPL(rtnl_link_unregister);
366
Patrick McHardy38f7b872007-06-13 12:03:51 -0700367static size_t rtnl_link_get_size(const struct net_device *dev)
368{
369 const struct rtnl_link_ops *ops = dev->rtnl_link_ops;
370 size_t size;
371
372 if (!ops)
373 return 0;
374
Thomas Graf369cf772010-11-11 15:47:59 +0000375 size = nla_total_size(sizeof(struct nlattr)) + /* IFLA_LINKINFO */
376 nla_total_size(strlen(ops->kind) + 1); /* IFLA_INFO_KIND */
Patrick McHardy38f7b872007-06-13 12:03:51 -0700377
378 if (ops->get_size)
379 /* IFLA_INFO_DATA + nested data */
Thomas Graf369cf772010-11-11 15:47:59 +0000380 size += nla_total_size(sizeof(struct nlattr)) +
Patrick McHardy38f7b872007-06-13 12:03:51 -0700381 ops->get_size(dev);
382
383 if (ops->get_xstats_size)
Thomas Graf369cf772010-11-11 15:47:59 +0000384 /* IFLA_INFO_XSTATS */
385 size += nla_total_size(ops->get_xstats_size(dev));
Patrick McHardy38f7b872007-06-13 12:03:51 -0700386
387 return size;
388}
389
Thomas Graff8ff1822010-11-16 04:30:14 +0000390static LIST_HEAD(rtnl_af_ops);
391
392static const struct rtnl_af_ops *rtnl_af_lookup(const int family)
393{
394 const struct rtnl_af_ops *ops;
395
396 list_for_each_entry(ops, &rtnl_af_ops, list) {
397 if (ops->family == family)
398 return ops;
399 }
400
401 return NULL;
402}
403
404/**
405 * __rtnl_af_register - Register rtnl_af_ops with rtnetlink.
406 * @ops: struct rtnl_af_ops * to register
407 *
408 * The caller must hold the rtnl_mutex.
409 *
410 * Returns 0 on success or a negative error code.
411 */
412int __rtnl_af_register(struct rtnl_af_ops *ops)
413{
414 list_add_tail(&ops->list, &rtnl_af_ops);
415 return 0;
416}
417EXPORT_SYMBOL_GPL(__rtnl_af_register);
418
419/**
420 * rtnl_af_register - Register rtnl_af_ops with rtnetlink.
421 * @ops: struct rtnl_af_ops * to register
422 *
423 * Returns 0 on success or a negative error code.
424 */
425int rtnl_af_register(struct rtnl_af_ops *ops)
426{
427 int err;
428
429 rtnl_lock();
430 err = __rtnl_af_register(ops);
431 rtnl_unlock();
432 return err;
433}
434EXPORT_SYMBOL_GPL(rtnl_af_register);
435
436/**
437 * __rtnl_af_unregister - Unregister rtnl_af_ops from rtnetlink.
438 * @ops: struct rtnl_af_ops * to unregister
439 *
440 * The caller must hold the rtnl_mutex.
441 */
442void __rtnl_af_unregister(struct rtnl_af_ops *ops)
443{
444 list_del(&ops->list);
445}
446EXPORT_SYMBOL_GPL(__rtnl_af_unregister);
447
448/**
449 * rtnl_af_unregister - Unregister rtnl_af_ops from rtnetlink.
450 * @ops: struct rtnl_af_ops * to unregister
451 */
452void rtnl_af_unregister(struct rtnl_af_ops *ops)
453{
454 rtnl_lock();
455 __rtnl_af_unregister(ops);
456 rtnl_unlock();
457}
458EXPORT_SYMBOL_GPL(rtnl_af_unregister);
459
460static size_t rtnl_link_get_af_size(const struct net_device *dev)
461{
462 struct rtnl_af_ops *af_ops;
463 size_t size;
464
465 /* IFLA_AF_SPEC */
466 size = nla_total_size(sizeof(struct nlattr));
467
468 list_for_each_entry(af_ops, &rtnl_af_ops, list) {
469 if (af_ops->get_link_af_size) {
470 /* AF_* + nested data */
471 size += nla_total_size(sizeof(struct nlattr)) +
472 af_ops->get_link_af_size(dev);
473 }
474 }
475
476 return size;
477}
478
Patrick McHardy38f7b872007-06-13 12:03:51 -0700479static int rtnl_link_fill(struct sk_buff *skb, const struct net_device *dev)
480{
481 const struct rtnl_link_ops *ops = dev->rtnl_link_ops;
482 struct nlattr *linkinfo, *data;
483 int err = -EMSGSIZE;
484
485 linkinfo = nla_nest_start(skb, IFLA_LINKINFO);
486 if (linkinfo == NULL)
487 goto out;
488
489 if (nla_put_string(skb, IFLA_INFO_KIND, ops->kind) < 0)
490 goto err_cancel_link;
491 if (ops->fill_xstats) {
492 err = ops->fill_xstats(skb, dev);
493 if (err < 0)
494 goto err_cancel_link;
495 }
496 if (ops->fill_info) {
497 data = nla_nest_start(skb, IFLA_INFO_DATA);
498 if (data == NULL)
499 goto err_cancel_link;
500 err = ops->fill_info(skb, dev);
501 if (err < 0)
502 goto err_cancel_data;
503 nla_nest_end(skb, data);
504 }
505
506 nla_nest_end(skb, linkinfo);
507 return 0;
508
509err_cancel_data:
510 nla_nest_cancel(skb, data);
511err_cancel_link:
512 nla_nest_cancel(skb, linkinfo);
513out:
514 return err;
515}
516
Thomas Grafdb46edc2005-05-03 14:29:39 -0700517static const int rtm_min[RTM_NR_FAMILIES] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518{
Thomas Graff90a0a72005-05-03 14:29:00 -0700519 [RTM_FAM(RTM_NEWLINK)] = NLMSG_LENGTH(sizeof(struct ifinfomsg)),
520 [RTM_FAM(RTM_NEWADDR)] = NLMSG_LENGTH(sizeof(struct ifaddrmsg)),
521 [RTM_FAM(RTM_NEWROUTE)] = NLMSG_LENGTH(sizeof(struct rtmsg)),
Thomas Graf14c0b972006-08-04 03:38:38 -0700522 [RTM_FAM(RTM_NEWRULE)] = NLMSG_LENGTH(sizeof(struct fib_rule_hdr)),
Thomas Graff90a0a72005-05-03 14:29:00 -0700523 [RTM_FAM(RTM_NEWQDISC)] = NLMSG_LENGTH(sizeof(struct tcmsg)),
524 [RTM_FAM(RTM_NEWTCLASS)] = NLMSG_LENGTH(sizeof(struct tcmsg)),
525 [RTM_FAM(RTM_NEWTFILTER)] = NLMSG_LENGTH(sizeof(struct tcmsg)),
526 [RTM_FAM(RTM_NEWACTION)] = NLMSG_LENGTH(sizeof(struct tcamsg)),
Thomas Graff90a0a72005-05-03 14:29:00 -0700527 [RTM_FAM(RTM_GETMULTICAST)] = NLMSG_LENGTH(sizeof(struct rtgenmsg)),
528 [RTM_FAM(RTM_GETANYCAST)] = NLMSG_LENGTH(sizeof(struct rtgenmsg)),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529};
530
Thomas Grafdb46edc2005-05-03 14:29:39 -0700531static const int rta_max[RTM_NR_FAMILIES] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532{
Thomas Graff90a0a72005-05-03 14:29:00 -0700533 [RTM_FAM(RTM_NEWLINK)] = IFLA_MAX,
534 [RTM_FAM(RTM_NEWADDR)] = IFA_MAX,
535 [RTM_FAM(RTM_NEWROUTE)] = RTA_MAX,
Thomas Graf14c0b972006-08-04 03:38:38 -0700536 [RTM_FAM(RTM_NEWRULE)] = FRA_MAX,
Thomas Graff90a0a72005-05-03 14:29:00 -0700537 [RTM_FAM(RTM_NEWQDISC)] = TCA_MAX,
538 [RTM_FAM(RTM_NEWTCLASS)] = TCA_MAX,
539 [RTM_FAM(RTM_NEWTFILTER)] = TCA_MAX,
540 [RTM_FAM(RTM_NEWACTION)] = TCAA_MAX,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541};
542
543void __rta_fill(struct sk_buff *skb, int attrtype, int attrlen, const void *data)
544{
545 struct rtattr *rta;
546 int size = RTA_LENGTH(attrlen);
547
Eric Dumazete0d087a2009-11-07 01:26:17 -0800548 rta = (struct rtattr *)skb_put(skb, RTA_ALIGN(size));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 rta->rta_type = attrtype;
550 rta->rta_len = size;
551 memcpy(RTA_DATA(rta), data, attrlen);
Patrick McHardyb3563c42005-06-28 12:54:43 -0700552 memset(RTA_DATA(rta) + attrlen, 0, RTA_ALIGN(size) - size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553}
Eric Dumazete0d087a2009-11-07 01:26:17 -0800554EXPORT_SYMBOL(__rta_fill);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
Denis V. Lunev97c53ca2007-11-19 22:26:51 -0800556int rtnetlink_send(struct sk_buff *skb, struct net *net, u32 pid, unsigned group, int echo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557{
Denis V. Lunev97c53ca2007-11-19 22:26:51 -0800558 struct sock *rtnl = net->rtnl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 int err = 0;
560
Patrick McHardyac6d4392005-08-14 19:29:52 -0700561 NETLINK_CB(skb).dst_group = group;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 if (echo)
563 atomic_inc(&skb->users);
564 netlink_broadcast(rtnl, skb, pid, group, GFP_KERNEL);
565 if (echo)
566 err = netlink_unicast(rtnl, skb, pid, MSG_DONTWAIT);
567 return err;
568}
569
Denis V. Lunev97c53ca2007-11-19 22:26:51 -0800570int rtnl_unicast(struct sk_buff *skb, struct net *net, u32 pid)
Thomas Graf2942e902006-08-15 00:30:25 -0700571{
Denis V. Lunev97c53ca2007-11-19 22:26:51 -0800572 struct sock *rtnl = net->rtnl;
573
Thomas Graf2942e902006-08-15 00:30:25 -0700574 return nlmsg_unicast(rtnl, skb, pid);
575}
Eric Dumazete0d087a2009-11-07 01:26:17 -0800576EXPORT_SYMBOL(rtnl_unicast);
Thomas Graf2942e902006-08-15 00:30:25 -0700577
Pablo Neira Ayuso1ce85fe2009-02-24 23:18:28 -0800578void rtnl_notify(struct sk_buff *skb, struct net *net, u32 pid, u32 group,
579 struct nlmsghdr *nlh, gfp_t flags)
Thomas Graf97676b62006-08-15 00:31:41 -0700580{
Denis V. Lunev97c53ca2007-11-19 22:26:51 -0800581 struct sock *rtnl = net->rtnl;
Thomas Graf97676b62006-08-15 00:31:41 -0700582 int report = 0;
583
584 if (nlh)
585 report = nlmsg_report(nlh);
586
Pablo Neira Ayuso1ce85fe2009-02-24 23:18:28 -0800587 nlmsg_notify(rtnl, skb, pid, group, report, flags);
Thomas Graf97676b62006-08-15 00:31:41 -0700588}
Eric Dumazete0d087a2009-11-07 01:26:17 -0800589EXPORT_SYMBOL(rtnl_notify);
Thomas Graf97676b62006-08-15 00:31:41 -0700590
Denis V. Lunev97c53ca2007-11-19 22:26:51 -0800591void rtnl_set_sk_err(struct net *net, u32 group, int error)
Thomas Graf97676b62006-08-15 00:31:41 -0700592{
Denis V. Lunev97c53ca2007-11-19 22:26:51 -0800593 struct sock *rtnl = net->rtnl;
594
Thomas Graf97676b62006-08-15 00:31:41 -0700595 netlink_set_err(rtnl, 0, group, error);
596}
Eric Dumazete0d087a2009-11-07 01:26:17 -0800597EXPORT_SYMBOL(rtnl_set_sk_err);
Thomas Graf97676b62006-08-15 00:31:41 -0700598
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599int rtnetlink_put_metrics(struct sk_buff *skb, u32 *metrics)
600{
Thomas Graf2d7202b2006-08-22 00:01:27 -0700601 struct nlattr *mx;
602 int i, valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603
Thomas Graf2d7202b2006-08-22 00:01:27 -0700604 mx = nla_nest_start(skb, RTA_METRICS);
605 if (mx == NULL)
606 return -ENOBUFS;
607
608 for (i = 0; i < RTAX_MAX; i++) {
609 if (metrics[i]) {
610 valid++;
David S. Millera6574342012-04-01 20:12:00 -0400611 if (nla_put_u32(skb, i+1, metrics[i]))
612 goto nla_put_failure;
Thomas Graf2d7202b2006-08-22 00:01:27 -0700613 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615
David S. Millera57d27f2006-08-22 22:20:14 -0700616 if (!valid) {
617 nla_nest_cancel(skb, mx);
618 return 0;
619 }
Thomas Graf2d7202b2006-08-22 00:01:27 -0700620
621 return nla_nest_end(skb, mx);
622
623nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -0700624 nla_nest_cancel(skb, mx);
625 return -EMSGSIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626}
Eric Dumazete0d087a2009-11-07 01:26:17 -0800627EXPORT_SYMBOL(rtnetlink_put_metrics);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628
Thomas Grafe3703b32006-11-27 09:27:07 -0800629int rtnl_put_cacheinfo(struct sk_buff *skb, struct dst_entry *dst, u32 id,
630 u32 ts, u32 tsage, long expires, u32 error)
631{
632 struct rta_cacheinfo ci = {
633 .rta_lastuse = jiffies_to_clock_t(jiffies - dst->lastuse),
634 .rta_used = dst->__use,
635 .rta_clntref = atomic_read(&(dst->__refcnt)),
636 .rta_error = error,
637 .rta_id = id,
638 .rta_ts = ts,
639 .rta_tsage = tsage,
640 };
641
642 if (expires)
643 ci.rta_expires = jiffies_to_clock_t(expires);
644
645 return nla_put(skb, RTA_CACHEINFO, sizeof(ci), &ci);
646}
Thomas Grafe3703b32006-11-27 09:27:07 -0800647EXPORT_SYMBOL_GPL(rtnl_put_cacheinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648
David S. Miller93b2d4a2008-02-17 18:35:07 -0800649static void set_operstate(struct net_device *dev, unsigned char transition)
Stefan Rompfb00055a2006-03-20 17:09:11 -0800650{
651 unsigned char operstate = dev->operstate;
652
Eric Dumazete0d087a2009-11-07 01:26:17 -0800653 switch (transition) {
Stefan Rompfb00055a2006-03-20 17:09:11 -0800654 case IF_OPER_UP:
655 if ((operstate == IF_OPER_DORMANT ||
656 operstate == IF_OPER_UNKNOWN) &&
657 !netif_dormant(dev))
658 operstate = IF_OPER_UP;
659 break;
660
661 case IF_OPER_DORMANT:
662 if (operstate == IF_OPER_UP ||
663 operstate == IF_OPER_UNKNOWN)
664 operstate = IF_OPER_DORMANT;
665 break;
Stephen Hemminger3ff50b72007-04-20 17:09:22 -0700666 }
Stefan Rompfb00055a2006-03-20 17:09:11 -0800667
668 if (dev->operstate != operstate) {
669 write_lock_bh(&dev_base_lock);
670 dev->operstate = operstate;
671 write_unlock_bh(&dev_base_lock);
David S. Miller93b2d4a2008-02-17 18:35:07 -0800672 netdev_state_change(dev);
673 }
Stefan Rompfb00055a2006-03-20 17:09:11 -0800674}
675
Patrick McHardy3729d502010-02-26 06:34:54 +0000676static unsigned int rtnl_dev_combine_flags(const struct net_device *dev,
677 const struct ifinfomsg *ifm)
678{
679 unsigned int flags = ifm->ifi_flags;
680
681 /* bugwards compatibility: ifi_change == 0 is treated as ~0 */
682 if (ifm->ifi_change)
683 flags = (flags & ifm->ifi_change) |
684 (dev->flags & ~ifm->ifi_change);
685
686 return flags;
687}
688
Thomas Grafb60c5112006-08-04 23:05:34 -0700689static void copy_rtnl_link_stats(struct rtnl_link_stats *a,
Ben Hutchingsbe1f3c22010-06-08 07:19:54 +0000690 const struct rtnl_link_stats64 *b)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691{
Thomas Grafb60c5112006-08-04 23:05:34 -0700692 a->rx_packets = b->rx_packets;
693 a->tx_packets = b->tx_packets;
694 a->rx_bytes = b->rx_bytes;
695 a->tx_bytes = b->tx_bytes;
696 a->rx_errors = b->rx_errors;
697 a->tx_errors = b->tx_errors;
698 a->rx_dropped = b->rx_dropped;
699 a->tx_dropped = b->tx_dropped;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700
Thomas Grafb60c5112006-08-04 23:05:34 -0700701 a->multicast = b->multicast;
702 a->collisions = b->collisions;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703
Thomas Grafb60c5112006-08-04 23:05:34 -0700704 a->rx_length_errors = b->rx_length_errors;
705 a->rx_over_errors = b->rx_over_errors;
706 a->rx_crc_errors = b->rx_crc_errors;
707 a->rx_frame_errors = b->rx_frame_errors;
708 a->rx_fifo_errors = b->rx_fifo_errors;
709 a->rx_missed_errors = b->rx_missed_errors;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710
Thomas Grafb60c5112006-08-04 23:05:34 -0700711 a->tx_aborted_errors = b->tx_aborted_errors;
712 a->tx_carrier_errors = b->tx_carrier_errors;
713 a->tx_fifo_errors = b->tx_fifo_errors;
714 a->tx_heartbeat_errors = b->tx_heartbeat_errors;
715 a->tx_window_errors = b->tx_window_errors;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716
Thomas Grafb60c5112006-08-04 23:05:34 -0700717 a->rx_compressed = b->rx_compressed;
718 a->tx_compressed = b->tx_compressed;
Jan Engelhardt10708f32010-03-11 09:57:29 +0000719}
720
Ben Hutchingsbe1f3c22010-06-08 07:19:54 +0000721static void copy_rtnl_link_stats64(void *v, const struct rtnl_link_stats64 *b)
Jan Engelhardt10708f32010-03-11 09:57:29 +0000722{
Eric Dumazetafdcba32010-08-23 07:14:36 +0000723 memcpy(v, b, sizeof(*b));
Jan Engelhardt10708f32010-03-11 09:57:29 +0000724}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725
Chris Wrightc02db8c2010-05-16 01:05:45 -0700726/* All VF info */
Greg Rose115c9b82012-02-21 16:54:48 -0500727static inline int rtnl_vfinfo_size(const struct net_device *dev,
728 u32 ext_filter_mask)
Williams, Mitch Aebc08a62010-02-10 01:44:05 +0000729{
Greg Rose115c9b82012-02-21 16:54:48 -0500730 if (dev->dev.parent && dev_is_pci(dev->dev.parent) &&
731 (ext_filter_mask & RTEXT_FILTER_VF)) {
Chris Wrightc02db8c2010-05-16 01:05:45 -0700732 int num_vfs = dev_num_vf(dev->dev.parent);
Scott Feldman045de012010-05-28 03:42:43 -0700733 size_t size = nla_total_size(sizeof(struct nlattr));
734 size += nla_total_size(num_vfs * sizeof(struct nlattr));
735 size += num_vfs *
736 (nla_total_size(sizeof(struct ifla_vf_mac)) +
737 nla_total_size(sizeof(struct ifla_vf_vlan)) +
Greg Rose5f8444a2011-10-08 03:05:24 +0000738 nla_total_size(sizeof(struct ifla_vf_tx_rate)) +
739 nla_total_size(sizeof(struct ifla_vf_spoofchk)));
Chris Wrightc02db8c2010-05-16 01:05:45 -0700740 return size;
741 } else
Williams, Mitch Aebc08a62010-02-10 01:44:05 +0000742 return 0;
743}
744
Scott Feldman57b61082010-05-17 22:49:55 -0700745static size_t rtnl_port_size(const struct net_device *dev)
746{
747 size_t port_size = nla_total_size(4) /* PORT_VF */
748 + nla_total_size(PORT_PROFILE_MAX) /* PORT_PROFILE */
749 + nla_total_size(sizeof(struct ifla_port_vsi))
750 /* PORT_VSI_TYPE */
751 + nla_total_size(PORT_UUID_MAX) /* PORT_INSTANCE_UUID */
752 + nla_total_size(PORT_UUID_MAX) /* PORT_HOST_UUID */
753 + nla_total_size(1) /* PROT_VDP_REQUEST */
754 + nla_total_size(2); /* PORT_VDP_RESPONSE */
755 size_t vf_ports_size = nla_total_size(sizeof(struct nlattr));
756 size_t vf_port_size = nla_total_size(sizeof(struct nlattr))
757 + port_size;
758 size_t port_self_size = nla_total_size(sizeof(struct nlattr))
759 + port_size;
760
761 if (!dev->netdev_ops->ndo_get_vf_port || !dev->dev.parent)
762 return 0;
763 if (dev_num_vf(dev->dev.parent))
764 return port_self_size + vf_ports_size +
765 vf_port_size * dev_num_vf(dev->dev.parent);
766 else
767 return port_self_size;
768}
769
Greg Rose115c9b82012-02-21 16:54:48 -0500770static noinline size_t if_nlmsg_size(const struct net_device *dev,
771 u32 ext_filter_mask)
Thomas Graf339bf982006-11-10 14:10:15 -0800772{
773 return NLMSG_ALIGN(sizeof(struct ifinfomsg))
774 + nla_total_size(IFNAMSIZ) /* IFLA_IFNAME */
Stephen Hemminger0b815a12008-09-22 21:28:11 -0700775 + nla_total_size(IFALIASZ) /* IFLA_IFALIAS */
Thomas Graf339bf982006-11-10 14:10:15 -0800776 + nla_total_size(IFNAMSIZ) /* IFLA_QDISC */
777 + nla_total_size(sizeof(struct rtnl_link_ifmap))
778 + nla_total_size(sizeof(struct rtnl_link_stats))
Jan Engelhardtadcfe192010-03-27 17:15:29 -0700779 + nla_total_size(sizeof(struct rtnl_link_stats64))
Thomas Graf339bf982006-11-10 14:10:15 -0800780 + nla_total_size(MAX_ADDR_LEN) /* IFLA_ADDRESS */
781 + nla_total_size(MAX_ADDR_LEN) /* IFLA_BROADCAST */
782 + nla_total_size(4) /* IFLA_TXQLEN */
783 + nla_total_size(4) /* IFLA_WEIGHT */
784 + nla_total_size(4) /* IFLA_MTU */
785 + nla_total_size(4) /* IFLA_LINK */
786 + nla_total_size(4) /* IFLA_MASTER */
Ben Greearedbc0bb2012-03-29 12:51:30 +0000787 + nla_total_size(4) /* IFLA_PROMISCUITY */
Thomas Graf339bf982006-11-10 14:10:15 -0800788 + nla_total_size(1) /* IFLA_OPERSTATE */
Patrick McHardy38f7b872007-06-13 12:03:51 -0700789 + nla_total_size(1) /* IFLA_LINKMODE */
Greg Rose115c9b82012-02-21 16:54:48 -0500790 + nla_total_size(ext_filter_mask
791 & RTEXT_FILTER_VF ? 4 : 0) /* IFLA_NUM_VF */
792 + rtnl_vfinfo_size(dev, ext_filter_mask) /* IFLA_VFINFO_LIST */
Scott Feldman57b61082010-05-17 22:49:55 -0700793 + rtnl_port_size(dev) /* IFLA_VF_PORTS + IFLA_PORT_SELF */
Thomas Graff8ff1822010-11-16 04:30:14 +0000794 + rtnl_link_get_size(dev) /* IFLA_LINKINFO */
795 + rtnl_link_get_af_size(dev); /* IFLA_AF_SPEC */
Thomas Graf339bf982006-11-10 14:10:15 -0800796}
797
Scott Feldman57b61082010-05-17 22:49:55 -0700798static int rtnl_vf_ports_fill(struct sk_buff *skb, struct net_device *dev)
799{
800 struct nlattr *vf_ports;
801 struct nlattr *vf_port;
802 int vf;
803 int err;
804
805 vf_ports = nla_nest_start(skb, IFLA_VF_PORTS);
806 if (!vf_ports)
807 return -EMSGSIZE;
808
809 for (vf = 0; vf < dev_num_vf(dev->dev.parent); vf++) {
810 vf_port = nla_nest_start(skb, IFLA_VF_PORT);
Scott Feldman8ca94182010-05-28 03:42:18 -0700811 if (!vf_port)
812 goto nla_put_failure;
David S. Millera6574342012-04-01 20:12:00 -0400813 if (nla_put_u32(skb, IFLA_PORT_VF, vf))
814 goto nla_put_failure;
Scott Feldman57b61082010-05-17 22:49:55 -0700815 err = dev->netdev_ops->ndo_get_vf_port(dev, vf, skb);
Scott Feldman8ca94182010-05-28 03:42:18 -0700816 if (err == -EMSGSIZE)
817 goto nla_put_failure;
Scott Feldman57b61082010-05-17 22:49:55 -0700818 if (err) {
Scott Feldman57b61082010-05-17 22:49:55 -0700819 nla_nest_cancel(skb, vf_port);
820 continue;
821 }
822 nla_nest_end(skb, vf_port);
823 }
824
825 nla_nest_end(skb, vf_ports);
826
827 return 0;
Scott Feldman8ca94182010-05-28 03:42:18 -0700828
829nla_put_failure:
830 nla_nest_cancel(skb, vf_ports);
831 return -EMSGSIZE;
Scott Feldman57b61082010-05-17 22:49:55 -0700832}
833
834static int rtnl_port_self_fill(struct sk_buff *skb, struct net_device *dev)
835{
836 struct nlattr *port_self;
837 int err;
838
839 port_self = nla_nest_start(skb, IFLA_PORT_SELF);
840 if (!port_self)
841 return -EMSGSIZE;
842
843 err = dev->netdev_ops->ndo_get_vf_port(dev, PORT_SELF_VF, skb);
844 if (err) {
845 nla_nest_cancel(skb, port_self);
Scott Feldman8ca94182010-05-28 03:42:18 -0700846 return (err == -EMSGSIZE) ? err : 0;
Scott Feldman57b61082010-05-17 22:49:55 -0700847 }
848
849 nla_nest_end(skb, port_self);
850
851 return 0;
852}
853
854static int rtnl_port_fill(struct sk_buff *skb, struct net_device *dev)
855{
856 int err;
857
858 if (!dev->netdev_ops->ndo_get_vf_port || !dev->dev.parent)
859 return 0;
860
861 err = rtnl_port_self_fill(skb, dev);
862 if (err)
863 return err;
864
865 if (dev_num_vf(dev->dev.parent)) {
866 err = rtnl_vf_ports_fill(skb, dev);
867 if (err)
868 return err;
869 }
870
871 return 0;
872}
873
Thomas Grafb60c5112006-08-04 23:05:34 -0700874static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
Patrick McHardy575c3e22007-05-22 17:00:49 -0700875 int type, u32 pid, u32 seq, u32 change,
Greg Rose115c9b82012-02-21 16:54:48 -0500876 unsigned int flags, u32 ext_filter_mask)
Thomas Grafb60c5112006-08-04 23:05:34 -0700877{
878 struct ifinfomsg *ifm;
879 struct nlmsghdr *nlh;
Eric Dumazet28172732010-07-07 14:58:56 -0700880 struct rtnl_link_stats64 temp;
Ben Hutchingsbe1f3c22010-06-08 07:19:54 +0000881 const struct rtnl_link_stats64 *stats;
Thomas Graff8ff1822010-11-16 04:30:14 +0000882 struct nlattr *attr, *af_spec;
883 struct rtnl_af_ops *af_ops;
Thomas Grafb60c5112006-08-04 23:05:34 -0700884
Eric Dumazet2907c352011-05-25 07:34:04 +0000885 ASSERT_RTNL();
Thomas Grafb60c5112006-08-04 23:05:34 -0700886 nlh = nlmsg_put(skb, pid, seq, type, sizeof(*ifm), flags);
887 if (nlh == NULL)
Patrick McHardy26932562007-01-31 23:16:40 -0800888 return -EMSGSIZE;
Thomas Grafb60c5112006-08-04 23:05:34 -0700889
890 ifm = nlmsg_data(nlh);
891 ifm->ifi_family = AF_UNSPEC;
892 ifm->__ifi_pad = 0;
893 ifm->ifi_type = dev->type;
894 ifm->ifi_index = dev->ifindex;
895 ifm->ifi_flags = dev_get_flags(dev);
896 ifm->ifi_change = change;
897
David S. Millera6574342012-04-01 20:12:00 -0400898 if (nla_put_string(skb, IFLA_IFNAME, dev->name) ||
899 nla_put_u32(skb, IFLA_TXQLEN, dev->tx_queue_len) ||
900 nla_put_u8(skb, IFLA_OPERSTATE,
901 netif_running(dev) ? dev->operstate : IF_OPER_DOWN) ||
902 nla_put_u8(skb, IFLA_LINKMODE, dev->link_mode) ||
903 nla_put_u32(skb, IFLA_MTU, dev->mtu) ||
904 nla_put_u32(skb, IFLA_GROUP, dev->group) ||
Ben Greearedbc0bb2012-03-29 12:51:30 +0000905 nla_put_u32(skb, IFLA_PROMISCUITY, dev->promiscuity) ||
David S. Millera6574342012-04-01 20:12:00 -0400906 (dev->ifindex != dev->iflink &&
907 nla_put_u32(skb, IFLA_LINK, dev->iflink)) ||
908 (dev->master &&
909 nla_put_u32(skb, IFLA_MASTER, dev->master->ifindex)) ||
910 (dev->qdisc &&
911 nla_put_string(skb, IFLA_QDISC, dev->qdisc->ops->id)) ||
912 (dev->ifalias &&
913 nla_put_string(skb, IFLA_IFALIAS, dev->ifalias)))
914 goto nla_put_failure;
Stephen Hemminger0b815a12008-09-22 21:28:11 -0700915
Stefan Rompfb00055a2006-03-20 17:09:11 -0800916 if (1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 struct rtnl_link_ifmap map = {
918 .mem_start = dev->mem_start,
919 .mem_end = dev->mem_end,
920 .base_addr = dev->base_addr,
921 .irq = dev->irq,
922 .dma = dev->dma,
923 .port = dev->if_port,
924 };
David S. Millera6574342012-04-01 20:12:00 -0400925 if (nla_put(skb, IFLA_MAP, sizeof(map), &map))
926 goto nla_put_failure;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 }
928
929 if (dev->addr_len) {
David S. Millera6574342012-04-01 20:12:00 -0400930 if (nla_put(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr) ||
931 nla_put(skb, IFLA_BROADCAST, dev->addr_len, dev->broadcast))
932 goto nla_put_failure;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 }
934
Pavel Emelyanov96e74082008-05-21 14:12:46 -0700935 attr = nla_reserve(skb, IFLA_STATS,
936 sizeof(struct rtnl_link_stats));
937 if (attr == NULL)
938 goto nla_put_failure;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939
Eric Dumazet28172732010-07-07 14:58:56 -0700940 stats = dev_get_stats(dev, &temp);
Pavel Emelyanov96e74082008-05-21 14:12:46 -0700941 copy_rtnl_link_stats(nla_data(attr), stats);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942
Jan Engelhardt10708f32010-03-11 09:57:29 +0000943 attr = nla_reserve(skb, IFLA_STATS64,
944 sizeof(struct rtnl_link_stats64));
945 if (attr == NULL)
946 goto nla_put_failure;
Jan Engelhardt10708f32010-03-11 09:57:29 +0000947 copy_rtnl_link_stats64(nla_data(attr), stats);
948
David S. Millera6574342012-04-01 20:12:00 -0400949 if (dev->dev.parent && (ext_filter_mask & RTEXT_FILTER_VF) &&
950 nla_put_u32(skb, IFLA_NUM_VF, dev_num_vf(dev->dev.parent)))
951 goto nla_put_failure;
Scott Feldman57b61082010-05-17 22:49:55 -0700952
Greg Rose115c9b82012-02-21 16:54:48 -0500953 if (dev->netdev_ops->ndo_get_vf_config && dev->dev.parent
954 && (ext_filter_mask & RTEXT_FILTER_VF)) {
Williams, Mitch Aebc08a62010-02-10 01:44:05 +0000955 int i;
Williams, Mitch Aebc08a62010-02-10 01:44:05 +0000956
Chris Wrightc02db8c2010-05-16 01:05:45 -0700957 struct nlattr *vfinfo, *vf;
958 int num_vfs = dev_num_vf(dev->dev.parent);
959
Chris Wrightc02db8c2010-05-16 01:05:45 -0700960 vfinfo = nla_nest_start(skb, IFLA_VFINFO_LIST);
961 if (!vfinfo)
962 goto nla_put_failure;
963 for (i = 0; i < num_vfs; i++) {
964 struct ifla_vf_info ivi;
965 struct ifla_vf_mac vf_mac;
966 struct ifla_vf_vlan vf_vlan;
967 struct ifla_vf_tx_rate vf_tx_rate;
Greg Rose5f8444a2011-10-08 03:05:24 +0000968 struct ifla_vf_spoofchk vf_spoofchk;
969
970 /*
971 * Not all SR-IOV capable drivers support the
972 * spoofcheck query. Preset to -1 so the user
973 * space tool can detect that the driver didn't
974 * report anything.
975 */
976 ivi.spoofchk = -1;
Williams, Mitch Aebc08a62010-02-10 01:44:05 +0000977 if (dev->netdev_ops->ndo_get_vf_config(dev, i, &ivi))
978 break;
Greg Rose5f8444a2011-10-08 03:05:24 +0000979 vf_mac.vf =
980 vf_vlan.vf =
981 vf_tx_rate.vf =
982 vf_spoofchk.vf = ivi.vf;
983
Chris Wrightc02db8c2010-05-16 01:05:45 -0700984 memcpy(vf_mac.mac, ivi.mac, sizeof(ivi.mac));
985 vf_vlan.vlan = ivi.vlan;
986 vf_vlan.qos = ivi.qos;
987 vf_tx_rate.rate = ivi.tx_rate;
Greg Rose5f8444a2011-10-08 03:05:24 +0000988 vf_spoofchk.setting = ivi.spoofchk;
Chris Wrightc02db8c2010-05-16 01:05:45 -0700989 vf = nla_nest_start(skb, IFLA_VF_INFO);
990 if (!vf) {
991 nla_nest_cancel(skb, vfinfo);
992 goto nla_put_failure;
993 }
David S. Millera6574342012-04-01 20:12:00 -0400994 if (nla_put(skb, IFLA_VF_MAC, sizeof(vf_mac), &vf_mac) ||
995 nla_put(skb, IFLA_VF_VLAN, sizeof(vf_vlan), &vf_vlan) ||
996 nla_put(skb, IFLA_VF_TX_RATE, sizeof(vf_tx_rate),
997 &vf_tx_rate) ||
998 nla_put(skb, IFLA_VF_SPOOFCHK, sizeof(vf_spoofchk),
999 &vf_spoofchk))
1000 goto nla_put_failure;
Chris Wrightc02db8c2010-05-16 01:05:45 -07001001 nla_nest_end(skb, vf);
Williams, Mitch Aebc08a62010-02-10 01:44:05 +00001002 }
Chris Wrightc02db8c2010-05-16 01:05:45 -07001003 nla_nest_end(skb, vfinfo);
Williams, Mitch Aebc08a62010-02-10 01:44:05 +00001004 }
Scott Feldman57b61082010-05-17 22:49:55 -07001005
1006 if (rtnl_port_fill(skb, dev))
1007 goto nla_put_failure;
1008
Patrick McHardy38f7b872007-06-13 12:03:51 -07001009 if (dev->rtnl_link_ops) {
1010 if (rtnl_link_fill(skb, dev) < 0)
1011 goto nla_put_failure;
1012 }
1013
Thomas Graff8ff1822010-11-16 04:30:14 +00001014 if (!(af_spec = nla_nest_start(skb, IFLA_AF_SPEC)))
1015 goto nla_put_failure;
1016
1017 list_for_each_entry(af_ops, &rtnl_af_ops, list) {
1018 if (af_ops->fill_link_af) {
1019 struct nlattr *af;
1020 int err;
1021
1022 if (!(af = nla_nest_start(skb, af_ops->family)))
1023 goto nla_put_failure;
1024
1025 err = af_ops->fill_link_af(skb, dev);
1026
1027 /*
1028 * Caller may return ENODATA to indicate that there
1029 * was no data to be dumped. This is not an error, it
1030 * means we should trim the attribute header and
1031 * continue.
1032 */
1033 if (err == -ENODATA)
1034 nla_nest_cancel(skb, af);
1035 else if (err < 0)
1036 goto nla_put_failure;
1037
1038 nla_nest_end(skb, af);
1039 }
1040 }
1041
1042 nla_nest_end(skb, af_spec);
1043
Thomas Grafb60c5112006-08-04 23:05:34 -07001044 return nlmsg_end(skb, nlh);
1045
1046nla_put_failure:
Patrick McHardy26932562007-01-31 23:16:40 -08001047 nlmsg_cancel(skb, nlh);
1048 return -EMSGSIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049}
1050
Thomas Grafb60c5112006-08-04 23:05:34 -07001051static int rtnl_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052{
YOSHIFUJI Hideaki3b1e0a62008-03-26 02:26:21 +09001053 struct net *net = sock_net(skb->sk);
Eric Dumazet7c28bd02009-10-24 06:13:17 -07001054 int h, s_h;
1055 int idx = 0, s_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 struct net_device *dev;
Eric Dumazet7c28bd02009-10-24 06:13:17 -07001057 struct hlist_head *head;
1058 struct hlist_node *node;
Greg Rose115c9b82012-02-21 16:54:48 -05001059 struct nlattr *tb[IFLA_MAX+1];
1060 u32 ext_filter_mask = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061
Eric Dumazet7c28bd02009-10-24 06:13:17 -07001062 s_h = cb->args[0];
1063 s_idx = cb->args[1];
1064
Eric Dumazete67f88d2011-04-27 22:56:07 +00001065 rcu_read_lock();
Thomas Graf4e985ad2011-06-21 03:11:20 +00001066 cb->seq = net->dev_base_seq;
1067
Eric Dumazeta4b64fb2012-03-04 12:32:10 +00001068 if (nlmsg_parse(cb->nlh, sizeof(struct rtgenmsg), tb, IFLA_MAX,
1069 ifla_policy) >= 0) {
Greg Rose115c9b82012-02-21 16:54:48 -05001070
Eric Dumazeta4b64fb2012-03-04 12:32:10 +00001071 if (tb[IFLA_EXT_MASK])
1072 ext_filter_mask = nla_get_u32(tb[IFLA_EXT_MASK]);
1073 }
Greg Rose115c9b82012-02-21 16:54:48 -05001074
Eric Dumazet7c28bd02009-10-24 06:13:17 -07001075 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
1076 idx = 0;
1077 head = &net->dev_index_head[h];
Eric Dumazete67f88d2011-04-27 22:56:07 +00001078 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
Eric Dumazet7c28bd02009-10-24 06:13:17 -07001079 if (idx < s_idx)
1080 goto cont;
1081 if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
1082 NETLINK_CB(cb->skb).pid,
1083 cb->nlh->nlmsg_seq, 0,
Greg Rose115c9b82012-02-21 16:54:48 -05001084 NLM_F_MULTI,
1085 ext_filter_mask) <= 0)
Eric Dumazet7c28bd02009-10-24 06:13:17 -07001086 goto out;
Thomas Graf4e985ad2011-06-21 03:11:20 +00001087
1088 nl_dump_check_consistent(cb, nlmsg_hdr(skb));
Pavel Emelianov7562f872007-05-03 15:13:45 -07001089cont:
Eric Dumazet7c28bd02009-10-24 06:13:17 -07001090 idx++;
1091 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 }
Eric Dumazet7c28bd02009-10-24 06:13:17 -07001093out:
Eric Dumazete67f88d2011-04-27 22:56:07 +00001094 rcu_read_unlock();
Eric Dumazet7c28bd02009-10-24 06:13:17 -07001095 cb->args[1] = idx;
1096 cb->args[0] = h;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097
1098 return skb->len;
1099}
1100
Pavel Emelianove7199282007-08-08 22:16:38 -07001101const struct nla_policy ifla_policy[IFLA_MAX+1] = {
Thomas Graf5176f912006-08-26 20:13:18 -07001102 [IFLA_IFNAME] = { .type = NLA_STRING, .len = IFNAMSIZ-1 },
Patrick McHardy38f7b872007-06-13 12:03:51 -07001103 [IFLA_ADDRESS] = { .type = NLA_BINARY, .len = MAX_ADDR_LEN },
1104 [IFLA_BROADCAST] = { .type = NLA_BINARY, .len = MAX_ADDR_LEN },
Thomas Graf5176f912006-08-26 20:13:18 -07001105 [IFLA_MAP] = { .len = sizeof(struct rtnl_link_ifmap) },
Thomas Grafda5e0492006-08-10 21:17:37 -07001106 [IFLA_MTU] = { .type = NLA_U32 },
Thomas Graf76e87302008-02-19 16:12:08 -08001107 [IFLA_LINK] = { .type = NLA_U32 },
Jiri Pirkofbaec0e2011-02-13 10:15:37 +00001108 [IFLA_MASTER] = { .type = NLA_U32 },
Thomas Grafda5e0492006-08-10 21:17:37 -07001109 [IFLA_TXQLEN] = { .type = NLA_U32 },
1110 [IFLA_WEIGHT] = { .type = NLA_U32 },
1111 [IFLA_OPERSTATE] = { .type = NLA_U8 },
1112 [IFLA_LINKMODE] = { .type = NLA_U8 },
Thomas Graf76e87302008-02-19 16:12:08 -08001113 [IFLA_LINKINFO] = { .type = NLA_NESTED },
Eric W. Biedermand8a5ec62007-09-12 13:57:04 +02001114 [IFLA_NET_NS_PID] = { .type = NLA_U32 },
Eric W. Biedermanf0630522011-05-04 17:51:50 -07001115 [IFLA_NET_NS_FD] = { .type = NLA_U32 },
Stephen Hemminger0b815a12008-09-22 21:28:11 -07001116 [IFLA_IFALIAS] = { .type = NLA_STRING, .len = IFALIASZ-1 },
Chris Wrightc02db8c2010-05-16 01:05:45 -07001117 [IFLA_VFINFO_LIST] = {. type = NLA_NESTED },
Scott Feldman57b61082010-05-17 22:49:55 -07001118 [IFLA_VF_PORTS] = { .type = NLA_NESTED },
1119 [IFLA_PORT_SELF] = { .type = NLA_NESTED },
Thomas Graff8ff1822010-11-16 04:30:14 +00001120 [IFLA_AF_SPEC] = { .type = NLA_NESTED },
Greg Rose115c9b82012-02-21 16:54:48 -05001121 [IFLA_EXT_MASK] = { .type = NLA_U32 },
Ben Greearedbc0bb2012-03-29 12:51:30 +00001122 [IFLA_PROMISCUITY] = { .type = NLA_U32 },
Thomas Grafda5e0492006-08-10 21:17:37 -07001123};
Eric Dumazete0d087a2009-11-07 01:26:17 -08001124EXPORT_SYMBOL(ifla_policy);
Thomas Grafda5e0492006-08-10 21:17:37 -07001125
Patrick McHardy38f7b872007-06-13 12:03:51 -07001126static const struct nla_policy ifla_info_policy[IFLA_INFO_MAX+1] = {
1127 [IFLA_INFO_KIND] = { .type = NLA_STRING },
1128 [IFLA_INFO_DATA] = { .type = NLA_NESTED },
1129};
1130
Chris Wrightc02db8c2010-05-16 01:05:45 -07001131static const struct nla_policy ifla_vfinfo_policy[IFLA_VF_INFO_MAX+1] = {
1132 [IFLA_VF_INFO] = { .type = NLA_NESTED },
1133};
1134
1135static const struct nla_policy ifla_vf_policy[IFLA_VF_MAX+1] = {
1136 [IFLA_VF_MAC] = { .type = NLA_BINARY,
1137 .len = sizeof(struct ifla_vf_mac) },
1138 [IFLA_VF_VLAN] = { .type = NLA_BINARY,
1139 .len = sizeof(struct ifla_vf_vlan) },
1140 [IFLA_VF_TX_RATE] = { .type = NLA_BINARY,
1141 .len = sizeof(struct ifla_vf_tx_rate) },
Greg Rose48752f62012-02-08 00:45:00 +00001142 [IFLA_VF_SPOOFCHK] = { .type = NLA_BINARY,
1143 .len = sizeof(struct ifla_vf_spoofchk) },
Chris Wrightc02db8c2010-05-16 01:05:45 -07001144};
1145
Scott Feldman57b61082010-05-17 22:49:55 -07001146static const struct nla_policy ifla_port_policy[IFLA_PORT_MAX+1] = {
1147 [IFLA_PORT_VF] = { .type = NLA_U32 },
1148 [IFLA_PORT_PROFILE] = { .type = NLA_STRING,
1149 .len = PORT_PROFILE_MAX },
1150 [IFLA_PORT_VSI_TYPE] = { .type = NLA_BINARY,
1151 .len = sizeof(struct ifla_port_vsi)},
1152 [IFLA_PORT_INSTANCE_UUID] = { .type = NLA_BINARY,
1153 .len = PORT_UUID_MAX },
1154 [IFLA_PORT_HOST_UUID] = { .type = NLA_STRING,
1155 .len = PORT_UUID_MAX },
1156 [IFLA_PORT_REQUEST] = { .type = NLA_U8, },
1157 [IFLA_PORT_RESPONSE] = { .type = NLA_U16, },
1158};
1159
Eric W. Biederman81adee42009-11-08 00:53:51 -08001160struct net *rtnl_link_get_net(struct net *src_net, struct nlattr *tb[])
1161{
1162 struct net *net;
1163 /* Examine the link attributes and figure out which
1164 * network namespace we are talking about.
1165 */
1166 if (tb[IFLA_NET_NS_PID])
1167 net = get_net_ns_by_pid(nla_get_u32(tb[IFLA_NET_NS_PID]));
Eric W. Biedermanf0630522011-05-04 17:51:50 -07001168 else if (tb[IFLA_NET_NS_FD])
1169 net = get_net_ns_by_fd(nla_get_u32(tb[IFLA_NET_NS_FD]));
Eric W. Biederman81adee42009-11-08 00:53:51 -08001170 else
1171 net = get_net(src_net);
1172 return net;
1173}
1174EXPORT_SYMBOL(rtnl_link_get_net);
1175
Thomas Graf1840bb12008-02-23 19:54:36 -08001176static int validate_linkmsg(struct net_device *dev, struct nlattr *tb[])
1177{
1178 if (dev) {
1179 if (tb[IFLA_ADDRESS] &&
1180 nla_len(tb[IFLA_ADDRESS]) < dev->addr_len)
1181 return -EINVAL;
1182
1183 if (tb[IFLA_BROADCAST] &&
1184 nla_len(tb[IFLA_BROADCAST]) < dev->addr_len)
1185 return -EINVAL;
1186 }
1187
Thomas Grafcf7afbf2010-11-22 01:31:54 +00001188 if (tb[IFLA_AF_SPEC]) {
1189 struct nlattr *af;
1190 int rem, err;
1191
1192 nla_for_each_nested(af, tb[IFLA_AF_SPEC], rem) {
1193 const struct rtnl_af_ops *af_ops;
1194
1195 if (!(af_ops = rtnl_af_lookup(nla_type(af))))
1196 return -EAFNOSUPPORT;
1197
1198 if (!af_ops->set_link_af)
1199 return -EOPNOTSUPP;
1200
1201 if (af_ops->validate_link_af) {
Kurt Van Dijck6d3a9a62011-01-26 04:55:24 +00001202 err = af_ops->validate_link_af(dev, af);
Thomas Grafcf7afbf2010-11-22 01:31:54 +00001203 if (err < 0)
1204 return err;
1205 }
1206 }
1207 }
1208
Thomas Graf1840bb12008-02-23 19:54:36 -08001209 return 0;
1210}
1211
Chris Wrightc02db8c2010-05-16 01:05:45 -07001212static int do_setvfinfo(struct net_device *dev, struct nlattr *attr)
1213{
1214 int rem, err = -EINVAL;
1215 struct nlattr *vf;
1216 const struct net_device_ops *ops = dev->netdev_ops;
1217
1218 nla_for_each_nested(vf, attr, rem) {
1219 switch (nla_type(vf)) {
1220 case IFLA_VF_MAC: {
1221 struct ifla_vf_mac *ivm;
1222 ivm = nla_data(vf);
1223 err = -EOPNOTSUPP;
1224 if (ops->ndo_set_vf_mac)
1225 err = ops->ndo_set_vf_mac(dev, ivm->vf,
1226 ivm->mac);
1227 break;
1228 }
1229 case IFLA_VF_VLAN: {
1230 struct ifla_vf_vlan *ivv;
1231 ivv = nla_data(vf);
1232 err = -EOPNOTSUPP;
1233 if (ops->ndo_set_vf_vlan)
1234 err = ops->ndo_set_vf_vlan(dev, ivv->vf,
1235 ivv->vlan,
1236 ivv->qos);
1237 break;
1238 }
1239 case IFLA_VF_TX_RATE: {
1240 struct ifla_vf_tx_rate *ivt;
1241 ivt = nla_data(vf);
1242 err = -EOPNOTSUPP;
1243 if (ops->ndo_set_vf_tx_rate)
1244 err = ops->ndo_set_vf_tx_rate(dev, ivt->vf,
1245 ivt->rate);
1246 break;
1247 }
Greg Rose5f8444a2011-10-08 03:05:24 +00001248 case IFLA_VF_SPOOFCHK: {
1249 struct ifla_vf_spoofchk *ivs;
1250 ivs = nla_data(vf);
1251 err = -EOPNOTSUPP;
1252 if (ops->ndo_set_vf_spoofchk)
1253 err = ops->ndo_set_vf_spoofchk(dev, ivs->vf,
1254 ivs->setting);
1255 break;
1256 }
Chris Wrightc02db8c2010-05-16 01:05:45 -07001257 default:
1258 err = -EINVAL;
1259 break;
1260 }
1261 if (err)
1262 break;
1263 }
1264 return err;
1265}
1266
Jiri Pirkofbaec0e2011-02-13 10:15:37 +00001267static int do_set_master(struct net_device *dev, int ifindex)
1268{
1269 struct net_device *master_dev;
1270 const struct net_device_ops *ops;
1271 int err;
1272
1273 if (dev->master) {
1274 if (dev->master->ifindex == ifindex)
1275 return 0;
1276 ops = dev->master->netdev_ops;
1277 if (ops->ndo_del_slave) {
1278 err = ops->ndo_del_slave(dev->master, dev);
1279 if (err)
1280 return err;
1281 } else {
1282 return -EOPNOTSUPP;
1283 }
1284 }
1285
1286 if (ifindex) {
1287 master_dev = __dev_get_by_index(dev_net(dev), ifindex);
1288 if (!master_dev)
1289 return -EINVAL;
1290 ops = master_dev->netdev_ops;
1291 if (ops->ndo_add_slave) {
1292 err = ops->ndo_add_slave(master_dev, dev);
1293 if (err)
1294 return err;
1295 } else {
1296 return -EOPNOTSUPP;
1297 }
1298 }
1299 return 0;
1300}
1301
Patrick McHardy0157f602007-06-13 12:03:36 -07001302static int do_setlink(struct net_device *dev, struct ifinfomsg *ifm,
Patrick McHardy38f7b872007-06-13 12:03:51 -07001303 struct nlattr **tb, char *ifname, int modified)
Patrick McHardy0157f602007-06-13 12:03:36 -07001304{
Stephen Hemmingerd3147742008-11-19 21:32:24 -08001305 const struct net_device_ops *ops = dev->netdev_ops;
Patrick McHardy38f7b872007-06-13 12:03:51 -07001306 int send_addr_notify = 0;
Patrick McHardy0157f602007-06-13 12:03:36 -07001307 int err;
1308
Eric W. Biedermanf0630522011-05-04 17:51:50 -07001309 if (tb[IFLA_NET_NS_PID] || tb[IFLA_NET_NS_FD]) {
Eric W. Biederman81adee42009-11-08 00:53:51 -08001310 struct net *net = rtnl_link_get_net(dev_net(dev), tb);
Eric W. Biedermand8a5ec62007-09-12 13:57:04 +02001311 if (IS_ERR(net)) {
1312 err = PTR_ERR(net);
1313 goto errout;
1314 }
1315 err = dev_change_net_namespace(dev, net, ifname);
1316 put_net(net);
1317 if (err)
1318 goto errout;
1319 modified = 1;
1320 }
1321
Patrick McHardy0157f602007-06-13 12:03:36 -07001322 if (tb[IFLA_MAP]) {
1323 struct rtnl_link_ifmap *u_map;
1324 struct ifmap k_map;
1325
Stephen Hemmingerd3147742008-11-19 21:32:24 -08001326 if (!ops->ndo_set_config) {
Patrick McHardy0157f602007-06-13 12:03:36 -07001327 err = -EOPNOTSUPP;
1328 goto errout;
1329 }
1330
1331 if (!netif_device_present(dev)) {
1332 err = -ENODEV;
1333 goto errout;
1334 }
1335
1336 u_map = nla_data(tb[IFLA_MAP]);
1337 k_map.mem_start = (unsigned long) u_map->mem_start;
1338 k_map.mem_end = (unsigned long) u_map->mem_end;
1339 k_map.base_addr = (unsigned short) u_map->base_addr;
1340 k_map.irq = (unsigned char) u_map->irq;
1341 k_map.dma = (unsigned char) u_map->dma;
1342 k_map.port = (unsigned char) u_map->port;
1343
Stephen Hemmingerd3147742008-11-19 21:32:24 -08001344 err = ops->ndo_set_config(dev, &k_map);
Patrick McHardy0157f602007-06-13 12:03:36 -07001345 if (err < 0)
1346 goto errout;
1347
1348 modified = 1;
1349 }
1350
1351 if (tb[IFLA_ADDRESS]) {
1352 struct sockaddr *sa;
1353 int len;
1354
Stephen Hemmingerd3147742008-11-19 21:32:24 -08001355 if (!ops->ndo_set_mac_address) {
Patrick McHardy0157f602007-06-13 12:03:36 -07001356 err = -EOPNOTSUPP;
1357 goto errout;
1358 }
1359
1360 if (!netif_device_present(dev)) {
1361 err = -ENODEV;
1362 goto errout;
1363 }
1364
1365 len = sizeof(sa_family_t) + dev->addr_len;
1366 sa = kmalloc(len, GFP_KERNEL);
1367 if (!sa) {
1368 err = -ENOMEM;
1369 goto errout;
1370 }
1371 sa->sa_family = dev->type;
1372 memcpy(sa->sa_data, nla_data(tb[IFLA_ADDRESS]),
1373 dev->addr_len);
Stephen Hemmingerd3147742008-11-19 21:32:24 -08001374 err = ops->ndo_set_mac_address(dev, sa);
Patrick McHardy0157f602007-06-13 12:03:36 -07001375 kfree(sa);
1376 if (err)
1377 goto errout;
1378 send_addr_notify = 1;
1379 modified = 1;
1380 }
1381
1382 if (tb[IFLA_MTU]) {
1383 err = dev_set_mtu(dev, nla_get_u32(tb[IFLA_MTU]));
1384 if (err < 0)
1385 goto errout;
1386 modified = 1;
1387 }
1388
Vlad Dogarucbda10f2011-01-13 23:38:30 +00001389 if (tb[IFLA_GROUP]) {
1390 dev_set_group(dev, nla_get_u32(tb[IFLA_GROUP]));
1391 modified = 1;
1392 }
1393
Patrick McHardy0157f602007-06-13 12:03:36 -07001394 /*
1395 * Interface selected by interface index but interface
1396 * name provided implies that a name change has been
1397 * requested.
1398 */
1399 if (ifm->ifi_index > 0 && ifname[0]) {
1400 err = dev_change_name(dev, ifname);
1401 if (err < 0)
1402 goto errout;
1403 modified = 1;
1404 }
1405
Stephen Hemminger0b815a12008-09-22 21:28:11 -07001406 if (tb[IFLA_IFALIAS]) {
1407 err = dev_set_alias(dev, nla_data(tb[IFLA_IFALIAS]),
1408 nla_len(tb[IFLA_IFALIAS]));
1409 if (err < 0)
1410 goto errout;
1411 modified = 1;
1412 }
1413
Patrick McHardy0157f602007-06-13 12:03:36 -07001414 if (tb[IFLA_BROADCAST]) {
1415 nla_memcpy(dev->broadcast, tb[IFLA_BROADCAST], dev->addr_len);
1416 send_addr_notify = 1;
1417 }
1418
1419 if (ifm->ifi_flags || ifm->ifi_change) {
Patrick McHardy3729d502010-02-26 06:34:54 +00001420 err = dev_change_flags(dev, rtnl_dev_combine_flags(dev, ifm));
Johannes Berg5f9021c2008-11-16 23:20:31 -08001421 if (err < 0)
1422 goto errout;
Patrick McHardy0157f602007-06-13 12:03:36 -07001423 }
1424
Jiri Pirkofbaec0e2011-02-13 10:15:37 +00001425 if (tb[IFLA_MASTER]) {
1426 err = do_set_master(dev, nla_get_u32(tb[IFLA_MASTER]));
1427 if (err)
1428 goto errout;
1429 modified = 1;
1430 }
1431
David S. Miller93b2d4a2008-02-17 18:35:07 -08001432 if (tb[IFLA_TXQLEN])
1433 dev->tx_queue_len = nla_get_u32(tb[IFLA_TXQLEN]);
Patrick McHardy0157f602007-06-13 12:03:36 -07001434
Patrick McHardy0157f602007-06-13 12:03:36 -07001435 if (tb[IFLA_OPERSTATE])
David S. Miller93b2d4a2008-02-17 18:35:07 -08001436 set_operstate(dev, nla_get_u8(tb[IFLA_OPERSTATE]));
Patrick McHardy0157f602007-06-13 12:03:36 -07001437
1438 if (tb[IFLA_LINKMODE]) {
David S. Miller93b2d4a2008-02-17 18:35:07 -08001439 write_lock_bh(&dev_base_lock);
1440 dev->link_mode = nla_get_u8(tb[IFLA_LINKMODE]);
1441 write_unlock_bh(&dev_base_lock);
Patrick McHardy0157f602007-06-13 12:03:36 -07001442 }
1443
Chris Wrightc02db8c2010-05-16 01:05:45 -07001444 if (tb[IFLA_VFINFO_LIST]) {
1445 struct nlattr *attr;
1446 int rem;
1447 nla_for_each_nested(attr, tb[IFLA_VFINFO_LIST], rem) {
David Howells253683b2010-05-21 02:25:27 +00001448 if (nla_type(attr) != IFLA_VF_INFO) {
1449 err = -EINVAL;
Chris Wrightc02db8c2010-05-16 01:05:45 -07001450 goto errout;
David Howells253683b2010-05-21 02:25:27 +00001451 }
Chris Wrightc02db8c2010-05-16 01:05:45 -07001452 err = do_setvfinfo(dev, attr);
1453 if (err < 0)
1454 goto errout;
1455 modified = 1;
1456 }
Williams, Mitch Aebc08a62010-02-10 01:44:05 +00001457 }
Patrick McHardy0157f602007-06-13 12:03:36 -07001458 err = 0;
1459
Scott Feldman57b61082010-05-17 22:49:55 -07001460 if (tb[IFLA_VF_PORTS]) {
1461 struct nlattr *port[IFLA_PORT_MAX+1];
1462 struct nlattr *attr;
1463 int vf;
1464 int rem;
1465
1466 err = -EOPNOTSUPP;
1467 if (!ops->ndo_set_vf_port)
1468 goto errout;
1469
1470 nla_for_each_nested(attr, tb[IFLA_VF_PORTS], rem) {
1471 if (nla_type(attr) != IFLA_VF_PORT)
1472 continue;
1473 err = nla_parse_nested(port, IFLA_PORT_MAX,
1474 attr, ifla_port_policy);
1475 if (err < 0)
1476 goto errout;
1477 if (!port[IFLA_PORT_VF]) {
1478 err = -EOPNOTSUPP;
1479 goto errout;
1480 }
1481 vf = nla_get_u32(port[IFLA_PORT_VF]);
1482 err = ops->ndo_set_vf_port(dev, vf, port);
1483 if (err < 0)
1484 goto errout;
1485 modified = 1;
1486 }
1487 }
1488 err = 0;
1489
1490 if (tb[IFLA_PORT_SELF]) {
1491 struct nlattr *port[IFLA_PORT_MAX+1];
1492
1493 err = nla_parse_nested(port, IFLA_PORT_MAX,
1494 tb[IFLA_PORT_SELF], ifla_port_policy);
1495 if (err < 0)
1496 goto errout;
1497
1498 err = -EOPNOTSUPP;
1499 if (ops->ndo_set_vf_port)
1500 err = ops->ndo_set_vf_port(dev, PORT_SELF_VF, port);
1501 if (err < 0)
1502 goto errout;
1503 modified = 1;
1504 }
Thomas Graff8ff1822010-11-16 04:30:14 +00001505
1506 if (tb[IFLA_AF_SPEC]) {
1507 struct nlattr *af;
1508 int rem;
1509
1510 nla_for_each_nested(af, tb[IFLA_AF_SPEC], rem) {
1511 const struct rtnl_af_ops *af_ops;
1512
1513 if (!(af_ops = rtnl_af_lookup(nla_type(af))))
Thomas Grafcf7afbf2010-11-22 01:31:54 +00001514 BUG();
Thomas Graff8ff1822010-11-16 04:30:14 +00001515
Thomas Grafcf7afbf2010-11-22 01:31:54 +00001516 err = af_ops->set_link_af(dev, af);
Thomas Graff8ff1822010-11-16 04:30:14 +00001517 if (err < 0)
1518 goto errout;
1519
1520 modified = 1;
1521 }
1522 }
Scott Feldman57b61082010-05-17 22:49:55 -07001523 err = 0;
1524
Patrick McHardy0157f602007-06-13 12:03:36 -07001525errout:
1526 if (err < 0 && modified && net_ratelimit())
1527 printk(KERN_WARNING "A link change request failed with "
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001528 "some changes committed already. Interface %s may "
Patrick McHardy0157f602007-06-13 12:03:36 -07001529 "have been left with an inconsistent configuration, "
1530 "please check.\n", dev->name);
1531
1532 if (send_addr_notify)
1533 call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
Stefan Gulaf18da142012-01-26 11:01:06 +00001534
Patrick McHardy0157f602007-06-13 12:03:36 -07001535 return err;
1536}
1537
Thomas Grafda5e0492006-08-10 21:17:37 -07001538static int rtnl_setlink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539{
YOSHIFUJI Hideaki3b1e0a62008-03-26 02:26:21 +09001540 struct net *net = sock_net(skb->sk);
Thomas Grafda5e0492006-08-10 21:17:37 -07001541 struct ifinfomsg *ifm;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 struct net_device *dev;
Patrick McHardy0157f602007-06-13 12:03:36 -07001543 int err;
Thomas Grafda5e0492006-08-10 21:17:37 -07001544 struct nlattr *tb[IFLA_MAX+1];
1545 char ifname[IFNAMSIZ];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546
Thomas Grafda5e0492006-08-10 21:17:37 -07001547 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFLA_MAX, ifla_policy);
1548 if (err < 0)
1549 goto errout;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550
Thomas Graf5176f912006-08-26 20:13:18 -07001551 if (tb[IFLA_IFNAME])
1552 nla_strlcpy(ifname, tb[IFLA_IFNAME], IFNAMSIZ);
Patrick McHardy78e5b8912006-09-13 20:35:36 -07001553 else
1554 ifname[0] = '\0';
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 err = -EINVAL;
Thomas Grafda5e0492006-08-10 21:17:37 -07001557 ifm = nlmsg_data(nlh);
Patrick McHardy51055be2007-06-05 12:40:01 -07001558 if (ifm->ifi_index > 0)
Eric Dumazeta3d12892009-10-21 10:59:31 +00001559 dev = __dev_get_by_index(net, ifm->ifi_index);
Thomas Grafda5e0492006-08-10 21:17:37 -07001560 else if (tb[IFLA_IFNAME])
Eric Dumazeta3d12892009-10-21 10:59:31 +00001561 dev = __dev_get_by_name(net, ifname);
Thomas Grafda5e0492006-08-10 21:17:37 -07001562 else
1563 goto errout;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564
Thomas Grafda5e0492006-08-10 21:17:37 -07001565 if (dev == NULL) {
1566 err = -ENODEV;
1567 goto errout;
1568 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569
Eric Dumazete0d087a2009-11-07 01:26:17 -08001570 err = validate_linkmsg(dev, tb);
1571 if (err < 0)
Eric Dumazeta3d12892009-10-21 10:59:31 +00001572 goto errout;
Thomas Grafda5e0492006-08-10 21:17:37 -07001573
Patrick McHardy38f7b872007-06-13 12:03:51 -07001574 err = do_setlink(dev, ifm, tb, ifname, 0);
Thomas Grafda5e0492006-08-10 21:17:37 -07001575errout:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576 return err;
1577}
1578
Patrick McHardy38f7b872007-06-13 12:03:51 -07001579static int rtnl_dellink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
1580{
YOSHIFUJI Hideaki3b1e0a62008-03-26 02:26:21 +09001581 struct net *net = sock_net(skb->sk);
Patrick McHardy38f7b872007-06-13 12:03:51 -07001582 const struct rtnl_link_ops *ops;
1583 struct net_device *dev;
1584 struct ifinfomsg *ifm;
1585 char ifname[IFNAMSIZ];
1586 struct nlattr *tb[IFLA_MAX+1];
1587 int err;
Eric Dumazet226bd342011-05-08 23:17:57 +00001588 LIST_HEAD(list_kill);
Patrick McHardy38f7b872007-06-13 12:03:51 -07001589
1590 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFLA_MAX, ifla_policy);
1591 if (err < 0)
1592 return err;
1593
1594 if (tb[IFLA_IFNAME])
1595 nla_strlcpy(ifname, tb[IFLA_IFNAME], IFNAMSIZ);
1596
1597 ifm = nlmsg_data(nlh);
1598 if (ifm->ifi_index > 0)
Eric W. Biederman881d9662007-09-17 11:56:21 -07001599 dev = __dev_get_by_index(net, ifm->ifi_index);
Patrick McHardy38f7b872007-06-13 12:03:51 -07001600 else if (tb[IFLA_IFNAME])
Eric W. Biederman881d9662007-09-17 11:56:21 -07001601 dev = __dev_get_by_name(net, ifname);
Patrick McHardy38f7b872007-06-13 12:03:51 -07001602 else
1603 return -EINVAL;
1604
1605 if (!dev)
1606 return -ENODEV;
1607
1608 ops = dev->rtnl_link_ops;
1609 if (!ops)
1610 return -EOPNOTSUPP;
1611
Eric Dumazet226bd342011-05-08 23:17:57 +00001612 ops->dellink(dev, &list_kill);
1613 unregister_netdevice_many(&list_kill);
1614 list_del(&list_kill);
Patrick McHardy38f7b872007-06-13 12:03:51 -07001615 return 0;
1616}
1617
Patrick McHardy3729d502010-02-26 06:34:54 +00001618int rtnl_configure_link(struct net_device *dev, const struct ifinfomsg *ifm)
1619{
1620 unsigned int old_flags;
1621 int err;
1622
1623 old_flags = dev->flags;
1624 if (ifm && (ifm->ifi_flags || ifm->ifi_change)) {
1625 err = __dev_change_flags(dev, rtnl_dev_combine_flags(dev, ifm));
1626 if (err < 0)
1627 return err;
1628 }
1629
1630 dev->rtnl_link_state = RTNL_LINK_INITIALIZED;
1631 rtmsg_ifinfo(RTM_NEWLINK, dev, ~0U);
1632
1633 __dev_notify_flags(dev, old_flags);
1634 return 0;
1635}
1636EXPORT_SYMBOL(rtnl_configure_link);
1637
Eric W. Biederman81adee42009-11-08 00:53:51 -08001638struct net_device *rtnl_create_link(struct net *src_net, struct net *net,
1639 char *ifname, const struct rtnl_link_ops *ops, struct nlattr *tb[])
Pavel Emelianove7199282007-08-08 22:16:38 -07001640{
1641 int err;
1642 struct net_device *dev;
Eric Dumazet2e59af32009-09-02 18:03:00 -07001643 unsigned int num_queues = 1;
1644 unsigned int real_num_queues = 1;
Pavel Emelianove7199282007-08-08 22:16:38 -07001645
Eric Dumazet2e59af32009-09-02 18:03:00 -07001646 if (ops->get_tx_queues) {
Eric W. Biederman81adee42009-11-08 00:53:51 -08001647 err = ops->get_tx_queues(src_net, tb, &num_queues,
Eric Dumazete0d087a2009-11-07 01:26:17 -08001648 &real_num_queues);
Eric Dumazet2e59af32009-09-02 18:03:00 -07001649 if (err)
1650 goto err;
1651 }
Pavel Emelianove7199282007-08-08 22:16:38 -07001652 err = -ENOMEM;
Eric Dumazet2e59af32009-09-02 18:03:00 -07001653 dev = alloc_netdev_mq(ops->priv_size, ifname, ops->setup, num_queues);
Pavel Emelianove7199282007-08-08 22:16:38 -07001654 if (!dev)
1655 goto err;
1656
Eric W. Biederman81adee42009-11-08 00:53:51 -08001657 dev_net_set(dev, net);
1658 dev->rtnl_link_ops = ops;
Patrick McHardy3729d502010-02-26 06:34:54 +00001659 dev->rtnl_link_state = RTNL_LINK_INITIALIZING;
Eric W. Biederman81adee42009-11-08 00:53:51 -08001660
Pavel Emelianove7199282007-08-08 22:16:38 -07001661 if (tb[IFLA_MTU])
1662 dev->mtu = nla_get_u32(tb[IFLA_MTU]);
1663 if (tb[IFLA_ADDRESS])
1664 memcpy(dev->dev_addr, nla_data(tb[IFLA_ADDRESS]),
1665 nla_len(tb[IFLA_ADDRESS]));
1666 if (tb[IFLA_BROADCAST])
1667 memcpy(dev->broadcast, nla_data(tb[IFLA_BROADCAST]),
1668 nla_len(tb[IFLA_BROADCAST]));
1669 if (tb[IFLA_TXQLEN])
1670 dev->tx_queue_len = nla_get_u32(tb[IFLA_TXQLEN]);
1671 if (tb[IFLA_OPERSTATE])
David S. Miller93b2d4a2008-02-17 18:35:07 -08001672 set_operstate(dev, nla_get_u8(tb[IFLA_OPERSTATE]));
Pavel Emelianove7199282007-08-08 22:16:38 -07001673 if (tb[IFLA_LINKMODE])
1674 dev->link_mode = nla_get_u8(tb[IFLA_LINKMODE]);
Patrick McHardyffa934f2011-01-20 03:00:42 +00001675 if (tb[IFLA_GROUP])
1676 dev_set_group(dev, nla_get_u32(tb[IFLA_GROUP]));
Pavel Emelianove7199282007-08-08 22:16:38 -07001677
1678 return dev;
1679
Pavel Emelianove7199282007-08-08 22:16:38 -07001680err:
1681 return ERR_PTR(err);
1682}
Eric Dumazete0d087a2009-11-07 01:26:17 -08001683EXPORT_SYMBOL(rtnl_create_link);
Pavel Emelianove7199282007-08-08 22:16:38 -07001684
Vlad Dogarue7ed8282011-01-13 23:38:31 +00001685static int rtnl_group_changelink(struct net *net, int group,
1686 struct ifinfomsg *ifm,
1687 struct nlattr **tb)
1688{
1689 struct net_device *dev;
1690 int err;
1691
1692 for_each_netdev(net, dev) {
1693 if (dev->group == group) {
1694 err = do_setlink(dev, ifm, tb, NULL, 0);
1695 if (err < 0)
1696 return err;
1697 }
1698 }
1699
1700 return 0;
1701}
1702
Patrick McHardy38f7b872007-06-13 12:03:51 -07001703static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
1704{
YOSHIFUJI Hideaki3b1e0a62008-03-26 02:26:21 +09001705 struct net *net = sock_net(skb->sk);
Patrick McHardy38f7b872007-06-13 12:03:51 -07001706 const struct rtnl_link_ops *ops;
1707 struct net_device *dev;
1708 struct ifinfomsg *ifm;
1709 char kind[MODULE_NAME_LEN];
1710 char ifname[IFNAMSIZ];
1711 struct nlattr *tb[IFLA_MAX+1];
1712 struct nlattr *linkinfo[IFLA_INFO_MAX+1];
1713 int err;
1714
Johannes Berg95a5afc2008-10-16 15:24:51 -07001715#ifdef CONFIG_MODULES
Patrick McHardy38f7b872007-06-13 12:03:51 -07001716replay:
Thomas Graf8072f082007-07-31 14:13:50 -07001717#endif
Patrick McHardy38f7b872007-06-13 12:03:51 -07001718 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFLA_MAX, ifla_policy);
1719 if (err < 0)
1720 return err;
1721
1722 if (tb[IFLA_IFNAME])
1723 nla_strlcpy(ifname, tb[IFLA_IFNAME], IFNAMSIZ);
1724 else
1725 ifname[0] = '\0';
1726
1727 ifm = nlmsg_data(nlh);
1728 if (ifm->ifi_index > 0)
Eric W. Biederman881d9662007-09-17 11:56:21 -07001729 dev = __dev_get_by_index(net, ifm->ifi_index);
Vlad Dogarue7ed8282011-01-13 23:38:31 +00001730 else {
1731 if (ifname[0])
1732 dev = __dev_get_by_name(net, ifname);
Vlad Dogarue7ed8282011-01-13 23:38:31 +00001733 else
1734 dev = NULL;
1735 }
Patrick McHardy38f7b872007-06-13 12:03:51 -07001736
Eric Dumazete0d087a2009-11-07 01:26:17 -08001737 err = validate_linkmsg(dev, tb);
1738 if (err < 0)
Thomas Graf1840bb12008-02-23 19:54:36 -08001739 return err;
1740
Patrick McHardy38f7b872007-06-13 12:03:51 -07001741 if (tb[IFLA_LINKINFO]) {
1742 err = nla_parse_nested(linkinfo, IFLA_INFO_MAX,
1743 tb[IFLA_LINKINFO], ifla_info_policy);
1744 if (err < 0)
1745 return err;
1746 } else
1747 memset(linkinfo, 0, sizeof(linkinfo));
1748
1749 if (linkinfo[IFLA_INFO_KIND]) {
1750 nla_strlcpy(kind, linkinfo[IFLA_INFO_KIND], sizeof(kind));
1751 ops = rtnl_link_ops_get(kind);
1752 } else {
1753 kind[0] = '\0';
1754 ops = NULL;
1755 }
1756
1757 if (1) {
1758 struct nlattr *attr[ops ? ops->maxtype + 1 : 0], **data = NULL;
Eric W. Biederman81adee42009-11-08 00:53:51 -08001759 struct net *dest_net;
Patrick McHardy38f7b872007-06-13 12:03:51 -07001760
1761 if (ops) {
1762 if (ops->maxtype && linkinfo[IFLA_INFO_DATA]) {
1763 err = nla_parse_nested(attr, ops->maxtype,
1764 linkinfo[IFLA_INFO_DATA],
1765 ops->policy);
1766 if (err < 0)
1767 return err;
1768 data = attr;
1769 }
1770 if (ops->validate) {
1771 err = ops->validate(tb, data);
1772 if (err < 0)
1773 return err;
1774 }
1775 }
1776
1777 if (dev) {
1778 int modified = 0;
1779
1780 if (nlh->nlmsg_flags & NLM_F_EXCL)
1781 return -EEXIST;
1782 if (nlh->nlmsg_flags & NLM_F_REPLACE)
1783 return -EOPNOTSUPP;
1784
1785 if (linkinfo[IFLA_INFO_DATA]) {
1786 if (!ops || ops != dev->rtnl_link_ops ||
1787 !ops->changelink)
1788 return -EOPNOTSUPP;
1789
1790 err = ops->changelink(dev, tb, data);
1791 if (err < 0)
1792 return err;
1793 modified = 1;
1794 }
1795
1796 return do_setlink(dev, ifm, tb, ifname, modified);
1797 }
1798
Patrick McHardyffa934f2011-01-20 03:00:42 +00001799 if (!(nlh->nlmsg_flags & NLM_F_CREATE)) {
1800 if (ifm->ifi_index == 0 && tb[IFLA_GROUP])
1801 return rtnl_group_changelink(net,
1802 nla_get_u32(tb[IFLA_GROUP]),
1803 ifm, tb);
Patrick McHardy38f7b872007-06-13 12:03:51 -07001804 return -ENODEV;
Patrick McHardyffa934f2011-01-20 03:00:42 +00001805 }
Patrick McHardy38f7b872007-06-13 12:03:51 -07001806
Patrick McHardy3729d502010-02-26 06:34:54 +00001807 if (ifm->ifi_index)
Patrick McHardy38f7b872007-06-13 12:03:51 -07001808 return -EOPNOTSUPP;
Patrick McHardy0e068772007-07-11 19:42:31 -07001809 if (tb[IFLA_MAP] || tb[IFLA_MASTER] || tb[IFLA_PROTINFO])
Patrick McHardy38f7b872007-06-13 12:03:51 -07001810 return -EOPNOTSUPP;
1811
1812 if (!ops) {
Johannes Berg95a5afc2008-10-16 15:24:51 -07001813#ifdef CONFIG_MODULES
Patrick McHardy38f7b872007-06-13 12:03:51 -07001814 if (kind[0]) {
1815 __rtnl_unlock();
1816 request_module("rtnl-link-%s", kind);
1817 rtnl_lock();
1818 ops = rtnl_link_ops_get(kind);
1819 if (ops)
1820 goto replay;
1821 }
1822#endif
1823 return -EOPNOTSUPP;
1824 }
1825
1826 if (!ifname[0])
1827 snprintf(ifname, IFNAMSIZ, "%s%%d", ops->kind);
Patrick McHardy38f7b872007-06-13 12:03:51 -07001828
Eric W. Biederman81adee42009-11-08 00:53:51 -08001829 dest_net = rtnl_link_get_net(net, tb);
Eric W. Biederman13ad1772011-01-29 14:57:22 +00001830 if (IS_ERR(dest_net))
1831 return PTR_ERR(dest_net);
1832
Eric W. Biederman81adee42009-11-08 00:53:51 -08001833 dev = rtnl_create_link(net, dest_net, ifname, ops, tb);
Patrick McHardy38f7b872007-06-13 12:03:51 -07001834
Pavel Emelianove7199282007-08-08 22:16:38 -07001835 if (IS_ERR(dev))
1836 err = PTR_ERR(dev);
1837 else if (ops->newlink)
Eric W. Biederman81adee42009-11-08 00:53:51 -08001838 err = ops->newlink(net, dev, tb, data);
Patrick McHardy2d85cba2007-07-11 19:42:13 -07001839 else
1840 err = register_netdevice(dev);
Dan Carpenter80032cf2010-04-21 23:53:27 +00001841
1842 if (err < 0 && !IS_ERR(dev))
Patrick McHardy38f7b872007-06-13 12:03:51 -07001843 free_netdev(dev);
Dan Carpenter80032cf2010-04-21 23:53:27 +00001844 if (err < 0)
Patrick McHardy3729d502010-02-26 06:34:54 +00001845 goto out;
Eric W. Biederman81adee42009-11-08 00:53:51 -08001846
Patrick McHardy3729d502010-02-26 06:34:54 +00001847 err = rtnl_configure_link(dev, ifm);
1848 if (err < 0)
1849 unregister_netdevice(dev);
1850out:
Eric W. Biederman81adee42009-11-08 00:53:51 -08001851 put_net(dest_net);
Patrick McHardy38f7b872007-06-13 12:03:51 -07001852 return err;
1853 }
1854}
1855
Thomas Grafb60c5112006-08-04 23:05:34 -07001856static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
Jean Tourrilhes711e2c32006-02-22 15:10:56 -08001857{
YOSHIFUJI Hideaki3b1e0a62008-03-26 02:26:21 +09001858 struct net *net = sock_net(skb->sk);
Thomas Grafb60c5112006-08-04 23:05:34 -07001859 struct ifinfomsg *ifm;
Eric Dumazeta3d12892009-10-21 10:59:31 +00001860 char ifname[IFNAMSIZ];
Thomas Grafb60c5112006-08-04 23:05:34 -07001861 struct nlattr *tb[IFLA_MAX+1];
1862 struct net_device *dev = NULL;
1863 struct sk_buff *nskb;
Thomas Graf339bf982006-11-10 14:10:15 -08001864 int err;
Greg Rose115c9b82012-02-21 16:54:48 -05001865 u32 ext_filter_mask = 0;
Jean Tourrilhes711e2c32006-02-22 15:10:56 -08001866
Thomas Grafb60c5112006-08-04 23:05:34 -07001867 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFLA_MAX, ifla_policy);
1868 if (err < 0)
Eric Sesterhenn9918f232006-09-26 23:26:38 -07001869 return err;
Thomas Grafb60c5112006-08-04 23:05:34 -07001870
Eric Dumazeta3d12892009-10-21 10:59:31 +00001871 if (tb[IFLA_IFNAME])
1872 nla_strlcpy(ifname, tb[IFLA_IFNAME], IFNAMSIZ);
1873
Greg Rose115c9b82012-02-21 16:54:48 -05001874 if (tb[IFLA_EXT_MASK])
1875 ext_filter_mask = nla_get_u32(tb[IFLA_EXT_MASK]);
1876
Thomas Grafb60c5112006-08-04 23:05:34 -07001877 ifm = nlmsg_data(nlh);
Eric Dumazeta3d12892009-10-21 10:59:31 +00001878 if (ifm->ifi_index > 0)
1879 dev = __dev_get_by_index(net, ifm->ifi_index);
1880 else if (tb[IFLA_IFNAME])
1881 dev = __dev_get_by_name(net, ifname);
1882 else
Jean Tourrilhes711e2c32006-02-22 15:10:56 -08001883 return -EINVAL;
Thomas Grafb60c5112006-08-04 23:05:34 -07001884
Eric Dumazeta3d12892009-10-21 10:59:31 +00001885 if (dev == NULL)
1886 return -ENODEV;
1887
Greg Rose115c9b82012-02-21 16:54:48 -05001888 nskb = nlmsg_new(if_nlmsg_size(dev, ext_filter_mask), GFP_KERNEL);
Eric Dumazeta3d12892009-10-21 10:59:31 +00001889 if (nskb == NULL)
1890 return -ENOBUFS;
Jean Tourrilhes711e2c32006-02-22 15:10:56 -08001891
Patrick McHardy575c3e22007-05-22 17:00:49 -07001892 err = rtnl_fill_ifinfo(nskb, dev, RTM_NEWLINK, NETLINK_CB(skb).pid,
Greg Rose115c9b82012-02-21 16:54:48 -05001893 nlh->nlmsg_seq, 0, 0, ext_filter_mask);
Patrick McHardy26932562007-01-31 23:16:40 -08001894 if (err < 0) {
1895 /* -EMSGSIZE implies BUG in if_nlmsg_size */
1896 WARN_ON(err == -EMSGSIZE);
1897 kfree_skb(nskb);
Eric Dumazeta3d12892009-10-21 10:59:31 +00001898 } else
1899 err = rtnl_unicast(nskb, net, NETLINK_CB(skb).pid);
Thomas Grafb60c5112006-08-04 23:05:34 -07001900
Jean Tourrilhes711e2c32006-02-22 15:10:56 -08001901 return err;
Jean Tourrilhes711e2c32006-02-22 15:10:56 -08001902}
Jean Tourrilhes711e2c32006-02-22 15:10:56 -08001903
Greg Rose115c9b82012-02-21 16:54:48 -05001904static u16 rtnl_calcit(struct sk_buff *skb, struct nlmsghdr *nlh)
Greg Rosec7ac8672011-06-10 01:27:09 +00001905{
Greg Rose115c9b82012-02-21 16:54:48 -05001906 struct net *net = sock_net(skb->sk);
1907 struct net_device *dev;
1908 struct nlattr *tb[IFLA_MAX+1];
1909 u32 ext_filter_mask = 0;
1910 u16 min_ifinfo_dump_size = 0;
1911
Eric Dumazeta4b64fb2012-03-04 12:32:10 +00001912 if (nlmsg_parse(nlh, sizeof(struct rtgenmsg), tb, IFLA_MAX,
1913 ifla_policy) >= 0) {
1914 if (tb[IFLA_EXT_MASK])
1915 ext_filter_mask = nla_get_u32(tb[IFLA_EXT_MASK]);
1916 }
Greg Rose115c9b82012-02-21 16:54:48 -05001917
1918 if (!ext_filter_mask)
1919 return NLMSG_GOODSIZE;
1920 /*
1921 * traverse the list of net devices and compute the minimum
1922 * buffer size based upon the filter mask.
1923 */
1924 list_for_each_entry(dev, &net->dev_base_head, dev_list) {
1925 min_ifinfo_dump_size = max_t(u16, min_ifinfo_dump_size,
1926 if_nlmsg_size(dev,
1927 ext_filter_mask));
1928 }
1929
Greg Rosec7ac8672011-06-10 01:27:09 +00001930 return min_ifinfo_dump_size;
1931}
1932
Adrian Bunk42bad1d2007-04-26 00:57:41 -07001933static int rtnl_dump_all(struct sk_buff *skb, struct netlink_callback *cb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934{
1935 int idx;
1936 int s_idx = cb->family;
1937
1938 if (s_idx == 0)
1939 s_idx = 1;
Patrick McHardy25239ce2010-04-26 16:02:05 +02001940 for (idx = 1; idx <= RTNL_FAMILY_MAX; idx++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941 int type = cb->nlh->nlmsg_type-RTM_BASE;
1942 if (idx < s_idx || idx == PF_PACKET)
1943 continue;
Thomas Grafe2849862007-03-22 11:48:11 -07001944 if (rtnl_msg_handlers[idx] == NULL ||
1945 rtnl_msg_handlers[idx][type].dumpit == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946 continue;
1947 if (idx > s_idx)
1948 memset(&cb->args[0], 0, sizeof(cb->args));
Thomas Grafe2849862007-03-22 11:48:11 -07001949 if (rtnl_msg_handlers[idx][type].dumpit(skb, cb))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950 break;
1951 }
1952 cb->family = idx;
1953
1954 return skb->len;
1955}
1956
1957void rtmsg_ifinfo(int type, struct net_device *dev, unsigned change)
1958{
YOSHIFUJI Hideakic346dca2008-03-25 21:47:49 +09001959 struct net *net = dev_net(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960 struct sk_buff *skb;
Thomas Graf0ec6d3f2006-08-15 00:37:09 -07001961 int err = -ENOBUFS;
Greg Rosec7ac8672011-06-10 01:27:09 +00001962 size_t if_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963
Greg Rose115c9b82012-02-21 16:54:48 -05001964 skb = nlmsg_new((if_info_size = if_nlmsg_size(dev, 0)), GFP_KERNEL);
Thomas Graf0ec6d3f2006-08-15 00:37:09 -07001965 if (skb == NULL)
1966 goto errout;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967
Greg Rose115c9b82012-02-21 16:54:48 -05001968 err = rtnl_fill_ifinfo(skb, dev, type, 0, 0, change, 0, 0);
Patrick McHardy26932562007-01-31 23:16:40 -08001969 if (err < 0) {
1970 /* -EMSGSIZE implies BUG in if_nlmsg_size() */
1971 WARN_ON(err == -EMSGSIZE);
1972 kfree_skb(skb);
1973 goto errout;
1974 }
Pablo Neira Ayuso1ce85fe2009-02-24 23:18:28 -08001975 rtnl_notify(skb, net, 0, RTNLGRP_LINK, NULL, GFP_KERNEL);
1976 return;
Thomas Graf0ec6d3f2006-08-15 00:37:09 -07001977errout:
1978 if (err < 0)
Eric W. Biederman4b3da702007-11-19 22:27:40 -08001979 rtnl_set_sk_err(net, RTNLGRP_LINK, err);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980}
1981
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982/* Protected by RTNL sempahore. */
1983static struct rtattr **rta_buf;
1984static int rtattr_max;
1985
1986/* Process one rtnetlink message. */
1987
Thomas Graf1d00a4e2007-03-22 23:30:12 -07001988static int rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989{
YOSHIFUJI Hideaki3b1e0a62008-03-26 02:26:21 +09001990 struct net *net = sock_net(skb->sk);
Thomas Grafe2849862007-03-22 11:48:11 -07001991 rtnl_doit_func doit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992 int sz_idx, kind;
1993 int min_len;
1994 int family;
1995 int type;
Eric Dumazet2907c352011-05-25 07:34:04 +00001996 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998 type = nlh->nlmsg_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999 if (type > RTM_MAX)
Thomas Graf038890f2007-04-05 14:35:52 -07002000 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001
2002 type -= RTM_BASE;
2003
2004 /* All the messages must have at least 1 byte length */
2005 if (nlh->nlmsg_len < NLMSG_LENGTH(sizeof(struct rtgenmsg)))
2006 return 0;
2007
Eric Dumazete0d087a2009-11-07 01:26:17 -08002008 family = ((struct rtgenmsg *)NLMSG_DATA(nlh))->rtgen_family;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 sz_idx = type>>2;
2010 kind = type&3;
2011
Eric Parisfd778462012-01-03 12:25:16 -05002012 if (kind != 2 && !capable(CAP_NET_ADMIN))
Thomas Graf1d00a4e2007-03-22 23:30:12 -07002013 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014
David S. Millerb8f3ab42011-01-18 12:40:38 -08002015 if (kind == 2 && nlh->nlmsg_flags&NLM_F_DUMP) {
Denis V. Lunev97c53ca2007-11-19 22:26:51 -08002016 struct sock *rtnl;
Thomas Grafe2849862007-03-22 11:48:11 -07002017 rtnl_dumpit_func dumpit;
Greg Rosec7ac8672011-06-10 01:27:09 +00002018 rtnl_calcit_func calcit;
2019 u16 min_dump_alloc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020
Thomas Grafe2849862007-03-22 11:48:11 -07002021 dumpit = rtnl_get_dumpit(family, type);
2022 if (dumpit == NULL)
Thomas Graf038890f2007-04-05 14:35:52 -07002023 return -EOPNOTSUPP;
Greg Rosec7ac8672011-06-10 01:27:09 +00002024 calcit = rtnl_get_calcit(family, type);
2025 if (calcit)
Greg Rose115c9b82012-02-21 16:54:48 -05002026 min_dump_alloc = calcit(skb, nlh);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027
Eric Dumazet2907c352011-05-25 07:34:04 +00002028 __rtnl_unlock();
Denis V. Lunev97c53ca2007-11-19 22:26:51 -08002029 rtnl = net->rtnl;
Pablo Neira Ayuso80d326f2012-02-24 14:30:15 +00002030 {
2031 struct netlink_dump_control c = {
2032 .dump = dumpit,
2033 .min_dump_alloc = min_dump_alloc,
2034 };
2035 err = netlink_dump_start(rtnl, skb, nlh, &c);
2036 }
Eric Dumazet2907c352011-05-25 07:34:04 +00002037 rtnl_lock();
2038 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039 }
2040
2041 memset(rta_buf, 0, (rtattr_max * sizeof(struct rtattr *)));
2042
2043 min_len = rtm_min[sz_idx];
2044 if (nlh->nlmsg_len < min_len)
Thomas Graf1d00a4e2007-03-22 23:30:12 -07002045 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046
2047 if (nlh->nlmsg_len > min_len) {
2048 int attrlen = nlh->nlmsg_len - NLMSG_ALIGN(min_len);
Eric Dumazete0d087a2009-11-07 01:26:17 -08002049 struct rtattr *attr = (void *)nlh + NLMSG_ALIGN(min_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050
2051 while (RTA_OK(attr, attrlen)) {
2052 unsigned flavor = attr->rta_type;
2053 if (flavor) {
2054 if (flavor > rta_max[sz_idx])
Thomas Graf1d00a4e2007-03-22 23:30:12 -07002055 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 rta_buf[flavor-1] = attr;
2057 }
2058 attr = RTA_NEXT(attr, attrlen);
2059 }
2060 }
2061
Thomas Grafe2849862007-03-22 11:48:11 -07002062 doit = rtnl_get_doit(family, type);
2063 if (doit == NULL)
Thomas Graf038890f2007-04-05 14:35:52 -07002064 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065
Thomas Graf1d00a4e2007-03-22 23:30:12 -07002066 return doit(skb, nlh, (void *)&rta_buf[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067}
2068
Denis V. Lunevcd40b7d2007-10-10 21:15:29 -07002069static void rtnetlink_rcv(struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070{
Denis V. Lunevcd40b7d2007-10-10 21:15:29 -07002071 rtnl_lock();
2072 netlink_rcv_skb(skb, &rtnetlink_rcv_msg);
2073 rtnl_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074}
2075
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076static int rtnetlink_event(struct notifier_block *this, unsigned long event, void *ptr)
2077{
2078 struct net_device *dev = ptr;
Eric W. Biedermane9dc8652007-09-12 13:02:17 +02002079
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 switch (event) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081 case NETDEV_UP:
2082 case NETDEV_DOWN:
Patrick McHardy10de05a2010-02-26 06:34:50 +00002083 case NETDEV_PRE_UP:
Eric W. Biedermand90a9092009-12-12 22:11:15 +00002084 case NETDEV_POST_INIT:
2085 case NETDEV_REGISTER:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086 case NETDEV_CHANGE:
Patrick McHardy755d0e72010-03-19 04:42:24 +00002087 case NETDEV_PRE_TYPE_CHANGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088 case NETDEV_GOING_DOWN:
Patrick McHardya2835762010-02-26 06:34:51 +00002089 case NETDEV_UNREGISTER:
Eric W. Biedermand90a9092009-12-12 22:11:15 +00002090 case NETDEV_UNREGISTER_BATCH:
Amerigo Wangac3d3f82011-05-19 23:06:32 +00002091 case NETDEV_RELEASE:
2092 case NETDEV_JOIN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093 break;
2094 default:
2095 rtmsg_ifinfo(RTM_NEWLINK, dev, 0);
2096 break;
2097 }
2098 return NOTIFY_DONE;
2099}
2100
2101static struct notifier_block rtnetlink_dev_notifier = {
2102 .notifier_call = rtnetlink_event,
2103};
2104
Denis V. Lunev97c53ca2007-11-19 22:26:51 -08002105
Alexey Dobriyan2c8c1e72010-01-17 03:35:32 +00002106static int __net_init rtnetlink_net_init(struct net *net)
Denis V. Lunev97c53ca2007-11-19 22:26:51 -08002107{
2108 struct sock *sk;
2109 sk = netlink_kernel_create(net, NETLINK_ROUTE, RTNLGRP_MAX,
Eric Dumazet2907c352011-05-25 07:34:04 +00002110 rtnetlink_rcv, &rtnl_mutex, THIS_MODULE);
Denis V. Lunev97c53ca2007-11-19 22:26:51 -08002111 if (!sk)
2112 return -ENOMEM;
Denis V. Lunev97c53ca2007-11-19 22:26:51 -08002113 net->rtnl = sk;
2114 return 0;
2115}
2116
Alexey Dobriyan2c8c1e72010-01-17 03:35:32 +00002117static void __net_exit rtnetlink_net_exit(struct net *net)
Denis V. Lunev97c53ca2007-11-19 22:26:51 -08002118{
Denis V. Lunev775516b2008-01-18 23:55:19 -08002119 netlink_kernel_release(net->rtnl);
2120 net->rtnl = NULL;
Denis V. Lunev97c53ca2007-11-19 22:26:51 -08002121}
2122
2123static struct pernet_operations rtnetlink_net_ops = {
2124 .init = rtnetlink_net_init,
2125 .exit = rtnetlink_net_exit,
2126};
2127
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128void __init rtnetlink_init(void)
2129{
2130 int i;
2131
2132 rtattr_max = 0;
2133 for (i = 0; i < ARRAY_SIZE(rta_max); i++)
2134 if (rta_max[i] > rtattr_max)
2135 rtattr_max = rta_max[i];
2136 rta_buf = kmalloc(rtattr_max * sizeof(struct rtattr *), GFP_KERNEL);
2137 if (!rta_buf)
2138 panic("rtnetlink_init: cannot allocate rta_buf\n");
2139
Denis V. Lunev97c53ca2007-11-19 22:26:51 -08002140 if (register_pernet_subsys(&rtnetlink_net_ops))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141 panic("rtnetlink_init: cannot initialize rtnetlink\n");
Denis V. Lunev97c53ca2007-11-19 22:26:51 -08002142
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143 netlink_set_nonroot(NETLINK_ROUTE, NL_NONROOT_RECV);
2144 register_netdevice_notifier(&rtnetlink_dev_notifier);
Thomas Graf340d17f2007-03-22 11:49:22 -07002145
Greg Rosec7ac8672011-06-10 01:27:09 +00002146 rtnl_register(PF_UNSPEC, RTM_GETLINK, rtnl_getlink,
2147 rtnl_dump_ifinfo, rtnl_calcit);
2148 rtnl_register(PF_UNSPEC, RTM_SETLINK, rtnl_setlink, NULL, NULL);
2149 rtnl_register(PF_UNSPEC, RTM_NEWLINK, rtnl_newlink, NULL, NULL);
2150 rtnl_register(PF_UNSPEC, RTM_DELLINK, rtnl_dellink, NULL, NULL);
Thomas Graf687ad8c2007-03-22 11:59:42 -07002151
Greg Rosec7ac8672011-06-10 01:27:09 +00002152 rtnl_register(PF_UNSPEC, RTM_GETADDR, NULL, rtnl_dump_all, NULL);
2153 rtnl_register(PF_UNSPEC, RTM_GETROUTE, NULL, rtnl_dump_all, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154}
2155