naccyde / rpms / iproute

Forked from rpms/iproute 10 months ago
Clone

Blame SOURCES/0137-tc-fix-parsing-of-the-control-action.patch

99be8f
From cb73324026eb3f9c315735b9020890f43eeaac43 Mon Sep 17 00:00:00 2001
99be8f
From: Andrea Claudi <aclaudi@redhat.com>
99be8f
Date: Wed, 5 Jun 2019 13:12:06 +0200
99be8f
Subject: [PATCH] tc: fix parsing of the control action
99be8f
99be8f
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1714660
99be8f
Upstream Status: iproute2.git commit 75ef7b18d2a13
99be8f
Conflicts: context change due to missing commit 35f2a7639dca4
99be8f
           ("tc/actions: introduce support for jump action")
99be8f
99be8f
commit 75ef7b18d2a13657056706895bf8d8dd3ac93e46
99be8f
Author: Davide Caratti <dcaratti@redhat.com>
99be8f
Date:   Fri Mar 2 19:36:16 2018 +0100
99be8f
99be8f
    tc: fix parsing of the control action
99be8f
99be8f
    If the user didn't specify any control action, don't pop the command line
99be8f
    arguments: otherwise, parsing of the next argument (tipically the 'index'
99be8f
    keyword) results in an error, causing the following 'tc-testing' failures:
99be8f
99be8f
     Test a6d6: Add skbedit action with index
99be8f
     Test 38f3: Delete skbedit action
99be8f
     Test a568: Add action with ife type
99be8f
     Test b983: Add action without ife type
99be8f
     Test 7d50: Add skbmod action to set destination mac
99be8f
     Test 9b29: Add skbmod action to set source mac
99be8f
     Test e93a: Delete an skbmod action
99be8f
99be8f
    Also, add missing parse for 'ok' control action to m_police, to fix the
99be8f
    following 'tc-testing' failure:
99be8f
99be8f
     Test 8dd5: Add police action with control ok
99be8f
99be8f
    tested with:
99be8f
     # ./tdc.py
99be8f
99be8f
    test results:
99be8f
     all tests ok using kernel 4.16-rc2, except 9aa8 "Get a single skbmod
99be8f
     action from a list" (which is failing also before this commit)
99be8f
99be8f
    Fixes: 3572e01a090a ("tc: util: Don't call NEXT_ARG_FWD() in __parse_action_control()")
99be8f
    Cc: Michal Privoznik <mprivozn@redhat.com>
99be8f
    Cc: Wolfgang Bumiller <w.bumiller@proxmox.com>
99be8f
    Signed-off-by: Davide Caratti <dcaratti@redhat.com>
99be8f
    Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
99be8f
---
99be8f
 tc/m_bpf.c        |  1 -
99be8f
 tc/m_connmark.c   |  1 -
99be8f
 tc/m_csum.c       |  1 -
99be8f
 tc/m_gact.c       |  9 +++------
99be8f
 tc/m_ife.c        |  1 -
99be8f
 tc/m_mirred.c     |  5 ++---
99be8f
 tc/m_nat.c        |  1 -
99be8f
 tc/m_pedit.c      |  1 -
99be8f
 tc/m_police.c     | 16 ++++++++++------
99be8f
 tc/m_sample.c     |  1 -
99be8f
 tc/m_skbedit.c    |  1 -
99be8f
 tc/m_skbmod.c     |  1 -
99be8f
 tc/m_tunnel_key.c |  1 -
99be8f
 tc/m_vlan.c       |  1 -
99be8f
 tc/tc_util.c      |  6 +++++-
99be8f
 15 files changed, 20 insertions(+), 27 deletions(-)
99be8f
99be8f
diff --git a/tc/m_bpf.c b/tc/m_bpf.c
99be8f
index c2bad5640707c..57283030a35f5 100644
99be8f
--- a/tc/m_bpf.c
99be8f
+++ b/tc/m_bpf.c
99be8f
@@ -125,7 +125,6 @@ opt_bpf:
99be8f
 
99be8f
 	parse_action_control_dflt(&argc, &argv, &parm.action,
99be8f
 				  false, TC_ACT_PIPE);
99be8f
-	NEXT_ARG_FWD();
99be8f
 
