blob: cd8deea2d074e6af6172968c60cdd4128d40b16c [file] [log] [blame]
Cong Wangee07c6e2012-12-07 00:04:48 +00001#include <linux/err.h>
2#include <linux/igmp.h>
3#include <linux/kernel.h>
4#include <linux/netdevice.h>
5#include <linux/rculist.h>
6#include <linux/skbuff.h>
Cong Wangcfd56752012-12-11 22:23:08 +00007#include <linux/if_ether.h>
Cong Wangee07c6e2012-12-07 00:04:48 +00008#include <net/ip.h>
9#include <net/netlink.h>
10#if IS_ENABLED(CONFIG_IPV6)
11#include <net/ipv6.h>
Linus Lüssing3c3769e2013-09-04 02:13:39 +020012#include <net/addrconf.h>
Cong Wangee07c6e2012-12-07 00:04:48 +000013#endif
14
15#include "br_private.h"
16
17static int br_rports_fill_info(struct sk_buff *skb, struct netlink_callback *cb,
18 struct net_device *dev)
19{
20 struct net_bridge *br = netdev_priv(dev);
21 struct net_bridge_port *p;
Cong Wangee07c6e2012-12-07 00:04:48 +000022 struct nlattr *nest;
23
24 if (!br->multicast_router || hlist_empty(&br->router_list))
25 return 0;
26
27 nest = nla_nest_start(skb, MDBA_ROUTER);
28 if (nest == NULL)
29 return -EMSGSIZE;
30
Sasha Levinb67bfe02013-02-27 17:06:00 -080031 hlist_for_each_entry_rcu(p, &br->router_list, rlist) {
Cong Wangee07c6e2012-12-07 00:04:48 +000032 if (p && nla_put_u32(skb, MDBA_ROUTER_PORT, p->dev->ifindex))
33 goto fail;
34 }
35
36 nla_nest_end(skb, nest);
37 return 0;
38fail:
39 nla_nest_cancel(skb, nest);
40 return -EMSGSIZE;
41}
42
43static int br_mdb_fill_info(struct sk_buff *skb, struct netlink_callback *cb,
44 struct net_device *dev)
45{
46 struct net_bridge *br = netdev_priv(dev);
47 struct net_bridge_mdb_htable *mdb;
48 struct nlattr *nest, *nest2;
49 int i, err = 0;
50 int idx = 0, s_idx = cb->args[1];
51
52 if (br->multicast_disabled)
53 return 0;
54
55 mdb = rcu_dereference(br->mdb);
56 if (!mdb)
57 return 0;
58
59 nest = nla_nest_start(skb, MDBA_MDB);
60 if (nest == NULL)
61 return -EMSGSIZE;
62
63 for (i = 0; i < mdb->max; i++) {
Cong Wangee07c6e2012-12-07 00:04:48 +000064 struct net_bridge_mdb_entry *mp;
stephen hemminger762a3d82013-08-04 17:19:38 -070065 struct net_bridge_port_group *p;
66 struct net_bridge_port_group __rcu **pp;
Cong Wangee07c6e2012-12-07 00:04:48 +000067 struct net_bridge_port *port;
68
Sasha Levinb67bfe02013-02-27 17:06:00 -080069 hlist_for_each_entry_rcu(mp, &mdb->mhash[i], hlist[mdb->ver]) {
Cong Wangee07c6e2012-12-07 00:04:48 +000070 if (idx < s_idx)
71 goto skip;
72
73 nest2 = nla_nest_start(skb, MDBA_MDB_ENTRY);
74 if (nest2 == NULL) {
75 err = -EMSGSIZE;
76 goto out;
77 }
78
79 for (pp = &mp->ports;
80 (p = rcu_dereference(*pp)) != NULL;
81 pp = &p->next) {
82 port = p->port;
83 if (port) {
84 struct br_mdb_entry e;
Mathias Krausec085c492013-03-09 05:52:19 +000085 memset(&e, 0, sizeof(e));
Cong Wangee07c6e2012-12-07 00:04:48 +000086 e.ifindex = port->dev->ifindex;
Amerigo Wangccb1c312012-12-14 22:09:51 +000087 e.state = p->state;
Nikolay Aleksandrov74fe61f2015-07-10 08:02:08 -070088 e.vid = p->addr.vid;
Vlad Yasevich09d7cf72012-12-18 11:54:08 +000089 if (p->addr.proto == htons(ETH_P_IP))
90 e.addr.u.ip4 = p->addr.u.ip4;
Cong Wangee07c6e2012-12-07 00:04:48 +000091#if IS_ENABLED(CONFIG_IPV6)
Vlad Yasevich09d7cf72012-12-18 11:54:08 +000092 if (p->addr.proto == htons(ETH_P_IPV6))
93 e.addr.u.ip6 = p->addr.u.ip6;
Cong Wangee07c6e2012-12-07 00:04:48 +000094#endif
95 e.addr.proto = p->addr.proto;
96 if (nla_put(skb, MDBA_MDB_ENTRY_INFO, sizeof(e), &e)) {
97 nla_nest_cancel(skb, nest2);
98 err = -EMSGSIZE;
99 goto out;
100 }
101 }
102 }
103 nla_nest_end(skb, nest2);
104 skip:
105 idx++;
106 }
107 }
108
109out:
110 cb->args[1] = idx;
111 nla_nest_end(skb, nest);
112 return err;
113}
114
115static int br_mdb_dump(struct sk_buff *skb, struct netlink_callback *cb)
116{
117 struct net_device *dev;
118 struct net *net = sock_net(skb->sk);
119 struct nlmsghdr *nlh = NULL;
120 int idx = 0, s_idx;
121
122 s_idx = cb->args[0];
123
124 rcu_read_lock();
125
Cong Wang2ce297f2012-12-10 02:15:35 +0000126 /* In theory this could be wrapped to 0... */
127 cb->seq = net->dev_base_seq + br_mdb_rehash_seq;
Cong Wangee07c6e2012-12-07 00:04:48 +0000128
129 for_each_netdev_rcu(net, dev) {
130 if (dev->priv_flags & IFF_EBRIDGE) {
131 struct br_port_msg *bpm;
132
133 if (idx < s_idx)
134 goto skip;
135
136 nlh = nlmsg_put(skb, NETLINK_CB(cb->skb).portid,
137 cb->nlh->nlmsg_seq, RTM_GETMDB,
138 sizeof(*bpm), NLM_F_MULTI);
139 if (nlh == NULL)
140 break;
141
142 bpm = nlmsg_data(nlh);
Mathias Krausec085c492013-03-09 05:52:19 +0000143 memset(bpm, 0, sizeof(*bpm));
Cong Wangee07c6e2012-12-07 00:04:48 +0000144 bpm->ifindex = dev->ifindex;
145 if (br_mdb_fill_info(skb, cb, dev) < 0)
146 goto out;
147 if (br_rports_fill_info(skb, cb, dev) < 0)
148 goto out;
149
150 cb->args[1] = 0;
151 nlmsg_end(skb, nlh);
152 skip:
153 idx++;
154 }
155 }
156
157out:
158 if (nlh)
159 nlmsg_end(skb, nlh);
160 rcu_read_unlock();
161 cb->args[0] = idx;
162 return skb->len;
163}
164
Cong Wang37a393b2012-12-11 22:23:07 +0000165static int nlmsg_populate_mdb_fill(struct sk_buff *skb,
166 struct net_device *dev,
167 struct br_mdb_entry *entry, u32 pid,
168 u32 seq, int type, unsigned int flags)
169{
170 struct nlmsghdr *nlh;
171 struct br_port_msg *bpm;
172 struct nlattr *nest, *nest2;
173
Nicolas Dichtel82199672015-04-28 18:33:48 +0200174 nlh = nlmsg_put(skb, pid, seq, type, sizeof(*bpm), 0);
Cong Wang37a393b2012-12-11 22:23:07 +0000175 if (!nlh)
176 return -EMSGSIZE;
177
178 bpm = nlmsg_data(nlh);
Mathias Krausec085c492013-03-09 05:52:19 +0000179 memset(bpm, 0, sizeof(*bpm));
Cong Wang37a393b2012-12-11 22:23:07 +0000180 bpm->family = AF_BRIDGE;
181 bpm->ifindex = dev->ifindex;
182 nest = nla_nest_start(skb, MDBA_MDB);
183 if (nest == NULL)
184 goto cancel;
185 nest2 = nla_nest_start(skb, MDBA_MDB_ENTRY);
186 if (nest2 == NULL)
187 goto end;
188
189 if (nla_put(skb, MDBA_MDB_ENTRY_INFO, sizeof(*entry), entry))
190 goto end;
191
192 nla_nest_end(skb, nest2);
193 nla_nest_end(skb, nest);
Johannes Berg053c0952015-01-16 22:09:00 +0100194 nlmsg_end(skb, nlh);
195 return 0;
Cong Wang37a393b2012-12-11 22:23:07 +0000196
197end:
198 nla_nest_end(skb, nest);
199cancel:
200 nlmsg_cancel(skb, nlh);
201 return -EMSGSIZE;
202}
203
204static inline size_t rtnl_mdb_nlmsg_size(void)
205{
206 return NLMSG_ALIGN(sizeof(struct br_port_msg))
207 + nla_total_size(sizeof(struct br_mdb_entry));
208}
209
210static void __br_mdb_notify(struct net_device *dev, struct br_mdb_entry *entry,
211 int type)
212{
213 struct net *net = dev_net(dev);
214 struct sk_buff *skb;
215 int err = -ENOBUFS;
216
217 skb = nlmsg_new(rtnl_mdb_nlmsg_size(), GFP_ATOMIC);
218 if (!skb)
219 goto errout;
220
221 err = nlmsg_populate_mdb_fill(skb, dev, entry, 0, 0, type, NTF_SELF);
222 if (err < 0) {
223 kfree_skb(skb);
224 goto errout;
225 }
226
227 rtnl_notify(skb, net, 0, RTNLGRP_MDB, NULL, GFP_ATOMIC);
228 return;
229errout:
230 rtnl_set_sk_err(net, RTNLGRP_MDB, err);
231}
232
233void br_mdb_notify(struct net_device *dev, struct net_bridge_port *port,
Nikolay Aleksandrov09cf0212015-07-09 03:11:10 -0700234 struct br_ip *group, int type, u8 state)
Cong Wang37a393b2012-12-11 22:23:07 +0000235{
236 struct br_mdb_entry entry;
237
Mathias Krausec085c492013-03-09 05:52:19 +0000238 memset(&entry, 0, sizeof(entry));
Cong Wang37a393b2012-12-11 22:23:07 +0000239 entry.ifindex = port->dev->ifindex;
240 entry.addr.proto = group->proto;
241 entry.addr.u.ip4 = group->u.ip4;
242#if IS_ENABLED(CONFIG_IPV6)
243 entry.addr.u.ip6 = group->u.ip6;
244#endif
Nikolay Aleksandrov09cf0212015-07-09 03:11:10 -0700245 entry.state = state;
Nikolay Aleksandrov74fe61f2015-07-10 08:02:08 -0700246 entry.vid = group->vid;
Cong Wang37a393b2012-12-11 22:23:07 +0000247 __br_mdb_notify(dev, &entry, type);
248}
249
Satish Ashok949f1e32015-07-23 05:00:53 -0700250static int nlmsg_populate_rtr_fill(struct sk_buff *skb,
251 struct net_device *dev,
252 int ifindex, u32 pid,
253 u32 seq, int type, unsigned int flags)
254{
255 struct br_port_msg *bpm;
256 struct nlmsghdr *nlh;
257 struct nlattr *nest;
258
259 nlh = nlmsg_put(skb, pid, seq, type, sizeof(*bpm), NLM_F_MULTI);
260 if (!nlh)
261 return -EMSGSIZE;
262
263 bpm = nlmsg_data(nlh);
264 memset(bpm, 0, sizeof(*bpm));
265 bpm->family = AF_BRIDGE;
266 bpm->ifindex = dev->ifindex;
267 nest = nla_nest_start(skb, MDBA_ROUTER);
268 if (!nest)
269 goto cancel;
270
271 if (nla_put_u32(skb, MDBA_ROUTER_PORT, ifindex))
272 goto end;
273
274 nla_nest_end(skb, nest);
275 nlmsg_end(skb, nlh);
276 return 0;
277
278end:
279 nla_nest_end(skb, nest);
280cancel:
281 nlmsg_cancel(skb, nlh);
282 return -EMSGSIZE;
283}
284
285static inline size_t rtnl_rtr_nlmsg_size(void)
286{
287 return NLMSG_ALIGN(sizeof(struct br_port_msg))
288 + nla_total_size(sizeof(__u32));
289}
290
291void br_rtr_notify(struct net_device *dev, struct net_bridge_port *port,
292 int type)
293{
294 struct net *net = dev_net(dev);
295 struct sk_buff *skb;
296 int err = -ENOBUFS;
297 int ifindex;
298
299 ifindex = port ? port->dev->ifindex : 0;
300 skb = nlmsg_new(rtnl_rtr_nlmsg_size(), GFP_ATOMIC);
301 if (!skb)
302 goto errout;
303
304 err = nlmsg_populate_rtr_fill(skb, dev, ifindex, 0, 0, type, NTF_SELF);
305 if (err < 0) {
306 kfree_skb(skb);
307 goto errout;
308 }
309
310 rtnl_notify(skb, net, 0, RTNLGRP_MDB, NULL, GFP_ATOMIC);
311 return;
312
313errout:
314 rtnl_set_sk_err(net, RTNLGRP_MDB, err);
315}
316
Cong Wangcfd56752012-12-11 22:23:08 +0000317static bool is_valid_mdb_entry(struct br_mdb_entry *entry)
318{
319 if (entry->ifindex == 0)
320 return false;
321
322 if (entry->addr.proto == htons(ETH_P_IP)) {
323 if (!ipv4_is_multicast(entry->addr.u.ip4))
324 return false;
325 if (ipv4_is_local_multicast(entry->addr.u.ip4))
326 return false;
327#if IS_ENABLED(CONFIG_IPV6)
328 } else if (entry->addr.proto == htons(ETH_P_IPV6)) {
Linus Lüssing3c3769e2013-09-04 02:13:39 +0200329 if (ipv6_addr_is_ll_all_nodes(&entry->addr.u.ip6))
Cong Wangcfd56752012-12-11 22:23:08 +0000330 return false;
331#endif
332 } else
333 return false;
Amerigo Wangccb1c312012-12-14 22:09:51 +0000334 if (entry->state != MDB_PERMANENT && entry->state != MDB_TEMPORARY)
335 return false;
Nikolay Aleksandrov74fe61f2015-07-10 08:02:08 -0700336 if (entry->vid >= VLAN_VID_MASK)
337 return false;
Cong Wangcfd56752012-12-11 22:23:08 +0000338
339 return true;
340}
341
342static int br_mdb_parse(struct sk_buff *skb, struct nlmsghdr *nlh,
343 struct net_device **pdev, struct br_mdb_entry **pentry)
344{
345 struct net *net = sock_net(skb->sk);
346 struct br_mdb_entry *entry;
347 struct br_port_msg *bpm;
348 struct nlattr *tb[MDBA_SET_ENTRY_MAX+1];
349 struct net_device *dev;
350 int err;
351
Nicolas Dichtel12d87252015-01-15 16:29:12 +0100352 err = nlmsg_parse(nlh, sizeof(*bpm), tb, MDBA_SET_ENTRY_MAX, NULL);
Cong Wangcfd56752012-12-11 22:23:08 +0000353 if (err < 0)
354 return err;
355
356 bpm = nlmsg_data(nlh);
357 if (bpm->ifindex == 0) {
358 pr_info("PF_BRIDGE: br_mdb_parse() with invalid ifindex\n");
359 return -EINVAL;
360 }
361
362 dev = __dev_get_by_index(net, bpm->ifindex);
363 if (dev == NULL) {
364 pr_info("PF_BRIDGE: br_mdb_parse() with unknown ifindex\n");
365 return -ENODEV;
366 }
367
368 if (!(dev->priv_flags & IFF_EBRIDGE)) {
369 pr_info("PF_BRIDGE: br_mdb_parse() with non-bridge\n");
370 return -EOPNOTSUPP;
371 }
372
373 *pdev = dev;
374
375 if (!tb[MDBA_SET_ENTRY] ||
376 nla_len(tb[MDBA_SET_ENTRY]) != sizeof(struct br_mdb_entry)) {
377 pr_info("PF_BRIDGE: br_mdb_parse() with invalid attr\n");
378 return -EINVAL;
379 }
380
381 entry = nla_data(tb[MDBA_SET_ENTRY]);
382 if (!is_valid_mdb_entry(entry)) {
383 pr_info("PF_BRIDGE: br_mdb_parse() with invalid entry\n");
384 return -EINVAL;
385 }
386
387 *pentry = entry;
388 return 0;
389}
390
391static int br_mdb_add_group(struct net_bridge *br, struct net_bridge_port *port,
Amerigo Wangccb1c312012-12-14 22:09:51 +0000392 struct br_ip *group, unsigned char state)
Cong Wangcfd56752012-12-11 22:23:08 +0000393{
394 struct net_bridge_mdb_entry *mp;
395 struct net_bridge_port_group *p;
396 struct net_bridge_port_group __rcu **pp;
397 struct net_bridge_mdb_htable *mdb;
Satish Ashokf7e29652015-07-06 05:53:35 -0700398 unsigned long now = jiffies;
Cong Wangcfd56752012-12-11 22:23:08 +0000399 int err;
400
401 mdb = mlock_dereference(br->mdb, br);
402 mp = br_mdb_ip_get(mdb, group);
403 if (!mp) {
404 mp = br_multicast_new_group(br, port, group);
405 err = PTR_ERR(mp);
406 if (IS_ERR(mp))
407 return err;
408 }
409
410 for (pp = &mp->ports;
411 (p = mlock_dereference(*pp, br)) != NULL;
412 pp = &p->next) {
413 if (p->port == port)
414 return -EEXIST;
415 if ((unsigned long)p->port < (unsigned long)port)
416 break;
417 }
418
Amerigo Wangccb1c312012-12-14 22:09:51 +0000419 p = br_multicast_new_port_group(port, group, *pp, state);
Cong Wangcfd56752012-12-11 22:23:08 +0000420 if (unlikely(!p))
421 return -ENOMEM;
422 rcu_assign_pointer(*pp, p);
Satish Ashokf7e29652015-07-06 05:53:35 -0700423 if (state == MDB_TEMPORARY)
424 mod_timer(&p->timer, now + br->multicast_membership_interval);
Cong Wangcfd56752012-12-11 22:23:08 +0000425
Cong Wangcfd56752012-12-11 22:23:08 +0000426 return 0;
427}
428
429static int __br_mdb_add(struct net *net, struct net_bridge *br,
430 struct br_mdb_entry *entry)
431{
432 struct br_ip ip;
433 struct net_device *dev;
434 struct net_bridge_port *p;
435 int ret;
436
437 if (!netif_running(br->dev) || br->multicast_disabled)
438 return -EINVAL;
439
440 dev = __dev_get_by_index(net, entry->ifindex);
441 if (!dev)
442 return -ENODEV;
443
444 p = br_port_get_rtnl(dev);
445 if (!p || p->br != br || p->state == BR_STATE_DISABLED)
446 return -EINVAL;
447
Nikolay Aleksandrovf1158b72015-07-07 15:55:56 +0200448 memset(&ip, 0, sizeof(ip));
Nikolay Aleksandrov74fe61f2015-07-10 08:02:08 -0700449 ip.vid = entry->vid;
Cong Wangcfd56752012-12-11 22:23:08 +0000450 ip.proto = entry->addr.proto;
451 if (ip.proto == htons(ETH_P_IP))
452 ip.u.ip4 = entry->addr.u.ip4;
453#if IS_ENABLED(CONFIG_IPV6)
454 else
455 ip.u.ip6 = entry->addr.u.ip6;
456#endif
457
458 spin_lock_bh(&br->multicast_lock);
Amerigo Wangccb1c312012-12-14 22:09:51 +0000459 ret = br_mdb_add_group(br, p, &ip, entry->state);
Cong Wangcfd56752012-12-11 22:23:08 +0000460 spin_unlock_bh(&br->multicast_lock);
461 return ret;
462}
463
Thomas Graf661d2962013-03-21 07:45:29 +0000464static int br_mdb_add(struct sk_buff *skb, struct nlmsghdr *nlh)
Cong Wangcfd56752012-12-11 22:23:08 +0000465{
466 struct net *net = sock_net(skb->sk);
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200467 struct net_bridge_vlan_group *vg;
Satish Ashoke44deb22015-08-03 13:29:16 +0200468 struct net_device *dev, *pdev;
Cong Wangcfd56752012-12-11 22:23:08 +0000469 struct br_mdb_entry *entry;
Satish Ashoke44deb22015-08-03 13:29:16 +0200470 struct net_bridge_port *p;
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200471 struct net_bridge_vlan *v;
Cong Wangcfd56752012-12-11 22:23:08 +0000472 struct net_bridge *br;
473 int err;
474
475 err = br_mdb_parse(skb, nlh, &dev, &entry);
476 if (err < 0)
477 return err;
478
479 br = netdev_priv(dev);
480
Satish Ashoke44deb22015-08-03 13:29:16 +0200481 /* If vlan filtering is enabled and VLAN is not specified
482 * install mdb entry on all vlans configured on the port.
483 */
484 pdev = __dev_get_by_index(net, entry->ifindex);
485 if (!pdev)
486 return -ENODEV;
487
488 p = br_port_get_rtnl(pdev);
489 if (!p || p->br != br || p->state == BR_STATE_DISABLED)
490 return -EINVAL;
491
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200492 vg = nbp_vlan_group(p);
493 if (br_vlan_enabled(br) && vg && entry->vid == 0) {
494 list_for_each_entry(v, &vg->vlan_list, vlist) {
495 entry->vid = v->vid;
Satish Ashoke44deb22015-08-03 13:29:16 +0200496 err = __br_mdb_add(net, br, entry);
497 if (err)
498 break;
499 __br_mdb_notify(dev, entry, RTM_NEWMDB);
500 }
501 } else {
502 err = __br_mdb_add(net, br, entry);
503 if (!err)
504 __br_mdb_notify(dev, entry, RTM_NEWMDB);
505 }
506
Cong Wangcfd56752012-12-11 22:23:08 +0000507 return err;
508}
509
510static int __br_mdb_del(struct net_bridge *br, struct br_mdb_entry *entry)
511{
512 struct net_bridge_mdb_htable *mdb;
513 struct net_bridge_mdb_entry *mp;
514 struct net_bridge_port_group *p;
515 struct net_bridge_port_group __rcu **pp;
516 struct br_ip ip;
517 int err = -EINVAL;
518
519 if (!netif_running(br->dev) || br->multicast_disabled)
520 return -EINVAL;
521
Nikolay Aleksandrovf1158b72015-07-07 15:55:56 +0200522 memset(&ip, 0, sizeof(ip));
Nikolay Aleksandrov74fe61f2015-07-10 08:02:08 -0700523 ip.vid = entry->vid;
Cong Wangcfd56752012-12-11 22:23:08 +0000524 ip.proto = entry->addr.proto;
Satish Ashok51ed7f3e2015-07-09 04:12:45 -0700525 if (ip.proto == htons(ETH_P_IP))
Cong Wangcfd56752012-12-11 22:23:08 +0000526 ip.u.ip4 = entry->addr.u.ip4;
527#if IS_ENABLED(CONFIG_IPV6)
Satish Ashok51ed7f3e2015-07-09 04:12:45 -0700528 else
Cong Wangcfd56752012-12-11 22:23:08 +0000529 ip.u.ip6 = entry->addr.u.ip6;
530#endif
531
532 spin_lock_bh(&br->multicast_lock);
533 mdb = mlock_dereference(br->mdb, br);
534
535 mp = br_mdb_ip_get(mdb, &ip);
536 if (!mp)
537 goto unlock;
538
539 for (pp = &mp->ports;
540 (p = mlock_dereference(*pp, br)) != NULL;
541 pp = &p->next) {
542 if (!p->port || p->port->dev->ifindex != entry->ifindex)
543 continue;
544
545 if (p->port->state == BR_STATE_DISABLED)
546 goto unlock;
547
Nikolay Aleksandrov7ae90a42015-07-28 13:10:44 +0200548 entry->state = p->state;
Cong Wangcfd56752012-12-11 22:23:08 +0000549 rcu_assign_pointer(*pp, p->next);
550 hlist_del_init(&p->mglist);
551 del_timer(&p->timer);
552 call_rcu_bh(&p->rcu, br_multicast_free_pg);
553 err = 0;
554
Linus Lüssing454594f2013-10-20 00:58:57 +0200555 if (!mp->ports && !mp->mglist &&
Cong Wangcfd56752012-12-11 22:23:08 +0000556 netif_running(br->dev))
557 mod_timer(&mp->timer, jiffies);
558 break;
559 }
560
561unlock:
562 spin_unlock_bh(&br->multicast_lock);
563 return err;
564}
565
Thomas Graf661d2962013-03-21 07:45:29 +0000566static int br_mdb_del(struct sk_buff *skb, struct nlmsghdr *nlh)
Cong Wangcfd56752012-12-11 22:23:08 +0000567{
Satish Ashoke44deb22015-08-03 13:29:16 +0200568 struct net *net = sock_net(skb->sk);
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200569 struct net_bridge_vlan_group *vg;
Satish Ashoke44deb22015-08-03 13:29:16 +0200570 struct net_device *dev, *pdev;
Cong Wangcfd56752012-12-11 22:23:08 +0000571 struct br_mdb_entry *entry;
Satish Ashoke44deb22015-08-03 13:29:16 +0200572 struct net_bridge_port *p;
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200573 struct net_bridge_vlan *v;
Cong Wangcfd56752012-12-11 22:23:08 +0000574 struct net_bridge *br;
575 int err;
576
577 err = br_mdb_parse(skb, nlh, &dev, &entry);
578 if (err < 0)
579 return err;
580
581 br = netdev_priv(dev);
582
Satish Ashoke44deb22015-08-03 13:29:16 +0200583 /* If vlan filtering is enabled and VLAN is not specified
584 * delete mdb entry on all vlans configured on the port.
585 */
586 pdev = __dev_get_by_index(net, entry->ifindex);
587 if (!pdev)
588 return -ENODEV;
589
590 p = br_port_get_rtnl(pdev);
591 if (!p || p->br != br || p->state == BR_STATE_DISABLED)
592 return -EINVAL;
593
Nikolay Aleksandrov2594e902015-09-25 19:00:11 +0200594 vg = nbp_vlan_group(p);
595 if (br_vlan_enabled(br) && vg && entry->vid == 0) {
596 list_for_each_entry(v, &vg->vlan_list, vlist) {
597 entry->vid = v->vid;
Satish Ashoke44deb22015-08-03 13:29:16 +0200598 err = __br_mdb_del(br, entry);
599 if (!err)
600 __br_mdb_notify(dev, entry, RTM_DELMDB);
601 }
602 } else {
603 err = __br_mdb_del(br, entry);
604 if (!err)
605 __br_mdb_notify(dev, entry, RTM_DELMDB);
606 }
607
Cong Wangcfd56752012-12-11 22:23:08 +0000608 return err;
609}
610
Cong Wangee07c6e2012-12-07 00:04:48 +0000611void br_mdb_init(void)
612{
613 rtnl_register(PF_BRIDGE, RTM_GETMDB, NULL, br_mdb_dump, NULL);
Cong Wangcfd56752012-12-11 22:23:08 +0000614 rtnl_register(PF_BRIDGE, RTM_NEWMDB, br_mdb_add, NULL, NULL);
615 rtnl_register(PF_BRIDGE, RTM_DELMDB, br_mdb_del, NULL, NULL);
Cong Wangee07c6e2012-12-07 00:04:48 +0000616}
Vlad Yasevich63233152012-12-19 09:13:48 +0000617
618void br_mdb_uninit(void)
619{
620 rtnl_unregister(PF_BRIDGE, RTM_GETMDB);
621 rtnl_unregister(PF_BRIDGE, RTM_NEWMDB);
622 rtnl_unregister(PF_BRIDGE, RTM_DELMDB);
623}