mirror of
https://github.com/torvalds/linux.git
synced 2024-11-23 04:31:50 +00:00
selftests: bpf: Don't listen() on UDP sockets
Most tests for TCP sockmap can be adapted to UDP sockmap if the listen call is skipped. Rename listen_loopback, etc. to socket_loopback and skip listen() for SOCK_DGRAM. Signed-off-by: Lorenz Bauer <lmb@cloudflare.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Reviewed-by: Jakub Sitnicki <jakub@cloudflare.com> Acked-by: John Fastabend <john.fastabend@gmail.com> Link: https://lore.kernel.org/bpf/20200309111243.6982-10-lmb@cloudflare.com
This commit is contained in:
parent
7b98cd42b0
commit
b05fbb9f03
@ -230,7 +230,7 @@ static int enable_reuseport(int s, int progfd)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int listen_loopback_reuseport(int family, int sotype, int progfd)
|
||||
static int socket_loopback_reuseport(int family, int sotype, int progfd)
|
||||
{
|
||||
struct sockaddr_storage addr;
|
||||
socklen_t len;
|
||||
@ -249,6 +249,9 @@ static int listen_loopback_reuseport(int family, int sotype, int progfd)
|
||||
if (err)
|
||||
goto close;
|
||||
|
||||
if (sotype == SOCK_DGRAM)
|
||||
return s;
|
||||
|
||||
err = xlisten(s, SOMAXCONN);
|
||||
if (err)
|
||||
goto close;
|
||||
@ -259,9 +262,9 @@ close:
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int listen_loopback(int family, int sotype)
|
||||
static int socket_loopback(int family, int sotype)
|
||||
{
|
||||
return listen_loopback_reuseport(family, sotype, -1);
|
||||
return socket_loopback_reuseport(family, sotype, -1);
|
||||
}
|
||||
|
||||
static void test_insert_invalid(int family, int sotype, int mapfd)
|
||||
@ -333,7 +336,7 @@ static void test_insert_listening(int family, int sotype, int mapfd)
|
||||
u32 key;
|
||||
int s;
|
||||
|
||||
s = listen_loopback(family, sotype);
|
||||
s = socket_loopback(family, sotype);
|
||||
if (s < 0)
|
||||
return;
|
||||
|
||||
@ -349,7 +352,7 @@ static void test_delete_after_insert(int family, int sotype, int mapfd)
|
||||
u32 key;
|
||||
int s;
|
||||
|
||||
s = listen_loopback(family, sotype);
|
||||
s = socket_loopback(family, sotype);
|
||||
if (s < 0)
|
||||
return;
|
||||
|
||||
@ -366,7 +369,7 @@ static void test_delete_after_close(int family, int sotype, int mapfd)
|
||||
u64 value;
|
||||
u32 key;
|
||||
|
||||
s = listen_loopback(family, sotype);
|
||||
s = socket_loopback(family, sotype);
|
||||
if (s < 0)
|
||||
return;
|
||||
|
||||
@ -390,7 +393,7 @@ static void test_lookup_after_insert(int family, int sotype, int mapfd)
|
||||
u32 key;
|
||||
int s;
|
||||
|
||||
s = listen_loopback(family, sotype);
|
||||
s = socket_loopback(family, sotype);
|
||||
if (s < 0)
|
||||
return;
|
||||
|
||||
@ -417,7 +420,7 @@ static void test_lookup_after_delete(int family, int sotype, int mapfd)
|
||||
u64 value;
|
||||
u32 key;
|
||||
|
||||
s = listen_loopback(family, sotype);
|
||||
s = socket_loopback(family, sotype);
|
||||
if (s < 0)
|
||||
return;
|
||||
|
||||
@ -439,7 +442,7 @@ static void test_lookup_32_bit_value(int family, int sotype, int mapfd)
|
||||
u32 key, value32;
|
||||
int err, s;
|
||||
|
||||
s = listen_loopback(family, sotype);
|
||||
s = socket_loopback(family, sotype);
|
||||
if (s < 0)
|
||||
return;
|
||||
|
||||
@ -470,11 +473,11 @@ static void test_update_listening(int family, int sotype, int mapfd)
|
||||
u64 value;
|
||||
u32 key;
|
||||
|
||||
s1 = listen_loopback(family, sotype);
|
||||
s1 = socket_loopback(family, sotype);
|
||||
if (s1 < 0)
|
||||
return;
|
||||
|
||||
s2 = listen_loopback(family, sotype);
|
||||
s2 = socket_loopback(family, sotype);
|
||||
if (s2 < 0)
|
||||
goto close_s1;
|
||||
|
||||
@ -500,7 +503,7 @@ static void test_destroy_orphan_child(int family, int sotype, int mapfd)
|
||||
u64 value;
|
||||
u32 key;
|
||||
|
||||
s = listen_loopback(family, sotype);
|
||||
s = socket_loopback(family, sotype);
|
||||
if (s < 0)
|
||||
return;
|
||||
|
||||
@ -534,7 +537,7 @@ static void test_clone_after_delete(int family, int sotype, int mapfd)
|
||||
u64 value;
|
||||
u32 key;
|
||||
|
||||
s = listen_loopback(family, sotype);
|
||||
s = socket_loopback(family, sotype);
|
||||
if (s < 0)
|
||||
return;
|
||||
|
||||
@ -570,7 +573,7 @@ static void test_accept_after_delete(int family, int sotype, int mapfd)
|
||||
socklen_t len;
|
||||
u64 value;
|
||||
|
||||
s = listen_loopback(family, sotype);
|
||||
s = socket_loopback(family, sotype);
|
||||
if (s == -1)
|
||||
return;
|
||||
|
||||
@ -624,7 +627,7 @@ static void test_accept_before_delete(int family, int sotype, int mapfd)
|
||||
socklen_t len;
|
||||
u64 value;
|
||||
|
||||
s = listen_loopback(family, sotype);
|
||||
s = socket_loopback(family, sotype);
|
||||
if (s == -1)
|
||||
return;
|
||||
|
||||
@ -735,7 +738,7 @@ static void test_syn_recv_insert_delete(int family, int sotype, int mapfd)
|
||||
int err, s;
|
||||
u64 value;
|
||||
|
||||
s = listen_loopback(family, sotype | SOCK_NONBLOCK);
|
||||
s = socket_loopback(family, sotype | SOCK_NONBLOCK);
|
||||
if (s < 0)
|
||||
return;
|
||||
|
||||
@ -877,7 +880,7 @@ static void redir_to_connected(int family, int sotype, int sock_mapfd,
|
||||
|
||||
zero_verdict_count(verd_mapfd);
|
||||
|
||||
s = listen_loopback(family, sotype | SOCK_NONBLOCK);
|
||||
s = socket_loopback(family, sotype | SOCK_NONBLOCK);
|
||||
if (s < 0)
|
||||
return;
|
||||
|
||||
@ -1009,7 +1012,7 @@ static void redir_to_listening(int family, int sotype, int sock_mapfd,
|
||||
|
||||
zero_verdict_count(verd_mapfd);
|
||||
|
||||
s = listen_loopback(family, sotype | SOCK_NONBLOCK);
|
||||
s = socket_loopback(family, sotype | SOCK_NONBLOCK);
|
||||
if (s < 0)
|
||||
return;
|
||||
|
||||
@ -1120,7 +1123,7 @@ static void test_reuseport_select_listening(int family, int sotype,
|
||||
|
||||
zero_verdict_count(verd_map);
|
||||
|
||||
s = listen_loopback_reuseport(family, sotype, reuseport_prog);
|
||||
s = socket_loopback_reuseport(family, sotype, reuseport_prog);
|
||||
if (s < 0)
|
||||
return;
|
||||
|
||||
@ -1174,7 +1177,7 @@ static void test_reuseport_select_connected(int family, int sotype,
|
||||
|
||||
zero_verdict_count(verd_map);
|
||||
|
||||
s = listen_loopback_reuseport(family, sotype, reuseport_prog);
|
||||
s = socket_loopback_reuseport(family, sotype, reuseport_prog);
|
||||
if (s < 0)
|
||||
return;
|
||||
|
||||
@ -1249,11 +1252,11 @@ static void test_reuseport_mixed_groups(int family, int sotype, int sock_map,
|
||||
zero_verdict_count(verd_map);
|
||||
|
||||
/* Create two listeners, each in its own reuseport group */
|
||||
s1 = listen_loopback_reuseport(family, sotype, reuseport_prog);
|
||||
s1 = socket_loopback_reuseport(family, sotype, reuseport_prog);
|
||||
if (s1 < 0)
|
||||
return;
|
||||
|
||||
s2 = listen_loopback_reuseport(family, sotype, reuseport_prog);
|
||||
s2 = socket_loopback_reuseport(family, sotype, reuseport_prog);
|
||||
if (s2 < 0)
|
||||
goto close_srv1;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user