aboutsummaryrefslogtreecommitdiff
path: root/tc/tc_qdisc.c
diff options
context:
space:
mode:
Diffstat (limited to 'tc/tc_qdisc.c')
-rw-r--r--tc/tc_qdisc.c127
1 files changed, 80 insertions, 47 deletions
diff --git a/tc/tc_qdisc.c b/tc/tc_qdisc.c
index cb861e08..493538c2 100644
--- a/tc/tc_qdisc.c
+++ b/tc/tc_qdisc.c
@@ -34,7 +34,7 @@ static int usage(void)
fprintf(stderr, " [ stab [ help | STAB_OPTIONS] ]\n");
fprintf(stderr, " [ [ QDISC_KIND ] [ help | OPTIONS ] ]\n");
fprintf(stderr, "\n");
- fprintf(stderr, " tc qdisc show [ dev STRING ] [ ingress | clsact ]\n");
+ fprintf(stderr, " tc qdisc show [ dev STRING ] [ ingress | clsact ] [ invisible ]\n");
fprintf(stderr, "Where:\n");
fprintf(stderr, "QDISC_KIND := { [p|b]fifo | tbf | prio | cbq | red | etc. }\n");
fprintf(stderr, "OPTIONS := ... try tc qdisc add <desired QDISC_KIND> help\n");
@@ -42,32 +42,26 @@ static int usage(void)
return -1;
}
-static int tc_qdisc_modify(int cmd, unsigned flags, int argc, char **argv)
+static int tc_qdisc_modify(int cmd, unsigned int flags, int argc, char **argv)
{
struct qdisc_util *q = NULL;
- struct tc_estimator est;
+ struct tc_estimator est = {};
struct {
struct tc_sizespec szopts;
__u16 *data;
- } stab;
- char d[16];
- char k[16];
+ } stab = {};
+ char d[16] = {};
+ char k[16] = {};
struct {
- struct nlmsghdr n;
- struct tcmsg t;
- char buf[TCA_BUF_MAX];
- } req;
-
- memset(&req, 0, sizeof(req));
- memset(&stab, 0, sizeof(stab));
- memset(&est, 0, sizeof(est));
- memset(&d, 0, sizeof(d));
- memset(&k, 0, sizeof(k));
-
- req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcmsg));
- req.n.nlmsg_flags = NLM_F_REQUEST|flags;
- req.n.nlmsg_type = cmd;
- req.t.tcm_family = AF_UNSPEC;
+ struct nlmsghdr n;
+ struct tcmsg t;
+ char buf[TCA_BUF_MAX];
+ } req = {
+ .n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcmsg)),
+ .n.nlmsg_flags = NLM_F_REQUEST | flags,
+ .n.nlmsg_type = cmd,
+ .t.tcm_family = AF_UNSPEC,
+ };
while (argc > 0) {
if (strcmp(*argv, "dev") == 0) {
@@ -77,6 +71,7 @@ static int tc_qdisc_modify(int cmd, unsigned flags, int argc, char **argv)
strncpy(d, *argv, sizeof(d)-1);
} else if (strcmp(*argv, "handle") == 0) {
__u32 handle;
+
if (req.t.tcm_handle)
duparg("handle", *argv);
NEXT_ARG();
@@ -113,6 +108,7 @@ static int tc_qdisc_modify(int cmd, unsigned flags, int argc, char **argv)
break;
} else if (strcmp(*argv, "parent") == 0) {
__u32 handle;
+
NEXT_ARG();
if (req.t.tcm_parent)
duparg("parent", *argv);
@@ -186,7 +182,8 @@ static int tc_qdisc_modify(int cmd, unsigned flags, int argc, char **argv)
ll_init_map(&rth);
- if ((idx = ll_name_to_index(d)) == 0) {
+ idx = ll_name_to_index(d);
+ if (idx == 0) {
fprintf(stderr, "Cannot find device \"%s\"\n", d);
return 1;
}
@@ -202,13 +199,12 @@ static int tc_qdisc_modify(int cmd, unsigned flags, int argc, char **argv)
static int filter_ifindex;
int print_qdisc(const struct sockaddr_nl *who,
- struct nlmsghdr *n,
- void *arg)
+ struct nlmsghdr *n, void *arg)
{
- FILE *fp = (FILE*)arg;
+ FILE *fp = (FILE *)arg;
struct tcmsg *t = NLMSG_DATA(n);
int len = n->nlmsg_len;
- struct rtattr * tb[TCA_MAX+1];
+ struct rtattr *tb[TCA_MAX+1];
struct qdisc_util *q;
char abuf[256];
@@ -225,7 +221,6 @@ int print_qdisc(const struct sockaddr_nl *who,
if (filter_ifindex && filter_ifindex != t->tcm_ifindex)
return 0;
- memset(tb, 0, sizeof(tb));
parse_rtattr(tb, TCA_MAX, TCA_RTA(t), len);
if (tb[TCA_KIND] == NULL) {
@@ -236,21 +231,39 @@ int print_qdisc(const struct sockaddr_nl *who,
if (n->nlmsg_type == RTM_DELQDISC)
fprintf(fp, "deleted ");
- fprintf(fp, "qdisc %s %x: ", rta_getattr_str(tb[TCA_KIND]), t->tcm_handle>>16);
+ if (n->nlmsg_type == RTM_NEWQDISC &&
+ (n->nlmsg_flags & NLM_F_CREATE) &&
+ (n->nlmsg_flags & NLM_F_REPLACE))
+ fprintf(fp, "replaced ");
+
+ if (n->nlmsg_type == RTM_NEWQDISC &&
+ (n->nlmsg_flags & NLM_F_CREATE) &&
+ (n->nlmsg_flags & NLM_F_EXCL))
+ fprintf(fp, "added ");
+
+ if (show_raw)
+ fprintf(fp, "qdisc %s %x:[%08x] ",
+ rta_getattr_str(tb[TCA_KIND]),
+ t->tcm_handle >> 16, t->tcm_handle);
+ else
+ fprintf(fp, "qdisc %s %x: ", rta_getattr_str(tb[TCA_KIND]),
+ t->tcm_handle >> 16);
+
if (filter_ifindex == 0)
fprintf(fp, "dev %s ", ll_index_to_name(t->tcm_ifindex));
+
if (t->tcm_parent == TC_H_ROOT)
fprintf(fp, "root ");
else if (t->tcm_parent) {
print_tc_classid(abuf, sizeof(abuf), t->tcm_parent);
fprintf(fp, "parent %s ", abuf);
}
- if (t->tcm_info != 1) {
+
+ if (t->tcm_info != 1)
fprintf(fp, "refcnt %d ", t->tcm_info);
- }
- /* pfifo_fast is generic enough to warrant the hardcoding --JHS */
- if (0 == strcmp("pfifo_fast", RTA_DATA(tb[TCA_KIND])))
+ /* pfifo_fast is generic enough to warrant the hardcoding --JHS */
+ if (strcmp("pfifo_fast", RTA_DATA(tb[TCA_KIND])) == 0)
q = get_qdisc_kind("prio");
else
q = get_qdisc_kind(RTA_DATA(tb[TCA_KIND]));
@@ -262,10 +275,12 @@ int print_qdisc(const struct sockaddr_nl *who,
fprintf(fp, "[cannot parse qdisc parameters]");
}
fprintf(fp, "\n");
+
if (show_details && tb[TCA_STAB]) {
print_size_table(fp, " ", tb[TCA_STAB]);
fprintf(fp, "\n");
}
+
if (show_stats) {
struct rtattr *xstats = NULL;
@@ -285,26 +300,25 @@ int print_qdisc(const struct sockaddr_nl *who,
static int tc_qdisc_list(int argc, char **argv)
{
- struct tcmsg t;
- char d[16];
-
- memset(&t, 0, sizeof(t));
- t.tcm_family = AF_UNSPEC;
- memset(&d, 0, sizeof(d));
+ struct tcmsg t = { .tcm_family = AF_UNSPEC };
+ char d[16] = {};
+ bool dump_invisible = false;
while (argc > 0) {
if (strcmp(*argv, "dev") == 0) {
NEXT_ARG();
strncpy(d, *argv, sizeof(d)-1);
- } else if (strcmp(*argv, "ingress") == 0 ||
+ } else if (strcmp(*argv, "ingress") == 0 ||
strcmp(*argv, "clsact") == 0) {
- if (t.tcm_parent) {
- fprintf(stderr, "Duplicate parent ID\n");
- usage();
- }
- t.tcm_parent = TC_H_INGRESS;
+ if (t.tcm_parent) {
+ fprintf(stderr, "Duplicate parent ID\n");
+ usage();
+ }
+ t.tcm_parent = TC_H_INGRESS;
} else if (matches(*argv, "help") == 0) {
usage();
+ } else if (strcmp(*argv, "invisible") == 0) {
+ dump_invisible = true;
} else {
fprintf(stderr, "What is \"%s\"? Try \"tc qdisc help\".\n", *argv);
return -1;
@@ -316,14 +330,33 @@ static int tc_qdisc_list(int argc, char **argv)
ll_init_map(&rth);
if (d[0]) {
- if ((t.tcm_ifindex = ll_name_to_index(d)) == 0) {
+ t.tcm_ifindex = ll_name_to_index(d);
+ if (t.tcm_ifindex == 0) {
fprintf(stderr, "Cannot find device \"%s\"\n", d);
return 1;
}
filter_ifindex = t.tcm_ifindex;
}
- if (rtnl_dump_request(&rth, RTM_GETQDISC, &t, sizeof(t)) < 0) {
+ if (dump_invisible) {
+ struct {
+ struct nlmsghdr n;
+ struct tcmsg t;
+ char buf[256];
+ } req = {
+ .n.nlmsg_type = RTM_GETQDISC,
+ .n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcmsg)),
+ };
+
+ req.t.tcm_family = AF_UNSPEC;
+
+ addattr(&req.n, 256, TCA_DUMP_INVISIBLE);
+ if (rtnl_dump_request_n(&rth, &req.n) < 0) {
+ perror("Cannot send dump request");
+ return 1;
+ }
+
+ } else if (rtnl_dump_request(&rth, RTM_GETQDISC, &t, sizeof(t)) < 0) {
perror("Cannot send dump request");
return 1;
}
@@ -360,7 +393,7 @@ int do_qdisc(int argc, char **argv)
if (matches(*argv, "help") == 0) {
usage();
return 0;
- }
+ }
fprintf(stderr, "Command \"%s\" is unknown, try \"tc qdisc help\".\n", *argv);
return -1;
}