History

Revert "net: Add a second bind table hashed by port and address"

This reverts: commit d5a42de8bdbe ("net: Add a second bind table hashed by port and address") commit 538aaf9b2383 ("selftests: Add test for timing a bind request to a port with a populated bhash entry") Link: https://lore.kernel.org/netdev/20220520001834.2247810-1-kuba@kernel.org/ There are a few things that need to be fixed here: * Updating bhash2 in cases where the socket's rcv saddr changes * Adding bhash2 hashbucket locks Links to syzbot reports: https://lore.kernel.org/netdev/00000000000022208805e0df247a@google.com/ https://lore.kernel.org/netdev/0000000000003f33bc05dfaf44fe@google.com/

Joanne Koong committed 4 years ago

Commit 593d1eb1 parent 219b51a10 files · +83 −611Browse files

Showing the changes to tools/testing (3 of 10 files). Show all

Unified · Split

3 files
  1. tools/testing/selftests/net/.gitignore +0 −1
  2. tools/testing/selftests/net/Makefile +0 −2
  3. tools/testing/selftests/net/bind_bhash_test.c +0 −119
tools/testing/selftests/net/.gitignore+0−1
@@ -37,4 +37,3 @@ gro · 36 unmodified lines
37ioam6_parser37ioam6_parser
38toeplitz38toeplitz
39cmsg_sender39cmsg_sender
40bind_bhash_test
tools/testing/selftests/net/Makefile+0−2
@@ -59,7 +59,6 @@ TEST_GEN_FILES += toeplitz · 58 unmodified lines
59TEST_GEN_FILES += cmsg_sender59TEST_GEN_FILES += cmsg_sender
60TEST_GEN_FILES += stress_reuseport_listen60TEST_GEN_FILES += stress_reuseport_listen
61TEST_PROGS += test_vxlan_vnifiltering.sh61TEST_PROGS += test_vxlan_vnifiltering.sh
62TEST_GEN_FILES += bind_bhash_test
63 62
64TEST_FILES := settings63TEST_FILES := settings
65 64
@@ -70,5 +69,4 @@ include bpf/Makefile · 4 unmodified lines
70 69
71$(OUTPUT)/reuseport_bpf_numa: LDLIBS += -lnuma70$(OUTPUT)/reuseport_bpf_numa: LDLIBS += -lnuma
72$(OUTPUT)/tcp_mmap: LDLIBS += -lpthread71$(OUTPUT)/tcp_mmap: LDLIBS += -lpthread
73$(OUTPUT)/bind_bhash_test: LDLIBS += -lpthread
74$(OUTPUT)/tcp_inq: LDLIBS += -lpthread72$(OUTPUT)/tcp_inq: LDLIBS += -lpthread
tools/testing/selftests/net/bind_bhash_test.c+0−119
@@ -1,119 +0,0 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * This times how long it takes to bind to a port when the port already
4 * has multiple sockets in its bhash table.
5 *
6 * In the setup(), we populate the port's bhash table with
7 * MAX_THREADS * MAX_CONNECTIONS number of entries.
8 */
9
10#include <unistd.h>
11#include <stdio.h>
12#include <netdb.h>
13#include <pthread.h>
14
15#define MAX_THREADS 600
16#define MAX_CONNECTIONS 40
17
18static const char *bind_addr = "::1";
19static const char *port;
20
21static int fd_array[MAX_THREADS][MAX_CONNECTIONS];
22
23static int bind_socket(int opt, const char *addr)
24{
25 struct addrinfo *res, hint = {};
26 int sock_fd, reuse = 1, err;
27
28 sock_fd = socket(AF_INET6, SOCK_STREAM, 0);
29 if (sock_fd < 0) {
30 perror("socket fd err");
31 return -1;
32 }
33
34 hint.ai_family = AF_INET6;
35 hint.ai_socktype = SOCK_STREAM;
36
37 err = getaddrinfo(addr, port, &hint, &res);
38 if (err) {
39 perror("getaddrinfo failed");
40 return -1;
41 }
42
43 if (opt) {
44 err = setsockopt(sock_fd, SOL_SOCKET, opt, &reuse, sizeof(reuse));
45 if (err) {
46 perror("setsockopt failed");
47 return -1;
48 }
49 }
50
51 err = bind(sock_fd, res->ai_addr, res->ai_addrlen);
52 if (err) {
53 perror("failed to bind to port");
54 return -1;
55 }
56
57 return sock_fd;
58}
59
60static void *setup(void *arg)
61{
62 int sock_fd, i;
63 int *array = (int *)arg;
64
65 for (i = 0; i < MAX_CONNECTIONS; i++) {
66 sock_fd = bind_socket(SO_REUSEADDR | SO_REUSEPORT, bind_addr);
67 if (sock_fd < 0)
68 return NULL;
69 array[i] = sock_fd;
70 }
71
72 return NULL;
73}
74
75int main(int argc, const char *argv[])
76{
77 int listener_fd, sock_fd, i, j;
78 pthread_t tid[MAX_THREADS];
79 clock_t begin, end;
80
81 if (argc != 2) {
82 printf("Usage: listener <port>\n");
83 return -1;
84 }
85
86 port = argv[1];
87
88 listener_fd = bind_socket(SO_REUSEADDR | SO_REUSEPORT, bind_addr);
89 if (listen(listener_fd, 100) < 0) {
90 perror("listen failed");
91 return -1;
92 }
93
94 /* Set up threads to populate the bhash table entry for the port */
95 for (i = 0; i < MAX_THREADS; i++)
96 pthread_create(&tid[i], NULL, setup, fd_array[i]);
97
98 for (i = 0; i < MAX_THREADS; i++)
99 pthread_join(tid[i], NULL);
100
101 begin = clock();
102
103 /* Bind to the same port on a different address */
104 sock_fd = bind_socket(0, "2001:0db8:0:f101::1");
105
106 end = clock();
107
108 printf("time spent = %f\n", (double)(end - begin) / CLOCKS_PER_SEC);
109
110 /* clean up */
111 close(sock_fd);
112 close(listener_fd);
113 for (i = 0; i < MAX_THREADS; i++) {
114 for (j = 0; i < MAX_THREADS; i++)
115 close(fd_array[i][j]);
116 }
117
118 return 0;
119}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t