br_mdb.c 15.4 KB
Newer Older
1 2 3 4 5 6
#include <linux/err.h>
#include <linux/igmp.h>
#include <linux/kernel.h>
#include <linux/netdevice.h>
#include <linux/rculist.h>
#include <linux/skbuff.h>
7
#include <linux/if_ether.h>
8 9
#include <net/ip.h>
#include <net/netlink.h>
10
#include <net/switchdev.h>
11 12
#if IS_ENABLED(CONFIG_IPV6)
#include <net/ipv6.h>
13
#include <net/addrconf.h>
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#endif

#include "br_private.h"

static int br_rports_fill_info(struct sk_buff *skb, struct netlink_callback *cb,
			       struct net_device *dev)
{
	struct net_bridge *br = netdev_priv(dev);
	struct net_bridge_port *p;
	struct nlattr *nest;

	if (!br->multicast_router || hlist_empty(&br->router_list))
		return 0;

	nest = nla_nest_start(skb, MDBA_ROUTER);
	if (nest == NULL)
		return -EMSGSIZE;

32
	hlist_for_each_entry_rcu(p, &br->router_list, rlist) {
33 34 35 36 37 38 39 40 41 42 43
		if (p && nla_put_u32(skb, MDBA_ROUTER_PORT, p->dev->ifindex))
			goto fail;
	}

	nla_nest_end(skb, nest);
	return 0;
fail:
	nla_nest_cancel(skb, nest);
	return -EMSGSIZE;
}

44 45 46 47 48 49 50 51
static void __mdb_entry_fill_flags(struct br_mdb_entry *e, unsigned char flags)
{
	e->state = flags & MDB_PG_FLAGS_PERMANENT;
	e->flags = 0;
	if (flags & MDB_PG_FLAGS_OFFLOAD)
		e->flags |= MDB_FLAGS_OFFLOAD;
}

52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
static int br_mdb_fill_info(struct sk_buff *skb, struct netlink_callback *cb,
			    struct net_device *dev)
{
	struct net_bridge *br = netdev_priv(dev);
	struct net_bridge_mdb_htable *mdb;
	struct nlattr *nest, *nest2;
	int i, err = 0;
	int idx = 0, s_idx = cb->args[1];

	if (br->multicast_disabled)
		return 0;

	mdb = rcu_dereference(br->mdb);
	if (!mdb)
		return 0;

	nest = nla_nest_start(skb, MDBA_MDB);
	if (nest == NULL)
		return -EMSGSIZE;

	for (i = 0; i < mdb->max; i++) {
		struct net_bridge_mdb_entry *mp;
74 75
		struct net_bridge_port_group *p;
		struct net_bridge_port_group __rcu **pp;
76 77
		struct net_bridge_port *port;

78
		hlist_for_each_entry_rcu(mp, &mdb->mhash[i], hlist[mdb->ver]) {
79 80 81 82 83 84 85 86 87 88 89 90
			if (idx < s_idx)
				goto skip;

			nest2 = nla_nest_start(skb, MDBA_MDB_ENTRY);
			if (nest2 == NULL) {
				err = -EMSGSIZE;
				goto out;
			}

			for (pp = &mp->ports;
			     (p = rcu_dereference(*pp)) != NULL;
			      pp = &p->next) {
91
				struct nlattr *nest_ent;
92 93
				struct br_mdb_entry e;

94
				port = p->port;
95 96
				if (!port)
					continue;
97

98 99 100 101 102 103
				memset(&e, 0, sizeof(e));
				e.ifindex = port->dev->ifindex;
				e.vid = p->addr.vid;
				__mdb_entry_fill_flags(&e, p->flags);
				if (p->addr.proto == htons(ETH_P_IP))
					e.addr.u.ip4 = p->addr.u.ip4;
104
#if IS_ENABLED(CONFIG_IPV6)
105 106
				if (p->addr.proto == htons(ETH_P_IPV6))
					e.addr.u.ip6 = p->addr.u.ip6;
107
#endif
108
				e.addr.proto = p->addr.proto;
109 110 111 112 113 114 115 116 117 118 119 120
				nest_ent = nla_nest_start(skb,
							  MDBA_MDB_ENTRY_INFO);
				if (!nest_ent) {
					nla_nest_cancel(skb, nest2);
					err = -EMSGSIZE;
					goto out;
				}
				if (nla_put_nohdr(skb, sizeof(e), &e) ||
				    nla_put_u32(skb,
						MDBA_MDB_EATTR_TIMER,
						br_timer_value(&p->timer))) {
					nla_nest_cancel(skb, nest_ent);
121 122 123
					nla_nest_cancel(skb, nest2);
					err = -EMSGSIZE;
					goto out;
124
				}
125
				nla_nest_end(skb, nest_ent);
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
			}
			nla_nest_end(skb, nest2);
		skip:
			idx++;
		}
	}

out:
	cb->args[1] = idx;
	nla_nest_end(skb, nest);
	return err;
}

