From patchwork Mon Mar 9 11:12:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenz Bauer X-Patchwork-Id: 11426739 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9E83B14E3 for ; Mon, 9 Mar 2020 11:13:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 76F9D21D56 for ; Mon, 9 Mar 2020 11:13:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=cloudflare.com header.i=@cloudflare.com header.b="T+MwXpSF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726974AbgCILN2 (ORCPT ); Mon, 9 Mar 2020 07:13:28 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:51663 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726918AbgCILN1 (ORCPT ); Mon, 9 Mar 2020 07:13:27 -0400 Received: by mail-wm1-f68.google.com with SMTP id a132so9369620wme.1 for ; Mon, 09 Mar 2020 04:13:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=55uiRdkoDOcfMjXmIBGgTWxBo6cVNLF5HZAhtJG09Qo=; b=T+MwXpSFCv8TtcIPXQOLo/ehqfzZc7V3HmI3ofOMLNy0Wvp2yVNoVGlIOm7TqCTvs5 bK42YMWKtOubC3AOKn6Bx5AGQbBLsBmiv/wGfuJZy4kpUrxBnB5x+kkOi0CyUwdFV6Rk gbLPPXao982phGCjjwki8P8gejzjPYvkJdD58= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=55uiRdkoDOcfMjXmIBGgTWxBo6cVNLF5HZAhtJG09Qo=; b=fyx6Obt1ZLug8Biv8uWFj+hNnlKPhQ/V6bzBDmdz8dXL8MVorJDo++sVjpC0ZNXHwH uxyKPy+A4IiaOO2JubU9P7+7PBEqzBdMe4vK0TEXdgkYMxL/+g+ByUy0FviVkI36jajf Q1fjH8BfcPjS9gb5JqmtvGqkTFqEMEoEItQQ5ODIi8AgJsfiAJd8A8q3ISnHbnrR4Y20 2DvvRkpri3FkSpy3ftdqMvJGD2jG47OTMSLtdyDWCRm4cgqyJqQPuIzpeC27kVa3XSwm 0H36jGWe8pw9MpMdMkWmsyHR753tghcmf2pj27abpAMXlYsSVRNJlDlCNWPk2yT4bQbh k9jQ== X-Gm-Message-State: ANhLgQ196R8PamCZP9BcKxdvfk7wUFjS0WJlbCUloPMX20LyFGm1Wk0g AV/j6U3y3JAH34/z83BzEg8rCA== X-Google-Smtp-Source: ADFU+vsDspKmQnLy+9e4MN05+pJwgVV2LPfO50xaFIII9Ko+m3/F4t1jo9WJCpDMbx2wN4/3FGxKFA== X-Received: by 2002:a7b:cd83:: with SMTP id y3mr19429922wmj.176.1583752404907; Mon, 09 Mar 2020 04:13:24 -0700 (PDT) Received: from localhost.localdomain ([2a06:98c0:1000:8250:3dcc:c1d:7f05:4873]) by smtp.gmail.com with ESMTPSA id a5sm25732846wmb.37.2020.03.09.04.13.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Mar 2020 04:13:24 -0700 (PDT) From: Lorenz Bauer To: Shuah Khan , Alexei Starovoitov , Daniel Borkmann Cc: kernel-team@cloudflare.com, Lorenz Bauer , Jakub Sitnicki , John Fastabend , linux-kselftest@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next v4 09/12] selftests: bpf: don't listen() on UDP sockets Date: Mon, 9 Mar 2020 11:12:40 +0000 Message-Id: <20200309111243.6982-10-lmb@cloudflare.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200309111243.6982-1-lmb@cloudflare.com> References: <20200309111243.6982-1-lmb@cloudflare.com> MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org 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 Reviewed-by: Jakub Sitnicki Acked-by: John Fastabend --- .../selftests/bpf/prog_tests/sockmap_listen.c | 47 ++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c b/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c index b1b2acea0638..4ba41dd26d6b 100644 --- a/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c +++ b/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c @@ -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 @@ static int listen_loopback_reuseport(int family, int sotype, int progfd) 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; From patchwork Mon Mar 9 11:12:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenz Bauer X-Patchwork-Id: 11426741 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3C55214E3 for ; Mon, 9 Mar 2020 11:13:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0CD8120866 for ; Mon, 9 Mar 2020 11:13:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=cloudflare.com header.i=@cloudflare.com header.b="KEx0ardF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726977AbgCILNy (ORCPT ); Mon, 9 Mar 2020 07:13:54 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:55140 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726968AbgCILNa (ORCPT ); Mon, 9 Mar 2020 07:13:30 -0400 Received: by mail-wm1-f65.google.com with SMTP id n8so5347752wmc.4 for ; Mon, 09 Mar 2020 04:13:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kfIbQ9egZOgHYEi4ZCtd5fcolR6Q2j1G5CwpXRfW+tU=; b=KEx0ardFKYz7mGkN7NWnfSDkRafDapDG2sLJYkCv+JC2SBmTcFSiYizOTPYGLtPwGg bKeyCtwHIy/Z7AkMcCWM04z37PJvzgsnFbsqJ/0sbqLj3L0uzjmytRUSdSQqpfcLzzXg HsIKE38qf+XFkSf2BiB2MbBviHa0n40VfdxG4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kfIbQ9egZOgHYEi4ZCtd5fcolR6Q2j1G5CwpXRfW+tU=; b=SvPxdIhniiZgCtLYVNlD/QVhuJZVF7EH6S9q9afry3gu43+wYsRG9y35welEjAvBzN GMEsxMRAp//EgG0J+CbC2+XtWldU0QFdYh14QXYpYE9CF5wg6mXZruIAxOhVbZ7Ef06L zDPfkDmYH5TrRrZsg5OBRLsVxSd2U4Pi4XO3oBSVOrSr6nCvXh8mSfWUmPSkEToGYE0T 0tpPQEBlOreU4ftyjAxFZhm01tJowfKTtGG2sxOdA84GY1694ciXXiFVuCxHKesIJZcz sot670u99CGMLiR/NADH66Rq42sVBmEuq03iEptA0rHc9tLDEulQv63Svpt+zqgQBrAS gF0g== X-Gm-Message-State: ANhLgQ06RDzfHGbZWIotZWIdQitEfYGAARzvDhp+9VaDCwLQCpNlExrD VVyp7bHgq86vEuCY0todfBZuGFsYatf2IQ== X-Google-Smtp-Source: ADFU+vuRfiz5krPEg4BZ5r6jV4YZnMKnig5RI9m5gj5KCO1aBqQF6rqXdPIJcLzJwmHHi1znJBAZHw== X-Received: by 2002:a1c:a102:: with SMTP id k2mr6140449wme.125.1583752406466; Mon, 09 Mar 2020 04:13:26 -0700 (PDT) Received: from localhost.localdomain ([2a06:98c0:1000:8250:3dcc:c1d:7f05:4873]) by smtp.gmail.com with ESMTPSA id a5sm25732846wmb.37.2020.03.09.04.13.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Mar 2020 04:13:25 -0700 (PDT) From: Lorenz Bauer To: Shuah Khan , Alexei Starovoitov , Daniel Borkmann Cc: kernel-team@cloudflare.com, Lorenz Bauer , Jakub Sitnicki , John Fastabend , linux-kselftest@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next v4 10/12] selftests: bpf: add tests for UDP sockets in sockmap Date: Mon, 9 Mar 2020 11:12:41 +0000 Message-Id: <20200309111243.6982-11-lmb@cloudflare.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200309111243.6982-1-lmb@cloudflare.com> References: <20200309111243.6982-1-lmb@cloudflare.com> MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Expand the TCP sockmap test suite to also check UDP sockets. Signed-off-by: Jakub Sitnicki Signed-off-by: Lorenz Bauer Acked-by: John Fastabend --- .../selftests/bpf/prog_tests/sockmap_listen.c | 157 ++++++++++++++---- 1 file changed, 127 insertions(+), 30 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c b/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c index 4ba41dd26d6b..52aa468bdccd 100644 --- a/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c +++ b/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c @@ -108,6 +108,22 @@ __ret; \ }) +#define xsend(fd, buf, len, flags) \ + ({ \ + ssize_t __ret = send((fd), (buf), (len), (flags)); \ + if (__ret == -1) \ + FAIL_ERRNO("send"); \ + __ret; \ + }) + +#define xrecv(fd, buf, len, flags) \ + ({ \ + ssize_t __ret = recv((fd), (buf), (len), (flags)); \ + if (__ret == -1) \ + FAIL_ERRNO("recv"); \ + __ret; \ + }) + #define xsocket(family, sotype, flags) \ ({ \ int __ret = socket(family, sotype, flags); \ @@ -330,7 +346,7 @@ static void test_insert_bound(int family, int sotype, int mapfd) xclose(s); } -static void test_insert_listening(int family, int sotype, int mapfd) +static void test_insert(int family, int sotype, int mapfd) { u64 value; u32 key; @@ -467,7 +483,7 @@ static void test_lookup_32_bit_value(int family, int sotype, int mapfd) xclose(s); } -static void test_update_listening(int family, int sotype, int mapfd) +static void test_update_existing(int family, int sotype, int mapfd) { int s1, s2; u64 value; @@ -1116,7 +1132,7 @@ static void test_reuseport_select_listening(int family, int sotype, { struct sockaddr_storage addr; unsigned int pass; - int s, c, p, err; + int s, c, err; socklen_t len; u64 value; u32 key; @@ -1145,19 +1161,33 @@ static void test_reuseport_select_listening(int family, int sotype, if (err) goto close_cli; - p = xaccept(s, NULL, NULL); - if (p < 0) - goto close_cli; + if (sotype == SOCK_STREAM) { + int p; + + p = xaccept(s, NULL, NULL); + if (p < 0) + goto close_cli; + xclose(p); + } else { + char b = 'a'; + ssize_t n; + + n = xsend(c, &b, sizeof(b), 0); + if (n == -1) + goto close_cli; + + n = xrecv(s, &b, sizeof(b), 0); + if (n == -1) + goto close_cli; + } key = SK_PASS; err = xbpf_map_lookup_elem(verd_map, &key, &pass); if (err) - goto close_peer; + goto close_cli; if (pass != 1) FAIL("want pass count 1, have %d", pass); -close_peer: - xclose(p); close_cli: xclose(c); close_srv: @@ -1201,9 +1231,24 @@ static void test_reuseport_select_connected(int family, int sotype, if (err) goto close_cli0; - p0 = xaccept(s, NULL, NULL); - if (err) - goto close_cli0; + if (sotype == SOCK_STREAM) { + p0 = xaccept(s, NULL, NULL); + if (p0 < 0) + goto close_cli0; + } else { + p0 = xsocket(family, sotype, 0); + if (p0 < 0) + goto close_cli0; + + len = sizeof(addr); + err = xgetsockname(c0, sockaddr(&addr), &len); + if (err) + goto close_cli0; + + err = xconnect(p0, sockaddr(&addr), len); + if (err) + goto close_cli0; + } /* Update sock_map[0] to redirect to a connected socket */ key = 0; @@ -1216,8 +1261,24 @@ static void test_reuseport_select_connected(int family, int sotype, if (c1 < 0) goto close_peer0; + len = sizeof(addr); + err = xgetsockname(s, sockaddr(&addr), &len); + if (err) + goto close_srv; + errno = 0; err = connect(c1, sockaddr(&addr), len); + if (sotype == SOCK_DGRAM) { + char b = 'a'; + ssize_t n; + + n = xsend(c1, &b, sizeof(b), 0); + if (n == -1) + goto close_cli1; + + n = recv(c1, &b, sizeof(b), 0); + err = n == -1; + } if (!err || errno != ECONNREFUSED) FAIL_ERRNO("connect: expected ECONNREFUSED"); @@ -1281,7 +1342,18 @@ static void test_reuseport_mixed_groups(int family, int sotype, int sock_map, goto close_srv2; err = connect(c, sockaddr(&addr), len); - if (err && errno != ECONNREFUSED) { + if (sotype == SOCK_DGRAM) { + char b = 'a'; + ssize_t n; + + n = xsend(c, &b, sizeof(b), 0); + if (n == -1) + goto close_cli; + + n = recv(c, &b, sizeof(b), 0); + err = n == -1; + } + if (!err || errno != ECONNREFUSED) { FAIL_ERRNO("connect: expected ECONNREFUSED"); goto close_cli; } @@ -1302,9 +1374,9 @@ static void test_reuseport_mixed_groups(int family, int sotype, int sock_map, xclose(s1); } -#define TEST(fn) \ +#define TEST(fn, ...) \ { \ - fn, #fn \ + fn, #fn, __VA_ARGS__ \ } static void test_ops_cleanup(const struct bpf_map *map) @@ -1353,18 +1425,31 @@ static const char *map_type_str(const struct bpf_map *map) } } +static const char *sotype_str(int sotype) +{ + switch (sotype) { + case SOCK_DGRAM: + return "UDP"; + case SOCK_STREAM: + return "TCP"; + default: + return "unknown"; + } +} + static void test_ops(struct test_sockmap_listen *skel, struct bpf_map *map, int family, int sotype) { const struct op_test { void (*fn)(int family, int sotype, int mapfd); const char *name; + int sotype; } tests[] = { /* insert */ TEST(test_insert_invalid), TEST(test_insert_opened), - TEST(test_insert_bound), - TEST(test_insert_listening), + TEST(test_insert_bound, SOCK_STREAM), + TEST(test_insert), /* delete */ TEST(test_delete_after_insert), TEST(test_delete_after_close), @@ -1373,28 +1458,32 @@ static void test_ops(struct test_sockmap_listen *skel, struct bpf_map *map, TEST(test_lookup_after_delete), TEST(test_lookup_32_bit_value), /* update */ - TEST(test_update_listening), + TEST(test_update_existing), /* races with insert/delete */ - TEST(test_destroy_orphan_child), - TEST(test_syn_recv_insert_delete), - TEST(test_race_insert_listen), + TEST(test_destroy_orphan_child, SOCK_STREAM), + TEST(test_syn_recv_insert_delete, SOCK_STREAM), + TEST(test_race_insert_listen, SOCK_STREAM), /* child clone */ - TEST(test_clone_after_delete), - TEST(test_accept_after_delete), - TEST(test_accept_before_delete), + TEST(test_clone_after_delete, SOCK_STREAM), + TEST(test_accept_after_delete, SOCK_STREAM), + TEST(test_accept_before_delete, SOCK_STREAM), }; - const char *family_name, *map_name; + const char *family_name, *map_name, *sotype_name; const struct op_test *t; char s[MAX_TEST_NAME]; int map_fd; family_name = family_str(family); map_name = map_type_str(map); + sotype_name = sotype_str(sotype); map_fd = bpf_map__fd(map); for (t = tests; t < tests + ARRAY_SIZE(tests); t++) { - snprintf(s, sizeof(s), "%s %s %s", map_name, family_name, - t->name); + snprintf(s, sizeof(s), "%s %s %s %s", map_name, family_name, + sotype_name, t->name); + + if (t->sotype != 0 && t->sotype != sotype) + continue; if (!test__start_subtest(s)) continue; @@ -1427,6 +1516,7 @@ static void test_redir(struct test_sockmap_listen *skel, struct bpf_map *map, for (t = tests; t < tests + ARRAY_SIZE(tests); t++) { snprintf(s, sizeof(s), "%s %s %s", map_name, family_name, t->name); + if (!test__start_subtest(s)) continue; @@ -1441,26 +1531,31 @@ static void test_reuseport(struct test_sockmap_listen *skel, void (*fn)(int family, int sotype, int socket_map, int verdict_map, int reuseport_prog); const char *name; + int sotype; } tests[] = { TEST(test_reuseport_select_listening), TEST(test_reuseport_select_connected), TEST(test_reuseport_mixed_groups), }; int socket_map, verdict_map, reuseport_prog; - const char *family_name, *map_name; + const char *family_name, *map_name, *sotype_name; const struct reuseport_test *t; char s[MAX_TEST_NAME]; family_name = family_str(family); map_name = map_type_str(map); + sotype_name = sotype_str(sotype); socket_map = bpf_map__fd(map); verdict_map = bpf_map__fd(skel->maps.verdict_map); reuseport_prog = bpf_program__fd(skel->progs.prog_reuseport); for (t = tests; t < tests + ARRAY_SIZE(tests); t++) { - snprintf(s, sizeof(s), "%s %s %s", map_name, family_name, - t->name); + snprintf(s, sizeof(s), "%s %s %s %s", map_name, family_name, + sotype_name, t->name); + + if (t->sotype != 0 && t->sotype != sotype) + continue; if (!test__start_subtest(s)) continue; @@ -1473,8 +1568,10 @@ static void run_tests(struct test_sockmap_listen *skel, struct bpf_map *map, int family) { test_ops(skel, map, family, SOCK_STREAM); + test_ops(skel, map, family, SOCK_DGRAM); test_redir(skel, map, family, SOCK_STREAM); test_reuseport(skel, map, family, SOCK_STREAM); + test_reuseport(skel, map, family, SOCK_DGRAM); } void test_sockmap_listen(void) From patchwork Mon Mar 9 11:12:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenz Bauer X-Patchwork-Id: 11426737 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6F06314B7 for ; Mon, 9 Mar 2020 11:13:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 465EA2051A for ; Mon, 9 Mar 2020 11:13:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=cloudflare.com header.i=@cloudflare.com header.b="vhJLcMYm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726997AbgCILNa (ORCPT ); Mon, 9 Mar 2020 07:13:30 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:50648 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726986AbgCILN3 (ORCPT ); Mon, 9 Mar 2020 07:13:29 -0400 Received: by mail-wm1-f68.google.com with SMTP id a5so9392806wmb.0 for ; Mon, 09 Mar 2020 04:13:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QaTFcTkFq4Xguxn8bSzfnksfS0c2jnlyVSoCBPs8eek=; b=vhJLcMYmm/qr33TiAo7JT5z9HUaVRDrZxOEz87v6imXUfpQppv5xXULXiHOZUArRRp FFGy2atvM1OycOehbNrLU6P63rckxQ5xm5mpMolVJvbPuKMVwijc1yTXJj+7Q6XXNB9u mCjeJOvp1kRypn4zZL6FicO2iv+f6FuzwaSm0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QaTFcTkFq4Xguxn8bSzfnksfS0c2jnlyVSoCBPs8eek=; b=d7N76+ACmQqwul25ssHrWZxESiqxbJ+KhcJMw10R6LJS8Dia6vFzPCwdiydcPZEdnu FmdDeNKNUQJOzgmxVgc2sIey2zDEX+rhZTazBJIjYUcBtBelYxtmshLB7ZiTgRt601T1 pxwcH34OBE+cp5zlEtUXjBA70xEadNA6r2lTa3/wlQZMT+QQvo9CQVA0S4/19/aQL7Sa nSARcLFgTqq5YTlnTieX+aoJAdO6uVUq73XmsiCB1OTEG1J0dhtnrGuxoM59J8fRdelo 3zYuuUcjnQHKTMahOaMADRHU+pC1uyjgwqvNG15k3A3KEQ73WPqZ+HGWrsXrLaM2sL+x KIWg== X-Gm-Message-State: ANhLgQ23pzYQVvA5y5KIrbLcuXJp7z1yOLo05rOhSyOzC5SVejNzIq/4 riqJr5XiI4WuxUZNnpEj2AODAg== X-Google-Smtp-Source: ADFU+vtelcGYQQ7cq2t6WKsONlaRaq72BxVgq3eY1uel/I49QzMryenNk1JX3ZTxqPj2w/PQTT0LSA== X-Received: by 2002:a05:600c:2214:: with SMTP id z20mr18926382wml.57.1583752408076; Mon, 09 Mar 2020 04:13:28 -0700 (PDT) Received: from localhost.localdomain ([2a06:98c0:1000:8250:3dcc:c1d:7f05:4873]) by smtp.gmail.com with ESMTPSA id a5sm25732846wmb.37.2020.03.09.04.13.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Mar 2020 04:13:27 -0700 (PDT) From: Lorenz Bauer To: Shuah Khan , Alexei Starovoitov , Daniel Borkmann Cc: kernel-team@cloudflare.com, Lorenz Bauer , Jakub Sitnicki , John Fastabend , linux-kselftest@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next v4 11/12] selftests: bpf: enable UDP sockmap reuseport tests Date: Mon, 9 Mar 2020 11:12:42 +0000 Message-Id: <20200309111243.6982-12-lmb@cloudflare.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200309111243.6982-1-lmb@cloudflare.com> References: <20200309111243.6982-1-lmb@cloudflare.com> MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Remove the guard that disables UDP tests now that sockmap has support for them. Signed-off-by: Lorenz Bauer Reviewed-by: Jakub Sitnicki Acked-by: John Fastabend --- tools/testing/selftests/bpf/prog_tests/select_reuseport.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/select_reuseport.c b/tools/testing/selftests/bpf/prog_tests/select_reuseport.c index a1dd13b34d4b..821b4146b7b6 100644 --- a/tools/testing/selftests/bpf/prog_tests/select_reuseport.c +++ b/tools/testing/selftests/bpf/prog_tests/select_reuseport.c @@ -805,12 +805,6 @@ static void test_config(int sotype, sa_family_t family, bool inany) char s[MAX_TEST_NAME]; const struct test *t; - /* SOCKMAP/SOCKHASH don't support UDP yet */ - if (sotype == SOCK_DGRAM && - (inner_map_type == BPF_MAP_TYPE_SOCKMAP || - inner_map_type == BPF_MAP_TYPE_SOCKHASH)) - return; - for (t = tests; t < tests + ARRAY_SIZE(tests); t++) { if (t->need_sotype && t->need_sotype != sotype) continue; /* test not compatible with socket type */