Skip to contentSkip to conversation

selftests/bpf: add lwt ip encap tests to test_progs

PATCH Superseded Eyal Birger 2 participants 4 messages Aug 22, 2022 – Aug 24, 2022

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 selftests/bpf: add lwt ip encap tests to test_progs

Port test_lwt_ip_encap.sh tests onto test_progs.

In addition, this commit adds "egress_md" tests which test a similar flow as egress tests only they use gre devices in collect_md mode for encapsulation and set the tunnel key using bpf_set_tunnel_key().

This introduces minor changes to test_lwt_ip_encap.{sh,c} for consistency with the new tests:

- GRE key must exist as bpf_set_tunnel_key() explicitly sets the TUNNEL_KEY flag

- Source address for GRE traffic is set to IP*_5 instead of IP*_1 since GRE traffic is sent via veth5 so its address is selected when using bpf_set_tunnel_key()

Note: currently these programs use the legacy section name convention as iproute2 lwt configuration does not support providing function names.

----

v2:
- set CONFIG_NET_VRF and CONFIG_NET_L3_MASTER_DEV in reference .config
- add wait after sending large packet to allow it to get delivered as in the .sh test

---
 tools/testing/selftests/bpf/config            |   2 +
 .../selftests/bpf/prog_tests/lwt_ip_encap.c   | 585 ++++++++++++++++++
 .../selftests/bpf/progs/test_lwt_ip_encap.c   |  51 +-
 .../selftests/bpf/test_lwt_ip_encap.sh        |   6 +-
 4 files changed, 638 insertions(+), 6 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/lwt_ip_encap.c
tools/testing/selftests/bpf/config +2 -0
index 3fc46f9cfb22..04cc64e334ef 100644
@@ -64,3 +64,5 @@ CONFIG_TEST_BPF=m
 CONFIG_USERFAULTFD=y
 CONFIG_VXLAN=y
 CONFIG_XDP_SOCKETS=y
+CONFIG_NET_VRF=y
+CONFIG_NET_L3_MASTER_DEV=y
tools/testing/selftests/bpf/prog_tests/lwt_ip_encap.c new file +585 -0

585 lines not on this page · raw message

tools/testing/selftests/bpf/progs/test_lwt_ip_encap.c +47 -4

90 lines not on this page · raw message

tools/testing/selftests/bpf/test_lwt_ip_encap.sh +4 -2
index 6c69c42b1d60..a79f7840ceb1 100755
@@ -238,7 +238,8 @@ setup()
 	ip -netns ${NS3} -6 route add ${IPv6_6}/128 dev veth8 via ${IPv6_7}
 
 	# configure IPv4 GRE device in NS3, and a route to it via the "bottom" route
-	ip -netns ${NS3} tunnel add gre_dev mode gre remote ${IPv4_1} local ${IPv4_GRE} ttl 255
+	ip -netns ${NS3} tunnel add gre_dev mode gre remote ${IPv4_5} \
+		local ${IPv4_GRE} ttl 255 key 0
 	ip -netns ${NS3} link set gre_dev up
 	ip -netns ${NS3} addr add ${IPv4_GRE} dev gre_dev
 	ip -netns ${NS1} route add ${IPv4_GRE}/32 dev veth5 via ${IPv4_6} ${VRF}
@@ -246,7 +247,8 @@ setup()
 
 
 	# configure IPv6 GRE device in NS3, and a route to it via the "bottom" route
-	ip -netns ${NS3} -6 tunnel add name gre6_dev mode ip6gre remote ${IPv6_1} local ${IPv6_GRE} ttl 255
+	ip -netns ${NS3} -6 tunnel add name gre6_dev mode ip6gre remote ${IPv6_5} \
+		local ${IPv6_GRE} ttl 255 key 0
 	ip -netns ${NS3} link set gre6_dev up
 	ip -netns ${NS3} -6 addr add ${IPv6_GRE} nodad dev gre6_dev
 	ip -netns ${NS1} -6 route add ${IPv6_GRE}/128 dev veth5 via ${IPv6_6} ${VRF}
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 12 lines · Eyal Birger

Port test_lwt_ip_encap.sh tests onto test_progs.

In addition, this commit adds "egress_md" tests which test a similar flow as egress tests only they use gre devices in collect_md mode for encapsulation and set the tunnel key using bpf_set_tunnel_key().

This introduces minor changes to test_lwt_ip_encap.{sh,c} for consistency with the new tests:

- GRE key must exist as bpf_set_tunnel_key() explicitly sets the TUNNEL_KEY flag

Quoted 8 lines

- Source address for GRE traffic is set to IP*_5 instead of IP*_1 since GRE traffic is sent via veth5 so its address is selected when using bpf_set_tunnel_key()

Note: currently these programs use the legacy section name convention as iproute2 lwt configuration does not support providing function names.

[...]

Thanks for following up. Is there now anything that test_lwt_ip_encap.c doesn't cover over test_lwt_ip_encap.sh? If not, I'd vote for removing the latter given the port is then covered in CI via test_progs.

Quoted 25 lines
tools/testing/selftests/bpf/test_lwt_ip_encap.sh +4 -2
index 6c69c42b1d60..a79f7840ceb1 100755
@@ -238,7 +238,8 @@ setup()
  	ip -netns ${NS3} -6 route add ${IPv6_6}/128 dev veth8 via ${IPv6_7}
 
  	# configure IPv4 GRE device in NS3, and a route to it via the "bottom" route
