Skip to contentSkip to conversation

net/ipv6: Handle onlink flag with multipath routes

PATCH Superseded David Ahern 2 participants 7 messages Mar 13, 2018 – Mar 16, 2018

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover net/ipv6: Handle onlink flag with multipath routes

ONLINK flag is per nexthop. For multipath routes it is specified in rtnh_flags in struct rtnexthop versus rtm_flags for single path routes. Update ip6_route_multipath_add to look at rtnh_flags before the call to ip6_route_info_create.

Add multipath test cases as well.

David Ahern (2):
net/ipv6: Handle onlink flag with multipath routes
selftests: Add multipath tests for onlink flag

 net/ipv6/route.c                                |  1 +
 tools/testing/selftests/net/fib-onlink-tests.sh | 92 ++++++++++++++++++++++++-
 2 files changed, 90 insertions(+), 3 deletions(-)
Signature · 1 line
2.11.0
#1 lore raw

PATCH 1/2 net/ipv6: Handle onlink flag with multipath routes

For multipath routes the ONLINK flag is specified per nexthop in rtnh_flags (as opposed to rtm_flags for unicast routes). Update ip6_route_multipath_add to set fc_flags based on rtnh_flags.

Fixes fc1e64e1092f ("net/ipv6: Add support for onlink flag")
---
 net/ipv6/route.c | 1 +
 1 file changed, 1 insertion(+)
net/ipv6/route.c +1 -0
index f0ae58424c45..b223dffa8521 100644
@@ -4166,6 +4166,7 @@ static int ip6_route_multipath_add(struct fib6_config *cfg,
 				r_cfg.fc_encap_type = nla_get_u16(nla);
 		}
 
