Skip to content

Commit a5b3363

Browse files
committed
Merge branch 'bonding-overflow'
Hangbin Liu says: ==================== bonding: fix send_peer_notif overflow Bonding send_peer_notif was defined as u8. But the value is num_peer_notif multiplied by peer_notif_delay, which is u8 * u32. This would cause the send_peer_notif overflow. Before the fix: TEST: num_grat_arp (active-backup miimon num_grat_arp 10) [ OK ] TEST: num_grat_arp (active-backup miimon num_grat_arp 20) [ OK ] 4 garp packets sent on active slave eth1 TEST: num_grat_arp (active-backup miimon num_grat_arp 30) [FAIL] 24 garp packets sent on active slave eth1 TEST: num_grat_arp (active-backup miimon num_grat_arp 50) [FAIL] After the fix: TEST: num_grat_arp (active-backup miimon num_grat_arp 10) [ OK ] TEST: num_grat_arp (active-backup miimon num_grat_arp 20) [ OK ] TEST: num_grat_arp (active-backup miimon num_grat_arp 30) [ OK ] TEST: num_grat_arp (active-backup miimon num_grat_arp 50) [ OK ] ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 7c83e28 + 6cbe791 commit a5b3363

7 files changed

Lines changed: 73 additions & 8 deletions

File tree

Documentation/networking/bonding.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -776,10 +776,11 @@ peer_notif_delay
776776
Specify the delay, in milliseconds, between each peer
777777
notification (gratuitous ARP and unsolicited IPv6 Neighbor
778778
Advertisement) when they are issued after a failover event.
779-
This delay should be a multiple of the link monitor interval
780-
(arp_interval or miimon, whichever is active). The default
781-
value is 0 which means to match the value of the link monitor
782-
interval.
779+
This delay should be a multiple of the MII link monitor interval
780+
(miimon).
781+
782+
The valid range is 0 - 300000. The default value is 0, which means
783+
to match the value of the MII link monitor interval.
783784

784785
prio
785786
Slave priority. A higher number means higher priority.

drivers/net/bonding/bond_netlink.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ static int bond_fill_slave_info(struct sk_buff *skb,
8484
return -EMSGSIZE;
8585
}
8686

