Skip to contentSkip to conversation

Support pedit of ip6 dsfield

PATCH Superseded Petr Machata 3 participants 8 messages Mar 27, 2020 – Apr 2, 2020

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Support pedit of ip6 dsfield

The pedit action supports dsfield (and its synonyms, such as tos) for IPv4, but not for IPv6. Patch #1 of this series adds the IPv6 support. Patch #2 then adds two related examples to man page, and patch #3 removes from the man page a claim that the extended notation is only available for IPv4.

Petr Machata (3):
tc: p_ip6: Support pedit of IPv6 dsfield
man: tc-pedit: Add examples for dsfield and retain
man: tc-pedit: Drop the claim that pedit ex is only for IPv4

 man/man8/tc-pedit.8 | 39 +++++++++++++++++++++++++++++++++++----
 tc/p_ip6.c          | 16 ++++++++++++++++
 2 files changed, 51 insertions(+), 4 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/3 tc: p_ip6: Support pedit of IPv6 dsfield

Support keywords dsfield, traffic_class and tos in the IPv6 context.

---
 man/man8/tc-pedit.8 | 14 ++++++++++++--
 tc/p_ip6.c          | 16 ++++++++++++++++
 2 files changed, 28 insertions(+), 2 deletions(-)
man/man8/tc-pedit.8 +12 -2
index bbd725c4..b44b0263 100644
@@ -60,8 +60,8 @@ pedit - generic packet editor action
 
 .ti -8
 .IR IP6HDR_FIELD " := { "
-.BR src " | " dst " | " flow_lbl " | " payload_len " | " nexthdr " |"
-.BR hoplimit " }"
+.BR src " | " dst " | " tos " | " dsfield " | " traffic_class " | "
+.BR flow_lbl " | " payload_len " | " nexthdr " |" hoplimit " }"
 
 .ti -8
 .IR TCPHDR_FIELD " := { "
@@ -228,6 +228,16 @@ are:
 .B src
 .TQ
 .B dst
+.TP
+.B tos
+.TQ
+.B dsfield
+.TQ
+.B traffic_class
+Traffic Class, an 8-bit quantity. Because the field is shifted by 4 bits,
+it is necessary to specify the full 16-bit halfword, with the actual
+dsfield value sandwiched between 4-bit zeroes.
+.TP
 .TQ
 .B flow_lbl
 .TQ
tc/p_ip6.c +16 -0
index 7cc7997b..b6fe81f5 100644
@@ -56,6 +56,22 @@ parse_ip6(int *argc_p, char ***argv_p,
 		res = parse_cmd(&argc, &argv, 4, TU32, 0x0007ffff, sel, tkey);
 		goto done;
 	}
