6#include <netlink/cli/utils.h>
7#include <netlink/cli/tc.h>
8#include <netlink/cli/cls.h>
9#include <netlink/cli/link.h>
11#include <linux/netlink.h>
13static struct nl_sock *sock;
19static void print_usage(
void)
22"Usage: nl-cls-list [OPTION]...\n"
25" --details Show details\n"
26" --stats Show statistics\n"
27" -h, --help Show this help\n"
28" -v, --version Show versioning information\n"
30" -d, --dev=DEV Device the classifier is attached to. (default: all)\n"
31" -p, --parent=ID Identifier of parent class.\n"
32" -i, --id=ID Identifier.\n"
33" -k, --kind=NAME Kind of classifier (e.g. basic, u32, fw)\n"
34" --proto=PROTO Protocol to match (default: all)\n"
35" --prio=PRIO Priority (default: 0)\n"
38" # Display statistics of all classes on eth0\n"
39" $ nl-cls-list --stats --dev=eth0\n"
45static void __dump_link(
int ifindex,
struct rtnl_cls *filter)
47 struct nl_cache *cache;
50 cache = nl_cli_cls_alloc_cache(sock, ifindex, parent);
55static void dump_link(
struct nl_object *obj,
void *arg)
57 struct rtnl_link *link = nl_object_priv(obj);
62int main(
int argc,
char *argv[])
66 struct nl_cache *link_cache;
69 sock = nl_cli_alloc_socket();
70 nl_cli_connect(sock, NETLINK_ROUTE);
71 link_cache = nl_cli_link_alloc_cache(sock);
72 cls = nl_cli_cls_alloc();
73 tc = (
struct rtnl_tc *) cls;
75 params.
dp_fd = stdout;
85 static struct option long_opts[] = {
86 {
"details", 0, 0, ARG_DETAILS },
87 {
"stats", 0, 0, ARG_STATS },
88 {
"help", 0, 0,
'h' },
89 {
"version", 0, 0,
'v' },
91 {
"parent", 1, 0,
'p' },
93 {
"kind", 1, 0,
'k' },
94 {
"proto", 1, 0, ARG_PROTO },
95 {
"prio", 1, 0, ARG_PRIO },
99 c = getopt_long(argc, argv,
"hvd:p:i:k:", long_opts, &optidx);
106 case 'h': print_usage();
break;
107 case 'v': nl_cli_print_version();
break;
108 case 'd': nl_cli_tc_parse_dev(tc, link_cache, optarg);
break;
109 case 'p': nl_cli_tc_parse_parent(tc, optarg);
break;
110 case 'i': nl_cli_tc_parse_handle(tc, optarg, 0);
break;
111 case 'k': nl_cli_tc_parse_kind(tc, optarg);
break;
112 case ARG_PROTO: nl_cli_cls_parse_proto(cls, optarg);
break;
120 __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.