Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2869277pxk; Mon, 28 Sep 2020 02:10:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyII3xQk2Sk36FNgxExskcFasPvPHIltAUl7dzpy/zmhS/0XS4/C6P/354aiTzww60j/JEn X-Received: by 2002:a17:906:c34d:: with SMTP id ci13mr684769ejb.356.1601284206516; Mon, 28 Sep 2020 02:10:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601284206; cv=none; d=google.com; s=arc-20160816; b=DN19diJQlJRcXM0GQDOsr1VoXFx2GJWK04a91WNhJQ4SWvtmthijgBfpWacDimmZCQ j3OkdlHdTpIoKxXt3UNfIO2acCq+IC8dRTdgJ4CJ9koXYSq45TnT0IHVquHBMXCQHJi7 uLlzx9Pg55jwcwCZYkbDk16uyUxy3aQ+K4CmLQ+tVHgeGPyGtJ6VnRqLP2z8XMm9LUrG VSQG6S/2VjdDggyxrm4OmXKpscZs0qU/JVh0MnPl52GaCim+BN1TFoOvJM6/lSl5joYz 13l8h+ZOLKr6conc80M/8SgEKI4EzF2FPJo5nrl7mzplbvDaK9U4/tyzOwsDURgUwbs6 bmjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Hgo0C+B4MaRA4y0HWxs83icuwRAx25Hc6vqvCgKEaCI=; b=ZV9DLUq0YUDiIm7BvRMqRXzvRyWfZb6V2glfv5QJauYXT9SKWROE9na13x24Tuo6wf VILD+ZYOQuqnMDwGxE82huPplLPdN+xGXE0m7ez0TykxwA/UYNd0MERIi+WTT9l0eQBY V9lggkhC18f4ry720/fl300XN+KSSefuMpeWn4SSaZzTaPvSSAsSPnCBAiBh9pYZCMUZ npYBCqLtIUCDGLpn643jAdVt64ZvS7wlzY9AT2Tl/2ohK3hO9hgu/4ekw8tyZMNuOvUv h9vp7tVqbIO2JGuVMrWfl9WiyTk4fkMmLUfn20a6oIB3+LyiAbOkjBkqHGg2JpjtqEIC 4AEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=qZ9Iq9Y7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f2si213135edn.26.2020.09.28.02.09.43; Mon, 28 Sep 2020 02:10:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=qZ9Iq9Y7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726788AbgI1JIp (ORCPT + 99 others); Mon, 28 Sep 2020 05:08:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726716AbgI1JIo (ORCPT ); Mon, 28 Sep 2020 05:08:44 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D199CC0613D5 for ; Mon, 28 Sep 2020 02:08:42 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id s13so260904wmh.4 for ; Mon, 28 Sep 2020 02:08:42 -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=Hgo0C+B4MaRA4y0HWxs83icuwRAx25Hc6vqvCgKEaCI=; b=qZ9Iq9Y7IeU4EBY/MUElVtiiiS0QAMvrZjex6udneQ8xKfu1nUGnGrxo36TYNqocel s7Xx75wFu9HoFkQ9qgxrQNZSYtsgpIHTD+4B7xlCTdzCKjlCF2pqOhvpVwwnvyKY1OMK HOvWmn1FcO8XEBNHoStCb7DNlo82+DQYMIdig= 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=Hgo0C+B4MaRA4y0HWxs83icuwRAx25Hc6vqvCgKEaCI=; b=UfZ2lcHvq0I8kN6hznS9+jtucC2EwL1BFlm1dWEGpfNIsdBBOFdeZ07EqQInec+qO5 x7hEMeDZRRPkwT6W48bf4x6zlylo9IrEMMM+RQwb7KZE/wCglItR8GSiWf1T1Ij2mJ1E 5+NMQjXJG4x88aQHyOi/EaQObzcUs8L/woJt3/14AS+U9z2SbkfHi5MCYspQzUqrz5kd Es13WQnSrN3fxQzw41PYYdTR+isHH+tlETzhO31/Ba7ox7FUiJ+zibBrsMv5tWZGxfv3 OKOaNDEN+r1xQ5GaU6b+t1yEooZr9P/MJ3RNh9chhvO3pXMtyHLl6nRVlerwBf4v5nS+ Xg0Q== X-Gm-Message-State: AOAM5325gf21w36tJNJP1v4HyuGRMDyKnDiNlVbqCMumDcSdllEkvjYK hhOw8/YwU4Vxs+ISzhvFU9xpMQ== X-Received: by 2002:a7b:cd93:: with SMTP id y19mr561874wmj.112.1601284121348; Mon, 28 Sep 2020 02:08:41 -0700 (PDT) Received: from antares.lan (1.f.1.6.a.e.6.5.a.0.3.2.4.7.4.0.f.f.6.2.a.5.a.7.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:7a5a:26ff:474:230a:56ea:61f1]) by smtp.gmail.com with ESMTPSA id u13sm479631wrm.77.2020.09.28.02.08.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Sep 2020 02:08:40 -0700 (PDT) From: Lorenz Bauer To: kafai@fb.com, Shuah Khan , Alexei Starovoitov , Daniel Borkmann Cc: kernel-team@cloudflare.com, Lorenz Bauer , linux-kselftest@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next v2 2/4] selftests: bpf: Add helper to compare socket cookies Date: Mon, 28 Sep 2020 10:08:03 +0100 Message-Id: <20200928090805.23343-3-lmb@cloudflare.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200928090805.23343-1-lmb@cloudflare.com> References: <20200928090805.23343-1-lmb@cloudflare.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We compare socket cookies to ensure that insertion into a sockmap worked. Pull this out into a helper function for use in other tests. Signed-off-by: Lorenz Bauer --- .../selftests/bpf/prog_tests/sockmap_basic.c | 50 +++++++++++++------ 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c b/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c index 4b7a527e7e82..67d3301bdf81 100644 --- a/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c +++ b/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c @@ -50,6 +50,37 @@ static int connected_socket_v4(void) return -1; } +static void compare_cookies(struct bpf_map *src, struct bpf_map *dst) +{ + __u32 i, max_entries = bpf_map__max_entries(src); + int err, duration, src_fd, dst_fd; + + src_fd = bpf_map__fd(src); + dst_fd = bpf_map__fd(dst); + + for (i = 0; i < max_entries; i++) { + __u64 src_cookie, dst_cookie; + + err = bpf_map_lookup_elem(src_fd, &i, &src_cookie); + if (err && errno == ENOENT) { + err = bpf_map_lookup_elem(dst_fd, &i, &dst_cookie); + CHECK(!err, "map_lookup_elem(dst)", "element %u not deleted\n", i); + CHECK(err && errno != ENOENT, "map_lookup_elem(dst)", "%s\n", + strerror(errno)); + continue; + } + if (CHECK(err, "lookup_elem(src)", "%s\n", strerror(errno))) + continue; + + err = bpf_map_lookup_elem(dst_fd, &i, &dst_cookie); + if (CHECK(err, "lookup_elem(dst)", "%s\n", strerror(errno))) + continue; + + CHECK(dst_cookie != src_cookie, "cookie mismatch", + "%llu != %llu (pos %u)\n", dst_cookie, src_cookie, i); + } +} + /* Create a map, populate it with one socket, and free the map. */ static void test_sockmap_create_update_free(enum bpf_map_type map_type) { @@ -109,9 +140,9 @@ static void test_skmsg_helpers(enum bpf_map_type map_type) static void test_sockmap_update(enum bpf_map_type map_type) { struct bpf_prog_test_run_attr tattr; - int err, prog, src, dst, duration = 0; + int err, prog, src, duration = 0; struct test_sockmap_update *skel; - __u64 src_cookie, dst_cookie; + struct bpf_map *dst_map; const __u32 zero = 0; char dummy[14] = {0}; __s64 sk; @@ -127,18 +158,14 @@ static void test_sockmap_update(enum bpf_map_type map_type) prog = bpf_program__fd(skel->progs.copy_sock_map); src = bpf_map__fd(skel->maps.src); if (map_type == BPF_MAP_TYPE_SOCKMAP) - dst = bpf_map__fd(skel->maps.dst_sock_map); + dst_map = skel->maps.dst_sock_map; else - dst = bpf_map__fd(skel->maps.dst_sock_hash); + dst_map = skel->maps.dst_sock_hash; err = bpf_map_update_elem(src, &zero, &sk, BPF_NOEXIST); if (CHECK(err, "update_elem(src)", "errno=%u\n", errno)) goto out; - err = bpf_map_lookup_elem(src, &zero, &src_cookie); - if (CHECK(err, "lookup_elem(src, cookie)", "errno=%u\n", errno)) - goto out; - tattr = (struct bpf_prog_test_run_attr){ .prog_fd = prog, .repeat = 1, @@ -151,12 +178,7 @@ static void test_sockmap_update(enum bpf_map_type map_type) "errno=%u retval=%u\n", errno, tattr.retval)) goto out; - err = bpf_map_lookup_elem(dst, &zero, &dst_cookie); - if (CHECK(err, "lookup_elem(dst, cookie)", "errno=%u\n", errno)) - goto out; - - CHECK(dst_cookie != src_cookie, "cookie mismatch", "%llu != %llu\n", - dst_cookie, src_cookie); + compare_cookies(skel->maps.src, dst_map); out: test_sockmap_update__destroy(skel); -- 2.25.1