6#include <netlink/cli/utils.h>
7#include <netlink/cli/link.h>
8#include <netlink/cli/qdisc.h>
9#include <netlink/cli/class.h>
11#include <linux/netlink.h>
12#include <linux/pkt_sched.h>
14static struct nl_sock *sock;
15static struct nl_cache *qdisc_cache, *class_cache;
21static void print_qdisc(
struct nl_object *,
void *);
22static void print_tc_childs(
struct rtnl_tc *,
void *);
24static void print_usage(
void)
27 "Usage: nl-tctree-list [OPTION]...\n"
30 " -f, --format=TYPE Output format { brief | details | stats }\n"
31 " -h, --help Show this help\n"
32 " -v, --version Show versioning information\n"
37static void print_class(
struct nl_object *obj,
void *arg)
39 struct rtnl_qdisc *leaf;
40 struct rtnl_class *
class = (struct rtnl_class *) obj;
41 struct nl_cache *cls_cache;
49 print_qdisc((
struct nl_object *) leaf, (
char *) arg + 2);
51 print_tc_childs(
TC_CAST(
class), (
char *) arg + 2);
61static void print_tc_childs(
struct rtnl_tc *tc,
void *arg)
63 struct rtnl_class *filter;
65 filter = nl_cli_class_alloc();
72 rtnl_class_put(filter);
75static void print_qdisc(
struct nl_object *obj,
void *arg)
77 struct rtnl_qdisc *qdisc = (
struct rtnl_qdisc *) obj;
78 struct nl_cache *cls_cache;
84 print_tc_childs(
TC_CAST(qdisc), (
char *) arg + 2);
94static void print_link(
struct nl_object *obj,
void *arg)
97 struct rtnl_qdisc *qdisc;
108 print_qdisc((
struct nl_object *) qdisc, (
void *) 2);
109 rtnl_qdisc_put(qdisc);
114 print_qdisc((
struct nl_object *) qdisc, (
void *) 2);
115 rtnl_qdisc_put(qdisc);
120 print_qdisc((
struct nl_object *) qdisc, (
void *) 2);
121 rtnl_qdisc_put(qdisc);
127int main(
int argc,
char *argv[])
129 struct nl_cache *link_cache;
131 sock = nl_cli_alloc_socket();
132 nl_cli_connect(sock, NETLINK_ROUTE);
133 link_cache = nl_cli_link_alloc_cache(sock);
134 qdisc_cache = nl_cli_qdisc_alloc_cache(sock);
136 params.
dp_fd = stdout;
140 static struct option long_opts[] = {
141 {
"format", 1, 0,
'f' },
142 {
"help", 0, 0,
'h' },
143 {
"version", 0, 0,
'v' },
147 c = getopt_long(argc, argv,
"f:hv", long_opts, &optidx);
152 case 'f': params.
dp_type = nl_cli_parse_dumptype(optarg);
break;
153 case 'h': print_usage();
break;
154 case 'v': nl_cli_print_version();
break;
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_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.
struct rtnl_qdisc * rtnl_class_leaf_qdisc(struct rtnl_class *class, struct nl_cache *cache)
Lookup the leaf qdisc of a traffic class.
int rtnl_class_alloc_cache(struct nl_sock *sk, int ifindex, struct nl_cache **result)
Allocate a cache and fill it with all configured traffic classes.
int rtnl_cls_alloc_cache(struct nl_sock *sk, int ifindex, uint32_t parent, struct nl_cache **result)
Allocate a cache and fill it with all configured classifiers.
int rtnl_link_get_ifindex(struct rtnl_link *link)
Return interface index of link object.
void nl_object_dump(struct nl_object *obj, struct nl_dump_params *params)
Dump this object according to the specified parameters.
struct rtnl_qdisc * rtnl_qdisc_get_by_parent(struct nl_cache *cache, int ifindex, uint32_t parent)
Search qdisc by interface index and parent.
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.
#define TC_CAST(ptr)
Macro to cast qdisc/class/classifier to tc object.
void rtnl_tc_set_parent(struct rtnl_tc *tc, uint32_t parent)
Set the parent identifier of a traffic control object.
@ 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.