netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH iproute2 1/2] tc: added mask parameter in skbedit action
@ 2019-07-03 23:05 Roman Mashak
  2019-07-03 23:05 ` [PATCH iproute2 2/2] tc: document 'mask' parameter in skbedit man page Roman Mashak
  2019-07-08 15:15 ` [PATCH iproute2 1/2] tc: added mask parameter in skbedit action Stephen Hemminger
  0 siblings, 2 replies; 4+ messages in thread
From: Roman Mashak @ 2019-07-03 23:05 UTC (permalink / raw)
  To: stephen; +Cc: netdev, kernel, jhs, xiyou.wangcong, jiri, Roman Mashak

Add 32-bit missing mask attribute in iproute2/tc, which has been long
supported by the kernel side.

Signed-off-by: Roman Mashak <mrv@mojatatu.com>
---
 tc/m_skbedit.c | 30 ++++++++++++++++++++++++++----
 1 file changed, 26 insertions(+), 4 deletions(-)

diff --git a/tc/m_skbedit.c b/tc/m_skbedit.c
index b6b839f8ef6c..f47c9705a990 100644
--- a/tc/m_skbedit.c
+++ b/tc/m_skbedit.c
@@ -33,7 +33,7 @@ static void explain(void)
 	fprintf(stderr, "Usage: ... skbedit <[QM] [PM] [MM] [PT] [IF]>\n"
 		"QM = queue_mapping QUEUE_MAPPING\n"
 		"PM = priority PRIORITY\n"
-		"MM = mark MARK\n"
+		"MM = mark MARK[/MASK]\n"
 		"PT = ptype PACKETYPE\n"
 		"IF = inheritdsfield\n"
 		"PACKETYPE = is one of:\n"
@@ -41,6 +41,7 @@ static void explain(void)
 		"QUEUE_MAPPING = device transmit queue to use\n"
 		"PRIORITY = classID to assign to priority field\n"
 		"MARK = firewall mark to set\n"
+		"MASK = mask applied to firewall mark (0xffffffff by default)\n"
 		"note: inheritdsfield maps DS field to skb->priority\n");
 }
 
