8#include <linux/netlink.h>
10#include <netlink/cli/utils.h>
11#include <netlink/cli/tc.h>
12#include <netlink/cli/cls.h>
13#include <netlink/cli/link.h>
15static struct nl_sock *sock;
21static void print_usage(
void)
24"Usage: nl-cls-list [OPTION]...\n"
27" --details Show details\n"
28" --stats Show statistics\n"
29" -h, --help Show this help\n"
30" -v, --version Show versioning information\n"
32" -d, --dev=DEV Device the classifier is attached to. (default: all)\n"
33" -p, --parent=ID Identifier of parent class.\n"
34" -i, --id=ID Identifier.\n"
35" -k, --kind=NAME Kind of classifier (e.g. basic, u32, fw)\n"
36" --proto=PROTO Protocol to match (default: all)\n"
37" --prio=PRIO Priority (default: 0)\n"
40" # Display statistics of all classes on eth0\n"
41" $ nl-cls-list --stats --dev=eth0\n"
47static void __dump_link(
int ifindex,
struct rtnl_cls *filter)
49 struct nl_cache *cache;
52 cache = nl_cli_cls_alloc_cache(sock, ifindex, parent);
57static void dump_link(
struct nl_object *obj,
void *arg)
59 struct rtnl_link *link = nl_object_priv(obj);
64int main(
int argc,
char *argv[])
68 struct nl_cache *link_cache;
71 sock = nl_cli_alloc_socket();
72 nl_cli_connect(sock, NETLINK_ROUTE);
73 link_cache = nl_cli_link_alloc_cache(sock);
74 cls = nl_cli_cls_alloc();
77 params.
dp_fd = stdout;
87 static struct option long_opts[] = {
88 {
"details", 0, 0, ARG_DETAILS },
89 {
"stats", 0, 0, ARG_STATS },
90 {
"help", 0, 0,
'h' },
91 {
"version", 0, 0,
'v' },
93 {
"parent", 1, 0,
'p' },
95 {
"kind", 1, 0,
'k' },
96 {
"proto", 1, 0, ARG_PROTO },
97 {
"prio", 1, 0, ARG_PRIO },
101 c = getopt_long(argc, argv,
"hvd:p:i:k:", long_opts, &optidx);
108 case 'h': print_usage();
break;
109 case 'v': nl_cli_print_version();
break;
110 case 'd': nl_cli_tc_parse_dev(tc, link_cache, optarg);
break;
111 case 'p': nl_cli_tc_parse_parent(tc, optarg);
break;
112 case 'i': nl_cli_tc_parse_handle(tc, optarg, 0);
break;
113 case 'k': nl_cli_tc_parse_kind(tc, optarg);
break;
114 case ARG_PROTO: nl_cli_cls_parse_proto(cls, optarg);
break;
122 __dump_link(ifindex, cls);
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.
void nl_cache_free(struct nl_cache *cache)
Free a cache.
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).
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.
uint32_t rtnl_tc_get_parent(struct rtnl_tc *tc)
Return parent identifier of a traffic control object.
int rtnl_tc_get_ifindex(struct rtnl_tc *tc)
Return interface index of traffic control object.
@ NL_DUMP_STATS
Dump all attributes including statistics.
@ NL_DUMP_LINE
Dump object briefly on one line.
@ NL_DUMP_DETAILS
Dump all attributes but no statistics.
enum nl_dump_type dp_type
Specifies the type of dump that is requested.
FILE * dp_fd
File descriptor the dumping output should go to.