evaluate: set key byteorder when evaluating mapping
Pablo Neira Ayuso
maintainerPATCH 1/1 evaluate: set key byteorder when evaluating mapping
set->key->dtype is TYPE_INTEGER (see integer_type definition) which uses BYTEORDER_INVALID by default, this is used to set up the context for parsing the symbols in the mapping. Set explicit byteorder context to address this bug.
Fixes 144d97e151adb ("src: normalize set element with EXPR_MAPPING")
Reported-by Phil Sutter <[email protected]>
Signed-off-by Pablo Neira Ayuso <[email protected]>
--- src/evaluate.c | 3 +- .../maps/dumps/nat_addr_port.json-nft | 134 ++++++++++++++++++ .../testcases/maps/dumps/nat_addr_port.nft | 18 +++ tests/shell/testcases/maps/nat_addr_port | 12 ++ 4 files changed, 166 insertions(+), 1 deletion(-)
src/evaluate.c +2 -1
@@ -2393,7 +2393,8 @@ static int expr_evaluate_mapping(struct eval_ctx *ctx, struct expr **expr)if (!set_is_map (set->flags))return set_error (ctx, set,"set is not a map" ); -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 ); + ctx->ectx.key = key;if (expr_evaluate (ctx, &mapping->left) <0 )
tests/shell/testcases/maps/dumps/nat_addr_port.json-nft +134 -0
158 lines not on this page · raw message
tests/shell/testcases/maps/dumps/nat_addr_port.nft +18 -0
@@ -7,6 +7,14 @@ table ip ipfoo { typeof numgen inc mod 2 : ip daddr . tcp dport } + map w { + typeof numgen inc mod 3 : meta mark + elements = { 0 : 0x00000009, + 1 : 0x00000008, + 2 : 0x00000007, + 3 : 0x00000006 } + } + map x { type ipv4_addr : ipv4_addr }
@@ -32,6 +40,7 @@ table ip ipfoo { meta l4proto 6 dnat to 10.2.3.4:4242 dnat to numgen inc mod 2 map @t1 meta l4proto 6 dnat ip to numgen inc mod 2 map @t2 + meta mark set numgen inc mod 2000 map @w } } table ip6 ip6foo {
@@ -43,6 +52,14 @@ table ip6 ip6foo { typeof numgen inc mod 2 : ip6 daddr . tcp dport } + map w { + typeof numgen inc mod 3 : meta mark + elements = { 0 : 0x00000009, + 1 : 0x00000008, + 2 : 0x00000007, + 3 : 0x00000006 } + } + map x { type ipv6_addr : ipv6_addr }
@@ -66,6 +83,7 @@ table ip6 ip6foo { meta l4proto 6 dnat to [fd00:10:244::4]:6443 dnat to numgen inc mod 2 map @t1 meta l4proto 6 dnat ip6 to numgen inc mod 2 map @t2 + meta mark set numgen inc mod 2000 map @w } } table inet inetfoo {
tests/shell/testcases/maps/nat_addr_port +12 -0
@@ -11,6 +11,11 @@ table ip ipfoo { typeof numgen inc mod 2 : ip daddr . tcp dport } + map w { + typeof numgen inc mod 3 : meta mark + elements = { 0 : 9, 1 : 8, 2 : 7, 3 : 6 } + } + map x { type ipv4_addr : ipv4_addr }
@@ -34,6 +39,7 @@ table ip ipfoo { meta l4proto tcp dnat ip addr . port to 10.2.3.4 . 4242 dnat ip to numgen inc mod 2 map @t1 meta l4proto tcp dnat ip addr . port to numgen inc mod 2 map @t2 + meta mark set numgen inc mod 2000 map @w } } EOF
@@ -55,6 +61,11 @@ table ip6 ip6foo { typeof numgen inc mod 2 : ip6 daddr . tcp dport } + map w { + typeof numgen inc mod 3 : meta mark + elements = { 0 : 9, 1 : 8, 2 : 7, 3 : 6 } + } + map x { type ipv6_addr : ipv6_addr }
@@ -76,6 +87,7 @@ table ip6 ip6foo { meta l4proto tcp dnat ip6 addr . port to fd00:10:244::4 . 6443 dnat ip6 to numgen inc mod 2 map @t1 meta l4proto tcp dnat ip6 addr . port to numgen inc mod 2 map @t2 + meta mark set numgen inc mod 2000 map @w } } EOF
Signature · 1 line
2.47.3
Quoted 8 lines · Pablo Neira Ayuso
set->key->dtypeisTYPE_INTEGER(seeinteger_typedefinition) which usesBYTEORDER_INVALIDby default, this is used to set up the context for parsing the symbols in the mapping. Set explicit byteorder context to address this bug.Fixes 144d97e151adb ("src: normalize set element with EXPR_MAPPING")Reported-by Phil Sutter <[email protected]>Signed-off-by Pablo Neira Ayuso <[email protected]>
Tested-by Phil Sutter <[email protected]>
Thanks for the quick fix, Pablo!