History

net: bridge: mcast: add support for blocked port groups

When excluding S,G entries we need a way to block a particular S,G,port. The new port group flag is managed based on the source's timer as per RFCs 3376 and 3810. When a source expires and its port group is in EXCLUDE mode, it will be blocked.

Nikolay Aleksandrov committed 6 years ago

Commit 9116ffb1 parent 8266a044 files · +47 −6Browse files

Unified · Split

4 files
  1. include/uapi/linux/if_bridge.h +1 −0
  2. net/bridge/br_mdb.c +2 −0
  3. net/bridge/br_multicast.c +43 −6
  4. net/bridge/br_private.h +1 −0
include/uapi/linux/if_bridge.h+1−0
@@ -519,6 +519,7 @@ struct br_mdb_entry { · 518 unmodified lines
519519 #define MDB_FLAGS_OFFLOAD (1 << 0)
520520 #define MDB_FLAGS_FAST_LEAVE (1 << 1)
521521 #define MDB_FLAGS_STAR_EXCL (1 << 2)
522+#define MDB_FLAGS_BLOCKED (1 << 3)
522523 __u8 flags;
523524 __u16 vid;
524525 struct {
net/bridge/br_mdb.c+2−0
@@ -64,6 +64,8 @@ static void __mdb_entry_fill_flags(struct br_mdb_entry *e, unsigned char flags) · 63 unmodified lines
6464 e->flags |= MDB_FLAGS_FAST_LEAVE;
6565 if (flags & MDB_PG_FLAGS_STAR_EXCL)
6666 e->flags |= MDB_FLAGS_STAR_EXCL;
67+ if (flags & MDB_PG_FLAGS_BLOCKED)
68+ e->flags |= MDB_FLAGS_BLOCKED;
6769 }
6870
6971 static void __mdb_entry_to_br_ip(struct br_mdb_entry *entry, struct br_ip *ip,
net/bridge/br_multicast.c+43−6
@@ -72,7 +72,8 @@ __br_multicast_add_group(struct net_bridge *br, · 71 unmodified lines
7272 struct br_ip *group,
7373 const unsigned char *src,
7474 u8 filter_mode,
75− bool igmpv2_mldv1);
75+ bool igmpv2_mldv1,
76+ bool blocked);
7677 static void br_multicast_find_del_pg(struct net_bridge *br,
7778 struct net_bridge_port_group *pg);
7879
@@ -211,7 +212,7 @@ static void __fwd_add_star_excl(struct net_bridge_port_group *pg, · 132 unmodified lines
211212 return;
212213
213214 src_pg = __br_multicast_add_group(br, pg->key.port, sg_ip, pg->eth_addr,
214− MCAST_INCLUDE, false);
215+ MCAST_INCLUDE, false, false);
215216 if (IS_ERR_OR_NULL(src_pg) ||
216217 src_pg->rt_protocol != RTPROT_KERNEL)
217218 return;
@@ -343,7 +344,7 @@ void br_multicast_sg_add_exclude_ports(struct net_bridge_mdb_entry *star_mp, · 125 unmodified lines
343344 src_pg = __br_multicast_add_group(br, pg->key.port,
344345 &sg->key.addr,
345346 sg->eth_addr,
346− MCAST_INCLUDE, false);
347+ MCAST_INCLUDE, false, false);
347348 if (IS_ERR_OR_NULL(src_pg) ||
348349 src_pg->rt_protocol != RTPROT_KERNEL)
349350 continue;
@@ -364,7 +365,8 @@ static void br_multicast_fwd_src_add(struct net_bridge_group_src *src) · 14 unmodified lines
364365 sg_ip = src->pg->key.addr;
365366 sg_ip.src = src->addr.src;
366367 sg = __br_multicast_add_group(src->br, src->pg->key.port, &sg_ip,
367− src->pg->eth_addr, MCAST_INCLUDE, false);
368+ src->pg->eth_addr, MCAST_INCLUDE, false,
369+ !timer_pending(&src->timer));
368370 if (IS_ERR_OR_NULL(sg))
369371 return;
370372 src->flags |= BR_SGRP_F_INSTALLED;
@@ -415,9 +417,38 @@ static void br_multicast_fwd_src_remove(struct net_bridge_group_src *src) · 44 unmodified lines
415417 src->flags &= ~BR_SGRP_F_INSTALLED;
416418 }
417419
420+/* install S,G and based on src's timer enable or disable forwarding */
418421 static void br_multicast_fwd_src_handle(struct net_bridge_group_src *src)
419422 {
423+ struct net_bridge_port_group_sg_key sg_key;
424+ struct net_bridge_port_group *sg;
425+ u8 old_flags;
426+
420427 br_multicast_fwd_src_add(src);
428+
429+ memset(&sg_key, 0, sizeof(sg_key));
430+ sg_key.addr = src->pg->key.addr;
431+ sg_key.addr.src = src->addr.src;
432+ sg_key.port = src->pg->key.port;
433+
434+ sg = br_sg_port_find(src->br, &sg_key);
435+ if (!sg || (sg->flags & MDB_PG_FLAGS_PERMANENT))
436+ return;
437+
438+ old_flags = sg->flags;
439+ if (timer_pending(&src->timer))
440+ sg->flags &= ~MDB_PG_FLAGS_BLOCKED;
441+ else
442+ sg->flags |= MDB_PG_FLAGS_BLOCKED;
443+
444+ if (old_flags != sg->flags) {
445+ struct net_bridge_mdb_entry *sg_mp;
446+
447+ sg_mp = br_mdb_ip_get(src->br, &sg_key.addr);
448+ if (!sg_mp)
449+ return;
450+ br_mdb_notify(src->br->dev, sg_mp, sg, RTM_NEWMDB);
451+ }
421452 }
422453
423454 static void br_multicast_destroy_mdb_entry(struct net_bridge_mcast_gc *gc)
@@ -995,7 +1026,10 @@ static void br_multicast_group_src_expired(struct timer_list *t) · 571 unmodified lines
9951026 if (!hlist_empty(&pg->src_list))
9961027 goto out;
9971028 br_multicast_find_del_pg(br, pg);
1029+ } else {
1030+ br_multicast_fwd_src_handle(src);
9981031 }
1032+
9991033 out:
10001034 spin_unlock(&br->multicast_lock);
10011035 }
@@ -1131,7 +1165,8 @@ __br_multicast_add_group(struct net_bridge *br, · 129 unmodified lines
11311165 struct br_ip *group,
11321166 const unsigned char *src,
11331167 u8 filter_mode,
1134− bool igmpv2_mldv1)
1168+ bool igmpv2_mldv1,
1169+ bool blocked)
11351170 {
11361171 struct net_bridge_port_group __rcu **pp;
11371172 struct net_bridge_port_group *p = NULL;
@@ -1167,6 +1202,8 @@ __br_multicast_add_group(struct net_bridge *br, · 29 unmodified lines
11671202 goto out;
11681203 }
11691204 rcu_assign_pointer(*pp, p);
1205+ if (blocked)
1206+ p->flags |= MDB_PG_FLAGS_BLOCKED;
11701207 br_mdb_notify(br->dev, mp, p, RTM_NEWMDB);
11711208
11721209 found:
@@ -1189,7 +1226,7 @@ static int br_multicast_add_group(struct net_bridge *br, · 16 unmodified lines
11891226
11901227 spin_lock(&br->multicast_lock);
11911228 pg = __br_multicast_add_group(br, port, group, src, filter_mode,
1192− igmpv2_mldv1);
1229+ igmpv2_mldv1, false);
11931230 /* NULL is considered valid for host joined groups */
11941231 err = IS_ERR(pg) ? PTR_ERR(pg) : 0;
11951232 spin_unlock(&br->multicast_lock);
net/bridge/br_private.h+1−0
@@ -214,6 +214,7 @@ struct net_bridge_fdb_entry { · 213 unmodified lines
214214 #define MDB_PG_FLAGS_OFFLOAD BIT(1)
215215 #define MDB_PG_FLAGS_FAST_LEAVE BIT(2)
216216 #define MDB_PG_FLAGS_STAR_EXCL BIT(3)
217+#define MDB_PG_FLAGS_BLOCKED BIT(4)
217218
218219 #define PG_SRC_ENT_LIMIT 32
219220