bpftool: Implement link show support for netkit
authorDaniel Borkmann <daniel@iogearbox.net>
Tue, 24 Oct 2023 21:49:01 +0000 (23:49 +0200)
committerMartin KaFai Lau <martin.lau@kernel.org>
Tue, 24 Oct 2023 23:07:24 +0000 (16:07 -0700)
Add support to dump netkit link information to bpftool in similar way as
we have for XDP. The netkit link info only exposes the ifindex and the
attach_type.

Below shows an example link dump output, and a cgroup link is included for
comparison, too:

  # bpftool link
  [...]
  10: cgroup  prog 2466
        cgroup_id 1  attach_type cgroup_inet6_post_bind
  [...]
  8: netkit  prog 35
        ifindex nk1(18)  attach_type netkit_primary
  [...]

Equivalent json output:

  # bpftool link --json
  [...]
  {
    "id": 10,
    "type": "cgroup",
    "prog_id": 2466,
    "cgroup_id": 1,
    "attach_type": "cgroup_inet6_post_bind"
  },
  [...]
  {
    "id": 12,
    "type": "netkit",
    "prog_id": 61,
    "devname": "nk1",
    "ifindex": 21,
    "attach_type": "netkit_primary"
  }
  [...]

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Reviewed-by: Quentin Monnet <quentin@isovalent.com>
Acked-by: Martin KaFai Lau <martin.lau@kernel.org>
Link: https://lore.kernel.org/r/20231024214904.29825-5-daniel@iogearbox.net
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
tools/bpf/bpftool/link.c

index 4b1407b0505651c9bb1d1f75d6eb8c9e9ba78a26..a1528cde81abfc9e699a15d60d1c84872a449c76 100644 (file)
@@ -451,6 +451,10 @@ static int show_link_close_json(int fd, struct bpf_link_info *info)
                show_link_ifindex_json(info->tcx.ifindex, json_wtr);
                show_link_attach_type_json(info->tcx.attach_type, json_wtr);
                break;
+       case BPF_LINK_TYPE_NETKIT:
+               show_link_ifindex_json(info->netkit.ifindex, json_wtr);
+               show_link_attach_type_json(info->netkit.attach_type, json_wtr);
+               break;
        case BPF_LINK_TYPE_XDP:
                show_link_ifindex_json(info->xdp.ifindex, json_wtr);
                break;
@@ -791,6 +795,11 @@ static int show_link_close_plain(int fd, struct bpf_link_info *info)
                show_link_ifindex_plain(info->tcx.ifindex);
                show_link_attach_type_plain(info->tcx.attach_type);
                break;
+       case BPF_LINK_TYPE_NETKIT:
+               printf("\n\t");
+               show_link_ifindex_plain(info->netkit.ifindex);
+               show_link_attach_type_plain(info->netkit.attach_type);
+               break;
        case BPF_LINK_TYPE_XDP:
                printf("\n\t");
                show_link_ifindex_plain(info->xdp.ifindex);