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       -D, --define name=value
43           Define a variable. You can only combine this option with -f.
44
45       -i, --interactive
46           Read input from an interactive readline CLI. You can use quit to
47           exit, or use the EOF marker, normally this is CTRL-D.
48
49       -I, --includepath directory
50           Add the directory directory to the list of directories to be
51           searched for included files. This option may be specified multiple
52           times.
53
54       -c, --check
55           Check commands validity without actually applying the changes.
56
57       -o, --optimize
58           Optimize your ruleset. You can combine this option with -c to
59           inspect the proposed optimizations.
60
61       Ruleset list output formatting that modify the output of the list
62       ruleset command:
63
64       -a, --handle
65           Show object handles in output.
66
67       -s, --stateless
68           Omit stateful information of rules and stateful objects.
69
70       -t, --terse
71           Omit contents of sets from output.
72
73       -S, --service
74           Translate ports to service names as defined by /etc/services.
75
76       -N, --reversedns
77           Translate IP address to names via reverse DNS lookup. This may slow
78           down your listing since it generates network traffic.
79
80       -u, --guid
81           Translate numeric UID/GID to names as defined by /etc/passwd and
82           /etc/group.
83
84       -n, --numeric
85           Print fully numerical output.
86
87       -y, --numeric-priority
88           Display base chain priority numerically.
89
90       -p, --numeric-protocol
91           Display layer 4 protocol numerically.
92
93       -T, --numeric-time
94           Show time, day and hour values in numeric format.
95
96       Command output formatting:
97
98       -e, --echo
99           When inserting items into the ruleset using add, insert or replace
100           commands, print notifications just like nft monitor.
101
102       -j, --json
103           Format output in JSON. See libnftables-json(5) for a schema
104           description.
105
106       -d, --debug level
107           Enable debugging output. The debug level can be any of scanner,
108           parser, eval, netlink, mnl, proto-ctx, segtree, all. You can
109           combine more than one by separating by the , symbol, for example -d
110           eval,mnl.
111

INPUT FILE FORMATS

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

ADDRESS FAMILIES

174       Address families determine the type of packets which are processed. For
175       each address family, the kernel contains so called hooks at specific
176       stages of the packet processing paths, which invoke nftables if rules
177       for these hooks exist.
178
179
180       ip       IPv4 address family.
181
182       ip6      IPv6 address family.
183
184       inet     Internet (IPv4/IPv6)
185                address family.
186
187       arp      ARP address family,
188                handling IPv4 ARP packets.
189
190       bridge   Bridge address family,
191                handling packets which
192                traverse a bridge device.
193
194       netdev   Netdev address family,
195                handling packets on
196                ingress and egress.
197
198
199       All nftables objects exist in address family specific namespaces,
200       therefore all identifiers include an address family. If an identifier
201       is specified without an address family, the ip family is used by
202       default.
203
204   IPV4/IPV6/INET ADDRESS FAMILIES
205       The IPv4/IPv6/Inet address families handle IPv4, IPv6 or both types of
206       packets. They contain five hooks at different packet processing stages
207       in the network stack.
208
209       Table 1. IPv4/IPv6/Inet address family hooks
210       ┌────────────┬────────────────────────────┐
211Hook        Description                
212       ├────────────┼────────────────────────────┤
213       │            │                            │
214       │prerouting  │ All packets entering the   │
215       │            │ system are processed by    │
216       │            │ the prerouting hook. It is │
217       │            │ invoked before the routing │
218       │            │ process and is used for    │
219       │            │ early filtering or         │
220       │            │ changing packet attributes │
221       │            │ that affect routing.       │
222       ├────────────┼────────────────────────────┤
223       │            │                            │
224       │input       │ Packets delivered to the   │
225       │            │ local system are processed │
226       │            │ by the input hook.         │
227       ├────────────┼────────────────────────────┤
228       │            │                            │
229       │forward     │ Packets forwarded to a     │
230       │            │ different host are         │
231       │            │ processed by the forward   │
232       │            │ hook.                      │
233       ├────────────┼────────────────────────────┤
234       │            │                            │
235       │output      │ Packets sent by local      │
236       │            │ processes are processed by │
237       │            │ the output hook.           │
238       ├────────────┼────────────────────────────┤
239       │            │                            │
240       │postrouting │ All packets leaving the    │
241       │            │ system are processed by    │
242       │            │ the postrouting hook.      │
243       ├────────────┼────────────────────────────┤
244       │            │                            │
245       │ingress     │ All packets entering the   │
246       │            │ system are processed by    │
247       │            │ this hook. It is invoked   │
248       │            │ before layer 3 protocol    │
249       │            │ handlers, hence before the │
250       │            │ prerouting hook, and it    │
251       │            │ can be used for filtering  │
252       │            │ and policing. Ingress is   │
253       │            │ only available for Inet    │
254       │            │ family (since Linux kernel │
255       │            │ 5.10).                     │
256       └────────────┴────────────────────────────┘
257
258   ARP ADDRESS FAMILY
259       The ARP address family handles ARP packets received and sent by the
260       system. It is commonly used to mangle ARP packets for clustering.
261
262       Table 2. ARP address family hooks
263       ┌───────┬────────────────────────────┐
264Hook   Description                
265       ├───────┼────────────────────────────┤
266       │       │                            │
267       │input  │ Packets delivered to the   │
268       │       │ local system are processed │
269       │       │ by the input hook.         │
270       ├───────┼────────────────────────────┤
271       │       │                            │
272       │output │ Packets send by the local  │
273       │       │ system are processed by    │
274       │       │ the output hook.           │
275       └───────┴────────────────────────────┘
276
277   BRIDGE ADDRESS FAMILY
278       The bridge address family handles Ethernet packets traversing bridge
279       devices.
280
281       The list of supported hooks is identical to IPv4/IPv6/Inet address
282       families above.
283
284   NETDEV ADDRESS FAMILY
285       The Netdev address family handles packets from the device ingress and
286       egress path. This family allows you to filter packets of any ethertype
287       such as ARP, VLAN 802.1q, VLAN 802.1ad (Q-in-Q) as well as IPv4 and
288       IPv6 packets.
289
290       Table 3. Netdev address family hooks
291       ┌────────┬────────────────────────────┐
292Hook    Description                
293       ├────────┼────────────────────────────┤
294       │        │                            │
295       │ingress │ All packets entering the   │
296       │        │ system are processed by    │
297       │        │ this hook. It is invoked   │
298       │        │ after the network taps     │
299       │        │ (ie. tcpdump), right after │
300       │        │ tc ingress and before      │
301       │        │ layer 3 protocol handlers, │
302       │        │ it can be used for early   │
303       │        │ filtering and policing.    │
304       ├────────┼────────────────────────────┤
305       │        │                            │
306       │egress  │ All packets leaving the    │
307       │        │ system are processed by    │
308       │        │ this hook. It is invoked   │
309       │        │ after layer 3 protocol     │
310       │        │ handlers and before tc     
311       │        │ egress. It can be used for │
312       │        │ late filtering and         │
313       │        │ policing.                  │
314       └────────┴────────────────────────────┘
315
316       Tunneled packets (such as vxlan) are processed by netdev family hooks
317       both in decapsulated and encapsulated (tunneled) form. So a packet can
318       be filtered on the overlay network as well as on the underlying
319       network.
320
321       Note that the order of netfilter and tc is mirrored on ingress versus
322       egress. This ensures symmetry for NAT and other packet mangling.
323
324       Ingress packets which are redirected out some other interface are only
325       processed by netfilter on egress if they have passed through netfilter
326       ingress processing before. Thus, ingress packets which are redirected
327       by tc are not subjected to netfilter. But they are if they are
328       redirected by netfilter on ingress. Conceptually, tc and netfilter can
329       be thought of as layers, with netfilter layered above tc: If the packet
330       hasn’t been passed up from the tc layer to the netfilter layer, it’s
331       not subjected to netfilter on egress.
332

RULESET

334           {list | flush} ruleset [family]
335
336       The ruleset keyword is used to identify the whole set of tables,
337       chains, etc. currently in place in kernel. The following ruleset
338       commands exist:
339
340
341       list    Print the ruleset in
342               human-readable format.
343
344
345
346
347
348
349
350
351
352
353
354
355
356       flush   Clear the whole ruleset.
357               Note that, unlike
358               iptables, this will remove
359               all tables and whatever
360               they contain, effectively
361               leading to an empty
362               ruleset - no packet
363               filtering will happen
364               anymore, so the kernel
365               accepts any valid packet
366               it receives.
367
368
369       It is possible to limit list and flush to a specific address family
370       only. For a list of valid family names, see the section called “ADDRESS
371       FAMILIES” above.
372
373       By design, list ruleset command output may be used as input to nft -f.
374       Effectively, this is the nft-equivalent of iptables-save and
375       iptables-restore.
376

TABLES