+		r_cfg.fc_flags |= (rtnh->rtnh_flags & RTNH_F_ONLINK);
 		rt = ip6_route_info_create(&r_cfg, extack);
 		if (IS_ERR(rt)) {
 			err = PTR_ERR(rt);
Signature · 1 line
2.11.0
maintainer
#2 lore raw

From: David Ahern <[email protected]>
Date: Tue, 13 Mar 2018 08:40:09 -0700

Quoted 15 lines

For multipath routes the ONLINK flag is specified per nexthop in rtnh_flags (as opposed to rtm_flags for unicast routes). Update ip6_route_multipath_add to set fc_flags based on rtnh_flags.

Fixes fc1e64e1092f ("net/ipv6: Add support for onlink flag")
---
 net/ipv6/route.c | 1 +
 1 file changed, 1 insertion(+)
net/ipv6/route.c +0 -0
index f0ae58424c45..b223dffa8521 100644

net/ipv6/route.c static int ip6_route_multipath_add(struct fib6_config *cfg, · line 4172

Quoted 7 lines
net/ipv6/route.c +1 -0
@@ -4166,6 +4166,7 @@ static int ip6_route_multipath_add(struct fib6_config *cfg,
 				r_cfg.fc_encap_type = nla_get_u16(nla);
 		}
 
+		r_cfg.fc_flags |= (rtnh->rtnh_flags & RTNH_F_ONLINK);
 		rt = ip6_route_info_create(&r_cfg, extack);
 		if (IS_ERR(rt)) {
 			err = PTR_ERR(rt);

Hmmm, this actually "accumulates" the flag rather than sets it.

Have you thought about what should happen if the cfg has RTNH_F_ONLINK set?

I think you should either change this logic to a true 'set', or adjust your commit message to address this aspect of the new behavior.

Thank you.

#3 lore raw
Quoted 28 lines · David Miller

From: David Ahern <[email protected]>
Date: Tue, 13 Mar 2018 08:40:09 -0700

Quoted 15 lines

For multipath routes the ONLINK flag is specified per nexthop in rtnh_flags (as opposed to rtm_flags for unicast routes). Update ip6_route_multipath_add to set fc_flags based on rtnh_flags.

Fixes fc1e64e1092f ("net/ipv6: Add support for onlink flag")
---
 net/ipv6/route.c | 1 +
 1 file changed, 1 insertion(+)
net/ipv6/route.c +0 -0
index f0ae58424c45..b223dffa8521 100644

net/ipv6/route.c static int ip6_route_multipath_add(struct fib6_config *cfg, · line 4172

Quoted 7 lines
net/ipv6/route.c +1 -0
@@ -4166,6 +4166,7 @@ static int ip6_route_multipath_add(struct fib6_config *cfg,
 				r_cfg.fc_encap_type = nla_get_u16(nla);
 		}
 
+		r_cfg.fc_flags |= (rtnh->rtnh_flags & RTNH_F_ONLINK);
 		rt = ip6_route_info_create(&r_cfg, extack);
 		if (IS_ERR(rt)) {
 			err = PTR_ERR(rt);

Hmmm, this actually "accumulates" the flag rather than sets it.

Quoted 2 lines

Have you thought about what should happen if the cfg has RTNH_F_ONLINK set?

yes, that's why the test script adds cases with the ONLINK flag set for both nexthops, then one with it on the first nexthop only, and one with the flag only on the second nexthop.

If you look at the full loop 'cfg' is the variable with the user data, and r_cfg is the 'local loop version' so r_cfg.fc_flags gets reset for each nexthop:

        while (rtnh_ok(rtnh, remaining)) {
                memcpy(&r_cfg, cfg, sizeof(*cfg));
		...
		r_cfg.fc_flags |= (rtnh->rtnh_flags & RTNH_F_ONLINK);
		rt = ip6_route_info_create(&r_cfg, extack);
Quoted 3 lines

I think you should either change this logic to a true 'set', or adjust your commit message to address this aspect of the new behavior.

I can update the commit message.

maintainer
#4 lore raw

From: David Ahern <[email protected]>
Date: Fri, 16 Mar 2018 08:45:10 -0700

Quoted 14 lines · David Miller
Quoted 4 lines

Hmmm, this actually "accumulates" the flag rather than sets it.

Have you thought about what should happen if the cfg has RTNH_F_ONLINK set?

yes, that's why the test script adds cases with the ONLINK flag set for both nexthops, then one with it on the first nexthop only, and one with the flag only on the second nexthop.

If you look at the full loop 'cfg' is the variable with the user data, and r_cfg is the 'local loop version' so r_cfg.fc_flags gets reset for each nexthop:

Quoted 5 lines
        while (rtnh_ok(rtnh, remaining)) {
                memcpy(&r_cfg, cfg, sizeof(*cfg));
		...
		r_cfg.fc_flags |= (rtnh->rtnh_flags & RTNH_F_ONLINK);
		rt = ip6_route_info_create(&r_cfg, extack);

Right.

Quoted 4 lines
Quoted 2 lines

I think you should either change this logic to a true 'set', or adjust your commit message to address this aspect of the new behavior.

I can update the commit message.

Please do, thanks David.

#5 lore raw
Quoted 23 lines · David Miller

From: David Ahern <[email protected]>
Date: Fri, 16 Mar 2018 08:45:10 -0700

Quoted 14 lines · David Miller
Quoted 4 lines

Hmmm, this actually "accumulates" the flag rather than sets it.

Have you thought about what should happen if the cfg has RTNH_F_ONLINK set?

yes, that's why the test script adds cases with the ONLINK flag set for both nexthops, then one with it on the first nexthop only, and one with the flag only on the second nexthop.

If you look at the full loop 'cfg' is the variable with the user data, and r_cfg is the 'local loop version' so r_cfg.fc_flags gets reset for each nexthop:

Quoted 5 lines
        while (rtnh_ok(rtnh, remaining)) {
                memcpy(&r_cfg, cfg, sizeof(*cfg));
		...
		r_cfg.fc_flags |= (rtnh->rtnh_flags & RTNH_F_ONLINK);
		rt = ip6_route_info_create(&r_cfg, extack);
Quoted 9 lines

Right.

Quoted 4 lines
Quoted 2 lines

I think you should either change this logic to a true 'set', or adjust your commit message to address this aspect of the new behavior.

I can update the commit message.

Please do, thanks David.

And it looks like patch 1 needs to be in 'net'; did not realize the ipv6 ONLINK support is already in 4.16. I will send the patch adding tests separately for net-next.

#6 lore raw

PATCH 2/2 selftests: Add multipath tests for onlink flag

In reply to David Ahern

Add multipath tests for onlink flag: one test with onlink added to both nexthops, then tests with onlink added to only 1 nexthop.

---
 tools/testing/selftests/net/fib-onlink-tests.sh | 92 ++++++++++++++++++++++++-
 1 file changed, 89 insertions(+), 3 deletions(-)
tools/testing/selftests/net/fib-onlink-tests.sh +89 -3
index 06b1d7cc12cc..fcf0b589e652 100755
@@ -56,7 +56,8 @@ TEST_NET6[2]=2001:db8:102
 
 # connected gateway
 CONGW[1]=169.254.1.254
-CONGW[2]=169.254.5.254
+CONGW[2]=169.254.3.254
+CONGW[3]=169.254.5.254
 
 # recursive gateway
 RECGW4[1]=169.254.11.254
@@ -232,6 +233,23 @@ run_ip()
 	log_test $? ${exp_rc} "${desc}"
 }
 
+run_ip_mpath()
+{
+	local table="$1"
+	local prefix="$2"
+	local nh1="$3"
+	local nh2="$4"
+	local exp_rc="$5"
+	local desc="$6"
+
+	# dev arg may be empty
+	[ -n "${dev}" ] && dev="dev ${dev}"
+
+	run_cmd ip ro add table "${table}" "${prefix}"/32 \
+		nexthop via ${nh1} nexthop via ${nh2}
+	log_test $? ${exp_rc} "${desc}"
+}
+
 valid_onlink_ipv4()
 {
 	# - unicast connected, unicast recursive
@@ -243,13 +261,37 @@ valid_onlink_ipv4()
 
 	log_subsection "VRF ${VRF}"
 
-	run_ip ${VRF_TABLE} ${TEST_NET4[2]}.1 ${CONGW[2]} ${NETIFS[p5]} 0 "unicast connected"
+	run_ip ${VRF_TABLE} ${TEST_NET4[2]}.1 ${CONGW[3]} ${NETIFS[p5]} 0 "unicast connected"
 	run_ip ${VRF_TABLE} ${TEST_NET4[2]}.2 ${RECGW4[2]} ${NETIFS[p5]} 0 "unicast recursive"
 
 	log_subsection "VRF device, PBR table"
 
-	run_ip ${PBR_TABLE} ${TEST_NET4[2]}.3 ${CONGW[2]} ${NETIFS[p5]} 0 "unicast connected"
+	run_ip ${PBR_TABLE} ${TEST_NET4[2]}.3 ${CONGW[3]} ${NETIFS[p5]} 0 "unicast connected"
 	run_ip ${PBR_TABLE} ${TEST_NET4[2]}.4 ${RECGW4[2]} ${NETIFS[p5]} 0 "unicast recursive"
+
+	# multipath version
+	#
+	log_subsection "default VRF - main table - multipath"
+
+	run_ip_mpath 254 ${TEST_NET4[1]}.5 \
+		"${CONGW[1]} dev ${NETIFS[p1]} onlink" \
+		"${CONGW[2]} dev ${NETIFS[p3]} onlink" \
+		0 "unicast connected - multipath"
+
+	run_ip_mpath 254 ${TEST_NET4[1]}.6 \
+		"${RECGW4[1]} dev ${NETIFS[p1]} onlink" \
+		"${RECGW4[2]} dev ${NETIFS[p3]} onlink" \
+		0 "unicast recursive - multipath"
+
+	run_ip_mpath 254 ${TEST_NET4[1]}.7 \
+		"${CONGW[1]} dev ${NETIFS[p1]}"        \
+		"${CONGW[2]} dev ${NETIFS[p3]} onlink" \
+		0 "unicast connected - multipath onlink first only"
+
+	run_ip_mpath 254 ${TEST_NET4[1]}.8 \
+		"${CONGW[1]} dev ${NETIFS[p1]} onlink" \
+		"${CONGW[2]} dev ${NETIFS[p3]}"        \
+		0 "unicast connected - multipath onlink second only"
 }
 
 invalid_onlink_ipv4()
@@ -289,6 +331,20 @@ run_ip6()
 	log_test $? ${exp_rc} "${desc}"
 }
 
+run_ip6_mpath()
+{
+	local table="$1"
+	local prefix="$2"
+	local nh1="$3"
+	local nh2="$4"
+	local exp_rc="$5"
+	local desc="$6"
+
+	run_cmd ip -6 ro add table "${table}" "${prefix}"/128 \
+		nexthop via ${nh1} nexthop via ${nh2}
+	log_test $? ${exp_rc} "${desc}"
+}
+
 valid_onlink_ipv6()
 {
 	# - unicast connected, unicast recursive, v4-mapped
@@ -310,6 +366,35 @@ valid_onlink_ipv6()
 	run_ip6 ${PBR_TABLE} ${TEST_NET6[2]}::4 ${V6ADDRS[p5]/::*}::64 ${NETIFS[p5]} 0 "unicast connected"
 	run_ip6 ${PBR_TABLE} ${TEST_NET6[2]}::5 ${RECGW6[2]} ${NETIFS[p5]} 0 "unicast recursive"
 	run_ip6 ${PBR_TABLE} ${TEST_NET6[2]}::6 ::ffff:${TEST_NET4IN6[2]} ${NETIFS[p5]} 0 "v4-mapped"
+
+	# multipath version
+	#
+	log_subsection "default VRF - main table - multipath"
+
+	run_ip6_mpath 254 ${TEST_NET6[1]}::4 \
+		"${V6ADDRS[p1]/::*}::64 dev ${NETIFS[p1]} onlink" \
+		"${V6ADDRS[p3]/::*}::64 dev ${NETIFS[p3]} onlink" \
+		0 "unicast connected - multipath onlink"
+
+	run_ip6_mpath 254 ${TEST_NET6[1]}::5 \
+		"${RECGW6[1]} dev ${NETIFS[p1]} onlink" \
+		"${RECGW6[2]} dev ${NETIFS[p3]} onlink" \
+		0 "unicast recursive - multipath onlink"
+
+	run_ip6_mpath 254 ${TEST_NET6[1]}::6 \
+		"::ffff:${TEST_NET4IN6[1]} dev ${NETIFS[p1]} onlink" \
+		"::ffff:${TEST_NET4IN6[2]} dev ${NETIFS[p3]} onlink" \
+		0 "v4-mapped - multipath onlink"
+
+	run_ip6_mpath 254 ${TEST_NET6[1]}::7 \
+		"${V6ADDRS[p1]/::*}::64 dev ${NETIFS[p1]} onlink" \
+		"${V6ADDRS[p3]/::*}::64 dev ${NETIFS[p3]}" \
+		0 "unicast connected - multipath onlink first only"
+
+	run_ip6_mpath 254 ${TEST_NET6[1]}::8 \
+		"${V6ADDRS[p1]/::*}::64 dev ${NETIFS[p1]}"        \
+		"${V6ADDRS[p3]/::*}::64 dev ${NETIFS[p3]} onlink" \
+		0 "unicast connected - multipath onlink second only"
 }
 
 invalid_onlink_ipv6()
@@ -355,6 +440,7 @@ run_onlink_tests()
 	log_section "IPv6 onlink"
 	log_subsection "Valid onlink commands"
 	valid_onlink_ipv6
+	log_subsection "Invalid onlink commands"
 	invalid_onlink_ipv6
 }
 
Signature · 1 line
2.11.0