static int br_mdb_dump(struct sk_buff *skb, struct netlink_callback *cb)
{
	struct net_device *dev;
	struct net *net = sock_net(skb->sk);
	struct nlmsghdr *nlh = NULL;
	int idx = 0, s_idx;

	s_idx = cb->args[0];

	rcu_read_lock();

C
Cong Wang 已提交
150 151
	/* In theory this could be wrapped to 0... */
	cb->seq = net->dev_base_seq + br_mdb_rehash_seq;
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166

	for_each_netdev_rcu(net, dev) {
		if (dev->priv_flags & IFF_EBRIDGE) {
			struct br_port_msg *bpm;

			if (idx < s_idx)
				goto skip;

			nlh = nlmsg_put(skb, NETLINK_CB(cb->skb).portid,
					cb->nlh->nlmsg_seq, RTM_GETMDB,
					sizeof(*bpm), NLM_F_MULTI);
			if (nlh == NULL)
				break;

			bpm = nlmsg_data(nlh);
M
Mathias Krause 已提交
167
			memset(bpm, 0, sizeof(*bpm));
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
			bpm->ifindex = dev->ifindex;
			if (br_mdb_fill_info(skb, cb, dev) < 0)
				goto out;
			if (br_rports_fill_info(skb, cb, dev) < 0)
				goto out;

			cb->args[1] = 0;
			nlmsg_end(skb, nlh);
		skip:
			idx++;
		}
	}

out:
	if (nlh)
		nlmsg_end(skb, nlh);
	rcu_read_unlock();
	cb->args[0] = idx;
	return skb->len;
}

C
Cong Wang 已提交
189 190 191 192 193 194 195 196 197
static int nlmsg_populate_mdb_fill(struct sk_buff *skb,
				   struct net_device *dev,
				   struct br_mdb_entry *entry, u32 pid,
				   u32 seq, int type, unsigned int flags)
{
	struct nlmsghdr *nlh;
	struct br_port_msg *bpm;
	struct nlattr *nest, *nest2;

198
	nlh = nlmsg_put(skb, pid, seq, type, sizeof(*bpm), 0);
C
Cong Wang 已提交
199 200 201 202
	if (!nlh)
		return -EMSGSIZE;

	bpm = nlmsg_data(nlh);
M
Mathias Krause 已提交
203
	memset(bpm, 0, sizeof(*bpm));
C
Cong Wang 已提交
204 205 206 207 208 209 210 211 212 213 214 215 216 217
	bpm->family  = AF_BRIDGE;
	bpm->ifindex = dev->ifindex;
	nest = nla_nest_start(skb, MDBA_MDB);
	if (nest == NULL)
		goto cancel;
	nest2 = nla_nest_start(skb, MDBA_MDB_ENTRY);
	if (nest2 == NULL)
		goto end;

	if (nla_put(skb, MDBA_MDB_ENTRY_INFO, sizeof(*entry), entry))
		goto end;

	nla_nest_end(skb, nest2);
	nla_nest_end(skb, nest);
218 219
	nlmsg_end(skb, nlh);
	return 0;
C
Cong Wang 已提交
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234

end:
	nla_nest_end(skb, nest);
cancel:
	nlmsg_cancel(skb, nlh);
	return -EMSGSIZE;
}

static inline size_t rtnl_mdb_nlmsg_size(void)
{
	return NLMSG_ALIGN(sizeof(struct br_port_msg))
		+ nla_total_size(sizeof(struct br_mdb_entry));
}

static void __br_mdb_notify(struct net_device *dev, struct br_mdb_entry *entry,
235
			    int type, struct net_bridge_port_group *pg)
