1NFT(8)                                                                  NFT(8)
2
3
4

NAME

6       nft - Administration tool of the nftables framework for packet
7       filtering and classification
8

SYNOPSIS

10       nft [ -nNscaeSupyjt ] [ -I directory ] [ -f filename | -i | cmd ...]
11       nft -h
12       nft -v
13

DESCRIPTION

15       nft is the command line tool used to set up, maintain and inspect
16       packet filtering and classification rules in the Linux kernel, in the
17       nftables framework. The Linux kernel subsystem is known as nf_tables,
18       and ‘nf’ stands for Netfilter.
19

OPTIONS

21       The command accepts several different options which are documented here
22       in groups for better understanding of their meaning. You can get
23       information about options by running nft --help.
24
25       General options:
26
27       -h, --help
28           Show help message and all options.
29
30       -v, --version
31           Show version.
32
33       -V
34           Show long version information, including compile-time
35           configuration.
36
37       Ruleset input handling options that specify to how to load rulesets:
38
39       -f, --file filename
40           Read input from filename. If filename is -, read from stdin.
41
42       -i, --interactive
43           Read input from an interactive readline CLI. You can use quit to
44           exit, or use the EOF marker, normally this is CTRL-D.
45
46       -I, --includepath directory
47           Add the directory directory to the list of directories to be
48           searched for included files. This option may be specified multiple
49           times.
50
51       -c, --check
52           Check commands validity without actually applying the changes.
53
54       Ruleset list output formatting that modify the output of the list
55       ruleset command:
56
57       -a, --handle
58           Show object handles in output.
59
60       -s, --stateless
61           Omit stateful information of rules and stateful objects.
62
63       -t, --terse
64           Omit contents of sets from output.
65
66       -S, --service
67           Translate ports to service names as defined by /etc/services.
68
69       -N, --reversedns
70           Translate IP address to names via reverse DNS lookup. This may slow
71           down your listing since it generates network traffic.
72
73       -u, --guid
74           Translate numeric UID/GID to names as defined by /etc/passwd and
75           /etc/group.
76
77       -n, --numeric
78           Print fully numerical output.
79
80       -y, --numeric-priority
81           Display base chain priority numerically.
82
83       -p, --numeric-protocol
84           Display layer 4 protocol numerically.
85
86       -T, --numeric-time
87           Show time, day and hour values in numeric format.
88
89       Command output formatting:
90
91       -e, --echo
92           When inserting items into the ruleset using add, insert or replace
93           commands, print notifications just like nft monitor.
94
95       -j, --json
96           Format output in JSON. See libnftables-json(5) for a schema
97           description.
98
99       -d, --debug level
100           Enable debugging output. The debug level can be any of scanner,
101           parser, eval, netlink, mnl, proto-ctx, segtree, all. You can
102           combine more than one by separating by the , symbol, for example -d
103           eval,mnl.
104

INPUT FILE FORMATS

