selftests/bpf: Fix tc_redirect_dtime
authorMartin KaFai Lau <kafai@fb.com>
Wed, 1 Jun 2022 23:40:50 +0000 (16:40 -0700)
committerAndrii Nakryiko <andrii@kernel.org>
Fri, 3 Jun 2022 21:53:33 +0000 (14:53 -0700)
commite6ff92f41b65fce07365f1066fb13b5e42aca08d
treef13341d365d697ced4cbcffb3e189505c331317e
parent988d0d5899248b758d2f2eae3b57708fe78a8618
selftests/bpf: Fix tc_redirect_dtime

tc_redirect_dtime was reported flaky from time to time.  It
always fails at the udp test and complains about the bpf@tc-ingress
got a skb->tstamp when handling udp packet.  It is unexpected
because the skb->tstamp should have been cleared when crossing
different netns.

The most likely cause is that the skb is actually a tcp packet
from the earlier tcp test.  It could be the final TCP_FIN handling.

This patch tightens the skb->tstamp check in the bpf prog.  It ensures
the skb is the current testing traffic.  First, it checks that skb
matches the IPPROTO of the running test (i.e. tcp vs udp).
Second, it checks the server port (dst_ns_port).  The server
port is unique for each test (50000 + test_enum).

Also fixed a typo in test_udp_dtime(): s/P100/P101/

Fixes: c803475fd8dd ("bpf: selftests: test skb->tstamp in redirect_neigh")
Reported-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Song Liu <songliubraving@fb.com>
Link: https://lore.kernel.org/bpf/20220601234050.2572671-1-kafai@fb.com
tools/testing/selftests/bpf/prog_tests/tc_redirect.c
tools/testing/selftests/bpf/progs/test_tc_dtime.c