Subject: [PATCH iproute2] tc: cleanup qdisc arg parsing

From: Stephen Hemminger <[email-masked]>
Date: Fri, 17 Nov 2017 13:09:41 -0800

The qdisc arg parsing has magic limit of 16 for class which is not required
by kernel. Also the limit of 16 for device name is really IFNAMSIZ.

Signed-off-by: Stephen Hemminger <[email-masked]>
---
 tc/tc_qdisc.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/tc/tc_qdisc.c b/tc/tc_qdisc.c
index fcb75f29128e..1066ae05a4b5 100644
--- a/tc/tc_qdisc.c
+++ b/tc/tc_qdisc.c
@@ -17,6 +17,7 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
+#include <net/if.h>
 #include <string.h>
 #include <math.h>
 #include <malloc.h>
@@ -49,8 +50,7 @@ static int tc_qdisc_modify(int cmd, unsigned int flags, int argc, char **argv)
 		struct tc_sizespec	szopts;
 		__u16			*data;
 	} stab = {};
-	char  d[16] = {};
-	char  k[16] = {};
+	char  d[IFNAMSIZ] = {};
 	struct {
 		struct nlmsghdr	n;
 		struct tcmsg		t;
@@ -89,8 +89,8 @@ static int tc_qdisc_modify(int cmd, unsigned int flags, int argc, char **argv)
 				return -1;
 			}
 			req.t.tcm_parent = TC_H_CLSACT;
-			strncpy(k, "clsact", sizeof(k) - 1);
-			q = get_qdisc_kind(k);
+
+			q = get_qdisc_kind("clsact");
 			req.t.tcm_handle = TC_H_MAKE(TC_H_CLSACT, 0);
 			NEXT_ARG_FWD();
 			break;
@@ -100,8 +100,8 @@ static int tc_qdisc_modify(int cmd, unsigned int flags, int argc, char **argv)
 				return -1;
 			}
 			req.t.tcm_parent = TC_H_INGRESS;
-			strncpy(k, "ingress", sizeof(k) - 1);
-			q = get_qdisc_kind(k);
+
+			q = get_qdisc_kind("ingress");
 			req.t.tcm_handle = TC_H_MAKE(TC_H_INGRESS, 0);
 			NEXT_ARG_FWD();
 			break;
@@ -124,26 +124,23 @@ static int tc_qdisc_modify(int cmd, unsigned int flags, int argc, char **argv)
 		} else if (matches(*argv, "help") == 0) {
 			usage();
 		} else {
-			strncpy(k, *argv, sizeof(k)-1);
-
-			q = get_qdisc_kind(k);
+			q = get_qdisc_kind(*argv);
 			argc--; argv++;
 			break;
 		}
 		argc--; argv++;
 	}
 
-	if (k[0])
-		addattr_l(&req.n, sizeof(req), TCA_KIND, k, strlen(k)+1);
 	if (est.ewma_log)
 		addattr_l(&req.n, sizeof(req), TCA_RATE, &est, sizeof(est));
 
 	if (q) {
+		addattr_l(&req.n, sizeof(req), TCA_KIND, q->id, strlen(q->id) + 1);
 		if (q->parse_qopt) {
 			if (q->parse_qopt(q, argc, argv, &req.n))
 				return 1;
 		} else if (argc) {
-			fprintf(stderr, "qdisc '%s' does not support option parsing\n", k);
+			fprintf(stderr, "qdisc '%s' does not support option parsing\n", q->id);
 			return -1;
 		}
 	} else {
-- 
2.11.0