C
Cong Wang 已提交
236
{
237 238 239 240 241 242 243 244
	struct switchdev_obj_port_mdb mdb = {
		.obj = {
			.id = SWITCHDEV_OBJ_ID_PORT_MDB,
			.flags = SWITCHDEV_F_DEFER,
		},
		.vid = entry->vid,
	};
	struct net_device *port_dev;
C
Cong Wang 已提交
245 246 247 248
	struct net *net = dev_net(dev);
	struct sk_buff *skb;
	int err = -ENOBUFS;

249 250 251 252 253 254 255 256 257
	port_dev = __dev_get_by_index(net, entry->ifindex);
	if (entry->addr.proto == htons(ETH_P_IP))
		ip_eth_mc_map(entry->addr.u.ip4, mdb.addr);
#if IS_ENABLED(CONFIG_IPV6)
	else
		ipv6_eth_mc_map(&entry->addr.u.ip6, mdb.addr);
#endif

	mdb.obj.orig_dev = port_dev;
258 259 260 261 262
	if (port_dev && type == RTM_NEWMDB) {
		err = switchdev_port_obj_add(port_dev, &mdb.obj);
		if (!err && pg)
			pg->flags |= MDB_PG_FLAGS_OFFLOAD;
	} else if (port_dev && type == RTM_DELMDB) {
263
		switchdev_port_obj_del(port_dev, &mdb.obj);
264
	}
265

C
Cong Wang 已提交
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
	skb = nlmsg_new(rtnl_mdb_nlmsg_size(), GFP_ATOMIC);
	if (!skb)
		goto errout;

	err = nlmsg_populate_mdb_fill(skb, dev, entry, 0, 0, type, NTF_SELF);
	if (err < 0) {
		kfree_skb(skb);
		goto errout;
	}

	rtnl_notify(skb, net, 0, RTNLGRP_MDB, NULL, GFP_ATOMIC);
	return;
errout:
	rtnl_set_sk_err(net, RTNLGRP_MDB, err);
}

282 283
void br_mdb_notify(struct net_device *dev, struct net_bridge_port_group *pg,
		   int type)
C
Cong Wang 已提交
284 285 286
{
	struct br_mdb_entry entry;

M
Mathias Krause 已提交
287
	memset(&entry, 0, sizeof(entry));
288 289 290
	entry.ifindex = pg->port->dev->ifindex;
	entry.addr.proto = pg->addr.proto;
	entry.addr.u.ip4 = pg->addr.u.ip4;
C
Cong Wang 已提交
291
#if IS_ENABLED(CONFIG_IPV6)
292
	entry.addr.u.ip6 = pg->addr.u.ip6;
C
Cong Wang 已提交
293
#endif
294 295 296
	entry.vid = pg->addr.vid;
	__mdb_entry_fill_flags(&entry, pg->flags);
	__br_mdb_notify(dev, &entry, type, pg);
C
Cong Wang 已提交
297 298
}

299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
static int nlmsg_populate_rtr_fill(struct sk_buff *skb,
				   struct net_device *dev,
				   int ifindex, u32 pid,
				   u32 seq, int type, unsigned int flags)
{
	struct br_port_msg *bpm;
	struct nlmsghdr *nlh;
	struct nlattr *nest;

	nlh = nlmsg_put(skb, pid, seq, type, sizeof(*bpm), NLM_F_MULTI);
	if (!nlh)
		return -EMSGSIZE;

	bpm = nlmsg_data(nlh);
	memset(bpm, 0, sizeof(*bpm));
	bpm->family = AF_BRIDGE;
	bpm->ifindex = dev->ifindex;
	nest = nla_nest_start(skb, MDBA_ROUTER);
	if (!nest)
		goto cancel;

	if (nla_put_u32(skb, MDBA_ROUTER_PORT, ifindex))
		goto end;

	nla_nest_end(skb, nest);
	nlmsg_end(skb, nlh);
	return 0;

end:
	nla_nest_end(skb, nest);
cancel:
	nlmsg_cancel(skb, nlh);
	return -EMSGSIZE;
}

static inline size_t rtnl_rtr_nlmsg_size(void)
{
	return NLMSG_ALIGN(sizeof(struct br_port_msg))
		+ nla_total_size(sizeof(__u32));
}

