bpftool: Implement link_query for bpf iterators
authorYonghong Song <yhs@fb.com>
Fri, 21 Aug 2020 18:44:20 +0000 (11:44 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 21 Aug 2020 21:01:39 +0000 (14:01 -0700)
commite60495eafdba24a466a6ae62da86245a958954bc
treec46a23fc3d9d58a4007e65db5f4502b0c6d10a1a
parentb76f22269028fb252727a696084c70494d80a52c
bpftool: Implement link_query for bpf iterators

The link query for bpf iterators is implemented.
Besides being shown to the user what bpf iterator
the link represents, the target_name is also used
to filter out what additional information should be
printed out, e.g., whether map_id should be shown or not.
The following is an example of bpf_iter link dump,
plain output or pretty output.

  $ bpftool link show
  11: iter  prog 59  target_name task
          pids test_progs(1749)
  34: iter  prog 173  target_name bpf_map_elem  map_id 127
          pids test_progs_1(1753)
  $ bpftool -p link show
  [{
          "id": 11,
          "type": "iter",
          "prog_id": 59,
          "target_name": "task",
          "pids": [{
                  "pid": 1749,
                  "comm": "test_progs"
              }
          ]
      },{
          "id": 34,
          "type": "iter",
          "prog_id": 173,
          "target_name": "bpf_map_elem",
          "map_id": 127,
          "pids": [{
                  "pid": 1753,
                  "comm": "test_progs_1"
              }
          ]
      }
  ]

Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/20200821184420.574430-1-yhs@fb.com
tools/bpf/bpftool/link.c