Re: [PATCH bpf-next v4 09/12] bpftool: Use libbpf_bpf_attach_type_str

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

 



2022-05-23 23:04 UTC+0000 ~ Daniel Müller <deso@xxxxxxxxxx>
> This change switches bpftool over to using the recently introduced
> libbpf_bpf_attach_type_str function instead of maintaining its own
> string representation for the bpf_attach_type enum.
> 
> Note that contrary to other enum types, the variant names that bpftool
> maps bpf_attach_type to do not adhere a simple to follow rule. With
> bpf_prog_type, for example, the textual representation can easily be
> inferred by stripping the BPF_PROG_TYPE_ prefix and lowercasing the
> remaining string. bpf_attach_type violates this rule for various
> variants.
> We decided to fix up this deficiency with this change, meaning that
> bpftool uses the same textual representations as libbpf. Supporting
> tests, completion scripts, and man pages have been adjusted accordingly.
> However, we did add support for accepting (the now undocumented)
> original attach type names when they are provided by users.
> 
> For the test (test_bpftool_synctypes.py), I have removed the enum
> representation checks, because we no longer mirror the various enum
> variant names in bpftool source code. For the man page, help text, and
> completion script checks we are now using enum definitions from
> uapi/linux/bpf.h as the source of truth directly.
> 
> Signed-off-by: Daniel Müller <deso@xxxxxxxxxx>

Looks all good to me this time, thanks again! And thank you for
splitting the changes on the test script, it's also easier to follow.

Acked-by: Quentin Monnet <quentin@xxxxxxxxxxxxx>

> diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c
> index 39e1e71..6e08a30 100644
> --- a/tools/bpf/bpftool/prog.c
> +++ b/tools/bpf/bpftool/prog.c
> @@ -41,12 +41,24 @@ enum dump_mode {
>  	DUMP_XLATED,
>  };
>  
> +static const bool attach_types[] = {
> +	[BPF_SK_SKB_STREAM_PARSER] = true,
> +	[BPF_SK_SKB_STREAM_VERDICT] = true,
> +	[BPF_SK_SKB_VERDICT] = true,
> +	[BPF_SK_MSG_VERDICT] = true,
> +	[BPF_FLOW_DISSECTOR] = true,
> +	[__MAX_BPF_ATTACH_TYPE] = false,
> +};
> +
> +/*
> + * Textual representations traditionally used by the program and kept around for
> + * the sake of backwards compatibility.
> + */

Nit: Opening marker for comments should be on the same line as the text,
but this is not worth a respin.



[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