87+
/* Limit the max delay range to 300s */
88+
static struct netlink_range_validation delay_range = {
89+
.max = 300000,
90+
};
91+
8792
static const struct nla_policy bond_policy[IFLA_BOND_MAX + 1] = {
8893
[IFLA_BOND_MODE] = { .type = NLA_U8 },
8994
[IFLA_BOND_ACTIVE_SLAVE] = { .type = NLA_U32 },
@@ -114,7 +119,7 @@ static const struct nla_policy bond_policy[IFLA_BOND_MAX + 1] = {
114119
[IFLA_BOND_AD_ACTOR_SYSTEM] = { .type = NLA_BINARY,
115120
.len = ETH_ALEN },
116121
[IFLA_BOND_TLB_DYNAMIC_LB] = { .type = NLA_U8 },
117-
[IFLA_BOND_PEER_NOTIF_DELAY] = { .type = NLA_U32 },
122+
[IFLA_BOND_PEER_NOTIF_DELAY] = NLA_POLICY_FULL_RANGE(NLA_U32, &delay_range),
118123
[IFLA_BOND_MISSED_MAX] = { .type = NLA_U8 },
119124
[IFLA_BOND_NS_IP6_TARGET] = { .type = NLA_NESTED },
120125
};

drivers/net/bonding/bond_options.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ static const struct bond_opt_value bond_num_peer_notif_tbl[] = {
169169
{ NULL, -1, 0}
170170
};
171171

172+
static const struct bond_opt_value bond_peer_notif_delay_tbl[] = {
173+
{ "off", 0, 0},
174+
{ "maxval", 300000, BOND_VALFLAG_MAX},
175+
{ NULL, -1, 0}
176+
};
177+
172178
static const struct bond_opt_value bond_primary_reselect_tbl[] = {
173179
{ "always", BOND_PRI_RESELECT_ALWAYS, BOND_VALFLAG_DEFAULT},
174180
{ "better", BOND_PRI_RESELECT_BETTER, 0},
@@ -488,7 +494,7 @@ static const struct bond_option bond_opts[BOND_OPT_LAST] = {
488494
.id = BOND_OPT_PEER_NOTIF_DELAY,
489495
.name = "peer_notif_delay",
490496
.desc = "Delay between each peer notification on failover event, in milliseconds",
491-
.values = bond_intmax_tbl,
497+
.values = bond_peer_notif_delay_tbl,
492498
.set = bond_option_peer_notif_delay_set
493499
}
494500
};

include/net/bonding.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ struct bonding {
233233
*/
234234
spinlock_t mode_lock;
235235
spinlock_t stats_lock;
236-
u8 send_peer_notif;
236+
u32 send_peer_notif;
237237
u8 igmp_retrans;
238238
#ifdef CONFIG_PROC_FS
239239
struct proc_dir_entry *proc_entry;

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
ALL_TESTS="
77
prio
88
arp_validate
9+
num_grat_arp
910
"
1011

1112
REQUIRE_MZ=no
@@ -255,6 +256,55 @@ arp_validate()
255256
arp_validate_ns "active-backup"
256257
}
257258

259+
garp_test()
260+
{
261+
local param="$1"
262+
local active_slave exp_num real_num i
263+
RET=0
264+
265+
# create bond
266+
bond_reset "${param}"
267+
268+
bond_check_connection
269+
[ $RET -ne 0 ] && log_test "num_grat_arp" "$retmsg"
270+
271+
272+
# Add tc rules to count GARP number
273+
for i in $(seq 0 2); do
274+
tc -n ${g_ns} filter add dev s$i ingress protocol arp pref 1 handle 101 \
275+
flower skip_hw arp_op request arp_sip ${s_ip4} arp_tip ${s_ip4} action pass
276+
done
277+
278+
# Do failover
279+
active_slave=$(cmd_jq "ip -n ${s_ns} -d -j link show bond0" ".[].linkinfo.info_data.active_slave")
280+
ip -n ${s_ns} link set ${active_slave} down
281+
282+
exp_num=$(echo "${param}" | cut -f6 -d ' ')
283+
sleep $((exp_num + 2))
284+
285+
active_slave=$(cmd_jq "ip -n ${s_ns} -d -j link show bond0" ".[].linkinfo.info_data.active_slave")
286+
287+
# check result
288+
real_num=$(tc_rule_handle_stats_get "dev s${active_slave#eth} ingress" 101 ".packets" "-n ${g_ns}")
289+
if [ "${real_num}" -ne "${exp_num}" ]; then
290+
echo "$real_num garp packets sent on active slave ${active_slave}"
291+
RET=1
292+
fi
293+
294+
for i in $(seq 0 2); do
295+
tc -n ${g_ns} filter del dev s$i ingress
296+
done
297+
}
298+
299+
num_grat_arp()
300+
{
301+
local val
302+
for val in 10 20 30 50; do
303+
garp_test "mode active-backup miimon 100 num_grat_arp $val peer_notify_delay 1000"
304+
log_test "num_grat_arp" "active-backup miimon num_grat_arp $val"
305+
done
306+
}
307+
258308
trap cleanup EXIT
259309

260310
setup_prepare

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ server_create()
6161
ip -n ${g_ns} link set s${i} up
6262
ip -n ${g_ns} link set s${i} master br0
6363
ip -n ${s_ns} link set eth${i} master bond0
64+
65+
tc -n ${g_ns} qdisc add dev s${i} clsact
6466
done
6567

6668
ip -n ${s_ns} link set bond0 up

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,8 +791,9 @@ tc_rule_handle_stats_get()
791791
local id=$1; shift
792792
local handle=$1; shift
793793
local selector=${1:-.packets}; shift
794+
local netns=${1:-""}; shift
794795

795-
tc -j -s filter show $id \
796+
tc $netns -j -s filter show $id \
796797
| jq ".[] | select(.options.handle == $handle) | \
797798
.options.actions[0].stats$selector"
798799
}

0 commit comments

Comments
 (0)