Skip to content

Commit b251610

Browse files
author
Paolo Abeni
committed
Merge branch 'fix-macvlan-over-alb-bond-support'
Hangbin Liu says: ==================== fix macvlan over alb bond support Currently, the macvlan over alb bond is broken after commit 14af996 ("bonding: Support macvlans on top of tlb/rlb mode bonds"). Fix this and add relate tests. ==================== Link: https://lore.kernel.org/r/20230823071907.3027782-1-liuhangbin@gmail.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2 parents 30188bd + 246af95 commit b251610

File tree

7 files changed

+272
-127
lines changed

7 files changed

+272
-127
lines changed

drivers/net/bonding/bond_alb.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -660,10 +660,10 @@ static struct slave *rlb_arp_xmit(struct sk_buff *skb, struct bonding *bond)
660660
return NULL;
661661
arp = (struct arp_pkt *)skb_network_header(skb);
662662

663-
/* Don't modify or load balance ARPs that do not originate locally
664-
* (e.g.,arrive via a bridge).
663+
/* Don't modify or load balance ARPs that do not originate
664+
* from the bond itself or a VLAN directly above the bond.
665665
*/
666-
if (!bond_slave_has_mac_rx(bond, arp->mac_src))
666+
if (!bond_slave_has_mac_rcu(bond, arp->mac_src))
667667
return NULL;
668668

669669
dev = ip_dev_find(dev_net(bond->dev), arp->ip_src);

include/net/bonding.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -722,23 +722,14 @@ static inline struct slave *bond_slave_has_mac(struct bonding *bond,
722722
}
723723

724724
/* Caller must hold rcu_read_lock() for read */
725-
static inline bool bond_slave_has_mac_rx(struct bonding *bond, const u8 *mac)
725+
static inline bool bond_slave_has_mac_rcu(struct bonding *bond, const u8 *mac)
726726
{
727727
struct list_head *iter;
728728
struct slave *tmp;
729-
struct netdev_hw_addr *ha;
730729

731730
bond_for_each_slave_rcu(bond, tmp, iter)
732731
if (ether_addr_equal_64bits(mac, tmp->dev->dev_addr))
733732
return true;
734-
735-
if (netdev_uc_empty(bond->dev))
736-
return false;
737-
738-
netdev_for_each_uc_addr(ha, bond->dev)
739-
if (ether_addr_equal_64bits(mac, ha->addr))
740-
return true;
741-
742733
return false;
743734
}
744735

tools/testing/selftests/drivers/net/bonding/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ TEST_PROGS := \
99
mode-1-recovery-updelay.sh \
1010
mode-2-recovery-updelay.sh \
1111
bond_options.sh \
12-
bond-eth-type-change.sh
12+
bond-eth-type-change.sh \
13+
bond_macvlan.sh
1314

