From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA96CC33CB8 for ; Thu, 23 Jan 2020 15:55:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B1DB820704 for ; Thu, 23 Jan 2020 15:55:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=cloudflare.com header.i=@cloudflare.com header.b="hSmMaS84" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729094AbgAWPzx (ORCPT ); Thu, 23 Jan 2020 10:55:53 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:40069 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729075AbgAWPzw (ORCPT ); Thu, 23 Jan 2020 10:55:52 -0500 Received: by mail-wr1-f67.google.com with SMTP id c14so3637900wrn.7 for ; Thu, 23 Jan 2020 07:55:51 -0800 (PST) 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=4CXJwdpYP+mrY90uu9dxiHkdaf1zG454XQX7axBVn84=; b=hSmMaS84Gv1cVM3oKhryJYHkrp+IBmyxVnDTyOEANgvyF2EPs+LT3NXUychdR5VBJq 2oUe2bx2TyH9H+t78fYBzOXNqaDVCJ3F1axqG6UE7Md/xIUiDfSpvBzHKfM8KD5sbuGd 3+f9ZvmF5PoJe4OHOeOUpLASxgrJv71hr8/QA= 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=4CXJwdpYP+mrY90uu9dxiHkdaf1zG454XQX7axBVn84=; b=lm7TF0SrRKd2LE5zSN/JcaYBTGOLDgKv/M4BNVYlnirXqAQ2EVe7L/yfESJ4wiU1cX iCKqFQXh8Gqp2nmcS/PY3p6GYZjd7ccwcdJXGeOOA4XNxW56n5swnEsRzZkpmD7KSArI GBtbjpCgCamw2P1wOaUxG2EeOymPRqVjX2l5tfi0BwnADuuk0EPMTnQBVYPogl51fOs8 d8oHr/9ZUWNjQDQVYlL+UBDY7FWCRtiRLNd6Z0xr4p99qAsZlV9dJYSSuNvQeoo4vgon VBCZlXERorQ7fb0zO2Az1b8q2iXrhhUeUY9m1iZOabcBWr1YotUOgekoy70SSC+0WOfu AyGQ== X-Gm-Message-State: APjAAAVY6FbgCAaXa0KwcyNCwUdX+Mqg1m8vSfYgc98EBZhQLbnjKgTp LaN7a6RG0npBcalWRuOvWJ9qrYLnc9Uerw== X-Google-Smtp-Source: APXvYqxKr2cH5CNE2xIlh80k4WJwDKXpOW2kBYfH2vy+YfX7m7UhESniiQGebGeqe3hR0Si+iYzDDQ== X-Received: by 2002:a5d:6ca1:: with SMTP id a1mr17959120wra.36.1579794950225; Thu, 23 Jan 2020 07:55:50 -0800 (PST) Received: from cloudflare.com ([176.221.114.230]) by smtp.gmail.com with ESMTPSA id x7sm3431375wrq.41.2020.01.23.07.55.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jan 2020 07:55:49 -0800 (PST) From: Jakub Sitnicki To: bpf@vger.kernel.org Cc: netdev@vger.kernel.org, kernel-team@cloudflare.com, John Fastabend , Lorenz Bauer , Martin Lau Subject: [PATCH bpf-next v4 11/12] selftests/bpf: Extend SK_REUSEPORT tests to cover SOCKMAP Date: Thu, 23 Jan 2020 16:55:33 +0100 Message-Id: <20200123155534.114313-12-jakub@cloudflare.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200123155534.114313-1-jakub@cloudflare.com> References: <20200123155534.114313-1-jakub@cloudflare.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Parametrize the SK_REUSEPORT tests so that the map type for storing sockets is not hard-coded in the test setup routine. This, together with careful state cleaning after the tests, let's us run the test cases once with REUSEPORT_ARRAY and once with SOCKMAP (TCP only), to have test coverage for the latter as well. Acked-by: John Fastabend Signed-off-by: Jakub Sitnicki --- .../bpf/prog_tests/select_reuseport.c | 60 +++++++++++++++---- 1 file changed, 50 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/select_reuseport.c b/tools/testing/selftests/bpf/prog_tests/select_reuseport.c index 2c37ae7dc214..e7b4abfca2ab 100644 --- a/tools/testing/selftests/bpf/prog_tests/select_reuseport.c +++ b/tools/testing/selftests/bpf/prog_tests/select_reuseport.c @@ -36,6 +36,7 @@ static int result_map, tmp_index_ovr_map, linum_map, data_check_map; static enum result expected_results[NR_RESULTS]; static int sk_fds[REUSEPORT_ARRAY_SIZE]; static int reuseport_array = -1, outer_map = -1; +static enum bpf_map_type inner_map_type; static int select_by_skb_data_prog; static int saved_tcp_syncookie = -1; static struct bpf_object *obj; @@ -63,13 +64,15 @@ static union sa46 { } \ }) -static int create_maps(void) +static int create_maps(enum bpf_map_type inner_type) { struct bpf_create_map_attr attr = {}; + inner_map_type = inner_type; + /* Creating reuseport_array */ attr.name = "reuseport_array"; - attr.map_type = BPF_MAP_TYPE_REUSEPORT_SOCKARRAY; + attr.map_type = inner_type; attr.key_size = sizeof(__u32); attr.value_size = sizeof(__u32); attr.max_entries = REUSEPORT_ARRAY_SIZE; @@ -694,12 +697,34 @@ static void cleanup_per_test(bool no_inner_map) static void cleanup(void) { - if (outer_map != -1) + if (outer_map != -1) { close(outer_map); - if (reuseport_array != -1) + outer_map = -1; + } + + if (reuseport_array != -1) { close(reuseport_array); - if (obj) + reuseport_array = -1; + } + + if (obj) { bpf_object__close(obj); + obj = NULL; + } + + memset(expected_results, 0, sizeof(expected_results)); +} + +static const char *maptype_str(enum bpf_map_type type) +{ + switch (type) { + case BPF_MAP_TYPE_REUSEPORT_SOCKARRAY: + return "reuseport_sockarray"; + case BPF_MAP_TYPE_SOCKMAP: + return "sockmap"; + default: + return "unknown"; + } } static const char *family_str(sa_family_t family) @@ -747,13 +772,21 @@ static void test_config(int sotype, sa_family_t family, bool inany) const struct test *t; for (t = tests; t < tests + ARRAY_SIZE(tests); t++) { - snprintf(s, sizeof(s), "%s/%s %s %s", + snprintf(s, sizeof(s), "%s %s/%s %s %s", + maptype_str(inner_map_type), family_str(family), sotype_str(sotype), inany ? "INANY" : "LOOPBACK", t->name); if (!test__start_subtest(s)) continue; + if (sotype == SOCK_DGRAM && + inner_map_type == BPF_MAP_TYPE_SOCKMAP) { + /* SOCKMAP doesn't support UDP yet */ + test__skip(); + continue; + } + setup_per_test(sotype, family, inany, t->no_inner_map); t->fn(sotype, family); cleanup_per_test(t->no_inner_map); @@ -782,13 +815,20 @@ static void test_all(void) test_config(c->sotype, c->family, c->inany); } -void test_select_reuseport(void) +void test_map_type(enum bpf_map_type mt) { - if (create_maps()) + if (create_maps(mt)) goto out; if (prepare_bpf_obj()) goto out; + test_all(); +out: + cleanup(); +} + +void test_select_reuseport(void) +{ saved_tcp_fo = read_int_sysctl(TCP_FO_SYSCTL); saved_tcp_syncookie = read_int_sysctl(TCP_SYNCOOKIE_SYSCTL); if (saved_tcp_syncookie < 0 || saved_tcp_syncookie < 0) @@ -799,8 +839,8 @@ void test_select_reuseport(void) if (disable_syncookie()) goto out; - test_all(); + test_map_type(BPF_MAP_TYPE_REUSEPORT_SOCKARRAY); + test_map_type(BPF_MAP_TYPE_SOCKMAP); out: - cleanup(); restore_sysctls(); } -- 2.24.1