Skip to content

Commit 8a3feed

Browse files
iamkafaiborkmann
authored andcommitted
bpf, selftest: Fix flaky tcp_hdr_options test when adding addr to lo
The tcp_hdr_options test adds a "::eB9F" addr to the lo dev. However, this non loopback address will have a race on ipv6 dad which may lead to EADDRNOTAVAIL error from time to time. Even nodad is used in the iproute2 command, there is still a race in when the route will be added. This will then lead to ENETUNREACH from time to time. To avoid the above, this patch uses the default loopback address "::1" to do the test. Fixes: ad2f8eb ("bpf: selftests: Tcp header options") Reported-by: Andrii Nakryiko <[email protected]> Signed-off-by: Martin KaFai Lau <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent f58423a commit 8a3feed

File tree

2 files changed

+2
-26
lines changed

2 files changed

+2
-26
lines changed

tools/testing/selftests/bpf/prog_tests/tcp_hdr_options.c

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "test_tcp_hdr_options.skel.h"
1616
#include "test_misc_tcp_hdr_options.skel.h"
1717

18-
#define LO_ADDR6 "::eB9F"
18+
#define LO_ADDR6 "::1"
1919
#define CG_NAME "/tcpbpf-hdr-opt-test"
2020

2121
struct bpf_test_option exp_passive_estab_in;
@@ -40,27 +40,6 @@ struct sk_fds {
4040
int active_lport;
4141
};
4242

43-
static int add_lo_addr(void)
44-
{
45-
char ip_addr_cmd[256];
46-
int cmdlen;
47-
48-
cmdlen = snprintf(ip_addr_cmd, sizeof(ip_addr_cmd),
49-
"ip -6 addr add %s/128 dev lo scope host",
50-
LO_ADDR6);
51-
52-
if (CHECK(cmdlen >= sizeof(ip_addr_cmd), "compile ip cmd",
53-
"failed to add host addr %s to lo. ip cmdlen is too long\n",
54-
LO_ADDR6))
55-
return -1;
56-
57-
if (CHECK(system(ip_addr_cmd), "run ip cmd",
58-
"failed to add host addr %s to lo\n", LO_ADDR6))
59-
return -1;
60-
61-
return 0;
62-
}
63-
6443
static int create_netns(void)
6544
{
6645
if (CHECK(unshare(CLONE_NEWNET), "create netns",
@@ -72,9 +51,6 @@ static int create_netns(void)
7251
"failed to bring lo link up\n"))
7352
return -1;
7453

75-
if (add_lo_addr())
76-
return -1;
77-
7854
return 0;
7955
}
8056

tools/testing/selftests/bpf/progs/test_misc_tcp_hdr_options.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#define BPF_PROG_TEST_TCP_HDR_OPTIONS
1717
#include "test_tcp_hdr_options.h"
1818

19-
__u16 last_addr16_n = __bpf_htons(0xeB9F);
19+
__u16 last_addr16_n = __bpf_htons(1);
2020
__u16 active_lport_n = 0;
2121
__u16 active_lport_h = 0;
2222
__u16 passive_lport_n = 0;

0 commit comments

Comments
 (0)