12 #include <netlink/cli/utils.h>
13 #include <netlink/cli/tc.h>
14 #include <netlink/cli/qdisc.h>
15 #include <netlink/cli/class.h>
16 #include <netlink/cli/cls.h>
17 #include <netlink/cli/link.h>
21 static struct nl_sock *sock;
22 static int recursive = 0;
27 static void print_usage(
void)
30 "Usage: nl-qdisc-list [OPTION]... [QDISC]\n"
33 " --details Show details\n"
34 " --stats Show statistics\n"
35 " -r, --recursive Show recursive tree\n"
36 " -h, --help Show this help\n"
37 " -v, --version Show versioning information\n"
39 " -d, --dev=DEV Device the qdisc is attached to. (default: all)\n"
40 " -p, --parent=ID Identifier of parent qdisc.\n"
41 " -i, --id=ID Identifier.\n"
42 " -k, --kind=NAME Kind of qdisc (e.g. pfifo_fast)\n"
45 " # Display statistics of all qdiscs attached to eth0\n"
46 " $ nl-qdisc-list --details --dev=eth0\n"
52 static void list_classes(
int ifindex, uint32_t parent);
53 static void list_qdiscs(
int ifindex, uint32_t parent);
55 static void list_class(
struct nl_object *obj,
void *arg)
57 struct rtnl_tc *tc = nl_object_priv(obj);
64 static void list_classes(
int ifindex, uint32_t parent)
66 struct nl_cache *class_cache;
67 struct rtnl_class *filter = nl_cli_class_alloc();
69 class_cache = nl_cli_class_alloc_cache(sock, ifindex);
76 rtnl_class_put(filter);
80 static void list_cls(
int ifindex, uint32_t parent)
82 struct nl_cache *cls_cache;
84 cls_cache = nl_cli_cls_alloc_cache(sock, ifindex, parent);
93 static void list_qdisc(
struct nl_object *obj,
void *arg)
95 struct rtnl_qdisc *qdisc = nl_object_priv(obj);
96 struct rtnl_tc *tc = (
struct rtnl_tc *) qdisc;
110 static void list_qdiscs(
int ifindex, uint32_t parent)
112 struct nl_cache *qdisc_cache;
113 struct rtnl_qdisc *filter = nl_cli_qdisc_alloc();
115 qdisc_cache = nl_cli_qdisc_alloc_cache(sock);
123 rtnl_qdisc_put(filter);
127 int main(
int argc,
char *argv[])
129 struct rtnl_qdisc *qdisc;
131 struct nl_cache *link_cache, *qdisc_cache;
133 params.
dp_fd = stdout;
134 sock = nl_cli_alloc_socket();
135 nl_cli_connect(sock, NETLINK_ROUTE);
136 link_cache = nl_cli_link_alloc_cache(sock);
137 qdisc_cache = nl_cli_qdisc_alloc_cache(sock);
138 qdisc = nl_cli_qdisc_alloc();
139 tc = (
struct rtnl_tc *) qdisc;
147 static struct option long_opts[] = {
148 {
"details", 0, 0, ARG_DETAILS },
149 {
"stats", 0, 0, ARG_STATS },
150 {
"recursive", 0, 0,
'r' },
151 {
"help", 0, 0,
'h' },
152 {
"version", 0, 0,
'v' },
153 {
"dev", 1, 0,
'd' },
154 {
"parent", 1, 0,
'p' },
156 {
"kind", 1, 0,
'k' },
160 c = getopt_long(argc, argv,
"rhvd:p:i:k:", long_opts, &optidx);
167 case 'r': recursive = 1;
break;
168 case 'h': print_usage();
break;
169 case 'v': nl_cli_print_version();
break;
170 case 'd': nl_cli_tc_parse_dev(tc, link_cache, optarg);
break;
171 case 'p': nl_cli_tc_parse_parent(tc, optarg);
break;
172 case 'i': nl_cli_tc_parse_handle(tc, optarg, 0);
break;
173 case 'k': nl_cli_tc_parse_kind(tc, optarg);
break;