Skip to content

Commit 7ce878c

Browse files
iii-iAlexei Starovoitov
authored andcommitted
selftests/bpf: Fix sk_assign on s390x
sk_assign is failing on an s390x machine running Debian "bookworm" for 2 reasons: legacy server_map definition and uninitialized addrlen in recvfrom() call. Fix by adding a new-style server_map definition and dropping addrlen (recvfrom() allows NULL values for src_addr and addrlen). Since the test should support tc built without libbpf, build the prog twice: with the old-style definition and with the new-style definition, then select the right one at runtime. This could be done at compile time too, but this would not be cross-compilation friendly. Signed-off-by: Ilya Leoshkevich <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 07dcbd7 commit 7ce878c

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,23 @@ static int stop, duration;
2929
static bool
3030
configure_stack(void)
3131
{
32+
char tc_version[128];
3233
char tc_cmd[BUFSIZ];
34+
char *prog;
35+
FILE *tc;
36+
37+
/* Check whether tc is built with libbpf. */
38+
tc = popen("tc -V", "r");
39+
if (CHECK_FAIL(!tc))
40+
return false;
41+
if (CHECK_FAIL(!fgets(tc_version, sizeof(tc_version), tc)))
42+
return false;
43+
if (strstr(tc_version, ", libbpf "))
44+
prog = "test_sk_assign_libbpf.bpf.o";
45+
else
46+
prog = "test_sk_assign.bpf.o";
47+
if (CHECK_FAIL(pclose(tc)))
48+
return false;
3349

3450
/* Move to a new networking namespace */
3551
if (CHECK_FAIL(unshare(CLONE_NEWNET)))
@@ -46,8 +62,8 @@ configure_stack(void)
4662
/* Load qdisc, BPF program */
4763
if (CHECK_FAIL(system("tc qdisc add dev lo clsact")))
4864
return false;
49-
sprintf(tc_cmd, "%s %s %s %s", "tc filter add dev lo ingress bpf",
50-
"direct-action object-file ./test_sk_assign.bpf.o",
65+
sprintf(tc_cmd, "%s %s %s %s %s", "tc filter add dev lo ingress bpf",
66+
"direct-action object-file", prog,
5167
"section tc",
5268
(env.verbosity < VERBOSE_VERY) ? " 2>/dev/null" : "verbose");
5369
if (CHECK(system(tc_cmd), "BPF load failed;",
@@ -129,15 +145,12 @@ get_port(int fd)
129145
static ssize_t
130146
rcv_msg(int srv_client, int type)
131147
{
132-
struct sockaddr_storage ss;
133148
char buf[BUFSIZ];
134-
socklen_t slen;
135149

136150
if (type == SOCK_STREAM)
137151
return read(srv_client, &buf, sizeof(buf));
138152
else
139-
return recvfrom(srv_client, &buf, sizeof(buf), 0,
140-
(struct sockaddr *)&ss, &slen);
153+
return recvfrom(srv_client, &buf, sizeof(buf), 0, NULL, NULL);
141154
}
142155

143156
static int

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@
1616
#include <bpf/bpf_helpers.h>
1717
#include <bpf/bpf_endian.h>
1818

19+
#if defined(IPROUTE2_HAVE_LIBBPF)
20+
/* Use a new-style map definition. */
21+
struct {
22+
__uint(type, BPF_MAP_TYPE_SOCKMAP);
23+
__type(key, int);
24+
__type(value, __u64);
25+
__uint(pinning, LIBBPF_PIN_BY_NAME);
26+
__uint(max_entries, 1);
27+
} server_map SEC(".maps");
28+
#else
1929
/* Pin map under /sys/fs/bpf/tc/globals/<map name> */
2030
#define PIN_GLOBAL_NS 2
2131

@@ -35,6 +45,7 @@ struct {
3545
.max_elem = 1,
3646
.pinning = PIN_GLOBAL_NS,
3747
};
48+
#endif
3849

3950
char _license[] SEC("license") = "GPL";
4051

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
#define IPROUTE2_HAVE_LIBBPF
3+
#include "test_sk_assign.c"

0 commit comments

Comments
 (0)