selftests: Add VRF icmp error route lookup test
Subsystems (4)
RFC PATCH 1/3 selftests: Add VRF icmp error route lookup test
From: Michael Jeanson <[email protected]>
The objective is to check that the incoming vrf routing table is selected to send an ICMP error back to the source when the ttl of a packet reaches 1 while it is forwarded between different vrfs.
The first test sends a ping with a ttl of 1 from h1 to h2 and parses the output of the command to check that a ttl expired error is received.
[This may be flaky, I'm open to suggestions of a more robust approch.]
The second test runs traceroute from h1 to h2 and parses the output to check for a hop on r1.
--- tools/testing/selftests/net/Makefile | 1 + .../selftests/net/vrf_icmp_error_route.sh | 461 ++++++++++++++++++ 2 files changed, 462 insertions(+) create mode 100755 tools/testing/selftests/net/vrf_icmp_error_route.sh
tools/testing/selftests/net/Makefile +1 -0
@@ -17,6 +17,7 @@ TEST_PROGS += route_localnet.sh TEST_PROGS += reuseaddr_ports_exhausted.sh TEST_PROGS += txtimestamp.sh TEST_PROGS += vrf-xfrm-tests.sh +TEST_PROGS += vrf_icmp_error_route.sh TEST_PROGS_EXTENDED := in_netns.sh TEST_GEN_FILES = socket nettest TEST_GEN_FILES += psock_fanout psock_tpacket msg_zerocopy reuseport_addr_any
tools/testing/selftests/net/vrf_icmp_error_route.sh new file +461 -0
461 lines not on this page · raw message
Signature · 1 line
2.17.1
RFC PATCH 2/3 ipv4/icmp: l3mdev: Perform icmp error route lookup on source device routing table
As per RFC792, ICMP errors should be sent to the source host.
However, in configurations with Virtual Routing and Forwarding tables, looking up which routing table to use is currently done by using the destination net_device.
commit 9d1a6c4ea43e ("net: icmp_route_lookup should use rt dev to determine L3 domain") changes the interface passed to l3mdev_master_ifindex() and inet_addr_type_dev_table() from skb_in->dev to skb_dst(skb_in)->dev. This effectively uses the destination device rather than the source device for choosing which routing table should be used to lookup where to send the ICMP error.
Therefore, if the source and destination interfaces are within separate VRFs, or one in the global routing table and the other in a VRF, looking up the source host in the destination interface's routing table will fail if the destination interface's routing table contains no route to the source host.
One observable effect of this issue is that traceroute does not work in the following cases:
- Route leaking between global routing table and VRF
- Route leaking between VRFs
Preferably use the source device routing table when sending ICMPv6 error messages. If no source device is set, fall-back on the destination device routing table.
--- net/ipv4/icmp.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
net/ipv4/icmp.c +13 -2
@@ -465,6 +465,7 @@ static struct rtable *icmp_route_lookup(struct net *net, int type, int code, struct icmp_bxm *param) { + struct net_device *route_lookup_dev = NULL;struct rtable *rt, *rt2;struct flowi4 fl4_dec;int err;
@@ -479,7 +480,17 @@ static struct rtable *icmp_route_lookup(struct net *net, fl4->flowi4_proto =IPPROTO_ICMP ; fl4->fl4_icmp_type = type; fl4->fl4_icmp_code = code; - fl4->flowi4_oif =l3mdev_master_ifindex (skb_dst (skb_in)->dev); +/* +* The device used for looking up which routing table to use is +* preferably the source whenever it is set, which should ensure +* the icmp error can be sent to the source host, else fallback +* on the destination device. +*/ +if (skb_in->dev) + route_lookup_dev = skb_in->dev; +else if (skb_dst (skb_in)) + route_lookup_dev =skb_dst (skb_in)->dev; + fl4->flowi4_oif =l3mdev_master_ifindex (route_lookup_dev);security_skb_classify_flow (skb_in,flowi4_to_flowi (fl4)); rt =ip_route_output_key_hash (net, fl4, skb_in);
@@ -503,7 +514,7 @@ static struct rtable *icmp_route_lookup(struct net *net,if (err) goto relookup_failed; -if (inet_addr_type_dev_table (net,skb_dst (skb_in)->dev, +if (inet_addr_type_dev_table (net, route_lookup_dev, fl4_dec.saddr) ==RTN_LOCAL ) { rt2 =__ip_route_output_key (net, &fl4_dec);if (IS_ERR (rt2))
Signature · 1 line
2.17.1
RFC PATCH 3/3 ipv6/icmp: l3mdev: Perform icmp error route lookup on source device routing table
In reply to Mathieu DesnoyersAs per RFC4443, the destination address field for ICMPv6 error messages is copied from the source address field of the invoking packet.
In configurations with Virtual Routing and Forwarding tables, looking up which routing table to use for sending ICMPv6 error messages is currently done by using the destination net_device.
If the source and destination interfaces are within separate VRFs, or one in the global routing table and the other in a VRF, looking up the source address of the invoking packet in the destination interface's routing table will fail if the destination interface's routing table contains no route to the invoking packet's source address.
One observable effect of this issue is that traceroute6 does not work in the following cases:
- Route leaking between global routing table and VRF
- Route leaking between VRFs
Preferably use the source device routing table when sending ICMPv6 error messages. If no source device is set, fall-back on the destination device routing table.
--- net/ipv6/icmp.c | 15 +++++++++++++-- net/ipv6/ip6_output.c | 2 -- 2 files changed, 13 insertions(+), 4 deletions(-)
net/ipv6/icmp.c +13 -2
@@ -501,8 +501,19 @@ static void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info,if (__ipv6_addr_needs_scope_id (addr_type)) { iif =icmp6_iif (skb); }else { - dst =skb_dst (skb); - iif =l3mdev_master_ifindex (dst ? dst->dev : skb->dev); +struct net_device *route_lookup_dev =NULL ; + +/* +* The device used for looking up which routing table to use is +* preferably the source whenever it is set, which should +* ensure the icmp error can be sent to the source host, else +* fallback on the destination device. +*/ +if (skb->dev) + route_lookup_dev = skb->dev; +else if (skb_dst (skb)) + route_lookup_dev =skb_dst (skb)->dev; + iif =l3mdev_master_ifindex (route_lookup_dev); }/*
net/ipv6/ip6_output.c +0 -2
@@ -468,8 +468,6 @@ int ip6_forward(struct sk_buff *skb)* check and decrement ttl */ if (hdr->hop_limit <=1 ) { -/* Force OUTPUT device used as source address */ - skb->dev = dst->dev;icmpv6_send (skb,ICMPV6_TIME_EXCEED ,ICMPV6_EXC_HOPLIMIT ,0 );__IP6_INC_STATS (net, idev,IPSTATS_MIB_INHDRERRORS );
Signature · 1 line
2.17.1
Quoted 9 lines · Mathieu Desnoyers
From: Michael Jeanson <[email protected]>
The objective is to check that the incoming vrf routing table is selected to send an ICMP error back to the source when the ttl of a packet reaches 1 while it is forwarded between different vrfs.
The first test sends a ping with a ttl of 1 from h1 to h2 and parses the output of the command to check that a ttl expired error is received.
Quoted 7 lines
[This may be flaky, I'm open to suggestions of a more robust approch.]
The second test runs traceroute from h1 to h2 and parses the output to check for a hop on r1.
Signed-off-by Michael Jeanson <[email protected]>Cc David Ahern <[email protected]>
Update the address to [email protected]
Quoted 8 lines
Cc David S. Miller <[email protected]>--- tools/testing/selftests/net/Makefile | 1 + .../selftests/net/vrf_icmp_error_route.sh | 461 ++++++++++++++++++ 2 files changed, 462 insertions(+) create mode 100755 tools/testing/selftests/net/vrf_icmp_error_route.sh
Test seems fine to me. you copied icmp_redirect.sh which is fine but please clean up comments and functions not needed for this test.
PATCH 1/1 selftests: Add VRF icmp error route lookup test
The objective is to check that the incoming vrf routing table is selected to send an ICMP error back to the source when the ttl of a packet reaches 1 while it is forwarded between different vrfs.
The first test sends a ping with a ttl of 1 from h1 to h2 and parses the output of the command to check that a ttl expired error is received.
[This may be flaky, I'm open to suggestions of a more robust approch.]
The second test runs traceroute from h1 to h2 and parses the output to check for a hop on r1.
--- tools/testing/selftests/net/Makefile | 1 + .../selftests/net/vrf_icmp_error_route.sh | 429 ++++++++++++++++++ 2 files changed, 430 insertions(+) create mode 100755 tools/testing/selftests/net/vrf_icmp_error_route.sh
tools/testing/selftests/net/Makefile +1 -0
@@ -17,6 +17,7 @@ TEST_PROGS += route_localnet.sh TEST_PROGS += reuseaddr_ports_exhausted.sh TEST_PROGS += txtimestamp.sh TEST_PROGS += vrf-xfrm-tests.sh +TEST_PROGS += vrf_icmp_error_route.sh TEST_PROGS_EXTENDED := in_netns.sh TEST_GEN_FILES = socket nettest TEST_GEN_FILES += psock_fanout psock_tpacket msg_zerocopy reuseport_addr_any
tools/testing/selftests/net/vrf_icmp_error_route.sh new file +429 -0
429 lines not on this page · raw message
Signature · 1 line
2.27.0
David Miller
maintainerFrom: Michael Jeanson <[email protected]>
Date: Thu, 6 Aug 2020 14:51:21 -0400
Quoted 7 lines
The objective is to check that the incoming vrf routing table is selected to send an ICMP error back to the source when the ttl of a packet reaches 1 while it is forwarded between different vrfs.
The first test sends a ping with a ttl of 1 from h1 to h2 and parses the output of the command to check that a ttl expired error is received.
Quoted 6 lines
[This may be flaky, I'm open to suggestions of a more robust approch.]
The second test runs traceroute from h1 to h2 and parses the output to check for a hop on r1.
Signed-off-by Michael Jeanson <[email protected]>
This patch does not apply cleanly to the current net tree.
Quoted 10 lines · David Miller
From: Michael Jeanson <[email protected]>
Date: Thu, 6 Aug 2020 14:51:21 -0400Quoted 7 lines
The objective is to check that the incoming vrf routing table is selected to send an ICMP error back to the source when the ttl of a packet reaches 1 while it is forwarded between different vrfs.
The first test sends a ping with a ttl of 1 from h1 to h2 and parses the output of the command to check that a ttl expired error is received.
Quoted 9 lines
Quoted 6 lines
[This may be flaky, I'm open to suggestions of a more robust approch.]
The second test runs traceroute from h1 to h2 and parses the output to check for a hop on r1.
Signed-off-by Michael Jeanson <[email protected]>This patch does not apply cleanly to the current net tree.
It is also out of context since the tests fail on current net and net-next.
The tests along with the patches that fix the problem should be sent together.
Quoted 18 lines · ----- On Aug 11, 2020, at 2:57 PM, David Ahern [email protected] wrote:
Quoted 17 lines · David Miller
From: Michael Jeanson <[email protected]>
Date: Thu, 6 Aug 2020 14:51:21 -0400Quoted 13 lines
The objective is to check that the incoming vrf routing table is selected to send an ICMP error back to the source when the ttl of a packet reaches 1 while it is forwarded between different vrfs.
The first test sends a ping with a ttl of 1 from h1 to h2 and parses the output of the command to check that a ttl expired error is received.
[This may be flaky, I'm open to suggestions of a more robust approch.]
The second test runs traceroute from h1 to h2 and parses the output to check for a hop on r1.
Signed-off-by Michael Jeanson <[email protected]>
Quoted 7 lines
Quoted 2 lines
This patch does not apply cleanly to the current net tree.
It is also out of context since the tests fail on current net and net-next.
The tests along with the patches that fix the problem should be sent together.
One thing I am missing before this series can be considered for upstreaming is an Acked-by of the 2 fixes for ipv4 and ipv6 from you, as maintainer of l3mdev, if you think the approach I am taking with those fixes makes sense.
Thanks,
Mathieu
Signature · 3 lines
Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com
Quoted 3 lines · Mathieu Desnoyers
One thing I am missing before this series can be considered for upstreaming is an Acked-by of the 2 fixes for ipv4 and ipv6 from you, as maintainer of l3mdev, if you think the approach I am taking with those fixes makes sense.
Send the set, and I will review as vrf/l3mdev maintainer. I need working tests and patches to see the before and after.
Quoted 7 lines · ----- On Aug 11, 2020, at 3:14 PM, David Ahern [email protected] wrote:
Quoted 3 lines · Mathieu Desnoyers
One thing I am missing before this series can be considered for upstreaming is an Acked-by of the 2 fixes for ipv4 and ipv6 from you, as maintainer of l3mdev, if you think the approach I am taking with those fixes makes sense.
Send the set, and I will review as vrf/l3mdev maintainer. I need working tests and patches to see the before and after.
Allright, I'm rebasing on the net tree as we speak, and the patches will be on their way shortly.
Thanks,
Mathieu
Signature · 3 lines
Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com