]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
selftests/bpf: Move existing common networking parts into network_helpers
authorStanislav Fomichev <sdf@google.com>
Fri, 8 May 2020 17:46:09 +0000 (10:46 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Fri, 8 May 2020 22:48:20 +0000 (00:48 +0200)
1. Move pkt_v4 and pkt_v6 into network_helpers and adjust the users.
2. Copy-paste spin_lock_thread into two tests that use it.

Signed-off-by: Stanislav Fomichev <sdf@google.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Acked-by: Andrey Ignatov <rdna@fb.com>
Link: https://lore.kernel.org/bpf/20200508174611.228805-3-sdf@google.com
22 files changed:
tools/testing/selftests/bpf/network_helpers.c
tools/testing/selftests/bpf/network_helpers.h
tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c
tools/testing/selftests/bpf/prog_tests/flow_dissector.c
tools/testing/selftests/bpf/prog_tests/flow_dissector_load_bytes.c
tools/testing/selftests/bpf/prog_tests/global_data.c
tools/testing/selftests/bpf/prog_tests/kfree_skb.c
tools/testing/selftests/bpf/prog_tests/l4lb_all.c
tools/testing/selftests/bpf/prog_tests/map_lock.c
tools/testing/selftests/bpf/prog_tests/pkt_access.c
tools/testing/selftests/bpf/prog_tests/pkt_md_access.c
tools/testing/selftests/bpf/prog_tests/prog_run_xattr.c
tools/testing/selftests/bpf/prog_tests/queue_stack_map.c
tools/testing/selftests/bpf/prog_tests/signal_pending.c
tools/testing/selftests/bpf/prog_tests/skb_ctx.c
tools/testing/selftests/bpf/prog_tests/spinlock.c
tools/testing/selftests/bpf/prog_tests/xdp.c
tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c
tools/testing/selftests/bpf/prog_tests/xdp_bpf2bpf.c
tools/testing/selftests/bpf/prog_tests/xdp_noinline.c
tools/testing/selftests/bpf/test_progs.c
tools/testing/selftests/bpf/test_progs.h

index 0073dddb72fd465b210e3625ea7f7605e7f978c9..0ff64b70b74655e418c3a40091239280ca04024f 100644 (file)
 #define log_err(MSG, ...) fprintf(stderr, "(%s:%d: errno: %s) " MSG "\n", \
        __FILE__, __LINE__, clean_errno(), ##__VA_ARGS__)
 
+struct ipv4_packet pkt_v4 = {
+       .eth.h_proto = __bpf_constant_htons(ETH_P_IP),
+       .iph.ihl = 5,
+       .iph.protocol = IPPROTO_TCP,
+       .iph.tot_len = __bpf_constant_htons(MAGIC_BYTES),
+       .tcp.urg_ptr = 123,
+       .tcp.doff = 5,
+};
+
+struct ipv6_packet pkt_v6 = {
+       .eth.h_proto = __bpf_constant_htons(ETH_P_IPV6),
+       .iph.nexthdr = IPPROTO_TCP,
+       .iph.payload_len = __bpf_constant_htons(MAGIC_BYTES),
+       .tcp.urg_ptr = 123,
+       .tcp.doff = 5,
+};
+
 int start_server(int family, int type)
 {
        struct sockaddr_storage addr = {};
index 30068eacc1a24f70fef2460edb1c7adfc87e64c6..a0be7db4f67d6a5f4c8e8006d68ddca7e957a88e 100644 (file)
@@ -3,6 +3,35 @@
 #define __NETWORK_HELPERS_H
 #include <sys/socket.h>
 #include <sys/types.h>
+#include <linux/types.h>
+typedef __u16 __sum16;
+#include <linux/if_ether.h>
+#include <linux/if_packet.h>
+#include <linux/ip.h>
+#include <linux/ipv6.h>
+#include <netinet/tcp.h>
+#include <bpf/bpf_endian.h>
+
+#define MAGIC_VAL 0x1234
+#define NUM_ITER 100000
+#define VIP_NUM 5
+#define MAGIC_BYTES 123
+
+/* ipv4 test vector */
+struct ipv4_packet {
+       struct ethhdr eth;
+       struct iphdr iph;
+       struct tcphdr tcp;
+} __packed;
+extern struct ipv4_packet pkt_v4;
+
+/* ipv6 test vector */
+struct ipv6_packet {
+       struct ethhdr eth;
+       struct ipv6hdr iph;
+       struct tcphdr tcp;
+} __packed;
+extern struct ipv6_packet pkt_v6;
 
 int start_server(int family, int type);
 int connect_to_fd(int family, int type, int server_fd);
index c2642517e1d8d6a7bd77dbcdb0410b826e5ff960..a895bfed55db04ecedd03652149d11d2edd48943 100644 (file)
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 /* Copyright (c) 2019 Facebook */
 #include <test_progs.h>
+#include <network_helpers.h>
 
 static void test_fexit_bpf2bpf_common(const char *obj_file,
                                      const char *target_obj_file,
index 92563898867cb690e8d8193756603f4a8683ee81..2301c4d3ecec533770f5771855ae3ac988d24cf7 100644 (file)
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <test_progs.h>
+#include <network_helpers.h>
 #include <error.h>
 #include <linux/if.h>
 #include <linux/if_tun.h>
index dc5ef155ec282b3403df8db16ad81ceb7e4cc1a1..0e8a4d2f023d0453f3b5baf787f201f0fd486dc7 100644 (file)
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <test_progs.h>
+#include <network_helpers.h>
 
 void test_flow_dissector_load_bytes(void)
 {
index c680926fce7384914aa34eb368b4c5ebc83c3c65..e3cb62b0a110ec81b2be13b5134e283856b95965 100644 (file)
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <test_progs.h>
+#include <network_helpers.h>
 
 static void test_global_data_number(struct bpf_object *obj, __u32 duration)
 {
index 7507c8f689bc5c255513991a691481d63304cdbd..42c3a3103c26211421f4dbe64378aac8388e3dd0 100644 (file)
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <test_progs.h>
+#include <network_helpers.h>
 
 struct meta {
        int ifindex;
index eaf64595be8810aaaaf0a6fff5665ebf9a3f018e..c2d373e294bbf963aa6df836266110737e866875 100644 (file)
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <test_progs.h>
+#include <network_helpers.h>
 
 static void test_l4lb(const char *file)
 {
index 8f91f1881d114b1e13cc239efb22180c28fcad88..ce17b1ed8709f8f4ade0482aaa6ab577daad7e44 100644 (file)
@@ -1,5 +1,19 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <test_progs.h>
+#include <network_helpers.h>
+
+static void *spin_lock_thread(void *arg)
+{
+       __u32 duration, retval;
+       int err, prog_fd = *(u32 *) arg;
+
+       err = bpf_prog_test_run(prog_fd, 10000, &pkt_v4, sizeof(pkt_v4),
+                               NULL, NULL, &retval, &duration);
+       CHECK(err || retval, "",
+             "err %d errno %d retval %d duration %d\n",
+             err, errno, retval, duration);
+       pthread_exit(arg);
+}
 
 static void *parallel_map_access(void *arg)
 {
index a2537dfa899c6707e6ac46d074de9621bc6d96f6..44b514fabccd844d74b61da956fd595c60fecd82 100644 (file)
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <test_progs.h>
+#include <network_helpers.h>
 
 void test_pkt_access(void)
 {
index 5f7aea6050199bf8b2c0dffce6d0cbd424a005ab..939015cd6dbae3c781c7f10cd09d13d057e4d858 100644 (file)
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <test_progs.h>
+#include <network_helpers.h>
 
 void test_pkt_md_access(void)
 {
index 5dd89b941f53f397de2aa13e984d7371d47e8a97..dde2b7ae7bc9e9bee8b342f260e88fc524aab5bf 100644 (file)
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <test_progs.h>
+#include <network_helpers.h>
 
 void test_prog_run_xattr(void)
 {
index faccc66f4e3968af3c4efd0a03c33719f9d151dc..f47e7b1cb32cc781fd4190d0fa7c904a4362929a 100644 (file)
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <test_progs.h>
+#include <network_helpers.h>
 
 enum {
        QUEUE,
index 996e808f43a26bd7409d3fa0102f89093b48d27e..dfcbddcbe4d3f94cc7da06ec7d4a6ca907185603 100644 (file)
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <test_progs.h>
+#include <network_helpers.h>
 
 static void sigalrm_handler(int s) {}
 static struct sigaction sigalrm_action = {
index 4538bd08203f53205ee19c295b441d89047019eb..7021b92af31345c98197da76721c389266deef01 100644 (file)
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <test_progs.h>
+#include <network_helpers.h>
 
 void test_skb_ctx(void)
 {
index 1ae00cd3174ef8723c98c88350b85ccad7466ac2..7577a77a4c4c57b64a0e750c97eee73d5f2f4278 100644 (file)
@@ -1,5 +1,19 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <test_progs.h>
+#include <network_helpers.h>
+
+static void *spin_lock_thread(void *arg)
+{
+       __u32 duration, retval;
+       int err, prog_fd = *(u32 *) arg;
+
+       err = bpf_prog_test_run(prog_fd, 10000, &pkt_v4, sizeof(pkt_v4),
+                               NULL, NULL, &retval, &duration);
+       CHECK(err || retval, "",
+             "err %d errno %d retval %d duration %d\n",
+             err, errno, retval, duration);
+       pthread_exit(arg);
+}
 
 void test_spinlock(void)
 {
index dcb5ecac778e8a2cf07d6103f25a5252fe6fd1cd..48921ff748503a2b27cae4d08bfec33c38300c47 100644 (file)
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <test_progs.h>
+#include <network_helpers.h>
 
 void test_xdp(void)
 {
index 3744196d7cba923d249bfe541679210ab09a78eb..6c8ca1c93f9b1edcd96ee0ba0353cd12ffc3e37a 100644 (file)
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <test_progs.h>
+#include <network_helpers.h>
 
 void test_xdp_adjust_tail(void)
 {
index a0f688c370235d978f4d0c1a06aed3f46c04bb4c..2c6c570b21f8e8b90518ae5238295ef75ecb9093 100644 (file)
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <test_progs.h>
+#include <network_helpers.h>
 #include <net/if.h>
 #include "test_xdp.skel.h"
 #include "test_xdp_bpf2bpf.skel.h"
index c9404e6b226ee7f0c652a55b3eda3e1e3f65cf7f..f284f72158efd7744b629b7d93e29853f6292b03 100644 (file)
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <test_progs.h>
+#include <network_helpers.h>
 
 void test_xdp_noinline(void)
 {
index 93970ec1c9e942720e37c3adb9deecb3442925f1..0f411fdc4f6de181afba7166b1b953a35cc7e117 100644 (file)
@@ -222,23 +222,6 @@ int test__join_cgroup(const char *path)
        return fd;
 }
 
-struct ipv4_packet pkt_v4 = {
-       .eth.h_proto = __bpf_constant_htons(ETH_P_IP),
-       .iph.ihl = 5,
-       .iph.protocol = IPPROTO_TCP,
-       .iph.tot_len = __bpf_constant_htons(MAGIC_BYTES),
-       .tcp.urg_ptr = 123,
-       .tcp.doff = 5,
-};
-
-struct ipv6_packet pkt_v6 = {
-       .eth.h_proto = __bpf_constant_htons(ETH_P_IPV6),
-       .iph.nexthdr = IPPROTO_TCP,
-       .iph.payload_len = __bpf_constant_htons(MAGIC_BYTES),
-       .tcp.urg_ptr = 123,
-       .tcp.doff = 5,
-};
-
 int bpf_find_map(const char *test, struct bpf_object *obj, const char *name)
 {
        struct bpf_map *map;
@@ -358,19 +341,6 @@ err:
        return -1;
 }
 
-void *spin_lock_thread(void *arg)
-{
-       __u32 duration, retval;
-       int err, prog_fd = *(u32 *) arg;
-
-       err = bpf_prog_test_run(prog_fd, 10000, &pkt_v4, sizeof(pkt_v4),
-                               NULL, NULL, &retval, &duration);
-       CHECK(err || retval, "",
-             "err %d errno %d retval %d duration %d\n",
-             err, errno, retval, duration);
-       pthread_exit(arg);
-}
-
 /* extern declarations for test funcs */
 #define DEFINE_TEST(name) extern void test_##name(void);
 #include <prog_tests/tests.h>
index 10188cc8e9e019ce7421e71fc9954a180f29b11a..83287c76332b0031f78a83751c0674840202026a 100644 (file)
@@ -87,24 +87,6 @@ extern void test__skip(void);
 extern void test__fail(void);
 extern int test__join_cgroup(const char *path);
 
-#define MAGIC_BYTES 123
-
-/* ipv4 test vector */
-struct ipv4_packet {
-       struct ethhdr eth;
-       struct iphdr iph;
-       struct tcphdr tcp;
-} __packed;
-extern struct ipv4_packet pkt_v4;
-
-/* ipv6 test vector */
-struct ipv6_packet {
-       struct ethhdr eth;
-       struct ipv6hdr iph;
-       struct tcphdr tcp;
-} __packed;
-extern struct ipv6_packet pkt_v6;
-
 #define PRINT_FAIL(format...)                                                  \
        ({                                                                     \
                test__fail();                                                  \
@@ -143,10 +125,6 @@ extern struct ipv6_packet pkt_v6;
 #define CHECK_ATTR(condition, tag, format...) \
        _CHECK(condition, tag, tattr.duration, format)
 
-#define MAGIC_VAL 0x1234
-#define NUM_ITER 100000
-#define VIP_NUM 5
-
 static inline __u64 ptr_to_u64(const void *ptr)
 {
        return (__u64) (unsigned long) ptr;
@@ -156,7 +134,6 @@ int bpf_find_map(const char *test, struct bpf_object *obj, const char *name);
 int compare_map_keys(int map1_fd, int map2_fd);
 int compare_stack_ips(int smap_fd, int amap_fd, int stack_trace_len);
 int extract_build_id(char *build_id, size_t size);
-void *spin_lock_thread(void *arg);
 
 #ifdef __x86_64__
 #define SYS_NANOSLEEP_KPROBE_NAME "__x64_sys_nanosleep"