void br_rtr_notify(struct net_device *dev, struct net_bridge_port *port,
		   int type)
{
	struct net *net = dev_net(dev);
	struct sk_buff *skb;
	int err = -ENOBUFS;
	int ifindex;

	ifindex = port ? port->dev->ifindex : 0;
	skb = nlmsg_new(rtnl_rtr_nlmsg_size(), GFP_ATOMIC);
	if (!skb)
		goto errout;

	err = nlmsg_populate_rtr_fill(skb, dev, ifindex, 0, 0, type, NTF_SELF);
	if (err < 0) {
		kfree_skb(skb);
		goto errout;
	}

	rtnl_notify(skb, net, 0, RTNLGRP_MDB, NULL, GFP_ATOMIC);
	return;

errout:
	rtnl_set_sk_err(net, RTNLGRP_MDB, err);
}

366 367 368 369 370 371 372 373 374 375 376 377
static bool is_valid_mdb_entry(struct br_mdb_entry *entry)
{
	if (entry->ifindex == 0)
		return false;

	if (entry->addr.proto == htons(ETH_P_IP)) {
		if (!ipv4_is_multicast(entry->addr.u.ip4))
			return false;
		if (ipv4_is_local_multicast(entry->addr.u.ip4))
			return false;
#if IS_ENABLED(CONFIG_IPV6)
	} else if (entry->addr.proto == htons(ETH_P_IPV6)) {
378
		if (ipv6_addr_is_ll_all_nodes(&entry->addr.u.ip6))
379 380 381 382
			return false;
#endif
	} else
		return false;
383 384
	if (entry->state != MDB_PERMANENT && entry->state != MDB_TEMPORARY)
		return false;
385 386
	if (entry->vid >= VLAN_VID_MASK)
		return false;
387 388 389 390 391 392 393 394 395 396 397 398 399 400

	return true;
}

static int br_mdb_parse(struct sk_buff *skb, struct nlmsghdr *nlh,
			struct net_device **pdev, struct br_mdb_entry **pentry)
{
	struct net *net = sock_net(skb->sk);
	struct br_mdb_entry *entry;
	struct br_port_msg *bpm;
	struct nlattr *tb[MDBA_SET_ENTRY_MAX+1];
	struct net_device *dev;
	int err;

401
	err = nlmsg_parse(nlh, sizeof(*bpm), tb, MDBA_SET_ENTRY_MAX, NULL);
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440
	if (err < 0)
		return err;

	bpm = nlmsg_data(nlh);
	if (bpm->ifindex == 0) {
		pr_info("PF_BRIDGE: br_mdb_parse() with invalid ifindex\n");
		return -EINVAL;
	}

	dev = __dev_get_by_index(net, bpm->ifindex);
	if (dev == NULL) {
		pr_info("PF_BRIDGE: br_mdb_parse() with unknown ifindex\n");
		return -ENODEV;
	}

	if (!(dev->priv_flags & IFF_EBRIDGE)) {
		pr_info("PF_BRIDGE: br_mdb_parse() with non-bridge\n");
		return -EOPNOTSUPP;
	}

	*pdev = dev;

	if (!tb[MDBA_SET_ENTRY] ||
	    nla_len(tb[MDBA_SET_ENTRY]) != sizeof(struct br_mdb_entry)) {
		pr_info("PF_BRIDGE: br_mdb_parse() with invalid attr\n");
		return -EINVAL;
	}

	entry = nla_data(tb[MDBA_SET_ENTRY]);
	if (!is_valid_mdb_entry(entry)) {
		pr_info("PF_BRIDGE: br_mdb_parse() with invalid entry\n");
		return -EINVAL;
	}

	*pentry = entry;
	return 0;
}

static int br_mdb_add_group(struct net_bridge *br, struct net_bridge_port *port,
441 442
			    struct br_ip *group, unsigned char state,
			    struct net_bridge_port_group **pg)
