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

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

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ 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
  2 /* Copyright (c) 2022 Meta Platforms, Inc. and affiliates. */
  3 
  4 #include <sys/types.h>
  5 #include <sys/socket.h>
  6 #include <net/if.h>
  7 
  8 #include "test_progs.h"
  9 #include "network_helpers.h"
 10 #include "decap_sanity.skel.h"
 11 
 12 #define NS_TEST "decap_sanity_ns"
 13 #define IPV6_IFACE_ADDR "face::1"
 14 #define UDP_TEST_PORT 7777
 15 
 16 void test_decap_sanity(void)
 17 {
 18         LIBBPF_OPTS(bpf_tc_hook, qdisc_hook, .attach_point = BPF_TC_EGRESS);
 19         LIBBPF_OPTS(bpf_tc_opts, tc_attach);
 20         struct nstoken *nstoken = NULL;
 21         struct decap_sanity *skel;
 22         struct sockaddr_in6 addr;
 23         socklen_t addrlen;
 24         char buf[128] = {};
 25         int sockfd, err;
 26 
 27         skel = decap_sanity__open_and_load();
 28         if (!ASSERT_OK_PTR(skel, "skel open_and_load"))
 29                 return;
 30 
 31         SYS(fail, "ip netns add %s", NS_TEST);
 32         SYS(fail, "ip -net %s -6 addr add %s/128 dev lo nodad", NS_TEST, IPV6_IFACE_ADDR);
 33         SYS(fail, "ip -net %s link set dev lo up", NS_TEST);
 34 
 35         nstoken = open_netns(NS_TEST);
 36         if (!ASSERT_OK_PTR(nstoken, "open_netns"))
 37                 goto fail;
 38 
 39         qdisc_hook.ifindex = if_nametoindex("lo");
 40         if (!ASSERT_GT(qdisc_hook.ifindex, 0, "if_nametoindex lo"))
 41                 goto fail;
 42 
 43         err = bpf_tc_hook_create(&qdisc_hook);
 44         if (!ASSERT_OK(err, "create qdisc hook"))
 45                 goto fail;
 46 
 47         tc_attach.prog_fd = bpf_program__fd(skel->progs.decap_sanity);
 48         err = bpf_tc_attach(&qdisc_hook, &tc_attach);
 49         if (!ASSERT_OK(err, "attach filter"))
 50                 goto fail;
 51 
 52         addrlen = sizeof(addr);
 53         err = make_sockaddr(AF_INET6, IPV6_IFACE_ADDR, UDP_TEST_PORT,
 54                             (void *)&addr, &addrlen);
 55         if (!ASSERT_OK(err, "make_sockaddr"))
 56                 goto fail;
 57         sockfd = socket(AF_INET6, SOCK_DGRAM, 0);
 58         if (!ASSERT_NEQ(sockfd, -1, "socket"))
 59                 goto fail;
 60         err = sendto(sockfd, buf, sizeof(buf), 0, (void *)&addr, addrlen);
 61         close(sockfd);
 62         if (!ASSERT_EQ(err, sizeof(buf), "send"))
 63                 goto fail;
 64 
 65         ASSERT_TRUE(skel->bss->init_csum_partial, "init_csum_partial");
 66         ASSERT_TRUE(skel->bss->final_csum_none, "final_csum_none");
 67         ASSERT_FALSE(skel->bss->broken_csum_start, "broken_csum_start");
 68 
 69 fail:
 70         if (nstoken) {
 71                 bpf_tc_hook_destroy(&qdisc_hook);
 72                 close_netns(nstoken);
 73         }
 74         SYS_NOFAIL("ip netns del " NS_TEST);
 75         decap_sanity__destroy(skel);
 76 }
 77 

~ [ 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