13 #include <netlink/cli/utils.h> 14 #include <netlink/cli/tc.h> 15 #include <netlink/cli/cls.h> 16 #include <netlink/cli/link.h> 18 #include <linux/netlink.h> 20 static struct nl_sock *sock;
26 static void print_usage(
void)
29 "Usage: nl-cls-list [OPTION]...\n" 32 " --details Show details\n" 33 " --stats Show statistics\n" 34 " -h, --help Show this help\n" 35 " -v, --version Show versioning information\n" 37 " -d, --dev=DEV Device the classifier is attached to. (default: all)\n" 38 " -p, --parent=ID Identifier of parent class.\n" 39 " -i, --id=ID Identifier.\n" 40 " -k, --kind=NAME Kind of classifier (e.g. basic, u32, fw)\n" 41 " --proto=PROTO Protocol to match (default: all)\n" 42 " --prio=PRIO Priority (default: 0)\n" 45 " # Display statistics of all classes on eth0\n" 46 " $ nl-cls-list --stats --dev=eth0\n" 52 static void __dump_link(
int ifindex,
struct rtnl_cls *filter)
54 struct nl_cache *cache;
57 cache = nl_cli_cls_alloc_cache(sock, ifindex, parent);
62 static void dump_link(
struct nl_object *obj,
void *arg)
64 struct rtnl_link *link = nl_object_priv(obj);
69 int main(
int argc,
char *argv[])
73 struct nl_cache *link_cache;
76 sock = nl_cli_alloc_socket();
77 nl_cli_connect(sock, NETLINK_ROUTE);
78 link_cache = nl_cli_link_alloc_cache(sock);
79 cls = nl_cli_cls_alloc();
80 tc = (
struct rtnl_tc *) cls;
82 params.
dp_fd = stdout;
92 static struct option long_opts[] = {
93 {
"details", 0, 0, ARG_DETAILS },
94 {
"stats", 0, 0, ARG_STATS },
95 {
"help", 0, 0,
'h' },
96 {
"version", 0, 0,
'v' },
98 {
"parent", 1, 0,
'p' },
100 {
"kind", 1, 0,
'k' },
101 {
"proto", 1, 0, ARG_PROTO },
102 {
"prio", 1, 0, ARG_PRIO },
106 c = getopt_long(argc, argv,
"hvd:p:i:k:", long_opts, &optidx);
113 case 'h': print_usage();
break;
114 case 'v': nl_cli_print_version();
break;
115 case 'd': nl_cli_tc_parse_dev(tc, link_cache, optarg);
break;
116 case 'p': nl_cli_tc_parse_parent(tc, optarg);
break;
117 case 'i': nl_cli_tc_parse_handle(tc, optarg, 0);
break;
118 case 'k': nl_cli_tc_parse_kind(tc, optarg);
break;
119 case ARG_PROTO: nl_cli_cls_parse_proto(cls, optarg);
break;
127 __dump_link(ifindex, cls);
Dump object briefly on one line.
FILE * dp_fd
File descriptor the dumping output should go to.
enum nl_dump_type dp_type
Specifies the type of dump that is requested.
void nl_cache_dump_filter(struct nl_cache *cache, struct nl_dump_params *params, struct nl_object *filter)
Dump all elements of a cache (filtered).
Dump all attributes but no statistics.
void nl_cache_free(struct nl_cache *cache)
Free a cache.
void nl_cache_foreach(struct nl_cache *cache, void(*cb)(struct nl_object *, void *), void *arg)
Call a callback on each element of the cache.
uint32_t rtnl_tc_get_parent(struct rtnl_tc *tc)
Return parent identifier of a traffic control object.
uint32_t nl_cli_parse_u32(const char *arg)
Parse a text based 32 bit unsigned integer argument.
int rtnl_link_get_ifindex(struct rtnl_link *link)
Return interface index of link object.
int rtnl_tc_get_ifindex(struct rtnl_tc *tc)
Return interface index of traffic control object.
Dump all attributes including statistics.