8#include <linux/pkt_sched.h>
9#include <linux/netlink.h>
11#include <netlink/cli/utils.h>
12#include <netlink/cli/tc.h>
13#include <netlink/cli/qdisc.h>
14#include <netlink/cli/class.h>
15#include <netlink/cli/cls.h>
16#include <netlink/cli/link.h>
20static struct nl_sock *sock;
21static int recursive = 0;
26static void print_usage(
void)
29 "Usage: nl-qdisc-list [OPTION]... [QDISC]\n"
32 " --details Show details\n"
33 " --stats Show statistics\n"
34 " -r, --recursive Show recursive tree\n"
35 " -h, --help Show this help\n"
36 " -v, --version Show versioning information\n"
38 " -d, --dev=DEV Device the qdisc is attached to. (default: all)\n"
39 " -p, --parent=ID Identifier of parent qdisc.\n"
40 " -i, --id=ID Identifier.\n"
41 " -k, --kind=NAME Kind of qdisc (e.g. pfifo_fast)\n"
44 " # Display statistics of all qdiscs attached to eth0\n"
45 " $ nl-qdisc-list --details --dev=eth0\n"
51static void list_classes(
int ifindex, uint32_t parent);
52static void list_qdiscs(
int ifindex, uint32_t parent);
54static void list_class(
struct nl_object *obj,
void *arg)
56 struct rtnl_tc *tc = nl_object_priv(obj);
63static void list_classes(
int ifindex, uint32_t parent)
65 struct nl_cache *class_cache;
66 struct rtnl_class *filter = nl_cli_class_alloc();
68 class_cache = nl_cli_class_alloc_cache(sock, ifindex);
75 rtnl_class_put(filter);
79static void list_cls(
int ifindex, uint32_t parent)
81 struct nl_cache *cls_cache;
83 cls_cache = nl_cli_cls_alloc_cache(sock, ifindex, parent);
92static void list_qdisc(
struct nl_object *obj,
void *arg)
94 struct rtnl_qdisc *qdisc = nl_object_priv(obj);
109static void list_qdiscs(
int ifindex, uint32_t parent)
111 struct nl_cache *qdisc_cache;
112 struct rtnl_qdisc *filter = nl_cli_qdisc_alloc();
114 qdisc_cache = nl_cli_qdisc_alloc_cache(sock);
122 rtnl_qdisc_put(filter);
126int main(
int argc,
char *argv[])
130 struct nl_cache *link_cache, *qdisc_cache;
132 params.
dp_fd = stdout;
133 sock = nl_cli_alloc_socket();
134 nl_cli_connect(sock, NETLINK_ROUTE);
135 link_cache = nl_cli_link_alloc_cache(sock);
136 qdisc_cache = nl_cli_qdisc_alloc_cache(sock);
137 qdisc = nl_cli_qdisc_alloc();
146 static struct option long_opts[] = {
147 {
"details", 0, 0, ARG_DETAILS },
148 {
"stats", 0, 0, ARG_STATS },
149 {
"recursive", 0, 0,
'r' },
150 {
"help", 0, 0,
'h' },
151 {
"version", 0, 0,
'v' },
152 {
"dev", 1, 0,
'd' },
153 {
"parent", 1, 0,
'p' },
155 {
"kind", 1, 0,
'k' },
159 c = getopt_long(argc, argv,
"rhvd:p:i:k:", long_opts, &optidx);
166 case 'r': recursive = 1;
break;
167 case 'h': print_usage();
break;
168 case 'v': nl_cli_print_version();
break;
169 case 'd': nl_cli_tc_parse_dev(tc, link_cache, optarg);
break;
170 case 'p': nl_cli_tc_parse_parent(tc, optarg);
break;
171 case 'i': nl_cli_tc_parse_handle(tc, optarg, 0);
break;
172 case 'k': nl_cli_tc_parse_kind(tc, optarg);
break;
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).
void nl_cache_foreach_filter(struct nl_cache *cache, struct nl_object *filter, void(*cb)(struct nl_object *, void *), void *arg)
Call a callback on each element of the cache (filtered).
void nl_cache_dump(struct nl_cache *cache, struct nl_dump_params *params)
Dump all elements of a cache.
void nl_object_dump(struct nl_object *obj, struct nl_dump_params *params)
Dump this object according to the specified parameters.
uint32_t rtnl_tc_get_parent(struct rtnl_tc *tc)
Return parent identifier of a traffic control object.
void rtnl_tc_set_ifindex(struct rtnl_tc *tc, int ifindex)
Set interface index of traffic control object.
int rtnl_tc_get_ifindex(struct rtnl_tc *tc)
Return interface index of traffic control object.
uint32_t rtnl_tc_get_handle(struct rtnl_tc *tc)
Return identifier of a traffic control object.
void rtnl_tc_set_parent(struct rtnl_tc *tc, uint32_t parent)
Set the parent identifier of a 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.
int dp_prefix
Specifies the number of whitespaces to be put in front of every new line (indentation).
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.