Skip to contentSkip to conversation

src: add dscp support

PATCH In review Pablo Neira Ayuso 3 participants 14 messages Nov 25, 2015 – Nov 26, 2015 netfilter

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/2 src: add dscp support

This supports both IPv4:

 # nft --debug=netlink add rule filter forward ip dscp cs1 counter
 ip filter forward
  [ payload load 1b @ network header + 1 => reg 1 ]
  [ bitwise reg 1 = (reg=1 & 0x0000003f ) ^ 0x00000000 ]
  [ cmp eq reg 1 0x00000008 ]
  [ counter pkts 0 bytes 0 ]

And IPv6:

 # nft --debug=netlink add rule ip6 filter forward ip6 dscp cs1 counter
 ip6 filter forward
  [ payload load 1b @ network header + 1 => reg 1 ]
  [ bitwise reg 1 = (reg=1 & 0x0000003f ) ^ 0x00000000 ]
  [ cmp eq reg 1 0x00000008 ]
  [ counter pkts 0 bytes 0 ]
---
 doc/nft.xml        | 11 ++++++++---
 include/datatype.h |  2 ++
 include/proto.h    |  3 ++-
 src/parser_bison.y |  5 +++--
 src/proto.c        | 44 +++++++++++++++++++++++++++++++++++++++++++-
 src/scanner.l      |  2 +-
 6 files changed, 59 insertions(+), 8 deletions(-)
doc/nft.xml +8 -3
index d51876c..4ede9e1 100644
@@ -1337,9 +1337,9 @@ filter output oif eth0
 								<entry>integer (4 bit) FIXME scaling</entry>
 							</row>
 							<row>
-								<entry>tos</entry>
-								<entry>Type Of Service</entry>
-								<entry>FIXME</entry>
+								<entry>dscp</entry>
+								<entry>Differentiated Services Code Point</entry>
+								<entry>integer (6 bit)</entry>
 							</row>
 							<row>
 								<entry>length</entry>
@@ -1421,6 +1421,11 @@ filter output oif eth0
 								<entry></entry>
 							</row>
 							<row>
+								<entry>dscp</entry>
+								<entry>Differentiated Services Code Point</entry>
+								<entry>integer (6 bit)</entry>
+							</row>
+							<row>
 								<entry>flowlabel</entry>
 								<entry>Flow label</entry>
 								<entry></entry>
include/datatype.h +2 -0
index 07fedce..328e12a 100644
@@ -40,6 +40,7 @@
  * @TYPE_ICMPV6_CODE:	icmpv6 code (integer subtype)
  * @TYPE_ICMPX_CODE:	icmpx code (integer subtype)
  * @TYPE_DEVGROUP:	devgroup code (integer subtype)
