vxlan: Join / leave MC group when reconfigured
Subsystems (4)
v2 cover vxlan: Join / leave MC group when reconfigured
When a vxlan netdevice is brought up, if its default remote is a multicast address, the device joins the indicated group.
Therefore when the multicast remote address changes, the device should leave the current group and subscribe to the new one. Similarly when the interface used for endpoint communication is changed in a situation when multicast remote is configured. This is currently not done.
Both vxlan_igmp_join() and vxlan_igmp_leave() can however fail. So it is possible that with such fix, the netdevice will end up in an inconsistent situation where the old group is not joined anymore, but joining the new group fails. Should we join the new group first, and leave the old one second, we might end up in the opposite situation, where both groups are joined. Undoing any of this during rollback is going to be similarly problematic.
One solution would be to just forbid the change when the netdevice is up. However in vnifilter mode, changing the group address is allowed, and these problems are simply ignored (see vxlan_vni_update_group()):
# ip link add name br up type bridge vlan_filtering 1 # ip link add vx1 up master br type vxlan external vnifilter local 192.0.2.1 dev lo dstport 4789 # bridge vni add dev vx1 vni 200 group 224.0.0.1 # tcpdump -i lo & # bridge vni add dev vx1 vni 200 group 224.0.0.2 18:55:46.523438 IP 0.0.0.0 > 224.0.0.22: igmp v3 report, 1 group record(s) 18:55:46.943447 IP 0.0.0.0 > 224.0.0.22: igmp v3 report, 1 group record(s) # bridge vni dev vni group/remote vx1 200 224.0.0.2
Having two different modes of operation for conceptually the same interface is silly, so in this patchset, just do what the vnifilter code does and deal with the errors by crossing fingers real hard.
v2:
- Patch #1:
- New patch.
- Patch #2:
- Adjust the code so that it is closer to vnifilter. Expand the commit message the explain in detail which aspects of vnifilter code were emulated.
Petr Machata (5):
vxlan: Drop 'changelink' parameter from vxlan_dev_configure()
vxlan: Join / leave MC group after remote changes
selftests: forwarding: lib: Move require_command to net, generalize
selftests: test_vxlan_fdb_changelink: Convert to lib.sh
selftests: test_vxlan_fdb_changelink: Add a test for MC remote change
drivers/net/vxlan/vxlan_core.c | 24 +++- tools/testing/selftests/net/forwarding/lib.sh | 10 -- tools/testing/selftests/net/lib.sh | 19 +++ .../net/test_vxlan_fdb_changelink.sh | 111 ++++++++++++++++-- 4 files changed, 136 insertions(+), 28 deletions(-)
Signature · 1 line
2.47.0
PATCH v2 1/5 vxlan: Drop 'changelink' parameter from vxlan_dev_configure()
vxlan_dev_configure() only has a single caller that passes false for the changelink parameter. Drop the parameter and inline the sole value.
---
Notes:
v2:
- New patch.
---
CC: Andrew Lunn <[email protected]>
CC: Nikolay Aleksandrov <[email protected]>
CC: Roopa Prabhu <[email protected]>
CC: Menglong Dong <[email protected]>
CC: Guillaume Nault <[email protected]>
drivers/net/vxlan/vxlan_core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/vxlan/vxlan_core.c +3 -3
@@ -3936,7 +3936,7 @@ static void vxlan_config_apply(struct net_device *dev, }static int vxlan_dev_configure (struct net *src_net,struct net_device *dev, -struct vxlan_config *conf,bool changelink, +struct vxlan_config *conf,struct netlink_ext_ack *extack) {struct vxlan_dev *vxlan =netdev_priv (dev);
@@ -3947,7 +3947,7 @@ static int vxlan_dev_configure(struct net *src_net, struct net_device *dev,if (ret)return ret; -vxlan_config_apply (dev, conf, lowerdev, src_net, changelink); +vxlan_config_apply (dev, conf, lowerdev, src_net, false);return 0 ; }
@@ -3965,7 +3965,7 @@ static int __vxlan_dev_create(struct net *net, struct net_device *dev,int err; dst = &vxlan->default_dst; - err =vxlan_dev_configure (net, dev, conf, false, extack); + err =vxlan_dev_configure (net, dev, conf, extack);if (err)return err;
Signature · 1 line
2.47.0
PATCH v2 2/5 vxlan: Join / leave MC group after remote changes
In reply to Petr MachataWhen a vxlan netdevice is brought up, if its default remote is a multicast address, the device joins the indicated group.
Therefore when the multicast remote address changes, the device should leave the current group and subscribe to the new one. Similarly when the interface used for endpoint communication is changed in a situation when multicast remote is configured. This is currently not done.
Both vxlan_igmp_join() and vxlan_igmp_leave() can however fail. So it is possible that with such fix, the netdevice will end up in an inconsistent situation where the old group is not joined anymore, but joining the new group fails. Should we join the new group first, and leave the old one second, we might end up in the opposite situation, where both groups are joined. Undoing any of this during rollback is going to be similarly problematic.
One solution would be to just forbid the change when the netdevice is up. However in vnifilter mode, changing the group address is allowed, and these problems are simply ignored (see vxlan_vni_update_group()):
# ip link add name br up type bridge vlan_filtering 1 # ip link add vx1 up master br type vxlan external vnifilter local 192.0.2.1 dev lo dstport 4789 # bridge vni add dev vx1 vni 200 group 224.0.0.1 # tcpdump -i lo & # bridge vni add dev vx1 vni 200 group 224.0.0.2 18:55:46.523438 IP 0.0.0.0 > 224.0.0.22: igmp v3 report, 1 group record(s) 18:55:46.943447 IP 0.0.0.0 > 224.0.0.22: igmp v3 report, 1 group record(s) # bridge vni dev vni group/remote vx1 200 224.0.0.2
Having two different modes of operation for conceptually the same interface is silly, so in this patch, just do what the vnifilter code does and deal with the errors by crossing fingers real hard.
The vnifilter code leaves old before joining new, and in case of join / leave failures does not roll back the configuration changes that have already been applied, but bails out of joining if it could not leave. Do the same here: leave before join, apply changes unconditionally and do not attempt to join if we couldn't leave.
---
Notes:
v2:
- Adjust the code so that it is closer to vnifilter. Expand the commit message the explain in detail which aspects of vnifilter code were emulated.
---
CC: Andrew Lunn <[email protected]>
CC: Nikolay Aleksandrov <[email protected]>
CC: Roopa Prabhu <[email protected]>
CC: Menglong Dong <[email protected]>
CC: Guillaume Nault <[email protected]>
drivers/net/vxlan/vxlan_core.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
drivers/net/vxlan/vxlan_core.c +16 -2
@@ -4419,6 +4419,7 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[], struct netlink_ext_ack *extack) {struct vxlan_dev *vxlan =netdev_priv (dev); +bool rem_ip_changed, change_igmp;struct net_device *lowerdev;struct vxlan_config conf;struct vxlan_rdst *dst;
@@ -4442,8 +4443,13 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[],if (err)return err; + rem_ip_changed = !vxlan_addr_equal (&conf.remote_ip, &dst->remote_ip); + change_igmp = vxlan->dev->flags &IFF_UP && + (rem_ip_changed || + dst->remote_ifindex != conf.remote_ifindex); +/* handle default dst entry */ -if (!vxlan_addr_equal (&conf.remote_ip, &dst->remote_ip)) { +if (rem_ip_changed) {u32 hash_index =fdb_head_index (vxlan, all_zeros_mac, conf.vni);spin_lock_bh (&vxlan->hash_lock[hash_index]);
@@ -4487,6 +4493,9 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[], } } +if (change_igmp &&vxlan_addr_multicast (&dst->remote_ip)) + err =vxlan_multicast_leave (vxlan); +if (conf.age_interval != vxlan->cfg.age_interval)mod_timer (&vxlan->age_timer, jiffies);
@@ -4494,7 +4503,12 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[],if (lowerdev && lowerdev != dst->remote_dev) dst->remote_dev = lowerdev;vxlan_config_apply (dev, &conf, lowerdev, vxlan->net, true); -return 0 ; + +if (!err && change_igmp && +vxlan_addr_multicast (&dst->remote_ip)) + err =vxlan_multicast_join (vxlan); + +return err; }static void vxlan_dellink (struct net_device *dev,struct list_head *head)
Signature · 1 line
2.47.0
PATCH v2 3/5 selftests: forwarding: lib: Move require_command to net, generalize
In reply to Petr MachataThis helper could be useful to more than just forwarding tests. Move it upstairs and port over to log_test_skip().
Split the function into two parts: the bit that actually checks and reports skip, which is in a new function check_command(). And a bit that exits the test script if the check fails. This allows users consistent checking behavior while giving an option to bail out from a single test without bailing out of the whole script.
---
Notes:
CC: Simon Horman <[email protected]>
CC: Shuah Khan <[email protected]>
CC: [email protected]
tools/testing/selftests/net/forwarding/lib.sh | 10 ---------- tools/testing/selftests/net/lib.sh | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 10 deletions(-)
tools/testing/selftests/net/forwarding/lib.sh +0 -10
@@ -291,16 +291,6 @@ if [[ "$CHECK_TC" = "yes" ]]; then check_tc_version fi -require_command() -{ - local cmd=$1; shift - - if [[ ! -x "$(command -v "$cmd")" ]]; then - echo "SKIP: $cmd not installed" - exit $ksft_skip - fi -} - # IPv6 support was added in v3.0 check_mtools_version() {
tools/testing/selftests/net/lib.sh +19 -0
@@ -450,6 +450,25 @@ kill_process() { kill $pid && wait $pid; } 2>/dev/null } +check_command() +{ + local cmd=$1; shift + + if [[ ! -x "$(command -v "$cmd")" ]]; then + log_test_skip "$cmd not installed" + return $EXIT_STATUS + fi +} + +require_command() +{ + local cmd=$1; shift + + if ! check_command "$cmd"; then + exit $EXIT_STATUS + fi +} + ip_link_add() { local name=$1; shift
Signature · 1 line
2.47.0
PATCH v2 4/5 selftests: test_vxlan_fdb_changelink: Convert to lib.sh
In reply to Petr MachataInstead of inlining equivalents, use lib.sh-provided primitives. Use defer to manage vx lifetime.
This will make it easier to extend the test in the next patch.
---
Notes:
CC: Simon Horman <[email protected]>
CC: Shuah Khan <[email protected]>
CC: [email protected]
.../net/test_vxlan_fdb_changelink.sh | 39 ++++++++++++------- 1 file changed, 24 insertions(+), 15 deletions(-)
tools/testing/selftests/net/test_vxlan_fdb_changelink.sh +24 -15
@@ -1,29 +1,38 @@ #!/bin/bash # SPDX-License-Identifier: GPL-2.0 -# Check FDB default-remote handling across "ip link set". +ALL_TESTS=" + test_set_remote +" +source lib.sh check_remotes() { local what=$1; shift local N=$(bridge fdb sh dev vx | grep 00:00:00:00:00:00 | wc -l) - echo -ne "expected two remotes after $what\t" - if [[ $N != 2 ]]; then - echo "[FAIL]" - EXIT_STATUS=1 - else - echo "[ OK ]" - fi + ((N == 2)) + check_err $? "expected 2 remotes after $what, got $N" } -ip link add name vx up type vxlan id 2000 dstport 4789 -bridge fdb ap dev vx 00:00:00:00:00:00 dst 192.0.2.20 self permanent -bridge fdb ap dev vx 00:00:00:00:00:00 dst 192.0.2.30 self permanent -check_remotes "fdb append" +# Check FDB default-remote handling across "ip link set". +test_set_remote() +{ + RET=0 -ip link set dev vx type vxlan remote 192.0.2.30 -check_remotes "link set" + ip_link_add vx up type vxlan id 2000 dstport 4789 + bridge fdb ap dev vx 00:00:00:00:00:00 dst 192.0.2.20 self permanent + bridge fdb ap dev vx 00:00:00:00:00:00 dst 192.0.2.30 self permanent + check_remotes "fdb append" + + ip link set dev vx type vxlan remote 192.0.2.30 + check_remotes "link set" + + log_test 'FDB default-remote handling across "ip link set"' +} + +trap defer_scopes_cleanup EXIT + +tests_run -ip link del dev vx exit $EXIT_STATUS
Signature · 1 line
2.47.0
PATCH v2 5/5 selftests: test_vxlan_fdb_changelink: Add a test for MC remote change
In reply to Petr MachataChanges to MC remote need to be reflected in actual group memberships. Add a test to verify that it is the case.
---
Notes:
CC: Simon Horman <[email protected]>
CC: Shuah Khan <[email protected]>
CC: [email protected]
.../net/test_vxlan_fdb_changelink.sh | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+)
tools/testing/selftests/net/test_vxlan_fdb_changelink.sh +76 -0
@@ -3,6 +3,7 @@ ALL_TESTS=" test_set_remote + test_change_mc_remote " source lib.sh
@@ -31,6 +32,81 @@ test_set_remote() log_test 'FDB default-remote handling across "ip link set"' } +fmt_remote() +{ + local addr=$1; shift + + if [[ $addr == 224.* ]]; then + echo "group $addr" + else + echo "remote $addr" + fi +} + +change_remote() +{ + local remote=$1; shift + + ip link set dev vx type vxlan $(fmt_remote $remote) dev v1 +} + +check_membership() +{ + local check_vec=("$@") + + local memberships + memberships=$( + netstat -n --groups | + sed -n '/^v1\b/p' | + grep -o '[^ ]*$' + ) + check_err $? "Couldn't obtain group memberships" + + local item + for item in "${check_vec[@]}"; do + eval "local $item" + echo "$memberships" | grep -q "\b$group\b" + check_err_fail $fail $? "$group is_ex reported in IGMP query response" + done +} + +test_change_mc_remote() +{ + check_command netstat || return + + ip_link_add v1 up type veth peer name v2 + ip_link_set_up v2 + + RET=0 + + ip_link_add vx up type vxlan dstport 4789 \ + local 192.0.2.1 $(fmt_remote 224.1.1.1) dev v1 vni 1000 + + check_membership "group=224.1.1.1 fail=0" \ + "group=224.1.1.2 fail=1" \ + "group=224.1.1.3 fail=1" + + log_test "MC group report after VXLAN creation" + + RET=0 + + change_remote 224.1.1.2 + check_membership "group=224.1.1.1 fail=1" \ + "group=224.1.1.2 fail=0" \ + "group=224.1.1.3 fail=1" + + log_test "MC group report after changing VXLAN remote MC->MC" + + RET=0 + + change_remote 192.0.2.2 + check_membership "group=224.1.1.1 fail=1" \ + "group=224.1.1.2 fail=1" \ + "group=224.1.1.3 fail=1" + + log_test "MC group report after changing VXLAN remote MC->UC" +} + trap defer_scopes_cleanup EXIT tests_run
Signature · 1 line
2.47.0
Quoted 50 lines · Petr Machata
When a vxlan netdevice is brought up, if its default remote is a multicast address, the device joins the indicated group.
Therefore when the multicast remote address changes, the device should leave the current group and subscribe to the new one. Similarly when the interface used for endpoint communication is changed in a situation when multicast remote is configured. This is currently not done.
Both
vxlan_igmp_join()andvxlan_igmp_leave()can however fail. So it is possible that with such fix, the netdevice will end up in an inconsistent situation where the old group is not joined anymore, but joining the new group fails. Should we join the new group first, and leave the old one second, we might end up in the opposite situation, where both groups are joined. Undoing any of this during rollback is going to be similarly problematic.One solution would be to just forbid the change when the netdevice is up. However in vnifilter mode, changing the group address is allowed, and these problems are simply ignored (see
vxlan_vni_update_group()):# ip link add name br up type bridge vlan_filtering 1 # ip link add vx1 up master br type vxlan external vnifilter local 192.0.2.1 dev lo dstport 4789 # bridge vni add dev vx1 vni 200 group 224.0.0.1 # tcpdump -i lo & # bridge vni add dev vx1 vni 200 group 224.0.0.2 18:55:46.523438 IP 0.0.0.0 > 224.0.0.22: igmp v3 report, 1 group record(s) 18:55:46.943447 IP 0.0.0.0 > 224.0.0.22: igmp v3 report, 1 group record(s) # bridge vni dev vni group/remote vx1 200 224.0.0.2Having two different modes of operation for conceptually the same interface is silly, so in this patchset, just do what the vnifilter code does and deal with the errors by crossing fingers real hard.
v2:
- Patch #1:
- New patch.
- Patch #2:
- Adjust the code so that it is closer to vnifilter. Expand the commit message the explain in detail which aspects of vnifilter code were emulated.Petr Machata (5):
vxlan: Drop 'changelink' parameter fromvxlan_dev_configure()
vxlan: Join / leave MC group after remote changes
selftests: forwarding: lib: Moverequire_commandto net, generalize
selftests:test_vxlan_fdb_changelink: Convert tolib.sh
selftests:test_vxlan_fdb_changelink: Add a test for MC remote change
Quoted 6 lines
drivers/net/vxlan/vxlan_core.c | 24 +++- tools/testing/selftests/net/forwarding/lib.sh | 10 -- tools/testing/selftests/net/lib.sh | 19 +++ .../net/test_vxlan_fdb_changelink.sh | 111 ++++++++++++++++-- 4 files changed, 136 insertions(+), 28 deletions(-)
For the set:
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 9 lines · On Fri, 14 Feb 2025 17:18:19 +0100 you wrote:
When a vxlan netdevice is brought up, if its default remote is a multicast address, the device joins the indicated group.
Therefore when the multicast remote address changes, the device should leave the current group and subscribe to the new one. Similarly when the interface used for endpoint communication is changed in a situation when multicast remote is configured. This is currently not done.
[...]
Here is the summary with links:
- [net-next,v2,1/5] vxlan: Drop 'changelink' parameter from vxlan_dev_configure()
https://git.kernel.org/netdev/net-next/c/5afb1596b90c - [net-next,v2,2/5] vxlan: Join / leave MC group after remote changes https://git.kernel.org/netdev/net-next/c/d42d54336834 - [net-next,v2,3/5] selftests: forwarding: lib: Move require_command to net, generalize https://git.kernel.org/netdev/net-next/c/f802f172d78b - [net-next,v2,4/5] selftests: test_vxlan_fdb_changelink: Convert to lib.sh https://git.kernel.org/netdev/net-next/c/24adf47ea9ac - [net-next,v2,5/5] selftests: test_vxlan_fdb_changelink: Add a test for MC remote change https://git.kernel.org/netdev/net-next/c/eae1e92a1d41
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html