Skip to contentSkip to conversation

mlxsw: Offload bridge device mrouter

PATCH Superseded Jiri Pirko 4 participants 17 messages Oct 5, 2017 – Oct 8, 2017

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jiri Pirko

author maintainer
#0 lore raw

cover mlxsw: Offload bridge device mrouter

From: Jiri Pirko <[email protected]>

Yotam says:

Similarly to a bridged port, the bridge device itself can be configured by the user to be an mrouter port. In this case, all multicast traffic should be forwarded to it. Make the mlxsw Spectrum driver offload these directives to the Spectrum hardware.

Patches 1-3 add a new switchdev notification for bridge device mrouter port status and make the bridge module notify about it.

Patches 4-6 change the mlxsw Spectrum driver to handle these notifications by adding the Spectrum router port to the bridge MDB entries.

Yotam Gigi (6):
net: bridge: Use the MDB_RTR_TYPE_TEMP on bridge device too
net: bridge: Notify on bridge device mrouter state changes
net: bridge: Export bridge multicast router state
mlxsw: spectrum: router: Export the mlxsw_sp_router_port function
mlxsw: spectrum_switchdev: Add support for router port in SMID entries
mlxsw: spectrum_switchdev: Support bridge mrouter notifications

 .../net/ethernet/mellanox/mlxsw/spectrum_router.c  |  2 +-
 .../net/ethernet/mellanox/mlxsw/spectrum_router.h  |  1 +
 .../ethernet/mellanox/mlxsw/spectrum_switchdev.c   | 76 +++++++++++++++++++++-
 include/linux/if_bridge.h                          |  5 ++
 include/net/switchdev.h                            |  1 +
 net/bridge/br_multicast.c                          | 56 ++++++++++++++--
 net/bridge/br_netlink.c                            |  3 +-
 net/bridge/br_private.h                            | 13 +++-
 net/bridge/br_sysfs_br.c                           |  3 +-
 9 files changed, 147 insertions(+), 13 deletions(-)
Signature · 1 line
2.9.5
author maintainer
#1 lore raw

PATCH 1/6 net: bridge: Use the MDB_RTR_TYPE_TEMP on bridge device too

From: Yotam Gigi <[email protected]>

Every bridge port is in one of four mcast router port states:
- MDB_RTR_TYPE_PERM - the port is set by the user to be an mrouter port regardless of IGMP queries.
- MDB_RTR_TYPE_DISABLED - the port is set by the user to not be an mrouter port regardless of IGMP queries.
- MDB_RTR_TYPE_TEMP - the port is set by the user to be in mcast router learning state, but currently it is not an mrouter port as no IGMP query has been received by it for the last multicast_querier_interval.
- MDB_RTR_TYPE_TEMP_QUERY - the port is set by the user to be in mcast router learning state, and currently it is an mrouter port due to an IGMP query that has been received by it during the passed multicast_querier_interval.

The bridge device (brX) itself can also be configured by the user to be either fixed, disabled or learning mrouter port states, but currently there is no distinction between the MDB_RTR_TYPE_TEMP_QUERY and MDB_RTR_TYPE_TEMP in the bridge internal state. Due to that, when an IGMP query is received, it is not straightforward to tell whether it changes the bridge device mrouter port status or not.

Further patches in this patch-set will introduce notifications upon the bridge device mrouter port state. In order to prevent resending bridge mrouter notification when it is not needed, such distinction is necessary.

Hence, add the distinction between MDB_RTR_TYPE_TEMP and MDB_RTR_TYPE_TEMP_QUERY states for the bridge device, similarly to any other bridge port.

In order to not break the current kernel-user API, don't propagate the new state to the user and use it only in the bridge internal state. Thus, if the user reads (either via sysfs or netlink) the bridge device mrouter state, he will get the MDB_RTR_TYPE_TEMP_QUERY state even if the current bridge state is MDB_RTR_TYPE_TEMP.

---
 net/bridge/br_multicast.c | 25 +++++++++++++++++++++----
 net/bridge/br_netlink.c   |  3 ++-
 net/bridge/br_private.h   | 13 ++++++++++---
 net/bridge/br_sysfs_br.c  |  3 ++-
 4 files changed, 35 insertions(+), 9 deletions(-)
