]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - tc/tc_class.c
tc: Remove pointless assignments in batch()
[mirror_iproute2.git] / tc / tc_class.c
index 0214775b95a6ca83b0a2ce4255d3af7ccef2203e..6b4ea48073f2966198a793ca0b65331e5d3e2451 100644 (file)
@@ -13,7 +13,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <syslog.h>
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -68,8 +67,8 @@ static int tc_class_modify(int cmd, unsigned int flags, int argc, char **argv)
        };
        struct qdisc_util *q = NULL;
        struct tc_estimator est = {};
-       char  d[16] = {};
-       char  k[16] = {};
+       char  d[IFNAMSIZ] = {};
+       char  k[FILTER_NAMESZ] = {};
 
        while (argc > 0) {
                if (strcmp(*argv, "dev") == 0) {
@@ -129,7 +128,7 @@ static int tc_class_modify(int cmd, unsigned int flags, int argc, char **argv)
                        fprintf(stderr, "Error: Qdisc \"%s\" is classless.\n", k);
                        return 1;
                }
-               if (q->parse_copt(q, argc, argv, &req.n))
+               if (q->parse_copt(q, argc, argv, &req.n, d))
                        return 1;
        } else {
                if (argc) {
@@ -143,10 +142,9 @@ static int tc_class_modify(int cmd, unsigned int flags, int argc, char **argv)
        if (d[0])  {
                ll_init_map(&rth);
 
-               if ((req.t.tcm_ifindex = ll_name_to_index(d)) == 0) {
-                       fprintf(stderr, "Cannot find device \"%s\"\n", d);
-                       return 1;
-               }
+               req.t.tcm_ifindex = ll_name_to_index(d);
+               if (!req.t.tcm_ifindex)
+                       return -nodev(d);
        }
 
        if (rtnl_talk(&rth, &req.n, NULL) < 0)
@@ -220,7 +218,7 @@ static void graph_cls_show(FILE *fp, char *buf, struct hlist_head *root_list,
        char cls_id_str[256] = {};
        struct rtattr *tb[TCA_MAX + 1];
        struct qdisc_util *q;
-       char str[100] = {};
+       char str[300] = {};
 
        hlist_for_each_safe(n, tmp_cls, root_list) {
                struct hlist_node *c, *tmp_chld;
@@ -243,7 +241,8 @@ static void graph_cls_show(FILE *fp, char *buf, struct hlist_head *root_list,
                graph_indent(buf, cls, 0, 0);
 
                print_tc_classid(cls_id_str, sizeof(cls_id_str), cls->id);
-               sprintf(str, "+---(%s)", cls_id_str);
+               snprintf(str, sizeof(str),
+                        "+---(%s)", cls_id_str);
                strcat(buf, str);
 
                parse_rtattr(tb, TCA_MAX, (struct rtattr *)cls->data,
@@ -389,7 +388,7 @@ int print_class(const struct sockaddr_nl *who,
 static int tc_class_list(int argc, char **argv)
 {
        struct tcmsg t = { .tcm_family = AF_UNSPEC };
-       char d[16] = {};
+       char d[IFNAMSIZ] = {};
        char buf[1024] = {0};
 
        filter_qdisc = 0;
@@ -441,10 +440,9 @@ static int tc_class_list(int argc, char **argv)
        ll_init_map(&rth);
 
        if (d[0]) {
-               if ((t.tcm_ifindex = ll_name_to_index(d)) == 0) {
-                       fprintf(stderr, "Cannot find device \"%s\"\n", d);
-                       return 1;
-               }
+               t.tcm_ifindex = ll_name_to_index(d);
+               if (!t.tcm_ifindex)
+                       return -nodev(d);
                filter_ifindex = t.tcm_ifindex;
        }