mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2025-01-11 00:04:33 +08:00
f2e97dc126
Fix following build error. We could push a tcp.h header into one of the
include paths, but I think its easy enough to simply pull in the three
defines we need here. If we end up using more of tcp.h at some point
we can pull it in later.
/home/john/git/bpf/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c: In function ‘connected_socket_v4’:
/home/john/git/bpf/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c:20:11: error: ‘TCP_REPAIR_ON’ undeclared (first use in this function)
repair = TCP_REPAIR_ON;
^
/home/john/git/bpf/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c:20:11: note: each undeclared identifier is reported only once for each function it appears in
/home/john/git/bpf/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c:29:11: error: ‘TCP_REPAIR_OFF_NO_WP’ undeclared (first use in this function)
repair = TCP_REPAIR_OFF_NO_WP;
Then with fix,
$ ./test_progs -n 44
#44/1 sockmap create_update_free:OK
#44/2 sockhash create_update_free:OK
#44 sockmap_basic:OK
Fixes: 5d3919a953
("selftests/bpf: Test freeing sockmap/sockhash with a socket in it")
Signed-off-by: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Reviewed-by: Jakub Sitnicki <jakub@cloudflare.com>
Link: https://lore.kernel.org/bpf/158131347731.21414.12120493483848386652.stgit@john-Precision-5820-Tower
80 lines
1.7 KiB
C
80 lines
1.7 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
// Copyright (c) 2020 Cloudflare
|
|
|
|
#include "test_progs.h"
|
|
|
|
#define TCP_REPAIR 19 /* TCP sock is under repair right now */
|
|
|
|
#define TCP_REPAIR_ON 1
|
|
#define TCP_REPAIR_OFF_NO_WP -1 /* Turn off without window probes */
|
|
|
|
static int connected_socket_v4(void)
|
|
{
|
|
struct sockaddr_in addr = {
|
|
.sin_family = AF_INET,
|
|
.sin_port = htons(80),
|
|
.sin_addr = { inet_addr("127.0.0.1") },
|
|
};
|
|
socklen_t len = sizeof(addr);
|
|
int s, repair, err;
|
|
|
|
s = socket(AF_INET, SOCK_STREAM, 0);
|
|
if (CHECK_FAIL(s == -1))
|
|
goto error;
|
|
|
|
repair = TCP_REPAIR_ON;
|
|
err = setsockopt(s, SOL_TCP, TCP_REPAIR, &repair, sizeof(repair));
|
|
if (CHECK_FAIL(err))
|
|
goto error;
|
|
|
|
err = connect(s, (struct sockaddr *)&addr, len);
|
|
if (CHECK_FAIL(err))
|
|
goto error;
|
|
|
|
repair = TCP_REPAIR_OFF_NO_WP;
|
|
err = setsockopt(s, SOL_TCP, TCP_REPAIR, &repair, sizeof(repair));
|
|
if (CHECK_FAIL(err))
|
|
goto error;
|
|
|
|
return s;
|
|
error:
|
|
perror(__func__);
|
|
close(s);
|
|
return -1;
|
|
}
|
|
|
|
/* Create a map, populate it with one socket, and free the map. */
|
|
static void test_sockmap_create_update_free(enum bpf_map_type map_type)
|
|
{
|
|
const int zero = 0;
|
|
int s, map, err;
|
|
|
|
s = connected_socket_v4();
|
|
if (CHECK_FAIL(s == -1))
|
|
return;
|
|
|
|
map = bpf_create_map(map_type, sizeof(int), sizeof(int), 1, 0);
|
|
if (CHECK_FAIL(map == -1)) {
|
|
perror("bpf_create_map");
|
|
goto out;
|
|
}
|
|
|
|
err = bpf_map_update_elem(map, &zero, &s, BPF_NOEXIST);
|
|
if (CHECK_FAIL(err)) {
|
|
perror("bpf_map_update");
|
|
goto out;
|
|
}
|
|
|
|
out:
|
|
close(map);
|
|
close(s);
|
|
}
|
|
|
|
void test_sockmap_basic(void)
|
|
{
|
|
if (test__start_subtest("sockmap create_update_free"))
|
|
test_sockmap_create_update_free(BPF_MAP_TYPE_SOCKMAP);
|
|
if (test__start_subtest("sockhash create_update_free"))
|
|
test_sockmap_create_update_free(BPF_MAP_TYPE_SOCKHASH);
|
|
}
|