Nikolay Aleksandrov
2021-Mar-15 17:13 UTC
[Bridge] [PATCH net-next v2 0/2] net: bridge: mcast: simplify allow/block EHT code
From: Nikolay Aleksandrov <nikolay at nvidia.com> Hi, The set does two minor cleanups of the EHT allow/block handling code: patch 01 removes code which is unreachable (it was used in initial EHT versions, but isn't anymore) and prepares the allow/block functions to be factored out. Patch 02 factors out common allow/block handling code. There are no functional changes. v2: send patch 02 and the proper version of both patches Thanks, Nik Nikolay Aleksandrov (2): net: bridge: mcast: remove unreachable EHT code net: bridge: mcast: factor out common allow/block EHT handling net/bridge/br_multicast_eht.c | 141 +++++++++------------------------- 1 file changed, 35 insertions(+), 106 deletions(-) -- 2.29.2
Nikolay Aleksandrov
2021-Mar-15 17:13 UTC
[Bridge] [PATCH net-next v2 1/2] net: bridge: mcast: remove unreachable EHT code
From: Nikolay Aleksandrov <nikolay at nvidia.com> In the initial EHT versions there were common functions which handled allow/block messages for both INCLUDE and EXCLUDE modes, but later they were separated. It seems I've left some common code which cannot be reached because the filter mode is checked before calling the respective functions, i.e. the host filter is always in EXCLUDE mode when using __eht_allow_excl() and __eht_block_excl() thus we can drop the host_excl checks inside and simplify the code a bit. Signed-off-by: Nikolay Aleksandrov <nikolay at nvidia.com> --- net/bridge/br_multicast_eht.c | 57 +++++++++-------------------------- 1 file changed, 15 insertions(+), 42 deletions(-) diff --git a/net/bridge/br_multicast_eht.c b/net/bridge/br_multicast_eht.c index fea38b9a7268..982398e44658 100644 --- a/net/bridge/br_multicast_eht.c +++ b/net/bridge/br_multicast_eht.c @@ -522,31 +522,24 @@ static bool __eht_allow_excl(struct net_bridge_port_group *pg, u32 nsrcs, size_t addr_size) { - bool changed = false, host_excl = false; union net_bridge_eht_addr eht_src_addr; struct net_bridge_group_src *src_ent; + bool changed = false; struct br_ip src_ip; u32 src_idx; - host_excl = !!(br_multicast_eht_host_filter_mode(pg, h_addr) == MCAST_EXCLUDE); memset(&eht_src_addr, 0, sizeof(eht_src_addr)); for (src_idx = 0; src_idx < nsrcs; src_idx++) { memcpy(&eht_src_addr, srcs + (src_idx * addr_size), addr_size); - if (!host_excl) { - br_multicast_create_eht_set_entry(pg, &eht_src_addr, h_addr, - MCAST_INCLUDE, - false); - } else { - if (!br_multicast_del_eht_set_entry(pg, &eht_src_addr, - h_addr)) - continue; - memcpy(&src_ip, srcs + (src_idx * addr_size), addr_size); - src_ent = br_multicast_find_group_src(pg, &src_ip); - if (!src_ent) - continue; - br_multicast_del_group_src(src_ent, true); - changed = true; - } + if (!br_multicast_del_eht_set_entry(pg, &eht_src_addr, + h_addr)) + continue; + memcpy(&src_ip, srcs + (src_idx * addr_size), addr_size); + src_ent = br_multicast_find_group_src(pg, &src_ip); + if (!src_ent) + continue; + br_multicast_del_group_src(src_ent, true); + changed = true; } return changed; @@ -602,42 +595,22 @@ static bool __eht_block_incl(struct net_bridge_port_group *pg, return changed; } -static bool __eht_block_excl(struct net_bridge_port_group *pg, +static void __eht_block_excl(struct net_bridge_port_group *pg, union net_bridge_eht_addr *h_addr, void *srcs, u32 nsrcs, size_t addr_size) { - bool changed = false, host_excl = false; union net_bridge_eht_addr eht_src_addr; - struct net_bridge_group_src *src_ent; - struct br_ip src_ip; u32 src_idx; - host_excl = !!(br_multicast_eht_host_filter_mode(pg, h_addr) == MCAST_EXCLUDE); memset(&eht_src_addr, 0, sizeof(eht_src_addr)); - memset(&src_ip, 0, sizeof(src_ip)); - src_ip.proto = pg->key.addr.proto; for (src_idx = 0; src_idx < nsrcs; src_idx++) { memcpy(&eht_src_addr, srcs + (src_idx * addr_size), addr_size); - if (host_excl) { - br_multicast_create_eht_set_entry(pg, &eht_src_addr, h_addr, - MCAST_EXCLUDE, - false); - } else { - if (!br_multicast_del_eht_set_entry(pg, &eht_src_addr, - h_addr)) - continue; - memcpy(&src_ip, srcs + (src_idx * addr_size), addr_size); - src_ent = br_multicast_find_group_src(pg, &src_ip); - if (!src_ent) - continue; - br_multicast_del_group_src(src_ent, true); - changed = true; - } + br_multicast_create_eht_set_entry(pg, &eht_src_addr, h_addr, + MCAST_EXCLUDE, + false); } - - return changed; } static bool br_multicast_eht_block(struct net_bridge_port_group *pg, @@ -653,7 +626,7 @@ static bool br_multicast_eht_block(struct net_bridge_port_group *pg, changed = __eht_block_incl(pg, h_addr, srcs, nsrcs, addr_size); break; case MCAST_EXCLUDE: - changed = __eht_block_excl(pg, h_addr, srcs, nsrcs, addr_size); + __eht_block_excl(pg, h_addr, srcs, nsrcs, addr_size); break; } -- 2.29.2
Nikolay Aleksandrov
2021-Mar-15 17:13 UTC
[Bridge] [PATCH net-next v2 2/2] net: bridge: mcast: factor out common allow/block EHT handling
From: Nikolay Aleksandrov <nikolay at nvidia.com> We hande EHT state change for ALLOW messages in INCLUDE mode and for BLOCK messages in EXCLUDE mode similarly - create the new set entries with the proper filter mode. We also handle EHT state change for ALLOW messages in EXCLUDE mode and for BLOCK messages in INCLUDE mode in a similar way - delete the common entries (current set and new set). Factor out all the common code as follows: - ALLOW/INCLUDE, BLOCK/EXCLUDE: call __eht_create_set_entries() - ALLOW/EXCLUDE, BLOCK/INCLUDE: call __eht_del_common_set_entries() The set entries creation can be reused in __eht_inc_exc() as well. Signed-off-by: Nikolay Aleksandrov <nikolay at nvidia.com> --- net/bridge/br_multicast_eht.c | 98 ++++++++++------------------------- 1 file changed, 27 insertions(+), 71 deletions(-) diff --git a/net/bridge/br_multicast_eht.c b/net/bridge/br_multicast_eht.c index 982398e44658..13290a749d09 100644 --- a/net/bridge/br_multicast_eht.c +++ b/net/bridge/br_multicast_eht.c @@ -498,11 +498,13 @@ static void br_multicast_del_eht_host(struct net_bridge_port_group *pg, &set_h->h_addr); } -static void __eht_allow_incl(struct net_bridge_port_group *pg, - union net_bridge_eht_addr *h_addr, - void *srcs, - u32 nsrcs, - size_t addr_size) +/* create new set entries from reports */ +static void __eht_create_set_entries(struct net_bridge_port_group *pg, + union net_bridge_eht_addr *h_addr, + void *srcs, + u32 nsrcs, + size_t addr_size, + int filter_mode) { union net_bridge_eht_addr eht_src_addr; u32 src_idx; @@ -511,16 +513,17 @@ static void __eht_allow_incl(struct net_bridge_port_group *pg, for (src_idx = 0; src_idx < nsrcs; src_idx++) { memcpy(&eht_src_addr, srcs + (src_idx * addr_size), addr_size); br_multicast_create_eht_set_entry(pg, &eht_src_addr, h_addr, - MCAST_INCLUDE, + filter_mode, false); } } -static bool __eht_allow_excl(struct net_bridge_port_group *pg, - union net_bridge_eht_addr *h_addr, - void *srcs, - u32 nsrcs, - size_t addr_size) +/* delete existing set entries and their (S,G) entries if they were the last */ +static bool __eht_del_set_entries(struct net_bridge_port_group *pg, + union net_bridge_eht_addr *h_addr, + void *srcs, + u32 nsrcs, + size_t addr_size) { union net_bridge_eht_addr eht_src_addr; struct net_bridge_group_src *src_ent; @@ -529,10 +532,11 @@ static bool __eht_allow_excl(struct net_bridge_port_group *pg, u32 src_idx; memset(&eht_src_addr, 0, sizeof(eht_src_addr)); + memset(&src_ip, 0, sizeof(src_ip)); + src_ip.proto = pg->key.addr.proto; for (src_idx = 0; src_idx < nsrcs; src_idx++) { memcpy(&eht_src_addr, srcs + (src_idx * addr_size), addr_size); - if (!br_multicast_del_eht_set_entry(pg, &eht_src_addr, - h_addr)) + if (!br_multicast_del_eht_set_entry(pg, &eht_src_addr, h_addr)) continue; memcpy(&src_ip, srcs + (src_idx * addr_size), addr_size); src_ent = br_multicast_find_group_src(pg, &src_ip); @@ -555,64 +559,18 @@ static bool br_multicast_eht_allow(struct net_bridge_port_group *pg, switch (br_multicast_eht_host_filter_mode(pg, h_addr)) { case MCAST_INCLUDE: - __eht_allow_incl(pg, h_addr, srcs, nsrcs, addr_size); + __eht_create_set_entries(pg, h_addr, srcs, nsrcs, addr_size, + MCAST_INCLUDE); break; case MCAST_EXCLUDE: - changed = __eht_allow_excl(pg, h_addr, srcs, nsrcs, addr_size); + changed = __eht_del_set_entries(pg, h_addr, srcs, nsrcs, + addr_size); break; } return changed; } -static bool __eht_block_incl(struct net_bridge_port_group *pg, - union net_bridge_eht_addr *h_addr, - void *srcs, - u32 nsrcs, - size_t addr_size) -{ - union net_bridge_eht_addr eht_src_addr; - struct net_bridge_group_src *src_ent; - bool changed = false; - struct br_ip src_ip; - u32 src_idx; - - memset(&eht_src_addr, 0, sizeof(eht_src_addr)); - memset(&src_ip, 0, sizeof(src_ip)); - src_ip.proto = pg->key.addr.proto; - for (src_idx = 0; src_idx < nsrcs; src_idx++) { - memcpy(&eht_src_addr, srcs + (src_idx * addr_size), addr_size); - if (!br_multicast_del_eht_set_entry(pg, &eht_src_addr, h_addr)) - continue; - memcpy(&src_ip, srcs + (src_idx * addr_size), addr_size); - src_ent = br_multicast_find_group_src(pg, &src_ip); - if (!src_ent) - continue; - br_multicast_del_group_src(src_ent, true); - changed = true; - } - - return changed; -} - -static void __eht_block_excl(struct net_bridge_port_group *pg, - union net_bridge_eht_addr *h_addr, - void *srcs, - u32 nsrcs, - size_t addr_size) -{ - union net_bridge_eht_addr eht_src_addr; - u32 src_idx; - - memset(&eht_src_addr, 0, sizeof(eht_src_addr)); - for (src_idx = 0; src_idx < nsrcs; src_idx++) { - memcpy(&eht_src_addr, srcs + (src_idx * addr_size), addr_size); - br_multicast_create_eht_set_entry(pg, &eht_src_addr, h_addr, - MCAST_EXCLUDE, - false); - } -} - static bool br_multicast_eht_block(struct net_bridge_port_group *pg, union net_bridge_eht_addr *h_addr, void *srcs, @@ -623,10 +581,12 @@ static bool br_multicast_eht_block(struct net_bridge_port_group *pg, switch (br_multicast_eht_host_filter_mode(pg, h_addr)) { case MCAST_INCLUDE: - changed = __eht_block_incl(pg, h_addr, srcs, nsrcs, addr_size); + changed = __eht_del_set_entries(pg, h_addr, srcs, nsrcs, + addr_size); break; case MCAST_EXCLUDE: - __eht_block_excl(pg, h_addr, srcs, nsrcs, addr_size); + __eht_create_set_entries(pg, h_addr, srcs, nsrcs, addr_size, + MCAST_EXCLUDE); break; } @@ -644,7 +604,6 @@ static bool __eht_inc_exc(struct net_bridge_port_group *pg, { bool changed = false, flush_entries = to_report; union net_bridge_eht_addr eht_src_addr; - u32 src_idx; if (br_multicast_eht_host_filter_mode(pg, h_addr) != filter_mode) flush_entries = true; @@ -653,11 +612,8 @@ static bool __eht_inc_exc(struct net_bridge_port_group *pg, /* if we're changing mode del host and its entries */ if (flush_entries) br_multicast_del_eht_host(pg, h_addr); - for (src_idx = 0; src_idx < nsrcs; src_idx++) { - memcpy(&eht_src_addr, srcs + (src_idx * addr_size), addr_size); - br_multicast_create_eht_set_entry(pg, &eht_src_addr, h_addr, - filter_mode, false); - } + __eht_create_set_entries(pg, h_addr, srcs, nsrcs, addr_size, + filter_mode); /* we can be missing sets only if we've deleted some entries */ if (flush_entries) { struct net_bridge *br = pg->key.port->br; -- 2.29.2
Jakub Kicinski
2021-Mar-16 20:59 UTC
[Bridge] [PATCH net-next v2 0/2] net: bridge: mcast: simplify allow/block EHT code
On Mon, 15 Mar 2021 19:13:40 +0200 Nikolay Aleksandrov wrote:> There are no functional changes.That appears to indeed be the case: Reviewed-by: Jakub Kicinski <kuba at kernel.org>
patchwork-bot+netdevbpf at kernel.org
2021-Mar-16 22:00 UTC
[Bridge] [PATCH net-next v2 0/2] net: bridge: mcast: simplify allow/block EHT code
Hello: This series was applied to netdev/net-next.git (refs/heads/master): On Mon, 15 Mar 2021 19:13:40 +0200 you wrote:> From: Nikolay Aleksandrov <nikolay at nvidia.com> > > Hi, > The set does two minor cleanups of the EHT allow/block handling code: > patch 01 removes code which is unreachable (it was used in initial EHT > versions, but isn't anymore) and prepares the allow/block functions to be > factored out. Patch 02 factors out common allow/block handling code. > There are no functional changes. > > [...]Here is the summary with links: - [net-next,v2,1/2] net: bridge: mcast: remove unreachable EHT code https://git.kernel.org/netdev/net-next/c/6aa2c371c729 - [net-next,v2,2/2] net: bridge: mcast: factor out common allow/block EHT handling https://git.kernel.org/netdev/net-next/c/e09cf582059e You are awesome, thank you! -- Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html