1. 28 4月, 2019 1 次提交
  2. 13 4月, 2019 1 次提交
    • A
      selftests/bpf: Test BPF_CGROUP_SYSCTL · 1f5fa9ab
      Andrey Ignatov 提交于
      Add unit test for BPF_PROG_TYPE_CGROUP_SYSCTL program type.
      
      Test that program can allow/deny access.
      Test both valid and invalid accesses to ctx->write.
      
      Example of output:
        # ./test_sysctl
        Test case: sysctl wrong attach_type .. [PASS]
        Test case: sysctl:read allow all .. [PASS]
        Test case: sysctl:read deny all .. [PASS]
        Test case: ctx:write sysctl:read read ok .. [PASS]
        Test case: ctx:write sysctl:write read ok .. [PASS]
        Test case: ctx:write sysctl:read write reject .. [PASS]
        Summary: 6 PASSED, 0 FAILED
      Signed-off-by: NAndrey Ignatov <rdna@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      1f5fa9ab
  3. 03 4月, 2019 1 次提交
    • S
      selftests: bpf: tests.h should depend on .c files, not the output · 6b7b6995
      Stanislav Fomichev 提交于
      This makes sure we don't put headers as input files when doing
      compilation, because clang complains about the following:
      
      clang-9: error: cannot specify -o when generating multiple output files
      ../lib.mk:152: recipe for target 'xxx/tools/testing/selftests/bpf/test_verifier' failed
      make: *** [xxx/tools/testing/selftests/bpf/test_verifier] Error 1
      make: *** Waiting for unfinished jobs....
      clang-9: error: cannot specify -o when generating multiple output files
      ../lib.mk:152: recipe for target 'xxx/tools/testing/selftests/bpf/test_progs' failed
      Signed-off-by: NStanislav Fomichev <sdf@google.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      6b7b6995
  4. 23 3月, 2019 2 次提交
  5. 22 3月, 2019 2 次提交
  6. 07 3月, 2019 1 次提交
    • S
      selftests: bpf: fix compilation with out-of-tree $(OUTPUT) · e78e00bd
      Stanislav Fomichev 提交于
      A bunch of related changes lumped together:
      * Create prog_tests and verifier output directories; these don't exist with
        out-of-tree $(OUTPUT)
      * Add missing -I (via separate TEST_{PROGS,VERIFIER}_CFLAGS) for the main tree
        ($(PWD) != $(OUTPUT) for out-of-tree)
      * Add libbpf.a dependency for test_progs_32 (parallel make fails otherwise)
      * Add missing "; \" after "cd" when generating test.h headers
      
      Tested by:
      $ alias m="make -s -j$(nproc)"
      $ m -C tools/testing/selftests/bpf/ clean
      $ m -C tools/lib/bpf/ clean
      $ rm -rf xxx; mkdir xxx; m -C tools/testing/selftests/bpf/ OUTPUT=$PWD/xxx
      $ m -C tools/testing/selftests/bpf/
      
      Fixes: 3f306588 ("selftests: bpf: break up test_progs - preparations")
      Fixes: 2dfb4012 ("selftests: bpf: prepare for break up of verifier tests")
      Fixes: 3ef84346 ("selftests: bpf: makefile support sub-register code-gen test mode")
      Signed-off-by: NStanislav Fomichev <sdf@google.com>
      Acked-by: NYonghong Song <yhs@fb.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      e78e00bd
  7. 03 3月, 2019 1 次提交
    • S
      selftests: bpf: break up test_progs - preparations · 3f306588
      Stanislav Fomichev 提交于
      Add new prog_tests directory where tests are supposed to land.
      Each prog_tests/<filename>.c is expected to have a global function
      with signature 'void test_<filename>(void)'. Makefile automatically
      generates prog_tests/tests.h file with entry for each prog_tests file:
      
      	#ifdef DECLARE
      	extern void test_<filename>(void);
      	...
      	#endif
      
      	#ifdef CALL
      	test_<filename>();
      	...
      	#endif
      
      prog_tests/tests.h is included in test_progs.c in two places with
      appropriate defines. This scheme allows us to move each function with
      a separate patch without breaking anything.
      
      Compared to the recent verifier split, each separate file here is
      a compilation unit and test_progs.[ch] is now used as a place to put
      some common routines that might be used by multiple tests.
      Signed-off-by: NStanislav Fomichev <sdf@google.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      3f306588
  8. 14 2月, 2019 1 次提交
  9. 12 2月, 2019 3 次提交
  10. 11 2月, 2019 1 次提交
  11. 02 2月, 2019 3 次提交
  12. 29 1月, 2019 1 次提交
  13. 28 1月, 2019 1 次提交
  14. 27 1月, 2019 1 次提交
  15. 25 1月, 2019 1 次提交
  16. 16 1月, 2019 1 次提交
  17. 10 1月, 2019 1 次提交
  18. 22 11月, 2018 1 次提交
  19. 21 11月, 2018 1 次提交
  20. 09 11月, 2018 1 次提交
    • S
      selftests/bpf: add a test case for sock_ops perf-event notification · 435f90a3
      Sowmini Varadhan 提交于
      This patch provides a tcp_bpf based eBPF sample. The test
      
      - ncat(1) as the TCP client program to connect() to a port
        with the intention of triggerring SYN retransmissions: we
        first install an iptables DROP rule to make sure ncat SYNs are
        resent (instead of aborting instantly after a TCP RST)
      
      - has a bpf kernel module that sends a perf-event notification for
        each TCP retransmit, and also tracks the number of such notifications
        sent in the global_map
      
      The test passes when the number of event notifications intercepted
      in user-space matches the value in the global_map.
      Signed-off-by: NSowmini Varadhan <sowmini.varadhan@oracle.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      435f90a3
  21. 08 11月, 2018 2 次提交
    • P
      selftests: add dummy xdp test helper · bd8e1afe
      Paolo Abeni 提交于
      This trivial XDP program does nothing, but will be used by the
      next patch to test the GRO path in a net namespace, leveraging
      the veth XDP implementation.
      
      It's added here, despite its 'net' usage, to avoid the duplication
      of the llc-related makefile boilerplate.
      
      rfc v3 -> v1:
       - move the helper implementation into the bpf directory, don't
         touch udpgso_bench_rx
      
      rfc v2 -> rfc v3:
       - move 'x' option handling here
      Signed-off-by: NPaolo Abeni <pabeni@redhat.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      bd8e1afe
    • Q
      selftests/bpf: enable (uncomment) all tests in test_libbpf.sh · f96afa76
      Quentin Monnet 提交于
      libbpf is now able to load successfully test_l4lb_noinline.o and
      samples/bpf/tracex3_kern.o.
      
      For the test_l4lb_noinline, uncomment related tests from test_libbpf.c
      and remove the associated "TODO".
      
      For tracex3_kern.o, instead of loading a program from samples/bpf/ that
      might not have been compiled at this stage, try loading a program from
      BPF selftests. Since this test case is about loading a program compiled
      without the "-target bpf" flag, change the Makefile to compile one
      program accordingly (instead of passing the flag for compiling all
      programs).
      
      Regarding test_xdp_noinline.o: in its current shape the program fails to
      load because it provides no version section, but the loader needs one.
      The test was added to make sure that libbpf could load XDP programs even
      if they do not provide a version number in a dedicated section. But
      libbpf is already capable of doing that: in our case loading fails
      because the loader does not know that this is an XDP program (it does
      not need to, since it does not attach the program). So trying to load
      test_xdp_noinline.o does not bring much here: just delete this subtest.
      
      For the record, the error message obtained with tracex3_kern.o was
      fixed by commit e3d91b0c ("tools/libbpf: handle issues with bpf ELF
      objects containing .eh_frames")
      
      I have not been abled to reproduce the "libbpf: incorrect bpf_call
      opcode" error for test_l4lb_noinline.o, even with the version of libbpf
      present at the time when test_libbpf.sh and test_libbpf_open.c were
      created.
      
      RFC -> v1:
      - Compile test_xdp without the "-target bpf" flag, and try to load it
        instead of ../../samples/bpf/tracex3_kern.o.
      - Delete test_xdp_noinline.o subtest.
      
      Cc: Jesper Dangaard Brouer <brouer@redhat.com>
      Signed-off-by: NQuentin Monnet <quentin.monnet@netronome.com>
      Acked-by: NJakub Kicinski <jakub.kicinski@netronome.com>
      Acked-by: NJesper Dangaard Brouer <brouer@redhat.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      f96afa76
  22. 20 10月, 2018 1 次提交
  23. 11 10月, 2018 1 次提交
  24. 10 10月, 2018 1 次提交
    • J
      selftests/bpf: add XDP selftests for modifying and popping VLAN headers · 97396ff0
      Jesper Dangaard Brouer 提交于
      This XDP selftest also contain a small TC-bpf component. It provoke
      the generic-XDP bug fixed in previous commit.
      
      The selftest itself shows how to do VLAN manipulation from XDP and TC.
      The test demonstrate how XDP ingress can remove a VLAN tag, and how TC
      egress can add back a VLAN tag.
      
      This use-case originates from a production need by ISP (kviknet.dk),
      who gets DSL-lines terminated as VLAN Q-in-Q tagged packets, and want
      to avoid having an net_device for every end-customer on the box doing
      the L2 to L3 termination.
        The test-setup is done via a veth-pair and creating two network
      namespaces (ns1 and ns2).  The 'ns1' simulate the ISP network that are
      loading the BPF-progs stripping and adding VLAN IDs.  The 'ns2'
      simulate the DSL-customer that are using VLAN tagged packets.
      
      Running the script with --interactive, will simply not call the
      cleanup function.  This gives the effect of creating a testlab, that
      the users can inspect and play with.  The --verbose option will simply
      request that the shell will print input lines as they are read, this
      include comments, which in effect make the comments visible docs.
      Reported-by: NYoel Caspersen <yoel@kviknet.dk>
      Signed-off-by: NJesper Dangaard Brouer <brouer@redhat.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      97396ff0
  25. 03 10月, 2018 1 次提交
  26. 01 10月, 2018 1 次提交
    • R
      selftests/bpf: cgroup local storage-based network counters · 371e4fcc
      Roman Gushchin 提交于
      This commit adds a bpf kselftest, which demonstrates how percpu
      and shared cgroup local storage can be used for efficient lookup-free
      network accounting.
      
      Cgroup local storage provides generic memory area with a very efficient
      lookup free access. To avoid expensive atomic operations for each
      packet, per-cpu cgroup local storage is used. Each packet is initially
      charged to a per-cpu counter, and only if the counter reaches certain
      value (32 in this case), the charge is moved into the global atomic
      counter. This allows to amortize atomic operations, keeping reasonable
      accuracy.
      
      The test also implements a naive network traffic throttling, mostly to
      demonstrate the possibility of bpf cgroup--based network bandwidth
      control.
      
      Expected output:
        ./test_netcnt
        test_netcnt:PASS
      Signed-off-by: NRoman Gushchin <guro@fb.com>
      Acked-by: NSong Liu <songliubraving@fb.com>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      371e4fcc
  27. 28 9月, 2018 1 次提交
  28. 15 9月, 2018 2 次提交
  29. 13 8月, 2018 1 次提交
    • A
      selftests/bpf: Selftest for bpf_skb_ancestor_cgroup_id · 5ecd8c22
      Andrey Ignatov 提交于
      Add selftests for bpf_skb_ancestor_cgroup_id helper.
      
      test_skb_cgroup_id.sh prepares testing interface and adds tc qdisc and
      filter for it using BPF object compiled from test_skb_cgroup_id_kern.c
      program.
      
      BPF program in test_skb_cgroup_id_kern.c gets ancestor cgroup id using
      the new helper at different levels of cgroup hierarchy that skb belongs
      to, including root level and non-existing level, and saves it to the map
      where the key is the level of corresponding cgroup and the value is its
      id.
      
      To trigger BPF program, user space program test_skb_cgroup_id_user is
      run. It adds itself into testing cgroup and sends UDP datagram to
      link-local multicast address of testing interface. Then it reads cgroup
      ids saved in kernel for different levels from the BPF map and compares
      them with those in user space. They must be equal for every level of
      ancestry.
      
      Example of run:
        # ./test_skb_cgroup_id.sh
        Wait for testing link-local IP to become available ... OK
        Note: 8 bytes struct bpf_elf_map fixup performed due to size mismatch!
        [PASS]
      Signed-off-by: NAndrey Ignatov <rdna@fb.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      5ecd8c22
  30. 11 8月, 2018 1 次提交
  31. 03 8月, 2018 1 次提交
    • R
      selftests/bpf: add a cgroup storage test · 68cfa3ac
      Roman Gushchin 提交于
      Implement a test to cover the cgroup storage functionality.
      The test implements a bpf program which drops every second packet
      by using the cgroup storage as a persistent storage.
      
      The test also use the userspace API to check the data
      in the cgroup storage, alter it, and check that the loaded
      and attached bpf program sees the update.
      
      Expected output:
        $ ./test_cgroup_storage
        test_cgroup_storage:PASS
      Signed-off-by: NRoman Gushchin <guro@fb.com>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Daniel Borkmann <daniel@iogearbox.net>
      Acked-by: NMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      68cfa3ac
  32. 31 7月, 2018 1 次提交
    • A
      selftests/bpf: Test for get_socket_cookie · 194db0d9
      Andrey Ignatov 提交于
      Add test to use get_socket_cookie() from BPF programs of types
      BPF_PROG_TYPE_SOCK_OPS and BPF_PROG_TYPE_CGROUP_SOCK_ADDR.
      
      The test attaches two programs to cgroup, runs TCP server and client in
      the cgroup and checks that two operations are done properly on client
      socket when user calls connect(2):
      
      1. In BPF_CGROUP_INET6_CONNECT socket cookie is used as the key to write
         new value in a map for client socket.
      
      2. In BPF_CGROUP_SOCK_OPS (BPF_SOCK_OPS_TCP_CONNECT_CB callback) the
         value written in "1." is found by socket cookie, since it's the same
         socket, and updated.
      
      Finally the test verifies the value in the map.
      Signed-off-by: NAndrey Ignatov <rdna@fb.com>
      Acked-by: NYonghong Song <yhs@fb.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      194db0d9