-	ip -netns ${NS3} tunnel add gre_dev mode gre remote ${IPv4_1} local ${IPv4_GRE} ttl 255
+	ip -netns ${NS3} tunnel add gre_dev mode gre remote ${IPv4_5} \
+		local ${IPv4_GRE} ttl 255 key 0
  	ip -netns ${NS3} link set gre_dev up
  	ip -netns ${NS3} addr add ${IPv4_GRE} dev gre_dev
  	ip -netns ${NS1} route add ${IPv4_GRE}/32 dev veth5 via ${IPv4_6} ${VRF}
@@ -246,7 +247,8 @@ setup()
 
 
  	# configure IPv6 GRE device in NS3, and a route to it via the "bottom" route
-	ip -netns ${NS3} -6 tunnel add name gre6_dev mode ip6gre remote ${IPv6_1} local ${IPv6_GRE} ttl 255
+	ip -netns ${NS3} -6 tunnel add name gre6_dev mode ip6gre remote ${IPv6_5} \
+		local ${IPv6_GRE} ttl 255 key 0
  	ip -netns ${NS3} link set gre6_dev up
  	ip -netns ${NS3} -6 addr add ${IPv6_GRE} nodad dev gre6_dev
  	ip -netns ${NS1} -6 route add ${IPv6_GRE}/128 dev veth5 via ${IPv6_6} ${VRF}
#2 lore raw

Hi Daniel,

Quoted 21 lines · Daniel Borkmann
Quoted 19 lines · Eyal Birger

Port test_lwt_ip_encap.sh tests onto test_progs.

In addition, this commit adds "egress_md" tests which test a similar flow as egress tests only they use gre devices in collect_md mode for encapsulation and set the tunnel key using bpf_set_tunnel_key().

This introduces minor changes to test_lwt_ip_encap.{sh,c} for consistency with the new tests:

- GRE key must exist as bpf_set_tunnel_key() explicitly sets the TUNNEL_KEY flag

- Source address for GRE traffic is set to IP*_5 instead of IP*_1 since GRE traffic is sent via veth5 so its address is selected when using bpf_set_tunnel_key()

Note: currently these programs use the legacy section name convention as iproute2 lwt configuration does not support providing function names.

Quoted 6 lines
Quoted 1 line

[...]

Thanks for following up. Is there now anything that test_lwt_ip_encap.c doesn't cover over test_lwt_ip_encap.sh? If not, I'd vote for removing the latter given the port is then covered in CI via test_progs.

The .c version includes all tests in the .sh and two more. At least when I tried using vmtest the .sh version seems broken.

I can resubmit with an additional patch removing it, or send a follow up patch as you prefer.

Thanks,
Eyal.

Quoted 27 lines
Quoted 26 lines
tools/testing/selftests/bpf/test_lwt_ip_encap.sh +4 -2
index 6c69c42b1d60..a79f7840ceb1 100755
@@ -238,7 +238,8 @@ setup()
      ip -netns ${NS3} -6 route add ${IPv6_6}/128 dev veth8 via ${IPv6_7}
 
      # configure IPv4 GRE device in NS3, and a route to it via the "bottom" route
-     ip -netns ${NS3} tunnel add gre_dev mode gre remote ${IPv4_1} local ${IPv4_GRE} ttl 255
+     ip -netns ${NS3} tunnel add gre_dev mode gre remote ${IPv4_5} \
+             local ${IPv4_GRE} ttl 255 key 0
      ip -netns ${NS3} link set gre_dev up
      ip -netns ${NS3} addr add ${IPv4_GRE} dev gre_dev
      ip -netns ${NS1} route add ${IPv4_GRE}/32 dev veth5 via ${IPv4_6} ${VRF}
@@ -246,7 +247,8 @@ setup()
 
 
      # configure IPv6 GRE device in NS3, and a route to it via the "bottom" route
-     ip -netns ${NS3} -6 tunnel add name gre6_dev mode ip6gre remote ${IPv6_1} local ${IPv6_GRE} ttl 255
+     ip -netns ${NS3} -6 tunnel add name gre6_dev mode ip6gre remote ${IPv6_5} \
+             local ${IPv6_GRE} ttl 255 key 0
      ip -netns ${NS3} link set gre6_dev up
      ip -netns ${NS3} -6 addr add ${IPv6_GRE} nodad dev gre6_dev
      ip -netns ${NS1} -6 route add ${IPv6_GRE}/128 dev veth5 via ${IPv6_6} ${VRF}
maintainer
#3 lore raw
Quoted 31 lines · Eyal Birger

Hi Daniel,

Quoted 21 lines · Daniel Borkmann
Quoted 19 lines · Eyal Birger

Port test_lwt_ip_encap.sh tests onto test_progs.

In addition, this commit adds "egress_md" tests which test a similar flow as egress tests only they use gre devices in collect_md mode for encapsulation and set the tunnel key using bpf_set_tunnel_key().

This introduces minor changes to test_lwt_ip_encap.{sh,c} for consistency with the new tests:

- GRE key must exist as bpf_set_tunnel_key() explicitly sets the TUNNEL_KEY flag

- Source address for GRE traffic is set to IP*_5 instead of IP*_1 since GRE traffic is sent via veth5 so its address is selected when using bpf_set_tunnel_key()

Note: currently these programs use the legacy section name convention as iproute2 lwt configuration does not support providing function names.

Quoted 6 lines
Quoted 1 line

[...]

Thanks for following up. Is there now anything that test_lwt_ip_encap.c doesn't cover over test_lwt_ip_encap.sh? If not, I'd vote for removing the latter given the port is then covered in CI via test_progs.

Quoted 5 lines

The .c version includes all tests in the .sh and two more. At least when I tried using vmtest the .sh version seems broken.

I can resubmit with an additional patch removing it, or send a follow up patch as you prefer.

+1, could you squash the removal into the single patch and submit as a v3?

Thanks a lot,
Daniel