443 444 445 446 447
{
	struct net_bridge_mdb_entry *mp;
	struct net_bridge_port_group *p;
	struct net_bridge_port_group __rcu **pp;
	struct net_bridge_mdb_htable *mdb;
448
	unsigned long now = jiffies;
449 450 451 452 453 454
	int err;

	mdb = mlock_dereference(br->mdb, br);
	mp = br_mdb_ip_get(mdb, group);
	if (!mp) {
		mp = br_multicast_new_group(br, port, group);
455 456
		err = PTR_ERR_OR_ZERO(mp);
		if (err)
457 458 459 460 461 462 463 464 465 466 467 468
			return err;
	}

	for (pp = &mp->ports;
	     (p = mlock_dereference(*pp, br)) != NULL;
	     pp = &p->next) {
		if (p->port == port)
			return -EEXIST;
		if ((unsigned long)p->port < (unsigned long)port)
			break;
	}

469
	p = br_multicast_new_port_group(port, group, *pp, state);
470 471 472
	if (unlikely(!p))
		return -ENOMEM;
	rcu_assign_pointer(*pp, p);
473
	*pg = p;
474 475
	if (state == MDB_TEMPORARY)
		mod_timer(&p->timer, now + br->multicast_membership_interval);
476 477 478 479 480

	return 0;
}

static int __br_mdb_add(struct net *net, struct net_bridge *br,
481 482
			struct br_mdb_entry *entry,
			struct net_bridge_port_group **pg)
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499
{
	struct br_ip ip;
	struct net_device *dev;
	struct net_bridge_port *p;
	int ret;

	if (!netif_running(br->dev) || br->multicast_disabled)
		return -EINVAL;

	dev = __dev_get_by_index(net, entry->ifindex);
	if (!dev)
		return -ENODEV;

	p = br_port_get_rtnl(dev);
	if (!p || p->br != br || p->state == BR_STATE_DISABLED)
		return -EINVAL;

500
	memset(&ip, 0, sizeof(ip));
501
	ip.vid = entry->vid;
502 503 504 505 506 507 508 509 510
	ip.proto = entry->addr.proto;
	if (ip.proto == htons(ETH_P_IP))
		ip.u.ip4 = entry->addr.u.ip4;
#if IS_ENABLED(CONFIG_IPV6)
	else
		ip.u.ip6 = entry->addr.u.ip6;
#endif

	spin_lock_bh(&br->multicast_lock);
511
	ret = br_mdb_add_group(br, p, &ip, entry->state, pg);
512 513 514 515
	spin_unlock_bh(&br->multicast_lock);
	return ret;
}

516
static int br_mdb_add(struct sk_buff *skb, struct nlmsghdr *nlh)
517 518
{
	struct net *net = sock_net(skb->sk);
519
	struct net_bridge_port_group *pg;
520
	struct net_bridge_vlan_group *vg;
521
	struct net_device *dev, *pdev;
522
	struct br_mdb_entry *entry;
523
	struct net_bridge_port *p;
524
	struct net_bridge_vlan *v;
525 526 527 528 529 530 531 532 533
	struct net_bridge *br;
	int err;

	err = br_mdb_parse(skb, nlh, &dev, &entry);
	if (err < 0)
		return err;

	br = netdev_priv(dev);

534 535 536 537 538 539 540 541 542 543 544
	/* If vlan filtering is enabled and VLAN is not specified
	 * install mdb entry on all vlans configured on the port.
	 */
	pdev = __dev_get_by_index(net, entry->ifindex);
	if (!pdev)
		return -ENODEV;

	p = br_port_get_rtnl(pdev);
	if (!p || p->br != br || p->state == BR_STATE_DISABLED)
		return -EINVAL;

545 546 547 548
	vg = nbp_vlan_group(p);
	if (br_vlan_enabled(br) && vg && entry->vid == 0) {
		list_for_each_entry(v, &vg->vlan_list, vlist) {
			entry->vid = v->vid;
549
			err = __br_mdb_add(net, br, entry, &pg);
550 551
			if (err)
				break;
552
			__br_mdb_notify(dev, entry, RTM_NEWMDB, pg);
553 554
		}
	} else {
555
		err = __br_mdb_add(net, br, entry, &pg);
556
		if (!err)
557
			__br_mdb_notify(dev, entry, RTM_NEWMDB, pg);
558 559
	}

560 561 562 563 564 565 566 567 568 569 570 571 572 573 574
	return err;
}

