bridge: multicast to unicast
Subsystems (3)
PATCH v4 1/1 bridge: multicast to unicast
From: Felix Fietkau <[email protected]>
Implements an optional, per bridge port flag and feature to deliver multicast packets to any host on the according port via unicast individually. This is done by copying the packet per host and changing the multicast destination MAC to a unicast one accordingly.
multicast-to-unicast works on top of the multicast snooping feature of the bridge. Which means unicast copies are only delivered to hosts which are interested in it and signalized this via IGMP/MLD reports previously.
This feature is intended for interface types which have a more reliable and/or efficient way to deliver unicast packets than broadcast ones (e.g. wifi).
However, it should only be enabled on interfaces where no IGMPv2/MLDv1 report suppression takes place. This feature is disabled by default.
The initial patch and idea is from Felix Fietkau.
---
This feature is used and enabled by default in OpenWRT and LEDE for AP interfaces for more than a year now to allow both a more robust multicast delivery and multicast at higher rates (e.g. multicast streaming).
In OpenWRT/LEDE the IGMP/MLD report suppression issue is overcome by the network daemon enabling AP isolation and by that separating all STAs. Delivery of STA-to-STA IP mulitcast is made possible again by enabling and utilizing the bridge hairpin mode, which considers the incoming port as a potential outgoing port, too.
Hairpin-mode is performed after multicast snooping, therefore leading to only deliver reports to STAs running a multicast router.
Changes in v4:
* readd "From: Felix Fietkau [...]" (missed it again in v3)
Changes in v3:
* fix an uninitialized variable bug introduced in br_multicast_flood() in v2, found by kbuild test bot
Changes in v2:
* netlink support (thanks Nik!)
* fixed switching between multicast_to_unicast on/off -> even after toggling an already existing entry would stale in its mode and would never be replaced -> new extra check in br_port_group_equal)
* reduced checks in br_multicast_flood() from two to one to address fast-path concerns (thanks Nik!)
* rev-christmas tree ordering (thanks Nik!)
* removed "net_bridge_port_group::unicast", using ::flags instead (thanks Nik!)
* BR_MULTICAST_TO_UCAST -> BR_MULTICAST_TO_UNICAST (BR_MULTICAST_FLAST_LEAVE has the same length anyway)
* simplified maybe_deliver_addr()
(no return, no "prev" paramater -> was a NOP anyway)
* added "From: Felix Fietkau [...]"
* added "Signed-off-by: Felix Fietkau [...]"
--- include/linux/if_bridge.h | 1 + include/uapi/linux/if_link.h | 1 + net/bridge/br_forward.c | 37 ++++++++++++++++- net/bridge/br_mdb.c | 2 +- net/bridge/br_multicast.c | 96 ++++++++++++++++++++++++++++++++------------ net/bridge/br_netlink.c | 5 +++ net/bridge/br_private.h | 8 ++-- net/bridge/br_sysfs_if.c | 2 + 8 files changed, 121 insertions(+), 31 deletions(-)
include/linux/if_bridge.h +1 -0
@@ -46,6 +46,7 @@ struct br_ip_list {#define BR_LEARNING_SYNC BIT(9)#define BR_PROXYARP_WIFI BIT(10)#define BR_MCAST_FLOOD BIT(11) +#define BR_MULTICAST_TO_UNICAST BIT(12)#define BR_DEFAULT_AGEING_TIME (300 * HZ)
include/uapi/linux/if_link.h +1 -0
@@ -321,6 +321,7 @@ enum {IFLA_BRPORT_MULTICAST_ROUTER ,IFLA_BRPORT_PAD ,IFLA_BRPORT_MCAST_FLOOD , +IFLA_BRPORT_MCAST_TO_UCAST , __IFLA_BRPORT_MAX };#define IFLA_BRPORT_MAX (__IFLA_BRPORT_MAX - 1)
net/bridge/br_forward.c +35 -2
@@ -174,6 +174,29 @@ static struct net_bridge_port *maybe_deliver(return p; } +static void maybe_deliver_addr (struct net_bridge_port *p,struct sk_buff *skb, +const unsigned char *addr,bool local_orig) +{ +struct net_device *dev =BR_INPUT_SKB_CB (skb)->brdev; +const unsigned char *src =eth_hdr (skb)->h_source; + +if (!should_deliver (p, skb)) +return ; + +/* Even with hairpin, no soliloquies - prevent breaking IPv6 DAD */ +if (skb->dev == p->dev &ðer_addr_equal (src, addr)) +return ; + + skb =skb_copy (skb,GFP_ATOMIC ); +if (!skb) { + dev->stats.tx_dropped++; +return ; + } + +memcpy (eth_hdr (skb)->h_dest, addr,ETH_ALEN ); +__br_forward (p, skb, local_orig); +} +/* called under rcu_read_lock */ void br_flood (struct net_bridge *br,struct sk_buff *skb,enum br_pkt_type pkt_type,bool local_rcv,bool local_orig)
@@ -241,10 +264,20 @@ void br_multicast_flood(struct net_bridge_mdb_entry *mdst, rport = rp ? hlist_entry(rp, struct net_bridge_port, rlist) :NULL ; - port = (unsigned long )lport > (unsigned long )rport ? - lport : rport; +if ((unsigned long )lport > (unsigned long )rport) { + port = lport; + +if (p->flags &MDB_PG_FLAGS_MCAST_TO_UCAST ) { +maybe_deliver_addr (lport, skb, p->eth_addr, + local_orig); + goto delivered; + } + }else { + port = rport; + } prev =maybe_deliver (prev, port, skb, local_orig); +delivered:if (IS_ERR (prev)) goto out;if (prev == port)
net/bridge/br_mdb.c +1 -1
@@ -531,7 +531,7 @@ static int br_mdb_add_group(struct net_bridge *br, struct net_bridge_port *port,break ; } - p =br_multicast_new_port_group (port, group, *pp, state); + p =br_multicast_new_port_group (port, group, *pp, state,NULL );if (unlikely (!p))return -ENOMEM ;rcu_assign_pointer (*pp, p);
net/bridge/br_multicast.c +71 -25
273 lines not on this page · raw message
net/bridge/br_netlink.c +5 -0
@@ -123,6 +123,7 @@ static inline size_t br_port_info_size(void) +nla_total_size (1 )/* IFLA_BRPORT_GUARD */ +nla_total_size (1 )/* IFLA_BRPORT_PROTECT */ +nla_total_size (1 )/* IFLA_BRPORT_FAST_LEAVE */ + +nla_total_size (1 )/* IFLA_BRPORT_MCAST_TO_UCAST */ +nla_total_size (1 )/* IFLA_BRPORT_LEARNING */ +nla_total_size (1 )/* IFLA_BRPORT_UNICAST_FLOOD */ +nla_total_size (1 )/* IFLA_BRPORT_PROXYARP */
@@ -173,6 +174,8 @@ static int br_port_fill_attrs(struct sk_buff *skb, !!(p->flags & BR_ROOT_BLOCK)) ||nla_put_u8 (skb,IFLA_BRPORT_FAST_LEAVE , !!(p->flags &BR_MULTICAST_FAST_LEAVE )) || +nla_put_u8 (skb,IFLA_BRPORT_MCAST_TO_UCAST , + !!(p->flags &BR_MULTICAST_TO_UNICAST )) ||nla_put_u8 (skb,IFLA_BRPORT_LEARNING , !!(p->flags &BR_LEARNING )) ||nla_put_u8 (skb,IFLA_BRPORT_UNICAST_FLOOD , !!(p->flags & BR_FLOOD)) ||
@@ -586,6 +589,7 @@ static const struct nla_policy br_port_policy[IFLA_BRPORT_MAX + 1] = { [IFLA_BRPORT_PROXYARP] = { .type = NLA_U8 }, [IFLA_BRPORT_PROXYARP_WIFI] = { .type = NLA_U8 }, [IFLA_BRPORT_MULTICAST_ROUTER] = { .type = NLA_U8 }, + [IFLA_BRPORT_MCAST_TO_UCAST] = { .type = NLA_U8 }, };/* Change the state of the port and notify spanning tree */
@@ -636,6 +640,7 @@ static int br_setport(struct net_bridge_port *p, struct nlattr *tb[])br_set_port_flag (p, tb,IFLA_BRPORT_LEARNING ,BR_LEARNING );br_set_port_flag (p, tb,IFLA_BRPORT_UNICAST_FLOOD ,BR_FLOOD );br_set_port_flag (p, tb,IFLA_BRPORT_MCAST_FLOOD ,BR_MCAST_FLOOD ); +br_set_port_flag (p, tb,IFLA_BRPORT_MCAST_TO_UCAST ,BR_MULTICAST_TO_UNICAST );br_set_port_flag (p, tb,IFLA_BRPORT_PROXYARP ,BR_PROXYARP );br_set_port_flag (p, tb,IFLA_BRPORT_PROXYARP_WIFI ,BR_PROXYARP_WIFI );
net/bridge/br_private.h +5 -3
@@ -166,8 +166,9 @@ struct net_bridge_fdb_entrystruct rcu_head rcu; }; -#define MDB_PG_FLAGS_PERMANENT BIT(0) -#define MDB_PG_FLAGS_OFFLOAD BIT(1) +#define MDB_PG_FLAGS_PERMANENT BIT(0) +#define MDB_PG_FLAGS_OFFLOAD BIT(1) +#define MDB_PG_FLAGS_MCAST_TO_UCAST BIT(2)struct net_bridge_port_group {struct net_bridge_port *port;
@@ -177,6 +178,7 @@ struct net_bridge_port_group {struct timer_list timer;struct br_ip addr;unsigned char flags; +unsigned char eth_addr[ETH_ALEN ]; };struct net_bridge_mdb_entry
@@ -599,7 +601,7 @@ void br_multicast_free_pg(struct rcu_head *head);struct net_bridge_port_group *br_multicast_new_port_group (struct net_bridge_port *port,struct br_ip *group,struct net_bridge_port_group __rcu *next, -unsigned char flags); +unsigned char flags,const unsigned char *src);void br_mdb_init (void );void br_mdb_uninit (void ); void br_mdb_notify(struct net_device *dev, struct net_bridge_port *port,
net/bridge/br_sysfs_if.c +2 -0
@@ -188,6 +188,7 @@ static BRPORT_ATTR(multicast_router, S_IRUGO | S_IWUSR, show_multicast_router, store_multicast_router);BRPORT_ATTR_FLAG (multicast_fast_leave,BR_MULTICAST_FAST_LEAVE ); +BRPORT_ATTR_FLAG (multicast_to_unicast,BR_MULTICAST_TO_UNICAST );#endif static const struct brport_attribute *brport_attrs[] = {
@@ -214,6 +215,7 @@ static const struct brport_attribute *brport_attrs[] = {#ifdef CONFIG_BRIDGE_IGMP_SNOOPING &brport_attr_multicast_router, &brport_attr_multicast_fast_leave, + &brport_attr_multicast_to_unicast, #endif &brport_attr_proxyarp, &brport_attr_proxyarp_wifi,
Signature · 1 line
2.1.4
Quoted 64 lines · Linus Lüssing
From: Felix Fietkau <[email protected]>
Implements an optional, per bridge port flag and feature to deliver multicast packets to any host on the according port via unicast individually. This is done by copying the packet per host and changing the multicast destination MAC to a unicast one accordingly.
multicast-to-unicast works on top of the multicast snooping feature of the bridge. Which means unicast copies are only delivered to hosts which are interested in it and signalized this via IGMP/MLD reports previously.
This feature is intended for interface types which have a more reliable and/or efficient way to deliver unicast packets than broadcast ones (e.g. wifi).
However, it should only be enabled on interfaces where no IGMPv2/MLDv1 report suppression takes place. This feature is disabled by default.
The initial patch and idea is from Felix Fietkau.
Signed-off-by Felix Fietkau <[email protected]>[[email protected]: various bug + style fixes, commit message]Signed-off-by Linus Lüssing <[email protected]>---
This feature is used and enabled by default in OpenWRT and LEDE for AP interfaces for more than a year now to allow both a more robust multicast delivery and multicast at higher rates (e.g. multicast streaming).
In OpenWRT/LEDE the IGMP/MLD report suppression issue is overcome by the network daemon enabling AP isolation and by that separating all STAs. Delivery of STA-to-STA IP mulitcast is made possible again by enabling and utilizing the bridge hairpin mode, which considers the incoming port as a potential outgoing port, too.
Hairpin-mode is performed after multicast snooping, therefore leading to only deliver reports to STAs running a multicast router.
Changes in v4:
* readd "From: Felix Fietkau [...]" (missed it again in v3)Changes in v3:
* fix an uninitialized variable bug introduced inbr_multicast_flood()in v2, found by kbuild test botChanges in v2:
* netlink support (thanks Nik!)
* fixed switching betweenmulticast_to_unicaston/off -> even after toggling an already existing entry would stale in its mode and would never be replaced -> new extra check inbr_port_group_equal)
* reduced checks inbr_multicast_flood()from two to one to address fast-path concerns (thanks Nik!)
* rev-christmas tree ordering (thanks Nik!)
* removed "net_bridge_port_group::unicast", using ::flags instead (thanks Nik!)
*BR_MULTICAST_TO_UCAST->BR_MULTICAST_TO_UNICAST(BR_MULTICAST_FLAST_LEAVEhas the same length anyway)
* simplifiedmaybe_deliver_addr()
(no return, no "prev" paramater -> was a NOP anyway)
* added "From: Felix Fietkau [...]"
* added "Signed-off-by: Felix Fietkau [...]"
Quoted 11 lines
--- include/linux/if_bridge.h | 1 + include/uapi/linux/if_link.h | 1 + net/bridge/br_forward.c | 37 ++++++++++++++++- net/bridge/br_mdb.c | 2 +- net/bridge/br_multicast.c | 96 ++++++++++++++++++++++++++++++++------------ net/bridge/br_netlink.c | 5 +++ net/bridge/br_private.h | 8 ++-- net/bridge/br_sysfs_if.c | 2 + 8 files changed, 121 insertions(+), 31 deletions(-)
Looks good to me,
Quoted 16 lines · On Thu, 19 Jan 2017 03:45:10 +0100 Linus Lüssing <[email protected]>…
From: Felix Fietkau <[email protected]>
Implements an optional, per bridge port flag and feature to deliver multicast packets to any host on the according port via unicast individually. This is done by copying the packet per host and changing the multicast destination MAC to a unicast one accordingly.
multicast-to-unicast works on top of the multicast snooping feature of the bridge. Which means unicast copies are only delivered to hosts which are interested in it and signalized this via IGMP/MLD reports previously.
This feature is intended for interface types which have a more reliable and/or efficient way to deliver unicast packets than broadcast ones (e.g. wifi).
Quoted 9 lines
However, it should only be enabled on interfaces where no IGMPv2/MLDv1 report suppression takes place. This feature is disabled by default.
The initial patch and idea is from Felix Fietkau.
Signed-off-by Felix Fietkau <[email protected]>[[email protected]: various bug + style fixes, commit message]Signed-off-by Linus Lüssing <[email protected]>
In general this looks good.
One issue I see is how existing entries are handled when the bridge port flags are changed dynamically. It might be better to always record the necessary data in the bridge_port_group and not have a per-entry flag bit. In your current patch the API changes the response to future IGMP but does not take instant effect. Code would be simpler if there was less logic to handle per-entry flags.
Also, you might want to add sysfs interface for the attribute as well.