1. 26 6月, 2019 1 次提交
  2. 25 6月, 2019 1 次提交
    • T
      selftests, bpf: Add test for veth native XDP · 88091ff5
      Toshiaki Makita 提交于
      Add a test case for veth native XDP. It checks if XDP_PASS, XDP_TX and
      XDP_REDIRECT work properly.
      
        $ cd tools/testing/selftests/bpf
        $ make \
        	TEST_CUSTOM_PROGS= \
        	TEST_GEN_PROGS= \
        	TEST_GEN_PROGS_EXTENDED= \
        	TEST_PROGS_EXTENDED= \
        	TEST_PROGS="test_xdp_veth.sh" \
        	run_tests
        TAP version 13
        1..1
        # selftests: bpf: test_xdp_veth.sh
        # PING 10.1.1.33 (10.1.1.33) 56(84) bytes of data.
        # 64 bytes from 10.1.1.33: icmp_seq=1 ttl=64 time=0.073 ms
        #
        # --- 10.1.1.33 ping statistics ---
        # 1 packets transmitted, 1 received, 0% packet loss, time 0ms
        # rtt min/avg/max/mdev = 0.073/0.073/0.073/0.000 ms
        # selftests: xdp_veth [PASS]
        ok 1 selftests: bpf: test_xdp_veth.sh
      Signed-off-by: NToshiaki Makita <toshiaki.makita1@gmail.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      88091ff5
  3. 11 6月, 2019 1 次提交
    • H
      selftests/bpf : clean up feature/ when make clean · 89cceaa9
      Hechao Li 提交于
      An error "implicit declaration of function 'reallocarray'" can be thrown
      with the following steps:
      
      $ cd tools/testing/selftests/bpf
      $ make clean && make CC=<Path to GCC 4.8.5>
      $ make clean && make CC=<Path to GCC 7.x>
      
      The cause is that the feature folder generated by GCC 4.8.5 is not
      removed, leaving feature-reallocarray being 1, which causes reallocarray
      not defined when re-compliing with GCC 7.x. This diff adds feature
      folder to EXTRA_CLEAN to avoid this problem.
      
      v2: Rephrase the commit message.
      Signed-off-by: NHechao Li <hechaol@fb.com>
      Acked-by: NAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
      89cceaa9
  4. 05 6月, 2019 1 次提交
  5. 01 6月, 2019 1 次提交
    • A
      selftests/bpf: measure RTT from xdp using xdping · cd538502
      Alan Maguire 提交于
      xdping allows us to get latency estimates from XDP.  Output looks
      like this:
      
      ./xdping -I eth4 192.168.55.8
      Setting up XDP for eth4, please wait...
      XDP setup disrupts network connectivity, hit Ctrl+C to quit
      
      Normal ping RTT data
      [Ignore final RTT; it is distorted by XDP using the reply]
      PING 192.168.55.8 (192.168.55.8) from 192.168.55.7 eth4: 56(84) bytes of data.
      64 bytes from 192.168.55.8: icmp_seq=1 ttl=64 time=0.302 ms
      64 bytes from 192.168.55.8: icmp_seq=2 ttl=64 time=0.208 ms
      64 bytes from 192.168.55.8: icmp_seq=3 ttl=64 time=0.163 ms
      64 bytes from 192.168.55.8: icmp_seq=8 ttl=64 time=0.275 ms
      
      4 packets transmitted, 4 received, 0% packet loss, time 3079ms
      rtt min/avg/max/mdev = 0.163/0.237/0.302/0.054 ms
      
      XDP RTT data:
      64 bytes from 192.168.55.8: icmp_seq=5 ttl=64 time=0.02808 ms
      64 bytes from 192.168.55.8: icmp_seq=6 ttl=64 time=0.02804 ms
      64 bytes from 192.168.55.8: icmp_seq=7 ttl=64 time=0.02815 ms
      64 bytes from 192.168.55.8: icmp_seq=8 ttl=64 time=0.02805 ms
      
      The xdping program loads the associated xdping_kern.o BPF program
      and attaches it to the specified interface.  If run in client
      mode (the default), it will add a map entry keyed by the
      target IP address; this map will store RTT measurements, current
      sequence number etc.  Finally in client mode the ping command
      is executed, and the xdping BPF program will use the last ICMP
      reply, reformulate it as an ICMP request with the next sequence
      number and XDP_TX it.  After the reply to that request is received
      we can measure RTT and repeat until the desired number of
      measurements is made.  This is why the sequence numbers in the
      normal ping are 1, 2, 3 and 8.  We XDP_TX a modified version
      of ICMP reply 4 and keep doing this until we get the 4 replies
      we need; hence the networking stack only sees reply 8, where
      we have XDP_PASSed it upstream since we are done.
      
      In server mode (-s), xdping simply takes ICMP requests and replies
      to them in XDP rather than passing the request up to the networking
      stack.  No map entry is required.
      
      xdping can be run in native XDP mode (the default, or specified
      via -N) or in skb mode (-S).
      
      A test program test_xdping.sh exercises some of these options.
      
      Note that native XDP does not seem to XDP_TX for veths, hence -N
      is not tested.  Looking at the code, it looks like XDP_TX is
      supported so I'm not sure if that's expected.  Running xdping in
      native mode for ixgbe as both client and server works fine.
      
      Changes since v4
      
      - close fds on cleanup (Song Liu)
      
      Changes since v3
      
      - fixed seq to be __be16 (Song Liu)
      - fixed fd checks in xdping.c (Song Liu)
      
      Changes since v2
      
      - updated commit message to explain why seq number of last
        ICMP reply is 8 not 4 (Song Liu)
      - updated types of seq number, raddr and eliminated csum variable
        in xdpclient/xdpserver functions as it was not needed (Song Liu)
      - added XDPING_DEFAULT_COUNT definition and usage specification of
        default/max counts (Song Liu)
      
      Changes since v1
       - moved from RFC to PATCH
       - removed unused variable in ipv4_csum() (Song Liu)
       - refactored ICMP checks into icmp_check() function called by client
         and server programs and reworked client and server programs due
         to lack of shared code (Song Liu)
       - added checks to ensure that SKB and native mode are not requested
         together (Song Liu)
      Signed-off-by: NAlan Maguire <alan.maguire@oracle.com>
      Acked-by: NSong Liu <songliubraving@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      cd538502
  6. 29 5月, 2019 1 次提交
  7. 25 5月, 2019 3 次提交
    • J
      selftests: bpf: enable hi32 randomization for all tests · 9d120b41
      Jiong Wang 提交于
      The previous libbpf patch allows user to specify "prog_flags" to bpf
      program load APIs. To enable high 32-bit randomization for a test, we need
      to set BPF_F_TEST_RND_HI32 in "prog_flags".
      
      To enable such randomization for all tests, we need to make sure all places
      are passing BPF_F_TEST_RND_HI32. Changing them one by one is not
      convenient, also, it would be better if a test could be switched to
      "normal" running mode without code change.
      
      Given the program load APIs used across bpf selftests are mostly:
        bpf_prog_load:      load from file
        bpf_load_program:   load from raw insns
      
      A test_stub.c is implemented for bpf seltests, it offers two functions for
      testing purpose:
      
        bpf_prog_test_load
        bpf_test_load_program
      
      The are the same as "bpf_prog_load" and "bpf_load_program", except they
      also set BPF_F_TEST_RND_HI32. Given *_xattr functions are the APIs to
      customize any "prog_flags", it makes little sense to put these two
      functions into libbpf.
      
      Then, the following CFLAGS are passed to compilations for host programs:
        -Dbpf_prog_load=bpf_prog_test_load
        -Dbpf_load_program=bpf_test_load_program
      
      They migrate the used load APIs to the test version, hence enable high
      32-bit randomization for these tests without changing source code.
      
      Besides all these, there are several testcases are using
      "bpf_prog_load_attr" directly, their call sites are updated to pass
      BPF_F_TEST_RND_HI32.
      Signed-off-by: NJiong Wang <jiong.wang@netronome.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      9d120b41
    • A
      selftests/bpf: add btf_dump BTF-to-C conversion tests · 2d2a3ad8
      Andrii Nakryiko 提交于
      Add new test_btf_dump set of tests, validating BTF-to-C conversion
      correctness. Tests rely on clang to generate BTF from provided C test
      cases.
      Signed-off-by: NAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      2d2a3ad8
    • A
      selftests/bpf: add tests for libbpf's hashmap · 5d04ec68
      Andrii Nakryiko 提交于
      Test all APIs for internal hashmap implementation.
      Signed-off-by: NAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
      5d04ec68
  8. 28 4月, 2019 1 次提交
  9. 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
  10. 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
  11. 23 3月, 2019 2 次提交
  12. 22 3月, 2019 2 次提交
  13. 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
  14. 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
  15. 14 2月, 2019 1 次提交
  16. 12 2月, 2019 3 次提交
  17. 11 2月, 2019 1 次提交
  18. 02 2月, 2019 3 次提交
  19. 29 1月, 2019 1 次提交
  20. 28 1月, 2019 1 次提交
  21. 27 1月, 2019 1 次提交
  22. 25 1月, 2019 1 次提交
  23. 16 1月, 2019 1 次提交
  24. 10 1月, 2019 1 次提交
  25. 22 11月, 2018 1 次提交
  26. 21 11月, 2018 1 次提交
  27. 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
  28. 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
  29. 20 10月, 2018 1 次提交
  30. 11 10月, 2018 1 次提交
  31. 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