1415
TEST_FILES := \
1516
lag_lib.sh \
17+
bond_topo_2d1c.sh \
1618
bond_topo_3d1c.sh \
1719
net_forwarding_lib.sh
1820

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
#
4+
# Test macvlan over balance-alb
5+
6+
lib_dir=$(dirname "$0")
7+
source ${lib_dir}/bond_topo_2d1c.sh
8+
9+
m1_ns="m1-$(mktemp -u XXXXXX)"
10+
m2_ns="m1-$(mktemp -u XXXXXX)"
11+
m1_ip4="192.0.2.11"
12+
m1_ip6="2001:db8::11"
13+
m2_ip4="192.0.2.12"
14+
m2_ip6="2001:db8::12"
15+
16+
cleanup()
17+
{
18+
ip -n ${m1_ns} link del macv0
19+
ip netns del ${m1_ns}
20+
ip -n ${m2_ns} link del macv0
21+
ip netns del ${m2_ns}
22+
23+
client_destroy
24+
server_destroy
25+
gateway_destroy
26+
}
27+
28+
check_connection()
29+
{
30+
local ns=${1}
31+
local target=${2}
32+
local message=${3:-"macvlan_over_bond"}
33+
RET=0
34+
35+
36+
ip netns exec ${ns} ping ${target} -c 4 -i 0.1 &>/dev/null
37+
check_err $? "ping failed"
38+
log_test "$mode: $message"
39+
}
40+
41+
macvlan_over_bond()
42+
{
43+
local param="$1"
44+
RET=0
45+
46+
# setup new bond mode
47+
bond_reset "${param}"
48+
49+
ip -n ${s_ns} link add link bond0 name macv0 type macvlan mode bridge
50+
ip -n ${s_ns} link set macv0 netns ${m1_ns}
51+
ip -n ${m1_ns} link set dev macv0 up
52+
ip -n ${m1_ns} addr add ${m1_ip4}/24 dev macv0
53+
ip -n ${m1_ns} addr add ${m1_ip6}/24 dev macv0
54+
55+
ip -n ${s_ns} link add link bond0 name macv0 type macvlan mode bridge
56+
ip -n ${s_ns} link set macv0 netns ${m2_ns}
57+
ip -n ${m2_ns} link set dev macv0 up
58+
ip -n ${m2_ns} addr add ${m2_ip4}/24 dev macv0
59+
ip -n ${m2_ns} addr add ${m2_ip6}/24 dev macv0
60+
61+
sleep 2
62+
63+
check_connection "${c_ns}" "${s_ip4}" "IPv4: client->server"
64+
check_connection "${c_ns}" "${s_ip6}" "IPv6: client->server"
65+
check_connection "${c_ns}" "${m1_ip4}" "IPv4: client->macvlan_1"
66+
check_connection "${c_ns}" "${m1_ip6}" "IPv6: client->macvlan_1"
67+
check_connection "${c_ns}" "${m2_ip4}" "IPv4: client->macvlan_2"
68+
check_connection "${c_ns}" "${m2_ip6}" "IPv6: client->macvlan_2"
69+
check_connection "${m1_ns}" "${m2_ip4}" "IPv4: macvlan_1->macvlan_2"
70+
check_connection "${m1_ns}" "${m2_ip6}" "IPv6: macvlan_1->macvlan_2"
71+
72+
73+
sleep 5
74+
75+
check_connection "${s_ns}" "${c_ip4}" "IPv4: server->client"
76+
check_connection "${s_ns}" "${c_ip6}" "IPv6: server->client"
77+
check_connection "${m1_ns}" "${c_ip4}" "IPv4: macvlan_1->client"
78+
check_connection "${m1_ns}" "${c_ip6}" "IPv6: macvlan_1->client"
79+
check_connection "${m2_ns}" "${c_ip4}" "IPv4: macvlan_2->client"
80+
check_connection "${m2_ns}" "${c_ip6}" "IPv6: macvlan_2->client"
81+
check_connection "${m2_ns}" "${m1_ip4}" "IPv4: macvlan_2->macvlan_2"
82+
check_connection "${m2_ns}" "${m1_ip6}" "IPv6: macvlan_2->macvlan_2"
83+
84+
ip -n ${c_ns} neigh flush dev eth0
85+
}
86+
87+
trap cleanup EXIT
88+
89+
setup_prepare
90+
ip netns add ${m1_ns}
91+
ip netns add ${m2_ns}
92+
93+
modes="active-backup balance-tlb balance-alb"
94+
95+
for mode in $modes; do
96+
macvlan_over_bond "mode $mode"
97+
done
98+
99+
exit $EXIT_STATUS

tools/testing/selftests/drivers/net/bonding/bond_options.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ ALL_TESTS="
99
num_grat_arp
1010
"
1111

12-
REQUIRE_MZ=no
13-
NUM_NETIFS=0
1412
lib_dir=$(dirname "$0")
15-
source ${lib_dir}/net_forwarding_lib.sh
1613
source ${lib_dir}/bond_topo_3d1c.sh
1714

