8#include <linux/netlink.h>
9#include <linux/pkt_sched.h>
11#include <netlink/cli/utils.h>
12#include <netlink/cli/link.h>
13#include <netlink/cli/qdisc.h>
14#include <netlink/cli/class.h>
16static struct nl_sock *sock;
17static struct nl_cache *qdisc_cache, *class_cache;
23static void print_qdisc(
struct nl_object *,
void *);
24static void print_tc_childs(
struct rtnl_tc *,
void *);
26static void print_usage(
void)
29 "Usage: nl-tctree-list [OPTION]...\n"
32 " -f, --format=TYPE Output format { brief | details | stats }\n"
33 " -h, --help Show this help\n"
34 " -v, --version Show versioning information\n"
39static void print_class(
struct nl_object *obj,
void *arg)
43 struct nl_cache *cls_cache;
51 print_qdisc((
struct nl_object *) leaf, (
char *) arg + 2);
53 print_tc_childs(
TC_CAST(
class), (
char *) arg + 2);
63static void print_tc_childs(
struct rtnl_tc *tc,
void *arg)
67 filter = nl_cli_class_alloc();
74 rtnl_class_put(filter);
77static void print_qdisc(
struct nl_object *obj,
void *arg)
80 struct nl_cache *cls_cache;
86 print_tc_childs(
TC_CAST(qdisc), (
char *) arg + 2);
96static void print_link(
struct nl_object *obj,
void *arg)
110 print_qdisc((
struct nl_object *) qdisc, (
void *) 2);
111 rtnl_qdisc_put(qdisc);
116 print_qdisc((
struct nl_object *) qdisc, (
void *) 2);
117 rtnl_qdisc_put(qdisc);
122 print_qdisc((
struct nl_object *) qdisc, (
void *) 2);
123 rtnl_qdisc_put(qdisc);
129int main(
int argc,
char *argv[])
131 struct nl_cache *link_cache;
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);
138 params.
dp_fd = stdout;
142 static struct option long_opts[] = {
143 {
"format", 1, 0,
'f' },
144 {
"help", 0, 0,
'h' },
145 {
"version", 0, 0,
'v' },
149 c = getopt_long(argc, argv,
"f:hv", long_opts, &optidx);
154 case 'f': params.
dp_type = nl_cli_parse_dumptype(optarg);
break;
155 case 'h': print_usage();
break;
156 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.