6#include <netlink/cli/utils.h>
7#include <netlink/cli/tc.h>
8#include <netlink/cli/class.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-class-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 class 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 class (e.g. pfifo_fast)\n"
36 " # Display statistics of all classes on eth0\n"
37 " $ nl-class-list --stats --dev=eth0\n"
43static void __dump_class(
int ifindex,
struct rtnl_class *filter)
45 struct nl_cache *cache;
47 cache = nl_cli_class_alloc_cache(sock, ifindex);
51static void dump_class(
struct nl_object *obj,
void *arg)
53 struct rtnl_link *link = nl_object_priv(obj);
58int main(
int argc,
char *argv[])
60 struct rtnl_class *
class;
62 struct nl_cache *link_cache;
65 sock = nl_cli_alloc_socket();
66 nl_cli_connect(sock, NETLINK_ROUTE);
67 link_cache = nl_cli_link_alloc_cache(sock);
68 class = nl_cli_class_alloc();
69 tc = (
struct rtnl_tc *)
class;
71 params.
dp_fd = stdout;
79 static struct option long_opts[] = {
80 {
"details", 0, 0, ARG_DETAILS },
81 {
"stats", 0, 0, ARG_STATS },
82 {
"help", 0, 0,
'h' },
83 {
"version", 0, 0,
'v' },
85 {
"parent", 1, 0,
'p' },
87 {
"kind", 1, 0,
'k' },
91 c = getopt_long(argc, argv,
"hvd:p:i:k:", long_opts, &optidx);
98 case 'h': print_usage();
break;
99 case 'v': nl_cli_print_version();
break;
100 case 'd': nl_cli_tc_parse_dev(tc, link_cache, optarg);
break;
101 case 'p': nl_cli_tc_parse_parent(tc, optarg);
break;
102 case 'i': nl_cli_tc_parse_handle(tc, optarg, 0);
break;
103 case 'k': nl_cli_tc_parse_kind(tc, optarg);
break;
108 __dump_class(ifindex,
class);
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_dump_filter(struct nl_cache *cache, struct nl_dump_params *params, struct nl_object *filter)
Dump all elements of a cache (filtered).
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.
@ 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.