Issues with nft typeof
Hi,
I've been playing around with typeof support (on 2885cf2e on 5.4 kernel) and came across the following issues:
Quoted 3 lines
nft add table bridge t
nft set bridge t s3 '{typeof meta ibrpvid; elements = { 2, 3, 103 }; }' nft list ruleset
On an embedded system (openwrt on ppc) with kernel 5.4, this results in
table bridge t {
set s3 {
typeof meta ibrpvid
elements = { 2, 3, 103 }
}
}But on buster-backports kernel 5.4 (x86_64), this results in
table bridge t {
set s3 {
typeof meta ibrpvid
elements = { 512, 768, 26368 }
}
}Which is strange and not correct. It also happens with v0.9.4. Debug output on x86_64 Machine:
Quoted 1 line
nft --debug=netlink set bridge t s3 '{typeof meta ibrpvid; elements = { 2, 3, 103 }; }'
(null) (null) 0
s3 t 0
element 00000200 : 0 [end] element 00000300 : 0 [end]
element 00006700 : 0 [end]
Debug output on openwrt machine (ppc):
Quoted 1 line
nft --debug=netlink set bridge t s3 '{typeof meta ibrpvid; elements = { 2, 3, 103 }; }'
(null) (null) 0
s3 t 0
element 00020000 : 0 [end] element 00030000 : 0 [end]
element 00670000 : 0 [end]
So it looks like an endianess issue to me.
The nft set bridge output looks the same when using vlan id instead of meta ibrvpid. But nft list ruleset creates the correct output for vlan but not for meta ibrpvid.
x86_64 machine:
table bridge t {
set s3 {
typeof meta ibrpvid
elements = { 512, 768, 26368 }
}
set s4 {
typeof vlan id
elements = { 2, 3, 103 }
}
}OpenWRT machine (ppc):
table bridge t {
set s3 {
typeof meta ibrpvid
elements = { 2, 3, 103 }
}
set s4 {
typeof vlan id
elements = { 2, 3, 103 }
}
}So I'm unsure if this is a display error when reading back? Or is the wrong value written to the kernel?
Quoted 3 lines
nft add chain bridge t c3
nft add rule bridge t c3 'meta ibrpvid @s3 accept;' nft set bridge t s4 '{typeof vlan id . ip daddr; }'
Error: can not use variable sized data types (integer) in concat expressions set bridge t s4 {typeof vlan id . ip daddr; }
So while "typeof vlan id" and typeof with concatenations works, using both concatenation and vlan id does not.
Any hints here to start?
Regards,
Michael
Pablo Neira Ayuso
maintainerOn Tue, Apr 28, 2020 at 03:51:46PM +0200, michael-dev wrote:
[...]
Quoted 5 lines
table bridge t {
set s3 {
typeof meta ibrpvid
elements = { 2, 3, 103 }
}[...]
Quoted 4 lines
}
So I'm unsure if this is a display error when reading back? Or is the wrong value written to the kernel?
Looks like wrong value written to the kernel:
# nft --debug=netlink -f /tmp/x
s3 t 0
s3 t 0
element 00000100 : 0 [end] element 00000200 : 0 [end] element 00000300 : 0 [end]
^^^^^^^^That should be 00000001 instead.
where /tmp/x contains:
table ip t {
set s3 {
typeof meta ibrpvid
elements = { 1, 2, 3 }
}
}This seems to be related with the integer_type, that sets the byteorder to BYTEORDER_INVALID (which is implicitly handled as BYTEORDER_BIG_ENDIAN).
Could you give a try to the following patch?
If this works for you, I'd really appreciate if you could extend testcases/sets/typeof_sets_0 to include the 'meta ibrpvid' usecase above.
Thanks.
src/evaluate.c +2 -1
@@ -3544,7 +3544,8 @@ static int set_evaluate(struct eval_ctx *ctx, struct set *set) ctx->set = set;if (set->init !=NULL ) { -expr_set_context (&ctx->ectx, set->key->dtype, set->key->len); +__expr_set_context (&ctx->ectx, set->key->dtype, + set->key->byteorder, set->key->len,0 );if (expr_evaluate (ctx, &set->init) <0 )return -1 ; }
Pablo Neira Ayuso
maintainerQuoted 36 lines · Pablo Neira Ayuso
On Tue, Apr 28, 2020 at 03:51:46PM +0200, michael-dev wrote:
[...]Quoted 5 lines
table bridge t { set s3 { typeof meta ibrpvid elements = { 2, 3, 103 } }[...]
Quoted 4 lines
}
So I'm unsure if this is a display error when reading back? Or is the wrong value written to the kernel?
Looks like wrong value written to the kernel:
# nft --debug=netlink -f /tmp/x s3 t 0 s3 t 0 element 00000100 : 0 [end] element 00000200 : 0 [end] element 00000300 : 0 [end] ^^^^^^^^That should be 00000001 instead.
where
/tmp/xcontains:table ip t { set s3 { typeof meta ibrpvid elements = { 1, 2, 3 } } }This seems to be related with the
integer_type, that sets the byteorder toBYTEORDER_INVALID(which is implicitly handled asBYTEORDER_BIG_ENDIAN).
Quoted 5 lines
Could you give a try to the following patch?
If this works for you, I'd really appreciate if you could extend testcases/sets/typeof_sets_0 to include the 'meta ibrpvid' usecase above.
Already included the test update chunk in the patch that I have submitted, no worries:
https://patchwork.ozlabs.org/project/netfilter-devel/patch/[email protected]/
Thanks.
Am 29.04.2020 00:04, schrieb Pablo Neira Ayuso:
Quoted 1 line
Could you give a try to the following patch?
thanks, that fixes it for me.
Regards,
M. Braun