Skip to content
Snippets Groups Projects
  1. Sep 29, 2020
  2. Aug 13, 2020
  3. Jul 02, 2020
    • Martin KaFai Lau's avatar
      bpf: selftests: Restore netns after each test · 811d7e37
      Martin KaFai Lau authored
      
      It is common for networking tests creating its netns and making its own
      setting under this new netns (e.g. changing tcp sysctl).  If the test
      forgot to restore to the original netns, it would affect the
      result of other tests.
      
      This patch saves the original netns at the beginning and then restores it
      after every test.  Since the restore "setns()" is not expensive, it does it
      on all tests without tracking if a test has created a new netns or not.
      
      The new restore_netns() could also be done in test__end_subtest() such
      that each subtest will get an automatic netns reset.  However,
      the individual test would lose flexibility to have total control
      on netns for its own subtests.  In some cases, forcing a test to do
      unnecessary netns re-configure for each subtest is time consuming.
      e.g. In my vm, forcing netns re-configure on each subtest in sk_assign.c
      increased the runtime from 1s to 8s.  On top of that,  test_progs.c
      is also doing per-test (instead of per-subtest) cleanup for cgroup.
      Thus, this patch also does per-test restore_netns().  The only existing
      per-subtest cleanup is reset_affinity() and no test is depending on this.
      Thus, it is removed from test__end_subtest() to give a consistent
      expectation to the individual tests.  test_progs.c only ensures
      any affinity/netns/cgroup change made by an earlier test does not
      affect the following tests.
      
      Signed-off-by: default avatarMartin KaFai Lau <kafai@fb.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: default avatarAndrii Nakryiko <andriin@fb.com>
      Link: https://lore.kernel.org/bpf/20200702004858.2103728-1-kafai@fb.com
      811d7e37
  4. Jul 01, 2020
  5. May 13, 2020
  6. May 08, 2020
  7. Apr 26, 2020
    • Lorenz Bauer's avatar
      selftests/bpf: Add cls_redirect classifier · 23458901
      Lorenz Bauer authored
      cls_redirect is a TC clsact based replacement for the glb-redirect iptables
      module available at [1]. It enables what GitHub calls "second chance"
      flows [2], similarly proposed by the Beamer paper [3]. In contrast to
      glb-redirect, it also supports migrating UDP flows as long as connected
      sockets are used. cls_redirect is in production at Cloudflare, as part of
      our own L4 load balancer.
      
      We have modified the encapsulation format slightly from glb-redirect:
      glbgue_chained_routing.private_data_type has been repurposed to form a
      version field and several flags. Both have been arranged in a way that
      a private_data_type value of zero matches the current glb-redirect
      behaviour. This means that cls_redirect will understand packets in
      glb-redirect format, but not vice versa.
      
      The test suite only covers basic features. For example, cls_redirect will
      correctly forward path MTU discovery packets, but this is not exercised.
      It is also possible to switch the encapsulation format to GRE on the last
      hop, which is also not tested.
      
      There are two major distinctions from glb-redirect: first, cls_redirect
      relies on receiving encapsulated packets directly from a router. This is
      because we don't have access to the neighbour tables from BPF, yet. See
      forward_to_next_hop for details. Second, cls_redirect performs decapsulation
      instead of using separate ipip and sit tunnel devices. This
      avoids issues with the sit tunnel [4] and makes deploying the classifier
      easier: decapsulated packets appear on the same interface, so existing
      firewall rules continue to work as expected.
      
      The code base started it's life on v4.19, so there are most likely still
      hold overs from old workarounds. In no particular order:
      
      - The function buf_off is required to defeat a clang optimization
        that leads to the verifier rejecting the program due to pointer
        arithmetic in the wrong order.
      
      - The function pkt_parse_ipv6 is force inlined, because it would
        otherwise be rejected due to returning a pointer to stack memory.
      
      - The functions fill_tuple and classify_tcp contain kludges, because
        we've run out of function arguments.
      
      - The logic in general is rather nested, due to verifier restrictions.
        I think this is either because the verifier loses track of constants
        on the stack, or because it can't track enum like variables.
      
      1: https://github.com/github/glb-director/tree/master/src/glb-redirect
      2: https://github.com/github/glb-director/blob/master/docs/development/second-chance-design.md
      3: https://www.usenix.org/conference/nsdi18/presentation/olteanu
      4: https://github.com/github/glb-director/issues/64
      
      
      
      Signed-off-by: default avatarLorenz Bauer <lmb@cloudflare.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Link: https://lore.kernel.org/bpf/20200424185556.7358-2-lmb@cloudflare.com
      23458901
  8. Mar 17, 2020
  9. Mar 13, 2020
  10. Jan 21, 2020
  11. Jan 16, 2020
    • Andrii Nakryiko's avatar
      selftests/bpf: Add whitelist/blacklist of test names to test_progs · b65053cd
      Andrii Nakryiko authored
      
      Add ability to specify a list of test name substrings for selecting which
      tests to run. So now -t is accepting a comma-separated list of strings,
      similarly to how -n accepts a comma-separated list of test numbers.
      
      Additionally, add ability to blacklist tests by name. Blacklist takes
      precedence over whitelist. Blacklisting is important for cases where it's
      known that some tests can't pass (e.g., due to perf hardware events that are
      not available within VM). This is going to be used for libbpf testing in
      Travis CI in its Github repo.
      
      Example runs with just whitelist and whitelist + blacklist:
      
        $ sudo ./test_progs -tattach,core/existence
        #1 attach_probe:OK
        #6 cgroup_attach_autodetach:OK
        #7 cgroup_attach_multi:OK
        #8 cgroup_attach_override:OK
        #9 core_extern:OK
        #10/44 existence:OK
        #10/45 existence___minimal:OK
        #10/46 existence__err_int_sz:OK
        #10/47 existence__err_int_type:OK
        #10/48 existence__err_int_kind:OK
        #10/49 existence__err_arr_kind:OK
        #10/50 existence__err_arr_value_type:OK
        #10/51 existence__err_struct_type:OK
        #10 core_reloc:OK
        #19 flow_dissector_reattach:OK
        #60 tp_attach_query:OK
        Summary: 8/8 PASSED, 0 SKIPPED, 0 FAILED
      
        $ sudo ./test_progs -tattach,core/existence -bcgroup,flow/arr
        #1 attach_probe:OK
        #9 core_extern:OK
        #10/44 existence:OK
        #10/45 existence___minimal:OK
        #10/46 existence__err_int_sz:OK
        #10/47 existence__err_int_type:OK
        #10/48 existence__err_int_kind:OK
        #10/51 existence__err_struct_type:OK
        #10 core_reloc:OK
        #60 tp_attach_query:OK
        Summary: 4/6 PASSED, 0 SKIPPED, 0 FAILED
      
      Signed-off-by: default avatarAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Cc: Julia Kartseva <hex@fb.com>
      Link: https://lore.kernel.org/bpf/20200116005549.3644118-1-andriin@fb.com
      b65053cd
  12. Dec 21, 2019
  13. Nov 25, 2019
  14. Sep 06, 2019
  15. Sep 03, 2019
  16. Aug 27, 2019
  17. Aug 07, 2019
  18. Jul 28, 2019
    • Andrii Nakryiko's avatar
      selftests/bpf: add sub-tests support for test_progs · 3a516a0a
      Andrii Nakryiko authored
      
      Allow tests to have their own set of sub-tests. Also add ability to do
      test/subtest selection using `-t <test-name>/<subtest-name>` and `-n
      <test-nums-set>/<subtest-nums-set>`, as an extension of existing -t/-n
      selector options. For the <test-num-set> format: it's a comma-separated
      list of either individual test numbers (1-based), or range of test
      numbers. E.g., all of the following are valid sets of test numbers:
        - 10
        - 1,2,3
        - 1-3
        - 5-10,1,3-4
      
      '/<subtest' part is optional, but has the same format. E.g., to select
      test #3 and its sub-tests #10 through #15, use: -t 3/10-15.
      
      Similarly, to select tests by name, use `-t verif/strobe`:
      
        $ sudo ./test_progs -t verif/strobe
        #3/12 strobemeta.o:OK
        #3/13 strobemeta_nounroll1.o:OK
        #3/14 strobemeta_nounroll2.o:OK
        #3 bpf_verif_scale:OK
        Summary: 1/3 PASSED, 0 FAILED
      
      Example of using subtest API is in the next patch, converting
      bpf_verif_scale.c tests to use sub-tests.
      
      Signed-off-by: default avatarAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      3a516a0a
    • Andrii Nakryiko's avatar
      selftests/bpf: abstract away test log output · 0ff97e56
      Andrii Nakryiko authored
      
      This patch changes how test output is printed out. By default, if test
      had no errors, the only output will be a single line with test number,
      name, and verdict at the end, e.g.:
      
        #31 xdp:OK
      
      If test had any errors, all log output captured during test execution
      will be output after test completes.
      
      It's possible to force output of log with `-v` (`--verbose`) option, in
      which case output won't be buffered and will be output immediately.
      
      To support this, individual tests are required to use helper methods for
      logging: `test__printf()` and `test__vprintf()`.
      
      Signed-off-by: default avatarAndrii Nakryiko <andriin@fb.com>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      0ff97e56
  19. Jul 17, 2019
  20. Apr 03, 2019
    • Alexei Starovoitov's avatar
      selftests/bpf: add few verifier scale tests · e5e7a8f2
      Alexei Starovoitov authored
      
      Add 3 basic tests that stress verifier scalability.
      
      test_verif_scale1.c calls non-inlined jhash() function 90 times on
      different position in the packet.
      This test simulates network packet parsing.
      jhash function is ~140 instructions and main program is ~1200 insns.
      
      test_verif_scale2.c force inlines jhash() function 90 times.
      This program is ~15k instructions long.
      
      test_verif_scale3.c calls non-inlined jhash() function 90 times on
      But this time jhash has to process 32-bytes from the packet
      instead of 14-bytes in tests 1 and 2.
      jhash function is ~230 insns and main program is ~1200 insns.
      
      $ test_progs -s
      can be used to see verifier stats.
      
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      e5e7a8f2
  21. Mar 02, 2019
Loading