106   LEXICAL CONVENTIONS
107       Input is parsed line-wise. When the last character of a line, just
108       before the newline character, is a non-quoted backslash (\), the next
109       line is treated as a continuation. Multiple commands on the same line
110       can be separated using a semicolon (;).
111
112       A hash sign (#) begins a comment. All following characters on the same
113       line are ignored.
114
115       Identifiers begin with an alphabetic character (a-z,A-Z), followed zero
116       or more alphanumeric characters (a-z,A-Z,0-9) and the characters slash
117       (/), backslash (\), underscore (_) and dot (.). Identifiers using
118       different characters or clashing with a keyword need to be enclosed in
119       double quotes (").
120
121   INCLUDE FILES
122           include filename
123
124       Other files can be included by using the include statement. The
125       directories to be searched for include files can be specified using the
126       -I/--includepath option. You can override this behaviour either by
127       prepending ‘./’ to your path to force inclusion of files located in the
128       current working directory (i.e. relative path) or / for file location
129       expressed as an absolute path.
130
131       If -I/--includepath is not specified, then nft relies on the default
132       directory that is specified at compile time. You can retrieve this
133       default directory via -h/--help option.
134
135       Include statements support the usual shell wildcard symbols (\*,?,[]).
136       Having no matches for an include statement is not an error, if wildcard
137       symbols are used in the include statement. This allows having
138       potentially empty include directories for statements like include
139       "/etc/firewall/rules/". The wildcard matches are loaded in alphabetical
140       order. Files beginning with dot (.) are not matched by include
141       statements.
142
143   SYMBOLIC VARIABLES
144           define variable = expr
145           $variable
146
147       Symbolic variables can be defined using the define statement. Variable
148       references are expressions and can be used initialize other variables.
149       The scope of a definition is the current block and all blocks contained
150       within.
151
152       Using symbolic variables.
153
154           define int_if1 = eth0
155           define int_if2 = eth1
156           define int_ifs = { $int_if1, $int_if2 }
157
158           filter input iif $int_ifs accept
159
160

ADDRESS FAMILIES

162       Address families determine the type of packets which are processed. For
163       each address family, the kernel contains so called hooks at specific
164       stages of the packet processing paths, which invoke nftables if rules
165       for these hooks exist.
166
167
168       ip       IPv4 address family.
169
170       ip6      IPv6 address family.
171
172       inet     Internet (IPv4/IPv6)
173                address family.
174
175       arp      ARP address family,
176                handling IPv4 ARP packets.
177
178       bridge   Bridge address family,
179                handling packets which
180                traverse a bridge device.
181
182       netdev   Netdev address family,
183                handling packets from
184                ingress.
185
186
187       All nftables objects exist in address family specific namespaces,
188       therefore all identifiers include an address family. If an identifier
189       is specified without an address family, the ip family is used by
190       default.
191
192   IPV4/IPV6/INET ADDRESS FAMILIES
193       The IPv4/IPv6/Inet address families handle IPv4, IPv6 or both types of
194       packets. They contain five hooks at different packet processing stages
195       in the network stack.
196
197       Table 1. IPv4/IPv6/Inet address family hooks
198       ┌────────────┬────────────────────────────┐
199Hook        Description                
200       ├────────────┼────────────────────────────┤
201       │            │                            │
202       │prerouting  │ All packets entering the   │
203       │            │ system are processed by    │
204       │            │ the prerouting hook. It is │
205       │            │ invoked before the routing │
206       │            │ process and is used for    │
207       │            │ early filtering or         │
208       │            │ changing packet attributes │
209       │            │ that affect routing.       │
210       ├────────────┼────────────────────────────┤
211       │            │                            │
212       │input       │ Packets delivered to the   │
213       │            │ local system are processed │
214       │            │ by the input hook.         │
215       ├────────────┼────────────────────────────┤
216       │            │                            │
217       │forward     │ Packets forwarded to a     │
218       │            │ different host are         │
219       │            │ processed by the forward   │
220       │            │ hook.                      │
221       ├────────────┼────────────────────────────┤
222       │            │                            │
223       │output      │ Packets sent by local      │
224       │            │ processes are processed by │
225       │            │ the output hook.           │
226       ├────────────┼────────────────────────────┤
227       │            │                            │
228       │postrouting │ All packets leaving the    │
229       │            │ system are processed by    │
230       │            │ the postrouting hook.      │
231       ├────────────┼────────────────────────────┤
232       │            │                            │
233       │ingress     │ All packets entering the   │
234       │            │ system are processed by    │
235       │            │ this hook. It is invoked   │
236       │            │ before layer 3 protocol    │
237       │            │ handlers, hence before the │
238       │            │ prerouting hook, and it    │
239       │            │ can be used for filtering  │
240       │            │ and policing. Ingress is   │
241       │            │ only available for Inet    │
242       │            │ family (since Linux kernel │
243       │            │ 5.10).                     │
244       └────────────┴────────────────────────────┘
245
246   ARP ADDRESS FAMILY
247       The ARP address family handles ARP packets received and sent by the
248       system. It is commonly used to mangle ARP packets for clustering.
249
250       Table 2. ARP address family hooks
251       ┌───────┬────────────────────────────┐
252Hook   Description                
253       ├───────┼────────────────────────────┤
254       │       │                            │
255       │input  │ Packets delivered to the   │
256       │       │ local system are processed │
257       │       │ by the input hook.         │
258       ├───────┼────────────────────────────┤
259       │       │                            │
260       │output │ Packets send by the local  │
261       │       │ system are processed by    │
262       │       │ the output hook.           │
263       └───────┴────────────────────────────┘
264
265   BRIDGE ADDRESS FAMILY
266       The bridge address family handles Ethernet packets traversing bridge
267       devices.
268
269       The list of supported hooks is identical to IPv4/IPv6/Inet address
270       families above.
271
272   NETDEV ADDRESS FAMILY
273       The Netdev address family handles packets from the device ingress path.
274       This family allows you to filter packets of any ethertype such as ARP,
275       VLAN 802.1q, VLAN 802.1ad (Q-in-Q) as well as IPv4 and IPv6 packets.
276
277       Table 3. Netdev address family hooks
278       ┌────────┬────────────────────────────┐
279Hook    Description                
280       ├────────┼────────────────────────────┤
281       │        │                            │
282       │ingress │ All packets entering the   │
283       │        │ system are processed by    │
284       │        │ this hook. It is invoked   │
285       │        │ after the network taps     │
286       │        │ (ie. tcpdump), right after │
287       │        │ tc ingress and before      │
288       │        │ layer 3 protocol handlers, │
289       │        │ it can be used for early   │
290       │        │ filtering and policing.    │
291       └────────┴────────────────────────────┘
292

RULESET

294           {list | flush} ruleset [family]
295
296       The ruleset keyword is used to identify the whole set of tables,
297       chains, etc. currently in place in kernel. The following ruleset
298       commands exist:
299
300
301       list    Print the ruleset in
302               human-readable format.
303
304       flush   Clear the whole ruleset.
305               Note that, unlike
306               iptables, this will remove
307               all tables and whatever
308               they contain, effectively
309               leading to an empty
310               ruleset - no packet
311               filtering will happen
312               anymore, so the kernel
313               accepts any valid packet
314               it receives.
315
316
317       It is possible to limit list and flush to a specific address family
318       only. For a list of valid family names, see the section called “ADDRESS
319       FAMILIES” above.
320
321       By design, list ruleset command output may be used as input to nft -f.
322       Effectively, this is the nft-equivalent of iptables-save and
323       iptables-restore.
324

TABLES

326           {add | create} table [family] table [{ flags flags ; }]
327           {delete | list | flush} table [family] table
328           list tables [family]
329           delete table [family] handle handle
330
331       Tables are containers for chains, sets and stateful objects. They are
332       identified by their address family and their name. The address family
333       must be one of ip, ip6, inet, arp, bridge, netdev. The inet address
334       family is a dummy family which is used to create hybrid IPv4/IPv6
335       tables. The meta expression nfproto keyword can be used to test which
336       family (ipv4 or ipv6) context the packet is being processed in. When no
337       address family is specified, ip is used by default. The only difference
338       between add and create is that the former will not return an error if
339       the specified table already exists while create will return an error.
340
341       Table 4. Table flags
342       ┌────────┬────────────────────────────┐
343Flag    Description                
344       ├────────┼────────────────────────────┤
345       │        │                            │
346       │dormant │ table is not evaluated any │
347       │        │ more (base chains are      │
348       │        │ unregistered).             │
349       └────────┴────────────────────────────┘
350
351       Add, change, delete a table.
352
353           # start nft in interactive mode
354           nft --interactive
355
356           # create a new table.
357           create table inet mytable
358
359           # add a new base chain: get input packets
360           add chain inet mytable myin { type filter hook input priority 0; }
361
362           # add a single counter to the chain
363           add rule inet mytable myin counter
364
365           # disable the table temporarily -- rules are not evaluated anymore
366           add table inet mytable { flags dormant; }
367
368           # make table active again:
369           add table inet mytable
370
371
372
373       add      Add a new table for the
374                given family with the
375                given name.
376
377       delete   Delete the specified
378                table.
379
380       list     List all chains and rules
381                of the specified table.
382
383       flush    Flush all chains and rules
384                of the specified table.
385
386

CHAINS

388           {add | create} chain [family] table chain [{ type type hook hook [device device] priority priority ; [policy policy ;] }]
389           {delete | list | flush} chain [family] table chain
390           list chains [family]
391           delete chain [family] table handle handle
392           rename chain [family] table chain newname
393
394       Chains are containers for rules. They exist in two kinds, base chains
395       and regular chains. A base chain is an entry point for packets from the
396       networking stack, a regular chain may be used as jump target and is
397       used for better rule organization.
398
399
400       add      Add a new chain in the
401                specified table. When a
402                hook and priority value
403                are specified, the chain
404                is created as a base chain
405                and hooked up to the
406                networking stack.
407
408       create   Similar to the add
409                command, but returns an
410                error if the chain already
411                exists.
412
413       delete   Delete the specified
414                chain. The chain must not
415                contain any rules or be
416                used as jump target.
417
418       rename   Rename the specified
419                chain.
420
421       list     List all rules of the
422                specified chain.
423
424       flush    Flush all rules of the
425                specified chain.
426
427
428       For base chains, type, hook and priority parameters are mandatory.
429
430       Table 5. Supported chain types
431       ┌───────┬───────────────┬────────────────┬──────────────────┐
432Type   Families      Hooks          Description      
433       ├───────┼───────────────┼────────────────┼──────────────────┤
434       │       │               │                │                  │
435       │filter │ all           │ all            │ Standard chain   │
436       │       │               │                │ type to use in   │
437       │       │               │                │ doubt.           │
438       ├───────┼───────────────┼────────────────┼──────────────────┤
439       │       │               │                │                  │
440       │nat    │ ip, ip6, inet │ prerouting,    │ Chains of this   │
441       │       │               │ input, output, │ type perform     │
442       │       │               │ postrouting    │ Native Address   │
443       │       │               │                │ Translation      │
444       │       │               │                │ based on         │
445       │       │               │                │ conntrack        │
446       │       │               │                │ entries. Only    │
447       │       │               │                │ the first packet │
448       │       │               │                │ of a connection  │
449       │       │               │                │ actually         │
450       │       │               │                │ traverses this   │
451       │       │               │                │ chain - its      │
452       │       │               │                │ rules usually    │
453       │       │               │                │ define details   │
454       │       │               │                │ of the created   │
455       │       │               │                │ conntrack entry  │
456       │       │               │                │ (NAT statements  │
457       │       │               │                │ for instance).   │
458       ├───────┼───────────────┼────────────────┼──────────────────┤
459       │       │               │                │                  │
460       │route  │ ip, ip6       │ output         │ If a packet has  │
461       │       │               │                │ traversed a      │
462       │       │               │                │ chain of this    │
463       │       │               │                │ type and is      │
464       │       │               │                │ about to be      │
465       │       │               │                │ accepted, a new  │
466       │       │               │                │ route lookup is  │
467       │       │               │                │ performed if     │
468       │       │               │                │ relevant parts   │
469       │       │               │                │ of the IP header │
470       │       │               │                │ have changed.    │
471       │       │               │                │ This allows to   │
472       │       │               │                │ e.g. implement   │
473       │       │               │                │ policy routing   │
474       │       │               │                │ selectors in     │
475       │       │               │                │ nftables.        │
476       └───────┴───────────────┴────────────────┴──────────────────┘
477
478       Apart from the special cases illustrated above (e.g. nat type not
479       supporting forward hook or route type only supporting output hook),
480       there are three further quirks worth noticing:
481
482       •   The netdev family supports merely a single combination, namely
483           filter type and ingress hook. Base chains in this family also
484           require the device parameter to be present since they exist per
485           incoming interface only.
486
487       •   The arp family supports only the input and output hooks, both in
488           chains of type filter.
489
490       •   The inet family also supports the ingress hook (since Linux kernel
491           5.10), to filter IPv4 and IPv6 packet at the same location as the
492           netdev ingress hook. This inet hook allows you to share sets and
493           maps between the usual prerouting, input, forward, output,
494           postrouting and this ingress hook.
495
496       The priority parameter accepts a signed integer value or a standard
497       priority name which specifies the order in which chains with same hook
498       value are traversed. The ordering is ascending, i.e. lower priority
499       values have precedence over higher ones.
500
501       Standard priority values can be replaced with easily memorizable names.
502       Not all names make sense in every family with every hook (see the
503       compatibility matrices below) but their numerical value can still be
504       used for prioritizing chains.
505
506       These names and values are defined and made available based on what
507       priorities are used by xtables when registering their default chains.
508
509       Most of the families use the same values, but bridge uses different
510       ones from the others. See the following tables that describe the values
511       and compatibility.
512
513       Table 6. Standard priority names, family and hook compatibility matrix
514       ┌─────────┬───────┬────────────────┬─────────────┐
515Name     Value Families       Hooks       
516       ├─────────┼───────┼────────────────┼─────────────┤
517       │         │       │                │             │
518       │raw      │ -300  │ ip, ip6, inet  │ all         │
519       ├─────────┼───────┼────────────────┼─────────────┤
520       │         │       │                │             │
521       │mangle   │ -150  │ ip, ip6, inet  │ all         │
522       ├─────────┼───────┼────────────────┼─────────────┤
523       │         │       │                │             │
524       │dstnat   │ -100  │ ip, ip6, inet  │ prerouting  │
525       ├─────────┼───────┼────────────────┼─────────────┤
526       │         │       │                │             │
527       │filter   │ 0     │ ip, ip6, inet, │ all         │
528       │         │       │ arp, netdev    │             │
529       ├─────────┼───────┼────────────────┼─────────────┤
530       │         │       │                │             │
531       │security │ 50    │ ip, ip6, inet  │ all         │
532       ├─────────┼───────┼────────────────┼─────────────┤
533       │         │       │                │             │
534       │srcnat   │ 100   │ ip, ip6, inet  │ postrouting │
535       └─────────┴───────┴────────────────┴─────────────┘
536
537       Table 7. Standard priority names and hook compatibility for the bridge
538       family
539       ┌───────┬───────┬─────────────┐
540       │       │       │             │
541       │Name   │ Value │ Hooks       │
542       ├───────┼───────┼─────────────┤
543       │       │       │             │
544       │dstnat │ -300  │ prerouting  │
545       ├───────┼───────┼─────────────┤
546       │       │       │             │
547       │filter │ -200  │ all         │
548       ├───────┼───────┼─────────────┤
549       │       │       │             │
550       │out    │ 100   │ output      │
551       ├───────┼───────┼─────────────┤
552       │       │       │             │
553       │srcnat │ 300   │ postrouting │
554       └───────┴───────┴─────────────┘
555
556       Basic arithmetic expressions (addition and subtraction) can also be
557       achieved with these standard names to ease relative prioritizing, e.g.
558       mangle - 5 stands for -155. Values will also be printed like this until
559       the value is not further than 10 form the standard value.
560
561       Base chains also allow to set the chain’s policy, i.e. what happens to
562       packets not explicitly accepted or refused in contained rules.
563       Supported policy values are accept (which is the default) or drop.
564

RULES

566           {add | insert} rule [family] table chain [handle handle | index index] statement ... [comment comment]
567           replace rule [family] table chain handle handle statement ... [comment comment]
568           delete rule [family] table chain handle handle
569
570       Rules are added to chains in the given table. If the family is not
571       specified, the ip family is used. Rules are constructed from two kinds
572       of components according to a set of grammatical rules: expressions and
573       statements.
574
575       The add and insert commands support an optional location specifier,
576       which is either a handle or the index (starting at zero) of an existing
577       rule. Internally, rule locations are always identified by handle and
578       the translation from index happens in userspace. This has two potential
579       implications in case a concurrent ruleset change happens after the
580       translation was done: The effective rule index might change if a rule
581       was inserted or deleted before the referred one. If the referred rule
582       was deleted, the command is rejected by the kernel just as if an
583       invalid handle was given.
584
585       A comment is a single word or a double-quoted (") multi-word string
586       which can be used to make notes regarding the actual rule. Note: If you
587       use bash for adding rules, you have to escape the quotation marks, e.g.
588       \"enable ssh for servers\".
589
590
591
592
593
594
595
596
597
598       add       Add a new rule described
599                 by the list of statements.
600                 The rule is appended to
601                 the given chain unless a
602                 location is specified, in
603                 which case the rule is
604                 inserted after the
605                 specified rule.
606
607       insert    Same as add except the
608                 rule is inserted at the
609                 beginning of the chain or
610                 before the specified rule.
611
612       replace   Similar to add, but the
613                 rule replaces the
614                 specified rule.
615
616       delete    Delete the specified rule.
617
618
619       add a rule to ip table output chain.
620
621           nft add rule filter output ip daddr 192.168.0.0/24 accept # 'ip filter' is assumed
622           # same command, slightly more verbose
623           nft add rule ip filter output ip daddr 192.168.0.0/24 accept
624
625       delete rule from inet table.
626
627           # nft -a list ruleset
628           table inet filter {
629                   chain input {
630                           type filter hook input priority 0; policy accept;
631                           ct state established,related accept # handle 4
632                           ip saddr 10.1.1.1 tcp dport ssh accept # handle 5
633                     ...
634           # delete the rule with handle 5
635           # nft delete rule inet filter input handle 5
636
637

SETS

639       nftables offers two kinds of set concepts. Anonymous sets are sets that
640       have no specific name. The set members are enclosed in curly braces,
641       with commas to separate elements when creating the rule the set is used
642       in. Once that rule is removed, the set is removed as well. They cannot
643       be updated, i.e. once an anonymous set is declared it cannot be changed
644       anymore except by removing/altering the rule that uses the anonymous
645       set.
646
647       Using anonymous sets to accept particular subnets and ports.
648
649           nft add rule filter input ip saddr { 10.0.0.0/8, 192.168.0.0/16 } tcp dport { 22, 443 } accept
650
651       Named sets are sets that need to be defined first before they can be
652       referenced in rules. Unlike anonymous sets, elements can be added to or
653       removed from a named set at any time. Sets are referenced from rules
654       using an @ prefixed to the sets name.
655
656       Using named sets to accept addresses and ports.
657
658           nft add rule filter input ip saddr @allowed_hosts tcp dport @allowed_ports accept
659
660       The sets allowed_hosts and allowed_ports need to be created first. The
661       next section describes nft set syntax in more detail.
662
663           add set [family] table set { type type | typeof expression ; [flags flags ;] [timeout timeout ;] [gc-interval gc-interval ;] [elements = { element[, ...] } ;] [size size ;] [policy policy ;] [auto-merge ;] }
664           {delete | list | flush} set [family] table set
665           list sets [family]
666           delete set [family] table handle handle
667           {add | delete} element [family] table set { element[, ...] }
668
669       Sets are element containers of a user-defined data type, they are
670       uniquely identified by a user-defined name and attached to tables.
671       Their behaviour can be tuned with the flags that can be specified at
672       set creation time.
673
674
675       add      Add a new set in the
676                specified table. See the
677                Set specification table
678                below for more information
679                about how to specify a
680                sets properties.
681
682       delete   Delete the specified set.
683
684       list     Display the elements in
685                the specified set.
686
687       flush    Remove all elements from
688                the specified set.
689
690
691       Table 8. Set specifications
692       ┌────────────┬──────────────────────┬─────────────────────┐
693Keyword     Description          Type                
694       ├────────────┼──────────────────────┼─────────────────────┤
695       │            │                      │                     │
696       │type        │ data type of set     │ string: ipv4_addr,  │
697       │            │ elements             │ ipv6_addr,          │
698       │            │                      │ ether_addr,         │
699       │            │                      │ inet_proto,         │
700       │            │                      │ inet_service, mark  │
701       ├────────────┼──────────────────────┼─────────────────────┤
702       │            │                      │                     │
703       │typeof      │ data type of set     │ expression to       │
704       │            │ element              │ derive the data     │
705       │            │                      │ type from           │
706       ├────────────┼──────────────────────┼─────────────────────┤
707       │            │                      │                     │
708       │flags       │ set flags            │ string: constant,   │
709       │            │                      │ dynamic, interval,  │
710       │            │                      │ timeout             │
711       ├────────────┼──────────────────────┼─────────────────────┤
712       │            │                      │                     │
713       │timeout     │ time an element      │ string, decimal     │
714       │            │ stays in the set,    │ followed by unit.   │
715       │            │ mandatory if set is  │ Units are: d, h, m, │
716       │            │ added to from the    │ s                   │
717       │            │ packet path          │                     │
718       │            │ (ruleset).           │                     │
719       ├────────────┼──────────────────────┼─────────────────────┤
720       │            │                      │                     │
721       │gc-interval │ garbage collection   │ string, decimal     │
722       │            │ interval, only       │ followed by unit.   │
723       │            │ available when       │ Units are: d, h, m, │
724       │            │ timeout or flag      │ s                   │
725       │            │ timeout are active   │                     │
726       ├────────────┼──────────────────────┼─────────────────────┤
727       │            │                      │                     │
728       │elements    │ elements contained   │ set data type       │
729       │            │ by the set           │                     │
730       ├────────────┼──────────────────────┼─────────────────────┤
731       │            │                      │                     │
732       │size        │ maximum number of    │ unsigned integer    │
733       │            │ elements in the      │ (64 bit)            │
734       │            │ set, mandatory if    │                     │
735       │            │ set is added to      │                     │
736       │            │ from the packet      │                     │
737       │            │ path (ruleset).      │                     │
738       ├────────────┼──────────────────────┼─────────────────────┤
739       │            │                      │                     │
740       │policy      │ set policy           │ string: performance │
741       │            │                      │ [default], memory   │
742       ├────────────┼──────────────────────┼─────────────────────┤
743       │            │                      │                     │
744       │auto-merge  │ automatic merge of   │                     │
745       │            │ adjacent/overlapping │                     │
746       │            │ set elements (only   │                     │
747       │            │ for interval sets)   │                     │
748       └────────────┴──────────────────────┴─────────────────────┘
749

MAPS

751           add map [family] table map { type type | typeof expression [flags flags ;] [elements = { element[, ...] } ;] [size size ;] [policy policy ;] }
752           {delete | list | flush} map [family] table map
753           list maps [family]
754
755       Maps store data based on some specific key used as input. They are
756       uniquely identified by a user-defined name and attached to tables.
757
758
759       add              Add a new map in the
760                        specified table.
761
762       delete           Delete the specified map.
763
764       list             Display the elements in
765                        the specified map.
766
767       flush            Remove all elements from
768                        the specified map.
769
770       add element      Comma-separated list of
771                        elements to add into the
772                        specified map.
773
774       delete element   Comma-separated list of
775                        element keys to delete
776                        from the specified map.
777
778
779       Table 9. Map specifications
780       ┌─────────┬─────────────────────┬─────────────────────┐
781Keyword  Description         Type                
782       ├─────────┼─────────────────────┼─────────────────────┤
783       │         │                     │                     │
784       │type     │ data type of map    │ string: ipv4_addr,  │
785       │         │ elements            │ ipv6_addr,          │
786       │         │                     │ ether_addr,         │
787       │         │                     │ inet_proto,         │
788       │         │                     │ inet_service, mark, │
789       │         │                     │ counter, quota.     │
790       │         │                     │ Counter and quota   │
791       │         │                     │ can’t be used as    │
792       │         │                     │ keys                │
793       ├─────────┼─────────────────────┼─────────────────────┤
794       │         │                     │                     │
795       │typeof   │ data type of set    │ expression to       │
796       │         │ element             │ derive the data     │
797       │         │                     │ type from           │
798       ├─────────┼─────────────────────┼─────────────────────┤
799       │         │                     │                     │
800       │flags    │ map flags           │ string: constant,   │
801       │         │                     │ interval            │
802       ├─────────┼─────────────────────┼─────────────────────┤
803       │         │                     │                     │
804       │elements │ elements contained  │ map data type       │
805       │         │ by the map          │                     │
806       ├─────────┼─────────────────────┼─────────────────────┤
807       │         │                     │                     │
808       │size     │ maximum number of   │ unsigned integer    │
809       │         │ elements in the map │ (64 bit)            │
810       ├─────────┼─────────────────────┼─────────────────────┤
811       │         │                     │                     │
812       │policy   │ map policy          │ string: performance │
813       │         │                     │ [default], memory   │
814       └─────────┴─────────────────────┴─────────────────────┘
815

ELEMENTS

817           {add | create | delete | get } element [family] table set { ELEMENT[, ...] }
818
819           ELEMENT := key_expression OPTIONS [: value_expression]
820           OPTIONS := [timeout TIMESPEC] [expires TIMESPEC] [comment string]
821           TIMESPEC := [numd][numh][numm][num[s]]
822
823       Element-related commands allow to change contents of named sets and
824       maps. key_expression is typically a value matching the set type.
825       value_expression is not allowed in sets but mandatory when adding to
826       maps, where it matches the data part in it’s type definition. When
827       deleting from maps, it may be specified but is optional as
828       key_expression uniquely identifies the element.
829
830       create command is similar to add with the exception that none of the
831       listed elements may already exist.
832
833       get command is useful to check if an element is contained in a set
834       which may be non-trivial in very large and/or interval sets. In the
835       latter case, the containing interval is returned instead of just the
836       element itself.
837
838       Table 10. Element options
839       ┌────────┬───────────────────────────┐
840Option  Description               
841       ├────────┼───────────────────────────┤
842       │        │                           │
843       │timeout │ timeout value for         │
844       │        │ sets/maps with flag       │
845       │        │ timeout                   
846       ├────────┼───────────────────────────┤
847       │        │                           │
848       │expires │ the time until given      │
849       │        │ element expires, useful   │
850       │        │ for ruleset replication   │
851       │        │ only                      │
852       ├────────┼───────────────────────────┤
853       │        │                           │
854       │comment │ per element comment field │
855       └────────┴───────────────────────────┘
856

FLOWTABLES

858           {add | create} flowtable [family] table flowtable { hook hook priority priority ; devices = { device[, ...] } ; }
859           list flowtables [family]
860           {delete | list} flowtable [family] table flowtable
861           delete flowtable [family] table handle handle
862
863       Flowtables allow you to accelerate packet forwarding in software.
864       Flowtables entries are represented through a tuple that is composed of
865       the input interface, source and destination address, source and
866       destination port; and layer 3/4 protocols. Each entry also caches the
867       destination interface and the gateway address - to update the
868       destination link-layer address - to forward packets. The ttl and
869       hoplimit fields are also decremented. Hence, flowtables provides an
870       alternative path that allow packets to bypass the classic forwarding
871       path. Flowtables reside in the ingress hook that is located before the
872       prerouting hook. You can select which flows you want to offload through
873       the flow expression from the forward chain. Flowtables are identified
874       by their address family and their name. The address family must be one
875       of ip, ip6, or inet. The inet address family is a dummy family which is
876       used to create hybrid IPv4/IPv6 tables. When no address family is
877       specified, ip is used by default.
878
879       The priority can be a signed integer or filter which stands for 0.
880       Addition and subtraction can be used to set relative priority, e.g.
881       filter + 5 equals to 5.
882
883
884       add      Add a new flowtable for
885                the given family with the
886                given name.
887
888       delete   Delete the specified
889                flowtable.
890
891       list     List all flowtables.
892
893

STATEFUL OBJECTS

895           {add | delete | list | reset} type [family] table object
896           delete type [family] table handle handle
897           list counters [family]
898           list quotas [family]
899
900       Stateful objects are attached to tables and are identified by an unique
901       name. They group stateful information from rules, to reference them in
902       rules the keywords "type name" are used e.g. "counter name".
903
904
905       add      Add a new stateful object
906                in the specified table.
907
908       delete   Delete the specified
909                object.
910
911       list     Display stateful
912                information the object
913                holds.
914
915       reset    List-and-reset stateful
916                object.
917
918
919   CT HELPER
920           ct helper helper { type type protocol protocol ; [l3proto family ;] }
921
922       Ct helper is used to define connection tracking helpers that can then
923       be used in combination with the ct helper set statement. type and
924       protocol are mandatory, l3proto is derived from the table family by
925       default, i.e. in the inet table the kernel will try to load both the
926       ipv4 and ipv6 helper backends, if they are supported by the kernel.
927
928       Table 11. conntrack helper specifications
929       ┌─────────┬─────────────────────┬─────────────────────┐
930Keyword  Description         Type                
931       ├─────────┼─────────────────────┼─────────────────────┤
932       │         │                     │                     │
933       │type     │ name of helper type │ quoted string (e.g. │
934       │         │                     │ "ftp")              │
935       ├─────────┼─────────────────────┼─────────────────────┤
936       │         │                     │                     │
937       │protocol │ layer 4 protocol of │ string (e.g. ip)    │
938       │         │ the helper          │                     │
939       ├─────────┼─────────────────────┼─────────────────────┤
940       │         │                     │                     │
941       │l3proto  │ layer 3 protocol of │ address family      │
942       │         │ the helper          │ (e.g. ip)           │
943       └─────────┴─────────────────────┴─────────────────────┘
944
945       defining and assigning ftp helper.
946
947           Unlike iptables, helper assignment needs to be performed after the conntrack
948           lookup has completed, for example with the default 0 hook priority.
949
950           table inet myhelpers {
951             ct helper ftp-standard {
952                type "ftp" protocol tcp
953             }
954             chain prerouting {
955                 type filter hook prerouting priority 0;
956                 tcp dport 21 ct helper set "ftp-standard"
957             }
958           }
959
960
961   CT TIMEOUT
962           ct timeout name { protocol protocol ; policy = { state: value [, ...] } ; [l3proto family ;] }
963
964       Ct timeout is used to update connection tracking timeout values.Timeout
965       policies are assigned with the ct timeout set statement. protocol and
966       policy are mandatory, l3proto is derived from the table family by
967       default.
968
969       Table 12. conntrack timeout specifications
970       ┌─────────┬─────────────────────┬──────────────────┐
971Keyword  Description         Type             
972       ├─────────┼─────────────────────┼──────────────────┤
973       │         │                     │                  │
974       │protocol │ layer 4 protocol of │ string (e.g. ip) │
975       │         │ the timeout object  │                  │
976       ├─────────┼─────────────────────┼──────────────────┤
977       │         │                     │                  │
978       │state    │ connection state    │ string (e.g.     │
979       │         │ name                │ "established")   │
980       ├─────────┼─────────────────────┼──────────────────┤
981       │         │                     │                  │
982       │value    │ timeout value for   │ unsigned integer │
983       │         │ connection state    │                  │
984       ├─────────┼─────────────────────┼──────────────────┤
985       │         │                     │                  │
986       │l3proto  │ layer 3 protocol of │ address family   │
987       │         │ the timeout object  │ (e.g. ip)        │
988       └─────────┴─────────────────────┴──────────────────┘
989
990       defining and assigning ct timeout policy.
991
992           table ip filter {
993                   ct timeout customtimeout {
994                           protocol tcp;
995                           l3proto ip
996                           policy = { established: 120, close: 20 }
997                   }
998
999                   chain output {
1000                           type filter hook output priority filter; policy accept;
1001                           ct timeout set "customtimeout"
1002                   }
1003           }
1004
1005       testing the updated timeout policy.
1006
1007           % conntrack -E
1008
1009           It should display:
1010
1011           [UPDATE] tcp      6 120 ESTABLISHED src=172.16.19.128 dst=172.16.19.1
1012           sport=22 dport=41360 [UNREPLIED] src=172.16.19.1 dst=172.16.19.128
1013           sport=41360 dport=22
1014
1015
1016   CT EXPECTATION
1017           ct expectation name { protocol protocol ; dport dport ; timeout timeout ; size size ; [*l3proto family ;] }
1018
1019       Ct expectation is used to create connection expectations. Expectations
1020       are assigned with the ct expectation set statement. protocol, dport,
1021       timeout and size are mandatory, l3proto is derived from the table
1022       family by default.
1023
1024       Table 13. conntrack expectation specifications
1025       ┌─────────┬─────────────────────┬──────────────────┐
1026Keyword  Description         Type             
1027       ├─────────┼─────────────────────┼──────────────────┤
1028       │         │                     │                  │
1029       │protocol │ layer 4 protocol of │ string (e.g. ip) │
1030       │         │ the expectation     │                  │
1031       │         │ object              │                  │
1032       ├─────────┼─────────────────────┼──────────────────┤
1033       │         │                     │                  │
1034       │dport    │ destination port of │ unsigned integer │
1035       │         │ expected connection │                  │
1036       ├─────────┼─────────────────────┼──────────────────┤
1037       │         │                     │                  │
1038       │timeout  │ timeout value for   │ unsigned integer │
1039       │         │ expectation         │                  │
1040       ├─────────┼─────────────────────┼──────────────────┤
1041       │         │                     │                  │
1042       │size     │ size value for      │ unsigned integer │
1043       │         │ expectation         │                  │
1044       ├─────────┼─────────────────────┼──────────────────┤
1045       │         │                     │                  │
1046       │l3proto  │ layer 3 protocol of │ address family   │
1047       │         │ the expectation     │ (e.g. ip)        │
1048       │         │ object              │                  │
1049       └─────────┴─────────────────────┴──────────────────┘
1050
1051       defining and assigning ct expectation policy.
1052
1053           table ip filter {
1054                   ct expectation expect {
1055                           protocol udp
1056                           dport 9876
1057                           timeout 2m
1058                           size 8
1059                           l3proto ip
1060                   }
1061
1062                   chain input {
1063                           type filter hook input priority filter; policy accept;
1064                           ct expectation set "expect"
1065                   }
1066           }
1067
1068
1069   COUNTER
1070           counter [packets bytes]
1071
1072       Table 14. Counter specifications
1073       ┌────────┬──────────────────┬──────────────────┐
1074Keyword Description      Type             
1075       ├────────┼──────────────────┼──────────────────┤
1076       │        │                  │                  │
1077       │packets │ initial count of │ unsigned integer │
1078       │        │ packets          │ (64 bit)         │
1079       ├────────┼──────────────────┼──────────────────┤
1080       │        │                  │                  │
1081       │bytes   │ initial count of │ unsigned integer │
1082       │        │ bytes            │ (64 bit)         │
1083       └────────┴──────────────────┴──────────────────┘
1084
1085   QUOTA
1086           quota [over | until] [used]
1087
1088       Table 15. Quota specifications
1089       ┌────────┬───────────────────┬────────────────────┐
1090Keyword Description       Type               
1091       ├────────┼───────────────────┼────────────────────┤
1092       │        │                   │                    │
1093       │quota   │ quota limit, used │ Two arguments,     │
1094       │        │ as the quota name │ unsigned integer   │
1095       │        │                   │ (64 bit) and       │
1096       │        │                   │ string: bytes,     │
1097       │        │                   │ kbytes, mbytes.    │
1098       │        │                   │ "over" and "until" │
1099       │        │                   │ go before these    │
1100       │        │                   │ arguments          │
1101       ├────────┼───────────────────┼────────────────────┤
1102       │        │                   │                    │
1103       │used    │ initial value of  │ Two arguments,     │
1104       │        │ used quota        │ unsigned integer   │
1105       │        │                   │ (64 bit) and       │
1106       │        │                   │ string: bytes,     │
1107       │        │                   │ kbytes, mbytes     │
1108       └────────┴───────────────────┴────────────────────┘
1109

EXPRESSIONS

1111       Expressions represent values, either constants like network addresses,
1112       port numbers, etc., or data gathered from the packet during ruleset
1113       evaluation. Expressions can be combined using binary, logical,
1114       relational and other types of expressions to form complex or relational
1115       (match) expressions. They are also used as arguments to certain types
1116       of operations, like NAT, packet marking etc.
1117
1118       Each expression has a data type, which determines the size, parsing and
1119       representation of symbolic values and type compatibility with other
1120       expressions.
1121
1122   DESCRIBE COMMAND
1123           describe expression | data type
1124
1125       The describe command shows information about the type of an expression
1126       and its data type. A data type may also be given, in which nft will
1127       display more information about the type.
1128
1129       The describe command.
1130
1131           $ nft describe tcp flags
1132           payload expression, datatype tcp_flag (TCP flag) (basetype bitmask, integer), 8 bits
1133
1134           predefined symbolic constants:
1135           fin                           0x01
1136           syn                           0x02
1137           rst                           0x04
1138           psh                           0x08
1139           ack                           0x10
1140           urg                           0x20
1141           ecn                           0x40
1142           cwr                           0x80
1143
1144

DATA TYPES

1146       Data types determine the size, parsing and representation of symbolic
1147       values and type compatibility of expressions. A number of global data
1148       types exist, in addition some expression types define further data
1149       types specific to the expression type. Most data types have a fixed
1150       size, some however may have a dynamic size, f.i. the string type. Some
1151       types also have predefined symbolic constants. Those can be listed
1152       using the nft describe command:
1153
1154           $ nft describe ct_state
1155           datatype ct_state (conntrack state) (basetype bitmask, integer), 32 bits
1156
1157           pre-defined symbolic constants (in hexadecimal):
1158           invalid                         0x00000001
1159           new ...
1160
1161       Types may be derived from lower order types, f.i. the IPv4 address type
1162       is derived from the integer type, meaning an IPv4 address can also be
1163       specified as an integer value.
1164
1165       In certain contexts (set and map definitions), it is necessary to
1166       explicitly specify a data type. Each type has a name which is used for
1167       this.
1168
1169   INTEGER TYPE
1170       ┌────────┬─────────┬──────────┬───────────┐
1171Name    Keyword Size     Base type 
1172       ├────────┼─────────┼──────────┼───────────┤
1173       │        │         │          │           │
1174       │Integer │ integer │ variable │ -         │
1175       └────────┴─────────┴──────────┴───────────┘
1176
1177       The integer type is used for numeric values. It may be specified as a
1178       decimal, hexadecimal or octal number. The integer type does not have a
1179       fixed size, its size is determined by the expression for which it is
1180       used.
1181
1182   BITMASK TYPE
1183       ┌────────┬─────────┬──────────┬───────────┐
1184Name    Keyword Size     Base type 
1185       ├────────┼─────────┼──────────┼───────────┤
1186       │        │         │          │           │
1187       │Bitmask │ bitmask │ variable │ integer   │
1188       └────────┴─────────┴──────────┴───────────┘
1189
1190       The bitmask type (bitmask) is used for bitmasks.
1191
1192   STRING TYPE
1193       ┌───────┬─────────┬──────────┬───────────┐
1194Name   Keyword Size     Base type 
1195       ├───────┼─────────┼──────────┼───────────┤
1196       │       │         │          │           │
1197       │String │ string  │ variable │ -         │
1198       └───────┴─────────┴──────────┴───────────┘
1199
1200       The string type is used for character strings. A string begins with an
1201       alphabetic character (a-zA-Z) followed by zero or more alphanumeric
1202       characters or the characters /, -, _ and .. In addition, anything
1203       enclosed in double quotes (") is recognized as a string.
1204
1205       String specification.
1206
1207           # Interface name
1208           filter input iifname eth0
1209
1210           # Weird interface name
1211           filter input iifname "(eth0)"
1212
1213
1214   LINK LAYER ADDRESS TYPE
1215       ┌───────────┬─────────┬──────────┬───────────┐
1216Name       Keyword Size     Base type 
1217       ├───────────┼─────────┼──────────┼───────────┤
1218       │           │         │          │           │
1219       │Link layer │ lladdr  │ variable │ integer   │
1220       │address    │         │          │           │
1221       └───────────┴─────────┴──────────┴───────────┘
1222
1223       The link layer address type is used for link layer addresses. Link
1224       layer addresses are specified as a variable amount of groups of two
1225       hexadecimal digits separated using colons (:).
1226
1227       Link layer address specification.
1228
1229           # Ethernet destination MAC address
1230           filter input ether daddr 20:c9:d0:43:12:d9
1231
1232
1233   IPV4 ADDRESS TYPE
1234       ┌─────────────┬───────────┬────────┬───────────┐
1235Name         Keyword   Size   Base type 
1236       ├─────────────┼───────────┼────────┼───────────┤
1237       │             │           │        │           │
1238       │IPV4 address │ ipv4_addr │ 32 bit │ integer   │
1239       └─────────────┴───────────┴────────┴───────────┘
1240
1241       The IPv4 address type is used for IPv4 addresses. Addresses are
1242       specified in either dotted decimal, dotted hexadecimal, dotted octal,
1243       decimal, hexadecimal, octal notation or as a host name. A host name
1244       will be resolved using the standard system resolver.
1245
1246       IPv4 address specification.
1247
1248           # dotted decimal notation
1249           filter output ip daddr 127.0.0.1
1250
1251           # host name
1252           filter output ip daddr localhost
1253
1254
1255   IPV6 ADDRESS TYPE
1256       ┌─────────────┬───────────┬─────────┬───────────┐
1257Name         Keyword   Size    Base type 
1258       ├─────────────┼───────────┼─────────┼───────────┤
1259       │             │           │         │           │
1260       │IPv6 address │ ipv6_addr │ 128 bit │ integer   │
1261       └─────────────┴───────────┴─────────┴───────────┘
1262
1263       The IPv6 address type is used for IPv6 addresses. Addresses are
1264       specified as a host name or as hexadecimal halfwords separated by
1265       colons. Addresses might be enclosed in square brackets ("[]") to
1266       differentiate them from port numbers.
1267
1268       IPv6 address specification.
1269
1270           # abbreviated loopback address
1271           filter output ip6 daddr ::1
1272
1273       IPv6 address specification with bracket notation.
1274
1275           # without [] the port number (22) would be parsed as part of the
1276           # ipv6 address
1277           ip6 nat prerouting tcp dport 2222 dnat to [1ce::d0]:22
1278
1279
1280   BOOLEAN TYPE
1281       ┌────────┬─────────┬───────┬───────────┐
1282Name    Keyword Size  Base type 
1283       ├────────┼─────────┼───────┼───────────┤
1284       │        │         │       │           │
1285       │Boolean │ boolean │ 1 bit │ integer   │
1286       └────────┴─────────┴───────┴───────────┘
1287
1288       The boolean type is a syntactical helper type in userspace. Its use is
1289       in the right-hand side of a (typically implicit) relational expression
1290       to change the expression on the left-hand side into a boolean check
1291       (usually for existence).
1292
1293       Table 16. The following keywords will automatically resolve into a
1294       boolean type with given value
1295       ┌────────┬───────┐
1296Keyword Value 
1297       ├────────┼───────┤
1298       │        │       │
1299       │exists  │ 1     │
1300       ├────────┼───────┤
1301       │        │       │
1302       │missing │ 0     │
1303       └────────┴───────┘
1304
1305       Table 17. expressions support a boolean comparison
1306       ┌───────────┬─────────────────────────┐
1307Expression Behaviour               
1308       ├───────────┼─────────────────────────┤
1309       │           │                         │
1310       │fib        │ Check route existence.  │
1311       ├───────────┼─────────────────────────┤
1312       │           │                         │
1313       │exthdr     │ Check IPv6 extension    │
1314       │           │ header existence.       │
1315       ├───────────┼─────────────────────────┤
1316       │           │                         │
1317       │tcp option │ Check TCP option header │
1318       │           │ existence.              │
1319       └───────────┴─────────────────────────┘
1320
1321       Boolean specification.
1322
1323           # match if route exists
1324           filter input fib daddr . iif oif exists
1325
1326           # match only non-fragmented packets in IPv6 traffic
1327           filter input exthdr frag missing
1328
1329           # match if TCP timestamp option is present
1330           filter input tcp option timestamp exists
1331
1332
1333   ICMP TYPE TYPE
1334       ┌──────────┬───────────┬───────┬───────────┐
1335Name      Keyword   Size  Base type 
1336       ├──────────┼───────────┼───────┼───────────┤
1337       │          │           │       │           │
1338       │ICMP Type │ icmp_type │ 8 bit │ integer   │
1339       └──────────┴───────────┴───────┴───────────┘
1340
1341       The ICMP Type type is used to conveniently specify the ICMP header’s
1342       type field.
1343
1344       Table 18. Keywords may be used when specifying the ICMP type
1345       ┌────────────────────────┬───────┐
1346Keyword                 Value 
1347       ├────────────────────────┼───────┤
1348       │                        │       │
1349       │echo-reply              │ 0     │
1350       ├────────────────────────┼───────┤
1351       │                        │       │
1352       │destination-unreachable │ 3     │
1353       ├────────────────────────┼───────┤
1354       │                        │       │
1355       │source-quench           │ 4     │
1356       ├────────────────────────┼───────┤
1357       │                        │       │
1358       │redirect                │ 5     │
1359       ├────────────────────────┼───────┤
1360       │                        │       │
1361       │echo-request            │ 8     │
1362       ├────────────────────────┼───────┤
1363       │                        │       │
1364       │router-advertisement    │ 9     │
1365       ├────────────────────────┼───────┤
1366       │                        │       │
1367       │router-solicitation     │ 10    │
1368       ├────────────────────────┼───────┤
1369       │                        │       │
1370       │time-exceeded           │ 11    │
1371       ├────────────────────────┼───────┤
1372       │                        │       │
1373       │parameter-problem       │ 12    │
1374       ├────────────────────────┼───────┤
1375       │                        │       │
1376       │timestamp-request       │ 13    │
1377       ├────────────────────────┼───────┤
1378       │                        │       │
1379       │timestamp-reply         │ 14    │
1380       ├────────────────────────┼───────┤
1381       │                        │       │
1382       │info-request            │ 15    │
1383       ├────────────────────────┼───────┤
1384       │                        │       │
1385       │info-reply              │ 16    │
1386       ├────────────────────────┼───────┤
1387       │                        │       │
1388       │address-mask-request    │ 17    │
1389       ├────────────────────────┼───────┤
1390       │                        │       │
1391       │address-mask-reply      │ 18    │
1392       └────────────────────────┴───────┘
1393
1394       ICMP Type specification.
1395
1396           # match ping packets
1397           filter output icmp type { echo-request, echo-reply }
1398
1399
1400   ICMP CODE TYPE
1401       ┌──────────┬───────────┬───────┬───────────┐
1402Name      Keyword   Size  Base type 
1403       ├──────────┼───────────┼───────┼───────────┤
1404       │          │           │       │           │
1405       │ICMP Code │ icmp_code │ 8 bit │ integer   │
1406       └──────────┴───────────┴───────┴───────────┘
1407
1408       The ICMP Code type is used to conveniently specify the ICMP header’s
1409       code field.
1410
1411       Table 19. Keywords may be used when specifying the ICMP code
1412       ┌─────────────────┬───────┐
1413Keyword          Value 
1414       ├─────────────────┼───────┤
1415       │                 │       │
1416       │net-unreachable  │ 0     │
1417       ├─────────────────┼───────┤
1418       │                 │       │
1419       │host-unreachable │ 1     │
1420       ├─────────────────┼───────┤
1421       │                 │       │
1422       │prot-unreachable │ 2     │
1423       ├─────────────────┼───────┤
1424       │                 │       │
1425       │port-unreachable │ 3     │
1426       ├─────────────────┼───────┤
1427       │                 │       │
1428       │frag-needed      │ 4     │
1429       ├─────────────────┼───────┤
1430       │                 │       │
1431       │net-prohibited   │ 9     │
1432       ├─────────────────┼───────┤
1433       │                 │       │
1434       │host-prohibited  │ 10    │
1435       ├─────────────────┼───────┤
1436       │                 │       │
1437       │admin-prohibited │ 13    │
1438       └─────────────────┴───────┘
1439
1440   ICMPV6 TYPE TYPE
1441       ┌────────────┬────────────┬───────┬───────────┐
1442Name        Keyword    Size  Base type 
1443       ├────────────┼────────────┼───────┼───────────┤
1444       │            │            │       │           │
1445       │ICMPv6 Type │ icmpx_code │ 8 bit │ integer   │
1446       └────────────┴────────────┴───────┴───────────┘
1447
1448       The ICMPv6 Type type is used to conveniently specify the ICMPv6
1449       header’s type field.
1450
1451       Table 20. keywords may be used when specifying the ICMPv6 type:
1452       ┌────────────────────────┬───────┐
1453Keyword                 Value 
1454       ├────────────────────────┼───────┤
1455       │                        │       │
1456       │destination-unreachable │ 1     │
1457       ├────────────────────────┼───────┤
1458       │                        │       │
1459       │packet-too-big          │ 2     │
1460       ├────────────────────────┼───────┤
1461       │                        │       │
1462       │time-exceeded           │ 3     │
1463       ├────────────────────────┼───────┤
1464       │                        │       │
1465       │parameter-problem       │ 4     │
1466       ├────────────────────────┼───────┤
1467       │                        │       │
1468       │echo-request            │ 128   │
1469       ├────────────────────────┼───────┤
1470       │                        │       │
1471       │echo-reply              │ 129   │
1472       ├────────────────────────┼───────┤
1473       │                        │       │
1474       │mld-listener-query      │ 130   │
1475       ├────────────────────────┼───────┤
1476       │                        │       │
1477       │mld-listener-report     │ 131   │
1478       ├────────────────────────┼───────┤
1479       │                        │       │
1480       │mld-listener-done       │ 132   │
1481       ├────────────────────────┼───────┤
1482       │                        │       │
1483       │mld-listener-reduction  │ 132   │
1484       ├────────────────────────┼───────┤
1485       │                        │       │
1486       │nd-router-solicit       │ 133   │
1487       ├────────────────────────┼───────┤
1488       │                        │       │
1489       │nd-router-advert        │ 134   │
1490       ├────────────────────────┼───────┤
1491       │                        │       │
1492       │nd-neighbor-solicit     │ 135   │
1493       ├────────────────────────┼───────┤
1494       │                        │       │
1495       │nd-neighbor-advert      │ 136   │
1496       ├────────────────────────┼───────┤
1497       │                        │       │
1498       │nd-redirect             │ 137   │
1499       ├────────────────────────┼───────┤
1500       │                        │       │
1501       │router-renumbering      │ 138   │
1502       ├────────────────────────┼───────┤
1503       │                        │       │
1504       │ind-neighbor-solicit    │ 141   │
1505       ├────────────────────────┼───────┤
1506       │                        │       │
1507       │ind-neighbor-advert     │ 142   │
1508       ├────────────────────────┼───────┤
1509       │                        │       │
1510       │mld2-listener-report    │ 143   │
1511       └────────────────────────┴───────┘
1512
1513       ICMPv6 Type specification.
1514
1515           # match ICMPv6 ping packets
1516           filter output icmpv6 type { echo-request, echo-reply }
1517
1518
1519   ICMPV6 CODE TYPE
1520       ┌────────────┬─────────────┬───────┬───────────┐
1521Name        Keyword     Size  Base type 
1522       ├────────────┼─────────────┼───────┼───────────┤
1523       │            │             │       │           │
1524       │ICMPv6 Code │ icmpv6_code │ 8 bit │ integer   │
1525       └────────────┴─────────────┴───────┴───────────┘
1526
1527       The ICMPv6 Code type is used to conveniently specify the ICMPv6
1528       header’s code field.
1529
1530       Table 21. keywords may be used when specifying the ICMPv6 code
1531       ┌─────────────────┬───────┐
1532Keyword          Value 
1533       ├─────────────────┼───────┤
1534       │                 │       │
1535       │no-route         │ 0     │
1536       ├─────────────────┼───────┤
1537       │                 │       │
1538       │admin-prohibited │ 1     │
1539       ├─────────────────┼───────┤
1540       │                 │       │
1541       │addr-unreachable │ 3     │
1542       ├─────────────────┼───────┤
1543       │                 │       │
1544       │port-unreachable │ 4     │
1545       ├─────────────────┼───────┤
1546       │                 │       │
1547       │policy-fail      │ 5     │
1548       ├─────────────────┼───────┤
1549       │                 │       │
1550       │reject-route     │ 6     │
1551       └─────────────────┴───────┘
1552
1553   ICMPVX CODE TYPE
1554       ┌────────────┬─────────────┬───────┬───────────┐
1555Name        Keyword     Size  Base type 
1556       ├────────────┼─────────────┼───────┼───────────┤
1557       │            │             │       │           │
1558       │ICMPvX Code │ icmpv6_type │ 8 bit │ integer   │
1559       └────────────┴─────────────┴───────┴───────────┘
1560
1561       The ICMPvX Code type abstraction is a set of values which overlap
1562       between ICMP and ICMPv6 Code types to be used from the inet family.
1563
1564       Table 22. keywords may be used when specifying the ICMPvX code
1565       ┌─────────────────┬───────┐
1566Keyword          Value 
1567       ├─────────────────┼───────┤
1568       │                 │       │
1569       │no-route         │ 0     │
1570       ├─────────────────┼───────┤
1571       │                 │       │
1572       │port-unreachable │ 1     │
1573       ├─────────────────┼───────┤
1574       │                 │       │
1575       │host-unreachable │ 2     │
1576       ├─────────────────┼───────┤
1577       │                 │       │
1578       │admin-prohibited │ 3     │
1579       └─────────────────┴───────┘
1580
1581   CONNTRACK TYPES
1582       Table 23. overview of types used in ct expression and statement
1583       ┌─────────────────┬───────────┬─────────┬───────────┐
1584Name             Keyword   Size    Base type 
1585       ├─────────────────┼───────────┼─────────┼───────────┤
1586       │                 │           │         │           │
1587       │conntrack state  │ ct_state  │ 4 byte  │ bitmask   │
1588       ├─────────────────┼───────────┼─────────┼───────────┤
1589       │                 │           │         │           │
1590       │conntrack        │ ct_dir    │ 8 bit   │ integer   │
1591       │direction        │           │         │           │
1592       ├─────────────────┼───────────┼─────────┼───────────┤
1593       │                 │           │         │           │
1594       │conntrack status │ ct_status │ 4 byte  │ bitmask   │
1595       ├─────────────────┼───────────┼─────────┼───────────┤
1596       │                 │           │         │           │
1597       │conntrack event  │ ct_event  │ 4 byte  │ bitmask   │
1598       │bits             │           │         │           │
1599       ├─────────────────┼───────────┼─────────┼───────────┤
1600       │                 │           │         │           │
1601       │conntrack label  │ ct_label  │ 128 bit │ bitmask   │
1602       └─────────────────┴───────────┴─────────┴───────────┘
1603
1604       For each of the types above, keywords are available for convenience:
1605
1606       Table 24. conntrack state (ct_state)
1607       ┌────────────┬───────┐
1608Keyword     Value 
1609       ├────────────┼───────┤
1610       │            │       │
1611       │invalid     │ 1     │
1612       ├────────────┼───────┤
1613       │            │       │
1614       │established │ 2     │
1615       ├────────────┼───────┤
1616       │            │       │
1617       │related     │ 4     │
1618       ├────────────┼───────┤
1619       │            │       │
1620       │new         │ 8     │
1621       ├────────────┼───────┤
1622       │            │       │
1623       │untracked   │ 64    │
1624       └────────────┴───────┘
1625
1626       Table 25. conntrack direction (ct_dir)
1627       ┌─────────┬───────┐
1628Keyword  Value 
1629       ├─────────┼───────┤
1630       │         │       │
1631       │original │ 0     │
1632       ├─────────┼───────┤
1633       │         │       │
1634       │reply    │ 1     │
1635       └─────────┴───────┘
1636
1637       Table 26. conntrack status (ct_status)
1638       ┌───────────┬───────┐
1639Keyword    Value 
1640       ├───────────┼───────┤
1641       │           │       │
1642       │expected   │ 1     │
1643       ├───────────┼───────┤
1644       │           │       │
1645       │seen-reply │ 2     │
1646       ├───────────┼───────┤
1647       │           │       │
1648       │assured    │ 4     │
1649       ├───────────┼───────┤
1650       │           │       │
1651       │confirmed  │ 8     │
1652       ├───────────┼───────┤
1653       │           │       │
1654       │snat       │ 16    │
1655       ├───────────┼───────┤
1656       │           │       │
1657       │dnat       │ 32    │
1658       ├───────────┼───────┤
1659       │           │       │
1660       │dying      │ 512   │
1661       └───────────┴───────┘
1662
1663       Table 27. conntrack event bits (ct_event)
1664       ┌──────────┬───────┐
1665Keyword   Value 
1666       ├──────────┼───────┤
1667       │          │       │
1668       │new       │ 1     │
1669       ├──────────┼───────┤
1670       │          │       │
1671       │related   │ 2     │
1672       ├──────────┼───────┤
1673       │          │       │
1674       │destroy   │ 4     │
1675       ├──────────┼───────┤
1676       │          │       │
1677       │reply     │ 8     │
1678       ├──────────┼───────┤
1679       │          │       │
1680       │assured   │ 16    │
1681       ├──────────┼───────┤
1682       │          │       │
1683       │protoinfo │ 32    │
1684       ├──────────┼───────┤
1685       │          │       │
1686       │helper    │ 64    │
1687       ├──────────┼───────┤
1688       │          │       │
1689       │mark      │ 128   │
1690       ├──────────┼───────┤
1691       │          │       │
1692       │seqadj    │ 256   │
1693       ├──────────┼───────┤
1694       │          │       │
1695       │secmark   │ 512   │
1696       ├──────────┼───────┤
1697       │          │       │
1698       │label     │ 1024  │
1699       └──────────┴───────┘
1700
1701       Possible keywords for conntrack label type (ct_label) are read at
1702       runtime from /etc/connlabel.conf.
1703
1704   DCCP PKTTYPE TYPE
1705       ┌─────────────────┬──────────────┬───────┬───────────┐
1706Name             Keyword      Size  Base type 
1707       ├─────────────────┼──────────────┼───────┼───────────┤
1708       │                 │              │       │           │
1709       │DCCP packet type │ dccp_pkttype │ 4 bit │ integer   │
1710       └─────────────────┴──────────────┴───────┴───────────┘
1711
1712       The DCCP packet type abstracts the different legal values of the
1713       respective four bit field in the DCCP header, as stated by RFC4340.
1714       Note that possible values 10-15 are considered reserved and therefore
1715       not allowed to be used. In iptables' dccp match, these values are
1716       aliased INVALID. With nftables, one may simply match on the numeric
1717       value range, i.e. 10-15.
1718
1719       Table 28. keywords may be used when specifying the DCCP packet type
1720       ┌─────────┬───────┐
1721Keyword  Value 
1722       ├─────────┼───────┤
1723       │         │       │
1724       │request  │ 0     │
1725       ├─────────┼───────┤
1726       │         │       │
1727       │response │ 1     │
1728       ├─────────┼───────┤
1729       │         │       │
1730       │data     │ 2     │
1731       ├─────────┼───────┤
1732       │         │       │
1733       │ack      │ 3     │
1734       ├─────────┼───────┤
1735       │         │       │
1736       │dataack  │ 4     │
1737       ├─────────┼───────┤
1738       │         │       │
1739       │closereq │ 5     │
1740       ├─────────┼───────┤
1741       │         │       │
1742       │close    │ 6     │
1743       ├─────────┼───────┤
1744       │         │       │
1745       │reset    │ 7     │
1746       ├─────────┼───────┤
1747       │         │       │
1748       │sync     │ 8     │
1749       ├─────────┼───────┤
1750       │         │       │
1751       │syncack  │ 9     │
1752       └─────────┴───────┘
1753

PRIMARY EXPRESSIONS

1755       The lowest order expression is a primary expression, representing
1756       either a constant or a single datum from a packet’s payload, meta data
1757       or a stateful module.
1758
1759   META EXPRESSIONS
1760           meta {length | nfproto | l4proto | protocol | priority}
1761           [meta] {mark | iif | iifname | iiftype | oif | oifname | oiftype | skuid | skgid | nftrace | rtclassid | ibrname | obrname | pkttype | cpu | iifgroup | oifgroup | cgroup | random | ipsec | iifkind | oifkind | time | hour | day }
1762
1763       A meta expression refers to meta data associated with a packet.
1764
1765       There are two types of meta expressions: unqualified and qualified meta
1766       expressions. Qualified meta expressions require the meta keyword before
1767       the meta key, unqualified meta expressions can be specified by using
1768       the meta key directly or as qualified meta expressions. Meta l4proto is
1769       useful to match a particular transport protocol that is part of either
1770       an IPv4 or IPv6 packet. It will also skip any IPv6 extension headers
1771       present in an IPv6 packet.
1772
1773       meta iif, oif, iifname and oifname are used to match the interface a
1774       packet arrived on or is about to be sent out on.
1775
1776       iif and oif are used to match on the interface index, whereas iifname
1777       and oifname are used to match on the interface name. This is not the
1778       same — assuming the rule
1779
1780           filter input meta iif "foo"
1781
1782       Then this rule can only be added if the interface "foo" exists. Also,
1783       the rule will continue to match even if the interface "foo" is renamed
1784       to "bar".
1785
1786       This is because internally the interface index is used. In case of
1787       dynamically created interfaces, such as tun/tap or dialup interfaces
1788       (ppp for example), it might be better to use iifname or oifname
1789       instead.
1790
1791       In these cases, the name is used so the interface doesn’t have to exist
1792       to add such a rule, it will stop matching if the interface gets renamed
1793       and it will match again in case interface gets deleted and later a new
1794       interface with the same name is created.
1795
1796       Like with iptables, wildcard matching on interface name prefixes is
1797       available for iifname and oifname matches by appending an asterisk (*)
1798       character. Note however that unlike iptables, nftables does not accept
1799       interface names consisting of the wildcard character only - users are
1800       supposed to just skip those always matching expressions. In order to
1801       match on literal asterisk character, one may escape it using backslash
1802       (\).
1803
1804       Table 29. Meta expression types
1805       ┌──────────┬─────────────────────┬─────────────────────┐
1806Keyword   Description         Type                
1807       ├──────────┼─────────────────────┼─────────────────────┤
1808       │          │                     │                     │
1809       │length    │ Length of the       │ integer (32-bit)    │
1810       │          │ packet in bytes     │                     │
1811       ├──────────┼─────────────────────┼─────────────────────┤
1812       │          │                     │                     │
1813       │nfproto   │ real hook protocol  │ integer (32 bit)    │
1814       │          │ family, useful only │                     │
1815       │          │ in inet table       │                     │
1816       ├──────────┼─────────────────────┼─────────────────────┤
1817       │          │                     │                     │
1818       │l4proto   │ layer 4 protocol,   │ integer (8 bit)     │
1819       │          │ skips ipv6          │                     │
1820       │          │ extension headers   │                     │
1821       ├──────────┼─────────────────────┼─────────────────────┤
1822       │          │                     │                     │
1823       │protocol  │ EtherType protocol  │ ether_type          │
1824       │          │ value               │                     │
1825       ├──────────┼─────────────────────┼─────────────────────┤
1826       │          │                     │                     │
1827       │priority  │ TC packet priority  │ tc_handle           │
1828       ├──────────┼─────────────────────┼─────────────────────┤
1829       │          │                     │                     │
1830       │mark      │ Packet mark         │ mark                │
1831       ├──────────┼─────────────────────┼─────────────────────┤
1832       │          │                     │                     │
1833       │iif       │ Input interface     │ iface_index         │
1834       │          │ index               │                     │
1835       ├──────────┼─────────────────────┼─────────────────────┤
1836       │          │                     │                     │
1837       │iifname   │ Input interface     │ ifname              │
1838       │          │ name                │                     │
1839       ├──────────┼─────────────────────┼─────────────────────┤
1840       │          │                     │                     │
1841       │iiftype   │ Input interface     │ iface_type          │
1842       │          │ type                │                     │
1843       ├──────────┼─────────────────────┼─────────────────────┤
1844       │          │                     │                     │
1845       │oif       │ Output interface    │ iface_index         │
1846       │          │ index               │                     │
1847       ├──────────┼─────────────────────┼─────────────────────┤
1848       │          │                     │                     │
1849       │oifname   │ Output interface    │ ifname              │
1850       │          │ name                │                     │
1851       ├──────────┼─────────────────────┼─────────────────────┤
1852       │          │                     │                     │
1853       │oiftype   │ Output interface    │ iface_type          │
1854       │          │ hardware type       │                     │
1855       ├──────────┼─────────────────────┼─────────────────────┤
1856       │          │                     │                     │
1857       │sdif      │ Slave device input  │ iface_index         │
1858       │          │ interface index     │                     │
1859       ├──────────┼─────────────────────┼─────────────────────┤
1860       │          │                     │                     │
1861       │sdifname  │ Slave device        │ ifname              │
1862       │          │ interface name      │                     │
1863       ├──────────┼─────────────────────┼─────────────────────┤
1864       │          │                     │                     │
1865       │skuid     │ UID associated with │ uid                 │
1866       │          │ originating socket  │                     │
1867       ├──────────┼─────────────────────┼─────────────────────┤
1868       │          │                     │                     │
1869       │skgid     │ GID associated with │ gid                 │
1870       │          │ originating socket  │                     │
1871       ├──────────┼─────────────────────┼─────────────────────┤
1872       │          │                     │                     │
1873       │rtclassid │ Routing realm       │ realm               │
1874       ├──────────┼─────────────────────┼─────────────────────┤
1875       │          │                     │                     │
1876       │ibrname   │ Input bridge        │ ifname              │
1877       │          │ interface name      │                     │
1878       ├──────────┼─────────────────────┼─────────────────────┤
1879       │          │                     │                     │
1880       │obrname   │ Output bridge       │ ifname              │
1881       │          │ interface name      │                     │
1882       ├──────────┼─────────────────────┼─────────────────────┤
1883       │          │                     │                     │
1884       │pkttype   │ packet type         │ pkt_type            │
1885       ├──────────┼─────────────────────┼─────────────────────┤
1886       │          │                     │                     │
1887       │cpu       │ cpu number          │ integer (32 bit)    │
1888       │          │ processing the      │                     │
1889       │          │ packet              │                     │
1890       ├──────────┼─────────────────────┼─────────────────────┤
1891       │          │                     │                     │
1892       │iifgroup  │ incoming device     │ devgroup            │
1893       │          │ group               │                     │
1894       ├──────────┼─────────────────────┼─────────────────────┤
1895       │          │                     │                     │
1896       │oifgroup  │ outgoing device     │ devgroup            │
1897       │          │ group               │                     │
1898       ├──────────┼─────────────────────┼─────────────────────┤
1899       │          │                     │                     │
1900       │cgroup    │ control group id    │ integer (32 bit)    │
1901       ├──────────┼─────────────────────┼─────────────────────┤
1902       │          │                     │                     │
1903       │random    │ pseudo-random       │ integer (32 bit)    │
1904       │          │ number              │                     │
1905       ├──────────┼─────────────────────┼─────────────────────┤
1906       │          │                     │                     │
1907       │ipsec     │ true if packet was  │ boolean (1 bit)     │
1908       │          │ ipsec encrypted     │                     │
1909       ├──────────┼─────────────────────┼─────────────────────┤
1910       │          │                     │                     │
1911       │iifkind   │ Input interface     │                     │
1912       │          │ kind                │                     │
1913       ├──────────┼─────────────────────┼─────────────────────┤
1914       │          │                     │                     │
1915       │oifkind   │ Output interface    │                     │
1916       │          │ kind                │                     │
1917       ├──────────┼─────────────────────┼─────────────────────┤
1918       │          │                     │                     │
1919       │time      │ Absolute time of    │ Integer (32 bit) or │
1920       │          │ packet reception    │ string              │
1921       ├──────────┼─────────────────────┼─────────────────────┤
1922       │          │                     │                     │
1923       │day       │ Day of week         │ Integer (8 bit) or  │
1924       │          │                     │ string              │
1925       ├──────────┼─────────────────────┼─────────────────────┤
1926       │          │                     │                     │
1927       │hour      │ Hour of day         │ String              │
1928       └──────────┴─────────────────────┴─────────────────────┘
1929
1930       Table 30. Meta expression specific types
1931       ┌──────────────┬────────────────────────────┐
1932Type          Description                
1933       ├──────────────┼────────────────────────────┤
1934       │              │                            │
1935       │iface_index   │ Interface index (32 bit    │
1936       │              │ number). Can be specified  │
1937       │              │ numerically or as name of  │
1938       │              │ an existing interface.     │
1939       ├──────────────┼────────────────────────────┤
1940       │              │                            │
1941       │ifname        │ Interface name (16 byte    │
1942       │              │ string). Does not have to  │
1943       │              │ exist.                     │
1944       ├──────────────┼────────────────────────────┤
1945       │              │                            │
1946       │iface_type    │ Interface type (16 bit     │
1947       │              │ number).                   │
1948       ├──────────────┼────────────────────────────┤
1949       │              │                            │
1950       │uid           │ User ID (32 bit number).   │
1951       │              │ Can be specified           │
1952       │              │ numerically or as user     │
1953       │              │ name.                      │
1954       ├──────────────┼────────────────────────────┤
1955       │              │                            │
1956       │gid           │ Group ID (32 bit number).  │
1957       │              │ Can be specified           │
1958       │              │ numerically or as group    │
1959       │              │ name.                      │
1960       ├──────────────┼────────────────────────────┤
1961       │              │                            │
1962       │realm         │ Routing Realm (32 bit      │
1963       │              │ number). Can be specified  │
1964       │              │ numerically or as symbolic │
1965       │              │ name defined in            │
1966       │              │ /etc/iproute2/rt_realms.   │
1967       ├──────────────┼────────────────────────────┤
1968       │              │                            │
1969       │devgroup_type │ Device group (32 bit       │
1970       │              │ number). Can be specified  │
1971       │              │ numerically or as symbolic │
1972       │              │ name defined in            │
1973       │              │ /etc/iproute2/group.       │
1974       ├──────────────┼────────────────────────────┤
1975       │              │                            │
1976       │pkt_type      │ Packet type: host          
1977       │              │ (addressed to local host), │
1978       │              │ broadcast (to all),        │
1979       │              │ multicast (to group),      │
1980       │              │ other (addressed to        │
1981       │              │ another host).             │
1982       ├──────────────┼────────────────────────────┤
1983       │              │                            │
1984       │ifkind        │ Interface kind (16 byte    │
1985       │              │ string). See TYPES in      │
1986       │              │ ip-link(8) for a list.     │
1987       ├──────────────┼────────────────────────────┤
1988       │              │                            │
1989       │time          │ Either an integer or a     │
1990       │              │ date in ISO format. For    │
1991       │              │ example: "2019-06-06       │
1992       │              │ 17:00". Hour and seconds   │
1993       │              │ are optional and can be    │
1994       │              │ omitted if desired. If     │
1995       │              │ omitted, midnight will be  │
1996       │              │ assumed. The following     │
1997       │              │ three would be equivalent: │
1998       │              │ "2019-06-06", "2019-06-06  │
1999       │              │ 00:00" and "2019-06-06     │
2000       │              │ 00:00:00". When an integer │
2001       │              │ is given, it is assumed to │
2002       │              │ be a UNIX timestamp.       │
2003       ├──────────────┼────────────────────────────┤
2004       │              │                            │
2005       │day           │ Either a day of week       │
2006       │              │ ("Monday", "Tuesday",      │
2007       │              │ etc.), or an integer       │
2008       │              │ between 0 and 6. Strings   │
2009       │              │ are matched                │
2010       │              │ case-insensitively, and a  │
2011       │              │ full match is not expected │
2012       │              │ (e.g. "Mon" would match    │
2013       │              │ "Monday"). When an integer │
2014       │              │ is given, 0 is Sunday and  │
2015       │              │ 6 is Saturday.             │
2016       ├──────────────┼────────────────────────────┤
2017       │              │                            │
2018       │hour          │ A string representing an   │
2019       │              │ hour in 24-hour format.    │
2020       │              │ Seconds can optionally be  │
2021       │              │ specified. For example,    │
2022       │              │ 17:00 and 17:00:00 would   │
2023       │              │ be equivalent.             │
2024       └──────────────┴────────────────────────────┘
2025
2026       Using meta expressions.
2027
2028           # qualified meta expression
2029           filter output meta oif eth0
2030           filter forward meta iifkind { "tun", "veth" }
2031
2032           # unqualified meta expression
2033           filter output oif eth0
2034
2035           # incoming packet was subject to ipsec processing
2036           raw prerouting meta ipsec exists accept
2037
2038
2039   SOCKET EXPRESSION
2040           socket {transparent | mark | wildcard}
2041
2042       Socket expression can be used to search for an existing open TCP/UDP
2043       socket and its attributes that can be associated with a packet. It
2044       looks for an established or non-zero bound listening socket (possibly
2045       with a non-local address).
2046
2047       Table 31. Available socket attributes
2048       ┌────────────┬─────────────────────┬─────────────────┐
2049Name        Description         Type            
2050       ├────────────┼─────────────────────┼─────────────────┤
2051       │            │                     │                 │
2052       │transparent │ Value of the        │ boolean (1 bit) │
2053       │            │ IP_TRANSPARENT      │                 │
2054       │            │ socket option in    │                 │
2055       │            │ the found socket.   │                 │
2056       │            │ It can be 0 or 1.   │                 │
2057       ├────────────┼─────────────────────┼─────────────────┤
2058       │            │                     │                 │
2059       │mark        │ Value of the socket │ mark            │
2060       │            │ mark (SOL_SOCKET,   │                 │
2061       │            │ SO_MARK).           │                 │
2062       ├────────────┼─────────────────────┼─────────────────┤
2063       │            │                     │                 │
2064       │wildcard    │ Indicates whether   │ boolean (1 bit) │
2065       │            │ the socket is       │                 │
2066       │            │ wildcard-bound      │                 │
2067       │            │ (e.g. 0.0.0.0 or    │                 │
2068       │            │ ::0).               │                 │
2069       └────────────┴─────────────────────┴─────────────────┘
2070
2071       Using socket expression.
2072
2073           # Mark packets that correspond to a transparent socket. "socket wildcard 0"
2074           # means that zero-bound listener sockets are NOT matched (which is usually
2075           # exactly what you want).
2076           table inet x {
2077               chain y {
2078                   type filter hook prerouting priority -150; policy accept;
2079                   socket transparent 1 socket wildcard 0 mark set 0x00000001 accept
2080               }
2081           }
2082
2083           # Trace packets that corresponds to a socket with a mark value of 15
2084           table inet x {
2085               chain y {
2086                   type filter hook prerouting priority -150; policy accept;
2087                   socket mark 0x0000000f nftrace set 1
2088               }
2089           }
2090
2091           # Set packet mark to socket mark
2092           table inet x {
2093               chain y {
2094                   type filter hook prerouting priority -150; policy accept;
2095                   tcp dport 8080 mark set socket mark
2096               }
2097           }
2098
2099
2100   OSF EXPRESSION
2101           osf [ttl {loose | skip}] {name | version}
2102
2103       The osf expression does passive operating system fingerprinting. This
2104       expression compares some data (Window Size, MSS, options and their
2105       order, DF, and others) from packets with the SYN bit set.
2106
2107       Table 32. Available osf attributes
2108       ┌────────┬─────────────────────┬────────┐
2109Name    Description         Type   
2110       ├────────┼─────────────────────┼────────┤
2111       │        │                     │        │
2112       │ttl     │ Do TTL checks on    │ string │
2113       │        │ the packet to       │        │
2114       │        │ determine the       │        │
2115       │        │ operating system.   │        │
2116       ├────────┼─────────────────────┼────────┤
2117       │        │                     │        │
2118       │version │ Do OS version       │        │
2119       │        │ checks on the       │        │
2120       │        │ packet.             │        │
2121       ├────────┼─────────────────────┼────────┤
2122       │        │                     │        │
2123       │name    │ Name of the OS      │ string │
2124       │        │ signature to match. │        │
2125       │        │ All signatures can  │        │
2126       │        │ be found at pf.os   │        │
2127       │        │ file. Use "unknown" │        │
2128       │        │ for OS signatures   │        │
2129       │        │ that the expression │        │
2130       │        │ could not detect.   │        │
2131       └────────┴─────────────────────┴────────┘
2132
2133       Available ttl values.
2134
2135           If no TTL attribute is passed, make a true IP header and fingerprint TTL true comparison. This generally works for LANs.
2136
2137           * loose: Check if the IP header's TTL is less than the fingerprint one. Works for globally-routable addresses.
2138           * skip: Do not compare the TTL at all.
2139
2140       Using osf expression.
2141
2142           # Accept packets that match the "Linux" OS genre signature without comparing TTL.
2143           table inet x {
2144               chain y {
2145                   type filter hook input priority 0; policy accept;
2146                   osf ttl skip name "Linux"
2147               }
2148           }
2149
2150
2151   FIB EXPRESSIONS
2152           fib {saddr | daddr | mark | iif | oif} [. ...] {oif | oifname | type}
2153
2154       A fib expression queries the fib (forwarding information base) to
2155       obtain information such as the output interface index a particular
2156       address would use. The input is a tuple of elements that is used as
2157       input to the fib lookup functions.
2158
2159       Table 33. fib expression specific types
2160       ┌────────┬──────────────────┬──────────────────┐
2161Keyword Description      Type             
2162       ├────────┼──────────────────┼──────────────────┤
2163       │        │                  │                  │
2164       │oif     │ Output interface │ integer (32 bit) │
2165       │        │ index            │                  │
2166       ├────────┼──────────────────┼──────────────────┤
2167       │        │                  │                  │
2168       │oifname │ Output interface │ string           │
2169       │        │ name             │                  │
2170       ├────────┼──────────────────┼──────────────────┤
2171       │        │                  │                  │
2172       │type    │ Address type     │ fib_addrtype     │
2173       └────────┴──────────────────┴──────────────────┘
2174
2175       Use nft describe fib_addrtype to get a list of all address types.
2176
2177       Using fib expressions.
2178
2179           # drop packets without a reverse path
2180           filter prerouting fib saddr . iif oif missing drop
2181
2182           In this example, 'saddr . iif' looks up routing information based on the source address and the input interface.
2183           oif picks the output interface index from the routing information.
2184           If no route was found for the source address/input interface combination, the output interface index is zero.
2185           In case the input interface is specified as part of the input key, the output interface index is always the same as the input interface index or zero.
2186           If only 'saddr oif' is given, then oif can be any interface index or zero.
2187
2188           # drop packets to address not configured on incoming interface
2189           filter prerouting fib daddr . iif type != { local, broadcast, multicast } drop
2190
2191           # perform lookup in a specific 'blackhole' table (0xdead, needs ip appropriate ip rule)
2192           filter prerouting meta mark set 0xdead fib daddr . mark type vmap { blackhole : drop, prohibit : jump prohibited, unreachable : drop }
2193
2194
2195   ROUTING EXPRESSIONS
2196           rt [ip | ip6] {classid | nexthop | mtu | ipsec}
2197
2198       A routing expression refers to routing data associated with a packet.
2199
2200       Table 34. Routing expression types
2201       ┌────────┬─────────────────────┬─────────────────────┐
2202Keyword Description         Type                
2203       ├────────┼─────────────────────┼─────────────────────┤
2204       │        │                     │                     │
2205       │classid │ Routing realm       │ realm               │
2206       ├────────┼─────────────────────┼─────────────────────┤
2207       │        │                     │                     │
2208       │nexthop │ Routing nexthop     │ ipv4_addr/ipv6_addr │
2209       ├────────┼─────────────────────┼─────────────────────┤
2210       │        │                     │                     │
2211       │mtu     │ TCP maximum segment │ integer (16 bit)    │
2212       │        │ size of route       │                     │
2213       ├────────┼─────────────────────┼─────────────────────┤
2214       │        │                     │                     │
2215       │ipsec   │ route via ipsec     │ boolean             │
2216       │        │ tunnel or transport │                     │
2217       └────────┴─────────────────────┴─────────────────────┘
2218
2219       Table 35. Routing expression specific types
2220       ┌──────┬────────────────────────────┐
2221Type  Description                
2222       ├──────┼────────────────────────────┤
2223       │      │                            │
2224       │realm │ Routing Realm (32 bit      │
2225       │      │ number). Can be specified  │
2226       │      │ numerically or as symbolic │
2227       │      │ name defined in            │
2228       │      │ /etc/iproute2/rt_realms.   │
2229       └──────┴────────────────────────────┘
2230
2231       Using routing expressions.
2232
2233           # IP family independent rt expression
2234           filter output rt classid 10
2235
2236           # IP family dependent rt expressions
2237           ip filter output rt nexthop 192.168.0.1
2238           ip6 filter output rt nexthop fd00::1
2239           inet filter output rt ip nexthop 192.168.0.1
2240           inet filter output rt ip6 nexthop fd00::1
2241
2242           # outgoing packet will be encapsulated/encrypted by ipsec
2243           filter output rt ipsec exists
2244
2245
2246   IPSEC EXPRESSIONS
2247           ipsec {in | out} [ spnum NUM ]  {reqid | spi}
2248           ipsec {in | out} [ spnum NUM ]  {ip | ip6} {saddr | daddr}
2249
2250       An ipsec expression refers to ipsec data associated with a packet.
2251
2252       The in or out keyword needs to be used to specify if the expression
2253       should examine inbound or outbound policies. The in keyword can be used
2254       in the prerouting, input and forward hooks. The out keyword applies to
2255       forward, output and postrouting hooks. The optional keyword spnum can
2256       be used to match a specific state in a chain, it defaults to 0.
2257
2258       Table 36. Ipsec expression types
2259       ┌────────┬─────────────────────┬─────────────────────┐
2260Keyword Description         Type                
2261       ├────────┼─────────────────────┼─────────────────────┤
2262       │        │                     │                     │
2263       │reqid   │ Request ID          │ integer (32 bit)    │
2264       ├────────┼─────────────────────┼─────────────────────┤
2265       │        │                     │                     │
2266       │spi     │ Security Parameter  │ integer (32 bit)    │
2267       │        │ Index               │                     │
2268       ├────────┼─────────────────────┼─────────────────────┤
2269       │        │                     │                     │
2270       │saddr   │ Source address of   │ ipv4_addr/ipv6_addr │
2271       │        │ the tunnel          │                     │
2272       ├────────┼─────────────────────┼─────────────────────┤
2273       │        │                     │                     │
2274       │daddr   │ Destination address │ ipv4_addr/ipv6_addr │
2275       │        │ of the tunnel       │                     │
2276       └────────┴─────────────────────┴─────────────────────┘
2277
2278   NUMGEN EXPRESSION
2279           numgen {inc | random} mod NUM [ offset NUM ]
2280
2281       Create a number generator. The inc or random keywords control its
2282       operation mode: In inc mode, the last returned value is simply
2283       incremented. In random mode, a new random number is returned. The value
2284       after mod keyword specifies an upper boundary (read: modulus) which is
2285       not reached by returned numbers. The optional offset allows to
2286       increment the returned value by a fixed offset.
2287
2288       A typical use-case for numgen is load-balancing:
2289
2290       Using numgen expression.
2291
2292           # round-robin between 192.168.10.100 and 192.168.20.200:
2293           add rule nat prerouting dnat to numgen inc mod 2 map \
2294                   { 0 : 192.168.10.100, 1 : 192.168.20.200 }
2295
2296           # probability-based with odd bias using intervals:
2297           add rule nat prerouting dnat to numgen random mod 10 map \
2298                   { 0-2 : 192.168.10.100, 3-9 : 192.168.20.200 }
2299
2300
2301   HASH EXPRESSIONS
2302           jhash {ip saddr | ip6 daddr | tcp dport | udp sport | ether saddr} [. ...] mod NUM [ seed NUM ] [ offset NUM ]
2303           symhash mod NUM [ offset NUM ]
2304
2305       Use a hashing function to generate a number. The functions available
2306       are jhash, known as Jenkins Hash, and symhash, for Symmetric Hash. The
2307       jhash requires an expression to determine the parameters of the packet
2308       header to apply the hashing, concatenations are possible as well. The
2309       value after mod keyword specifies an upper boundary (read: modulus)
2310       which is not reached by returned numbers. The optional seed is used to
2311       specify an init value used as seed in the hashing function. The
2312       optional offset allows to increment the returned value by a fixed
2313       offset.
2314
2315       A typical use-case for jhash and symhash is load-balancing:
2316
2317       Using hash expressions.
2318
2319           # load balance based on source ip between 2 ip addresses:
2320           add rule nat prerouting dnat to jhash ip saddr mod 2 map \
2321                   { 0 : 192.168.10.100, 1 : 192.168.20.200 }
2322
2323           # symmetric load balancing between 2 ip addresses:
2324           add rule nat prerouting dnat to symhash mod 2 map \
2325                   { 0 : 192.168.10.100, 1 : 192.168.20.200 }
2326
2327

PAYLOAD EXPRESSIONS

2329       Payload expressions refer to data from the packet’s payload.
2330
2331   ETHERNET HEADER EXPRESSION
2332           ether {daddr | saddr | type}
2333
2334       Table 37. Ethernet header expression types
2335       ┌────────┬────────────────────┬────────────┐
2336Keyword Description        Type       
2337       ├────────┼────────────────────┼────────────┤
2338       │        │                    │            │
2339       │daddr   │ Destination MAC    │ ether_addr │
2340       │        │ address            │            │
2341       ├────────┼────────────────────┼────────────┤
2342       │        │                    │            │
2343       │saddr   │ Source MAC address │ ether_addr │
2344       ├────────┼────────────────────┼────────────┤
2345       │        │                    │            │
2346       │type    │ EtherType          │ ether_type │
2347       └────────┴────────────────────┴────────────┘
2348
2349   VLAN HEADER EXPRESSION
2350           vlan {id | cfi | pcp | type}
2351
2352       Table 38. VLAN header expression
2353       ┌────────┬─────────────────────┬──────────────────┐
2354Keyword Description         Type             
2355       ├────────┼─────────────────────┼──────────────────┤
2356       │        │                     │                  │
2357       │id      │ VLAN ID (VID)       │ integer (12 bit) │
2358       ├────────┼─────────────────────┼──────────────────┤
2359       │        │                     │                  │
2360       │cfi     │ Canonical Format    │ integer (1 bit)  │
2361       │        │ Indicator           │                  │
2362       ├────────┼─────────────────────┼──────────────────┤
2363       │        │                     │                  │
2364       │pcp     │ Priority code point │ integer (3 bit)  │
2365       ├────────┼─────────────────────┼──────────────────┤
2366       │        │                     │                  │
2367       │type    │ EtherType           │ ether_type       │
2368       └────────┴─────────────────────┴──────────────────┘
2369
2370   ARP HEADER EXPRESSION
2371           arp {htype | ptype | hlen | plen | operation | saddr { ip | ether } | daddr { ip | ether }
2372
2373       Table 39. ARP header expression
2374       ┌────────────┬─────────────────────┬──────────────────┐
2375Keyword     Description         Type             
2376       ├────────────┼─────────────────────┼──────────────────┤
2377       │            │                     │                  │
2378       │htype       │ ARP hardware type   │ integer (16 bit) │
2379       ├────────────┼─────────────────────┼──────────────────┤
2380       │            │                     │                  │
2381       │ptype       │ EtherType           │ ether_type       │
2382       ├────────────┼─────────────────────┼──────────────────┤
2383       │            │                     │                  │
2384       │hlen        │ Hardware address    │ integer (8 bit)  │
2385       │            │ len                 │                  │
2386       ├────────────┼─────────────────────┼──────────────────┤
2387       │            │                     │                  │
2388       │plen        │ Protocol address    │ integer (8 bit)  │
2389       │            │ len                 │                  │
2390       ├────────────┼─────────────────────┼──────────────────┤
2391       │            │                     │                  │
2392       │operation   │ Operation           │ arp_op           │
2393       ├────────────┼─────────────────────┼──────────────────┤
2394       │            │                     │                  │
2395       │saddr ether │ Ethernet sender     │ ether_addr       │
2396       │            │ address             │                  │
2397       ├────────────┼─────────────────────┼──────────────────┤
2398       │            │                     │                  │
2399       │daddr ether │ Ethernet target     │ ether_addr       │
2400       │            │ address             │                  │
2401       ├────────────┼─────────────────────┼──────────────────┤
2402       │            │                     │                  │
2403       │saddr ip    │ IPv4 sender address │ ipv4_addr        │
2404       ├────────────┼─────────────────────┼──────────────────┤
2405       │            │                     │                  │
2406       │daddr ip    │ IPv4 target address │ ipv4_addr        │
2407       └────────────┴─────────────────────┴──────────────────┘
2408
2409   IPV4 HEADER EXPRESSION
2410           ip {version | hdrlength | dscp | ecn | length | id | frag-off | ttl | protocol | checksum | saddr | daddr }
2411
2412       Table 40. IPv4 header expression
2413       ┌──────────┬─────────────────────┬──────────────────┐
2414Keyword   Description         Type             
2415       ├──────────┼─────────────────────┼──────────────────┤
2416       │          │                     │                  │
2417       │version   │ IP header version   │ integer (4 bit)  │
2418       │          │ (4)                 │                  │
2419       ├──────────┼─────────────────────┼──────────────────┤
2420       │          │                     │                  │
2421       │hdrlength │ IP header length    │ integer (4 bit)  │
2422       │          │ including options   │ FIXME scaling    │
2423       ├──────────┼─────────────────────┼──────────────────┤
2424       │          │                     │                  │
2425       │dscp      │ Differentiated      │ dscp             │
2426       │          │ Services Code Point │                  │
2427       ├──────────┼─────────────────────┼──────────────────┤
2428       │          │                     │                  │
2429       │ecn       │ Explicit Congestion │ ecn              │
2430       │          │ Notification        │                  │
2431       ├──────────┼─────────────────────┼──────────────────┤
2432       │          │                     │                  │
2433       │length    │ Total packet length │ integer (16 bit) │
2434       ├──────────┼─────────────────────┼──────────────────┤
2435       │          │                     │                  │
2436       │id        │ IP ID               │ integer (16 bit) │
2437       ├──────────┼─────────────────────┼──────────────────┤
2438       │          │                     │                  │
2439       │frag-off  │ Fragment offset     │ integer (16 bit) │
2440       ├──────────┼─────────────────────┼──────────────────┤
2441       │          │                     │                  │
2442       │ttl       │ Time to live        │ integer (8 bit)  │
2443       ├──────────┼─────────────────────┼──────────────────┤
2444       │          │                     │                  │
2445       │protocol  │ Upper layer         │ inet_proto       │
2446       │          │ protocol            │                  │
2447       ├──────────┼─────────────────────┼──────────────────┤
2448       │          │                     │                  │
2449       │checksum  │ IP header checksum  │ integer (16 bit) │
2450       ├──────────┼─────────────────────┼──────────────────┤
2451       │          │                     │                  │
2452       │saddr     │ Source address      │ ipv4_addr        │
2453       ├──────────┼─────────────────────┼──────────────────┤
2454       │          │                     │                  │
2455       │daddr     │ Destination address │ ipv4_addr        │
2456       └──────────┴─────────────────────┴──────────────────┘
2457
2458   ICMP HEADER EXPRESSION
2459           icmp {type | code | checksum | id | sequence | gateway | mtu}
2460
2461       This expression refers to ICMP header fields. When using it in inet,
2462       bridge or netdev families, it will cause an implicit dependency on IPv4
2463       to be created. To match on unusual cases like ICMP over IPv6, one has
2464       to add an explicit meta protocol ip6 match to the rule.
2465
2466       Table 41. ICMP header expression
2467       ┌─────────┬─────────────────────┬──────────────────┐
2468Keyword  Description         Type             
2469       ├─────────┼─────────────────────┼──────────────────┤
2470       │         │                     │                  │
2471       │type     │ ICMP type field     │ icmp_type        │
2472       ├─────────┼─────────────────────┼──────────────────┤
2473       │         │                     │                  │
2474       │code     │ ICMP code field     │ integer (8 bit)  │
2475       ├─────────┼─────────────────────┼──────────────────┤
2476       │         │                     │                  │
2477       │checksum │ ICMP checksum field │ integer (16 bit) │
2478       ├─────────┼─────────────────────┼──────────────────┤
2479       │         │                     │                  │
2480       │id       │ ID of echo          │ integer (16 bit) │
2481       │         │ request/response    │                  │
2482       ├─────────┼─────────────────────┼──────────────────┤
2483       │         │                     │                  │
2484       │sequence │ sequence number of  │ integer (16 bit) │
2485       │         │ echo                │                  │
2486       │         │ request/response    │                  │
2487       ├─────────┼─────────────────────┼──────────────────┤
2488       │         │                     │                  │
2489       │gateway  │ gateway of          │ integer (32 bit) │
2490       │         │ redirects           │                  │
2491       ├─────────┼─────────────────────┼──────────────────┤
2492       │         │                     │                  │
2493       │mtu      │ MTU of path MTU     │ integer (16 bit) │
2494       │         │ discovery           │                  │
2495       └─────────┴─────────────────────┴──────────────────┘
2496
2497   IGMP HEADER EXPRESSION
2498           igmp {type | mrt | checksum | group}
2499
2500       This expression refers to IGMP header fields. When using it in inet,
2501       bridge or netdev families, it will cause an implicit dependency on IPv4
2502       to be created. To match on unusual cases like IGMP over IPv6, one has
2503       to add an explicit meta protocol ip6 match to the rule.
2504
2505       Table 42. IGMP header expression
2506       ┌─────────┬─────────────────────┬──────────────────┐
2507Keyword  Description         Type             
2508       ├─────────┼─────────────────────┼──────────────────┤
2509       │         │                     │                  │
2510       │type     │ IGMP type field     │ igmp_type        │
2511       ├─────────┼─────────────────────┼──────────────────┤
2512       │         │                     │                  │
2513       │mrt      │ IGMP maximum        │ integer (8 bit)  │
2514       │         │ response time field │                  │
2515       ├─────────┼─────────────────────┼──────────────────┤
2516       │         │                     │                  │
2517       │checksum │ IGMP checksum field │ integer (16 bit) │
2518       ├─────────┼─────────────────────┼──────────────────┤
2519       │         │                     │                  │
2520       │group    │ Group address       │ integer (32 bit) │
2521       └─────────┴─────────────────────┴──────────────────┘
2522
2523   IPV6 HEADER EXPRESSION
2524           ip6 {version | dscp | ecn | flowlabel | length | nexthdr | hoplimit | saddr | daddr}
2525
2526       This expression refers to the ipv6 header fields. Caution when using
2527       ip6 nexthdr, the value only refers to the next header, i.e. ip6 nexthdr
2528       tcp will only match if the ipv6 packet does not contain any extension
2529       headers. Packets that are fragmented or e.g. contain a routing
2530       extension headers will not be matched. Please use meta l4proto if you
2531       wish to match the real transport header and ignore any additional
2532       extension headers instead.
2533
2534       Table 43. IPv6 header expression
2535       ┌──────────┬─────────────────────┬──────────────────┐
2536Keyword   Description         Type             
2537       ├──────────┼─────────────────────┼──────────────────┤
2538       │          │                     │                  │
2539       │version   │ IP header version   │ integer (4 bit)  │
2540       │          │ (6)                 │                  │
2541       ├──────────┼─────────────────────┼──────────────────┤
2542       │          │                     │                  │
2543       │dscp      │ Differentiated      │ dscp             │
2544       │          │ Services Code Point │                  │
2545       ├──────────┼─────────────────────┼──────────────────┤
2546       │          │                     │                  │
2547       │ecn       │ Explicit Congestion │ ecn              │
2548       │          │ Notification        │                  │
2549       ├──────────┼─────────────────────┼──────────────────┤
2550       │          │                     │                  │
2551       │flowlabel │ Flow label          │ integer (20 bit) │
2552       ├──────────┼─────────────────────┼──────────────────┤
2553       │          │                     │                  │
2554       │length    │ Payload length      │ integer (16 bit) │
2555       ├──────────┼─────────────────────┼──────────────────┤
2556       │          │                     │                  │
2557       │nexthdr   │ Nexthdr protocol    │ inet_proto       │
2558       ├──────────┼─────────────────────┼──────────────────┤
2559       │          │                     │                  │
2560       │hoplimit  │ Hop limit           │ integer (8 bit)  │
2561       ├──────────┼─────────────────────┼──────────────────┤
2562       │          │                     │                  │
2563       │saddr     │ Source address      │ ipv6_addr        │
2564       ├──────────┼─────────────────────┼──────────────────┤
2565       │          │                     │                  │
2566       │daddr     │ Destination address │ ipv6_addr        │
2567       └──────────┴─────────────────────┴──────────────────┘
2568
2569       Using ip6 header expressions.
2570
2571           # matching if first extension header indicates a fragment
2572           ip6 nexthdr ipv6-frag
2573
2574
2575   ICMPV6 HEADER EXPRESSION
2576           icmpv6 {type | code | checksum | parameter-problem | packet-too-big | id | sequence | max-delay}
2577
2578       This expression refers to ICMPv6 header fields. When using it in inet,
2579       bridge or netdev families, it will cause an implicit dependency on IPv6
2580       to be created. To match on unusual cases like ICMPv6 over IPv4, one has
2581       to add an explicit meta protocol ip match to the rule.
2582
2583       Table 44. ICMPv6 header expression
2584       ┌──────────────────┬────────────────────┬──────────────────┐
2585Keyword           Description        Type             
2586       ├──────────────────┼────────────────────┼──────────────────┤
2587       │                  │                    │                  │
2588       │type              │ ICMPv6 type field  │ icmpv6_type      │
2589       ├──────────────────┼────────────────────┼──────────────────┤
2590       │                  │                    │                  │
2591       │code              │ ICMPv6 code field  │ integer (8 bit)  │
2592       ├──────────────────┼────────────────────┼──────────────────┤
2593       │                  │                    │                  │
2594       │checksum          │ ICMPv6 checksum    │ integer (16 bit) │
2595       │                  │ field              │                  │
2596       ├──────────────────┼────────────────────┼──────────────────┤
2597       │                  │                    │                  │
2598       │parameter-problem │ pointer to problem │ integer (32 bit) │
2599       ├──────────────────┼────────────────────┼──────────────────┤
2600       │                  │                    │                  │
2601       │packet-too-big    │ oversized MTU      │ integer (32 bit) │
2602       ├──────────────────┼────────────────────┼──────────────────┤
2603       │                  │                    │                  │
2604       │id                │ ID of echo         │ integer (16 bit) │
2605       │                  │ request/response   │                  │
2606       ├──────────────────┼────────────────────┼──────────────────┤
2607       │                  │                    │                  │
2608       │sequence          │ sequence number of │ integer (16 bit) │
2609       │                  │ echo               │                  │
2610       │                  │ request/response   │                  │
2611       ├──────────────────┼────────────────────┼──────────────────┤
2612       │                  │                    │                  │
2613       │max-delay         │ maximum response   │ integer (16 bit) │
2614       │                  │ delay of MLD       │                  │
2615       │                  │ queries            │                  │
2616       └──────────────────┴────────────────────┴──────────────────┘
2617
2618   TCP HEADER EXPRESSION
2619           tcp {sport | dport | sequence | ackseq | doff | reserved | flags | window | checksum | urgptr}
2620
2621       Table 45. TCP header expression
2622       ┌─────────┬──────────────────┬──────────────────┐
2623Keyword  Description      Type             
2624       ├─────────┼──────────────────┼──────────────────┤
2625       │         │                  │                  │
2626       │sport    │ Source port      │ inet_service     │
2627       ├─────────┼──────────────────┼──────────────────┤
2628       │         │                  │                  │
2629       │dport    │ Destination port │ inet_service     │
2630       ├─────────┼──────────────────┼──────────────────┤
2631       │         │                  │                  │
2632       │sequence │ Sequence number  │ integer (32 bit) │
2633       ├─────────┼──────────────────┼──────────────────┤
2634       │         │                  │                  │
2635       │ackseq   │ Acknowledgement  │ integer (32 bit) │
2636       │         │ number           │                  │
2637       ├─────────┼──────────────────┼──────────────────┤
2638       │         │                  │                  │
2639       │doff     │ Data offset      │ integer (4 bit)  │
2640       │         │                  │ FIXME scaling    │
2641       ├─────────┼──────────────────┼──────────────────┤
2642       │         │                  │                  │
2643       │reserved │ Reserved area    │ integer (4 bit)  │
2644       ├─────────┼──────────────────┼──────────────────┤
2645       │         │                  │                  │
2646       │flags    │ TCP flags        │ tcp_flag         │
2647       ├─────────┼──────────────────┼──────────────────┤
2648       │         │                  │                  │
2649       │window   │ Window           │ integer (16 bit) │
2650       ├─────────┼──────────────────┼──────────────────┤
2651       │         │                  │                  │
2652       │checksum │ Checksum         │ integer (16 bit) │
2653       ├─────────┼──────────────────┼──────────────────┤
2654       │         │                  │                  │
2655       │urgptr   │ Urgent pointer   │ integer (16 bit) │
2656       └─────────┴──────────────────┴──────────────────┘
2657
2658   UDP HEADER EXPRESSION
2659           udp {sport | dport | length | checksum}
2660
2661       Table 46. UDP header expression
2662       ┌─────────┬─────────────────────┬──────────────────┐
2663Keyword  Description         Type             
2664       ├─────────┼─────────────────────┼──────────────────┤
2665       │         │                     │                  │
2666       │sport    │ Source port         │ inet_service     │
2667       ├─────────┼─────────────────────┼──────────────────┤
2668       │         │                     │                  │
2669       │dport    │ Destination port    │ inet_service     │
2670       ├─────────┼─────────────────────┼──────────────────┤
2671       │         │                     │                  │
2672       │length   │ Total packet length │ integer (16 bit) │
2673       ├─────────┼─────────────────────┼──────────────────┤
2674       │         │                     │                  │
2675       │checksum │ Checksum            │ integer (16 bit) │
2676       └─────────┴─────────────────────┴──────────────────┘
2677
2678   UDP-LITE HEADER EXPRESSION
2679           udplite {sport | dport | checksum}
2680
2681       Table 47. UDP-Lite header expression
2682       ┌─────────┬──────────────────┬──────────────────┐
2683Keyword  Description      Type             
2684       ├─────────┼──────────────────┼──────────────────┤
2685       │         │                  │                  │
2686       │sport    │ Source port      │ inet_service     │
2687       ├─────────┼──────────────────┼──────────────────┤
2688       │         │                  │                  │
2689       │dport    │ Destination port │ inet_service     │
2690       ├─────────┼──────────────────┼──────────────────┤
2691       │         │                  │                  │
2692       │checksum │ Checksum         │ integer (16 bit) │
2693       └─────────┴──────────────────┴──────────────────┘
2694
2695   SCTP HEADER EXPRESSION
2696           sctp {sport | dport | vtag | checksum}
2697
2698       Table 48. SCTP header expression
2699       ┌─────────┬──────────────────┬──────────────────┐
2700Keyword  Description      Type             
2701       ├─────────┼──────────────────┼──────────────────┤
2702       │         │                  │                  │
2703       │sport    │ Source port      │ inet_service     │
2704       ├─────────┼──────────────────┼──────────────────┤
2705       │         │                  │                  │
2706       │dport    │ Destination port │ inet_service     │
2707       ├─────────┼──────────────────┼──────────────────┤
2708       │         │                  │                  │
2709       │vtag     │ Verification Tag │ integer (32 bit) │
2710       ├─────────┼──────────────────┼──────────────────┤
2711       │         │                  │                  │
2712       │checksum │ Checksum         │ integer (32 bit) │
2713       └─────────┴──────────────────┴──────────────────┘
2714
2715   DCCP HEADER EXPRESSION
2716           dccp {sport | dport | type}
2717
2718       Table 49. DCCP header expression
2719       ┌────────┬──────────────────┬──────────────┐
2720Keyword Description      Type         
2721       ├────────┼──────────────────┼──────────────┤
2722       │        │                  │              │
2723       │sport   │ Source port      │ inet_service │
2724       ├────────┼──────────────────┼──────────────┤
2725       │        │                  │              │
2726       │dport   │ Destination port │ inet_service │
2727       ├────────┼──────────────────┼──────────────┤
2728       │        │                  │              │
2729       │type    │ Packet type      │ dccp_pkttype │
2730       └────────┴──────────────────┴──────────────┘
2731
2732   AUTHENTICATION HEADER EXPRESSION
2733           ah {nexthdr | hdrlength | reserved | spi | sequence}
2734
2735       Table 50. AH header expression
2736       ┌──────────┬────────────────────┬──────────────────┐
2737Keyword   Description        Type             
2738       ├──────────┼────────────────────┼──────────────────┤
2739       │          │                    │                  │
2740       │nexthdr   │ Next header        │ inet_proto       │
2741       │          │ protocol           │                  │
2742       ├──────────┼────────────────────┼──────────────────┤
2743       │          │                    │                  │
2744       │hdrlength │ AH Header length   │ integer (8 bit)  │
2745       ├──────────┼────────────────────┼──────────────────┤
2746       │          │                    │                  │
2747       │reserved  │ Reserved area      │ integer (16 bit) │
2748       ├──────────┼────────────────────┼──────────────────┤
2749       │          │                    │                  │
2750       │spi       │ Security Parameter │ integer (32 bit) │
2751       │          │ Index              │                  │
2752       ├──────────┼────────────────────┼──────────────────┤
2753       │          │                    │                  │
2754       │sequence  │ Sequence number    │ integer (32 bit) │
2755       └──────────┴────────────────────┴──────────────────┘
2756
2757   ENCRYPTED SECURITY PAYLOAD HEADER EXPRESSION
2758           esp {spi | sequence}
2759
2760       Table 51. ESP header expression
2761       ┌─────────┬────────────────────┬──────────────────┐
2762Keyword  Description        Type             
2763       ├─────────┼────────────────────┼──────────────────┤
2764       │         │                    │                  │
2765       │spi      │ Security Parameter │ integer (32 bit) │
2766       │         │ Index              │                  │
2767       ├─────────┼────────────────────┼──────────────────┤
2768       │         │                    │                  │
2769       │sequence │ Sequence number    │ integer (32 bit) │
2770       └─────────┴────────────────────┴──────────────────┘
2771
2772   IPCOMP HEADER EXPRESSION
2773       comp {nexthdr | flags | cpi}
2774
2775       Table 52. IPComp header expression
2776       ┌────────┬─────────────────┬──────────────────┐
2777Keyword Description     Type             
2778       ├────────┼─────────────────┼──────────────────┤
2779       │        │                 │                  │
2780       │nexthdr │ Next header     │ inet_proto       │
2781       │        │ protocol        │                  │
2782       ├────────┼─────────────────┼──────────────────┤
2783       │        │                 │                  │
2784       │flags   │ Flags           │ bitmask          │
2785       ├────────┼─────────────────┼──────────────────┤
2786       │        │                 │                  │
2787       │cpi     │ compression     │ integer (16 bit) │
2788       │        │ Parameter Index │                  │
2789       └────────┴─────────────────┴──────────────────┘
2790
2791   RAW PAYLOAD EXPRESSION
2792           @base,offset,length
2793
2794       The raw payload expression instructs to load length bits starting at
2795       offset bits. Bit 0 refers to the very first bit — in the C programming
2796       language, this corresponds to the topmost bit, i.e. 0x80 in case of an
2797       octet. They are useful to match headers that do not have a
2798       human-readable template expression yet. Note that nft will not add
2799       dependencies for Raw payload expressions. If you e.g. want to match
2800       protocol fields of a transport header with protocol number 5, you need
2801       to manually exclude packets that have a different transport header, for
2802       instance by using meta l4proto 5 before the raw expression.
2803
2804       Table 53. Supported payload protocol bases
2805       ┌─────┬─────────────────────────┐
2806Base Description             
2807       ├─────┼─────────────────────────┤
2808       │     │                         │
2809       │ll   │ Link layer, for example │
2810       │     │ the Ethernet header     │
2811       ├─────┼─────────────────────────┤
2812       │     │                         │
2813       │nh   │ Network header, for     │
2814       │     │ example IPv4 or IPv6    │
2815       ├─────┼─────────────────────────┤
2816       │     │                         │
2817       │th   │ Transport Header, for   │
2818       │     │ example TCP             │
2819       └─────┴─────────────────────────┘
2820
2821       Matching destination port of both UDP and TCP.
2822
2823           inet filter input meta l4proto {tcp, udp} @th,16,16 { 53, 80 }
2824
2825       The above can also be written as
2826
2827           inet filter input meta l4proto {tcp, udp} th dport { 53, 80 }
2828
2829       it is more convenient, but like the raw expression notation no
2830       dependencies are created or checked. It is the users responsibility to
2831       restrict matching to those header types that have a notion of ports.
2832       Otherwise, rules using raw expressions will errnously match unrelated
2833       packets, e.g. mis-interpreting ESP packets SPI field as a port.
2834
2835       Rewrite arp packet target hardware address if target protocol address
2836       matches a given address.
2837
2838           input meta iifname enp2s0 arp ptype 0x0800 arp htype 1 arp hlen 6 arp plen 4 @nh,192,32 0xc0a88f10 @nh,144,48 set 0x112233445566 accept
2839
2840
2841   EXTENSION HEADER EXPRESSIONS
2842       Extension header expressions refer to data from variable-sized protocol
2843       headers, such as IPv6 extension headers, TCP options and IPv4 options.
2844
2845       nftables currently supports matching (finding) a given ipv6 extension
2846       header, TCP option or IPv4 option.
2847
2848           hbh {nexthdr | hdrlength}
2849           frag {nexthdr | frag-off | more-fragments | id}
2850           rt {nexthdr | hdrlength | type | seg-left}
2851           dst {nexthdr | hdrlength}
2852           mh {nexthdr | hdrlength | checksum | type}
2853           srh {flags | tag | sid | seg-left}
2854           tcp option {eol | nop | maxseg | window | sack-perm | sack | sack0 | sack1 | sack2 | sack3 | timestamp} tcp_option_field
2855           ip option { lsrr | ra | rr | ssrr } ip_option_field
2856
2857       The following syntaxes are valid only in a relational expression with
2858       boolean type on right-hand side for checking header existence only:
2859
2860           exthdr {hbh | frag | rt | dst | mh}
2861           tcp option {eol | nop | maxseg | window | sack-perm | sack | sack0 | sack1 | sack2 | sack3 | timestamp}
2862           ip option { lsrr | ra | rr | ssrr }
2863
2864       Table 54. IPv6 extension headers
2865       ┌────────┬────────────────────────┐
2866Keyword Description            
2867       ├────────┼────────────────────────┤
2868       │        │                        │
2869       │hbh     │ Hop by Hop             │
2870       ├────────┼────────────────────────┤
2871       │        │                        │
2872       │rt      │ Routing Header         │
2873       ├────────┼────────────────────────┤
2874       │        │                        │
2875       │frag    │ Fragmentation header   │
2876       ├────────┼────────────────────────┤
2877       │        │                        │
2878       │dst     │ dst options            │
2879       ├────────┼────────────────────────┤
2880       │        │                        │
2881       │mh      │ Mobility Header        │
2882       ├────────┼────────────────────────┤
2883       │        │                        │
2884       │srh     │ Segment Routing Header │
2885       └────────┴────────────────────────┘
2886
2887       Table 55. TCP Options
2888       ┌──────────┬─────────────────────┬─────────────────────┐
2889Keyword   Description         TCP option fields   
2890       ├──────────┼─────────────────────┼─────────────────────┤
2891       │          │                     │                     │
2892       │eol       │ End if option list  │ kind                │
2893       ├──────────┼─────────────────────┼─────────────────────┤
2894       │          │                     │                     │
2895       │nop       │ 1 Byte TCP Nop      │ kind                │
2896       │          │ padding option      │                     │
2897       ├──────────┼─────────────────────┼─────────────────────┤
2898       │          │                     │                     │
2899       │maxseg    │ TCP Maximum Segment │ kind, length, size  │
2900       │          │ Size                │                     │
2901       ├──────────┼─────────────────────┼─────────────────────┤
2902       │          │                     │                     │
2903       │window    │ TCP Window Scaling  │ kind, length, count │
2904       ├──────────┼─────────────────────┼─────────────────────┤
2905       │          │                     │                     │
2906       │sack-perm │ TCP SACK permitted  │ kind, length        │
2907       ├──────────┼─────────────────────┼─────────────────────┤
2908       │          │                     │                     │
2909       │sack      │ TCP Selective       │ kind, length, left, │
2910       │          │ Acknowledgement     │ right               │
2911       │          │ (alias of block 0)  │                     │
2912       ├──────────┼─────────────────────┼─────────────────────┤
2913       │          │                     │                     │
2914       │sack0     │ TCP Selective       │ kind, length, left, │
2915       │          │ Acknowledgement     │ right               │
2916       │          │ (block 0)           │                     │
2917       ├──────────┼─────────────────────┼─────────────────────┤
2918       │          │                     │                     │
2919       │sack1     │ TCP Selective       │ kind, length, left, │
2920       │          │ Acknowledgement     │ right               │
2921       │          │ (block 1)           │                     │
2922       ├──────────┼─────────────────────┼─────────────────────┤
2923       │          │                     │                     │
2924       │sack2     │ TCP Selective       │ kind, length, left, │
2925       │          │ Acknowledgement     │ right               │
2926       │          │ (block 2)           │                     │
2927       ├──────────┼─────────────────────┼─────────────────────┤
2928       │          │                     │                     │
2929       │sack3     │ TCP Selective       │ kind, length, left, │
2930       │          │ Acknowledgement     │ right               │
2931       │          │ (block 3)           │                     │
2932       ├──────────┼─────────────────────┼─────────────────────┤
2933       │          │                     │                     │
2934       │timestamp │ TCP Timestamps      │ kind, length,       │
2935       │          │                     │ tsval, tsecr        │
2936       └──────────┴─────────────────────┴─────────────────────┘
2937
2938       TCP option matching also supports raw expression syntax to access
2939       arbitrary options:
2940
2941           tcp option
2942
2943           tcp option @number,offset,length
2944
2945       Table 56. IP Options
2946       ┌────────┬─────────────────────┬─────────────────────┐
2947Keyword Description         IP option fields    
2948       ├────────┼─────────────────────┼─────────────────────┤
2949       │        │                     │                     │
2950       │lsrr    │ Loose Source Route  │ type, length, ptr,  │
2951       │        │                     │ addr                │
2952       ├────────┼─────────────────────┼─────────────────────┤
2953       │        │                     │                     │
2954       │ra      │ Router Alert        │ type, length, value │
2955       ├────────┼─────────────────────┼─────────────────────┤
2956       │        │                     │                     │
2957       │rr      │ Record Route        │ type, length, ptr,  │
2958       │        │                     │ addr                │
2959       ├────────┼─────────────────────┼─────────────────────┤
2960       │        │                     │                     │
2961       │ssrr    │ Strict Source Route │ type, length, ptr,  │
2962       │        │                     │ addr                │
2963       └────────┴─────────────────────┴─────────────────────┘
2964
2965       finding TCP options.
2966
2967           filter input tcp option sack-perm kind 1 counter
2968
2969       matching IPv6 exthdr.
2970
2971           ip6 filter input frag more-fragments 1 counter
2972
2973       finding IP option.
2974
2975           filter input ip option lsrr exists counter
2976
2977
2978   CONNTRACK EXPRESSIONS
2979       Conntrack expressions refer to meta data of the connection tracking
2980       entry associated with a packet.
2981
2982       There are three types of conntrack expressions. Some conntrack
2983       expressions require the flow direction before the conntrack key, others
2984       must be used directly because they are direction agnostic. The packets,
2985       bytes and avgpkt keywords can be used with or without a direction. If
2986       the direction is omitted, the sum of the original and the reply
2987       direction is returned. The same is true for the zone, if a direction is
2988       given, the zone is only matched if the zone id is tied to the given
2989       direction.
2990
2991           ct {state | direction | status | mark | expiration | helper | label}
2992           ct [original | reply] {l3proto | protocol | bytes | packets | avgpkt | zone | id}
2993           ct {original | reply} {proto-src | proto-dst}
2994           ct {original | reply} {ip | ip6} {saddr | daddr}
2995
2996       The conntrack-specific types in this table are described in the
2997       sub-section CONNTRACK TYPES above.
2998
2999       Table 57. Conntrack expressions
3000       ┌───────────┬─────────────────────┬─────────────────────┐
3001Keyword    Description         Type                
3002       ├───────────┼─────────────────────┼─────────────────────┤
3003       │           │                     │                     │
3004       │state      │ State of the        │ ct_state            │
3005       │           │ connection          │                     │
3006       ├───────────┼─────────────────────┼─────────────────────┤
3007       │           │                     │                     │
3008       │direction  │ Direction of the    │ ct_dir              │
3009       │           │ packet relative to  │                     │
3010       │           │ the connection      │                     │
3011       ├───────────┼─────────────────────┼─────────────────────┤
3012       │           │                     │                     │
3013       │status     │ Status of the       │ ct_status           │
3014       │           │ connection          │                     │
3015       ├───────────┼─────────────────────┼─────────────────────┤
3016       │           │                     │                     │
3017       │mark       │ Connection mark     │ mark                │
3018       ├───────────┼─────────────────────┼─────────────────────┤
3019       │           │                     │                     │
3020       │expiration │ Connection          │ time                │
3021       │           │ expiration time     │                     │
3022       ├───────────┼─────────────────────┼─────────────────────┤
3023       │           │                     │                     │
3024       │helper     │ Helper associated   │ string              │
3025       │           │ with the connection │                     │
3026       ├───────────┼─────────────────────┼─────────────────────┤
3027       │           │                     │                     │
3028       │label      │ Connection tracking │ ct_label            │
3029       │           │ label bit or        │                     │
3030       │           │ symbolic name       │                     │
3031       │           │ defined in          │                     │
3032       │           │ connlabel.conf in   │                     │
3033       │           │ the nftables        │                     │
3034       │           │ include path        │                     │
3035       ├───────────┼─────────────────────┼─────────────────────┤
3036       │           │                     │                     │
3037       │l3proto    │ Layer 3 protocol of │ nf_proto            │
3038       │           │ the connection      │                     │
3039       ├───────────┼─────────────────────┼─────────────────────┤
3040       │           │                     │                     │
3041       │saddr      │ Source address of   │ ipv4_addr/ipv6_addr │
3042       │           │ the connection for  │                     │
3043       │           │ the given direction │                     │
3044       ├───────────┼─────────────────────┼─────────────────────┤
3045       │           │                     │                     │
3046       │daddr      │ Destination address │ ipv4_addr/ipv6_addr │
3047       │           │ of the connection   │                     │
3048       │           │ for the given       │                     │
3049       │           │ direction           │                     │
3050       ├───────────┼─────────────────────┼─────────────────────┤
3051       │           │                     │                     │
3052       │protocol   │ Layer 4 protocol of │ inet_proto          │
3053       │           │ the connection for  │                     │
3054       │           │ the given direction │                     │
3055       ├───────────┼─────────────────────┼─────────────────────┤
3056       │           │                     │                     │
3057       │proto-src  │ Layer 4 protocol    │ integer (16 bit)    │
3058       │           │ source for the      │                     │
3059       │           │ given direction     │                     │
3060       ├───────────┼─────────────────────┼─────────────────────┤
3061       │           │                     │                     │
3062       │proto-dst  │ Layer 4 protocol    │ integer (16 bit)    │
3063       │           │ destination for the │                     │
3064       │           │ given direction     │                     │
3065       ├───────────┼─────────────────────┼─────────────────────┤
3066       │           │                     │                     │
3067       │packets    │ packet count seen   │ integer (64 bit)    │
3068       │           │ in the given        │                     │
3069       │           │ direction or sum of │                     │
3070       │           │ original and reply  │                     │
3071       ├───────────┼─────────────────────┼─────────────────────┤
3072       │           │                     │                     │
3073       │bytes      │ byte count seen,    │ integer (64 bit)    │
3074       │           │ see description for │                     │
3075       │           │ packets keyword     │                     │
3076       ├───────────┼─────────────────────┼─────────────────────┤
3077       │           │                     │                     │
3078       │avgpkt     │ average bytes per   │ integer (64 bit)    │
3079       │           │ packet, see         │                     │
3080       │           │ description for     │                     │
3081       │           │ packets keyword     │                     │
3082       ├───────────┼─────────────────────┼─────────────────────┤
3083       │           │                     │                     │
3084       │zone       │ conntrack zone      │ integer (16 bit)    │
3085       ├───────────┼─────────────────────┼─────────────────────┤
3086       │           │                     │                     │
3087       │count      │ number of current   │ integer (32 bit)    │
3088       │           │ connections         │                     │
3089       ├───────────┼─────────────────────┼─────────────────────┤
3090       │           │                     │                     │
3091       │id         │ Connection id       │ ct_id               │
3092       └───────────┴─────────────────────┴─────────────────────┘
3093
3094       restrict the number of parallel connections to a server.
3095
3096           nft add set filter ssh_flood '{ type ipv4_addr; flags dynamic; }'
3097           nft add rule filter input tcp dport 22 add @ssh_flood '{ ip saddr ct count over 2 }' reject
3098
3099

STATEMENTS

3101       Statements represent actions to be performed. They can alter control
3102       flow (return, jump to a different chain, accept or drop the packet) or
3103       can perform actions, such as logging, rejecting a packet, etc.
3104
3105       Statements exist in two kinds. Terminal statements unconditionally
3106       terminate evaluation of the current rule, non-terminal statements
3107       either only conditionally or never terminate evaluation of the current
3108       rule, in other words, they are passive from the ruleset evaluation
3109       perspective. There can be an arbitrary amount of non-terminal
3110       statements in a rule, but only a single terminal statement as the final
3111       statement.
3112
3113   VERDICT STATEMENT
3114       The verdict statement alters control flow in the ruleset and issues
3115       policy decisions for packets.
3116
3117           {accept | drop | queue | continue | return}
3118           {jump | goto} chain
3119
3120       accept and drop are absolute verdicts — they terminate ruleset
3121       evaluation immediately.
3122
3123
3124       accept       Terminate ruleset
3125                    evaluation and accept the
3126                    packet. The packet can
3127                    still be dropped later by
3128                    another hook, for instance
3129                    accept in the forward hook
3130                    still allows to drop the
3131                    packet later in the
3132                    postrouting hook, or
3133                    another forward base chain
3134                    that has a higher priority
3135                    number and is evaluated
3136                    afterwards in the
3137                    processing pipeline.
3138
3139
3140       drop         Terminate ruleset
3141                    evaluation and drop the
3142                    packet. The drop occurs
3143                    instantly, no further
3144                    chains or hooks are
3145                    evaluated. It is not
3146                    possible to accept the
3147                    packet in a later chain
3148                    again, as those are not
3149                    evaluated anymore for the
3150                    packet.
3151
3152       queue        Terminate ruleset
3153                    evaluation and queue the
3154                    packet to userspace.
3155                    Userspace must provide a
3156                    drop or accept verdict. In
3157                    case of accept, processing
3158                    resumes with the next base
3159                    chain hook, not the rule
3160                    following the queue
3161                    verdict.
3162
3163       continue     Continue ruleset
3164                    evaluation with the next
3165                    rule. This is the default
3166                    behaviour in case a rule
3167                    issues no verdict.
3168
3169       return       Return from the current
3170                    chain and continue
3171                    evaluation at the next
3172                    rule in the last chain. If
3173                    issued in a base chain, it
3174                    is equivalent to the base
3175                    chain policy.
3176
3177       jump chain   Continue evaluation at the
3178                    first rule in chain. The
3179                    current position in the
3180                    ruleset is pushed to a
3181                    call stack and evaluation
3182                    will continue there when
3183                    the new chain is entirely
3184                    evaluated or a return
3185                    verdict is issued. In case
3186                    an absolute verdict is
3187                    issued by a rule in the
3188                    chain, ruleset evaluation
3189                    terminates immediately and
3190                    the specific action is
3191                    taken.
3192
3193       goto chain   Similar to jump, but the
3194                    current position is not
3195                    pushed to the call stack,
3196                    meaning that after the new
3197                    chain evaluation will
3198                    continue at the last chain
3199                    instead of the one
3200                    containing the goto
3201                    statement.
3202
3203
3204       Using verdict statements.
3205
3206           # process packets from eth0 and the internal network in from_lan
3207           # chain, drop all packets from eth0 with different source addresses.
3208
3209           filter input iif eth0 ip saddr 192.168.0.0/24 jump from_lan
3210           filter input iif eth0 drop
3211
3212
3213   PAYLOAD STATEMENT
3214           payload_expression set value
3215
3216       The payload statement alters packet content. It can be used for example
3217       to set ip DSCP (diffserv) header field or ipv6 flow labels.
3218
3219       route some packets instead of bridging.
3220
3221           # redirect tcp:http from 192.160.0.0/16 to local machine for routing instead of bridging
3222           # assumes 00:11:22:33:44:55 is local MAC address.
3223           bridge input meta iif eth0 ip saddr 192.168.0.0/16 tcp dport 80 meta pkttype set unicast ether daddr set 00:11:22:33:44:55
3224
3225       Set IPv4 DSCP header field.
3226
3227           ip forward ip dscp set 42
3228
3229
3230   EXTENSION HEADER STATEMENT
3231           extension_header_expression set value
3232
3233       The extension header statement alters packet content in variable-sized
3234       headers. This can currently be used to alter the TCP Maximum segment
3235       size of packets, similar to TCPMSS.
3236
3237       change tcp mss.
3238
3239           tcp flags syn tcp option maxseg size set 1360
3240           # set a size based on route information:
3241           tcp flags syn tcp option maxseg size set rt mtu
3242
3243
3244   LOG STATEMENT
3245           log [prefix quoted_string] [level syslog-level] [flags log-flags]
3246           log group nflog_group [prefix quoted_string] [queue-threshold value] [snaplen size]
3247           log level audit
3248
3249       The log statement enables logging of matching packets. When this
3250       statement is used from a rule, the Linux kernel will print some
3251       information on all matching packets, such as header fields, via the
3252       kernel log (where it can be read with dmesg(1) or read in the syslog).
3253
3254       In the second form of invocation (if nflog_group is specified), the
3255       Linux kernel will pass the packet to nfnetlink_log which will multicast
3256       the packet through a netlink socket to the specified multicast group.
3257       One or more userspace processes may subscribe to the group to receive
3258       the packets, see libnetfilter_queue documentation for details.
3259
3260       In the third form of invocation (if level audit is specified), the
3261       Linux kernel writes a message into the audit buffer suitably formatted
3262       for reading with auditd. Therefore no further formatting options (such
3263       as prefix or flags) are allowed in this mode.
3264
3265       This is a non-terminating statement, so the rule evaluation continues
3266       after the packet is logged.
3267
3268       Table 58. log statement options
3269       ┌────────────────┬─────────────────────┬───────────────────┐
3270Keyword         Description         Type              
3271       ├────────────────┼─────────────────────┼───────────────────┤
3272       │                │                     │                   │
3273       │prefix          │ Log message prefix  │ quoted string     │
3274       ├────────────────┼─────────────────────┼───────────────────┤
3275       │                │                     │                   │
3276       │level           │ Syslog level of     │ string: emerg,    │
3277       │                │ logging             │ alert, crit, err, │
3278       │                │                     │ warn [default],   │
3279       │                │                     │ notice, info,     │
3280       │                │                     │ debug, audit      │
3281       ├────────────────┼─────────────────────┼───────────────────┤
3282       │                │                     │                   │
3283       │group           │ NFLOG group to send │ unsigned integer  │
3284       │                │ messages to         │ (16 bit)          │
3285       ├────────────────┼─────────────────────┼───────────────────┤
3286       │                │                     │                   │
3287       │snaplen         │ Length of packet    │ unsigned integer  │
3288       │                │ payload to include  │ (32 bit)          │
3289       │                │ in netlink message  │                   │
3290       ├────────────────┼─────────────────────┼───────────────────┤
3291       │                │                     │                   │
3292       │queue-threshold │ Number of packets   │ unsigned integer  │
3293       │                │ to queue inside the │ (32 bit)          │
3294       │                │ kernel before       │                   │
3295       │                │ sending them to     │                   │
3296       │                │ userspace           │                   │
3297       └────────────────┴─────────────────────┴───────────────────┘
3298
3299       Table 59. log-flags
3300       ┌─────────────┬───────────────────────────┐
3301Flag         Description               
3302       ├─────────────┼───────────────────────────┤
3303       │             │                           │
3304       │tcp sequence │ Log TCP sequence numbers. │
3305       ├─────────────┼───────────────────────────┤
3306       │             │                           │
3307       │tcp options  │ Log options from the TCP  │
3308       │             │ packet header.            │
3309       ├─────────────┼───────────────────────────┤
3310       │             │                           │
3311       │ip options   │ Log options from the      │
3312       │             │ IP/IPv6 packet header.    │
3313       ├─────────────┼───────────────────────────┤
3314       │             │                           │
3315       │skuid        │ Log the userid of the     │
3316       │             │ process which generated   │
3317       │             │ the packet.               │
3318       ├─────────────┼───────────────────────────┤
3319       │             │                           │
3320       │ether        │ Decode MAC addresses and  │
3321       │             │ protocol.                 │
3322       ├─────────────┼───────────────────────────┤
3323       │             │                           │
3324       │all          │ Enable all log flags      │
3325       │             │ listed above.             │
3326       └─────────────┴───────────────────────────┘
3327
3328       Using log statement.
3329
3330           # log the UID which generated the packet and ip options
3331           ip filter output log flags skuid flags ip options
3332
3333           # log the tcp sequence numbers and tcp options from the TCP packet
3334           ip filter output log flags tcp sequence,options
3335
3336           # enable all supported log flags
3337           ip6 filter output log flags all
3338
3339
3340   REJECT STATEMENT
3341           reject [ with REJECT_WITH ]
3342
3343           REJECT_WITH := icmp type icmp_code |
3344                            icmpv6 type icmpv6_code |
3345                            icmpx type icmpx_code |
3346                            tcp reset
3347
3348       A reject statement is used to send back an error packet in response to
3349       the matched packet otherwise it is equivalent to drop so it is a
3350       terminating statement, ending rule traversal. This statement is only
3351       valid in base chains using the input, forward or output hooks, and
3352       user-defined chains which are only called from those chains.
3353
3354       Table 60. different ICMP reject variants are meant for use in different
3355       table families
3356       ┌────────┬────────┬─────────────┐
3357Variant Family Type        
3358       ├────────┼────────┼─────────────┤
3359       │        │        │             │
3360       │icmp    │ ip     │ icmp_code   │
3361       ├────────┼────────┼─────────────┤
3362       │        │        │             │
3363       │icmpv6  │ ip6    │ icmpv6_code │
3364       ├────────┼────────┼─────────────┤
3365       │        │        │             │
3366       │icmpx   │ inet   │ icmpx_code  │
3367       └────────┴────────┴─────────────┘
3368
3369       For a description of the different types and a list of supported
3370       keywords refer to DATA TYPES section above. The common default reject
3371       value is port-unreachable.
3372
3373       Note that in bridge family, reject statement is only allowed in base
3374       chains which hook into input or prerouting.
3375
3376   COUNTER STATEMENT
3377       A counter statement sets the hit count of packets along with the number
3378       of bytes.
3379
3380           counter packets number bytes number
3381           counter { packets number | bytes number }
3382
3383   CONNTRACK STATEMENT
3384       The conntrack statement can be used to set the conntrack mark and
3385       conntrack labels.
3386
3387           ct {mark | event | label | zone} set value
3388
3389       The ct statement sets meta data associated with a connection. The zone
3390       id has to be assigned before a conntrack lookup takes place, i.e. this
3391       has to be done in prerouting and possibly output (if locally generated
3392       packets need to be placed in a distinct zone), with a hook priority of
3393       -300.
3394
3395       Unlike iptables, where the helper assignment happens in the raw table,
3396       the helper needs to be assigned after a conntrack entry has been found,
3397       i.e. it will not work when used with hook priorities equal or before
3398       -200.
3399
3400       Table 61. Conntrack statement types
3401       ┌────────┬─────────────────────┬──────────────────┐
3402Keyword Description         Value            
3403       ├────────┼─────────────────────┼──────────────────┤
3404       │        │                     │                  │
3405       │event   │ conntrack event     │ bitmask, integer │
3406       │        │ bits                │ (32 bit)         │
3407       ├────────┼─────────────────────┼──────────────────┤
3408       │        │                     │                  │
3409       │helper  │ name of ct helper   │ quoted string    │
3410       │        │ object to assign to │                  │
3411       │        │ the connection      │                  │
3412       ├────────┼─────────────────────┼──────────────────┤
3413       │        │                     │                  │
3414       │mark    │ Connection tracking │ mark             │
3415       │        │ mark                │                  │
3416       ├────────┼─────────────────────┼──────────────────┤
3417       │        │                     │                  │
3418       │label   │ Connection tracking │ label            │
3419       │        │ label               │                  │
3420       ├────────┼─────────────────────┼──────────────────┤
3421       │        │                     │                  │
3422       │zone    │ conntrack zone      │ integer (16 bit) │
3423       └────────┴─────────────────────┴──────────────────┘
3424
3425       save packet nfmark in conntrack.
3426
3427           ct mark set meta mark
3428
3429       set zone mapped via interface.
3430
3431           table inet raw {
3432             chain prerouting {
3433                 type filter hook prerouting priority -300;
3434                 ct zone set iif map { "eth1" : 1, "veth1" : 2 }
3435             }
3436             chain output {
3437                 type filter hook output priority -300;
3438                 ct zone set oif map { "eth1" : 1, "veth1" : 2 }
3439             }
3440           }
3441
3442       restrict events reported by ctnetlink.
3443
3444           ct event set new,related,destroy
3445
3446
3447   NOTRACK STATEMENT
3448       The notrack statement allows to disable connection tracking for certain
3449       packets.
3450
3451           notrack
3452
3453       Note that for this statement to be effective, it has to be applied to
3454       packets before a conntrack lookup happens. Therefore, it needs to sit
3455       in a chain with either prerouting or output hook and a hook priority of
3456       -300 or less.
3457
3458       See SYNPROXY STATEMENT for an example usage.
3459
3460   META STATEMENT
3461       A meta statement sets the value of a meta expression. The existing meta
3462       fields are: priority, mark, pkttype, nftrace.
3463
3464           meta {mark | priority | pkttype | nftrace} set value
3465
3466       A meta statement sets meta data associated with a packet.
3467
3468       Table 62. Meta statement types
3469       ┌─────────┬─────────────────────┬───────────┐
3470Keyword  Description         Value     
3471       ├─────────┼─────────────────────┼───────────┤
3472       │         │                     │           │
3473       │priority │ TC packet priority  │ tc_handle │
3474       ├─────────┼─────────────────────┼───────────┤
3475       │         │                     │           │
3476       │mark     │ Packet mark         │ mark      │
3477       ├─────────┼─────────────────────┼───────────┤
3478       │         │                     │           │
3479       │pkttype  │ packet type         │ pkt_type  │
3480       ├─────────┼─────────────────────┼───────────┤
3481       │         │                     │           │
3482       │nftrace  │ ruleset packet      │ 0, 1      │
3483       │         │ tracing on/off. Use │           │
3484       │         │ monitor trace       │           │
3485       │         │ command to watch    │           │
3486       │         │ traces              │           │
3487       └─────────┴─────────────────────┴───────────┘
3488
3489   LIMIT STATEMENT
3490           limit rate [over] packet_number / TIME_UNIT [burst packet_number packets]
3491           limit rate [over] byte_number BYTE_UNIT / TIME_UNIT [burst byte_number BYTE_UNIT]
3492
3493           TIME_UNIT := second | minute | hour | day
3494           BYTE_UNIT := bytes | kbytes | mbytes
3495
3496       A limit statement matches at a limited rate using a token bucket
3497       filter. A rule using this statement will match until this limit is
3498       reached. It can be used in combination with the log statement to give
3499       limited logging. The optional over keyword makes it match over the
3500       specified rate. Default burst is 5. if you specify burst, it must be
3501       non-zero value.
3502
3503       Table 63. limit statement values
3504       ┌──────────────┬───────────────────┬──────────────────┐
3505Value         Description       Type             
3506       ├──────────────┼───────────────────┼──────────────────┤
3507       │              │                   │                  │
3508       │packet_number │ Number of packets │ unsigned integer │
3509       │              │                   │ (32 bit)         │
3510       ├──────────────┼───────────────────┼──────────────────┤
3511       │              │                   │                  │
3512       │byte_number   │ Number of bytes   │ unsigned integer │
3513       │              │                   │ (32 bit)         │
3514       └──────────────┴───────────────────┴──────────────────┘
3515
3516   NAT STATEMENTS
3517           snat to address [:port] [PRF_FLAGS]
3518           snat to address - address [:port - port] [PRF_FLAGS]
3519           snat { ip | ip6 } to address - address [:port - port] [PR_FLAGS]
3520           dnat to address [:port] [PRF_FLAGS]
3521           dnat to address [:port - port] [PR_FLAGS]
3522           dnat { ip | ip6 } to address [:port - port] [PR_FLAGS]
3523           masquerade to [:port] [PRF_FLAGS]
3524           masquerade to [:port - port] [PRF_FLAGS]
3525           redirect to [:port] [PRF_FLAGS]
3526           redirect to [:port - port] [PRF_FLAGS]
3527
3528           PRF_FLAGS := PRF_FLAG [, PRF_FLAGS]
3529           PR_FLAGS  := PR_FLAG [, PR_FLAGS]
3530           PRF_FLAG  := PR_FLAG | fully-random
3531           PR_FLAG   := persistent | random
3532
3533       The nat statements are only valid from nat chain types.
3534
3535       The snat and masquerade statements specify that the source address of
3536       the packet should be modified. While snat is only valid in the
3537       postrouting and input chains, masquerade makes sense only in
3538       postrouting. The dnat and redirect statements are only valid in the
3539       prerouting and output chains, they specify that the destination address
3540       of the packet should be modified. You can use non-base chains which are
3541       called from base chains of nat chain type too. All future packets in
3542       this connection will also be mangled, and rules should cease being
3543       examined.
3544
3545       The masquerade statement is a special form of snat which always uses
3546       the outgoing interface’s IP address to translate to. It is particularly
3547       useful on gateways with dynamic (public) IP addresses.
3548
3549       The redirect statement is a special form of dnat which always
3550       translates the destination address to the local host’s one. It comes in
3551       handy if one only wants to alter the destination port of incoming
3552       traffic on different interfaces.
3553
3554       When used in the inet family (available with kernel 5.2), the dnat and
3555       snat statements require the use of the ip and ip6 keyword in case an
3556       address is provided, see the examples below.
3557
3558       Before kernel 4.18 nat statements require both prerouting and
3559       postrouting base chains to be present since otherwise packets on the
3560       return path won’t be seen by netfilter and therefore no reverse
3561       translation will take place.
3562
3563       Table 64. NAT statement values
3564       ┌───────────┬─────────────────────┬─────────────────────┐
3565Expression Description         Type                
3566       ├───────────┼─────────────────────┼─────────────────────┤
3567       │           │                     │                     │
3568       │address    │ Specifies that the  │ ipv4_addr,          │
3569       │           │ source/destination  │ ipv6_addr, e.g.     │
3570       │           │ address of the      │ abcd::1234, or you  │
3571       │           │ packet should be    │ can use a mapping,  │
3572       │           │ modified. You may   │ e.g. meta mark map  │
3573       │           │ specify a mapping   │ { 10 : 192.168.1.2, │
3574       │           │ to relate a list of │ 20 : 192.168.1.3 }  │
3575       │           │ tuples composed of  │                     │
3576       │           │ arbitrary           │                     │
3577       │           │ expression key with │                     │
3578       │           │ address value.      │                     │
3579       ├───────────┼─────────────────────┼─────────────────────┤
3580       │           │                     │                     │
3581       │port       │ Specifies that the  │ port number (16     │
3582       │           │ source/destination  │ bit)                │
3583       │           │ address of the      │                     │
3584       │           │ packet should be    │                     │
3585       │           │ modified.           │                     │
3586       └───────────┴─────────────────────┴─────────────────────┘
3587
3588       Table 65. NAT statement flags
3589       ┌─────────────┬─────────────────────────────┐
3590Flag         Description                 
3591       ├─────────────┼─────────────────────────────┤
3592       │             │                             │
3593       │persistent   │ Gives a client the same     │
3594       │             │ source-/destination-address │
3595       │             │ for each connection.        │
3596       ├─────────────┼─────────────────────────────┤
3597       │             │                             │
3598       │random       │ In kernel 5.0 and newer     │
3599       │             │ this is the same as         │
3600       │             │ fully-random. In earlier    │
3601       │             │ kernels the port mapping    │
3602       │             │ will be randomized using a  │
3603       │             │ seeded MD5 hash mix using   │
3604       │             │ source and destination      │
3605       │             │ address and destination     │
3606       │             │ port.                       │
3607       ├─────────────┼─────────────────────────────┤
3608       │             │                             │
3609       │fully-random │ If used then port mapping   │
3610       │             │ is generated based on a     │
3611       │             │ 32-bit pseudo-random        │
3612       │             │ algorithm.                  │
3613       └─────────────┴─────────────────────────────┘
3614
3615       Using NAT statements.
3616
3617           # create a suitable table/chain setup for all further examples
3618           add table nat
3619           add chain nat prerouting { type nat hook prerouting priority 0; }
3620           add chain nat postrouting { type nat hook postrouting priority 100; }
3621
3622           # translate source addresses of all packets leaving via eth0 to address 1.2.3.4
3623           add rule nat postrouting oif eth0 snat to 1.2.3.4
3624
3625           # redirect all traffic entering via eth0 to destination address 192.168.1.120
3626           add rule nat prerouting iif eth0 dnat to 192.168.1.120
3627
3628           # translate source addresses of all packets leaving via eth0 to whatever
3629           # locally generated packets would use as source to reach the same destination
3630           add rule nat postrouting oif eth0 masquerade
3631
3632           # redirect incoming TCP traffic for port 22 to port 2222
3633           add rule nat prerouting tcp dport 22 redirect to :2222
3634
3635           # inet family:
3636           # handle ip dnat:
3637           add rule inet nat prerouting dnat ip to 10.0.2.99
3638           # handle ip6 dnat:
3639           add rule inet nat prerouting dnat ip6 to fe80::dead
3640           # this masquerades both ipv4 and ipv6:
3641           add rule inet nat postrouting meta oif ppp0 masquerade
3642
3643
3644   TPROXY STATEMENT
3645       Tproxy redirects the packet to a local socket without changing the
3646       packet header in any way. If any of the arguments is missing the data
3647       of the incoming packet is used as parameter. Tproxy matching requires
3648       another rule that ensures the presence of transport protocol header is
3649       specified.
3650
3651           tproxy to address:port
3652           tproxy to {address | :port}
3653
3654       This syntax can be used in ip/ip6 tables where network layer protocol
3655       is obvious. Either IP address or port can be specified, but at least
3656       one of them is necessary.
3657
3658           tproxy {ip | ip6} to address[:port]
3659           tproxy to :port
3660
3661       This syntax can be used in inet tables. The ip/ip6 parameter defines
3662       the family the rule will match. The address parameter must be of this
3663       family. When only port is defined, the address family should not be
3664       specified. In this case the rule will match for both families.
3665
3666       Table 66. tproxy attributes
3667       ┌────────┬────────────────────────────┐
3668Name    Description                
3669       ├────────┼────────────────────────────┤
3670       │        │                            │
3671       │address │ IP address the listening   │
3672       │        │ socket with IP_TRANSPARENT │
3673       │        │ option is bound to.        │
3674       ├────────┼────────────────────────────┤
3675       │        │                            │
3676       │port    │ Port the listening socket  │
3677       │        │ with IP_TRANSPARENT option │
3678       │        │ is bound to.               │
3679       └────────┴────────────────────────────┘
3680
3681       Example ruleset for tproxy statement.
3682
3683           table ip x {
3684               chain y {
3685                   type filter hook prerouting priority -150; policy accept;
3686                   tcp dport ntp tproxy to 1.1.1.1
3687                   udp dport ssh tproxy to :2222
3688               }
3689           }
3690           table ip6 x {
3691               chain y {
3692                  type filter hook prerouting priority -150; policy accept;
3693                  tcp dport ntp tproxy to [dead::beef]
3694                  udp dport ssh tproxy to :2222
3695               }
3696           }
3697           table inet x {
3698               chain y {
3699                   type filter hook prerouting priority -150; policy accept;
3700                   tcp dport 321 tproxy to :ssh
3701                   tcp dport 99 tproxy ip to 1.1.1.1:999
3702                   udp dport 155 tproxy ip6 to [dead::beef]:smux
3703               }
3704           }
3705
3706
3707   SYNPROXY STATEMENT
3708       This statement will process TCP three-way-handshake parallel in
3709       netfilter context to protect either local or backend system. This
3710       statement requires connection tracking because sequence numbers need to
3711       be translated.
3712
3713           synproxy [mss mss_value] [wscale wscale_value] [SYNPROXY_FLAGS]
3714
3715       Table 67. synproxy statement attributes
3716       ┌───────┬────────────────────────────┐
3717Name   Description                
3718       ├───────┼────────────────────────────┤
3719       │       │                            │
3720       │mss    │ Maximum segment size       │
3721       │       │ announced to clients. This │
3722       │       │ must match the backend.    │
3723       ├───────┼────────────────────────────┤
3724       │       │                            │
3725       │wscale │ Window scale announced to  │
3726       │       │ clients. This must match   │
3727       │       │ the backend.               │
3728       └───────┴────────────────────────────┘
3729
3730       Table 68. synproxy statement flags
3731       ┌──────────┬────────────────────────────┐
3732Flag      Description                
3733       ├──────────┼────────────────────────────┤
3734       │          │                            │
3735       │sack-perm │ Pass client selective      │
3736       │          │ acknowledgement option to  │
3737       │          │ backend (will be disabled  │
3738       │          │ if not present).           │
3739       ├──────────┼────────────────────────────┤
3740       │          │                            │
3741       │timestamp │ Pass client timestamp      │
3742       │          │ option to backend (will be │
3743       │          │ disabled if not present,   │
3744       │          │ also needed for selective  │
3745       │          │ acknowledgement and window │
3746       │          │ scaling).                  │
3747       └──────────┴────────────────────────────┘
3748
3749       Example ruleset for synproxy statement.
3750
3751           Determine tcp options used by backend, from an external system
3752
3753                         tcpdump -pni eth0 -c 1 'tcp[tcpflags] == (tcp-syn|tcp-ack)'
3754                             port 80 &
3755                         telnet 192.0.2.42 80
3756                         18:57:24.693307 IP 192.0.2.42.80 > 192.0.2.43.48757:
3757                             Flags [S.], seq 360414582, ack 788841994, win 14480,
3758                             options [mss 1460,sackOK,
3759                             TS val 1409056151 ecr 9690221,
3760                             nop,wscale 9],
3761                             length 0
3762
3763           Switch tcp_loose mode off, so conntrack will mark out-of-flow packets as state INVALID.
3764
3765                         echo 0 > /proc/sys/net/netfilter/nf_conntrack_tcp_loose
3766
3767           Make SYN packets untracked.
3768
3769                   table ip x {
3770                           chain y {
3771                                   type filter hook prerouting priority raw; policy accept;
3772                                   tcp flags syn notrack
3773                           }
3774                   }
3775
3776           Catch UNTRACKED (SYN  packets) and INVALID (3WHS ACK packets) states and send
3777           them to SYNPROXY. This rule will respond to SYN packets with SYN+ACK
3778           syncookies, create ESTABLISHED for valid client response (3WHS ACK packets) and
3779           drop incorrect cookies. Flags combinations not expected during  3WHS will not
3780           match and continue (e.g. SYN+FIN, SYN+ACK). Finally, drop invalid packets, this
3781           will be out-of-flow packets that were not matched by SYNPROXY.
3782
3783               table ip foo {
3784                       chain z {
3785                               type filter hook input priority filter; policy accept;
3786                               ct state { invalid, untracked } synproxy mss 1460 wscale 9 timestamp sack-perm
3787                               ct state invalid drop
3788                       }
3789               }
3790
3791           The outcome ruleset of the steps above should be similar to the one below.
3792
3793                   table ip x {
3794                           chain y {
3795                                   type filter hook prerouting priority raw; policy accept;
3796                                   tcp flags syn notrack
3797                           }
3798
3799                           chain z {
3800                                   type filter hook input priority filter; policy accept;
3801                                   ct state { invalid, untracked } synproxy mss 1460 wscale 9 timestamp sack-perm
3802                                   ct state invalid drop
3803                           }
3804                   }
3805
3806
3807   FLOW STATEMENT
3808       A flow statement allows us to select what flows you want to accelerate
3809       forwarding through layer 3 network stack bypass. You have to specify
3810       the flowtable name where you want to offload this flow.
3811
3812       flow add @flowtable
3813
3814   QUEUE STATEMENT
3815       This statement passes the packet to userspace using the nfnetlink_queue
3816       handler. The packet is put into the queue identified by its 16-bit
3817       queue number. Userspace can inspect and modify the packet if desired.
3818       Userspace must then drop or re-inject the packet into the kernel. See
3819       libnetfilter_queue documentation for details.
3820
3821           queue [num queue_number] [bypass]
3822           queue [num queue_number_from - queue_number_to] [QUEUE_FLAGS]
3823
3824           QUEUE_FLAGS := QUEUE_FLAG [, QUEUE_FLAGS]
3825           QUEUE_FLAG  := bypass | fanout
3826
3827       Table 69. queue statement values
3828       ┌──────────────────┬────────────────────┬──────────────────┐
3829Value             Description        Type             
3830       ├──────────────────┼────────────────────┼──────────────────┤
3831       │                  │                    │                  │
3832       │queue_number      │ Sets queue number, │ unsigned integer │
3833       │                  │ default is 0.      │ (16 bit)         │
3834       ├──────────────────┼────────────────────┼──────────────────┤
3835       │                  │                    │                  │
3836       │queue_number_from │ Sets initial queue │ unsigned integer │
3837       │                  │ in the range, if   │ (16 bit)         │
3838       │                  │ fanout is used.    │                  │
3839       ├──────────────────┼────────────────────┼──────────────────┤
3840       │                  │                    │                  │
3841       │queue_number_to   │ Sets closing queue │ unsigned integer │
3842       │                  │ in the range, if   │ (16 bit)         │
3843       │                  │ fanout is used.    │                  │
3844       └──────────────────┴────────────────────┴──────────────────┘
3845
3846       Table 70. queue statement flags
3847       ┌───────┬────────────────────────────┐
3848Flag   Description                
3849       ├───────┼────────────────────────────┤
3850       │       │                            │
3851       │bypass │ Let packets go through if  │
3852       │       │ userspace application      │
3853       │       │ cannot back off. Before    │
3854       │       │ using this flag, read      │
3855       │       │ libnetfilter_queue         │
3856       │       │ documentation for          │
3857       │       │ performance tuning         │
3858       │       │ recommendations.           │
3859       ├───────┼────────────────────────────┤
3860       │       │                            │
3861       │fanout │ Distribute packets between │
3862       │       │ several queues.            │
3863       └───────┴────────────────────────────┘
3864
3865   DUP STATEMENT
3866       The dup statement is used to duplicate a packet and send the copy to a
3867       different destination.
3868
3869           dup to device
3870           dup to address device device
3871
3872       Table 71. Dup statement values
3873       ┌───────────┬─────────────────────┬─────────────────────┐
3874Expression Description         Type                
3875       ├───────────┼─────────────────────┼─────────────────────┤
3876       │           │                     │                     │
3877       │address    │ Specifies that the  │ ipv4_addr,          │
3878       │           │ copy of the packet  │ ipv6_addr, e.g.     │
3879       │           │ should be sent to a │ abcd::1234, or you  │
3880       │           │ new gateway.        │ can use a mapping,  │
3881       │           │                     │ e.g. ip saddr map { │
3882       │           │                     │ 192.168.1.2 :       │
3883       │           │                     │ 10.1.1.1 }          │
3884       ├───────────┼─────────────────────┼─────────────────────┤
3885       │           │                     │                     │
3886       │device     │ Specifies that the  │ string              │
3887       │           │ copy should be      │                     │
3888       │           │ transmitted via     │                     │
3889       │           │ device.             │                     │
3890       └───────────┴─────────────────────┴─────────────────────┘
3891
3892       Using the dup statement.
3893
3894           # send to machine with ip address 10.2.3.4 on eth0
3895           ip filter forward dup to 10.2.3.4 device "eth0"
3896
3897           # copy raw frame to another interface
3898           netdetv ingress dup to "eth0"
3899           dup to "eth0"
3900
3901           # combine with map dst addr to gateways
3902           dup to ip daddr map { 192.168.7.1 : "eth0", 192.168.7.2 : "eth1" }
3903
3904
3905   FWD STATEMENT
3906       The fwd statement is used to redirect a raw packet to another
3907       interface. It is only available in the netdev family ingress hook. It
3908       is similar to the dup statement except that no copy is made.
3909
3910       fwd to device
3911
3912   SET STATEMENT
3913       The set statement is used to dynamically add or update elements in a
3914       set from the packet path. The set setname must already exist in the
3915       given table and must have been created with one or both of the dynamic
3916       and the timeout flags. The dynamic flag is required if the set
3917       statement expression includes a stateful object. The timeout flag is
3918       implied if the set is created with a timeout, and is required if the
3919       set statement updates elements, rather than adding them. Furthermore,
3920       these sets should specify both a maximum set size (to prevent memory
3921       exhaustion), and their elements should have a timeout (so their number
3922       will not grow indefinitely) either from the set definition or from the
3923       statement that adds or updates them. The set statement can be used to
3924       e.g. create dynamic blacklists.
3925
3926           {add | update} @setname { expression [timeout timeout] [comment string] }
3927
3928       Example for simple blacklist.
3929
3930           # declare a set, bound to table "filter", in family "ip".
3931           # Timeout and size are mandatory because we will add elements from packet path.
3932           # Entries will timeout after one minute, after which they might be
3933           # re-added if limit condition persists.
3934           nft add set ip filter blackhole \
3935               "{ type ipv4_addr; flags dynamic; timeout 1m; size 65536; }"
3936
3937           # declare a set to store the limit per saddr.
3938           # This must be separate from blackhole since the timeout is different
3939           nft add set ip filter flood \
3940               "{ type ipv4_addr; flags dynamic; timeout 10s; size 128000; }"
3941
3942           # whitelist internal interface.
3943           nft add rule ip filter input meta iifname "internal" accept
3944
3945           # drop packets coming from blacklisted ip addresses.
3946           nft add rule ip filter input ip saddr @blackhole counter drop
3947
3948           # add source ip addresses to the blacklist if more than 10 tcp connection
3949           # requests occurred per second and ip address.
3950           nft add rule ip filter input tcp flags syn tcp dport ssh \
3951               add @flood { ip saddr limit rate over 10/second } \
3952               add @blackhole { ip saddr } drop
3953
3954           # inspect state of the sets.
3955           nft list set ip filter flood
3956           nft list set ip filter blackhole
3957
3958           # manually add two addresses to the blackhole.
3959           nft add element filter blackhole { 10.2.3.4, 10.23.1.42 }
3960
3961
3962   MAP STATEMENT
3963       The map statement is used to lookup data based on some specific input
3964       key.
3965
3966           expression map { MAP_ELEMENTS }
3967
3968           MAP_ELEMENTS := MAP_ELEMENT [, MAP_ELEMENTS]
3969           MAP_ELEMENT  := key : value
3970
3971       The key is a value returned by expression.
3972
3973       Using the map statement.
3974
3975           # select DNAT target based on TCP dport:
3976           # connections to port 80 are redirected to 192.168.1.100,
3977           # connections to port 8888 are redirected to 192.168.1.101
3978           nft add rule ip nat prerouting dnat tcp dport map { 80 : 192.168.1.100, 8888 : 192.168.1.101 }
3979
3980           # source address based SNAT:
3981           # packets from net 192.168.1.0/24 will appear as originating from 10.0.0.1,
3982           # packets from net 192.168.2.0/24 will appear as originating from 10.0.0.2
3983           nft add rule ip nat postrouting snat to ip saddr map { 192.168.1.0/24 : 10.0.0.1, 192.168.2.0/24 : 10.0.0.2 }
3984
3985
3986   VMAP STATEMENT
3987       The verdict map (vmap) statement works analogous to the map statement,
3988       but contains verdicts as values.
3989
3990           expression vmap { VMAP_ELEMENTS }
3991
3992           VMAP_ELEMENTS := VMAP_ELEMENT [, VMAP_ELEMENTS]
3993           VMAP_ELEMENT  := key : verdict
3994
3995       Using the vmap statement.
3996
3997           # jump to different chains depending on layer 4 protocol type:
3998           nft add rule ip filter input ip protocol vmap { tcp : jump tcp-chain, udp : jump udp-chain , icmp : jump icmp-chain }
3999
4000

ADDITIONAL COMMANDS

4002       These are some additional commands included in nft.
4003
4004   MONITOR
4005       The monitor command allows you to listen to Netlink events produced by
4006       the nf_tables subsystem, related to creation and deletion of objects.
4007       When they occur, nft will print to stdout the monitored events in
4008       either JSON or native nft format.
4009
4010       To filter events related to a concrete object, use one of the keywords
4011       tables, chains, sets, rules, elements, ruleset.
4012
4013       To filter events related to a concrete action, use keyword new or
4014       destroy.
4015
4016       Hit ^C to finish the monitor operation.
4017
4018       Listen to all events, report in native nft format.
4019
4020           % nft monitor
4021
4022       Listen to deleted rules, report in JSON format.
4023
4024           % nft -j monitor destroy rules
4025
4026       Listen to both new and destroyed chains, in native nft format.
4027
4028           % nft monitor chains
4029
4030       Listen to ruleset events such as table, chain, rule, set, counters and
4031       quotas, in native nft format.
4032
4033           % nft monitor ruleset
4034
4035

ERROR REPORTING

4037       When an error is detected, nft shows the line(s) containing the error,
4038       the position of the erroneous parts in the input stream and marks up
4039       the erroneous parts using carets (^). If the error results from the
4040       combination of two expressions or statements, the part imposing the
4041       constraints which are violated is marked using tildes (~).
4042
4043       For errors returned by the kernel, nft cannot detect which parts of the
4044       input caused the error and the entire command is marked.
4045
4046       Error caused by single incorrect expression.
4047
4048           <cmdline>:1:19-22: Error: Interface does not exist
4049           filter output oif eth0
4050                             ^^^^
4051
4052       Error caused by invalid combination of two expressions.
4053
4054           <cmdline>:1:28-36: Error: Right hand side of relational expression (==) must be constant
4055           filter output tcp dport == tcp dport
4056                                   ~~ ^^^^^^^^^
4057
4058       Error returned by the kernel.
4059
4060           <cmdline>:0:0-23: Error: Could not process rule: Operation not permitted
4061           filter output oif wlan0
4062           ^^^^^^^^^^^^^^^^^^^^^^^
4063
4064

EXIT STATUS

4066       On success, nft exits with a status of 0. Unspecified errors cause it
4067       to exit with a status of 1, memory allocation errors with a status of
4068       2, unable to open Netlink socket with 3.
4069

SEE ALSO

4071           libnftables(3), libnftables-json(5), iptables(8), ip6tables(8), arptables(8), ebtables(8), ip(8), tc(8)
4072
4073       There is an official wiki at: https://wiki.nftables.org
4074

AUTHORS

4076       nftables was written by Patrick McHardy and Pablo Neira Ayuso, among
4077       many other contributors from the Netfilter community.
4078
4080       Copyright © 2008-2014 Patrick McHardy <kaber@trash.net> Copyright ©
4081       2013-2018 Pablo Neira Ayuso <pablo@netfilter.org>
4082
4083       nftables is free software; you can redistribute it and/or modify it
4084       under the terms of the GNU General Public License version 2 as
4085       published by the Free Software Foundation.
4086
4087       This documentation is licensed under the terms of the Creative Commons
4088       Attribution-ShareAlike 4.0 license, CC BY-SA 4.0
4089       http://creativecommons.org/licenses/by-sa/4.0/.
4090
4091
4092
4093                                  01/15/2021                            NFT(8)
Impressum