12 #include <netlink/cli/utils.h>
13 #include <netlink/cli/tc.h>
14 #include <netlink/cli/cls.h>
15 #include <netlink/cli/link.h>
17 static struct nl_sock *sock;
23 static void print_usage(
void)
26 "Usage: nl-cls-list [OPTION]...\n"
29 " --details Show details\n"
30 " --stats Show statistics\n"
31 " -h, --help Show this help\n"
32 " -v, --version Show versioning information\n"
34 " -d, --dev=DEV Device the classifier is attached to. (default: all)\n"
35 " -p, --parent=ID Identifier of parent class.\n"
36 " -i, --id=ID Identifier.\n"
37 " -k, --kind=NAME Kind of classifier (e.g. basic, u32, fw)\n"
38 " --protocol=PROTO Protocol to match (default: all)\n"
39 " --prio=PRIO Priority (default: 0)\n"
42 " # Display statistics of all classes on eth0\n"
43 " $ nl-cls-list --stats --dev=eth0\n"
49 static void __dump_link(
int ifindex,
struct rtnl_cls *filter)
51 struct nl_cache *cache;
54 cache = nl_cli_cls_alloc_cache(sock, ifindex, parent);
59 static void dump_link(
struct nl_object *obj,
void *arg)
61 struct rtnl_link *link = nl_object_priv(obj);
66 int main(
int argc,
char *argv[])
70 struct nl_cache *link_cache;
73 sock = nl_cli_alloc_socket();
74 nl_cli_connect(sock, NETLINK_ROUTE);
75 link_cache = nl_cli_link_alloc_cache(sock);
76 cls = nl_cli_cls_alloc();
77 tc = (
struct rtnl_tc *) cls;
79 params.
dp_fd = stdout;
89 static struct option long_opts[] = {
90 {
"details", 0, 0, ARG_DETAILS },
91 {
"stats", 0, 0, ARG_STATS },
92 {
"help", 0, 0,
'h' },
93 {
"version", 0, 0,
'v' },
95 {
"parent", 1, 0,
'p' },
97 {
"kind", 1, 0,
'k' },
98 {
"proto", 1, 0, ARG_PROTO },
99 {
"prio", 1, 0, ARG_PRIO },
103 c = getopt_long(argc, argv,
"hvd:p:i:k:", long_opts, &optidx);
110 case 'h': print_usage();
break;
111 case 'v': nl_cli_print_version();
break;
112 case 'd': nl_cli_tc_parse_dev(tc, link_cache, optarg);
break;
113 case 'p': nl_cli_tc_parse_parent(tc, optarg);
break;
114 case 'i': nl_cli_tc_parse_handle(tc, optarg, 0);
break;
115 case 'k': nl_cli_tc_parse_kind(tc, optarg);
break;
116 case ARG_PROTO: nl_cli_cls_parse_proto(cls, optarg);
break;
124 __dump_link(ifindex, cls);