+	if (strcmp(*argv, "traffic_class") == 0 ||
+	    strcmp(*argv, "tos") == 0 ||
+	    strcmp(*argv, "dsfield") == 0) {
+		NEXT_ARG();
+		tkey->off = 1;
+		res = parse_cmd(&argc, &argv, 1, TU32, RU8, sel, tkey);
+
+		/* Shift the field by 4 bits on success. */
+		if (!res) {
+			int nkeys = sel->sel.nkeys;
+			struct tc_pedit_key *key = &sel->sel.keys[nkeys - 1];
+			key->mask = htonl(ntohl(key->mask) << 4 | 0xf);
+			key->val = htonl(ntohl(key->val) << 4);
+		}
+		goto done;
+	}
 	if (strcmp(*argv, "payload_len") == 0) {
 		NEXT_ARG();
 		tkey->off = 4;
Signature · 1 line
2.20.1
#6 lore raw

PATCH 2/3 man: tc-pedit: Add examples for dsfield and retain

In reply to Petr Machata

Describe a way to update just the DSCP and just the ECN part of the dsfield. That is useful on its own, but also it shows how retain works.

---
 man/man8/tc-pedit.8 | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
man/man8/tc-pedit.8 +22 -0
index b44b0263..54b91d3d 100644
@@ -377,6 +377,28 @@ tc filter add dev eth0 parent ffff: u32 \\
 	action pedit ex munge tcp dport set 22
 .EE
 .RE
+
+To rewrite just part of a field, use the
+.B retain
+directive. E.g. to overwrite the DSCP part of a dsfield with $DSCP, without
+touching ECN:
+
+.RS
+.EX
+tc filter add dev eth0 ingress flower ... \\
+	action pedit ex munge ip dsfield set $((DSCP << 2)) retain 0xfc
+.EE
+.RE
+
+And vice versa, to set ECN to e.g. 1 without impacting DSCP:
+
+.RS
+.EX
+tc filter add dev eth0 ingress flower ... \\
+	action pedit ex munge ip dsfield set 1 retain 0x3
+.EE
+.RE
+
 .SH SEE ALSO
 .BR tc (8),
 .BR tc-htb (8),
Signature · 1 line
2.20.1
#7 lore raw

PATCH 3/3 man: tc-pedit: Drop the claim that pedit ex is only for IPv4

In reply to Petr Machata

This sentence predates addition of extended pedit for IPv6 packets.

---
 man/man8/tc-pedit.8 | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
man/man8/tc-pedit.8 +1 -2
index 54b91d3d..ae9f7c2e 100644
@@ -90,8 +90,7 @@ action can be used to change arbitrary packet data. The location of data to
 change can either be specified by giving an offset and size as in
 .IR RAW_OP ,
 or for header values by naming the header and field to edit the size is then
-chosen automatically based on the header field size. Currently this is supported
-only for IPv4 headers.
+chosen automatically based on the header field size.
 .SH OPTIONS
 .TP
 .B ex
Signature · 1 line
2.20.1
#2 lore raw

Re: [PATCH iproute2-next 1/3] tc: p_ip6: Support pedit of IPv6 dsfield

In reply to Petr Machata
Quoted 54 lines · On Fri, 27 Mar 2020 20:55:08 +0300 Petr Machata <[email protected]> wrote:

Support keywords dsfield, traffic_class and tos in the IPv6 context.

---
 man/man8/tc-pedit.8 | 14 ++++++++++++--
 tc/p_ip6.c          | 16 ++++++++++++++++
 2 files changed, 28 insertions(+), 2 deletions(-)
man/man8/tc-pedit.8 +12 -2
index bbd725c4..b44b0263 100644
@@ -60,8 +60,8 @@ pedit - generic packet editor action
 
 .ti -8
 .IR IP6HDR_FIELD " := { "
-.BR src " | " dst " | " flow_lbl " | " payload_len " | " nexthdr " |"
-.BR hoplimit " }"
+.BR src " | " dst " | " tos " | " dsfield " | " traffic_class " | "
+.BR flow_lbl " | " payload_len " | " nexthdr " |" hoplimit " }"
 
 .ti -8
 .IR TCPHDR_FIELD " := { "
@@ -228,6 +228,16 @@ are:
 .B src
 .TQ
 .B dst
+.TP
+.B tos
+.TQ
+.B dsfield
+.TQ
+.B traffic_class
+Traffic Class, an 8-bit quantity. Because the field is shifted by 4 bits,
+it is necessary to specify the full 16-bit halfword, with the actual
+dsfield value sandwiched between 4-bit zeroes.
+.TP
 .TQ
 .B flow_lbl
 .TQ
tc/p_ip6.c +6 -0
index 7cc7997b..b6fe81f5 100644
@@ -56,6 +56,22 @@ parse_ip6(int *argc_p, char ***argv_p,
 		res = parse_cmd(&argc, &argv, 4, TU32, 0x0007ffff, sel, tkey);
 		goto done;
 	}
+	if (strcmp(*argv, "traffic_class") == 0 ||
+	    strcmp(*argv, "tos") == 0 ||
+	    strcmp(*argv, "dsfield") == 0) {
+		NEXT_ARG();
+		tkey->off = 1;
+		res = parse_cmd(&argc, &argv, 1, TU32, RU8, sel, tkey);

tc/p_ip6.c parse_ip6(int *argc_p, char ***argv_p, · line 74

Quoted 10 lines
tc/p_ip6.c +10 -0
+
+		/* Shift the field by 4 bits on success. */
+		if (!res) {
+			int nkeys = sel->sel.nkeys;
+			struct tc_pedit_key *key = &sel->sel.keys[nkeys - 1];
+			key->mask = htonl(ntohl(key->mask) << 4 | 0xf);
+			key->val = htonl(ntohl(key->val) << 4);
+		}
+		goto done;
+	}

Why in the middle of the list? Why three aliases for the same value? Since this is new code choose one and make it match what IPv6 standard calls that field.

#3 lore raw

Re: [PATCH iproute2-next 1/3] tc: p_ip6: Support pedit of IPv6 dsfield

Quoted 17 lines · Stephen Hemminger
Quoted 17 lines
tc/p_ip6.c +9 -0
index 7cc7997b..b6fe81f5 100644
@@ -56,6 +56,22 @@ parse_ip6(int *argc_p, char ***argv_p,
 		res = parse_cmd(&argc, &argv, 4, TU32, 0x0007ffff, sel, tkey);
 		goto done;
 	}
+	if (strcmp(*argv, "traffic_class") == 0 ||
+	    strcmp(*argv, "tos") == 0 ||
+	    strcmp(*argv, "dsfield") == 0) {
+		NEXT_ARG();
+		tkey->off = 1;
+		res = parse_cmd(&argc, &argv, 1, TU32, RU8, sel, tkey);
+
+		/* Shift the field by 4 bits on success. */
+		if (!res) {
Quoted 8 lines

tc/p_ip6.c parse_ip6(int *argc_p, char ***argv_p, · line 74

Quoted 7 lines
tc/p_ip6.c +7 -0
+			int nkeys = sel->sel.nkeys;
+			struct tc_pedit_key *key = &sel->sel.keys[nkeys - 1];
+			key->mask = htonl(ntohl(key->mask) << 4 | 0xf);
+			key->val = htonl(ntohl(key->val) << 4);
+		}
+		goto done;
+	}

Why in the middle of the list?

Because that's the order IPv4 code does them.

Quoted 3 lines

Why three aliases for the same value?
Since this is new code choose one and make it match what IPv6 standard calls that field.

TOS because flower also calls it TOS, even if it's the IPv6 field. dsfield, because the IPv4 pedit also accepts this. I'm fine with just accepting traffic_class though.

#4 lore raw

Re: [PATCH iproute2-next 1/3] tc: p_ip6: Support pedit of IPv6 dsfield

Quoted 29 lines · Petr Machata
Quoted 17 lines · Stephen Hemminger
Quoted 17 lines
tc/p_ip6.c +9 -0
index 7cc7997b..b6fe81f5 100644
@@ -56,6 +56,22 @@ parse_ip6(int *argc_p, char ***argv_p,
 		res = parse_cmd(&argc, &argv, 4, TU32, 0x0007ffff, sel, tkey);
 		goto done;
 	}
+	if (strcmp(*argv, "traffic_class") == 0 ||
+	    strcmp(*argv, "tos") == 0 ||
+	    strcmp(*argv, "dsfield") == 0) {
+		NEXT_ARG();
+		tkey->off = 1;
+		res = parse_cmd(&argc, &argv, 1, TU32, RU8, sel, tkey);
+
+		/* Shift the field by 4 bits on success. */
+		if (!res) {
Quoted 8 lines

tc/p_ip6.c parse_ip6(int *argc_p, char ***argv_p, · line 74

Quoted 7 lines
tc/p_ip6.c +7 -0
+			int nkeys = sel->sel.nkeys;
+			struct tc_pedit_key *key = &sel->sel.keys[nkeys - 1];
+			key->mask = htonl(ntohl(key->mask) << 4 | 0xf);
+			key->val = htonl(ntohl(key->val) << 4);
+		}
+		goto done;
+	}

Why in the middle of the list?

Quoted 1 line

Because that's the order IPv4 code does them.

neither parse function uses matches() so the order should not matter.

Quoted 9 lines
Quoted 4 lines

Why three aliases for the same value?
Since this is new code choose one and make it match what IPv6 standard calls that field.

TOS because flower also calls it TOS, even if it's the IPv6 field. dsfield, because the IPv4 pedit also accepts this. I'm fine with just accepting traffic_class though.

that's probably the right thing to do since this is ipv6 related

#5 lore raw

Re: [PATCH iproute2-next 1/3] tc: p_ip6: Support pedit of IPv6 dsfield

Quoted 30 lines · David Ahern
Quoted 29 lines · Petr Machata
Quoted 25 lines · Stephen Hemminger
Quoted 14 lines
tc/p_ip6.c +6 -0
index 7cc7997b..b6fe81f5 100644
@@ -56,6 +56,22 @@ parse_ip6(int *argc_p, char ***argv_p,
 		res = parse_cmd(&argc, &argv, 4, TU32, 0x0007ffff, sel, tkey);
 		goto done;
 	}
+	if (strcmp(*argv, "traffic_class") == 0 ||
+	    strcmp(*argv, "tos") == 0 ||
+	    strcmp(*argv, "dsfield") == 0) {
+		NEXT_ARG();
+		tkey->off = 1;
+		res = parse_cmd(&argc, &argv, 1, TU32, RU8, sel, tkey);

tc/p_ip6.c parse_ip6(int *argc_p, char ***argv_p, · line 74

Quoted 10 lines
tc/p_ip6.c +10 -0
+
+		/* Shift the field by 4 bits on success. */
+		if (!res) {
+			int nkeys = sel->sel.nkeys;
+			struct tc_pedit_key *key = &sel->sel.keys[nkeys - 1];
+			key->mask = htonl(ntohl(key->mask) << 4 | 0xf);
+			key->val = htonl(ntohl(key->val) << 4);
+		}
+		goto done;
+	}

Why in the middle of the list?

Quoted 3 lines
Quoted 1 line

Because that's the order IPv4 code does them.

neither parse function uses matches() so the order should not matter.

It was purely a consistency thing. So you both seem to imply I should move it to the end, so I'll do that in v2.

Quoted 11 lines
Quoted 9 lines
Quoted 4 lines

Why three aliases for the same value?
Since this is new code choose one and make it match what IPv6 standard calls that field.

TOS because flower also calls it TOS, even if it's the IPv6 field. dsfield, because the IPv4 pedit also accepts this. I'm fine with just accepting traffic_class though.

that's probably the right thing to do since this is ipv6 related

All right, I'll send v2 with this fix.