@@ -76,6 +76,11 @@ static const char * const attach_type_strings[] = {
76
76
[NET_ATTACH_TYPE_XDP_OFFLOAD ] = "xdpoffload" ,
77
77
};
78
78
79
+ static const char * const attach_loc_strings [] = {
80
+ [BPF_TCX_INGRESS ] = "tcx/ingress" ,
81
+ [BPF_TCX_EGRESS ] = "tcx/egress" ,
82
+ };
83
+
79
84
const size_t net_attach_type_size = ARRAY_SIZE (attach_type_strings );
80
85
81
86
static enum net_attach_type parse_attach_type (const char * str )
@@ -422,8 +427,80 @@ static int dump_filter_nlmsg(void *cookie, void *msg, struct nlattr **tb)
422
427
filter_info -> devname , filter_info -> ifindex );
423
428
}
424
429
425
- static int show_dev_tc_bpf (int sock , unsigned int nl_pid ,
426
- struct ip_devname_ifindex * dev )
430
+ static const char * flags_strings (__u32 flags )
431
+ {
432
+ return json_output ? "none" : "" ;
433
+ }
434
+
435
+ static int __show_dev_tc_bpf_name (__u32 id , char * name , size_t len )
436
+ {
437
+ struct bpf_prog_info info = {};
438
+ __u32 ilen = sizeof (info );
439
+ int fd , ret ;
440
+
441
+ fd = bpf_prog_get_fd_by_id (id );
442
+ if (fd < 0 )
443
+ return fd ;
444
+ ret = bpf_obj_get_info_by_fd (fd , & info , & ilen );
445
+ if (ret < 0 )
446
+ goto out ;
447
+ ret = - ENOENT ;
448
+ if (info .name [0 ]) {
449
+ get_prog_full_name (& info , fd , name , len );
450
+ ret = 0 ;
451
+ }
452
+ out :
453
+ close (fd );
454
+ return ret ;
455
+ }
456
+
457
+ static void __show_dev_tc_bpf (const struct ip_devname_ifindex * dev ,
458
+ const enum bpf_attach_type loc )
459
+ {
460
+ __u32 prog_flags [64 ] = {}, link_flags [64 ] = {}, i ;
461
+ __u32 prog_ids [64 ] = {}, link_ids [64 ] = {};
462
+ LIBBPF_OPTS (bpf_prog_query_opts , optq );
463
+ char prog_name [MAX_PROG_FULL_NAME ];
464
+ int ret ;
465
+
466
+ optq .prog_ids = prog_ids ;
467
+ optq .prog_attach_flags = prog_flags ;
468
+ optq .link_ids = link_ids ;
469
+ optq .link_attach_flags = link_flags ;
470
+ optq .count = ARRAY_SIZE (prog_ids );
471
+
472
+ ret = bpf_prog_query_opts (dev -> ifindex , loc , & optq );
473
+ if (ret )
474
+ return ;
475
+ for (i = 0 ; i < optq .count ; i ++ ) {
476
+ NET_START_OBJECT ;
477
+ NET_DUMP_STR ("devname" , "%s" , dev -> devname );
478
+ NET_DUMP_UINT ("ifindex" , "(%u)" , dev -> ifindex );
479
+ NET_DUMP_STR ("kind" , " %s" , attach_loc_strings [loc ]);
480
+ ret = __show_dev_tc_bpf_name (prog_ids [i ], prog_name ,
481
+ sizeof (prog_name ));
482
+ if (!ret )
483
+ NET_DUMP_STR ("name" , " %s" , prog_name );
484
+ NET_DUMP_UINT ("prog_id" , " prog id %u" , prog_ids [i ]);
485
+ if (prog_flags [i ])
486
+ NET_DUMP_STR ("prog_flags" , "%s" , flags_strings (prog_flags [i ]));
487
+ if (link_ids [i ])
488
+ NET_DUMP_UINT ("link_id" , " link id %u" ,
489
+ link_ids [i ]);
490
+ if (link_flags [i ])
491
+ NET_DUMP_STR ("link_flags" , "%s" , flags_strings (link_flags [i ]));
492
+ NET_END_OBJECT_FINAL ;
493
+ }
494
+ }
495
+
496
+ static void show_dev_tc_bpf (struct ip_devname_ifindex * dev )
497
+ {
498
+ __show_dev_tc_bpf (dev , BPF_TCX_INGRESS );
499
+ __show_dev_tc_bpf (dev , BPF_TCX_EGRESS );
500
+ }
501
+
502
+ static int show_dev_tc_bpf_classic (int sock , unsigned int nl_pid ,
503
+ struct ip_devname_ifindex * dev )
427
504
{
428
505
struct bpf_filter_t filter_info ;
429
506
struct bpf_tcinfo_t tcinfo ;
@@ -790,8 +867,9 @@ static int do_show(int argc, char **argv)
790
867
if (!ret ) {
791
868
NET_START_ARRAY ("tc" , "%s:\n" );
792
869
for (i = 0 ; i < dev_array .used_len ; i ++ ) {
793
- ret = show_dev_tc_bpf (sock , nl_pid ,
794
- & dev_array .devices [i ]);
870
+ show_dev_tc_bpf (& dev_array .devices [i ]);
871
+ ret = show_dev_tc_bpf_classic (sock , nl_pid ,
872
+ & dev_array .devices [i ]);
795
873
if (ret )
796
874
break ;
797
875
}
@@ -839,7 +917,8 @@ static int do_help(int argc, char **argv)
839
917
" ATTACH_TYPE := { xdp | xdpgeneric | xdpdrv | xdpoffload }\n"
840
918
" " HELP_SPEC_OPTIONS " }\n"
841
919
"\n"
842
- "Note: Only xdp and tc attachments are supported now.\n"
920
+ "Note: Only xdp, tcx, tc, flow_dissector and netfilter attachments\n"
921
+ " are currently supported.\n"
843
922
" For progs attached to cgroups, use \"bpftool cgroup\"\n"
844
923
" to dump program attachments. For program types\n"
845
924
" sk_{filter,skb,msg,reuseport} and lwt/seg6, please\n"
0 commit comments