Sevinj Aghayeva
2022-Sep-17 20:17 UTC
[Bridge] [PATCH RFC net-next 0/5] net: vlan: fix bridge binding behavior and add selftests
When bridge binding is enabled for a vlan interface, it is expected that the link state of the vlan interface will track the subset of the ports that are also members of the corresponding vlan, rather than that of all ports. Currently, this feature works as expected when a vlan interface is created with bridge binding enabled: ip link add link br name vlan10 type vlan id 10 protocol 802.1q \ bridge_binding on However, the feature does not work when a vlan interface is created with bridge binding disabled, and then enabled later: ip link add link br name vlan10 type vlan id 10 protocol 802.1q \ bridge_binding off ip link set vlan10 type vlan bridge_binding on After these two commands, the link state of the vlan interface continues to track that of all ports, which is inconsistent and confusing to users. This series fixes this bug and introduces two tests for the valid behavior. Sevinj Aghayeva (5): net: core: export call_netdevice_notifiers_info net: core: introduce a new notifier for link-type-specific changes net: 8021q: notify bridge module of bridge-binding flag change net: bridge: handle link-type-specific changes in the bridge module selftests: net: tests for bridge binding behavior include/linux/if_vlan.h | 4 + include/linux/netdevice.h | 3 + include/linux/notifier_info.h | 21 +++ net/8021q/vlan.h | 2 +- net/8021q/vlan_dev.c | 20 ++- net/bridge/br.c | 5 + net/bridge/br_private.h | 7 + net/bridge/br_vlan.c | 18 +++ net/core/dev.c | 7 +- tools/testing/selftests/net/Makefile | 1 + .../selftests/net/bridge_vlan_binding_test.sh | 143 ++++++++++++++++++ 11 files changed, 223 insertions(+), 8 deletions(-) create mode 100644 include/linux/notifier_info.h create mode 100755 tools/testing/selftests/net/bridge_vlan_binding_test.sh -- 2.34.1
Sevinj Aghayeva
2022-Sep-17 20:17 UTC
[Bridge] [PATCH RFC net-next 1/5] net: core: export call_netdevice_notifiers_info
The function call_netdevice_notifiers_info will be used by the vlan module for sending link-type-specific information to other modules. Signed-off-by: Sevinj Aghayeva <sevinj.aghayeva at gmail.com> --- include/linux/netdevice.h | 2 ++ net/core/dev.c | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index f0068c1ff1df..56b96b1e4c4c 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -2906,6 +2906,8 @@ netdev_notifier_info_to_extack(const struct netdev_notifier_info *info) } int call_netdevice_notifiers(unsigned long val, struct net_device *dev); +int call_netdevice_notifiers_info(unsigned long val, + struct netdev_notifier_info *info); extern rwlock_t dev_base_lock; /* Device list lock */ diff --git a/net/core/dev.c b/net/core/dev.c index d66c73c1c734..e233145d1452 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -160,8 +160,6 @@ struct list_head ptype_base[PTYPE_HASH_SIZE] __read_mostly; struct list_head ptype_all __read_mostly; /* Taps */ static int netif_rx_internal(struct sk_buff *skb); -static int call_netdevice_notifiers_info(unsigned long val, - struct netdev_notifier_info *info); static int call_netdevice_notifiers_extack(unsigned long val, struct net_device *dev, struct netlink_ext_ack *extack); @@ -1927,7 +1925,7 @@ static void move_netdevice_notifiers_dev_net(struct net_device *dev, * are as for raw_notifier_call_chain(). */ -static int call_netdevice_notifiers_info(unsigned long val, +int call_netdevice_notifiers_info(unsigned long val, struct netdev_notifier_info *info) { struct net *net = dev_net(info->dev); @@ -1944,6 +1942,7 @@ static int call_netdevice_notifiers_info(unsigned long val, return ret; return raw_notifier_call_chain(&netdev_chain, val, info); } +EXPORT_SYMBOL_GPL(call_netdevice_notifiers_info); /** * call_netdevice_notifiers_info_robust - call per-netns notifier blocks -- 2.34.1
Sevinj Aghayeva
2022-Sep-17 20:17 UTC
[Bridge] [PATCH RFC net-next 2/5] net: core: introduce a new notifier for link-type-specific changes
The netdev notification subsystem is lacking a generic notifier than can pass link-type-specific information alongside the device. For example, the VLAN subsystem needs to notify the bridge of a change in the VLAN bridge brinding flag. This flag change might result in the bridge setting VLAN devices UP or DOWN depending on the state of the bridge ports. Instead of introducing one new NETDEV_* notification just for this specific use-case, introduce a generic notifier which can pass link-type specific information. The notification?s target can decode the union type by checking the type of the target device. That way, other link types will be able to reuse this notification type to notify with their own specific link specific struct. As this notification is only for internal use, there?s no need to export it to userspace. Other NETDEV_* notifiers have also been looked at to see if it is possible to consolidate: * NETDEV_CHANGEINFODATA: this notification needs to be sent to userspace; keep it separate from NETDEV_CHANGE_DETAILS. * NETDEV_CHANGE: this is to notify net_device->flags change; it is not link-type specific. Signed-off-by: Sevinj Aghayeva <sevinj.aghayeva at gmail.com> --- include/linux/if_vlan.h | 4 ++++ include/linux/netdevice.h | 1 + include/linux/notifier_info.h | 21 +++++++++++++++++++++ net/core/dev.c | 2 +- 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 include/linux/notifier_info.h diff --git a/include/linux/if_vlan.h b/include/linux/if_vlan.h index e00c4ee81ff7..38ffd2ee5112 100644 --- a/include/linux/if_vlan.h +++ b/include/linux/if_vlan.h @@ -37,6 +37,10 @@ struct vlan_hdr { __be16 h_vlan_encapsulated_proto; }; +struct vlan_change_details { + bool bridge_binding; +}; + /** * struct vlan_ethhdr - vlan ethernet header (ethhdr + vlan_hdr) * @h_dest: destination ethernet address diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 56b96b1e4c4c..912c04b09ebb 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -2770,6 +2770,7 @@ enum netdev_cmd { NETDEV_UNREGISTER, NETDEV_CHANGEMTU, /* notify after mtu change happened */ NETDEV_CHANGEADDR, /* notify after the address change */ + NETDEV_CHANGE_DETAILS, NETDEV_PRE_CHANGEADDR, /* notify before the address change */ NETDEV_GOING_DOWN, NETDEV_CHANGENAME, diff --git a/include/linux/notifier_info.h b/include/linux/notifier_info.h new file mode 100644 index 000000000000..3e53f18c6da1 --- /dev/null +++ b/include/linux/notifier_info.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _LINUX_NOTIFIER_INFO_H_ +#define _LINUX_NOTIFIER_INFO_H_ + +#include <linux/netdevice.h> +#include <linux/if_vlan.h> + +/* + * This struct is used for passing link-type-specific information to + * the device. + */ + +struct netdev_notifier_change_details_info { + struct netdev_notifier_info info; /* must be first */ + union { + struct vlan_change_details vlan; + }; +}; + +#endif /* !(_LINUX_NOTIFIER_INFO_H_) */ diff --git a/net/core/dev.c b/net/core/dev.c index e233145d1452..b50470378994 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -1622,7 +1622,7 @@ const char *netdev_cmd_to_name(enum netdev_cmd cmd) N(POST_INIT) N(RELEASE) N(NOTIFY_PEERS) N(JOIN) N(CHANGEUPPER) N(RESEND_IGMP) N(PRECHANGEMTU) N(CHANGEINFODATA) N(BONDING_INFO) N(PRECHANGEUPPER) N(CHANGELOWERSTATE) N(UDP_TUNNEL_PUSH_INFO) - N(UDP_TUNNEL_DROP_INFO) N(CHANGE_TX_QUEUE_LEN) + N(UDP_TUNNEL_DROP_INFO) N(CHANGE_TX_QUEUE_LEN) N(CHANGE_DETAILS) N(CVLAN_FILTER_PUSH_INFO) N(CVLAN_FILTER_DROP_INFO) N(SVLAN_FILTER_PUSH_INFO) N(SVLAN_FILTER_DROP_INFO) N(PRE_CHANGEADDR) N(OFFLOAD_XSTATS_ENABLE) N(OFFLOAD_XSTATS_DISABLE) -- 2.34.1
Sevinj Aghayeva
2022-Sep-17 20:17 UTC
[Bridge] [PATCH RFC net-next 3/5] net: 8021q: notify bridge module of bridge-binding flag change
Notify the bridge module when a user changes the bridge-binding flag of a VLAN interface using "ip link set ... vlan bridge_binding on" command, so that the bridge module can take the appropriate action for this change. Signed-off-by: Sevinj Aghayeva <sevinj.aghayeva at gmail.com> --- net/8021q/vlan.h | 2 +- net/8021q/vlan_dev.c | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/net/8021q/vlan.h b/net/8021q/vlan.h index 5eaf38875554..71947cdcfaaa 100644 --- a/net/8021q/vlan.h +++ b/net/8021q/vlan.h @@ -130,7 +130,7 @@ void vlan_dev_set_ingress_priority(const struct net_device *dev, int vlan_dev_set_egress_priority(const struct net_device *dev, u32 skb_prio, u16 vlan_prio); void vlan_dev_free_egress_priority(const struct net_device *dev); -int vlan_dev_change_flags(const struct net_device *dev, u32 flag, u32 mask); +int vlan_dev_change_flags(struct net_device *dev, u32 flag, u32 mask); void vlan_dev_get_realdev_name(const struct net_device *dev, char *result, size_t size); diff --git a/net/8021q/vlan_dev.c b/net/8021q/vlan_dev.c index e1bb41a443c4..7c61b813e654 100644 --- a/net/8021q/vlan_dev.c +++ b/net/8021q/vlan_dev.c @@ -22,6 +22,7 @@ #include <linux/skbuff.h> #include <linux/netdevice.h> #include <linux/net_tstamp.h> +#include <linux/notifier_info.h> #include <linux/etherdevice.h> #include <linux/ethtool.h> #include <linux/phy.h> @@ -211,8 +212,9 @@ int vlan_dev_set_egress_priority(const struct net_device *dev, /* Flags are defined in the vlan_flags enum in * include/uapi/linux/if_vlan.h file. */ -int vlan_dev_change_flags(const struct net_device *dev, u32 flags, u32 mask) +int vlan_dev_change_flags(struct net_device *dev, u32 flags, u32 mask) { + struct netdev_notifier_change_details_info details; struct vlan_dev_priv *vlan = vlan_dev_priv(dev); u32 old_flags = vlan->flags; @@ -223,19 +225,31 @@ int vlan_dev_change_flags(const struct net_device *dev, u32 flags, u32 mask) vlan->flags = (old_flags & ~mask) | (flags & mask); - if (netif_running(dev) && (vlan->flags ^ old_flags) & VLAN_FLAG_GVRP) { + if (!netif_running(dev)) + return 0; + + if ((vlan->flags ^ old_flags) & VLAN_FLAG_GVRP) { if (vlan->flags & VLAN_FLAG_GVRP) vlan_gvrp_request_join(dev); else vlan_gvrp_request_leave(dev); } - if (netif_running(dev) && (vlan->flags ^ old_flags) & VLAN_FLAG_MVRP) { + if ((vlan->flags ^ old_flags) & VLAN_FLAG_MVRP) { if (vlan->flags & VLAN_FLAG_MVRP) vlan_mvrp_request_join(dev); else vlan_mvrp_request_leave(dev); } + + if ((vlan->flags ^ old_flags) & VLAN_FLAG_BRIDGE_BINDING && + netif_is_bridge_master(vlan->real_dev)) { + details.info.dev = dev; + details.vlan.bridge_binding + !!(vlan->flags & VLAN_FLAG_BRIDGE_BINDING); + call_netdevice_notifiers_info(NETDEV_CHANGE_DETAILS, &details.info); + } + return 0; } -- 2.34.1
Sevinj Aghayeva
2022-Sep-17 20:18 UTC
[Bridge] [PATCH RFC net-next 4/5] net: bridge: handle link-type-specific changes in the bridge module
Introduce a handler to bridge module for handling vlan-specific events. Signed-off-by: Sevinj Aghayeva <sevinj.aghayeva at gmail.com> --- net/bridge/br.c | 5 +++++ net/bridge/br_private.h | 7 +++++++ net/bridge/br_vlan.c | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/net/bridge/br.c b/net/bridge/br.c index 96e91d69a9a8..62e939c6a3f0 100644 --- a/net/bridge/br.c +++ b/net/bridge/br.c @@ -51,6 +51,11 @@ static int br_device_event(struct notifier_block *unused, unsigned long event, v } } + if (is_vlan_dev(dev)) { + br_vlan_device_event(dev, event, ptr); + return NOTIFY_DONE; + } + /* not a port of a bridge */ p = br_port_get_rtnl(dev); if (!p) diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index 06e5f6faa431..a9a08e49c76c 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -1470,6 +1470,8 @@ void br_vlan_get_stats(const struct net_bridge_vlan *v, void br_vlan_port_event(struct net_bridge_port *p, unsigned long event); int br_vlan_bridge_event(struct net_device *dev, unsigned long event, void *ptr); +void br_vlan_device_event(struct net_device *dev, unsigned long event, + void *ptr); void br_vlan_rtnl_init(void); void br_vlan_rtnl_uninit(void); void br_vlan_notify(const struct net_bridge *br, @@ -1701,6 +1703,11 @@ static inline int br_vlan_bridge_event(struct net_device *dev, return 0; } +static void br_vlan_device_event(struct net_device *dev, + unsigned long event, void *ptr) +{ +} + static inline void br_vlan_rtnl_init(void) { } diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c index 6e53dc991409..ba4e3c7a5f03 100644 --- a/net/bridge/br_vlan.c +++ b/net/bridge/br_vlan.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only #include <linux/kernel.h> #include <linux/netdevice.h> +#include <linux/notifier_info.h> #include <linux/rtnetlink.h> #include <linux/slab.h> #include <net/switchdev.h> @@ -1768,6 +1769,23 @@ void br_vlan_port_event(struct net_bridge_port *p, unsigned long event) } } +void br_vlan_device_event(struct net_device *dev, + unsigned long event, void *ptr) +{ + struct netdev_notifier_change_details_info *details; + struct net_device *br_dev; + + switch (event) { + case NETDEV_CHANGE_DETAILS: + details = ptr; + if (!netif_is_bridge_master(vlan_dev_priv(dev)->real_dev)) + break; + br_dev = vlan_dev_priv(dev)->real_dev; + br_vlan_upper_change(br_dev, dev, details->vlan.bridge_binding); + break; + } +} + static bool br_vlan_stats_fill(struct sk_buff *skb, const struct net_bridge_vlan *v) { -- 2.34.1
Sevinj Aghayeva
2022-Sep-17 20:18 UTC
[Bridge] [PATCH RFC net-next 5/5] selftests: net: tests for bridge binding behavior
This patch adds two tests in a single file. The first of these is in function run_test_late_bridge_binding_set, which tests that when a vlan interface is created with bridge binding turned off, and later bridge binding is turned on (using ip link set... command), the vlan interface behaves accordingly, that is, it tracks the status of the ports in its vlan. The second test, which is in function run_test_multiple_vlan, tests that when there are two vlan interfaces with bridge binding turned on, turning off the bridge binding in one of the vlan interfaces does not affect the bridge binding on the other interface. Signed-off-by: Sevinj Aghayeva <sevinj.aghayeva at gmail.com> --- tools/testing/selftests/net/Makefile | 1 + .../selftests/net/bridge_vlan_binding_test.sh | 143 ++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100755 tools/testing/selftests/net/bridge_vlan_binding_test.sh diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile index f5ac1433c301..48443928c3dd 100644 --- a/tools/testing/selftests/net/Makefile +++ b/tools/testing/selftests/net/Makefile @@ -44,6 +44,7 @@ TEST_PROGS += arp_ndisc_untracked_subnets.sh TEST_PROGS += stress_reuseport_listen.sh TEST_PROGS += l2_tos_ttl_inherit.sh TEST_PROGS += bind_bhash.sh +TEST_PROGS += bridge_vlan_binding_test.sh TEST_PROGS_EXTENDED := in_netns.sh setup_loopback.sh setup_veth.sh TEST_PROGS_EXTENDED += toeplitz_client.sh toeplitz.sh TEST_GEN_FILES = socket nettest diff --git a/tools/testing/selftests/net/bridge_vlan_binding_test.sh b/tools/testing/selftests/net/bridge_vlan_binding_test.sh new file mode 100755 index 000000000000..d094d847800c --- /dev/null +++ b/tools/testing/selftests/net/bridge_vlan_binding_test.sh @@ -0,0 +1,143 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-or-later + +cleanup() { + # Remove interfaces created by the previous run + ip link delete veth10 2>/dev/null + ip link delete veth20 2>/dev/null + ip link delete veth30 2>/dev/null + ip link delete br_default 2>/dev/null +} + +trap cleanup EXIT + +setup() { + cleanup + + # Create a bridge and add three ports to it. + ip link add dev br_default type bridge + ip link add dev veth10 type veth peer name veth11 + ip link add dev veth20 type veth peer name veth21 + ip link add dev veth30 type veth peer name veth31 + ip link set dev veth10 master br_default + ip link set dev veth20 master br_default + ip link set dev veth30 master br_default + + # Create VLAN 10 and VLAN 20. + bridge vlan add vid 10 dev br_default self + bridge vlan add vid 20 dev br_default self + + # Add veth10 to VLAN 10 and veth20 to VLAN 20. + bridge vlan add vid 10 dev veth10 + bridge vlan add vid 20 dev veth20 + + # Bring up the ports and the bridge. + ip link set veth10 up + ip link set veth11 up + ip link set veth20 up + ip link set veth21 up + ip link set veth30 up + ip link set veth31 up + ip link set br_default up +} + +# This test checks that when a vlan interface is created with bridge +# binding off, and then bridge binding turned on using "ip link set" +# command, bridge binding is actually turned on -- this hasn't been +# the case in the past. +run_test_late_bridge_binding_set() { + setup + + # Add VLAN interface vlan10 to VLAN 10 with bridge binding off. + ip link add link br_default name vlan10 type vlan id 10 protocol \ + 802.1q bridge_binding off + + # Bring up VLAN interface. + ip link set vlan10 up + + # Turn bridge binding on for vlan10. + ip link set vlan10 type vlan bridge_binding on + + # Bring down the port in vlan 10. + ip link set veth10 down + + # Since bridge binding is turned on for vlan10 interface, it + # should be tracking only the port, veth10 in its vlan. Since + # veth10 is down, vlan10 should be down as well. + if ! ip link show vlan10 | grep -q 'state LOWERLAYERDOWN'; then + echo "FAIL - vlan10 should be LOWERLAYERDOWN but it is not" + exit 1 + fi + + # Bringe the port back up. + ip link set veth10 up + + # The vlan 10 interface should be up now. + if ! ip link show vlan10 | grep -q 'state UP'; then + echo "FAIL - vlan10 should be UP but it is not" + exit 1 + fi + + echo "OK" +} + +# This test checks that when there are multiple vlan interfaces with +# bridge binding on, turning off bride binding in one of the vlan +# interfaces does not affect the bridge binding of the other +# interface. +run_test_multiple_vlan() { + setup + + # Add VLAN interface vlan10 to VLAN 10 with bridge binding on. + ip link add link br_default name vlan10 type vlan id 10 protocol \ + 802.1q bridge_binding on + # Add VLAN interface vlan20 to VLAN 20 with bridge binding on. + ip link add link br_default name vlan20 type vlan id 20 protocol \ + 802.1q bridge_binding on + + # Bring up VLAN interfaces. + ip link set vlan10 up + ip link set vlan20 up + + # Turn bridge binding off for vlan10. + ip link set vlan10 type vlan bridge_binding off + + # Bring down the ports in vlans 10 and 20. + ip link set veth10 down + ip link set veth20 down + + # Since bridge binding is off for vlan10 interface, it should + # be tracking all of the ports in the bridge; since veth30 is + # still up, vlan10 should also be up. + if ! ip link show vlan10 | grep -q 'state UP'; then + echo "FAIL - vlan10 should be UP but it is not" + exit 1 + fi + + # Since bridge binding is on for vlan20 interface, it should + # be tracking only the ports in its vlan. This port is veth20, + # and it is down; therefore, vlan20 should be down as well. + if ! ip link show vlan20 | grep -q 'state LOWERLAYERDOWN'; then + echo "FAIL - vlan20 should be LOWERLAYERDOWN but it is not" + exit 1 + fi + + # Bring the ports back up. + ip link set veth10 up + ip link set veth20 up + + # Both vlan interfaces should be up now. + if ! ip link show vlan10 | grep -q 'state UP'; then + echo "FAIL - vlan10 should be UP but it is not" + exit 1 + fi + if ! ip link show vlan20 | grep -q 'state UP' ; then + echo "FAIL - vlan20 should be UP but it is not" + exit 1 + fi + + echo "OK" +} + +run_test_late_bridge_binding_set +run_test_multiple_vlan -- 2.34.1
Nikolay Aleksandrov
2022-Sep-20 09:16 UTC
[Bridge] [PATCH RFC net-next 0/5] net: vlan: fix bridge binding behavior and add selftests
On 17/09/2022 23:17, Sevinj Aghayeva wrote:> When bridge binding is enabled for a vlan interface, it is expected > that the link state of the vlan interface will track the subset of the > ports that are also members of the corresponding vlan, rather than > that of all ports. > > Currently, this feature works as expected when a vlan interface is > created with bridge binding enabled: > > ip link add link br name vlan10 type vlan id 10 protocol 802.1q \ > bridge_binding on > > However, the feature does not work when a vlan interface is created > with bridge binding disabled, and then enabled later: > > ip link add link br name vlan10 type vlan id 10 protocol 802.1q \ > bridge_binding off > ip link set vlan10 type vlan bridge_binding on > > After these two commands, the link state of the vlan interface > continues to track that of all ports, which is inconsistent and > confusing to users. This series fixes this bug and introduces two > tests for the valid behavior. > > Sevinj Aghayeva (5): > net: core: export call_netdevice_notifiers_info > net: core: introduce a new notifier for link-type-specific changes > net: 8021q: notify bridge module of bridge-binding flag change > net: bridge: handle link-type-specific changes in the bridge module > selftests: net: tests for bridge binding behavior > > include/linux/if_vlan.h | 4 + > include/linux/netdevice.h | 3 + > include/linux/notifier_info.h | 21 +++ > net/8021q/vlan.h | 2 +- > net/8021q/vlan_dev.c | 20 ++- > net/bridge/br.c | 5 + > net/bridge/br_private.h | 7 + > net/bridge/br_vlan.c | 18 +++ > net/core/dev.c | 7 +- > tools/testing/selftests/net/Makefile | 1 + > .../selftests/net/bridge_vlan_binding_test.sh | 143 ++++++++++++++++++ > 11 files changed, 223 insertions(+), 8 deletions(-) > create mode 100644 include/linux/notifier_info.h > create mode 100755 tools/testing/selftests/net/bridge_vlan_binding_test.sh >The set looks good to me, the bridge and vlan direct dependency is gone and the new notification type is used for passing link type specific info. If the others are ok with it I think you can send it as non-RFC, but I'd give it a few more days at least. :) Thanks, Nik