diff mbox series

[bpf-next,1/1] libbpf: add an ability to delete qdisc via bpf_tc_hook_destroy from C++

Message ID 20240728202853.87641-1-sergey@lobanov.in (mailing list archive)
State Changes Requested
Delegated to: BPF
Headers show
Series [bpf-next,1/1] libbpf: add an ability to delete qdisc via bpf_tc_hook_destroy from C++ | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for bpf-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 7 this patch: 7
netdev/build_tools success Errors and warnings before: 2 this patch: 2
netdev/cc_maintainers fail 17 maintainers not CCed: kpsingh@kernel.org haoluo@google.com nathan@kernel.org john.fastabend@gmail.com song@kernel.org morbo@google.com ndesaulniers@google.com daniel@iogearbox.net llvm@lists.linux.dev andrii@kernel.org justinstitt@google.com jolsa@kernel.org ast@kernel.org yonghong.song@linux.dev martin.lau@linux.dev eddyz87@gmail.com sdf@fomichev.me
netdev/build_clang success Errors and warnings before: 7 this patch: 7
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 7 this patch: 7
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 7 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 260 this patch: 260
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-VM_Test-28 success Logs for x86_64-llvm-17 / build / build for x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-29 success Logs for x86_64-llvm-17 / build-release / build for x86_64 with llvm-17-O2
bpf/vmtest-bpf-next-VM_Test-35 success Logs for x86_64-llvm-18 / build / build for x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-36 success Logs for x86_64-llvm-18 / build-release / build for x86_64 with llvm-18-O2
bpf/vmtest-bpf-next-VM_Test-34 success Logs for x86_64-llvm-17 / veristat
bpf/vmtest-bpf-next-VM_Test-42 success Logs for x86_64-llvm-18 / veristat
bpf/vmtest-bpf-next-VM_Test-27 success Logs for x86_64-gcc / veristat / veristat on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-25 success Logs for x86_64-gcc / test (test_progs_parallel, true, 30) / test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-26 success Logs for x86_64-gcc / test (test_verifier, false, 360) / test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-31 success Logs for x86_64-llvm-17 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-30 success Logs for x86_64-llvm-17 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-32 success Logs for x86_64-llvm-17 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-37 success Logs for x86_64-llvm-18 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-38 success Logs for x86_64-llvm-18 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-33 success Logs for x86_64-llvm-17 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-39 success Logs for x86_64-llvm-18 / test (test_progs_cpuv4, false, 360) / test_progs_cpuv4 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-40 success Logs for x86_64-llvm-18 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-41 success Logs for x86_64-llvm-18 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-0 success Logs for Lint
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Unittests
bpf/vmtest-bpf-next-VM_Test-3 success Logs for Validate matrix.py
bpf/vmtest-bpf-next-VM_Test-5 success Logs for aarch64-gcc / build-release
bpf/vmtest-bpf-next-PR fail PR summary
bpf/vmtest-bpf-next-VM_Test-6 success Logs for aarch64-gcc / test
bpf/vmtest-bpf-next-VM_Test-8 fail Logs for s390x-gcc / build / build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-4 fail Logs for aarch64-gcc / build / build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-10 success Logs for s390x-gcc / test
bpf/vmtest-bpf-next-VM_Test-7 success Logs for aarch64-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-9 success Logs for s390x-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-14 success Logs for x86_64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-13 fail Logs for x86_64-gcc / build / build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-12 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-11 success Logs for s390x-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-15 success Logs for x86_64-gcc / test
bpf/vmtest-bpf-next-VM_Test-16 success Logs for x86_64-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-17 fail Logs for x86_64-llvm-17 / build / build for x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-18 fail Logs for x86_64-llvm-17 / build-release / build for x86_64 with llvm-17-O2
bpf/vmtest-bpf-next-VM_Test-20 success Logs for x86_64-llvm-17 / veristat
bpf/vmtest-bpf-next-VM_Test-19 success Logs for x86_64-llvm-17 / test
bpf/vmtest-bpf-next-VM_Test-22 fail Logs for x86_64-llvm-18 / build-release / build for x86_64 with llvm-18-O2
bpf/vmtest-bpf-next-VM_Test-21 fail Logs for x86_64-llvm-18 / build / build for x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-24 success Logs for x86_64-llvm-18 / veristat
bpf/vmtest-bpf-next-VM_Test-23 success Logs for x86_64-llvm-18 / test