1815
skip_prio()
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
#
4+
# Topology for Bond mode 1,5,6 testing
5+
#
6+
# +-------------------------+
7+
# | bond0 | Server
8+
# | + | 192.0.2.1/24
9+
# | eth0 | eth1 | 2001:db8::1/24
10+
# | +---+---+ |
11+
# | | | |
12+
# +-------------------------+
13+
# | |
14+
# +-------------------------+
15+
# | | | |
16+
# | +---+-------+---+ | Gateway
17+
# | | br0 | | 192.0.2.254/24
18+
# | +-------+-------+ | 2001:db8::254/24
19+
# | | |
20+
# +-------------------------+
21+
# |
22+
# +-------------------------+
23+
# | | | Client
24+
# | + | 192.0.2.10/24
25+
# | eth0 | 2001:db8::10/24
26+
# +-------------------------+
27+
28+
REQUIRE_MZ=no
29+
NUM_NETIFS=0
30+
lib_dir=$(dirname "$0")
31+
source ${lib_dir}/net_forwarding_lib.sh
32+
33+
s_ns="s-$(mktemp -u XXXXXX)"
34+
c_ns="c-$(mktemp -u XXXXXX)"
35+
g_ns="g-$(mktemp -u XXXXXX)"
36+
s_ip4="192.0.2.1"
37+
c_ip4="192.0.2.10"
38+
g_ip4="192.0.2.254"
39+
s_ip6="2001:db8::1"
40+
c_ip6="2001:db8::10"
41+
g_ip6="2001:db8::254"
42+
43+
gateway_create()
44+
{
45+
ip netns add ${g_ns}
46+
ip -n ${g_ns} link add br0 type bridge
47+
ip -n ${g_ns} link set br0 up
48+
ip -n ${g_ns} addr add ${g_ip4}/24 dev br0
49+
ip -n ${g_ns} addr add ${g_ip6}/24 dev br0
50+
}
51+
52+
gateway_destroy()
53+
{
54+
ip -n ${g_ns} link del br0
55+
ip netns del ${g_ns}
56+
}
57+
58+
server_create()
59+
{
60+
ip netns add ${s_ns}
61+
ip -n ${s_ns} link add bond0 type bond mode active-backup miimon 100
62+
63+
for i in $(seq 0 1); do
64+
ip -n ${s_ns} link add eth${i} type veth peer name s${i} netns ${g_ns}
65+
66+
ip -n ${g_ns} link set s${i} up
67+
ip -n ${g_ns} link set s${i} master br0
68+
ip -n ${s_ns} link set eth${i} master bond0
69+
70+
tc -n ${g_ns} qdisc add dev s${i} clsact
71+
done
72+
73+
ip -n ${s_ns} link set bond0 up
74+
ip -n ${s_ns} addr add ${s_ip4}/24 dev bond0
75+
ip -n ${s_ns} addr add ${s_ip6}/24 dev bond0
76+
sleep 2
77+
}
78+
79+
# Reset bond with new mode and options
80+
bond_reset()
81+
{
82+
# Count the eth link number in real-time as this function
83+
# maybe called from other topologies.
84+
local link_num=$(ip -n ${s_ns} -br link show | grep -c "^eth")
85+
local param="$1"
86+
link_num=$((link_num -1))
87+
88+
ip -n ${s_ns} link set bond0 down
89+
ip -n ${s_ns} link del bond0
90+
91+
ip -n ${s_ns} link add bond0 type bond $param
92+
for i in $(seq 0 ${link_num}); do
93+
ip -n ${s_ns} link set eth$i master bond0
94+
done
95+
96+
ip -n ${s_ns} link set bond0 up
97+
ip -n ${s_ns} addr add ${s_ip4}/24 dev bond0
98+
ip -n ${s_ns} addr add ${s_ip6}/24 dev bond0
99+
sleep 2
100+
}
101+
102+
server_destroy()
103+
{
104+
# Count the eth link number in real-time as this function
105+
# maybe called from other topologies.
106+
local link_num=$(ip -n ${s_ns} -br link show | grep -c "^eth")
107+
link_num=$((link_num -1))
108+
for i in $(seq 0 ${link_num}); do
109+
ip -n ${s_ns} link del eth${i}
110+
done
111+
ip netns del ${s_ns}
112+
}
113+
114+
client_create()
115+
{
116+
ip netns add ${c_ns}
117+
ip -n ${c_ns} link add eth0 type veth peer name c0 netns ${g_ns}
118+
119+
ip -n ${g_ns} link set c0 up
120+
ip -n ${g_ns} link set c0 master br0
121+
122+
ip -n ${c_ns} link set eth0 up
123+
ip -n ${c_ns} addr add ${c_ip4}/24 dev eth0
124+
ip -n ${c_ns} addr add ${c_ip6}/24 dev eth0
125+
}
126+
127+
client_destroy()
128+
{
129+
ip -n ${c_ns} link del eth0
130+
ip netns del ${c_ns}
131+
}
132+
133+
setup_prepare()
134+
{
135+
gateway_create
136+
server_create
137+
client_create
138+
}
139+
140+
cleanup()
141+
{
142+
pre_cleanup
143+
144+
client_destroy
145+
server_destroy
146+
gateway_destroy
147+
}
148+
149+
bond_check_connection()
150+
{
151+
local msg=${1:-"check connection"}
152+
153+
sleep 2
154+
ip netns exec ${s_ns} ping ${c_ip4} -c5 -i 0.1 &>/dev/null
155+
check_err $? "${msg}: ping failed"
156+
ip netns exec ${s_ns} ping6 ${c_ip6} -c5 -i 0.1 &>/dev/null
157+
check_err $? "${msg}: ping6 failed"
158+
}

0 commit comments

Comments
 (0)