public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
* [PATCH iproute2] tc: cleanup qdisc arg parsing
@ 2017-11-17 21:09 Stephen Hemminger
  0 siblings, 0 replies; only message in thread
From: Stephen Hemminger @ 2017-11-17 21:09 UTC (permalink / raw)
  To: netdev; +Cc: Stephen Hemminger

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 <stephen@networkplumber•org>
---
 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

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2017-11-17 21:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-17 21:09 [PATCH iproute2] tc: cleanup qdisc arg parsing Stephen Hemminger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox