netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH iproute2-next v2] net:sched: add action inheritdsfield to skbedit
@ 2018-07-12 16:09 Qiaobin Fu
  2018-07-12 20:50 ` Marcelo Ricardo Leitner
  2018-07-12 22:05 ` Stephen Hemminger
  0 siblings, 2 replies; 3+ messages in thread
From: Qiaobin Fu @ 2018-07-12 16:09 UTC (permalink / raw)
  To: dsahern
  Cc: stephen, davem, netdev, jhs, michel, marcelo.leitner,
	xiyou.wangcong, dcaratti, Qiaobin Fu

The new action inheritdsfield copies the field DS of
IPv4 and IPv6 packets into skb->priority. This enables
later classification of packets based on the DS field.

v2:
* Align the output syntax with the input syntax

* Fix the style issues

Original idea by Jamal Hadi Salim <jhs@mojatatu.com>

Signed-off-by: Qiaobin Fu <qiaobinf@bu.edu>
Reviewed-by: Michel Machado <michel@digirati.com.br>
Reviewed-by: Cong Wang <xiyou.wangcong@gmail.com>
---

Note that the motivation for this patch is found in the following discussion:
https://www.spinics.net/lists/netdev/msg501061.html
---
 tc/m_skbedit.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/tc/m_skbedit.c b/tc/m_skbedit.c
index 7391fc7f..59b2affc 100644
--- a/tc/m_skbedit.c
+++ b/tc/m_skbedit.c
@@ -30,16 +30,18 @@
 
 static void explain(void)
 {
-	fprintf(stderr, "Usage: ... skbedit <[QM] [PM] [MM] [PT]>\n"
+	fprintf(stderr, "Usage: ... skbedit <[QM] [PM] [MM] [PT] [IF]>\n"
 		"QM = queue_mapping QUEUE_MAPPING\n"
 		"PM = priority PRIORITY\n"
 		"MM = mark MARK\n"
 		"PT = ptype PACKETYPE\n"
+		"IF = inheritdsfield\n"
 		"PACKETYPE = is one of:\n"
 		"  host, otherhost, broadcast, multicast\n"
 		"QUEUE_MAPPING = device transmit queue to use\n"
 		"PRIORITY = classID to assign to priority field\n"
-		"MARK = firewall mark to set\n");
+		"MARK = firewall mark to set\n"
+		"note: inheritdsfield maps DS field to skb->priority\n");
 }
 
 static void
@@ -60,6 +62,7 @@ parse_skbedit(struct action_util *a, int *argc_p, char ***argv_p, int tca_id,
 	unsigned int tmp;
 	__u16 queue_mapping, ptype;
 	__u32 flags = 0, priority, mark;
+	__u64 pure_flags = 0;
 	struct tc_skbedit sel = { 0 };
 
 	if (matches(*argv, "skbedit") != 0)
@@ -111,6 +114,9 @@ parse_skbedit(struct action_util *a, int *argc_p, char ***argv_p, int tca_id,
 			}
 			flags |= SKBEDIT_F_PTYPE;
 			ok++;
+		} else if (matches(*argv, "inheritdsfield") == 0) {
+			pure_flags |= SKBEDIT_F_INHERITDSFIELD;
+			ok++;
 		} else if (matches(*argv, "help") == 0) {
 			usage();
 		} else {
@@ -156,6 +162,9 @@ parse_skbedit(struct action_util *a, int *argc_p, char ***argv_p, int tca_id,
 	if (flags & SKBEDIT_F_PTYPE)
 		addattr_l(n, MAX_MSG, TCA_SKBEDIT_PTYPE,
 			  &ptype, sizeof(ptype));
+	if (pure_flags != 0)
+		addattr_l(n, MAX_MSG, TCA_SKBEDIT_FLAGS,
+			&pure_flags, sizeof(pure_flags));
 	addattr_nest_end(n, tail);
 
 	*argc_p = argc;
@@ -214,6 +223,13 @@ static int print_skbedit(struct action_util *au, FILE *f, struct rtattr *arg)
 		else
 			print_uint(PRINT_ANY, "ptype", " ptype %u", ptype);
 	}
+	if (tb[TCA_SKBEDIT_FLAGS] != NULL) {
+		__u64 *flags = RTA_DATA(tb[TCA_SKBEDIT_FLAGS]);
+
+		if (*flags & SKBEDIT_F_INHERITDSFIELD)
+			print_string(PRINT_ANY, "inheritdsfield", " %s",
+				     "inheritdsfield");
+	}
 
 	print_action_control(f, " ", p->action, "");
 
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH iproute2-next v2] net:sched: add action inheritdsfield to skbedit
  2018-07-12 16:09 [PATCH iproute2-next v2] net:sched: add action inheritdsfield to skbedit Qiaobin Fu
@ 2018-07-12 20:50 ` Marcelo Ricardo Leitner
  2018-07-12 22:05 ` Stephen Hemminger
  1 sibling, 0 replies; 3+ messages in thread
From: Marcelo Ricardo Leitner @ 2018-07-12 20:50 UTC (permalink / raw)
  To: Qiaobin Fu
  Cc: dsahern, stephen, davem, netdev, jhs, michel, xiyou.wangcong,
	dcaratti

On Thu, Jul 12, 2018 at 12:09:26PM -0400, Qiaobin Fu wrote:
> @@ -156,6 +162,9 @@ parse_skbedit(struct action_util *a, int *argc_p, char ***argv_p, int tca_id,
>  	if (flags & SKBEDIT_F_PTYPE)
>  		addattr_l(n, MAX_MSG, TCA_SKBEDIT_PTYPE,
>  			  &ptype, sizeof(ptype));
> +	if (pure_flags != 0)
> +		addattr_l(n, MAX_MSG, TCA_SKBEDIT_FLAGS,
> +			&pure_flags, sizeof(pure_flags));

It is missing 2 spaces  ^--- here, to make the indentation right. (as
in the block above)

  Marcelo

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH iproute2-next v2] net:sched: add action inheritdsfield to skbedit
  2018-07-12 16:09 [PATCH iproute2-next v2] net:sched: add action inheritdsfield to skbedit Qiaobin Fu
  2018-07-12 20:50 ` Marcelo Ricardo Leitner
@ 2018-07-12 22:05 ` Stephen Hemminger
  1 sibling, 0 replies; 3+ messages in thread
From: Stephen Hemminger @ 2018-07-12 22:05 UTC (permalink / raw)
  To: Qiaobin Fu
  Cc: dsahern, davem, netdev, jhs, michel, marcelo.leitner,
	xiyou.wangcong, dcaratti

On Thu, 12 Jul 2018 12:09:26 -0400
Qiaobin Fu <qiaobinf@bu.edu> wrote:

> +		if (*flags & SKBEDIT_F_INHERITDSFIELD)
> +			print_string(PRINT_ANY, "inheritdsfield", " %s",
> +				     "inheritdsfield");

Flags should be represented in JSON output as a null value (or boolean).
		print_null(PRINT_ANY, "inheritdsfield", " %s", "inheritdsfield");
This will generate:
			"inheritdsfield" : null,
Instead of:

			"inheritdsfield" : "inheritdsfield",

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-07-12 22:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-12 16:09 [PATCH iproute2-next v2] net:sched: add action inheritdsfield to skbedit Qiaobin Fu
2018-07-12 20:50 ` Marcelo Ricardo Leitner
2018-07-12 22:05 ` Stephen Hemminger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).