Re: [PATCH bpf-next v6 7/7] selftests/bpf: Add tests for XDP bonding

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Aug 5, 2021 at 9:10 AM Jussi Maki <joamaki@xxxxxxxxx> wrote:
>
> Add a test suite to test XDP bonding implementation
> over a pair of veth devices.
>
> Signed-off-by: Jussi Maki <joamaki@xxxxxxxxx>
> ---
>  .../selftests/bpf/prog_tests/xdp_bonding.c    | 520 ++++++++++++++++++
>  1 file changed, 520 insertions(+)
>

I don't pretend to understand what's going on in this selftests, but
it looks good from the generic selftest standpoint. One and half small
issues below, please double-check (and probably fix the fd close
issue).

Acked-by: Andrii Nakryiko <andrii@xxxxxxxxxx>


[...]

> +
> +/* Test the broadcast redirection using xdp_redirect_map_multi_prog and adding
> + * all the interfaces to it and checking that broadcasting won't send the packet
> + * to neither the ingress bond device (bond2) or its slave (veth2_1).
> + */
> +static void test_xdp_bonding_redirect_multi(struct skeletons *skeletons)
> +{
> +       static const char * const ifaces[] = {"bond2", "veth2_1", "veth2_2"};
> +       int veth1_1_rx, veth1_2_rx;
> +       int err;
> +
> +       if (bonding_setup(skeletons, BOND_MODE_ROUNDROBIN, BOND_XMIT_POLICY_LAYER23,
> +                         BOND_ONE_NO_ATTACH))
> +               goto out;
> +
> +
> +       if (!ASSERT_OK(setns_by_name("ns_dst"), "could not set netns to ns_dst"))
> +               goto out;
> +
> +       /* populate the devmap with the relevant interfaces */
> +       for (int i = 0; i < ARRAY_SIZE(ifaces); i++) {
> +               int ifindex = if_nametoindex(ifaces[i]);
> +               int map_fd = bpf_map__fd(skeletons->xdp_redirect_multi_kern->maps.map_all);
> +
> +               if (!ASSERT_GT(ifindex, 0, "could not get interface index"))
> +                       goto out;
> +
> +               err = bpf_map_update_elem(map_fd, &ifindex, &ifindex, 0);
> +               if (!ASSERT_OK(err, "add interface to map_all"))
> +                       goto out;
> +       }
> +
> +       if (xdp_attach(skeletons,
> +                      skeletons->xdp_redirect_multi_kern->progs.xdp_redirect_map_multi_prog,
> +                      "bond2"))
> +               goto out;
> +
> +       restore_root_netns();

the "goto out" below might call restore_root_netns() again, is that ok?

> +
> +       if (send_udp_packets(BOND_MODE_ROUNDROBIN))
> +               goto out;
> +
> +       veth1_1_rx = get_rx_packets("veth1_1");
> +       veth1_2_rx = get_rx_packets("veth1_2");
> +
> +       ASSERT_EQ(veth1_1_rx, 0, "expected no packets on veth1_1");
> +       ASSERT_GE(veth1_2_rx, NPACKETS, "expected packets on veth1_2");
> +
> +out:
> +       restore_root_netns();
> +       bonding_cleanup(skeletons);
> +}
> +

[...]

> +
> +void test_xdp_bonding(void)
> +{
> +       libbpf_print_fn_t old_print_fn;
> +       struct skeletons skeletons = {};
> +       int i;
> +
> +       old_print_fn = libbpf_set_print(libbpf_debug_print);
> +
> +       root_netns_fd = open("/proc/self/ns/net", O_RDONLY);
> +       if (!ASSERT_GE(root_netns_fd, 0, "open /proc/self/ns/net"))
> +               goto out;
> +
> +       skeletons.xdp_dummy = xdp_dummy__open_and_load();
> +       if (!ASSERT_OK_PTR(skeletons.xdp_dummy, "xdp_dummy__open_and_load"))
> +               goto out;
> +
> +       skeletons.xdp_tx = xdp_tx__open_and_load();
> +       if (!ASSERT_OK_PTR(skeletons.xdp_tx, "xdp_tx__open_and_load"))
> +               goto out;
> +
> +       skeletons.xdp_redirect_multi_kern = xdp_redirect_multi_kern__open_and_load();
> +       if (!ASSERT_OK_PTR(skeletons.xdp_redirect_multi_kern,
> +                          "xdp_redirect_multi_kern__open_and_load"))
> +               goto out;
> +
> +       if (!test__start_subtest("xdp_bonding_attach"))
> +               test_xdp_bonding_attach(&skeletons);
> +
> +       for (i = 0; i < ARRAY_SIZE(bond_test_cases); i++) {
> +               struct bond_test_case *test_case = &bond_test_cases[i];
> +
> +               if (!test__start_subtest(test_case->name))
> +                       test_xdp_bonding_with_mode(
> +                               &skeletons,
> +                               test_case->mode,
> +                               test_case->xmit_policy);
> +       }
> +
> +       if (!test__start_subtest("xdp_bonding_redirect_multi"))
> +               test_xdp_bonding_redirect_multi(&skeletons);
> +
> +out:
> +       xdp_dummy__destroy(skeletons.xdp_dummy);
> +       xdp_tx__destroy(skeletons.xdp_tx);
> +       xdp_redirect_multi_kern__destroy(skeletons.xdp_redirect_multi_kern);
> +
> +       libbpf_set_print(old_print_fn);
> +       if (root_netns_fd)

technically, fd could be 0, so for fds we have if (fd >= 0)
everywhere. Also, if open() above fails, root_netns_fd will be -1 and
you'll still attempt to close it.

> +               close(root_netns_fd);
> +}
> --
> 2.17.1
>



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux