• Andrey Ignatov's avatar
    selftests/bpf: Selftest for sys_bind post-hooks. · 1d436885
    Andrey Ignatov authored
    Add selftest for attach types `BPF_CGROUP_INET4_POST_BIND` and
    `BPF_CGROUP_INET6_POST_BIND`.
    
    The main things tested are:
    * prog load behaves as expected (valid/invalid accesses in prog);
    * prog attach behaves as expected (load- vs attach-time attach types);
    * `BPF_CGROUP_INET_SOCK_CREATE` can be attached in a backward compatible
      way;
    * post-hooks return expected result and errno.
    
    Example:
      # ./test_sock
      Test case: bind4 load with invalid access: src_ip6 .. [PASS]
      Test case: bind4 load with invalid access: mark .. [PASS]
      Test case: bind6 load with invalid access: src_ip4 .. [PASS]
      Test case: sock_create load with invalid access: src_port .. [PASS]
      Test case: sock_create load w/o expected_attach_type (compat mode) ..
      [PASS]
      Test case: sock_create load w/ expected_attach_type .. [PASS]
      Test case: attach type mismatch bind4 vs bind6 .. [PASS]
      Test case: attach type mismatch bind6 vs bind4 .. [PASS]
      Test case: attach type mismatch default vs bind4 .. [PASS]
      Test case: attach type mismatch bind6 vs sock_create .. [PASS]
      Test case: bind4 reject all .. [PASS]
      Test case: bind6 reject all .. [PASS]
      Test case: bind6 deny specific IP & port .. [PASS]
      Test case: bind4 allow specific IP & port .. [PASS]
      Test case: bind4 allow all .. [PASS]
      Test case: bind6 allow all .. [PASS]
      Summary: 16 PASSED, 0 FAILED
    Signed-off-by: default avatarAndrey Ignatov <rdna@fb.com>
    Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
    1d436885
test_sock.c 9.04 KB