diff options
Diffstat (limited to 'tools/testing')
| -rw-r--r-- | tools/testing/selftests/lib/Makefile | 2 | ||||
| -rwxr-xr-x | tools/testing/selftests/lib/bitmap.sh | 10 | ||||
| -rw-r--r-- | tools/testing/selftests/net/.gitignore | 1 | ||||
| -rw-r--r-- | tools/testing/selftests/net/Makefile | 2 | ||||
| -rw-r--r-- | tools/testing/selftests/net/reuseport_bpf.c | 117 | ||||
| -rw-r--r-- | tools/testing/selftests/net/reuseport_bpf_cpu.c | 258 |
6 files changed, 381 insertions, 9 deletions
diff --git a/tools/testing/selftests/lib/Makefile b/tools/testing/selftests/lib/Makefile index 47147b968514..08360060ab14 100644 --- a/tools/testing/selftests/lib/Makefile +++ b/tools/testing/selftests/lib/Makefile | |||
| @@ -3,6 +3,6 @@ | |||
| 3 | # No binaries, but make sure arg-less "make" doesn't trigger "run_tests" | 3 | # No binaries, but make sure arg-less "make" doesn't trigger "run_tests" |
| 4 | all: | 4 | all: |
| 5 | 5 | ||
| 6 | TEST_PROGS := printf.sh | 6 | TEST_PROGS := printf.sh bitmap.sh |
| 7 | 7 | ||
| 8 | include ../lib.mk | 8 | include ../lib.mk |
diff --git a/tools/testing/selftests/lib/bitmap.sh b/tools/testing/selftests/lib/bitmap.sh new file mode 100755 index 000000000000..2da187b6ddad --- /dev/null +++ b/tools/testing/selftests/lib/bitmap.sh | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | # Runs bitmap infrastructure tests using test_bitmap kernel module | ||
| 3 | |||
| 4 | if /sbin/modprobe -q test_bitmap; then | ||
| 5 | /sbin/modprobe -q -r test_bitmap | ||
| 6 | echo "bitmap: ok" | ||
| 7 | else | ||
| 8 | echo "bitmap: [FAIL]" | ||
| 9 | exit 1 | ||
| 10 | fi | ||
diff --git a/tools/testing/selftests/net/.gitignore b/tools/testing/selftests/net/.gitignore index 6fb23366b258..69bb3fc38fb2 100644 --- a/tools/testing/selftests/net/.gitignore +++ b/tools/testing/selftests/net/.gitignore | |||
| @@ -2,3 +2,4 @@ socket | |||
| 2 | psock_fanout | 2 | psock_fanout |
| 3 | psock_tpacket | 3 | psock_tpacket |
| 4 | reuseport_bpf | 4 | reuseport_bpf |
| 5 | reuseport_bpf_cpu | ||
diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile index 41449b5ad0a9..c658792d47b4 100644 --- a/tools/testing/selftests/net/Makefile +++ b/tools/testing/selftests/net/Makefile | |||
| @@ -4,7 +4,7 @@ CFLAGS = -Wall -O2 -g | |||
| 4 | 4 | ||
| 5 | CFLAGS += -I../../../../usr/include/ | 5 | CFLAGS += -I../../../../usr/include/ |
| 6 | 6 | ||
| 7 | NET_PROGS = socket psock_fanout psock_tpacket reuseport_bpf | 7 | NET_PROGS = socket psock_fanout psock_tpacket reuseport_bpf reuseport_bpf_cpu |
| 8 | 8 | ||
| 9 | all: $(NET_PROGS) | 9 | all: $(NET_PROGS) |
| 10 | %: %.c | 10 | %: %.c |
diff --git a/tools/testing/selftests/net/reuseport_bpf.c b/tools/testing/selftests/net/reuseport_bpf.c index bec1b5dd2530..96ba386b1b7b 100644 --- a/tools/testing/selftests/net/reuseport_bpf.c +++ b/tools/testing/selftests/net/reuseport_bpf.c | |||
| @@ -9,10 +9,12 @@ | |||
| 9 | 9 | ||
| 10 | #include <errno.h> | 10 | #include <errno.h> |
| 11 | #include <error.h> | 11 | #include <error.h> |
| 12 | #include <fcntl.h> | ||
| 12 | #include <linux/bpf.h> | 13 | #include <linux/bpf.h> |
| 13 | #include <linux/filter.h> | 14 | #include <linux/filter.h> |
| 14 | #include <linux/unistd.h> | 15 | #include <linux/unistd.h> |
| 15 | #include <netinet/in.h> | 16 | #include <netinet/in.h> |
| 17 | #include <netinet/tcp.h> | ||
| 16 | #include <stdio.h> | 18 | #include <stdio.h> |
| 17 | #include <stdlib.h> | 19 | #include <stdlib.h> |
| 18 | #include <string.h> | 20 | #include <string.h> |
| @@ -169,9 +171,15 @@ static void build_recv_group(const struct test_params p, int fd[], uint16_t mod, | |||
| 169 | if (bind(fd[i], addr, sockaddr_size())) | 171 | if (bind(fd[i], addr, sockaddr_size())) |
| 170 | error(1, errno, "failed to bind recv socket %d", i); | 172 | error(1, errno, "failed to bind recv socket %d", i); |
| 171 | 173 | ||
| 172 | if (p.protocol == SOCK_STREAM) | 174 | if (p.protocol == SOCK_STREAM) { |
| 175 | opt = 4; | ||
| 176 | if (setsockopt(fd[i], SOL_TCP, TCP_FASTOPEN, &opt, | ||
| 177 | sizeof(opt))) | ||
| 178 | error(1, errno, | ||
| 179 | "failed to set TCP_FASTOPEN on %d", i); | ||
| 173 | if (listen(fd[i], p.recv_socks * 10)) | 180 | if (listen(fd[i], p.recv_socks * 10)) |
| 174 | error(1, errno, "failed to listen on socket"); | 181 | error(1, errno, "failed to listen on socket"); |
| 182 | } | ||
| 175 | } | 183 | } |
| 176 | free(addr); | 184 | free(addr); |
| 177 | } | 185 | } |
| @@ -189,10 +197,8 @@ static void send_from(struct test_params p, uint16_t sport, char *buf, | |||
| 189 | 197 | ||
| 190 | if (bind(fd, saddr, sockaddr_size())) | 198 | if (bind(fd, saddr, sockaddr_size())) |
| 191 | error(1, errno, "failed to bind send socket"); | 199 | error(1, errno, "failed to bind send socket"); |
| 192 | if (connect(fd, daddr, sockaddr_size())) | ||
| 193 | error(1, errno, "failed to connect"); | ||
| 194 | 200 | ||
| 195 | if (send(fd, buf, len, 0) < 0) | 201 | if (sendto(fd, buf, len, MSG_FASTOPEN, daddr, sockaddr_size()) < 0) |
| 196 | error(1, errno, "failed to send message"); | 202 | error(1, errno, "failed to send message"); |
| 197 | 203 | ||
| 198 | close(fd); | 204 | close(fd); |
| @@ -260,7 +266,7 @@ static void test_recv_order(const struct test_params p, int fd[], int mod) | |||
| 260 | } | 266 | } |
| 261 | } | 267 | } |
| 262 | 268 | ||
| 263 | static void test_reuseport_ebpf(const struct test_params p) | 269 | static void test_reuseport_ebpf(struct test_params p) |
| 264 | { | 270 | { |
| 265 | int i, fd[p.recv_socks]; | 271 | int i, fd[p.recv_socks]; |
| 266 | 272 | ||
| @@ -268,6 +274,7 @@ static void test_reuseport_ebpf(const struct test_params p) | |||
| 268 | build_recv_group(p, fd, p.recv_socks, attach_ebpf); | 274 | build_recv_group(p, fd, p.recv_socks, attach_ebpf); |
| 269 | test_recv_order(p, fd, p.recv_socks); | 275 | test_recv_order(p, fd, p.recv_socks); |
| 270 | 276 | ||
| 277 | p.send_port_min += p.recv_socks * 2; | ||
| 271 | fprintf(stderr, "Reprograming, testing mod %zd...\n", p.recv_socks / 2); | 278 | fprintf(stderr, "Reprograming, testing mod %zd...\n", p.recv_socks / 2); |
| 272 | attach_ebpf(fd[0], p.recv_socks / 2); | 279 | attach_ebpf(fd[0], p.recv_socks / 2); |
| 273 | test_recv_order(p, fd, p.recv_socks / 2); | 280 | test_recv_order(p, fd, p.recv_socks / 2); |
| @@ -276,7 +283,7 @@ static void test_reuseport_ebpf(const struct test_params p) | |||
| 276 | close(fd[i]); | 283 | close(fd[i]); |
| 277 | } | 284 | } |
| 278 | 285 | ||
| 279 | static void test_reuseport_cbpf(const struct test_params p) | 286 | static void test_reuseport_cbpf(struct test_params p) |
| 280 | { | 287 | { |
| 281 | int i, fd[p.recv_socks]; | 288 | int i, fd[p.recv_socks]; |
| 282 | 289 | ||
| @@ -284,6 +291,7 @@ static void test_reuseport_cbpf(const struct test_params p) | |||
| 284 | build_recv_group(p, fd, p.recv_socks, attach_cbpf); | 291 | build_recv_group(p, fd, p.recv_socks, attach_cbpf); |
| 285 | test_recv_order(p, fd, p.recv_socks); | 292 | test_recv_order(p, fd, p.recv_socks); |
| 286 | 293 | ||
| 294 | p.send_port_min += p.recv_socks * 2; | ||
| 287 | fprintf(stderr, "Reprograming, testing mod %zd...\n", p.recv_socks / 2); | 295 | fprintf(stderr, "Reprograming, testing mod %zd...\n", p.recv_socks / 2); |
| 288 | attach_cbpf(fd[0], p.recv_socks / 2); | 296 | attach_cbpf(fd[0], p.recv_socks / 2); |
| 289 | test_recv_order(p, fd, p.recv_socks / 2); | 297 | test_recv_order(p, fd, p.recv_socks / 2); |
| @@ -377,7 +385,7 @@ static void test_filter_no_reuseport(const struct test_params p) | |||
| 377 | 385 | ||
| 378 | static void test_filter_without_bind(void) | 386 | static void test_filter_without_bind(void) |
| 379 | { | 387 | { |
| 380 | int fd1, fd2; | 388 | int fd1, fd2, opt = 1; |
| 381 | 389 | ||
| 382 | fprintf(stderr, "Testing filter add without bind...\n"); | 390 | fprintf(stderr, "Testing filter add without bind...\n"); |
| 383 | fd1 = socket(AF_INET, SOCK_DGRAM, 0); | 391 | fd1 = socket(AF_INET, SOCK_DGRAM, 0); |
| @@ -386,6 +394,10 @@ static void test_filter_without_bind(void) | |||
| 386 | fd2 = socket(AF_INET, SOCK_DGRAM, 0); | 394 | fd2 = socket(AF_INET, SOCK_DGRAM, 0); |
| 387 | if (fd2 < 0) | 395 | if (fd2 < 0) |
| 388 | error(1, errno, "failed to create socket 2"); | 396 | error(1, errno, "failed to create socket 2"); |
| 397 | if (setsockopt(fd1, SOL_SOCKET, SO_REUSEPORT, &opt, sizeof(opt))) | ||
| 398 | error(1, errno, "failed to set SO_REUSEPORT on socket 1"); | ||
| 399 | if (setsockopt(fd2, SOL_SOCKET, SO_REUSEPORT, &opt, sizeof(opt))) | ||
| 400 | error(1, errno, "failed to set SO_REUSEPORT on socket 2"); | ||
| 389 | 401 | ||
| 390 | attach_ebpf(fd1, 10); | 402 | attach_ebpf(fd1, 10); |
| 391 | attach_cbpf(fd2, 10); | 403 | attach_cbpf(fd2, 10); |
| @@ -394,6 +406,32 @@ static void test_filter_without_bind(void) | |||
| 394 | close(fd2); | 406 | close(fd2); |
| 395 | } | 407 | } |
| 396 | 408 | ||
| 409 | void enable_fastopen(void) | ||
| 410 | { | ||
| 411 | int fd = open("/proc/sys/net/ipv4/tcp_fastopen", 0); | ||
| 412 | int rw_mask = 3; /* bit 1: client side; bit-2 server side */ | ||
| 413 | int val, size; | ||
| 414 | char buf[16]; | ||
| 415 | |||
| 416 | if (fd < 0) | ||
| 417 | error(1, errno, "Unable to open tcp_fastopen sysctl"); | ||
| 418 | if (read(fd, buf, sizeof(buf)) <= 0) | ||
| 419 | error(1, errno, "Unable to read tcp_fastopen sysctl"); | ||
| 420 | val = atoi(buf); | ||
| 421 | close(fd); | ||
| 422 | |||
| 423 | if ((val & rw_mask) != rw_mask) { | ||
| 424 | fd = open("/proc/sys/net/ipv4/tcp_fastopen", O_RDWR); | ||
| 425 | if (fd < 0) | ||
| 426 | error(1, errno, | ||
| 427 | "Unable to open tcp_fastopen sysctl for writing"); | ||
