Skip to content

Commit ccb1c31

Browse files
Amerigo Wangdavem330
authored andcommitted
bridge: add flags to distinguish permanent mdb entires
This patch adds a flag to each mdb entry, so that we can distinguish permanent entries with temporary entries. Cc: Herbert Xu <[email protected]> Cc: Stephen Hemminger <[email protected]> Cc: "David S. Miller" <[email protected]> Signed-off-by: Cong Wang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 9dd9ff9 commit ccb1c31

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

include/uapi/linux/if_bridge.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ struct br_port_msg {
163163

164164
struct br_mdb_entry {
165165
__u32 ifindex;
166+
#define MDB_TEMPORARY 0
167+
#define MDB_PERMANENT 1
168+
__u8 state;
166169
struct {
167170
union {
168171
__be32 ip4;

net/bridge/br_mdb.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ static int br_mdb_fill_info(struct sk_buff *skb, struct netlink_callback *cb,
8383
if (port) {
8484
struct br_mdb_entry e;
8585
e.ifindex = port->dev->ifindex;
86+
e.state = p->state;
8687
e.addr.u.ip4 = p->addr.u.ip4;
8788
#if IS_ENABLED(CONFIG_IPV6)
8889
e.addr.u.ip6 = p->addr.u.ip6;
@@ -253,6 +254,8 @@ static bool is_valid_mdb_entry(struct br_mdb_entry *entry)
253254
#endif
254255
} else
255256
return false;
257+
if (entry->state != MDB_PERMANENT && entry->state != MDB_TEMPORARY)
258+
return false;
256259

257260
return true;
258261
}
@@ -310,7 +313,7 @@ static int br_mdb_parse(struct sk_buff *skb, struct nlmsghdr *nlh,
310313
}
311314

312315
static int br_mdb_add_group(struct net_bridge *br, struct net_bridge_port *port,
313-
struct br_ip *group)
316+
struct br_ip *group, unsigned char state)
314317
{
315318
struct net_bridge_mdb_entry *mp;
316319
struct net_bridge_port_group *p;
@@ -336,7 +339,7 @@ static int br_mdb_add_group(struct net_bridge *br, struct net_bridge_port *port,
336339
break;
337340
}
338341

339-
p = br_multicast_new_port_group(port, group, *pp);
342+
p = br_multicast_new_port_group(port, group, *pp, state);
340343
if (unlikely(!p))
341344
return -ENOMEM;
342345
rcu_assign_pointer(*pp, p);
@@ -373,7 +376,7 @@ static int __br_mdb_add(struct net *net, struct net_bridge *br,
373376
#endif
374377

375378
spin_lock_bh(&br->multicast_lock);
376-
ret = br_mdb_add_group(br, p, &ip);
379+
ret = br_mdb_add_group(br, p, &ip, entry->state);
377380
spin_unlock_bh(&br->multicast_lock);
378381
return ret;
379382
}

net/bridge/br_multicast.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ static void br_multicast_port_group_expired(unsigned long data)
279279

280280
spin_lock(&br->multicast_lock);
281281
if (!netif_running(br->dev) || timer_pending(&pg->timer) ||
282-
hlist_unhashed(&pg->mglist))
282+
hlist_unhashed(&pg->mglist) || pg->state & MDB_PERMANENT)
283283
goto out;
284284

285285
br_multicast_del_pg(br, pg);
@@ -622,7 +622,8 @@ struct net_bridge_mdb_entry *br_multicast_new_group(struct net_bridge *br,
622622
struct net_bridge_port_group *br_multicast_new_port_group(
623623
struct net_bridge_port *port,
624624
struct br_ip *group,
625-
struct net_bridge_port_group __rcu *next)
625+
struct net_bridge_port_group __rcu *next,
626+
unsigned char state)
626627
{
627628
struct net_bridge_port_group *p;
628629

@@ -632,6 +633,7 @@ struct net_bridge_port_group *br_multicast_new_port_group(
632633

633634
p->addr = *group;
634635
p->port = port;
636+
p->state = state;
635637
rcu_assign_pointer(p->next, next);
636638
hlist_add_head(&p->mglist, &port->mglist);
637639
setup_timer(&p->timer, br_multicast_port_group_expired,
@@ -674,7 +676,7 @@ static int br_multicast_add_group(struct net_bridge *br,
674676
break;
675677
}
676678

677-
p = br_multicast_new_port_group(port, group, *pp);
679+
p = br_multicast_new_port_group(port, group, *pp, MDB_TEMPORARY);
678680
if (unlikely(!p))
679681
goto err;
680682
rcu_assign_pointer(*pp, p);

net/bridge/br_private.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ struct net_bridge_port_group {
8383
struct rcu_head rcu;
8484
struct timer_list timer;
8585
struct br_ip addr;
86+
unsigned char state;
8687
};
8788

8889
struct net_bridge_mdb_entry
@@ -443,7 +444,8 @@ extern void br_multicast_free_pg(struct rcu_head *head);
443444
extern struct net_bridge_port_group *br_multicast_new_port_group(
444445
struct net_bridge_port *port,
445446
struct br_ip *group,
446-
struct net_bridge_port_group *next);
447+
struct net_bridge_port_group *next,
448+
unsigned char state);
447449
extern void br_mdb_init(void);
448450
extern void br_mdb_notify(struct net_device *dev, struct net_bridge_port *port,
449451
struct br_ip *group, int type);

0 commit comments

Comments
 (0)