+ * @TYPE_DSCP:		Differentiated Services Code Point (integer subtype)
  */
 enum datatypes {
 	TYPE_INVALID,
@@ -78,6 +79,7 @@ enum datatypes {
 	TYPE_ICMPV6_CODE,
 	TYPE_ICMPX_CODE,
 	TYPE_DEVGROUP,
+	TYPE_DSCP,
 	__TYPE_MAX
 };
 #define TYPE_MAX		(__TYPE_MAX - 1)
include/proto.h +2 -1
index a43bf98..41af0c1 100644
@@ -176,7 +176,7 @@ enum ip_hdr_fields {
 	IPHDR_INVALID,
 	IPHDR_VERSION,
 	IPHDR_HDRLENGTH,
-	IPHDR_TOS,
+	IPHDR_DSCP,
 	IPHDR_LENGTH,
 	IPHDR_ID,
 	IPHDR_FRAG_OFF,
@@ -214,6 +214,7 @@ enum ip6_hdr_fields {
 	IP6HDR_INVALID,
 	IP6HDR_VERSION,
 	IP6HDR_PRIORITY,
+	IP6HDR_DSCP,
 	IP6HDR_FLOWLABEL,
 	IP6HDR_LENGTH,
 	IP6HDR_NEXTHDR,
src/parser_bison.y +3 -2
index e72d24d..7a5d7f8 100644
@@ -246,7 +246,7 @@ static void location_update(struct location *loc, struct location *rhs, int n)
 %token IP			"ip"
 %token HDRVERSION		"version"
 %token HDRLENGTH		"hdrlength"
-%token TOS			"tos"
+%token DSCP			"dscp"
 %token LENGTH			"length"
 %token FRAG_OFF			"frag-off"
 %token TTL			"ttl"
@@ -2172,7 +2172,7 @@ ip_hdr_expr		:	IP	ip_hdr_field
 
 ip_hdr_field		:	HDRVERSION	{ $$ = IPHDR_VERSION; }
 			|	HDRLENGTH	{ $$ = IPHDR_HDRLENGTH; }
-			|	TOS		{ $$ = IPHDR_TOS; }
+			|	DSCP		{ $$ = IPHDR_DSCP; }
 			|	LENGTH		{ $$ = IPHDR_LENGTH; }
 			|	ID		{ $$ = IPHDR_ID; }
 			|	FRAG_OFF	{ $$ = IPHDR_FRAG_OFF; }
@@ -2219,6 +2219,7 @@ ip6_hdr_expr		:	IP6	ip6_hdr_field
 
 ip6_hdr_field		:	HDRVERSION	{ $$ = IP6HDR_VERSION; }
 			|	PRIORITY	{ $$ = IP6HDR_PRIORITY; }
+			|	DSCP		{ $$ = IP6HDR_DSCP; }
 			|	FLOWLABEL	{ $$ = IP6HDR_FLOWLABEL; }
 			|	LENGTH		{ $$ = IP6HDR_LENGTH; }
 			|	NEXTHDR		{ $$ = IP6HDR_NEXTHDR; }
src/proto.c +43 -1

66 lines not on this page · raw message

src/scanner.l +1 -1
index 04fddc9..cb7ec4c 100644
@@ -361,7 +361,7 @@ addrstring	({macaddr}|{ip4addr}|{ip6addr})
 "ip"			{ return IP; }
 "version"		{ return HDRVERSION; }
 "hdrlength"		{ return HDRLENGTH; }
-"tos"			{ return TOS; }
+"dscp"			{ return DSCP; }
 "length"		{ return LENGTH; }
 "frag-off"		{ return FRAG_OFF; }
 "ttl"			{ return TTL; }
Signature · 1 line
2.1.4
author maintainer
#1 lore raw

PATCH 2/2 src: add ecn support

This supports both IPv4:

 # nft --debug=netlink add rule ip filter forward ip ecn ce counter
 ip filter forward
  [ payload load 1b @ network header + 1 => reg 1 ]
  [ bitwise reg 1 = (reg=1 & 0x000000c0 ) ^ 0x00000000 ]
  [ cmp eq reg 1 0x000000c0 ]
  [ counter pkts 0 bytes 0 ]

For IPv6:

 # nft --debug=netlink add rule ip6 filter forward ip6 ecn ce counter
 ip6 filter forward
  [ payload load 1b @ network header + 1 => reg 1 ]
  [ bitwise reg 1 = (reg=1 & 0x000000c0 ) ^ 0x00000000 ]
  [ cmp eq reg 1 0x000000c0 ]
  [ counter pkts 0 bytes 0 ]
---
 doc/nft.xml        | 10 ++++++++++
 include/datatype.h |  1 +
 include/proto.h    |  2 ++
 src/parser_bison.y |  3 +++
 src/proto.c        | 24 ++++++++++++++++++++++++
 src/scanner.l      |  1 +
 6 files changed, 41 insertions(+)
doc/nft.xml +10 -0
index 4ede9e1..1bce4b3 100644
@@ -1342,6 +1342,11 @@ filter output oif eth0
 								<entry>integer (6 bit)</entry>
 							</row>
 							<row>
+								<entry>ecn</entry>
+								<entry>Explicit Congestion Notification</entry>
+								<entry>integer (2 bit)</entry>
+							</row>
+							<row>
 								<entry>length</entry>
 								<entry>Total packet length</entry>
 								<entry>integer (16 bit)</entry>
@@ -1426,6 +1431,11 @@ filter output oif eth0
 								<entry>integer (6 bit)</entry>
 							</row>
 							<row>
+								<entry>ecn</entry>
+								<entry>Explicit Congestion Notification</entry>
+								<entry>integer (2 bit)</entry>
+							</row>
+							<row>
 								<entry>flowlabel</entry>
 								<entry>Flow label</entry>
 								<entry></entry>
include/datatype.h +1 -0
index 328e12a..31925b4 100644
@@ -80,6 +80,7 @@ enum datatypes {
 	TYPE_ICMPX_CODE,
 	TYPE_DEVGROUP,
 	TYPE_DSCP,
+	TYPE_ECN,
 	__TYPE_MAX
 };
 #define TYPE_MAX		(__TYPE_MAX - 1)
include/proto.h +2 -0
index 41af0c1..914c292 100644
@@ -177,6 +177,7 @@ enum ip_hdr_fields {
 	IPHDR_VERSION,
 	IPHDR_HDRLENGTH,
 	IPHDR_DSCP,
+	IPHDR_ECN,
 	IPHDR_LENGTH,
 	IPHDR_ID,
 	IPHDR_FRAG_OFF,
@@ -215,6 +216,7 @@ enum ip6_hdr_fields {
 	IP6HDR_VERSION,
 	IP6HDR_PRIORITY,
 	IP6HDR_DSCP,
+	IP6HDR_ECN,
 	IP6HDR_FLOWLABEL,
 	IP6HDR_LENGTH,
 	IP6HDR_NEXTHDR,
src/parser_bison.y +3 -0
index 7a5d7f8..67c6009 100644
@@ -247,6 +247,7 @@ static void location_update(struct location *loc, struct location *rhs, int n)
 %token HDRVERSION		"version"
 %token HDRLENGTH		"hdrlength"
 %token DSCP			"dscp"
+%token ECN			"ecn"
 %token LENGTH			"length"
 %token FRAG_OFF			"frag-off"
 %token TTL			"ttl"
@@ -2173,6 +2174,7 @@ ip_hdr_expr		:	IP	ip_hdr_field
 ip_hdr_field		:	HDRVERSION	{ $$ = IPHDR_VERSION; }
 			|	HDRLENGTH	{ $$ = IPHDR_HDRLENGTH; }
 			|	DSCP		{ $$ = IPHDR_DSCP; }
+			|	ECN		{ $$ = IPHDR_ECN; }
 			|	LENGTH		{ $$ = IPHDR_LENGTH; }
 			|	ID		{ $$ = IPHDR_ID; }
 			|	FRAG_OFF	{ $$ = IPHDR_FRAG_OFF; }
@@ -2220,6 +2222,7 @@ ip6_hdr_expr		:	IP6	ip6_hdr_field
 ip6_hdr_field		:	HDRVERSION	{ $$ = IP6HDR_VERSION; }
 			|	PRIORITY	{ $$ = IP6HDR_PRIORITY; }
 			|	DSCP		{ $$ = IP6HDR_DSCP; }
+			|	ECN		{ $$ = IP6HDR_ECN; }
 			|	FLOWLABEL	{ $$ = IP6HDR_FLOWLABEL; }
 			|	LENGTH		{ $$ = IP6HDR_LENGTH; }
 			|	NEXTHDR		{ $$ = IP6HDR_NEXTHDR; }
src/proto.c +24 -0
index 0e5932d..a1f5e75 100644
@@ -523,6 +523,27 @@ static const struct datatype dscp_type = {
 	.sym_tbl	= &dscp_type_tbl,
 };
 
+static const struct symbol_table ecn_type_tbl = {
+	.symbols	= {
+		SYMBOL("non-ect",	0x00),
+		SYMBOL("ect1",		0x01),
+		SYMBOL("ect0",		0x02),
+		SYMBOL("ce",		0x03),
+		SYMBOL_LIST_END
+	},
+};
+
+static const struct datatype ecn_type = {
+	.type		= TYPE_ECN,
+	.name		= "ecn_type",
+	.desc		= "explicit congestion notification",
+	.byteorder	= BYTEORDER_BIG_ENDIAN,
+	.size		= 2,
+	.basetype	= &integer_type,
+	.basefmt	= "0x%.1Zx",
+	.sym_tbl	= &ecn_type_tbl,
+};
+
 #define IPHDR_FIELD(__name, __member) \
 	HDR_FIELD(__name, struct iphdr, __member)
 #define IPHDR_ADDR(__name, __member) \
@@ -547,6 +568,7 @@ const struct proto_desc proto_ip = {
 		[IPHDR_VERSION]		= HDR_BITFIELD("version", &integer_type, 4, 4),
 		[IPHDR_HDRLENGTH]	= HDR_BITFIELD("hdrlength", &integer_type, 0, 4),
 		[IPHDR_DSCP]		= HDR_BITFIELD("dscp", &dscp_type, 8, 6),
+		[IPHDR_ECN]		= HDR_BITFIELD("ecn", &ecn_type, 14, 2),
 		[IPHDR_LENGTH]		= IPHDR_FIELD("length",		tot_len),
 		[IPHDR_ID]		= IPHDR_FIELD("id",		id),
 		[IPHDR_FRAG_OFF]	= IPHDR_FIELD("frag-off",	frag_off),
@@ -645,6 +667,7 @@ const struct proto_desc proto_ip6 = {
 		[IP6HDR_VERSION]	= HDR_BITFIELD("version", &integer_type, 0, 4),
 		[IP6HDR_PRIORITY]	= HDR_BITFIELD("priority", &integer_type, 4, 4),
 		[IP6HDR_DSCP]		= HDR_BITFIELD("dscp", &dscp_type, 8, 6),
+		[IP6HDR_ECN]		= HDR_BITFIELD("ecn", &ecn_type, 14, 2),
 		[IP6HDR_FLOWLABEL]	= IP6HDR_FIELD("flowlabel",	flow_lbl),
 		[IP6HDR_LENGTH]		= IP6HDR_FIELD("length",	payload_len),
 		[IP6HDR_NEXTHDR]	= INET_PROTOCOL("nexthdr", struct ipv6hdr, nexthdr),
@@ -850,4 +873,5 @@ static void __init proto_init(void)
 	datatype_register(&ethertype_type);
 	datatype_register(&icmp6_type_type);
 	datatype_register(&dscp_type);
+	datatype_register(&ecn_type);
 }
src/scanner.l +1 -0
index cb7ec4c..54063bf 100644
@@ -362,6 +362,7 @@ addrstring	({macaddr}|{ip4addr}|{ip6addr})
 "version"		{ return HDRVERSION; }
 "hdrlength"		{ return HDRLENGTH; }
 "dscp"			{ return DSCP; }
+"ecn"			{ return ECN; }
 "length"		{ return LENGTH; }
 "frag-off"		{ return FRAG_OFF; }
 "ttl"			{ return TTL; }
Signature · 1 line
2.1.4
#2 lore raw

Re: [PATCH nft 2/2] src: add ecn support

src/proto.c static const struct datatype dscp_type = { · line 526

Quoted 9 lines · Pablo Neira Ayuso
src/proto.c +4 -0
index 0e5932d..a1f5e75 100644
@@ -523,6 +523,27 @@ static const struct datatype dscp_type = {
+...
+static const struct datatype ecn_type = {
+	.type		= TYPE_ECN,
+	.name		= "ecn_type",

Same here (_type).

Otherwise looks good to me, thanks.

#3 lore raw
In reply to Pablo Neira Ayuso

include/proto.h enum ip_hdr_fields { · line 179

Quoted 11 lines · Pablo Neira Ayuso

#define TYPE_MAX (__TYPE_MAX - 1)

include/proto.h +1 -1
index a43bf98..41af0c1 100644
@@ -176,7 +176,7 @@ enum ip_hdr_fields {
 	IPHDR_INVALID,
 	IPHDR_VERSION,
 	IPHDR_HDRLENGTH,
-	IPHDR_TOS,
+	IPHDR_DSCP,

Shouldn't we keep both? I think it should work to do that or at least not be difficult to make it work.

src/proto.c const struct proto_desc proto_sctp = { · line 517

Quoted 8 lines
src/proto.c +3 -0
index 28b93cb..0e5932d 100644
...
+static const struct datatype dscp_type = {
+	.type		= TYPE_DSCP,
+	.name		= "dscp_type",

We usually only add a _type suffix if that's really a part of the name, pkt dccp_pkttype.

author maintainer
#4 lore raw
Quoted 15 lines · Patrick McHardy

include/proto.h enum ip_hdr_fields { · line 179

Quoted 11 lines · Pablo Neira Ayuso

#define TYPE_MAX (__TYPE_MAX - 1)

include/proto.h +1 -1
index a43bf98..41af0c1 100644
@@ -176,7 +176,7 @@ enum ip_hdr_fields {
 	IPHDR_INVALID,
 	IPHDR_VERSION,
 	IPHDR_HDRLENGTH,
-	IPHDR_TOS,
+	IPHDR_DSCP,

Shouldn't we keep both? I think it should work to do that or at least not be difficult to make it work.

Last time we discussed this, people arised concerns related to the fact that this is obsolete, and nobody should be using this these days.

https://patchwork.ozlabs.org/patch/352016/

#5 lore raw
Quoted 17 lines · Pablo Neira Ayuso
Quoted 15 lines · Patrick McHardy

include/proto.h enum ip_hdr_fields { · line 179

Quoted 11 lines · Pablo Neira Ayuso

#define TYPE_MAX (__TYPE_MAX - 1)

include/proto.h +1 -1
index a43bf98..41af0c1 100644
@@ -176,7 +176,7 @@ enum ip_hdr_fields {
 	IPHDR_INVALID,
 	IPHDR_VERSION,
 	IPHDR_HDRLENGTH,
-	IPHDR_TOS,
+	IPHDR_DSCP,

Shouldn't we keep both? I think it should work to do that or at least not be difficult to make it work.

Quoted 3 lines

Last time we discussed this, people arised concerns related to the fact that this is obsolete, and nobody should be using this these days.

I don't really buy into these arguments. We support lots of obsolete things, the fact is that even though it is obsoleted, it still exists and for old devices might even be the only thing they support.

author maintainer
#6 lore raw
Quoted 18 lines · Patrick McHardy
Quoted 17 lines · Pablo Neira Ayuso
Quoted 15 lines · Patrick McHardy

include/proto.h enum ip_hdr_fields { · line 179

Quoted 11 lines · Pablo Neira Ayuso

#define TYPE_MAX (__TYPE_MAX - 1)

include/proto.h +1 -1
index a43bf98..41af0c1 100644
@@ -176,7 +176,7 @@ enum ip_hdr_fields {
 	IPHDR_INVALID,
 	IPHDR_VERSION,
 	IPHDR_HDRLENGTH,
-	IPHDR_TOS,
+	IPHDR_DSCP,

Shouldn't we keep both? I think it should work to do that or at least not be difficult to make it work.

Quoted 7 lines
Quoted 3 lines

Last time we discussed this, people arised concerns related to the fact that this is obsolete, and nobody should be using this these days.

I don't really buy into these arguments. We support lots of obsolete things, the fact is that even though it is obsoleted, it still exists and for old devices might even be the only thing they support.

ToS breaks useful things like ECN, and the more I keep reading docs on the Internet, the more problem I have to see how the user can benefit from this.

#7 lore raw
Quoted 23 lines · Pablo Neira Ayuso
Quoted 22 lines · Patrick McHardy
Quoted 20 lines · Pablo Neira Ayuso
Quoted 15 lines · Patrick McHardy

include/proto.h enum ip_hdr_fields { · line 179

Quoted 11 lines · Pablo Neira Ayuso

#define TYPE_MAX (__TYPE_MAX - 1)

include/proto.h +1 -1
index a43bf98..41af0c1 100644
@@ -176,7 +176,7 @@ enum ip_hdr_fields {
 	IPHDR_INVALID,
 	IPHDR_VERSION,
 	IPHDR_HDRLENGTH,
-	IPHDR_TOS,
+	IPHDR_DSCP,

Shouldn't we keep both? I think it should work to do that or at least not be difficult to make it work.

Last time we discussed this, people arised concerns related to the fact that this is obsolete, and nobody should be using this these days.

Quoted 7 lines
Quoted 3 lines

I don't really buy into these arguments. We support lots of obsolete things, the fact is that even though it is obsoleted, it still exists and for old devices might even be the only thing they support.

ToS breaks useful things like ECN, and the more I keep reading docs on the Internet, the more problem I have to see how the user can benefit from this.

We *match* on ToS, that cannot possibly break anything. Also I'm unsure how this could break ECN even otherwise, ToS does not even use the ECN bits.

Its quite simple, if the user has old devices that set ToS values, he will be able to match on that without manually converting it to DSCP values. Given that our current tos definition is also not to practical for that since its too broad, I don't really care that much, although I think it should rather be fixed than simply thrown out.

author maintainer
#8 lore raw
Quoted 28 lines · Patrick McHardy
Quoted 27 lines · Pablo Neira Ayuso
Quoted 25 lines · Patrick McHardy
Quoted 17 lines · Pablo Neira Ayuso
Quoted 15 lines · Patrick McHardy

include/proto.h enum ip_hdr_fields { · line 179

Quoted 11 lines · Pablo Neira Ayuso

#define TYPE_MAX (__TYPE_MAX - 1)

include/proto.h +1 -1
index a43bf98..41af0c1 100644
@@ -176,7 +176,7 @@ enum ip_hdr_fields {
 	IPHDR_INVALID,
 	IPHDR_VERSION,
 	IPHDR_HDRLENGTH,
-	IPHDR_TOS,
+	IPHDR_DSCP,

Shouldn't we keep both? I think it should work to do that or at least not be difficult to make it work.

Quoted 3 lines

Last time we discussed this, people arised concerns related to the fact that this is obsolete, and nobody should be using this these days.

I don't really buy into these arguments. We support lots of obsolete things, the fact is that even though it is obsoleted, it still exists and for old devices might even be the only thing they support.

Quoted 6 lines
Quoted 3 lines

ToS breaks useful things like ECN, and the more I keep reading docs on the Internet, the more problem I have to see how the user can benefit from this.

We *match* on ToS, that cannot possibly break anything. Also I'm unsure how this could break ECN even otherwise, ToS does not even use the ECN bits.

ToS bits overlap with ECN bits, from that original ToS 8 bit-field now we use 6 bit for DSCP and 2 bits for ECN.

Quoted 5 lines

Its quite simple, if the user has old devices that set ToS values, he will be able to match on that without manually converting it to DSCP values. Given that our current tos definition is also not to practical for that since its too broad, I don't really care that much, although I think it should rather be fixed than simply thrown out.

People that designed DSCP and ECN did not care about having some reasonable backward compatible behaviour wrt. ToS. They just changed the semantics of those bits long time ago.

I can explore keeping this backward if you like, we can probably accept ToS from the parser, then map it to DSCP, but that will no achieve what the user expected on the network. I'm usually reticent to break old stuff, but in this case I would skip.

Cheers,
Pablo

#9 lore raw
Quoted 9 lines · Pablo Neira Ayuso
Quoted 6 lines
Quoted 3 lines

ToS breaks useful things like ECN, and the more I keep reading docs on the Internet, the more problem I have to see how the user can benefit from this.

We *match* on ToS, that cannot possibly break anything. Also I'm unsure how this could break ECN even otherwise, ToS does not even use the ECN bits.

ToS bits overlap with ECN bits, from that original ToS 8 bit-field now we use 6 bit for DSCP and 2 bits for ECN.

Sure, but our ToS definition is wrong anyway, the ToS-bits are actually 3 + 3 + 2 unused bits (ECN).

Quoted 6 lines
Quoted 5 lines

Its quite simple, if the user has old devices that set ToS values, he will be able to match on that without manually converting it to DSCP values. Given that our current tos definition is also not to practical for that since its too broad, I don't really care that much, although I think it should rather be fixed than simply thrown out.

Quoted 8 lines

People that designed DSCP and ECN did not care about having some reasonable backward compatible behaviour wrt. ToS. They just changed the semantics of those bits long time ago.

I can explore keeping this backward if you like, we can probably accept ToS from the parser, then map it to DSCP, but that will no achieve what the user expected on the network. I'm usually reticent to break old stuff, but in this case I would skip.

My thought was more fixing our ToS field definition, at that point the user can use whatever is actually used within his network. I mean, sure, you can map them to DSCP, but if you're using old devices that only support the ToS definitions its a lot easier to use the same values instead of mapping them.

I don't know. I think it should be fairly easy to fix, so I'd prefer that way I guess. Your choice.

author maintainer
#10 lore raw
Quoted 5 lines · Patrick McHardy
Quoted 4 lines · Pablo Neira Ayuso
Quoted 4 lines
Quoted 3 lines

ToS breaks useful things like ECN, and the more I keep reading docs on the Internet, the more problem I have to see how the user can benefit from this.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

We *match* on ToS, that cannot possibly break anything. Also I'm unsure how this could break ECN even otherwise, ToS does not even use the ECN bits.

ToS bits overlap with ECN bits, from that original ToS 8 bit-field now we use 6 bit for DSCP and 2 bits for ECN.

Sure, but our ToS definition is wrong anyway, the ToS-bits are actually 3 + 3 + 2 unused bits (ECN).

That's right according to the original ToS definition, but looking a bit further on the RFCs, someone outthere extended this, so I found this:

See 22. Historical Definitions for the IPv4 TOS Octet from
https://tools.ietf.org/html/rfc3168.

It refers to https://tools.ietf.org/html/rfc1349 that defines Minimize Monetary Cost TOS Value and it extends it to one extra bit (from 3 to 4, scratching one from the unused bits).

Bottom line says "Because of this unstable history, the definition of the ECN field in this document cannot be guaranteed to be backwards compatible with all past uses of these two bits."

Anyway, looking at the Linux header definitions, we have the

#define IPTOS_MINCOST 0x02

The mincost thing is there.

#define IPTOS_TOS_MASK 0x1E
#define IPTOS_TOS(tos) ((tos)&IPTOS_TOS_MASK)

So it seems our headers are considering ToS is 4 bits too.

Cheers,
Pablo

#11 lore raw
Quoted 32 lines · Pablo Neira Ayuso
Quoted 5 lines · Patrick McHardy
Quoted 4 lines · Pablo Neira Ayuso
Quoted 4 lines
Quoted 3 lines

ToS breaks useful things like ECN, and the more I keep reading docs on the Internet, the more problem I have to see how the user can benefit from this.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

We *match* on ToS, that cannot possibly break anything. Also I'm unsure how this could break ECN even otherwise, ToS does not even use the ECN bits.

ToS bits overlap with ECN bits, from that original ToS 8 bit-field now we use 6 bit for DSCP and 2 bits for ECN.

Sure, but our ToS definition is wrong anyway, the ToS-bits are actually 3 + 3 + 2 unused bits (ECN).

That's right according to the original ToS definition, but looking a bit further on the RFCs, someone outthere extended this, so I found this:

See 22. Historical Definitions for the IPv4 TOS Octet from
https://tools.ietf.org/html/rfc3168.

It refers to https://tools.ietf.org/html/rfc1349 that defines Minimize Monetary Cost TOS Value and it extends it to one extra bit (from 3 to 4, scratching one from the unused bits).

Bottom line says "Because of this unstable history, the definition of the ECN field in this document cannot be guaranteed to be backwards compatible with all past uses of these two bits."

Anyway, looking at the Linux header definitions, we have the

Quoted 8 lines

#define IPTOS_MINCOST 0x02

The mincost thing is there.

#define IPTOS_TOS_MASK 0x1E
#define IPTOS_TOS(tos) ((tos)&IPTOS_TOS_MASK)

So it seems our headers are considering ToS is 4 bits too.

Hmm Ok its really a mess. Let's get rid of it for now and we might reconsider if a user turns up that can make a valid case.

#12 lore raw
In reply to Patrick McHardy
Quoted 15 lines · Patrick McHardy

include/proto.h enum ip_hdr_fields { · line 179

Quoted 11 lines · Pablo Neira Ayuso

#define TYPE_MAX (__TYPE_MAX - 1)

include/proto.h +1 -1
index a43bf98..41af0c1 100644
@@ -176,7 +176,7 @@ enum ip_hdr_fields {
 	IPHDR_INVALID,
 	IPHDR_VERSION,
 	IPHDR_HDRLENGTH,
-	IPHDR_TOS,
+	IPHDR_DSCP,

Shouldn't we keep both?

Quoted 1 line

From what I read from RFC 2474, DSCP is the 6-bit portion.

The 8-bit field is known as
(a) TOS per IPv4 RFC
(b) TC (Traffic Class) per IPv6 RFC 2460
(c) DS per RFC 2472

I would therefore recommend against IPHDR_DSCP, and instead go with either of IPHDR_TOS, IPHDR_DS, IPHDR_DIFFSERV, or even some mnemonic involving traffic class.

#13 lore raw
Quoted 18 lines · Jan Engelhardt
Quoted 15 lines · Patrick McHardy

include/proto.h enum ip_hdr_fields { · line 179

Quoted 11 lines · Pablo Neira Ayuso

#define TYPE_MAX (__TYPE_MAX - 1)

include/proto.h +1 -1
index a43bf98..41af0c1 100644
@@ -176,7 +176,7 @@ enum ip_hdr_fields {
 	IPHDR_INVALID,
 	IPHDR_VERSION,
 	IPHDR_HDRLENGTH,
-	IPHDR_TOS,
+	IPHDR_DSCP,

Shouldn't we keep both?

Quoted 1 line

From what I read from RFC 2474, DSCP is the 6-bit portion.

Quoted 8 lines

The 8-bit field is known as
(a) TOS per IPv4 RFC
(b) TC (Traffic Class) per IPv6 RFC 2460
(c) DS per RFC 2472

I would therefore recommend against IPHDR_DSCP, and instead go with either of IPHDR_TOS, IPHDR_DS, IPHDR_DIFFSERV, or even some mnemonic involving traffic class.

But we actually do refer to the 6 bit sub-field and the further 2 bit ECN sub-field, they are seperate fields with Pablo's patch.