History

bpftool: print program device bound info

If program is bound to a device, print the name of the relevant interface or unknown if the netdev has since been removed.

Jakub Kicinski committed 9 years ago

Commit 928631e1 parent bd601b62 files · +38 −0Browse files

Unified · Split

2 files
  1. tools/bpf/bpftool/prog.c +31 −0
  2. tools/include/uapi/linux/bpf.h +7 −0
tools/bpf/bpftool/prog.c+31−0
@@ -41,6 +41,7 @@ · 40 unmodified lines
41#include <string.h>41#include <string.h>
42#include <time.h>42#include <time.h>
43#include <unistd.h>43#include <unistd.h>
44#include <net/if.h>
44#include <sys/types.h>45#include <sys/types.h>
45#include <sys/stat.h>46#include <sys/stat.h>
46 47
@@ -229,6 +230,21 @@ static void print_prog_json(struct bpf_prog_info *info, int fd) · 182 unmodified lines
229 info->tag[0], info->tag[1], info->tag[2], info->tag[3],230 info->tag[0], info->tag[1], info->tag[2], info->tag[3],
230 info->tag[4], info->tag[5], info->tag[6], info->tag[7]);231 info->tag[4], info->tag[5], info->tag[6], info->tag[7]);
231 232
233 if (info->status & BPF_PROG_STATUS_DEV_BOUND) {
234 jsonw_name(json_wtr, "dev");
235 if (info->ifindex) {
236 char name[IF_NAMESIZE];
237
238 if (!if_indextoname(info->ifindex, name))
239 jsonw_printf(json_wtr, "\"ifindex:%d\"",
240 info->ifindex);
241 else
242 jsonw_printf(json_wtr, "\"%s\"", name);
243 } else {
244 jsonw_printf(json_wtr, "\"unknown\"");
245 }
246 }
247
232 if (info->load_time) {248 if (info->load_time) {
233 char buf[32];249 char buf[32];
234 250
@@ -274,6 +290,21 @@ static void print_prog_plain(struct bpf_prog_info *info, int fd) · 39 unmodified lines
274 290
275 printf("tag ");291 printf("tag ");
276 fprint_hex(stdout, info->tag, BPF_TAG_SIZE, "");292 fprint_hex(stdout, info->tag, BPF_TAG_SIZE, "");
293 printf(" ");
294
295 if (info->status & BPF_PROG_STATUS_DEV_BOUND) {
296 printf("dev ");
297 if (info->ifindex) {
298 char name[IF_NAMESIZE];
299
300 if (!if_indextoname(info->ifindex, name))
301 printf("ifindex:%d ", info->ifindex);
302 else
303 printf("%s ", name);
304 } else {
305 printf("unknown ");
306 }
307 }
277 printf("\n");308 printf("\n");
278 309
279 if (info->load_time) {310 if (info->load_time) {
tools/include/uapi/linux/bpf.h+7−0
@@ -259,6 +259,7 @@ union bpf_attr { · 258 unmodified lines
259 __u32 kern_version; /* checked when prog_type=kprobe */259 __u32 kern_version; /* checked when prog_type=kprobe */
260 __u32 prog_flags;260 __u32 prog_flags;
261 char prog_name[BPF_OBJ_NAME_LEN];261 char prog_name[BPF_OBJ_NAME_LEN];
262 __u32 prog_target_ifindex; /* ifindex of netdev to prep for */
262 };263 };
263 264
264 struct { /* anonymous struct used by BPF_OBJ_* commands */265 struct { /* anonymous struct used by BPF_OBJ_* commands */
@@ -893,6 +894,10 @@ enum sk_action { · 628 unmodified lines
893 894
894#define BPF_TAG_SIZE 8895#define BPF_TAG_SIZE 8
895 896
897enum bpf_prog_status {
898 BPF_PROG_STATUS_DEV_BOUND = (1 << 0),
899};
900
896struct bpf_prog_info {901struct bpf_prog_info {
897 __u32 type;902 __u32 type;
898 __u32 id;903 __u32 id;
@@ -906,6 +911,8 @@ struct bpf_prog_info { · 7 unmodified lines
906 __u32 nr_map_ids;911 __u32 nr_map_ids;
907 __aligned_u64 map_ids;912 __aligned_u64 map_ids;
908 char name[BPF_OBJ_NAME_LEN];913 char name[BPF_OBJ_NAME_LEN];
914 __u32 ifindex;
915 __u32 status;
909} __attribute__((aligned(8)));916} __attribute__((aligned(8)));
910 917
911struct bpf_map_info {918struct bpf_map_info {