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

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

 



On Sun, Jul 28, 2024 at 1:29 PM Sergey V. Lobanov <sergey@xxxxxxxxxx> 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@xxxxxxxxxx>
> ---
>  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
>
>





[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