Skip to content

Commit 01072de

Browse files
author
Paolo Abeni
committed
Merge branch 'vxlan-join-leave-mc-group-when-reconfigured'
Petr Machata says: ==================== 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. ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
2 parents 43130d0 + eae1e92 commit 01072de

File tree

4 files changed

+136
-28
lines changed

4 files changed

+136
-28
lines changed

drivers/net/vxlan/vxlan_core.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3936,7 +3936,7 @@ static void vxlan_config_apply(struct net_device *dev,
39363936
}
39373937

39383938
static int vxlan_dev_configure(struct net *src_net, struct net_device *dev,
3939-
struct vxlan_config *conf, bool changelink,
3939+
struct vxlan_config *conf,
39403940
struct netlink_ext_ack *extack)
39413941
{
39423942
struct vxlan_dev *vxlan = netdev_priv(dev);
@@ -3947,7 +3947,7 @@ static int vxlan_dev_configure(struct net *src_net, struct net_device *dev,
39473947
if (ret)
39483948
return ret;
39493949

3950-
vxlan_config_apply(dev, conf, lowerdev, src_net, changelink);
3950+
vxlan_config_apply(dev, conf, lowerdev, src_net, false);
39513951

39523952
return 0;
39533953
}
@@ -3965,7 +3965,7 @@ static int __vxlan_dev_create(struct net *net, struct net_device *dev,
39653965
int err;
39663966

39673967
dst = &vxlan->default_dst;
3968-
err = vxlan_dev_configure(net, dev, conf, false, extack);
3968+
err = vxlan_dev_configure(net, dev, conf, extack);
39693969
if (err)
39703970
return err;
39713971

@@ -4419,6 +4419,7 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[],
44194419
struct netlink_ext_ack *extack)
44204420
{
44214421
struct vxlan_dev *vxlan = netdev_priv(dev);
4422+
bool rem_ip_changed, change_igmp;
44224423
struct net_device *lowerdev;
44234424
struct vxlan_config conf;
44244425
struct vxlan_rdst *dst;
@@ -4442,8 +4443,13 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[],
44424443
if (err)
44434444
return err;
44444445

4446+
rem_ip_changed = !vxlan_addr_equal(&conf.remote_ip, &dst->remote_ip);
4447+
change_igmp = vxlan->dev->flags & IFF_UP &&
4448+
(rem_ip_changed ||
4449+
dst->remote_ifindex != conf.remote_ifindex);
4450+
44454451
/* handle default dst entry */
4446-
if (!vxlan_addr_equal(&conf.remote_ip, &dst->remote_ip)) {
4452+
if (rem_ip_changed) {
44474453
u32 hash_index = fdb_head_index(vxlan, all_zeros_mac, conf.vni);
44484454

44494455
spin_lock_bh(&vxlan->hash_lock[hash_index]);
@@ -4487,14 +4493,22 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[],
44874493
}
44884494
}
44894495

4496+
if (change_igmp && vxlan_addr_multicast(&dst->remote_ip))
4497+
err = vxlan_multicast_leave(vxlan);
4498+
44904499
if (conf.age_interval != vxlan->cfg.age_interval)
44914500
mod_timer(&vxlan->age_timer, jiffies);
44924501

44934502
netdev_adjacent_change_commit(dst->remote_dev, lowerdev, dev);
44944503
if (lowerdev && lowerdev != dst->remote_dev)
44954504
dst->remote_dev = lowerdev;
44964505
vxlan_config_apply(dev, &conf, lowerdev, vxlan->net, true);
4497-
return 0;
4506+
4507+
if (!err && change_igmp &&
4508+
vxlan_addr_multicast(&dst->remote_ip))
4509+
err = vxlan_multicast_join(vxlan);
4510+
4511+
return err;
44984512
}
44994513

45004514
static void vxlan_dellink(struct net_device *dev, struct list_head *head)

tools/testing/selftests/net/forwarding/lib.sh

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -291,16 +291,6 @@ if [[ "$CHECK_TC" = "yes" ]]; then
291291
check_tc_version
292292
fi
293293

294-
require_command()
295-
{
296-
local cmd=$1; shift
297-
298-
if [[ ! -x "$(command -v "$cmd")" ]]; then
299-
echo "SKIP: $cmd not installed"
300-
exit $ksft_skip
301-
fi
302-
}
303-
304294
# IPv6 support was added in v3.0
305295
check_mtools_version()
306296
{

tools/testing/selftests/net/lib.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,25 @@ kill_process()
450450
{ kill $pid && wait $pid; } 2>/dev/null
451451
}
452452

453+
check_command()
454+
{
455+
local cmd=$1; shift
456+
457+
if [[ ! -x "$(command -v "$cmd")" ]]; then
458+
log_test_skip "$cmd not installed"
459+
return $EXIT_STATUS
460+
fi
461+
}
462+
463+
require_command()
464+
{
465+
local cmd=$1; shift
466+
467+
if ! check_command "$cmd"; then
468+
exit $EXIT_STATUS
469+
fi
470+
}
471+
453472
ip_link_add()
454473
{
455474
local name=$1; shift
Lines changed: 98 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,114 @@
11
#!/bin/bash
22
# SPDX-License-Identifier: GPL-2.0
33

4-
# Check FDB default-remote handling across "ip link set".
4+
ALL_TESTS="
5+
test_set_remote
6+
test_change_mc_remote
7+
"
8+
source lib.sh
59

610
check_remotes()
711
{
812
local what=$1; shift
913
local N=$(bridge fdb sh dev vx | grep 00:00:00:00:00:00 | wc -l)
1014

11-
echo -ne "expected two remotes after $what\t"
12-
if [[ $N != 2 ]]; then
13-
echo "[FAIL]"
14-
EXIT_STATUS=1
15+
((N == 2))
16+
check_err $? "expected 2 remotes after $what, got $N"
17+
}
18+
19+
# Check FDB default-remote handling across "ip link set".
20+
test_set_remote()
21+
{
22+
RET=0
23+
24+
ip_link_add vx up type vxlan id 2000 dstport 4789
25+
bridge fdb ap dev vx 00:00:00:00:00:00 dst 192.0.2.20 self permanent
26+
bridge fdb ap dev vx 00:00:00:00:00:00 dst 192.0.2.30 self permanent
27+
check_remotes "fdb append"
28+
29+
ip link set dev vx type vxlan remote 192.0.2.30
30+
check_remotes "link set"
31+
32+
log_test 'FDB default-remote handling across "ip link set"'
33+
}
34+
35+
fmt_remote()
36+
{
37+
local addr=$1; shift
38+
39+
if [[ $addr == 224.* ]]; then
40+
echo "group $addr"
1541
else
16-
echo "[ OK ]"
42+
echo "remote $addr"
1743
fi
1844
}
1945

20-
ip link add name vx up type vxlan id 2000 dstport 4789
21-
bridge fdb ap dev vx 00:00:00:00:00:00 dst 192.0.2.20 self permanent
22-
bridge fdb ap dev vx 00:00:00:00:00:00 dst 192.0.2.30 self permanent
23-
check_remotes "fdb append"
46+
change_remote()
47+
{
48+
local remote=$1; shift
49+
50+
ip link set dev vx type vxlan $(fmt_remote $remote) dev v1
51+
}
52+
53+
check_membership()
54+
{
55+
local check_vec=("$@")
56+
57+
local memberships
58+
memberships=$(
59+
netstat -n --groups |
60+
sed -n '/^v1\b/p' |
61+
grep -o '[^ ]*$'
62+
)
63+
check_err $? "Couldn't obtain group memberships"
64+
65+
local item
66+
for item in "${check_vec[@]}"; do
67+
eval "local $item"
68+
echo "$memberships" | grep -q "\b$group\b"
69+
check_err_fail $fail $? "$group is_ex reported in IGMP query response"
70+
done
71+
}
72+
73+
test_change_mc_remote()
74+
{
75+
check_command netstat || return
76+
77+
ip_link_add v1 up type veth peer name v2
78+
ip_link_set_up v2
79+
80+
RET=0
81+
82+
ip_link_add vx up type vxlan dstport 4789 \
83+
local 192.0.2.1 $(fmt_remote 224.1.1.1) dev v1 vni 1000
84+
85+
check_membership "group=224.1.1.1 fail=0" \
86+
"group=224.1.1.2 fail=1" \
87+
"group=224.1.1.3 fail=1"
88+
89+
log_test "MC group report after VXLAN creation"
90+
91+
RET=0
92+
93+
change_remote 224.1.1.2
94+
check_membership "group=224.1.1.1 fail=1" \
95+
"group=224.1.1.2 fail=0" \
96+
"group=224.1.1.3 fail=1"
97+
98+
log_test "MC group report after changing VXLAN remote MC->MC"
99+
100+
RET=0
101+
102+
change_remote 192.0.2.2
103+
check_membership "group=224.1.1.1 fail=1" \
104+
"group=224.1.1.2 fail=1" \
105+
"group=224.1.1.3 fail=1"
106+
107+
log_test "MC group report after changing VXLAN remote MC->UC"
108+
}
109+
110+
trap defer_scopes_cleanup EXIT
24111

25-
ip link set dev vx type vxlan remote 192.0.2.30
26-
check_remotes "link set"
112+
tests_run
27113

28-
ip link del dev vx
29114
exit $EXIT_STATUS

0 commit comments

Comments
 (0)