]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
src: queue: allow use of MAP statement for queue number retrieval
authorFlorian Westphal <fw@strlen.de>
Wed, 16 Jun 2021 16:45:56 +0000 (18:45 +0200)
committerFlorian Westphal <fw@strlen.de>
Mon, 21 Jun 2021 12:44:58 +0000 (14:44 +0200)
This allows to chose a queue number at run time using map statements,
e.g.:

queue flags bypass to ip saddr map { 192.168.7/24 : 0, 192.168.0/24 : 1 }

Signed-off-by: Florian Westphal <fw@strlen.de>
doc/statements.txt
src/parser_bison.y
tests/py/any/queue.t
tests/py/any/queue.t.json
tests/py/any/queue.t.payload

index c2a616594fce99fc72b98ff170380fe6b6398469..097cf2e07eeb37f7da135772555bad532fab1088 100644 (file)
@@ -595,11 +595,13 @@ ____
 
 'QUEUE_FLAGS' := 'QUEUE_FLAG' [*,* 'QUEUE_FLAGS']
 'QUEUE_FLAG'  := *bypass* | *fanout*
-'QUEUE_EXPRESSION' := *numgen* | *hash* | *symhash*
+'QUEUE_EXPRESSION' := *numgen* | *hash* | *symhash* | *MAP STATEMENT*
 ____
 
 QUEUE_EXPRESSION can be used to compute a queue number
-at run-time with the hash or numgen expressions.
+at run-time with the hash or numgen expressions. It also
+allows to use the map statement to assign fixed queue numbers
+based on external inputs such as the source ip address or interface names.
 
 .queue statement values
 [options="header"]
index cb3e80e3facfa3f5818a12a5ecceb89366192a2b..c31cc4e7ea8f10eaff5134b1fcbd850e224e39ce 100644 (file)
@@ -3787,6 +3787,7 @@ queue_stmt_expr_simple    :       integer_expr
 
 queue_stmt_expr                :       numgen_expr
                        |       hash_expr
+                       |       map_expr
                        ;
 
 queue_stmt_flags       :       queue_stmt_flag
index 670dfd92d5b073a1b407433f88fef37136e7fcb3..446b8b1806f24b0883e3546ab84a67d13eeb5cec 100644 (file)
@@ -25,3 +25,4 @@ queue flags bypass to numgen inc mod 65536;ok
 queue to jhash oif . meta mark mod 32;ok
 queue to oif;fail
 queue num oif;fail
+queue flags bypass to oifname map { "eth0" : 0, "ppp0" : 2, "eth1" : 2 };ok
index 18ed3c817ac91b120b76c8ec59d8e3eefc99f5a7..162bdff875d66ee2724b3bc75cc15a397121e58e 100644 (file)
     }
 ]
 
+# queue flags bypass to oifname map { "eth0" : 0, "ppp0" : 2, "eth1" : 2 }
+[
+    {
+        "queue": {
+            "flags": "bypass",
+            "num": {
+                "map": {
+                    "data": {
+                        "set": [
+                            [
+                                "eth0",
+                                0
+                            ],
+                            [
+                                "ppp0",
+                                2
+                            ],
+                            [
+                                "eth1",
+                                2
+                            ]
+                        ]
+                    },
+                    "key": {
+                        "meta": {
+                            "key": "oifname"
+                        }
+                    }
+                }
+            }
+        }
+    }
+]
+
index 35e757ee5cf05b19d12816c632c9aa62fc65464e..02660afa8d3085dcf1fd1a0243eccbc9ce99619a 100644 (file)
@@ -46,3 +46,12 @@ ip
 ip
   [ numgen reg 1 = inc mod 65536 ]
   [ queue sreg_qnum 1 bypass ]
+
+# queue flags bypass to oifname map { "eth0" : 0, "ppp0" : 2, "eth1" : 2 }
+__map%d test-ip4 b size 3
+__map%d test-ip4 0
+       element 30687465 00000000 00000000 00000000  : 00000000 0 [end] element 30707070 00000000 00000000 00000000  : 00000002 0 [end] element 31687465 00000000 00000000 00000000  : 00000002 0 [end]
+ip
+  [ meta load oifname => reg 1 ]
+  [ lookup reg 1 set __map%d dreg 1 ]
+  [ queue sreg_qnum 1 bypass ]