Skip to content

Commit 4ed591c

Browse files
dsaherndavem330
authored andcommitted
net/ipv6: Allow onlink routes to have a device mismatch if it is the default route
The intent of ip6_route_check_nh_onlink is to make sure the gateway given for an onlink route is not actually on a connected route for a different interface (e.g., 2001:db8:1::/64 is on dev eth1 and then an onlink route has a via 2001:db8:1::1 dev eth2). If the gateway lookup hits the default route then it most likely will be a different interface than the onlink route which is ok. Update ip6_route_check_nh_onlink to disregard the device mismatch if the gateway lookup hits the default route. Turns out the existing onlink tests are passing because there is no default route or it is an unreachable default, so update the onlink tests to have a default route other than unreachable. Fixes: fc1e64e ("net/ipv6: Add support for onlink flag") Signed-off-by: David Ahern <dsahern@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent e72bde6 commit 4ed591c

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

net/ipv6/route.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2745,6 +2745,8 @@ static int ip6_route_check_nh_onlink(struct net *net,
27452745
grt = ip6_nh_lookup_table(net, cfg, gw_addr, tbid, 0);
27462746
if (grt) {
27472747
if (!grt->dst.error &&
2748+
/* ignore match if it is the default route */
2749+
grt->from && !ipv6_addr_any(&grt->from->fib6_dst.addr) &&
27482750
(grt->rt6i_flags & flags || dev != grt->dst.dev)) {
27492751
NL_SET_ERR_MSG(extack,
27502752
"Nexthop has invalid gateway or device mismatch");

tools/testing/selftests/net/fib-onlink-tests.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ setup()
167167
# add vrf table
168168
ip li add ${VRF} type vrf table ${VRF_TABLE}
169169
ip li set ${VRF} up
170-
ip ro add table ${VRF_TABLE} unreachable default
171-
ip -6 ro add table ${VRF_TABLE} unreachable default
170+
ip ro add table ${VRF_TABLE} unreachable default metric 8192
171+
ip -6 ro add table ${VRF_TABLE} unreachable default metric 8192
172172

173173
# create test interfaces
174174
ip li add ${NETIFS[p1]} type veth peer name ${NETIFS[p2]}
@@ -185,20 +185,20 @@ setup()
185185
for n in 1 3 5 7; do
186186
ip li set ${NETIFS[p${n}]} up
187187
ip addr add ${V4ADDRS[p${n}]}/24 dev ${NETIFS[p${n}]}
188-
ip addr add ${V6ADDRS[p${n}]}/64 dev ${NETIFS[p${n}]}
188+
ip addr add ${V6ADDRS[p${n}]}/64 dev ${NETIFS[p${n}]} nodad
189189
done
190190

191191
# move peer interfaces to namespace and add addresses
192192
for n in 2 4 6 8; do
193193
ip li set ${NETIFS[p${n}]} netns ${PEER_NS} up
194194
ip -netns ${PEER_NS} addr add ${V4ADDRS[p${n}]}/24 dev ${NETIFS[p${n}]}
195-
ip -netns ${PEER_NS} addr add ${V6ADDRS[p${n}]}/64 dev ${NETIFS[p${n}]}
195+
ip -netns ${PEER_NS} addr add ${V6ADDRS[p${n}]}/64 dev ${NETIFS[p${n}]} nodad
196196
done
197197

198-
set +e
198+
ip -6 ro add default via ${V6ADDRS[p3]/::[0-9]/::64}
199+
ip -6 ro add table ${VRF_TABLE} default via ${V6ADDRS[p7]/::[0-9]/::64}
199200

200-
# let DAD complete - assume default of 1 probe
201-
sleep 1
201+
set +e
202202
}
203203

204204
cleanup()

0 commit comments

Comments
 (0)