]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
doc: add more documentation on bitmasks and sets
authorChristoph Anton Mitterer <mail@christoph.anton.mitterer.name>
Fri, 24 Oct 2025 01:36:47 +0000 (03:36 +0200)
committerFlorian Westphal <fw@strlen.de>
Sun, 26 Oct 2025 13:13:01 +0000 (14:13 +0100)
Signed-off-by: Christoph Anton Mitterer <mail@christoph.anton.mitterer.name>
Signed-off-by: Florian Westphal <fw@strlen.de>
doc/data-types.txt
doc/nft.txt

index 18af266a3cfcd79d44d5248d00109389a872fb98..e44308b5322cb3aa341b8051cc9646df7b600c3f 100644 (file)
@@ -13,6 +13,7 @@ The integer type is used for numeric values. It may be specified as a decimal,
 hexadecimal or octal number. The integer type does not have a fixed size, its
 size is determined by the expression for which it is used.
 
+[[BITMASK_TYPE]]
 BITMASK TYPE
 ~~~~~~~~~~~~
 [options="header"]
@@ -26,6 +27,37 @@ integer
 
 The bitmask type (*bitmask*) is used for bitmasks.
 
+In expressions the bits of a bitmask may be specified as *'bit'[,'bit']...* with
+'bit' being the value of the bit or a pre-defined symbolic constant, if any (for
+example *ct state*’s bit 0x1 has the symbolic constant `new`).
+
+Equality of a value with such bitmask is given, if the value has any of the
+bitmask’s bits set (and optionally others).
+
+The syntax *'expression' 'value' / 'mask'* is identical to
+*'expression' and 'mask' == 'value'*.
+For example `tcp flags syn,ack / syn,ack,fin,rst` is the same as
+`tcp flags and (syn|ack|fin|rst) == syn|ack`.
+
+Note that *'expression' 'bit'[,'bit']...* is not generally the same as
+*'expression' {'bit'[,'bit']...}* and analogously with a named set.
+The latter forms are lookups in a set and will match only if the set contains
+exactly one value that matches.
+They are however effectively the same (with matching bitmasks typically being
+faster) when all bits are semantically mutually exclusive.
+
+Examples:
+* *tcp flags syn,ack* matches packets that have the SYN, the ACK or both SYN and
+  ACK flags set. Other flags are ignored.
+  *tcp flags { syn, ack }* matches packets that have either only the SYN or only
+  the ACK flag set. All other flags must be unset.
+* *ct state established,related* and *ct state { established, related } * match
+  exactly the same packets, because the bits of *ct state* are all mutually
+  exclusive.
+
+As usual, the the *nft describe* command may be used to get details on a data
+type, which for bitmasks shows the symbolic names and values of the bits.
+
 STRING TYPE
 ~~~~~~~~~~~~
 [options="header"]
index e0a3d173667f73e995a1f92cdc63176c6fa1d1b8..b4c889afb3531d52fefd74d73cc6fd7a3d6ec646 100644 (file)
@@ -674,6 +674,11 @@ Example: When the set contains range *1.2.3.1-1.2.3.4*, then adding element *1.2
 effect.  Adding *1.2.3.5* changes the existing range to cover *1.2.3.1-1.2.3.5*.
 Without this flag, *1.2.3.2* can not be added and *1.2.3.5* is inserted as a new entry.
 
+Equality of a value with a set is given if the value matches exactly one value
+in the set (which for intervals means that it’s contained in any of them).
+See <<BITMASK_TYPE>> for the subtle differences between syntactically similarly
+looking equiality checks of sets and bitmasks.
+
 MAPS
 -----
 [verse]