]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - net/core/rtnetlink.c
bridge/mdb: remove wrong use of NLM_F_MULTI
[mirror_ubuntu-bionic-kernel.git] / net / core / rtnetlink.c
CommitLineData
1da177e4
LT
1/*
2 * INET An implementation of the TCP/IP protocol suite for the LINUX
3 * operating system. INET is implemented using the BSD Socket
4 * interface as the means of communication with the user level.
5 *
6 * Routing netlink socket interface: protocol independent part.
7 *
8 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
14 *
15 * Fixes:
16 * Vitaly E. Lavrov RTA_OK arithmetics was wrong.
17 */
18
1da177e4
LT
19#include <linux/errno.h>
20#include <linux/module.h>
21#include <linux/types.h>
22#include <linux/socket.h>
23#include <linux/kernel.h>
1da177e4
LT
24#include <linux/timer.h>
25#include <linux/string.h>
26#include <linux/sockios.h>
27#include <linux/net.h>
28#include <linux/fcntl.h>
29#include <linux/mm.h>
30#include <linux/slab.h>
31#include <linux/interrupt.h>
32#include <linux/capability.h>
33#include <linux/skbuff.h>
34#include <linux/init.h>
35#include <linux/security.h>
6756ae4b 36#include <linux/mutex.h>
1823730f 37#include <linux/if_addr.h>
77162022 38#include <linux/if_bridge.h>
f6f6424b 39#include <linux/if_vlan.h>
ebc08a6f 40#include <linux/pci.h>
77162022 41#include <linux/etherdevice.h>
1da177e4
LT
42
43#include <asm/uaccess.h>
1da177e4
LT
44
45#include <linux/inet.h>
46#include <linux/netdevice.h>
82f28412 47#include <net/switchdev.h>
1da177e4
LT
48#include <net/ip.h>
49#include <net/protocol.h>
50#include <net/arp.h>
51#include <net/route.h>
52#include <net/udp.h>
ea697639 53#include <net/tcp.h>
1da177e4
LT
54#include <net/sock.h>
55#include <net/pkt_sched.h>
14c0b97d 56#include <net/fib_rules.h>
e2849863 57#include <net/rtnetlink.h>
30ffee84 58#include <net/net_namespace.h>
1da177e4 59
e0d087af 60struct rtnl_link {
e2849863
TG
61 rtnl_doit_func doit;
62 rtnl_dumpit_func dumpit;
c7ac8679 63 rtnl_calcit_func calcit;
e2849863
TG
64};
65
6756ae4b 66static DEFINE_MUTEX(rtnl_mutex);
1da177e4
LT
67
68void rtnl_lock(void)
69{
6756ae4b 70 mutex_lock(&rtnl_mutex);
1da177e4 71}
e0d087af 72EXPORT_SYMBOL(rtnl_lock);
1da177e4 73
6756ae4b 74void __rtnl_unlock(void)
1da177e4 75{
6756ae4b 76 mutex_unlock(&rtnl_mutex);
1da177e4 77}
6756ae4b 78
1da177e4
LT
79void rtnl_unlock(void)
80{
58ec3b4d 81 /* This fellow will unlock it for us. */
1da177e4
LT
82 netdev_run_todo();
83}
e0d087af 84EXPORT_SYMBOL(rtnl_unlock);
1da177e4 85
6756ae4b
SH
86int rtnl_trylock(void)
87{
88 return mutex_trylock(&rtnl_mutex);
89}
e0d087af 90EXPORT_SYMBOL(rtnl_trylock);
6756ae4b 91
c9c1014b
PM
92int rtnl_is_locked(void)
93{
94 return mutex_is_locked(&rtnl_mutex);
95}
e0d087af 96EXPORT_SYMBOL(rtnl_is_locked);
c9c1014b 97
a898def2
PM
98#ifdef CONFIG_PROVE_LOCKING
99int lockdep_rtnl_is_held(void)
100{
101 return lockdep_is_held(&rtnl_mutex);
102}
103EXPORT_SYMBOL(lockdep_rtnl_is_held);
104#endif /* #ifdef CONFIG_PROVE_LOCKING */
105
25239cee 106static struct rtnl_link *rtnl_msg_handlers[RTNL_FAMILY_MAX + 1];
e2849863
TG
107
108static inline int rtm_msgindex(int msgtype)
109{
110 int msgindex = msgtype - RTM_BASE;
111
112 /*
113 * msgindex < 0 implies someone tried to register a netlink
114 * control code. msgindex >= RTM_NR_MSGTYPES may indicate that
115 * the message type has not been added to linux/rtnetlink.h
116 */
117 BUG_ON(msgindex < 0 || msgindex >= RTM_NR_MSGTYPES);
118
119 return msgindex;
120}
121
122static rtnl_doit_func rtnl_get_doit(int protocol, int msgindex)
123{
124 struct rtnl_link *tab;
125
25239cee 126 if (protocol <= RTNL_FAMILY_MAX)
0f87b1dd
PM
127 tab = rtnl_msg_handlers[protocol];
128 else
129 tab = NULL;
130
51057f2f 131 if (tab == NULL || tab[msgindex].doit == NULL)
e2849863
TG
132 tab = rtnl_msg_handlers[PF_UNSPEC];
133
c80bbeae 134 return tab[msgindex].doit;
e2849863
TG
135}
136
137static rtnl_dumpit_func rtnl_get_dumpit(int protocol, int msgindex)
138{
139 struct rtnl_link *tab;
140
25239cee 141 if (protocol <= RTNL_FAMILY_MAX)
0f87b1dd
PM
142 tab = rtnl_msg_handlers[protocol];
143 else
144 tab = NULL;
145
51057f2f 146 if (tab == NULL || tab[msgindex].dumpit == NULL)
e2849863
TG
147 tab = rtnl_msg_handlers[PF_UNSPEC];
148
c80bbeae 149 return tab[msgindex].dumpit;
e2849863
TG
150}
151
c7ac8679
GR
152static rtnl_calcit_func rtnl_get_calcit(int protocol, int msgindex)
153{
154 struct rtnl_link *tab;
155
156 if (protocol <= RTNL_FAMILY_MAX)
157 tab = rtnl_msg_handlers[protocol];
158 else
159 tab = NULL;
160
161 if (tab == NULL || tab[msgindex].calcit == NULL)
162 tab = rtnl_msg_handlers[PF_UNSPEC];
163
c80bbeae 164 return tab[msgindex].calcit;
c7ac8679
GR
165}
166
e2849863
TG
167/**
168 * __rtnl_register - Register a rtnetlink message type
169 * @protocol: Protocol family or PF_UNSPEC
170 * @msgtype: rtnetlink message type
171 * @doit: Function pointer called for each request message
172 * @dumpit: Function pointer called for each dump request (NLM_F_DUMP) message
c7ac8679 173 * @calcit: Function pointer to calc size of dump message
e2849863
TG
174 *
175 * Registers the specified function pointers (at least one of them has
176 * to be non-NULL) to be called whenever a request message for the
177 * specified protocol family and message type is received.
178 *
179 * The special protocol family PF_UNSPEC may be used to define fallback
180 * function pointers for the case when no entry for the specific protocol
181 * family exists.
182 *
183 * Returns 0 on success or a negative error code.
184 */
185int __rtnl_register(int protocol, int msgtype,
c7ac8679
GR
186 rtnl_doit_func doit, rtnl_dumpit_func dumpit,
187 rtnl_calcit_func calcit)
e2849863
TG
188{
189 struct rtnl_link *tab;
190 int msgindex;
191
25239cee 192 BUG_ON(protocol < 0 || protocol > RTNL_FAMILY_MAX);
e2849863
TG
193 msgindex = rtm_msgindex(msgtype);
194
195 tab = rtnl_msg_handlers[protocol];
196 if (tab == NULL) {
197 tab = kcalloc(RTM_NR_MSGTYPES, sizeof(*tab), GFP_KERNEL);
198 if (tab == NULL)
199 return -ENOBUFS;
200
201 rtnl_msg_handlers[protocol] = tab;
202 }
203
204 if (doit)
205 tab[msgindex].doit = doit;
206
207 if (dumpit)
208 tab[msgindex].dumpit = dumpit;
209
c7ac8679
GR
210 if (calcit)
211 tab[msgindex].calcit = calcit;
212
e2849863
TG
213 return 0;
214}
e2849863
TG
215EXPORT_SYMBOL_GPL(__rtnl_register);
216
217/**
218 * rtnl_register - Register a rtnetlink message type
219 *
220 * Identical to __rtnl_register() but panics on failure. This is useful
221 * as failure of this function is very unlikely, it can only happen due
222 * to lack of memory when allocating the chain to store all message
223 * handlers for a protocol. Meant for use in init functions where lack
25985edc 224 * of memory implies no sense in continuing.
e2849863
TG
225 */
226void rtnl_register(int protocol, int msgtype,
c7ac8679
GR
227 rtnl_doit_func doit, rtnl_dumpit_func dumpit,
228 rtnl_calcit_func calcit)
e2849863 229{
c7ac8679 230 if (__rtnl_register(protocol, msgtype, doit, dumpit, calcit) < 0)
e2849863
TG
231 panic("Unable to register rtnetlink message handler, "
232 "protocol = %d, message type = %d\n",
233 protocol, msgtype);
234}
e2849863
TG
235EXPORT_SYMBOL_GPL(rtnl_register);
236
237/**
238 * rtnl_unregister - Unregister a rtnetlink message type
239 * @protocol: Protocol family or PF_UNSPEC
240 * @msgtype: rtnetlink message type
241 *
242 * Returns 0 on success or a negative error code.
243 */
244int rtnl_unregister(int protocol, int msgtype)
245{
246 int msgindex;
247
25239cee 248 BUG_ON(protocol < 0 || protocol > RTNL_FAMILY_MAX);
e2849863
TG
249 msgindex = rtm_msgindex(msgtype);
250
251 if (rtnl_msg_handlers[protocol] == NULL)
252 return -ENOENT;
253
254 rtnl_msg_handlers[protocol][msgindex].doit = NULL;
255 rtnl_msg_handlers[protocol][msgindex].dumpit = NULL;
256
257 return 0;
258}
e2849863
TG
259EXPORT_SYMBOL_GPL(rtnl_unregister);
260
261/**
262 * rtnl_unregister_all - Unregister all rtnetlink message type of a protocol
263 * @protocol : Protocol family or PF_UNSPEC
264 *
265 * Identical to calling rtnl_unregster() for all registered message types
266 * of a certain protocol family.
267 */
268void rtnl_unregister_all(int protocol)
269{
25239cee 270 BUG_ON(protocol < 0 || protocol > RTNL_FAMILY_MAX);
e2849863
TG
271
272 kfree(rtnl_msg_handlers[protocol]);
273 rtnl_msg_handlers[protocol] = NULL;
274}
e2849863 275EXPORT_SYMBOL_GPL(rtnl_unregister_all);
1da177e4 276
38f7b870
PM
277static LIST_HEAD(link_ops);
278
c63044f0
ED
279static const struct rtnl_link_ops *rtnl_link_ops_get(const char *kind)
280{
281 const struct rtnl_link_ops *ops;
282
283 list_for_each_entry(ops, &link_ops, list) {
284 if (!strcmp(ops->kind, kind))
285 return ops;
286 }
287 return NULL;
288}
289
38f7b870
PM
290/**
291 * __rtnl_link_register - Register rtnl_link_ops with rtnetlink.
292 * @ops: struct rtnl_link_ops * to register
293 *
294 * The caller must hold the rtnl_mutex. This function should be used
295 * by drivers that create devices during module initialization. It
296 * must be called before registering the devices.
297 *
298 * Returns 0 on success or a negative error code.
299 */
300int __rtnl_link_register(struct rtnl_link_ops *ops)
301{
c63044f0
ED
302 if (rtnl_link_ops_get(ops->kind))
303 return -EEXIST;
304
b0ab2fab
JP
305 /* The check for setup is here because if ops
306 * does not have that filled up, it is not possible
307 * to use the ops for creating device. So do not
308 * fill up dellink as well. That disables rtnl_dellink.
309 */
310 if (ops->setup && !ops->dellink)
23289a37 311 ops->dellink = unregister_netdevice_queue;
2d85cba2 312
38f7b870
PM
313 list_add_tail(&ops->list, &link_ops);
314 return 0;
315}
38f7b870
PM
316EXPORT_SYMBOL_GPL(__rtnl_link_register);
317
318/**
319 * rtnl_link_register - Register rtnl_link_ops with rtnetlink.
320 * @ops: struct rtnl_link_ops * to register
321 *
322 * Returns 0 on success or a negative error code.
323 */
324int rtnl_link_register(struct rtnl_link_ops *ops)
325{
326 int err;
327
328 rtnl_lock();
329 err = __rtnl_link_register(ops);
330 rtnl_unlock();
331 return err;
332}
38f7b870
PM
333EXPORT_SYMBOL_GPL(rtnl_link_register);
334
669f87ba
PE
335static void __rtnl_kill_links(struct net *net, struct rtnl_link_ops *ops)
336{
337 struct net_device *dev;
23289a37
ED
338 LIST_HEAD(list_kill);
339
669f87ba 340 for_each_netdev(net, dev) {
23289a37
ED
341 if (dev->rtnl_link_ops == ops)
342 ops->dellink(dev, &list_kill);
669f87ba 343 }
23289a37 344 unregister_netdevice_many(&list_kill);
669f87ba
PE
345}
346
38f7b870
PM
347/**
348 * __rtnl_link_unregister - Unregister rtnl_link_ops from rtnetlink.
349 * @ops: struct rtnl_link_ops * to unregister
350 *
2d85cba2 351 * The caller must hold the rtnl_mutex.
38f7b870
PM
352 */
353void __rtnl_link_unregister(struct rtnl_link_ops *ops)
354{
881d966b 355 struct net *net;
2d85cba2 356
881d966b 357 for_each_net(net) {
669f87ba 358 __rtnl_kill_links(net, ops);
2d85cba2 359 }
38f7b870
PM
360 list_del(&ops->list);
361}
38f7b870
PM
362EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
363
200b916f
CW
364/* Return with the rtnl_lock held when there are no network
365 * devices unregistering in any network namespace.
366 */
367static void rtnl_lock_unregistering_all(void)
368{
369 struct net *net;
370 bool unregistering;
ff960a73 371 DEFINE_WAIT_FUNC(wait, woken_wake_function);
200b916f 372
ff960a73 373 add_wait_queue(&netdev_unregistering_wq, &wait);
200b916f 374 for (;;) {
200b916f
CW
375 unregistering = false;
376 rtnl_lock();
377 for_each_net(net) {
378 if (net->dev_unreg_count > 0) {
379 unregistering = true;
380 break;
381 }
382 }
383 if (!unregistering)
384 break;
385 __rtnl_unlock();
ff960a73
PZ
386
387 wait_woken(&wait, TASK_UNINTERRUPTIBLE, MAX_SCHEDULE_TIMEOUT);
200b916f 388 }
ff960a73 389 remove_wait_queue(&netdev_unregistering_wq, &wait);
200b916f
CW
390}
391
38f7b870
PM
392/**
393 * rtnl_link_unregister - Unregister rtnl_link_ops from rtnetlink.
394 * @ops: struct rtnl_link_ops * to unregister
395 */
396void rtnl_link_unregister(struct rtnl_link_ops *ops)
397{
200b916f
CW
398 /* Close the race with cleanup_net() */
399 mutex_lock(&net_mutex);
400 rtnl_lock_unregistering_all();
38f7b870
PM
401 __rtnl_link_unregister(ops);
402 rtnl_unlock();
200b916f 403 mutex_unlock(&net_mutex);
38f7b870 404}
38f7b870
PM
405EXPORT_SYMBOL_GPL(rtnl_link_unregister);
406
ba7d49b1
JP
407static size_t rtnl_link_get_slave_info_data_size(const struct net_device *dev)
408{
409 struct net_device *master_dev;
410 const struct rtnl_link_ops *ops;
411
412 master_dev = netdev_master_upper_dev_get((struct net_device *) dev);
413 if (!master_dev)
414 return 0;
415 ops = master_dev->rtnl_link_ops;
6049f253 416 if (!ops || !ops->get_slave_size)
ba7d49b1
JP
417 return 0;
418 /* IFLA_INFO_SLAVE_DATA + nested data */
419 return nla_total_size(sizeof(struct nlattr)) +
420 ops->get_slave_size(master_dev, dev);
421}
422
38f7b870
PM
423static size_t rtnl_link_get_size(const struct net_device *dev)
424{
425 const struct rtnl_link_ops *ops = dev->rtnl_link_ops;
426 size_t size;
427
428 if (!ops)
429 return 0;
430
369cf77a
TG
431 size = nla_total_size(sizeof(struct nlattr)) + /* IFLA_LINKINFO */
432 nla_total_size(strlen(ops->kind) + 1); /* IFLA_INFO_KIND */
38f7b870
PM
433
434 if (ops->get_size)
435 /* IFLA_INFO_DATA + nested data */
369cf77a 436 size += nla_total_size(sizeof(struct nlattr)) +
38f7b870
PM
437 ops->get_size(dev);
438
439 if (ops->get_xstats_size)
369cf77a
TG
440 /* IFLA_INFO_XSTATS */
441 size += nla_total_size(ops->get_xstats_size(dev));
38f7b870 442
ba7d49b1
JP
443 size += rtnl_link_get_slave_info_data_size(dev);
444
38f7b870
PM
445 return size;
446}
447
f8ff182c
TG
448static LIST_HEAD(rtnl_af_ops);
449
450static const struct rtnl_af_ops *rtnl_af_lookup(const int family)
451{
452 const struct rtnl_af_ops *ops;
453
454 list_for_each_entry(ops, &rtnl_af_ops, list) {
455 if (ops->family == family)
456 return ops;
457 }
458
459 return NULL;
460}
461
f8ff182c
TG
462/**
463 * rtnl_af_register - Register rtnl_af_ops with rtnetlink.
464 * @ops: struct rtnl_af_ops * to register
465 *
466 * Returns 0 on success or a negative error code.
467 */
3678a9d8 468void rtnl_af_register(struct rtnl_af_ops *ops)
f8ff182c 469{
f8ff182c 470 rtnl_lock();
3678a9d8 471 list_add_tail(&ops->list, &rtnl_af_ops);
f8ff182c 472 rtnl_unlock();
f8ff182c
TG
473}
474EXPORT_SYMBOL_GPL(rtnl_af_register);
475
476/**
477 * __rtnl_af_unregister - Unregister rtnl_af_ops from rtnetlink.
478 * @ops: struct rtnl_af_ops * to unregister
479 *
480 * The caller must hold the rtnl_mutex.
481 */
482void __rtnl_af_unregister(struct rtnl_af_ops *ops)
483{
484 list_del(&ops->list);
485}
486EXPORT_SYMBOL_GPL(__rtnl_af_unregister);
487
488/**
489 * rtnl_af_unregister - Unregister rtnl_af_ops from rtnetlink.
490 * @ops: struct rtnl_af_ops * to unregister
491 */
492void rtnl_af_unregister(struct rtnl_af_ops *ops)
493{
494 rtnl_lock();
495 __rtnl_af_unregister(ops);
496 rtnl_unlock();
497}
498EXPORT_SYMBOL_GPL(rtnl_af_unregister);
499
500static size_t rtnl_link_get_af_size(const struct net_device *dev)
501{
502 struct rtnl_af_ops *af_ops;
503 size_t size;
504
505 /* IFLA_AF_SPEC */
506 size = nla_total_size(sizeof(struct nlattr));
507
508 list_for_each_entry(af_ops, &rtnl_af_ops, list) {
509 if (af_ops->get_link_af_size) {
510 /* AF_* + nested data */
511 size += nla_total_size(sizeof(struct nlattr)) +
512 af_ops->get_link_af_size(dev);
513 }
514 }
515
516 return size;
517}
518
ba7d49b1 519static bool rtnl_have_link_slave_info(const struct net_device *dev)
38f7b870 520{
ba7d49b1 521 struct net_device *master_dev;
38f7b870 522
ba7d49b1 523 master_dev = netdev_master_upper_dev_get((struct net_device *) dev);
813f020c 524 if (master_dev && master_dev->rtnl_link_ops)
ba7d49b1
JP
525 return true;
526 return false;
527}
528
529static int rtnl_link_slave_info_fill(struct sk_buff *skb,
530 const struct net_device *dev)
531{
532 struct net_device *master_dev;
533 const struct rtnl_link_ops *ops;
534 struct nlattr *slave_data;
535 int err;
38f7b870 536
ba7d49b1
JP
537 master_dev = netdev_master_upper_dev_get((struct net_device *) dev);
538 if (!master_dev)
539 return 0;
540 ops = master_dev->rtnl_link_ops;
541 if (!ops)
542 return 0;
543 if (nla_put_string(skb, IFLA_INFO_SLAVE_KIND, ops->kind) < 0)
544 return -EMSGSIZE;
545 if (ops->fill_slave_info) {
546 slave_data = nla_nest_start(skb, IFLA_INFO_SLAVE_DATA);
547 if (!slave_data)
548 return -EMSGSIZE;
549 err = ops->fill_slave_info(skb, master_dev, dev);
550 if (err < 0)
551 goto err_cancel_slave_data;
552 nla_nest_end(skb, slave_data);
553 }
554 return 0;
555
556err_cancel_slave_data:
557 nla_nest_cancel(skb, slave_data);
558 return err;
559}
560
561static int rtnl_link_info_fill(struct sk_buff *skb,
562 const struct net_device *dev)
563{
564 const struct rtnl_link_ops *ops = dev->rtnl_link_ops;
565 struct nlattr *data;
566 int err;
567
568 if (!ops)
569 return 0;
38f7b870 570 if (nla_put_string(skb, IFLA_INFO_KIND, ops->kind) < 0)
ba7d49b1 571 return -EMSGSIZE;
38f7b870
PM
572 if (ops->fill_xstats) {
573 err = ops->fill_xstats(skb, dev);
574 if (err < 0)
ba7d49b1 575 return err;
38f7b870
PM
576 }
577 if (ops->fill_info) {
578 data = nla_nest_start(skb, IFLA_INFO_DATA);
ba7d49b1
JP
579 if (data == NULL)
580 return -EMSGSIZE;
38f7b870
PM
581 err = ops->fill_info(skb, dev);
582 if (err < 0)
583 goto err_cancel_data;
584 nla_nest_end(skb, data);
585 }
38f7b870
PM
586 return 0;
587
588err_cancel_data:
589 nla_nest_cancel(skb, data);
ba7d49b1
JP
590 return err;
591}
592
593static int rtnl_link_fill(struct sk_buff *skb, const struct net_device *dev)
594{
595 struct nlattr *linkinfo;
596 int err = -EMSGSIZE;
597
598 linkinfo = nla_nest_start(skb, IFLA_LINKINFO);
599 if (linkinfo == NULL)
600 goto out;
601
602 err = rtnl_link_info_fill(skb, dev);
603 if (err < 0)
604 goto err_cancel_link;
605
606 err = rtnl_link_slave_info_fill(skb, dev);
607 if (err < 0)
608 goto err_cancel_link;
609
610 nla_nest_end(skb, linkinfo);
611 return 0;
612
38f7b870
PM
613err_cancel_link:
614 nla_nest_cancel(skb, linkinfo);
615out:
616 return err;
617}
618
95c96174 619int rtnetlink_send(struct sk_buff *skb, struct net *net, u32 pid, unsigned int group, int echo)
1da177e4 620{
97c53cac 621 struct sock *rtnl = net->rtnl;
1da177e4
LT
622 int err = 0;
623
ac6d439d 624 NETLINK_CB(skb).dst_group = group;
1da177e4
LT
625 if (echo)
626 atomic_inc(&skb->users);
627 netlink_broadcast(rtnl, skb, pid, group, GFP_KERNEL);
628 if (echo)
629 err = netlink_unicast(rtnl, skb, pid, MSG_DONTWAIT);
630 return err;
631}
632
97c53cac 633int rtnl_unicast(struct sk_buff *skb, struct net *net, u32 pid)
2942e900 634{
97c53cac
DL
635 struct sock *rtnl = net->rtnl;
636
2942e900
TG
637 return nlmsg_unicast(rtnl, skb, pid);
638}
e0d087af 639EXPORT_SYMBOL(rtnl_unicast);
2942e900 640
1ce85fe4
PNA
641void rtnl_notify(struct sk_buff *skb, struct net *net, u32 pid, u32 group,
642 struct nlmsghdr *nlh, gfp_t flags)
97676b6b 643{
97c53cac 644 struct sock *rtnl = net->rtnl;
97676b6b
TG
645 int report = 0;
646
647 if (nlh)
648 report = nlmsg_report(nlh);
649
1ce85fe4 650 nlmsg_notify(rtnl, skb, pid, group, report, flags);
97676b6b 651}
e0d087af 652EXPORT_SYMBOL(rtnl_notify);
97676b6b 653
97c53cac 654void rtnl_set_sk_err(struct net *net, u32 group, int error)
97676b6b 655{
97c53cac
DL
656 struct sock *rtnl = net->rtnl;
657
97676b6b
TG
658 netlink_set_err(rtnl, 0, group, error);
659}
e0d087af 660EXPORT_SYMBOL(rtnl_set_sk_err);
97676b6b 661
1da177e4
LT
662int rtnetlink_put_metrics(struct sk_buff *skb, u32 *metrics)
663{
2d7202bf
TG
664 struct nlattr *mx;
665 int i, valid = 0;
666
667 mx = nla_nest_start(skb, RTA_METRICS);
668 if (mx == NULL)
669 return -ENOBUFS;
670
671 for (i = 0; i < RTAX_MAX; i++) {
672 if (metrics[i]) {
ea697639
DB
673 if (i == RTAX_CC_ALGO - 1) {
674 char tmp[TCP_CA_NAME_MAX], *name;
675
676 name = tcp_ca_get_name_by_key(metrics[i], tmp);
677 if (!name)
678 continue;
679 if (nla_put_string(skb, i + 1, name))
680 goto nla_put_failure;
681 } else {
682 if (nla_put_u32(skb, i + 1, metrics[i]))
683 goto nla_put_failure;
684 }
2d7202bf 685 valid++;
2d7202bf 686 }
1da177e4 687 }
1da177e4 688
a57d27fc
DM
689 if (!valid) {
690 nla_nest_cancel(skb, mx);
691 return 0;
692 }
2d7202bf
TG
693
694 return nla_nest_end(skb, mx);
695
696nla_put_failure:
bc3ed28c
TG
697 nla_nest_cancel(skb, mx);
698 return -EMSGSIZE;
1da177e4 699}
e0d087af 700EXPORT_SYMBOL(rtnetlink_put_metrics);
1da177e4 701
e3703b3d 702int rtnl_put_cacheinfo(struct sk_buff *skb, struct dst_entry *dst, u32 id,
87a50699 703 long expires, u32 error)
e3703b3d
TG
704{
705 struct rta_cacheinfo ci = {
a399a805 706 .rta_lastuse = jiffies_delta_to_clock_t(jiffies - dst->lastuse),
e3703b3d
TG
707 .rta_used = dst->__use,
708 .rta_clntref = atomic_read(&(dst->__refcnt)),
709 .rta_error = error,
710 .rta_id = id,
e3703b3d
TG
711 };
712
8253947e
LW
713 if (expires) {
714 unsigned long clock;
e3703b3d 715
8253947e
LW
716 clock = jiffies_to_clock_t(abs(expires));
717 clock = min_t(unsigned long, clock, INT_MAX);
718 ci.rta_expires = (expires > 0) ? clock : -clock;
719 }
e3703b3d
TG
720 return nla_put(skb, RTA_CACHEINFO, sizeof(ci), &ci);
721}
e3703b3d 722EXPORT_SYMBOL_GPL(rtnl_put_cacheinfo);
1da177e4 723
93b2d4a2 724static void set_operstate(struct net_device *dev, unsigned char transition)
b00055aa
SR
725{
726 unsigned char operstate = dev->operstate;
727
e0d087af 728 switch (transition) {
b00055aa
SR
729 case IF_OPER_UP:
730 if ((operstate == IF_OPER_DORMANT ||
731 operstate == IF_OPER_UNKNOWN) &&
732 !netif_dormant(dev))
733 operstate = IF_OPER_UP;
734 break;
735
736 case IF_OPER_DORMANT:
737 if (operstate == IF_OPER_UP ||
738 operstate == IF_OPER_UNKNOWN)
739 operstate = IF_OPER_DORMANT;
740 break;
3ff50b79 741 }
b00055aa
SR
742
743 if (dev->operstate != operstate) {
744 write_lock_bh(&dev_base_lock);
745 dev->operstate = operstate;
746 write_unlock_bh(&dev_base_lock);
93b2d4a2
DM
747 netdev_state_change(dev);
748 }
b00055aa
SR
749}
750
b1beb681
JB
751static unsigned int rtnl_dev_get_flags(const struct net_device *dev)
752{
753 return (dev->flags & ~(IFF_PROMISC | IFF_ALLMULTI)) |
754 (dev->gflags & (IFF_PROMISC | IFF_ALLMULTI));
755}
756
3729d502
PM
757static unsigned int rtnl_dev_combine_flags(const struct net_device *dev,
758 const struct ifinfomsg *ifm)
759{
760 unsigned int flags = ifm->ifi_flags;
761
762 /* bugwards compatibility: ifi_change == 0 is treated as ~0 */
763 if (ifm->ifi_change)
764 flags = (flags & ifm->ifi_change) |
b1beb681 765 (rtnl_dev_get_flags(dev) & ~ifm->ifi_change);
3729d502
PM
766
767 return flags;
768}
769
b60c5115 770static void copy_rtnl_link_stats(struct rtnl_link_stats *a,
be1f3c2c 771 const struct rtnl_link_stats64 *b)
1da177e4 772{
b60c5115
TG
773 a->rx_packets = b->rx_packets;
774 a->tx_packets = b->tx_packets;
775 a->rx_bytes = b->rx_bytes;
776 a->tx_bytes = b->tx_bytes;
777 a->rx_errors = b->rx_errors;
778 a->tx_errors = b->tx_errors;
779 a->rx_dropped = b->rx_dropped;
780 a->tx_dropped = b->tx_dropped;
781
782 a->multicast = b->multicast;
783 a->collisions = b->collisions;
784
785 a->rx_length_errors = b->rx_length_errors;
786 a->rx_over_errors = b->rx_over_errors;
787 a->rx_crc_errors = b->rx_crc_errors;
788 a->rx_frame_errors = b->rx_frame_errors;
789 a->rx_fifo_errors = b->rx_fifo_errors;
790 a->rx_missed_errors = b->rx_missed_errors;
791
792 a->tx_aborted_errors = b->tx_aborted_errors;
793 a->tx_carrier_errors = b->tx_carrier_errors;
794 a->tx_fifo_errors = b->tx_fifo_errors;
795 a->tx_heartbeat_errors = b->tx_heartbeat_errors;
796 a->tx_window_errors = b->tx_window_errors;
797
798 a->rx_compressed = b->rx_compressed;
799 a->tx_compressed = b->tx_compressed;
10708f37
JE
800}
801
be1f3c2c 802static void copy_rtnl_link_stats64(void *v, const struct rtnl_link_stats64 *b)
10708f37 803{
afdcba37 804 memcpy(v, b, sizeof(*b));
10708f37 805}
1da177e4 806
c02db8c6 807/* All VF info */
115c9b81
GR
808static inline int rtnl_vfinfo_size(const struct net_device *dev,
809 u32 ext_filter_mask)
ebc08a6f 810{
115c9b81
GR
811 if (dev->dev.parent && dev_is_pci(dev->dev.parent) &&
812 (ext_filter_mask & RTEXT_FILTER_VF)) {
c02db8c6 813 int num_vfs = dev_num_vf(dev->dev.parent);
045de01a
SF
814 size_t size = nla_total_size(sizeof(struct nlattr));
815 size += nla_total_size(num_vfs * sizeof(struct nlattr));
816 size += num_vfs *
817 (nla_total_size(sizeof(struct ifla_vf_mac)) +
818 nla_total_size(sizeof(struct ifla_vf_vlan)) +
ed616689 819 nla_total_size(sizeof(struct ifla_vf_spoofchk)) +
945a3676 820 nla_total_size(sizeof(struct ifla_vf_rate)) +
01a3d796
VZ
821 nla_total_size(sizeof(struct ifla_vf_link_state)) +
822 nla_total_size(sizeof(struct ifla_vf_rss_query_en)));
c02db8c6
CW
823 return size;
824 } else
ebc08a6f
WM
825 return 0;
826}
827
c53864fd
DG
828static size_t rtnl_port_size(const struct net_device *dev,
829 u32 ext_filter_mask)
57b61080
SF
830{
831 size_t port_size = nla_total_size(4) /* PORT_VF */
832 + nla_total_size(PORT_PROFILE_MAX) /* PORT_PROFILE */
833 + nla_total_size(sizeof(struct ifla_port_vsi))
834 /* PORT_VSI_TYPE */
835 + nla_total_size(PORT_UUID_MAX) /* PORT_INSTANCE_UUID */
836 + nla_total_size(PORT_UUID_MAX) /* PORT_HOST_UUID */
837 + nla_total_size(1) /* PROT_VDP_REQUEST */
838 + nla_total_size(2); /* PORT_VDP_RESPONSE */
839 size_t vf_ports_size = nla_total_size(sizeof(struct nlattr));
840 size_t vf_port_size = nla_total_size(sizeof(struct nlattr))
841 + port_size;
842 size_t port_self_size = nla_total_size(sizeof(struct nlattr))
843 + port_size;
844
c53864fd
DG
845 if (!dev->netdev_ops->ndo_get_vf_port || !dev->dev.parent ||
846 !(ext_filter_mask & RTEXT_FILTER_VF))
57b61080
SF
847 return 0;
848 if (dev_num_vf(dev->dev.parent))
849 return port_self_size + vf_ports_size +
850 vf_port_size * dev_num_vf(dev->dev.parent);
851 else
852 return port_self_size;
853}
854
115c9b81
GR
855static noinline size_t if_nlmsg_size(const struct net_device *dev,
856 u32 ext_filter_mask)
339bf98f
TG
857{
858 return NLMSG_ALIGN(sizeof(struct ifinfomsg))
859 + nla_total_size(IFNAMSIZ) /* IFLA_IFNAME */
0b815a1a 860 + nla_total_size(IFALIASZ) /* IFLA_IFALIAS */
339bf98f
TG
861 + nla_total_size(IFNAMSIZ) /* IFLA_QDISC */
862 + nla_total_size(sizeof(struct rtnl_link_ifmap))
863 + nla_total_size(sizeof(struct rtnl_link_stats))
adcfe196 864 + nla_total_size(sizeof(struct rtnl_link_stats64))
339bf98f
TG
865 + nla_total_size(MAX_ADDR_LEN) /* IFLA_ADDRESS */
866 + nla_total_size(MAX_ADDR_LEN) /* IFLA_BROADCAST */
867 + nla_total_size(4) /* IFLA_TXQLEN */
868 + nla_total_size(4) /* IFLA_WEIGHT */
869 + nla_total_size(4) /* IFLA_MTU */
870 + nla_total_size(4) /* IFLA_LINK */
871 + nla_total_size(4) /* IFLA_MASTER */
9a57247f 872 + nla_total_size(1) /* IFLA_CARRIER */
edbc0bb3 873 + nla_total_size(4) /* IFLA_PROMISCUITY */
76ff5cc9
JP
874 + nla_total_size(4) /* IFLA_NUM_TX_QUEUES */
875 + nla_total_size(4) /* IFLA_NUM_RX_QUEUES */
339bf98f 876 + nla_total_size(1) /* IFLA_OPERSTATE */
38f7b870 877 + nla_total_size(1) /* IFLA_LINKMODE */
2d3b479d 878 + nla_total_size(4) /* IFLA_CARRIER_CHANGES */
d37512a2 879 + nla_total_size(4) /* IFLA_LINK_NETNSID */
115c9b81
GR
880 + nla_total_size(ext_filter_mask
881 & RTEXT_FILTER_VF ? 4 : 0) /* IFLA_NUM_VF */
882 + rtnl_vfinfo_size(dev, ext_filter_mask) /* IFLA_VFINFO_LIST */
c53864fd 883 + rtnl_port_size(dev, ext_filter_mask) /* IFLA_VF_PORTS + IFLA_PORT_SELF */
f8ff182c 884 + rtnl_link_get_size(dev) /* IFLA_LINKINFO */
66cae9ed 885 + rtnl_link_get_af_size(dev) /* IFLA_AF_SPEC */
82f28412
JP
886 + nla_total_size(MAX_PHYS_ITEM_ID_LEN) /* IFLA_PHYS_PORT_ID */
887 + nla_total_size(MAX_PHYS_ITEM_ID_LEN); /* IFLA_PHYS_SWITCH_ID */
339bf98f
TG
888}
889
57b61080
SF
890static int rtnl_vf_ports_fill(struct sk_buff *skb, struct net_device *dev)
891{
892 struct nlattr *vf_ports;
893 struct nlattr *vf_port;
894 int vf;
895 int err;
896
897 vf_ports = nla_nest_start(skb, IFLA_VF_PORTS);
898 if (!vf_ports)
899 return -EMSGSIZE;
900
901 for (vf = 0; vf < dev_num_vf(dev->dev.parent); vf++) {
902 vf_port = nla_nest_start(skb, IFLA_VF_PORT);
8ca94183
SF
903 if (!vf_port)
904 goto nla_put_failure;
a6574349
DM
905 if (nla_put_u32(skb, IFLA_PORT_VF, vf))
906 goto nla_put_failure;
57b61080 907 err = dev->netdev_ops->ndo_get_vf_port(dev, vf, skb);
8ca94183
SF
908 if (err == -EMSGSIZE)
909 goto nla_put_failure;
57b61080 910 if (err) {
57b61080
SF
911 nla_nest_cancel(skb, vf_port);
912 continue;
913 }
914 nla_nest_end(skb, vf_port);
915 }
916
917 nla_nest_end(skb, vf_ports);
918
919 return 0;
8ca94183
SF
920
921nla_put_failure:
922 nla_nest_cancel(skb, vf_ports);
923 return -EMSGSIZE;
57b61080
SF
924}
925
926static int rtnl_port_self_fill(struct sk_buff *skb, struct net_device *dev)
927{
928 struct nlattr *port_self;
929 int err;
930
931 port_self = nla_nest_start(skb, IFLA_PORT_SELF);
932 if (!port_self)
933 return -EMSGSIZE;
934
935 err = dev->netdev_ops->ndo_get_vf_port(dev, PORT_SELF_VF, skb);
936 if (err) {
937 nla_nest_cancel(skb, port_self);
8ca94183 938 return (err == -EMSGSIZE) ? err : 0;
57b61080
SF
939 }
940
941 nla_nest_end(skb, port_self);
942
943 return 0;
944}
945
c53864fd
DG
946static int rtnl_port_fill(struct sk_buff *skb, struct net_device *dev,
947 u32 ext_filter_mask)
57b61080
SF
948{
949 int err;
950
c53864fd
DG
951 if (!dev->netdev_ops->ndo_get_vf_port || !dev->dev.parent ||
952 !(ext_filter_mask & RTEXT_FILTER_VF))
57b61080
SF
953 return 0;
954
955 err = rtnl_port_self_fill(skb, dev);
956 if (err)
957 return err;
958
959 if (dev_num_vf(dev->dev.parent)) {
960 err = rtnl_vf_ports_fill(skb, dev);
961 if (err)
962 return err;
963 }
964
965 return 0;
966}
967
66cae9ed
JP
968static int rtnl_phys_port_id_fill(struct sk_buff *skb, struct net_device *dev)
969{
970 int err;
02637fce 971 struct netdev_phys_item_id ppid;
66cae9ed
JP
972
973 err = dev_get_phys_port_id(dev, &ppid);
974 if (err) {
975 if (err == -EOPNOTSUPP)
976 return 0;
977 return err;
978 }
979
980 if (nla_put(skb, IFLA_PHYS_PORT_ID, ppid.id_len, ppid.id))
981 return -EMSGSIZE;
982
983 return 0;
984}
985
db24a904
DA
986static int rtnl_phys_port_name_fill(struct sk_buff *skb, struct net_device *dev)
987{
988 char name[IFNAMSIZ];
989 int err;
990
991 err = dev_get_phys_port_name(dev, name, sizeof(name));
992 if (err) {
993 if (err == -EOPNOTSUPP)
994 return 0;
995 return err;
996 }
997
998 if (nla_put(skb, IFLA_PHYS_PORT_NAME, strlen(name), name))
999 return -EMSGSIZE;
1000
1001 return 0;
1002}
1003
82f28412
JP
1004static int rtnl_phys_switch_id_fill(struct sk_buff *skb, struct net_device *dev)
1005{
1006 int err;
1007 struct netdev_phys_item_id psid;
1008
1009 err = netdev_switch_parent_id_get(dev, &psid);
1010 if (err) {
1011 if (err == -EOPNOTSUPP)
1012 return 0;
1013 return err;
1014 }
1015
1016 if (nla_put(skb, IFLA_PHYS_SWITCH_ID, psid.id_len, psid.id))
1017 return -EMSGSIZE;
1018
1019 return 0;
1020}
1021
b60c5115 1022static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
575c3e2a 1023 int type, u32 pid, u32 seq, u32 change,
115c9b81 1024 unsigned int flags, u32 ext_filter_mask)
b60c5115
TG
1025{
1026 struct ifinfomsg *ifm;
1027 struct nlmsghdr *nlh;
28172739 1028 struct rtnl_link_stats64 temp;
be1f3c2c 1029 const struct rtnl_link_stats64 *stats;
f8ff182c
TG
1030 struct nlattr *attr, *af_spec;
1031 struct rtnl_af_ops *af_ops;
898e5061 1032 struct net_device *upper_dev = netdev_master_upper_dev_get(dev);
1da177e4 1033
2907c35f 1034 ASSERT_RTNL();
b60c5115
TG
1035 nlh = nlmsg_put(skb, pid, seq, type, sizeof(*ifm), flags);
1036 if (nlh == NULL)
26932566 1037 return -EMSGSIZE;
1da177e4 1038
b60c5115
TG
1039 ifm = nlmsg_data(nlh);
1040 ifm->ifi_family = AF_UNSPEC;
1041 ifm->__ifi_pad = 0;
1042 ifm->ifi_type = dev->type;
1043 ifm->ifi_index = dev->ifindex;
1044 ifm->ifi_flags = dev_get_flags(dev);
1045 ifm->ifi_change = change;
1046
a6574349
DM
1047 if (nla_put_string(skb, IFLA_IFNAME, dev->name) ||
1048 nla_put_u32(skb, IFLA_TXQLEN, dev->tx_queue_len) ||
1049 nla_put_u8(skb, IFLA_OPERSTATE,
1050 netif_running(dev) ? dev->operstate : IF_OPER_DOWN) ||
1051 nla_put_u8(skb, IFLA_LINKMODE, dev->link_mode) ||
1052 nla_put_u32(skb, IFLA_MTU, dev->mtu) ||
1053 nla_put_u32(skb, IFLA_GROUP, dev->group) ||
edbc0bb3 1054 nla_put_u32(skb, IFLA_PROMISCUITY, dev->promiscuity) ||
76ff5cc9 1055 nla_put_u32(skb, IFLA_NUM_TX_QUEUES, dev->num_tx_queues) ||
1d69c2b3 1056#ifdef CONFIG_RPS
76ff5cc9 1057 nla_put_u32(skb, IFLA_NUM_RX_QUEUES, dev->num_rx_queues) ||
1d69c2b3 1058#endif
a54acb3a
ND
1059 (dev->ifindex != dev_get_iflink(dev) &&
1060 nla_put_u32(skb, IFLA_LINK, dev_get_iflink(dev))) ||
898e5061
JP
1061 (upper_dev &&
1062 nla_put_u32(skb, IFLA_MASTER, upper_dev->ifindex)) ||
9a57247f 1063 nla_put_u8(skb, IFLA_CARRIER, netif_carrier_ok(dev)) ||
a6574349
DM
1064 (dev->qdisc &&
1065 nla_put_string(skb, IFLA_QDISC, dev->qdisc->ops->id)) ||
1066 (dev->ifalias &&
2d3b479d 1067 nla_put_string(skb, IFLA_IFALIAS, dev->ifalias)) ||
1068 nla_put_u32(skb, IFLA_CARRIER_CHANGES,
1069 atomic_read(&dev->carrier_changes)))
a6574349 1070 goto nla_put_failure;
0b815a1a 1071
1da177e4
LT
1072 if (1) {
1073 struct rtnl_link_ifmap map = {
1074 .mem_start = dev->mem_start,
1075 .mem_end = dev->mem_end,
1076 .base_addr = dev->base_addr,
1077 .irq = dev->irq,
1078 .dma = dev->dma,
1079 .port = dev->if_port,
1080 };
a6574349
DM
1081 if (nla_put(skb, IFLA_MAP, sizeof(map), &map))
1082 goto nla_put_failure;
1da177e4
LT
1083 }
1084
1085 if (dev->addr_len) {
a6574349
DM
1086 if (nla_put(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr) ||
1087 nla_put(skb, IFLA_BROADCAST, dev->addr_len, dev->broadcast))
1088 goto nla_put_failure;
1da177e4
LT
1089 }
1090
66cae9ed
JP
1091 if (rtnl_phys_port_id_fill(skb, dev))
1092 goto nla_put_failure;
1093
db24a904
DA
1094 if (rtnl_phys_port_name_fill(skb, dev))
1095 goto nla_put_failure;
1096
82f28412
JP
1097 if (rtnl_phys_switch_id_fill(skb, dev))
1098 goto nla_put_failure;
1099
96e74088
PE
1100 attr = nla_reserve(skb, IFLA_STATS,
1101 sizeof(struct rtnl_link_stats));
1102 if (attr == NULL)
1103 goto nla_put_failure;
b60c5115 1104
28172739 1105 stats = dev_get_stats(dev, &temp);
96e74088 1106 copy_rtnl_link_stats(nla_data(attr), stats);
1da177e4 1107
10708f37
JE
1108 attr = nla_reserve(skb, IFLA_STATS64,
1109 sizeof(struct rtnl_link_stats64));
1110 if (attr == NULL)
1111 goto nla_put_failure;
10708f37
JE
1112 copy_rtnl_link_stats64(nla_data(attr), stats);
1113
a6574349
DM
1114 if (dev->dev.parent && (ext_filter_mask & RTEXT_FILTER_VF) &&
1115 nla_put_u32(skb, IFLA_NUM_VF, dev_num_vf(dev->dev.parent)))
1116 goto nla_put_failure;
57b61080 1117
115c9b81
GR
1118 if (dev->netdev_ops->ndo_get_vf_config && dev->dev.parent
1119 && (ext_filter_mask & RTEXT_FILTER_VF)) {
ebc08a6f 1120 int i;
ebc08a6f 1121
c02db8c6
CW
1122 struct nlattr *vfinfo, *vf;
1123 int num_vfs = dev_num_vf(dev->dev.parent);
1124
c02db8c6
CW
1125 vfinfo = nla_nest_start(skb, IFLA_VFINFO_LIST);
1126 if (!vfinfo)
1127 goto nla_put_failure;
1128 for (i = 0; i < num_vfs; i++) {
1129 struct ifla_vf_info ivi;
1130 struct ifla_vf_mac vf_mac;
1131 struct ifla_vf_vlan vf_vlan;
ed616689 1132 struct ifla_vf_rate vf_rate;
c02db8c6 1133 struct ifla_vf_tx_rate vf_tx_rate;
5f8444a3 1134 struct ifla_vf_spoofchk vf_spoofchk;
1d8faf48 1135 struct ifla_vf_link_state vf_linkstate;
01a3d796 1136 struct ifla_vf_rss_query_en vf_rss_query_en;
5f8444a3
GR
1137
1138 /*
1139 * Not all SR-IOV capable drivers support the
01a3d796
VZ
1140 * spoofcheck and "RSS query enable" query. Preset to
1141 * -1 so the user space tool can detect that the driver
1142 * didn't report anything.
5f8444a3
GR
1143 */
1144 ivi.spoofchk = -1;
01a3d796 1145 ivi.rss_query_en = -1;
84d73cd3 1146 memset(ivi.mac, 0, sizeof(ivi.mac));
1d8faf48
RE
1147 /* The default value for VF link state is "auto"
1148 * IFLA_VF_LINK_STATE_AUTO which equals zero
1149 */
1150 ivi.linkstate = 0;
ebc08a6f
WM
1151 if (dev->netdev_ops->ndo_get_vf_config(dev, i, &ivi))
1152 break;
5f8444a3
GR
1153 vf_mac.vf =
1154 vf_vlan.vf =
ed616689 1155 vf_rate.vf =
5f8444a3 1156 vf_tx_rate.vf =
1d8faf48 1157 vf_spoofchk.vf =
01a3d796
VZ
1158 vf_linkstate.vf =
1159 vf_rss_query_en.vf = ivi.vf;
5f8444a3 1160
c02db8c6
CW
1161 memcpy(vf_mac.mac, ivi.mac, sizeof(ivi.mac));
1162 vf_vlan.vlan = ivi.vlan;
1163 vf_vlan.qos = ivi.qos;
ed616689
SC
1164 vf_tx_rate.rate = ivi.max_tx_rate;
1165 vf_rate.min_tx_rate = ivi.min_tx_rate;
1166 vf_rate.max_tx_rate = ivi.max_tx_rate;
5f8444a3 1167 vf_spoofchk.setting = ivi.spoofchk;
1d8faf48 1168 vf_linkstate.link_state = ivi.linkstate;
01a3d796 1169 vf_rss_query_en.setting = ivi.rss_query_en;
c02db8c6
CW
1170 vf = nla_nest_start(skb, IFLA_VF_INFO);
1171 if (!vf) {
1172 nla_nest_cancel(skb, vfinfo);
1173 goto nla_put_failure;
1174 }
a6574349
DM
1175 if (nla_put(skb, IFLA_VF_MAC, sizeof(vf_mac), &vf_mac) ||
1176 nla_put(skb, IFLA_VF_VLAN, sizeof(vf_vlan), &vf_vlan) ||
ed616689
SC
1177 nla_put(skb, IFLA_VF_RATE, sizeof(vf_rate),
1178 &vf_rate) ||
a6574349
DM
1179 nla_put(skb, IFLA_VF_TX_RATE, sizeof(vf_tx_rate),
1180 &vf_tx_rate) ||
1181 nla_put(skb, IFLA_VF_SPOOFCHK, sizeof(vf_spoofchk),
1d8faf48
RE
1182 &vf_spoofchk) ||
1183 nla_put(skb, IFLA_VF_LINK_STATE, sizeof(vf_linkstate),
01a3d796
VZ
1184 &vf_linkstate) ||
1185 nla_put(skb, IFLA_VF_RSS_QUERY_EN,
1186 sizeof(vf_rss_query_en),
1187 &vf_rss_query_en))
a6574349 1188 goto nla_put_failure;
c02db8c6 1189 nla_nest_end(skb, vf);
ebc08a6f 1190 }
c02db8c6 1191 nla_nest_end(skb, vfinfo);
ebc08a6f 1192 }
57b61080 1193
c53864fd 1194 if (rtnl_port_fill(skb, dev, ext_filter_mask))
57b61080
SF
1195 goto nla_put_failure;
1196
ba7d49b1 1197 if (dev->rtnl_link_ops || rtnl_have_link_slave_info(dev)) {
38f7b870
PM
1198 if (rtnl_link_fill(skb, dev) < 0)
1199 goto nla_put_failure;
1200 }
1201
d37512a2
ND
1202 if (dev->rtnl_link_ops &&
1203 dev->rtnl_link_ops->get_link_net) {
1204 struct net *link_net = dev->rtnl_link_ops->get_link_net(dev);
1205
1206 if (!net_eq(dev_net(dev), link_net)) {
1207 int id = peernet2id(dev_net(dev), link_net);
1208
1209 if (nla_put_s32(skb, IFLA_LINK_NETNSID, id))
1210 goto nla_put_failure;
1211 }
1212 }
1213
f8ff182c
TG
1214 if (!(af_spec = nla_nest_start(skb, IFLA_AF_SPEC)))
1215 goto nla_put_failure;
1216
1217 list_for_each_entry(af_ops, &rtnl_af_ops, list) {
1218 if (af_ops->fill_link_af) {
1219 struct nlattr *af;
1220 int err;
1221
1222 if (!(af = nla_nest_start(skb, af_ops->family)))
1223 goto nla_put_failure;
1224
1225 err = af_ops->fill_link_af(skb, dev);
1226
1227 /*
1228 * Caller may return ENODATA to indicate that there
1229 * was no data to be dumped. This is not an error, it
1230 * means we should trim the attribute header and
1231 * continue.
1232 */
1233 if (err == -ENODATA)
1234 nla_nest_cancel(skb, af);
1235 else if (err < 0)
1236 goto nla_put_failure;
1237
1238 nla_nest_end(skb, af);
1239 }
1240 }
1241
1242 nla_nest_end(skb, af_spec);
1243
053c095a
JB
1244 nlmsg_end(skb, nlh);
1245 return 0;
b60c5115
TG
1246
1247nla_put_failure:
26932566
PM
1248 nlmsg_cancel(skb, nlh);
1249 return -EMSGSIZE;
1da177e4
LT
1250}
1251
f7b12606 1252static const struct nla_policy ifla_policy[IFLA_MAX+1] = {
5176f91e 1253 [IFLA_IFNAME] = { .type = NLA_STRING, .len = IFNAMSIZ-1 },
38f7b870
PM
1254 [IFLA_ADDRESS] = { .type = NLA_BINARY, .len = MAX_ADDR_LEN },
1255 [IFLA_BROADCAST] = { .type = NLA_BINARY, .len = MAX_ADDR_LEN },
5176f91e 1256 [IFLA_MAP] = { .len = sizeof(struct rtnl_link_ifmap) },
da5e0494 1257 [IFLA_MTU] = { .type = NLA_U32 },
76e87306 1258 [IFLA_LINK] = { .type = NLA_U32 },
fbaec0ea 1259 [IFLA_MASTER] = { .type = NLA_U32 },
9a57247f 1260 [IFLA_CARRIER] = { .type = NLA_U8 },
da5e0494
TG
1261 [IFLA_TXQLEN] = { .type = NLA_U32 },
1262 [IFLA_WEIGHT] = { .type = NLA_U32 },
1263 [IFLA_OPERSTATE] = { .type = NLA_U8 },
1264 [IFLA_LINKMODE] = { .type = NLA_U8 },
76e87306 1265 [IFLA_LINKINFO] = { .type = NLA_NESTED },
d8a5ec67 1266 [IFLA_NET_NS_PID] = { .type = NLA_U32 },
f0630529 1267 [IFLA_NET_NS_FD] = { .type = NLA_U32 },
0b815a1a 1268 [IFLA_IFALIAS] = { .type = NLA_STRING, .len = IFALIASZ-1 },
c02db8c6 1269 [IFLA_VFINFO_LIST] = {. type = NLA_NESTED },
57b61080
SF
1270 [IFLA_VF_PORTS] = { .type = NLA_NESTED },
1271 [IFLA_PORT_SELF] = { .type = NLA_NESTED },
f8ff182c 1272 [IFLA_AF_SPEC] = { .type = NLA_NESTED },
115c9b81 1273 [IFLA_EXT_MASK] = { .type = NLA_U32 },
edbc0bb3 1274 [IFLA_PROMISCUITY] = { .type = NLA_U32 },
76ff5cc9
JP
1275 [IFLA_NUM_TX_QUEUES] = { .type = NLA_U32 },
1276 [IFLA_NUM_RX_QUEUES] = { .type = NLA_U32 },
02637fce 1277 [IFLA_PHYS_PORT_ID] = { .type = NLA_BINARY, .len = MAX_PHYS_ITEM_ID_LEN },
2d3b479d 1278 [IFLA_CARRIER_CHANGES] = { .type = NLA_U32 }, /* ignored */
82f28412 1279 [IFLA_PHYS_SWITCH_ID] = { .type = NLA_BINARY, .len = MAX_PHYS_ITEM_ID_LEN },
317f4810 1280 [IFLA_LINK_NETNSID] = { .type = NLA_S32 },
da5e0494
TG
1281};
1282
38f7b870
PM
1283static const struct nla_policy ifla_info_policy[IFLA_INFO_MAX+1] = {
1284 [IFLA_INFO_KIND] = { .type = NLA_STRING },
1285 [IFLA_INFO_DATA] = { .type = NLA_NESTED },
ba7d49b1
JP
1286 [IFLA_INFO_SLAVE_KIND] = { .type = NLA_STRING },
1287 [IFLA_INFO_SLAVE_DATA] = { .type = NLA_NESTED },
38f7b870
PM
1288};
1289
c02db8c6
CW
1290static const struct nla_policy ifla_vfinfo_policy[IFLA_VF_INFO_MAX+1] = {
1291 [IFLA_VF_INFO] = { .type = NLA_NESTED },
1292};
1293
1294static const struct nla_policy ifla_vf_policy[IFLA_VF_MAX+1] = {
364d5716
DB
1295 [IFLA_VF_MAC] = { .len = sizeof(struct ifla_vf_mac) },
1296 [IFLA_VF_VLAN] = { .len = sizeof(struct ifla_vf_vlan) },
1297 [IFLA_VF_TX_RATE] = { .len = sizeof(struct ifla_vf_tx_rate) },
1298 [IFLA_VF_SPOOFCHK] = { .len = sizeof(struct ifla_vf_spoofchk) },
1299 [IFLA_VF_RATE] = { .len = sizeof(struct ifla_vf_rate) },
1300 [IFLA_VF_LINK_STATE] = { .len = sizeof(struct ifla_vf_link_state) },
01a3d796 1301 [IFLA_VF_RSS_QUERY_EN] = { .len = sizeof(struct ifla_vf_rss_query_en) },
c02db8c6
CW
1302};
1303
57b61080
SF
1304static const struct nla_policy ifla_port_policy[IFLA_PORT_MAX+1] = {
1305 [IFLA_PORT_VF] = { .type = NLA_U32 },
1306 [IFLA_PORT_PROFILE] = { .type = NLA_STRING,
1307 .len = PORT_PROFILE_MAX },
1308 [IFLA_PORT_VSI_TYPE] = { .type = NLA_BINARY,
1309 .len = sizeof(struct ifla_port_vsi)},
1310 [IFLA_PORT_INSTANCE_UUID] = { .type = NLA_BINARY,
1311 .len = PORT_UUID_MAX },
1312 [IFLA_PORT_HOST_UUID] = { .type = NLA_STRING,
1313 .len = PORT_UUID_MAX },
1314 [IFLA_PORT_REQUEST] = { .type = NLA_U8, },
1315 [IFLA_PORT_RESPONSE] = { .type = NLA_U16, },
1316};
1317
f7b12606
JP
1318static int rtnl_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
1319{
1320 struct net *net = sock_net(skb->sk);
1321 int h, s_h;
1322 int idx = 0, s_idx;
1323 struct net_device *dev;
1324 struct hlist_head *head;
1325 struct nlattr *tb[IFLA_MAX+1];
1326 u32 ext_filter_mask = 0;
973462bb 1327 int err;
e5eca6d4 1328 int hdrlen;
f7b12606
JP
1329
1330 s_h = cb->args[0];
1331 s_idx = cb->args[1];
1332
f7b12606
JP
1333 cb->seq = net->dev_base_seq;
1334
e5eca6d4
MS
1335 /* A hack to preserve kernel<->userspace interface.
1336 * The correct header is ifinfomsg. It is consistent with rtnl_getlink.
1337 * However, before Linux v3.9 the code here assumed rtgenmsg and that's
1338 * what iproute2 < v3.9.0 used.
1339 * We can detect the old iproute2. Even including the IFLA_EXT_MASK
1340 * attribute, its netlink message is shorter than struct ifinfomsg.
1341 */
1342 hdrlen = nlmsg_len(cb->nlh) < sizeof(struct ifinfomsg) ?
1343 sizeof(struct rtgenmsg) : sizeof(struct ifinfomsg);
1344
1345 if (nlmsg_parse(cb->nlh, hdrlen, tb, IFLA_MAX, ifla_policy) >= 0) {
f7b12606
JP
1346
1347 if (tb[IFLA_EXT_MASK])
1348 ext_filter_mask = nla_get_u32(tb[IFLA_EXT_MASK]);
1349 }
1350
1351 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
1352 idx = 0;
1353 head = &net->dev_index_head[h];
cac5e65e 1354 hlist_for_each_entry(dev, head, index_hlist) {
f7b12606
JP
1355 if (idx < s_idx)
1356 goto cont;
973462bb
DG
1357 err = rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
1358 NETLINK_CB(cb->skb).portid,
1359 cb->nlh->nlmsg_seq, 0,
1360 NLM_F_MULTI,
1361 ext_filter_mask);
1362 /* If we ran out of room on the first message,
1363 * we're in trouble
1364 */
1365 WARN_ON((err == -EMSGSIZE) && (skb->len == 0));
1366
7b46a644 1367 if (err < 0)
f7b12606
JP
1368 goto out;
1369
1370 nl_dump_check_consistent(cb, nlmsg_hdr(skb));
1371cont:
1372 idx++;
1373 }
1374 }
1375out:
f7b12606
JP
1376 cb->args[1] = idx;
1377 cb->args[0] = h;
1378
1379 return skb->len;
1380}
1381
1382int rtnl_nla_parse_ifla(struct nlattr **tb, const struct nlattr *head, int len)
1383{
1384 return nla_parse(tb, IFLA_MAX, head, len, ifla_policy);
1385}
1386EXPORT_SYMBOL(rtnl_nla_parse_ifla);
1387
81adee47
EB
1388struct net *rtnl_link_get_net(struct net *src_net, struct nlattr *tb[])
1389{
1390 struct net *net;
1391 /* Examine the link attributes and figure out which
1392 * network namespace we are talking about.
1393 */
1394 if (tb[IFLA_NET_NS_PID])
1395 net = get_net_ns_by_pid(nla_get_u32(tb[IFLA_NET_NS_PID]));
f0630529
EB
1396 else if (tb[IFLA_NET_NS_FD])
1397 net = get_net_ns_by_fd(nla_get_u32(tb[IFLA_NET_NS_FD]));
81adee47
EB
1398 else
1399 net = get_net(src_net);
1400 return net;
1401}
1402EXPORT_SYMBOL(rtnl_link_get_net);
1403
1840bb13
TG
1404static int validate_linkmsg(struct net_device *dev, struct nlattr *tb[])
1405{
1406 if (dev) {
1407 if (tb[IFLA_ADDRESS] &&
1408 nla_len(tb[IFLA_ADDRESS]) < dev->addr_len)
1409 return -EINVAL;
1410
1411 if (tb[IFLA_BROADCAST] &&
1412 nla_len(tb[IFLA_BROADCAST]) < dev->addr_len)
1413 return -EINVAL;
1414 }
1415
cf7afbfe
TG
1416 if (tb[IFLA_AF_SPEC]) {
1417 struct nlattr *af;
1418 int rem, err;
1419
1420 nla_for_each_nested(af, tb[IFLA_AF_SPEC], rem) {
1421 const struct rtnl_af_ops *af_ops;
1422
1423 if (!(af_ops = rtnl_af_lookup(nla_type(af))))
1424 return -EAFNOSUPPORT;
1425
1426 if (!af_ops->set_link_af)
1427 return -EOPNOTSUPP;
1428
1429 if (af_ops->validate_link_af) {
6d3a9a68 1430 err = af_ops->validate_link_af(dev, af);
cf7afbfe
TG
1431 if (err < 0)
1432 return err;
1433 }
1434 }
1435 }
1436
1840bb13
TG
1437 return 0;
1438}
1439
c02db8c6
CW
1440static int do_setvfinfo(struct net_device *dev, struct nlattr *attr)
1441{
1442 int rem, err = -EINVAL;
1443 struct nlattr *vf;
1444 const struct net_device_ops *ops = dev->netdev_ops;
1445
1446 nla_for_each_nested(vf, attr, rem) {
1447 switch (nla_type(vf)) {
1448 case IFLA_VF_MAC: {
1449 struct ifla_vf_mac *ivm;
1450 ivm = nla_data(vf);
1451 err = -EOPNOTSUPP;
1452 if (ops->ndo_set_vf_mac)
1453 err = ops->ndo_set_vf_mac(dev, ivm->vf,
1454 ivm->mac);
1455 break;
1456 }
1457 case IFLA_VF_VLAN: {
1458 struct ifla_vf_vlan *ivv;
1459 ivv = nla_data(vf);
1460 err = -EOPNOTSUPP;
1461 if (ops->ndo_set_vf_vlan)
1462 err = ops->ndo_set_vf_vlan(dev, ivv->vf,
1463 ivv->vlan,
1464 ivv->qos);
1465 break;
1466 }
1467 case IFLA_VF_TX_RATE: {
1468 struct ifla_vf_tx_rate *ivt;
ed616689 1469 struct ifla_vf_info ivf;
c02db8c6
CW
1470 ivt = nla_data(vf);
1471 err = -EOPNOTSUPP;
ed616689
SC
1472 if (ops->ndo_get_vf_config)
1473 err = ops->ndo_get_vf_config(dev, ivt->vf,
1474 &ivf);
1475 if (err)
1476 break;
1477 err = -EOPNOTSUPP;
1478 if (ops->ndo_set_vf_rate)
1479 err = ops->ndo_set_vf_rate(dev, ivt->vf,
1480 ivf.min_tx_rate,
1481 ivt->rate);
1482 break;
1483 }
1484 case IFLA_VF_RATE: {
1485 struct ifla_vf_rate *ivt;
1486 ivt = nla_data(vf);
1487 err = -EOPNOTSUPP;
1488 if (ops->ndo_set_vf_rate)
1489 err = ops->ndo_set_vf_rate(dev, ivt->vf,
1490 ivt->min_tx_rate,
1491 ivt->max_tx_rate);
c02db8c6
CW
1492 break;
1493 }
5f8444a3
GR
1494 case IFLA_VF_SPOOFCHK: {
1495 struct ifla_vf_spoofchk *ivs;
1496 ivs = nla_data(vf);
1497 err = -EOPNOTSUPP;
1498 if (ops->ndo_set_vf_spoofchk)
1499 err = ops->ndo_set_vf_spoofchk(dev, ivs->vf,
1500 ivs->setting);
1501 break;
1502 }
1d8faf48
RE
1503 case IFLA_VF_LINK_STATE: {
1504 struct ifla_vf_link_state *ivl;
1505 ivl = nla_data(vf);
1506 err = -EOPNOTSUPP;
1507 if (ops->ndo_set_vf_link_state)
1508 err = ops->ndo_set_vf_link_state(dev, ivl->vf,
1509 ivl->link_state);
1510 break;
1511 }
01a3d796
VZ
1512 case IFLA_VF_RSS_QUERY_EN: {
1513 struct ifla_vf_rss_query_en *ivrssq_en;
1514
1515 ivrssq_en = nla_data(vf);
1516 err = -EOPNOTSUPP;
1517 if (ops->ndo_set_vf_rss_query_en)
1518 err = ops->ndo_set_vf_rss_query_en(dev,
1519 ivrssq_en->vf,
1520 ivrssq_en->setting);
1521 break;
1522 }
c02db8c6
CW
1523 default:
1524 err = -EINVAL;
1525 break;
1526 }
1527 if (err)
1528 break;
1529 }
1530 return err;
1531}
1532
fbaec0ea
JP
1533static int do_set_master(struct net_device *dev, int ifindex)
1534{
898e5061 1535 struct net_device *upper_dev = netdev_master_upper_dev_get(dev);
fbaec0ea
JP
1536 const struct net_device_ops *ops;
1537 int err;
1538
898e5061
JP
1539 if (upper_dev) {
1540 if (upper_dev->ifindex == ifindex)
fbaec0ea 1541 return 0;
898e5061 1542 ops = upper_dev->netdev_ops;
fbaec0ea 1543 if (ops->ndo_del_slave) {
898e5061 1544 err = ops->ndo_del_slave(upper_dev, dev);
fbaec0ea
JP
1545 if (err)
1546 return err;
1547 } else {
1548 return -EOPNOTSUPP;
1549 }
1550 }
1551
1552 if (ifindex) {
898e5061
JP
1553 upper_dev = __dev_get_by_index(dev_net(dev), ifindex);
1554 if (!upper_dev)
fbaec0ea 1555 return -EINVAL;
898e5061 1556 ops = upper_dev->netdev_ops;
fbaec0ea 1557 if (ops->ndo_add_slave) {
898e5061 1558 err = ops->ndo_add_slave(upper_dev, dev);
fbaec0ea
JP
1559 if (err)
1560 return err;
1561 } else {
1562 return -EOPNOTSUPP;
1563 }
1564 }
1565 return 0;
1566}
1567
90c325e3 1568#define DO_SETLINK_MODIFIED 0x01
ba998906
ND
1569/* notify flag means notify + modified. */
1570#define DO_SETLINK_NOTIFY 0x03
90f62cf3
EB
1571static int do_setlink(const struct sk_buff *skb,
1572 struct net_device *dev, struct ifinfomsg *ifm,
90c325e3 1573 struct nlattr **tb, char *ifname, int status)
1da177e4 1574{
d314774c 1575 const struct net_device_ops *ops = dev->netdev_ops;
0157f60c 1576 int err;
1da177e4 1577
f0630529 1578 if (tb[IFLA_NET_NS_PID] || tb[IFLA_NET_NS_FD]) {
81adee47 1579 struct net *net = rtnl_link_get_net(dev_net(dev), tb);
d8a5ec67
EB
1580 if (IS_ERR(net)) {
1581 err = PTR_ERR(net);
1582 goto errout;
1583 }
90f62cf3 1584 if (!netlink_ns_capable(skb, net->user_ns, CAP_NET_ADMIN)) {
e0ebde0e 1585 put_net(net);
b51642f6
EB
1586 err = -EPERM;
1587 goto errout;
1588 }
d8a5ec67
EB
1589 err = dev_change_net_namespace(dev, net, ifname);
1590 put_net(net);
1591 if (err)
1592 goto errout;
90c325e3 1593 status |= DO_SETLINK_MODIFIED;
d8a5ec67
EB
1594 }
1595
da5e0494 1596 if (tb[IFLA_MAP]) {
1da177e4
LT
1597 struct rtnl_link_ifmap *u_map;
1598 struct ifmap k_map;
1599
d314774c 1600 if (!ops->ndo_set_config) {
1da177e4 1601 err = -EOPNOTSUPP;
0157f60c 1602 goto errout;
1da177e4
LT
1603 }
1604
1605 if (!netif_device_present(dev)) {
1606 err = -ENODEV;
0157f60c 1607 goto errout;
1da177e4 1608 }
1da177e4 1609
da5e0494 1610 u_map = nla_data(tb[IFLA_MAP]);
1da177e4
LT
1611 k_map.mem_start = (unsigned long) u_map->mem_start;
1612 k_map.mem_end = (unsigned long) u_map->mem_end;
1613 k_map.base_addr = (unsigned short) u_map->base_addr;
1614 k_map.irq = (unsigned char) u_map->irq;
1615 k_map.dma = (unsigned char) u_map->dma;
1616 k_map.port = (unsigned char) u_map->port;
1617
d314774c 1618 err = ops->ndo_set_config(dev, &k_map);
da5e0494 1619 if (err < 0)
0157f60c 1620 goto errout;
1da177e4 1621
ba998906 1622 status |= DO_SETLINK_NOTIFY;
1da177e4
LT
1623 }
1624
da5e0494 1625 if (tb[IFLA_ADDRESS]) {
70f8e78e
DM
1626 struct sockaddr *sa;
1627 int len;
1628
70f8e78e
DM
1629 len = sizeof(sa_family_t) + dev->addr_len;
1630 sa = kmalloc(len, GFP_KERNEL);
1631 if (!sa) {
1632 err = -ENOMEM;
0157f60c 1633 goto errout;
70f8e78e
DM
1634 }
1635 sa->sa_family = dev->type;
da5e0494 1636 memcpy(sa->sa_data, nla_data(tb[IFLA_ADDRESS]),
70f8e78e 1637 dev->addr_len);
e7c3273e 1638 err = dev_set_mac_address(dev, sa);
70f8e78e 1639 kfree(sa);
1da177e4 1640 if (err)
0157f60c 1641 goto errout;
90c325e3 1642 status |= DO_SETLINK_MODIFIED;
1da177e4
LT
1643 }
1644
da5e0494
TG
1645 if (tb[IFLA_MTU]) {
1646 err = dev_set_mtu(dev, nla_get_u32(tb[IFLA_MTU]));
1647 if (err < 0)
0157f60c 1648 goto errout;
90c325e3 1649 status |= DO_SETLINK_MODIFIED;
1da177e4
LT
1650 }
1651
cbda10fa
VD
1652 if (tb[IFLA_GROUP]) {
1653 dev_set_group(dev, nla_get_u32(tb[IFLA_GROUP]));
ba998906 1654 status |= DO_SETLINK_NOTIFY;
cbda10fa
VD
1655 }
1656
da5e0494
TG
1657 /*
1658 * Interface selected by interface index but interface
1659 * name provided implies that a name change has been
1660 * requested.
1661 */
51055be8 1662 if (ifm->ifi_index > 0 && ifname[0]) {
da5e0494
TG
1663 err = dev_change_name(dev, ifname);
1664 if (err < 0)
0157f60c 1665 goto errout;
90c325e3 1666 status |= DO_SETLINK_MODIFIED;
1da177e4
LT
1667 }
1668
0b815a1a
SH
1669 if (tb[IFLA_IFALIAS]) {
1670 err = dev_set_alias(dev, nla_data(tb[IFLA_IFALIAS]),
1671 nla_len(tb[IFLA_IFALIAS]));
1672 if (err < 0)
1673 goto errout;
ba998906 1674 status |= DO_SETLINK_NOTIFY;
0b815a1a
SH
1675 }
1676
da5e0494
TG
1677 if (tb[IFLA_BROADCAST]) {
1678 nla_memcpy(dev->broadcast, tb[IFLA_BROADCAST], dev->addr_len);
e7c3273e 1679 call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
1da177e4
LT
1680 }
1681
83b496e9 1682 if (ifm->ifi_flags || ifm->ifi_change) {
3729d502 1683 err = dev_change_flags(dev, rtnl_dev_combine_flags(dev, ifm));
5f9021cf
JB
1684 if (err < 0)
1685 goto errout;
83b496e9 1686 }
1da177e4 1687
fbaec0ea
JP
1688 if (tb[IFLA_MASTER]) {
1689 err = do_set_master(dev, nla_get_u32(tb[IFLA_MASTER]));
1690 if (err)
1691 goto errout;
90c325e3 1692 status |= DO_SETLINK_MODIFIED;
fbaec0ea
JP
1693 }
1694
9a57247f
JP
1695 if (tb[IFLA_CARRIER]) {
1696 err = dev_change_carrier(dev, nla_get_u8(tb[IFLA_CARRIER]));
1697 if (err)
1698 goto errout;
90c325e3 1699 status |= DO_SETLINK_MODIFIED;
9a57247f
JP
1700 }
1701
5d1180fc
ND
1702 if (tb[IFLA_TXQLEN]) {
1703 unsigned long value = nla_get_u32(tb[IFLA_TXQLEN]);
1704
1705 if (dev->tx_queue_len ^ value)
ba998906 1706 status |= DO_SETLINK_NOTIFY;
5d1180fc
ND
1707
1708 dev->tx_queue_len = value;
1709 }
b00055aa 1710
da5e0494 1711 if (tb[IFLA_OPERSTATE])
93b2d4a2 1712 set_operstate(dev, nla_get_u8(tb[IFLA_OPERSTATE]));
b00055aa 1713
da5e0494 1714 if (tb[IFLA_LINKMODE]) {
1889b0e7
ND
1715 unsigned char value = nla_get_u8(tb[IFLA_LINKMODE]);
1716
93b2d4a2 1717 write_lock_bh(&dev_base_lock);
1889b0e7 1718 if (dev->link_mode ^ value)
ba998906 1719 status |= DO_SETLINK_NOTIFY;
1889b0e7 1720 dev->link_mode = value;
93b2d4a2 1721 write_unlock_bh(&dev_base_lock);
b00055aa
SR
1722 }
1723
c02db8c6
CW
1724 if (tb[IFLA_VFINFO_LIST]) {
1725 struct nlattr *attr;
1726 int rem;
1727 nla_for_each_nested(attr, tb[IFLA_VFINFO_LIST], rem) {
253683bb
DH
1728 if (nla_type(attr) != IFLA_VF_INFO) {
1729 err = -EINVAL;
c02db8c6 1730 goto errout;
253683bb 1731 }
c02db8c6
CW
1732 err = do_setvfinfo(dev, attr);
1733 if (err < 0)
1734 goto errout;
ba998906 1735 status |= DO_SETLINK_NOTIFY;
c02db8c6 1736 }
ebc08a6f 1737 }
1da177e4
LT
1738 err = 0;
1739
57b61080
SF
1740 if (tb[IFLA_VF_PORTS]) {
1741 struct nlattr *port[IFLA_PORT_MAX+1];
1742 struct nlattr *attr;
1743 int vf;
1744 int rem;
1745
1746 err = -EOPNOTSUPP;
1747 if (!ops->ndo_set_vf_port)
1748 goto errout;
1749
1750 nla_for_each_nested(attr, tb[IFLA_VF_PORTS], rem) {
1751 if (nla_type(attr) != IFLA_VF_PORT)
1752 continue;
1753 err = nla_parse_nested(port, IFLA_PORT_MAX,
1754 attr, ifla_port_policy);
1755 if (err < 0)
1756 goto errout;
1757 if (!port[IFLA_PORT_VF]) {
1758 err = -EOPNOTSUPP;
1759 goto errout;
1760 }
1761 vf = nla_get_u32(port[IFLA_PORT_VF]);
1762 err = ops->ndo_set_vf_port(dev, vf, port);
1763 if (err < 0)
1764 goto errout;
ba998906 1765 status |= DO_SETLINK_NOTIFY;
57b61080
SF
1766 }
1767 }
1768 err = 0;
1769
1770 if (tb[IFLA_PORT_SELF]) {
1771 struct nlattr *port[IFLA_PORT_MAX+1];
1772
1773 err = nla_parse_nested(port, IFLA_PORT_MAX,
1774 tb[IFLA_PORT_SELF], ifla_port_policy);
1775 if (err < 0)
1776 goto errout;
1777
1778 err = -EOPNOTSUPP;
1779 if (ops->ndo_set_vf_port)
1780 err = ops->ndo_set_vf_port(dev, PORT_SELF_VF, port);
1781 if (err < 0)
1782 goto errout;
ba998906 1783 status |= DO_SETLINK_NOTIFY;
57b61080 1784 }
f8ff182c
TG
1785
1786 if (tb[IFLA_AF_SPEC]) {
1787 struct nlattr *af;
1788 int rem;
1789
1790 nla_for_each_nested(af, tb[IFLA_AF_SPEC], rem) {
1791 const struct rtnl_af_ops *af_ops;
1792
1793 if (!(af_ops = rtnl_af_lookup(nla_type(af))))
cf7afbfe 1794 BUG();
f8ff182c 1795
cf7afbfe 1796 err = af_ops->set_link_af(dev, af);
f8ff182c
TG
1797 if (err < 0)
1798 goto errout;
1799
ba998906 1800 status |= DO_SETLINK_NOTIFY;
f8ff182c
TG
1801 }
1802 }
57b61080
SF
1803 err = 0;
1804
0157f60c 1805errout:
ba998906
ND
1806 if (status & DO_SETLINK_MODIFIED) {
1807 if (status & DO_SETLINK_NOTIFY)
1808 netdev_state_change(dev);
1809
1810 if (err < 0)
1811 net_warn_ratelimited("A link change request failed with some changes committed already. Interface %s may have been left with an inconsistent configuration, please check.\n",
1812 dev->name);
1813 }
da5e0494 1814
0157f60c
PM
1815 return err;
1816}
1da177e4 1817
661d2967 1818static int rtnl_setlink(struct sk_buff *skb, struct nlmsghdr *nlh)
0157f60c 1819{
3b1e0a65 1820 struct net *net = sock_net(skb->sk);
0157f60c
PM
1821 struct ifinfomsg *ifm;
1822 struct net_device *dev;
1823 int err;
1824 struct nlattr *tb[IFLA_MAX+1];
1825 char ifname[IFNAMSIZ];
1826
1827 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFLA_MAX, ifla_policy);
1828 if (err < 0)
1829 goto errout;
1830
1831 if (tb[IFLA_IFNAME])
1832 nla_strlcpy(ifname, tb[IFLA_IFNAME], IFNAMSIZ);
1833 else
1834 ifname[0] = '\0';
1835
1836 err = -EINVAL;
1837 ifm = nlmsg_data(nlh);
1838 if (ifm->ifi_index > 0)
a3d12891 1839 dev = __dev_get_by_index(net, ifm->ifi_index);
0157f60c 1840 else if (tb[IFLA_IFNAME])
a3d12891 1841 dev = __dev_get_by_name(net, ifname);
0157f60c
PM
1842 else
1843 goto errout;
1844
1845 if (dev == NULL) {
1846 err = -ENODEV;
1847 goto errout;
1848 }
1849
e0d087af
ED
1850 err = validate_linkmsg(dev, tb);
1851 if (err < 0)
a3d12891 1852 goto errout;
0157f60c 1853
90f62cf3 1854 err = do_setlink(skb, dev, ifm, tb, ifname, 0);
da5e0494 1855errout:
1da177e4
LT
1856 return err;
1857}
1858
66400d54
WC
1859static int rtnl_group_dellink(const struct net *net, int group)
1860{
1861 struct net_device *dev, *aux;
1862 LIST_HEAD(list_kill);
1863 bool found = false;
1864
1865 if (!group)
1866 return -EPERM;
1867
1868 for_each_netdev(net, dev) {
1869 if (dev->group == group) {
1870 const struct rtnl_link_ops *ops;
1871
1872 found = true;
1873 ops = dev->rtnl_link_ops;
1874 if (!ops || !ops->dellink)
1875 return -EOPNOTSUPP;
1876 }
1877 }
1878
1879 if (!found)
1880 return -ENODEV;
1881
1882 for_each_netdev_safe(net, dev, aux) {
1883 if (dev->group == group) {
1884 const struct rtnl_link_ops *ops;
1885
1886 ops = dev->rtnl_link_ops;
1887 ops->dellink(dev, &list_kill);
1888 }
1889 }
1890 unregister_netdevice_many(&list_kill);
1891
1892 return 0;
1893}
1894
661d2967 1895static int rtnl_dellink(struct sk_buff *skb, struct nlmsghdr *nlh)
38f7b870 1896{
3b1e0a65 1897 struct net *net = sock_net(skb->sk);
38f7b870
PM
1898 const struct rtnl_link_ops *ops;
1899 struct net_device *dev;
1900 struct ifinfomsg *ifm;
1901 char ifname[IFNAMSIZ];
1902 struct nlattr *tb[IFLA_MAX+1];
1903 int err;
226bd341 1904 LIST_HEAD(list_kill);
38f7b870
PM
1905
1906 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFLA_MAX, ifla_policy);
1907 if (err < 0)
1908 return err;
1909
1910 if (tb[IFLA_IFNAME])
1911 nla_strlcpy(ifname, tb[IFLA_IFNAME], IFNAMSIZ);
1912
1913 ifm = nlmsg_data(nlh);
1914 if (ifm->ifi_index > 0)
881d966b 1915 dev = __dev_get_by_index(net, ifm->ifi_index);
38f7b870 1916 else if (tb[IFLA_IFNAME])
881d966b 1917 dev = __dev_get_by_name(net, ifname);
66400d54
WC
1918 else if (tb[IFLA_GROUP])
1919 return rtnl_group_dellink(net, nla_get_u32(tb[IFLA_GROUP]));
38f7b870
PM
1920 else
1921 return -EINVAL;
1922
1923 if (!dev)
1924 return -ENODEV;
1925
1926 ops = dev->rtnl_link_ops;
b0ab2fab 1927 if (!ops || !ops->dellink)
38f7b870
PM
1928 return -EOPNOTSUPP;
1929
226bd341
ED
1930 ops->dellink(dev, &list_kill);
1931 unregister_netdevice_many(&list_kill);
38f7b870
PM
1932 return 0;
1933}
1934
3729d502
PM
1935int rtnl_configure_link(struct net_device *dev, const struct ifinfomsg *ifm)
1936{
1937 unsigned int old_flags;
1938 int err;
1939
1940 old_flags = dev->flags;
1941 if (ifm && (ifm->ifi_flags || ifm->ifi_change)) {
1942 err = __dev_change_flags(dev, rtnl_dev_combine_flags(dev, ifm));
1943 if (err < 0)
1944 return err;
1945 }
1946
1947 dev->rtnl_link_state = RTNL_LINK_INITIALIZED;
3729d502 1948
a528c219 1949 __dev_notify_flags(dev, old_flags, ~0U);
3729d502
PM
1950 return 0;
1951}
1952EXPORT_SYMBOL(rtnl_configure_link);
1953
c0713563 1954struct net_device *rtnl_create_link(struct net *net,
78ebb0d0 1955 const char *ifname, unsigned char name_assign_type,
5517750f 1956 const struct rtnl_link_ops *ops, struct nlattr *tb[])
e7199288
PE
1957{
1958 int err;
1959 struct net_device *dev;
d40156aa
JP
1960 unsigned int num_tx_queues = 1;
1961 unsigned int num_rx_queues = 1;
e7199288 1962
76ff5cc9
JP
1963 if (tb[IFLA_NUM_TX_QUEUES])
1964 num_tx_queues = nla_get_u32(tb[IFLA_NUM_TX_QUEUES]);
1965 else if (ops->get_num_tx_queues)
d40156aa 1966 num_tx_queues = ops->get_num_tx_queues();
76ff5cc9
JP
1967
1968 if (tb[IFLA_NUM_RX_QUEUES])
1969 num_rx_queues = nla_get_u32(tb[IFLA_NUM_RX_QUEUES]);
1970 else if (ops->get_num_rx_queues)
d40156aa 1971 num_rx_queues = ops->get_num_rx_queues();
efacb309 1972
e7199288 1973 err = -ENOMEM;
5517750f 1974 dev = alloc_netdev_mqs(ops->priv_size, ifname, name_assign_type,
c835a677 1975 ops->setup, num_tx_queues, num_rx_queues);
e7199288
PE
1976 if (!dev)
1977 goto err;
1978
81adee47
EB
1979 dev_net_set(dev, net);
1980 dev->rtnl_link_ops = ops;
3729d502 1981 dev->rtnl_link_state = RTNL_LINK_INITIALIZING;
81adee47 1982
e7199288
PE
1983 if (tb[IFLA_MTU])
1984 dev->mtu = nla_get_u32(tb[IFLA_MTU]);
2afb9b53 1985 if (tb[IFLA_ADDRESS]) {
e7199288
PE
1986 memcpy(dev->dev_addr, nla_data(tb[IFLA_ADDRESS]),
1987 nla_len(tb[IFLA_ADDRESS]));
2afb9b53
JP
1988 dev->addr_assign_type = NET_ADDR_SET;
1989 }
e7199288
PE
1990 if (tb[IFLA_BROADCAST])
1991 memcpy(dev->broadcast, nla_data(tb[IFLA_BROADCAST]),
1992 nla_len(tb[IFLA_BROADCAST]));
1993 if (tb[IFLA_TXQLEN])
1994 dev->tx_queue_len = nla_get_u32(tb[IFLA_TXQLEN]);
1995 if (tb[IFLA_OPERSTATE])
93b2d4a2 1996 set_operstate(dev, nla_get_u8(tb[IFLA_OPERSTATE]));
e7199288
PE
1997 if (tb[IFLA_LINKMODE])
1998 dev->link_mode = nla_get_u8(tb[IFLA_LINKMODE]);
ffa934f1
PM
1999 if (tb[IFLA_GROUP])
2000 dev_set_group(dev, nla_get_u32(tb[IFLA_GROUP]));
e7199288
PE
2001
2002 return dev;
2003
e7199288
PE
2004err:
2005 return ERR_PTR(err);
2006}
e0d087af 2007EXPORT_SYMBOL(rtnl_create_link);
e7199288 2008
90f62cf3
EB
2009static int rtnl_group_changelink(const struct sk_buff *skb,
2010 struct net *net, int group,
e7ed828f
VD
2011 struct ifinfomsg *ifm,
2012 struct nlattr **tb)
2013{
d079535d 2014 struct net_device *dev, *aux;
e7ed828f
VD
2015 int err;
2016
d079535d 2017 for_each_netdev_safe(net, dev, aux) {
e7ed828f 2018 if (dev->group == group) {
90f62cf3 2019 err = do_setlink(skb, dev, ifm, tb, NULL, 0);
e7ed828f
VD
2020 if (err < 0)
2021 return err;
2022 }
2023 }
2024
2025 return 0;
2026}
2027
661d2967 2028static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh)
38f7b870 2029{
3b1e0a65 2030 struct net *net = sock_net(skb->sk);
38f7b870 2031 const struct rtnl_link_ops *ops;
ba7d49b1 2032 const struct rtnl_link_ops *m_ops = NULL;
38f7b870 2033 struct net_device *dev;
ba7d49b1 2034 struct net_device *master_dev = NULL;
38f7b870
PM
2035 struct ifinfomsg *ifm;
2036 char kind[MODULE_NAME_LEN];
2037 char ifname[IFNAMSIZ];
2038 struct nlattr *tb[IFLA_MAX+1];
2039 struct nlattr *linkinfo[IFLA_INFO_MAX+1];
5517750f 2040 unsigned char name_assign_type = NET_NAME_USER;
38f7b870
PM
2041 int err;
2042
95a5afca 2043#ifdef CONFIG_MODULES
38f7b870 2044replay:
8072f085 2045#endif
38f7b870
PM
2046 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFLA_MAX, ifla_policy);
2047 if (err < 0)
2048 return err;
2049
2050 if (tb[IFLA_IFNAME])
2051 nla_strlcpy(ifname, tb[IFLA_IFNAME], IFNAMSIZ);
2052 else
2053 ifname[0] = '\0';
2054
2055 ifm = nlmsg_data(nlh);
2056 if (ifm->ifi_index > 0)
881d966b 2057 dev = __dev_get_by_index(net, ifm->ifi_index);
e7ed828f
VD
2058 else {
2059 if (ifname[0])
2060 dev = __dev_get_by_name(net, ifname);
e7ed828f
VD
2061 else
2062 dev = NULL;
2063 }
38f7b870 2064
ba7d49b1
JP
2065 if (dev) {
2066 master_dev = netdev_master_upper_dev_get(dev);
2067 if (master_dev)
2068 m_ops = master_dev->rtnl_link_ops;
2069 }
2070
e0d087af
ED
2071 err = validate_linkmsg(dev, tb);
2072 if (err < 0)
1840bb13
TG
2073 return err;
2074
38f7b870
PM
2075 if (tb[IFLA_LINKINFO]) {
2076 err = nla_parse_nested(linkinfo, IFLA_INFO_MAX,
2077 tb[IFLA_LINKINFO], ifla_info_policy);
2078 if (err < 0)
2079 return err;
2080 } else
2081 memset(linkinfo, 0, sizeof(linkinfo));
2082
2083 if (linkinfo[IFLA_INFO_KIND]) {
2084 nla_strlcpy(kind, linkinfo[IFLA_INFO_KIND], sizeof(kind));
2085 ops = rtnl_link_ops_get(kind);
2086 } else {
2087 kind[0] = '\0';
2088 ops = NULL;
2089 }
2090
2091 if (1) {
4e10fd5b
SL
2092 struct nlattr *attr[ops ? ops->maxtype + 1 : 1];
2093 struct nlattr *slave_attr[m_ops ? m_ops->slave_maxtype + 1 : 1];
ba7d49b1
JP
2094 struct nlattr **data = NULL;
2095 struct nlattr **slave_data = NULL;
317f4810 2096 struct net *dest_net, *link_net = NULL;
38f7b870
PM
2097
2098 if (ops) {
2099 if (ops->maxtype && linkinfo[IFLA_INFO_DATA]) {
2100 err = nla_parse_nested(attr, ops->maxtype,
2101 linkinfo[IFLA_INFO_DATA],
2102 ops->policy);
2103 if (err < 0)
2104 return err;
2105 data = attr;
2106 }
2107 if (ops->validate) {
2108 err = ops->validate(tb, data);
2109 if (err < 0)
2110 return err;
2111 }
2112 }
2113
ba7d49b1
JP
2114 if (m_ops) {
2115 if (m_ops->slave_maxtype &&
2116 linkinfo[IFLA_INFO_SLAVE_DATA]) {
2117 err = nla_parse_nested(slave_attr,
2118 m_ops->slave_maxtype,
2119 linkinfo[IFLA_INFO_SLAVE_DATA],
2120 m_ops->slave_policy);
2121 if (err < 0)
2122 return err;
2123 slave_data = slave_attr;
2124 }
2125 if (m_ops->slave_validate) {
2126 err = m_ops->slave_validate(tb, slave_data);
2127 if (err < 0)
2128 return err;
2129 }
2130 }
2131
38f7b870 2132 if (dev) {
90c325e3 2133 int status = 0;
38f7b870
PM
2134
2135 if (nlh->nlmsg_flags & NLM_F_EXCL)
2136 return -EEXIST;
2137 if (nlh->nlmsg_flags & NLM_F_REPLACE)
2138 return -EOPNOTSUPP;
2139
2140 if (linkinfo[IFLA_INFO_DATA]) {
2141 if (!ops || ops != dev->rtnl_link_ops ||
2142 !ops->changelink)
2143 return -EOPNOTSUPP;
2144
2145 err = ops->changelink(dev, tb, data);
2146 if (err < 0)
2147 return err;
ba998906 2148 status |= DO_SETLINK_NOTIFY;
38f7b870
PM
2149 }
2150
ba7d49b1
JP
2151 if (linkinfo[IFLA_INFO_SLAVE_DATA]) {
2152 if (!m_ops || !m_ops->slave_changelink)
2153 return -EOPNOTSUPP;
2154
2155 err = m_ops->slave_changelink(master_dev, dev,
2156 tb, slave_data);
2157 if (err < 0)
2158 return err;
ba998906 2159 status |= DO_SETLINK_NOTIFY;
ba7d49b1
JP
2160 }
2161
90c325e3 2162 return do_setlink(skb, dev, ifm, tb, ifname, status);
38f7b870
PM
2163 }
2164
ffa934f1
PM
2165 if (!(nlh->nlmsg_flags & NLM_F_CREATE)) {
2166 if (ifm->ifi_index == 0 && tb[IFLA_GROUP])
90f62cf3 2167 return rtnl_group_changelink(skb, net,
ffa934f1
PM
2168 nla_get_u32(tb[IFLA_GROUP]),
2169 ifm, tb);
38f7b870 2170 return -ENODEV;
ffa934f1 2171 }
38f7b870 2172
0e06877c 2173 if (tb[IFLA_MAP] || tb[IFLA_MASTER] || tb[IFLA_PROTINFO])
38f7b870
PM
2174 return -EOPNOTSUPP;
2175
2176 if (!ops) {
95a5afca 2177#ifdef CONFIG_MODULES
38f7b870
PM
2178 if (kind[0]) {
2179 __rtnl_unlock();
2180 request_module("rtnl-link-%s", kind);
2181 rtnl_lock();
2182 ops = rtnl_link_ops_get(kind);
2183 if (ops)
2184 goto replay;
2185 }
2186#endif
2187 return -EOPNOTSUPP;
2188 }
2189
b0ab2fab
JP
2190 if (!ops->setup)
2191 return -EOPNOTSUPP;
2192
5517750f 2193 if (!ifname[0]) {
38f7b870 2194 snprintf(ifname, IFNAMSIZ, "%s%%d", ops->kind);
5517750f
TG
2195 name_assign_type = NET_NAME_ENUM;
2196 }
e7199288 2197
81adee47 2198 dest_net = rtnl_link_get_net(net, tb);
13ad1774
EB
2199 if (IS_ERR(dest_net))
2200 return PTR_ERR(dest_net);
2201
505ce415
EB
2202 err = -EPERM;
2203 if (!netlink_ns_capable(skb, dest_net->user_ns, CAP_NET_ADMIN))
2204 goto out;
2205
317f4810
ND
2206 if (tb[IFLA_LINK_NETNSID]) {
2207 int id = nla_get_s32(tb[IFLA_LINK_NETNSID]);
2208
2209 link_net = get_net_ns_by_id(dest_net, id);
2210 if (!link_net) {
2211 err = -EINVAL;
2212 goto out;
2213 }
06615bed
EB
2214 err = -EPERM;
2215 if (!netlink_ns_capable(skb, link_net->user_ns, CAP_NET_ADMIN))
2216 goto out;
317f4810
ND
2217 }
2218
2219 dev = rtnl_create_link(link_net ? : dest_net, ifname,
2220 name_assign_type, ops, tb);
9c7dafbf 2221 if (IS_ERR(dev)) {
e7199288 2222 err = PTR_ERR(dev);
9c7dafbf
PE
2223 goto out;
2224 }
2225
2226 dev->ifindex = ifm->ifi_index;
2227
0e0eee24 2228 if (ops->newlink) {
7b4ce694 2229 err = ops->newlink(link_net ? : net, dev, tb, data);
0e0eee24 2230 /* Drivers should call free_netdev() in ->destructor
e51fb152
CW
2231 * and unregister it on failure after registration
2232 * so that device could be finally freed in rtnl_unlock.
0e0eee24 2233 */
e51fb152
CW
2234 if (err < 0) {
2235 /* If device is not registered at all, free it now */
2236 if (dev->reg_state == NETREG_UNINITIALIZED)
2237 free_netdev(dev);
0e0eee24 2238 goto out;
e51fb152 2239 }
0e0eee24 2240 } else {
2d85cba2 2241 err = register_netdevice(dev);
0e0eee24
CW
2242 if (err < 0) {
2243 free_netdev(dev);
2244 goto out;
2245 }
fce9b9be 2246 }
3729d502 2247 err = rtnl_configure_link(dev, ifm);
43638900
DM
2248 if (err < 0)
2249 goto out_unregister;
bdef279b 2250 if (link_net) {
317f4810 2251 err = dev_change_net_namespace(dev, dest_net, ifname);
bdef279b 2252 if (err < 0)
43638900 2253 goto out_unregister;
bdef279b 2254 }
3729d502 2255out:
317f4810
ND
2256 if (link_net)
2257 put_net(link_net);
81adee47 2258 put_net(dest_net);
38f7b870 2259 return err;
43638900
DM
2260out_unregister:
2261 if (ops->newlink) {
2262 LIST_HEAD(list_kill);
2263
2264 ops->dellink(dev, &list_kill);
2265 unregister_netdevice_many(&list_kill);
2266 } else {
2267 unregister_netdevice(dev);
2268 }
2269 goto out;
38f7b870
PM
2270 }
2271}
2272
661d2967 2273static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr* nlh)
711e2c33 2274{
3b1e0a65 2275 struct net *net = sock_net(skb->sk);
b60c5115 2276 struct ifinfomsg *ifm;
a3d12891 2277 char ifname[IFNAMSIZ];
b60c5115
TG
2278 struct nlattr *tb[IFLA_MAX+1];
2279 struct net_device *dev = NULL;
2280 struct sk_buff *nskb;
339bf98f 2281 int err;
115c9b81 2282 u32 ext_filter_mask = 0;
711e2c33 2283
b60c5115
TG
2284 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFLA_MAX, ifla_policy);
2285 if (err < 0)
9918f230 2286 return err;
b60c5115 2287
a3d12891
ED
2288 if (tb[IFLA_IFNAME])
2289 nla_strlcpy(ifname, tb[IFLA_IFNAME], IFNAMSIZ);
2290
115c9b81
GR
2291 if (tb[IFLA_EXT_MASK])
2292 ext_filter_mask = nla_get_u32(tb[IFLA_EXT_MASK]);
2293
b60c5115 2294 ifm = nlmsg_data(nlh);
a3d12891
ED
2295 if (ifm->ifi_index > 0)
2296 dev = __dev_get_by_index(net, ifm->ifi_index);
2297 else if (tb[IFLA_IFNAME])
2298 dev = __dev_get_by_name(net, ifname);
2299 else
711e2c33 2300 return -EINVAL;
711e2c33 2301
a3d12891
ED
2302 if (dev == NULL)
2303 return -ENODEV;
2304
115c9b81 2305 nskb = nlmsg_new(if_nlmsg_size(dev, ext_filter_mask), GFP_KERNEL);
a3d12891
ED
2306 if (nskb == NULL)
2307 return -ENOBUFS;
b60c5115 2308
15e47304 2309 err = rtnl_fill_ifinfo(nskb, dev, RTM_NEWLINK, NETLINK_CB(skb).portid,
115c9b81 2310 nlh->nlmsg_seq, 0, 0, ext_filter_mask);
26932566
PM
2311 if (err < 0) {
2312 /* -EMSGSIZE implies BUG in if_nlmsg_size */
2313 WARN_ON(err == -EMSGSIZE);
2314 kfree_skb(nskb);
a3d12891 2315 } else
15e47304 2316 err = rtnl_unicast(nskb, net, NETLINK_CB(skb).portid);
711e2c33 2317
b60c5115 2318 return err;
711e2c33 2319}
711e2c33 2320
115c9b81 2321static u16 rtnl_calcit(struct sk_buff *skb, struct nlmsghdr *nlh)
c7ac8679 2322{
115c9b81
GR
2323 struct net *net = sock_net(skb->sk);
2324 struct net_device *dev;
2325 struct nlattr *tb[IFLA_MAX+1];
2326 u32 ext_filter_mask = 0;
2327 u16 min_ifinfo_dump_size = 0;
e5eca6d4
MS
2328 int hdrlen;
2329
2330 /* Same kernel<->userspace interface hack as in rtnl_dump_ifinfo. */
2331 hdrlen = nlmsg_len(nlh) < sizeof(struct ifinfomsg) ?
2332 sizeof(struct rtgenmsg) : sizeof(struct ifinfomsg);
115c9b81 2333
e5eca6d4 2334 if (nlmsg_parse(nlh, hdrlen, tb, IFLA_MAX, ifla_policy) >= 0) {
a4b64fbe
ED
2335 if (tb[IFLA_EXT_MASK])
2336 ext_filter_mask = nla_get_u32(tb[IFLA_EXT_MASK]);
2337 }
115c9b81
GR
2338
2339 if (!ext_filter_mask)
2340 return NLMSG_GOODSIZE;
2341 /*
2342 * traverse the list of net devices and compute the minimum
2343 * buffer size based upon the filter mask.
2344 */
2345 list_for_each_entry(dev, &net->dev_base_head, dev_list) {
2346 min_ifinfo_dump_size = max_t(u16, min_ifinfo_dump_size,
2347 if_nlmsg_size(dev,
2348 ext_filter_mask));
2349 }
2350
c7ac8679
GR
2351 return min_ifinfo_dump_size;
2352}
2353
42bad1da 2354static int rtnl_dump_all(struct sk_buff *skb, struct netlink_callback *cb)
1da177e4
LT
2355{
2356 int idx;
2357 int s_idx = cb->family;
2358
2359 if (s_idx == 0)
2360 s_idx = 1;
25239cee 2361 for (idx = 1; idx <= RTNL_FAMILY_MAX; idx++) {
1da177e4
LT
2362 int type = cb->nlh->nlmsg_type-RTM_BASE;
2363 if (idx < s_idx || idx == PF_PACKET)
2364 continue;
e2849863
TG
2365 if (rtnl_msg_handlers[idx] == NULL ||
2366 rtnl_msg_handlers[idx][type].dumpit == NULL)
1da177e4 2367 continue;
0465277f 2368 if (idx > s_idx) {
1da177e4 2369 memset(&cb->args[0], 0, sizeof(cb->args));
0465277f
ND
2370 cb->prev_seq = 0;
2371 cb->seq = 0;
2372 }
e2849863 2373 if (rtnl_msg_handlers[idx][type].dumpit(skb, cb))
1da177e4
LT
2374 break;
2375 }
2376 cb->family = idx;
2377
2378 return skb->len;
2379}
2380
395eea6c
MB
2381struct sk_buff *rtmsg_ifinfo_build_skb(int type, struct net_device *dev,
2382 unsigned int change, gfp_t flags)
1da177e4 2383{
c346dca1 2384 struct net *net = dev_net(dev);
1da177e4 2385 struct sk_buff *skb;
0ec6d3f4 2386 int err = -ENOBUFS;
c7ac8679 2387 size_t if_info_size;
1da177e4 2388
7f294054 2389 skb = nlmsg_new((if_info_size = if_nlmsg_size(dev, 0)), flags);
0ec6d3f4
TG
2390 if (skb == NULL)
2391 goto errout;
1da177e4 2392
115c9b81 2393 err = rtnl_fill_ifinfo(skb, dev, type, 0, 0, change, 0, 0);
26932566
PM
2394 if (err < 0) {
2395 /* -EMSGSIZE implies BUG in if_nlmsg_size() */
2396 WARN_ON(err == -EMSGSIZE);
2397 kfree_skb(skb);
2398 goto errout;
2399 }
395eea6c 2400 return skb;
0ec6d3f4
TG
2401errout:
2402 if (err < 0)
4b3da706 2403 rtnl_set_sk_err(net, RTNLGRP_LINK, err);
395eea6c
MB
2404 return NULL;
2405}
2406
2407void rtmsg_ifinfo_send(struct sk_buff *skb, struct net_device *dev, gfp_t flags)
2408{
2409 struct net *net = dev_net(dev);
2410
2411 rtnl_notify(skb, net, 0, RTNLGRP_LINK, NULL, flags);
2412}
2413
2414void rtmsg_ifinfo(int type, struct net_device *dev, unsigned int change,
2415 gfp_t flags)
2416{
2417 struct sk_buff *skb;
2418
2419 skb = rtmsg_ifinfo_build_skb(type, dev, change, flags);
2420 if (skb)
2421 rtmsg_ifinfo_send(skb, dev, flags);
1da177e4 2422}
471cb5a3 2423EXPORT_SYMBOL(rtmsg_ifinfo);
1da177e4 2424
d83b0603
JF
2425static int nlmsg_populate_fdb_fill(struct sk_buff *skb,
2426 struct net_device *dev,
1e53d5bb 2427 u8 *addr, u16 vid, u32 pid, u32 seq,
1c104a6b
ND
2428 int type, unsigned int flags,
2429 int nlflags)
d83b0603
JF
2430{
2431 struct nlmsghdr *nlh;
2432 struct ndmsg *ndm;
2433
1c104a6b 2434 nlh = nlmsg_put(skb, pid, seq, type, sizeof(*ndm), nlflags);
d83b0603
JF
2435 if (!nlh)
2436 return -EMSGSIZE;
2437
2438 ndm = nlmsg_data(nlh);
2439 ndm->ndm_family = AF_BRIDGE;
2440 ndm->ndm_pad1 = 0;
2441 ndm->ndm_pad2 = 0;
2442 ndm->ndm_flags = flags;
2443 ndm->ndm_type = 0;
2444 ndm->ndm_ifindex = dev->ifindex;
2445 ndm->ndm_state = NUD_PERMANENT;
2446
2447 if (nla_put(skb, NDA_LLADDR, ETH_ALEN, addr))
2448 goto nla_put_failure;
1e53d5bb
HS
2449 if (vid)
2450 if (nla_put(skb, NDA_VLAN, sizeof(u16), &vid))
2451 goto nla_put_failure;
d83b0603 2452
053c095a
JB
2453 nlmsg_end(skb, nlh);
2454 return 0;
d83b0603
JF
2455
2456nla_put_failure:
2457 nlmsg_cancel(skb, nlh);
2458 return -EMSGSIZE;
2459}
2460
3ff661c3
JF
2461static inline size_t rtnl_fdb_nlmsg_size(void)
2462{
2463 return NLMSG_ALIGN(sizeof(struct ndmsg)) + nla_total_size(ETH_ALEN);
2464}
2465
1e53d5bb 2466static void rtnl_fdb_notify(struct net_device *dev, u8 *addr, u16 vid, int type)
3ff661c3
JF
2467{
2468 struct net *net = dev_net(dev);
2469 struct sk_buff *skb;
2470 int err = -ENOBUFS;
2471
2472 skb = nlmsg_new(rtnl_fdb_nlmsg_size(), GFP_ATOMIC);
2473 if (!skb)
2474 goto errout;
2475
1e53d5bb
HS
2476 err = nlmsg_populate_fdb_fill(skb, dev, addr, vid,
2477 0, 0, type, NTF_SELF, 0);
3ff661c3
JF
2478 if (err < 0) {
2479 kfree_skb(skb);
2480 goto errout;
2481 }
2482
2483 rtnl_notify(skb, net, 0, RTNLGRP_NEIGH, NULL, GFP_ATOMIC);
2484 return;
2485errout:
2486 rtnl_set_sk_err(net, RTNLGRP_NEIGH, err);
2487}
2488
090096bf
VY
2489/**
2490 * ndo_dflt_fdb_add - default netdevice operation to add an FDB entry
2491 */
2492int ndo_dflt_fdb_add(struct ndmsg *ndm,
2493 struct nlattr *tb[],
2494 struct net_device *dev,
f6f6424b 2495 const unsigned char *addr, u16 vid,
090096bf
VY
2496 u16 flags)
2497{
2498 int err = -EINVAL;
2499
2500 /* If aging addresses are supported device will need to
2501 * implement its own handler for this.
2502 */
2503 if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
2504 pr_info("%s: FDB only supports static addresses\n", dev->name);
2505 return err;
2506 }
2507
65891fea
OG
2508 if (vid) {
2509 pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev->name);
2510 return err;
2511 }
2512
090096bf
VY
2513 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
2514 err = dev_uc_add_excl(dev, addr);
2515 else if (is_multicast_ether_addr(addr))
2516 err = dev_mc_add_excl(dev, addr);
2517
2518 /* Only return duplicate errors if NLM_F_EXCL is set */
2519 if (err == -EEXIST && !(flags & NLM_F_EXCL))
2520 err = 0;
2521
2522 return err;
2523}
2524EXPORT_SYMBOL(ndo_dflt_fdb_add);
2525
f6f6424b
JP
2526static int fdb_vid_parse(struct nlattr *vlan_attr, u16 *p_vid)
2527{
2528 u16 vid = 0;
2529
2530 if (vlan_attr) {
2531 if (nla_len(vlan_attr) != sizeof(u16)) {
2532 pr_info("PF_BRIDGE: RTM_NEWNEIGH with invalid vlan\n");
2533 return -EINVAL;
2534 }
2535
2536 vid = nla_get_u16(vlan_attr);
2537
2538 if (!vid || vid >= VLAN_VID_MASK) {
2539 pr_info("PF_BRIDGE: RTM_NEWNEIGH with invalid vlan id %d\n",
2540 vid);
2541 return -EINVAL;
2542 }
2543 }
2544 *p_vid = vid;
2545 return 0;
2546}
2547
661d2967 2548static int rtnl_fdb_add(struct sk_buff *skb, struct nlmsghdr *nlh)
77162022
JF
2549{
2550 struct net *net = sock_net(skb->sk);
77162022
JF
2551 struct ndmsg *ndm;
2552 struct nlattr *tb[NDA_MAX+1];
2553 struct net_device *dev;
2554 u8 *addr;
f6f6424b 2555 u16 vid;
77162022
JF
2556 int err;
2557
2558 err = nlmsg_parse(nlh, sizeof(*ndm), tb, NDA_MAX, NULL);
2559 if (err < 0)
2560 return err;
2561
2562 ndm = nlmsg_data(nlh);
2563 if (ndm->ndm_ifindex == 0) {
2564 pr_info("PF_BRIDGE: RTM_NEWNEIGH with invalid ifindex\n");
2565 return -EINVAL;
2566 }
2567
2568 dev = __dev_get_by_index(net, ndm->ndm_ifindex);
2569 if (dev == NULL) {
2570 pr_info("PF_BRIDGE: RTM_NEWNEIGH with unknown ifindex\n");
2571 return -ENODEV;
2572 }
2573
2574 if (!tb[NDA_LLADDR] || nla_len(tb[NDA_LLADDR]) != ETH_ALEN) {
2575 pr_info("PF_BRIDGE: RTM_NEWNEIGH with invalid address\n");
2576 return -EINVAL;
2577 }
2578
2579 addr = nla_data(tb[NDA_LLADDR]);
77162022 2580
f6f6424b
JP
2581 err = fdb_vid_parse(tb[NDA_VLAN], &vid);
2582 if (err)
2583 return err;
2584
77162022
JF
2585 err = -EOPNOTSUPP;
2586
2587 /* Support fdb on master device the net/bridge default case */
2588 if ((!ndm->ndm_flags || ndm->ndm_flags & NTF_MASTER) &&
2589 (dev->priv_flags & IFF_BRIDGE_PORT)) {
898e5061
JP
2590 struct net_device *br_dev = netdev_master_upper_dev_get(dev);
2591 const struct net_device_ops *ops = br_dev->netdev_ops;
2592
f6f6424b
JP
2593 err = ops->ndo_fdb_add(ndm, tb, dev, addr, vid,
2594 nlh->nlmsg_flags);
77162022
JF
2595 if (err)
2596 goto out;
2597 else
2598 ndm->ndm_flags &= ~NTF_MASTER;
2599 }
2600
2601 /* Embedded bridge, macvlan, and any other device support */
090096bf
VY
2602 if ((ndm->ndm_flags & NTF_SELF)) {
2603 if (dev->netdev_ops->ndo_fdb_add)
2604 err = dev->netdev_ops->ndo_fdb_add(ndm, tb, dev, addr,
f6f6424b 2605 vid,
090096bf
VY
2606 nlh->nlmsg_flags);
2607 else
f6f6424b 2608 err = ndo_dflt_fdb_add(ndm, tb, dev, addr, vid,
090096bf 2609 nlh->nlmsg_flags);
77162022 2610
3ff661c3 2611 if (!err) {
1e53d5bb 2612 rtnl_fdb_notify(dev, addr, vid, RTM_NEWNEIGH);
77162022 2613 ndm->ndm_flags &= ~NTF_SELF;
3ff661c3 2614 }
77162022
JF
2615 }
2616out:
2617 return err;
2618}
2619
090096bf
VY
2620/**
2621 * ndo_dflt_fdb_del - default netdevice operation to delete an FDB entry
2622 */
2623int ndo_dflt_fdb_del(struct ndmsg *ndm,
2624 struct nlattr *tb[],
2625 struct net_device *dev,
f6f6424b 2626 const unsigned char *addr, u16 vid)
090096bf 2627{
c8a89c4a 2628 int err = -EINVAL;
090096bf
VY
2629
2630 /* If aging addresses are supported device will need to
2631 * implement its own handler for this.
2632 */
64535993 2633 if (!(ndm->ndm_state & NUD_PERMANENT)) {
090096bf 2634 pr_info("%s: FDB only supports static addresses\n", dev->name);
c8a89c4a 2635 return err;
090096bf
VY
2636 }
2637
2638 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
2639 err = dev_uc_del(dev, addr);
2640 else if (is_multicast_ether_addr(addr))
2641 err = dev_mc_del(dev, addr);
090096bf
VY
2642
2643 return err;
2644}
2645EXPORT_SYMBOL(ndo_dflt_fdb_del);
2646
661d2967 2647static int rtnl_fdb_del(struct sk_buff *skb, struct nlmsghdr *nlh)
77162022
JF
2648{
2649 struct net *net = sock_net(skb->sk);
2650 struct ndmsg *ndm;
1690be63 2651 struct nlattr *tb[NDA_MAX+1];
77162022
JF
2652 struct net_device *dev;
2653 int err = -EINVAL;
2654 __u8 *addr;
f6f6424b 2655 u16 vid;
77162022 2656
90f62cf3 2657 if (!netlink_capable(skb, CAP_NET_ADMIN))
1690be63
VY
2658 return -EPERM;
2659
2660 err = nlmsg_parse(nlh, sizeof(*ndm), tb, NDA_MAX, NULL);
2661 if (err < 0)
2662 return err;
77162022
JF
2663
2664 ndm = nlmsg_data(nlh);
2665 if (ndm->ndm_ifindex == 0) {
2666 pr_info("PF_BRIDGE: RTM_DELNEIGH with invalid ifindex\n");
2667 return -EINVAL;
2668 }
2669
2670 dev = __dev_get_by_index(net, ndm->ndm_ifindex);
2671 if (dev == NULL) {
2672 pr_info("PF_BRIDGE: RTM_DELNEIGH with unknown ifindex\n");
2673 return -ENODEV;
2674 }
2675
1690be63
VY
2676 if (!tb[NDA_LLADDR] || nla_len(tb[NDA_LLADDR]) != ETH_ALEN) {
2677 pr_info("PF_BRIDGE: RTM_DELNEIGH with invalid address\n");
2678 return -EINVAL;
2679 }
2680
2681 addr = nla_data(tb[NDA_LLADDR]);
77162022 2682
f6f6424b
JP
2683 err = fdb_vid_parse(tb[NDA_VLAN], &vid);
2684 if (err)
2685 return err;
2686
77162022
JF
2687 err = -EOPNOTSUPP;
2688
2689 /* Support fdb on master device the net/bridge default case */
2690 if ((!ndm->ndm_flags || ndm->ndm_flags & NTF_MASTER) &&
2691 (dev->priv_flags & IFF_BRIDGE_PORT)) {
898e5061
JP
2692 struct net_device *br_dev = netdev_master_upper_dev_get(dev);
2693 const struct net_device_ops *ops = br_dev->netdev_ops;
77162022 2694
898e5061 2695 if (ops->ndo_fdb_del)
f6f6424b 2696 err = ops->ndo_fdb_del(ndm, tb, dev, addr, vid);
77162022
JF
2697
2698 if (err)
2699 goto out;
2700 else
2701 ndm->ndm_flags &= ~NTF_MASTER;
2702 }
2703
2704 /* Embedded bridge, macvlan, and any other device support */
090096bf
VY
2705 if (ndm->ndm_flags & NTF_SELF) {
2706 if (dev->netdev_ops->ndo_fdb_del)
f6f6424b
JP
2707 err = dev->netdev_ops->ndo_fdb_del(ndm, tb, dev, addr,
2708 vid);
090096bf 2709 else
f6f6424b 2710 err = ndo_dflt_fdb_del(ndm, tb, dev, addr, vid);
77162022 2711
3ff661c3 2712 if (!err) {
1e53d5bb 2713 rtnl_fdb_notify(dev, addr, vid, RTM_DELNEIGH);
77162022 2714 ndm->ndm_flags &= ~NTF_SELF;
3ff661c3 2715 }
77162022
JF
2716 }
2717out:
2718 return err;
2719}
2720
d83b0603
JF
2721static int nlmsg_populate_fdb(struct sk_buff *skb,
2722 struct netlink_callback *cb,
2723 struct net_device *dev,
2724 int *idx,
2725 struct netdev_hw_addr_list *list)
2726{
2727 struct netdev_hw_addr *ha;
2728 int err;
15e47304 2729 u32 portid, seq;
d83b0603 2730
15e47304 2731 portid = NETLINK_CB(cb->skb).portid;
d83b0603
JF
2732 seq = cb->nlh->nlmsg_seq;
2733
2734 list_for_each_entry(ha, &list->list, list) {
2735 if (*idx < cb->args[0])
2736 goto skip;
2737
1e53d5bb 2738 err = nlmsg_populate_fdb_fill(skb, dev, ha->addr, 0,
a7a558fe 2739 portid, seq,
1c104a6b
ND
2740 RTM_NEWNEIGH, NTF_SELF,
2741 NLM_F_MULTI);
d83b0603
JF
2742 if (err < 0)
2743 return err;
2744skip:
2745 *idx += 1;
2746 }
2747 return 0;
2748}
2749
2750/**
2c53040f 2751 * ndo_dflt_fdb_dump - default netdevice operation to dump an FDB table.
d83b0603
JF
2752 * @nlh: netlink message header
2753 * @dev: netdevice
2754 *
2755 * Default netdevice operation to dump the existing unicast address list.
91f3e7b1 2756 * Returns number of addresses from list put in skb.
d83b0603
JF
2757 */
2758int ndo_dflt_fdb_dump(struct sk_buff *skb,
2759 struct netlink_callback *cb,
2760 struct net_device *dev,
5d5eacb3 2761 struct net_device *filter_dev,
d83b0603
JF
2762 int idx)
2763{
2764 int err;
2765
2766 netif_addr_lock_bh(dev);
2767 err = nlmsg_populate_fdb(skb, cb, dev, &idx, &dev->uc);
2768 if (err)
2769 goto out;
2770 nlmsg_populate_fdb(skb, cb, dev, &idx, &dev->mc);
2771out:
2772 netif_addr_unlock_bh(dev);
2773 return idx;
2774}
2775EXPORT_SYMBOL(ndo_dflt_fdb_dump);
2776
77162022
JF
2777static int rtnl_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb)
2778{
77162022 2779 struct net_device *dev;
5e6d2435 2780 struct nlattr *tb[IFLA_MAX+1];
5e6d2435
JHS
2781 struct net_device *br_dev = NULL;
2782 const struct net_device_ops *ops = NULL;
2783 const struct net_device_ops *cops = NULL;
2784 struct ifinfomsg *ifm = nlmsg_data(cb->nlh);
2785 struct net *net = sock_net(skb->sk);
2786 int brport_idx = 0;
2787 int br_idx = 0;
2788 int idx = 0;
2789
2790 if (nlmsg_parse(cb->nlh, sizeof(struct ifinfomsg), tb, IFLA_MAX,
2791 ifla_policy) == 0) {
2792 if (tb[IFLA_MASTER])
2793 br_idx = nla_get_u32(tb[IFLA_MASTER]);
2794 }
2795
2796 brport_idx = ifm->ifi_index;
2797
2798 if (br_idx) {
2799 br_dev = __dev_get_by_index(net, br_idx);
2800 if (!br_dev)
2801 return -ENODEV;
2802
2803 ops = br_dev->netdev_ops;
5e6d2435
JHS
2804 }
2805
2806 for_each_netdev(net, dev) {
2807 if (brport_idx && (dev->ifindex != brport_idx))
2808 continue;
2809
2810 if (!br_idx) { /* user did not specify a specific bridge */
2811 if (dev->priv_flags & IFF_BRIDGE_PORT) {
2812 br_dev = netdev_master_upper_dev_get(dev);
2813 cops = br_dev->netdev_ops;
2814 }
2815
5e6d2435
JHS
2816 } else {
2817 if (dev != br_dev &&
2818 !(dev->priv_flags & IFF_BRIDGE_PORT))
2819 continue;
2820
2821 if (br_dev != netdev_master_upper_dev_get(dev) &&
2822 !(dev->priv_flags & IFF_EBRIDGE))
2823 continue;
2824
5e6d2435
JHS
2825 cops = ops;
2826 }
77162022 2827
77162022 2828 if (dev->priv_flags & IFF_BRIDGE_PORT) {
5e6d2435
JHS
2829 if (cops && cops->ndo_fdb_dump)
2830 idx = cops->ndo_fdb_dump(skb, cb, br_dev, dev,
2831 idx);
77162022
JF
2832 }
2833
2834 if (dev->netdev_ops->ndo_fdb_dump)
6cb69742 2835 idx = dev->netdev_ops->ndo_fdb_dump(skb, cb, dev, NULL,
5d5eacb3 2836 idx);
6cb69742
HS
2837 else
2838 idx = ndo_dflt_fdb_dump(skb, cb, dev, NULL, idx);
5e6d2435
JHS
2839
2840 cops = NULL;
77162022 2841 }
77162022
JF
2842
2843 cb->args[0] = idx;
2844 return skb->len;
2845}
2846
2c3c031c
SF
2847static int brport_nla_put_flag(struct sk_buff *skb, u32 flags, u32 mask,
2848 unsigned int attrnum, unsigned int flag)
2849{
2850 if (mask & flag)
2851 return nla_put_u8(skb, attrnum, !!(flags & flag));
2852 return 0;
2853}
2854
815cccbf 2855int ndo_dflt_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
2c3c031c
SF
2856 struct net_device *dev, u16 mode,
2857 u32 flags, u32 mask)
815cccbf
JF
2858{
2859 struct nlmsghdr *nlh;
2860 struct ifinfomsg *ifm;
2861 struct nlattr *br_afspec;
2c3c031c 2862 struct nlattr *protinfo;
815cccbf 2863 u8 operstate = netif_running(dev) ? dev->operstate : IF_OPER_DOWN;
898e5061 2864 struct net_device *br_dev = netdev_master_upper_dev_get(dev);
815cccbf
JF
2865
2866 nlh = nlmsg_put(skb, pid, seq, RTM_NEWLINK, sizeof(*ifm), NLM_F_MULTI);
2867 if (nlh == NULL)
2868 return -EMSGSIZE;
2869
2870 ifm = nlmsg_data(nlh);
2871 ifm->ifi_family = AF_BRIDGE;
2872 ifm->__ifi_pad = 0;
2873 ifm->ifi_type = dev->type;
2874 ifm->ifi_index = dev->ifindex;
2875 ifm->ifi_flags = dev_get_flags(dev);
2876 ifm->ifi_change = 0;
2877
2878
2879 if (nla_put_string(skb, IFLA_IFNAME, dev->name) ||
2880 nla_put_u32(skb, IFLA_MTU, dev->mtu) ||
2881 nla_put_u8(skb, IFLA_OPERSTATE, operstate) ||
898e5061
JP
2882 (br_dev &&
2883 nla_put_u32(skb, IFLA_MASTER, br_dev->ifindex)) ||
815cccbf
JF
2884 (dev->addr_len &&
2885 nla_put(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr)) ||
a54acb3a
ND
2886 (dev->ifindex != dev_get_iflink(dev) &&
2887 nla_put_u32(skb, IFLA_LINK, dev_get_iflink(dev))))
815cccbf
JF
2888 goto nla_put_failure;
2889
2890 br_afspec = nla_nest_start(skb, IFLA_AF_SPEC);
2891 if (!br_afspec)
2892 goto nla_put_failure;
2893
1d460b98 2894 if (nla_put_u16(skb, IFLA_BRIDGE_FLAGS, BRIDGE_FLAGS_SELF)) {
815cccbf
JF
2895 nla_nest_cancel(skb, br_afspec);
2896 goto nla_put_failure;
2897 }
1d460b98
RP
2898
2899 if (mode != BRIDGE_MODE_UNDEF) {
2900 if (nla_put_u16(skb, IFLA_BRIDGE_MODE, mode)) {
2901 nla_nest_cancel(skb, br_afspec);
2902 goto nla_put_failure;
2903 }
2904 }
815cccbf
JF
2905 nla_nest_end(skb, br_afspec);
2906
2c3c031c
SF
2907 protinfo = nla_nest_start(skb, IFLA_PROTINFO | NLA_F_NESTED);
2908 if (!protinfo)
2909 goto nla_put_failure;
2910
2911 if (brport_nla_put_flag(skb, flags, mask,
2912 IFLA_BRPORT_MODE, BR_HAIRPIN_MODE) ||
2913 brport_nla_put_flag(skb, flags, mask,
2914 IFLA_BRPORT_GUARD, BR_BPDU_GUARD) ||
2915 brport_nla_put_flag(skb, flags, mask,
2916 IFLA_BRPORT_FAST_LEAVE,
2917 BR_MULTICAST_FAST_LEAVE) ||
2918 brport_nla_put_flag(skb, flags, mask,
2919 IFLA_BRPORT_PROTECT, BR_ROOT_BLOCK) ||
2920 brport_nla_put_flag(skb, flags, mask,
2921 IFLA_BRPORT_LEARNING, BR_LEARNING) ||
2922 brport_nla_put_flag(skb, flags, mask,
2923 IFLA_BRPORT_LEARNING_SYNC, BR_LEARNING_SYNC) ||
2924 brport_nla_put_flag(skb, flags, mask,
2925 IFLA_BRPORT_UNICAST_FLOOD, BR_FLOOD) ||
2926 brport_nla_put_flag(skb, flags, mask,
2927 IFLA_BRPORT_PROXYARP, BR_PROXYARP)) {
2928 nla_nest_cancel(skb, protinfo);
2929 goto nla_put_failure;
2930 }
2931
2932 nla_nest_end(skb, protinfo);
2933
053c095a
JB
2934 nlmsg_end(skb, nlh);
2935 return 0;
815cccbf
JF
2936nla_put_failure:
2937 nlmsg_cancel(skb, nlh);
2938 return -EMSGSIZE;
2939}
2940EXPORT_SYMBOL(ndo_dflt_bridge_getlink);
2941
e5a55a89
JF
2942static int rtnl_bridge_getlink(struct sk_buff *skb, struct netlink_callback *cb)
2943{
2944 struct net *net = sock_net(skb->sk);
2945 struct net_device *dev;
2946 int idx = 0;
2947 u32 portid = NETLINK_CB(cb->skb).portid;
2948 u32 seq = cb->nlh->nlmsg_seq;
6cbdceeb
VY
2949 u32 filter_mask = 0;
2950
aa68c20f
TG
2951 if (nlmsg_len(cb->nlh) > sizeof(struct ifinfomsg)) {
2952 struct nlattr *extfilt;
2953
2954 extfilt = nlmsg_find_attr(cb->nlh, sizeof(struct ifinfomsg),
2955 IFLA_EXT_MASK);
2956 if (extfilt) {
2957 if (nla_len(extfilt) < sizeof(filter_mask))
2958 return -EINVAL;
2959
2960 filter_mask = nla_get_u32(extfilt);
2961 }
2962 }
e5a55a89
JF
2963
2964 rcu_read_lock();
2965 for_each_netdev_rcu(net, dev) {
2966 const struct net_device_ops *ops = dev->netdev_ops;
898e5061 2967 struct net_device *br_dev = netdev_master_upper_dev_get(dev);
e5a55a89 2968
898e5061 2969 if (br_dev && br_dev->netdev_ops->ndo_bridge_getlink) {
25b1e679 2970 if (idx >= cb->args[0] &&
898e5061 2971 br_dev->netdev_ops->ndo_bridge_getlink(
6cbdceeb 2972 skb, portid, seq, dev, filter_mask) < 0)
e5a55a89 2973 break;
25b1e679 2974 idx++;
e5a55a89
JF
2975 }
2976
2977 if (ops->ndo_bridge_getlink) {
25b1e679 2978 if (idx >= cb->args[0] &&
6cbdceeb
VY
2979 ops->ndo_bridge_getlink(skb, portid, seq, dev,
2980 filter_mask) < 0)
e5a55a89 2981 break;
25b1e679 2982 idx++;
e5a55a89
JF
2983 }
2984 }
2985 rcu_read_unlock();
2986 cb->args[0] = idx;
2987
2988 return skb->len;
2989}
2990
2469ffd7
JF
2991static inline size_t bridge_nlmsg_size(void)
2992{
2993 return NLMSG_ALIGN(sizeof(struct ifinfomsg))
2994 + nla_total_size(IFNAMSIZ) /* IFLA_IFNAME */
2995 + nla_total_size(MAX_ADDR_LEN) /* IFLA_ADDRESS */
2996 + nla_total_size(sizeof(u32)) /* IFLA_MASTER */
2997 + nla_total_size(sizeof(u32)) /* IFLA_MTU */
2998 + nla_total_size(sizeof(u32)) /* IFLA_LINK */
2999 + nla_total_size(sizeof(u32)) /* IFLA_OPERSTATE */
3000 + nla_total_size(sizeof(u8)) /* IFLA_PROTINFO */
3001 + nla_total_size(sizeof(struct nlattr)) /* IFLA_AF_SPEC */
3002 + nla_total_size(sizeof(u16)) /* IFLA_BRIDGE_FLAGS */
3003 + nla_total_size(sizeof(u16)); /* IFLA_BRIDGE_MODE */
3004}
3005
02dba438 3006static int rtnl_bridge_notify(struct net_device *dev)
2469ffd7
JF
3007{
3008 struct net *net = dev_net(dev);
2469ffd7
JF
3009 struct sk_buff *skb;
3010 int err = -EOPNOTSUPP;
3011
02dba438
RP
3012 if (!dev->netdev_ops->ndo_bridge_getlink)
3013 return 0;
3014
2469ffd7
JF
3015 skb = nlmsg_new(bridge_nlmsg_size(), GFP_ATOMIC);
3016 if (!skb) {
3017 err = -ENOMEM;
3018 goto errout;
3019 }
3020
02dba438
RP
3021 err = dev->netdev_ops->ndo_bridge_getlink(skb, 0, 0, dev, 0);
3022 if (err < 0)
3023 goto errout;
2469ffd7 3024
59ccaaaa
RP
3025 if (!skb->len)
3026 goto errout;
3027
2469ffd7
JF
3028 rtnl_notify(skb, net, 0, RTNLGRP_LINK, NULL, GFP_ATOMIC);
3029 return 0;
3030errout:
3031 WARN_ON(err == -EMSGSIZE);
3032 kfree_skb(skb);
59ccaaaa
RP
3033 if (err)
3034 rtnl_set_sk_err(net, RTNLGRP_LINK, err);
2469ffd7
JF
3035 return err;
3036}
3037
661d2967 3038static int rtnl_bridge_setlink(struct sk_buff *skb, struct nlmsghdr *nlh)
e5a55a89
JF
3039{
3040 struct net *net = sock_net(skb->sk);
3041 struct ifinfomsg *ifm;
3042 struct net_device *dev;
2469ffd7
JF
3043 struct nlattr *br_spec, *attr = NULL;
3044 int rem, err = -EOPNOTSUPP;
4de8b413 3045 u16 flags = 0;
c38e01b8 3046 bool have_flags = false;
e5a55a89
JF
3047
3048 if (nlmsg_len(nlh) < sizeof(*ifm))
3049 return -EINVAL;
3050
3051 ifm = nlmsg_data(nlh);
3052 if (ifm->ifi_family != AF_BRIDGE)
3053 return -EPFNOSUPPORT;
3054
3055 dev = __dev_get_by_index(net, ifm->ifi_index);
3056 if (!dev) {
3057 pr_info("PF_BRIDGE: RTM_SETLINK with unknown ifindex\n");
3058 return -ENODEV;
3059 }
3060
2469ffd7
JF
3061 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
3062 if (br_spec) {
3063 nla_for_each_nested(attr, br_spec, rem) {
3064 if (nla_type(attr) == IFLA_BRIDGE_FLAGS) {
6e8d1c55
TG
3065 if (nla_len(attr) < sizeof(flags))
3066 return -EINVAL;
3067
c38e01b8 3068 have_flags = true;
2469ffd7
JF
3069 flags = nla_get_u16(attr);
3070 break;
3071 }
3072 }
3073 }
3074
3075 if (!flags || (flags & BRIDGE_FLAGS_MASTER)) {
898e5061
JP
3076 struct net_device *br_dev = netdev_master_upper_dev_get(dev);
3077
3078 if (!br_dev || !br_dev->netdev_ops->ndo_bridge_setlink) {
2469ffd7
JF
3079 err = -EOPNOTSUPP;
3080 goto out;
3081 }
3082
add511b3 3083 err = br_dev->netdev_ops->ndo_bridge_setlink(dev, nlh, flags);
e5a55a89
JF
3084 if (err)
3085 goto out;
2469ffd7
JF
3086
3087 flags &= ~BRIDGE_FLAGS_MASTER;
e5a55a89
JF
3088 }
3089
2469ffd7
JF
3090 if ((flags & BRIDGE_FLAGS_SELF)) {
3091 if (!dev->netdev_ops->ndo_bridge_setlink)
3092 err = -EOPNOTSUPP;
3093 else
add511b3
RP
3094 err = dev->netdev_ops->ndo_bridge_setlink(dev, nlh,
3095 flags);
02dba438 3096 if (!err) {
2469ffd7 3097 flags &= ~BRIDGE_FLAGS_SELF;
02dba438
RP
3098
3099 /* Generate event to notify upper layer of bridge
3100 * change
3101 */
3102 err = rtnl_bridge_notify(dev);
3103 }
2469ffd7 3104 }
e5a55a89 3105
c38e01b8 3106 if (have_flags)
2469ffd7 3107 memcpy(nla_data(attr), &flags, sizeof(flags));
e5a55a89
JF
3108out:
3109 return err;
3110}
3111
661d2967 3112static int rtnl_bridge_dellink(struct sk_buff *skb, struct nlmsghdr *nlh)
407af329
VY
3113{
3114 struct net *net = sock_net(skb->sk);
3115 struct ifinfomsg *ifm;
3116 struct net_device *dev;
3117 struct nlattr *br_spec, *attr = NULL;
3118 int rem, err = -EOPNOTSUPP;
4de8b413 3119 u16 flags = 0;
407af329
VY
3120 bool have_flags = false;
3121
3122 if (nlmsg_len(nlh) < sizeof(*ifm))
3123 return -EINVAL;
3124
3125 ifm = nlmsg_data(nlh);
3126 if (ifm->ifi_family != AF_BRIDGE)
3127 return -EPFNOSUPPORT;
3128
3129 dev = __dev_get_by_index(net, ifm->ifi_index);
3130 if (!dev) {
3131 pr_info("PF_BRIDGE: RTM_SETLINK with unknown ifindex\n");
3132 return -ENODEV;
3133 }
3134
3135 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
3136 if (br_spec) {
3137 nla_for_each_nested(attr, br_spec, rem) {
3138 if (nla_type(attr) == IFLA_BRIDGE_FLAGS) {
6e8d1c55
TG
3139 if (nla_len(attr) < sizeof(flags))
3140 return -EINVAL;
3141
407af329
VY
3142 have_flags = true;
3143 flags = nla_get_u16(attr);
3144 break;
3145 }
3146 }
3147 }
3148
407af329
VY
3149 if (!flags || (flags & BRIDGE_FLAGS_MASTER)) {
3150 struct net_device *br_dev = netdev_master_upper_dev_get(dev);
3151
3152 if (!br_dev || !br_dev->netdev_ops->ndo_bridge_dellink) {
3153 err = -EOPNOTSUPP;
3154 goto out;
3155 }
3156
add511b3 3157 err = br_dev->netdev_ops->ndo_bridge_dellink(dev, nlh, flags);
407af329
VY
3158 if (err)
3159 goto out;
3160
3161 flags &= ~BRIDGE_FLAGS_MASTER;
3162 }
3163
3164 if ((flags & BRIDGE_FLAGS_SELF)) {
3165 if (!dev->netdev_ops->ndo_bridge_dellink)
3166 err = -EOPNOTSUPP;
3167 else
add511b3
RP
3168 err = dev->netdev_ops->ndo_bridge_dellink(dev, nlh,
3169 flags);
407af329 3170
02dba438 3171 if (!err) {
407af329 3172 flags &= ~BRIDGE_FLAGS_SELF;
02dba438
RP
3173
3174 /* Generate event to notify upper layer of bridge
3175 * change
3176 */
3177 err = rtnl_bridge_notify(dev);
3178 }
407af329
VY
3179 }
3180
3181 if (have_flags)
3182 memcpy(nla_data(attr), &flags, sizeof(flags));
407af329
VY
3183out:
3184 return err;
3185}
3186
1da177e4
LT
3187/* Process one rtnetlink message. */
3188
1d00a4eb 3189static int rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
1da177e4 3190{
3b1e0a65 3191 struct net *net = sock_net(skb->sk);
e2849863 3192 rtnl_doit_func doit;
1da177e4 3193 int sz_idx, kind;
1da177e4
LT
3194 int family;
3195 int type;
2907c35f 3196 int err;
1da177e4 3197
1da177e4 3198 type = nlh->nlmsg_type;
1da177e4 3199 if (type > RTM_MAX)
038890fe 3200 return -EOPNOTSUPP;
1da177e4
LT
3201
3202 type -= RTM_BASE;
3203
3204 /* All the messages must have at least 1 byte length */
573ce260 3205 if (nlmsg_len(nlh) < sizeof(struct rtgenmsg))
1da177e4
LT
3206 return 0;
3207
573ce260 3208 family = ((struct rtgenmsg *)nlmsg_data(nlh))->rtgen_family;
1da177e4
LT
3209 sz_idx = type>>2;
3210 kind = type&3;
3211
90f62cf3 3212 if (kind != 2 && !netlink_net_capable(skb, CAP_NET_ADMIN))
1d00a4eb 3213 return -EPERM;
1da177e4 3214
b8f3ab42 3215 if (kind == 2 && nlh->nlmsg_flags&NLM_F_DUMP) {
97c53cac 3216 struct sock *rtnl;
e2849863 3217 rtnl_dumpit_func dumpit;
c7ac8679
GR
3218 rtnl_calcit_func calcit;
3219 u16 min_dump_alloc = 0;
1da177e4 3220
e2849863
TG
3221 dumpit = rtnl_get_dumpit(family, type);
3222 if (dumpit == NULL)
038890fe 3223 return -EOPNOTSUPP;
c7ac8679
GR
3224 calcit = rtnl_get_calcit(family, type);
3225 if (calcit)
115c9b81 3226 min_dump_alloc = calcit(skb, nlh);
9ac4a169 3227
2907c35f 3228 __rtnl_unlock();
97c53cac 3229 rtnl = net->rtnl;
80d326fa
PNA
3230 {
3231 struct netlink_dump_control c = {
3232 .dump = dumpit,
3233 .min_dump_alloc = min_dump_alloc,
3234 };
3235 err = netlink_dump_start(rtnl, skb, nlh, &c);
3236 }
2907c35f
ED
3237 rtnl_lock();
3238 return err;
1da177e4
LT
3239 }
3240
e2849863
TG
3241 doit = rtnl_get_doit(family, type);
3242 if (doit == NULL)
038890fe 3243 return -EOPNOTSUPP;
1da177e4 3244
661d2967 3245 return doit(skb, nlh);
1da177e4
LT
3246}
3247
cd40b7d3 3248static void rtnetlink_rcv(struct sk_buff *skb)
1da177e4 3249{
cd40b7d3
DL
3250 rtnl_lock();
3251 netlink_rcv_skb(skb, &rtnetlink_rcv_msg);
3252 rtnl_unlock();
1da177e4
LT
3253}
3254
1da177e4
LT
3255static int rtnetlink_event(struct notifier_block *this, unsigned long event, void *ptr)
3256{
351638e7 3257 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
e9dc8653 3258
1da177e4 3259 switch (event) {
1da177e4
LT
3260 case NETDEV_UP:
3261 case NETDEV_DOWN:
10de05af 3262 case NETDEV_PRE_UP:
d90a909e
EB
3263 case NETDEV_POST_INIT:
3264 case NETDEV_REGISTER:
1da177e4 3265 case NETDEV_CHANGE:
755d0e77 3266 case NETDEV_PRE_TYPE_CHANGE:
1da177e4 3267 case NETDEV_GOING_DOWN:
a2835763 3268 case NETDEV_UNREGISTER:
0115e8e3 3269 case NETDEV_UNREGISTER_FINAL:
ac3d3f81
AW
3270 case NETDEV_RELEASE:
3271 case NETDEV_JOIN:
61bd3857 3272 case NETDEV_BONDING_INFO:
1da177e4
LT
3273 break;
3274 default:
7f294054 3275 rtmsg_ifinfo(RTM_NEWLINK, dev, 0, GFP_KERNEL);
1da177e4
LT
3276 break;
3277 }
3278 return NOTIFY_DONE;
3279}
3280
3281static struct notifier_block rtnetlink_dev_notifier = {
3282 .notifier_call = rtnetlink_event,
3283};
3284
97c53cac 3285
2c8c1e72 3286static int __net_init rtnetlink_net_init(struct net *net)
97c53cac
DL
3287{
3288 struct sock *sk;
a31f2d17
PNA
3289 struct netlink_kernel_cfg cfg = {
3290 .groups = RTNLGRP_MAX,
3291 .input = rtnetlink_rcv,
3292 .cb_mutex = &rtnl_mutex,
9785e10a 3293 .flags = NL_CFG_F_NONROOT_RECV,
a31f2d17
PNA
3294 };
3295
9f00d977 3296 sk = netlink_kernel_create(net, NETLINK_ROUTE, &cfg);
97c53cac
DL
3297 if (!sk)
3298 return -ENOMEM;
97c53cac
DL
3299 net->rtnl = sk;
3300 return 0;
3301}
3302
2c8c1e72 3303static void __net_exit rtnetlink_net_exit(struct net *net)
97c53cac 3304{
775516bf
DL
3305 netlink_kernel_release(net->rtnl);
3306 net->rtnl = NULL;
97c53cac
DL
3307}
3308
3309static struct pernet_operations rtnetlink_net_ops = {
3310 .init = rtnetlink_net_init,
3311 .exit = rtnetlink_net_exit,
3312};
3313
1da177e4
LT
3314void __init rtnetlink_init(void)
3315{
97c53cac 3316 if (register_pernet_subsys(&rtnetlink_net_ops))
1da177e4 3317 panic("rtnetlink_init: cannot initialize rtnetlink\n");
97c53cac 3318
1da177e4 3319 register_netdevice_notifier(&rtnetlink_dev_notifier);
340d17fc 3320
c7ac8679
GR
3321 rtnl_register(PF_UNSPEC, RTM_GETLINK, rtnl_getlink,
3322 rtnl_dump_ifinfo, rtnl_calcit);
3323 rtnl_register(PF_UNSPEC, RTM_SETLINK, rtnl_setlink, NULL, NULL);
3324 rtnl_register(PF_UNSPEC, RTM_NEWLINK, rtnl_newlink, NULL, NULL);
3325 rtnl_register(PF_UNSPEC, RTM_DELLINK, rtnl_dellink, NULL, NULL);
687ad8cc 3326
c7ac8679
GR
3327 rtnl_register(PF_UNSPEC, RTM_GETADDR, NULL, rtnl_dump_all, NULL);
3328 rtnl_register(PF_UNSPEC, RTM_GETROUTE, NULL, rtnl_dump_all, NULL);
77162022
JF
3329
3330 rtnl_register(PF_BRIDGE, RTM_NEWNEIGH, rtnl_fdb_add, NULL, NULL);
3331 rtnl_register(PF_BRIDGE, RTM_DELNEIGH, rtnl_fdb_del, NULL, NULL);
3332 rtnl_register(PF_BRIDGE, RTM_GETNEIGH, NULL, rtnl_fdb_dump, NULL);
e5a55a89
JF
3333
3334 rtnl_register(PF_BRIDGE, RTM_GETLINK, NULL, rtnl_bridge_getlink, NULL);
407af329 3335 rtnl_register(PF_BRIDGE, RTM_DELLINK, rtnl_bridge_dellink, NULL, NULL);
e5a55a89 3336 rtnl_register(PF_BRIDGE, RTM_SETLINK, rtnl_bridge_setlink, NULL, NULL);
1da177e4
LT
3337}
3338