13 #include <netlink/cli/utils.h> 14 #include <netlink/cli/link.h> 15 #include <netlink/cli/qdisc.h> 16 #include <netlink/cli/class.h> 18 #include <linux/netlink.h> 19 #include <linux/pkt_sched.h> 21 static struct nl_sock *sock;
22 static struct nl_cache *qdisc_cache, *class_cache;
28 static void print_qdisc(
struct nl_object *,
void *);
29 static void print_tc_childs(
struct rtnl_tc *,
void *);
31 static void print_usage(
void)
34 "Usage: nl-tctree-list [OPTION]...\n" 37 " -f, --format=TYPE Output format { brief | details | stats }\n" 38 " -h, --help Show this help\n" 39 " -v, --version Show versioning information\n" 44 static void print_class(
struct nl_object *obj,
void *arg)
46 struct rtnl_qdisc *leaf;
47 struct rtnl_class *
class = (struct rtnl_class *) obj;
48 struct nl_cache *cls_cache;
56 print_qdisc((
struct nl_object *) leaf, (
char *) arg + 2);
58 print_tc_childs(
TC_CAST(
class), (
char *) arg + 2);
68 static void print_tc_childs(
struct rtnl_tc *tc,
void *arg)
70 struct rtnl_class *filter;
72 filter = nl_cli_class_alloc();
79 rtnl_class_put(filter);
82 static void print_qdisc(
struct nl_object *obj,
void *arg)
84 struct rtnl_qdisc *qdisc = (
struct rtnl_qdisc *) obj;
85 struct nl_cache *cls_cache;
91 print_tc_childs(
TC_CAST(qdisc), (
char *) arg + 2);
101 static void print_link(
struct nl_object *obj,
void *arg)
104 struct rtnl_qdisc *qdisc;
115 print_qdisc((
struct nl_object *) qdisc, (
void *) 2);
116 rtnl_qdisc_put(qdisc);
121 print_qdisc((
struct nl_object *) qdisc, (
void *) 2);
122 rtnl_qdisc_put(qdisc);
127 print_qdisc((
struct nl_object *) qdisc, (
void *) 2);
128 rtnl_qdisc_put(qdisc);
134 int main(
int argc,
char *argv[])
136 struct nl_cache *link_cache;
138 sock = nl_cli_alloc_socket();
139 nl_cli_connect(sock, NETLINK_ROUTE);
140 link_cache = nl_cli_link_alloc_cache(sock);
141 qdisc_cache = nl_cli_qdisc_alloc_cache(sock);
143 params.
dp_fd = stdout;
147 static struct option long_opts[] = {
148 {
"format", 1, 0,
'f' },
149 {
"help", 0, 0,
'h' },
150 {
"version", 0, 0,
'v' },
154 c = getopt_long(argc, argv,
"f:hv", long_opts, &optidx);
159 case 'f': params.
dp_type = nl_cli_parse_dumptype(optarg);
break;
160 case 'h': print_usage();
break;
161 case 'v': nl_cli_print_version();
break;
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.
struct rtnl_qdisc * rtnl_qdisc_get_by_parent(struct nl_cache *cache, int ifindex, uint32_t parent)
Search qdisc by interface index and parent.
FILE * dp_fd
File descriptor the dumping output should go to.
enum nl_dump_type dp_type
Specifies the type of dump that is requested.
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.
void rtnl_tc_set_parent(struct rtnl_tc *tc, uint32_t parent)
Set the parent identifier of a traffic control object.
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).
Dump all attributes but no statistics.
void nl_cache_free(struct nl_cache *cache)
Free a cache.
uint32_t rtnl_tc_get_handle(struct rtnl_tc *tc)
Return identifier of a traffic control object.
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 rtnl_tc_set_ifindex(struct rtnl_tc *tc, int ifindex)
Set interface index of traffic control object.
#define TC_CAST(ptr)
Macro to cast qdisc/class/classifier to tc object.
void nl_object_dump(struct nl_object *obj, struct nl_dump_params *params)
Dump this object according to the specified parameters.
void nl_cache_dump(struct nl_cache *cache, struct nl_dump_params *params)
Dump all elements of a cache.
int dp_prefix
Specifies the number of whitespaces to be put in front of every new line (indentation).
int rtnl_link_get_ifindex(struct rtnl_link *link)
Return interface index of link object.
int rtnl_tc_get_ifindex(struct rtnl_tc *tc)
Return interface index of traffic control object.