src: Add DSCP support in nftables
PATCH 2/2 src: Add DSCP support in nftables
From: Álvaro Neira Ayuso <[email protected]>
This patch allows to use DSCP support in nftables.
--- include/datatype.h | 2 ++ include/proto.h | 1 + src/parser.y | 2 ++ src/proto.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/scanner.l | 1 + 5 files changed, 79 insertions(+)
include/datatype.h +2 -0
@@ -36,6 +36,7 @@* @TYPE_ICMP6_TYPE: ICMPv6 type codes (integer subtype) * @TYPE_CT_LABEL: Conntrack Label (bitmask subtype) * @TYPE_TOS: Type of service (integer subtype) +* @TYPE_DSCP: Differentiated Services Field (integer subtype) */ enum datatypes {TYPE_INVALID ,
@@ -70,6 +71,7 @@ enum datatypes {TYPE_ICMP6_TYPE ,TYPE_CT_LABEL ,TYPE_TOS , +TYPE_DSCP , __TYPE_MAX };#define TYPE_MAX (__TYPE_MAX - 1)
include/proto.h +1 -0
@@ -169,6 +169,7 @@ enum ip_hdr_fields {IPHDR_INVALID ,IPHDR_VERSION ,IPHDR_HDRLENGTH , +IPHDR_DSCP ,IPHDR_TOS ,IPHDR_LENGTH , IPHDR_ID,
src/parser.y +2 -0
@@ -229,6 +229,7 @@ static void location_update(struct location *loc, struct location *rhs, int n) %token IP "ip" %token VERSION "version" %token HDRLENGTH "hdrlength" +%token DSCP "dscp" %token TOS "tos" %token LENGTH "length" %token FRAG_OFF "frag-off"
@@ -1793,6 +1794,7 @@ ip_hdr_expr : IP ip_hdr_field ip_hdr_field : VERSION { $$ = IPHDR_VERSION; } | HDRLENGTH { $$ = IPHDR_HDRLENGTH; } | TOS { $$ = IPHDR_TOS; } + | DSCP { $$ = IPHDR_DSCP; } | LENGTH { $$ = IPHDR_LENGTH; } | ID { $$ = IPHDR_ID; } | FRAG_OFF { $$ = IPHDR_FRAG_OFF; }
src/proto.c +73 -0
90 lines not on this page · raw message
src/scanner.l +1 -0
@@ -329,6 +329,7 @@ addrstring ({macaddr}|{ip4addr}|{ip6addr}) "ip" { return IP; } "version" { return VERSION; } "hdrlength" { return HDRLENGTH; } +"dscp" { return DSCP; } "tos" { return TOS; } "length" { return LENGTH; } "frag-off" { return FRAG_OFF; }
Signature · 6 lines
1.7.10.4 -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v2 1/1 src: Replace TOS support for using DSCP support
From: Álvaro Neira Ayuso <[email protected]>
---
[changes in v2]
* Replace TOS support for using DSCP support
Now, when we add a rule with DSCP, in the code generation step, nftables compares 1 bytes but it should compare 6 bits. I think that the problem should be in the code generation.
include/datatype.h | 2 ++ include/proto.h | 2 +- src/parser.y | 4 +-- src/proto.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++- src/scanner.l | 2 +- 5 files changed, 82 insertions(+), 5 deletions(-)
include/datatype.h +2 -0
@@ -35,6 +35,7 @@* @TYPE_CT_STATUS: conntrack status (bitmask subtype) * @TYPE_ICMP6_TYPE: ICMPv6 type codes (integer subtype) * @TYPE_CT_LABEL: Conntrack Label (bitmask subtype) +* @TYPE_DSCP: Differentiated Services Code Point (integer subtype) */ enum datatypes {TYPE_INVALID ,
@@ -68,6 +69,7 @@ enum datatypes {TYPE_CT_STATUS ,TYPE_ICMP6_TYPE ,TYPE_CT_LABEL , +TYPE_DSCP , __TYPE_MAX };#define TYPE_MAX (__TYPE_MAX - 1)
include/proto.h +1 -1
@@ -169,7 +169,7 @@ enum ip_hdr_fields {IPHDR_INVALID ,IPHDR_VERSION ,IPHDR_HDRLENGTH , -IPHDR_TOS , +IPHDR_DSCP ,IPHDR_LENGTH ,IPHDR_ID , IPHDR_FRAG_OFF,
src/parser.y +2 -2
@@ -229,7 +229,7 @@ static void location_update(struct location *loc, struct location *rhs, int n) %token IP "ip" %token VERSION "version" %token HDRLENGTH "hdrlength" -%token TOS "tos" +%token DSCP "dscp" %token LENGTH "length" %token FRAG_OFF "frag-off" %token TTL "ttl"
@@ -1792,7 +1792,7 @@ ip_hdr_expr : IP ip_hdr_field ip_hdr_field : VERSION { $$ = IPHDR_VERSION; } | HDRLENGTH { $$ = IPHDR_HDRLENGTH; } - | TOS { $$ = IPHDR_TOS; } + | DSCP { $$ = IPHDR_DSCP; } | LENGTH { $$ = IPHDR_LENGTH; } | ID { $$ = IPHDR_ID; } | FRAG_OFF { $$ = IPHDR_FRAG_OFF; }
src/proto.c +76 -1
97 lines not on this page · raw message
src/scanner.l +1 -1
@@ -329,7 +329,7 @@ addrstring ({macaddr}|{ip4addr}|{ip6addr}) "ip" { return IP; } "version" { return VERSION; } "hdrlength" { return HDRLENGTH; } -"tos" { return TOS; } +"dscp" { return DSCP; } "length" { return LENGTH; } "frag-off" { return FRAG_OFF; } "ttl" { return TTL; }
Signature · 6 lines
1.7.10.4 -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [nftables PATCH v2] src: Replace TOS support for using DSCP support
Quoted 10 lines · Alvaro Neira Ayuso
From: Álvaro Neira Ayuso <[email protected]>
Signed-off-by Alvaro Neira Ayuso <[email protected]>---
[changes in v2]
* Replace TOS support for using DSCP supportNow, when we add a rule with DSCP, in the code generation step, nftables compares 1 bytes but it should compare 6 bits. I think that the problem should be in the code generation.
I don't really see how this patch changes this. The kernel operates in units of bytes. For anything smaller nftables will have to generate appropriate bitwise operations. Please explain in more detail how this patch changes this.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [nftables PATCH v2] src: Replace TOS support for using DSCP support
Quoted 8 lines · Patrick McHardy
Quoted 7 lines · Alvaro Neira Ayuso
From: Álvaro Neira Ayuso <[email protected]>
Signed-off-by Alvaro Neira Ayuso <[email protected]>---
[changes in v2]
* Replace TOS support for using DSCP support
Quoted 8 lines
Quoted 3 lines
Now, when we add a rule with DSCP, in the code generation step, nftables compares 1 bytes but it should compare 6 bits. I think that the problem should be in the code generation.
I don't really see how this patch changes this. The kernel operates in units of bytes. For anything smaller nftables will have to generate appropriate bitwise operations. Please explain in more detail how this patch changes this.
Now, nothing. For that it's stopped. I'm working for doing a patch for operating in the kernel not only with units of bytes like you say. In a couple of days, I'm going to send it to the list.
Thanks for the review, Patrick
Álvaro
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Florian Westphal
maintainerRe: [nftables PATCH v2] src: Replace TOS support for using DSCP support
Quoted 4 lines · Álvaro Neira Ayuso
Quoted 4 lines
Quoted 3 lines
Now, when we add a rule with DSCP, in the code generation step, nftables compares 1 bytes but it should compare 6 bits. I think that the problem should be in the code generation.
Quoted 8 lines
Quoted 4 lines
I don't really see how this patch changes this. The kernel operates in units of bytes. For anything smaller nftables will have to generate appropriate bitwise operations. Please explain in more detail how this patch changes this.
Now, nothing. For that it's stopped. I'm working for doing a patch for operating in the kernel not only with units of bytes like you say. In a couple of days, I'm going to send it to the list.
Are you sure this is the right approach?
It might be better to create appropriate masking instructions in userspace, in most cases byte addressing is sufficient.
Something like this (warning: untested, misses 'reverse' mapping to remove the implicit bitops when listing rules):
http://git.breakpoint.cc/cgit/fw/nftables.git/commit/?h=payload_offset_04&id=76ac27643400111785a8abb21fdd9e4311d9876e
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [nftables PATCH v2] src: Replace TOS support for using DSCP support
Quoted 19 lines · Florian Westphal
Quoted 4 lines · Álvaro Neira Ayuso
Quoted 4 lines
Quoted 3 lines
Now, when we add a rule with DSCP, in the code generation step, nftables compares 1 bytes but it should compare 6 bits. I think that the problem should be in the code generation.
Quoted 8 lines
Quoted 4 lines
I don't really see how this patch changes this. The kernel operates in units of bytes. For anything smaller nftables will have to generate appropriate bitwise operations. Please explain in more detail how this patch changes this.
Now, nothing. For that it's stopped. I'm working for doing a patch for operating in the kernel not only with units of bytes like you say. In a couple of days, I'm going to send it to the list.
Are you sure this is the right approach?
It might be better to create appropriate masking instructions in userspace, in most cases byte addressing is sufficient.
Quoted 8 lines
Something like this (warning: untested, misses 'reverse' mapping to remove the implicit bitops when listing rules):
http://git.breakpoint.cc/cgit/fw/nftables.git/commit/?h=payload_offset_04&id=76ac27643400111785a8abb21fdd9e4311d9876e
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
I know very little about how nftables is actually implemented. That said:
The IPv6 TOS byte is actually half in one byte half in the next, as a result of which the 6 dscp bits are 4 bits of one byte and 2 bits of the next.
The IPv6 flowinfo field is similarly a 20 bit field 12 bits into the packet. The IPv4 fragment offset is 13 bits in size.
I wonder if for performance reasons the right answer isn't to allow a fetch N<=64 bits from bit offset M (M=0..inf) opcode as opposed to doing the masking by hand (perhaps require (M%8)+N<=64 as well). Perhaps it should also be capable of left shifting the result by K bits (to deal with fields - like the ipv4 header length field - which count dwords instead of bytes).
Theoretically with a sufficiently good jit compiler it shouldn't matter... but I'm assuming that's in the far future. (??)
I'm not sure if there should be multiple versions of this (little-endian vs big-endian, bit ordering...) or just the immediately useful ones (ie. network byte order).
- Maciej
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [nftables PATCH v2] src: Replace TOS support for using DSCP support
In reply to Florian WestphalQuoted 16 lines · Florian Westphal
Quoted 4 lines · Álvaro Neira Ayuso
Quoted 4 lines
Quoted 3 lines
Now, when we add a rule with DSCP, in the code generation step, nftables compares 1 bytes but it should compare 6 bits. I think that the problem should be in the code generation.
Quoted 8 lines
Quoted 4 lines
I don't really see how this patch changes this. The kernel operates in units of bytes. For anything smaller nftables will have to generate appropriate bitwise operations. Please explain in more detail how this patch changes this.
Now, nothing. For that it's stopped. I'm working for doing a patch for operating in the kernel not only with units of bytes like you say. In a couple of days, I'm going to send it to the list.
Are you sure this is the right approach?
Quoted 8 lines
It might be better to create appropriate masking instructions in userspace, in most cases byte addressing is sufficient.
Something like this (warning: untested, misses 'reverse' mapping to remove the implicit bitops when listing rules):
I have explained very bad. I'm working in a patch like you but I have done a different solution. I have done my solution in the evaluation. I have added a bitwise node in the tree when we evaluate the relational if we have a EXPR_PAYLOAD node in the left and when the size of this left node is not a multiple of BITS_PER_BYTE. And I have used the function mpz_prefixmask for doing the masks. The problem come when I have added a rule like:
nft add rule ip filter input ip frag-off != 0
The mask that we need to use for take the 13 bits for frag-off is like this:
|00052|N-|00002| |len |flags| type| |00008|--|00001| |len |flags| type| | 00 00 00 01 | | data | |00008|--|00002| |len |flags| type| | 00 00 00 01 | | data | |00008|--|00003| |len |flags| type| | 00 00 00 02 | | data | |00012|N-|00004| |len |flags| type| |00006|--|00001| |len |flags| type| | 1f ff 00 00 | | data |
The problem is when I have seen the mask of the bitwise in the kernel, I have seen that the mask is 0xff1f. I'm working for trying to fix that. I have thought that maybe was a problem that I have tried this rule without my patch and we have the same problem:
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html