]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
parser_bison: missing relational operation on flag list
authorPablo Neira Ayuso <pablo@netfilter.org>
Mon, 19 Apr 2021 09:56:15 +0000 (11:56 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Sun, 2 May 2021 21:30:35 +0000 (23:30 +0200)
Complete e6c32b2fa0b8 ("src: add negation match on singleton bitmask
value") which was missing comma-separated list of flags.

This patch provides a shortcut for:

    tcp flags and fin,rst == 0

which allows to check for the packet whose fin and rst bits are unset:

    # nft add rule x y tcp flags not fin,rst counter

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/parser_bison.y
tests/py/inet/tcp.t
tests/py/inet/tcp.t.json
tests/py/inet/tcp.t.payload

index 0a3adbe8378c673c23b284c13f7dd3df07dcece9..ce4857b2ab555f1aad326534e4105fbde6984f36 100644 (file)
@@ -4472,6 +4472,10 @@ relational_expr          :       expr    /* implicit */  rhs_expr
                        {
                                $$ = relational_expr_alloc(&@2, $2, $1, $3);
                        }
+                       |       expr    relational_op   list_rhs_expr
+                       {
+                               $$ = relational_expr_alloc(&@2, $2, $1, $3);
+                       }
                        ;
 
 list_rhs_expr          :       basic_rhs_expr          COMMA           basic_rhs_expr
index 29f06f5ae4847f04aff231bc46ad7599bb9c5f3e..5f2caea987596d617b8518bcc094c96ed5701ff8 100644 (file)
@@ -81,6 +81,7 @@ tcp flags & (syn|fin) == (syn|fin);ok;tcp flags & (fin | syn) == fin | syn
 tcp flags & (fin | syn | rst | psh | ack | urg | ecn | cwr) == fin | syn | rst | psh | ack | urg | ecn | cwr;ok;tcp flags == 0xff
 tcp flags { syn, syn | ack };ok
 tcp flags & (fin | syn | rst | psh | ack | urg) == { fin, ack, psh | ack, fin | psh | ack };ok
+tcp flags ! fin,rst;ok
 
 tcp window 22222;ok
 tcp window 22;ok
index 70225182836027c8a9646a99c8c782ab27188cea..922ab91c9f0e63f7319d87ab8588d836abd746c0 100644 (file)
         }
     }
 ]
+
+# tcp flags ! fin,rst
+[
+    {
+        "match": {
+            "op": "!",
+            "left": {
+                "payload": {
+                    "protocol": "tcp",
+                    "field": "flags"
+                }
+            },
+            "right": [
+                "fin",
+                "rst"
+            ]
+        }
+    }
+]
index 5eaf4090462db4ade03a26628a50de7a1a68b58a..da932b6d8c122546aa1059f6998b7659c5c783cc 100644 (file)
@@ -701,3 +701,10 @@ inet
   [ payload load 1b @ transport header + 13 => reg 1 ]
   [ lookup reg 1 set __set%d ]
 
+# tcp flags ! fin,rst
+inet
+  [ meta load l4proto => reg 1 ]
+  [ cmp eq reg 1 0x00000006 ]
+  [ payload load 1b @ transport header + 13 => reg 1 ]
+  [ bitwise reg 1 = ( reg 1 & 0x00000005 ) ^ 0x00000000 ]
+  [ cmp eq reg 1 0x00000000 ]