lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Wed, 27 May 2020 23:02:02 -0700
From:   Andrii Nakryiko <andrii.nakryiko@...il.com>
To:     Jakub Sitnicki <jakub@...udflare.com>
Cc:     bpf <bpf@...r.kernel.org>, Networking <netdev@...r.kernel.org>,
        kernel-team@...udflare.com
Subject: Re: [PATCH bpf-next 7/8] bpftool: Support link show for
 netns-attached links

On Wed, May 27, 2020 at 12:16 PM Jakub Sitnicki <jakub@...udflare.com> wrote:
>
> Make `bpf link show` aware of new link type, that is links attached to
> netns. When listing netns-attached links, display netns inode number as its
> identifier and link attach type.
>
> Signed-off-by: Jakub Sitnicki <jakub@...udflare.com>
> ---
>  tools/bpf/bpftool/link.c | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
>
> diff --git a/tools/bpf/bpftool/link.c b/tools/bpf/bpftool/link.c
> index 670a561dc31b..83a17d62c4c3 100644
> --- a/tools/bpf/bpftool/link.c
> +++ b/tools/bpf/bpftool/link.c
> @@ -17,6 +17,7 @@ static const char * const link_type_name[] = {
>         [BPF_LINK_TYPE_TRACING]                 = "tracing",
>         [BPF_LINK_TYPE_CGROUP]                  = "cgroup",
>         [BPF_LINK_TYPE_ITER]                    = "iter",
> +       [BPF_LINK_TYPE_NETNS]                   = "netns",
>  };
>
>  static int link_parse_fd(int *argc, char ***argv)
> @@ -122,6 +123,16 @@ static int show_link_close_json(int fd, struct bpf_link_info *info)
>                         jsonw_uint_field(json_wtr, "attach_type",
>                                          info->cgroup.attach_type);
>                 break;
> +       case BPF_LINK_TYPE_NETNS:
> +               jsonw_uint_field(json_wtr, "netns_ino",
> +                                info->netns.netns_ino);
> +               if (info->netns.attach_type < ARRAY_SIZE(attach_type_name))
> +                       jsonw_string_field(json_wtr, "attach_type",
> +                               attach_type_name[info->netns.attach_type]);
> +               else
> +                       jsonw_uint_field(json_wtr, "attach_type",
> +                                        info->netns.attach_type);
> +               break;

Can you please extract this attach_type handling into a helper func,
it's annoying to read so many repetitive if/elses. Same for plain-text
variant below. Thanks!

>         default:
>                 break;
>         }
> @@ -190,6 +201,14 @@ static int show_link_close_plain(int fd, struct bpf_link_info *info)
>                 else
>                         printf("attach_type %u  ", info->cgroup.attach_type);
>                 break;
> +       case BPF_LINK_TYPE_NETNS:
> +               printf("\n\tnetns_ino %u  ", info->netns.netns_ino);
> +               if (info->netns.attach_type < ARRAY_SIZE(attach_type_name))
> +                       printf("attach_type %s  ",
> +                              attach_type_name[info->netns.attach_type]);
> +               else
> +                       printf("attach_type %u  ", info->netns.attach_type);
> +               break;
>         default:
>                 break;
>         }
> --
> 2.25.4
>

Powered by blists - more mailing lists