Commit b05fbb9f authored by Lorenz Bauer's avatar Lorenz Bauer Committed by Daniel Borkmann

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: default avatarLorenz Bauer <lmb@cloudflare.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Reviewed-by: default avatarJakub Sitnicki <jakub@cloudflare.com>
Acked-by: default avatarJohn Fastabend <john.fastabend@gmail.com>
Link: https://lore.kernel.org/bpf/20200309111243.6982-10-lmb@cloudflare.com
parent 7b98cd42
...@@ -230,7 +230,7 @@ static int enable_reuseport(int s, int progfd) ...@@ -230,7 +230,7 @@ static int enable_reuseport(int s, int progfd)
return 0; 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; struct sockaddr_storage addr;
socklen_t len; socklen_t len;
...@@ -249,6 +249,9 @@ static int listen_loopback_reuseport(int family, int sotype, int progfd) ...@@ -249,6 +249,9 @@ static int listen_loopback_reuseport(int family, int sotype, int progfd)
if (err) if (err)
goto close; goto close;
if (sotype == SOCK_DGRAM)
return s;
err = xlisten(s, SOMAXCONN); err = xlisten(s, SOMAXCONN);
if (err) if (err)
goto close; goto close;
...@@ -259,9 +262,9 @@ static int listen_loopback_reuseport(int family, int sotype, int progfd) ...@@ -259,9 +262,9 @@ static int listen_loopback_reuseport(int family, int sotype, int progfd)
return -1; 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) 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) ...@@ -333,7 +336,7 @@ static void test_insert_listening(int family, int sotype, int mapfd)
u32 key; u32 key;
int s; int s;
s = listen_loopback(family, sotype); s = socket_loopback(family, sotype);
if (s < 0) if (s < 0)
return; return;
...@@ -349,7 +352,7 @@ static void test_delete_after_insert(int family, int sotype, int mapfd) ...@@ -349,7 +352,7 @@ static void test_delete_after_insert(int family, int sotype, int mapfd)
u32 key; u32 key;
int s; int s;
s = listen_loopback(family, sotype); s = socket_loopback(family, sotype);
if (s < 0) if (s < 0)
return; return;
...@@ -366,7 +369,7 @@ static void test_delete_after_close(int family, int sotype, int mapfd) ...@@ -366,7 +369,7 @@ static void test_delete_after_close(int family, int sotype, int mapfd)
u64 value; u64 value;
u32 key; u32 key;
s = listen_loopback(family, sotype); s = socket_loopback(family, sotype);
if (s < 0) if (s < 0)
return; return;
...@@ -390,7 +393,7 @@ static void test_lookup_after_insert(int family, int sotype, int mapfd) ...@@ -390,7 +393,7 @@ static void test_lookup_after_insert(int family, int sotype, int mapfd)
u32 key; u32 key;
int s; int s;
s = listen_loopback(family, sotype); s = socket_loopback(family, sotype);
if (s < 0) if (s < 0)
return; return;
...@@ -417,7 +420,7 @@ static void test_lookup_after_delete(int family, int sotype, int mapfd) ...@@ -417,7 +420,7 @@ static void test_lookup_after_delete(int family, int sotype, int mapfd)
u64 value; u64 value;
u32 key; u32 key;
s = listen_loopback(family, sotype); s = socket_loopback(family, sotype);
if (s < 0) if (s < 0)
return; return;
...@@ -439,7 +442,7 @@ static void test_lookup_32_bit_value(int family, int sotype, int mapfd) ...@@ -439,7 +442,7 @@ static void test_lookup_32_bit_value(int family, int sotype, int mapfd)
u32 key, value32; u32 key, value32;
int err, s; int err, s;
s = listen_loopback(family, sotype); s = socket_loopback(family, sotype);
if (s < 0) if (s < 0)
return; return;
...@@ -470,11 +473,11 @@ static void test_update_listening(int family, int sotype, int mapfd) ...@@ -470,11 +473,11 @@ static void test_update_listening(int family, int sotype, int mapfd)
u64 value; u64 value;
u32 key; u32 key;
s1 = listen_loopback(family, sotype); s1 = socket_loopback(family, sotype);
if (s1 < 0) if (s1 < 0)
return; return;
s2 = listen_loopback(family, sotype); s2 = socket_loopback(family, sotype);
if (s2 < 0) if (s2 < 0)
goto close_s1; goto close_s1;
...@@ -500,7 +503,7 @@ static void test_destroy_orphan_child(int family, int sotype, int mapfd) ...@@ -500,7 +503,7 @@ static void test_destroy_orphan_child(int family, int sotype, int mapfd)
u64 value; u64 value;
u32 key; u32 key;
s = listen_loopback(family, sotype); s = socket_loopback(family, sotype);
if (s < 0) if (s < 0)
return; return;
...@@ -534,7 +537,7 @@ static void test_clone_after_delete(int family, int sotype, int mapfd) ...@@ -534,7 +537,7 @@ static void test_clone_after_delete(int family, int sotype, int mapfd)
u64 value; u64 value;
u32 key; u32 key;
s = listen_loopback(family, sotype); s = socket_loopback(family, sotype);
if (s < 0) if (s < 0)
return; return;
...@@ -570,7 +573,7 @@ static void test_accept_after_delete(int family, int sotype, int mapfd) ...@@ -570,7 +573,7 @@ static void test_accept_after_delete(int family, int sotype, int mapfd)
socklen_t len; socklen_t len;
u64 value; u64 value;
s = listen_loopback(family, sotype); s = socket_loopback(family, sotype);
if (s == -1) if (s == -1)
return; return;
...@@ -624,7 +627,7 @@ static void test_accept_before_delete(int family, int sotype, int mapfd) ...@@ -624,7 +627,7 @@ static void test_accept_before_delete(int family, int sotype, int mapfd)
socklen_t len; socklen_t len;
u64 value; u64 value;
s = listen_loopback(family, sotype); s = socket_loopback(family, sotype);
if (s == -1) if (s == -1)
return; return;
...@@ -735,7 +738,7 @@ static void test_syn_recv_insert_delete(int family, int sotype, int mapfd) ...@@ -735,7 +738,7 @@ static void test_syn_recv_insert_delete(int family, int sotype, int mapfd)
int err, s; int err, s;
u64 value; u64 value;
s = listen_loopback(family, sotype | SOCK_NONBLOCK); s = socket_loopback(family, sotype | SOCK_NONBLOCK);
if (s < 0) if (s < 0)
return; return;
...@@ -877,7 +880,7 @@ static void redir_to_connected(int family, int sotype, int sock_mapfd, ...@@ -877,7 +880,7 @@ static void redir_to_connected(int family, int sotype, int sock_mapfd,
zero_verdict_count(verd_mapfd); zero_verdict_count(verd_mapfd);
s = listen_loopback(family, sotype | SOCK_NONBLOCK); s = socket_loopback(family, sotype | SOCK_NONBLOCK);
if (s < 0) if (s < 0)
return; return;
...@@ -1009,7 +1012,7 @@ static void redir_to_listening(int family, int sotype, int sock_mapfd, ...@@ -1009,7 +1012,7 @@ static void redir_to_listening(int family, int sotype, int sock_mapfd,
zero_verdict_count(verd_mapfd); zero_verdict_count(verd_mapfd);
s = listen_loopback(family, sotype | SOCK_NONBLOCK); s = socket_loopback(family, sotype | SOCK_NONBLOCK);
if (s < 0) if (s < 0)
return; return;
...@@ -1120,7 +1123,7 @@ static void test_reuseport_select_listening(int family, int sotype, ...@@ -1120,7 +1123,7 @@ static void test_reuseport_select_listening(int family, int sotype,
zero_verdict_count(verd_map); zero_verdict_count(verd_map);
s = listen_loopback_reuseport(family, sotype, reuseport_prog); s = socket_loopback_reuseport(family, sotype, reuseport_prog);
if (s < 0) if (s < 0)
return; return;
...@@ -1174,7 +1177,7 @@ static void test_reuseport_select_connected(int family, int sotype, ...@@ -1174,7 +1177,7 @@ static void test_reuseport_select_connected(int family, int sotype,
zero_verdict_count(verd_map); zero_verdict_count(verd_map);
s = listen_loopback_reuseport(family, sotype, reuseport_prog); s = socket_loopback_reuseport(family, sotype, reuseport_prog);
if (s < 0) if (s < 0)
return; return;
...@@ -1249,11 +1252,11 @@ static void test_reuseport_mixed_groups(int family, int sotype, int sock_map, ...@@ -1249,11 +1252,11 @@ static void test_reuseport_mixed_groups(int family, int sotype, int sock_map,
zero_verdict_count(verd_map); zero_verdict_count(verd_map);
/* Create two listeners, each in its own reuseport group */ /* 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) if (s1 < 0)
return; return;
s2 = listen_loopback_reuseport(family, sotype, reuseport_prog); s2 = socket_loopback_reuseport(family, sotype, reuseport_prog);
if (s2 < 0) if (s2 < 0)
goto close_srv1; goto close_srv1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment