sockmap now rejects unbound UDP sockets. Adjust test_maps. While at it,
check socket()'s return value.

This effectively reverts commit c39aa2159974 ("bpf, selftests: Fix
test_maps now that sockmap supports UDP").

Reviewed-by: Kuniyuki Iwashima <[email protected]>
Signed-off-by: Michal Luczaj <[email protected]>
---
 tools/testing/selftests/bpf/test_maps.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/tools/testing/selftests/bpf/test_maps.c 
b/tools/testing/selftests/bpf/test_maps.c
index c32da7bd8be2..6a2641ee7897 100644
--- a/tools/testing/selftests/bpf/test_maps.c
+++ b/tools/testing/selftests/bpf/test_maps.c
@@ -759,16 +759,15 @@ static void test_sockmap(unsigned int tasks, void *data)
                goto out_sockmap;
        }
 
-       /* Test update with unsupported UDP socket */
+       /* Test update with unsupported unbound UDP socket */
        udp = socket(AF_INET, SOCK_DGRAM, 0);
-       i = 0;
-       err = bpf_map_update_elem(fd, &i, &udp, BPF_ANY);
-       if (err) {
-               printf("Failed socket update SOCK_DGRAM '%i:%i'\n",
-                      i, udp);
+       CHECK(udp < 0, "socket(AF_INET, SOCK_DGRAM)", "errno:%d\n", errno);
+       err = bpf_map_update_elem(fd, &(int){0}, &udp, BPF_ANY);
+       close(udp);
+       if (!err) {
+               printf("Unexpectedly succeeded unbound UDP update '0:%i'\n", 
udp);
                goto out_sockmap;
        }
-       close(udp);
 
        /* Test update without programs */
        for (i = 0; i < 6; i++) {

-- 
2.54.0


Reply via email to