public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber•org>
To: netdev@vger•kernel.org
Cc: Stephen Hemminger <stephen@networkplumber•org>
Subject: [PATCH iproute2] tc: cleanup qdisc arg parsing
Date: Fri, 17 Nov 2017 13:09:41 -0800	[thread overview]
Message-ID: <20171117210941.25386-1-stephen@networkplumber.org> (raw)

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

                 reply	other threads:[~2017-11-17 21:09 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171117210941.25386-1-stephen@networkplumber.org \
    --to=stephen@networkplumber$(echo .)org \
    --cc=netdev@vger$(echo .)kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox