~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/prog_tests/netfilter_link_attach.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-or-later
  2 
  3 #include <netinet/in.h>
  4 #include <linux/netfilter.h>
  5 
  6 #include "test_progs.h"
  7 #include "test_netfilter_link_attach.skel.h"
  8 
  9 struct nf_link_test {
 10         __u32 pf;
 11         __u32 hooknum;
 12         __s32 priority;
 13         __u32 flags;
 14 
 15         bool expect_success;
 16         const char * const name;
 17 };
 18 
 19 static const struct nf_link_test nf_hook_link_tests[] = {
 20         { .name = "allzero", },
 21         { .pf = NFPROTO_NUMPROTO, .name = "invalid-pf", },
 22         { .pf = NFPROTO_IPV4, .hooknum = 42, .name = "invalid-hooknum", },
 23         { .pf = NFPROTO_IPV4, .priority = INT_MIN, .name = "invalid-priority-min", },
 24         { .pf = NFPROTO_IPV4, .priority = INT_MAX, .name = "invalid-priority-max", },
 25         { .pf = NFPROTO_IPV4, .flags = UINT_MAX, .name = "invalid-flags", },
 26 
 27         { .pf = NFPROTO_INET, .priority = 1, .name = "invalid-inet-not-supported", },
 28 
 29         { .pf = NFPROTO_IPV4, .priority = -10000, .expect_success = true, .name = "attach ipv4", },
 30         { .pf = NFPROTO_IPV6, .priority =  10001, .expect_success = true, .name = "attach ipv6", },
 31 };
 32 
 33 void test_netfilter_link_attach(void)
 34 {
 35         struct test_netfilter_link_attach *skel;
 36         struct bpf_program *prog;
 37         LIBBPF_OPTS(bpf_netfilter_opts, opts);
 38         int i;
 39 
 40         skel = test_netfilter_link_attach__open_and_load();
 41         if (!ASSERT_OK_PTR(skel, "test_netfilter_link_attach__open_and_load"))
 42                 goto out;
 43 
 44         prog = skel->progs.nf_link_attach_test;
 45         if (!ASSERT_OK_PTR(prog, "attach program"))
 46                 goto out;
 47 
 48         for (i = 0; i < ARRAY_SIZE(nf_hook_link_tests); i++) {
 49                 struct bpf_link *link;
 50 
 51                 if (!test__start_subtest(nf_hook_link_tests[i].name))
 52                         continue;
 53 
 54 #define X(opts, m, i)   opts.m = nf_hook_link_tests[(i)].m
 55                 X(opts, pf, i);
 56                 X(opts, hooknum, i);
 57                 X(opts, priority, i);
 58                 X(opts, flags, i);
 59 #undef X
 60                 link = bpf_program__attach_netfilter(prog, &opts);
 61                 if (nf_hook_link_tests[i].expect_success) {
 62                         struct bpf_link *link2;
 63 
 64                         if (!ASSERT_OK_PTR(link, "program attach successful"))
 65                                 continue;
 66 
 67                         link2 = bpf_program__attach_netfilter(prog, &opts);
 68                         ASSERT_ERR_PTR(link2, "attach program with same pf/hook/priority");
 69 
 70                         if (!ASSERT_OK(bpf_link__destroy(link), "link destroy"))
 71                                 break;
 72 
 73                         link2 = bpf_program__attach_netfilter(prog, &opts);
 74                         if (!ASSERT_OK_PTR(link2, "program reattach successful"))
 75                                 continue;
 76                         if (!ASSERT_OK(bpf_link__destroy(link2), "link destroy"))
 77                                 break;
 78                 } else {
 79                         ASSERT_ERR_PTR(link, "program load failure");
 80                 }
 81         }
 82 
 83 out:
 84         test_netfilter_link_attach__destroy(skel);
 85 }
 86 
 87 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php