net/bridge/br_multicast.c +21 -4
index 8dc5c8d..b86307b 100644
@@ -861,6 +861,17 @@ static void br_multicast_router_expired(unsigned long data)
 
 static void br_multicast_local_router_expired(unsigned long data)
 {
+	struct net_bridge *br = (struct net_bridge *) data;
+
+	spin_lock(&br->multicast_lock);
+	if (br->multicast_router == MDB_RTR_TYPE_DISABLED ||
+	    br->multicast_router == MDB_RTR_TYPE_PERM ||
+	    timer_pending(&br->multicast_router_timer))
+		goto out;
+
+	br->multicast_router = MDB_RTR_TYPE_TEMP_QUERY;
+out:
+	spin_unlock(&br->multicast_lock);
 }
 
 static void br_multicast_querier_expired(struct net_bridge *br,
@@ -1364,9 +1375,12 @@ static void br_multicast_mark_router(struct net_bridge *br,
 	unsigned long now = jiffies;
 
 	if (!port) {
-		if (br->multicast_router == MDB_RTR_TYPE_TEMP_QUERY)
+		if (br->multicast_router == MDB_RTR_TYPE_TEMP_QUERY ||
+		    br->multicast_router == MDB_RTR_TYPE_TEMP) {
 			mod_timer(&br->multicast_router_timer,
 				  now + br->multicast_querier_interval);
+			br->multicast_router = MDB_RTR_TYPE_TEMP;
+		}
 		return;
 	}
 
@@ -1952,7 +1966,7 @@ void br_multicast_init(struct net_bridge *br)
 
 	spin_lock_init(&br->multicast_lock);
 	setup_timer(&br->multicast_router_timer,
-		    br_multicast_local_router_expired, 0);
+		    br_multicast_local_router_expired, (unsigned long)br);
 	setup_timer(&br->ip4_other_query.timer,
 		    br_ip4_multicast_querier_expired, (unsigned long)br);
 	setup_timer(&br->ip4_own_query.timer, br_ip4_multicast_query_expired,
@@ -2043,11 +2057,14 @@ int br_multicast_set_router(struct net_bridge *br, unsigned long val)
 	case MDB_RTR_TYPE_DISABLED:
 	case MDB_RTR_TYPE_PERM:
 		del_timer(&br->multicast_router_timer);
-		/* fall through */
-	case MDB_RTR_TYPE_TEMP_QUERY:
 		br->multicast_router = val;
 		err = 0;
 		break;
+	case MDB_RTR_TYPE_TEMP_QUERY:
+		if (br->multicast_router != MDB_RTR_TYPE_TEMP)
+			br->multicast_router = val;
+		err = 0;
+		break;
 	}
 
 	spin_unlock_bh(&br->multicast_lock);
net/bridge/br_netlink.c +2 -1
index dea88a2..cee5016 100644
@@ -1357,7 +1357,8 @@ static int br_fill_info(struct sk_buff *skb, const struct net_device *brdev)
 		return -EMSGSIZE;
 #endif
 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
-	if (nla_put_u8(skb, IFLA_BR_MCAST_ROUTER, br->multicast_router) ||
+	if (nla_put_u8(skb, IFLA_BR_MCAST_ROUTER,
+		       br_multicast_router_translate(br->multicast_router)) ||
 	    nla_put_u8(skb, IFLA_BR_MCAST_SNOOPING, !br->multicast_disabled) ||
 	    nla_put_u8(skb, IFLA_BR_MCAST_QUERY_USE_IFADDR,
 		       br->multicast_query_use_ifaddr) ||
net/bridge/br_private.h +10 -3
index ab4df24..e6e3fec 100644
@@ -649,9 +649,8 @@ void br_multicast_get_stats(const struct net_bridge *br,
 
 static inline bool br_multicast_is_router(struct net_bridge *br)
 {
-	return br->multicast_router == 2 ||
-	       (br->multicast_router == 1 &&
-		timer_pending(&br->multicast_router_timer));
+	return br->multicast_router == MDB_RTR_TYPE_PERM ||
+	       br->multicast_router == MDB_RTR_TYPE_TEMP;
 }
 
 static inline bool
@@ -790,6 +789,14 @@ static inline int br_multicast_igmp_type(const struct sk_buff *skb)
 }
 #endif
 
+static inline unsigned char
+br_multicast_router_translate(unsigned char multicast_router)
+{
+	if (multicast_router == MDB_RTR_TYPE_TEMP)
+		return MDB_RTR_TYPE_TEMP_QUERY;
+	return multicast_router;
+}
+
 /* br_vlan.c */
 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
 bool br_allowed_ingress(const struct net_bridge *br,
net/bridge/br_sysfs_br.c +2 -1
index 723f25e..9b9c597 100644
@@ -340,7 +340,8 @@ static ssize_t multicast_router_show(struct device *d,
 				     struct device_attribute *attr, char *buf)
 {
 	struct net_bridge *br = to_bridge(d);
-	return sprintf(buf, "%d\n", br->multicast_router);
+	return sprintf(buf, "%d\n",
+		       br_multicast_router_translate(br->multicast_router));
 }
 
 static ssize_t multicast_router_store(struct device *d,
Signature · 1 line
2.9.5
author maintainer
#9 lore raw

PATCH 2/6 net: bridge: Notify on bridge device mrouter state changes

In reply to Jiri Pirko

From: Yotam Gigi <[email protected]>

Add the SWITCHDEV_ATTR_ID_BRIDGE_MROUTER switchdev notification type, used to indicate whether the bridge is or isn't mrouter. Notify when the bridge changes its state, similarly to the already existing bridged port mrouter notifications.

The notification uses the switchdev_attr.u.mrouter boolean flag to indicate the current bridge mrouter status. Thus, it only indicates whether the bridge is currently used as an mrouter or not, and does not indicate the exact mrouter state of the bridge (learning, permanent, etc.).

---
 include/net/switchdev.h   |  1 +
 net/bridge/br_multicast.c | 21 ++++++++++++++++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)
include/net/switchdev.h +1 -0
index d767b79..d756fbe 100644
@@ -51,6 +51,7 @@ enum switchdev_attr_id {
 	SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME,
 	SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING,
 	SWITCHDEV_ATTR_ID_BRIDGE_MC_DISABLED,
+	SWITCHDEV_ATTR_ID_BRIDGE_MROUTER,
 };
 
 struct switchdev_attr {
net/bridge/br_multicast.c +20 -1
index b86307b..4d4fcb5 100644
@@ -859,6 +859,19 @@ static void br_multicast_router_expired(unsigned long data)
 	spin_unlock(&br->multicast_lock);
 }
 
+static void br_mc_router_state_change(struct net_bridge *p,
+				      bool is_mc_router)
+{
+	struct switchdev_attr attr = {
+		.orig_dev = p->dev,
+		.id = SWITCHDEV_ATTR_ID_BRIDGE_MROUTER,
+		.flags = SWITCHDEV_F_DEFER,
+		.u.mrouter = is_mc_router,
+	};
+
+	switchdev_port_attr_set(p->dev, &attr);
+}
+
 static void br_multicast_local_router_expired(unsigned long data)
 {
 	struct net_bridge *br = (struct net_bridge *) data;
@@ -869,6 +882,7 @@ static void br_multicast_local_router_expired(unsigned long data)
 	    timer_pending(&br->multicast_router_timer))
 		goto out;
 
+	br_mc_router_state_change(br, false);
 	br->multicast_router = MDB_RTR_TYPE_TEMP_QUERY;
 out:
 	spin_unlock(&br->multicast_lock);
@@ -1379,6 +1393,8 @@ static void br_multicast_mark_router(struct net_bridge *br,
 		    br->multicast_router == MDB_RTR_TYPE_TEMP) {
 			mod_timer(&br->multicast_router_timer,
 				  now + br->multicast_querier_interval);
+			if (br->multicast_router == MDB_RTR_TYPE_TEMP_QUERY)
+				br_mc_router_state_change(br, true);
 			br->multicast_router = MDB_RTR_TYPE_TEMP;
 		}
 		return;
@@ -2056,13 +2072,16 @@ int br_multicast_set_router(struct net_bridge *br, unsigned long val)
 	switch (val) {
 	case MDB_RTR_TYPE_DISABLED:
 	case MDB_RTR_TYPE_PERM:
+		br_mc_router_state_change(br, val == MDB_RTR_TYPE_PERM);
 		del_timer(&br->multicast_router_timer);
 		br->multicast_router = val;
 		err = 0;
 		break;
 	case MDB_RTR_TYPE_TEMP_QUERY:
-		if (br->multicast_router != MDB_RTR_TYPE_TEMP)
+		if (br->multicast_router != MDB_RTR_TYPE_TEMP) {
+			br_mc_router_state_change(br, false);
 			br->multicast_router = val;
+		}
 		err = 0;
 		break;
 	}
Signature · 1 line
2.9.5
author maintainer
#11 lore raw

PATCH 3/6 net: bridge: Export bridge multicast router state

In reply to Jiri Pirko

From: Yotam Gigi <[email protected]>

Add an access function that, given a bridge netdevice, returns whether the bridge device is currently an mrouter or not. The function uses the already existing br_multicast_is_router function to check that.

This function is needed in order to allow ports that join an already existing bridge to know the current mrouter state of the bridge device. Together with the bridge device mrouter ports switchdev notifications, it is possible to have full offloading of the semantics of the bridge device mcast router state.

Due to the fact that the bridge multicast router status can change in packet RX path, take the multicast_router bridge spinlock to protect the read.

---
 include/linux/if_bridge.h |  5 +++++
 net/bridge/br_multicast.c | 12 ++++++++++++
 2 files changed, 17 insertions(+)
include/linux/if_bridge.h +5 -0
index 3cd18ac..283a9be 100644
@@ -63,6 +63,7 @@ int br_multicast_list_adjacent(struct net_device *dev,
 bool br_multicast_has_querier_anywhere(struct net_device *dev, int proto);
 bool br_multicast_has_querier_adjacent(struct net_device *dev, int proto);
 bool br_multicast_enabled(const struct net_device *dev);
+bool br_multicast_router(const struct net_device *dev);
 #else
 static inline int br_multicast_list_adjacent(struct net_device *dev,
 					     struct list_head *br_ip_list)
@@ -83,6 +84,10 @@ static inline bool br_multicast_enabled(const struct net_device *dev)
 {
 	return false;
 }
+static inline bool br_multicast_router(const struct net_device *dev)
+{
+	return false;
+}
 #endif
 
 #if IS_ENABLED(CONFIG_BRIDGE) && IS_ENABLED(CONFIG_BRIDGE_VLAN_FILTERING)
net/bridge/br_multicast.c +12 -0
index 4d4fcb5..b4c98a3 100644
@@ -2220,6 +2220,18 @@ bool br_multicast_enabled(const struct net_device *dev)
 }
 EXPORT_SYMBOL_GPL(br_multicast_enabled);
 
+bool br_multicast_router(const struct net_device *dev)
+{
+	struct net_bridge *br = netdev_priv(dev);
+	bool is_router;
+
+	spin_lock_bh(&br->multicast_lock);
+	is_router = br_multicast_is_router(br);
+	spin_unlock_bh(&br->multicast_lock);
+	return is_router;
+}
+EXPORT_SYMBOL_GPL(br_multicast_router);
+
 int br_multicast_set_querier(struct net_bridge *br, unsigned long val)
 {
 	unsigned long max_delay;
Signature · 1 line
2.9.5
author maintainer
#13 lore raw

PATCH 4/6 mlxsw: spectrum: router: Export the mlxsw_sp_router_port function

In reply to Jiri Pirko

From: Yotam Gigi <[email protected]>

In Spectrum hardware, the router port is a virtual port that is the gateway to the routing mechanism. Hence, in order for a packet to be L3 forwarded, it must first be L2 forwarded to the router port inside the hardware.

Further patches in this patchset are going to introduce support in bridge device used as an mrouter port. In this case, the router port index will be needed in order to update the MDB entries to include the router port. Thus, export the mlxsw_sp_router_port function, which returns the index of the Spectrum router port.

---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c | 2 +-
 drivers/net/ethernet/mellanox/mlxsw/spectrum_router.h | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +1 -1
index 58bc04c..58adb23 100644
@@ -5947,7 +5947,7 @@ static int mlxsw_sp_rif_vlan_fid_op(struct mlxsw_sp_rif *rif,
 	return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(ritr), ritr_pl);
 }
 
-static u8 mlxsw_sp_router_port(const struct mlxsw_sp *mlxsw_sp)
+u8 mlxsw_sp_router_port(const struct mlxsw_sp *mlxsw_sp)
 {
 	return mlxsw_core_max_ports(mlxsw_sp->core) + 1;
 }
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.h +1 -0
index 3d44918..3f2d840 100644
@@ -70,6 +70,7 @@ u16 mlxsw_sp_rif_index(const struct mlxsw_sp_rif *rif);
 u16 mlxsw_sp_ipip_lb_rif_index(const struct mlxsw_sp_rif_ipip_lb *rif);
 u16 mlxsw_sp_ipip_lb_ul_vr_id(const struct mlxsw_sp_rif_ipip_lb *rif);
 int mlxsw_sp_rif_dev_ifindex(const struct mlxsw_sp_rif *rif);
+u8 mlxsw_sp_router_port(const struct mlxsw_sp *mlxsw_sp);
 const struct net_device *mlxsw_sp_rif_dev(const struct mlxsw_sp_rif *rif);
 int mlxsw_sp_rif_counter_value_get(struct mlxsw_sp *mlxsw_sp,
 				   struct mlxsw_sp_rif *rif,
Signature · 1 line
2.9.5
author maintainer
#14 lore raw

PATCH 5/6 mlxsw: spectrum_switchdev: Add support for router port in SMID entries

In reply to Jiri Pirko

From: Yotam Gigi <[email protected]>

In Spectrum, MDB entries point to MID entries, that indicate which ports a packet should be forwarded to. Add the support in creating MID entries that forward the packet to the Spectrum router port.

This will be later used to handle the bridge mrouter port switchdev notifications.

---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c +11 -2
index 0f9eac5..092231a 100644
@@ -48,6 +48,7 @@
 #include <linux/rtnetlink.h>
 #include <net/switchdev.h>
 
+#include "spectrum_router.h"
 #include "spectrum.h"
 #include "core.h"
 #include "reg.h"
@@ -1241,7 +1242,8 @@ static int mlxsw_sp_port_mdb_op(struct mlxsw_sp *mlxsw_sp, const char *addr,
 }
 
 static int mlxsw_sp_port_smid_full_entry(struct mlxsw_sp *mlxsw_sp, u16 mid_idx,
-					 long *ports_bitmap)
+					 long *ports_bitmap,
+					 bool set_router_port)
 {
 	char *smid_pl;
 	int err, i;
@@ -1256,9 +1258,15 @@ static int mlxsw_sp_port_smid_full_entry(struct mlxsw_sp *mlxsw_sp, u16 mid_idx,
 			mlxsw_reg_smid_port_mask_set(smid_pl, i, 1);
 	}
 
+	mlxsw_reg_smid_port_mask_set(smid_pl,
+				     mlxsw_sp_router_port(mlxsw_sp), 1);
+
 	for_each_set_bit(i, ports_bitmap, mlxsw_core_max_ports(mlxsw_sp->core))
 		mlxsw_reg_smid_port_set(smid_pl, i, 1);
 
+	mlxsw_reg_smid_port_set(smid_pl, mlxsw_sp_router_port(mlxsw_sp),
+				set_router_port);
+
 	err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(smid), smid_pl);
 	kfree(smid_pl);
 	return err;
@@ -1362,7 +1370,8 @@ mlxsw_sp_mc_write_mdb_entry(struct mlxsw_sp *mlxsw_sp,
 	mlxsw_sp_mc_get_mrouters_bitmap(flood_bitmap, bridge_device, mlxsw_sp);
 
 	mid->mid = mid_idx;
-	err = mlxsw_sp_port_smid_full_entry(mlxsw_sp, mid_idx, flood_bitmap);
+	err = mlxsw_sp_port_smid_full_entry(mlxsw_sp, mid_idx, flood_bitmap,
+					    false);
 	kfree(flood_bitmap);
 	if (err)
 		return false;
Signature · 1 line
2.9.5
author maintainer
#15 lore raw

PATCH 6/6 mlxsw: spectrum_switchdev: Support bridge mrouter notifications

In reply to Jiri Pirko

From: Yotam Gigi <[email protected]>

Support the SWITCHDEV_ATTR_ID_BRIDGE_MROUTER port attribute switchdev notification.

To do that, add the mrouter flag to struct mlxsw_sp_bridge_device, which indicates whether the bridge device was set to be mrouter port. This field is set when:
- A new bridge is created, where the value is taken from the kernel bridge value.
- A switchdev SWITCHDEV_ATTR_ID_BRIDGE_MROUTER notification is sent.

In addition, change the bridge MID entries to include the router port when the bridge device is configured to be mrouter port. The MID entries are updated in the following cases:
- When a new MID entry is created, update the router port according to the bridge mrouter state.
- When a SWITCHDEV_ATTR_ID_BRIDGE_MROUTER notification is sent, update all the bridge's MID entries.

This is aligned with the case where a bridge slave is configured to be mrouter port.

---
 .../ethernet/mellanox/mlxsw/spectrum_switchdev.c   | 65 +++++++++++++++++++++-
 1 file changed, 63 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c +63 -2
index 092231a..15bb5f9 100644
@@ -79,7 +79,8 @@ struct mlxsw_sp_bridge_device {
 	struct list_head ports_list;
 	struct list_head mids_list;
 	u8 vlan_enabled:1,
-	   multicast_enabled:1;
+	   multicast_enabled:1,
+	   mrouter:1;
 	const struct mlxsw_sp_bridge_ops *ops;
 };
 
@@ -169,6 +170,7 @@ mlxsw_sp_bridge_device_create(struct mlxsw_sp_bridge *bridge,
 	bridge_device->dev = br_dev;
 	bridge_device->vlan_enabled = vlan_enabled;
 	bridge_device->multicast_enabled = br_multicast_enabled(br_dev);
+	bridge_device->mrouter = br_multicast_router(br_dev);
 	INIT_LIST_HEAD(&bridge_device->ports_list);
 	if (vlan_enabled) {
 		bridge->vlan_enabled_exists = true;
@@ -811,6 +813,60 @@ static int mlxsw_sp_port_mc_disabled_set(struct mlxsw_sp_port *mlxsw_sp_port,
 	return 0;
 }
 
+static int mlxsw_sp_smid_router_port_set(struct mlxsw_sp *mlxsw_sp,
+					 u16 mid_idx, bool add)
+{
+	char *smid_pl;
+	int err;
+
+	smid_pl = kmalloc(MLXSW_REG_SMID_LEN, GFP_KERNEL);
+	if (!smid_pl)
+		return -ENOMEM;
+
+	mlxsw_reg_smid_pack(smid_pl, mid_idx,
+			    mlxsw_sp_router_port(mlxsw_sp), add);
+	err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(smid), smid_pl);
+	kfree(smid_pl);
+	return err;
+}
+
+static void
+mlxsw_sp_bridge_mrouter_update_mdb(struct mlxsw_sp *mlxsw_sp,
+				   struct mlxsw_sp_bridge_device *bridge_device,
+				   bool add)
+{
+	struct mlxsw_sp_mid *mid;
+
+	list_for_each_entry(mid, &bridge_device->mids_list, list)
+		mlxsw_sp_smid_router_port_set(mlxsw_sp, mid->mid, add);
+}
+
+static int
+mlxsw_sp_port_attr_br_mrouter_set(struct mlxsw_sp_port *mlxsw_sp_port,
+				  struct switchdev_trans *trans,
+				  struct net_device *orig_dev,
+				  bool is_mrouter)
+{
+	struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
+	struct mlxsw_sp_bridge_device *bridge_device;
+
+	if (switchdev_trans_ph_prepare(trans))
+		return 0;
+
+	/* It's possible we failed to enslave the port, yet this
+	 * operation is executed due to it being deferred.
+	 */
+	bridge_device = mlxsw_sp_bridge_device_find(mlxsw_sp->bridge, orig_dev);
+	if (!bridge_device)
+		return 0;
+
+	if (bridge_device->mrouter != is_mrouter)
+		mlxsw_sp_bridge_mrouter_update_mdb(mlxsw_sp, bridge_device,
+						   is_mrouter);
+	bridge_device->mrouter = is_mrouter;
+	return 0;
+}
+
 static int mlxsw_sp_port_attr_set(struct net_device *dev,
 				  const struct switchdev_attr *attr,
 				  struct switchdev_trans *trans)
@@ -848,6 +904,11 @@ static int mlxsw_sp_port_attr_set(struct net_device *dev,
 						    attr->orig_dev,
 						    attr->u.mc_disabled);
 		break;
+	case SWITCHDEV_ATTR_ID_BRIDGE_MROUTER:
+		err = mlxsw_sp_port_attr_br_mrouter_set(mlxsw_sp_port, trans,
+							attr->orig_dev,
+							attr->u.mrouter);
+		break;
 	default:
 		err = -EOPNOTSUPP;
 		break;
@@ -1371,7 +1432,7 @@ mlxsw_sp_mc_write_mdb_entry(struct mlxsw_sp *mlxsw_sp,
 
 	mid->mid = mid_idx;
 	err = mlxsw_sp_port_smid_full_entry(mlxsw_sp, mid_idx, flood_bitmap,
-					    false);
+					    bridge_device->mrouter);
 	kfree(flood_bitmap);
 	if (err)
 		return false;
Signature · 1 line
2.9.5
#2 lore raw

Re: [patch net-next 1/6] net: bridge: Use the MDB_RTR_TYPE_TEMP on bridge device too

In reply to Jiri Pirko
Quoted 14 lines · Jiri Pirko

From: Yotam Gigi <[email protected]>

Every bridge port is in one of four mcast router port states:
- MDB_RTR_TYPE_PERM - the port is set by the user to be an mrouter port regardless of IGMP queries.
- MDB_RTR_TYPE_DISABLED - the port is set by the user to not be an mrouter port regardless of IGMP queries.
- MDB_RTR_TYPE_TEMP - the port is set by the user to be in mcast router learning state, but currently it is not an mrouter port as no IGMP query has been received by it for the last multicast_querier_interval.
- MDB_RTR_TYPE_TEMP_QUERY - the port is set by the user to be in mcast router learning state, and currently it is an mrouter port due to an IGMP query that has been received by it during the passed multicast_querier_interval.

I think you got the last two partially mixed up, MDB_RTR_TYPE_TEMP marks the port as a router regardless if there were any igmp queries, while TYPE_TEMP_QUERY means it's in learning state. It is the timer (armed vs not) that defines if currently the port is a router when one of the TEMP/TEMP_QUERY are set. In the _TEMP case it is always armed as it is refreshed by user or igmp queries which was the point of that mode.
So this means in br_multicast_router() just check for the timer_pending or perm mode.

In the port code you have the following transitions:
_TEMP -> TEMP_QUERY (on timer fire or user-set val, port becomes learning only) _TEMP -> _TEMP (noop on user refresh or igmp query, timer refreshes) _TEMP_QUERY -> _TEMP_QUERY (on igmp query the timer is armed, port becomes router)

you never have _TEMP_QUERY -> _TEMP, which you're using here to denote the timer getting armed and the bridge becoming a router.

Quoted 7 lines

The bridge device (brX) itself can also be configured by the user to be either fixed, disabled or learning mrouter port states, but currently there is no distinction between the MDB_RTR_TYPE_TEMP_QUERY and MDB_RTR_TYPE_TEMP in the bridge internal state. Due to that, when an IGMP query is received, it is not straightforward to tell whether it changes the bridge device mrouter port status or not.

But before this patch the bridge device could not get that set.

Quoted 5 lines

Further patches in this patch-set will introduce notifications upon the bridge device mrouter port state. In order to prevent resending bridge mrouter notification when it is not needed, such distinction is necessary.

Granted the bridge device hasn't got a way to clearly distinguish the transitions without the chance for a race and if using the timer one could get an unnecessary notification but that seems like a corner case when the timer fires exactly at the same time as the igmp query is received. Can't it be handled by just checking if the new state is different in the notification receiver ?
If it can't and is a problem then I'd prefer to add a new boolean to denote that router on/off transition rather than doing this.

Quoted 4 lines

Hence, add the distinction between MDB_RTR_TYPE_TEMP and MDB_RTR_TYPE_TEMP_QUERY states for the bridge device, similarly to any other bridge port.

This does not add proper MDB_RTR_TYPE_TEMP support for the bridge device but seems to abuse it to distinguish the timer state, and changes the meaning of MDB_RTR_TYPE_TEMP. Can't you just use the timer instead ? I think it will simplify the set and avoid all of this.

Quoted 109 lines

In order to not break the current kernel-user API, don't propagate the new state to the user and use it only in the bridge internal state. Thus, if the user reads (either via sysfs or netlink) the bridge device mrouter state, he will get the MDB_RTR_TYPE_TEMP_QUERY state even if the current bridge state is MDB_RTR_TYPE_TEMP.

---
 net/bridge/br_multicast.c | 25 +++++++++++++++++++++----
 net/bridge/br_netlink.c   |  3 ++-
 net/bridge/br_private.h   | 13 ++++++++++---
 net/bridge/br_sysfs_br.c  |  3 ++-
 4 files changed, 35 insertions(+), 9 deletions(-)
net/bridge/br_multicast.c +21 -4
index 8dc5c8d..b86307b 100644
@@ -861,6 +861,17 @@ static void br_multicast_router_expired(unsigned long data)
 
 static void br_multicast_local_router_expired(unsigned long data)
 {
+	struct net_bridge *br = (struct net_bridge *) data;
+
+	spin_lock(&br->multicast_lock);
+	if (br->multicast_router == MDB_RTR_TYPE_DISABLED ||
+	    br->multicast_router == MDB_RTR_TYPE_PERM ||
+	    timer_pending(&br->multicast_router_timer))
+		goto out;
+
+	br->multicast_router = MDB_RTR_TYPE_TEMP_QUERY;
+out:
+	spin_unlock(&br->multicast_lock);
 }
 
 static void br_multicast_querier_expired(struct net_bridge *br,
@@ -1364,9 +1375,12 @@ static void br_multicast_mark_router(struct net_bridge *br,
 	unsigned long now = jiffies;
 
 	if (!port) {
-		if (br->multicast_router == MDB_RTR_TYPE_TEMP_QUERY)
+		if (br->multicast_router == MDB_RTR_TYPE_TEMP_QUERY ||
+		    br->multicast_router == MDB_RTR_TYPE_TEMP) {
 			mod_timer(&br->multicast_router_timer,
 				  now + br->multicast_querier_interval);
+			br->multicast_router = MDB_RTR_TYPE_TEMP;
+		}
 		return;
 	}
 
@@ -1952,7 +1966,7 @@ void br_multicast_init(struct net_bridge *br)
 
 	spin_lock_init(&br->multicast_lock);
 	setup_timer(&br->multicast_router_timer,
-		    br_multicast_local_router_expired, 0);
+		    br_multicast_local_router_expired, (unsigned long)br);
 	setup_timer(&br->ip4_other_query.timer,
 		    br_ip4_multicast_querier_expired, (unsigned long)br);
 	setup_timer(&br->ip4_own_query.timer, br_ip4_multicast_query_expired,
@@ -2043,11 +2057,14 @@ int br_multicast_set_router(struct net_bridge *br, unsigned long val)
 	case MDB_RTR_TYPE_DISABLED:
 	case MDB_RTR_TYPE_PERM:
 		del_timer(&br->multicast_router_timer);
-		/* fall through */
-	case MDB_RTR_TYPE_TEMP_QUERY:
 		br->multicast_router = val;
 		err = 0;
 		break;
+	case MDB_RTR_TYPE_TEMP_QUERY:
+		if (br->multicast_router != MDB_RTR_TYPE_TEMP)
+			br->multicast_router = val;
+		err = 0;
+		break;
 	}
 
 	spin_unlock_bh(&br->multicast_lock);
net/bridge/br_netlink.c +2 -1
index dea88a2..cee5016 100644
@@ -1357,7 +1357,8 @@ static int br_fill_info(struct sk_buff *skb, const struct net_device *brdev)
 		return -EMSGSIZE;
 #endif
 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
-	if (nla_put_u8(skb, IFLA_BR_MCAST_ROUTER, br->multicast_router) ||
+	if (nla_put_u8(skb, IFLA_BR_MCAST_ROUTER,
+		       br_multicast_router_translate(br->multicast_router)) ||
 	    nla_put_u8(skb, IFLA_BR_MCAST_SNOOPING, !br->multicast_disabled) ||
 	    nla_put_u8(skb, IFLA_BR_MCAST_QUERY_USE_IFADDR,
 		       br->multicast_query_use_ifaddr) ||
net/bridge/br_private.h +2 -3
index ab4df24..e6e3fec 100644
@@ -649,9 +649,8 @@ void br_multicast_get_stats(const struct net_bridge *br,
 
 static inline bool br_multicast_is_router(struct net_bridge *br)
 {
-	return br->multicast_router == 2 ||
-	       (br->multicast_router == 1 &&
-		timer_pending(&br->multicast_router_timer));
+	return br->multicast_router == MDB_RTR_TYPE_PERM ||
+	       br->multicast_router == MDB_RTR_TYPE_TEMP;
 }
 
 static inline bool

net/bridge/br_private.h static inline int br_multicast_igmp_type(const struct sk_buff *skb) · line 792

Quoted 4 lines
net/bridge/br_private.h +1 -0
@@ -790,6 +789,14 @@ static inline int br_multicast_igmp_type(const struct sk_buff *skb)
 }
 #endif
 
+static inline unsigned char

u8

net/bridge/br_private.h static inline int br_multicast_igmp_type(const struct sk_buff *skb) · line 793

Quoted 1 line
net/bridge/br_private.h +1 -0
+br_multicast_router_translate(unsigned char multicast_router)

u8, if need be change the type of the struct member

Quoted 24 lines
net/bridge/br_private.h +6 -0
+{
+	if (multicast_router == MDB_RTR_TYPE_TEMP)
+		return MDB_RTR_TYPE_TEMP_QUERY;
+	return multicast_router;
+}
+
 /* br_vlan.c */
 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
 bool br_allowed_ingress(const struct net_bridge *br,
net/bridge/br_sysfs_br.c +2 -1
index 723f25e..9b9c597 100644
@@ -340,7 +340,8 @@ static ssize_t multicast_router_show(struct device *d,
 				     struct device_attribute *attr, char *buf)
 {
 	struct net_bridge *br = to_bridge(d);
-	return sprintf(buf, "%d\n", br->multicast_router);
+	return sprintf(buf, "%d\n",
+		       br_multicast_router_translate(br->multicast_router));
 }
 
 static ssize_t multicast_router_store(struct device *d,
#3 lore raw

Re: [patch net-next 1/6] net: bridge: Use the MDB_RTR_TYPE_TEMP on bridge device too

Quoted 23 lines · Nikolay Aleksandrov
Quoted 14 lines · Jiri Pirko

From: Yotam Gigi <[email protected]>

Every bridge port is in one of four mcast router port states:
- MDB_RTR_TYPE_PERM - the port is set by the user to be an mrouter port regardless of IGMP queries.
- MDB_RTR_TYPE_DISABLED - the port is set by the user to not be an mrouter port regardless of IGMP queries.
- MDB_RTR_TYPE_TEMP - the port is set by the user to be in mcast router learning state, but currently it is not an mrouter port as no IGMP query has been received by it for the last multicast_querier_interval.
- MDB_RTR_TYPE_TEMP_QUERY - the port is set by the user to be in mcast router learning state, and currently it is an mrouter port due to an IGMP query that has been received by it during the passed multicast_querier_interval.

I think you got the last two partially mixed up, MDB_RTR_TYPE_TEMP marks the port as a router regardless if there were any igmp queries, while TYPE_TEMP_QUERY means it's in learning state. It is the timer (armed vs not) that defines if currently the port is a router when one of the TEMP/TEMP_QUERY are set. In the _TEMP case it is always armed as it is refreshed by user or igmp queries which was the point of that mode.
So this means in br_multicast_router() just check for the timer_pending or perm mode.

Quoted 7 lines

In the port code you have the following transitions:
_TEMP -> TEMP_QUERY (on timer fire or user-set val, port becomes learning only) _TEMP -> _TEMP (noop on user refresh or igmp query, timer refreshes) _TEMP_QUERY -> _TEMP_QUERY (on igmp query the timer is armed, port becomes router)

you never have _TEMP_QUERY -> _TEMP, which you're using here to denote the timer getting armed and the bridge becoming a router.

Okay, technically the user can change the mode in such way manually. But it is not done automatically is what I was trying to say.

Quoted 180 lines
Quoted 8 lines

The bridge device (brX) itself can also be configured by the user to be either fixed, disabled or learning mrouter port states, but currently there is no distinction between the MDB_RTR_TYPE_TEMP_QUERY and MDB_RTR_TYPE_TEMP in the bridge internal state. Due to that, when an IGMP query is received, it is not straightforward to tell whether it changes the bridge device mrouter port status or not.

But before this patch the bridge device could not get that set.

Quoted 5 lines

Further patches in this patch-set will introduce notifications upon the bridge device mrouter port state. In order to prevent resending bridge mrouter notification when it is not needed, such distinction is necessary.

Granted the bridge device hasn't got a way to clearly distinguish the transitions without the chance for a race and if using the timer one could get an unnecessary notification but that seems like a corner case when the timer fires exactly at the same time as the igmp query is received. Can't it be handled by just checking if the new state is different in the notification receiver ?
If it can't and is a problem then I'd prefer to add a new boolean to denote that router on/off transition rather than doing this.

Quoted 4 lines

Hence, add the distinction between MDB_RTR_TYPE_TEMP and MDB_RTR_TYPE_TEMP_QUERY states for the bridge device, similarly to any other bridge port.

This does not add proper MDB_RTR_TYPE_TEMP support for the bridge device but seems to abuse it to distinguish the timer state, and changes the meaning of MDB_RTR_TYPE_TEMP. Can't you just use the timer instead ? I think it will simplify the set and avoid all of this.

Quoted 109 lines

In order to not break the current kernel-user API, don't propagate the new state to the user and use it only in the bridge internal state. Thus, if the user reads (either via sysfs or netlink) the bridge device mrouter state, he will get the MDB_RTR_TYPE_TEMP_QUERY state even if the current bridge state is MDB_RTR_TYPE_TEMP.

---
 net/bridge/br_multicast.c | 25 +++++++++++++++++++++----
 net/bridge/br_netlink.c   |  3 ++-
 net/bridge/br_private.h   | 13 ++++++++++---
 net/bridge/br_sysfs_br.c  |  3 ++-
 4 files changed, 35 insertions(+), 9 deletions(-)
net/bridge/br_multicast.c +21 -4
index 8dc5c8d..b86307b 100644
@@ -861,6 +861,17 @@ static void br_multicast_router_expired(unsigned long data)
 
 static void br_multicast_local_router_expired(unsigned long data)
 {
+	struct net_bridge *br = (struct net_bridge *) data;
+
+	spin_lock(&br->multicast_lock);
+	if (br->multicast_router == MDB_RTR_TYPE_DISABLED ||
+	    br->multicast_router == MDB_RTR_TYPE_PERM ||
+	    timer_pending(&br->multicast_router_timer))
+		goto out;
+
+	br->multicast_router = MDB_RTR_TYPE_TEMP_QUERY;
+out:
+	spin_unlock(&br->multicast_lock);
 }
 
 static void br_multicast_querier_expired(struct net_bridge *br,
@@ -1364,9 +1375,12 @@ static void br_multicast_mark_router(struct net_bridge *br,
 	unsigned long now = jiffies;
 
 	if (!port) {
-		if (br->multicast_router == MDB_RTR_TYPE_TEMP_QUERY)
+		if (br->multicast_router == MDB_RTR_TYPE_TEMP_QUERY ||
+		    br->multicast_router == MDB_RTR_TYPE_TEMP) {
 			mod_timer(&br->multicast_router_timer,
 				  now + br->multicast_querier_interval);
+			br->multicast_router = MDB_RTR_TYPE_TEMP;
+		}
 		return;
 	}
 
@@ -1952,7 +1966,7 @@ void br_multicast_init(struct net_bridge *br)
 
 	spin_lock_init(&br->multicast_lock);
 	setup_timer(&br->multicast_router_timer,
-		    br_multicast_local_router_expired, 0);
+		    br_multicast_local_router_expired, (unsigned long)br);
 	setup_timer(&br->ip4_other_query.timer,
 		    br_ip4_multicast_querier_expired, (unsigned long)br);
 	setup_timer(&br->ip4_own_query.timer, br_ip4_multicast_query_expired,
@@ -2043,11 +2057,14 @@ int br_multicast_set_router(struct net_bridge *br, unsigned long val)
 	case MDB_RTR_TYPE_DISABLED:
 	case MDB_RTR_TYPE_PERM:
 		del_timer(&br->multicast_router_timer);
-		/* fall through */
-	case MDB_RTR_TYPE_TEMP_QUERY:
 		br->multicast_router = val;
 		err = 0;
 		break;
+	case MDB_RTR_TYPE_TEMP_QUERY:
+		if (br->multicast_router != MDB_RTR_TYPE_TEMP)
+			br->multicast_router = val;
+		err = 0;
+		break;
 	}
 
 	spin_unlock_bh(&br->multicast_lock);
net/bridge/br_netlink.c +2 -1
index dea88a2..cee5016 100644
@@ -1357,7 +1357,8 @@ static int br_fill_info(struct sk_buff *skb, const struct net_device *brdev)
 		return -EMSGSIZE;
 #endif
 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
-	if (nla_put_u8(skb, IFLA_BR_MCAST_ROUTER, br->multicast_router) ||
+	if (nla_put_u8(skb, IFLA_BR_MCAST_ROUTER,
+		       br_multicast_router_translate(br->multicast_router)) ||
 	    nla_put_u8(skb, IFLA_BR_MCAST_SNOOPING, !br->multicast_disabled) ||
 	    nla_put_u8(skb, IFLA_BR_MCAST_QUERY_USE_IFADDR,
 		       br->multicast_query_use_ifaddr) ||
net/bridge/br_private.h +2 -3
index ab4df24..e6e3fec 100644
@@ -649,9 +649,8 @@ void br_multicast_get_stats(const struct net_bridge *br,
 
 static inline bool br_multicast_is_router(struct net_bridge *br)
 {
-	return br->multicast_router == 2 ||
-	       (br->multicast_router == 1 &&
-		timer_pending(&br->multicast_router_timer));
+	return br->multicast_router == MDB_RTR_TYPE_PERM ||
+	       br->multicast_router == MDB_RTR_TYPE_TEMP;
 }
 
 static inline bool

net/bridge/br_private.h static inline int br_multicast_igmp_type(const struct sk_buff *skb) · line 792

Quoted 4 lines
net/bridge/br_private.h +1 -0
@@ -790,6 +789,14 @@ static inline int br_multicast_igmp_type(const struct sk_buff *skb)
 }
 #endif
 
+static inline unsigned char

u8

net/bridge/br_private.h static inline int br_multicast_igmp_type(const struct sk_buff *skb) · line 793

Quoted 1 line
net/bridge/br_private.h +1 -0
+br_multicast_router_translate(unsigned char multicast_router)

u8, if need be change the type of the struct member

Quoted 24 lines
net/bridge/br_private.h +6 -0
+{
+	if (multicast_router == MDB_RTR_TYPE_TEMP)
+		return MDB_RTR_TYPE_TEMP_QUERY;
+	return multicast_router;
+}
+
 /* br_vlan.c */
 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
 bool br_allowed_ingress(const struct net_bridge *br,
net/bridge/br_sysfs_br.c +2 -1
index 723f25e..9b9c597 100644
@@ -340,7 +340,8 @@ static ssize_t multicast_router_show(struct device *d,
 				     struct device_attribute *attr, char *buf)
 {
 	struct net_bridge *br = to_bridge(d);
-	return sprintf(buf, "%d\n", br->multicast_router);
+	return sprintf(buf, "%d\n",
+		       br_multicast_router_translate(br->multicast_router));
 }
 
 static ssize_t multicast_router_store(struct device *d,
#4 lore raw

Re: [patch net-next 1/6] net: bridge: Use the MDB_RTR_TYPE_TEMP on bridge device too

In reply to Nikolay Aleksandrov
Quoted 47 lines · Nikolay Aleksandrov
Quoted 14 lines · Jiri Pirko

From: Yotam Gigi <[email protected]>

Every bridge port is in one of four mcast router port states:
- MDB_RTR_TYPE_PERM - the port is set by the user to be an mrouter port regardless of IGMP queries.
- MDB_RTR_TYPE_DISABLED - the port is set by the user to not be an mrouter port regardless of IGMP queries.
- MDB_RTR_TYPE_TEMP - the port is set by the user to be in mcast router learning state, but currently it is not an mrouter port as no IGMP query has been received by it for the last multicast_querier_interval.
- MDB_RTR_TYPE_TEMP_QUERY - the port is set by the user to be in mcast router learning state, and currently it is an mrouter port due to an IGMP query that has been received by it during the passed multicast_querier_interval.

I think you got the last two partially mixed up, MDB_RTR_TYPE_TEMP marks the port as a router regardless if there were any igmp queries, while TYPE_TEMP_QUERY means it's in learning state. It is the timer (armed vs not) that defines if currently the port is a router when one of the TEMP/TEMP_QUERY are set. In the _TEMP case it is always armed as it is refreshed by user or igmp queries which was the point of that mode.
So this means in br_multicast_router() just check for the timer_pending or perm mode.

In the port code you have the following transitions:
_TEMP -> TEMP_QUERY (on timer fire or user-set val, port becomes learning only) _TEMP -> _TEMP (noop on user refresh or igmp query, timer refreshes) _TEMP_QUERY -> _TEMP_QUERY (on igmp query the timer is armed, port becomes router)

you never have _TEMP_QUERY -> _TEMP, which you're using here to denote the timer getting armed and the bridge becoming a router.

Quoted 7 lines

The bridge device (brX) itself can also be configured by the user to be either fixed, disabled or learning mrouter port states, but currently there is no distinction between the MDB_RTR_TYPE_TEMP_QUERY and MDB_RTR_TYPE_TEMP in the bridge internal state. Due to that, when an IGMP query is received, it is not straightforward to tell whether it changes the bridge device mrouter port status or not.

But before this patch the bridge device could not get that set.

Quoted 5 lines

Further patches in this patch-set will introduce notifications upon the bridge device mrouter port state. In order to prevent resending bridge mrouter notification when it is not needed, such distinction is necessary.

Quoted 5 lines

Granted the bridge device hasn't got a way to clearly distinguish the transitions without the chance for a race and if using the timer one could get an unnecessary notification but that seems like a corner case when the timer fires exactly at the same time as the igmp query is received. Can't it be handled by just checking if the new state is different in the notification receiver ?

Scratch the sentence below, on a second thought I'd prefer to stick with this version if it's a problem. :-)

Quoted 19 lines

If it can't and is a problem then I'd prefer to add a new boolean to denote that router on/off transition rather than doing this.

Quoted 4 lines

Hence, add the distinction between MDB_RTR_TYPE_TEMP and MDB_RTR_TYPE_TEMP_QUERY states for the bridge device, similarly to any other bridge port.

This does not add proper MDB_RTR_TYPE_TEMP support for the bridge device but seems to abuse it to distinguish the timer state, and changes the meaning of MDB_RTR_TYPE_TEMP. Can't you just use the timer instead ? I think it will simplify the set and avoid all of this.

Quoted 6 lines

In order to not break the current kernel-user API, don't propagate the new state to the user and use it only in the bridge internal state. Thus, if the user reads (either via sysfs or netlink) the bridge device mrouter state, he will get the MDB_RTR_TYPE_TEMP_QUERY state even if the current bridge state is MDB_RTR_TYPE_TEMP.

[snip]

Reviewed-by on v1 3/6
#12 lore raw

Re: [patch net-next 3/6] net: bridge: Export bridge multicast router state

In reply to Jiri Pirko
Quoted 16 lines · Jiri Pirko

From: Yotam Gigi <[email protected]>

Add an access function that, given a bridge netdevice, returns whether the bridge device is currently an mrouter or not. The function uses the already existing br_multicast_is_router function to check that.

This function is needed in order to allow ports that join an already existing bridge to know the current mrouter state of the bridge device. Together with the bridge device mrouter ports switchdev notifications, it is possible to have full offloading of the semantics of the bridge device mcast router state.

Due to the fact that the bridge multicast router status can change in packet RX path, take the multicast_router bridge spinlock to protect the read.

Quoted 8 lines
---
 include/linux/if_bridge.h |  5 +++++
 net/bridge/br_multicast.c | 12 ++++++++++++
 2 files changed, 17 insertions(+)
Reviewed-by on v1 2/6
#10 lore raw

Re: [patch net-next 2/6] net: bridge: Notify on bridge device mrouter state changes

In reply to Jiri Pirko
Quoted 12 lines · Jiri Pirko

From: Yotam Gigi <[email protected]>

Add the SWITCHDEV_ATTR_ID_BRIDGE_MROUTER switchdev notification type, used to indicate whether the bridge is or isn't mrouter. Notify when the bridge changes its state, similarly to the already existing bridged port mrouter notifications.

The notification uses the switchdev_attr.u.mrouter boolean flag to indicate the current bridge mrouter status. Thus, it only indicates whether the bridge is currently used as an mrouter or not, and does not indicate the exact mrouter state of the bridge (learning, permanent, etc.).

Quoted 8 lines
---
 include/net/switchdev.h   |  1 +
 net/bridge/br_multicast.c | 21 ++++++++++++++++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

LGTM, but if we switch to using the timer state it will need some adjustment. Anyway for this version,

maintainer
#16 lore raw
In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>
Date: Thu, 5 Oct 2017 12:36:36 +0200

Quoted 9 lines

From: Jiri Pirko <[email protected]>

Yotam says:

Similarly to a bridged port, the bridge device itself can be configured by the user to be an mrouter port. In this case, all multicast traffic should be forwarded to it. Make the mlxsw Spectrum driver offload these directives to the Spectrum hardware.

Quoted 5 lines

Patches 1-3 add a new switchdev notification for bridge device mrouter port status and make the bridge module notify about it.

Patches 4-6 change the mlxsw Spectrum driver to handle these notifications by adding the Spectrum router port to the bridge MDB entries.

It looks like Nikolay wants some feedback addressed for patch #1.

Thanks.

#5 lore raw

Re: [patch net-next 1/6] net: bridge: Use the MDB_RTR_TYPE_TEMP on bridge device too

In reply to Nikolay Aleksandrov
Quoted 15 lines · Nikolay Aleksandrov
Quoted 14 lines · Jiri Pirko

From: Yotam Gigi <[email protected]>

Every bridge port is in one of four mcast router port states:
- MDB_RTR_TYPE_PERM - the port is set by the user to be an mrouter port regardless of IGMP queries.
- MDB_RTR_TYPE_DISABLED - the port is set by the user to not be an mrouter port regardless of IGMP queries.
- MDB_RTR_TYPE_TEMP - the port is set by the user to be in mcast router learning state, but currently it is not an mrouter port as no IGMP query has been received by it for the last multicast_querier_interval.
- MDB_RTR_TYPE_TEMP_QUERY - the port is set by the user to be in mcast router learning state, and currently it is an mrouter port due to an IGMP query that has been received by it during the passed multicast_querier_interval.

Quoted 6 lines

I think you got the last two partially mixed up, MDB_RTR_TYPE_TEMP marks the port as a router regardless if there were any igmp queries, while TYPE_TEMP_QUERY means it's in learning state. It is the timer (armed vs not) that defines if currently the port is a router when one of the TEMP/TEMP_QUERY are set. In the _TEMP case it is always armed as it is refreshed by user or igmp queries which was the point of that mode.
So this means in br_multicast_router() just check for the timer_pending or perm mode.

As much as I tried to make this clear, it seems like I failed :)

The 4 states I described are currently the "bridged port" states, not the "bridge device" state. A bridged port has these 4 states, all can be set by the user, while the bridge device only uses 3 of these states. This patch makes the bridge device use the 4 states too. I thought it makes sense.

The first paragraph describes the current states of a bridged port, and the second one explains the difference between bridged port and bridge device. I will (try to) make it clearer if we agree on resending this patch.

Is it clearer now?

Quoted 8 lines

In the port code you have the following transitions:
_TEMP -> TEMP_QUERY (on timer fire or user-set val, port becomes learning only) _TEMP -> _TEMP (noop on user refresh or igmp query, timer refreshes) _TEMP_QUERY -> _TEMP_QUERY (on igmp query the timer is armed, port becomes router)

you never have _TEMP_QUERY -> _TEMP, which you're using here to denote the timer getting armed and the bridge becoming a router.

I am not sure I got this one. I do address that: when an IGMP query is recieved and the current state is _TEMP_QUERY, I arm the timer and set the state to _TEMP. I marked that place on the patch, so you can see below.

Quoted 7 lines
Quoted 7 lines

The bridge device (brX) itself can also be configured by the user to be either fixed, disabled or learning mrouter port states, but currently there is no distinction between the MDB_RTR_TYPE_TEMP_QUERY and MDB_RTR_TYPE_TEMP in the bridge internal state. Due to that, when an IGMP query is received, it is not straightforward to tell whether it changes the bridge device mrouter port status or not.

Quoted 8 lines

But before this patch the bridge device could not get that set.

Quoted 4 lines

Further patches in this patch-set will introduce notifications upon the bridge device mrouter port state. In order to prevent resending bridge mrouter notification when it is not needed, such distinction is necessary.

Granted the bridge device hasn't got a way to clearly distinguish the transitions without the chance for a race and if using the timer one could get an unnecessary

Is there a race condition?

Quoted 56 lines

notification but that seems like a corner case when the timer fires exactly at the same time as the igmp query is received. Can't it be handled by just checking if the new state is different in the notification receiver ?
If it can't and is a problem then I'd prefer to add a new boolean to denote that router on/off transition rather than doing this.

Quoted 4 lines

Hence, add the distinction between MDB_RTR_TYPE_TEMP and MDB_RTR_TYPE_TEMP_QUERY states for the bridge device, similarly to any other bridge port.

This does not add proper MDB_RTR_TYPE_TEMP support for the bridge device but seems to abuse it to distinguish the timer state, and changes the meaning of MDB_RTR_TYPE_TEMP. Can't you just use the timer instead ? I think it will simplify the set and avoid all of this.

Quoted 41 lines

In order to not break the current kernel-user API, don't propagate the new state to the user and use it only in the bridge internal state. Thus, if the user reads (either via sysfs or netlink) the bridge device mrouter state, he will get the MDB_RTR_TYPE_TEMP_QUERY state even if the current bridge state is MDB_RTR_TYPE_TEMP.

---
 net/bridge/br_multicast.c | 25 +++++++++++++++++++++----
 net/bridge/br_netlink.c   |  3 ++-
 net/bridge/br_private.h   | 13 ++++++++++---
 net/bridge/br_sysfs_br.c  |  3 ++-
 4 files changed, 35 insertions(+), 9 deletions(-)
net/bridge/br_multicast.c +11 -0
index 8dc5c8d..b86307b 100644
@@ -861,6 +861,17 @@ static void br_multicast_router_expired(unsigned long data)
 
 static void br_multicast_local_router_expired(unsigned long data)
 {
+	struct net_bridge *br = (struct net_bridge *) data;
+
+	spin_lock(&br->multicast_lock);
+	if (br->multicast_router == MDB_RTR_TYPE_DISABLED ||
+	    br->multicast_router == MDB_RTR_TYPE_PERM ||
+	    timer_pending(&br->multicast_router_timer))
+		goto out;
+
+	br->multicast_router = MDB_RTR_TYPE_TEMP_QUERY;
+out:
+	spin_unlock(&br->multicast_lock);
 }
 
 static void br_multicast_querier_expired(struct net_bridge *br,
@@ -1364,9 +1375,12 @@ static void br_multicast_mark_router(struct net_bridge *br,
 	unsigned long now = jiffies;
 
Quoted 8 lines

net/bridge/br_multicast.c static void br_multicast_mark_router(struct net_bridge *br, · line 1383

Quoted 8 lines
net/bridge/br_multicast.c +4 -1
 	if (!port) {
-		if (br->multicast_router == MDB_RTR_TYPE_TEMP_QUERY)
+		if (br->multicast_router == MDB_RTR_TYPE_TEMP_QUERY ||
+		    br->multicast_router == MDB_RTR_TYPE_TEMP) {
 			mod_timer(&br->multicast_router_timer,
 				  now + br->multicast_querier_interval);
+			br->multicast_router = MDB_RTR_TYPE_TEMP;
+		}

These are the transitions:
_TEMP -> _TEMP_QUERY
_TEMP_QUERY -> _TEMP_QUERY

In both transitions the timer is armed.

Quoted 63 lines
Quoted 63 lines
net/bridge/br_multicast.c +6 -3
 		return;
 	}
 
@@ -1952,7 +1966,7 @@ void br_multicast_init(struct net_bridge *br)
 
 	spin_lock_init(&br->multicast_lock);
 	setup_timer(&br->multicast_router_timer,
-		    br_multicast_local_router_expired, 0);
+		    br_multicast_local_router_expired, (unsigned long)br);
 	setup_timer(&br->ip4_other_query.timer,
 		    br_ip4_multicast_querier_expired, (unsigned long)br);
 	setup_timer(&br->ip4_own_query.timer, br_ip4_multicast_query_expired,
@@ -2043,11 +2057,14 @@ int br_multicast_set_router(struct net_bridge *br, unsigned long val)
 	case MDB_RTR_TYPE_DISABLED:
 	case MDB_RTR_TYPE_PERM:
 		del_timer(&br->multicast_router_timer);
-		/* fall through */
-	case MDB_RTR_TYPE_TEMP_QUERY:
 		br->multicast_router = val;
 		err = 0;
 		break;
+	case MDB_RTR_TYPE_TEMP_QUERY:
+		if (br->multicast_router != MDB_RTR_TYPE_TEMP)
+			br->multicast_router = val;
+		err = 0;
+		break;
 	}
 
 	spin_unlock_bh(&br->multicast_lock);
net/bridge/br_netlink.c +2 -1
index dea88a2..cee5016 100644
@@ -1357,7 +1357,8 @@ static int br_fill_info(struct sk_buff *skb, const struct net_device *brdev)
 		return -EMSGSIZE;
 #endif
 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
-	if (nla_put_u8(skb, IFLA_BR_MCAST_ROUTER, br->multicast_router) ||
+	if (nla_put_u8(skb, IFLA_BR_MCAST_ROUTER,
+		       br_multicast_router_translate(br->multicast_router)) ||
 	    nla_put_u8(skb, IFLA_BR_MCAST_SNOOPING, !br->multicast_disabled) ||
 	    nla_put_u8(skb, IFLA_BR_MCAST_QUERY_USE_IFADDR,
 		       br->multicast_query_use_ifaddr) ||
net/bridge/br_private.h +2 -3
index ab4df24..e6e3fec 100644
@@ -649,9 +649,8 @@ void br_multicast_get_stats(const struct net_bridge *br,
 
 static inline bool br_multicast_is_router(struct net_bridge *br)
 {
-	return br->multicast_router == 2 ||
-	       (br->multicast_router == 1 &&
-		timer_pending(&br->multicast_router_timer));
+	return br->multicast_router == MDB_RTR_TYPE_PERM ||
+	       br->multicast_router == MDB_RTR_TYPE_TEMP;
 }
 
 static inline bool
@@ -790,6 +789,14 @@ static inline int br_multicast_igmp_type(const struct sk_buff *skb)
 }
 #endif
 
Quoted 5 lines

net/bridge/br_private.h static inline int br_multicast_igmp_type(const struct sk_buff *skb) · line 792

Quoted 1 line
net/bridge/br_private.h +1 -0
+static inline unsigned char

u8

net/bridge/br_private.h static inline int br_multicast_igmp_type(const struct sk_buff *skb) · line 793

Quoted 1 line
net/bridge/br_private.h +1 -0
+br_multicast_router_translate(unsigned char multicast_router)

u8, if need be change the type of the struct member

Sorry, didn't quite get that. Currently, both the bridge_port and bridge have the multicast_router field, and in both cases it is of type unsigned char. Do you suggest to change both to be "u8"?

Quoted 25 lines
Quoted 25 lines
net/bridge/br_private.h +6 -0
+{
+	if (multicast_router == MDB_RTR_TYPE_TEMP)
+		return MDB_RTR_TYPE_TEMP_QUERY;
+	return multicast_router;
+}
+
 /* br_vlan.c */
 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
 bool br_allowed_ingress(const struct net_bridge *br,
net/bridge/br_sysfs_br.c +2 -1
index 723f25e..9b9c597 100644
@@ -340,7 +340,8 @@ static ssize_t multicast_router_show(struct device *d,
 				     struct device_attribute *attr, char *buf)
 {
 	struct net_bridge *br = to_bridge(d);
-	return sprintf(buf, "%d\n", br->multicast_router);
+	return sprintf(buf, "%d\n",
+		       br_multicast_router_translate(br->multicast_router));
 }
 
 static ssize_t multicast_router_store(struct device *d,
#6 lore raw

Re: [patch net-next 1/6] net: bridge: Use the MDB_RTR_TYPE_TEMP on bridge device too

Quoted 24 lines · Yotam Gigi
Quoted 15 lines · Nikolay Aleksandrov
Quoted 14 lines · Jiri Pirko

From: Yotam Gigi <[email protected]>

Every bridge port is in one of four mcast router port states:
- MDB_RTR_TYPE_PERM - the port is set by the user to be an mrouter port regardless of IGMP queries.
- MDB_RTR_TYPE_DISABLED - the port is set by the user to not be an mrouter port regardless of IGMP queries.
- MDB_RTR_TYPE_TEMP - the port is set by the user to be in mcast router learning state, but currently it is not an mrouter port as no IGMP query has been received by it for the last multicast_querier_interval.
- MDB_RTR_TYPE_TEMP_QUERY - the port is set by the user to be in mcast router learning state, and currently it is an mrouter port due to an IGMP query that has been received by it during the passed multicast_querier_interval.

Quoted 6 lines

I think you got the last two partially mixed up, MDB_RTR_TYPE_TEMP marks the port as a router regardless if there were any igmp queries, while TYPE_TEMP_QUERY means it's in learning state. It is the timer (armed vs not) that defines if currently the port is a router when one of the TEMP/TEMP_QUERY are set. In the _TEMP case it is always armed as it is refreshed by user or igmp queries which was the point of that mode.
So this means in br_multicast_router() just check for the timer_pending or perm mode.

Quoted 6 lines

As much as I tried to make this clear, it seems like I failed :)

The 4 states I described are currently the "bridged port" states, not the "bridge device" state. A bridged port has these 4 states, all can be set by the user, while the bridge device only uses 3 of these states. This patch makes the bridge device use the 4 states too. I thought it makes sense.

(disclaimer: this is all about bridge ports, not bridge device) Right, I'll try to explain again: _TEMP always marks the port as a mcast router, it does not put it into just learning state waiting for an igmp query and it can be refreshed by either a query or the user again setting the port in _TEMP. While _TEMP_QUERY puts the port in learning state waiting for a query to become a router, and _TEMP downgrades to _TEMP_QUERY if it expires.

Does that make it clearer ?

so for _TEMP you say:

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

- MDB_RTR_TYPE_TEMP - the port is set by the user to be in mcast router learning state, but currently it is not an mrouter port as no IGMP query has been received by it for the last multicast_querier_interval.

which is not the case, it is always a router when that mode is set on a port. Same for _TEMP_QUERY.

Quoted 14 lines

The first paragraph describes the current states of a bridged port, and the second one explains the difference between bridged port and bridge device. I will (try to) make it clearer if we agree on resending this patch.

Is it clearer now?

Quoted 6 lines

In the port code you have the following transitions:
_TEMP -> TEMP_QUERY (on timer fire or user-set val, port becomes learning only) _TEMP -> _TEMP (noop on user refresh or igmp query, timer refreshes) _TEMP_QUERY -> _TEMP_QUERY (on igmp query the timer is armed, port becomes router)

Quoted 8 lines
Quoted 2 lines

you never have _TEMP_QUERY -> _TEMP, which you're using here to denote the timer getting armed and the bridge becoming a router.

I am not sure I got this one. I do address that: when an IGMP query is recieved and the current state is _TEMP_QUERY, I arm the timer and set the state to _TEMP. I marked that place on the patch, so you can see below.

Exactly, there is no such transition for the ports. I tried to say that you're using the router type to distinguish between when a query is received and it is just learning. I get that you need to do so, but that deviates from how ports are handled, thus I suggested to use the timer state instead and drop the _TEMP for bridge device altogether. If it's possible then the patch will be much simpler and you will not need the hacks to hide the state from user-space which is the part I really don't like.

Quoted 10 lines
Quoted 10 lines
Quoted 8 lines

The bridge device (brX) itself can also be configured by the user to be either fixed, disabled or learning mrouter port states, but currently there is no distinction between the MDB_RTR_TYPE_TEMP_QUERY and MDB_RTR_TYPE_TEMP in the bridge internal state. Due to that, when an IGMP query is received, it is not straightforward to tell whether it changes the bridge device mrouter port status or not.

But before this patch the bridge device could not get that set.

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

Further patches in this patch-set will introduce notifications upon the bridge device mrouter port state. In order to prevent resending bridge mrouter notification when it is not needed, such distinction is necessary.

Granted the bridge device hasn't got a way to clearly distinguish the transitions without the chance for a race and if using the timer one could get an unnecessary

Is there a race condition?

With this state - no, if you try to use the timer state though there might be an extra notification as I've explained below, that's why I asked if it would be a problem. I think it is worth looking into using the timer state because it will remove a lot of the hacks for hiding the state needed in this patch.

Quoted 56 lines
Quoted 56 lines

notification but that seems like a corner case when the timer fires exactly at the same time as the igmp query is received. Can't it be handled by just checking if the new state is different in the notification receiver ?
If it can't and is a problem then I'd prefer to add a new boolean to denote that router on/off transition rather than doing this.

Quoted 4 lines

Hence, add the distinction between MDB_RTR_TYPE_TEMP and MDB_RTR_TYPE_TEMP_QUERY states for the bridge device, similarly to any other bridge port.

This does not add proper MDB_RTR_TYPE_TEMP support for the bridge device but seems to abuse it to distinguish the timer state, and changes the meaning of MDB_RTR_TYPE_TEMP. Can't you just use the timer instead ? I think it will simplify the set and avoid all of this.

Quoted 41 lines

In order to not break the current kernel-user API, don't propagate the new state to the user and use it only in the bridge internal state. Thus, if the user reads (either via sysfs or netlink) the bridge device mrouter state, he will get the MDB_RTR_TYPE_TEMP_QUERY state even if the current bridge state is MDB_RTR_TYPE_TEMP.

---
 net/bridge/br_multicast.c | 25 +++++++++++++++++++++----
 net/bridge/br_netlink.c   |  3 ++-
 net/bridge/br_private.h   | 13 ++++++++++---
 net/bridge/br_sysfs_br.c  |  3 ++-
 4 files changed, 35 insertions(+), 9 deletions(-)
net/bridge/br_multicast.c +11 -0
index 8dc5c8d..b86307b 100644
@@ -861,6 +861,17 @@ static void br_multicast_router_expired(unsigned long data)
 
 static void br_multicast_local_router_expired(unsigned long data)
 {
+	struct net_bridge *br = (struct net_bridge *) data;
+
+	spin_lock(&br->multicast_lock);
+	if (br->multicast_router == MDB_RTR_TYPE_DISABLED ||
+	    br->multicast_router == MDB_RTR_TYPE_PERM ||
+	    timer_pending(&br->multicast_router_timer))
+		goto out;
+
+	br->multicast_router = MDB_RTR_TYPE_TEMP_QUERY;
+out:
+	spin_unlock(&br->multicast_lock);
 }
 
 static void br_multicast_querier_expired(struct net_bridge *br,
@@ -1364,9 +1375,12 @@ static void br_multicast_mark_router(struct net_bridge *br,
 	unsigned long now = jiffies;
 
Quoted 13 lines
Quoted 8 lines

net/bridge/br_multicast.c static void br_multicast_mark_router(struct net_bridge *br, · line 1383

Quoted 8 lines
net/bridge/br_multicast.c +4 -1
 	if (!port) {
-		if (br->multicast_router == MDB_RTR_TYPE_TEMP_QUERY)
+		if (br->multicast_router == MDB_RTR_TYPE_TEMP_QUERY ||
+		    br->multicast_router == MDB_RTR_TYPE_TEMP) {
 			mod_timer(&br->multicast_router_timer,
 				  now + br->multicast_querier_interval);
+			br->multicast_router = MDB_RTR_TYPE_TEMP;
+		}

These are the transitions:
_TEMP -> _TEMP_QUERY
_TEMP_QUERY -> _TEMP_QUERY

You clearly always set multicast_router to _TEMP, where did you see a transition _TEMP_QUERY -> _TEMP_QUERY or _TEMP -> _TEMP_QUERY ?
All transitions are -> _TEMP, because you use it to differentiate between learning state and when a query was received. Maybe we have different definition for a transition :-)

Quoted 70 lines

In both transitions the timer is armed.

Quoted 66 lines
Quoted 60 lines
net/bridge/br_multicast.c +6 -3
 		return;
 	}
 
@@ -1952,7 +1966,7 @@ void br_multicast_init(struct net_bridge *br)
 
 	spin_lock_init(&br->multicast_lock);
 	setup_timer(&br->multicast_router_timer,
-		    br_multicast_local_router_expired, 0);
+		    br_multicast_local_router_expired, (unsigned long)br);
 	setup_timer(&br->ip4_other_query.timer,
 		    br_ip4_multicast_querier_expired, (unsigned long)br);
 	setup_timer(&br->ip4_own_query.timer, br_ip4_multicast_query_expired,
@@ -2043,11 +2057,14 @@ int br_multicast_set_router(struct net_bridge *br, unsigned long val)
 	case MDB_RTR_TYPE_DISABLED:
 	case MDB_RTR_TYPE_PERM:
 		del_timer(&br->multicast_router_timer);
-		/* fall through */
-	case MDB_RTR_TYPE_TEMP_QUERY:
 		br->multicast_router = val;
 		err = 0;
 		break;
+	case MDB_RTR_TYPE_TEMP_QUERY:
+		if (br->multicast_router != MDB_RTR_TYPE_TEMP)
+			br->multicast_router = val;
+		err = 0;
+		break;
 	}
 
 	spin_unlock_bh(&br->multicast_lock);
net/bridge/br_netlink.c +2 -1
index dea88a2..cee5016 100644
@@ -1357,7 +1357,8 @@ static int br_fill_info(struct sk_buff *skb, const struct net_device *brdev)
 		return -EMSGSIZE;
 #endif
 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
-	if (nla_put_u8(skb, IFLA_BR_MCAST_ROUTER, br->multicast_router) ||
+	if (nla_put_u8(skb, IFLA_BR_MCAST_ROUTER,
+		       br_multicast_router_translate(br->multicast_router)) ||
 	    nla_put_u8(skb, IFLA_BR_MCAST_SNOOPING, !br->multicast_disabled) ||
 	    nla_put_u8(skb, IFLA_BR_MCAST_QUERY_USE_IFADDR,
 		       br->multicast_query_use_ifaddr) ||
net/bridge/br_private.h +2 -3
index ab4df24..e6e3fec 100644
@@ -649,9 +649,8 @@ void br_multicast_get_stats(const struct net_bridge *br,
 
 static inline bool br_multicast_is_router(struct net_bridge *br)
 {
-	return br->multicast_router == 2 ||
-	       (br->multicast_router == 1 &&
-		timer_pending(&br->multicast_router_timer));
+	return br->multicast_router == MDB_RTR_TYPE_PERM ||
+	       br->multicast_router == MDB_RTR_TYPE_TEMP;
 }
 
 static inline bool

net/bridge/br_private.h static inline int br_multicast_igmp_type(const struct sk_buff *skb) · line 792

Quoted 4 lines
net/bridge/br_private.h +1 -0
@@ -790,6 +789,14 @@ static inline int br_multicast_igmp_type(const struct sk_buff *skb)
 }
 #endif
 
+static inline unsigned char

u8

Quoted 8 lines
Quoted 2 lines

net/bridge/br_private.h static inline int br_multicast_igmp_type(const struct sk_buff *skb) · line 793

Quoted 1 line
net/bridge/br_private.h +1 -0
+br_multicast_router_translate(unsigned char multicast_router)

u8, if need be change the type of the struct member

Sorry, didn't quite get that. Currently, both the bridge_port and bridge have the multicast_router field, and in both cases it is of type unsigned char. Do you suggest to change both to be "u8"?

Right, and this is unnecessarily long and requires to be broken ugly like that with the type above and name below. So I suggested to use u8 to avoid that.

Quoted 27 lines
Quoted 26 lines
Quoted 26 lines
net/bridge/br_private.h +6 -0
+{
+	if (multicast_router == MDB_RTR_TYPE_TEMP)
+		return MDB_RTR_TYPE_TEMP_QUERY;
+	return multicast_router;
+}
+
 /* br_vlan.c */
 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
 bool br_allowed_ingress(const struct net_bridge *br,
net/bridge/br_sysfs_br.c +2 -1
index 723f25e..9b9c597 100644
@@ -340,7 +340,8 @@ static ssize_t multicast_router_show(struct device *d,
 				     struct device_attribute *attr, char *buf)
 {
 	struct net_bridge *br = to_bridge(d);
-	return sprintf(buf, "%d\n", br->multicast_router);
+	return sprintf(buf, "%d\n",
+		       br_multicast_router_translate(br->multicast_router));
 }
 
 static ssize_t multicast_router_store(struct device *d,
#7 lore raw

Re: [patch net-next 1/6] net: bridge: Use the MDB_RTR_TYPE_TEMP on bridge device too

Quoted 41 lines · Nikolay Aleksandrov
Quoted 24 lines · Yotam Gigi
Quoted 15 lines · Nikolay Aleksandrov
Quoted 14 lines · Jiri Pirko

From: Yotam Gigi <[email protected]>

Every bridge port is in one of four mcast router port states:
- MDB_RTR_TYPE_PERM - the port is set by the user to be an mrouter port regardless of IGMP queries.
- MDB_RTR_TYPE_DISABLED - the port is set by the user to not be an mrouter port regardless of IGMP queries.
- MDB_RTR_TYPE_TEMP - the port is set by the user to be in mcast router learning state, but currently it is not an mrouter port as no IGMP query has been received by it for the last multicast_querier_interval.
- MDB_RTR_TYPE_TEMP_QUERY - the port is set by the user to be in mcast router learning state, and currently it is an mrouter port due to an IGMP query that has been received by it during the passed multicast_querier_interval.

Quoted 6 lines

I think you got the last two partially mixed up, MDB_RTR_TYPE_TEMP marks the port as a router regardless if there were any igmp queries, while TYPE_TEMP_QUERY means it's in learning state. It is the timer (armed vs not) that defines if currently the port is a router when one of the TEMP/TEMP_QUERY are set. In the _TEMP case it is always armed as it is refreshed by user or igmp queries which was the point of that mode.
So this means in br_multicast_router() just check for the timer_pending or perm mode.

Quoted 6 lines

As much as I tried to make this clear, it seems like I failed :)

The 4 states I described are currently the "bridged port" states, not the "bridge device" state. A bridged port has these 4 states, all can be set by the user, while the bridge device only uses 3 of these states. This patch makes the bridge device use the 4 states too. I thought it makes sense.

(disclaimer: this is all about bridge ports, not bridge device) Right, I'll try to explain again: _TEMP always marks the port as a mcast router, it does not put it into just learning state waiting for an igmp query and it can be refreshed by either a query or the user again setting the port in _TEMP. While _TEMP_QUERY puts the port in learning state waiting for a query to become a router, and _TEMP downgrades to _TEMP_QUERY if it expires.

Does that make it clearer ?

Quoted 7 lines

so for _TEMP you say:

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

- MDB_RTR_TYPE_TEMP - the port is set by the user to be in mcast router learning state, but currently it is not an mrouter port as no IGMP query has been received by it for the last multicast_querier_interval.

which is not the case, it is always a router when that mode is set on a port. Same for _TEMP_QUERY.

Err, sorry by same I meant it is not correct, not that the _TEMP definition is the same. Need to get coffee :-)

Quoted 242 lines
Quoted 15 lines

The first paragraph describes the current states of a bridged port, and the second one explains the difference between bridged port and bridge device. I will (try to) make it clearer if we agree on resending this patch.

Is it clearer now?

Quoted 6 lines

In the port code you have the following transitions:
_TEMP -> TEMP_QUERY (on timer fire or user-set val, port becomes learning only) _TEMP -> _TEMP (noop on user refresh or igmp query, timer refreshes) _TEMP_QUERY -> _TEMP_QUERY (on igmp query the timer is armed, port becomes router)

Quoted 8 lines
Quoted 2 lines

you never have _TEMP_QUERY -> _TEMP, which you're using here to denote the timer getting armed and the bridge becoming a router.

I am not sure I got this one. I do address that: when an IGMP query is recieved and the current state is _TEMP_QUERY, I arm the timer and set the state to _TEMP. I marked that place on the patch, so you can see below.

Exactly, there is no such transition for the ports. I tried to say that you're using the router type to distinguish between when a query is received and it is just learning. I get that you need to do so, but that deviates from how ports are handled, thus I suggested to use the timer state instead and drop the _TEMP for bridge device altogether. If it's possible then the patch will be much simpler and you will not need the hacks to hide the state from user-space which is the part I really don't like.

Quoted 10 lines
Quoted 10 lines
Quoted 8 lines

The bridge device (brX) itself can also be configured by the user to be either fixed, disabled or learning mrouter port states, but currently there is no distinction between the MDB_RTR_TYPE_TEMP_QUERY and MDB_RTR_TYPE_TEMP in the bridge internal state. Due to that, when an IGMP query is received, it is not straightforward to tell whether it changes the bridge device mrouter port status or not.

But before this patch the bridge device could not get that set.

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

Further patches in this patch-set will introduce notifications upon the bridge device mrouter port state. In order to prevent resending bridge mrouter notification when it is not needed, such distinction is necessary.

Granted the bridge device hasn't got a way to clearly distinguish the transitions without the chance for a race and if using the timer one could get an unnecessary

Is there a race condition?

With this state - no, if you try to use the timer state though there might be an extra notification as I've explained below, that's why I asked if it would be a problem. I think it is worth looking into using the timer state because it will remove a lot of the hacks for hiding the state needed in this patch.

Quoted 56 lines
Quoted 56 lines

notification but that seems like a corner case when the timer fires exactly at the same time as the igmp query is received. Can't it be handled by just checking if the new state is different in the notification receiver ?
If it can't and is a problem then I'd prefer to add a new boolean to denote that router on/off transition rather than doing this.

Quoted 4 lines

Hence, add the distinction between MDB_RTR_TYPE_TEMP and MDB_RTR_TYPE_TEMP_QUERY states for the bridge device, similarly to any other bridge port.

This does not add proper MDB_RTR_TYPE_TEMP support for the bridge device but seems to abuse it to distinguish the timer state, and changes the meaning of MDB_RTR_TYPE_TEMP. Can't you just use the timer instead ? I think it will simplify the set and avoid all of this.

Quoted 41 lines

In order to not break the current kernel-user API, don't propagate the new state to the user and use it only in the bridge internal state. Thus, if the user reads (either via sysfs or netlink) the bridge device mrouter state, he will get the MDB_RTR_TYPE_TEMP_QUERY state even if the current bridge state is MDB_RTR_TYPE_TEMP.

---
 net/bridge/br_multicast.c | 25 +++++++++++++++++++++----
 net/bridge/br_netlink.c   |  3 ++-
 net/bridge/br_private.h   | 13 ++++++++++---
 net/bridge/br_sysfs_br.c  |  3 ++-
 4 files changed, 35 insertions(+), 9 deletions(-)
net/bridge/br_multicast.c +11 -0
index 8dc5c8d..b86307b 100644
@@ -861,6 +861,17 @@ static void br_multicast_router_expired(unsigned long data)
 
 static void br_multicast_local_router_expired(unsigned long data)
 {
+	struct net_bridge *br = (struct net_bridge *) data;
+
+	spin_lock(&br->multicast_lock);
+	if (br->multicast_router == MDB_RTR_TYPE_DISABLED ||
+	    br->multicast_router == MDB_RTR_TYPE_PERM ||
+	    timer_pending(&br->multicast_router_timer))
+		goto out;
+
+	br->multicast_router = MDB_RTR_TYPE_TEMP_QUERY;
+out:
+	spin_unlock(&br->multicast_lock);
 }
 
 static void br_multicast_querier_expired(struct net_bridge *br,
@@ -1364,9 +1375,12 @@ static void br_multicast_mark_router(struct net_bridge *br,
 	unsigned long now = jiffies;
 
Quoted 13 lines
Quoted 8 lines

net/bridge/br_multicast.c static void br_multicast_mark_router(struct net_bridge *br, · line 1383

Quoted 8 lines
net/bridge/br_multicast.c +4 -1
 	if (!port) {
-		if (br->multicast_router == MDB_RTR_TYPE_TEMP_QUERY)
+		if (br->multicast_router == MDB_RTR_TYPE_TEMP_QUERY ||
+		    br->multicast_router == MDB_RTR_TYPE_TEMP) {
 			mod_timer(&br->multicast_router_timer,
 				  now + br->multicast_querier_interval);
+			br->multicast_router = MDB_RTR_TYPE_TEMP;
+		}

These are the transitions:
_TEMP -> _TEMP_QUERY
_TEMP_QUERY -> _TEMP_QUERY

You clearly always set multicast_router to _TEMP, where did you see a transition _TEMP_QUERY -> _TEMP_QUERY or _TEMP -> _TEMP_QUERY ?
All transitions are -> _TEMP, because you use it to differentiate between learning state and when a query was received. Maybe we have different definition for a transition :-)

Quoted 70 lines

In both transitions the timer is armed.

Quoted 66 lines
Quoted 60 lines
net/bridge/br_multicast.c +6 -3
 		return;
 	}
 
@@ -1952,7 +1966,7 @@ void br_multicast_init(struct net_bridge *br)
 
 	spin_lock_init(&br->multicast_lock);
 	setup_timer(&br->multicast_router_timer,
-		    br_multicast_local_router_expired, 0);
+		    br_multicast_local_router_expired, (unsigned long)br);
 	setup_timer(&br->ip4_other_query.timer,
 		    br_ip4_multicast_querier_expired, (unsigned long)br);
 	setup_timer(&br->ip4_own_query.timer, br_ip4_multicast_query_expired,
@@ -2043,11 +2057,14 @@ int br_multicast_set_router(struct net_bridge *br, unsigned long val)
 	case MDB_RTR_TYPE_DISABLED:
 	case MDB_RTR_TYPE_PERM:
 		del_timer(&br->multicast_router_timer);
-		/* fall through */
-	case MDB_RTR_TYPE_TEMP_QUERY:
 		br->multicast_router = val;
 		err = 0;
 		break;
+	case MDB_RTR_TYPE_TEMP_QUERY:
+		if (br->multicast_router != MDB_RTR_TYPE_TEMP)
+			br->multicast_router = val;
+		err = 0;
+		break;
 	}
 
 	spin_unlock_bh(&br->multicast_lock);
net/bridge/br_netlink.c +2 -1
index dea88a2..cee5016 100644
@@ -1357,7 +1357,8 @@ static int br_fill_info(struct sk_buff *skb, const struct net_device *brdev)
 		return -EMSGSIZE;
 #endif
 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
-	if (nla_put_u8(skb, IFLA_BR_MCAST_ROUTER, br->multicast_router) ||
+	if (nla_put_u8(skb, IFLA_BR_MCAST_ROUTER,
+		       br_multicast_router_translate(br->multicast_router)) ||
 	    nla_put_u8(skb, IFLA_BR_MCAST_SNOOPING, !br->multicast_disabled) ||
 	    nla_put_u8(skb, IFLA_BR_MCAST_QUERY_USE_IFADDR,
 		       br->multicast_query_use_ifaddr) ||
net/bridge/br_private.h +2 -3
index ab4df24..e6e3fec 100644
@@ -649,9 +649,8 @@ void br_multicast_get_stats(const struct net_bridge *br,
 
 static inline bool br_multicast_is_router(struct net_bridge *br)
 {
-	return br->multicast_router == 2 ||
-	       (br->multicast_router == 1 &&
-		timer_pending(&br->multicast_router_timer));
+	return br->multicast_router == MDB_RTR_TYPE_PERM ||
+	       br->multicast_router == MDB_RTR_TYPE_TEMP;
 }
 
 static inline bool

net/bridge/br_private.h static inline int br_multicast_igmp_type(const struct sk_buff *skb) · line 792

Quoted 4 lines
net/bridge/br_private.h +1 -0
@@ -790,6 +789,14 @@ static inline int br_multicast_igmp_type(const struct sk_buff *skb)
 }
 #endif
 
+static inline unsigned char

u8

Quoted 8 lines
Quoted 2 lines

net/bridge/br_private.h static inline int br_multicast_igmp_type(const struct sk_buff *skb) · line 793

Quoted 1 line
net/bridge/br_private.h +1 -0
+br_multicast_router_translate(unsigned char multicast_router)

u8, if need be change the type of the struct member

Sorry, didn't quite get that. Currently, both the bridge_port and bridge have the multicast_router field, and in both cases it is of type unsigned char. Do you suggest to change both to be "u8"?

Right, and this is unnecessarily long and requires to be broken ugly like that with the type above and name below. So I suggested to use u8 to avoid that.

Quoted 27 lines
Quoted 26 lines
Quoted 26 lines
net/bridge/br_private.h +6 -0
+{
+	if (multicast_router == MDB_RTR_TYPE_TEMP)
+		return MDB_RTR_TYPE_TEMP_QUERY;
+	return multicast_router;
+}
+
 /* br_vlan.c */
 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
 bool br_allowed_ingress(const struct net_bridge *br,
net/bridge/br_sysfs_br.c +2 -1
index 723f25e..9b9c597 100644
@@ -340,7 +340,8 @@ static ssize_t multicast_router_show(struct device *d,
 				     struct device_attribute *attr, char *buf)
 {
 	struct net_bridge *br = to_bridge(d);
-	return sprintf(buf, "%d\n", br->multicast_router);
+	return sprintf(buf, "%d\n",
+		       br_multicast_router_translate(br->multicast_router));
 }
 
 static ssize_t multicast_router_store(struct device *d,
#8 lore raw

Re: [patch net-next 1/6] net: bridge: Use the MDB_RTR_TYPE_TEMP on bridge device too

Quoted 40 lines · Nikolay Aleksandrov
Quoted 39 lines · Nikolay Aleksandrov
Quoted 23 lines · Yotam Gigi
Quoted 15 lines · Nikolay Aleksandrov
Quoted 14 lines · Jiri Pirko

From: Yotam Gigi <[email protected]>

Every bridge port is in one of four mcast router port states:
- MDB_RTR_TYPE_PERM - the port is set by the user to be an mrouter port regardless of IGMP queries.
- MDB_RTR_TYPE_DISABLED - the port is set by the user to not be an mrouter port regardless of IGMP queries.
- MDB_RTR_TYPE_TEMP - the port is set by the user to be in mcast router learning state, but currently it is not an mrouter port as no IGMP query has been received by it for the last multicast_querier_interval.
- MDB_RTR_TYPE_TEMP_QUERY - the port is set by the user to be in mcast router learning state, and currently it is an mrouter port due to an IGMP query that has been received by it during the passed multicast_querier_interval.

Quoted 6 lines

I think you got the last two partially mixed up, MDB_RTR_TYPE_TEMP marks the port as a router regardless if there were any igmp queries, while TYPE_TEMP_QUERY means it's in learning state. It is the timer (armed vs not) that defines if currently the port is a router when one of the TEMP/TEMP_QUERY are set. In the _TEMP case it is always armed as it is refreshed by user or igmp queries which was the point of that mode.
So this means in br_multicast_router() just check for the timer_pending or perm mode.

Quoted 6 lines

As much as I tried to make this clear, it seems like I failed :)

The 4 states I described are currently the "bridged port" states, not the "bridge device" state. A bridged port has these 4 states, all can be set by the user, while the bridge device only uses 3 of these states. This patch makes the bridge device use the 4 states too. I thought it makes sense.

(disclaimer: this is all about bridge ports, not bridge device) Right, I'll try to explain again: _TEMP always marks the port as a mcast router, it does not put it into just learning state waiting for an igmp query and it can be refreshed by either a query or the user again setting the port in _TEMP. While _TEMP_QUERY puts the port in learning state waiting for a query to become a router, and _TEMP downgrades to _TEMP_QUERY if it expires.

Does that make it clearer ?

Quoted 8 lines
Quoted 6 lines

so for _TEMP you say:

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

- MDB_RTR_TYPE_TEMP - the port is set by the user to be in mcast router learning state, but currently it is not an mrouter port as no IGMP query has been received by it for the last multicast_querier_interval.

which is not the case, it is always a router when that mode is set on a port. Same for _TEMP_QUERY.

Err, sorry by same I meant it is not correct, not that the _TEMP definition is the same. Need to get coffee :-)

Ho, I see that I was clear but not right :)

I had a look at the code and seems like you are right - for some reason I thought that _TEMP is learning-active and _TEMP_QUERY is learning-inactive, and the ports change states when according to IGMP queries.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

The first paragraph describes the current states of a bridged port, and the second one explains the difference between bridged port and bridge device. I will (try to) make it clearer if we agree on resending this patch.

Is it clearer now?

Yes it is.

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 9 lines

In the port code you have the following transitions:
_TEMP -> TEMP_QUERY (on timer fire or user-set val, port becomes learning only) _TEMP -> _TEMP (noop on user refresh or igmp query, timer refreshes) _TEMP_QUERY -> _TEMP_QUERY (on igmp query the timer is armed, port becomes router)

you never have _TEMP_QUERY -> _TEMP, which you're using here to denote the timer getting armed and the bridge becoming a router.

I am not sure I got this one. I do address that: when an IGMP query is recieved and the current state is _TEMP_QUERY, I arm the timer and set the state to _TEMP. I marked that place on the patch, so you can see below.

Quoted 6 lines
Quoted 6 lines

Exactly, there is no such transition for the ports. I tried to say that you're using the router type to distinguish between when a query is received and it is just learning. I get that you need to do so, but that deviates from how ports are handled, thus I suggested to use the timer state instead and drop the _TEMP for bridge device altogether. If it's possible then the patch will be much simpler and you will not need the hacks to hide the state from user-space which is the part I really don't like.

Yeah, I agree. Thanks for the feedback and sorry for the late answer :)

Quoted 199 lines
Quoted 199 lines
Quoted 9 lines
Quoted 9 lines
Quoted 7 lines

The bridge device (brX) itself can also be configured by the user to be either fixed, disabled or learning mrouter port states, but currently there is no distinction between the MDB_RTR_TYPE_TEMP_QUERY and MDB_RTR_TYPE_TEMP in the bridge internal state. Due to that, when an IGMP query is received, it is not straightforward to tell whether it changes the bridge device mrouter port status or not.

But before this patch the bridge device could not get that set.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

Further patches in this patch-set will introduce notifications upon the bridge device mrouter port state. In order to prevent resending bridge mrouter notification when it is not needed, such distinction is necessary.

Granted the bridge device hasn't got a way to clearly distinguish the transitions without the chance for a race and if using the timer one could get an unnecessary

Is there a race condition?

With this state - no, if you try to use the timer state though there might be an extra notification as I've explained below, that's why I asked if it would be a problem. I think it is worth looking into using the timer state because it will remove a lot of the hacks for hiding the state needed in this patch.

Quoted 56 lines
Quoted 56 lines

notification but that seems like a corner case when the timer fires exactly at the same time as the igmp query is received. Can't it be handled by just checking if the new state is different in the notification receiver ?
If it can't and is a problem then I'd prefer to add a new boolean to denote that router on/off transition rather than doing this.

Quoted 4 lines

Hence, add the distinction between MDB_RTR_TYPE_TEMP and MDB_RTR_TYPE_TEMP_QUERY states for the bridge device, similarly to any other bridge port.

This does not add proper MDB_RTR_TYPE_TEMP support for the bridge device but seems to abuse it to distinguish the timer state, and changes the meaning of MDB_RTR_TYPE_TEMP. Can't you just use the timer instead ? I think it will simplify the set and avoid all of this.

Quoted 41 lines

In order to not break the current kernel-user API, don't propagate the new state to the user and use it only in the bridge internal state. Thus, if the user reads (either via sysfs or netlink) the bridge device mrouter state, he will get the MDB_RTR_TYPE_TEMP_QUERY state even if the current bridge state is MDB_RTR_TYPE_TEMP.

---
 net/bridge/br_multicast.c | 25 +++++++++++++++++++++----
 net/bridge/br_netlink.c   |  3 ++-
 net/bridge/br_private.h   | 13 ++++++++++---
 net/bridge/br_sysfs_br.c  |  3 ++-
 4 files changed, 35 insertions(+), 9 deletions(-)
net/bridge/br_multicast.c +11 -0
index 8dc5c8d..b86307b 100644
@@ -861,6 +861,17 @@ static void br_multicast_router_expired(unsigned long data)
 
 static void br_multicast_local_router_expired(unsigned long data)
 {
+	struct net_bridge *br = (struct net_bridge *) data;
+
+	spin_lock(&br->multicast_lock);
+	if (br->multicast_router == MDB_RTR_TYPE_DISABLED ||
+	    br->multicast_router == MDB_RTR_TYPE_PERM ||
+	    timer_pending(&br->multicast_router_timer))
+		goto out;
+
+	br->multicast_router = MDB_RTR_TYPE_TEMP_QUERY;
+out:
+	spin_unlock(&br->multicast_lock);
 }
 
 static void br_multicast_querier_expired(struct net_bridge *br,
@@ -1364,9 +1375,12 @@ static void br_multicast_mark_router(struct net_bridge *br,
 	unsigned long now = jiffies;
 
Quoted 12 lines
Quoted 8 lines

net/bridge/br_multicast.c static void br_multicast_mark_router(struct net_bridge *br, · line 1383

Quoted 8 lines
net/bridge/br_multicast.c +4 -1
 	if (!port) {
-		if (br->multicast_router == MDB_RTR_TYPE_TEMP_QUERY)
+		if (br->multicast_router == MDB_RTR_TYPE_TEMP_QUERY ||
+		    br->multicast_router == MDB_RTR_TYPE_TEMP) {
 			mod_timer(&br->multicast_router_timer,
 				  now + br->multicast_querier_interval);
+			br->multicast_router = MDB_RTR_TYPE_TEMP;
+		}

These are the transitions:
_TEMP -> _TEMP_QUERY
_TEMP_QUERY -> _TEMP_QUERY

You clearly always set multicast_router to _TEMP, where did you see a transition _TEMP_QUERY -> _TEMP_QUERY or _TEMP -> _TEMP_QUERY ?
All transitions are -> _TEMP, because you use it to differentiate between learning state and when a query was received. Maybe we have different definition for a transition :-)

Quoted 69 lines

In both transitions the timer is armed.

Quoted 66 lines
Quoted 60 lines
net/bridge/br_multicast.c +6 -3
 		return;
 	}
 
@@ -1952,7 +1966,7 @@ void br_multicast_init(struct net_bridge *br)
 
 	spin_lock_init(&br->multicast_lock);
 	setup_timer(&br->multicast_router_timer,
-		    br_multicast_local_router_expired, 0);
+		    br_multicast_local_router_expired, (unsigned long)br);
 	setup_timer(&br->ip4_other_query.timer,
 		    br_ip4_multicast_querier_expired, (unsigned long)br);
 	setup_timer(&br->ip4_own_query.timer, br_ip4_multicast_query_expired,
@@ -2043,11 +2057,14 @@ int br_multicast_set_router(struct net_bridge *br, unsigned long val)
 	case MDB_RTR_TYPE_DISABLED:
 	case MDB_RTR_TYPE_PERM:
 		del_timer(&br->multicast_router_timer);
-		/* fall through */
-	case MDB_RTR_TYPE_TEMP_QUERY:
 		br->multicast_router = val;
 		err = 0;
 		break;
+	case MDB_RTR_TYPE_TEMP_QUERY:
+		if (br->multicast_router != MDB_RTR_TYPE_TEMP)
+			br->multicast_router = val;
+		err = 0;
+		break;
 	}
 
 	spin_unlock_bh(&br->multicast_lock);
net/bridge/br_netlink.c +2 -1
index dea88a2..cee5016 100644
@@ -1357,7 +1357,8 @@ static int br_fill_info(struct sk_buff *skb, const struct net_device *brdev)
 		return -EMSGSIZE;
 #endif
 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
-	if (nla_put_u8(skb, IFLA_BR_MCAST_ROUTER, br->multicast_router) ||
+	if (nla_put_u8(skb, IFLA_BR_MCAST_ROUTER,
+		       br_multicast_router_translate(br->multicast_router)) ||
 	    nla_put_u8(skb, IFLA_BR_MCAST_SNOOPING, !br->multicast_disabled) ||
 	    nla_put_u8(skb, IFLA_BR_MCAST_QUERY_USE_IFADDR,
 		       br->multicast_query_use_ifaddr) ||
net/bridge/br_private.h +2 -3
index ab4df24..e6e3fec 100644
@@ -649,9 +649,8 @@ void br_multicast_get_stats(const struct net_bridge *br,
 
 static inline bool br_multicast_is_router(struct net_bridge *br)
 {
-	return br->multicast_router == 2 ||
-	       (br->multicast_router == 1 &&
-		timer_pending(&br->multicast_router_timer));
+	return br->multicast_router == MDB_RTR_TYPE_PERM ||
+	       br->multicast_router == MDB_RTR_TYPE_TEMP;
 }
 
 static inline bool

net/bridge/br_private.h static inline int br_multicast_igmp_type(const struct sk_buff *skb) · line 792

Quoted 4 lines
net/bridge/br_private.h +1 -0
@@ -790,6 +789,14 @@ static inline int br_multicast_igmp_type(const struct sk_buff *skb)
 }
 #endif
 
+static inline unsigned char

u8

Quoted 7 lines
Quoted 2 lines

net/bridge/br_private.h static inline int br_multicast_igmp_type(const struct sk_buff *skb) · line 793

Quoted 1 line
net/bridge/br_private.h +1 -0
+br_multicast_router_translate(unsigned char multicast_router)

u8, if need be change the type of the struct member

Sorry, didn't quite get that. Currently, both the bridge_port and bridge have the multicast_router field, and in both cases it is of type unsigned char. Do you suggest to change both to be "u8"?

Right, and this is unnecessarily long and requires to be broken ugly like that with the type above and name below. So I suggested to use u8 to avoid that.

Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
net/bridge/br_private.h +6 -0
+{
+	if (multicast_router == MDB_RTR_TYPE_TEMP)
+		return MDB_RTR_TYPE_TEMP_QUERY;
+	return multicast_router;
+}
+
 /* br_vlan.c */
 #ifdef CONFIG_BRIDGE_VLAN_FILTERING
 bool br_allowed_ingress(const struct net_bridge *br,
net/bridge/br_sysfs_br.c +2 -1
index 723f25e..9b9c597 100644
@@ -340,7 +340,8 @@ static ssize_t multicast_router_show(struct device *d,
 				     struct device_attribute *attr, char *buf)
 {
 	struct net_bridge *br = to_bridge(d);
-	return sprintf(buf, "%d\n", br->multicast_router);
+	return sprintf(buf, "%d\n",
+		       br_multicast_router_translate(br->multicast_router));
 }
 
 static ssize_t multicast_router_store(struct device *d,