378           {add | create} table [family] table [ {comment comment ;} { flags 'flags ; }]
379           {delete | list | flush} table [family] table
380           list tables [family]
381           delete table [family] handle handle
382
383       Tables are containers for chains, sets and stateful objects. They are
384       identified by their address family and their name. The address family
385       must be one of ip, ip6, inet, arp, bridge, netdev. The inet address
386       family is a dummy family which is used to create hybrid IPv4/IPv6
387       tables. The meta expression nfproto keyword can be used to test which
388       family (ipv4 or ipv6) context the packet is being processed in. When no
389       address family is specified, ip is used by default. The only difference
390       between add and create is that the former will not return an error if
391       the specified table already exists while create will return an error.
392
393       Table 4. Table flags
394       ┌────────┬────────────────────────────┐
395Flag    Description                
396       ├────────┼────────────────────────────┤
397       │        │                            │
398       │dormant │ table is not evaluated any │
399       │        │ more (base chains are      │
400       │        │ unregistered).             │
401       └────────┴────────────────────────────┘
402
403       Add, change, delete a table.
404
405           # start nft in interactive mode
406           nft --interactive
407
408           # create a new table.
409           create table inet mytable
410
411           # add a new base chain: get input packets
412           add chain inet mytable myin { type filter hook input priority filter; }
413
414           # add a single counter to the chain
415           add rule inet mytable myin counter
416
417           # disable the table temporarily -- rules are not evaluated anymore
418           add table inet mytable { flags dormant; }
419
420           # make table active again:
421           add table inet mytable
422
423
424
425       add      Add a new table for the
426                given family with the
427                given name.
428
429       delete   Delete the specified
430                table.
431
432
433
434       list     List all chains and rules
435                of the specified table.
436
437       flush    Flush all chains and rules
438                of the specified table.
439
440

CHAINS

442           {add | create} chain [family] table chain [{ type type hook hook [device device] priority priority ; [policy policy ;] [comment comment ;] }]
443           {delete | list | flush} chain ['family] table chain
444           list chains [family]
445           delete chain [family] table handle handle
446           rename chain [family] table chain newname
447
448       Chains are containers for rules. They exist in two kinds, base chains
449       and regular chains. A base chain is an entry point for packets from the
450       networking stack, a regular chain may be used as jump target and is
451       used for better rule organization.
452
453
454       add      Add a new chain in the
455                specified table. When a
456                hook and priority value
457                are specified, the chain
458                is created as a base chain
459                and hooked up to the
460                networking stack.
461
462       create   Similar to the add
463                command, but returns an
464                error if the chain already
465                exists.
466
467       delete   Delete the specified
468                chain. The chain must not
469                contain any rules or be
470                used as jump target.
471
472       rename   Rename the specified
473                chain.
474
475       list     List all rules of the
476                specified chain.
477
478       flush    Flush all rules of the
479                specified chain.
480
481
482       For base chains, type, hook and priority parameters are mandatory.
483
484       Table 5. Supported chain types
485       ┌───────┬───────────────┬────────────────┬──────────────────┐
486Type   Families      Hooks          Description      
487       ├───────┼───────────────┼────────────────┼──────────────────┤
488       │       │               │                │                  │
489       │filter │ all           │ all            │ Standard chain   │
490       │       │               │                │ type to use in   │
491       │       │               │                │ doubt.           │
492       ├───────┼───────────────┼────────────────┼──────────────────┤
493       │       │               │                │                  │
494       │nat    │ ip, ip6, inet │ prerouting,    │ Chains of this   │
495       │       │               │ input, output, │ type perform     │
496       │       │               │ postrouting    │ Native Address   │
497       │       │               │                │ Translation      │
498       │       │               │                │ based on         │
499       │       │               │                │ conntrack        │
500       │       │               │                │ entries. Only    │
501       │       │               │                │ the first packet │
502       │       │               │                │ of a connection  │
503       │       │               │                │ actually         │
504       │       │               │                │ traverses this   │
505       │       │               │                │ chain - its      │
506       │       │               │                │ rules usually    │
507       │       │               │                │ define details   │
508       │       │               │                │ of the created   │
509       │       │               │                │ conntrack entry  │
510       │       │               │                │ (NAT statements  │
511       │       │               │                │ for instance).   │
512       ├───────┼───────────────┼────────────────┼──────────────────┤
513       │       │               │                │                  │
514       │route  │ ip, ip6       │ output         │ If a packet has  │
515       │       │               │                │ traversed a      │
516       │       │               │                │ chain of this    │
517       │       │               │                │ type and is      │
518       │       │               │                │ about to be      │
519       │       │               │                │ accepted, a new  │
520       │       │               │                │ route lookup is  │
521       │       │               │                │ performed if     │
522       │       │               │                │ relevant parts   │
523       │       │               │                │ of the IP header │
524       │       │               │                │ have changed.    │
525       │       │               │                │ This allows to   │
526       │       │               │                │ e.g. implement   │
527       │       │               │                │ policy routing   │
528       │       │               │                │ selectors in     │
529       │       │               │                │ nftables.        │
530       └───────┴───────────────┴────────────────┴──────────────────┘
531
532       Apart from the special cases illustrated above (e.g. nat type not
533       supporting forward hook or route type only supporting output hook),
534       there are three further quirks worth noticing:
535
536       •   The netdev family supports merely two combinations, namely filter
537           type with ingress hook and filter type with egress hook. Base
538           chains in this family also require the device parameter to be
539           present since they exist per interface only.
540
541       •   The arp family supports only the input and output hooks, both in
542           chains of type filter.
543
544       •   The inet family also supports the ingress hook (since Linux kernel
545           5.10), to filter IPv4 and IPv6 packet at the same location as the
546           netdev ingress hook. This inet hook allows you to share sets and
547           maps between the usual prerouting, input, forward, output,
548           postrouting and this ingress hook.
549
550       The priority parameter accepts a signed integer value or a standard
551       priority name which specifies the order in which chains with the same
552       hook value are traversed. The ordering is ascending, i.e. lower
553       priority values have precedence over higher ones.
554
555       Standard priority values can be replaced with easily memorizable names.
556       Not all names make sense in every family with every hook (see the
557       compatibility matrices below) but their numerical value can still be
558       used for prioritizing chains.
559
560       These names and values are defined and made available based on what
561       priorities are used by xtables when registering their default chains.
562
563       Most of the families use the same values, but bridge uses different
564       ones from the others. See the following tables that describe the values
565       and compatibility.
566
567       Table 6. Standard priority names, family and hook compatibility matrix
568       ┌─────────┬───────┬────────────────┬─────────────┐
569Name     Value Families       Hooks       
570       ├─────────┼───────┼────────────────┼─────────────┤
571       │         │       │                │             │
572       │raw      │ -300  │ ip, ip6, inet  │ all         │
573       ├─────────┼───────┼────────────────┼─────────────┤
574       │         │       │                │             │
575       │mangle   │ -150  │ ip, ip6, inet  │ all         │
576       ├─────────┼───────┼────────────────┼─────────────┤
577       │         │       │                │             │
578       │dstnat   │ -100  │ ip, ip6, inet  │ prerouting  │
579       ├─────────┼───────┼────────────────┼─────────────┤
580       │         │       │                │             │
581       │filter   │ 0     │ ip, ip6, inet, │ all         │
582       │         │       │ arp, netdev    │             │
583       ├─────────┼───────┼────────────────┼─────────────┤
584       │         │       │                │             │
585       │security │ 50    │ ip, ip6, inet  │ all         │
586       ├─────────┼───────┼────────────────┼─────────────┤
587       │         │       │                │             │
588       │srcnat   │ 100   │ ip, ip6, inet  │ postrouting │
589       └─────────┴───────┴────────────────┴─────────────┘
590
591       Table 7. Standard priority names and hook compatibility for the bridge
592       family
593       ┌───────┬───────┬─────────────┐
594       │       │       │             │
595       │Name   │ Value │ Hooks       │
596       ├───────┼───────┼─────────────┤
597       │       │       │             │
598       │dstnat │ -300  │ prerouting  │
599       ├───────┼───────┼─────────────┤
600       │       │       │             │
601       │filter │ -200  │ all         │
602       ├───────┼───────┼─────────────┤
603       │       │       │             │
604       │out    │ 100   │ output      │
605       ├───────┼───────┼─────────────┤
606       │       │       │             │
607       │srcnat │ 300   │ postrouting │
608       └───────┴───────┴─────────────┘
609
610       Basic arithmetic expressions (addition and subtraction) can also be
611       achieved with these standard names to ease relative prioritizing, e.g.
612       mangle - 5 stands for -155. Values will also be printed like this until
613       the value is not further than 10 from the standard value.
614
615       Base chains also allow to set the chain’s policy, i.e. what happens to
616       packets not explicitly accepted or refused in contained rules.
617       Supported policy values are accept (which is the default) or drop.
618

RULES

620           {add | insert} rule [family] table chain [handle handle | index index] statement ... [comment comment]
621           replace rule [family] table chain handle handle statement ... [comment comment]
622           delete rule [family] table chain handle handle
623
624       Rules are added to chains in the given table. If the family is not
625       specified, the ip family is used. Rules are constructed from two kinds
626       of components according to a set of grammatical rules: expressions and
627       statements.
628
629       The add and insert commands support an optional location specifier,
630       which is either a handle or the index (starting at zero) of an existing
631       rule. Internally, rule locations are always identified by handle and
632       the translation from index happens in userspace. This has two potential
633       implications in case a concurrent ruleset change happens after the
634       translation was done: The effective rule index might change if a rule
635       was inserted or deleted before the referred one. If the referred rule
636       was deleted, the command is rejected by the kernel just as if an
637       invalid handle was given.
638
639       A comment is a single word or a double-quoted (") multi-word string
640       which can be used to make notes regarding the actual rule. Note: If you
641       use bash for adding rules, you have to escape the quotation marks, e.g.
642       \"enable ssh for servers\".
643
644
645       add       Add a new rule described
646                 by the list of statements.
647                 The rule is appended to
648                 the given chain unless a
649                 location is specified, in
650                 which case the rule is
651                 inserted after the
652                 specified rule.
653
654       insert    Same as add except the
655                 rule is inserted at the
656                 beginning of the chain or
657                 before the specified rule.
658
659       replace   Similar to add, but the
660                 rule replaces the
661                 specified rule.
662
663       delete    Delete the specified rule.
664
665
666       add a rule to ip table output chain.
667
668           nft add rule filter output ip daddr 192.168.0.0/24 accept # 'ip filter' is assumed
669           # same command, slightly more verbose
670           nft add rule ip filter output ip daddr 192.168.0.0/24 accept
671
672       delete rule from inet table.
673
674           # nft -a list ruleset
675           table inet filter {
676                   chain input {
677                           type filter hook input priority filter; policy accept;
678                           ct state established,related accept # handle 4
679                           ip saddr 10.1.1.1 tcp dport ssh accept # handle 5
680                     ...
681           # delete the rule with handle 5
682           nft delete rule inet filter input handle 5
683
684

SETS

686       nftables offers two kinds of set concepts. Anonymous sets are sets that
687       have no specific name. The set members are enclosed in curly braces,
688       with commas to separate elements when creating the rule the set is used
689       in. Once that rule is removed, the set is removed as well. They cannot
690       be updated, i.e. once an anonymous set is declared it cannot be changed
691       anymore except by removing/altering the rule that uses the anonymous
692       set.
693
694       Using anonymous sets to accept particular subnets and ports.
695
696           nft add rule filter input ip saddr { 10.0.0.0/8, 192.168.0.0/16 } tcp dport { 22, 443 } accept
697
698       Named sets are sets that need to be defined first before they can be
699       referenced in rules. Unlike anonymous sets, elements can be added to or
700       removed from a named set at any time. Sets are referenced from rules
701       using an @ prefixed to the sets name.
702
703       Using named sets to accept addresses and ports.
704
705           nft add rule filter input ip saddr @allowed_hosts tcp dport @allowed_ports accept
706
707       The sets allowed_hosts and allowed_ports need to be created first. The
708       next section describes nft set syntax in more detail.
709
710           add set [family] table set { type type | typeof expression ; [flags flags ;] [timeout timeout ;] [gc-interval gc-interval ;] [elements = { element[, ...] } ;] [size size ;] [comment comment ;] [policy 'policy ;] [auto-merge ;] }
711           {delete | list | flush} set [family] table set
712           list sets [family]
713           delete set [family] table handle handle
714           {add | delete} element [family] table set { element[, ...] }
715
716       Sets are element containers of a user-defined data type, they are
717       uniquely identified by a user-defined name and attached to tables.
718       Their behaviour can be tuned with the flags that can be specified at
719       set creation time.
720
721
722       add      Add a new set in the
723                specified table. See the
724                Set specification table
725                below for more information
726                about how to specify
727                properties of a set.
728
729
730
731       delete   Delete the specified set.
732
733       list     Display the elements in
734                the specified set.
735
736       flush    Remove all elements from
737                the specified set.
738
739
740       Table 8. Set specifications
741       ┌────────────┬──────────────────────┬─────────────────────┐
742Keyword     Description          Type                
743       ├────────────┼──────────────────────┼─────────────────────┤
744       │            │                      │                     │
745       │type        │ data type of set     │ string: ipv4_addr,  │
746       │            │ elements             │ ipv6_addr,          │
747       │            │                      │ ether_addr,         │
748       │            │                      │ inet_proto,         │
749       │            │                      │ inet_service, mark  │
750       ├────────────┼──────────────────────┼─────────────────────┤
751       │            │                      │                     │
752       │typeof      │ data type of set     │ expression to       │
753       │            │ element              │ derive the data     │
754       │            │                      │ type from           │
755       ├────────────┼──────────────────────┼─────────────────────┤
756       │            │                      │                     │
757       │flags       │ set flags            │ string: constant,   │
758       │            │                      │ dynamic, interval,  │
759       │            │                      │ timeout             │
760       ├────────────┼──────────────────────┼─────────────────────┤
761       │            │                      │                     │
762       │timeout     │ time an element      │ string, decimal     │
763       │            │ stays in the set,    │ followed by unit.   │
764       │            │ mandatory if set is  │ Units are: d, h, m, │
765       │            │ added to from the    │ s                   │
766       │            │ packet path          │                     │
767       │            │ (ruleset)            │                     │
768       ├────────────┼──────────────────────┼─────────────────────┤
769       │            │                      │                     │
770       │gc-interval │ garbage collection   │ string, decimal     │
771       │            │ interval, only       │ followed by unit.   │
772       │            │ available when       │ Units are: d, h, m, │
773       │            │ timeout or flag      │ s                   │
774       │            │ timeout are active   │                     │
775       ├────────────┼──────────────────────┼─────────────────────┤
776       │            │                      │                     │
777       │elements    │ elements contained   │ set data type       │
778       │            │ by the set           │                     │
779       ├────────────┼──────────────────────┼─────────────────────┤
780       │            │                      │                     │
781       │size        │ maximum number of    │ unsigned integer    │
782       │            │ elements in the      │ (64 bit)            │
783       │            │ set, mandatory if    │                     │
784       │            │ set is added to      │                     │
785       │            │ from the packet      │                     │
786       │            │ path (ruleset)       │                     │
787       ├────────────┼──────────────────────┼─────────────────────┤
788       │            │                      │                     │
789       │policy      │ set policy           │ string: performance │
790       │            │                      │ [default], memory   │
791       ├────────────┼──────────────────────┼─────────────────────┤
792       │            │                      │                     │
793       │auto-merge  │ automatic merge of   │                     │
794       │            │ adjacent/overlapping │                     │
795       │            │ set elements (only   │                     │
796       │            │ for interval sets)   │                     │
797       └────────────┴──────────────────────┴─────────────────────┘
798

MAPS

800           add map [family] table map { type type | typeof expression [flags flags ;] [elements = { element[, ...] } ;] [size size ;] [comment comment ;] [policy 'policy ;] }
801           {delete | list | flush} map [family] table map
802           list maps [family]
803
804       Maps store data based on some specific key used as input. They are
805       uniquely identified by a user-defined name and attached to tables.
806
807
808       add              Add a new map in the
809                        specified table.
810
811       delete           Delete the specified map.
812
813       list             Display the elements in
814                        the specified map.
815
816       flush            Remove all elements from
817                        the specified map.
818
819       add element      Comma-separated list of
820                        elements to add into the
821                        specified map.
822
823       delete element   Comma-separated list of
824                        element keys to delete
825                        from the specified map.
826
827
828       Table 9. Map specifications
829       ┌─────────┬─────────────────────┬─────────────────────┐
830Keyword  Description         Type                
831       ├─────────┼─────────────────────┼─────────────────────┤
832       │         │                     │                     │
833       │type     │ data type of map    │ string: ipv4_addr,  │
834       │         │ elements            │ ipv6_addr,          │
835       │         │                     │ ether_addr,         │
836       │         │                     │ inet_proto,         │
837       │         │                     │ inet_service, mark, │
838       │         │                     │ counter, quota.     │
839       │         │                     │ Counter and quota   │
840       │         │                     │ can’t be used as    │
841       │         │                     │ keys                │
842       ├─────────┼─────────────────────┼─────────────────────┤
843       │         │                     │                     │
844       │typeof   │ data type of set    │ expression to       │
845       │         │ element             │ derive the data     │
846       │         │                     │ type from           │
847       ├─────────┼─────────────────────┼─────────────────────┤
848       │         │                     │                     │
849       │flags    │ map flags           │ string: constant,   │
850       │         │                     │ interval            │
851       ├─────────┼─────────────────────┼─────────────────────┤
852       │         │                     │                     │
853       │elements │ elements contained  │ map data type       │
854       │         │ by the map          │                     │
855       ├─────────┼─────────────────────┼─────────────────────┤
856       │         │                     │                     │
857       │size     │ maximum number of   │ unsigned integer    │
858       │         │ elements in the map │ (64 bit)            │
859       ├─────────┼─────────────────────┼─────────────────────┤
860       │         │                     │                     │
861       │policy   │ map policy          │ string: performance │
862       │         │                     │ [default], memory   │
863       └─────────┴─────────────────────┴─────────────────────┘
864

ELEMENTS

866           {add | create | delete | get } element [family] table set { ELEMENT[, ...] }
867
868           ELEMENT := key_expression OPTIONS [: value_expression]
869           OPTIONS := [timeout TIMESPEC] [expires TIMESPEC] [comment string]
870           TIMESPEC := [numd][numh][numm][num[s]]
871
872       Element-related commands allow to change contents of named sets and
873       maps. key_expression is typically a value matching the set type.
874       value_expression is not allowed in sets but mandatory when adding to
875       maps, where it matches the data part in its type definition. When
876       deleting from maps, it may be specified but is optional as
877       key_expression uniquely identifies the element.
878
879       create command is similar to add with the exception that none of the
880       listed elements may already exist.
881
882       get command is useful to check if an element is contained in a set
883       which may be non-trivial in very large and/or interval sets. In the
884       latter case, the containing interval is returned instead of just the
885       element itself.
886
887       Table 10. Element options
888       ┌────────┬───────────────────────────┐
889Option  Description               
890       ├────────┼───────────────────────────┤
891       │        │                           │
892       │timeout │ timeout value for         │
893       │        │ sets/maps with flag       │
894       │        │ timeout                   
895       ├────────┼───────────────────────────┤
896       │        │                           │
897       │expires │ the time until given      │
898       │        │ element expires, useful   │
899       │        │ for ruleset replication   │
900       │        │ only                      │
901       ├────────┼───────────────────────────┤
902       │        │                           │
903       │comment │ per element comment field │
904       └────────┴───────────────────────────┘
905

FLOWTABLES

907           {add | create} flowtable [family] table flowtable { hook hook priority priority ; devices = { device[, ...] } ; }
908           list flowtables [family]
909           {delete | list} flowtable [family] table flowtable
910           delete flowtable [family] table handle handle
911
912       Flowtables allow you to accelerate packet forwarding in software.
913       Flowtables entries are represented through a tuple that is composed of
914       the input interface, source and destination address, source and
915       destination port; and layer 3/4 protocols. Each entry also caches the
916       destination interface and the gateway address - to update the
917       destination link-layer address - to forward packets. The ttl and
918       hoplimit fields are also decremented. Hence, flowtables provides an
919       alternative path that allow packets to bypass the classic forwarding
920       path. Flowtables reside in the ingress hook that is located before the
921       prerouting hook. You can select which flows you want to offload through
922       the flow expression from the forward chain. Flowtables are identified
923       by their address family and their name. The address family must be one
924       of ip, ip6, or inet. The inet address family is a dummy family which is
925       used to create hybrid IPv4/IPv6 tables. When no address family is
926       specified, ip is used by default.
927
928       The priority can be a signed integer or filter which stands for 0.
929       Addition and subtraction can be used to set relative priority, e.g.
930       filter + 5 equals to 5.
931
932
933       add      Add a new flowtable for
934                the given family with the
935                given name.
936
937       delete   Delete the specified
938                flowtable.
939
940       list     List all flowtables.
941
942

LISTING

944           list { secmarks | synproxys | flow tables | meters | hooks } [family]
945           list { secmarks | synproxys | flow tables | meters | hooks } table [family] table
946           list ct { timeout | expectation | helper | helpers } table [family] table
947
948       Inspect configured objects. list hooks shows the full hook pipeline,
949       including those registered by kernel modules, such as nf_conntrack.
950

STATEFUL OBJECTS

952           {add | delete | list | reset} type [family] table object
953           delete type [family] table handle handle
954           list counters [family]
955           list quotas [family]
956           list limits [family]
957
958       Stateful objects are attached to tables and are identified by a unique
959       name. They group stateful information from rules, to reference them in
960       rules the keywords "type name" are used e.g. "counter name".
961
962
963       add      Add a new stateful object
964                in the specified table.
965
966       delete   Delete the specified
967                object.
968
969       list     Display stateful
970                information the object
971                holds.
972
973       reset    List-and-reset stateful
974                object.
975
976
977   CT HELPER
978           add ct helper [family] table name { type type protocol protocol ; [l3proto family ;] }
979           delete ct helper [family] table name
980           list ct helpers
981
982       Ct helper is used to define connection tracking helpers that can then
983       be used in combination with the ct helper set statement. type and
984       protocol are mandatory, l3proto is derived from the table family by
985       default, i.e. in the inet table the kernel will try to load both the
986       ipv4 and ipv6 helper backends, if they are supported by the kernel.
987
988       Table 11. conntrack helper specifications
989       ┌─────────┬─────────────────────┬─────────────────────┐
990Keyword  Description         Type                
991       ├─────────┼─────────────────────┼─────────────────────┤
992       │         │                     │                     │
993       │type     │ name of helper type │ quoted string (e.g. │
994       │         │                     │ "ftp")              │
995       ├─────────┼─────────────────────┼─────────────────────┤
996       │         │                     │                     │
997       │protocol │ layer 4 protocol of │ string (e.g. ip)    │
998       │         │ the helper          │                     │
999       ├─────────┼─────────────────────┼─────────────────────┤
1000       │         │                     │                     │
1001       │l3proto  │ layer 3 protocol of │ address family      │
1002       │         │ the helper          │ (e.g. ip)           │
1003       ├─────────┼─────────────────────┼─────────────────────┤
1004       │         │                     │                     │
1005       │comment  │ per ct helper       │ string              │
1006       │         │ comment field       │                     │
1007       └─────────┴─────────────────────┴─────────────────────┘
1008
1009       defining and assigning ftp helper.
1010
1011           Unlike iptables, helper assignment needs to be performed after the conntrack
1012           lookup has completed, for example with the default 0 hook priority.
1013
1014           table inet myhelpers {
1015             ct helper ftp-standard {
1016                type "ftp" protocol tcp
1017             }
1018             chain prerouting {
1019                 type filter hook prerouting priority filter;
1020                 tcp dport 21 ct helper set "ftp-standard"
1021             }
1022           }
1023
1024
1025   CT TIMEOUT
1026           add ct timeout  [family] table name { protocol protocol ; policy = { state: value [, ...] } ; [l3proto family ;] }
1027           delete ct timeout [family] table name
1028           list ct timeouts
1029
1030       Ct timeout is used to update connection tracking timeout values.Timeout
1031       policies are assigned with the ct timeout set statement. protocol and
1032       policy are mandatory, l3proto is derived from the table family by
1033       default.
1034
1035       Table 12. conntrack timeout specifications
1036       ┌─────────┬─────────────────────┬──────────────────┐
1037Keyword  Description         Type             
1038       ├─────────┼─────────────────────┼──────────────────┤
1039       │         │                     │                  │
1040       │protocol │ layer 4 protocol of │ string (e.g. ip) │
1041       │         │ the timeout object  │                  │
1042       ├─────────┼─────────────────────┼──────────────────┤
1043       │         │                     │                  │
1044       │state    │ connection state    │ string (e.g.     │
1045       │         │ name                │ "established")   │
1046       ├─────────┼─────────────────────┼──────────────────┤
1047       │         │                     │                  │
1048       │value    │ timeout value for   │ unsigned integer │
1049       │         │ connection state    │                  │
1050       ├─────────┼─────────────────────┼──────────────────┤
1051       │         │                     │                  │
1052       │l3proto  │ layer 3 protocol of │ address family   │
1053       │         │ the timeout object  │ (e.g. ip)        │
1054       ├─────────┼─────────────────────┼──────────────────┤
1055       │         │                     │                  │
1056       │comment  │ per ct timeout      │ string           │
1057       │         │ comment field       │                  │
1058       └─────────┴─────────────────────┴──────────────────┘
1059
1060       tcp connection state names that can have a specific timeout value are:
1061
1062       close, close_wait, established, fin_wait, last_ack, retrans, syn_recv,
1063       syn_sent, time_wait and unack.
1064
1065       You can use sysctl -a |grep net.netfilter.nf_conntrack_tcp_timeout_ to
1066       view and change the system-wide defaults. ct timeout allows for
1067       flow-specific settings, without changing the global timeouts.
1068
1069       For example, tcp port 53 could have much lower settings than other
1070       traffic.
1071
1072       udp state names that can have a specific timeout value are replied and
1073       unreplied.
1074
1075       defining and assigning ct timeout policy.
1076
1077           table ip filter {
1078                   ct timeout customtimeout {
1079                           protocol tcp;
1080                           l3proto ip
1081                           policy = { established: 120, close: 20 }
1082                   }
1083
1084                   chain output {
1085                           type filter hook output priority filter; policy accept;
1086                           ct timeout set "customtimeout"
1087                   }
1088           }
1089
1090       testing the updated timeout policy.
1091
1092           % conntrack -E
1093
1094           It should display:
1095
1096           [UPDATE] tcp      6 120 ESTABLISHED src=172.16.19.128 dst=172.16.19.1
1097           sport=22 dport=41360 [UNREPLIED] src=172.16.19.1 dst=172.16.19.128
1098           sport=41360 dport=22
1099
1100
1101   CT EXPECTATION
1102           add ct expectation  [family] table name { protocol protocol ; dport dport ; timeout timeout ; size size ; [*l3proto family ;] }
1103           delete ct expectation  [family] table name
1104           list ct expectations
1105
1106       Ct expectation is used to create connection expectations. Expectations
1107       are assigned with the ct expectation set statement. protocol, dport,
1108       timeout and size are mandatory, l3proto is derived from the table
1109       family by default.
1110
1111       Table 13. conntrack expectation specifications
1112       ┌─────────┬─────────────────────┬──────────────────┐
1113Keyword  Description         Type             
1114       ├─────────┼─────────────────────┼──────────────────┤
1115       │         │                     │                  │
1116       │protocol │ layer 4 protocol of │ string (e.g. ip) │
1117       │         │ the expectation     │                  │
1118       │         │ object              │                  │
1119       ├─────────┼─────────────────────┼──────────────────┤
1120       │         │                     │                  │
1121       │dport    │ destination port of │ unsigned integer │
1122       │         │ expected connection │                  │
1123       ├─────────┼─────────────────────┼──────────────────┤
1124       │         │                     │                  │
1125       │timeout  │ timeout value for   │ unsigned integer │
1126       │         │ expectation         │                  │
1127       ├─────────┼─────────────────────┼──────────────────┤
1128       │         │                     │                  │
1129       │size     │ size value for      │ unsigned integer │
1130       │         │ expectation         │                  │
1131       ├─────────┼─────────────────────┼──────────────────┤
1132       │         │                     │                  │
1133       │l3proto  │ layer 3 protocol of │ address family   │
1134       │         │ the expectation     │ (e.g. ip)        │
1135       │         │ object              │                  │
1136       ├─────────┼─────────────────────┼──────────────────┤
1137       │         │                     │                  │
1138       │comment  │ per ct expectation  │ string           │
1139       │         │ comment field       │                  │
1140       └─────────┴─────────────────────┴──────────────────┘
1141
1142       defining and assigning ct expectation policy.
1143
1144           table ip filter {
1145                   ct expectation expect {
1146                           protocol udp
1147                           dport 9876
1148                           timeout 2m
1149                           size 8
1150                           l3proto ip
1151                   }
1152
1153                   chain input {
1154                           type filter hook input priority filter; policy accept;
1155                           ct expectation set "expect"
1156                   }
1157           }
1158
1159
1160   COUNTER
1161           add counter [family] table name [{ [ packets packets bytes bytes ; ] [ comment comment ; }]
1162           delete counter [family] table name
1163           list counters
1164
1165       Table 14. Counter specifications
1166       ┌────────┬─────────────────────┬──────────────────┐
1167Keyword Description         Type             
1168       ├────────┼─────────────────────┼──────────────────┤
1169       │        │                     │                  │
1170       │packets │ initial count of    │ unsigned integer │
1171       │        │ packets             │ (64 bit)         │
1172       ├────────┼─────────────────────┼──────────────────┤
1173       │        │                     │                  │
1174       │bytes   │ initial count of    │ unsigned integer │
1175       │        │ bytes               │ (64 bit)         │
1176       ├────────┼─────────────────────┼──────────────────┤
1177       │        │                     │                  │
1178       │comment │ per counter comment │ string           │
1179       │        │ field               │                  │
1180       └────────┴─────────────────────┴──────────────────┘
1181
1182       Using named counters.
1183
1184           nft add counter filter http
1185           nft add rule filter input tcp dport 80 counter name \"http\"
1186
1187       Using named counters with maps.
1188
1189           nft add counter filter http
1190           nft add counter filter https
1191           nft add rule filter input counter name tcp dport map { 80 : \"http\", 443 : \"https\" }
1192
1193
1194   QUOTA
1195           add quota [family] table name { [over|until] bytes BYTE_UNIT [ used bytes BYTE_UNIT ] ; [ comment comment ; ] }
1196           BYTE_UNIT := bytes | kbytes | mbytes
1197           delete quota [family] table name
1198           list quotas
1199
1200       Table 15. Quota specifications
1201       ┌────────┬───────────────────┬────────────────────┐
1202Keyword Description       Type               
1203       ├────────┼───────────────────┼────────────────────┤
1204       │        │                   │                    │
1205       │quota   │ quota limit, used │ Two arguments,     │
1206       │        │ as the quota name │ unsigned integer   │
1207       │        │                   │ (64 bit) and       │
1208       │        │                   │ string: bytes,     │
1209       │        │                   │ kbytes, mbytes.    │
1210       │        │                   │ "over" and "until" │
1211       │        │                   │ go before these    │
1212       │        │                   │ arguments          │
1213       ├────────┼───────────────────┼────────────────────┤
1214       │        │                   │                    │
1215       │used    │ initial value of  │ Two arguments,     │
1216       │        │ used quota        │ unsigned integer   │
1217       │        │                   │ (64 bit) and       │
1218       │        │                   │ string: bytes,     │
1219       │        │                   │ kbytes, mbytes     │
1220       ├────────┼───────────────────┼────────────────────┤
1221       │        │                   │                    │
1222       │comment │ per quota comment │ string             │
1223       │        │ field             │                    │
1224       └────────┴───────────────────┴────────────────────┘
1225
1226       Using named quotas.
1227
1228           nft add quota filter user123 { over 20 mbytes }
1229           nft add rule filter input ip saddr 192.168.10.123 quota name \"user123\"
1230
1231       Using named quotas with maps.
1232
1233           nft add quota filter user123 { over 20 mbytes }
1234           nft add quota filter user124 { over 20 mbytes }
1235           nft add rule filter input quota name ip saddr map { 192.168.10.123 : \"user123\", 192.168.10.124 : \"user124\" }
1236
1237

EXPRESSIONS

1239       Expressions represent values, either constants like network addresses,
1240       port numbers, etc., or data gathered from the packet during ruleset
1241       evaluation. Expressions can be combined using binary, logical,
1242       relational and other types of expressions to form complex or relational
1243       (match) expressions. They are also used as arguments to certain types
1244       of operations, like NAT, packet marking etc.
1245
1246       Each expression has a data type, which determines the size, parsing and
1247       representation of symbolic values and type compatibility with other
1248       expressions.
1249
1250   DESCRIBE COMMAND
1251           describe expression | data type
1252
1253       The describe command shows information about the type of an expression
1254       and its data type. A data type may also be given, in which nft will
1255       display more information about the type.
1256
1257       The describe command.
1258
1259           $ nft describe tcp flags
1260           payload expression, datatype tcp_flag (TCP flag) (basetype bitmask, integer), 8 bits
1261
1262           predefined symbolic constants:
1263           fin                           0x01
1264           syn                           0x02
1265           rst                           0x04
1266           psh                           0x08
1267           ack                           0x10
1268           urg                           0x20
1269           ecn                           0x40
1270           cwr                           0x80
1271
1272

DATA TYPES

1274       Data types determine the size, parsing and representation of symbolic
1275       values and type compatibility of expressions. A number of global data
1276       types exist, in addition some expression types define further data
1277       types specific to the expression type. Most data types have a fixed
1278       size, some however may have a dynamic size, f.i. the string type. Some
1279       types also have predefined symbolic constants. Those can be listed
1280       using the nft describe command:
1281
1282           $ nft describe ct_state
1283           datatype ct_state (conntrack state) (basetype bitmask, integer), 32 bits
1284
1285           pre-defined symbolic constants (in hexadecimal):
1286           invalid                         0x00000001
1287           new ...
1288
1289       Types may be derived from lower order types, f.i. the IPv4 address type
1290       is derived from the integer type, meaning an IPv4 address can also be
1291       specified as an integer value.
1292
1293       In certain contexts (set and map definitions), it is necessary to
1294       explicitly specify a data type. Each type has a name which is used for
1295       this.
1296
1297   INTEGER TYPE
1298       ┌────────┬─────────┬──────────┬───────────┐
1299Name    Keyword Size     Base type 
1300       ├────────┼─────────┼──────────┼───────────┤
1301       │        │         │          │           │
1302       │Integer │ integer │ variable │ -         │
1303       └────────┴─────────┴──────────┴───────────┘
1304
1305       The integer type is used for numeric values. It may be specified as a
1306       decimal, hexadecimal or octal number. The integer type does not have a
1307       fixed size, its size is determined by the expression for which it is
1308       used.
1309
1310   BITMASK TYPE
1311       ┌────────┬─────────┬──────────┬───────────┐
1312Name    Keyword Size     Base type 
1313       ├────────┼─────────┼──────────┼───────────┤
1314       │        │         │          │           │
1315       │Bitmask │ bitmask │ variable │ integer   │
1316       └────────┴─────────┴──────────┴───────────┘
1317
1318       The bitmask type (bitmask) is used for bitmasks.
1319
1320   STRING TYPE
1321       ┌───────┬─────────┬──────────┬───────────┐
1322Name   Keyword Size     Base type 
1323       ├───────┼─────────┼──────────┼───────────┤
1324       │       │         │          │           │
1325       │String │ string  │ variable │ -         │
1326       └───────┴─────────┴──────────┴───────────┘
1327
1328       The string type is used for character strings. A string begins with an
1329       alphabetic character (a-zA-Z) followed by zero or more alphanumeric
1330       characters or the characters /, -, _ and .. In addition, anything
1331       enclosed in double quotes (") is recognized as a string.
1332
1333       String specification.
1334
1335           # Interface name
1336           filter input iifname eth0
1337
1338           # Weird interface name
1339           filter input iifname "(eth0)"
1340
1341
1342   LINK LAYER ADDRESS TYPE
1343       ┌───────────┬─────────┬──────────┬───────────┐
1344Name       Keyword Size     Base type 
1345       ├───────────┼─────────┼──────────┼───────────┤
1346       │           │         │          │           │
1347       │Link layer │ lladdr  │ variable │ integer   │
1348       │address    │         │          │           │
1349       └───────────┴─────────┴──────────┴───────────┘
1350
1351       The link layer address type is used for link layer addresses. Link
1352       layer addresses are specified as a variable amount of groups of two
1353       hexadecimal digits separated using colons (:).
1354
1355       Link layer address specification.
1356
1357           # Ethernet destination MAC address
1358           filter input ether daddr 20:c9:d0:43:12:d9
1359
1360
1361   IPV4 ADDRESS TYPE
1362       ┌─────────────┬───────────┬────────┬───────────┐
1363Name         Keyword   Size   Base type 
1364       ├─────────────┼───────────┼────────┼───────────┤
1365       │             │           │        │           │
1366       │IPV4 address │ ipv4_addr │ 32 bit │ integer   │
1367       └─────────────┴───────────┴────────┴───────────┘
1368
1369       The IPv4 address type is used for IPv4 addresses. Addresses are
1370       specified in either dotted decimal, dotted hexadecimal, dotted octal,
1371       decimal, hexadecimal, octal notation or as a host name. A host name
1372       will be resolved using the standard system resolver.
1373
1374       IPv4 address specification.
1375
1376           # dotted decimal notation
1377           filter output ip daddr 127.0.0.1
1378
1379           # host name
1380           filter output ip daddr localhost
1381
1382
1383   IPV6 ADDRESS TYPE
1384       ┌─────────────┬───────────┬─────────┬───────────┐
1385Name         Keyword   Size    Base type 
1386       ├─────────────┼───────────┼─────────┼───────────┤
1387       │             │           │         │           │
1388       │IPv6 address │ ipv6_addr │ 128 bit │ integer   │
1389       └─────────────┴───────────┴─────────┴───────────┘
1390
1391       The IPv6 address type is used for IPv6 addresses. Addresses are
1392       specified as a host name or as hexadecimal halfwords separated by
1393       colons. Addresses might be enclosed in square brackets ("[]") to
1394       differentiate them from port numbers.
1395
1396       IPv6 address specification.
1397
1398           # abbreviated loopback address
1399           filter output ip6 daddr ::1
1400
1401       IPv6 address specification with bracket notation.
1402
1403           # without [] the port number (22) would be parsed as part of the
1404           # ipv6 address
1405           ip6 nat prerouting tcp dport 2222 dnat to [1ce::d0]:22
1406
1407
1408   BOOLEAN TYPE
1409       ┌────────┬─────────┬───────┬───────────┐
1410Name    Keyword Size  Base type 
1411       ├────────┼─────────┼───────┼───────────┤
1412       │        │         │       │           │
1413       │Boolean │ boolean │ 1 bit │ integer   │
1414       └────────┴─────────┴───────┴───────────┘
1415
1416       The boolean type is a syntactical helper type in userspace. Its use is
1417       in the right-hand side of a (typically implicit) relational expression
1418       to change the expression on the left-hand side into a boolean check
1419       (usually for existence).
1420
1421       Table 16. The following keywords will automatically resolve into a
1422       boolean type with given value
1423       ┌────────┬───────┐
1424Keyword Value 
1425       ├────────┼───────┤
1426       │        │       │
1427       │exists  │ 1     │
1428       ├────────┼───────┤
1429       │        │       │
1430       │missing │ 0     │
1431       └────────┴───────┘
1432
1433       Table 17. expressions support a boolean comparison
1434       ┌───────────┬─────────────────────────┐
1435Expression Behaviour               
1436       ├───────────┼─────────────────────────┤
1437       │           │                         │
1438       │fib        │ Check route existence.  │
1439       ├───────────┼─────────────────────────┤
1440       │           │                         │
1441       │exthdr     │ Check IPv6 extension    │
1442       │           │ header existence.       │
1443       ├───────────┼─────────────────────────┤
1444       │           │                         │
1445       │tcp option │ Check TCP option header │
1446       │           │ existence.              │
1447       └───────────┴─────────────────────────┘
1448
1449       Boolean specification.
1450
1451           # match if route exists
1452           filter input fib daddr . iif oif exists
1453
1454           # match only non-fragmented packets in IPv6 traffic
1455           filter input exthdr frag missing
1456
1457           # match if TCP timestamp option is present
1458           filter input tcp option timestamp exists
1459
1460
1461   ICMP TYPE TYPE
1462       ┌──────────┬───────────┬───────┬───────────┐
1463Name      Keyword   Size  Base type 
1464       ├──────────┼───────────┼───────┼───────────┤
1465       │          │           │       │           │
1466       │ICMP Type │ icmp_type │ 8 bit │ integer   │
1467       └──────────┴───────────┴───────┴───────────┘
1468
1469       The ICMP Type type is used to conveniently specify the ICMP header’s
1470       type field.
1471
1472       Table 18. Keywords may be used when specifying the ICMP type
1473       ┌────────────────────────┬───────┐
1474Keyword                 Value 
1475       ├────────────────────────┼───────┤
1476       │                        │       │
1477       │echo-reply              │ 0     │
1478       ├────────────────────────┼───────┤
1479       │                        │       │
1480       │destination-unreachable │ 3     │
1481       ├────────────────────────┼───────┤
1482       │                        │       │
1483       │source-quench           │ 4     │
1484       ├────────────────────────┼───────┤
1485       │                        │       │
1486       │redirect                │ 5     │
1487       ├────────────────────────┼───────┤
1488       │                        │       │
1489       │echo-request            │ 8     │
1490       ├────────────────────────┼───────┤
1491       │                        │       │
1492       │router-advertisement    │ 9     │
1493       ├────────────────────────┼───────┤
1494       │                        │       │
1495       │router-solicitation     │ 10    │
1496       ├────────────────────────┼───────┤
1497       │                        │       │
1498       │time-exceeded           │ 11    │
1499       ├────────────────────────┼───────┤
1500       │                        │       │
1501       │parameter-problem       │ 12    │
1502       ├────────────────────────┼───────┤
1503       │                        │       │
1504       │timestamp-request       │ 13    │
1505       ├────────────────────────┼───────┤
1506       │                        │       │
1507       │timestamp-reply         │ 14    │
1508       ├────────────────────────┼───────┤
1509       │                        │       │
1510       │info-request            │ 15    │
1511       ├────────────────────────┼───────┤
1512       │                        │       │
1513       │info-reply              │ 16    │
1514       ├────────────────────────┼───────┤
1515       │                        │       │
1516       │address-mask-request    │ 17    │
1517       ├────────────────────────┼───────┤
1518       │                        │       │
1519       │address-mask-reply      │ 18    │
1520       └────────────────────────┴───────┘
1521
1522       ICMP Type specification.
1523
1524           # match ping packets
1525           filter output icmp type { echo-request, echo-reply }
1526
1527
1528   ICMP CODE TYPE
1529       ┌──────────┬───────────┬───────┬───────────┐
1530Name      Keyword   Size  Base type 
1531       ├──────────┼───────────┼───────┼───────────┤
1532       │          │           │       │           │
1533       │ICMP Code │ icmp_code │ 8 bit │ integer   │
1534       └──────────┴───────────┴───────┴───────────┘
1535
1536       The ICMP Code type is used to conveniently specify the ICMP header’s
1537       code field.
1538
1539       Table 19. Keywords may be used when specifying the ICMP code
1540       ┌─────────────────┬───────┐
1541Keyword          Value 
1542       ├─────────────────┼───────┤
1543       │                 │       │
1544       │net-unreachable  │ 0     │
1545       ├─────────────────┼───────┤
1546       │                 │       │
1547       │host-unreachable │ 1     │
1548       ├─────────────────┼───────┤
1549       │                 │       │
1550       │prot-unreachable │ 2     │
1551       ├─────────────────┼───────┤
1552       │                 │       │
1553       │port-unreachable │ 3     │
1554       ├─────────────────┼───────┤
1555       │                 │       │
1556       │frag-needed      │ 4     │
1557       ├─────────────────┼───────┤
1558       │                 │       │
1559       │net-prohibited   │ 9     │
1560       ├─────────────────┼───────┤
1561       │                 │       │
1562       │host-prohibited  │ 10    │
1563       ├─────────────────┼───────┤
1564       │                 │       │
1565       │admin-prohibited │ 13    │
1566       └─────────────────┴───────┘
1567
1568   ICMPV6 TYPE TYPE
1569       ┌────────────┬────────────┬───────┬───────────┐
1570Name        Keyword    Size  Base type 
1571       ├────────────┼────────────┼───────┼───────────┤
1572       │            │            │       │           │
1573       │ICMPv6 Type │ icmpx_code │ 8 bit │ integer   │
1574       └────────────┴────────────┴───────┴───────────┘
1575
1576       The ICMPv6 Type type is used to conveniently specify the ICMPv6
1577       header’s type field.
1578
1579       Table 20. keywords may be used when specifying the ICMPv6 type:
1580       ┌────────────────────────┬───────┐
1581Keyword                 Value 
1582       ├────────────────────────┼───────┤
1583       │                        │       │
1584       │destination-unreachable │ 1     │
1585       ├────────────────────────┼───────┤
1586       │                        │       │
1587       │packet-too-big          │ 2     │
1588       ├────────────────────────┼───────┤
1589       │                        │       │
1590       │time-exceeded           │ 3     │
1591       ├────────────────────────┼───────┤
1592       │                        │       │
1593       │parameter-problem       │ 4     │
1594       ├────────────────────────┼───────┤
1595       │                        │       │
1596       │echo-request            │ 128   │
1597       ├────────────────────────┼───────┤
1598       │                        │       │
1599       │echo-reply              │ 129   │
1600       ├────────────────────────┼───────┤
1601       │                        │       │
1602       │mld-listener-query      │ 130   │
1603       ├────────────────────────┼───────┤
1604       │                        │       │
1605       │mld-listener-report     │ 131   │
1606       ├────────────────────────┼───────┤
1607       │                        │       │
1608       │mld-listener-done       │ 132   │
1609       ├────────────────────────┼───────┤
1610       │                        │       │
1611       │mld-listener-reduction  │ 132   │
1612       ├────────────────────────┼───────┤
1613       │                        │       │
1614       │nd-router-solicit       │ 133   │
1615       ├────────────────────────┼───────┤
1616       │                        │       │
1617       │nd-router-advert        │ 134   │
1618       ├────────────────────────┼───────┤
1619       │                        │       │
1620       │nd-neighbor-solicit     │ 135   │
1621       ├────────────────────────┼───────┤
1622       │                        │       │
1623       │nd-neighbor-advert      │ 136   │
1624       ├────────────────────────┼───────┤
1625       │                        │       │
1626       │nd-redirect             │ 137   │
1627       ├────────────────────────┼───────┤
1628       │                        │       │
1629       │router-renumbering      │ 138   │
1630       ├────────────────────────┼───────┤
1631       │                        │       │
1632       │ind-neighbor-solicit    │ 141   │
1633       ├────────────────────────┼───────┤
1634       │                        │       │
1635       │ind-neighbor-advert     │ 142   │
1636       ├────────────────────────┼───────┤
1637       │                        │       │
1638       │mld2-listener-report    │ 143   │
1639       └────────────────────────┴───────┘
1640
1641       ICMPv6 Type specification.
1642
1643           # match ICMPv6 ping packets
1644           filter output icmpv6 type { echo-request, echo-reply }
1645
1646
1647   ICMPV6 CODE TYPE
1648       ┌────────────┬─────────────┬───────┬───────────┐
1649Name        Keyword     Size  Base type 
1650       ├────────────┼─────────────┼───────┼───────────┤
1651       │            │             │       │           │
1652       │ICMPv6 Code │ icmpv6_code │ 8 bit │ integer   │
1653       └────────────┴─────────────┴───────┴───────────┘
1654
1655       The ICMPv6 Code type is used to conveniently specify the ICMPv6
1656       header’s code field.
1657
1658       Table 21. keywords may be used when specifying the ICMPv6 code
1659       ┌─────────────────┬───────┐
1660Keyword          Value 
1661       ├─────────────────┼───────┤
1662       │                 │       │
1663       │no-route         │ 0     │
1664       ├─────────────────┼───────┤
1665       │                 │       │
1666       │admin-prohibited │ 1     │
1667       ├─────────────────┼───────┤
1668       │                 │       │
1669       │addr-unreachable │ 3     │
1670       ├─────────────────┼───────┤
1671       │                 │       │
1672       │port-unreachable │ 4     │
1673       ├─────────────────┼───────┤
1674       │                 │       │
1675       │policy-fail      │ 5     │
1676       ├─────────────────┼───────┤
1677       │                 │       │
1678       │reject-route     │ 6     │
1679       └─────────────────┴───────┘
1680
1681   ICMPVX CODE TYPE
1682       ┌────────────┬─────────────┬───────┬───────────┐
1683Name        Keyword     Size  Base type 
1684       ├────────────┼─────────────┼───────┼───────────┤
1685       │            │             │       │           │
1686       │ICMPvX Code │ icmpv6_type │ 8 bit │ integer   │
1687       └────────────┴─────────────┴───────┴───────────┘
1688
1689       The ICMPvX Code type abstraction is a set of values which overlap
1690       between ICMP and ICMPv6 Code types to be used from the inet family.
1691
1692       Table 22. keywords may be used when specifying the ICMPvX code
1693       ┌─────────────────┬───────┐
1694Keyword          Value 
1695       ├─────────────────┼───────┤
1696       │                 │       │
1697       │no-route         │ 0     │
1698       ├─────────────────┼───────┤
1699       │                 │       │
1700       │port-unreachable │ 1     │
1701       ├─────────────────┼───────┤
1702       │                 │       │
1703       │host-unreachable │ 2     │
1704       ├─────────────────┼───────┤
1705       │                 │       │
1706       │admin-prohibited │ 3     │
1707       └─────────────────┴───────┘
1708
1709   CONNTRACK TYPES
1710       Table 23. overview of types used in ct expression and statement
1711       ┌─────────────────┬───────────┬─────────┬───────────┐
1712Name             Keyword   Size    Base type 
1713       ├─────────────────┼───────────┼─────────┼───────────┤
1714       │                 │           │         │           │
1715       │conntrack state  │ ct_state  │ 4 byte  │ bitmask   │
1716       ├─────────────────┼───────────┼─────────┼───────────┤
1717       │                 │           │         │           │
1718       │conntrack        │ ct_dir    │ 8 bit   │ integer   │
1719       │direction        │           │         │           │
1720       ├─────────────────┼───────────┼─────────┼───────────┤
1721       │                 │           │         │           │
1722       │conntrack status │ ct_status │ 4 byte  │ bitmask   │
1723       ├─────────────────┼───────────┼─────────┼───────────┤
1724       │                 │           │         │           │
1725       │conntrack event  │ ct_event  │ 4 byte  │ bitmask   │
1726       │bits             │           │         │           │
1727       ├─────────────────┼───────────┼─────────┼───────────┤
1728       │                 │           │         │           │
1729       │conntrack label  │ ct_label  │ 128 bit │ bitmask   │
1730       └─────────────────┴───────────┴─────────┴───────────┘
1731
1732       For each of the types above, keywords are available for convenience:
1733
1734       Table 24. conntrack state (ct_state)
1735       ┌────────────┬───────┐
1736Keyword     Value 
1737       ├────────────┼───────┤
1738       │            │       │
1739       │invalid     │ 1     │
1740       ├────────────┼───────┤
1741       │            │       │
1742       │established │ 2     │
1743       ├────────────┼───────┤
1744       │            │       │
1745       │related     │ 4     │
1746       ├────────────┼───────┤
1747       │            │       │
1748       │new         │ 8     │
1749       ├────────────┼───────┤
1750       │            │       │
1751       │untracked   │ 64    │
1752       └────────────┴───────┘
1753
1754       Table 25. conntrack direction (ct_dir)
1755       ┌─────────┬───────┐
1756Keyword  Value 
1757       ├─────────┼───────┤
1758       │         │       │
1759       │original │ 0     │
1760       ├─────────┼───────┤
1761       │         │       │
1762       │reply    │ 1     │
1763       └─────────┴───────┘
1764
1765       Table 26. conntrack status (ct_status)
1766       ┌───────────┬───────┐
1767Keyword    Value 
1768       ├───────────┼───────┤
1769       │           │       │
1770       │expected   │ 1     │
1771       ├───────────┼───────┤
1772       │           │       │
1773       │seen-reply │ 2     │
1774       ├───────────┼───────┤
1775       │           │       │
1776       │assured    │ 4     │
1777       ├───────────┼───────┤
1778       │           │       │
1779       │confirmed  │ 8     │
1780       ├───────────┼───────┤
1781       │           │       │
1782       │snat       │ 16    │
1783       ├───────────┼───────┤
1784       │           │       │
1785       │dnat       │ 32    │
1786       ├───────────┼───────┤
1787       │           │       │
1788       │dying      │ 512   │
1789       └───────────┴───────┘
1790
1791       Table 27. conntrack event bits (ct_event)
1792       ┌──────────┬───────┐
1793Keyword   Value 
1794       ├──────────┼───────┤
1795       │          │       │
1796       │new       │ 1     │
1797       ├──────────┼───────┤
1798       │          │       │
1799       │related   │ 2     │
1800       ├──────────┼───────┤
1801       │          │       │
1802       │destroy   │ 4     │
1803       ├──────────┼───────┤
1804       │          │       │
1805       │reply     │ 8     │
1806       ├──────────┼───────┤
1807       │          │       │
1808       │assured   │ 16    │
1809       ├──────────┼───────┤
1810       │          │       │
1811       │protoinfo │ 32    │
1812       ├──────────┼───────┤
1813       │          │       │
1814       │helper    │ 64    │
1815       ├──────────┼───────┤
1816       │          │       │
1817       │mark      │ 128   │
1818       ├──────────┼───────┤
1819       │          │       │
1820       │seqadj    │ 256   │
1821       ├──────────┼───────┤
1822       │          │       │
1823       │secmark   │ 512   │
1824       ├──────────┼───────┤
1825       │          │       │
1826       │label     │ 1024  │
1827       └──────────┴───────┘
1828
1829       Possible keywords for conntrack label type (ct_label) are read at
1830       runtime from /etc/connlabel.conf.
1831
1832   DCCP PKTTYPE TYPE
1833       ┌─────────────────┬──────────────┬───────┬───────────┐
1834Name             Keyword      Size  Base type 
1835       ├─────────────────┼──────────────┼───────┼───────────┤
1836       │                 │              │       │           │
1837       │DCCP packet type │ dccp_pkttype │ 4 bit │ integer   │
1838       └─────────────────┴──────────────┴───────┴───────────┘
1839
1840       The DCCP packet type abstracts the different legal values of the
1841       respective four bit field in the DCCP header, as stated by RFC4340.
1842       Note that possible values 10-15 are considered reserved and therefore
1843       not allowed to be used. In iptables' dccp match, these values are
1844       aliased INVALID. With nftables, one may simply match on the numeric
1845       value range, i.e. 10-15.
1846
1847       Table 28. keywords may be used when specifying the DCCP packet type
1848       ┌─────────┬───────┐
1849Keyword  Value 
1850       ├─────────┼───────┤
1851       │         │       │
1852       │request  │ 0     │
1853       ├─────────┼───────┤
1854       │         │       │
1855       │response │ 1     │
1856       ├─────────┼───────┤
1857       │         │       │
1858       │data     │ 2     │
1859       ├─────────┼───────┤
1860       │         │       │
1861       │ack      │ 3     │
1862       ├─────────┼───────┤
1863       │         │       │
1864       │dataack  │ 4     │
1865       ├─────────┼───────┤
1866       │         │       │
1867       │closereq │ 5     │
1868       ├─────────┼───────┤
1869       │         │       │
1870       │close    │ 6     │
1871       ├─────────┼───────┤
1872       │         │       │
1873       │reset    │ 7     │
1874       ├─────────┼───────┤
1875       │         │       │
1876       │sync     │ 8     │
1877       ├─────────┼───────┤
1878       │         │       │
1879       │syncack  │ 9     │
1880       └─────────┴───────┘
1881

PRIMARY EXPRESSIONS

1883       The lowest order expression is a primary expression, representing
1884       either a constant or a single datum from a packet’s payload, meta data
1885       or a stateful module.
1886
1887   META EXPRESSIONS
1888           meta {length | nfproto | l4proto | protocol | priority}
1889           [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 }
1890
1891       A meta expression refers to meta data associated with a packet.
1892
1893       There are two types of meta expressions: unqualified and qualified meta
1894       expressions. Qualified meta expressions require the meta keyword before
1895       the meta key, unqualified meta expressions can be specified by using
1896       the meta key directly or as qualified meta expressions. Meta l4proto is
1897       useful to match a particular transport protocol that is part of either
1898       an IPv4 or IPv6 packet. It will also skip any IPv6 extension headers
1899       present in an IPv6 packet.
1900
1901       meta iif, oif, iifname and oifname are used to match the interface a
1902       packet arrived on or is about to be sent out on.
1903
1904       iif and oif are used to match on the interface index, whereas iifname
1905       and oifname are used to match on the interface name. This is not the
1906       same — assuming the rule
1907
1908           filter input meta iif "foo"
1909
1910       Then this rule can only be added if the interface "foo" exists. Also,
1911       the rule will continue to match even if the interface "foo" is renamed
1912       to "bar".
1913
1914       This is because internally the interface index is used. In case of
1915       dynamically created interfaces, such as tun/tap or dialup interfaces
1916       (ppp for example), it might be better to use iifname or oifname
1917       instead.
1918
1919       In these cases, the name is used so the interface doesn’t have to exist
1920       to add such a rule, it will stop matching if the interface gets renamed
1921       and it will match again in case interface gets deleted and later a new
1922       interface with the same name is created.
1923
1924       Like with iptables, wildcard matching on interface name prefixes is
1925       available for iifname and oifname matches by appending an asterisk (*)
1926       character. Note however that unlike iptables, nftables does not accept
1927       interface names consisting of the wildcard character only - users are
1928       supposed to just skip those always matching expressions. In order to
1929       match on literal asterisk character, one may escape it using backslash
1930       (\).
1931
1932       Table 29. Meta expression types
1933       ┌──────────┬─────────────────────┬─────────────────────┐
1934Keyword   Description         Type                
1935       ├──────────┼─────────────────────┼─────────────────────┤
1936       │          │                     │                     │
1937       │length    │ Length of the       │ integer (32-bit)    │
1938       │          │ packet in bytes     │                     │
1939       ├──────────┼─────────────────────┼─────────────────────┤
1940       │          │                     │                     │
1941       │nfproto   │ real hook protocol  │ integer (32 bit)    │
1942       │          │ family, useful only │                     │
1943       │          │ in inet table       │                     │
1944       ├──────────┼─────────────────────┼─────────────────────┤
1945       │          │                     │                     │
1946       │l4proto   │ layer 4 protocol,   │ integer (8 bit)     │
1947       │          │ skips ipv6          │                     │
1948       │          │ extension headers   │                     │
1949       ├──────────┼─────────────────────┼─────────────────────┤
1950       │          │                     │                     │
1951       │protocol  │ EtherType protocol  │ ether_type          │
1952       │          │ value               │                     │
1953       ├──────────┼─────────────────────┼─────────────────────┤
1954       │          │                     │                     │
1955       │priority  │ TC packet priority  │ tc_handle           │
1956       ├──────────┼─────────────────────┼─────────────────────┤
1957       │          │                     │                     │
1958       │mark      │ Packet mark         │ mark                │
1959       ├──────────┼─────────────────────┼─────────────────────┤
1960       │          │                     │                     │
1961       │iif       │ Input interface     │ iface_index         │
1962       │          │ index               │                     │
1963       ├──────────┼─────────────────────┼─────────────────────┤
1964       │          │                     │                     │
1965       │iifname   │ Input interface     │ ifname              │
1966       │          │ name                │                     │
1967       ├──────────┼─────────────────────┼─────────────────────┤
1968       │          │                     │                     │
1969       │iiftype   │ Input interface     │ iface_type          │
1970       │          │ type                │                     │
1971       ├──────────┼─────────────────────┼─────────────────────┤
1972       │          │                     │                     │
1973       │oif       │ Output interface    │ iface_index         │
1974       │          │ index               │                     │
1975       ├──────────┼─────────────────────┼─────────────────────┤
1976       │          │                     │                     │
1977       │oifname   │ Output interface    │ ifname              │
1978       │          │ name                │                     │
1979       ├──────────┼─────────────────────┼─────────────────────┤
1980       │          │                     │                     │
1981       │oiftype   │ Output interface    │ iface_type          │
1982       │          │ hardware type       │                     │
1983       ├──────────┼─────────────────────┼─────────────────────┤
1984       │          │                     │                     │
1985       │sdif      │ Slave device input  │ iface_index         │
1986       │          │ interface index     │                     │
1987       ├──────────┼─────────────────────┼─────────────────────┤
1988       │          │                     │                     │
1989       │sdifname  │ Slave device        │ ifname              │
1990       │          │ interface name      │                     │
1991       ├──────────┼─────────────────────┼─────────────────────┤
1992       │          │                     │                     │
1993       │skuid     │ UID associated with │ uid                 │
1994       │          │ originating socket  │                     │
1995       ├──────────┼─────────────────────┼─────────────────────┤
1996       │          │                     │                     │
1997       │skgid     │ GID associated with │ gid                 │
1998       │          │ originating socket  │                     │
1999       ├──────────┼─────────────────────┼─────────────────────┤
2000       │          │                     │                     │
2001       │rtclassid │ Routing realm       │ realm               │
2002       ├──────────┼─────────────────────┼─────────────────────┤
2003       │          │                     │                     │
2004       │ibrname   │ Input bridge        │ ifname              │
2005       │          │ interface name      │                     │
2006       ├──────────┼─────────────────────┼─────────────────────┤
2007       │          │                     │                     │
2008       │obrname   │ Output bridge       │ ifname              │
2009       │          │ interface name      │                     │
2010       ├──────────┼─────────────────────┼─────────────────────┤
2011       │          │                     │                     │
2012       │pkttype   │ packet type         │ pkt_type            │
2013       ├──────────┼─────────────────────┼─────────────────────┤
2014       │          │                     │                     │
2015       │cpu       │ cpu number          │ integer (32 bit)    │
2016       │          │ processing the      │                     │
2017       │          │ packet              │                     │
2018       ├──────────┼─────────────────────┼─────────────────────┤
2019       │          │                     │                     │
2020       │iifgroup  │ incoming device     │ devgroup            │
2021       │          │ group               │                     │
2022       ├──────────┼─────────────────────┼─────────────────────┤
2023       │          │                     │                     │
2024       │oifgroup  │ outgoing device     │ devgroup            │
2025       │          │ group               │                     │
2026       ├──────────┼─────────────────────┼─────────────────────┤
2027       │          │                     │                     │
2028       │cgroup    │ control group id    │ integer (32 bit)    │
2029       ├──────────┼─────────────────────┼─────────────────────┤
2030       │          │                     │                     │
2031       │random    │ pseudo-random       │ integer (32 bit)    │
2032       │          │ number              │                     │
2033       ├──────────┼─────────────────────┼─────────────────────┤
2034       │          │                     │                     │
2035       │ipsec     │ true if packet was  │ boolean (1 bit)     │
2036       │          │ ipsec encrypted     │                     │
2037       ├──────────┼─────────────────────┼─────────────────────┤
2038       │          │                     │                     │
2039       │iifkind   │ Input interface     │                     │
2040       │          │ kind                │                     │
2041       ├──────────┼─────────────────────┼─────────────────────┤
2042       │          │                     │                     │
2043       │oifkind   │ Output interface    │                     │
2044       │          │ kind                │                     │
2045       ├──────────┼─────────────────────┼─────────────────────┤
2046       │          │                     │                     │
2047       │time      │ Absolute time of    │ Integer (32 bit) or │
2048       │          │ packet reception    │ string              │
2049       ├──────────┼─────────────────────┼─────────────────────┤
2050       │          │                     │                     │
2051       │day       │ Day of week         │ Integer (8 bit) or  │
2052       │          │                     │ string              │
2053       ├──────────┼─────────────────────┼─────────────────────┤
2054       │          │                     │                     │
2055       │hour      │ Hour of day         │ String              │
2056       └──────────┴─────────────────────┴─────────────────────┘
2057
2058       Table 30. Meta expression specific types
2059       ┌──────────────┬────────────────────────────┐
2060Type          Description                
2061       ├──────────────┼────────────────────────────┤
2062       │              │                            │
2063       │iface_index   │ Interface index (32 bit    │
2064       │              │ number). Can be specified  │
2065       │              │ numerically or as name of  │
2066       │              │ an existing interface.     │
2067       ├──────────────┼────────────────────────────┤
2068       │              │                            │
2069       │ifname        │ Interface name (16 byte    │
2070       │              │ string). Does not have to  │
2071       │              │ exist.                     │
2072       ├──────────────┼────────────────────────────┤
2073       │              │                            │
2074       │iface_type    │ Interface type (16 bit     │
2075       │              │ number).                   │
2076       ├──────────────┼────────────────────────────┤
2077       │              │                            │
2078       │uid           │ User ID (32 bit number).   │
2079       │              │ Can be specified           │
2080       │              │ numerically or as user     │
2081       │              │ name.                      │
2082       ├──────────────┼────────────────────────────┤
2083       │              │                            │
2084       │gid           │ Group ID (32 bit number).  │
2085       │              │ Can be specified           │
2086       │              │ numerically or as group    │
2087       │              │ name.                      │
2088       ├──────────────┼────────────────────────────┤
2089       │              │                            │
2090       │realm         │ Routing Realm (32 bit      │
2091       │              │ number). Can be specified  │
2092       │              │ numerically or as symbolic │
2093       │              │ name defined in            │
2094       │              │ /etc/iproute2/rt_realms.   │
2095       ├──────────────┼────────────────────────────┤
2096       │              │                            │
2097       │devgroup_type │ Device group (32 bit       │
2098       │              │ number). Can be specified  │
2099       │              │ numerically or as symbolic │
2100       │              │ name defined in            │
2101       │              │ /etc/iproute2/group.       │
2102       ├──────────────┼────────────────────────────┤
2103       │              │                            │
2104       │pkt_type      │ Packet type: host          
2105       │              │ (addressed to local host), │
2106       │              │ broadcast (to all),        │
2107       │              │ multicast (to group),      │
2108       │              │ other (addressed to        │
2109       │              │ another host).             │
2110       ├──────────────┼────────────────────────────┤
2111       │              │                            │
2112       │ifkind        │ Interface kind (16 byte    │
2113       │              │ string). See TYPES in      │
2114       │              │ ip-link(8) for a list.     │
2115       ├──────────────┼────────────────────────────┤
2116       │              │                            │
2117       │time          │ Either an integer or a     │
2118       │              │ date in ISO format. For    │
2119       │              │ example: "2019-06-06       │
2120       │              │ 17:00". Hour and seconds   │
2121       │              │ are optional and can be    │
2122       │              │ omitted if desired. If     │
2123       │              │ omitted, midnight will be  │
2124       │              │ assumed. The following     │
2125       │              │ three would be equivalent: │
2126       │              │ "2019-06-06", "2019-06-06  │
2127       │              │ 00:00" and "2019-06-06     │
2128       │              │ 00:00:00". When an integer │
2129       │              │ is given, it is assumed to │
2130       │              │ be a UNIX timestamp.       │
2131       ├──────────────┼────────────────────────────┤
2132       │              │                            │
2133       │day           │ Either a day of week       │
2134       │              │ ("Monday", "Tuesday",      │
2135       │              │ etc.), or an integer       │
2136       │              │ between 0 and 6. Strings   │
2137       │              │ are matched                │
2138       │              │ case-insensitively, and a  │
2139       │              │ full match is not expected │
2140       │              │ (e.g. "Mon" would match    │
2141       │              │ "Monday"). When an integer │
2142       │              │ is given, 0 is Sunday and  │
2143       │              │ 6 is Saturday.             │
2144       ├──────────────┼────────────────────────────┤
2145       │              │                            │
2146       │hour          │ A string representing an   │
2147       │              │ hour in 24-hour format.    │
2148       │              │ Seconds can optionally be  │
2149       │              │ specified. For example,    │
2150       │              │ 17:00 and 17:00:00 would   │
2151       │              │ be equivalent.             │
2152       └──────────────┴────────────────────────────┘
2153
2154       Using meta expressions.
2155
2156           # qualified meta expression
2157           filter output meta oif eth0
2158           filter forward meta iifkind { "tun", "veth" }
2159
2160           # unqualified meta expression
2161           filter output oif eth0
2162
2163           # incoming packet was subject to ipsec processing
2164           raw prerouting meta ipsec exists accept
2165
2166
2167   SOCKET EXPRESSION
2168           socket {transparent | mark | wildcard}
2169           socket cgroupv2 level NUM
2170
2171       Socket expression can be used to search for an existing open TCP/UDP
2172       socket and its attributes that can be associated with a packet. It
2173       looks for an established or non-zero bound listening socket (possibly
2174       with a non-local address). You can also use it to match on the socket
2175       cgroupv2 at a given ancestor level, e.g. if the socket belongs to
2176       cgroupv2 a/b, ancestor level 1 checks for a matching on cgroup a and
2177       ancestor level 2 checks for a matching on cgroup b.
2178
2179       Table 31. Available socket attributes
2180       ┌────────────┬─────────────────────┬─────────────────┐
2181Name        Description         Type            
2182       ├────────────┼─────────────────────┼─────────────────┤
2183       │            │                     │                 │
2184       │transparent │ Value of the        │ boolean (1 bit) │
2185       │            │ IP_TRANSPARENT      │                 │
2186       │            │ socket option in    │                 │
2187       │            │ the found socket.   │                 │
2188       │            │ It can be 0 or 1.   │                 │
2189       ├────────────┼─────────────────────┼─────────────────┤
2190       │            │                     │                 │
2191       │mark        │ Value of the socket │ mark            │
2192       │            │ mark (SOL_SOCKET,   │                 │
2193       │            │ SO_MARK).           │                 │
2194       ├────────────┼─────────────────────┼─────────────────┤
2195       │            │                     │                 │
2196       │wildcard    │ Indicates whether   │ boolean (1 bit) │
2197       │            │ the socket is       │                 │
2198       │            │ wildcard-bound      │                 │
2199       │            │ (e.g. 0.0.0.0 or    │                 │
2200       │            │ ::0).               │                 │
2201       ├────────────┼─────────────────────┼─────────────────┤
2202       │            │                     │                 │
2203       │cgroupv2    │ cgroup version 2    │ cgroupv2        │
2204       │            │ for this socket     │                 │
2205       │            │ (path from          │                 │
2206       │            │ /sys/fs/cgroup)     │                 │
2207       └────────────┴─────────────────────┴─────────────────┘
2208
2209       Using socket expression.
2210
2211           # Mark packets that correspond to a transparent socket. "socket wildcard 0"
2212           # means that zero-bound listener sockets are NOT matched (which is usually
2213           # exactly what you want).
2214           table inet x {
2215               chain y {
2216                   type filter hook prerouting priority mangle; policy accept;
2217                   socket transparent 1 socket wildcard 0 mark set 0x00000001 accept
2218               }
2219           }
2220
2221           # Trace packets that corresponds to a socket with a mark value of 15
2222           table inet x {
2223               chain y {
2224                   type filter hook prerouting priority mangle; policy accept;
2225                   socket mark 0x0000000f nftrace set 1
2226               }
2227           }
2228
2229           # Set packet mark to socket mark
2230           table inet x {
2231               chain y {
2232                   type filter hook prerouting priority mangle; policy accept;
2233                   tcp dport 8080 mark set socket mark
2234               }
2235           }
2236
2237           # Count packets for cgroupv2 "user.slice" at level 1
2238           table inet x {
2239               chain y {
2240                   type filter hook input priority filter; policy accept;
2241                   socket cgroupv2 level 1 "user.slice" counter
2242               }
2243           }
2244
2245
2246   OSF EXPRESSION
2247           osf [ttl {loose | skip}] {name | version}
2248
2249       The osf expression does passive operating system fingerprinting. This
2250       expression compares some data (Window Size, MSS, options and their
2251       order, DF, and others) from packets with the SYN bit set.
2252
2253       Table 32. Available osf attributes
2254       ┌────────┬─────────────────────┬────────┐
2255Name    Description         Type   
2256       ├────────┼─────────────────────┼────────┤
2257       │        │                     │        │
2258       │ttl     │ Do TTL checks on    │ string │
2259       │        │ the packet to       │        │
2260       │        │ determine the       │        │
2261       │        │ operating system.   │        │
2262       ├────────┼─────────────────────┼────────┤
2263       │        │                     │        │
2264       │version │ Do OS version       │        │
2265       │        │ checks on the       │        │
2266       │        │ packet.             │        │
2267       ├────────┼─────────────────────┼────────┤
2268       │        │                     │        │
2269       │name    │ Name of the OS      │ string │
2270       │        │ signature to match. │        │
2271       │        │ All signatures can  │        │
2272       │        │ be found at pf.os   │        │
2273       │        │ file. Use "unknown" │        │
2274       │        │ for OS signatures   │        │
2275       │        │ that the expression │        │
2276       │        │ could not detect.   │        │
2277       └────────┴─────────────────────┴────────┘
2278
2279       Available ttl values.
2280
2281           If no TTL attribute is passed, make a true IP header and fingerprint TTL true comparison. This generally works for LANs.
2282
2283           * loose: Check if the IP header's TTL is less than the fingerprint one. Works for globally-routable addresses.
2284           * skip: Do not compare the TTL at all.
2285
2286       Using osf expression.
2287
2288           # Accept packets that match the "Linux" OS genre signature without comparing TTL.
2289           table inet x {
2290               chain y {
2291                   type filter hook input priority filter; policy accept;
2292                   osf ttl skip name "Linux"
2293               }
2294           }
2295
2296
2297   FIB EXPRESSIONS
2298           fib {saddr | daddr | mark | iif | oif} [. ...] {oif | oifname | type}
2299
2300       A fib expression queries the fib (forwarding information base) to
2301       obtain information such as the output interface index a particular
2302       address would use. The input is a tuple of elements that is used as
2303       input to the fib lookup functions.
2304
2305       Table 33. fib expression specific types
2306       ┌────────┬──────────────────┬──────────────────┐
2307Keyword Description      Type             
2308       ├────────┼──────────────────┼──────────────────┤
2309       │        │                  │                  │
2310       │oif     │ Output interface │ integer (32 bit) │
2311       │        │ index            │                  │
2312       ├────────┼──────────────────┼──────────────────┤
2313       │        │                  │                  │
2314       │oifname │ Output interface │ string           │
2315       │        │ name             │                  │
2316       ├────────┼──────────────────┼──────────────────┤
2317       │        │                  │                  │
2318       │type    │ Address type     │ fib_addrtype     │
2319       └────────┴──────────────────┴──────────────────┘
2320
2321       Use nft describe fib_addrtype to get a list of all address types.
2322
2323       Using fib expressions.
2324
2325           # drop packets without a reverse path
2326           filter prerouting fib saddr . iif oif missing drop
2327
2328           In this example, 'saddr . iif' looks up routing information based on the source address and the input interface.
2329           oif picks the output interface index from the routing information.
2330           If no route was found for the source address/input interface combination, the output interface index is zero.
2331           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.
2332           If only 'saddr oif' is given, then oif can be any interface index or zero.
2333
2334           # drop packets to address not configured on incoming interface
2335           filter prerouting fib daddr . iif type != { local, broadcast, multicast } drop
2336
2337           # perform lookup in a specific 'blackhole' table (0xdead, needs ip appropriate ip rule)
2338           filter prerouting meta mark set 0xdead fib daddr . mark type vmap { blackhole : drop, prohibit : jump prohibited, unreachable : drop }
2339
2340
2341   ROUTING EXPRESSIONS
2342           rt [ip | ip6] {classid | nexthop | mtu | ipsec}
2343
2344       A routing expression refers to routing data associated with a packet.
2345
2346       Table 34. Routing expression types
2347       ┌────────┬─────────────────────┬─────────────────────┐
2348Keyword Description         Type                
2349       ├────────┼─────────────────────┼─────────────────────┤
2350       │        │                     │                     │
2351       │classid │ Routing realm       │ realm               │
2352       ├────────┼─────────────────────┼─────────────────────┤
2353       │        │                     │                     │
2354       │nexthop │ Routing nexthop     │ ipv4_addr/ipv6_addr │
2355       ├────────┼─────────────────────┼─────────────────────┤
2356       │        │                     │                     │
2357       │mtu     │ TCP maximum segment │ integer (16 bit)    │
2358       │        │ size of route       │                     │
2359       ├────────┼─────────────────────┼─────────────────────┤
2360       │        │                     │                     │
2361       │ipsec   │ route via ipsec     │ boolean             │
2362       │        │ tunnel or transport │                     │
2363       └────────┴─────────────────────┴─────────────────────┘
2364
2365       Table 35. Routing expression specific types
2366       ┌──────┬────────────────────────────┐
2367Type  Description                
2368       ├──────┼────────────────────────────┤
2369       │      │                            │
2370       │realm │ Routing Realm (32 bit      │
2371       │      │ number). Can be specified  │
2372       │      │ numerically or as symbolic │
2373       │      │ name defined in            │
2374       │      │ /etc/iproute2/rt_realms.   │
2375       └──────┴────────────────────────────┘
2376
2377       Using routing expressions.
2378
2379           # IP family independent rt expression
2380           filter output rt classid 10
2381
2382           # IP family dependent rt expressions
2383           ip filter output rt nexthop 192.168.0.1
2384           ip6 filter output rt nexthop fd00::1
2385           inet filter output rt ip nexthop 192.168.0.1
2386           inet filter output rt ip6 nexthop fd00::1
2387
2388           # outgoing packet will be encapsulated/encrypted by ipsec
2389           filter output rt ipsec exists
2390
2391
2392   IPSEC EXPRESSIONS
2393           ipsec {in | out} [ spnum NUM ]  {reqid | spi}
2394           ipsec {in | out} [ spnum NUM ]  {ip | ip6} {saddr | daddr}
2395
2396       An ipsec expression refers to ipsec data associated with a packet.
2397
2398       The in or out keyword needs to be used to specify if the expression
2399       should examine inbound or outbound policies. The in keyword can be used
2400       in the prerouting, input and forward hooks. The out keyword applies to
2401       forward, output and postrouting hooks. The optional keyword spnum can
2402       be used to match a specific state in a chain, it defaults to 0.
2403
2404       Table 36. Ipsec expression types
2405       ┌────────┬─────────────────────┬─────────────────────┐
2406Keyword Description         Type                
2407       ├────────┼─────────────────────┼─────────────────────┤
2408       │        │                     │                     │
2409       │reqid   │ Request ID          │ integer (32 bit)    │
2410       ├────────┼─────────────────────┼─────────────────────┤
2411       │        │                     │                     │
2412       │spi     │ Security Parameter  │ integer (32 bit)    │
2413       │        │ Index               │                     │
2414       ├────────┼─────────────────────┼─────────────────────┤
2415       │        │                     │                     │
2416       │saddr   │ Source address of   │ ipv4_addr/ipv6_addr │
2417       │        │ the tunnel          │                     │
2418       ├────────┼─────────────────────┼─────────────────────┤
2419       │        │                     │                     │
2420       │daddr   │ Destination address │ ipv4_addr/ipv6_addr │
2421       │        │ of the tunnel       │                     │
2422       └────────┴─────────────────────┴─────────────────────┘
2423
2424   NUMGEN EXPRESSION
2425           numgen {inc | random} mod NUM [ offset NUM ]
2426
2427       Create a number generator. The inc or random keywords control its
2428       operation mode: In inc mode, the last returned value is simply
2429       incremented. In random mode, a new random number is returned. The value
2430       after mod keyword specifies an upper boundary (read: modulus) which is
2431       not reached by returned numbers. The optional offset allows to
2432       increment the returned value by a fixed offset.
2433
2434       A typical use-case for numgen is load-balancing:
2435
2436       Using numgen expression.
2437
2438           # round-robin between 192.168.10.100 and 192.168.20.200:
2439           add rule nat prerouting dnat to numgen inc mod 2 map \
2440                   { 0 : 192.168.10.100, 1 : 192.168.20.200 }
2441
2442           # probability-based with odd bias using intervals:
2443           add rule nat prerouting dnat to numgen random mod 10 map \
2444                   { 0-2 : 192.168.10.100, 3-9 : 192.168.20.200 }
2445
2446
2447   HASH EXPRESSIONS
2448           jhash {ip saddr | ip6 daddr | tcp dport | udp sport | ether saddr} [. ...] mod NUM [ seed NUM ] [ offset NUM ]
2449           symhash mod NUM [ offset NUM ]
2450
2451       Use a hashing function to generate a number. The functions available
2452       are jhash, known as Jenkins Hash, and symhash, for Symmetric Hash. The
2453       jhash requires an expression to determine the parameters of the packet
2454       header to apply the hashing, concatenations are possible as well. The
2455       value after mod keyword specifies an upper boundary (read: modulus)
2456       which is not reached by returned numbers. The optional seed is used to
2457       specify an init value used as seed in the hashing function. The
2458       optional offset allows to increment the returned value by a fixed
2459       offset.
2460
2461       A typical use-case for jhash and symhash is load-balancing:
2462
2463       Using hash expressions.
2464
2465           # load balance based on source ip between 2 ip addresses:
2466           add rule nat prerouting dnat to jhash ip saddr mod 2 map \
2467                   { 0 : 192.168.10.100, 1 : 192.168.20.200 }
2468
2469           # symmetric load balancing between 2 ip addresses:
2470           add rule nat prerouting dnat to symhash mod 2 map \
2471                   { 0 : 192.168.10.100, 1 : 192.168.20.200 }
2472
2473

PAYLOAD EXPRESSIONS

2475       Payload expressions refer to data from the packet’s payload.
2476
2477   ETHERNET HEADER EXPRESSION
2478           ether {daddr | saddr | type}
2479
2480       Table 37. Ethernet header expression types
2481       ┌────────┬────────────────────┬────────────┐
2482Keyword Description        Type       
2483       ├────────┼────────────────────┼────────────┤
2484       │        │                    │            │
2485       │daddr   │ Destination MAC    │ ether_addr │
2486       │        │ address            │            │
2487       ├────────┼────────────────────┼────────────┤
2488       │        │                    │            │
2489       │saddr   │ Source MAC address │ ether_addr │
2490       ├────────┼────────────────────┼────────────┤
2491       │        │                    │            │
2492       │type    │ EtherType          │ ether_type │
2493       └────────┴────────────────────┴────────────┘
2494
2495   VLAN HEADER EXPRESSION
2496           vlan {id | dei | pcp | type}
2497
2498       Table 38. VLAN header expression
2499       ┌────────┬─────────────────────┬──────────────────┐
2500Keyword Description         Type             
2501       ├────────┼─────────────────────┼──────────────────┤
2502       │        │                     │                  │
2503       │id      │ VLAN ID (VID)       │ integer (12 bit) │
2504       ├────────┼─────────────────────┼──────────────────┤
2505       │        │                     │                  │
2506       │dei     │ Drop Eligible       │ integer (1 bit)  │
2507       │        │ Indicator           │                  │
2508       ├────────┼─────────────────────┼──────────────────┤
2509       │        │                     │                  │
2510       │pcp     │ Priority code point │ integer (3 bit)  │
2511       ├────────┼─────────────────────┼──────────────────┤
2512       │        │                     │                  │
2513       │type    │ EtherType           │ ether_type       │
2514       └────────┴─────────────────────┴──────────────────┘
2515
2516   ARP HEADER EXPRESSION
2517           arp {htype | ptype | hlen | plen | operation | saddr { ip | ether } | daddr { ip | ether }
2518
2519       Table 39. ARP header expression
2520       ┌────────────┬─────────────────────┬──────────────────┐
2521Keyword     Description         Type             
2522       ├────────────┼─────────────────────┼──────────────────┤
2523       │            │                     │                  │
2524       │htype       │ ARP hardware type   │ integer (16 bit) │
2525       ├────────────┼─────────────────────┼──────────────────┤
2526       │            │                     │                  │
2527       │ptype       │ EtherType           │ ether_type       │
2528       ├────────────┼─────────────────────┼──────────────────┤
2529       │            │                     │                  │
2530       │hlen        │ Hardware address    │ integer (8 bit)  │
2531       │            │ len                 │                  │
2532       ├────────────┼─────────────────────┼──────────────────┤
2533       │            │                     │                  │
2534       │plen        │ Protocol address    │ integer (8 bit)  │
2535       │            │ len                 │                  │
2536       ├────────────┼─────────────────────┼──────────────────┤
2537       │            │                     │                  │
2538       │operation   │ Operation           │ arp_op           │
2539       ├────────────┼─────────────────────┼──────────────────┤
2540       │            │                     │                  │
2541       │saddr ether │ Ethernet sender     │ ether_addr       │
2542       │            │ address             │                  │
2543       ├────────────┼─────────────────────┼──────────────────┤
2544       │            │                     │                  │
2545       │daddr ether │ Ethernet target     │ ether_addr       │
2546       │            │ address             │                  │
2547       ├────────────┼─────────────────────┼──────────────────┤
2548       │            │                     │                  │
2549       │saddr ip    │ IPv4 sender address │ ipv4_addr        │
2550       ├────────────┼─────────────────────┼──────────────────┤
2551       │            │                     │                  │
2552       │daddr ip    │ IPv4 target address │ ipv4_addr        │
2553       └────────────┴─────────────────────┴──────────────────┘
2554
2555   IPV4 HEADER EXPRESSION
2556           ip {version | hdrlength | dscp | ecn | length | id | frag-off | ttl | protocol | checksum | saddr | daddr }
2557
2558       Table 40. IPv4 header expression
2559       ┌──────────┬─────────────────────┬──────────────────┐
2560Keyword   Description         Type             
2561       ├──────────┼─────────────────────┼──────────────────┤
2562       │          │                     │                  │
2563       │version   │ IP header version   │ integer (4 bit)  │
2564       │          │ (4)                 │                  │
2565       ├──────────┼─────────────────────┼──────────────────┤
2566       │          │                     │                  │
2567       │hdrlength │ IP header length    │ integer (4 bit)  │
2568       │          │ including options   │ FIXME scaling    │
2569       ├──────────┼─────────────────────┼──────────────────┤
2570       │          │                     │                  │
2571       │dscp      │ Differentiated      │ dscp             │
2572       │          │ Services Code Point │                  │
2573       ├──────────┼─────────────────────┼──────────────────┤
2574       │          │                     │                  │
2575       │ecn       │ Explicit Congestion │ ecn              │
2576       │          │ Notification        │                  │
2577       ├──────────┼─────────────────────┼──────────────────┤
2578       │          │                     │                  │
2579       │length    │ Total packet length │ integer (16 bit) │
2580       ├──────────┼─────────────────────┼──────────────────┤
2581       │          │                     │                  │
2582       │id        │ IP ID               │ integer (16 bit) │
2583       ├──────────┼─────────────────────┼──────────────────┤
2584       │          │                     │                  │
2585       │frag-off  │ Fragment offset     │ integer (16 bit) │
2586       ├──────────┼─────────────────────┼──────────────────┤
2587       │          │                     │                  │
2588       │ttl       │ Time to live        │ integer (8 bit)  │
2589       ├──────────┼─────────────────────┼──────────────────┤
2590       │          │                     │                  │
2591       │protocol  │ Upper layer         │ inet_proto       │
2592       │          │ protocol            │                  │
2593       ├──────────┼─────────────────────┼──────────────────┤
2594       │          │                     │                  │
2595       │checksum  │ IP header checksum  │ integer (16 bit) │
2596       ├──────────┼─────────────────────┼──────────────────┤
2597       │          │                     │                  │
2598       │saddr     │ Source address      │ ipv4_addr        │
2599       ├──────────┼─────────────────────┼──────────────────┤
2600       │          │                     │                  │
2601       │daddr     │ Destination address │ ipv4_addr        │
2602       └──────────┴─────────────────────┴──────────────────┘
2603
2604   ICMP HEADER EXPRESSION
2605           icmp {type | code | checksum | id | sequence | gateway | mtu}
2606
2607       This expression refers to ICMP header fields. When using it in inet,
2608       bridge or netdev families, it will cause an implicit dependency on IPv4
2609       to be created. To match on unusual cases like ICMP over IPv6, one has
2610       to add an explicit meta protocol ip6 match to the rule.
2611
2612       Table 41. ICMP header expression
2613       ┌─────────┬─────────────────────┬──────────────────┐
2614Keyword  Description         Type             
2615       ├─────────┼─────────────────────┼──────────────────┤
2616       │         │                     │                  │
2617       │type     │ ICMP type field     │ icmp_type        │
2618       ├─────────┼─────────────────────┼──────────────────┤
2619       │         │                     │                  │
2620       │code     │ ICMP code field     │ integer (8 bit)  │
2621       ├─────────┼─────────────────────┼──────────────────┤
2622       │         │                     │                  │
2623       │checksum │ ICMP checksum field │ integer (16 bit) │
2624       ├─────────┼─────────────────────┼──────────────────┤
2625       │         │                     │                  │
2626       │id       │ ID of echo          │ integer (16 bit) │
2627       │         │ request/response    │                  │
2628       ├─────────┼─────────────────────┼──────────────────┤
2629       │         │                     │                  │
2630       │sequence │ sequence number of  │ integer (16 bit) │
2631       │         │ echo                │                  │
2632       │         │ request/response    │                  │
2633       ├─────────┼─────────────────────┼──────────────────┤
2634       │         │                     │                  │
2635       │gateway  │ gateway of          │ integer (32 bit) │
2636       │         │ redirects           │                  │
2637       ├─────────┼─────────────────────┼──────────────────┤
2638       │         │                     │                  │
2639       │mtu      │ MTU of path MTU     │ integer (16 bit) │
2640       │         │ discovery           │                  │
2641       └─────────┴─────────────────────┴──────────────────┘
2642
2643   IGMP HEADER EXPRESSION
2644           igmp {type | mrt | checksum | group}
2645
2646       This expression refers to IGMP header fields. When using it in inet,
2647       bridge or netdev families, it will cause an implicit dependency on IPv4
2648       to be created. To match on unusual cases like IGMP over IPv6, one has
2649       to add an explicit meta protocol ip6 match to the rule.
2650
2651       Table 42. IGMP header expression
2652       ┌─────────┬─────────────────────┬──────────────────┐
2653Keyword  Description         Type             
2654       ├─────────┼─────────────────────┼──────────────────┤
2655       │         │                     │                  │
2656       │type     │ IGMP type field     │ igmp_type        │
2657       ├─────────┼─────────────────────┼──────────────────┤
2658       │         │                     │                  │
2659       │mrt      │ IGMP maximum        │ integer (8 bit)  │
2660       │         │ response time field │                  │
2661       ├─────────┼─────────────────────┼──────────────────┤
2662       │         │                     │                  │
2663       │checksum │ IGMP checksum field │ integer (16 bit) │
2664       ├─────────┼─────────────────────┼──────────────────┤
2665       │         │                     │                  │
2666       │group    │ Group address       │ integer (32 bit) │
2667       └─────────┴─────────────────────┴──────────────────┘
2668
2669   IPV6 HEADER EXPRESSION
2670           ip6 {version | dscp | ecn | flowlabel | length | nexthdr | hoplimit | saddr | daddr}
2671
2672       This expression refers to the ipv6 header fields. Caution when using
2673       ip6 nexthdr, the value only refers to the next header, i.e. ip6 nexthdr
2674       tcp will only match if the ipv6 packet does not contain any extension
2675       headers. Packets that are fragmented or e.g. contain a routing
2676       extension headers will not be matched. Please use meta l4proto if you
2677       wish to match the real transport header and ignore any additional
2678       extension headers instead.
2679
2680       Table 43. IPv6 header expression
2681       ┌──────────┬─────────────────────┬──────────────────┐
2682Keyword   Description         Type             
2683       ├──────────┼─────────────────────┼──────────────────┤
2684       │          │                     │                  │
2685       │version   │ IP header version   │ integer (4 bit)  │
2686       │          │ (6)                 │                  │
2687       ├──────────┼─────────────────────┼──────────────────┤
2688       │          │                     │                  │
2689       │dscp      │ Differentiated      │ dscp             │
2690       │          │ Services Code Point │                  │
2691       ├──────────┼─────────────────────┼──────────────────┤
2692       │          │                     │                  │
2693       │ecn       │ Explicit Congestion │ ecn              │
2694       │          │ Notification        │                  │
2695       ├──────────┼─────────────────────┼──────────────────┤
2696       │          │                     │                  │
2697       │flowlabel │ Flow label          │ integer (20 bit) │
2698       ├──────────┼─────────────────────┼──────────────────┤
2699       │          │                     │                  │
2700       │length    │ Payload length      │ integer (16 bit) │
2701       ├──────────┼─────────────────────┼──────────────────┤
2702       │          │                     │                  │
2703       │nexthdr   │ Nexthdr protocol    │ inet_proto       │
2704       ├──────────┼─────────────────────┼──────────────────┤
2705       │          │                     │                  │
2706       │hoplimit  │ Hop limit           │ integer (8 bit)  │
2707       ├──────────┼─────────────────────┼──────────────────┤
2708       │          │                     │                  │
2709       │saddr     │ Source address      │ ipv6_addr        │
2710       ├──────────┼─────────────────────┼──────────────────┤
2711       │          │                     │                  │
2712       │daddr     │ Destination address │ ipv6_addr        │
2713       └──────────┴─────────────────────┴──────────────────┘
2714
2715       Using ip6 header expressions.
2716
2717           # matching if first extension header indicates a fragment
2718           ip6 nexthdr ipv6-frag
2719
2720
2721   ICMPV6 HEADER EXPRESSION
2722           icmpv6 {type | code | checksum | parameter-problem | packet-too-big | id | sequence | max-delay}
2723
2724       This expression refers to ICMPv6 header fields. When using it in inet,
2725       bridge or netdev families, it will cause an implicit dependency on IPv6
2726       to be created. To match on unusual cases like ICMPv6 over IPv4, one has
2727       to add an explicit meta protocol ip match to the rule.
2728
2729       Table 44. ICMPv6 header expression
2730       ┌──────────────────┬────────────────────┬──────────────────┐
2731Keyword           Description        Type             
2732       ├──────────────────┼────────────────────┼──────────────────┤
2733       │                  │                    │                  │
2734       │type              │ ICMPv6 type field  │ icmpv6_type      │
2735       ├──────────────────┼────────────────────┼──────────────────┤
2736       │                  │                    │                  │
2737       │code              │ ICMPv6 code field  │ integer (8 bit)  │
2738       ├──────────────────┼────────────────────┼──────────────────┤
2739       │                  │                    │                  │
2740       │checksum          │ ICMPv6 checksum    │ integer (16 bit) │
2741       │                  │ field              │                  │
2742       ├──────────────────┼────────────────────┼──────────────────┤
2743       │                  │                    │                  │
2744       │parameter-problem │ pointer to problem │ integer (32 bit) │
2745       ├──────────────────┼────────────────────┼──────────────────┤
2746       │                  │                    │                  │
2747       │packet-too-big    │ oversized MTU      │ integer (32 bit) │
2748       ├──────────────────┼────────────────────┼──────────────────┤
2749       │                  │                    │                  │
2750       │id                │ ID of echo         │ integer (16 bit) │
2751       │                  │ request/response   │                  │
2752       ├──────────────────┼────────────────────┼──────────────────┤
2753       │                  │                    │                  │
2754       │sequence          │ sequence number of │ integer (16 bit) │
2755       │                  │ echo               │                  │
2756       │                  │ request/response   │                  │
2757       ├──────────────────┼────────────────────┼──────────────────┤
2758       │                  │                    │                  │
2759       │max-delay         │ maximum response   │ integer (16 bit) │
2760       │                  │ delay of MLD       │                  │
2761       │                  │ queries            │                  │
2762       └──────────────────┴────────────────────┴──────────────────┘
2763
2764   TCP HEADER EXPRESSION
2765           tcp {sport | dport | sequence | ackseq | doff | reserved | flags | window | checksum | urgptr}
2766
2767       Table 45. TCP header expression
2768       ┌─────────┬──────────────────┬──────────────────┐
2769Keyword  Description      Type             
2770       ├─────────┼──────────────────┼──────────────────┤
2771       │         │                  │                  │
2772       │sport    │ Source port      │ inet_service     │
2773       ├─────────┼──────────────────┼──────────────────┤
2774       │         │                  │                  │
2775       │dport    │ Destination port │ inet_service     │
2776       ├─────────┼──────────────────┼──────────────────┤
2777       │         │                  │                  │
2778       │sequence │ Sequence number  │ integer (32 bit) │
2779       ├─────────┼──────────────────┼──────────────────┤
2780       │         │                  │                  │
2781       │ackseq   │ Acknowledgement  │ integer (32 bit) │
2782       │         │ number           │                  │
2783       ├─────────┼──────────────────┼──────────────────┤
2784       │         │                  │                  │
2785       │doff     │ Data offset      │ integer (4 bit)  │
2786       │         │                  │ FIXME scaling    │
2787       ├─────────┼──────────────────┼──────────────────┤
2788       │         │                  │                  │
2789       │reserved │ Reserved area    │ integer (4 bit)  │
2790       ├─────────┼──────────────────┼──────────────────┤
2791       │         │                  │                  │
2792       │flags    │ TCP flags        │ tcp_flag         │
2793       ├─────────┼──────────────────┼──────────────────┤
2794       │         │                  │                  │
2795       │window   │ Window           │ integer (16 bit) │
2796       ├─────────┼──────────────────┼──────────────────┤
2797       │         │                  │                  │
2798       │checksum │ Checksum         │ integer (16 bit) │
2799       ├─────────┼──────────────────┼──────────────────┤
2800       │         │                  │                  │
2801       │urgptr   │ Urgent pointer   │ integer (16 bit) │
2802       └─────────┴──────────────────┴──────────────────┘
2803
2804   UDP HEADER EXPRESSION
2805           udp {sport | dport | length | checksum}
2806
2807       Table 46. UDP header expression
2808       ┌─────────┬─────────────────────┬──────────────────┐
2809Keyword  Description         Type             
2810       ├─────────┼─────────────────────┼──────────────────┤
2811       │         │                     │                  │
2812       │sport    │ Source port         │ inet_service     │
2813       ├─────────┼─────────────────────┼──────────────────┤
2814       │         │                     │                  │
2815       │dport    │ Destination port    │ inet_service     │
2816       ├─────────┼─────────────────────┼──────────────────┤
2817       │         │                     │                  │
2818       │length   │ Total packet length │ integer (16 bit) │
2819       ├─────────┼─────────────────────┼──────────────────┤
2820       │         │                     │                  │
2821       │checksum │ Checksum            │ integer (16 bit) │
2822       └─────────┴─────────────────────┴──────────────────┘
2823
2824   UDP-LITE HEADER EXPRESSION
2825           udplite {sport | dport | checksum}
2826
2827       Table 47. UDP-Lite header expression
2828       ┌─────────┬──────────────────┬──────────────────┐
2829Keyword  Description      Type             
2830       ├─────────┼──────────────────┼──────────────────┤
2831       │         │                  │                  │
2832       │sport    │ Source port      │ inet_service     │
2833       ├─────────┼──────────────────┼──────────────────┤
2834       │         │                  │                  │
2835       │dport    │ Destination port │ inet_service     │
2836       ├─────────┼──────────────────┼──────────────────┤
2837       │         │                  │                  │
2838       │checksum │ Checksum         │ integer (16 bit) │
2839       └─────────┴──────────────────┴──────────────────┘
2840
2841   SCTP HEADER EXPRESSION
2842           sctp {sport | dport | vtag | checksum}
2843           sctp chunk CHUNK [ FIELD ]
2844
2845           CHUNK := data | init | init-ack | sack | heartbeat |
2846                      heartbeat-ack | abort | shutdown | shutdown-ack | error |
2847                      cookie-echo | cookie-ack | ecne | cwr | shutdown-complete
2848                      | asconf-ack | forward-tsn | asconf
2849
2850           FIELD := COMMON_FIELD | DATA_FIELD | INIT_FIELD | INIT_ACK_FIELD |
2851                      SACK_FIELD | SHUTDOWN_FIELD | ECNE_FIELD | CWR_FIELD |
2852                      ASCONF_ACK_FIELD | FORWARD_TSN_FIELD | ASCONF_FIELD
2853
2854           COMMON_FIELD := type | flags | length
2855           DATA_FIELD := tsn | stream | ssn | ppid
2856           INIT_FIELD := init-tag | a-rwnd | num-outbound-streams |
2857                           num-inbound-streams | initial-tsn
2858           INIT_ACK_FIELD := INIT_FIELD
2859           SACK_FIELD := cum-tsn-ack | a-rwnd | num-gap-ack-blocks |
2860                           num-dup-tsns
2861           SHUTDOWN_FIELD := cum-tsn-ack
2862           ECNE_FIELD := lowest-tsn
2863           CWR_FIELD := lowest-tsn
2864           ASCONF_ACK_FIELD := seqno
2865           FORWARD_TSN_FIELD := new-cum-tsn
2866           ASCONF_FIELD := seqno
2867
2868       Table 48. SCTP header expression
2869       ┌─────────┬──────────────────┬────────────────────┐
2870Keyword  Description      Type               
2871       ├─────────┼──────────────────┼────────────────────┤
2872       │         │                  │                    │
2873       │sport    │ Source port      │ inet_service       │
2874       ├─────────┼──────────────────┼────────────────────┤
2875       │         │                  │                    │
2876       │dport    │ Destination port │ inet_service       │
2877       ├─────────┼──────────────────┼────────────────────┤
2878       │         │                  │                    │
2879       │vtag     │ Verification Tag │ integer (32 bit)   │
2880       ├─────────┼──────────────────┼────────────────────┤
2881       │         │                  │                    │
2882       │checksum │ Checksum         │ integer (32 bit)   │
2883       ├─────────┼──────────────────┼────────────────────┤
2884       │         │                  │                    │
2885       │chunk    │ Search chunk in  │ without FIELD,     │
2886       │         │ packet           │ boolean indicating │
2887       │         │                  │ existence          │
2888       └─────────┴──────────────────┴────────────────────┘
2889
2890       Table 49. SCTP chunk fields
2891       ┌─────────────────────┬───────────────┬─────────────────┬──────────────────┐
2892Name                 Width in bits Chunk           Notes            
2893       ├─────────────────────┼───────────────┼─────────────────┼──────────────────┤
2894       │                     │               │                 │                  │
2895       │type                 │ 8             │ all             │ not useful,      │
2896       │                     │               │                 │ defined by chunk │
2897       │                     │               │                 │ type             │
2898       ├─────────────────────┼───────────────┼─────────────────┼──────────────────┤
2899       │                     │               │                 │                  │
2900       │flags                │ 8             │ all             │ semantics        │
2901       │                     │               │                 │ defined on       │
2902       │                     │               │                 │ per-chunk basis  │
2903       ├─────────────────────┼───────────────┼─────────────────┼──────────────────┤
2904       │                     │               │                 │                  │
2905       │length               │ 16            │ all             │ length of this   │
2906       │                     │               │                 │ chunk in bytes   │
2907       │                     │               │                 │ excluding        │
2908       │                     │               │                 │ padding          │
2909       ├─────────────────────┼───────────────┼─────────────────┼──────────────────┤
2910       │                     │               │                 │                  │
2911       │tsn                  │ 32            │ data            │ transmission     │
2912       │                     │               │                 │ sequence number  │
2913       ├─────────────────────┼───────────────┼─────────────────┼──────────────────┤
2914       │                     │               │                 │                  │
2915       │stream               │ 16            │ data            │ stream           │
2916       │                     │               │                 │ identifier       │
2917       ├─────────────────────┼───────────────┼─────────────────┼──────────────────┤
2918       │                     │               │                 │                  │
2919       │ssn                  │ 16            │ data            │ stream sequence  │
2920       │                     │               │                 │ number           │
2921       ├─────────────────────┼───────────────┼─────────────────┼──────────────────┤
2922       │                     │               │                 │                  │
2923       │ppid                 │ 32            │ data            │ payload protocol │
2924       │                     │               │                 │ identifier       │
2925       ├─────────────────────┼───────────────┼─────────────────┼──────────────────┤
2926       │                     │               │                 │                  │
2927       │init-tag             │ 32            │ init, init-ack  │ initiate tag     │
2928       ├─────────────────────┼───────────────┼─────────────────┼──────────────────┤
2929       │                     │               │                 │                  │
2930       │a-rwnd               │ 32            │ init, init-ack, │ advertised       │
2931       │                     │               │ sack            │ receiver window  │
2932       │                     │               │                 │ credit           │
2933       ├─────────────────────┼───────────────┼─────────────────┼──────────────────┤
2934       │                     │               │                 │                  │
2935       │num-outbound-streams │ 16            │ init, init-ack  │ number of        │
2936       │                     │               │                 │ outbound streams │
2937       ├─────────────────────┼───────────────┼─────────────────┼──────────────────┤
2938       │                     │               │                 │                  │
2939       │num-inbound-streams  │ 16            │ init, init-ack  │ number of        │
2940       │                     │               │                 │ inbound streams  │
2941       ├─────────────────────┼───────────────┼─────────────────┼──────────────────┤
2942       │                     │               │                 │                  │
2943       │initial-tsn          │ 32            │ init, init-ack  │ initial transmit │
2944       │                     │               │                 │ sequence number  │
2945       ├─────────────────────┼───────────────┼─────────────────┼──────────────────┤
2946       │                     │               │                 │                  │
2947       │cum-tsn-ack          │ 32            │ sack, shutdown  │ cumulative       │
2948       │                     │               │                 │ transmission     │
2949       │                     │               │                 │ sequence number  │
2950       │                     │               │                 │ acknowledged     │
2951       ├─────────────────────┼───────────────┼─────────────────┼──────────────────┤
2952       │                     │               │                 │                  │
2953       │num-gap-ack-blocks   │ 16            │ sack            │ number of Gap    │
2954       │                     │               │                 │ Ack Blocks       │
2955       │                     │               │                 │ included         │
2956       ├─────────────────────┼───────────────┼─────────────────┼──────────────────┤
2957       │                     │               │                 │                  │
2958       │num-dup-tsns         │ 16            │ sack            │ number of        │
2959       │                     │               │                 │ duplicate        │
2960       │                     │               │                 │ transmission     │
2961       │                     │               │                 │ sequence numbers │
2962       │                     │               │                 │ received         │
2963       ├─────────────────────┼───────────────┼─────────────────┼──────────────────┤
2964       │                     │               │                 │                  │
2965       │lowest-tsn           │ 32            │ ecne, cwr       │ lowest           │
2966       │                     │               │                 │ transmission     │
2967       │                     │               │                 │ sequence number  │
2968       ├─────────────────────┼───────────────┼─────────────────┼──────────────────┤
2969       │                     │               │                 │                  │
2970       │seqno                │ 32            │ asconf-ack,     │ sequence number  │
2971       │                     │               │ asconf          │                  │
2972       ├─────────────────────┼───────────────┼─────────────────┼──────────────────┤
2973       │                     │               │                 │                  │
2974       │new-cum-tsn          │ 32            │ forward-tsn     │ new cumulative   │
2975       │                     │               │                 │ transmission     │
2976       │                     │               │                 │ sequence number  │
2977       └─────────────────────┴───────────────┴─────────────────┴──────────────────┘
2978
2979   DCCP HEADER EXPRESSION
2980           dccp {sport | dport | type}
2981
2982       Table 50. DCCP header expression
2983       ┌────────┬──────────────────┬──────────────┐
2984Keyword Description      Type         
2985       ├────────┼──────────────────┼──────────────┤
2986       │        │                  │              │
2987       │sport   │ Source port      │ inet_service │
2988       ├────────┼──────────────────┼──────────────┤
2989       │        │                  │              │
2990       │dport   │ Destination port │ inet_service │
2991       ├────────┼──────────────────┼──────────────┤
2992       │        │                  │              │
2993       │type    │ Packet type      │ dccp_pkttype │
2994       └────────┴──────────────────┴──────────────┘
2995
2996   AUTHENTICATION HEADER EXPRESSION
2997           ah {nexthdr | hdrlength | reserved | spi | sequence}
2998
2999       Table 51. AH header expression
3000       ┌──────────┬────────────────────┬──────────────────┐
3001Keyword   Description        Type             
3002       ├──────────┼────────────────────┼──────────────────┤
3003       │          │                    │                  │
3004       │nexthdr   │ Next header        │ inet_proto       │
3005       │          │ protocol           │                  │
3006       ├──────────┼────────────────────┼──────────────────┤
3007       │          │                    │                  │
3008       │hdrlength │ AH Header length   │ integer (8 bit)  │
3009       ├──────────┼────────────────────┼──────────────────┤
3010       │          │                    │                  │
3011       │reserved  │ Reserved area      │ integer (16 bit) │
3012       ├──────────┼────────────────────┼──────────────────┤
3013       │          │                    │                  │
3014       │spi       │ Security Parameter │ integer (32 bit) │
3015       │          │ Index              │                  │
3016       ├──────────┼────────────────────┼──────────────────┤
3017       │          │                    │                  │
3018       │sequence  │ Sequence number    │ integer (32 bit) │
3019       └──────────┴────────────────────┴──────────────────┘
3020
3021   ENCRYPTED SECURITY PAYLOAD HEADER EXPRESSION
3022           esp {spi | sequence}
3023
3024       Table 52. ESP header expression
3025       ┌─────────┬────────────────────┬──────────────────┐
3026Keyword  Description        Type             
3027       ├─────────┼────────────────────┼──────────────────┤
3028       │         │                    │                  │
3029       │spi      │ Security Parameter │ integer (32 bit) │
3030       │         │ Index              │                  │
3031       ├─────────┼────────────────────┼──────────────────┤
3032       │         │                    │                  │
3033       │sequence │ Sequence number    │ integer (32 bit) │
3034       └─────────┴────────────────────┴──────────────────┘
3035
3036   IPCOMP HEADER EXPRESSION
3037       comp {nexthdr | flags | cpi}
3038
3039       Table 53. IPComp header expression
3040       ┌────────┬─────────────────┬──────────────────┐
3041Keyword Description     Type             
3042       ├────────┼─────────────────┼──────────────────┤
3043       │        │                 │                  │
3044       │nexthdr │ Next header     │ inet_proto       │
3045       │        │ protocol        │                  │
3046       ├────────┼─────────────────┼──────────────────┤
3047       │        │                 │                  │
3048       │flags   │ Flags           │ bitmask          │
3049       ├────────┼─────────────────┼──────────────────┤
3050       │        │                 │                  │
3051       │cpi     │ compression     │ integer (16 bit) │
3052       │        │ Parameter Index │                  │
3053       └────────┴─────────────────┴──────────────────┘
3054
3055   RAW PAYLOAD EXPRESSION
3056           @base,offset,length
3057
3058       The raw payload expression instructs to load length bits starting at
3059       offset bits. Bit 0 refers to the very first bit — in the C programming
3060       language, this corresponds to the topmost bit, i.e. 0x80 in case of an
3061       octet. They are useful to match headers that do not have a
3062       human-readable template expression yet. Note that nft will not add
3063       dependencies for Raw payload expressions. If you e.g. want to match
3064       protocol fields of a transport header with protocol number 5, you need
3065       to manually exclude packets that have a different transport header, for
3066       instance by using meta l4proto 5 before the raw expression.
3067
3068       Table 54. Supported payload protocol bases
3069       ┌─────┬─────────────────────────┐
3070Base Description             
3071       ├─────┼─────────────────────────┤
3072       │     │                         │
3073       │ll   │ Link layer, for example │
3074       │     │ the Ethernet header     │
3075       ├─────┼─────────────────────────┤
3076       │     │                         │
3077       │nh   │ Network header, for     │
3078       │     │ example IPv4 or IPv6    │
3079       ├─────┼─────────────────────────┤
3080       │     │                         │
3081       │th   │ Transport Header, for   │
3082       │     │ example TCP             │
3083       └─────┴─────────────────────────┘
3084
3085       Matching destination port of both UDP and TCP.
3086
3087           inet filter input meta l4proto {tcp, udp} @th,16,16 { 53, 80 }
3088
3089       The above can also be written as
3090
3091           inet filter input meta l4proto {tcp, udp} th dport { 53, 80 }
3092
3093       it is more convenient, but like the raw expression notation no
3094       dependencies are created or checked. It is the users responsibility to
3095       restrict matching to those header types that have a notion of ports.
3096       Otherwise, rules using raw expressions will errnously match unrelated
3097       packets, e.g. mis-interpreting ESP packets SPI field as a port.
3098
3099       Rewrite arp packet target hardware address if target protocol address
3100       matches a given address.
3101
3102           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
3103
3104
3105   EXTENSION HEADER EXPRESSIONS
3106       Extension header expressions refer to data from variable-sized protocol
3107       headers, such as IPv6 extension headers, TCP options and IPv4 options.
3108
3109       nftables currently supports matching (finding) a given ipv6 extension
3110       header, TCP option or IPv4 option.
3111
3112           hbh {nexthdr | hdrlength}
3113           frag {nexthdr | frag-off | more-fragments | id}
3114           rt {nexthdr | hdrlength | type | seg-left}
3115           dst {nexthdr | hdrlength}
3116           mh {nexthdr | hdrlength | checksum | type}
3117           srh {flags | tag | sid | seg-left}
3118           tcp option {eol | nop | maxseg | window | sack-perm | sack | sack0 | sack1 | sack2 | sack3 | timestamp} tcp_option_field
3119           ip option { lsrr | ra | rr | ssrr } ip_option_field
3120
3121       The following syntaxes are valid only in a relational expression with
3122       boolean type on right-hand side for checking header existence only:
3123
3124           exthdr {hbh | frag | rt | dst | mh}
3125           tcp option {eol | nop | maxseg | window | sack-perm | sack | sack0 | sack1 | sack2 | sack3 | timestamp}
3126           ip option { lsrr | ra | rr | ssrr }
3127
3128       Table 55. IPv6 extension headers
3129       ┌────────┬────────────────────────┐
3130Keyword Description            
3131       ├────────┼────────────────────────┤
3132       │        │                        │
3133       │hbh     │ Hop by Hop             │
3134       ├────────┼────────────────────────┤
3135       │        │                        │
3136       │rt      │ Routing Header         │
3137       ├────────┼────────────────────────┤
3138       │        │                        │
3139       │frag    │ Fragmentation header   │
3140       ├────────┼────────────────────────┤
3141       │        │                        │
3142       │dst     │ dst options            │
3143       ├────────┼────────────────────────┤
3144       │        │                        │
3145       │mh      │ Mobility Header        │
3146       ├────────┼────────────────────────┤
3147       │        │                        │
3148       │srh     │ Segment Routing Header │
3149       └────────┴────────────────────────┘
3150
3151       Table 56. TCP Options
3152       ┌──────────┬─────────────────────┬─────────────────────┐
3153Keyword   Description         TCP option fields   
3154       ├──────────┼─────────────────────┼─────────────────────┤
3155       │          │                     │                     │
3156       │eol       │ End if option list  │ -                   │
3157       ├──────────┼─────────────────────┼─────────────────────┤
3158       │          │                     │                     │
3159       │nop       │ 1 Byte TCP Nop      │ -                   │
3160       │          │ padding option      │                     │
3161       ├──────────┼─────────────────────┼─────────────────────┤
3162       │          │                     │                     │
3163       │maxseg    │ TCP Maximum Segment │ length, size        │
3164       │          │ Size                │                     │
3165       ├──────────┼─────────────────────┼─────────────────────┤
3166       │          │                     │                     │
3167       │window    │ TCP Window Scaling  │ length, count       │
3168       ├──────────┼─────────────────────┼─────────────────────┤
3169       │          │                     │                     │
3170       │sack-perm │ TCP SACK permitted  │ length              │
3171       ├──────────┼─────────────────────┼─────────────────────┤
3172       │          │                     │                     │
3173       │sack      │ TCP Selective       │ length, left, right │
3174       │          │ Acknowledgement     │                     │
3175       │          │ (alias of block 0)  │                     │
3176       ├──────────┼─────────────────────┼─────────────────────┤
3177       │          │                     │                     │
3178       │sack0     │ TCP Selective       │ length, left, right │
3179       │          │ Acknowledgement     │                     │
3180       │          │ (block 0)           │                     │
3181       ├──────────┼─────────────────────┼─────────────────────┤
3182       │          │                     │                     │
3183       │sack1     │ TCP Selective       │ length, left, right │
3184       │          │ Acknowledgement     │                     │
3185       │          │ (block 1)           │                     │
3186       ├──────────┼─────────────────────┼─────────────────────┤
3187       │          │                     │                     │
3188       │sack2     │ TCP Selective       │ length, left, right │
3189       │          │ Acknowledgement     │                     │
3190       │          │ (block 2)           │                     │
3191       ├──────────┼─────────────────────┼─────────────────────┤
3192       │          │                     │                     │
3193       │sack3     │ TCP Selective       │ length, left, right │
3194       │          │ Acknowledgement     │                     │
3195       │          │ (block 3)           │                     │
3196       ├──────────┼─────────────────────┼─────────────────────┤
3197       │          │                     │                     │
3198       │timestamp │ TCP Timestamps      │ length, tsval,      │
3199       │          │                     │ tsecr               │
3200       └──────────┴─────────────────────┴─────────────────────┘
3201
3202       TCP option matching also supports raw expression syntax to access
3203       arbitrary options:
3204
3205           tcp option
3206
3207           tcp option @number,offset,length
3208
3209       Table 57. IP Options
3210       ┌────────┬─────────────────────┬─────────────────────┐
3211Keyword Description         IP option fields    
3212       ├────────┼─────────────────────┼─────────────────────┤
3213       │        │                     │                     │
3214       │lsrr    │ Loose Source Route  │ type, length, ptr,  │
3215       │        │                     │ addr                │
3216       ├────────┼─────────────────────┼─────────────────────┤
3217       │        │                     │                     │
3218       │ra      │ Router Alert        │ type, length, value │
3219       ├────────┼─────────────────────┼─────────────────────┤
3220       │        │                     │                     │
3221       │rr      │ Record Route        │ type, length, ptr,  │
3222       │        │                     │ addr                │
3223       ├────────┼─────────────────────┼─────────────────────┤
3224       │        │                     │                     │
3225       │ssrr    │ Strict Source Route │ type, length, ptr,  │
3226       │        │                     │ addr                │
3227       └────────┴─────────────────────┴─────────────────────┘
3228
3229       finding TCP options.
3230
3231           filter input tcp option sack-perm exists counter
3232
3233       matching TCP options.
3234
3235           filter input tcp option maxseg size lt 536
3236
3237       matching IPv6 exthdr.
3238
3239           ip6 filter input frag more-fragments 1 counter
3240
3241       finding IP option.
3242
3243           filter input ip option lsrr exists counter
3244
3245
3246   CONNTRACK EXPRESSIONS
3247       Conntrack expressions refer to meta data of the connection tracking
3248       entry associated with a packet.
3249
3250       There are three types of conntrack expressions. Some conntrack
3251       expressions require the flow direction before the conntrack key, others
3252       must be used directly because they are direction agnostic. The packets,
3253       bytes and avgpkt keywords can be used with or without a direction. If
3254       the direction is omitted, the sum of the original and the reply
3255       direction is returned. The same is true for the zone, if a direction is
3256       given, the zone is only matched if the zone id is tied to the given
3257       direction.
3258
3259           ct {state | direction | status | mark | expiration | helper | label | count | id}
3260           ct [original | reply] {l3proto | protocol | bytes | packets | avgpkt | zone}
3261           ct {original | reply} {proto-src | proto-dst}
3262           ct {original | reply} {ip | ip6} {saddr | daddr}
3263
3264       The conntrack-specific types in this table are described in the
3265       sub-section CONNTRACK TYPES above.
3266
3267       Table 58. Conntrack expressions
3268       ┌───────────┬─────────────────────┬─────────────────────┐
3269Keyword    Description         Type                
3270       ├───────────┼─────────────────────┼─────────────────────┤
3271       │           │                     │                     │
3272       │state      │ State of the        │ ct_state            │
3273       │           │ connection          │                     │
3274       ├───────────┼─────────────────────┼─────────────────────┤
3275       │           │                     │                     │
3276       │direction  │ Direction of the    │ ct_dir              │
3277       │           │ packet relative to  │                     │
3278       │           │ the connection      │                     │
3279       ├───────────┼─────────────────────┼─────────────────────┤
3280       │           │                     │                     │
3281       │status     │ Status of the       │ ct_status           │
3282       │           │ connection          │                     │
3283       ├───────────┼─────────────────────┼─────────────────────┤
3284       │           │                     │                     │
3285       │mark       │ Connection mark     │ mark                │
3286       ├───────────┼─────────────────────┼─────────────────────┤
3287       │           │                     │                     │
3288       │expiration │ Connection          │ time                │
3289       │           │ expiration time     │                     │
3290       ├───────────┼─────────────────────┼─────────────────────┤
3291       │           │                     │                     │
3292       │helper     │ Helper associated   │ string              │
3293       │           │ with the connection │                     │
3294       ├───────────┼─────────────────────┼─────────────────────┤
3295       │           │                     │                     │
3296       │label      │ Connection tracking │ ct_label            │
3297       │           │ label bit or        │                     │
3298       │           │ symbolic name       │                     │
3299       │           │ defined in          │                     │
3300       │           │ connlabel.conf in   │                     │
3301       │           │ the nftables        │                     │
3302       │           │ include path        │                     │
3303       ├───────────┼─────────────────────┼─────────────────────┤
3304       │           │                     │                     │
3305       │l3proto    │ Layer 3 protocol of │ nf_proto            │
3306       │           │ the connection      │                     │
3307       ├───────────┼─────────────────────┼─────────────────────┤
3308       │           │                     │                     │
3309       │saddr      │ Source address of   │ ipv4_addr/ipv6_addr │
3310       │           │ the connection for  │                     │
3311       │           │ the given direction │                     │
3312       ├───────────┼─────────────────────┼─────────────────────┤
3313       │           │                     │                     │
3314       │daddr      │ Destination address │ ipv4_addr/ipv6_addr │
3315       │           │ of the connection   │                     │
3316       │           │ for the given       │                     │
3317       │           │ direction           │                     │
3318       ├───────────┼─────────────────────┼─────────────────────┤
3319       │           │                     │                     │
3320       │protocol   │ Layer 4 protocol of │ inet_proto          │
3321       │           │ the connection for  │                     │
3322       │           │ the given direction │                     │
3323       ├───────────┼─────────────────────┼─────────────────────┤
3324       │           │                     │                     │
3325       │proto-src  │ Layer 4 protocol    │ integer (16 bit)    │
3326       │           │ source for the      │                     │
3327       │           │ given direction     │                     │
3328       ├───────────┼─────────────────────┼─────────────────────┤
3329       │           │                     │                     │
3330       │proto-dst  │ Layer 4 protocol    │ integer (16 bit)    │
3331       │           │ destination for the │                     │
3332       │           │ given direction     │                     │
3333       ├───────────┼─────────────────────┼─────────────────────┤
3334       │           │                     │                     │
3335       │packets    │ packet count seen   │ integer (64 bit)    │
3336       │           │ in the given        │                     │
3337       │           │ direction or sum of │                     │
3338       │           │ original and reply  │                     │
3339       ├───────────┼─────────────────────┼─────────────────────┤
3340       │           │                     │                     │
3341       │bytes      │ byte count seen,    │ integer (64 bit)    │
3342       │           │ see description for │                     │
3343       │           │ packets keyword     │                     │
3344       ├───────────┼─────────────────────┼─────────────────────┤
3345       │           │                     │                     │
3346       │avgpkt     │ average bytes per   │ integer (64 bit)    │
3347       │           │ packet, see         │                     │
3348       │           │ description for     │                     │
3349       │           │ packets keyword     │                     │
3350       ├───────────┼─────────────────────┼─────────────────────┤
3351       │           │                     │                     │
3352       │zone       │ conntrack zone      │ integer (16 bit)    │
3353       ├───────────┼─────────────────────┼─────────────────────┤
3354       │           │                     │                     │
3355       │count      │ number of current   │ integer (32 bit)    │
3356       │           │ connections         │                     │
3357       ├───────────┼─────────────────────┼─────────────────────┤
3358       │           │                     │                     │
3359       │id         │ Connection id       │ ct_id               │
3360       └───────────┴─────────────────────┴─────────────────────┘
3361
3362       restrict the number of parallel connections to a server.
3363
3364           nft add set filter ssh_flood '{ type ipv4_addr; flags dynamic; }'
3365           nft add rule filter input tcp dport 22 add @ssh_flood '{ ip saddr ct count over 2 }' reject
3366
3367

STATEMENTS

3369       Statements represent actions to be performed. They can alter control
3370       flow (return, jump to a different chain, accept or drop the packet) or
3371       can perform actions, such as logging, rejecting a packet, etc.
3372
3373       Statements exist in two kinds. Terminal statements unconditionally
3374       terminate evaluation of the current rule, non-terminal statements
3375       either only conditionally or never terminate evaluation of the current
3376       rule, in other words, they are passive from the ruleset evaluation
3377       perspective. There can be an arbitrary amount of non-terminal
3378       statements in a rule, but only a single terminal statement as the final
3379       statement.
3380
3381   VERDICT STATEMENT
3382       The verdict statement alters control flow in the ruleset and issues
3383       policy decisions for packets.
3384
3385           {accept | drop | queue | continue | return}
3386           {jump | goto} chain
3387
3388       accept and drop are absolute verdicts — they terminate ruleset
3389       evaluation immediately.
3390
3391
3392       accept       Terminate ruleset
3393                    evaluation and accept the
3394                    packet. The packet can
3395                    still be dropped later by
3396                    another hook, for instance
3397                    accept in the forward hook
3398                    still allows to drop the
3399                    packet later in the
3400                    postrouting hook, or
3401                    another forward base chain
3402                    that has a higher priority
3403                    number and is evaluated
3404                    afterwards in the
3405                    processing pipeline.
3406
3407       drop         Terminate ruleset
3408                    evaluation and drop the
3409                    packet. The drop occurs
3410                    instantly, no further
3411                    chains or hooks are
3412                    evaluated. It is not
3413                    possible to accept the
3414                    packet in a later chain
3415                    again, as those are not
3416                    evaluated anymore for the
3417                    packet.
3418
3419       queue        Terminate ruleset
3420                    evaluation and queue the
3421                    packet to userspace.
3422                    Userspace must provide a
3423                    drop or accept verdict. In
3424                    case of accept, processing
3425                    resumes with the next base
3426                    chain hook, not the rule
3427                    following the queue
3428                    verdict.
3429
3430       continue     Continue ruleset
3431                    evaluation with the next
3432                    rule. This is the default
3433                    behaviour in case a rule
3434                    issues no verdict.
3435
3436       return       Return from the current
3437                    chain and continue
3438                    evaluation at the next
3439                    rule in the last chain. If
3440                    issued in a base chain, it
3441                    is equivalent to the base
3442                    chain policy.
3443
3444       jump chain   Continue evaluation at the
3445                    first rule in chain. The
3446                    current position in the
3447                    ruleset is pushed to a
3448                    call stack and evaluation
3449                    will continue there when
3450                    the new chain is entirely
3451                    evaluated or a return
3452                    verdict is issued. In case
3453                    an absolute verdict is
3454                    issued by a rule in the
3455                    chain, ruleset evaluation
3456                    terminates immediately and
3457                    the specific action is
3458                    taken.
3459
3460       goto chain   Similar to jump, but the
3461                    current position is not
3462                    pushed to the call stack,
3463                    meaning that after the new
3464                    chain evaluation will
3465                    continue at the last chain
3466                    instead of the one
3467                    containing the goto
3468                    statement.
3469
3470
3471       Using verdict statements.
3472
3473           # process packets from eth0 and the internal network in from_lan
3474           # chain, drop all packets from eth0 with different source addresses.
3475
3476           filter input iif eth0 ip saddr 192.168.0.0/24 jump from_lan
3477           filter input iif eth0 drop
3478
3479
3480   PAYLOAD STATEMENT
3481           payload_expression set value
3482
3483       The payload statement alters packet content. It can be used for example
3484       to set ip DSCP (diffserv) header field or ipv6 flow labels.
3485
3486       route some packets instead of bridging.
3487
3488           # redirect tcp:http from 192.160.0.0/16 to local machine for routing instead of bridging
3489           # assumes 00:11:22:33:44:55 is local MAC address.
3490           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
3491
3492       Set IPv4 DSCP header field.
3493
3494           ip forward ip dscp set 42
3495
3496
3497   EXTENSION HEADER STATEMENT
3498           extension_header_expression set value
3499
3500       The extension header statement alters packet content in variable-sized
3501       headers. This can currently be used to alter the TCP Maximum segment
3502       size of packets, similar to the TCPMSS target in iptables.
3503
3504       change tcp mss.
3505
3506           tcp flags syn tcp option maxseg size set 1360
3507           # set a size based on route information:
3508           tcp flags syn tcp option maxseg size set rt mtu
3509
3510       You can also remove tcp options via reset keyword.
3511
3512       remove tcp option.
3513
3514           tcp flags syn reset tcp option sack-perm
3515
3516
3517   LOG STATEMENT
3518           log [prefix quoted_string] [level syslog-level] [flags log-flags]
3519           log group nflog_group [prefix quoted_string] [queue-threshold value] [snaplen size]
3520           log level audit
3521
3522       The log statement enables logging of matching packets. When this
3523       statement is used from a rule, the Linux kernel will print some
3524       information on all matching packets, such as header fields, via the
3525       kernel log (where it can be read with dmesg(1) or read in the syslog).
3526
3527       In the second form of invocation (if nflog_group is specified), the
3528       Linux kernel will pass the packet to nfnetlink_log which will send the
3529       log through a netlink socket to the specified group. One userspace
3530       process may subscribe to the group to receive the logs, see man(8)
3531       ulogd for the Netfilter userspace log daemon and libnetfilter_log
3532       documentation for details in case you would like to develop a custom
3533       program to digest your logs.
3534
3535       In the third form of invocation (if level audit is specified), the
3536       Linux kernel writes a message into the audit buffer suitably formatted
3537       for reading with auditd. Therefore no further formatting options (such
3538       as prefix or flags) are allowed in this mode.
3539
3540       This is a non-terminating statement, so the rule evaluation continues
3541       after the packet is logged.
3542
3543       Table 59. log statement options
3544       ┌────────────────┬─────────────────────┬───────────────────┐
3545Keyword         Description         Type              
3546       ├────────────────┼─────────────────────┼───────────────────┤
3547       │                │                     │                   │
3548       │prefix          │ Log message prefix  │ quoted string     │
3549       ├────────────────┼─────────────────────┼───────────────────┤
3550       │                │                     │                   │
3551       │level           │ Syslog level of     │ string: emerg,    │
3552       │                │ logging             │ alert, crit, err, │
3553       │                │                     │ warn [default],   │
3554       │                │                     │ notice, info,     │
3555       │                │                     │ debug, audit      │
3556       ├────────────────┼─────────────────────┼───────────────────┤
3557       │                │                     │                   │
3558       │group           │ NFLOG group to send │ unsigned integer  │
3559       │                │ messages to         │ (16 bit)          │
3560       ├────────────────┼─────────────────────┼───────────────────┤
3561       │                │                     │                   │
3562       │snaplen         │ Length of packet    │ unsigned integer  │
3563       │                │ payload to include  │ (32 bit)          │
3564       │                │ in netlink message  │                   │
3565       ├────────────────┼─────────────────────┼───────────────────┤
3566       │                │                     │                   │
3567       │queue-threshold │ Number of packets   │ unsigned integer  │
3568       │                │ to queue inside the │ (32 bit)          │
3569       │                │ kernel before       │                   │
3570       │                │ sending them to     │                   │
3571       │                │ userspace           │                   │
3572       └────────────────┴─────────────────────┴───────────────────┘
3573
3574       Table 60. log-flags
3575       ┌─────────────┬───────────────────────────┐
3576Flag         Description               
3577       ├─────────────┼───────────────────────────┤
3578       │             │                           │
3579       │tcp sequence │ Log TCP sequence numbers. │
3580       ├─────────────┼───────────────────────────┤
3581       │             │                           │
3582       │tcp options  │ Log options from the TCP  │
3583       │             │ packet header.            │
3584       ├─────────────┼───────────────────────────┤
3585       │             │                           │
3586       │ip options   │ Log options from the      │
3587       │             │ IP/IPv6 packet header.    │
3588       ├─────────────┼───────────────────────────┤
3589       │             │                           │
3590       │skuid        │ Log the userid of the     │
3591       │             │ process which generated   │
3592       │             │ the packet.               │
3593       ├─────────────┼───────────────────────────┤
3594       │             │                           │
3595       │ether        │ Decode MAC addresses and  │
3596       │             │ protocol.                 │
3597       ├─────────────┼───────────────────────────┤
3598       │             │                           │
3599       │all          │ Enable all log flags      │
3600       │             │ listed above.             │
3601       └─────────────┴───────────────────────────┘
3602
3603       Using log statement.
3604
3605           # log the UID which generated the packet and ip options
3606           ip filter output log flags skuid flags ip options
3607
3608           # log the tcp sequence numbers and tcp options from the TCP packet
3609           ip filter output log flags tcp sequence,options
3610
3611           # enable all supported log flags
3612           ip6 filter output log flags all
3613
3614
3615   REJECT STATEMENT
3616           reject [ with REJECT_WITH ]
3617
3618           REJECT_WITH := icmp icmp_code |
3619                            icmpv6 icmpv6_code |
3620                            icmpx icmpx_code |
3621                            tcp reset
3622
3623       A reject statement is used to send back an error packet in response to
3624       the matched packet otherwise it is equivalent to drop so it is a
3625       terminating statement, ending rule traversal. This statement is only
3626       valid in base chains using the input, forward or output hooks, and
3627       user-defined chains which are only called from those chains.
3628
3629       Table 61. different ICMP reject variants are meant for use in different
3630       table families
3631       ┌────────┬────────┬─────────────┐
3632Variant Family Type        
3633       ├────────┼────────┼─────────────┤
3634       │        │        │             │
3635       │icmp    │ ip     │ icmp_code   │
3636       ├────────┼────────┼─────────────┤
3637       │        │        │             │
3638       │icmpv6  │ ip6    │ icmpv6_code │
3639       ├────────┼────────┼─────────────┤
3640       │        │        │             │
3641       │icmpx   │ inet   │ icmpx_code  │
3642       └────────┴────────┴─────────────┘
3643
3644       For a description of the different types and a list of supported
3645       keywords refer to DATA TYPES section above. The common default reject
3646       value is port-unreachable.
3647
3648       Note that in bridge family, reject statement is only allowed in base
3649       chains which hook into input or prerouting.
3650
3651   COUNTER STATEMENT
3652       A counter statement sets the hit count of packets along with the number
3653       of bytes.
3654
3655           counter packets number bytes number
3656           counter { packets number | bytes number }
3657
3658   CONNTRACK STATEMENT
3659       The conntrack statement can be used to set the conntrack mark and
3660       conntrack labels.
3661
3662           ct {mark | event | label | zone} set value
3663
3664       The ct statement sets meta data associated with a connection. The zone
3665       id has to be assigned before a conntrack lookup takes place, i.e. this
3666       has to be done in prerouting and possibly output (if locally generated
3667       packets need to be placed in a distinct zone), with a hook priority of
3668       raw (-300).
3669
3670       Unlike iptables, where the helper assignment happens in the raw table,
3671       the helper needs to be assigned after a conntrack entry has been found,
3672       i.e. it will not work when used with hook priorities equal or before
3673       -200.
3674
3675       Table 62. Conntrack statement types
3676       ┌────────┬─────────────────────┬──────────────────┐
3677Keyword Description         Value            
3678       ├────────┼─────────────────────┼──────────────────┤
3679       │        │                     │                  │
3680       │event   │ conntrack event     │ bitmask, integer │
3681       │        │ bits                │ (32 bit)         │
3682       ├────────┼─────────────────────┼──────────────────┤
3683       │        │                     │                  │
3684       │helper  │ name of ct helper   │ quoted string    │
3685       │        │ object to assign to │                  │
3686       │        │ the connection      │                  │
3687       ├────────┼─────────────────────┼──────────────────┤
3688       │        │                     │                  │
3689       │mark    │ Connection tracking │ mark             │
3690       │        │ mark                │                  │
3691       ├────────┼─────────────────────┼──────────────────┤
3692       │        │                     │                  │
3693       │label   │ Connection tracking │ label            │
3694       │        │ label               │                  │
3695       ├────────┼─────────────────────┼──────────────────┤
3696       │        │                     │                  │
3697       │zone    │ conntrack zone      │ integer (16 bit) │
3698       └────────┴─────────────────────┴──────────────────┘
3699
3700       save packet nfmark in conntrack.
3701
3702           ct mark set meta mark
3703
3704       set zone mapped via interface.
3705
3706           table inet raw {
3707             chain prerouting {
3708                 type filter hook prerouting priority raw;
3709                 ct zone set iif map { "eth1" : 1, "veth1" : 2 }
3710             }
3711             chain output {
3712                 type filter hook output priority raw;
3713                 ct zone set oif map { "eth1" : 1, "veth1" : 2 }
3714             }
3715           }
3716
3717       restrict events reported by ctnetlink.
3718
3719           ct event set new,related,destroy
3720
3721
3722   NOTRACK STATEMENT
3723       The notrack statement allows to disable connection tracking for certain
3724       packets.
3725
3726           notrack
3727
3728       Note that for this statement to be effective, it has to be applied to
3729       packets before a conntrack lookup happens. Therefore, it needs to sit
3730       in a chain with either prerouting or output hook and a hook priority of
3731       -300 (raw) or less.
3732
3733       See SYNPROXY STATEMENT for an example usage.
3734
3735   META STATEMENT
3736       A meta statement sets the value of a meta expression. The existing meta
3737       fields are: priority, mark, pkttype, nftrace.
3738
3739           meta {mark | priority | pkttype | nftrace} set value
3740
3741       A meta statement sets meta data associated with a packet.
3742
3743       Table 63. Meta statement types
3744       ┌─────────┬─────────────────────┬───────────┐
3745Keyword  Description         Value     
3746       ├─────────┼─────────────────────┼───────────┤
3747       │         │                     │           │
3748       │priority │ TC packet priority  │ tc_handle │
3749       ├─────────┼─────────────────────┼───────────┤
3750       │         │                     │           │
3751       │mark     │ Packet mark         │ mark      │
3752       ├─────────┼─────────────────────┼───────────┤
3753       │         │                     │           │
3754       │pkttype  │ packet type         │ pkt_type  │
3755       ├─────────┼─────────────────────┼───────────┤
3756       │         │                     │           │
3757       │nftrace  │ ruleset packet      │ 0, 1      │
3758       │         │ tracing on/off. Use │           │
3759       │         │ monitor trace       │           │
3760       │         │ command to watch    │           │
3761       │         │ traces              │           │
3762       └─────────┴─────────────────────┴───────────┘
3763
3764   LIMIT STATEMENT
3765           limit rate [over] packet_number / TIME_UNIT [burst packet_number packets]
3766           limit rate [over] byte_number BYTE_UNIT / TIME_UNIT [burst byte_number BYTE_UNIT]
3767
3768           TIME_UNIT := second | minute | hour | day
3769           BYTE_UNIT := bytes | kbytes | mbytes
3770
3771       A limit statement matches at a limited rate using a token bucket
3772       filter. A rule using this statement will match until this limit is
3773       reached. It can be used in combination with the log statement to give
3774       limited logging. The optional over keyword makes it match over the
3775       specified rate. Default burst is 5. if you specify burst, it must be
3776       non-zero value.
3777
3778       Table 64. limit statement values
3779       ┌──────────────┬───────────────────┬──────────────────┐
3780Value         Description       Type             
3781       ├──────────────┼───────────────────┼──────────────────┤
3782       │              │                   │                  │
3783       │packet_number │ Number of packets │ unsigned integer │
3784       │              │                   │ (32 bit)         │
3785       ├──────────────┼───────────────────┼──────────────────┤
3786       │              │                   │                  │
3787       │byte_number   │ Number of bytes   │ unsigned integer │
3788       │              │                   │ (32 bit)         │
3789       └──────────────┴───────────────────┴──────────────────┘
3790
3791   NAT STATEMENTS
3792           snat [[ip | ip6] to] ADDR_SPEC [:PORT_SPEC] [FLAGS]
3793           dnat [[ip | ip6] to] ADDR_SPEC [:PORT_SPEC] [FLAGS]
3794           masquerade [to :PORT_SPEC] [FLAGS]
3795           redirect [to :PORT_SPEC] [FLAGS]
3796
3797           ADDR_SPEC := address | address - address
3798           PORT_SPEC := port | port - port
3799
3800           FLAGS  := FLAG [, FLAGS]
3801           FLAG  := persistent | random | fully-random
3802
3803       The nat statements are only valid from nat chain types.
3804
3805       The snat and masquerade statements specify that the source address of
3806       the packet should be modified. While snat is only valid in the
3807       postrouting and input chains, masquerade makes sense only in
3808       postrouting. The dnat and redirect statements are only valid in the
3809       prerouting and output chains, they specify that the destination address
3810       of the packet should be modified. You can use non-base chains which are
3811       called from base chains of nat chain type too. All future packets in
3812       this connection will also be mangled, and rules should cease being
3813       examined.
3814
3815       The masquerade statement is a special form of snat which always uses
3816       the outgoing interface’s IP address to translate to. It is particularly
3817       useful on gateways with dynamic (public) IP addresses.
3818
3819       The redirect statement is a special form of dnat which always
3820       translates the destination address to the local host’s one. It comes in
3821       handy if one only wants to alter the destination port of incoming
3822       traffic on different interfaces.
3823
3824       When used in the inet family (available with kernel 5.2), the dnat and
3825       snat statements require the use of the ip and ip6 keyword in case an
3826       address is provided, see the examples below.
3827
3828       Before kernel 4.18 nat statements require both prerouting and
3829       postrouting base chains to be present since otherwise packets on the
3830       return path won’t be seen by netfilter and therefore no reverse
3831       translation will take place.
3832
3833       Table 65. NAT statement values
3834       ┌───────────┬─────────────────────┬─────────────────────┐
3835Expression Description         Type                
3836       ├───────────┼─────────────────────┼─────────────────────┤
3837       │           │                     │                     │
3838       │address    │ Specifies that the  │ ipv4_addr,          │
3839       │           │ source/destination  │ ipv6_addr, e.g.     │
3840       │           │ address of the      │ abcd::1234, or you  │
3841       │           │ packet should be    │ can use a mapping,  │
3842       │           │ modified. You may   │ e.g. meta mark map  │
3843       │           │ specify a mapping   │ { 10 : 192.168.1.2, │
3844       │           │ to relate a list of │ 20 : 192.168.1.3 }  │
3845       │           │ tuples composed of  │                     │
3846       │           │ arbitrary           │                     │
3847       │           │ expression key with │                     │
3848       │           │ address value.      │                     │
3849       ├───────────┼─────────────────────┼─────────────────────┤
3850       │           │                     │                     │
3851       │port       │ Specifies that the  │ port number (16     │
3852       │           │ source/destination  │ bit)                │
3853       │           │ address of the      │                     │
3854       │           │ packet should be    │                     │
3855       │           │ modified.           │                     │
3856       └───────────┴─────────────────────┴─────────────────────┘
3857
3858       Table 66. NAT statement flags
3859       ┌─────────────┬─────────────────────────────┐
3860Flag         Description                 
3861       ├─────────────┼─────────────────────────────┤
3862       │             │                             │
3863       │persistent   │ Gives a client the same     │
3864       │             │ source-/destination-address │
3865       │             │ for each connection.        │
3866       ├─────────────┼─────────────────────────────┤
3867       │             │                             │
3868       │random       │ In kernel 5.0 and newer     │
3869       │             │ this is the same as         │
3870       │             │ fully-random. In earlier    │
3871       │             │ kernels the port mapping    │
3872       │             │ will be randomized using a  │
3873       │             │ seeded MD5 hash mix using   │
3874       │             │ source and destination      │
3875       │             │ address and destination     │
3876       │             │ port.                       │
3877       ├─────────────┼─────────────────────────────┤
3878       │             │                             │
3879       │fully-random │ If used then port mapping   │
3880       │             │ is generated based on a     │
3881       │             │ 32-bit pseudo-random        │
3882       │             │ algorithm.                  │
3883       └─────────────┴─────────────────────────────┘
3884
3885       Using NAT statements.
3886
3887           # create a suitable table/chain setup for all further examples
3888           add table nat
3889           add chain nat prerouting { type nat hook prerouting priority dstnat; }
3890           add chain nat postrouting { type nat hook postrouting priority srcnat; }
3891
3892           # translate source addresses of all packets leaving via eth0 to address 1.2.3.4
3893           add rule nat postrouting oif eth0 snat to 1.2.3.4
3894
3895           # redirect all traffic entering via eth0 to destination address 192.168.1.120
3896           add rule nat prerouting iif eth0 dnat to 192.168.1.120
3897
3898           # translate source addresses of all packets leaving via eth0 to whatever
3899           # locally generated packets would use as source to reach the same destination
3900           add rule nat postrouting oif eth0 masquerade
3901
3902           # redirect incoming TCP traffic for port 22 to port 2222
3903           add rule nat prerouting tcp dport 22 redirect to :2222
3904
3905           # inet family:
3906           # handle ip dnat:
3907           add rule inet nat prerouting dnat ip to 10.0.2.99
3908           # handle ip6 dnat:
3909           add rule inet nat prerouting dnat ip6 to fe80::dead
3910           # this masquerades both ipv4 and ipv6:
3911           add rule inet nat postrouting meta oif ppp0 masquerade
3912
3913
3914   TPROXY STATEMENT
3915       Tproxy redirects the packet to a local socket without changing the
3916       packet header in any way. If any of the arguments is missing the data
3917       of the incoming packet is used as parameter. Tproxy matching requires
3918       another rule that ensures the presence of transport protocol header is
3919       specified.
3920
3921           tproxy to address:port
3922           tproxy to {address | :port}
3923
3924       This syntax can be used in ip/ip6 tables where network layer protocol
3925       is obvious. Either IP address or port can be specified, but at least
3926       one of them is necessary.
3927
3928           tproxy {ip | ip6} to address[:port]
3929           tproxy to :port
3930
3931       This syntax can be used in inet tables. The ip/ip6 parameter defines
3932       the family the rule will match. The address parameter must be of this
3933       family. When only port is defined, the address family should not be
3934       specified. In this case the rule will match for both families.
3935
3936       Table 67. tproxy attributes
3937       ┌────────┬────────────────────────────┐
3938Name    Description                
3939       ├────────┼────────────────────────────┤
3940       │        │                            │
3941       │address │ IP address the listening   │
3942       │        │ socket with IP_TRANSPARENT │
3943       │        │ option is bound to.        │
3944       ├────────┼────────────────────────────┤
3945       │        │                            │
3946       │port    │ Port the listening socket  │
3947       │        │ with IP_TRANSPARENT option │
3948       │        │ is bound to.               │
3949       └────────┴────────────────────────────┘
3950
3951       Example ruleset for tproxy statement.
3952
3953           table ip x {
3954               chain y {
3955                   type filter hook prerouting priority mangle; policy accept;
3956                   tcp dport ntp tproxy to 1.1.1.1
3957                   udp dport ssh tproxy to :2222
3958               }
3959           }
3960           table ip6 x {
3961               chain y {
3962                  type filter hook prerouting priority mangle; policy accept;
3963                  tcp dport ntp tproxy to [dead::beef]
3964                  udp dport ssh tproxy to :2222
3965               }
3966           }
3967           table inet x {
3968               chain y {
3969                   type filter hook prerouting priority mangle; policy accept;
3970                   tcp dport 321 tproxy to :ssh
3971                   tcp dport 99 tproxy ip to 1.1.1.1:999
3972                   udp dport 155 tproxy ip6 to [dead::beef]:smux
3973               }
3974           }
3975
3976
3977   SYNPROXY STATEMENT
3978       This statement will process TCP three-way-handshake parallel in
3979       netfilter context to protect either local or backend system. This
3980       statement requires connection tracking because sequence numbers need to
3981       be translated.
3982
3983           synproxy [mss mss_value] [wscale wscale_value] [SYNPROXY_FLAGS]
3984
3985       Table 68. synproxy statement attributes
3986       ┌───────┬────────────────────────────┐
3987Name   Description                
3988       ├───────┼────────────────────────────┤
3989       │       │                            │
3990       │mss    │ Maximum segment size       │
3991       │       │ announced to clients. This │
3992       │       │ must match the backend.    │
3993       ├───────┼────────────────────────────┤
3994       │       │                            │
3995       │wscale │ Window scale announced to  │
3996       │       │ clients. This must match   │
3997       │       │ the backend.               │
3998       └───────┴────────────────────────────┘
3999
4000       Table 69. synproxy statement flags
4001       ┌──────────┬────────────────────────────┐
4002Flag      Description                
4003       ├──────────┼────────────────────────────┤
4004       │          │                            │
4005       │sack-perm │ Pass client selective      │
4006       │          │ acknowledgement option to  │
4007       │          │ backend (will be disabled  │
4008       │          │ if not present).           │
4009       ├──────────┼────────────────────────────┤
4010       │          │                            │
4011       │timestamp │ Pass client timestamp      │
4012       │          │ option to backend (will be │
4013       │          │ disabled if not present,   │
4014       │          │ also needed for selective  │
4015       │          │ acknowledgement and window │
4016       │          │ scaling).                  │
4017       └──────────┴────────────────────────────┘
4018
4019       Example ruleset for synproxy statement.
4020
4021           Determine tcp options used by backend, from an external system
4022
4023                         tcpdump -pni eth0 -c 1 'tcp[tcpflags] == (tcp-syn|tcp-ack)'
4024                             port 80 &
4025                         telnet 192.0.2.42 80
4026                         18:57:24.693307 IP 192.0.2.42.80 > 192.0.2.43.48757:
4027                             Flags [S.], seq 360414582, ack 788841994, win 14480,
4028                             options [mss 1460,sackOK,
4029                             TS val 1409056151 ecr 9690221,
4030                             nop,wscale 9],
4031                             length 0
4032
4033           Switch tcp_loose mode off, so conntrack will mark out-of-flow packets as state INVALID.
4034
4035                         echo 0 > /proc/sys/net/netfilter/nf_conntrack_tcp_loose
4036
4037           Make SYN packets untracked.
4038
4039                   table ip x {
4040                           chain y {
4041                                   type filter hook prerouting priority raw; policy accept;
4042                                   tcp flags syn notrack
4043                           }
4044                   }
4045
4046           Catch UNTRACKED (SYN  packets) and INVALID (3WHS ACK packets) states and send
4047           them to SYNPROXY. This rule will respond to SYN packets with SYN+ACK
4048           syncookies, create ESTABLISHED for valid client response (3WHS ACK packets) and
4049           drop incorrect cookies. Flags combinations not expected during  3WHS will not
4050           match and continue (e.g. SYN+FIN, SYN+ACK). Finally, drop invalid packets, this
4051           will be out-of-flow packets that were not matched by SYNPROXY.
4052
4053               table ip x {
4054                       chain z {
4055                               type filter hook input priority filter; policy accept;
4056                               ct state invalid, untracked synproxy mss 1460 wscale 9 timestamp sack-perm
4057                               ct state invalid drop
4058                       }
4059               }
4060
4061
4062   FLOW STATEMENT
4063       A flow statement allows us to select what flows you want to accelerate
4064       forwarding through layer 3 network stack bypass. You have to specify
4065       the flowtable name where you want to offload this flow.
4066
4067       flow add @flowtable
4068
4069   QUEUE STATEMENT
4070       This statement passes the packet to userspace using the nfnetlink_queue
4071       handler. The packet is put into the queue identified by its 16-bit
4072       queue number. Userspace can inspect and modify the packet if desired.
4073       Userspace must then drop or re-inject the packet into the kernel. See
4074       libnetfilter_queue documentation for details.
4075
4076           queue [flags QUEUE_FLAGS] [to queue_number]
4077           queue [flags QUEUE_FLAGS] [to queue_number_from - queue_number_to]
4078           queue [flags QUEUE_FLAGS] [to QUEUE_EXPRESSION ]
4079
4080           QUEUE_FLAGS := QUEUE_FLAG [, QUEUE_FLAGS]
4081           QUEUE_FLAG  := bypass | fanout
4082           QUEUE_EXPRESSION := numgen | hash | symhash | MAP STATEMENT
4083
4084       QUEUE_EXPRESSION can be used to compute a queue number at run-time with
4085       the hash or numgen expressions. It also allows to use the map statement
4086       to assign fixed queue numbers based on external inputs such as the
4087       source ip address or interface names.
4088
4089       Table 70. queue statement values
4090       ┌──────────────────┬────────────────────┬──────────────────┐
4091Value             Description        Type             
4092       ├──────────────────┼────────────────────┼──────────────────┤
4093       │                  │                    │                  │
4094       │queue_number      │ Sets queue number, │ unsigned integer │
4095       │                  │ default is 0.      │ (16 bit)         │
4096       ├──────────────────┼────────────────────┼──────────────────┤
4097       │                  │                    │                  │
4098       │queue_number_from │ Sets initial queue │ unsigned integer │
4099       │                  │ in the range, if   │ (16 bit)         │
4100       │                  │ fanout is used.    │                  │
4101       ├──────────────────┼────────────────────┼──────────────────┤
4102       │                  │                    │                  │
4103       │queue_number_to   │ Sets closing queue │ unsigned integer │
4104       │                  │ in the range, if   │ (16 bit)         │
4105       │                  │ fanout is used.    │                  │
4106       └──────────────────┴────────────────────┴──────────────────┘
4107
4108       Table 71. queue statement flags
4109       ┌───────┬────────────────────────────┐
4110Flag   Description                
4111       ├───────┼────────────────────────────┤
4112       │       │                            │
4113       │bypass │ Let packets go through if  │
4114       │       │ userspace application      │
4115       │       │ cannot back off. Before    │
4116       │       │ using this flag, read      │
4117       │       │ libnetfilter_queue         │
4118       │       │ documentation for          │
4119       │       │ performance tuning         │
4120       │       │ recommendations.           │
4121       ├───────┼────────────────────────────┤
4122       │       │                            │
4123       │fanout │ Distribute packets between │
4124       │       │ several queues.            │
4125       └───────┴────────────────────────────┘
4126
4127   DUP STATEMENT
4128       The dup statement is used to duplicate a packet and send the copy to a
4129       different destination.
4130
4131           dup to device
4132           dup to address device device
4133
4134       Table 72. Dup statement values
4135       ┌───────────┬─────────────────────┬─────────────────────┐
4136Expression Description         Type                
4137       ├───────────┼─────────────────────┼─────────────────────┤
4138       │           │                     │                     │
4139       │address    │ Specifies that the  │ ipv4_addr,          │
4140       │           │ copy of the packet  │ ipv6_addr, e.g.     │
4141       │           │ should be sent to a │ abcd::1234, or you  │
4142       │           │ new gateway.        │ can use a mapping,  │
4143       │           │                     │ e.g. ip saddr map { │
4144       │           │                     │ 192.168.1.2 :       │
4145       │           │                     │ 10.1.1.1 }          │
4146       ├───────────┼─────────────────────┼─────────────────────┤
4147       │           │                     │                     │
4148       │device     │ Specifies that the  │ string              │
4149       │           │ copy should be      │                     │
4150       │           │ transmitted via     │                     │
4151       │           │ device.             │                     │
4152       └───────────┴─────────────────────┴─────────────────────┘
4153
4154       Using the dup statement.
4155
4156           # send to machine with ip address 10.2.3.4 on eth0
4157           ip filter forward dup to 10.2.3.4 device "eth0"
4158
4159           # copy raw frame to another interface
4160           netdev ingress dup to "eth0"
4161           dup to "eth0"
4162
4163           # combine with map dst addr to gateways
4164           dup to ip daddr map { 192.168.7.1 : "eth0", 192.168.7.2 : "eth1" }
4165
4166
4167   FWD STATEMENT
4168       The fwd statement is used to redirect a raw packet to another
4169       interface. It is only available in the netdev family ingress and egress
4170       hooks. It is similar to the dup statement except that no copy is made.
4171
4172       fwd to device
4173
4174   SET STATEMENT
4175       The set statement is used to dynamically add or update elements in a
4176       set from the packet path. The set setname must already exist in the
4177       given table and must have been created with one or both of the dynamic
4178       and the timeout flags. The dynamic flag is required if the set
4179       statement expression includes a stateful object. The timeout flag is
4180       implied if the set is created with a timeout, and is required if the
4181       set statement updates elements, rather than adding them. Furthermore,
4182       these sets should specify both a maximum set size (to prevent memory
4183       exhaustion), and their elements should have a timeout (so their number
4184       will not grow indefinitely) either from the set definition or from the
4185       statement that adds or updates them. The set statement can be used to
4186       e.g. create dynamic blacklists.
4187
4188           {add | update} @setname { expression [timeout timeout] [comment string] }
4189
4190       Example for simple blacklist.
4191
4192           # declare a set, bound to table "filter", in family "ip".
4193           # Timeout and size are mandatory because we will add elements from packet path.
4194           # Entries will timeout after one minute, after which they might be
4195           # re-added if limit condition persists.
4196           nft add set ip filter blackhole \
4197               "{ type ipv4_addr; flags dynamic; timeout 1m; size 65536; }"
4198
4199           # declare a set to store the limit per saddr.
4200           # This must be separate from blackhole since the timeout is different
4201           nft add set ip filter flood \
4202               "{ type ipv4_addr; flags dynamic; timeout 10s; size 128000; }"
4203
4204           # whitelist internal interface.
4205           nft add rule ip filter input meta iifname "internal" accept
4206
4207           # drop packets coming from blacklisted ip addresses.
4208           nft add rule ip filter input ip saddr @blackhole counter drop
4209
4210           # add source ip addresses to the blacklist if more than 10 tcp connection
4211           # requests occurred per second and ip address.
4212           nft add rule ip filter input tcp flags syn tcp dport ssh \
4213               add @flood { ip saddr limit rate over 10/second } \
4214               add @blackhole { ip saddr } \
4215               drop
4216
4217           # inspect state of the sets.
4218           nft list set ip filter flood
4219           nft list set ip filter blackhole
4220
4221           # manually add two addresses to the blackhole.
4222           nft add element filter blackhole { 10.2.3.4, 10.23.1.42 }
4223
4224
4225   MAP STATEMENT
4226       The map statement is used to lookup data based on some specific input
4227       key.
4228
4229           expression map { MAP_ELEMENTS }
4230
4231           MAP_ELEMENTS := MAP_ELEMENT [, MAP_ELEMENTS]
4232           MAP_ELEMENT  := key : value
4233
4234       The key is a value returned by expression.
4235
4236       Using the map statement.
4237
4238           # select DNAT target based on TCP dport:
4239           # connections to port 80 are redirected to 192.168.1.100,
4240           # connections to port 8888 are redirected to 192.168.1.101
4241           nft add rule ip nat prerouting dnat tcp dport map { 80 : 192.168.1.100, 8888 : 192.168.1.101 }
4242
4243           # source address based SNAT:
4244           # packets from net 192.168.1.0/24 will appear as originating from 10.0.0.1,
4245           # packets from net 192.168.2.0/24 will appear as originating from 10.0.0.2
4246           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 }
4247
4248
4249   VMAP STATEMENT
4250       The verdict map (vmap) statement works analogous to the map statement,
4251       but contains verdicts as values.
4252
4253           expression vmap { VMAP_ELEMENTS }
4254
4255           VMAP_ELEMENTS := VMAP_ELEMENT [, VMAP_ELEMENTS]
4256           VMAP_ELEMENT  := key : verdict
4257
4258       Using the vmap statement.
4259
4260           # jump to different chains depending on layer 4 protocol type:
4261           nft add rule ip filter input ip protocol vmap { tcp : jump tcp-chain, udp : jump udp-chain , icmp : jump icmp-chain }
4262
4263

ADDITIONAL COMMANDS

4265       These are some additional commands included in nft.
4266
4267   MONITOR
4268       The monitor command allows you to listen to Netlink events produced by
4269       the nf_tables subsystem. These are either related to creation and
4270       deletion of objects or to packets for which meta nftrace was enabled.
4271       When they occur, nft will print to stdout the monitored events in
4272       either JSON or native nft format.
4273
4274           monitor [new | destroy] MONITOR_OBJECT
4275           monitor trace
4276
4277           MONITOR_OBJECT := tables | chains | sets | rules | elements | ruleset
4278
4279       To filter events related to a concrete object, use one of the keywords
4280       in MONITOR_OBJECT.
4281
4282       To filter events related to a concrete action, use keyword new or
4283       destroy.
4284
4285       The second form of invocation takes no further options and exclusively
4286       prints events generated for packets with nftrace enabled.
4287
4288       Hit ^C to finish the monitor operation.
4289
4290       Listen to all events, report in native nft format.
4291
4292           % nft monitor
4293
4294       Listen to deleted rules, report in JSON format.
4295
4296           % nft -j monitor destroy rules
4297
4298       Listen to both new and destroyed chains, in native nft format.
4299
4300           % nft monitor chains
4301
4302       Listen to ruleset events such as table, chain, rule, set, counters and
4303       quotas, in native nft format.
4304
4305           % nft monitor ruleset
4306
4307       Trace incoming packets from host 10.0.0.1.
4308
4309           % nft add rule filter input ip saddr 10.0.0.1 meta nftrace set 1
4310           % nft monitor trace
4311
4312

ERROR REPORTING

4314       When an error is detected, nft shows the line(s) containing the error,
4315       the position of the erroneous parts in the input stream and marks up
4316       the erroneous parts using carets (^). If the error results from the
4317       combination of two expressions or statements, the part imposing the
4318       constraints which are violated is marked using tildes (~).
4319
4320       For errors returned by the kernel, nft cannot detect which parts of the
4321       input caused the error and the entire command is marked.
4322
4323       Error caused by single incorrect expression.
4324
4325           <cmdline>:1:19-22: Error: Interface does not exist
4326           filter output oif eth0
4327                             ^^^^
4328
4329       Error caused by invalid combination of two expressions.
4330
4331           <cmdline>:1:28-36: Error: Right hand side of relational expression (==) must be constant
4332           filter output tcp dport == tcp dport
4333                                   ~~ ^^^^^^^^^
4334
4335       Error returned by the kernel.
4336
4337           <cmdline>:0:0-23: Error: Could not process rule: Operation not permitted
4338           filter output oif wlan0
4339           ^^^^^^^^^^^^^^^^^^^^^^^
4340
4341

EXIT STATUS

4343       On success, nft exits with a status of 0. Unspecified errors cause it
4344       to exit with a status of 1, memory allocation errors with a status of
4345       2, unable to open Netlink socket with 3.
4346

SEE ALSO

4348           libnftables(3), libnftables-json(5), iptables(8), ip6tables(8), arptables(8), ebtables(8), ip(8), tc(8)
4349
4350       There is an official wiki at: https://wiki.nftables.org
4351

AUTHORS

4353       nftables was written by Patrick McHardy and Pablo Neira Ayuso, among
4354       many other contributors from the Netfilter community.
4355
4357       Copyright © 2008-2014 Patrick McHardy <kaber@trash.net> Copyright ©
4358       2013-2018 Pablo Neira Ayuso <pablo@netfilter.org>
4359
4360       nftables is free software; you can redistribute it and/or modify it
4361       under the terms of the GNU General Public License version 2 as
4362       published by the Free Software Foundation.
4363
4364       This documentation is licensed under the terms of the Creative Commons
4365       Attribution-ShareAlike 4.0 license, CC BY-SA 4.0
4366       http://creativecommons.org/licenses/by-sa/4.0/.
4367
4368
4369
4370                                  06/07/2022                            NFT(8)
Impressum