2
* src/nl-class-list.c List Traffic Classes
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation version 2.1
9
* Copyright (c) 2010 Thomas Graf <tgraf@suug.ch>
12
#include <netlink/cli/utils.h>
13
#include <netlink/cli/tc.h>
14
#include <netlink/cli/class.h>
15
#include <netlink/cli/link.h>
19
struct nl_dump_params params = {
20
.dp_type = NL_DUMP_LINE,
23
static void print_usage(void)
26
"Usage: nl-class-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 class 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 class (e.g. pfifo_fast)\n"
40
" # Display statistics of all classes on eth0\n"
41
" $ nl-class-list --stats --dev=eth0\n"
47
static void __dump_class(int ifindex, struct rtnl_class *filter)
49
struct nl_cache *cache;
51
cache = nl_cli_class_alloc_cache(sock, ifindex);
52
nl_cache_dump_filter(cache, ¶ms, OBJ_CAST(filter));
55
static void dump_class(struct nl_object *obj, void *arg)
57
struct rtnl_link *link = nl_object_priv(obj);
59
__dump_class(rtnl_link_get_ifindex(link), arg);
62
int main(int argc, char *argv[])
64
struct rtnl_class *class;
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
class = nl_cli_class_alloc();
73
tc = (struct rtnl_tc *) class;
75
params.dp_fd = stdout;
83
static struct option long_opts[] = {
84
{ "details", 0, 0, ARG_DETAILS },
85
{ "stats", 0, 0, ARG_STATS },
86
{ "help", 0, 0, 'h' },
87
{ "version", 0, 0, 'v' },
89
{ "parent", 1, 0, 'p' },
91
{ "kind", 1, 0, 'k' },
95
c = getopt_long(argc, argv, "hvd:p:i:k:", long_opts, &optidx);
100
case ARG_DETAILS: params.dp_type = NL_DUMP_DETAILS; break;
101
case ARG_STATS: params.dp_type = NL_DUMP_STATS; break;
102
case 'h': print_usage(); break;
103
case 'v': nl_cli_print_version(); break;
104
case 'd': nl_cli_tc_parse_dev(tc, link_cache, optarg); break;
105
case 'p': nl_cli_tc_parse_parent(tc, optarg); break;
106
case 'i': nl_cli_tc_parse_handle(tc, optarg, 0); break;
107
case 'k': nl_cli_tc_parse_kind(tc, optarg); break;
111
if ((ifindex = rtnl_tc_get_ifindex(tc)))
112
__dump_class(ifindex, class);
114
nl_cache_foreach(link_cache, dump_class, class);