99be8f
 	if (argc) {
99be8f
 		if (matches(*argv, "index") == 0) {
99be8f
diff --git a/tc/m_connmark.c b/tc/m_connmark.c
99be8f
index 47c7a8c2b17e7..37d7185415490 100644
99be8f
--- a/tc/m_connmark.c
99be8f
+++ b/tc/m_connmark.c
99be8f
@@ -82,7 +82,6 @@ parse_connmark(struct action_util *a, int *argc_p, char ***argv_p, int tca_id,
99be8f
 	}
99be8f
 
99be8f
 	parse_action_control_dflt(&argc, &argv, &sel.action, false, TC_ACT_PIPE);
99be8f
-	NEXT_ARG_FWD();
99be8f
 
99be8f
 	if (argc) {
99be8f
 		if (matches(*argv, "index") == 0) {
99be8f
diff --git a/tc/m_csum.c b/tc/m_csum.c
99be8f
index e1352c0820f69..7b156734f64c5 100644
99be8f
--- a/tc/m_csum.c
99be8f
+++ b/tc/m_csum.c
99be8f
@@ -124,7 +124,6 @@ parse_csum(struct action_util *a, int *argc_p,
99be8f
 	}
99be8f
 
99be8f
 	parse_action_control_dflt(&argc, &argv, &sel.action, false, TC_ACT_OK);
99be8f
-	NEXT_ARG_FWD();
99be8f
 
99be8f
 	if (argc) {
99be8f
 		if (matches(*argv, "index") == 0) {
99be8f
diff --git a/tc/m_gact.c b/tc/m_gact.c
99be8f
index dd9542a5cc644..45eecf7ea1647 100644
99be8f
--- a/tc/m_gact.c
99be8f
+++ b/tc/m_gact.c
99be8f
@@ -86,12 +86,10 @@ parse_gact(struct action_util *a, int *argc_p, char ***argv_p,
99be8f
 	if (argc < 0)
99be8f
 		return -1;
99be8f
 
99be8f
-	if (matches(*argv, "gact") != 0 &&
99be8f
-		parse_action_control(&argc, &argv, &p.action, false) == -1) {
99be8f
+	if (!matches(*argv, "gact"))
99be8f
+		NEXT_ARG_FWD();
99be8f
+	if (parse_action_control(&argc, &argv, &p.action, false))
99be8f
 		usage();	/* does not return */
99be8f
-	}
99be8f
-
99be8f
-	NEXT_ARG_FWD();
99be8f
 
99be8f
 #ifdef CONFIG_GACT_PROB
99be8f
 	if (argc > 0) {
99be8f
@@ -112,7 +110,6 @@ parse_gact(struct action_util *a, int *argc_p, char ***argv_p,
99be8f
 			if (parse_action_control(&argc, &argv,
99be8f
 						 &pp.paction, false) == -1)
99be8f
 				usage();
99be8f
-			NEXT_ARG_FWD();
99be8f
 			if (get_u16(&pp.pval, *argv, 10)) {
99be8f
 				fprintf(stderr, "Illegal probability val 0x%x\n", pp.pval);
99be8f
 				return -1;
99be8f
diff --git a/tc/m_ife.c b/tc/m_ife.c
99be8f
index 54fad8f70e73a..e3521e62c178c 100644
99be8f
--- a/tc/m_ife.c
99be8f
+++ b/tc/m_ife.c
99be8f
@@ -158,7 +158,6 @@ static int parse_ife(struct action_util *a, int *argc_p, char ***argv_p,
99be8f
 
99be8f
 	parse_action_control_dflt(&argc, &argv, &p.action, false, TC_ACT_PIPE);
99be8f
 
99be8f
-	NEXT_ARG_FWD();
99be8f
 	if (argc) {
99be8f
 		if (matches(*argv, "index") == 0) {
99be8f
 			NEXT_ARG();
99be8f
diff --git a/tc/m_mirred.c b/tc/m_mirred.c
99be8f
index b09b016c2ca39..b1f45f1e6ecb0 100644
99be8f
--- a/tc/m_mirred.c
99be8f
+++ b/tc/m_mirred.c
99be8f
@@ -76,6 +76,7 @@ parse_direction(struct action_util *a, int *argc_p, char ***argv_p,
99be8f
 	while (argc > 0) {
99be8f
 
99be8f
 		if (matches(*argv, "action") == 0) {
99be8f
+			NEXT_ARG();
99be8f
 			break;
99be8f
 		} else if (!egress && matches(*argv, "egress") == 0) {
99be8f
 			egress = 1;
99be8f
@@ -170,10 +171,8 @@ parse_direction(struct action_util *a, int *argc_p, char ***argv_p,
99be8f
 	}
99be8f
 
99be8f
 
99be8f
-	if (p.eaction == TCA_EGRESS_MIRROR || p.eaction == TCA_INGRESS_MIRROR) {
99be8f
+	if (p.eaction == TCA_EGRESS_MIRROR || p.eaction == TCA_INGRESS_MIRROR)
99be8f
 		parse_action_control(&argc, &argv, &p.action, false);
99be8f
-		NEXT_ARG_FWD();
99be8f
-	}
99be8f
 
99be8f
 	if (argc) {
99be8f
 		if (iok && matches(*argv, "index") == 0) {
99be8f
diff --git a/tc/m_nat.c b/tc/m_nat.c
99be8f
index bb455f080b3a4..31b68fb6bd784 100644
99be8f
--- a/tc/m_nat.c
99be8f
+++ b/tc/m_nat.c
99be8f
@@ -117,7 +117,6 @@ parse_nat(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, struct
99be8f
 
99be8f
 	parse_action_control_dflt(&argc, &argv, &sel.action, false, TC_ACT_OK);
99be8f
 
99be8f
-	NEXT_ARG_FWD();
99be8f
 	if (argc) {
99be8f
 		if (matches(*argv, "index") == 0) {
99be8f
 			NEXT_ARG();
99be8f
diff --git a/tc/m_pedit.c b/tc/m_pedit.c
99be8f
index 3391be95da38c..5d89ab1d832ab 100644
99be8f
--- a/tc/m_pedit.c
99be8f
+++ b/tc/m_pedit.c
99be8f
@@ -673,7 +673,6 @@ int parse_pedit(struct action_util *a, int *argc_p, char ***argv_p, int tca_id,
99be8f
 
99be8f
 	parse_action_control_dflt(&argc, &argv, &sel.sel.action, false, TC_ACT_OK);
99be8f
 
99be8f
-	NEXT_ARG_FWD();
99be8f
 	if (argc) {
99be8f
 		if (matches(*argv, "index") == 0) {
99be8f
 			NEXT_ARG();
99be8f
diff --git a/tc/m_police.c b/tc/m_police.c
99be8f
index 86117db0482ec..b79545961f4d7 100644
99be8f
--- a/tc/m_police.c
99be8f
+++ b/tc/m_police.c
99be8f
@@ -151,15 +151,18 @@ int act_parse_police(struct action_util *a, int *argc_p, char ***argv_p,
99be8f
 			   matches(*argv, "shot") == 0 ||
99be8f
 			   matches(*argv, "continue") == 0 ||
99be8f
 			   matches(*argv, "pass") == 0 ||
99be8f
+			   matches(*argv, "ok") == 0 ||
99be8f
 			   matches(*argv, "pipe") == 0 ||
99be8f
 			   matches(*argv, "goto") == 0) {
99be8f
-			if (parse_action_control(&argc, &argv, &p.action, false))
99be8f
-				return -1;
99be8f
+			if (!parse_action_control(&argc, &argv, &p.action, false))
99be8f
+				goto action_ctrl_ok;
99be8f
+			return -1;
99be8f
 		} else if (strcmp(*argv, "conform-exceed") == 0) {
99be8f
 			NEXT_ARG();
99be8f
-			if (parse_action_control_slash(&argc, &argv, &p.action,
99be8f
-						       &presult, true))
99be8f
-				return -1;
99be8f
+			if (!parse_action_control_slash(&argc, &argv, &p.action,
99be8f
+							&presult, true))
99be8f
+				goto action_ctrl_ok;
99be8f
+			return -1;
99be8f
 		} else if (matches(*argv, "overhead") == 0) {
99be8f
 			NEXT_ARG();
99be8f
 			if (get_u16(&overhead, *argv, 10)) {
99be8f
@@ -175,8 +178,9 @@ int act_parse_police(struct action_util *a, int *argc_p, char ***argv_p,
99be8f
 		} else {
99be8f
 			break;
99be8f
 		}
99be8f
+		NEXT_ARG_FWD();
99be8f
+action_ctrl_ok:
99be8f
 		ok++;
99be8f
-		argc--; argv++;
99be8f
 	}
99be8f
 
99be8f
 	if (!ok)
99be8f
diff --git a/tc/m_sample.c b/tc/m_sample.c
99be8f
index 31774c0e806b4..ff5ee6bd1ef63 100644
99be8f
--- a/tc/m_sample.c
99be8f
+++ b/tc/m_sample.c
99be8f
@@ -100,7 +100,6 @@ static int parse_sample(struct action_util *a, int *argc_p, char ***argv_p,
99be8f
 
99be8f
 	parse_action_control_dflt(&argc, &argv, &p.action, false, TC_ACT_PIPE);
99be8f
 
99be8f
-	NEXT_ARG_FWD();
99be8f
 	if (argc) {
99be8f
 		if (matches(*argv, "index") == 0) {
99be8f
 			NEXT_ARG();
99be8f
diff --git a/tc/m_skbedit.c b/tc/m_skbedit.c
99be8f
index c41a7bb082dad..aa374fcb33ed9 100644
99be8f
--- a/tc/m_skbedit.c
99be8f
+++ b/tc/m_skbedit.c
99be8f
@@ -123,7 +123,6 @@ parse_skbedit(struct action_util *a, int *argc_p, char ***argv_p, int tca_id,
99be8f
 	parse_action_control_dflt(&argc, &argv, &sel.action,
99be8f
 				  false, TC_ACT_PIPE);
99be8f
 
99be8f
-	NEXT_ARG_FWD();
99be8f
 	if (argc) {
99be8f
 		if (matches(*argv, "index") == 0) {
99be8f
 			NEXT_ARG();
99be8f
diff --git a/tc/m_skbmod.c b/tc/m_skbmod.c
99be8f
index 00318d42642a5..ba79308ba8354 100644
99be8f
--- a/tc/m_skbmod.c
99be8f
+++ b/tc/m_skbmod.c
99be8f
@@ -125,7 +125,6 @@ static int parse_skbmod(struct action_util *a, int *argc_p, char ***argv_p,
99be8f
 
99be8f
 	parse_action_control_dflt(&argc, &argv, &p.action, false, TC_ACT_PIPE);
99be8f
 
99be8f
-	NEXT_ARG_FWD();
99be8f
 	if (argc) {
99be8f
 		if (matches(*argv, "index") == 0) {
99be8f
 			NEXT_ARG();
99be8f
diff --git a/tc/m_tunnel_key.c b/tc/m_tunnel_key.c
99be8f
index 0ff3f1a2b9876..cdde64a15b929 100644
99be8f
--- a/tc/m_tunnel_key.c
99be8f
+++ b/tc/m_tunnel_key.c
99be8f
@@ -197,7 +197,6 @@ static int parse_tunnel_key(struct action_util *a, int *argc_p, char ***argv_p,
99be8f
 	parse_action_control_dflt(&argc, &argv, &parm.action,
99be8f
 				  false, TC_ACT_PIPE);
99be8f
 
99be8f
-	NEXT_ARG_FWD();
99be8f
 	if (argc) {
99be8f
 		if (matches(*argv, "index") == 0) {
99be8f
 			NEXT_ARG();
99be8f
diff --git a/tc/m_vlan.c b/tc/m_vlan.c
99be8f
index 0b2966ce82e53..cccb4996b05f3 100644
99be8f
--- a/tc/m_vlan.c
99be8f
+++ b/tc/m_vlan.c
99be8f
@@ -137,7 +137,6 @@ static int parse_vlan(struct action_util *a, int *argc_p, char ***argv_p,
99be8f
 	parse_action_control_dflt(&argc, &argv, &parm.action,
99be8f
 				  false, TC_ACT_PIPE);
99be8f
 
99be8f
-	NEXT_ARG_FWD();
99be8f
 	if (argc) {
99be8f
 		if (matches(*argv, "index") == 0) {
99be8f
 			NEXT_ARG();
99be8f
diff --git a/tc/tc_util.c b/tc/tc_util.c
99be8f
index 4584d4a448fb4..65695ea592ed8 100644
99be8f
--- a/tc/tc_util.c
99be8f
+++ b/tc/tc_util.c
99be8f
@@ -507,6 +507,7 @@ static int __parse_action_control(int *argc_p, char ***argv_p, int *result_p,
99be8f
 		}
99be8f
 		result |= chain_index;
99be8f
 	}
99be8f
+	NEXT_ARG_FWD();
99be8f
 	*argc_p = argc;
99be8f
 	*argv_p = argv;
99be8f
 	*result_p = result;
99be8f
@@ -603,8 +604,8 @@ out:
99be8f
 int parse_action_control_slash(int *argc_p, char ***argv_p,
99be8f
 			       int *result1_p, int *result2_p, bool allow_num)
99be8f
 {
99be8f
+	int result1, result2, argc = *argc_p;
99be8f
 	char **argv = *argv_p;
99be8f
-	int result1, result2;
99be8f
 	char *p = strchr(*argv, '/');
99be8f
 
99be8f
 	if (!p)
99be8f
@@ -624,6 +625,9 @@ int parse_action_control_slash(int *argc_p, char ***argv_p,
99be8f
 
99be8f
 	*result1_p = result1;
99be8f
 	*result2_p = result2;
99be8f
+	NEXT_ARG_FWD();
99be8f
+	*argc_p = argc;
99be8f
+	*argv_p = argv;
99be8f
 	return 0;
99be8f
 }
99be8f
 
99be8f
-- 
99be8f
2.20.1
99be8f