blob: 4a0d8cfff2a020e2892475860ce3a3f3f97a902f [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42#include <linux/inet.h>
43#include <linux/netdevice.h>
44#include <net/ip.h>
45#include <net/protocol.h>
46#include <net/arp.h>
47#include <net/route.h>
48#include <net/udp.h>
49#include <net/sock.h>
50#include <net/pkt_sched.h>
Thomas Graf14c0b972006-08-04 03:38:38 -070051#include <net/fib_rules.h>
Thomas Grafe2849862007-03-22 11:48:11 -070052#include <net/rtnetlink.h>
Johannes Berg30ffee82009-07-10 09:51:35 +000053#include <net/net_namespace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
Eric Dumazete0d087a2009-11-07 01:26:17 -080055struct rtnl_link {
Thomas Grafe2849862007-03-22 11:48:11 -070056 rtnl_doit_func doit;
57 rtnl_dumpit_func dumpit;
Greg Rosec7ac8672011-06-10 01:27:09 +000058 rtnl_calcit_func calcit;
Thomas Grafe2849862007-03-22 11:48:11 -070059};
60
Stephen Hemminger6756ae42006-03-20 22:23:58 -080061static DEFINE_MUTEX(rtnl_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
63void rtnl_lock(void)
64{
Stephen Hemminger6756ae42006-03-20 22:23:58 -080065 mutex_lock(&rtnl_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066}
Eric Dumazete0d087a2009-11-07 01:26:17 -080067EXPORT_SYMBOL(rtnl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Stephen Hemminger6756ae42006-03-20 22:23:58 -080069void __rtnl_unlock(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070070{
Stephen Hemminger6756ae42006-03-20 22:23:58 -080071 mutex_unlock(&rtnl_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072}
Stephen Hemminger6756ae42006-03-20 22:23:58 -080073
Linus Torvalds1da177e2005-04-16 15:20:36 -070074void rtnl_unlock(void)
75{
Herbert Xu58ec3b42008-10-07 15:50:03 -070076 /* This fellow will unlock it for us. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 netdev_run_todo();
78}
Eric Dumazete0d087a2009-11-07 01:26:17 -080079EXPORT_SYMBOL(rtnl_unlock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
Stephen Hemminger6756ae42006-03-20 22:23:58 -080081int rtnl_trylock(void)
82{
83 return mutex_trylock(&rtnl_mutex);
84}
Eric Dumazete0d087a2009-11-07 01:26:17 -080085EXPORT_SYMBOL(rtnl_trylock);
Stephen Hemminger6756ae42006-03-20 22:23:58 -080086
Patrick McHardyc9c10142008-04-23 22:10:48 -070087int rtnl_is_locked(void)
88{
89 return mutex_is_locked(&rtnl_mutex);
90}
Eric Dumazete0d087a2009-11-07 01:26:17 -080091EXPORT_SYMBOL(rtnl_is_locked);
Patrick McHardyc9c10142008-04-23 22:10:48 -070092
Paul E. McKenneya898def2010-02-22 17:04:49 -080093#ifdef CONFIG_PROVE_LOCKING
94int lockdep_rtnl_is_held(void)
95{
96 return lockdep_is_held(&rtnl_mutex);
97}
98EXPORT_SYMBOL(lockdep_rtnl_is_held);
99#endif /* #ifdef CONFIG_PROVE_LOCKING */
100
Patrick McHardy25239ce2010-04-26 16:02:05 +0200101static struct rtnl_link *rtnl_msg_handlers[RTNL_FAMILY_MAX + 1];
Thomas Grafe2849862007-03-22 11:48:11 -0700102
103static inline int rtm_msgindex(int msgtype)
104{
105 int msgindex = msgtype - RTM_BASE;
106
107 /*
108 * msgindex < 0 implies someone tried to register a netlink
109 * control code. msgindex >= RTM_NR_MSGTYPES may indicate that
110 * the message type has not been added to linux/rtnetlink.h
111 */
112 BUG_ON(msgindex < 0 || msgindex >= RTM_NR_MSGTYPES);
113
114 return msgindex;
115}
116
117static rtnl_doit_func rtnl_get_doit(int protocol, int msgindex)
118{
119 struct rtnl_link *tab;
120
Patrick McHardy25239ce2010-04-26 16:02:05 +0200121 if (protocol <= RTNL_FAMILY_MAX)
Patrick McHardy0f87b1d2010-04-13 05:03:17 +0000122 tab = rtnl_msg_handlers[protocol];
123 else
124 tab = NULL;
125
Thomas Graf51057f22007-03-22 21:41:06 -0700126 if (tab == NULL || tab[msgindex].doit == NULL)
Thomas Grafe2849862007-03-22 11:48:11 -0700127 tab = rtnl_msg_handlers[PF_UNSPEC];
128
Thomas Graf51057f22007-03-22 21:41:06 -0700129 return tab ? tab[msgindex].doit : NULL;
Thomas Grafe2849862007-03-22 11:48:11 -0700130}
131
132static rtnl_dumpit_func rtnl_get_dumpit(int protocol, int msgindex)
133{
134 struct rtnl_link *tab;
135
Patrick McHardy25239ce2010-04-26 16:02:05 +0200136 if (protocol <= RTNL_FAMILY_MAX)
Patrick McHardy0f87b1d2010-04-13 05:03:17 +0000137 tab = rtnl_msg_handlers[protocol];
138 else
139 tab = NULL;
140
Thomas Graf51057f22007-03-22 21:41:06 -0700141 if (tab == NULL || tab[msgindex].dumpit == NULL)
Thomas Grafe2849862007-03-22 11:48:11 -0700142 tab = rtnl_msg_handlers[PF_UNSPEC];
143
Thomas Graf51057f22007-03-22 21:41:06 -0700144 return tab ? tab[msgindex].dumpit : NULL;
Thomas Grafe2849862007-03-22 11:48:11 -0700145}
146
Greg Rosec7ac8672011-06-10 01:27:09 +0000147static rtnl_calcit_func rtnl_get_calcit(int protocol, int msgindex)
148{
149 struct rtnl_link *tab;
150
151 if (protocol <= RTNL_FAMILY_MAX)
152 tab = rtnl_msg_handlers[protocol];
153 else
154 tab = NULL;
155
156 if (tab == NULL || tab[msgindex].calcit == NULL)
157 tab = rtnl_msg_handlers[PF_UNSPEC];
158
159 return tab ? tab[msgindex].calcit : NULL;
160}
161
Thomas Grafe2849862007-03-22 11:48:11 -0700162/**
163 * __rtnl_register - Register a rtnetlink message type
164 * @protocol: Protocol family or PF_UNSPEC
165 * @msgtype: rtnetlink message type
166 * @doit: Function pointer called for each request message
167 * @dumpit: Function pointer called for each dump request (NLM_F_DUMP) message
Greg Rosec7ac8672011-06-10 01:27:09 +0000168 * @calcit: Function pointer to calc size of dump message
Thomas Grafe2849862007-03-22 11:48:11 -0700169 *
170 * Registers the specified function pointers (at least one of them has
171 * to be non-NULL) to be called whenever a request message for the
172 * specified protocol family and message type is received.
173 *
174 * The special protocol family PF_UNSPEC may be used to define fallback
175 * function pointers for the case when no entry for the specific protocol
176 * family exists.
177 *
178 * Returns 0 on success or a negative error code.
179 */
180int __rtnl_register(int protocol, int msgtype,
Greg Rosec7ac8672011-06-10 01:27:09 +0000181 rtnl_doit_func doit, rtnl_dumpit_func dumpit,
182 rtnl_calcit_func calcit)
Thomas Grafe2849862007-03-22 11:48:11 -0700183{
184 struct rtnl_link *tab;
185 int msgindex;
186
Patrick McHardy25239ce2010-04-26 16:02:05 +0200187 BUG_ON(protocol < 0 || protocol > RTNL_FAMILY_MAX);
Thomas Grafe2849862007-03-22 11:48:11 -0700188 msgindex = rtm_msgindex(msgtype);
189
190 tab = rtnl_msg_handlers[protocol];
191 if (tab == NULL) {
192 tab = kcalloc(RTM_NR_MSGTYPES, sizeof(*tab), GFP_KERNEL);
193 if (tab == NULL)
194 return -ENOBUFS;
195
196 rtnl_msg_handlers[protocol] = tab;
197 }
198
199 if (doit)
200 tab[msgindex].doit = doit;
201
202 if (dumpit)
203 tab[msgindex].dumpit = dumpit;
204
Greg Rosec7ac8672011-06-10 01:27:09 +0000205 if (calcit)
206 tab[msgindex].calcit = calcit;
207
Thomas Grafe2849862007-03-22 11:48:11 -0700208 return 0;
209}
Thomas Grafe2849862007-03-22 11:48:11 -0700210EXPORT_SYMBOL_GPL(__rtnl_register);
211
212/**
213 * rtnl_register - Register a rtnetlink message type
214 *
215 * Identical to __rtnl_register() but panics on failure. This is useful
216 * as failure of this function is very unlikely, it can only happen due
217 * to lack of memory when allocating the chain to store all message
218 * handlers for a protocol. Meant for use in init functions where lack
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300219 * of memory implies no sense in continuing.
Thomas Grafe2849862007-03-22 11:48:11 -0700220 */
221void rtnl_register(int protocol, int msgtype,
Greg Rosec7ac8672011-06-10 01:27:09 +0000222 rtnl_doit_func doit, rtnl_dumpit_func dumpit,
223 rtnl_calcit_func calcit)
Thomas Grafe2849862007-03-22 11:48:11 -0700224{
Greg Rosec7ac8672011-06-10 01:27:09 +0000225 if (__rtnl_register(protocol, msgtype, doit, dumpit, calcit) < 0)
Thomas Grafe2849862007-03-22 11:48:11 -0700226 panic("Unable to register rtnetlink message handler, "
227 "protocol = %d, message type = %d\n",
228 protocol, msgtype);
229}
Thomas Grafe2849862007-03-22 11:48:11 -0700230EXPORT_SYMBOL_GPL(rtnl_register);
231
232/**
233 * rtnl_unregister - Unregister a rtnetlink message type
234 * @protocol: Protocol family or PF_UNSPEC
235 * @msgtype: rtnetlink message type
236 *
237 * Returns 0 on success or a negative error code.
238 */
239int rtnl_unregister(int protocol, int msgtype)
240{
241 int msgindex;
242
Patrick McHardy25239ce2010-04-26 16:02:05 +0200243 BUG_ON(protocol < 0 || protocol > RTNL_FAMILY_MAX);
Thomas Grafe2849862007-03-22 11:48:11 -0700244 msgindex = rtm_msgindex(msgtype);
245
246 if (rtnl_msg_handlers[protocol] == NULL)
247 return -ENOENT;
248
249 rtnl_msg_handlers[protocol][msgindex].doit = NULL;
250 rtnl_msg_handlers[protocol][msgindex].dumpit = NULL;
251
252 return 0;
253}
Thomas Grafe2849862007-03-22 11:48:11 -0700254EXPORT_SYMBOL_GPL(rtnl_unregister);
255
256/**
257 * rtnl_unregister_all - Unregister all rtnetlink message type of a protocol
258 * @protocol : Protocol family or PF_UNSPEC
259 *
260 * Identical to calling rtnl_unregster() for all registered message types
261 * of a certain protocol family.
262 */
263void rtnl_unregister_all(int protocol)
264{
Patrick McHardy25239ce2010-04-26 16:02:05 +0200265 BUG_ON(protocol < 0 || protocol > RTNL_FAMILY_MAX);
Thomas Grafe2849862007-03-22 11:48:11 -0700266
267 kfree(rtnl_msg_handlers[protocol]);
268 rtnl_msg_handlers[protocol] = NULL;
269}
Thomas Grafe2849862007-03-22 11:48:11 -0700270EXPORT_SYMBOL_GPL(rtnl_unregister_all);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
Patrick McHardy38f7b872007-06-13 12:03:51 -0700272static LIST_HEAD(link_ops);
273
Eric Dumazetc63044f2011-12-13 11:38:00 +0000274static const struct rtnl_link_ops *rtnl_link_ops_get(const char *kind)
275{
276 const struct rtnl_link_ops *ops;
277
278 list_for_each_entry(ops, &link_ops, list) {
279 if (!strcmp(ops->kind, kind))
280 return ops;
281 }
282 return NULL;
283}
284
Patrick McHardy38f7b872007-06-13 12:03:51 -0700285/**
286 * __rtnl_link_register - Register rtnl_link_ops with rtnetlink.
287 * @ops: struct rtnl_link_ops * to register
288 *
289 * The caller must hold the rtnl_mutex. This function should be used
290 * by drivers that create devices during module initialization. It
291 * must be called before registering the devices.
292 *
293 * Returns 0 on success or a negative error code.
294 */
295int __rtnl_link_register(struct rtnl_link_ops *ops)
296{
Eric Dumazetc63044f2011-12-13 11:38:00 +0000297 if (rtnl_link_ops_get(ops->kind))
298 return -EEXIST;
299
Patrick McHardy2d85cba2007-07-11 19:42:13 -0700300 if (!ops->dellink)
Eric Dumazet23289a32009-10-27 07:06:36 +0000301 ops->dellink = unregister_netdevice_queue;
Patrick McHardy2d85cba2007-07-11 19:42:13 -0700302
Patrick McHardy38f7b872007-06-13 12:03:51 -0700303 list_add_tail(&ops->list, &link_ops);
304 return 0;
305}
Patrick McHardy38f7b872007-06-13 12:03:51 -0700306EXPORT_SYMBOL_GPL(__rtnl_link_register);
307
308/**
309 * rtnl_link_register - Register rtnl_link_ops with rtnetlink.
310 * @ops: struct rtnl_link_ops * to register
311 *
312 * Returns 0 on success or a negative error code.
313 */
314int rtnl_link_register(struct rtnl_link_ops *ops)
315{
316 int err;
317
318 rtnl_lock();
319 err = __rtnl_link_register(ops);
320 rtnl_unlock();
321 return err;
322}
Patrick McHardy38f7b872007-06-13 12:03:51 -0700323EXPORT_SYMBOL_GPL(rtnl_link_register);
324
Pavel Emelyanov669f87b2008-04-16 00:46:52 -0700325static void __rtnl_kill_links(struct net *net, struct rtnl_link_ops *ops)
326{
327 struct net_device *dev;
Eric Dumazet23289a32009-10-27 07:06:36 +0000328 LIST_HEAD(list_kill);
329
Pavel Emelyanov669f87b2008-04-16 00:46:52 -0700330 for_each_netdev(net, dev) {
Eric Dumazet23289a32009-10-27 07:06:36 +0000331 if (dev->rtnl_link_ops == ops)
332 ops->dellink(dev, &list_kill);
Pavel Emelyanov669f87b2008-04-16 00:46:52 -0700333 }
Eric Dumazet23289a32009-10-27 07:06:36 +0000334 unregister_netdevice_many(&list_kill);
Pavel Emelyanov669f87b2008-04-16 00:46:52 -0700335}
336
Patrick McHardy38f7b872007-06-13 12:03:51 -0700337/**
338 * __rtnl_link_unregister - Unregister rtnl_link_ops from rtnetlink.
339 * @ops: struct rtnl_link_ops * to unregister
340 *
Patrick McHardy2d85cba2007-07-11 19:42:13 -0700341 * The caller must hold the rtnl_mutex.
Patrick McHardy38f7b872007-06-13 12:03:51 -0700342 */
343void __rtnl_link_unregister(struct rtnl_link_ops *ops)
344{
Eric W. Biederman881d9662007-09-17 11:56:21 -0700345 struct net *net;
Patrick McHardy2d85cba2007-07-11 19:42:13 -0700346
Eric W. Biederman881d9662007-09-17 11:56:21 -0700347 for_each_net(net) {
Pavel Emelyanov669f87b2008-04-16 00:46:52 -0700348 __rtnl_kill_links(net, ops);
Patrick McHardy2d85cba2007-07-11 19:42:13 -0700349 }
Patrick McHardy38f7b872007-06-13 12:03:51 -0700350 list_del(&ops->list);
351}
Patrick McHardy38f7b872007-06-13 12:03:51 -0700352EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
353
354/**
355 * rtnl_link_unregister - Unregister rtnl_link_ops from rtnetlink.
356 * @ops: struct rtnl_link_ops * to unregister
357 */
358void rtnl_link_unregister(struct rtnl_link_ops *ops)
359{
360 rtnl_lock();
361 __rtnl_link_unregister(ops);
362 rtnl_unlock();
363}
Patrick McHardy38f7b872007-06-13 12:03:51 -0700364EXPORT_SYMBOL_GPL(rtnl_link_unregister);
365
Patrick McHardy38f7b872007-06-13 12:03:51 -0700366static size_t rtnl_link_get_size(const struct net_device *dev)
367{
368 const struct rtnl_link_ops *ops = dev->rtnl_link_ops;
369 size_t size;
370
371 if (!ops)
372 return 0;
373
Thomas Graf369cf772010-11-11 15:47:59 +0000374 size = nla_total_size(sizeof(struct nlattr)) + /* IFLA_LINKINFO */
375 nla_total_size(strlen(ops->kind) + 1); /* IFLA_INFO_KIND */
Patrick McHardy38f7b872007-06-13 12:03:51 -0700376
377 if (ops->get_size)
378 /* IFLA_INFO_DATA + nested data */
Thomas Graf369cf772010-11-11 15:47:59 +0000379 size += nla_total_size(sizeof(struct nlattr)) +
Patrick McHardy38f7b872007-06-13 12:03:51 -0700380 ops->get_size(dev);
381
382 if (ops->get_xstats_size)
Thomas Graf369cf772010-11-11 15:47:59 +0000383 /* IFLA_INFO_XSTATS */
384 size += nla_total_size(ops->get_xstats_size(dev));
Patrick McHardy38f7b872007-06-13 12:03:51 -0700385
386 return size;
387}
388
Thomas Graff8ff1822010-11-16 04:30:14 +0000389static LIST_HEAD(rtnl_af_ops);
390
391static const struct rtnl_af_ops *rtnl_af_lookup(const int family)
392{
393 const struct rtnl_af_ops *ops;
394
395 list_for_each_entry(ops, &rtnl_af_ops, list) {
396 if (ops->family == family)
397 return ops;
398 }
399
400 return NULL;
401}
402
403/**
404 * __rtnl_af_register - Register rtnl_af_ops with rtnetlink.
405 * @ops: struct rtnl_af_ops * to register
406 *
407 * The caller must hold the rtnl_mutex.
408 *
409 * Returns 0 on success or a negative error code.
410 */
411int __rtnl_af_register(struct rtnl_af_ops *ops)
412{
413 list_add_tail(&ops->list, &rtnl_af_ops);
414 return 0;
415}
416EXPORT_SYMBOL_GPL(__rtnl_af_register);
417
418/**
419 * rtnl_af_register - Register rtnl_af_ops with rtnetlink.
420 * @ops: struct rtnl_af_ops * to register
421 *
422 * Returns 0 on success or a negative error code.
423 */
424int rtnl_af_register(struct rtnl_af_ops *ops)
425{
426 int err;
427
428 rtnl_lock();
429 err = __rtnl_af_register(ops);
430 rtnl_unlock();
431 return err;
432}
433EXPORT_SYMBOL_GPL(rtnl_af_register);
434
435/**
436 * __rtnl_af_unregister - Unregister rtnl_af_ops from rtnetlink.
437 * @ops: struct rtnl_af_ops * to unregister
438 *
439 * The caller must hold the rtnl_mutex.
440 */
441void __rtnl_af_unregister(struct rtnl_af_ops *ops)
442{
443 list_del(&ops->list);
444}
445EXPORT_SYMBOL_GPL(__rtnl_af_unregister);
446
447/**
448 * rtnl_af_unregister - Unregister rtnl_af_ops from rtnetlink.
449 * @ops: struct rtnl_af_ops * to unregister
450 */
451void rtnl_af_unregister(struct rtnl_af_ops *ops)
452{
453 rtnl_lock();
454 __rtnl_af_unregister(ops);
455 rtnl_unlock();
456}
457EXPORT_SYMBOL_GPL(rtnl_af_unregister);
458
459static size_t rtnl_link_get_af_size(const struct net_device *dev)
460{
461 struct rtnl_af_ops *af_ops;
462 size_t size;
463
464 /* IFLA_AF_SPEC */
465 size = nla_total_size(sizeof(struct nlattr));
466
467 list_for_each_entry(af_ops, &rtnl_af_ops, list) {
468 if (af_ops->get_link_af_size) {
469 /* AF_* + nested data */
470 size += nla_total_size(sizeof(struct nlattr)) +
471 af_ops->get_link_af_size(dev);
472 }
473 }
474
475 return size;
476}
477
Patrick McHardy38f7b872007-06-13 12:03:51 -0700478static int rtnl_link_fill(struct sk_buff *skb, const struct net_device *dev)
479{
480 const struct rtnl_link_ops *ops = dev->rtnl_link_ops;
481 struct nlattr *linkinfo, *data;
482 int err = -EMSGSIZE;
483
484 linkinfo = nla_nest_start(skb, IFLA_LINKINFO);
485 if (linkinfo == NULL)
486 goto out;
487
488 if (nla_put_string(skb, IFLA_INFO_KIND, ops->kind) < 0)
489 goto err_cancel_link;
490 if (ops->fill_xstats) {
491 err = ops->fill_xstats(skb, dev);
492 if (err < 0)
493 goto err_cancel_link;
494 }
495 if (ops->fill_info) {
496 data = nla_nest_start(skb, IFLA_INFO_DATA);
497 if (data == NULL)
498 goto err_cancel_link;
499 err = ops->fill_info(skb, dev);
500 if (err < 0)
501 goto err_cancel_data;
502 nla_nest_end(skb, data);
503 }
504
505 nla_nest_end(skb, linkinfo);
506 return 0;
507
508err_cancel_data:
509 nla_nest_cancel(skb, data);
510err_cancel_link:
511 nla_nest_cancel(skb, linkinfo);
512out:
513 return err;
514}
515
Thomas Grafdb46edc2005-05-03 14:29:39 -0700516static const int rtm_min[RTM_NR_FAMILIES] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517{
Thomas Graff90a0a72005-05-03 14:29:00 -0700518 [RTM_FAM(RTM_NEWLINK)] = NLMSG_LENGTH(sizeof(struct ifinfomsg)),
519 [RTM_FAM(RTM_NEWADDR)] = NLMSG_LENGTH(sizeof(struct ifaddrmsg)),
520 [RTM_FAM(RTM_NEWROUTE)] = NLMSG_LENGTH(sizeof(struct rtmsg)),
Thomas Graf14c0b972006-08-04 03:38:38 -0700521 [RTM_FAM(RTM_NEWRULE)] = NLMSG_LENGTH(sizeof(struct fib_rule_hdr)),
Thomas Graff90a0a72005-05-03 14:29:00 -0700522 [RTM_FAM(RTM_NEWQDISC)] = NLMSG_LENGTH(sizeof(struct tcmsg)),
523 [RTM_FAM(RTM_NEWTCLASS)] = NLMSG_LENGTH(sizeof(struct tcmsg)),
524 [RTM_FAM(RTM_NEWTFILTER)] = NLMSG_LENGTH(sizeof(struct tcmsg)),
525 [RTM_FAM(RTM_NEWACTION)] = NLMSG_LENGTH(sizeof(struct tcamsg)),
Thomas Graff90a0a72005-05-03 14:29:00 -0700526 [RTM_FAM(RTM_GETMULTICAST)] = NLMSG_LENGTH(sizeof(struct rtgenmsg)),
527 [RTM_FAM(RTM_GETANYCAST)] = NLMSG_LENGTH(sizeof(struct rtgenmsg)),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528};
529
Thomas Grafdb46edc2005-05-03 14:29:39 -0700530static const int rta_max[RTM_NR_FAMILIES] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531{
Thomas Graff90a0a72005-05-03 14:29:00 -0700532 [RTM_FAM(RTM_NEWLINK)] = IFLA_MAX,
533 [RTM_FAM(RTM_NEWADDR)] = IFA_MAX,
534 [RTM_FAM(RTM_NEWROUTE)] = RTA_MAX,
Thomas Graf14c0b972006-08-04 03:38:38 -0700535 [RTM_FAM(RTM_NEWRULE)] = FRA_MAX,
Thomas Graff90a0a72005-05-03 14:29:00 -0700536 [RTM_FAM(RTM_NEWQDISC)] = TCA_MAX,
537 [RTM_FAM(RTM_NEWTCLASS)] = TCA_MAX,
538 [RTM_FAM(RTM_NEWTFILTER)] = TCA_MAX,
539 [RTM_FAM(RTM_NEWACTION)] = TCAA_MAX,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540};
541
542void __rta_fill(struct sk_buff *skb, int attrtype, int attrlen, const void *data)
543{
544 struct rtattr *rta;
545 int size = RTA_LENGTH(attrlen);
546
Eric Dumazete0d087a2009-11-07 01:26:17 -0800547 rta = (struct rtattr *)skb_put(skb, RTA_ALIGN(size));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 rta->rta_type = attrtype;
549 rta->rta_len = size;
550 memcpy(RTA_DATA(rta), data, attrlen);
Patrick McHardyb3563c42005-06-28 12:54:43 -0700551 memset(RTA_DATA(rta) + attrlen, 0, RTA_ALIGN(size) - size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552}
Eric Dumazete0d087a2009-11-07 01:26:17 -0800553EXPORT_SYMBOL(__rta_fill);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554
Denis V. Lunev97c53ca2007-11-19 22:26:51 -0800555int rtnetlink_send(struct sk_buff *skb, struct net *net, u32 pid, unsigned group, int echo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556{
Denis V. Lunev97c53ca2007-11-19 22:26:51 -0800557 struct sock *rtnl = net->rtnl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 int err = 0;
559
Patrick McHardyac6d4392005-08-14 19:29:52 -0700560 NETLINK_CB(skb).dst_group = group;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 if (echo)
562 atomic_inc(&skb->users);
563 netlink_broadcast(rtnl, skb, pid, group, GFP_KERNEL);
564 if (echo)
565 err = netlink_unicast(rtnl, skb, pid, MSG_DONTWAIT);
566 return err;
567}
568
Denis V. Lunev97c53ca2007-11-19 22:26:51 -0800569int rtnl_unicast(struct sk_buff *skb, struct net *net, u32 pid)
Thomas Graf2942e902006-08-15 00:30:25 -0700570{
Denis V. Lunev97c53ca2007-11-19 22:26:51 -0800571 struct sock *rtnl = net->rtnl;
572
Thomas Graf2942e902006-08-15 00:30:25 -0700573 return nlmsg_unicast(rtnl, skb, pid);
574}
Eric Dumazete0d087a2009-11-07 01:26:17 -0800575EXPORT_SYMBOL(rtnl_unicast);
Thomas Graf2942e902006-08-15 00:30:25 -0700576
Pablo Neira Ayuso1ce85fe2009-02-24 23:18:28 -0800577void rtnl_notify(struct sk_buff *skb, struct net *net, u32 pid, u32 group,
578 struct nlmsghdr *nlh, gfp_t flags)
Thomas Graf97676b62006-08-15 00:31:41 -0700579{
Denis V. Lunev97c53ca2007-11-19 22:26:51 -0800580 struct sock *rtnl = net->rtnl;
Thomas Graf97676b62006-08-15 00:31:41 -0700581 int report = 0;
582
583 if (nlh)
584 report = nlmsg_report(nlh);
585
Pablo Neira Ayuso1ce85fe2009-02-24 23:18:28 -0800586 nlmsg_notify(rtnl, skb, pid, group, report, flags);
Thomas Graf97676b62006-08-15 00:31:41 -0700587}
Eric Dumazete0d087a2009-11-07 01:26:17 -0800588EXPORT_SYMBOL(rtnl_notify);
Thomas Graf97676b62006-08-15 00:31:41 -0700589
Denis V. Lunev97c53ca2007-11-19 22:26:51 -0800590void rtnl_set_sk_err(struct net *net, u32 group, int error)
Thomas Graf97676b62006-08-15 00:31:41 -0700591{
Denis V. Lunev97c53ca2007-11-19 22:26:51 -0800592 struct sock *rtnl = net->rtnl;
593
Thomas Graf97676b62006-08-15 00:31:41 -0700594 netlink_set_err(rtnl, 0, group, error);
595}
Eric Dumazete0d087a2009-11-07 01:26:17 -0800596EXPORT_SYMBOL(rtnl_set_sk_err);
Thomas Graf97676b62006-08-15 00:31:41 -0700597
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598int rtnetlink_put_metrics(struct sk_buff *skb, u32 *metrics)
599{
Thomas Graf2d7202b2006-08-22 00:01:27 -0700600 struct nlattr *mx;
601 int i, valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
Thomas Graf2d7202b2006-08-22 00:01:27 -0700603 mx = nla_nest_start(skb, RTA_METRICS);
604 if (mx == NULL)
605 return -ENOBUFS;
606
607 for (i = 0; i < RTAX_MAX; i++) {
608 if (metrics[i]) {
609 valid++;
David S. Millera6574342012-04-01 20:12:00 -0400610 if (nla_put_u32(skb, i+1, metrics[i]))
611 goto nla_put_failure;
Thomas Graf2d7202b2006-08-22 00:01:27 -0700612 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614
David S. Millera57d27f2006-08-22 22:20:14 -0700615 if (!valid) {
616 nla_nest_cancel(skb, mx);
617 return 0;
618 }
Thomas Graf2d7202b2006-08-22 00:01:27 -0700619
620 return nla_nest_end(skb, mx);
621
622nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -0700623 nla_nest_cancel(skb, mx);
624 return -EMSGSIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625}
Eric Dumazete0d087a2009-11-07 01:26:17 -0800626EXPORT_SYMBOL(rtnetlink_put_metrics);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627
Thomas Grafe3703b32006-11-27 09:27:07 -0800628int rtnl_put_cacheinfo(struct sk_buff *skb, struct dst_entry *dst, u32 id,
629 u32 ts, u32 tsage, long expires, u32 error)
630{
631 struct rta_cacheinfo ci = {
632 .rta_lastuse = jiffies_to_clock_t(jiffies - dst->lastuse),
633 .rta_used = dst->__use,
634 .rta_clntref = atomic_read(&(dst->__refcnt)),
635 .rta_error = error,
636 .rta_id = id,
637 .rta_ts = ts,
638 .rta_tsage = tsage,
639 };
640
641 if (expires)
642 ci.rta_expires = jiffies_to_clock_t(expires);
643
644 return nla_put(skb, RTA_CACHEINFO, sizeof(ci), &ci);
645}
Thomas Grafe3703b32006-11-27 09:27:07 -0800646EXPORT_SYMBOL_GPL(rtnl_put_cacheinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647
David S. Miller93b2d4a2008-02-17 18:35:07 -0800648static void set_operstate(struct net_device *dev, unsigned char transition)
Stefan Rompfb00055a2006-03-20 17:09:11 -0800649{
650 unsigned char operstate = dev->operstate;
651
Eric Dumazete0d087a2009-11-07 01:26:17 -0800652 switch (transition) {
Stefan Rompfb00055a2006-03-20 17:09:11 -0800653 case IF_OPER_UP:
654 if ((operstate == IF_OPER_DORMANT ||
655 operstate == IF_OPER_UNKNOWN) &&
656 !netif_dormant(dev))
657 operstate = IF_OPER_UP;
658 break;
659
660 case IF_OPER_DORMANT:
661 if (operstate == IF_OPER_UP ||
662 operstate == IF_OPER_UNKNOWN)
663 operstate = IF_OPER_DORMANT;
664 break;
Stephen Hemminger3ff50b72007-04-20 17:09:22 -0700665 }
Stefan Rompfb00055a2006-03-20 17:09:11 -0800666
667 if (dev->operstate != operstate) {
668 write_lock_bh(&dev_base_lock);
669 dev->operstate = operstate;
670 write_unlock_bh(&dev_base_lock);
David S. Miller93b2d4a2008-02-17 18:35:07 -0800671 netdev_state_change(dev);
672 }
Stefan Rompfb00055a2006-03-20 17:09:11 -0800673}
674
Patrick McHardy3729d502010-02-26 06:34:54 +0000675static unsigned int rtnl_dev_combine_flags(const struct net_device *dev,
676 const struct ifinfomsg *ifm)
677{
678 unsigned int flags = ifm->ifi_flags;
679
680 /* bugwards compatibility: ifi_change == 0 is treated as ~0 */
681 if (ifm->ifi_change)
682 flags = (flags & ifm->ifi_change) |
683 (dev->flags & ~ifm->ifi_change);
684
685 return flags;
686}
687
Thomas Grafb60c5112006-08-04 23:05:34 -0700688static void copy_rtnl_link_stats(struct rtnl_link_stats *a,
Ben Hutchingsbe1f3c22010-06-08 07:19:54 +0000689 const struct rtnl_link_stats64 *b)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690{
Thomas Grafb60c5112006-08-04 23:05:34 -0700691 a->rx_packets = b->rx_packets;
692 a->tx_packets = b->tx_packets;
693 a->rx_bytes = b->rx_bytes;
694 a->tx_bytes = b->tx_bytes;
695 a->rx_errors = b->rx_errors;
696 a->tx_errors = b->tx_errors;
697 a->rx_dropped = b->rx_dropped;
698 a->tx_dropped = b->tx_dropped;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699
Thomas Grafb60c5112006-08-04 23:05:34 -0700700 a->multicast = b->multicast;
701 a->collisions = b->collisions;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702
Thomas Grafb60c5112006-08-04 23:05:34 -0700703 a->rx_length_errors = b->rx_length_errors;
704 a->rx_over_errors = b->rx_over_errors;
705 a->rx_crc_errors = b->rx_crc_errors;
706 a->rx_frame_errors = b->rx_frame_errors;
707 a->rx_fifo_errors = b->rx_fifo_errors;
708 a->rx_missed_errors = b->rx_missed_errors;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709
Thomas Grafb60c5112006-08-04 23:05:34 -0700710 a->tx_aborted_errors = b->tx_aborted_errors;
711 a->tx_carrier_errors = b->tx_carrier_errors;
712 a->tx_fifo_errors = b->tx_fifo_errors;
713 a->tx_heartbeat_errors = b->tx_heartbeat_errors;
714 a->tx_window_errors = b->tx_window_errors;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
Thomas Grafb60c5112006-08-04 23:05:34 -0700716 a->rx_compressed = b->rx_compressed;
717 a->tx_compressed = b->tx_compressed;
Jan Engelhardt10708f32010-03-11 09:57:29 +0000718}
719
Ben Hutchingsbe1f3c22010-06-08 07:19:54 +0000720static void copy_rtnl_link_stats64(void *v, const struct rtnl_link_stats64 *b)
Jan Engelhardt10708f32010-03-11 09:57:29 +0000721{
Eric Dumazetafdcba32010-08-23 07:14:36 +0000722 memcpy(v, b, sizeof(*b));
Jan Engelhardt10708f32010-03-11 09:57:29 +0000723}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724
Chris Wrightc02db8c2010-05-16 01:05:45 -0700725/* All VF info */
Greg Rose115c9b82012-02-21 16:54:48 -0500726static inline int rtnl_vfinfo_size(const struct net_device *dev,
727 u32 ext_filter_mask)
Williams, Mitch Aebc08a62010-02-10 01:44:05 +0000728{
Greg Rose115c9b82012-02-21 16:54:48 -0500729 if (dev->dev.parent && dev_is_pci(dev->dev.parent) &&
730 (ext_filter_mask & RTEXT_FILTER_VF)) {
Chris Wrightc02db8c2010-05-16 01:05:45 -0700731 int num_vfs = dev_num_vf(dev->dev.parent);
Scott Feldman045de012010-05-28 03:42:43 -0700732 size_t size = nla_total_size(sizeof(struct nlattr));
733 size += nla_total_size(num_vfs * sizeof(struct nlattr));
734 size += num_vfs *
735 (nla_total_size(sizeof(struct ifla_vf_mac)) +
736 nla_total_size(sizeof(struct ifla_vf_vlan)) +
Greg Rose5f8444a2011-10-08 03:05:24 +0000737 nla_total_size(sizeof(struct ifla_vf_tx_rate)) +
738 nla_total_size(sizeof(struct ifla_vf_spoofchk)));
Chris Wrightc02db8c2010-05-16 01:05:45 -0700739 return size;
740 } else
Williams, Mitch Aebc08a62010-02-10 01:44:05 +0000741 return 0;
742}
743
Scott Feldman57b61082010-05-17 22:49:55 -0700744static size_t rtnl_port_size(const struct net_device *dev)
745{
746 size_t port_size = nla_total_size(4) /* PORT_VF */
747 + nla_total_size(PORT_PROFILE_MAX) /* PORT_PROFILE */
748 + nla_total_size(sizeof(struct ifla_port_vsi))
749 /* PORT_VSI_TYPE */
750 + nla_total_size(PORT_UUID_MAX) /* PORT_INSTANCE_UUID */
751 + nla_total_size(PORT_UUID_MAX) /* PORT_HOST_UUID */
752 + nla_total_size(1) /* PROT_VDP_REQUEST */
753 + nla_total_size(2); /* PORT_VDP_RESPONSE */
754 size_t vf_ports_size = nla_total_size(sizeof(struct nlattr));
755 size_t vf_port_size = nla_total_size(sizeof(struct nlattr))
756 + port_size;
757 size_t port_self_size = nla_total_size(sizeof(struct nlattr))
758 + port_size;
759
760 if (!dev->netdev_ops->ndo_get_vf_port || !dev->dev.parent)
761 return 0;
762 if (dev_num_vf(dev->dev.parent))
763 return port_self_size + vf_ports_size +
764 vf_port_size * dev_num_vf(dev->dev.parent);
765 else
766 return port_self_size;
767}
768
Greg Rose115c9b82012-02-21 16:54:48 -0500769static noinline size_t if_nlmsg_size(const struct net_device *dev,
770 u32 ext_filter_mask)
Thomas Graf339bf982006-11-10 14:10:15 -0800771{
772 return NLMSG_ALIGN(sizeof(struct ifinfomsg))
773 + nla_total_size(IFNAMSIZ) /* IFLA_IFNAME */
Stephen Hemminger0b815a12008-09-22 21:28:11 -0700774 + nla_total_size(IFALIASZ) /* IFLA_IFALIAS */
Thomas Graf339bf982006-11-10 14:10:15 -0800775 + nla_total_size(IFNAMSIZ) /* IFLA_QDISC */
776 + nla_total_size(sizeof(struct rtnl_link_ifmap))
777 + nla_total_size(sizeof(struct rtnl_link_stats))
Jan Engelhardtadcfe192010-03-27 17:15:29 -0700778 + nla_total_size(sizeof(struct rtnl_link_stats64))
Thomas Graf339bf982006-11-10 14:10:15 -0800779 + nla_total_size(MAX_ADDR_LEN) /* IFLA_ADDRESS */
780 + nla_total_size(MAX_ADDR_LEN) /* IFLA_BROADCAST */
781 + nla_total_size(4) /* IFLA_TXQLEN */
782 + nla_total_size(4) /* IFLA_WEIGHT */
783 + nla_total_size(4) /* IFLA_MTU */
784 + nla_total_size(4) /* IFLA_LINK */
785 + nla_total_size(4) /* IFLA_MASTER */
Ben Greearedbc0bb2012-03-29 12:51:30 +0000786 + nla_total_size(4) /* IFLA_PROMISCUITY */
Thomas Graf339bf982006-11-10 14:10:15 -0800787 + nla_total_size(1) /* IFLA_OPERSTATE */
Patrick McHardy38f7b872007-06-13 12:03:51 -0700788 + nla_total_size(1) /* IFLA_LINKMODE */
Greg Rose115c9b82012-02-21 16:54:48 -0500789 + nla_total_size(ext_filter_mask
790 & RTEXT_FILTER_VF ? 4 : 0) /* IFLA_NUM_VF */
791 + rtnl_vfinfo_size(dev, ext_filter_mask) /* IFLA_VFINFO_LIST */
Scott Feldman57b61082010-05-17 22:49:55 -0700792 + rtnl_port_size(dev) /* IFLA_VF_PORTS + IFLA_PORT_SELF */
Thomas Graff8ff1822010-11-16 04:30:14 +0000793 + rtnl_link_get_size(dev) /* IFLA_LINKINFO */
794 + rtnl_link_get_af_size(dev); /* IFLA_AF_SPEC */
Thomas Graf339bf982006-11-10 14:10:15 -0800795}
796
Scott Feldman57b61082010-05-17 22:49:55 -0700797static int rtnl_vf_ports_fill(struct sk_buff *skb, struct net_device *dev)
798{
799 struct nlattr *vf_ports;
800 struct nlattr *vf_port;
801 int vf;
802 int err;
803
804 vf_ports = nla_nest_start(skb, IFLA_VF_PORTS);
805 if (!vf_ports)
806 return -EMSGSIZE;
807
808 for (vf = 0; vf < dev_num_vf(dev->dev.parent); vf++) {
809 vf_port = nla_nest_start(skb, IFLA_VF_PORT);
Scott Feldman8ca94182010-05-28 03:42:18 -0700810 if (!vf_port)
811 goto nla_put_failure;
David S. Millera6574342012-04-01 20:12:00 -0400812 if (nla_put_u32(skb, IFLA_PORT_VF, vf))
813 goto nla_put_failure;
Scott Feldman57b61082010-05-17 22:49:55 -0700814 err = dev->netdev_ops->ndo_get_vf_port(dev, vf, skb);
Scott Feldman8ca94182010-05-28 03:42:18 -0700815 if (err == -EMSGSIZE)
816 goto nla_put_failure;
Scott Feldman57b61082010-05-17 22:49:55 -0700817 if (err) {
Scott Feldman57b61082010-05-17 22:49:55 -0700818 nla_nest_cancel(skb, vf_port);
819 continue;
820 }
821 nla_nest_end(skb, vf_port);
822 }
823
824 nla_nest_end(skb, vf_ports);
825
826 return 0;
Scott Feldman8ca94182010-05-28 03:42:18 -0700827
828nla_put_failure:
829 nla_nest_cancel(skb, vf_ports);
830 return -EMSGSIZE;
Scott Feldman57b61082010-05-17 22:49:55 -0700831}
832
833static int rtnl_port_self_fill(struct sk_buff *skb, struct net_device *dev)
834{
835 struct nlattr *port_self;
836 int err;
837
838 port_self = nla_nest_start(skb, IFLA_PORT_SELF);
839 if (!port_self)
840 return -EMSGSIZE;
841
842 err = dev->netdev_ops->ndo_get_vf_port(dev, PORT_SELF_VF, skb);
843 if (err) {
844 nla_nest_cancel(skb, port_self);
Scott Feldman8ca94182010-05-28 03:42:18 -0700845 return (err == -EMSGSIZE) ? err : 0;
Scott Feldman57b61082010-05-17 22:49:55 -0700846 }
847
848 nla_nest_end(skb, port_self);
849
850 return 0;
851}
852
853static int rtnl_port_fill(struct sk_buff *skb, struct net_device *dev)
854{
855 int err;
856
857 if (!dev->netdev_ops->ndo_get_vf_port || !dev->dev.parent)
858 return 0;
859
860 err = rtnl_port_self_fill(skb, dev);
861 if (err)
862 return err;
863
864 if (dev_num_vf(dev->dev.parent)) {
865 err = rtnl_vf_ports_fill(skb, dev);
866 if (err)
867 return err;
868 }
869
870 return 0;
871}
872
Thomas Grafb60c5112006-08-04 23:05:34 -0700873static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
Patrick McHardy575c3e22007-05-22 17:00:49 -0700874 int type, u32 pid, u32 seq, u32 change,
Greg Rose115c9b82012-02-21 16:54:48 -0500875 unsigned int flags, u32 ext_filter_mask)
Thomas Grafb60c5112006-08-04 23:05:34 -0700876{
877 struct ifinfomsg *ifm;
878 struct nlmsghdr *nlh;
Eric Dumazet28172732010-07-07 14:58:56 -0700879 struct rtnl_link_stats64 temp;
Ben Hutchingsbe1f3c22010-06-08 07:19:54 +0000880 const struct rtnl_link_stats64 *stats;
Thomas Graff8ff1822010-11-16 04:30:14 +0000881 struct nlattr *attr, *af_spec;
882 struct rtnl_af_ops *af_ops;
Thomas Grafb60c5112006-08-04 23:05:34 -0700883
Eric Dumazet2907c352011-05-25 07:34:04 +0000884 ASSERT_RTNL();
Thomas Grafb60c5112006-08-04 23:05:34 -0700885 nlh = nlmsg_put(skb, pid, seq, type, sizeof(*ifm), flags);
886 if (nlh == NULL)
Patrick McHardy26932562007-01-31 23:16:40 -0800887 return -EMSGSIZE;
Thomas Grafb60c5112006-08-04 23:05:34 -0700888
889 ifm = nlmsg_data(nlh);
890 ifm->ifi_family = AF_UNSPEC;
891 ifm->__ifi_pad = 0;
892 ifm->ifi_type = dev->type;
893 ifm->ifi_index = dev->ifindex;
894 ifm->ifi_flags = dev_get_flags(dev);
895 ifm->ifi_change = change;
896
David S. Millera6574342012-04-01 20:12:00 -0400897 if (nla_put_string(skb, IFLA_IFNAME, dev->name) ||
898 nla_put_u32(skb, IFLA_TXQLEN, dev->tx_queue_len) ||
899 nla_put_u8(skb, IFLA_OPERSTATE,
900 netif_running(dev) ? dev->operstate : IF_OPER_DOWN) ||
901 nla_put_u8(skb, IFLA_LINKMODE, dev->link_mode) ||
902 nla_put_u32(skb, IFLA_MTU, dev->mtu) ||
903 nla_put_u32(skb, IFLA_GROUP, dev->group) ||
Ben Greearedbc0bb2012-03-29 12:51:30 +0000904 nla_put_u32(skb, IFLA_PROMISCUITY, dev->promiscuity) ||
David S. Millera6574342012-04-01 20:12:00 -0400905 (dev->ifindex != dev->iflink &&
906 nla_put_u32(skb, IFLA_LINK, dev->iflink)) ||
907 (dev->master &&
908 nla_put_u32(skb, IFLA_MASTER, dev->master->ifindex)) ||
909 (dev->qdisc &&
910 nla_put_string(skb, IFLA_QDISC, dev->qdisc->ops->id)) ||
911 (dev->ifalias &&
912 nla_put_string(skb, IFLA_IFALIAS, dev->ifalias)))
913 goto nla_put_failure;
Stephen Hemminger0b815a12008-09-22 21:28:11 -0700914
Stefan Rompfb00055a2006-03-20 17:09:11 -0800915 if (1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 struct rtnl_link_ifmap map = {
917 .mem_start = dev->mem_start,
918 .mem_end = dev->mem_end,
919 .base_addr = dev->base_addr,
920 .irq = dev->irq,
921 .dma = dev->dma,
922 .port = dev->if_port,
923 };
David S. Millera6574342012-04-01 20:12:00 -0400924 if (nla_put(skb, IFLA_MAP, sizeof(map), &map))
925 goto nla_put_failure;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 }
927
928 if (dev->addr_len) {
David S. Millera6574342012-04-01 20:12:00 -0400929 if (nla_put(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr) ||
930 nla_put(skb, IFLA_BROADCAST, dev->addr_len, dev->broadcast))
931 goto nla_put_failure;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 }
933
Pavel Emelyanov96e74082008-05-21 14:12:46 -0700934 attr = nla_reserve(skb, IFLA_STATS,
935 sizeof(struct rtnl_link_stats));
936 if (attr == NULL)
937 goto nla_put_failure;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938
Eric Dumazet28172732010-07-07 14:58:56 -0700939 stats = dev_get_stats(dev, &temp);
Pavel Emelyanov96e74082008-05-21 14:12:46 -0700940 copy_rtnl_link_stats(nla_data(attr), stats);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941
Jan Engelhardt10708f32010-03-11 09:57:29 +0000942 attr = nla_reserve(skb, IFLA_STATS64,
943 sizeof(struct rtnl_link_stats64));
944 if (attr == NULL)
945 goto nla_put_failure;
Jan Engelhardt10708f32010-03-11 09:57:29 +0000946 copy_rtnl_link_stats64(nla_data(attr), stats);
947
David S. Millera6574342012-04-01 20:12:00 -0400948 if (dev->dev.parent && (ext_filter_mask & RTEXT_FILTER_VF) &&
949 nla_put_u32(skb, IFLA_NUM_VF, dev_num_vf(dev->dev.parent)))
950 goto nla_put_failure;
Scott Feldman57b61082010-05-17 22:49:55 -0700951
Greg Rose115c9b82012-02-21 16:54:48 -0500952 if (dev->netdev_ops->ndo_get_vf_config && dev->dev.parent
953 && (ext_filter_mask & RTEXT_FILTER_VF)) {
Williams, Mitch Aebc08a62010-02-10 01:44:05 +0000954 int i;
Williams, Mitch Aebc08a62010-02-10 01:44:05 +0000955
Chris Wrightc02db8c2010-05-16 01:05:45 -0700956 struct nlattr *vfinfo, *vf;
957 int num_vfs = dev_num_vf(dev->dev.parent);
958
Chris Wrightc02db8c2010-05-16 01:05:45 -0700959 vfinfo = nla_nest_start(skb, IFLA_VFINFO_LIST);
960 if (!vfinfo)
961 goto nla_put_failure;
962 for (i = 0; i < num_vfs; i++) {
963 struct ifla_vf_info ivi;
964 struct ifla_vf_mac vf_mac;
965 struct ifla_vf_vlan vf_vlan;
966 struct ifla_vf_tx_rate vf_tx_rate;
Greg Rose5f8444a2011-10-08 03:05:24 +0000967 struct ifla_vf_spoofchk vf_spoofchk;
968
969 /*
970 * Not all SR-IOV capable drivers support the
971 * spoofcheck query. Preset to -1 so the user
972 * space tool can detect that the driver didn't
973 * report anything.
974 */
975 ivi.spoofchk = -1;
Williams, Mitch Aebc08a62010-02-10 01:44:05 +0000976 if (dev->netdev_ops->ndo_get_vf_config(dev, i, &ivi))
977 break;
Greg Rose5f8444a2011-10-08 03:05:24 +0000978 vf_mac.vf =
979 vf_vlan.vf =
980 vf_tx_rate.vf =
981 vf_spoofchk.vf = ivi.vf;
982
Chris Wrightc02db8c2010-05-16 01:05:45 -0700983 memcpy(vf_mac.mac, ivi.mac, sizeof(ivi.mac));
984 vf_vlan.vlan = ivi.vlan;
985 vf_vlan.qos = ivi.qos;
986 vf_tx_rate.rate = ivi.tx_rate;
Greg Rose5f8444a2011-10-08 03:05:24 +0000987 vf_spoofchk.setting = ivi.spoofchk;
Chris Wrightc02db8c2010-05-16 01:05:45 -0700988 vf = nla_nest_start(skb, IFLA_VF_INFO);
989 if (!vf) {
990 nla_nest_cancel(skb, vfinfo);
991 goto nla_put_failure;
992 }
David S. Millera6574342012-04-01 20:12:00 -0400993 if (nla_put(skb, IFLA_VF_MAC, sizeof(vf_mac), &vf_mac) ||
994 nla_put(skb, IFLA_VF_VLAN, sizeof(vf_vlan), &vf_vlan) ||
995 nla_put(skb, IFLA_VF_TX_RATE, sizeof(vf_tx_rate),
996 &vf_tx_rate) ||
997 nla_put(skb, IFLA_VF_SPOOFCHK, sizeof(vf_spoofchk),
998 &vf_spoofchk))
999 goto nla_put_failure;
Chris Wrightc02db8c2010-05-16 01:05:45 -07001000 nla_nest_end(skb, vf);
Williams, Mitch Aebc08a62010-02-10 01:44:05 +00001001 }
Chris Wrightc02db8c2010-05-16 01:05:45 -07001002 nla_nest_end(skb, vfinfo);
Williams, Mitch Aebc08a62010-02-10 01:44:05 +00001003 }
Scott Feldman57b61082010-05-17 22:49:55 -07001004
1005 if (rtnl_port_fill(skb, dev))
1006 goto nla_put_failure;
1007
Patrick McHardy38f7b872007-06-13 12:03:51 -07001008 if (dev->rtnl_link_ops) {
1009 if (rtnl_link_fill(skb, dev) < 0)
1010 goto nla_put_failure;
1011 }
1012
Thomas Graff8ff1822010-11-16 04:30:14 +00001013 if (!(af_spec = nla_nest_start(skb, IFLA_AF_SPEC)))
1014 goto nla_put_failure;
1015
1016 list_for_each_entry(af_ops, &rtnl_af_ops, list) {
1017 if (af_ops->fill_link_af) {
1018 struct nlattr *af;
1019 int err;
1020
1021 if (!(af = nla_nest_start(skb, af_ops->family)))
1022 goto nla_put_failure;
1023
1024 err = af_ops->fill_link_af(skb, dev);
1025
1026 /*
1027 * Caller may return ENODATA to indicate that there
1028 * was no data to be dumped. This is not an error, it
1029 * means we should trim the attribute header and
1030 * continue.
1031 */
1032 if (err == -ENODATA)
1033 nla_nest_cancel(skb, af);
1034 else if (err < 0)
1035 goto nla_put_failure;
1036
1037 nla_nest_end(skb, af);
1038 }
1039 }
1040
1041 nla_nest_end(skb, af_spec);
1042
Thomas Grafb60c5112006-08-04 23:05:34 -07001043 return nlmsg_end(skb, nlh);
1044
1045nla_put_failure:
Patrick McHardy26932562007-01-31 23:16:40 -08001046 nlmsg_cancel(skb, nlh);
1047 return -EMSGSIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048}
1049
Thomas Grafb60c5112006-08-04 23:05:34 -07001050static int rtnl_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051{
YOSHIFUJI Hideaki3b1e0a62008-03-26 02:26:21 +09001052 struct net *net = sock_net(skb->sk);
Eric Dumazet7c28bd02009-10-24 06:13:17 -07001053 int h, s_h;
1054 int idx = 0, s_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 struct net_device *dev;
Eric Dumazet7c28bd02009-10-24 06:13:17 -07001056 struct hlist_head *head;
1057 struct hlist_node *node;
Greg Rose115c9b82012-02-21 16:54:48 -05001058 struct nlattr *tb[IFLA_MAX+1];
1059 u32 ext_filter_mask = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060
Eric Dumazet7c28bd02009-10-24 06:13:17 -07001061 s_h = cb->args[0];
1062 s_idx = cb->args[1];
1063
Eric Dumazete67f88d2011-04-27 22:56:07 +00001064 rcu_read_lock();
Thomas Graf4e985ad2011-06-21 03:11:20 +00001065 cb->seq = net->dev_base_seq;
1066
Eric Dumazeta4b64fb2012-03-04 12:32:10 +00001067 if (nlmsg_parse(cb->nlh, sizeof(struct rtgenmsg), tb, IFLA_MAX,
1068 ifla_policy) >= 0) {
Greg Rose115c9b82012-02-21 16:54:48 -05001069
Eric Dumazeta4b64fb2012-03-04 12:32:10 +00001070 if (tb[IFLA_EXT_MASK])
1071 ext_filter_mask = nla_get_u32(tb[IFLA_EXT_MASK]);
1072 }
Greg Rose115c9b82012-02-21 16:54:48 -05001073
Eric Dumazet7c28bd02009-10-24 06:13:17 -07001074 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
1075 idx = 0;
1076 head = &net->dev_index_head[h];
Eric Dumazete67f88d2011-04-27 22:56:07 +00001077 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
Eric Dumazet7c28bd02009-10-24 06:13:17 -07001078 if (idx < s_idx)
1079 goto cont;
1080 if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
1081 NETLINK_CB(cb->skb).pid,
1082 cb->nlh->nlmsg_seq, 0,
Greg Rose115c9b82012-02-21 16:54:48 -05001083 NLM_F_MULTI,
1084 ext_filter_mask) <= 0)
Eric Dumazet7c28bd02009-10-24 06:13:17 -07001085 goto out;
Thomas Graf4e985ad2011-06-21 03:11:20 +00001086
1087 nl_dump_check_consistent(cb, nlmsg_hdr(skb));
Pavel Emelianov7562f872007-05-03 15:13:45 -07001088cont:
Eric Dumazet7c28bd02009-10-24 06:13:17 -07001089 idx++;
1090 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 }
Eric Dumazet7c28bd02009-10-24 06:13:17 -07001092out:
Eric Dumazete67f88d2011-04-27 22:56:07 +00001093 rcu_read_unlock();
Eric Dumazet7c28bd02009-10-24 06:13:17 -07001094 cb->args[1] = idx;
1095 cb->args[0] = h;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096
1097 return skb->len;
1098}
1099
Pavel Emelianove7199282007-08-08 22:16:38 -07001100const struct nla_policy ifla_policy[IFLA_MAX+1] = {
Thomas Graf5176f912006-08-26 20:13:18 -07001101 [IFLA_IFNAME] = { .type = NLA_STRING, .len = IFNAMSIZ-1 },
Patrick McHardy38f7b872007-06-13 12:03:51 -07001102 [IFLA_ADDRESS] = { .type = NLA_BINARY, .len = MAX_ADDR_LEN },
1103 [IFLA_BROADCAST] = { .type = NLA_BINARY, .len = MAX_ADDR_LEN },
Thomas Graf5176f912006-08-26 20:13:18 -07001104 [IFLA_MAP] = { .len = sizeof(struct rtnl_link_ifmap) },
Thomas Grafda5e0492006-08-10 21:17:37 -07001105 [IFLA_MTU] = { .type = NLA_U32 },
Thomas Graf76e87302008-02-19 16:12:08 -08001106 [IFLA_LINK] = { .type = NLA_U32 },
Jiri Pirkofbaec0e2011-02-13 10:15:37 +00001107 [IFLA_MASTER] = { .type = NLA_U32 },
Thomas Grafda5e0492006-08-10 21:17:37 -07001108 [IFLA_TXQLEN] = { .type = NLA_U32 },
1109 [IFLA_WEIGHT] = { .type = NLA_U32 },
1110 [IFLA_OPERSTATE] = { .type = NLA_U8 },
1111 [IFLA_LINKMODE] = { .type = NLA_U8 },
Thomas Graf76e87302008-02-19 16:12:08 -08001112 [IFLA_LINKINFO] = { .type = NLA_NESTED },
Eric W. Biedermand8a5ec62007-09-12 13:57:04 +02001113 [IFLA_NET_NS_PID] = { .type = NLA_U32 },
Eric W. Biedermanf0630522011-05-04 17:51:50 -07001114 [IFLA_NET_NS_FD] = { .type = NLA_U32 },
Stephen Hemminger0b815a12008-09-22 21:28:11 -07001115 [IFLA_IFALIAS] = { .type = NLA_STRING, .len = IFALIASZ-1 },
Chris Wrightc02db8c2010-05-16 01:05:45 -07001116 [IFLA_VFINFO_LIST] = {. type = NLA_NESTED },
Scott Feldman57b61082010-05-17 22:49:55 -07001117 [IFLA_VF_PORTS] = { .type = NLA_NESTED },
1118 [IFLA_PORT_SELF] = { .type = NLA_NESTED },
Thomas Graff8ff1822010-11-16 04:30:14 +00001119 [IFLA_AF_SPEC] = { .type = NLA_NESTED },
Greg Rose115c9b82012-02-21 16:54:48 -05001120 [IFLA_EXT_MASK] = { .type = NLA_U32 },
Ben Greearedbc0bb2012-03-29 12:51:30 +00001121 [IFLA_PROMISCUITY] = { .type = NLA_U32 },
Thomas Grafda5e0492006-08-10 21:17:37 -07001122};
Eric Dumazete0d087a2009-11-07 01:26:17 -08001123EXPORT_SYMBOL(ifla_policy);
Thomas Grafda5e0492006-08-10 21:17:37 -07001124
Patrick McHardy38f7b872007-06-13 12:03:51 -07001125static const struct nla_policy ifla_info_policy[IFLA_INFO_MAX+1] = {
1126 [IFLA_INFO_KIND] = { .type = NLA_STRING },
1127 [IFLA_INFO_DATA] = { .type = NLA_NESTED },
1128};
1129
Chris Wrightc02db8c2010-05-16 01:05:45 -07001130static const struct nla_policy ifla_vfinfo_policy[IFLA_VF_INFO_MAX+1] = {
1131 [IFLA_VF_INFO] = { .type = NLA_NESTED },
1132};
1133
1134static const struct nla_policy ifla_vf_policy[IFLA_VF_MAX+1] = {
1135 [IFLA_VF_MAC] = { .type = NLA_BINARY,
1136 .len = sizeof(struct ifla_vf_mac) },
1137 [IFLA_VF_VLAN] = { .type = NLA_BINARY,
1138 .len = sizeof(struct ifla_vf_vlan) },
1139 [IFLA_VF_TX_RATE] = { .type = NLA_BINARY,
1140 .len = sizeof(struct ifla_vf_tx_rate) },
Greg Rose48752f62012-02-08 00:45:00 +00001141 [IFLA_VF_SPOOFCHK] = { .type = NLA_BINARY,
1142 .len = sizeof(struct ifla_vf_spoofchk) },
Chris Wrightc02db8c2010-05-16 01:05:45 -07001143};
1144
Scott Feldman57b61082010-05-17 22:49:55 -07001145static const struct nla_policy ifla_port_policy[IFLA_PORT_MAX+1] = {
1146 [IFLA_PORT_VF] = { .type = NLA_U32 },
1147 [IFLA_PORT_PROFILE] = { .type = NLA_STRING,
1148 .len = PORT_PROFILE_MAX },
1149 [IFLA_PORT_VSI_TYPE] = { .type = NLA_BINARY,
1150 .len = sizeof(struct ifla_port_vsi)},
1151 [IFLA_PORT_INSTANCE_UUID] = { .type = NLA_BINARY,
1152 .len = PORT_UUID_MAX },
1153 [IFLA_PORT_HOST_UUID] = { .type = NLA_STRING,
1154 .len = PORT_UUID_MAX },
1155 [IFLA_PORT_REQUEST] = { .type = NLA_U8, },
1156 [IFLA_PORT_RESPONSE] = { .type = NLA_U16, },
1157};
1158
Eric W. Biederman81adee42009-11-08 00:53:51 -08001159struct net *rtnl_link_get_net(struct net *src_net, struct nlattr *tb[])
1160{
1161 struct net *net;
1162 /* Examine the link attributes and figure out which
1163 * network namespace we are talking about.
1164 */
1165 if (tb[IFLA_NET_NS_PID])
1166 net = get_net_ns_by_pid(nla_get_u32(tb[IFLA_NET_NS_PID]));
Eric W. Biedermanf0630522011-05-04 17:51:50 -07001167 else if (tb[IFLA_NET_NS_FD])
1168 net = get_net_ns_by_fd(nla_get_u32(tb[IFLA_NET_NS_FD]));
Eric W. Biederman81adee42009-11-08 00:53:51 -08001169 else
1170 net = get_net(src_net);
1171 return net;
1172}
1173EXPORT_SYMBOL(rtnl_link_get_net);
1174
Thomas Graf1840bb12008-02-23 19:54:36 -08001175static int validate_linkmsg(struct net_device *dev, struct nlattr *tb[])
1176{
1177 if (dev) {
1178 if (tb[IFLA_ADDRESS] &&
1179 nla_len(tb[IFLA_ADDRESS]) < dev->addr_len)
1180 return -EINVAL;
1181
1182 if (tb[IFLA_BROADCAST] &&
1183 nla_len(tb[IFLA_BROADCAST]) < dev->addr_len)
1184 return -EINVAL;
1185 }
1186
Thomas Grafcf7afbf2010-11-22 01:31:54 +00001187 if (tb[IFLA_AF_SPEC]) {
1188 struct nlattr *af;
1189 int rem, err;
1190
1191 nla_for_each_nested(af, tb[IFLA_AF_SPEC], rem) {
1192 const struct rtnl_af_ops *af_ops;
1193
1194 if (!(af_ops = rtnl_af_lookup(nla_type(af))))
1195 return -EAFNOSUPPORT;
1196
1197 if (!af_ops->set_link_af)
1198 return -EOPNOTSUPP;
1199
1200 if (af_ops->validate_link_af) {
Kurt Van Dijck6d3a9a62011-01-26 04:55:24 +00001201 err = af_ops->validate_link_af(dev, af);
Thomas Grafcf7afbf2010-11-22 01:31:54 +00001202 if (err < 0)
1203 return err;
1204 }
1205 }
1206 }
1207
Thomas Graf1840bb12008-02-23 19:54:36 -08001208 return 0;
1209}
1210
Chris Wrightc02db8c2010-05-16 01:05:45 -07001211static int do_setvfinfo(struct net_device *dev, struct nlattr *attr)
1212{
1213 int rem, err = -EINVAL;
1214 struct nlattr *vf;
1215 const struct net_device_ops *ops = dev->netdev_ops;
1216
1217 nla_for_each_nested(vf, attr, rem) {
1218 switch (nla_type(vf)) {
1219 case IFLA_VF_MAC: {
1220 struct ifla_vf_mac *ivm;
1221 ivm = nla_data(vf);
1222 err = -EOPNOTSUPP;
1223 if (ops->ndo_set_vf_mac)
1224 err = ops->ndo_set_vf_mac(dev, ivm->vf,
1225 ivm->mac);
1226 break;
1227 }
1228 case IFLA_VF_VLAN: {
1229 struct ifla_vf_vlan *ivv;
1230 ivv = nla_data(vf);
1231 err = -EOPNOTSUPP;
1232 if (ops->ndo_set_vf_vlan)
1233 err = ops->ndo_set_vf_vlan(dev, ivv->vf,
1234 ivv->vlan,
1235 ivv->qos);
1236 break;
1237 }
1238 case IFLA_VF_TX_RATE: {
1239 struct ifla_vf_tx_rate *ivt;
1240 ivt = nla_data(vf);
1241 err = -EOPNOTSUPP;
1242 if (ops->ndo_set_vf_tx_rate)
1243 err = ops->ndo_set_vf_tx_rate(dev, ivt->vf,
1244 ivt->rate);
1245 break;
1246 }
Greg Rose5f8444a2011-10-08 03:05:24 +00001247 case IFLA_VF_SPOOFCHK: {
1248 struct ifla_vf_spoofchk *ivs;
1249 ivs = nla_data(vf);
1250 err = -EOPNOTSUPP;
1251 if (ops->ndo_set_vf_spoofchk)
1252 err = ops->ndo_set_vf_spoofchk(dev, ivs->vf,
1253 ivs->setting);
1254 break;
1255 }
Chris Wrightc02db8c2010-05-16 01:05:45 -07001256 default:
1257 err = -EINVAL;
1258 break;
1259 }
1260 if (err)
1261 break;
1262 }
1263 return err;
1264}
1265
Jiri Pirkofbaec0e2011-02-13 10:15:37 +00001266static int do_set_master(struct net_device *dev, int ifindex)
1267{
1268 struct net_device *master_dev;
1269 const struct net_device_ops *ops;
1270 int err;
1271
1272 if (dev->master) {
1273 if (dev->master->ifindex == ifindex)
1274 return 0;
1275 ops = dev->master->netdev_ops;
1276 if (ops->ndo_del_slave) {
1277 err = ops->ndo_del_slave(dev->master, dev);
1278 if (err)
1279 return err;
1280 } else {
1281 return -EOPNOTSUPP;
1282 }
1283 }
1284
1285 if (ifindex) {
1286 master_dev = __dev_get_by_index(dev_net(dev), ifindex);
1287 if (!master_dev)
1288 return -EINVAL;
1289 ops = master_dev->netdev_ops;
1290 if (ops->ndo_add_slave) {
1291 err = ops->ndo_add_slave(master_dev, dev);
1292 if (err)
1293 return err;
1294 } else {
1295 return -EOPNOTSUPP;
1296 }
1297 }
1298 return 0;
1299}
1300
Patrick McHardy0157f602007-06-13 12:03:36 -07001301static int do_setlink(struct net_device *dev, struct ifinfomsg *ifm,
Patrick McHardy38f7b872007-06-13 12:03:51 -07001302 struct nlattr **tb, char *ifname, int modified)
Patrick McHardy0157f602007-06-13 12:03:36 -07001303{
Stephen Hemmingerd3147742008-11-19 21:32:24 -08001304 const struct net_device_ops *ops = dev->netdev_ops;
Patrick McHardy38f7b872007-06-13 12:03:51 -07001305 int send_addr_notify = 0;
Patrick McHardy0157f602007-06-13 12:03:36 -07001306 int err;
1307
Eric W. Biedermanf0630522011-05-04 17:51:50 -07001308 if (tb[IFLA_NET_NS_PID] || tb[IFLA_NET_NS_FD]) {
Eric W. Biederman81adee42009-11-08 00:53:51 -08001309 struct net *net = rtnl_link_get_net(dev_net(dev), tb);
Eric W. Biedermand8a5ec62007-09-12 13:57:04 +02001310 if (IS_ERR(net)) {
1311 err = PTR_ERR(net);
1312 goto errout;
1313 }
1314 err = dev_change_net_namespace(dev, net, ifname);
1315 put_net(net);
1316 if (err)
1317 goto errout;
1318 modified = 1;
1319 }
1320
Patrick McHardy0157f602007-06-13 12:03:36 -07001321 if (tb[IFLA_MAP]) {
1322 struct rtnl_link_ifmap *u_map;
1323 struct ifmap k_map;
1324
Stephen Hemmingerd3147742008-11-19 21:32:24 -08001325 if (!ops->ndo_set_config) {
Patrick McHardy0157f602007-06-13 12:03:36 -07001326 err = -EOPNOTSUPP;
1327 goto errout;
1328 }
1329
1330 if (!netif_device_present(dev)) {
1331 err = -ENODEV;
1332 goto errout;
1333 }
1334
1335 u_map = nla_data(tb[IFLA_MAP]);
1336 k_map.mem_start = (unsigned long) u_map->mem_start;
1337 k_map.mem_end = (unsigned long) u_map->mem_end;
1338 k_map.base_addr = (unsigned short) u_map->base_addr;
1339 k_map.irq = (unsigned char) u_map->irq;
1340 k_map.dma = (unsigned char) u_map->dma;
1341 k_map.port = (unsigned char) u_map->port;
1342
Stephen Hemmingerd3147742008-11-19 21:32:24 -08001343 err = ops->ndo_set_config(dev, &k_map);
Patrick McHardy0157f602007-06-13 12:03:36 -07001344 if (err < 0)
1345 goto errout;
1346
1347 modified = 1;
1348 }
1349
1350 if (tb[IFLA_ADDRESS]) {
1351 struct sockaddr *sa;
1352 int len;
1353
Stephen Hemmingerd3147742008-11-19 21:32:24 -08001354 if (!ops->ndo_set_mac_address) {
Patrick McHardy0157f602007-06-13 12:03:36 -07001355 err = -EOPNOTSUPP;
1356 goto errout;
1357 }
1358
1359 if (!netif_device_present(dev)) {
1360 err = -ENODEV;
1361 goto errout;
1362 }
1363
1364 len = sizeof(sa_family_t) + dev->addr_len;
1365 sa = kmalloc(len, GFP_KERNEL);
1366 if (!sa) {
1367 err = -ENOMEM;
1368 goto errout;
1369 }
1370 sa->sa_family = dev->type;
1371 memcpy(sa->sa_data, nla_data(tb[IFLA_ADDRESS]),
1372 dev->addr_len);
Stephen Hemmingerd3147742008-11-19 21:32:24 -08001373 err = ops->ndo_set_mac_address(dev, sa);
Patrick McHardy0157f602007-06-13 12:03:36 -07001374 kfree(sa);
1375 if (err)
1376 goto errout;
1377 send_addr_notify = 1;
1378 modified = 1;
1379 }
1380
1381 if (tb[IFLA_MTU]) {
1382 err = dev_set_mtu(dev, nla_get_u32(tb[IFLA_MTU]));
1383 if (err < 0)
1384 goto errout;
1385 modified = 1;
1386 }
1387
Vlad Dogarucbda10f2011-01-13 23:38:30 +00001388 if (tb[IFLA_GROUP]) {
1389 dev_set_group(dev, nla_get_u32(tb[IFLA_GROUP]));
1390 modified = 1;
1391 }
1392
Patrick McHardy0157f602007-06-13 12:03:36 -07001393 /*
1394 * Interface selected by interface index but interface
1395 * name provided implies that a name change has been
1396 * requested.
1397 */
1398 if (ifm->ifi_index > 0 && ifname[0]) {
1399 err = dev_change_name(dev, ifname);
1400 if (err < 0)
1401 goto errout;
1402 modified = 1;
1403 }
1404
Stephen Hemminger0b815a12008-09-22 21:28:11 -07001405 if (tb[IFLA_IFALIAS]) {
1406 err = dev_set_alias(dev, nla_data(tb[IFLA_IFALIAS]),
1407 nla_len(tb[IFLA_IFALIAS]));
1408 if (err < 0)
1409 goto errout;
1410 modified = 1;
1411 }
1412
Patrick McHardy0157f602007-06-13 12:03:36 -07001413 if (tb[IFLA_BROADCAST]) {
1414 nla_memcpy(dev->broadcast, tb[IFLA_BROADCAST], dev->addr_len);
1415 send_addr_notify = 1;
1416 }
1417
1418 if (ifm->ifi_flags || ifm->ifi_change) {
Patrick McHardy3729d502010-02-26 06:34:54 +00001419 err = dev_change_flags(dev, rtnl_dev_combine_flags(dev, ifm));
Johannes Berg5f9021c2008-11-16 23:20:31 -08001420 if (err < 0)
1421 goto errout;
Patrick McHardy0157f602007-06-13 12:03:36 -07001422 }
1423
Jiri Pirkofbaec0e2011-02-13 10:15:37 +00001424 if (tb[IFLA_MASTER]) {
1425 err = do_set_master(dev, nla_get_u32(tb[IFLA_MASTER]));
1426 if (err)
1427 goto errout;
1428 modified = 1;
1429 }
1430
David S. Miller93b2d4a2008-02-17 18:35:07 -08001431 if (tb[IFLA_TXQLEN])
1432 dev->tx_queue_len = nla_get_u32(tb[IFLA_TXQLEN]);
Patrick McHardy0157f602007-06-13 12:03:36 -07001433
Patrick McHardy0157f602007-06-13 12:03:36 -07001434 if (tb[IFLA_OPERSTATE])
David S. Miller93b2d4a2008-02-17 18:35:07 -08001435 set_operstate(dev, nla_get_u8(tb[IFLA_OPERSTATE]));
Patrick McHardy0157f602007-06-13 12:03:36 -07001436
1437 if (tb[IFLA_LINKMODE]) {
David S. Miller93b2d4a2008-02-17 18:35:07 -08001438 write_lock_bh(&dev_base_lock);
1439 dev->link_mode = nla_get_u8(tb[IFLA_LINKMODE]);
1440 write_unlock_bh(&dev_base_lock);
Patrick McHardy0157f602007-06-13 12:03:36 -07001441 }
1442
Chris Wrightc02db8c2010-05-16 01:05:45 -07001443 if (tb[IFLA_VFINFO_LIST]) {
1444 struct nlattr *attr;
1445 int rem;
1446 nla_for_each_nested(attr, tb[IFLA_VFINFO_LIST], rem) {
David Howells253683b2010-05-21 02:25:27 +00001447 if (nla_type(attr) != IFLA_VF_INFO) {
1448 err = -EINVAL;
Chris Wrightc02db8c2010-05-16 01:05:45 -07001449 goto errout;
David Howells253683b2010-05-21 02:25:27 +00001450 }
Chris Wrightc02db8c2010-05-16 01:05:45 -07001451 err = do_setvfinfo(dev, attr);
1452 if (err < 0)
1453 goto errout;
1454 modified = 1;
1455 }
Williams, Mitch Aebc08a62010-02-10 01:44:05 +00001456 }
Patrick McHardy0157f602007-06-13 12:03:36 -07001457 err = 0;
1458
Scott Feldman57b61082010-05-17 22:49:55 -07001459 if (tb[IFLA_VF_PORTS]) {
1460 struct nlattr *port[IFLA_PORT_MAX+1];
1461 struct nlattr *attr;
1462 int vf;
1463 int rem;
1464
1465 err = -EOPNOTSUPP;
1466 if (!ops->ndo_set_vf_port)
1467 goto errout;
1468
1469 nla_for_each_nested(attr, tb[IFLA_VF_PORTS], rem) {
1470 if (nla_type(attr) != IFLA_VF_PORT)
1471 continue;
1472 err = nla_parse_nested(port, IFLA_PORT_MAX,
1473 attr, ifla_port_policy);
1474 if (err < 0)
1475 goto errout;
1476 if (!port[IFLA_PORT_VF]) {
1477 err = -EOPNOTSUPP;
1478 goto errout;
1479 }
1480 vf = nla_get_u32(port[IFLA_PORT_VF]);
1481 err = ops->ndo_set_vf_port(dev, vf, port);
1482 if (err < 0)
1483 goto errout;
1484 modified = 1;
1485 }
1486 }
1487 err = 0;
1488
1489 if (tb[IFLA_PORT_SELF]) {
1490 struct nlattr *port[IFLA_PORT_MAX+1];
1491
1492 err = nla_parse_nested(port, IFLA_PORT_MAX,
1493 tb[IFLA_PORT_SELF], ifla_port_policy);
1494 if (err < 0)
1495 goto errout;
1496
1497 err = -EOPNOTSUPP;
1498 if (ops->ndo_set_vf_port)
1499 err = ops->ndo_set_vf_port(dev, PORT_SELF_VF, port);
1500 if (err < 0)
1501 goto errout;
1502 modified = 1;
1503 }
Thomas Graff8ff1822010-11-16 04:30:14 +00001504
1505 if (tb[IFLA_AF_SPEC]) {
1506 struct nlattr *af;
1507 int rem;
1508
1509 nla_for_each_nested(af, tb[IFLA_AF_SPEC], rem) {
1510 const struct rtnl_af_ops *af_ops;
1511
1512 if (!(af_ops = rtnl_af_lookup(nla_type(af))))
Thomas Grafcf7afbf2010-11-22 01:31:54 +00001513 BUG();
Thomas Graff8ff1822010-11-16 04:30:14 +00001514
Thomas Grafcf7afbf2010-11-22 01:31:54 +00001515 err = af_ops->set_link_af(dev, af);
Thomas Graff8ff1822010-11-16 04:30:14 +00001516 if (err < 0)
1517 goto errout;
1518
1519 modified = 1;
1520 }
1521 }
Scott Feldman57b61082010-05-17 22:49:55 -07001522 err = 0;
1523
Patrick McHardy0157f602007-06-13 12:03:36 -07001524errout:
1525 if (err < 0 && modified && net_ratelimit())
1526 printk(KERN_WARNING "A link change request failed with "
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001527 "some changes committed already. Interface %s may "
Patrick McHardy0157f602007-06-13 12:03:36 -07001528 "have been left with an inconsistent configuration, "
1529 "please check.\n", dev->name);
1530
1531 if (send_addr_notify)
1532 call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
Stefan Gulaf18da142012-01-26 11:01:06 +00001533
Patrick McHardy0157f602007-06-13 12:03:36 -07001534 return err;
1535}
1536
Thomas Grafda5e0492006-08-10 21:17:37 -07001537static int rtnl_setlink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538{
YOSHIFUJI Hideaki3b1e0a62008-03-26 02:26:21 +09001539 struct net *net = sock_net(skb->sk);
Thomas Grafda5e0492006-08-10 21:17:37 -07001540 struct ifinfomsg *ifm;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 struct net_device *dev;
Patrick McHardy0157f602007-06-13 12:03:36 -07001542 int err;
Thomas Grafda5e0492006-08-10 21:17:37 -07001543 struct nlattr *tb[IFLA_MAX+1];
1544 char ifname[IFNAMSIZ];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545
Thomas Grafda5e0492006-08-10 21:17:37 -07001546 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFLA_MAX, ifla_policy);
1547 if (err < 0)
1548 goto errout;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549
Thomas Graf5176f912006-08-26 20:13:18 -07001550 if (tb[IFLA_IFNAME])
1551 nla_strlcpy(ifname, tb[IFLA_IFNAME], IFNAMSIZ);
Patrick McHardy78e5b8912006-09-13 20:35:36 -07001552 else
1553 ifname[0] = '\0';
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555 err = -EINVAL;
Thomas Grafda5e0492006-08-10 21:17:37 -07001556 ifm = nlmsg_data(nlh);
Patrick McHardy51055be2007-06-05 12:40:01 -07001557 if (ifm->ifi_index > 0)
Eric Dumazeta3d12892009-10-21 10:59:31 +00001558 dev = __dev_get_by_index(net, ifm->ifi_index);
Thomas Grafda5e0492006-08-10 21:17:37 -07001559 else if (tb[IFLA_IFNAME])
Eric Dumazeta3d12892009-10-21 10:59:31 +00001560 dev = __dev_get_by_name(net, ifname);
Thomas Grafda5e0492006-08-10 21:17:37 -07001561 else
1562 goto errout;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563
Thomas Grafda5e0492006-08-10 21:17:37 -07001564 if (dev == NULL) {
1565 err = -ENODEV;
1566 goto errout;
1567 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568
Eric Dumazete0d087a2009-11-07 01:26:17 -08001569 err = validate_linkmsg(dev, tb);
1570 if (err < 0)
Eric Dumazeta3d12892009-10-21 10:59:31 +00001571 goto errout;
Thomas Grafda5e0492006-08-10 21:17:37 -07001572
Patrick McHardy38f7b872007-06-13 12:03:51 -07001573 err = do_setlink(dev, ifm, tb, ifname, 0);
Thomas Grafda5e0492006-08-10 21:17:37 -07001574errout:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 return err;
1576}
1577
Patrick McHardy38f7b872007-06-13 12:03:51 -07001578static int rtnl_dellink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
1579{
YOSHIFUJI Hideaki3b1e0a62008-03-26 02:26:21 +09001580 struct net *net = sock_net(skb->sk);
Patrick McHardy38f7b872007-06-13 12:03:51 -07001581 const struct rtnl_link_ops *ops;
1582 struct net_device *dev;
1583 struct ifinfomsg *ifm;
1584 char ifname[IFNAMSIZ];
1585 struct nlattr *tb[IFLA_MAX+1];
1586 int err;
Eric Dumazet226bd342011-05-08 23:17:57 +00001587 LIST_HEAD(list_kill);
Patrick McHardy38f7b872007-06-13 12:03:51 -07001588
1589 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFLA_MAX, ifla_policy);
1590 if (err < 0)
1591 return err;
1592
1593 if (tb[IFLA_IFNAME])
1594 nla_strlcpy(ifname, tb[IFLA_IFNAME], IFNAMSIZ);
1595
1596 ifm = nlmsg_data(nlh);
1597 if (ifm->ifi_index > 0)
Eric W. Biederman881d9662007-09-17 11:56:21 -07001598 dev = __dev_get_by_index(net, ifm->ifi_index);
Patrick McHardy38f7b872007-06-13 12:03:51 -07001599 else if (tb[IFLA_IFNAME])
Eric W. Biederman881d9662007-09-17 11:56:21 -07001600 dev = __dev_get_by_name(net, ifname);
Patrick McHardy38f7b872007-06-13 12:03:51 -07001601 else
1602 return -EINVAL;
1603
1604 if (!dev)
1605 return -ENODEV;
1606
1607 ops = dev->rtnl_link_ops;
1608 if (!ops)
1609 return -EOPNOTSUPP;
1610
Eric Dumazet226bd342011-05-08 23:17:57 +00001611 ops->dellink(dev, &list_kill);
1612 unregister_netdevice_many(&list_kill);
1613 list_del(&list_kill);
Patrick McHardy38f7b872007-06-13 12:03:51 -07001614 return 0;
1615}
1616
Patrick McHardy3729d502010-02-26 06:34:54 +00001617int rtnl_configure_link(struct net_device *dev, const struct ifinfomsg *ifm)
1618{
1619 unsigned int old_flags;
1620 int err;
1621
1622 old_flags = dev->flags;
1623 if (ifm && (ifm->ifi_flags || ifm->ifi_change)) {
1624 err = __dev_change_flags(dev, rtnl_dev_combine_flags(dev, ifm));
1625 if (err < 0)
1626 return err;
1627 }
1628
1629 dev->rtnl_link_state = RTNL_LINK_INITIALIZED;
1630 rtmsg_ifinfo(RTM_NEWLINK, dev, ~0U);
1631
1632 __dev_notify_flags(dev, old_flags);
1633 return 0;
1634}
1635EXPORT_SYMBOL(rtnl_configure_link);
1636
Eric W. Biederman81adee42009-11-08 00:53:51 -08001637struct net_device *rtnl_create_link(struct net *src_net, struct net *net,
1638 char *ifname, const struct rtnl_link_ops *ops, struct nlattr *tb[])
Pavel Emelianove7199282007-08-08 22:16:38 -07001639{
1640 int err;
1641 struct net_device *dev;
Eric Dumazet2e59af32009-09-02 18:03:00 -07001642 unsigned int num_queues = 1;
Pavel Emelianove7199282007-08-08 22:16:38 -07001643
Eric Dumazet2e59af32009-09-02 18:03:00 -07001644 if (ops->get_tx_queues) {
stephen hemmingerefacb302012-04-10 18:34:43 +00001645 err = ops->get_tx_queues(src_net, tb);
1646 if (err < 0)
Eric Dumazet2e59af32009-09-02 18:03:00 -07001647 goto err;
stephen hemmingerefacb302012-04-10 18:34:43 +00001648 num_queues = err;
Eric Dumazet2e59af32009-09-02 18:03:00 -07001649 }
stephen hemmingerefacb302012-04-10 18:34:43 +00001650
Pavel Emelianove7199282007-08-08 22:16:38 -07001651 err = -ENOMEM;
Eric Dumazet2e59af32009-09-02 18:03:00 -07001652 dev = alloc_netdev_mq(ops->priv_size, ifname, ops->setup, num_queues);
Pavel Emelianove7199282007-08-08 22:16:38 -07001653 if (!dev)
1654 goto err;
1655
Eric W. Biederman81adee42009-11-08 00:53:51 -08001656 dev_net_set(dev, net);
1657 dev->rtnl_link_ops = ops;
Patrick McHardy3729d502010-02-26 06:34:54 +00001658 dev->rtnl_link_state = RTNL_LINK_INITIALIZING;
Eric W. Biederman81adee42009-11-08 00:53:51 -08001659
Pavel Emelianove7199282007-08-08 22:16:38 -07001660 if (tb[IFLA_MTU])
1661 dev->mtu = nla_get_u32(tb[IFLA_MTU]);
1662 if (tb[IFLA_ADDRESS])
1663 memcpy(dev->dev_addr, nla_data(tb[IFLA_ADDRESS]),
1664 nla_len(tb[IFLA_ADDRESS]));
1665 if (tb[IFLA_BROADCAST])
1666 memcpy(dev->broadcast, nla_data(tb[IFLA_BROADCAST]),
1667 nla_len(tb[IFLA_BROADCAST]));
1668 if (tb[IFLA_TXQLEN])
1669 dev->tx_queue_len = nla_get_u32(tb[IFLA_TXQLEN]);
1670 if (tb[IFLA_OPERSTATE])
David S. Miller93b2d4a2008-02-17 18:35:07 -08001671 set_operstate(dev, nla_get_u8(tb[IFLA_OPERSTATE]));
Pavel Emelianove7199282007-08-08 22:16:38 -07001672 if (tb[IFLA_LINKMODE])
1673 dev->link_mode = nla_get_u8(tb[IFLA_LINKMODE]);
Patrick McHardyffa934f2011-01-20 03:00:42 +00001674 if (tb[IFLA_GROUP])
1675 dev_set_group(dev, nla_get_u32(tb[IFLA_GROUP]));
Pavel Emelianove7199282007-08-08 22:16:38 -07001676
1677 return dev;
1678
Pavel Emelianove7199282007-08-08 22:16:38 -07001679err:
1680 return ERR_PTR(err);
1681}
Eric Dumazete0d087a2009-11-07 01:26:17 -08001682EXPORT_SYMBOL(rtnl_create_link);
Pavel Emelianove7199282007-08-08 22:16:38 -07001683
Vlad Dogarue7ed8282011-01-13 23:38:31 +00001684static int rtnl_group_changelink(struct net *net, int group,
1685 struct ifinfomsg *ifm,
1686 struct nlattr **tb)
1687{
1688 struct net_device *dev;
1689 int err;
1690
1691 for_each_netdev(net, dev) {
1692 if (dev->group == group) {
1693 err = do_setlink(dev, ifm, tb, NULL, 0);
1694 if (err < 0)
1695 return err;
1696 }
1697 }
1698
1699 return 0;
1700}
1701
Patrick McHardy38f7b872007-06-13 12:03:51 -07001702static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
1703{
YOSHIFUJI Hideaki3b1e0a62008-03-26 02:26:21 +09001704 struct net *net = sock_net(skb->sk);
Patrick McHardy38f7b872007-06-13 12:03:51 -07001705 const struct rtnl_link_ops *ops;
1706 struct net_device *dev;
1707 struct ifinfomsg *ifm;
1708 char kind[MODULE_NAME_LEN];
1709 char ifname[IFNAMSIZ];
1710 struct nlattr *tb[IFLA_MAX+1];
1711 struct nlattr *linkinfo[IFLA_INFO_MAX+1];
1712 int err;
1713
Johannes Berg95a5afc2008-10-16 15:24:51 -07001714#ifdef CONFIG_MODULES
Patrick McHardy38f7b872007-06-13 12:03:51 -07001715replay:
Thomas Graf8072f082007-07-31 14:13:50 -07001716#endif
Patrick McHardy38f7b872007-06-13 12:03:51 -07001717 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFLA_MAX, ifla_policy);
1718 if (err < 0)
1719 return err;
1720
1721 if (tb[IFLA_IFNAME])
1722 nla_strlcpy(ifname, tb[IFLA_IFNAME], IFNAMSIZ);
1723 else
1724 ifname[0] = '\0';
1725
1726 ifm = nlmsg_data(nlh);
1727 if (ifm->ifi_index > 0)
Eric W. Biederman881d9662007-09-17 11:56:21 -07001728 dev = __dev_get_by_index(net, ifm->ifi_index);
Vlad Dogarue7ed8282011-01-13 23:38:31 +00001729 else {
1730 if (ifname[0])
1731 dev = __dev_get_by_name(net, ifname);
Vlad Dogarue7ed8282011-01-13 23:38:31 +00001732 else
1733 dev = NULL;
1734 }
Patrick McHardy38f7b872007-06-13 12:03:51 -07001735
Eric Dumazete0d087a2009-11-07 01:26:17 -08001736 err = validate_linkmsg(dev, tb);
1737 if (err < 0)
Thomas Graf1840bb12008-02-23 19:54:36 -08001738 return err;
1739
Patrick McHardy38f7b872007-06-13 12:03:51 -07001740 if (tb[IFLA_LINKINFO]) {
1741 err = nla_parse_nested(linkinfo, IFLA_INFO_MAX,
1742 tb[IFLA_LINKINFO], ifla_info_policy);
1743 if (err < 0)
1744 return err;
1745 } else
1746 memset(linkinfo, 0, sizeof(linkinfo));
1747
1748 if (linkinfo[IFLA_INFO_KIND]) {
1749 nla_strlcpy(kind, linkinfo[IFLA_INFO_KIND], sizeof(kind));
1750 ops = rtnl_link_ops_get(kind);
1751 } else {
1752 kind[0] = '\0';
1753 ops = NULL;
1754 }
1755
1756 if (1) {
1757 struct nlattr *attr[ops ? ops->maxtype + 1 : 0], **data = NULL;
Eric W. Biederman81adee42009-11-08 00:53:51 -08001758 struct net *dest_net;
Patrick McHardy38f7b872007-06-13 12:03:51 -07001759
1760 if (ops) {
1761 if (ops->maxtype && linkinfo[IFLA_INFO_DATA]) {
1762 err = nla_parse_nested(attr, ops->maxtype,
1763 linkinfo[IFLA_INFO_DATA],
1764 ops->policy);
1765 if (err < 0)
1766 return err;
1767 data = attr;
1768 }
1769 if (ops->validate) {
1770 err = ops->validate(tb, data);
1771 if (err < 0)
1772 return err;
1773 }
1774 }
1775
1776 if (dev) {
1777 int modified = 0;
1778
1779 if (nlh->nlmsg_flags & NLM_F_EXCL)
1780 return -EEXIST;
1781 if (nlh->nlmsg_flags & NLM_F_REPLACE)
1782 return -EOPNOTSUPP;
1783
1784 if (linkinfo[IFLA_INFO_DATA]) {
1785 if (!ops || ops != dev->rtnl_link_ops ||
1786 !ops->changelink)
1787 return -EOPNOTSUPP;
1788
1789 err = ops->changelink(dev, tb, data);
1790 if (err < 0)
1791 return err;
1792 modified = 1;
1793 }
1794
1795 return do_setlink(dev, ifm, tb, ifname, modified);
1796 }
1797
Patrick McHardyffa934f2011-01-20 03:00:42 +00001798 if (!(nlh->nlmsg_flags & NLM_F_CREATE)) {
1799 if (ifm->ifi_index == 0 && tb[IFLA_GROUP])
1800 return rtnl_group_changelink(net,
1801 nla_get_u32(tb[IFLA_GROUP]),
1802 ifm, tb);
Patrick McHardy38f7b872007-06-13 12:03:51 -07001803 return -ENODEV;
Patrick McHardyffa934f2011-01-20 03:00:42 +00001804 }
Patrick McHardy38f7b872007-06-13 12:03:51 -07001805
Patrick McHardy3729d502010-02-26 06:34:54 +00001806 if (ifm->ifi_index)
Patrick McHardy38f7b872007-06-13 12:03:51 -07001807 return -EOPNOTSUPP;
Patrick McHardy0e068772007-07-11 19:42:31 -07001808 if (tb[IFLA_MAP] || tb[IFLA_MASTER] || tb[IFLA_PROTINFO])
Patrick McHardy38f7b872007-06-13 12:03:51 -07001809 return -EOPNOTSUPP;
1810
1811 if (!ops) {
Johannes Berg95a5afc2008-10-16 15:24:51 -07001812#ifdef CONFIG_MODULES
Patrick McHardy38f7b872007-06-13 12:03:51 -07001813 if (kind[0]) {
1814 __rtnl_unlock();
1815 request_module("rtnl-link-%s", kind);
1816 rtnl_lock();
1817 ops = rtnl_link_ops_get(kind);
1818 if (ops)
1819 goto replay;
1820 }
1821#endif
1822 return -EOPNOTSUPP;
1823 }
1824
1825 if (!ifname[0])
1826 snprintf(ifname, IFNAMSIZ, "%s%%d", ops->kind);
Patrick McHardy38f7b872007-06-13 12:03:51 -07001827
Eric W. Biederman81adee42009-11-08 00:53:51 -08001828 dest_net = rtnl_link_get_net(net, tb);
Eric W. Biederman13ad1772011-01-29 14:57:22 +00001829 if (IS_ERR(dest_net))
1830 return PTR_ERR(dest_net);
1831
Eric W. Biederman81adee42009-11-08 00:53:51 -08001832 dev = rtnl_create_link(net, dest_net, ifname, ops, tb);
Patrick McHardy38f7b872007-06-13 12:03:51 -07001833
Pavel Emelianove7199282007-08-08 22:16:38 -07001834 if (IS_ERR(dev))
1835 err = PTR_ERR(dev);
1836 else if (ops->newlink)
Eric W. Biederman81adee42009-11-08 00:53:51 -08001837 err = ops->newlink(net, dev, tb, data);
Patrick McHardy2d85cba2007-07-11 19:42:13 -07001838 else
1839 err = register_netdevice(dev);
Dan Carpenter80032cf2010-04-21 23:53:27 +00001840
1841 if (err < 0 && !IS_ERR(dev))
Patrick McHardy38f7b872007-06-13 12:03:51 -07001842 free_netdev(dev);
Dan Carpenter80032cf2010-04-21 23:53:27 +00001843 if (err < 0)
Patrick McHardy3729d502010-02-26 06:34:54 +00001844 goto out;
Eric W. Biederman81adee42009-11-08 00:53:51 -08001845
Patrick McHardy3729d502010-02-26 06:34:54 +00001846 err = rtnl_configure_link(dev, ifm);
1847 if (err < 0)
1848 unregister_netdevice(dev);
1849out:
Eric W. Biederman81adee42009-11-08 00:53:51 -08001850 put_net(dest_net);
Patrick McHardy38f7b872007-06-13 12:03:51 -07001851 return err;
1852 }
1853}
1854
Thomas Grafb60c5112006-08-04 23:05:34 -07001855static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
Jean Tourrilhes711e2c32006-02-22 15:10:56 -08001856{
YOSHIFUJI Hideaki3b1e0a62008-03-26 02:26:21 +09001857 struct net *net = sock_net(skb->sk);
Thomas Grafb60c5112006-08-04 23:05:34 -07001858 struct ifinfomsg *ifm;
Eric Dumazeta3d12892009-10-21 10:59:31 +00001859 char ifname[IFNAMSIZ];
Thomas Grafb60c5112006-08-04 23:05:34 -07001860 struct nlattr *tb[IFLA_MAX+1];
1861 struct net_device *dev = NULL;
1862 struct sk_buff *nskb;
Thomas Graf339bf982006-11-10 14:10:15 -08001863 int err;
Greg Rose115c9b82012-02-21 16:54:48 -05001864 u32 ext_filter_mask = 0;
Jean Tourrilhes711e2c32006-02-22 15:10:56 -08001865
Thomas Grafb60c5112006-08-04 23:05:34 -07001866 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFLA_MAX, ifla_policy);
1867 if (err < 0)
Eric Sesterhenn9918f232006-09-26 23:26:38 -07001868 return err;
Thomas Grafb60c5112006-08-04 23:05:34 -07001869
Eric Dumazeta3d12892009-10-21 10:59:31 +00001870 if (tb[IFLA_IFNAME])
1871 nla_strlcpy(ifname, tb[IFLA_IFNAME], IFNAMSIZ);
1872
Greg Rose115c9b82012-02-21 16:54:48 -05001873 if (tb[IFLA_EXT_MASK])
1874 ext_filter_mask = nla_get_u32(tb[IFLA_EXT_MASK]);
1875
Thomas Grafb60c5112006-08-04 23:05:34 -07001876 ifm = nlmsg_data(nlh);
Eric Dumazeta3d12892009-10-21 10:59:31 +00001877 if (ifm->ifi_index > 0)
1878 dev = __dev_get_by_index(net, ifm->ifi_index);
1879 else if (tb[IFLA_IFNAME])
1880 dev = __dev_get_by_name(net, ifname);
1881 else
Jean Tourrilhes711e2c32006-02-22 15:10:56 -08001882 return -EINVAL;
Thomas Grafb60c5112006-08-04 23:05:34 -07001883
Eric Dumazeta3d12892009-10-21 10:59:31 +00001884 if (dev == NULL)
1885 return -ENODEV;
1886
Greg Rose115c9b82012-02-21 16:54:48 -05001887 nskb = nlmsg_new(if_nlmsg_size(dev, ext_filter_mask), GFP_KERNEL);
Eric Dumazeta3d12892009-10-21 10:59:31 +00001888 if (nskb == NULL)
1889 return -ENOBUFS;
Jean Tourrilhes711e2c32006-02-22 15:10:56 -08001890
Patrick McHardy575c3e22007-05-22 17:00:49 -07001891 err = rtnl_fill_ifinfo(nskb, dev, RTM_NEWLINK, NETLINK_CB(skb).pid,
Greg Rose115c9b82012-02-21 16:54:48 -05001892 nlh->nlmsg_seq, 0, 0, ext_filter_mask);
Patrick McHardy26932562007-01-31 23:16:40 -08001893 if (err < 0) {
1894 /* -EMSGSIZE implies BUG in if_nlmsg_size */
1895 WARN_ON(err == -EMSGSIZE);
1896 kfree_skb(nskb);
Eric Dumazeta3d12892009-10-21 10:59:31 +00001897 } else
1898 err = rtnl_unicast(nskb, net, NETLINK_CB(skb).pid);
Thomas Grafb60c5112006-08-04 23:05:34 -07001899
Jean Tourrilhes711e2c32006-02-22 15:10:56 -08001900 return err;
Jean Tourrilhes711e2c32006-02-22 15:10:56 -08001901}
Jean Tourrilhes711e2c32006-02-22 15:10:56 -08001902
Greg Rose115c9b82012-02-21 16:54:48 -05001903static u16 rtnl_calcit(struct sk_buff *skb, struct nlmsghdr *nlh)
Greg Rosec7ac8672011-06-10 01:27:09 +00001904{
Greg Rose115c9b82012-02-21 16:54:48 -05001905 struct net *net = sock_net(skb->sk);
1906 struct net_device *dev;
1907 struct nlattr *tb[IFLA_MAX+1];
1908 u32 ext_filter_mask = 0;
1909 u16 min_ifinfo_dump_size = 0;
1910
Eric Dumazeta4b64fb2012-03-04 12:32:10 +00001911 if (nlmsg_parse(nlh, sizeof(struct rtgenmsg), tb, IFLA_MAX,
1912 ifla_policy) >= 0) {
1913 if (tb[IFLA_EXT_MASK])
1914 ext_filter_mask = nla_get_u32(tb[IFLA_EXT_MASK]);
1915 }
Greg Rose115c9b82012-02-21 16:54:48 -05001916
1917 if (!ext_filter_mask)
1918 return NLMSG_GOODSIZE;
1919 /*
1920 * traverse the list of net devices and compute the minimum
1921 * buffer size based upon the filter mask.
1922 */
1923 list_for_each_entry(dev, &net->dev_base_head, dev_list) {
1924 min_ifinfo_dump_size = max_t(u16, min_ifinfo_dump_size,
1925 if_nlmsg_size(dev,
1926 ext_filter_mask));
1927 }
1928
Greg Rosec7ac8672011-06-10 01:27:09 +00001929 return min_ifinfo_dump_size;
1930}
1931
Adrian Bunk42bad1d2007-04-26 00:57:41 -07001932static int rtnl_dump_all(struct sk_buff *skb, struct netlink_callback *cb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933{
1934 int idx;
1935 int s_idx = cb->family;
1936
1937 if (s_idx == 0)
1938 s_idx = 1;
Patrick McHardy25239ce2010-04-26 16:02:05 +02001939 for (idx = 1; idx <= RTNL_FAMILY_MAX; idx++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940 int type = cb->nlh->nlmsg_type-RTM_BASE;
1941 if (idx < s_idx || idx == PF_PACKET)
1942 continue;
Thomas Grafe2849862007-03-22 11:48:11 -07001943 if (rtnl_msg_handlers[idx] == NULL ||
1944 rtnl_msg_handlers[idx][type].dumpit == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945 continue;
1946 if (idx > s_idx)
1947 memset(&cb->args[0], 0, sizeof(cb->args));
Thomas Grafe2849862007-03-22 11:48:11 -07001948 if (rtnl_msg_handlers[idx][type].dumpit(skb, cb))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 break;
1950 }
1951 cb->family = idx;
1952
1953 return skb->len;
1954}
1955
1956void rtmsg_ifinfo(int type, struct net_device *dev, unsigned change)
1957{
YOSHIFUJI Hideakic346dca2008-03-25 21:47:49 +09001958 struct net *net = dev_net(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959 struct sk_buff *skb;
Thomas Graf0ec6d3f2006-08-15 00:37:09 -07001960 int err = -ENOBUFS;
Greg Rosec7ac8672011-06-10 01:27:09 +00001961 size_t if_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962
Greg Rose115c9b82012-02-21 16:54:48 -05001963 skb = nlmsg_new((if_info_size = if_nlmsg_size(dev, 0)), GFP_KERNEL);
Thomas Graf0ec6d3f2006-08-15 00:37:09 -07001964 if (skb == NULL)
1965 goto errout;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966
Greg Rose115c9b82012-02-21 16:54:48 -05001967 err = rtnl_fill_ifinfo(skb, dev, type, 0, 0, change, 0, 0);
Patrick McHardy26932562007-01-31 23:16:40 -08001968 if (err < 0) {
1969 /* -EMSGSIZE implies BUG in if_nlmsg_size() */
1970 WARN_ON(err == -EMSGSIZE);
1971 kfree_skb(skb);
1972 goto errout;
1973 }
Pablo Neira Ayuso1ce85fe2009-02-24 23:18:28 -08001974 rtnl_notify(skb, net, 0, RTNLGRP_LINK, NULL, GFP_KERNEL);
1975 return;
Thomas Graf0ec6d3f2006-08-15 00:37:09 -07001976errout:
1977 if (err < 0)
Eric W. Biederman4b3da702007-11-19 22:27:40 -08001978 rtnl_set_sk_err(net, RTNLGRP_LINK, err);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979}
1980
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981/* Protected by RTNL sempahore. */
1982static struct rtattr **rta_buf;
1983static int rtattr_max;
1984
1985/* Process one rtnetlink message. */
1986
Thomas Graf1d00a4e2007-03-22 23:30:12 -07001987static int rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988{
YOSHIFUJI Hideaki3b1e0a62008-03-26 02:26:21 +09001989 struct net *net = sock_net(skb->sk);
Thomas Grafe2849862007-03-22 11:48:11 -07001990 rtnl_doit_func doit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991 int sz_idx, kind;
1992 int min_len;
1993 int family;
1994 int type;
Eric Dumazet2907c352011-05-25 07:34:04 +00001995 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997 type = nlh->nlmsg_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998 if (type > RTM_MAX)
Thomas Graf038890f2007-04-05 14:35:52 -07001999 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000
2001 type -= RTM_BASE;
2002
2003 /* All the messages must have at least 1 byte length */
2004 if (nlh->nlmsg_len < NLMSG_LENGTH(sizeof(struct rtgenmsg)))
2005 return 0;
2006
Eric Dumazete0d087a2009-11-07 01:26:17 -08002007 family = ((struct rtgenmsg *)NLMSG_DATA(nlh))->rtgen_family;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008 sz_idx = type>>2;
2009 kind = type&3;
2010
Eric Parisfd778462012-01-03 12:25:16 -05002011 if (kind != 2 && !capable(CAP_NET_ADMIN))
Thomas Graf1d00a4e2007-03-22 23:30:12 -07002012 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013
David S. Millerb8f3ab42011-01-18 12:40:38 -08002014 if (kind == 2 && nlh->nlmsg_flags&NLM_F_DUMP) {
Denis V. Lunev97c53ca2007-11-19 22:26:51 -08002015 struct sock *rtnl;
Thomas Grafe2849862007-03-22 11:48:11 -07002016 rtnl_dumpit_func dumpit;
Greg Rosec7ac8672011-06-10 01:27:09 +00002017 rtnl_calcit_func calcit;
2018 u16 min_dump_alloc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019
Thomas Grafe2849862007-03-22 11:48:11 -07002020 dumpit = rtnl_get_dumpit(family, type);
2021 if (dumpit == NULL)
Thomas Graf038890f2007-04-05 14:35:52 -07002022 return -EOPNOTSUPP;
Greg Rosec7ac8672011-06-10 01:27:09 +00002023 calcit = rtnl_get_calcit(family, type);
2024 if (calcit)
Greg Rose115c9b82012-02-21 16:54:48 -05002025 min_dump_alloc = calcit(skb, nlh);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026
Eric Dumazet2907c352011-05-25 07:34:04 +00002027 __rtnl_unlock();
Denis V. Lunev97c53ca2007-11-19 22:26:51 -08002028 rtnl = net->rtnl;
Pablo Neira Ayuso80d326f2012-02-24 14:30:15 +00002029 {
2030 struct netlink_dump_control c = {
2031 .dump = dumpit,
2032 .min_dump_alloc = min_dump_alloc,
2033 };
2034 err = netlink_dump_start(rtnl, skb, nlh, &c);
2035 }
Eric Dumazet2907c352011-05-25 07:34:04 +00002036 rtnl_lock();
2037 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038 }
2039
2040 memset(rta_buf, 0, (rtattr_max * sizeof(struct rtattr *)));
2041
2042 min_len = rtm_min[sz_idx];
2043 if (nlh->nlmsg_len < min_len)
Thomas Graf1d00a4e2007-03-22 23:30:12 -07002044 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045
2046 if (nlh->nlmsg_len > min_len) {
2047 int attrlen = nlh->nlmsg_len - NLMSG_ALIGN(min_len);
Eric Dumazete0d087a2009-11-07 01:26:17 -08002048 struct rtattr *attr = (void *)nlh + NLMSG_ALIGN(min_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049
2050 while (RTA_OK(attr, attrlen)) {
2051 unsigned flavor = attr->rta_type;
2052 if (flavor) {
2053 if (flavor > rta_max[sz_idx])
Thomas Graf1d00a4e2007-03-22 23:30:12 -07002054 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055 rta_buf[flavor-1] = attr;
2056 }
2057 attr = RTA_NEXT(attr, attrlen);
2058 }
2059 }
2060
Thomas Grafe2849862007-03-22 11:48:11 -07002061 doit = rtnl_get_doit(family, type);
2062 if (doit == NULL)
Thomas Graf038890f2007-04-05 14:35:52 -07002063 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064
Thomas Graf1d00a4e2007-03-22 23:30:12 -07002065 return doit(skb, nlh, (void *)&rta_buf[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066}
2067
Denis V. Lunevcd40b7d2007-10-10 21:15:29 -07002068static void rtnetlink_rcv(struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069{
Denis V. Lunevcd40b7d2007-10-10 21:15:29 -07002070 rtnl_lock();
2071 netlink_rcv_skb(skb, &rtnetlink_rcv_msg);
2072 rtnl_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073}
2074
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075static int rtnetlink_event(struct notifier_block *this, unsigned long event, void *ptr)
2076{
2077 struct net_device *dev = ptr;
Eric W. Biedermane9dc8652007-09-12 13:02:17 +02002078
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 switch (event) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 case NETDEV_UP:
2081 case NETDEV_DOWN:
Patrick McHardy10de05a2010-02-26 06:34:50 +00002082 case NETDEV_PRE_UP:
Eric W. Biedermand90a9092009-12-12 22:11:15 +00002083 case NETDEV_POST_INIT:
2084 case NETDEV_REGISTER:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085 case NETDEV_CHANGE:
Patrick McHardy755d0e72010-03-19 04:42:24 +00002086 case NETDEV_PRE_TYPE_CHANGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087 case NETDEV_GOING_DOWN:
Patrick McHardya2835762010-02-26 06:34:51 +00002088 case NETDEV_UNREGISTER:
Eric W. Biedermand90a9092009-12-12 22:11:15 +00002089 case NETDEV_UNREGISTER_BATCH:
Amerigo Wangac3d3f82011-05-19 23:06:32 +00002090 case NETDEV_RELEASE:
2091 case NETDEV_JOIN:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 break;
2093 default:
2094 rtmsg_ifinfo(RTM_NEWLINK, dev, 0);
2095 break;
2096 }
2097 return NOTIFY_DONE;
2098}
2099
2100static struct notifier_block rtnetlink_dev_notifier = {
2101 .notifier_call = rtnetlink_event,
2102};
2103
Denis V. Lunev97c53ca2007-11-19 22:26:51 -08002104
Alexey Dobriyan2c8c1e72010-01-17 03:35:32 +00002105static int __net_init rtnetlink_net_init(struct net *net)
Denis V. Lunev97c53ca2007-11-19 22:26:51 -08002106{
2107 struct sock *sk;
2108 sk = netlink_kernel_create(net, NETLINK_ROUTE, RTNLGRP_MAX,
Eric Dumazet2907c352011-05-25 07:34:04 +00002109 rtnetlink_rcv, &rtnl_mutex, THIS_MODULE);
Denis V. Lunev97c53ca2007-11-19 22:26:51 -08002110 if (!sk)
2111 return -ENOMEM;
Denis V. Lunev97c53ca2007-11-19 22:26:51 -08002112 net->rtnl = sk;
2113 return 0;
2114}
2115
Alexey Dobriyan2c8c1e72010-01-17 03:35:32 +00002116static void __net_exit rtnetlink_net_exit(struct net *net)
Denis V. Lunev97c53ca2007-11-19 22:26:51 -08002117{
Denis V. Lunev775516b2008-01-18 23:55:19 -08002118 netlink_kernel_release(net->rtnl);
2119 net->rtnl = NULL;
Denis V. Lunev97c53ca2007-11-19 22:26:51 -08002120}
2121
2122static struct pernet_operations rtnetlink_net_ops = {
2123 .init = rtnetlink_net_init,
2124 .exit = rtnetlink_net_exit,
2125};
2126
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127void __init rtnetlink_init(void)
2128{
2129 int i;
2130
2131 rtattr_max = 0;
2132 for (i = 0; i < ARRAY_SIZE(rta_max); i++)
2133 if (rta_max[i] > rtattr_max)
2134 rtattr_max = rta_max[i];
2135 rta_buf = kmalloc(rtattr_max * sizeof(struct rtattr *), GFP_KERNEL);
2136 if (!rta_buf)
2137 panic("rtnetlink_init: cannot allocate rta_buf\n");
2138
Denis V. Lunev97c53ca2007-11-19 22:26:51 -08002139 if (register_pernet_subsys(&rtnetlink_net_ops))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140 panic("rtnetlink_init: cannot initialize rtnetlink\n");
Denis V. Lunev97c53ca2007-11-19 22:26:51 -08002141
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142 netlink_set_nonroot(NETLINK_ROUTE, NL_NONROOT_RECV);
2143 register_netdevice_notifier(&rtnetlink_dev_notifier);
Thomas Graf340d17f2007-03-22 11:49:22 -07002144
Greg Rosec7ac8672011-06-10 01:27:09 +00002145 rtnl_register(PF_UNSPEC, RTM_GETLINK, rtnl_getlink,
2146 rtnl_dump_ifinfo, rtnl_calcit);
2147 rtnl_register(PF_UNSPEC, RTM_SETLINK, rtnl_setlink, NULL, NULL);
2148 rtnl_register(PF_UNSPEC, RTM_NEWLINK, rtnl_newlink, NULL, NULL);
2149 rtnl_register(PF_UNSPEC, RTM_DELLINK, rtnl_dellink, NULL, NULL);
Thomas Graf687ad8c2007-03-22 11:59:42 -07002150
Greg Rosec7ac8672011-06-10 01:27:09 +00002151 rtnl_register(PF_UNSPEC, RTM_GETADDR, NULL, rtnl_dump_all, NULL);
2152 rtnl_register(PF_UNSPEC, RTM_GETROUTE, NULL, rtnl_dump_all, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153}
2154