selftests/bpf: Fix sk_assign on s390x
[ Upstream commit 7ce878ca81bca7811e669db4c394b86780e0dbe4 ] 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 <iii@linux.ibm.com> Link: https://lore.kernel.org/r/20230129190501.1624747-2-iii@linux.ibm.com Signed-off-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Pu Lehui <pulehui@huawei.com> Tested-by: Luiz Capitulino <luizcap@amazon.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:

committed by
Greg Kroah-Hartman

parent
b1a3e27d6b
commit
7328c5319e
@@ -29,7 +29,23 @@ static int stop, duration;
|
|||||||
static bool
|
static bool
|
||||||
configure_stack(void)
|
configure_stack(void)
|
||||||
{
|
{
|
||||||
|
char tc_version[128];
|
||||||
char tc_cmd[BUFSIZ];
|
char tc_cmd[BUFSIZ];
|
||||||
|
char *prog;
|
||||||
|
FILE *tc;
|
||||||
|
|
||||||
|
/* Check whether tc is built with libbpf. */
|
||||||
|
tc = popen("tc -V", "r");
|
||||||
|
if (CHECK_FAIL(!tc))
|
||||||
|
return false;
|
||||||
|
if (CHECK_FAIL(!fgets(tc_version, sizeof(tc_version), tc)))
|
||||||
|
return false;
|
||||||
|
if (strstr(tc_version, ", libbpf "))
|
||||||
|
prog = "test_sk_assign_libbpf.o";
|
||||||
|
else
|
||||||
|
prog = "test_sk_assign.o";
|
||||||
|
if (CHECK_FAIL(pclose(tc)))
|
||||||
|
return false;
|
||||||
|
|
||||||
/* Move to a new networking namespace */
|
/* Move to a new networking namespace */
|
||||||
if (CHECK_FAIL(unshare(CLONE_NEWNET)))
|
if (CHECK_FAIL(unshare(CLONE_NEWNET)))
|
||||||
@@ -46,8 +62,8 @@ configure_stack(void)
|
|||||||
/* Load qdisc, BPF program */
|
/* Load qdisc, BPF program */
|
||||||
if (CHECK_FAIL(system("tc qdisc add dev lo clsact")))
|
if (CHECK_FAIL(system("tc qdisc add dev lo clsact")))
|
||||||
return false;
|
return false;
|
||||||
sprintf(tc_cmd, "%s %s %s %s", "tc filter add dev lo ingress bpf",
|
sprintf(tc_cmd, "%s %s %s %s %s", "tc filter add dev lo ingress bpf",
|
||||||
"direct-action object-file ./test_sk_assign.o",
|
"direct-action object-file", prog,
|
||||||
"section classifier/sk_assign_test",
|
"section classifier/sk_assign_test",
|
||||||
(env.verbosity < VERBOSE_VERY) ? " 2>/dev/null" : "verbose");
|
(env.verbosity < VERBOSE_VERY) ? " 2>/dev/null" : "verbose");
|
||||||
if (CHECK(system(tc_cmd), "BPF load failed;",
|
if (CHECK(system(tc_cmd), "BPF load failed;",
|
||||||
@@ -129,15 +145,12 @@ get_port(int fd)
|
|||||||
static ssize_t
|
static ssize_t
|
||||||
rcv_msg(int srv_client, int type)
|
rcv_msg(int srv_client, int type)
|
||||||
{
|
{
|
||||||
struct sockaddr_storage ss;
|
|
||||||
char buf[BUFSIZ];
|
char buf[BUFSIZ];
|
||||||
socklen_t slen;
|
|
||||||
|
|
||||||
if (type == SOCK_STREAM)
|
if (type == SOCK_STREAM)
|
||||||
return read(srv_client, &buf, sizeof(buf));
|
return read(srv_client, &buf, sizeof(buf));
|
||||||
else
|
else
|
||||||
return recvfrom(srv_client, &buf, sizeof(buf), 0,
|
return recvfrom(srv_client, &buf, sizeof(buf), 0, NULL, NULL);
|
||||||
(struct sockaddr *)&ss, &slen);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@@ -16,6 +16,16 @@
|
|||||||
#include <bpf/bpf_helpers.h>
|
#include <bpf/bpf_helpers.h>
|
||||||
#include <bpf/bpf_endian.h>
|
#include <bpf/bpf_endian.h>
|
||||||
|
|
||||||
|
#if defined(IPROUTE2_HAVE_LIBBPF)
|
||||||
|
/* Use a new-style map definition. */
|
||||||
|
struct {
|
||||||
|
__uint(type, BPF_MAP_TYPE_SOCKMAP);
|
||||||
|
__type(key, int);
|
||||||
|
__type(value, __u64);
|
||||||
|
__uint(pinning, LIBBPF_PIN_BY_NAME);
|
||||||
|
__uint(max_entries, 1);
|
||||||
|
} server_map SEC(".maps");
|
||||||
|
#else
|
||||||
/* Pin map under /sys/fs/bpf/tc/globals/<map name> */
|
/* Pin map under /sys/fs/bpf/tc/globals/<map name> */
|
||||||
#define PIN_GLOBAL_NS 2
|
#define PIN_GLOBAL_NS 2
|
||||||
|
|
||||||
@@ -35,6 +45,7 @@ struct {
|
|||||||
.max_elem = 1,
|
.max_elem = 1,
|
||||||
.pinning = PIN_GLOBAL_NS,
|
.pinning = PIN_GLOBAL_NS,
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
int _version SEC("version") = 1;
|
int _version SEC("version") = 1;
|
||||||
char _license[] SEC("license") = "GPL";
|
char _license[] SEC("license") = "GPL";
|
||||||
|
@@ -0,0 +1,3 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0
|
||||||
|
#define IPROUTE2_HAVE_LIBBPF
|
||||||
|
#include "test_sk_assign.c"
|
Reference in New Issue
Block a user