static int __br_mdb_del(struct net_bridge *br, struct br_mdb_entry *entry)
{
	struct net_bridge_mdb_htable *mdb;
	struct net_bridge_mdb_entry *mp;
	struct net_bridge_port_group *p;
	struct net_bridge_port_group __rcu **pp;
	struct br_ip ip;
	int err = -EINVAL;

	if (!netif_running(br->dev) || br->multicast_disabled)
		return -EINVAL;

575
	memset(&ip, 0, sizeof(ip));
576
	ip.vid = entry->vid;
577
	ip.proto = entry->addr.proto;
578
	if (ip.proto == htons(ETH_P_IP))
579 580
		ip.u.ip4 = entry->addr.u.ip4;
#if IS_ENABLED(CONFIG_IPV6)
581
	else
582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600
		ip.u.ip6 = entry->addr.u.ip6;
#endif

	spin_lock_bh(&br->multicast_lock);
	mdb = mlock_dereference(br->mdb, br);

	mp = br_mdb_ip_get(mdb, &ip);
	if (!mp)
		goto unlock;

	for (pp = &mp->ports;
	     (p = mlock_dereference(*pp, br)) != NULL;
	     pp = &p->next) {
		if (!p->port || p->port->dev->ifindex != entry->ifindex)
			continue;

		if (p->port->state == BR_STATE_DISABLED)
			goto unlock;

601
		__mdb_entry_fill_flags(entry, p->flags);
602 603 604 605 606 607
		rcu_assign_pointer(*pp, p->next);
		hlist_del_init(&p->mglist);
		del_timer(&p->timer);
		call_rcu_bh(&p->rcu, br_multicast_free_pg);
		err = 0;

608
		if (!mp->ports && !mp->mglist &&
609 610 611 612 613 614 615 616 617 618
		    netif_running(br->dev))
			mod_timer(&mp->timer, jiffies);
		break;
	}

unlock:
	spin_unlock_bh(&br->multicast_lock);
	return err;
}

619
static int br_mdb_del(struct sk_buff *skb, struct nlmsghdr *nlh)
620
{
621
	struct net *net = sock_net(skb->sk);
622
	struct net_bridge_vlan_group *vg;
623
	struct net_device *dev, *pdev;
624
	struct br_mdb_entry *entry;
625
	struct net_bridge_port *p;
626
	struct net_bridge_vlan *v;
627 628 629 630 631 632 633 634 635
	struct net_bridge *br;
	int err;

	err = br_mdb_parse(skb, nlh, &dev, &entry);
	if (err < 0)
		return err;

	br = netdev_priv(dev);

636 637 638 639 640 641 642 643 644 645 646
	/* If vlan filtering is enabled and VLAN is not specified
	 * delete mdb entry on all vlans configured on the port.
	 */
	pdev = __dev_get_by_index(net, entry->ifindex);
	if (!pdev)
		return -ENODEV;

	p = br_port_get_rtnl(pdev);
	if (!p || p->br != br || p->state == BR_STATE_DISABLED)
		return -EINVAL;

647 648 649 650
	vg = nbp_vlan_group(p);
	if (br_vlan_enabled(br) && vg && entry->vid == 0) {
		list_for_each_entry(v, &vg->vlan_list, vlist) {
			entry->vid = v->vid;
651 652
			err = __br_mdb_del(br, entry);
			if (!err)
653
				__br_mdb_notify(dev, entry, RTM_DELMDB, NULL);
654 655 656 657
		}
	} else {
		err = __br_mdb_del(br, entry);
		if (!err)
658
			__br_mdb_notify(dev, entry, RTM_DELMDB, NULL);
659 660
	}

661 662 663
	return err;
}

664 665 666
void br_mdb_init(void)
{
	rtnl_register(PF_BRIDGE, RTM_GETMDB, NULL, br_mdb_dump, NULL);
667 668
	rtnl_register(PF_BRIDGE, RTM_NEWMDB, br_mdb_add, NULL, NULL);
	rtnl_register(PF_BRIDGE, RTM_DELMDB, br_mdb_del, NULL, NULL);
669
}
670 671 672 673 674 675 676

void br_mdb_uninit(void)
{
	rtnl_unregister(PF_BRIDGE, RTM_GETMDB);
	rtnl_unregister(PF_BRIDGE, RTM_NEWMDB);
	rtnl_unregister(PF_BRIDGE, RTM_DELMDB);
}