@@ -61,7 +62,7 @@ parse_skbedit(struct action_util *a, int *argc_p, char ***argv_p, int tca_id,
 	struct rtattr *tail;
 	unsigned int tmp;
 	__u16 queue_mapping, ptype;
-	__u32 flags = 0, priority, mark;
+	__u32 flags = 0, priority, mark, mask;
 	__u64 pure_flags = 0;
 	struct tc_skbedit sel = { 0 };
 
@@ -89,12 +90,26 @@ parse_skbedit(struct action_util *a, int *argc_p, char ***argv_p, int tca_id,
 			}
 			ok++;
 		} else if (matches(*argv, "mark") == 0) {
-			flags |= SKBEDIT_F_MARK;
+			char *slash;
+
 			NEXT_ARG();
+			slash = strchr(*argv, '/');
+			if (slash)
+				*slash = '\0';
+
+			flags |= SKBEDIT_F_MARK;
 			if (get_u32(&mark, *argv, 0)) {
 				fprintf(stderr, "Illegal mark\n");
 				return -1;
 			}
+
+			if (slash) {
+				if (get_u32(&mask, slash + 1, 0)) {
+					fprintf(stderr, "Illegal mask\n");
+					return -1;
+				}
+				flags |= SKBEDIT_F_MASK;
+			}
 			ok++;
 		} else if (matches(*argv, "ptype") == 0) {
 
@@ -133,7 +148,7 @@ parse_skbedit(struct action_util *a, int *argc_p, char ***argv_p, int tca_id,
 		if (matches(*argv, "index") == 0) {
 			NEXT_ARG();
 			if (get_u32(&sel.index, *argv, 10)) {
-				fprintf(stderr, "Pedit: Illegal \"index\"\n");
+				fprintf(stderr, "skbedit: Illegal \"index\"\n");
 				return -1;
 			}
 			argc--;
@@ -159,6 +174,9 @@ parse_skbedit(struct action_util *a, int *argc_p, char ***argv_p, int tca_id,
 	if (flags & SKBEDIT_F_MARK)
 		addattr_l(n, MAX_MSG, TCA_SKBEDIT_MARK,
 			  &mark, sizeof(mark));
+	if (flags & SKBEDIT_F_MASK)
+		addattr_l(n, MAX_MSG, TCA_SKBEDIT_MASK,
+			  &mask, sizeof(mask));
 	if (flags & SKBEDIT_F_PTYPE)
 		addattr_l(n, MAX_MSG, TCA_SKBEDIT_PTYPE,
 			  &ptype, sizeof(ptype));
@@ -206,6 +224,10 @@ static int print_skbedit(struct action_util *au, FILE *f, struct rtattr *arg)
 		print_uint(PRINT_ANY, "mark", " mark %u",
 			   rta_getattr_u32(tb[TCA_SKBEDIT_MARK]));
 	}
+	if (tb[TCA_SKBEDIT_MASK]) {
+		print_uint(PRINT_ANY, "mask", "/0x%x",
+			   rta_getattr_u32(tb[TCA_SKBEDIT_MASK]));
+	}
 	if (tb[TCA_SKBEDIT_PTYPE] != NULL) {
 		ptype = rta_getattr_u16(tb[TCA_SKBEDIT_PTYPE]);
 		if (ptype == PACKET_HOST)
-- 
2.7.4


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

* [PATCH iproute2 2/2] tc: document 'mask' parameter in skbedit man page
  2019-07-03 23:05 [PATCH iproute2 1/2] tc: added mask parameter in skbedit action Roman Mashak
@ 2019-07-03 23:05 ` Roman Mashak
  2019-07-08 15:15 ` [PATCH iproute2 1/2] tc: added mask parameter in skbedit action Stephen Hemminger
  1 sibling, 0 replies; 4+ messages in thread
From: Roman Mashak @ 2019-07-03 23:05 UTC (permalink / raw)
  To: stephen; +Cc: netdev, kernel, jhs, xiyou.wangcong, jiri, Roman Mashak

Signed-off-by: Roman Mashak <mrv@mojatatu.com>
---
 man/man8/tc-skbedit.8 | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/man/man8/tc-skbedit.8 b/man/man8/tc-skbedit.8
index 2459198261e6..704f63bdb061 100644
--- a/man/man8/tc-skbedit.8
+++ b/man/man8/tc-skbedit.8
@@ -9,8 +9,7 @@ skbedit - SKB editing action
 .IR QUEUE_MAPPING " ] ["
 .B priority
 .IR PRIORITY " ] ["
-.B mark
-.IR MARK " ] ["
+.BI mark " MARK\fR[\fB/\fIMASK] ] ["
 .B ptype
 .IR PTYPE " ] ["
 .BR inheritdsfield " ]"
@@ -49,12 +48,14 @@ or a hexadecimal major class ID optionally followed by a colon
 .RB ( : )
 and a hexadecimal minor class ID.
 .TP
-.BI mark " MARK"
+.BI mark " MARK\fR[\fB/\fIMASK]"
 Change the packet's firewall mark value.
 .I MARK
 is an unsigned 32bit value in automatically detected format (i.e., prefix with
 .RB ' 0x '
 for hexadecimal interpretation, etc.).
+.I MASK
+defines the 32-bit mask selecting bits of mark value. Default is 0xffffffff.
 .TP
 .BI ptype " PTYPE"
 Override the packet's type. Useful for setting packet type to host when
-- 
2.7.4


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

* Re: [PATCH iproute2 1/2] tc: added mask parameter in skbedit action
  2019-07-03 23:05 [PATCH iproute2 1/2] tc: added mask parameter in skbedit action Roman Mashak
  2019-07-03 23:05 ` [PATCH iproute2 2/2] tc: document 'mask' parameter in skbedit man page Roman Mashak
@ 2019-07-08 15:15 ` Stephen Hemminger
  2019-07-08 16:04   ` Roman Mashak
  1 sibling, 1 reply; 4+ messages in thread
From: Stephen Hemminger @ 2019-07-08 15:15 UTC (permalink / raw)
  To: Roman Mashak; +Cc: netdev, kernel, jhs, xiyou.wangcong, jiri

On Wed,  3 Jul 2019 19:05:31 -0400
Roman Mashak <mrv@mojatatu.com> wrote:

> +	if (tb[TCA_SKBEDIT_MASK]) {
> +		print_uint(PRINT_ANY, "mask", "/0x%x",
> +			   rta_getattr_u32(tb[TCA_SKBEDIT_MASK]));

Why not print in hex with.

	print_hex(PRINT_ANY, "mask", "/%#x",
			rta_getattr_u32(tb[TCA_SKBEDIT_MASK]));

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

* Re: [PATCH iproute2 1/2] tc: added mask parameter in skbedit action
  2019-07-08 15:15 ` [PATCH iproute2 1/2] tc: added mask parameter in skbedit action Stephen Hemminger
@ 2019-07-08 16:04   ` Roman Mashak
  0 siblings, 0 replies; 4+ messages in thread
From: Roman Mashak @ 2019-07-08 16:04 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev, kernel, jhs, xiyou.wangcong, jiri

Stephen Hemminger <stephen@networkplumber.org> writes:

> On Wed,  3 Jul 2019 19:05:31 -0400
> Roman Mashak <mrv@mojatatu.com> wrote:
>
>> +	if (tb[TCA_SKBEDIT_MASK]) {
>> +		print_uint(PRINT_ANY, "mask", "/0x%x",
>> +			   rta_getattr_u32(tb[TCA_SKBEDIT_MASK]));
>
> Why not print in hex with.
>
> 	print_hex(PRINT_ANY, "mask", "/%#x",
> 			rta_getattr_u32(tb[TCA_SKBEDIT_MASK]));

Sure, I will send v2.

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

end of thread, other threads:[~2019-07-08 16:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-07-03 23:05 [PATCH iproute2 1/2] tc: added mask parameter in skbedit action Roman Mashak
2019-07-03 23:05 ` [PATCH iproute2 2/2] tc: document 'mask' parameter in skbedit man page Roman Mashak
2019-07-08 15:15 ` [PATCH iproute2 1/2] tc: added mask parameter in skbedit action Stephen Hemminger
2019-07-08 16:04   ` Roman Mashak

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).