summaryrefslogtreecommitdiffstats
path: root/tests/py/inet
diff options
context:
space:
mode:
authorJeremy Sowden <jeremy@azazel.net>2024-11-19 00:18:28 +0100
committerPablo Neira Ayuso <pablo@netfilter.org>2024-12-04 15:35:55 +0100
commit54bfc38c522babe709e951f1fd128ff725b36704 (patch)
tree4432fccc08834428082c176fab42cbb3e880e819 /tests/py/inet
parentbc0311378285d41850e3508df905d75959ba4239 (diff)
src: allow binop expressions with variable right-hand operands
Hitherto, the kernel has required constant values for the `xor` and `mask` attributes of boolean bitwise expressions. This has meant that the right-hand operand of a boolean binop must be constant. Now the kernel has support for AND, OR and XOR operations with right-hand operands passed via registers, we can relax this restriction. Allow non-constant right-hand operands if the left-hand operand is not constant, e.g.: ct mark & 0xffff0000 | meta mark & 0xffff The kernel now supports performing AND, OR and XOR operations directly, on one register and an immediate value or on two registers, so we need to be able to generate and parse bitwise boolean expressions of this form. If a boolean operation has a constant RHS, we continue to send a mask-and-xor expression to the kernel. Add tests for {ct,meta} mark with variable RHS operands. JSON support is also included. This requires Linux kernel >= 6.13-rc. [ Originally posted as patch 1/8 and 6/8 which has been collapsed and simplified to focus on initial {ct,meta} mark support. Tests have been extracted from 8/8 including a tests/py fix to payload output due to incorrect output in original patchset. JSON support has been extracted from patch 7/8 --pablo] Signed-off-by: Jeremy Sowden <jeremy@azazel.net> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'tests/py/inet')
-rw-r--r--tests/py/inet/meta.t2
-rw-r--r--tests/py/inet/meta.t.json37
-rw-r--r--tests/py/inet/meta.t.payload9
3 files changed, 48 insertions, 0 deletions
diff --git a/tests/py/inet/meta.t b/tests/py/inet/meta.t
index 7d2515c9..5c5c11d4 100644
--- a/tests/py/inet/meta.t
+++ b/tests/py/inet/meta.t
@@ -31,3 +31,5 @@ meta mark set ip dscp;ok
meta mark set ip dscp | 0x40;ok
meta mark set ip6 dscp;ok
meta mark set ip6 dscp | 0x40;ok
+
+meta mark set ct mark and 0xffff0000 or meta mark and 0xffff;ok;meta mark set ct mark & 0xffff0000 | meta mark & 0x0000ffff
diff --git a/tests/py/inet/meta.t.json b/tests/py/inet/meta.t.json
index 0fee165f..4352b963 100644
--- a/tests/py/inet/meta.t.json
+++ b/tests/py/inet/meta.t.json
@@ -236,6 +236,43 @@
}
]
+# meta mark set ct mark and 0xffff0000 or meta mark and 0xffff
+[
+ {
+ "mangle": {
+ "key": {
+ "meta": {
+ "key": "mark"
+ }
+ },
+ "value": {
+ "|": [
+ {
+ "&": [
+ {
+ "ct": {
+ "key": "mark"
+ }
+ },
+ 4294901760
+ ]
+ },
+ {
+ "&": [
+ {
+ "meta": {
+ "key": "mark"
+ }
+ },
+ 65535
+ ]
+ }
+ ]
+ }
+ }
+ }
+]
+
# meta protocol ip udp dport 67
[
{
diff --git a/tests/py/inet/meta.t.payload b/tests/py/inet/meta.t.payload
index 7184fa0c..04dfbd8f 100644
--- a/tests/py/inet/meta.t.payload
+++ b/tests/py/inet/meta.t.payload
@@ -80,6 +80,15 @@ inet test-inet input
[ bitwise reg 1 = ( reg 1 >> 0x00000008 ) ]
[ meta set mark with reg 1 ]
+# meta mark set ct mark and 0xffff0000 or meta mark and 0xffff
+inet test-inet input
+ [ ct load mark => reg 1 ]
+ [ bitwise reg 1 = ( reg 1 & 0xffff0000 ) ^ 0x00000000 ]
+ [ meta load mark => reg 2 ]
+ [ bitwise reg 2 = ( reg 2 & 0x0000ffff ) ^ 0x00000000 ]
+ [ bitwise reg 1 = ( reg 1 | reg 2 ) ]
+ [ meta set mark with reg 1 ]
+
# meta protocol ip udp dport 67
inet test-inet input
[ meta load protocol => reg 1 ]