]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
bpftool: Refactor xdp attach/detach type judgment
authorTao Chen <chen.dylane@gmail.com>
Sun, 21 Jul 2024 14:33:50 +0000 (22:33 +0800)
committerAndrii Nakryiko <andrii@kernel.org>
Mon, 29 Jul 2024 19:53:50 +0000 (12:53 -0700)
This commit no logical changed, just increases code readability and
facilitates TCX prog expansion, which will be implemented in the next
patch.

Signed-off-by: Tao Chen <chen.dylane@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Quentin Monnet <qmo@kernel.org>
Link: https://lore.kernel.org/bpf/20240721143353.95980-2-chen.dylane@gmail.com
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
tools/bpf/bpftool/net.c

index 968714b4c3d45bfdcadcc338adceab6bb60dbb6e..1b9f4225b394ee372e34a6da1b07f0e64a61eb52 100644 (file)
@@ -684,10 +684,18 @@ static int do_attach(int argc, char **argv)
                }
        }
 
+       switch (attach_type) {
        /* attach xdp prog */
-       if (is_prefix("xdp", attach_type_strings[attach_type]))
-               err = do_attach_detach_xdp(progfd, attach_type, ifindex,
-                                          overwrite);
+       case NET_ATTACH_TYPE_XDP:
+       case NET_ATTACH_TYPE_XDP_GENERIC:
+       case NET_ATTACH_TYPE_XDP_DRIVER:
+       case NET_ATTACH_TYPE_XDP_OFFLOAD:
+               err = do_attach_detach_xdp(progfd, attach_type, ifindex, overwrite);
+               break;
+       default:
+               break;
+       }
+
        if (err) {
                p_err("interface %s attach failed: %s",
                      attach_type_strings[attach_type], strerror(-err));
@@ -721,10 +729,18 @@ static int do_detach(int argc, char **argv)
        if (ifindex < 1)
                return -EINVAL;
 
+       switch (attach_type) {
        /* detach xdp prog */
-       progfd = -1;
-       if (is_prefix("xdp", attach_type_strings[attach_type]))
+       case NET_ATTACH_TYPE_XDP:
+       case NET_ATTACH_TYPE_XDP_GENERIC:
+       case NET_ATTACH_TYPE_XDP_DRIVER:
+       case NET_ATTACH_TYPE_XDP_OFFLOAD:
+               progfd = -1;
                err = do_attach_detach_xdp(progfd, attach_type, ifindex, NULL);
+               break;
+       default:
+               break;
+       }
 
        if (err < 0) {
                p_err("interface %s detach failed: %s",