mark statement support for non-constant expression
Pablo Neira Ayuso
maintainercover mark statement support for non-constant expression
Hi,
This patchset recovers the initial effort from Jeremy Sowden to enhance mark statement support for variable expression, eg. use an existing selector to set the meta and ct mark.
This also includes support for bitwise arithmetics, including shift operations.
Selectors in network byte order are turned into host byte order before the assignment to ensure ruleset portability.
No kernel updates are required in this batch.
Patches 1 to 5 are preparation work for patch 5, which finally adds support for mark statements compatibility with selectors using integer basetype:
Patch #1 provides a fix for missing byteorder conversion in network byteorder
field between 9 and 15 bytes such as ip6 dscp.
Patch #2 prepares for listing bitwise expression in hexadecimal, instead of
using symbolic values specific of the datatype of the expression.
Patch #3 upgrade length of shift to the mark statement size, to allow for
larger shift than the expression length.
Patch #4 remove redundant evaluation of unary expression arguments.
Patch #5 use length of mark statements for the bitwise expression, instead of
the length of the r-value expression.
Finally patch #6 allows for datatype compatibility between mark statements and rvalue expression of integer datatype. This includes byteorder compatibility conversion.
Patch 7 to 9 add more tests.
Jeremy Sowden (6):
evaluate: insert byte-order conversions for expressions between 9 and 15 bits
netlink_delinearize: correct type and byte-order of shifts
evaluate: support shifts larger than the width of the left operand
evaluate: don't eval unary arguments
tests: shell: rename and move bitwise test-cases
tests: shell: add test-cases for ct and packet mark payload expressions
Pablo Neira Ayuso (3):
evaluate: get length from statement instead of lhs expression
evaluate: relax type-checking for integer arguments in mark statements
tests: py: add test-cases for ct and packet mark payload expressions
src/evaluate.c | 46 +++++++----
src/netlink_delinearize.c | 17 +++-
tests/py/ip/ct.t | 2 +
tests/py/ip/ct.t.json | 58 ++++++++++++++
tests/py/ip/ct.t.payload | 18 +++++
tests/py/ip/meta.t | 5 ++
tests/py/ip/meta.t.json | 78 +++++++++++++++++++
tests/py/ip/meta.t.payload | 25 ++++++
tests/py/ip6/ct.t | 6 ++
tests/py/ip6/ct.t.payload | 19 +++++
tests/py/ip6/meta.t | 3 +
tests/py/ip6/meta.t.json | 58 ++++++++++++++
tests/py/ip6/meta.t.payload | 20 +++++
.../0040mark_binop_0} | 2 +-
.../0040mark_binop_1} | 2 +-
.../shell/testcases/bitwise/0040mark_binop_2 | 11 +++
.../shell/testcases/bitwise/0040mark_binop_3 | 11 +++
.../shell/testcases/bitwise/0040mark_binop_4 | 11 +++
.../shell/testcases/bitwise/0040mark_binop_5 | 11 +++
.../shell/testcases/bitwise/0040mark_binop_6 | 11 +++
.../shell/testcases/bitwise/0040mark_binop_7 | 11 +++
.../shell/testcases/bitwise/0040mark_binop_8 | 11 +++
.../shell/testcases/bitwise/0040mark_binop_9 | 11 +++
.../dumps/0040mark_binop_0.nft} | 2 +-
.../dumps/0040mark_binop_1.nft} | 2 +-
.../bitwise/dumps/0040mark_binop_2.nft | 6 ++
.../bitwise/dumps/0040mark_binop_3.nft | 6 ++
.../bitwise/dumps/0040mark_binop_4.nft | 6 ++
.../bitwise/dumps/0040mark_binop_5.nft | 6 ++
.../bitwise/dumps/0040mark_binop_6.nft | 6 ++
.../bitwise/dumps/0040mark_binop_7.nft | 6 ++
.../bitwise/dumps/0040mark_binop_8.nft | 6 ++
.../bitwise/dumps/0040mark_binop_9.nft | 6 ++
33 files changed, 474 insertions(+), 25 deletions(-)
create mode 100644 tests/py/ip6/ct.t
create mode 100644 tests/py/ip6/ct.t.payload
rename tests/shell/testcases/{chains/0040mark_shift_0 => bitwise/0040mark_binop_0} (68%)
rename tests/shell/testcases/{chains/0040mark_shift_1 => bitwise/0040mark_binop_1} (70%)
create mode 100755 tests/shell/testcases/bitwise/0040mark_binop_2
create mode 100755 tests/shell/testcases/bitwise/0040mark_binop_3
create mode 100755 tests/shell/testcases/bitwise/0040mark_binop_4
create mode 100755 tests/shell/testcases/bitwise/0040mark_binop_5
create mode 100755 tests/shell/testcases/bitwise/0040mark_binop_6
create mode 100755 tests/shell/testcases/bitwise/0040mark_binop_7
create mode 100755 tests/shell/testcases/bitwise/0040mark_binop_8
create mode 100755 tests/shell/testcases/bitwise/0040mark_binop_9
rename tests/shell/testcases/{chains/dumps/0040mark_shift_0.nft => bitwise/dumps/0040mark_binop_0.nft} (58%)
rename tests/shell/testcases/{chains/dumps/0040mark_shift_1.nft => bitwise/dumps/0040mark_binop_1.nft} (64%)
create mode 100644 tests/shell/testcases/bitwise/dumps/0040mark_binop_2.nft
create mode 100644 tests/shell/testcases/bitwise/dumps/0040mark_binop_3.nft
create mode 100644 tests/shell/testcases/bitwise/dumps/0040mark_binop_4.nft
create mode 100644 tests/shell/testcases/bitwise/dumps/0040mark_binop_5.nft
create mode 100644 tests/shell/testcases/bitwise/dumps/0040mark_binop_6.nft
create mode 100644 tests/shell/testcases/bitwise/dumps/0040mark_binop_7.nft
create mode 100644 tests/shell/testcases/bitwise/dumps/0040mark_binop_8.nft
create mode 100644 tests/shell/testcases/bitwise/dumps/0040mark_binop_9.nftSignature · 1 line
2.40.0
Pablo Neira Ayuso
maintainerPATCH 1/9 evaluate: insert byte-order conversions for expressions between 9 and 15 bits
From: Jeremy Sowden <[email protected]>
Round up expression lengths when determining whether to insert a byte-order conversion. For example, if one is masking a network header which spans a byte boundary, the mask will span two bytes and so it will need to be in NBO.
--- src/evaluate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/evaluate.c +1 -1
@@ -193,7 +193,7 @@ static int byteorder_conversion(struct eval_ctx *ctx, struct expr **expr, byteorder_names[(*expr)->byteorder]); } -if (expr_is_constant (*expr) || (*expr)->len /BITS_PER_BYTE <2 ) +if (expr_is_constant (*expr) ||div_round_up ((*expr)->len,BITS_PER_BYTE ) <2 ) (*expr)->byteorder = byteorder;else { op =byteorder_conversion_op (*expr, byteorder);
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 2/9 netlink_delinearize: correct type and byte-order of shifts
In reply to Pablo Neira AyusoFrom: Jeremy Sowden <[email protected]>
Downgrade to base type integer instead of the specific type from the expression that is used in the shift operation.
Without this, listing a rule like:
ct mark set ip dscp lshift 2 or 0x10
will return:
ct mark set ip dscp << 2 | cs2
because the type of the OR's right operand will be transitively derived from ip dscp. However, this is not valid syntax:
# nft add rule t c ct mark set ip dscp '<<' 2 '|' cs2
Error: Could not parse integer
add rule t c ct mark set ip dscp << 2 | cs2
^^^Use xinteger_type to print the output in hexadecimal.
--- src/netlink_delinearize.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
src/netlink_delinearize.c +11 -2
@@ -2810,8 +2810,17 @@ static void expr_postprocess(struct rule_pp_ctx *ctx, struct expr **exprp) }expr_postprocess (ctx, &expr->right); -expr_set_type (expr, expr->left->dtype, - expr->left->byteorder); +switch (expr->op) { +case OP_LSHIFT : +case OP_RSHIFT : +expr_set_type (expr, &xinteger_type, +BYTEORDER_HOST_ENDIAN ); +break ; +default : +expr_set_type (expr, expr->left->dtype, + expr->left->byteorder); + } +break ;case EXPR_RELATIONAL :switch (expr->left->etype) {
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 3/9 evaluate: support shifts larger than the width of the left operand
In reply to Pablo Neira AyusoFrom: Jeremy Sowden <[email protected]>
If we want to left-shift a value of narrower type and assign the result to a variable of a wider type, we are constrained to only shifting up to the width of the narrower type. Thus:
add rule t c meta mark set ip dscp << 2
works, but:
add rule t c meta mark set ip dscp << 8
does not, even though the lvalue is large enough to accommodate the result.
Evaluation of the left-hand operand of a shift overwrites the len field of the evaluation context when expr_evaluate_primary is called. Instead, preserve the len value of the evaluation context for shifts, and support shifts up to that size, even if they are larger than the length of the left operand.
Update netlink_delinearize.c to handle the case where the length of a shift expression does not match that of its left-hand operand.
--- src/evaluate.c | 23 ++++++++++++++--------- src/netlink_delinearize.c | 4 ++-- 2 files changed, 16 insertions(+), 11 deletions(-)
src/evaluate.c +14 -9
@@ -1289,14 +1289,18 @@ static int constant_binop_simplify(struct eval_ctx *ctx, struct expr **expr)static int expr_evaluate_shift (struct eval_ctx *ctx,struct expr **expr) {struct expr *op = *expr, *left = op->left, *right = op->right; +unsigned int shift =mpz_get_uint32 (right->value); +unsigned int op_len = left->len; -if (mpz_get_uint32 (right->value) >= left->len) -return expr_binary_error (ctx->msgs, right, left, -"%s shift of %u bits is undefined " -"for type of %u bits width" , - op->op ==OP_LSHIFT ?"Left" :"Right" , -mpz_get_uint32 (right->value), - left->len); +if (shift >= op_len) { +if (shift >= ctx->ectx.len) +return expr_binary_error (ctx->msgs, right, left, +"%s shift of %u bits is undefined for type of %u bits width" , + op->op ==OP_LSHIFT ?"Left" :"Right" , + shift, + op_len); + op_len = ctx->ectx.len; + }/* Both sides need to be in host byte order */ if (byteorder_conversion (ctx, &op->left,BYTEORDER_HOST_ENDIAN ) <0 )
@@ -1306,7 +1310,7 @@ static int expr_evaluate_shift(struct eval_ctx *ctx, struct expr **expr)return -1 ; op->byteorder =BYTEORDER_HOST_ENDIAN ; - op->len = left->len; + op->len = op_len;if (expr_is_constant (left))return constant_binop_simplify (ctx, expr);
@@ -1339,6 +1343,7 @@ static int expr_evaluate_binop(struct eval_ctx *ctx, struct expr **expr) {struct expr *op = *expr, *left, *right;const char *sym = expr_op_symbols[op->op]; +unsigned int ectx_len = ctx->ectx.len;if (expr_evaluate (ctx, &op->left) <0 )return -1 ;
@@ -1346,7 +1351,7 @@ static int expr_evaluate_binop(struct eval_ctx *ctx, struct expr **expr)if (op->op ==OP_LSHIFT || op->op ==OP_RSHIFT )__expr_set_context (&ctx->ectx, &integer_type, - left->byteorder, ctx->ectx.len,0 ); + left->byteorder, ectx_len,0 );if (expr_evaluate (ctx, &op->right) <0 )return -1 ; right = op->right;
src/netlink_delinearize.c +2 -2
@@ -489,7 +489,7 @@ static struct expr *netlink_parse_bitwise_bool(struct netlink_parse_ctx *ctx,mpz_ior (m, m, o); } -if (left->len >0 &&mpz_scan0 (m,0 ) == left->len) { +if (left->len >0 &&mpz_scan0 (m,0 ) >= left->len) {/* mask encompasses the entire value */ expr_free (mask); }else {
@@ -537,7 +537,7 @@ static struct expr *netlink_parse_bitwise_shift(struct netlink_parse_ctx *ctx, right->byteorder =BYTEORDER_HOST_ENDIAN ; expr =binop_expr_alloc (loc, op, left, right); - expr->len = left->len; + expr->len =nftnl_expr_get_u32 (nle,NFTNL_EXPR_BITWISE_LEN ) *BITS_PER_BYTE ;return expr; }
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 4/9 evaluate: don't eval unary arguments
In reply to Pablo Neira AyusoFrom: Jeremy Sowden <[email protected]>
When a unary expression is inserted to implement a byte-order conversion, the expression being converted has already been evaluated and so expr_evaluate_unary doesn't need to do so.
This is required by {ct|meta} statements with bitwise operations, which might result in byteorder conversion of the expression.
--- src/evaluate.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
src/evaluate.c +2 -4
@@ -1198,12 +1198,10 @@ static int expr_evaluate_range(struct eval_ctx *ctx, struct expr **expr)*/ static int expr_evaluate_unary (struct eval_ctx *ctx,struct expr **expr) { -struct expr *unary = *expr, *arg; +struct expr *unary = *expr, *arg = unary->arg;enum byteorder byteorder; -if (expr_evaluate (ctx, &unary->arg) <0 ) -return -1 ; - arg = unary->arg; +/* unary expression arguments has already been evaluated. */ assert (!expr_is_constant (arg));assert (expr_basetype (arg)->type ==TYPE_INTEGER );
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 5/9 evaluate: get length from statement instead of lhs expression
In reply to Pablo Neira AyusoGet length from statement, instead infering it from the expression that is used to set the value. In the particular case of {ct|meta} mark, this is 32 bits.
Otherwise, bytecode generation is not correct:
# nft -c --debug=netlink 'add rule ip6 x y ct mark set ip6 dscp << 2 | 0x10' [ payload load 2b @ network header + 0 => reg 1 ] [ bitwise reg 1 = ( reg 1 & 0x0000c00f ) ^ 0x00000000 ] [ bitwise reg 1 = ( reg 1 >> 0x00000006 ) ] [ byteorder reg 1 = ntoh(reg 1, 2, 1) ] [ bitwise reg 1 = ( reg 1 << 0x00000002 ) ] [ bitwise reg 1 = ( reg 1 & 0x00000fef ) ^ 0x00000010 ] <--- incorrect! [ ct set mark with reg 1 ]
the previous bitwise shift already upgraded to 32-bits (not visible from the netlink debug output above).
After this patch, the last | 0x10 uses 32-bits:
[ bitwise reg 1 = ( reg 1 & 0xffffffef ) ^ 0x00000010 ]
note that mask 0xffffffef is used instead of 0x00000fef.
--- src/evaluate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/evaluate.c +1 -1
@@ -1324,7 +1324,7 @@ static int expr_evaluate_bitwise(struct eval_ctx *ctx, struct expr **expr) op->dtype = left->dtype; op->byteorder = left->byteorder; - op->len = left->len; + op->len = ctx->ectx.len;if (expr_is_constant (left))return constant_binop_simplify (ctx, expr);
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 6/9 evaluate: relax type-checking for integer arguments in mark statements
In reply to Pablo Neira AyusoIn order to be able to set ct and meta marks to values derived from payload expressions, we need to relax the requirement that the type of the statement argument must match that of the statement key. Instead, we require that the base-type of the argument is integer and that the argument is small enough to fit.
Moreover, swap expression byteorder before to make it compatible with the statement byteorder, to ensure rulesets are portable.
# nft --debug=netlink add rule ip t c 'meta mark set ip saddr' ip t c [ payload load 4b @ network header + 12 => reg 1 ] [ byteorder reg 1 = ntoh(reg 1, 4, 4) ] <----------- byteorder swap [ meta set mark with reg 1 ]
The following patches are required for this to work:
evaluate: get length from statement instead of lhs expression
evaluate: don't eval unary arguments
evaluate: support shifts larger than the width of the left operandnetlink_delinearize: correct type and byte-order of shifts
evaluate: insert byte-order conversions for expressions between 9 and 15 bits
Add one testcase for tests/py.
--- src/evaluate.c | 13 +++++++++++-- tests/py/ip/meta.t | 2 ++ tests/py/ip/meta.t.json | 20 ++++++++++++++++++++ tests/py/ip/meta.t.payload | 8 ++++++++ 4 files changed, 41 insertions(+), 2 deletions(-)
src/evaluate.c +11 -2
@@ -2736,13 +2736,22 @@ static int __stmt_evaluate_arg(struct eval_ctx *ctx, struct stmt *stmt,"expression has type %s with length %d" , dtype->desc, (*expr)->dtype->desc, (*expr)->len); - else if ((*expr)->dtype->type != TYPE_INTEGER && - !datatype_equal((*expr)->dtype, dtype)) + +if ((dtype->type ==TYPE_MARK && + !datatype_equal (datatype_basetype (dtype),datatype_basetype ((*expr)->dtype))) || + (dtype->type !=TYPE_MARK && + (*expr)->dtype->type !=TYPE_INTEGER && + !datatype_equal ((*expr)->dtype, dtype)))return stmt_binary_error (ctx, *expr, stmt,/* verdict vs invalid? */ "datatype mismatch: expected %s, " "expression has type %s" , dtype->desc, (*expr)->dtype->desc); +if (dtype->type ==TYPE_MARK && +datatype_equal (datatype_basetype (dtype),datatype_basetype ((*expr)->dtype)) && + !expr_is_constant (*expr)) +return byteorder_conversion (ctx, expr, byteorder); +/* we are setting a value, we can't use a set */ switch ((*expr)->etype) {case EXPR_SET :
tests/py/ip/meta.t +2 -0
@@ -15,3 +15,5 @@ meta obrname "br0";fail meta sdif "lo" accept;ok meta sdifname != "vrf1" accept;ok + +meta mark set ip dscp;ok
tests/py/ip/meta.t.json +20 -0
@@ -156,3 +156,23 @@ } } ] + +# meta mark set ip dscp +[ + { + "mangle": { + "key": { + "meta": { + "key": "mark" + } + }, + "value": { + "payload": { + "field": "dscp", + "protocol": "ip" + } + } + } + } +] +
tests/py/ip/meta.t.payload +8 -0
@@ -51,3 +51,11 @@ ip test-ip4 input [ cmp eq reg 1 0x00000011 ] [ payload load 2b @ transport header + 2 => reg 1 ] [ cmp eq reg 1 0x00004300 ] + +# meta mark set ip dscp +ip test-ip4 input + [ payload load 1b @ network header + 1 => reg 1 ] + [ bitwise reg 1 = ( reg 1 & 0x000000fc ) ^ 0x00000000 ] + [ bitwise reg 1 = ( reg 1 >> 0x00000002 ) ] + [ meta set mark with reg 1 ] +
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 7/9 tests: py: add test-cases for ct and packet mark payload expressions
In reply to Pablo Neira AyusoAdd new test-cases to verify that defining a rule that sets the ct or packet mark to a value derived from a payload works correctly.
--- tests/py/ip/ct.t | 2 ++ tests/py/ip/ct.t.json | 58 +++++++++++++++++++++++++++++++++++++ tests/py/ip/ct.t.payload | 18 ++++++++++++ tests/py/ip/meta.t | 3 ++ tests/py/ip/meta.t.json | 58 +++++++++++++++++++++++++++++++++++++ tests/py/ip/meta.t.payload | 17 +++++++++++ tests/py/ip6/ct.t | 6 ++++ tests/py/ip6/ct.t.payload | 19 ++++++++++++ tests/py/ip6/meta.t | 3 ++ tests/py/ip6/meta.t.json | 58 +++++++++++++++++++++++++++++++++++++ tests/py/ip6/meta.t.payload | 20 +++++++++++++ 11 files changed, 262 insertions(+) create mode 100644 tests/py/ip6/ct.t create mode 100644 tests/py/ip6/ct.t.payload
tests/py/ip/ct.t +2 -0
@@ -28,3 +28,5 @@ meta mark set ct original saddr . meta mark map { 1.1.1.1 . 0x00000014 : 0x00000 meta mark set ct original ip saddr . meta mark map { 1.1.1.1 . 0x00000014 : 0x0000001e };ok ct original saddr . meta mark { 1.1.1.1 . 0x00000014 };fail ct original ip saddr . meta mark { 1.1.1.1 . 0x00000014 };ok +ct mark set ip dscp << 2 | 0x10;ok +ct mark set ip dscp << 26 | 0x10;ok
tests/py/ip/ct.t.json +58 -0
61 lines not on this page · raw message
tests/py/ip/ct.t.payload +18 -0
@@ -84,3 +84,21 @@ ip [ ct load src_ip => reg 1 , dir original ] [ meta load mark => reg 9 ] [ lookup reg 1 set __set%d ] + +# ct mark set ip dscp << 2 | 0x10 +ip test-ip4 output + [ payload load 1b @ network header + 1 => reg 1 ] + [ bitwise reg 1 = ( reg 1 & 0x000000fc ) ^ 0x00000000 ] + [ bitwise reg 1 = ( reg 1 >> 0x00000002 ) ] + [ bitwise reg 1 = ( reg 1 << 0x00000002 ) ] + [ bitwise reg 1 = ( reg 1 & 0xffffffef ) ^ 0x00000010 ] + [ ct set mark with reg 1 ] + +# ct mark set ip dscp << 26 | 0x10 +ip + [ payload load 1b @ network header + 1 => reg 1 ] + [ bitwise reg 1 = ( reg 1 & 0x000000fc ) ^ 0x00000000 ] + [ bitwise reg 1 = ( reg 1 >> 0x00000002 ) ] + [ bitwise reg 1 = ( reg 1 << 0x0000001a ) ] + [ bitwise reg 1 = ( reg 1 & 0xffffffef ) ^ 0x00000010 ] + [ ct set mark with reg 1 ]
tests/py/ip/meta.t +3 -0
@@ -17,3 +17,6 @@ meta sdif "lo" accept;ok meta sdifname != "vrf1" accept;ok meta mark set ip dscp;ok + +meta mark set ip dscp << 2 | 0x10;ok +meta mark set ip dscp << 26 | 0x10;ok
tests/py/ip/meta.t.json +58 -0
61 lines not on this page · raw message
tests/py/ip/meta.t.payload +17 -0
@@ -59,3 +59,20 @@ ip test-ip4 input [ bitwise reg 1 = ( reg 1 >> 0x00000002 ) ] [ meta set mark with reg 1 ] +# meta mark set ip dscp << 2 | 0x10 +ip test-ip4 input + [ payload load 1b @ network header + 1 => reg 1 ] + [ bitwise reg 1 = ( reg 1 & 0x000000fc ) ^ 0x00000000 ] + [ bitwise reg 1 = ( reg 1 >> 0x00000002 ) ] + [ bitwise reg 1 = ( reg 1 << 0x00000002 ) ] + [ bitwise reg 1 = ( reg 1 & 0xffffffef ) ^ 0x00000010 ] + [ meta set mark with reg 1 ] + +# meta mark set ip dscp << 26 | 0x10 +ip + [ payload load 1b @ network header + 1 => reg 1 ] + [ bitwise reg 1 = ( reg 1 & 0x000000fc ) ^ 0x00000000 ] + [ bitwise reg 1 = ( reg 1 >> 0x00000002 ) ] + [ bitwise reg 1 = ( reg 1 << 0x0000001a ) ] + [ bitwise reg 1 = ( reg 1 & 0xffffffef ) ^ 0x00000010 ] + [ meta set mark with reg 1 ]
tests/py/ip6/ct.t new file +6 -0
@@ -0,0 +1,6 @@ +:output;type filter hook output priority 0 + +*ip6;test-ip6;output + +ct mark set ip6 dscp << 2 | 0x10;ok +ct mark set ip6 dscp << 26 | 0x10;ok
tests/py/ip6/ct.t.payload new file +19 -0
@@ -0,0 +1,19 @@ +# ct mark set ip6 dscp << 2 | 0x10 +ip6 test-ip6 output + [ payload load 2b @ network header + 0 => reg 1 ] + [ bitwise reg 1 = ( reg 1 & 0x0000c00f ) ^ 0x00000000 ] + [ bitwise reg 1 = ( reg 1 >> 0x00000006 ) ] + [ byteorder reg 1 = ntoh(reg 1, 2, 1) ] + [ bitwise reg 1 = ( reg 1 << 0x00000002 ) ] + [ bitwise reg 1 = ( reg 1 & 0xffffffef ) ^ 0x00000010 ] + [ ct set mark with reg 1 ] + +# ct mark set ip6 dscp << 26 | 0x10 +ip6 test-ip6 output + [ payload load 2b @ network header + 0 => reg 1 ] + [ bitwise reg 1 = ( reg 1 & 0x0000c00f ) ^ 0x00000000 ] + [ bitwise reg 1 = ( reg 1 >> 0x00000006 ) ] + [ byteorder reg 1 = ntoh(reg 1, 2, 1) ] + [ bitwise reg 1 = ( reg 1 << 0x0000001a ) ] + [ bitwise reg 1 = ( reg 1 & 0xffffffef ) ^ 0x00000010 ] + [ ct set mark with reg 1 ]
tests/py/ip6/meta.t +3 -0
@@ -14,3 +14,6 @@ meta protocol ip6 udp dport 67;ok;udp dport 67 meta sdif "lo" accept;ok meta sdifname != "vrf1" accept;ok + +meta mark set ip6 dscp << 2 | 0x10;ok +meta mark set ip6 dscp << 26 | 0x10;ok
tests/py/ip6/meta.t.json +58 -0
61 lines not on this page · raw message
tests/py/ip6/meta.t.payload +20 -0
@@ -60,3 +60,23 @@ ip6 test-ip6 input [ cmp eq reg 1 0x00000011 ] [ payload load 2b @ transport header + 2 => reg 1 ] [ cmp eq reg 1 0x00004300 ] + +# meta mark set ip6 dscp << 2 | 0x10 +ip6 test-ip6 input + [ payload load 2b @ network header + 0 => reg 1 ] + [ bitwise reg 1 = ( reg 1 & 0x0000c00f ) ^ 0x00000000 ] + [ bitwise reg 1 = ( reg 1 >> 0x00000006 ) ] + [ byteorder reg 1 = ntoh(reg 1, 2, 1) ] + [ bitwise reg 1 = ( reg 1 << 0x00000002 ) ] + [ bitwise reg 1 = ( reg 1 & 0xffffffef ) ^ 0x00000010 ] + [ meta set mark with reg 1 ] + +# meta mark set ip6 dscp << 26 | 0x10 +ip6 test-ip6 input + [ payload load 2b @ network header + 0 => reg 1 ] + [ bitwise reg 1 = ( reg 1 & 0x0000c00f ) ^ 0x00000000 ] + [ bitwise reg 1 = ( reg 1 >> 0x00000006 ) ] + [ byteorder reg 1 = ntoh(reg 1, 2, 1) ] + [ bitwise reg 1 = ( reg 1 << 0x0000001a ) ] + [ bitwise reg 1 = ( reg 1 & 0xffffffef ) ^ 0x00000010 ] + [ meta set mark with reg 1 ]
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 8/9 tests: shell: rename and move bitwise test-cases
In reply to Pablo Neira AyusoFrom: Jeremy Sowden <[email protected]>
The 0040mark_shift_? tests are testing not just shifts, but binops more generally, so name them accordingly.
Move them to a new folder specifically for bitwise operations.
Change the priorities of the chains to match the type.
---
.../{chains/0040mark_shift_0 => bitwise/0040mark_binop_0} | 2 +-
.../{chains/0040mark_shift_1 => bitwise/0040mark_binop_1} | 2 +-
.../0040mark_shift_0.nft => bitwise/dumps/0040mark_binop_0.nft} | 2 +-
.../0040mark_shift_1.nft => bitwise/dumps/0040mark_binop_1.nft} | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
rename tests/shell/testcases/{chains/0040mark_shift_0 => bitwise/0040mark_binop_0} (68%)
rename tests/shell/testcases/{chains/0040mark_shift_1 => bitwise/0040mark_binop_1} (70%)
rename tests/shell/testcases/{chains/dumps/0040mark_shift_0.nft => bitwise/dumps/0040mark_binop_0.nft} (58%)
rename tests/shell/testcases/{chains/dumps/0040mark_shift_1.nft => bitwise/dumps/0040mark_binop_1.nft} (64%)tests/shell/testcases/bitwise/0040mark_binop_0 renamed from tests/shell/testcases/chains/0040mark_shift_0 +1 -1
@@ -4,7 +4,7 @@ set -e RULESET=" add table t - add chain t c { type filter hook output priority mangle; } + add chain t c { type filter hook output priority filter; } add rule t c oif lo ct mark set (meta mark | 0x10) << 8 "
tests/shell/testcases/bitwise/0040mark_binop_1 renamed from tests/shell/testcases/chains/0040mark_shift_1 +1 -1
@@ -4,7 +4,7 @@ set -e RULESET=" add table t - add chain t c { type filter hook input priority mangle; } + add chain t c { type filter hook input priority filter; } add rule t c iif lo ct mark & 0xff 0x10 meta mark set ct mark >> 8 "
tests/shell/testcases/bitwise/dumps/0040mark_binop_0.nft renamed from tests/shell/testcases/chains/dumps/0040mark_shift_0.nft +1 -1
@@ -1,6 +1,6 @@ table ip t { chain c { - type filter hook output priority mangle; policy accept; + type filter hook output priority filter; policy accept; oif "lo" ct mark set (meta mark | 0x00000010) << 8 } }
tests/shell/testcases/bitwise/dumps/0040mark_binop_1.nft renamed from tests/shell/testcases/chains/dumps/0040mark_shift_1.nft +1 -1
@@ -1,6 +1,6 @@ table ip t { chain c { - type filter hook input priority mangle; policy accept; + type filter hook input priority filter; policy accept; iif "lo" ct mark & 0x000000ff == 0x00000010 meta mark set ct mark >> 8 } }
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 9/9 tests: shell: add test-cases for ct and packet mark payload expressions
In reply to Pablo Neira AyusoFrom: Jeremy Sowden <[email protected]>
Add new test-cases to verify that defining a rule that sets the ct or packet mark to a value derived from a payload works correctly.
--- tests/shell/testcases/bitwise/0040mark_binop_2 | 11 +++++++++++ tests/shell/testcases/bitwise/0040mark_binop_3 | 11 +++++++++++ tests/shell/testcases/bitwise/0040mark_binop_4 | 11 +++++++++++ tests/shell/testcases/bitwise/0040mark_binop_5 | 11 +++++++++++ tests/shell/testcases/bitwise/0040mark_binop_6 | 11 +++++++++++ tests/shell/testcases/bitwise/0040mark_binop_7 | 11 +++++++++++ tests/shell/testcases/bitwise/0040mark_binop_8 | 11 +++++++++++ tests/shell/testcases/bitwise/0040mark_binop_9 | 11 +++++++++++ .../testcases/bitwise/dumps/0040mark_binop_2.nft | 6 ++++++ .../testcases/bitwise/dumps/0040mark_binop_3.nft | 6 ++++++ .../testcases/bitwise/dumps/0040mark_binop_4.nft | 6 ++++++ .../testcases/bitwise/dumps/0040mark_binop_5.nft | 6 ++++++ .../testcases/bitwise/dumps/0040mark_binop_6.nft | 6 ++++++ .../testcases/bitwise/dumps/0040mark_binop_7.nft | 6 ++++++ .../testcases/bitwise/dumps/0040mark_binop_8.nft | 6 ++++++ .../testcases/bitwise/dumps/0040mark_binop_9.nft | 6 ++++++ 16 files changed, 136 insertions(+) create mode 100755 tests/shell/testcases/bitwise/0040mark_binop_2 create mode 100755 tests/shell/testcases/bitwise/0040mark_binop_3 create mode 100755 tests/shell/testcases/bitwise/0040mark_binop_4 create mode 100755 tests/shell/testcases/bitwise/0040mark_binop_5 create mode 100755 tests/shell/testcases/bitwise/0040mark_binop_6 create mode 100755 tests/shell/testcases/bitwise/0040mark_binop_7 create mode 100755 tests/shell/testcases/bitwise/0040mark_binop_8 create mode 100755 tests/shell/testcases/bitwise/0040mark_binop_9 create mode 100644 tests/shell/testcases/bitwise/dumps/0040mark_binop_2.nft create mode 100644 tests/shell/testcases/bitwise/dumps/0040mark_binop_3.nft create mode 100644 tests/shell/testcases/bitwise/dumps/0040mark_binop_4.nft create mode 100644 tests/shell/testcases/bitwise/dumps/0040mark_binop_5.nft create mode 100644 tests/shell/testcases/bitwise/dumps/0040mark_binop_6.nft create mode 100644 tests/shell/testcases/bitwise/dumps/0040mark_binop_7.nft create mode 100644 tests/shell/testcases/bitwise/dumps/0040mark_binop_8.nft create mode 100644 tests/shell/testcases/bitwise/dumps/0040mark_binop_9.nft
tests/shell/testcases/bitwise/0040mark_binop_2 new file +11 -0
@@ -0,0 +1,11 @@ +#!/bin/bash + +set -e + +RULESET=" + add table t + add chain t c { type filter hook output priority filter; } + add rule t c ct mark set ip dscp lshift 2 or 0x10 +" + +$NFT -f - <<< "$RULESET"
tests/shell/testcases/bitwise/0040mark_binop_3 new file +11 -0
@@ -0,0 +1,11 @@ +#!/bin/bash + +set -e + +RULESET=" + add table t + add chain t c { type filter hook input priority filter; } + add rule t c meta mark set ip dscp lshift 2 or 0x10 +" + +$NFT -f - <<< "$RULESET"
tests/shell/testcases/bitwise/0040mark_binop_4 new file +11 -0
@@ -0,0 +1,11 @@ +#!/bin/bash + +set -e + +RULESET=" + add table t + add chain t c { type filter hook output priority filter; } + add rule t c ct mark set ip dscp lshift 26 or 0x10 +" + +$NFT -f - <<< "$RULESET"
tests/shell/testcases/bitwise/0040mark_binop_5 new file +11 -0
@@ -0,0 +1,11 @@ +#!/bin/bash + +set -e + +RULESET=" + add table t + add chain t c { type filter hook input priority filter; } + add rule t c meta mark set ip dscp lshift 26 or 0x10 +" + +$NFT -f - <<< "$RULESET"
tests/shell/testcases/bitwise/0040mark_binop_6 new file +11 -0
@@ -0,0 +1,11 @@ +#!/bin/bash + +set -e + +RULESET=" + add table ip6 t + add chain ip6 t c { type filter hook output priority filter; } + add rule ip6 t c ct mark set ip6 dscp lshift 2 or 0x10 +" + +$NFT -f - <<< "$RULESET"
tests/shell/testcases/bitwise/0040mark_binop_7 new file +11 -0
@@ -0,0 +1,11 @@ +#!/bin/bash + +set -e + +RULESET=" + add table ip6 t + add chain ip6 t c { type filter hook input priority filter; } + add rule ip6 t c meta mark set ip6 dscp lshift 2 or 0x10 +" + +$NFT -f - <<< "$RULESET"
tests/shell/testcases/bitwise/0040mark_binop_8 new file +11 -0
@@ -0,0 +1,11 @@ +#!/bin/bash + +set -e + +RULESET=" + add table ip6 t + add chain ip6 t c { type filter hook output priority filter; } + add rule ip6 t c ct mark set ip6 dscp lshift 26 or 0x10 +" + +$NFT -f - <<< "$RULESET"
tests/shell/testcases/bitwise/0040mark_binop_9 new file +11 -0
@@ -0,0 +1,11 @@ +#!/bin/bash + +set -e + +RULESET=" + add table ip6 t + add chain ip6 t c { type filter hook input priority filter; } + add rule ip6 t c meta mark set ip6 dscp lshift 26 or 0x10 +" + +$NFT -f - <<< "$RULESET"
tests/shell/testcases/bitwise/dumps/0040mark_binop_2.nft new file +6 -0
@@ -0,0 +1,6 @@ +table ip t { + chain c { + type filter hook output priority filter; policy accept; + ct mark set ip dscp << 2 | 0x10 + } +}
tests/shell/testcases/bitwise/dumps/0040mark_binop_3.nft new file +6 -0
@@ -0,0 +1,6 @@ +table ip t { + chain c { + type filter hook input priority filter; policy accept; + meta mark set ip dscp << 2 | 0x10 + } +}
tests/shell/testcases/bitwise/dumps/0040mark_binop_4.nft new file +6 -0
@@ -0,0 +1,6 @@ +table ip t { + chain c { + type filter hook output priority filter; policy accept; + ct mark set ip dscp << 26 | 0x10 + } +}
tests/shell/testcases/bitwise/dumps/0040mark_binop_5.nft new file +6 -0
@@ -0,0 +1,6 @@ +table ip t { + chain c { + type filter hook input priority filter; policy accept; + meta mark set ip dscp << 26 | 0x10 + } +}
tests/shell/testcases/bitwise/dumps/0040mark_binop_6.nft new file +6 -0
@@ -0,0 +1,6 @@ +table ip6 t { + chain c { + type filter hook output priority filter; policy accept; + ct mark set ip6 dscp << 2 | 0x10 + } +}
tests/shell/testcases/bitwise/dumps/0040mark_binop_7.nft new file +6 -0
@@ -0,0 +1,6 @@ +table ip6 t { + chain c { + type filter hook input priority filter; policy accept; + meta mark set ip6 dscp << 2 | 0x10 + } +}
tests/shell/testcases/bitwise/dumps/0040mark_binop_8.nft new file +6 -0
@@ -0,0 +1,6 @@ +table ip6 t { + chain c { + type filter hook output priority filter; policy accept; + ct mark set ip6 dscp << 26 | 0x10 + } +}
tests/shell/testcases/bitwise/dumps/0040mark_binop_9.nft new file +6 -0
@@ -0,0 +1,6 @@ +table ip6 t { + chain c { + type filter hook input priority filter; policy accept; + meta mark set ip6 dscp << 26 | 0x10 + } +}
Signature · 1 line
2.30.2