13 #include <netlink/cli/utils.h> 14 #include <netlink/cli/tc.h> 15 #include <netlink/cli/qdisc.h> 16 #include <netlink/cli/class.h> 17 #include <netlink/cli/cls.h> 18 #include <netlink/cli/link.h> 20 #include <linux/pkt_sched.h> 21 #include <linux/netlink.h> 25 static struct nl_sock *sock;
26 static int recursive = 0;
31 static void print_usage(
void)
34 "Usage: nl-qdisc-list [OPTION]... [QDISC]\n" 37 " --details Show details\n" 38 " --stats Show statistics\n" 39 " -r, --recursive Show recursive tree\n" 40 " -h, --help Show this help\n" 41 " -v, --version Show versioning information\n" 43 " -d, --dev=DEV Device the qdisc is attached to. (default: all)\n" 44 " -p, --parent=ID Identifier of parent qdisc.\n" 45 " -i, --id=ID Identifier.\n" 46 " -k, --kind=NAME Kind of qdisc (e.g. pfifo_fast)\n" 49 " # Display statistics of all qdiscs attached to eth0\n" 50 " $ nl-qdisc-list --details --dev=eth0\n" 56 static void list_classes(
int ifindex, uint32_t parent);
57 static void list_qdiscs(
int ifindex, uint32_t parent);
59 static void list_class(
struct nl_object *obj,
void *arg)
61 struct rtnl_tc *tc = nl_object_priv(obj);
68 static void list_classes(
int ifindex, uint32_t parent)
70 struct nl_cache *class_cache;
71 struct rtnl_class *filter = nl_cli_class_alloc();
73 class_cache = nl_cli_class_alloc_cache(sock, ifindex);
80 rtnl_class_put(filter);
84 static void list_cls(
int ifindex, uint32_t parent)
86 struct nl_cache *cls_cache;
88 cls_cache = nl_cli_cls_alloc_cache(sock, ifindex, parent);
97 static void list_qdisc(
struct nl_object *obj,
void *arg)
99 struct rtnl_qdisc *qdisc = nl_object_priv(obj);
100 struct rtnl_tc *tc = (
struct rtnl_tc *) qdisc;
114 static void list_qdiscs(
int ifindex, uint32_t parent)
116 struct nl_cache *qdisc_cache;
117 struct rtnl_qdisc *filter = nl_cli_qdisc_alloc();
119 qdisc_cache = nl_cli_qdisc_alloc_cache(sock);
127 rtnl_qdisc_put(filter);
131 int main(
int argc,
char *argv[])
133 struct rtnl_qdisc *qdisc;
135 struct nl_cache *link_cache, *qdisc_cache;
137 params.
dp_fd = stdout;
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);
142 qdisc = nl_cli_qdisc_alloc();
143 tc = (
struct rtnl_tc *) qdisc;
151 static struct option long_opts[] = {
152 {
"details", 0, 0, ARG_DETAILS },
153 {
"stats", 0, 0, ARG_STATS },
154 {
"recursive", 0, 0,
'r' },
155 {
"help", 0, 0,
'h' },
156 {
"version", 0, 0,
'v' },
157 {
"dev", 1, 0,
'd' },
158 {
"parent", 1, 0,
'p' },
160 {
"kind", 1, 0,
'k' },
164 c = getopt_long(argc, argv,
"rhvd:p:i:k:", long_opts, &optidx);
171 case 'r': recursive = 1;
break;
172 case 'h': print_usage();
break;
173 case 'v': nl_cli_print_version();
break;
174 case 'd': nl_cli_tc_parse_dev(tc, link_cache, optarg);
break;
175 case 'p': nl_cli_tc_parse_parent(tc, optarg);
break;
176 case 'i': nl_cli_tc_parse_handle(tc, optarg, 0);
break;
177 case 'k': nl_cli_tc_parse_kind(tc, optarg);
break;
Dump object briefly on one line.
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.
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 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 rtnl_tc_set_ifindex(struct rtnl_tc *tc, int ifindex)
Set interface index of traffic control object.
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 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_tc_get_ifindex(struct rtnl_tc *tc)
Return interface index of traffic control object.
Dump all attributes including statistics.