Commit Message

Sergey V. Lobanov July 28, 2024, 8:28 p.m. UTC
bpf_tc_hook_destroy() deletes qdisc only if hook.attach_point is set to
BPF_TC_INGRESS | BPF_TC_EGRESS, but it is impossible to do from C++ code
because hook.attach_point is enum, but it is prohibited to set struct
enum member to non-enum value in C++.

This patch introduces new enum value BPF_TC_BOTH = BPF_TC_INGRESS | BPF_TC_EGRESS
This value allows to delete qdisc from C++ code.

An example of program compatible with C but incompatible with C++:
\#include <bpf/libbpf.h>
int main() {
    struct bpf_tc_hook hook;
    hook.attach_point = BPF_TC_INGRESS | BPF_TC_EGRESS;
}

'clang program.c' is OK, but 'clang++ program.cpp' fails:
program.cpp:4:40: error: assigning to 'enum bpf_tc_attach_point' from incompatible type 'int'
    4 |     hook.attach_point = BPF_TC_INGRESS | BPF_TC_EGRESS;
      |                         ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
1 error generated.

The same issue with g++.

Signed-off-by: Sergey V. Lobanov <sergey@lobanov.in>
---
 tools/lib/bpf/libbpf.h | 1 +
 1 file changed, 1 insertion(+)

Comments

Andrii Nakryiko July 29, 2024, 9:09 p.m. UTC | #1
On Sun, Jul 28, 2024 at 1:29 PM Sergey V. Lobanov <sergey@lobanov.in> wrote:
>
> bpf_tc_hook_destroy() deletes qdisc only if hook.attach_point is set to
> BPF_TC_INGRESS | BPF_TC_EGRESS, but it is impossible to do from C++ code
> because hook.attach_point is enum, but it is prohibited to set struct
> enum member to non-enum value in C++.
>
> This patch introduces new enum value BPF_TC_BOTH = BPF_TC_INGRESS | BPF_TC_EGRESS
> This value allows to delete qdisc from C++ code.
>
> An example of program compatible with C but incompatible with C++:
> \#include <bpf/libbpf.h>
> int main() {
>     struct bpf_tc_hook hook;
>     hook.attach_point = BPF_TC_INGRESS | BPF_TC_EGRESS;
> }
>
> 'clang program.c' is OK, but 'clang++ program.cpp' fails:
> program.cpp:4:40: error: assigning to 'enum bpf_tc_attach_point' from incompatible type 'int'
>     4 |     hook.attach_point = BPF_TC_INGRESS | BPF_TC_EGRESS;
>       |                         ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
> 1 error generated.
>
> The same issue with g++.
>
> Signed-off-by: Sergey V. Lobanov <sergey@lobanov.in>
> ---
>  tools/lib/bpf/libbpf.h | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
> index 64a6a3d32..494f99152 100644
> --- a/tools/lib/bpf/libbpf.h
> +++ b/tools/lib/bpf/libbpf.h
> @@ -1257,6 +1257,7 @@ LIBBPF_API int bpf_xdp_query_id(int ifindex, int flags, __u32 *prog_id);
>  enum bpf_tc_attach_point {
>         BPF_TC_INGRESS = 1 << 0,
>         BPF_TC_EGRESS  = 1 << 1,
> +       BPF_TC_BOTH    = BPF_TC_INGRESS | BPF_TC_EGRESS,

BOTH implies there could be only INGRESS or EGRESS, right? But what
about TC_CUSTOM? I'll leave it up to Daniel to comment, but something
like BPF_TC_INGRESS_OR_EGRESS would be way more mouthful, but more
correct, IMO?

And as for C++'s woes with enum, you can always cast, no? Ugly, but works.

>         BPF_TC_CUSTOM  = 1 << 2,
>  };
>
> --
> 2.34.1
>
>
diff mbox series

Patch

diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index 64a6a3d32..494f99152 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -1257,6 +1257,7 @@  LIBBPF_API int bpf_xdp_query_id(int ifindex, int flags, __u32 *prog_id);
 enum bpf_tc_attach_point {
 	BPF_TC_INGRESS = 1 << 0,
 	BPF_TC_EGRESS  = 1 << 1,
+	BPF_TC_BOTH    = BPF_TC_INGRESS | BPF_TC_EGRESS,
 	BPF_TC_CUSTOM  = 1 << 2,
 };