summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArushi Singhal <arushisinghal19971997@gmail.com>2018-07-25 16:56:43 +0530
committerFlorian Westphal <fw@strlen.de>2018-07-26 14:47:26 +0200
commita277479dc94fdcc340337b1683644cab40f57bf9 (patch)
tree89222b222dc12083e42476d9515f8b8c617555d7
parentf8c35865d3ed2e8399f7630891be650a188dc3b9 (diff)
nft: doc: Convert man page source to asciidoc
This patch converts nft.xml into asciidoc markup. Signed-off-by: Arushi Singhal <arushisinghal19971997@gmail.com> Signed-off-by: Florian Westphal <fw@strlen.de>
-rw-r--r--configure.ac18
-rw-r--r--doc/Makefile.am21
-rw-r--r--doc/data-types.txt485
-rw-r--r--doc/nft.txt619
-rw-r--r--doc/nft.xml5723
-rw-r--r--doc/payload-expression.txt590
-rw-r--r--doc/primary-expression.txt226
-rw-r--r--doc/stateful-objects.txt71
-rw-r--r--doc/statements.txt425
9 files changed, 2435 insertions, 5743 deletions
diff --git a/configure.ac b/configure.ac
index b1a790d0..c1c9035f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -54,25 +54,15 @@ fi
AM_PROG_AR
AM_PROG_LIBTOOL
-AM_COND_IF([BUILD_MAN], [
- AC_CHECK_PROG(DOCBOOK2X_MAN, [docbook2x-man], [docbook2x-man], [no])
- AC_CHECK_PROG(DB2X_DOCBOOK2MAN, [db2x_docbook2man], [db2x_docbook2man], [no])
- AS_IF([test "$DOCBOOK2X_MAN" != "no"], [DB2MAN="$DOCBOOK2X_MAN"],
- [AS_IF([test "$DB2X_DOCBOOK2MAN" != "no"],
- [DB2MAN="$DB2X_DOCBOOK2MAN --xinclude"],
- [AC_MSG_ERROR([docbook2x-man/db2x_docbook2man not found, required for building man pages])]
- )]
- )
- AC_SUBST(DB2MAN)
-
- [need_a2x=yes]
-])
+AC_CHECK_PROG(A2X, [a2x], [a2x])
+AM_CONDITIONAL([BUILD_MAN], [test -n "$A2X"])
AM_COND_IF([BUILD_PDF], [
AC_CHECK_PROG(DBLATEX, [dblatex], [found], [no])
AS_IF([test "$DBLATEX" == "no"],
[AC_MSG_ERROR([dblatex not found])])
-
+ AS_IF([test -z "$A2X"],
+ [AC_MSG_ERROR([a2x not found])])
[need_a2x=yes]
])
diff --git a/doc/Makefile.am b/doc/Makefile.am
index 1ec3b3e3..8978a156 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -6,13 +6,22 @@ if BUILD_PDF
pdf_DATA = nft.pdf libnftables-json.pdf libnftables.pdf
endif
+ASCIIDOC_MAIN = nft.txt
+ASCIIDOC_INCLUDES = \
+ data-types.txt \
+ payload-expression.txt \
+ primary-expression.txt \
+ stateful-objects.txt \
+ statements.txt
+ASCIIDOCS = ${ASCIIDOC_MAIN} ${ASCIIDOC_INCLUDES}
+
pdfdir=${docdir}/pdf
-.xml.pdf:
- ${AM_V_GEN}dblatex -q -t pdf -o ${builddir}/$@ $<
+nft.8: ${ASCIIDOCS}
+ ${AM_V_GEN}${A2X} --doctype manpage --format manpage ${ASCIIDOC_MAIN}
-.xml.8:
- ${AM_V_GEN}${DB2MAN} --xinclude $<
+nft.pdf: ${ASCIIDOCS}
+ ${AM_V_GEN}${A2X} --doctype manpage --format pdf ${ASCIIDOC_MAIN}
.adoc.pdf:
a2x --doctype manpage --format pdf -D ${builddir} $<
@@ -23,10 +32,10 @@ pdfdir=${docdir}/pdf
.adoc.5:
a2x --doctype manpage --format manpage -D ${builddir} $<
-EXTRA_DIST = nft.xml libnftables-json.adoc libnftables.adoc
+EXTRA_DIST = ${ASCIIDOCS} libnftables-json.adoc libnftables.adoc
CLEANFILES = \
- nft.pdf nft.8 \
+ nft.xml nft.pdf nft.8 \
libnftables-json.pdf libnftables-json.5 \
libnftables.pdf libnftables.3 \
*~
diff --git a/doc/data-types.txt b/doc/data-types.txt
new file mode 100644
index 00000000..1d4218eb
--- /dev/null
+++ b/doc/data-types.txt
@@ -0,0 +1,485 @@
+INTEGER TYPE
+~~~~~~~~~~~
+[options="header"]
+|==================
+|Name | Keyword | Size | Base type
+|Integer |
+integer |
+variable |
+-
+|===================
+
+The integer type is used for numeric values. It may be specified as decimal, hexadecimal or octal number. The integer type doesn't have a fixed size, its size is determined by the expression for which it is used.
+
+BITMASK TYPE
+~~~~~~~~~~~~
+[options="header"]
+|==================
+|Name | Keyword | Size | Base type
+|Bitmask |
+bitmask |
+variable |
+integer
+|===================
+
+The bitmask type (bitmask) is used for bitmasks.
+
+STRING TYPE
+~~~~~~~~~~~~
+[options="header"]
+|==================
+|Name | Keyword | Size | Base type
+|String |
+string |
+variable |
+-
+|===================
+
+The string type is used for character strings. A string begins with an alphabetic character (a-zA-Z) followed by zero or more alphanumeric characters or the characters /, -, _ and .. In addition anything enclosed in double quotes (") is recognized as a string.
+
+.String specification
+----------------------
+# Interface name
+filter input iifname eth0
+
+# Weird interface name
+filter input iifname "(eth0)"
+----------------------------
+
+LINK LAYER ADDRESS TYPE
+~~~~~~~~~~~~~~~~~~~~~~~
+[options="header"]
+|==================
+|Name | Keyword | Size | Base type
+|Link layer address |
+lladdr|
+variable |
+integer
+|===================
+
+The link layer address type is used for link layer addresses. Link layer addresses are specified as a variable amount of groups of two hexadecimal digits separated using colons (:).
+
+.Link layer address specification
+----------------------
+# Ethernet destination MAC address
+filter input ether daddr 20:c9:d0:43:12:d9
+----------------------------
+
+IPV4 ADDRESS TYPE
+~~~~~~~~~~~~~~~~~
+[options="header"]
+|==================
+|Name | Keyword | Size | Base type
+|IPV4 address|
+ipv4_addr|
+32 bit|
+integer
+|===================
+
+The IPv4 address type is used for IPv4 addresses. Addresses are specified in either dotted decimal, dotted hexadecimal, dotted octal, decimal, hexadecimal, octal notation or as a host name. A host name will be resolved using the standard system resolver.
+
+.IPv4 address specification
+----------------------
+# dotted decimal notation
+filter output ip daddr 127.0.0.1
+
+# host name
+filter output ip daddr localhost
+----------------------------
+
+IPV6 ADDRESS TYPE
+~~~~~~~~~~~~~~~~~
+[options="header"]
+|==================
+|Name | Keyword | Size | Base type
+|IPv6 address|
+ipv6_addr|
+128 bit|
+integer
+|===================
+
+The IPv6 address type is used for IPv6 addresses. Addresses are specified as a host name or as hexadecimal halfwords separated by colons. Addresses might be enclosed in square brackets ("[]") to differentiate them from port numbers.
+
+.IPv6 address specificationIPv6 address specification with bracket notation
+----------------------
+# abbreviated loopback address
+filter output ip6 daddr ::1
+
+# without [] the port number (22) would be parsed as part of ipv6 address
+ip6 nat prerouting tcp dport 2222 dnat to [1ce::d0]:22
+----------------------------
+
+BOOLEAN TYPE
+~~~~~~~~~~~~
+[options="header"]
+|==================
+|Name | Keyword | Size | Base type
+|Boolean |
+boolean |
+1 bit |
+integer
+|===================
+
+The boolean type is a syntactical helper type in user space. It's use is in the right-hand side of a (typically implicit) relational expression to change the expression on the left-hand side into a boolean check (usually for existence). +
+
+The following keywords will automatically resolve into a boolean type with given value:
+The bitmask type (bitmask) is used for bitmasks.
+
+[options="header"]
+|==================
+|Keyword | Value
+|exits |
+1 |
+missing |
+0
+|===================
+
+[options="header"]
+|======================================
+|Expression | Behaviour
+|fib |
+Check route existence.
+|exthdr|
+Check IPv6 extension header existence.
+|tcp option |
+Check TCP option header existence.
+|===================
+
+.expressions support a boolean comparison:
+[options="header"]
+|======================================
+|Expression | Behaviour
+|fib |
+Check route existence.
+|exthdr|
+Check IPv6 extension header existence.
+|tcp option |
+Check TCP option header existence.
+|===================
+
+.Boolean specification
+----------------------
+# match if route exists
+filter input fib daddr . iif oif exists
+
+# match only non-fragmented packets in IPv6 traffic
+filter input exthdr frag missing
+
+# match if TCP timestamp option is present
+filter input tcp option timestamp exists
+------------------------------------------
+
+ICMP TYPE TYPE
+~~~~~~~~~~~~~~
+[options="header"]
+|==================
+|Name | Keyword | Size | Base type
+|ICMP Type |
+icmp_type |
+8 bit |
+integer
+|===================
+The ICMP Type type is used to conveniently specify the ICMP header's type field.
+
+.Keywords may be used when specifying the ICMP type
+[options="header"]
+|==================
+|Keyword | Value
+|echo-reply |
+0
+|destination-unreachable |
+3
+|source-quench|
+4
+|redirect|
+5
+|echo-request|
+8
+|router-advertisement|
+9
+|router-solicitation|
+10
+|time-exceeded|
+11
+|parameter-problem|
+12
+|timestamp-request|
+13
+|timestamp-reply|
+14
+|info-request|
+15
+|info-reply|
+16
+|address-mask-request|
+17
+|address-mask-reply|
+18
+|===================
+
+.ICMP Type specification
+------------------------
+# match ping packets
+filter output icmp type { echo-request, echo-reply }
+------------------------
+
+ICMP CODE TYPE
+~~~~~~~~~~~~~~
+[options="header"]
+|==================
+|Name | Keyword | Size | Base type
+|ICMP Type |
+icmp_type |
+8 bit |
+integer
+|===================
+
+The ICMP Code type is used to conveniently specify the ICMP header's code field.
+
+.Keywords may be used when specifying the ICMP type
+[options="header"]
+|==================
+|Keyword | Value
+|net-unreachable |
+0
+|host-unreachable |
+1
+|prot-unreachable|
+2
+|port-unreachable|
+3
+|net-prohibited|
+9
+|host-prohibited|
+10
+|admin-prohibited|
+13
+|===================
+
+ICMPV6 TYPE TYPE
+~~~~~~~~~~~~~~~~
+[options="header"]
+|==================
+|Name | Keyword | Size | Base type
+|ICMPv6 Type |
+icmpv6_type |
+8 bit |
+integer
+|===================
+
+The ICMPv6 Type type is used to conveniently specify the ICMPv6 header's type field.
+
+.keywords may be used when specifying the ICMPv6 type:
+[options="header"]
+|==================
+|Keyword | Value
+|destination-unreachable |
+1
+|packet-too-big|
+2
+|time-exceeded|
+3
+|parameter-problem|
+4
+|echo-request|
+128
+|echo-reply|
+129
+|mld-listener-query|
+130
+|mld-listener-report|
+131
+|mld-listener-done |
+132
+|mld-listener-reduction|
+132
+|nd-router-solicit |
+133
+|nd-router-advert|
+134
+|nd-neighbor-solicit|
+135
+|nd-neighbor-advert|
+136
+|nd-redirect|
+137
+|router-renumbering|
+138
+|ind-neighbor-solicit|
+141
+|ind-neighbor-advert|
+142
+|mld2-listener-report|
+143
+|===================
+
+.ICMPv6 Type specification
+--------------------------
+# match ICMPv6 ping packets
+filter output icmpv6 type { echo-request, echo-reply }
+--------------------------
+
+ICMPV6 CODE TYPE
+~~~~~~~~~~~~~~~~
+[options="header"]
+|==================
+|Name | Keyword | Size | Base type
+|ICMPv6 Code |
+icmpv6_type |
+8 bit |
+integer
+|===================
+
+The ICMPv6 Code type is used to conveniently specify the ICMPv6 header's code field.
+
+.keywords may be used when specifying the ICMPv6 code
+[options="header"]
+|==================
+|Keyword |Value
+|no-route|
+0
+|admin-prohibited|
+1
+|addr-unreachable|
+3
+|port-unreachable|
+4
+|policy-fail|
+5
+|reject-route|
+6
+|==================
+
+ICMPVX CODE TYPE
+~~~~~~~~~~~~~~~~
+[options="header"]
+|==================
+|Name | Keyword | Size | Base type
+|ICMPvX Code |
+icmpv6_type |
+8 bit |
+integer
+|===================
+
+The ICMPvX Code type abstraction is a set of values which overlap between ICMP and ICMPv6 Code types to be used from the inet family.
+
+.keywords may be used when specifying the ICMPvX code
+[options="header"]
+|==================
+|Keyword |Value
+|no-route|
+0
+|port-unreachable|
+1
+|host-unreachable|
+2
+|admin-prohibited|
+3
+|=================
+
+CONNTRACK TYPES
+~~~~~~~~~~~~~~~
+
+.overview of types used in ct expression and statement
+[options="header"]
+|==================
+|Name | Keyword |Size |Base type
+|conntrack state|
+ct_state|
+4 byte|
+bitmask
+|conntrack direction|
+ct_dir |
+8 bit|
+integer
+|conntrack status|
+ct_status|
+4 byte|
+bitmask
+|conntrack event bits|
+ct_events |
+4 byte |
+bitmask
+|conntrack label|
+ct_label |
+128 bit|
+bitmask
+|=================
+
+For each of the types above, keywords are available for convenience:
+
+.conntrack state (ct_state)
+[options="header"]
+|==================
+|Keyword| Value
+|invalid|
+1
+|established|
+2
+|related|
+4
+|new|
+8
+|untracked|
+64
+|================
+
+.conntrack direction (ct_dir)
+[options="header"]
+|==================
+|Keyword| Value
+|original|
+0
+|reply|
+1
+|================
+
+.conntrack status (ct_status)
+[options="header"]
+|==================
+|Keyword| Value
+|expected|
+1
+|seen-reply|
+1
+|assured|
+4
+|confirmed|
+8
+|snat|
+16
+|dnat|
+32
+|dying|
+512
+|================
+
+.conntrack event bits (ct_event)
+[options="header"]
+|==================
+|Keyword| Value
+|new|
+1
+|related|
+2
+|destroy|
+4
+|reply|
+8
+|assured|
+16
+|protoinfo|
+32
+|helper|
+64
+|mark|
+128
+|seqadj|
+256
+|secmark|
+512
+|label|
+1024
+|==================
+
+Possible keywords for conntrack label type (ct_label) are read at runtime from /etc/connlabel.conf.
diff --git a/doc/nft.txt b/doc/nft.txt
new file mode 100644
index 00000000..e317cfd8
--- /dev/null
+++ b/doc/nft.txt
@@ -0,0 +1,619 @@
+nft(8)
+======
+
+NAME
+----
+nft - Administration tool of the nftables framework for packet filtering and classification
+
+
+SYNOPSIS
+--------
+[verse]
+*nft* [ *-nNscae* ] [ *-I* 'directory' ] [ *-f* 'filename' | *-i* | 'cmd' ...]
+*nft* *-h*
+*nft* *-v*
+
+DESCRIPTION
+-----------
+nft is the command line tool used to set up, maintain and inspect packet filtering and classification rules in the Linux kernel, in the nftables framework. The Linux kernel subsystem is known as nf_tables, and `nft' stands for Netfilter.
+
+OPTIONS
+-------
+For a full summary of options, run *nft --help*.
+
+*-h*::
+*--help*::
+ Show help message and all options.
+
+*-v*::
+*--version*::
+ Show version.
+
+*-n*::
+*--numeric*::
+ Show data numerically. When used once (the default behaviour), skip
+ lookup of addresses to symbolic names. Use twice to also show Internet
+ services (port numbers) numerically. Use three times to also show
+ protocols and UIDs/GIDs numerically.
+
+*-s*::
+*--stateless*::
+ Omit stateful information of rules and stateful objects.
+
+*-l*::
+*--literal*::
+ Translate numeric to literal. When used once (the default behav‐
+ iour), print services (instead of numerical port numbers). Use
+ twice to perform the IP address to name lookup, this usually re‐
+ quires network traffic for DNS lookup that slows down the rule‐
+ set listing.
+
+*-c*::
+*--check*::
+ Check commands validity without actually applying the changes.
+
+*-a*::
+*--handle*::
+ Show object handles in output.
+
+*-e*::
+*--echo*::
+ When inserting items into the ruleset using add, insert or replace commands, print notifications
+ just like nft monitor.
+
+*-I*::
+*--includepath directory*::
+ Add the directory 'directory' to the list of directories to be searched for included files. This op‐
+ tion may be specified multiple times.
+
+*-f*::
+*--file 'filename'*::
+ Read input from 'filename'. If 'filename' is -, read from stdin. +
+ nft scripts must start #!/usr/sbin/nft -f
+
+*-i*::
+*--interactive*::
+ Read input from an interactive readline CLI. You can use quit to exit, or use the EOF marker, nor‐
+ mally this is CTRL-D.
+
+INPUT FILE FORMATS
+------------------
+LEXICAL CONVENTIONS
+~~~~~~~~~~~~~~~~~~~
+Input is parsed line-wise. When the last character of a line, just before the newline character, is a non-quoted backslash (\), the next line is treated as a continuation. Multiple commands on the same line can be separated using a semicolon (;). +
+
+A hash sign (#) begins a comment. All following characters on the same line are ignored. +
+
+Identifiers begin with an alphabetic character (a-z,A-Z), followed zero or more alphanumeric characters (a-z,A-Z,0-9) and the characters slash (/), backslash (\), underscore (_) and dot (.). Identifiers using different characters or clashing with a keyword need to be enclosed in double quotes (").
+
+INCLUDE FILES
+~~~~~~~~~~~~~
+[verse]
+*include* 'filename'
+
+Other files can be included by using the *include* statement. The directories to be searched for include files can be specified using the *-I*/*--includepath* option. You can override this behaviour either by prepending `./' to your path to force inclusion of files located in the current working directory (i.e. relative path) or / for file location expressed as an absolute path. +
+
+If *-I*/*--includepath* is not specified, then nft relies on the default directory that is specified at compile time. You can retrieve this default directory via *-h*/*--help* option. +
+
+Include statements support the usual shell wildcard symbols (\*,?,[]). Having no matches for an include statement is not an error, if wildcard symbols are used in the include statement. This allows having potentially empty include directories for statements like **include "/etc/firewall/rules/"**. The wildcard matches are loaded in alphabetical order. Files beginning with dot (.) are not matched by include statements.
+
+SYMBOLIC VARIABLES
+~~~~~~~~~~~~~~~~~~
+[verse]
+*define* variable 'expr'
+*$variable*
+
+Symbolic variables can be defined using the *define* statement. Variable references are expressions and can be used initialize other variables. The scope of a definition is the current block and all blocks contained within.
+
+.Using symbolic variables
+---------------------------------------
+define int_if1 = eth0
+define int_if2 = eth1
+define int_ifs = { $int_if1, $int_if2 }
+
+filter input iif $int_ifs accept
+---------------------------------------
+
+[[ADDRESS_FAMILIES]]
+ADDRESS FAMILIES
+----------------
+Address families determine the type of packets which are processed. For each address family the kernel contains so called hooks at specific stages of the packet processing paths, which invoke nftables if rules for these hooks exist.
+
+[horizontal]
+ip:: IPv4 address family.
+ip6:: IPv6 address family.
+inet:: Internet (IPv4/IPv6) address family.
+arp:: ARP address family, handling IPv4 ARP packets.
+bridge:: Bridge address family, handling packets which traverse a bridge device.
+netdev:: Netdev address family, handling packets from ingress.
+
+All nftables objects exist in address family specific namespaces, therefore all identifiers include an address family. If an identifier is specified without an address family, the *ip* family is used by default.
+
+IPV4/IPV6/INET ADDRESS FAMILIES
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+The IPv4/IPv6/Inet address families handle IPv4, IPv6 or both types of packets. They contain five hooks at different packet processing stages in the network stack.
+
+.IPv4/IPv6/Inet address family hooks
+[options="header"]
+|==================
+|Hook | Description
+|prerouting |
+All packets entering the system are processed by the prerouting hook. It is invoked before the routing process and is used for early filtering or changing packet attributes that affect routing.
+|input |
+Packets delivered to the local system are processed by the input hook.
+|forward |
+Packets forwarded to a different host are processed by the forward hook.
+|output |
+Packets sent by local processes are processed by the output hook.
+|postrouting |
+All packets leaving the system are processed by the postrouting hook.
+|===================
+
+ARP ADDRESS FAMILY
+~~~~~~~~~~~~~~~~~~
+The ARP address family handles ARP packets received and sent by the system. It
+is commonly used to mangle ARP packets for clustering.
+
+.ARP address family hooks
+[options="header"]
+|=================
+|Hook | Description
+|input |
+Packets delivered to the local system are processed by the input hook.
+|output |
+Packets send by the local system are processed by the output hook.
+|=================
+
+BRIDGE ADDRESS FAMILY
+~~~~~~~~~~~~~~~~~~~~~
+The bridge address family handles ethernet packets traversing bridge devices.
+
+The list of supported hooks is identical to IPv4/IPv6/Inet address families above.
+
+NETDEV ADDRESS FAMILY
+~~~~~~~~~~~~~~~~~~~~
+The Netdev address family handles packets from ingress.
+
+.Netdev address family hooks
+[options="header"]
+|=================
+|Hook | Description
+|ingress |
+All packets entering the system are processed by this hook. It is invoked before layer 3 protocol handlers and it can be used for early filtering and policing.
+|=================
+
+RULESET
+-------
+[verse]
+{list | flush} *ruleset* ['family']
+\{export\} [*ruleset*] {'format'}
+
+The *ruleset* keyword is used to identify the whole set of tables, chains, etc. currently in place in kernel. The following *ruleset* commands exist:
+
+[horizontal]
+*list*:: Print the ruleset in human-readable format.
+
+*flush*:: Clear the whole ruleset. Note that unlike iptables, this will remove all tables and whatever they contain, effectively leading to an empty ruleset - no packet filtering will happen anymore, so the kernel accepts any valid packet it receives.
+
+*export*:: Print the ruleset in machine readable format. The mandatory 'format' parameter may be either *xml* or *json*.
+
+It is possible to limit *list* and *flush* to a specific address family only. For a list of valid family names, see <<ADDRESS_FAMILIES>> above.
+
+Note that contrary to what one might assume, the output generated by *export* is not parseable by *nft -f*. Instead, the output of *list* command serves well for that purpose.
+
+TABLES
+------
+[verse]
+{add | create} *table* ['family'] 'table' [ {flags 'flags'} ]
+{delete | list | flush} *table* ['family'] 'table'
+delete *table* ['family'] handle 'handle'
+
+Tables are containers for chains, sets and stateful objects. They are identified by their address family and their name. The address family must be one of *ip*, *ip6*, *inet*, *arp*, *bridge*, *netdev*. The *inet* address family is a dummy family which is used to create hybrid IPv4/IPv6 tables. The *meta expression nfproto* keyword can be used to test which family (ipv4 or ipv6) context the packet is being processed in. When no address family is specified, *ip* is used by default. The only difference between add and create is that the former will not return an error if the specified table already exists while *create* will return an error.
+
+.Table flags
+[options="header"]
+|=================
+|Flag | Description
+|dormant |
+table is not evaluated any more (base chains are unregistered).
+|=================
+
+.*Add, change, delete a table*
+---------------------------------------
+# start nft in interactive mode
+nft --interactive
+
+# create a new table.
+create table inet mytable
+
+# add a new base chain: get input packets
+add chain inet mytable myin { type filter hook input priority 0; }
+
+# add a single counter to the chain
+add rule inet mytable myin counter
+
+# disable the table temporarily -- rules are not evaluated anymore
+add table inet mytable { flags dormant; }
+
+# make table active again:
+add table inet mytable
+---------------------------------------
+
+[horizontal]
+*add*:: Add a new table for the given family with the given name.
+*delete*:: Delete the specified table.
+*list*:: List all chains and rules of the specified table.
+*flush*:: Flush all chains and rules of the specified table.
+
+CHAINS
+------
+[verse]
+{add | create} *chain* ['family'] 'table' 'chain' [ { type 'type' hook 'hook' [device 'device'] priority 'priority' ; [policy 'policy' ;] }]
+{delete | list | flush} *chain* ['family'] 'table' 'chain'
+delete *chain* ['family'] 'table' handle 'handle'
+rename *chain* ['family'] 'table' 'chain' 'newname'
+
+Chains are containers for rules. They exist in two kinds, base chains and regular chains. A base chain is an entry point for packets from the networking stack, a regular chain may be used as jump target and is used for better rule organization.
+
+[horizontal]
+*add*:: Add a new chain in the specified table. When a hook and priority value are specified, the chain is created as a base chain and hooked up to the networking stack.
+*create*:: Similar to the *add* command, but returns an error if the chain already exists.
+*delete*:: Delete the specified chain. The chain must not contain any rules or be used as jump target.
+*rename*:: Rename the specified chain.
+*list*:: List all rules of the specified chain.
+*flush*:: Flush all rules of the specified chain.
+
+For base chains, *type*, *hook* and *priority* parameters are mandatory.
+
+.Supported chain types
+[options="header"]
+|=================
+|Type | Families | Hooks | Description
+|filter | all | all |
+Standard chain type to use in doubt.
+|nat | ip, ip6 |
+prerouting, input, output, postrouting |
+Chains of this type perform Native Address Translation based on conntrack
+entries. Only the first packet of a connection actually traverses this chain -
+its rules usually define details of the created conntrack entry (NAT
+statements for instance).
+|route | ip, ip6 | output |
+If a packet has traversed a chain of this type and is about to be accepted, a
+new route lookup is performed if relevant parts of the IP header have changed.
+This allows to e.g. implement policy routing selectors in nftables.
+|=================
+
+Apart from the special cases illustrated above (e.g. *nat* type not supporting *forward* hook or *route* type only supporting *output* hook), there are two further quirks worth noticing:
+
+* netdev family supports merely a single combination, namely *filter* type and *ingress* hook. Base chains in this family also require the *device* parameter to be present since they exist per incoming interface only.
+* arp family supports only *input* and *output* hooks, both in chains of type *filter*.
+
+The *priority* parameter accepts a signed integer value which specifies the order in which chains with same *hook* value are traversed. The ordering is
+ascending, i.e. lower priority values have precedence over higher ones.
+
+Base chains also allow to set the chain's *policy*, i.e. what happens to packets not explicitly accepted or refused in contained rules. Supported policy values are *accept* (which is the default) or *drop*.
+
+RULES
+-----
+[verse]
+[add | insert] *rule* ['family'] 'table' 'chain' [ {handle | position} 'handle' | index 'index' ] 'statement'...
+replace *rule* ['family'] 'table' 'chain' handle 'handle' 'statement'...
+delete *rule* ['family'] 'table' 'chain' handle 'handle'
+
+Rules are added to chain in the given table. If the family is not specified, the ip family is used. Rules are constructed from two kinds of components according to a set of grammatical rules: ex‐ pressions and statements.
+
+The add and insert commands support an optional location specifier, which is either a 'handle' of an existing rule or an 'index' (starting at zero). Internally, rule locations are always identified by 'handle' and the translation from 'index' happens in userspace. This has two potential implications in case a concurrent ruleset change happens after the translation was done: The effective rule index might change if a rule was inserted or deleted before the referred one. If the referred rule was deleted, the command is rejected by the kernel just as if an invalid 'handle' was given.
+
+*add*::
+Add a new rule described by the list of statements. The rule is appended to the given chain unless a position is specified, in which case the rule is appended to the rule given by the 'handle'. The alternative name position is deprecated and should not be used anymore.
+
+*insert*:: Similar to the *add* command, but the rule is prepended to the beginning of the chain or before the rule at the given position.
+
+*replace*:: Similar to the add command, but the rule replaces the specified rule.
+
+*delete*:: Delete the specified rule.
+
+.*add a rule to ip table input chain*
+-------------
+nft add rule filter output ip daddr 192.168.0.0/24 accept # 'ip filter' is assumed
+# same command, slightly more verbose
+nft add rule ip filter output ip daddr 192.168.0.0/24 accept
+--------------
+
+.*delete rule from inet table*
+-----------------------
+# nft -a list ruleset
+table inet filter {
+ chain input {
+ type filter hook input priority 0; policy accept;
+ ct state established,related accept # handle 4
+ ip saddr 10.1.1.1 tcp dport ssh accept # handle 5
+ ...
+# delete the rule with handle 5
+# nft delete rule inet filter input handle 5
+-------------------------
+
+SETS
+----
+nftables offers two kinds of set concepts. Anonymous sets are sets that have no specific name. The set members are enclosed in curly braces, with commas to separate elements when creating the rule the set is used in. Once that rule is removed, the set is removed as well. They cannot be updated, i.e. once an anonymous set is declared it cannot be changed anymore except by removing/altering the rule that uses the anonymous set.
+
+.*Using anonymous sets to accept particular subnets and ports*
+----------
+nft add rule filter input ip saddr { 10.0.0.0/8, 192.168.0.0/16 } tcp dport { 22, 443 } accept
+----------
+
+Named sets are sets that need to be defined first before they can be referenced in rules. Unlike anonymous sets, elements can be added to or removed from a named set at any time. Sets are referenced from rules using an @ prefixed to the sets name.
+
+.*Using named sets to accept addresses and ports*
+------------------
+nft add rule filter input ip saddr @allowed_hosts tcp dport @allowed_ports accept
+------------------
+
+The sets allowed_hosts and allowed_ports need to be created first. The next section describes nft set syntax in more detail.
+
+[verse]
+add *set* ['family'] 'table' 'set' { type 'type' ; [flags 'flags' ;] [timeout 'timeout' ;] [gc-interval 'gc-interval' ;] [elements = { 'element'[,...]
+} ;] [size size ;] [policy policy ;] [auto-merge auto-merge ;] }
+{delete | list | flush} *set* ['family'] 'table' 'set'
+delete *set* ['family'] 'table' handle 'handle'
+{add | delete} *element* ['family'] 'table' 'set' { 'element'[,...] }
+
+Sets are elements containers of an user-defined data type, they are uniquely identified by an user-defined name and attached to tables. Their behaviour can be tuned with the flags that can be specified at set creation time.
+
+[horizontal]
+*add*:: Add a new set in the specified table. See the Set specification table below for more information about how to specify a sets properties.
+*delete*:: Delete the specified set.
+*list*:: Display the elements in the specified set.
+*flush*:: Remove all elements from the specified set.
+*add element*:: Comma-separated list of elements to add into the specified set.
+*delete element*:: Comma-separated list of elements to delete from the specified set.
+
+.Set specifications
+[options="header"]
+|=================
+|Keyword | Description | Type
+|type |
+data type of set elements |
+string: ipv4_addr, ipv6_addr, ether_addr, inet_proto, inet_service, mark
+|flags |
+set flags |
+string: constant, dynamic, interval, timeout
+|timeout |
+time an element stays in the set, mandatory if set is added to from the packet path (ruleset).|
+string, decimal followed by unit. Units are: d, h, m, s
+|gc-interval |
+garbage collection interval, only available when timeout or flag timeout are
+active |
+string, decimal followed by unit. Units are: d, h, m, s
+|elements |
+elements contained by the set |
+set data type
+|size |
+maximun number of elements in the set, mandatory if set is added to from the packet path (ruleset).|
+unsigned integer (64 bit)
+|policy |
+set policy |
+string: performance [default], memory
+|auto-merge |
+automatic merge of adjacent/overlapping set elements (only for interval sets) |
+|=================
+
+
+MAPS
+-----
+[verse]
+add *map* ['family'] 'table' 'map' { type 'type' [flags 'flags' ;] [elements = {'elements'[,...] } ;] [size 'size' ;] [policy 'policy' ;] }
+{delete | list | flush} *map* ['family'] 'table' 'map'
+{add | delete} *element* ['family'] 'table' 'map' { elements = { 'elements'[,...] } ; }
+
+Maps store data based on some specific key used as input, they are uniquely identified by an user-defined name and attached to tables.
+
+[horizontal]
+*add*:: Add a new map in the specified table.
+*delete*:: Delete the specified map.
+*list*:: Display the elements in the specified map.
+*flush*:: Remove all elements from the specified map.
+*add element*:: Comma-separated list of elements to add into the specified map.
+*delete element*:: Comma-separated list of element keys to delete from the specified map.
+
+.Map specifications
+[options="header"]
+|=================
+|Keyword | Description | Type
+|type |
+data type of map elements |
+string `:' string: ipv4_addr, ipv6_addr, ether_addr, inet_proto, inet_service, mark, counter, quota. Counter and quota can't be used as keys
+|flags |
+map flags |
+string: constant, interval
+|elements |
+elements contained by the map |
+map data type
+|size |
+maximun number of elements in the map |
+unsigned integer (64 bit)
+| policy |
+map policy |
+string: performance [default], memory
+|=================
+
+
+FLOWTABLES
+-----------
+[verse]
+{add | create} *flowtable* ['family'] 'table' 'flowtable' { hook 'hook' priority 'priority' ; devices = { 'device'[,...] } ; }
+{delete | list} *flowtable* ['family'] 'table' 'flowtable'
+
+Flowtables allow you to accelerate packet forwarding in software. Flowtables entries are represented through a tuple that is composed of the input interface, source and destination address, source and destination port; and layer 3/4 protocols. Each entry also caches the destination interface and the gateway address - to update the destination link-layer address - to forward packets. The ttl and hoplimit fields are also decremented. Hence, flowtables provides an alternative path that allow packets to bypass the classic forwarding path. Flowtables reside in the ingress hook, that is located before the prerouting hook. You can select what flows you want to offload through the flow offload expression from the forward chain. Flowtables are identified by their address family and their name. The address family must be one of ip, ip6, inet. The inet address family is a dummy family which is used to create hybrid IPv4/IPv6 tables. When no address family is specified, ip is used by default.
+
+[horizontal]
+*add*:: Add a new flowtable for the given family with the given name.
+*delete*:: Delete the specified flowtable.
+*list*:: List all flowtables.
+
+
+STATEFUL OBJECTS
+----------------
+[verse]
+{add | delete | list | reset} type ['family'] 'table' 'object'
+delete type ['family'] 'table' handle 'handle'
+
+Stateful objects are attached to tables and are identified by an unique name. They group stateful information from rules, to reference them in rules the keywords "type name" are used e.g. "counter name".
+
+[horizontal]
+*add*:: Add a new stateful object in the specified table.
+*delete*:: Delete the specified object.
+*list*:: Display stateful information the object holds.
+*reset*:: List-and-reset stateful object.
+
+include::stateful-objects.txt[]
+
+EXPRESSIONS
+------------
+Expressions represent values, either constants like network addresses, port numbers etc. or data gathered from the packet during ruleset evaluation.
+Expressions can be combined using binary, logical, relational and other types of expressions to form complex or relational (match) expressions. They are also used as arguments to certain types of operations, like NAT, packet marking etc. +
+
+Each expression has a data type, which determines the size, parsing and representation of symbolic values and type compatibility with other expressions.
+
+DESCRIBE COMMAND
+~~~~~~~~~~~~~~~~
+[verse]
+*describe* 'expression'
+
+The *describe* command shows information about the type of an expression and its data type.
+
+.The describe command
+---------------------
+$ nft describe tcp flags
+payload expression, datatype tcp_flag (TCP flag) (basetype bitmask, integer), 8 bits
+
+predefined symbolic constants:
+fin 0x01
+syn 0x02
+rst 0x04
+psh 0x08
+ack 0x10
+urg 0x20
+ecn 0x40
+cwr 0x80
+---------------------
+
+DATA TYPES
+----------
+
+Data types determine the size, parsing and representation of symbolic values and type compatibility of expressions. A number of global data types exist, in addition some expression types define further data types specific to the expression type. Most data types have a fixed size, some however may have a dynamic size, f.i. the string type. +
+
+Types may be derived from lower order types, f.i. the IPv4 address type is derived from the integer type, meaning an IPv4 address can also be specified as an integer value. +
+
+In certain contexts (set and map definitions) it is necessary to explicitly specify a data type. Each type has a name which is used for this.
+
+include::data-types.txt[]
+
+PRIMARY EXPRESSIONS
+-------------------
+The lowest order expression is a primary expression, representing either a constant or a single datum from a packet's payload, meta data or a stateful module.
+
+include::primary-expression.txt[]
+
+PAYLOAD EXPRESSIONS
+-------------------
+Payload expressions refer to data from the packet's payload.
+
+include::payload-expression.txt[]
+
+STATEMENTS
+----------
+Statements represent actions to be performed. They can alter control flow (return, jump to a different chain, accept or drop the packet) or can perform actions, such as logging, rejecting a packet, etc. +
+
+Statements exist in two kinds. Terminal statements unconditionally terminate evaluation of the current rule, non-terminal statements either only conditionally or never terminate evaluation of the current rule, in other words, they are passive from the ruleset evaluation perspective. There can be an arbitrary amount of non-terminal statements in a rule, but only a single terminal statement as the final statement.
+
+include::statements.txt[]
+
+ADDITIONAL COMMANDS
+-------------------
+These are some additional commands included in nft.
+
+MONITOR
+~~~~~~~~
+The monitor command allows you to listen to Netlink events produced by the nf_tables subsystem, related to creation and deletion of objects. When they occur, nft will print to stdout the monitored events in either XML, JSON or native nft format. +
+
+To filter events related to a concrete object, use one of the keywords 'tables', 'chains', 'sets', 'rules', 'elements', 'ruleset'. +
+
+To filter events related to a concrete action, use keyword 'new' or 'destroy'.
+
+Hit ^C to finish the monitor operation.
+
+.Listen to all events, report in native nft format
+--------------------------------------------------
+% nft monitor
+--------------------------------------------------
+
+.Listen to added tables, report in XML format
+--------------------------------------------
+% nft monitor new tables xml
+--------------------------------------------
+
+.Listen to deleted rules, report in JSON format
+-----------------------------------------------
+% nft monitor destroy rules json
+-----------------------------------------------
+
+.Listen to both new and destroyed chains, in native nft format
+-----------------------------------------------------------------
+% nft monitor chains
+-------------------------------
+
+.Listen to ruleset events such as table, chain, rule, set, counters and quotas, in native nft format
+----------------------------------------------------------------------------------------------------
+% nft monitor ruleset
+---------------------
+
+ERROR REPORTING
+---------------
+When an error is detected, nft shows the line(s) containing the error, the position of the erroneous parts in the input stream and marks up the erroneous parts using carets (^). If the error results from the combination of two expressions or statements, the part imposing the constraints which are violated is marked using tildes (~). +
+
+For errors returned by the kernel, nft can't detect which parts of the input caused the error and the entire command is marked.
+
+.Error caused by single incorrect expression
+--------------------------------------------
+<cmdline>:1:19-22: Error: Interface does not exist
+filter output oif eth0
+ ^^^^
+--------------------------------------------
+
+.Error caused by invalid combination of two expressions
+-------------------------------------------------------
+<cmdline>:1:28-36: Error: Right hand side of relational expression (==) must be constant
+filter output tcp dport == tcp dport
+ ~~ ^^^^^^^^^
+-------------------------------------------------------
+
+.Error returned by the kernel
+-----------------------------
+<cmdline>:0:0-23: Error: Could not process rule: Operation not permitted
+filter output oif wlan0
+ ^^^^^^^^^^^^^^^^^^^^^^^
+---------------------------------
+
+EXIT STATUS
+-----------
+On success, nft exits with a status of 0. Unspecified errors cause it to exit with a status of 1, memory allocation errors with a status of 2, unable to open Netlink socket with 3.
+
+SEE ALSO
+--------
+[verse]
+iptables(8), ip6tables(8), arptables(8), ebtables(8), ip(8), tc(8)
+
+There is an official wiki at: https://wiki.nftables.org
+
+AUTHORS
+-------
+nftables was written by Patrick McHardy and Pablo Neira Ayuso, among many other contributors from the Netfilter community.
+
+COPYRIGHT
+---------
+Copyright © 2008-2014 Patrick McHardy <kaber@trash.net> Copyright © 2013-2018 Pablo Neira Ayuso <pablo@netfilter.org> +
+
+nftables is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. +
+
+This documentation is licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0 license, CC BY-SA 4.0 ⟨http://creativecommons.org/licenses/by-sa/4.0/⟩.
diff --git a/doc/nft.xml b/doc/nft.xml
deleted file mode 100644
index 6fbf0399..00000000
--- a/doc/nft.xml
+++ /dev/null
@@ -1,5723 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
-"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
-<!--
-vi:ts=4 sw=4
--->
-
-<refentry xmlns:xi="http://www.w3.org/2001/XInclude">
- <refentryinfo>
- <author>
- <firstname>Patrick</firstname>
- <surname>McHardy</surname>
- <email>kaber@trash.net</email>
- </author>
- <copyright>
- <year>2008-2014</year>
- <holder>Patrick McHardy</holder>
- </copyright>
- </refentryinfo>
-
- <refentryinfo>
- <author>
- <firstname>Pablo Neira</firstname>
- <surname>Neira Ayuso</surname>
- <email>pablo@netfilter.org</email>
- </author>
- <copyright>
- <year>2013-2016</year>
- <holder>Pablo Neira Ayuso</holder>
- </copyright>
- </refentryinfo>
-
- <refmeta>
- <refentrytitle>nft</refentrytitle>
- <manvolnum>8</manvolnum>
- </refmeta>
-
- <refnamediv>
- <refname>nft</refname>
- <refpurpose>
- Administration tool of the nftables framework for packet filtering and classification
- </refpurpose>
- </refnamediv>
-
- <refsynopsisdiv>
- <cmdsynopsis>
- <command>nft</command>
- <group>
- <arg><option> -nNscae </option></arg>
- </group>
- <arg> -I
- <replaceable>directory</replaceable>
- </arg>
- <group>
- <arg> -f
- <replaceable>filename</replaceable>
- </arg>
- <arg> -i
- </arg>
- <arg rep="repeat">
- <replaceable>cmd</replaceable>
- </arg>
- </group>
- </cmdsynopsis>
- <cmdsynopsis>
- <command>nft -h</command>
- </cmdsynopsis>
- <cmdsynopsis>
- <command>nft -v</command>
- </cmdsynopsis>
- </refsynopsisdiv>
-
- <refsect1>
- <title>Description</title>
- <para>
- nft is the command line tool used to set up, maintain and inspect packet
- filtering and classification rules in the Linux kernel, in the nftables framework.
- The Linux kernel subsystem is known as nf_tables, and 'nf' stands for Netfilter.
- </para>
- </refsect1>
-
- <refsect1>
- <title>Options</title>
- <para>
- For a full summary of options, run <command>nft --help</command>.
- </para>
-
- <variablelist>
- <varlistentry>
- <term><option>-h, --help</option></term>
- <listitem>
- <para>
- Show help message and all options.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>-v, --version</option></term>
- <listitem>
- <para>
- Show version.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>-n, --numeric</option></term>
- <listitem>
- <para>
- Show data numerically. When used once (the default behaviour), skip
- lookup of addresses to symbolic names. Use twice to also show Internet
- services (port numbers) numerically. Use three times to also show
- protocols and UIDs/GIDs numerically.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>-s, --stateless</option></term>
- <listitem>
- <para>
- Omit stateful information of rules and stateful objects.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>-l, --literal</option></term>
- <listitem>
- <para>
- Translate numeric to literal. When used once (the default behaviour),
- print services (instead of numerical port numbers). Use twice to
- perform the IP address to name lookup, this usually requires network
- traffic for DNS lookup that slows down the ruleset listing.
-
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>-c, --check</option></term>
- <listitem>
- <para>
- Check commands validity without actually applying the changes.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>-a, --handle</option></term>
- <listitem>
- <para>
- Show object handles in output.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>-e, --echo</option></term>
- <listitem>
- <para>
- When inserting items into the ruleset using <command>add</command>,
- <command>insert</command> or <command>replace</command> commands,
- print notifications just like <command>nft monitor</command>.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>-I, --includepath <replaceable>directory</replaceable></option></term>
- <listitem>
- <para>
- Add the directory <replaceable>directory</replaceable> to the list of directories to be searched for included files. This option may be specified multiple times.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>-f, --file <replaceable>filename</replaceable></option></term>
- <listitem>
- <para>
- Read input from <replaceable>filename</replaceable>. If <replaceable>filename</replaceable> is <literal>-</literal>, read from <literal>stdin</literal>.
- </para>
- <para>
- nft scripts must start <command>#!/usr/sbin/nft -f</command>
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>-i, --interactive</option></term>
- <listitem>
- <para>
- Read input from an interactive readline CLI. You can use <command>quit</command> to exit, or use the <literal>EOF</literal> marker, normally this is <literal>CTRL-D</literal>.
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </refsect1>
-
- <refsect1>
- <title>Input file format</title>
- <refsect2>
- <title>Lexical conventions</title>
- <para>
- Input is parsed line-wise. When the last character of a line, just before
- the newline character, is a non-quoted backslash (<literal>\</literal>),
- the next line is treated as a continuation. Multiple commands on the
- same line can be separated using a semicolon (<literal>;</literal>).
- </para>
- <para>
- A hash sign (<literal>#</literal>) begins a comment. All following characters
- on the same line are ignored.
- </para>
- <para>
- Identifiers begin with an alphabetic character (<literal>a-z,A-Z</literal>),
- followed zero or more alphanumeric characters (<literal>a-z,A-Z,0-9</literal>)
- and the characters slash (<literal>/</literal>), backslash (<literal>\</literal>),
- underscore (<literal>_</literal>) and dot (<literal>.</literal>). Identifiers
- using different characters or clashing with a keyword need to be enclosed in
- double quotes (<literal>"</literal>).
- </para>
- <para>
- </para>
- </refsect2>
- <refsect2>
- <title>Include files</title>
- <para>
- <cmdsynopsis>
- <command>include</command> "<replaceable>filename</replaceable>"
- </cmdsynopsis>
- </para>
- <para>
- Other files can be included by using the <command>include</command> statement.
- The directories to be searched for include files can be specified using
- the <option>-I/--includepath</option> option. You can override this behaviour
- either by prepending ./ to your path to force inclusion of files located in the
- current working directory (i.e. relative path) or / for file location expressed
- as an absolute path.
- </para>
- <para>
- If -I/--includepath is not specified, then nft relies on the default directory
- that is specified at compile time. You can retrieve this default directory via
- -h/--help option.
- </para>
- <para>
- Include statements support the usual shell wildcard symbols
- (<literal>*,?,[]</literal>). Having no matches for an include statement is not
- an error, if wildcard symbols are used in the include statement. This allows having
- potentially empty include directories for statements like
- <literal>include "/etc/firewall/rules/*"</literal>. The wildcard matches are
- loaded in alphabetical order. Files beginning with dot (<literal>.</literal>) are
- not matched by include statements.
- </para>
- </refsect2>
- <refsect2>
- <title>Symbolic variables</title>
- <para>
- <cmdsynopsis>
- <command>define</command> <varname><replaceable>variable</replaceable></varname> = <replaceable>expr</replaceable>
- </cmdsynopsis>
- <cmdsynopsis>
- <command>$<varname><replaceable>variable</replaceable></varname></command>
- </cmdsynopsis>
- </para>
- <para>
- Symbolic variables can be defined using the <command>define</command> statement.
- Variable references are expressions and can be used initialize other variables.
- The scope of a definition is the current block and all blocks contained within.
-
- <example>
- <title>Using symbolic variables</title>
- <programlisting>
-define int_if1 = eth0
-define int_if2 = eth1
-define int_ifs = { $int_if1, $int_if2 }
-
-filter input iif $int_ifs accept
- </programlisting>
- </example>
- </para>
- </refsect2>
- </refsect1>
-
- <refsect1>
- <title>Address families</title>
- <para>
- Address families determine the type of packets which are processed. For each address
- family the kernel contains so called hooks at specific stages of the packet processing
- paths, which invoke nftables if rules for these hooks exist.
- </para>
- <para>
- <variablelist>
- <varlistentry>
- <term><option>ip</option></term>
- <listitem>
- <para>
- IPv4 address family.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>ip6</option></term>
- <listitem>
- <para>
- IPv6 address family.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>inet</option></term>
- <listitem>
- <para>
- Internet (IPv4/IPv6) address family.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>arp</option></term>
- <listitem>
- <para>
- ARP address family, handling IPv4 ARP packets.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>bridge</option></term>
- <listitem>
- <para>
- Bridge address family, handling packets which traverse a bridge device.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>netdev</option></term>
- <listitem>
- <para>
- Netdev address family, handling packets from ingress.
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </para>
- <para>
- All nftables objects exist in address family specific namespaces, therefore
- all identifiers include an address family. If an identifier is specified without
- an address family, the <literal>ip</literal> family is used by default.
- </para>
-
- <refsect2>
- <title>IPv4/IPv6/Inet address families</title>
- <para>
- The IPv4/IPv6/Inet address families handle IPv4, IPv6 or both types of packets. They
- contain five hooks at different packet processing stages in the network stack.
- </para>
- <para>
- <table frame="all">
- <title>IPv4/IPv6/Inet address family hooks</title>
- <tgroup cols='2' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1' colwidth="1*"/>
- <colspec colname='c2' colwidth="5*"/>
- <thead>
- <row>
- <entry>Hook</entry>
- <entry>Description</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>prerouting</entry>
- <entry>
- All packets entering the system are processed by the prerouting hook. It is invoked
- before the routing process and is used for early filtering or changing packet
- attributes that affect routing.
- </entry>
- </row>
- <row>
- <entry>input</entry>
- <entry>
- Packets delivered to the local system are processed by the input hook.
- </entry>
- </row>
- <row>
- <entry>forward</entry>
- <entry>
- Packets forwarded to a different host are processed by the forward hook.
- </entry>
- </row>
- <row>
- <entry>output</entry>
- <entry>
- Packets sent by local processes are processed by the output hook.
- </entry>
- </row>
- <row>
- <entry>postrouting</entry>
- <entry>
- All packets leaving the system are processed by the postrouting hook.
- </entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- </refsect2>
- <refsect2>
- <title>ARP address family</title>
- <para>
- The ARP address family handles ARP packets received and sent by the system. It is commonly used
- to mangle ARP packets for clustering.
- </para>
- <para>
- <table frame="all">
- <title>ARP address family hooks</title>
- <tgroup cols='2' align='left' colsep='1' rowsep='1' pgwide="1">
- <colspec colname='c1' colwidth="1*"/>
- <colspec colname='c2' colwidth="5*"/>
- <thead>
- <row>
- <entry>Hook</entry>
- <entry>Description</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>input</entry>
- <entry>
- Packets delivered to the local system are processed by the input hook.
- </entry>
- </row>
- <row>
- <entry>output</entry>
- <entry>
- Packets send by the local system are processed by the output hook.
- </entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- </refsect2>
- <refsect2>
- <title>Bridge address family</title>
- <para>
- The bridge address family handles Ethernet packets traversing bridge devices.
- </para>
- <para>
- The list of supported hooks is identical to IPv4/IPv6/Inet address families above.
- </para>
- </refsect2>
- <refsect2>
- <title>Netdev address family</title>
- <para>
- The Netdev address family handles packets from ingress.
- </para>
- <para>
- <table frame="all">
- <title>Netdev address family hooks</title>
- <tgroup cols='2' align='left' colsep='1' rowsep='1' pgwide="1">
- <colspec colname='c1' colwidth="1*"/>
- <colspec colname='c2' colwidth="5*"/>
- <thead>
- <row>
- <entry>Hook</entry>
- <entry>Description</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>ingress</entry>
- <entry>
- All packets entering the system are processed by this hook. It is invoked
- before layer 3 protocol handlers and it can be used for early filtering and
- policing.
- </entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- </refsect2>
-
- </refsect1>
-
- <refsect1>
- <title>Ruleset</title>
- <para>
- <cmdsynopsis>
- <group choice="req">
- <arg>list</arg>
- <arg>flush</arg>
- </group>
- <command>ruleset</command>
- <arg choice="opt"><replaceable>family</replaceable></arg>
- </cmdsynopsis>
- <cmdsynopsis>
- <arg choice="plain">export</arg>
- <arg choice="opt"><command>ruleset</command></arg>
- <arg choice="plain"><replaceable>format</replaceable></arg>
- </cmdsynopsis>
- </para>
-
- <para>
- The <command>ruleset</command> keyword is used to identify the whole
- set of tables, chains, etc. currently in place in kernel. The
- following <command>ruleset</command> commands exist:
- </para>
-
- <variablelist>
- <varlistentry>
- <term><option>list</option></term>
- <listitem>
- <para>
- Print the ruleset in human-readable format.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>flush</option></term>
- <listitem>
- <para>
- Clear the whole ruleset. Note that unlike iptables, this
- will remove all tables and whatever they contain,
- effectively leading to an empty ruleset - no packet
- filtering will happen anymore, so the kernel accepts any
- valid packet it receives.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>export</option></term>
- <listitem>
- <para>
- Print the ruleset in machine readable format. The
- mandatory <replaceable>format</replaceable> parameter
- may be either <literal>xml</literal> or
- <literal>json</literal>.
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
-
- <para>
- It is possible to limit <command>list</command> and
- <command>flush</command> to a specific address family only. For a
- list of valid family names, see <literal>ADDRESS FAMILIES</literal> above.
- </para>
-
- <para>
- Note that contrary to what one might assume, the output generated
- by <command>export</command> is not parseable by
- <command>nft -f</command>. Instead, the output of
- <command>list</command> command serves well for that purpose.
- </para>
- </refsect1>
-
- <refsect1>
- <title>Tables</title>
- <para>
- <cmdsynopsis>
- <group choice="req">
- <arg>add</arg>
- <arg>create</arg>
- </group>
- <command>table</command>
- <arg choice="opt"><replaceable>family</replaceable></arg>
- <replaceable>table</replaceable>
- <arg choice="opt">
- <arg choice="req">
- flags <replaceable>flags</replaceable>
- </arg>
- </arg>
- </cmdsynopsis>
- <cmdsynopsis>
- <group choice="req">
- <arg>delete</arg>
- <arg>list</arg>
- <arg>flush</arg>
- </group>
- <command>table</command>
- <arg choice="opt"><replaceable>family</replaceable></arg>
- <replaceable>table</replaceable>
- </cmdsynopsis>
- <cmdsynopsis>
- <literal>delete</literal>
- <command>table</command>
- <arg choice="opt"><replaceable>family</replaceable></arg>
- <literal> handle </literal><replaceable>handle</replaceable>
- </cmdsynopsis>
- </para>
-
- <para>
- Tables are containers for chains, sets and stateful objects. They are identified by their address family
- and their name. The address family must be one of
-
- <simplelist type="inline">
- <member><literal>ip</literal></member>
- <member><literal>ip6</literal></member>
- <member><literal>inet</literal></member>
- <member><literal>arp</literal></member>
- <member><literal>bridge</literal></member>
- <member><literal>netdev</literal></member>
- </simplelist>.
-
- The <literal>inet</literal> address family is a dummy family which is used to create
- hybrid IPv4/IPv6 tables. The <literal>meta</literal> expression <literal>nfproto</literal>
- keyword can be used to test which family (IPv4 or IPv6) context the packet is being processed in.
-
- When no address family is specified, <literal>ip</literal> is used by default.
-
- The only difference between <command>add</command> and <command>create</command> is that the former will
- not return an error if the specified table already exists while <command>create</command> will return an error.
-
- <table frame="all">
- <title>Table flags</title>
- <tgroup cols='2' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <thead>
- <row>
- <entry>Flag</entry>
- <entry>Description</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>dormant</entry>
- <entry>table is not evaluated any more (base chains are unregistered)</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
-
- <para>
- <example>
- <title>Add, change, delete a table</title>
- <programlisting>
-# start nft in interactive mode
-nft --interactive
-
-# create a new table.
-create table inet mytable
-
-# add a new base chain: get input packets
-add chain inet mytable myin { type filter hook input priority 0; }
-
-# add a single counter to the chain
-add rule inet mytable myin counter
-
-# disable the table temporarily -- rules are not evaluated anymore
-add table inet mytable { flags dormant; }
-
-# make table active again:
-add table inet mytable
- </programlisting>
- </example>
- </para>
-
- <variablelist>
- <varlistentry>
- <term><option>add</option></term>
- <listitem>
- <para>
- Add a new table for the given family with the given name.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>delete</option></term>
- <listitem>
- <para>
- Delete the specified table.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>list</option></term>
- <listitem>
- <para>
- List all chains and rules of the specified table.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>flush</option></term>
- <listitem>
- <para>
- Flush all chains and rules of the specified table.
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </refsect1>
-
- <refsect1>
- <title>Chains</title>
- <para>
- <cmdsynopsis>
- <group choice="req">
- <arg>add</arg>
- <arg>create</arg>
- </group>
- <command>chain</command>
- <arg choice="opt"><replaceable>family</replaceable></arg>
- <arg choice="plain"><replaceable>table</replaceable></arg>
- <arg choice="plain"><replaceable>chain</replaceable></arg>
- <arg choice="opt">
- <arg choice="req">
- type <replaceable>type</replaceable>
- hook <replaceable>hook</replaceable>
- <arg choice="opt">device <replaceable>device</replaceable></arg>
- priority <replaceable>priority</replaceable> ;
- <arg choice="opt">policy <replaceable>policy</replaceable> ;</arg>
- </arg>
- </arg>
- </cmdsynopsis>
- <cmdsynopsis>
- <group choice="req">
- <arg>delete</arg>
- <arg>list</arg>
- <arg>flush</arg>
- </group>
- <command>chain</command>
- <arg choice="opt"><replaceable>family</replaceable></arg>
- <replaceable>table</replaceable>
- <replaceable>chain</replaceable>
- </cmdsynopsis>
- <cmdsynopsis>
- <literal>delete</literal>
- <command>chain</command>
- <arg choice="opt"><replaceable>family</replaceable></arg>
- <replaceable>table</replaceable>
- <literal> handle </literal><replaceable>handle</replaceable>
- </cmdsynopsis>
- <cmdsynopsis>
- <literal>rename</literal>
- <command>chain</command>
- <arg choice="opt"><replaceable>family</replaceable></arg>
- <replaceable>table</replaceable>
- <replaceable>chain</replaceable>
- <replaceable>newname</replaceable>
- </cmdsynopsis>
- </para>
-
- <para>
- Chains are containers for rules. They exist in two kinds,
- base chains and regular chains. A base chain is an entry point for
- packets from the networking stack, a regular chain may be used
- as jump target and is used for better rule organization.
- </para>
-
- <variablelist>
- <varlistentry>
- <term><option>add</option></term>
- <listitem>
- <para>
- Add a new chain in the specified table. When a hook and priority
- value are specified, the chain is created as a base chain and hooked
- up to the networking stack.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>create</option></term>
- <listitem>
- <para>
- Similar to the <command>add</command> command, but returns an error if the
- chain already exists.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>delete</option></term>
- <listitem>
- <para>
- Delete the specified chain. The chain must not contain any rules or be
- used as jump target.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>rename</option></term>
- <listitem>
- <para>
- Rename the specified chain.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>list</option></term>
- <listitem>
- <para>
- List all rules of the specified chain.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>flush</option></term>
- <listitem>
- <para>
- Flush all rules of the specified chain.
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
-
- <para>
- For base chains, <command>type</command>, <command>hook</command> and <command>priority</command> parameters are mandatory.
- </para>
- <para>
- <table frame="all">
- <title>Supported chain types</title>
- <tgroup cols="4" align="left" colsep="1" rowsep="1">
- <colspec colname="c1"/>
- <colspec colname="c2"/>
- <colspec colname="c3"/>
- <colspec colname="c4"/>
- <thead>
- <row>
- <entry>Type</entry>
- <entry>Families</entry>
- <entry>Hooks</entry>
- <entry>Description</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>filter</entry>
- <entry>all</entry>
- <entry>all</entry>
- <entry>Standard chain type to use in doubt.</entry>
- </row>
- <row>
- <entry>nat</entry>
- <entry>ip, ip6</entry>
- <entry>prerouting, input, output, postrouting</entry>
- <entry>Chains of this type perform Network Address Translation based on conntrack entries. Only the first packet of a connection actually traverses this chain - its rules usually define details of the created conntrack entry (NAT statements for instance).</entry>
- </row>
- <row>
- <entry>route</entry>
- <entry>ip, ip6</entry>
- <entry>output</entry>
- <entry>If a packet has traversed a chain of this
- type and is about to be accepted, a new route
- lookup is performed if relevant parts of the IP
- header have changed. This allows to e.g.
- implement policy routing selectors in
- nftables.</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- <para>
- Apart from the special cases illustrated above (e.g. <literal>nat</literal> type not supporting <literal>forward</literal> hook or <literal>route</literal> type only supporting <literal>output</literal> hook), there are two further quirks worth noticing:
- <itemizedlist>
- <listitem>
- <literal>netdev</literal> family supports merely a single
- combination, namely <literal>filter</literal> type and
- <literal>ingress</literal> hook. Base chains in this family also require the <literal>device</literal> parameter to be present since they exist per incoming interface only.
- </listitem>
- <listitem>
- <literal>arp</literal> family supports only
- <literal>input</literal> and <literal>output</literal>
- hooks, both in chains of type
- <literal>filter</literal>.
- </listitem>
- </itemizedlist>
- </para>
- <para>
- The <literal>priority</literal> parameter accepts a signed integer value which specifies the order in which chains with same <literal>hook</literal> value are traversed. The ordering is ascending, i.e. lower priority values have precedence over higher ones.
- </para>
- <para>
- Base chains also allow to set the chain's <literal>policy</literal>, i.e. what happens to packets not explicitly accepted or refused in contained rules. Supported policy values are <literal>accept</literal> (which is the default) or <literal>drop</literal>.
- </para>
- </refsect1>
-
- <refsect1>
- <title>Rules</title>
- <para>
- <cmdsynopsis>
- <group>
- <arg choice="opt">add</arg>
- <arg choice="req">insert</arg>
- </group>
- <command>rule</command>
- <arg choice="opt"><replaceable>family</replaceable></arg>
- <replaceable>table</replaceable>
- <replaceable>chain</replaceable>
- <group choice="opt">
- <arg>
- <group choice="req">
- <arg>handle</arg>
- <arg>position</arg>
- </group>
- <replaceable>handle</replaceable>
- </arg>
- <arg>
- <literal>index</literal>
- <replaceable>index</replaceable>
- </arg>
- </group>
- <replaceable>statement</replaceable>...
- </cmdsynopsis>
- <cmdsynopsis>
-
- <literal>replace </literal><command>rule</command>
- <arg choice="opt"><replaceable>family</replaceable></arg>
- <replaceable>table</replaceable>
- <replaceable>chain</replaceable>
- <literal> handle </literal><replaceable>handle</replaceable>
- <replaceable>statement</replaceable>...
- </cmdsynopsis>
- <cmdsynopsis>
- <literal>delete</literal>
- <command>rule</command>
- <arg choice="opt"><replaceable>family</replaceable></arg>
- <replaceable>table</replaceable>
- <replaceable>chain</replaceable>
- <literal> handle </literal><replaceable>handle</replaceable>
- </cmdsynopsis>
- </para>
- <para>
- Rules are added to <literal>chain</literal> in the given <literal>table</literal>.
- If the <literal>family</literal> is not specified, the <literal>ip</literal> family
- is used.
- Rules are constructed from two kinds of components according to a set
- of grammatical rules: expressions and statements.
- </para>
- <para>
- The <literal>add</literal> and <literal>insert</literal> commands support an optional
- location specifier, which is either a <replaceable>handle</replaceable> of an existing
- rule or an <replaceable>index</replaceable> (starting at zero). Internally,
- rule locations are always identified by <replaceable>handle</replaceable> and the
- translation from <replaceable>index</replaceable> happens in userspace. This has two
- potential implications in case a concurrent ruleset change happens after the translation
- was done: The effective rule index might change if a rule was inserted or deleted before
- the referred one. If the referred rule was deleted, the command is rejected by the
- kernel just as if an invalid <replaceable>handle</replaceable> was given.
- </para>
-
- <variablelist>
- <varlistentry>
- <term><option>add</option></term>
- <listitem>
- <para>
- Add a new rule described by the list of statements. The rule is appended to the
- given chain unless a <literal>handle</literal> is specified, in which case the
- rule is appended to the rule given by the <replaceable>handle</replaceable>.
- The alternative name <literal>position</literal> is deprecated and should not be
- used anymore.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>insert</option></term>
- <listitem>
- <para>
- Similar to the <command>add</command> command, but the rule is prepended to the
- beginning of the chain or before the rule with the given
- <replaceable>handle</replaceable>.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>replace</option></term>
- <listitem>
- <para>
- Similar to the <command>add</command> command, but the rule replaces the specified rule.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>delete</option></term>
- <listitem>
- <para>
- Delete the specified rule.
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
-
- <example>
- <title>add a rule to ip table input chain</title>
- <programlisting>
-nft add rule filter output ip daddr 192.168.0.0/24 accept # 'ip filter' is assumed
-# same command, slightly more verbose
-nft add rule ip filter output ip daddr 192.168.0.0/24 accept
-
- </programlisting>
- </example>
- <example>
- <title>delete rule from inet table</title>
- <programlisting>
-# nft -a list ruleset
-table inet filter {
- chain input {
- type filter hook input priority 0; policy accept;
- ct state established,related accept # handle 4
- ip saddr 10.1.1.1 tcp dport ssh accept # handle 5
- ...
-# delete the rule with handle 5
-# nft delete rule inet filter input handle 5
- </programlisting>
- </example>
- </refsect1>
-
- <refsect1>
- <title>Sets</title>
- <para>
- nftables offers two kinds of set concepts.
- Anonymous sets are sets that have no specific name. The set members are enclosed in curly braces,
- with commas to separate elements when creating the rule the set is used in.
- Once that rule is removed, the set is removed as well.
- They cannot be updated, i.e. once an anonymous set is declared it cannot be changed anymore except by
- removing/altering the rule that uses the anonymous set.
- <example>
- <title>Using anonymous sets to accept particular subnets and ports</title>
- <programlisting>
- nft add rule filter input ip saddr { 10.0.0.0/8, 192.168.0.0/16 } tcp dport { 22, 443 } accept
- </programlisting>
- </example>
- Named sets are sets that need to be defined first before they can be referenced
- in rules. Unlike anonymous sets, elements can be added to or removed from a named set at any time.
- Sets are referenced from rules using an <literal>@</literal> prefixed to the sets name.
- <example>
- <title>Using named sets to accept addresses and ports</title>
- <programlisting>
- nft add rule filter input ip saddr @allowed_hosts tcp dport @allowed_ports accept
- </programlisting>
- The sets <literal>allowed_hosts</literal> and <literal>allowed_ports</literal> need to
- be created first. The next section describes nft set syntax in more detail.
- </example>
- </para>
- <para>
- <cmdsynopsis>
- <literal>add</literal>
- <command> set</command>
- <arg choice="opt"><replaceable>family</replaceable></arg>
- <replaceable>table</replaceable>
- <replaceable>set</replaceable>
- { type
- <replaceable>type</replaceable> ;
- <arg choice="opt">flags <replaceable>flags</replaceable> ;</arg>
- <arg choice="opt">timeout <replaceable>timeout</replaceable> ;</arg>
- <arg choice="opt">gc-interval <replaceable>gc-interval</replaceable> ;</arg>
- <arg choice="opt">elements = { <replaceable>element</replaceable>[,...] } ;</arg>
- <arg choice="opt">size <replaceable>size</replaceable> ;</arg>
- <arg choice="opt">policy <replaceable>policy</replaceable> ;</arg>
- <arg choice="opt">auto-merge <replaceable>auto-merge</replaceable> ;</arg>
- }
- </cmdsynopsis>
- <cmdsynopsis>
- <group choice="req">
- <arg>delete</arg>
- <arg>list</arg>
- <arg>flush</arg>
- </group>
- <command> set</command>
- <arg choice="opt"><replaceable>family</replaceable></arg>
- <replaceable>table</replaceable>
- <replaceable>set</replaceable>
- </cmdsynopsis>
- <cmdsynopsis>
- <literal>delete</literal>
- <command> set</command>
- <arg choice="opt"><replaceable>family</replaceable></arg>
- <replaceable>table</replaceable>
- <literal> handle </literal><replaceable>handle</replaceable>
- </cmdsynopsis>
- <cmdsynopsis>
- <group choice="req">
- <arg>add</arg>
- <arg>delete</arg>
- </group>
- <command> element</command>
- <arg choice="opt"><replaceable>family</replaceable></arg>
- <replaceable>table</replaceable>
- <replaceable>set</replaceable>
- {
- <replaceable>element</replaceable>[,...] }
- </cmdsynopsis>
- </para>
- <para>
- Sets are elements containers of an user-defined data type, they are uniquely identified by an user-defined name and attached to tables.
- Their behaviour can be tuned with the <literal>flags</literal> that can be specified at set creation time.
- </para>
-
- <variablelist>
- <varlistentry>
- <term><option>add</option></term>
- <listitem>
- <para>
- Add a new set in the specified table. See the <literal>Set specification</literal> table below
- for more information about how to specify a sets properties.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>delete</option></term>
- <listitem>
- <para>
- Delete the specified set.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>list</option></term>
- <listitem>
- <para>
- Display the elements in the specified set.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>flush</option></term>
- <listitem>
- <para>
- Remove all elements from the specified set.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>add element</option></term>
- <listitem>
- <para>
- Comma-separated list of elements to add into the specified set.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>delete element</option></term>
- <listitem>
- <para>
- Comma-separated list of elements to delete from the specified set.
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
-
- <table frame="all">
- <title>Set specifications</title>
- <tgroup cols='3' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <colspec colname='c3'/>
- <thead>
- <row>
- <entry>Keyword</entry>
- <entry>Description</entry>
- <entry>Type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>type</entry>
- <entry>data type of set elements</entry>
- <entry>string: ipv4_addr, ipv6_addr, ether_addr, inet_proto, inet_service, mark</entry>
- </row>
- <row>
- <entry>flags</entry>
- <entry>set flags</entry>
- <entry>string: constant, dynamic, interval, timeout</entry>
- </row>
- <row>
- <entry>timeout</entry>
- <entry>time an element stays in the set, mandatory if set is added to from the packet path (ruleset).</entry>
- <entry>string, decimal followed by unit. Units are: d, h, m, s</entry>
- </row>
- <row>
- <entry>gc-interval</entry>
- <entry>garbage collection interval, only available when timeout or flag timeout are active</entry>
- <entry>string, decimal followed by unit. Units are: d, h, m, s</entry>
- </row>
- <row>
- <entry>elements</entry>
- <entry>elements contained by the set</entry>
- <entry>set data type</entry>
- </row>
- <row>
- <entry>size</entry>
- <entry>maximum number of elements in the set, mandatory if set is added to from the packet path (ruleset).</entry>
- <entry>unsigned integer (64 bit)</entry>
- </row>
- <row>
- <entry>policy</entry>
- <entry>set policy</entry>
- <entry>string: performance [default], memory</entry>
- </row>
- <row>
- <entry>auto-merge</entry>
- <entry>automatic merge of adjacent/overlapping set elements (only for interval sets)</entry>
- <entry></entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </refsect1>
-
- <refsect1>
- <title>Maps</title>
- <para>
- <cmdsynopsis>
- <literal>add</literal>
- <command> map</command>
- <arg choice="opt"><replaceable>family</replaceable></arg>
- <replaceable>table</replaceable>
- <replaceable>map</replaceable>
- { type
- <replaceable>type</replaceable>
- <arg choice="opt">flags <replaceable>flags</replaceable> ;</arg>
- <arg choice="opt">elements = { <replaceable>element</replaceable>[,...] } ;</arg>
- <arg choice="opt">size <replaceable>size</replaceable> ;</arg>
- <arg choice="opt">policy <replaceable>policy</replaceable> ;</arg>
- }
- </cmdsynopsis>
- <cmdsynopsis>
- <group choice="req">
- <arg>delete</arg>
- <arg>list</arg>
- <arg>flush</arg>
- </group>
- <command> map</command>
- <arg choice="opt"><replaceable>family</replaceable></arg>
- <replaceable>table</replaceable>
- <replaceable>map</replaceable>
- </cmdsynopsis>
- <cmdsynopsis>
- <group choice="req">
- <arg>add</arg>
- <arg>delete</arg>
- </group>
- <command> element</command>
- <arg choice="opt"><replaceable>family</replaceable></arg>
- <replaceable>table</replaceable>
- <replaceable>map</replaceable>
- {
- elements = { <replaceable>element</replaceable>[,...] } ;
- }
- </cmdsynopsis>
- </para>
- <para>
- Maps store data based on some specific key used as input, they are uniquely identified by an user-defined name and attached to tables.
- </para>
-
- <variablelist>
- <varlistentry>
- <term><option>add</option></term>
- <listitem>
- <para>
- Add a new map in the specified table.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>delete</option></term>
- <listitem>
- <para>
- Delete the specified map.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>list</option></term>
- <listitem>
- <para>
- Display the elements in the specified map.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>flush</option></term>
- <listitem>
- <para>
- Remove all elements from the specified map.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>add element</option></term>
- <listitem>
- <para>
- Comma-separated list of elements to add into the specified map.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>delete element</option></term>
- <listitem>
- <para>
- Comma-separated list of element keys to delete from the specified map.
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
-
- <table frame="all">
- <title>Map specifications</title>
- <tgroup cols='3' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <colspec colname='c3'/>
- <thead>
- <row>
- <entry>Keyword</entry>
- <entry>Description</entry>
- <entry>Type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>type</entry>
- <entry>data type of map elements</entry>
- <entry>string ':' string: ipv4_addr, ipv6_addr, ether_addr, inet_proto, inet_service, mark, counter, quota. Counter and quota can't be used as keys</entry>
- </row>
- <row>
- <entry>flags</entry>
- <entry>map flags</entry>
- <entry>string: constant, interval</entry>
- </row>
- <row>
- <entry>elements</entry>
- <entry>elements contained by the map</entry>
- <entry>map data type</entry>
- </row>
- <row>
- <entry>size</entry>
- <entry>maximum number of elements in the map</entry>
- <entry>unsigned integer (64 bit)</entry>
- </row>
- <row>
- <entry>policy</entry>
- <entry>map policy</entry>
- <entry>string: performance [default], memory</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </refsect1>
-
- <refsect1>
- <title>Flowtables</title>
- <para>
- <cmdsynopsis>
- <group choice="req">
- <arg>add</arg>
- <arg>create</arg>
- </group>
- <command>flowtable</command>
- <arg choice="opt"><replaceable>family</replaceable></arg>
- <arg choice="plain"><replaceable>table</replaceable></arg>
- <arg choice="plain"><replaceable>flowtable</replaceable></arg>
- <arg choice="req">
- hook <replaceable>hook</replaceable>
- priority <replaceable>priority</replaceable> ;
- devices = { <replaceable>device</replaceable>[,...] } ;
- </arg>
- </cmdsynopsis>
- <cmdsynopsis>
- <group choice="req">
- <arg>delete</arg>
- <arg>list</arg>
- </group>
- <command>flowtable</command>
- <arg choice="opt"><replaceable>family</replaceable></arg>
- <replaceable>table</replaceable>
- <replaceable>flowtable</replaceable>
- </cmdsynopsis>
- </para>
-
- <para>
- Flowtables allow you to accelerate packet forwarding in software.
- Flowtables entries are represented through a tuple that is composed of the
- input interface, source and destination address, source and destination
- port; and layer 3/4 protocols. Each entry also caches the destination
- interface and the gateway address - to update the destination link-layer
- address - to forward packets. The ttl and hoplimit fields are also
- decremented. Hence, flowtables provides an alternative path that allow
- packets to bypass the classic forwarding path. Flowtables reside in the
- ingress hook, that is located before the prerouting hook. You can select
- what flows you want to offload through the <literal>flow offload</literal>
- expression from the <literal>forward</literal> chain. Flowtables are
- identified by their address family and their name. The address family
- must be one of
-
- <simplelist type="inline">
- <member><literal>ip</literal></member>
- <member><literal>ip6</literal></member>
- <member><literal>inet</literal></member>
- </simplelist>.
-
- The <literal>inet</literal> address family is a dummy family which is used to create
- hybrid IPv4/IPv6 tables.
-
- When no address family is specified, <literal>ip</literal> is used by default.
- </para>
-
- <variablelist>
- <varlistentry>
- <term><option>add</option></term>
- <listitem>
- <para>
- Add a new flowtable for the given family with the given name.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>delete</option></term>
- <listitem>
- <para>
- Delete the specified flowtable.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>list</option></term>
- <listitem>
- <para>
- List all flowtables.
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </refsect1>
-
- <refsect1>
- <title>Stateful objects</title>
- <para>
- <cmdsynopsis>
- <group choice="req">
- <arg>add</arg>
- <arg>delete</arg>
- <arg>list</arg>
- <arg>reset</arg>
- </group>
- <command> type</command>
- <arg choice="opt"><replaceable>family</replaceable></arg>
- <replaceable>table</replaceable>
- <replaceable>object</replaceable>
- </cmdsynopsis>
- <cmdsynopsis>
- <literal>delete</literal>
- <command> type</command>
- <arg choice="opt"><replaceable>family</replaceable></arg>
- <replaceable>table</replaceable>
- <literal> handle </literal><replaceable>handle</replaceable>
- </cmdsynopsis>
- </para>
- <para>
- Stateful objects are attached to tables and are identified by a unique name. They group stateful information from rules, to reference them in rules the keywords "type name" are used e.g. "counter name".
- </para>
-
- <variablelist>
- <varlistentry>
- <term><option>add</option></term>
- <listitem>
- <para>
- Add a new stateful object in the specified table.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>delete</option></term>
- <listitem>
- <para>
- Delete the specified object.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>list</option></term>
- <listitem>
- <para>
- Display stateful information the object holds.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>reset</option></term>
- <listitem>
- <para>
- List-and-reset stateful object.
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
-
- <refsect2>
- <title>Ct</title>
- <para>
- <cmdsynopsis>
- <command>ct</command>
- <literal>helper</literal>
- <replaceable>helper</replaceable>
- <literal> { type </literal>
- <replaceable>type</replaceable>
- <literal> protocol </literal>
- <replaceable>protocol</replaceable>
- <literal> ;</literal>
- <arg choice="opt"><literal>l3proto </literal><replaceable>family</replaceable><literal> ;</literal></arg>
- <literal> }</literal>
- </cmdsynopsis>
- </para>
- <para>
- Ct helper is used to define connection tracking helpers that can then be used in combination with the <literal>"ct helper set"</literal> statement.
- type and protocol are mandatory, l3proto is derived from the table family by default, i.e. in the inet table the kernel will
- try to load both the IPv4 and IPv6 helper backends, if they are supported by the kernel.
- </para>
- <table frame="all">
- <title>conntrack helper specifications</title>
- <tgroup cols='3' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <colspec colname='c3'/>
- <thead>
- <row>
- <entry>Keyword</entry>
- <entry>Description</entry>
- <entry>Type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>type</entry>
- <entry>name of helper type</entry>
- <entry>quoted string (e.g. "ftp")</entry>
- </row>
- <row>
- <entry>protocol</entry>
- <entry>layer 4 protocol of the helper</entry>
- <entry>string (e.g. tcp)</entry>
- </row>
- <row>
- <entry>l3proto</entry>
- <entry>layer 3 protocol of the helper</entry>
- <entry>address family (e.g. ip)</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- <example>
- <title>defining and assigning ftp helper</title>
- <para>
- Unlike iptables, helper assignment needs to be performed after the conntrack lookup has completed, for example
- with the default 0 hook priority.
- </para>
- <programlisting>
-table inet myhelpers {
- ct helper ftp-standard {
- type "ftp" protocol tcp
- }
- chain prerouting {
- type filter hook prerouting priority 0;
- tcp dport 21 ct helper set "ftp-standard"
- }
-}
- </programlisting>
- </example>
- </refsect2>
-
- <refsect2>
- <title>Counter</title>
- <para>
- <cmdsynopsis>
- <command>counter</command>
- <arg choice="opt">packets bytes</arg>
- </cmdsynopsis>
- </para>
- <table frame="all">
- <title>Counter specifications</title>
- <tgroup cols='3' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <colspec colname='c3'/>
- <thead>
- <row>
- <entry>Keyword</entry>
- <entry>Description</entry>
- <entry>Type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>packets</entry>
- <entry>initial count of packets</entry>
- <entry>unsigned integer (64 bit)</entry>
- </row>
- <row>
- <entry>bytes</entry>
- <entry>initial count of bytes</entry>
- <entry>unsigned integer (64 bit)</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </refsect2>
-
- <refsect2>
- <title>Quota</title>
- <para>
- <cmdsynopsis>
- <command>quota</command>
- <group choice="opt">
- <arg>over</arg>
- <arg>until</arg>
- </group>
- <arg choice="opt">used</arg>
- </cmdsynopsis>
- </para>
- <table frame="all">
- <title>Quota specifications</title>
- <tgroup cols='3' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <colspec colname='c3'/>
- <thead>
- <row>
- <entry>Keyword</entry>
- <entry>Description</entry>
- <entry>Type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>quota</entry>
- <entry>quota limit, used as the quota name</entry>
- <entry>Two arguments, unsigned integer (64 bit) and string: bytes, kbytes, mbytes. "over" and "until" go before these arguments</entry>
- </row>
- <row>
- <entry>used</entry>
- <entry>initial value of used quota</entry>
- <entry>Two arguments, unsigned integer (64 bit) and string: bytes, kbytes, mbytes</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </refsect2>
- </refsect1>
-
- <refsect1>
- <title>Expressions</title>
- <para>
- Expressions represent values, either constants like network addresses, port numbers etc. or data
- gathered from the packet during ruleset evaluation. Expressions can be combined using binary,
- logical, relational and other types of expressions to form complex or relational (match) expressions.
- They are also used as arguments to certain types of operations, like NAT, packet marking etc.
- </para>
- <para>
- Each expression has a data type, which determines the size, parsing and representation of
- symbolic values and type compatibility with other expressions.
- </para>
-
- <refsect2>
- <title>describe command</title>
- <para>
- <cmdsynopsis>
- <command>describe</command>
- <replaceable>expression</replaceable>
- </cmdsynopsis>
- </para>
- <para>
- The <command>describe</command> command shows information about the type of an expression and
- its data type.
- </para>
- <example>
- <title>The <command>describe</command> command</title>
- <programlisting>
-$ nft describe tcp flags
-payload expression, datatype tcp_flag (TCP flag) (basetype bitmask, integer), 8 bits
-
-predefined symbolic constants:
-fin 0x01
-syn 0x02
-rst 0x04
-psh 0x08
-ack 0x10
-urg 0x20
-ecn 0x40
-cwr 0x80
- </programlisting>
- </example>
- </refsect2>
- </refsect1>
-
- <refsect1>
- <title>Data types</title>
- <para>
- Data types determine the size, parsing and representation of symbolic values and type compatibility
- of expressions. A number of global data types exist, in addition some expression types define further
- data types specific to the expression type. Most data types have a fixed size, some however may have
- a dynamic size, f.i. the string type.
- </para>
- <para>
- Types may be derived from lower order types, f.i. the IPv4 address type is derived from the integer
- type, meaning an IPv4 address can also be specified as an integer value.
- </para>
- <para>
- In certain contexts (set and map definitions) it is necessary to explicitly specify a data type.
- Each type has a name which is used for this.
- </para>
-
- <refsect2>
- <title>Integer type</title>
- <para>
- <table frame="all">
- <tgroup cols='4' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <colspec colname='c3'/>
- <colspec colname='c4'/>
- <thead>
- <row>
- <entry>Name</entry>
- <entry>Keyword</entry>
- <entry>Size</entry>
- <entry>Base type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>Integer</entry>
- <entry>integer</entry>
- <entry>variable</entry>
- <entry>-</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- <para>
- The integer type is used for numeric values. It may be specified as decimal, hexadecimal
- or octal number. The integer type doesn't have a fixed size, its size is determined by the
- expression for which it is used.
- </para>
- </refsect2>
-
- <refsect2>
- <title>Bitmask type</title>
- <para>
- <table frame="all">
- <tgroup cols='4' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <colspec colname='c3'/>
- <colspec colname='c4'/>
- <thead>
- <row>
- <entry>Name</entry>
- <entry>Keyword</entry>
- <entry>Size</entry>
- <entry>Base type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>Bitmask</entry>
- <entry>bitmask</entry>
- <entry>variable</entry>
- <entry>integer</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- <para>
- The bitmask type (<command>bitmask</command>) is used for bitmasks.
- </para>
- </refsect2>
-
- <refsect2>
- <title>String type</title>
- <para>
- <table frame="all">
- <tgroup cols='4' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <colspec colname='c3'/>
- <colspec colname='c4'/>
- <thead>
- <row>
- <entry>Name</entry>
- <entry>Keyword</entry>
- <entry>Size</entry>
- <entry>Base type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>String</entry>
- <entry>string</entry>
- <entry>variable</entry>
- <entry>-</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- <para>
- The string type is used for character strings. A string begins with an alphabetic character
- (a-zA-Z) followed by zero or more alphanumeric characters or the characters <literal>/</literal>,
- <literal>-</literal>, <literal>_</literal> and <literal>.</literal>. In addition anything enclosed
- in double quotes (<literal>"</literal>) is recognized as a string.
- </para>
- <example>
- <title>String specification</title>
- <programlisting>
-# Interface name
-filter input iifname eth0
-
-# Weird interface name
-filter input iifname "(eth0)"
- </programlisting>
- </example>
- </refsect2>
-
- <refsect2>
- <title>Link layer address type</title>
- <para>
- <table frame="all">
- <tgroup cols='4' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <colspec colname='c3'/>
- <colspec colname='c4'/>
- <thead>
- <row>
- <entry>Name</entry>
- <entry>Keyword</entry>
- <entry>Size</entry>
- <entry>Base type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>Link layer address</entry>
- <entry>lladdr</entry>
- <entry>variable</entry>
- <entry>integer</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- <para>
- The link layer address type is used for link layer addresses. Link layer addresses are specified
- as a variable amount of groups of two hexadecimal digits separated using colons (<literal>:</literal>).
- </para>
- <example>
- <title>Link layer address specification</title>
- <programlisting>
-# Ethernet destination MAC address
-filter input ether daddr 20:c9:d0:43:12:d9
- </programlisting>
- </example>
- </refsect2>
-
- <refsect2>
- <title>IPv4 address type</title>
- <para>
- <table frame="all">
- <tgroup cols='4' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <colspec colname='c3'/>
- <colspec colname='c4'/>
- <thead>
- <row>
- <entry>Name</entry>
- <entry>Keyword</entry>
- <entry>Size</entry>
- <entry>Base type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>IPv4 address</entry>
- <entry>ipv4_addr</entry>
- <entry>32 bit</entry>
- <entry>integer</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- <para>
- The IPv4 address type is used for IPv4 addresses. Addresses are specified in either dotted decimal,
- dotted hexadecimal, dotted octal, decimal, hexadecimal, octal notation or as a host name. A host name
- will be resolved using the standard system resolver.
- </para>
- <example>
- <title>IPv4 address specification</title>
- <programlisting>
-# dotted decimal notation
-filter output ip daddr 127.0.0.1
-
-# host name
-filter output ip daddr localhost
- </programlisting>
- </example>
- </refsect2>
-
- <refsect2>
- <title>IPv6 address type</title>
- <para>
- <table frame="all">
- <tgroup cols='4' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <colspec colname='c3'/>
- <colspec colname='c4'/>
- <thead>
- <row>
- <entry>Name</entry>
- <entry>Keyword</entry>
- <entry>Size</entry>
- <entry>Base type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>IPv6 address</entry>
- <entry>ipv6_addr</entry>
- <entry>128 bit</entry>
- <entry>integer</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- <para>
- The IPv6 address type is used for IPv6 addresses.
- Addresses are specified as a host name or as hexadecimal halfwords separated
- by colons. Addresses might be enclosed in square brackets ("[]") to differentiate them
- from port numbers.
- </para>
- <example>
- <title>IPv6 address specification</title>
- <programlisting>
-# abbreviated loopback address
-filter output ip6 daddr ::1
- </programlisting>
- <example>
- </example>
- <title>IPv6 address specification with bracket notation</title>
- <programlisting>
-# without [] the port number (22) would be parsed as part of ipv6 address
-ip6 nat prerouting tcp dport 2222 dnat to [1ce::d0]:22
- </programlisting>
- </example>
- </refsect2>
-
- <refsect2>
- <title>Boolean type</title>
- <para>
- <table frame="all">
- <tgroup cols='4' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <colspec colname='c3'/>
- <colspec colname='c4'/>
- <thead>
- <row>
- <entry>Name</entry>
- <entry>Keyword</entry>
- <entry>Size</entry>
- <entry>Base type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>Boolean</entry>
- <entry>boolean</entry>
- <entry>1 bit</entry>
- <entry>integer</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- <para>
- The boolean type is a syntactical helper type in user space.
- It's use is in the right-hand side of a (typically implicit)
- relational expression to change the expression on the left-hand
- side into a boolean check (usually for existence).
- </para>
- <para>
- The following keywords will automatically resolve into a boolean
- type with given value:
- <table frame="all">
- <tgroup cols='2' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <thead>
- <row>
- <entry>Keyword</entry>
- <entry>Value</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>exists</entry>
- <entry>1</entry>
- </row>
- <row>
- <entry>missing</entry>
- <entry>0</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- <example>
- <title>Boolean specification</title>
- <para>
- The following expressions support a boolean comparison:
- <table frame="all">
- <tgroup cols='2' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <thead>
- <row>
- <entry>Expression</entry>
- <entry>Behaviour</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>fib</entry>
- <entry>Check route existence.</entry>
- </row>
- <row>
- <entry>exthdr</entry>
- <entry>Check IPv6 extension header existence.</entry>
- </row>
- <row>
- <entry>tcp option</entry>
- <entry>Check TCP option header existence.</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- <programlisting>
-# match if route exists
-filter input fib daddr . iif oif exists
-
-# match only non-fragmented packets in IPv6 traffic
-filter input exthdr frag missing
-
-# match if TCP timestamp option is present
-filter input tcp option timestamp exists
- </programlisting>
- </example>
- </refsect2>
- <refsect2>
- <title>ICMP Type type</title>
- <para>
- <table frame="all">
- <tgroup cols="4" align="left" colsep="1" rowsep="1">
- <colspec colname="c1"/>
- <colspec colname="c2"/>
- <colspec colname="c3"/>
- <colspec colname="c4"/>
- <thead>
- <row>
- <entry>Name</entry>
- <entry>Keyword</entry>
- <entry>Size</entry>
- <entry>Base type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>ICMP Type</entry>
- <entry>icmp_type</entry>
- <entry>8 bit</entry>
- <entry>integer</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- <para>
- The ICMP Type type is used to conveniently specify the ICMP header's type field.
- </para>
- <para>
- The following keywords may be used when specifying the ICMP type:
- <table frame="all">
- <tgroup cols="2" align="left" colsep="1" rowsep="1">
- <colspec colname="c1"/>
- <colspec colname="c2"/>
- <thead>
- <row>
- <entry>Keyword</entry>
- <entry>Value</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>echo-reply</entry>
- <entry>0</entry>
- </row>
- <row>
- <entry>destination-unreachable</entry>
- <entry>3</entry>
- </row>
- <row>
- <entry>source-quench</entry>
- <entry>4</entry>
- </row>
- <row>
- <entry>redirect</entry>
- <entry>5</entry>
- </row>
- <row>
- <entry>echo-request</entry>
- <entry>8</entry>
- </row>
- <row>
- <entry>router-advertisement</entry>
- <entry>9</entry>
- </row>
- <row>
- <entry>router-solicitation</entry>
- <entry>10</entry>
- </row>
- <row>
- <entry>time-exceeded</entry>
- <entry>11</entry>
- </row>
- <row>
- <entry>parameter-problem</entry>
- <entry>12</entry>
- </row>
- <row>
- <entry>timestamp-request</entry>
- <entry>13</entry>
- </row>
- <row>
- <entry>timestamp-reply</entry>
- <entry>14</entry>
- </row>
- <row>
- <entry>info-request</entry>
- <entry>15</entry>
- </row>
- <row>
- <entry>info-reply</entry>
- <entry>16</entry>
- </row>
- <row>
- <entry>address-mask-request</entry>
- <entry>17</entry>
- </row>
- <row>
- <entry>address-mask-reply</entry>
- <entry>18</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- <example>
- <title>ICMP Type specification</title>
- <programlisting>
-# match ping packets
-filter output icmp type { echo-request, echo-reply }
- </programlisting>
- </example>
- </refsect2>
- <refsect2>
- <title>ICMP Code type</title>
- <para>
- <table frame="all">
- <tgroup cols="4" align="left" colsep="1" rowsep="1">
- <colspec colname="c1"/>
- <colspec colname="c2"/>
- <colspec colname="c3"/>
- <colspec colname="c4"/>
- <thead>
- <row>
- <entry>Name</entry>
- <entry>Keyword</entry>
- <entry>Size</entry>
- <entry>Base type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>ICMP Code</entry>
- <entry>icmp_code</entry>
- <entry>8 bit</entry>
- <entry>integer</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- <para>
- The ICMP Code type is used to conveniently specify the ICMP header's code field.
- </para>
- <para>
- The following keywords may be used when specifying the ICMP code:
- <table frame="all">
- <tgroup cols="2" align="left" colsep="1" rowsep="1">
- <colspec colname="c1"/>
- <colspec colname="c2"/>
- <thead>
- <row>
- <entry>Keyword</entry>
- <entry>Value</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>net-unreachable</entry>
- <entry>0</entry>
- </row>
- <row>
- <entry>host-unreachable</entry>
- <entry>1</entry>
- </row>
- <row>
- <entry>prot-unreachable</entry>
- <entry>2</entry>
- </row>
- <row>
- <entry>port-unreachable</entry>
- <entry>3</entry>
- </row>
- <row>
- <entry>net-prohibited</entry>
- <entry>9</entry>
- </row>
- <row>
- <entry>host-prohibited</entry>
- <entry>10</entry>
- </row>
- <row>
- <entry>admin-prohibited</entry>
- <entry>13</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- </refsect2>
- <refsect2>
- <title>ICMPv6 Type type</title>
- <para>
- <table frame="all">
- <tgroup cols="4" align="left" colsep="1" rowsep="1">
- <colspec colname="c1"/>
- <colspec colname="c2"/>
- <colspec colname="c3"/>
- <colspec colname="c4"/>
- <thead>
- <row>
- <entry>Name</entry>
- <entry>Keyword</entry>
- <entry>Size</entry>
- <entry>Base type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>ICMPv6 Type</entry>
- <entry>icmpv6_type</entry>
- <entry>8 bit</entry>
- <entry>integer</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- <para>
- The ICMPv6 Type type is used to conveniently specify the ICMPv6 header's type field.
- </para>
- <para>
- The following keywords may be used when specifying the ICMPv6 type:
- <table frame="all">
- <tgroup cols="2" align="left" colsep="1" rowsep="1">
- <colspec colname="c1"/>
- <colspec colname="c2"/>
- <thead>
- <row>
- <entry>Keyword</entry>
- <entry>Value</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>destination-unreachable</entry>
- <entry>1</entry>
- </row>
- <row>
- <entry>packet-too-big</entry>
- <entry>2</entry>
- </row>
- <row>
- <entry>time-exceeded</entry>
- <entry>3</entry>
- </row>
- <row>
- <entry>parameter-problem</entry>
- <entry>4</entry>
- </row>
- <row>
- <entry>echo-request</entry>
- <entry>128</entry>
- </row>
- <row>
- <entry>echo-reply</entry>
- <entry>129</entry>
- </row>
- <row>
- <entry>mld-listener-query</entry>
- <entry>130</entry>
- </row>
- <row>
- <entry>mld-listener-report</entry>
- <entry>131</entry>
- </row>
- <row>
- <entry>mld-listener-done</entry>
- <entry>132</entry>
- </row>
- <row>
- <entry>mld-listener-reduction</entry>
- <entry>132</entry>
- </row>
- <row>
- <entry>nd-router-solicit</entry>
- <entry>133</entry>
- </row>
- <row>
- <entry>nd-router-advert</entry>
- <entry>134</entry>
- </row>
- <row>
- <entry>nd-neighbor-solicit</entry>
- <entry>135</entry>
- </row>
- <row>
- <entry>nd-neighbor-advert</entry>
- <entry>136</entry>
- </row>
- <row>
- <entry>nd-redirect</entry>
- <entry>137</entry>
- </row>
- <row>
- <entry>router-renumbering</entry>
- <entry>138</entry>
- </row>
- <row>
- <entry>ind-neighbor-solicit</entry>
- <entry>141</entry>
- </row>
- <row>
- <entry>ind-neighbor-advert</entry>
- <entry>142</entry>
- </row>
- <row>
- <entry>mld2-listener-report</entry>
- <entry>143</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- <example>
- <title>ICMPv6 Type specification</title>
- <programlisting>
-# match ICMPv6 ping packets
-filter output icmpv6 type { echo-request, echo-reply }
- </programlisting>
- </example>
- </refsect2>
- <refsect2>
- <title>ICMPv6 Code type</title>
- <para>
- <table frame="all">
- <tgroup cols="4" align="left" colsep="1" rowsep="1">
- <colspec colname="c1"/>
- <colspec colname="c2"/>
- <colspec colname="c3"/>
- <colspec colname="c4"/>
- <thead>
- <row>
- <entry>Name</entry>
- <entry>Keyword</entry>
- <entry>Size</entry>
- <entry>Base type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>ICMPv6 Code</entry>
- <entry>icmpv6_code</entry>
- <entry>8 bit</entry>
- <entry>integer</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- <para>
- The ICMPv6 Code type is used to conveniently specify the ICMPv6 header's code field.
- </para>
- <para>
- The following keywords may be used when specifying the ICMPv6 code:
- <table frame="all">
- <tgroup cols="2" align="left" colsep="1" rowsep="1">
- <colspec colname="c1"/>
- <colspec colname="c2"/>
- <thead>
- <row>
- <entry>Keyword</entry>
- <entry>Value</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>no-route</entry>
- <entry>0</entry>
- </row>
- <row>
- <entry>admin-prohibited</entry>
- <entry>1</entry>
- </row>
- <row>
- <entry>addr-unreachable</entry>
- <entry>3</entry>
- </row>
- <row>
- <entry>port-unreachable</entry>
- <entry>4</entry>
- </row>
- <row>
- <entry>policy-fail</entry>
- <entry>5</entry>
- </row>
- <row>
- <entry>reject-route</entry>
- <entry>6</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- </refsect2>
- <refsect2>
- <title>ICMPvX Code type</title>
- <para>
- <table frame="all">
- <tgroup cols="4" align="left" colsep="1" rowsep="1">
- <colspec colname="c1"/>
- <colspec colname="c2"/>
- <colspec colname="c3"/>
- <colspec colname="c4"/>
- <thead>
- <row>
- <entry>Name</entry>
- <entry>Keyword</entry>
- <entry>Size</entry>
- <entry>Base type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>ICMPvX Code</entry>
- <entry>icmpx_code</entry>
- <entry>8 bit</entry>
- <entry>integer</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- <para>
- The ICMPvX Code type abstraction is a set of values which
- overlap between ICMP and ICMPv6 Code types to be used from the
- inet family.
- </para>
- <para>
- The following keywords may be used when specifying the ICMPvX code:
- <table frame="all">
- <tgroup cols="2" align="left" colsep="1" rowsep="1">
- <colspec colname="c1"/>
- <colspec colname="c2"/>
- <thead>
- <row>
- <entry>Keyword</entry>
- <entry>Value</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>no-route</entry>
- <entry>0</entry>
- </row>
- <row>
- <entry>port-unreachable</entry>
- <entry>1</entry>
- </row>
- <row>
- <entry>host-unreachable</entry>
- <entry>2</entry>
- </row>
- <row>
- <entry>admin-prohibited</entry>
- <entry>3</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- </refsect2>
- <refsect2>
- <title>Conntrack types</title>
- <para>
- This is an overview of types used in <command>ct</command>
- expression and statement:
- <table frame="all">
- <tgroup cols="4" align="left" colsep="1" rowsep="1">
- <colspec colname="c1"/>
- <colspec colname="c2"/>
- <colspec colname="c3"/>
- <colspec colname="c4"/>
- <thead>
- <row>
- <entry>Name</entry>
- <entry>Keyword</entry>
- <entry>Size</entry>
- <entry>Base type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>conntrack state</entry>
- <entry>ct_state</entry>
- <entry>4 byte</entry>
- <entry>bitmask</entry>
- </row>
- <row>
- <entry>conntrack direction</entry>
- <entry>ct_dir</entry>
- <entry>8 bit</entry>
- <entry>integer</entry>
- </row>
- <row>
- <entry>conntrack status</entry>
- <entry>ct_status</entry>
- <entry>4 byte</entry>
- <entry>bitmask</entry>
- </row>
- <row>
- <entry>conntrack event bits</entry>
- <entry>ct_event</entry>
- <entry>4 byte</entry>
- <entry>bitmask</entry>
- </row>
- <row>
- <entry>conntrack label</entry>
- <entry>ct_label</entry>
- <entry>128 bit</entry>
- <entry>bitmask</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- <para>
- For each of the types above, keywords are available for convenience:
- <table frame="all">
- <title>conntrack state (ct_state)</title>
- <tgroup cols="2" align="left" colsep="1" rowsep="1">
- <colspec colname="c1"/>
- <colspec colname="c2"/>
- <thead>
- <row>
- <entry>Keyword</entry>
- <entry>Value</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>invalid</entry>
- <entry>1</entry>
- </row>
- <row>
- <entry>established</entry>
- <entry>2</entry>
- </row>
- <row>
- <entry>related</entry>
- <entry>4</entry>
- </row>
- <row>
- <entry>new</entry>
- <entry>8</entry>
- </row>
- <row>
- <entry>untracked</entry>
- <entry>64</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
-
- <table frame="all">
- <title>conntrack direction (ct_dir)</title>
- <tgroup cols="2" align="left" colsep="1" rowsep="1">
- <colspec colname="c1"/>
- <colspec colname="c2"/>
- <thead>
- <row>
- <entry>Keyword</entry>
- <entry>Value</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>original</entry>
- <entry>0</entry>
- </row>
- <row>
- <entry>reply</entry>
- <entry>1</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
-
- <table frame="all">
- <title>conntrack status (ct_status)</title>
- <tgroup cols="2" align="left" colsep="1" rowsep="1">
- <colspec colname="c1"/>
- <colspec colname="c2"/>
- <thead>
- <row>
- <entry>Keyword</entry>
- <entry>Value</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>expected</entry>
- <entry>1</entry>
- </row>
- <row>
- <entry>seen-reply</entry>
- <entry>2</entry>
- </row>
- <row>
- <entry>assured</entry>
- <entry>4</entry>
- </row>
- <row>
- <entry>confirmed</entry>
- <entry>8</entry>
- </row>
- <row>
- <entry>snat</entry>
- <entry>16</entry>
- </row>
- <row>
- <entry>dnat</entry>
- <entry>32</entry>
- </row>
- <row>
- <entry>dying</entry>
- <entry>512</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
-
- <table frame="all">
- <title>conntrack event bits (ct_event)</title>
- <tgroup cols="2" align="left" colsep="1" rowsep="1">
- <colspec colname="c1"/>
- <colspec colname="c2"/>
- <thead>
- <row>
- <entry>Keyword</entry>
- <entry>Value</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>new</entry>
- <entry>1</entry>
- </row>
- <row>
- <entry>related</entry>
- <entry>2</entry>
- </row>
- <row>
- <entry>destroy</entry>
- <entry>4</entry>
- </row>
- <row>
- <entry>reply</entry>
- <entry>8</entry>
- </row>
- <row>
- <entry>assured</entry>
- <entry>16</entry>
- </row>
- <row>
- <entry>protoinfo</entry>
- <entry>32</entry>
- </row>
- <row>
- <entry>helper</entry>
- <entry>64</entry>
- </row>
- <row>
- <entry>mark</entry>
- <entry>128</entry>
- </row>
- <row>
- <entry>seqadj</entry>
- <entry>256</entry>
- </row>
- <row>
- <entry>secmark</entry>
- <entry>512</entry>
- </row>
- <row>
- <entry>label</entry>
- <entry>1024</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- <para>
- Possible keywords for conntrack label type
- (<command>ct_label</command>) are read at runtime from
- <literal>/etc/connlabel.conf</literal>.
- </para>
- </para>
- </refsect2>
- </refsect1>
-
- <refsect1>
- <title>Primary expressions</title>
- <para>
- The lowest order expression is a primary expression, representing either a constant or a single
- datum from a packet's payload, meta data or a stateful module.
- </para>
- <refsect2>
- <title>Meta expressions</title>
- <para>
- <cmdsynopsis>
- <command>meta</command>
- <group choice="req">
- <arg>length</arg>
- <arg>nfproto</arg>
- <arg>l4proto</arg>
- <arg>protocol</arg>
- <arg>priority</arg>
- </group>
- </cmdsynopsis>
- <cmdsynopsis>
- <arg choice="opt">meta</arg>
- <group choice="req">
- <arg>mark</arg>
- <arg>iif</arg>
- <arg>iifname</arg>
- <arg>iiftype</arg>
- <arg>oif</arg>
- <arg>oifname</arg>
- <arg>oiftype</arg>
- <arg>skuid</arg>
- <arg>skgid</arg>
- <arg>nftrace</arg>
- <arg>rtclassid</arg>
- <arg>ibrname</arg>
- <arg>obrname</arg>
- <arg>pkttype</arg>
- <arg>cpu</arg>
- <arg>iifgroup</arg>
- <arg>oifgroup</arg>
- <arg>cgroup</arg>
- <arg>random</arg>
- <arg>secpath</arg>
- </group>
- </cmdsynopsis>
- </para>
- <para>
- A meta expression refers to meta data associated with a packet.
- </para>
- <para>
- There are two types of meta expressions: unqualified and qualified meta expressions.
- Qualified meta expressions require the <command>meta</command> keyword before the
- meta key, unqualified meta expressions can be specified by using the meta key directly
- or as qualified meta expressions.
-
- Meta l4proto is useful to match a particular transport protocol that is part of either
- an IPv4 or IPv6 packet. It will also skip any IPv6 extension headers present in an IPv6 packet.
- </para>
- <para>
- <table frame="all">
- <title>Meta expression types</title>
- <tgroup cols='3' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <colspec colname='c3'/>
- <thead>
- <row>
- <entry>Keyword</entry>
- <entry>Description</entry>
- <entry>Type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>length</entry>
- <entry>Length of the packet in bytes</entry>
- <entry>integer (32 bit)</entry>
- </row>
- <row>
- <entry>nfproto</entry>
- <entry>real hook protocol family, useful only in inet table</entry>
- <entry>integer (32 bit)</entry>
- </row>
- <row>
- <entry>l4proto</entry>
- <entry>layer 4 protocol, skips ipv6 extension headers</entry>
- <entry>integer (8 bit)</entry>
- </row>
- <row>
- <entry>protocol</entry>
- <entry>EtherType protocol value</entry>
- <entry>ether_type</entry>
- </row>
- <row>
- <entry>priority</entry>
- <entry>TC packet priority</entry>
- <entry>tc_handle</entry>
- </row>
- <row>
- <entry>mark</entry>
- <entry>Packet mark</entry>
- <entry>mark</entry>
- </row>
- <row>
- <entry>iif</entry>
- <entry>Input interface index</entry>
- <entry>iface_index</entry>
- </row>
- <row>
- <entry>iifname</entry>
- <entry>Input interface name</entry>
- <entry>ifname</entry>
- </row>
- <row>
- <entry>iiftype</entry>
- <entry>Input interface type</entry>
- <entry>iface_type</entry>
- </row>
- <row>
- <entry>oif</entry>
- <entry>Output interface index</entry>
- <entry>iface_index</entry>
- </row>
- <row>
- <entry>oifname</entry>
- <entry>Output interface name</entry>
- <entry>ifname</entry>
- </row>
- <row>
- <entry>oiftype</entry>
- <entry>Output interface hardware type</entry>
- <entry>iface_type</entry>
- </row>
- <row>
- <entry>skuid</entry>
- <entry>UID associated with originating socket</entry>
- <entry>uid</entry>
- </row>
- <row>
- <entry>skgid</entry>
- <entry>GID associated with originating socket</entry>
- <entry>gid</entry>
- </row>
- <row>
- <entry>rtclassid</entry>
- <entry>Routing realm</entry>
- <entry>realm</entry>
- </row>
- <row>
- <entry>ibrname</entry>
- <entry>Input bridge interface name</entry>
- <entry>ifname</entry>
- </row>
- <row>
- <entry>obrname</entry>
- <entry>Output bridge interface name</entry>
- <entry>ifname</entry>
- </row>
- <row>
- <entry>pkttype</entry>
- <entry>packet type</entry>
- <entry>pkt_type</entry>
- </row>
- <row>
- <entry>cpu</entry>
- <entry>cpu number processing the packet</entry>
- <entry>integer (32 bits)</entry>
- </row>
- <row>
- <entry>iifgroup</entry>
- <entry>incoming device group</entry>
- <entry>devgroup</entry>
- </row>
- <row>
- <entry>oifgroup</entry>
- <entry>outgoing device group</entry>
- <entry>devgroup</entry>
- </row>
- <row>
- <entry>cgroup</entry>
- <entry>control group id</entry>
- <entry>integer (32 bits)</entry>
- </row>
- <row>
- <entry>random</entry>
- <entry>pseudo-random number</entry>
- <entry>integer (32 bits)</entry>
- </row>
- <row>
- <entry>secpath</entry>
- <entry>boolean</entry>
- <entry>boolean (1 bit)</entry>
- </row>
-
- </tbody>
- </tgroup>
- </table>
- </para>
- <para>
- <table frame="all">
- <title>Meta expression specific types</title>
- <tgroup cols='2' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <thead>
- <row>
- <entry>Type</entry>
- <entry>Description</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>iface_index</entry>
- <entry>
- Interface index (32 bit number). Can be specified numerically
- or as name of an existing interface.
- </entry>
- </row>
- <row>
- <entry>ifname</entry>
- <entry>
- Interface name (16 byte string). Does not have to exist.
- </entry>
- </row>
- <row>
- <entry>iface_type</entry>
- <entry>
- Interface type (16 bit number).
- </entry>
- </row>
- <row>
- <entry>uid</entry>
- <entry>
- User ID (32 bit number). Can be specified numerically or as
- user name.
- </entry>
- </row>
- <row>
- <entry>gid</entry>
- <entry>
- Group ID (32 bit number). Can be specified numerically or as
- group name.
- </entry>
- </row>
- <row>
- <entry>realm</entry>
- <entry>
- Routing Realm (32 bit number). Can be specified numerically
- or as symbolic name defined in /etc/iproute2/rt_realms.
- </entry>
- </row>
- <row>
- <entry>devgroup_type</entry>
- <entry>
- Device group (32 bit number). Can be specified numerically
- or as symbolic name defined in /etc/iproute2/group.
- </entry>
- </row>
- <row>
- <entry>pkt_type</entry>
- <entry>
- Packet type: Unicast (addressed to local host),
- Broadcast (to all), Multicast (to group).
- </entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- <para>
- <example>
- <title>Using meta expressions</title>
- <programlisting>
-# qualified meta expression
-filter output meta oif eth0
-
-# unqualified meta expression
-filter output oif eth0
-
-# packed was subject to ipsec processing
-raw prerouting meta secpath exists accept
- </programlisting>
- </example>
- </para>
- </refsect2>
- <refsect2>
- <title>socket expression</title>
- <para>
- <cmdsynopsis>
- <command>socket</command>
- <group choice="req">
- <arg>transparent</arg>
- </group>
- </cmdsynopsis>
- </para>
- <para>
- Socket expression can be used to search for an existing open TCP/UDP socket
- and its attributes that can be associated with a packet. It looks for an
- established or non-zero bound listening socket (possibly with a non-local address).
- </para>
- <para>
- <table frame="all">
- <title>Available socket attributes</title>
- <tgroup cols='3' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <colspec colname='c3'/>
- <thead>
- <row>
- <entry>Name</entry>
- <entry>Description</entry>
- <entry>Type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>transparent</entry>
- <entry>
- Value of the IP_TRANSPARENT socket option in the found socket. It can be 0 or 1.
- </entry>
- <entry>boolean (1 bit)</entry> <!-- From the aspect of the user at least. -->
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- <para>
- <example>
- <title>Using socket expression</title>
- <programlisting>
-# Mark packets that correspond to a transparent socket
-table inet x {
- chain y {
- type filter hook prerouting priority -150; policy accept;
- socket transparent 1 mark set 0x00000001 accept
- }
-}
- </programlisting>
- </example>
- </para>
- </refsect2>
- <refsect2>
- <title>fib expressions</title>
- <para>
- <cmdsynopsis>
- <command>fib</command>
- <group choice="req">
- <arg>saddr</arg>
- <arg>daddr</arg>
- <group choice="req">
- <arg>mark</arg>
- <arg>iif</arg>
- <arg>oif</arg>
- </group>
- </group>
- <group choice="req">
- <arg>oif</arg>
- <arg>oifname</arg>
- <arg>type</arg>
- </group>
- </cmdsynopsis>
- </para>
- <para>
- A fib expression queries the fib (forwarding information base)
- to obtain information such as the output interface index a particular address would use. The input is a tuple of elements that is used as input to the fib lookup
- functions.
- </para>
- <para>
- <table frame="all">
- <title>fib expression specific types</title>
- <tgroup cols='3' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <colspec colname='c3'/>
- <thead>
- <row>
- <entry>Keyword</entry>
- <entry>Description</entry>
- <entry>Type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>oif</entry>
- <entry>Output interface index</entry>
- <entry>integer (32 bit)</entry>
- </row>
- <row>
- <entry>oifname</entry>
- <entry>Output interface name</entry>
- <entry>string</entry>
- </row>
- <row>
- <entry>type</entry>
- <entry>Address type</entry>
- <entry>fib_addrtype</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- <para>
- <example>
- <title>Using fib expressions</title>
- <programlisting>
-# drop packets without a reverse path
-filter prerouting fib saddr . iif oif missing drop
-
-# drop packets to address not configured on ininterface
-filter prerouting fib daddr . iif type != { local, broadcast, multicast } drop
-
-# perform lookup in a specific 'blackhole' table (0xdead, needs ip appropriate ip rule)
-filter prerouting meta mark set 0xdead fib daddr . meta mark type vmap { blackhole : drop, prohibit : jump prohibited, unreachable : drop }
- </programlisting>
- </example>
- </para>
- </refsect2>
- <refsect2>
- <title>Routing expressions</title>
- <para>
- <cmdsynopsis>
- <command>rt</command>
- <group choice="req">
- <arg>classid</arg>
- <arg>nexthop</arg>
- </group>
- </cmdsynopsis>
- </para>
- <para>
- A routing expression refers to routing data associated with a packet.
- </para>
- <para>
- <table frame="all">
- <title>Routing expression types</title>
- <tgroup cols='3' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <colspec colname='c3'/>
- <thead>
- <row>
- <entry>Keyword</entry>
- <entry>Description</entry>
- <entry>Type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>classid</entry>
- <entry>Routing realm</entry>
- <entry>realm</entry>
- </row>
- <row>
- <entry>nexthop</entry>
- <entry>Routing nexthop</entry>
- <entry>ipv4_addr/ipv6_addr</entry>
- </row>
- <row>
- <entry>mtu</entry>
- <entry>TCP maximum segment size of route</entry>
- <entry>integer (16 bit)</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- <para>
- <table frame="all">
- <title>Routing expression specific types</title>
- <tgroup cols='2' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <thead>
- <row>
- <entry>Type</entry>
- <entry>Description</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>realm</entry>
- <entry>
- Routing Realm (32 bit number). Can be specified numerically
- or as symbolic name defined in /etc/iproute2/rt_realms.
- </entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- <para>
- <example>
- <title>Using routing expressions</title>
- <programlisting>
-# IP family independent rt expression
-filter output rt classid 10
-
-# IP family dependent rt expressions
-ip filter output rt nexthop 192.168.0.1
-ip6 filter output rt nexthop fd00::1
-inet filter output rt ip nexthop 192.168.0.1
-inet filter output rt ip6 nexthop fd00::1
- </programlisting>
- </example>
- </para>
- </refsect2>
- </refsect1>
-
- <refsect1>
- <title>Payload expressions</title>
- <para>
- Payload expressions refer to data from the packet's payload.
- </para>
-
- <refsect2>
- <title>Ethernet header expression</title>
- <para>
- <cmdsynopsis>
- <command>ether</command>
- <arg opt="req"><replaceable>Ethernet header field</replaceable></arg>
- </cmdsynopsis>
- </para>
- <para>
- <table frame="all">
- <title>Ethernet header expression types</title>
- <tgroup cols='3' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <colspec colname='c3'/>
- <thead>
- <row>
- <entry>Keyword</entry>
- <entry>Description</entry>
- <entry>Type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>daddr</entry>
- <entry>Destination MAC address</entry>
- <entry>ether_addr</entry>
- </row>
- <row>
- <entry>saddr</entry>
- <entry>Source MAC address</entry>
- <entry>ether_addr</entry>
- </row>
- <row>
- <entry>type</entry>
- <entry>EtherType</entry>
- <entry>ether_type</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- </refsect2>
-
- <refsect2>
- <title>VLAN header expression</title>
- <para>
- <cmdsynopsis>
- <command>vlan</command>
- <arg opt="req"><replaceable>VLAN header field</replaceable></arg>
- </cmdsynopsis>
- </para>
- <para>
- <table frame="all">
- <title>VLAN header expression</title>
- <tgroup cols='3' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <colspec colname='c2'/>
- <thead>
- <row>
- <entry>Keyword</entry>
- <entry>Description</entry>
- <entry>Type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>id</entry>
- <entry>VLAN ID (VID)</entry>
- <entry>integer (12 bit)</entry>
- </row>
- <row>
- <entry>cfi</entry>
- <entry>Canonical Format Indicator</entry>
- <entry>integer (1 bit)</entry>
- </row>
- <row>
- <entry>pcp</entry>
- <entry>Priority code point</entry>
- <entry>integer (3 bit)</entry>
- </row>
- <row>
- <entry>type</entry>
- <entry>EtherType</entry>
- <entry>ether_type</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- </refsect2>
-
- <refsect2>
- <title>ARP header expression</title>
- <para>
- <cmdsynopsis>
- <command>arp</command>
- <arg opt="req"><replaceable>ARP header field</replaceable></arg>
- </cmdsynopsis>
- </para>
- <para>
- <table frame="all">
- <title>ARP header expression</title>
- <tgroup cols='3' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <colspec colname='c3'/>
- <thead>
- <row>
- <entry>Keyword</entry>
- <entry>Description</entry>
- <entry>Type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>htype</entry>
- <entry>ARP hardware type</entry>
- <entry>integer (16 bit)</entry>
- </row>
- <row>
- <entry>ptype</entry>
- <entry>EtherType</entry>
- <entry>ether_type</entry>
- </row>
- <row>
- <entry>hlen</entry>
- <entry>Hardware address len</entry>
- <entry>integer (8 bit)</entry>
- </row>
- <row>
- <entry>plen</entry>
- <entry>Protocol address len</entry>
- <entry>integer (8 bit)</entry>
- </row>
- <row>
- <entry>operation</entry>
- <entry>Operation</entry>
- <entry>arp_op</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- </refsect2>
-
- <refsect2>
- <title>IPv4 header expression</title>
- <para>
- <cmdsynopsis>
- <command>ip</command>
- <arg opt="req"><replaceable>IPv4 header field</replaceable></arg>
- </cmdsynopsis>
- </para>
- <para>
- <table frame="all">
- <title>IPv4 header expression</title>
- <tgroup cols='3' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <colspec colname='c3'/>
- <thead>
- <row>
- <entry>Keyword</entry>
- <entry>Description</entry>
- <entry>Type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>version</entry>
- <entry>IP header version (4)</entry>
- <entry>integer (4 bit)</entry>
- </row>
- <row>
- <entry>hdrlength</entry>
- <entry>IP header length including options</entry>
- <entry>integer (4 bit) FIXME scaling</entry>
- </row>
- <row>
- <entry>dscp</entry>
- <entry>Differentiated Services Code Point</entry>
- <entry>dscp</entry>
- </row>
- <row>
- <entry>ecn</entry>
- <entry>Explicit Congestion Notification</entry>
- <entry>ecn</entry>
- </row>
- <row>
- <entry>length</entry>
- <entry>Total packet length</entry>
- <entry>integer (16 bit)</entry>
- </row>
- <row>
- <entry>id</entry>
- <entry>IP ID</entry>
- <entry>integer (16 bit)</entry>
- </row>
- <row>
- <entry>frag-off</entry>
- <entry>Fragment offset</entry>
- <entry>integer (16 bit)</entry>
- </row>
- <row>
- <entry>ttl</entry>
- <entry>Time to live</entry>
- <entry>integer (8 bit)</entry>
- </row>
- <row>
- <entry>protocol</entry>
- <entry>Upper layer protocol</entry>
- <entry>inet_proto</entry>
- </row>
- <row>
- <entry>checksum</entry>
- <entry>IP header checksum</entry>
- <entry>integer (16 bit)</entry>
- </row>
- <row>
- <entry>saddr</entry>
- <entry>Source address</entry>
- <entry>ipv4_addr</entry>
- </row>
- <row>
- <entry>daddr</entry>
- <entry>Destination address</entry>
- <entry>ipv4_addr</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- </refsect2>
-
- <refsect2>
- <title>ICMP header expression</title>
- <para>
- <cmdsynopsis>
- <command>icmp</command>
- <arg opt="req"><replaceable>ICMP header field</replaceable></arg>
- </cmdsynopsis>
- </para>
- <para>
- <table frame="all">
- <title>ICMP header expression</title>
- <tgroup cols="3" align="left" colsep="1" rowsep="1">
- <colspec colname="c1"/>
- <colspec colname="c2"/>
- <colspec colname="c3"/>
- <thead>
- <row>
- <entry>Keyword</entry>
- <entry>Description</entry>
- <entry>Type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>type</entry>
- <entry>ICMP type field</entry>
- <entry>icmp_type</entry>
- </row>
- <row>
- <entry>code</entry>
- <entry>ICMP code field</entry>
- <entry>integer (8 bit)</entry>
- </row>
- <row>
- <entry>checksum</entry>
- <entry>ICMP checksum field</entry>
- <entry>integer (16 bit)</entry>
- </row>
- <row>
- <entry>id</entry>
- <entry>ID of echo request/response</entry>
- <entry>integer (16 bit)</entry>
- </row>
- <row>
- <entry>sequence</entry>
- <entry>sequence number of echo request/response</entry>
- <entry>integer (16 bit)</entry>
- </row>
- <row>
- <entry>gateway</entry>
- <entry>gateway of redirects</entry>
- <entry>integer (32 bit)</entry>
- </row>
- <row>
- <entry>mtu</entry>
- <entry>MTU of path MTU discovery</entry>
- <entry>integer (16 bit)</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- </refsect2>
-
- <refsect2>
- <title>IPv6 header expression</title>
- <para>
- <cmdsynopsis>
- <command>ip6</command>
- <arg opt="req"><replaceable>IPv6 header field</replaceable></arg>
- </cmdsynopsis>
- </para>
- <para>
- This expression refers to the ipv6 header fields.
- Caution when using <command>ip6 nexthdr</command>, the value only refers to
- the next header, i.e. <command>ip6 nexthdr tcp</command> will only match if the ipv6 packet does not
- contain any extension headers. Packets that are fragmented or e.g. contain a routing extension headers
- will not be matched.
- Please use <command>meta l4proto</command> if you wish to match the real transport header and
- ignore any additional extension headers instead.
- </para>
- <para>
- <table frame="all">
- <title>IPv6 header expression</title>
- <tgroup cols='3' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <colspec colname='c3'/>
- <thead>
- <row>
- <entry>Keyword</entry>
- <entry>Description</entry>
- <entry>Type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>version</entry>
- <entry>IP header version (6)</entry>
- <entry>integer (4 bit)</entry>
- </row>
- <row>
- <entry>dscp</entry>
- <entry>Differentiated Services Code Point</entry>
- <entry>dscp</entry>
- </row>
- <row>
- <entry>ecn</entry>
- <entry>Explicit Congestion Notification</entry>
- <entry>ecn</entry>
- </row>
- <row>
- <entry>flowlabel</entry>
- <entry>Flow label</entry>
- <entry>integer (20 bit)</entry>
- </row>
- <row>
- <entry>length</entry>
- <entry>Payload length</entry>
- <entry>integer (16 bit)</entry>
- </row>
- <row>
- <entry>nexthdr</entry>
- <entry>Nexthdr protocol</entry>
- <entry>inet_proto</entry>
- </row>
- <row>
- <entry>hoplimit</entry>
- <entry>Hop limit</entry>
- <entry>integer (8 bit)</entry>
- </row>
- <row>
- <entry>saddr</entry>
- <entry>Source address</entry>
- <entry>ipv6_addr</entry>
- </row>
- <row>
- <entry>daddr</entry>
- <entry>Destination address</entry>
- <entry>ipv6_addr</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- <para>
- <example>
- <title>matching if first extension header indicates a fragment</title>
- <programlisting>
-ip6 nexthdr ipv6-frag counter
- </programlisting>
- </example>
- </para>
- </refsect2>
- <refsect2>
- <title>ICMPv6 header expression</title>
- <para>
- <cmdsynopsis>
- <command>icmpv6</command>
- <arg opt="req"><replaceable>ICMPv6 header field</replaceable></arg>
- </cmdsynopsis>
- </para>
- <para>
- <table frame="all">
- <title>ICMPv6 header expression</title>
- <tgroup cols="3" align="left" colsep="1" rowsep="1">
- <colspec colname="c1"/>
- <colspec colname="c2"/>
- <colspec colname="c3"/>
- <thead>
- <row>
- <entry>Keyword</entry>
- <entry>Description</entry>
- <entry>Type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>type</entry>
- <entry>ICMPv6 type field</entry>
- <entry>icmpv6_type</entry>
- </row>
- <row>
- <entry>code</entry>
- <entry>ICMPv6 code field</entry>
- <entry>integer (8 bit)</entry>
- </row>
- <row>
- <entry>checksum</entry>
- <entry>ICMPv6 checksum field</entry>
- <entry>integer (16 bit)</entry>
- </row>
- <row>
- <entry>parameter-problem</entry>
- <entry>pointer to problem</entry>
- <entry>integer (32 bit)</entry>
- </row>
- <row>
- <entry>packet-too-big</entry>
- <entry>oversized MTU</entry>
- <entry>integer (32 bit)</entry>
- </row>
- <row>
- <entry>id</entry>
- <entry>ID of echo request/response</entry>
- <entry>integer (16 bit)</entry>
- </row>
- <row>
- <entry>sequence</entry>
- <entry>sequence number of echo request/response</entry>
- <entry>integer (16 bit)</entry>
- </row>
- <row>
- <entry>max-delay</entry>
- <entry>maximum response delay of MLD queries</entry>
- <entry>integer (16 bit)</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- </refsect2>
- <refsect2>
- <title>TCP header expression</title>
- <para>
- <cmdsynopsis>
- <command>tcp</command>
- <arg opt="req"><replaceable>TCP header field</replaceable></arg>
- </cmdsynopsis>
- </para>
- <para>
- <table frame="all">
- <title>TCP header expression</title>
- <tgroup cols='3' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <colspec colname='c3'/>
- <thead>
- <row>
- <entry>Keyword</entry>
- <entry>Description</entry>
- <entry>Type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>sport</entry>
- <entry>Source port</entry>
- <entry>inet_service</entry>
- </row>
- <row>
- <entry>dport</entry>
- <entry>Destination port</entry>
- <entry>inet_service</entry>
- </row>
- <row>
- <entry>sequence</entry>
- <entry>Sequence number</entry>
- <entry>integer (32 bit)</entry>
- </row>
- <row>
- <entry>ackseq</entry>
- <entry>Acknowledgement number</entry>
- <entry>integer (32 bit)</entry>
- </row>
- <row>
- <entry>doff</entry>
- <entry>Data offset</entry>
- <entry>integer (4 bit) FIXME scaling</entry>
- </row>
- <row>
- <entry>reserved</entry>
- <entry>Reserved area</entry>
- <entry>integer (4 bit)</entry>
- </row>
- <row>
- <entry>flags</entry>
- <entry>TCP flags</entry>
- <entry>tcp_flag</entry>
- </row>
- <row>
- <entry>window</entry>
- <entry>Window</entry>
- <entry>integer (16 bit)</entry>
- </row>
- <row>
- <entry>checksum</entry>
- <entry>Checksum</entry>
- <entry>integer (16 bit)</entry>
- </row>
- <row>
- <entry>urgptr</entry>
- <entry>Urgent pointer</entry>
- <entry>integer (16 bit)</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- </refsect2>
-
- <refsect2>
- <title>UDP header expression</title>
- <para>
- <cmdsynopsis>
- <command>udp</command>
- <arg opt="req"><replaceable>UDP header field</replaceable></arg>
- </cmdsynopsis>
- </para>
- <para>
- <table frame="all">
- <title>UDP header expression</title>
- <tgroup cols='3' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <colspec colname='c3'/>
- <thead>
- <row>
- <entry>Keyword</entry>
- <entry>Description</entry>
- <entry>Type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>sport</entry>
- <entry>Source port</entry>
- <entry>inet_service</entry>
- </row>
- <row>
- <entry>dport</entry>
- <entry>Destination port</entry>
- <entry>inet_service</entry>
- </row>
- <row>
- <entry>length</entry>
- <entry>Total packet length</entry>
- <entry>integer (16 bit)</entry>
- </row>
- <row>
- <entry>checksum</entry>
- <entry>Checksum</entry>
- <entry>integer (16 bit)</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- </refsect2>
-
- <refsect2>
- <title>UDP-Lite header expression</title>
- <para>
- <cmdsynopsis>
- <command>udplite</command>
- <arg opt="req"><replaceable>UDP-Lite header field</replaceable></arg>
- </cmdsynopsis>
- </para>
- <para>
- <table frame="all">
- <title>UDP-Lite header expression</title>
- <tgroup cols='3' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <colspec colname='c3'/>
- <thead>
- <row>
- <entry>Keyword</entry>
- <entry>Description</entry>
- <entry>Type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>sport</entry>
- <entry>Source port</entry>
- <entry>inet_service</entry>
- </row>
- <row>
- <entry>dport</entry>
- <entry>Destination port</entry>
- <entry>inet_service</entry>
- </row>
- <row>
- <entry>checksum</entry>
- <entry>Checksum</entry>
- <entry>integer (16 bit)</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- </refsect2>
-
-
- <refsect2>
- <title>SCTP header expression</title>
- <para>
- <cmdsynopsis>
- <command>sctp</command>
- <arg opt="req"><replaceable>SCTP header field</replaceable></arg>
- </cmdsynopsis>
- </para>
- <para>
- <table frame="all">
- <title>SCTP header expression</title>
- <tgroup cols='3' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <colspec colname='c3'/>
- <thead>
- <row>
- <entry>Keyword</entry>
- <entry>Description</entry>
- <entry>Type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>sport</entry>
- <entry>Source port</entry>
- <entry>inet_service</entry>
- </row>
- <row>
- <entry>dport</entry>
- <entry>Destination port</entry>
- <entry>inet_service</entry>
- </row>
- <row>
- <entry>vtag</entry>
- <entry>Verification Tag</entry>
- <entry>integer (32 bit)</entry>
- </row>
- <row>
- <entry>checksum</entry>
- <entry>Checksum</entry>
- <entry>integer (32 bit)</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- </refsect2>
-
- <refsect2>
- <title>DCCP header expression</title>
- <para>
- <cmdsynopsis>
- <command>dccp</command>
- <arg opt="req"><replaceable>DCCP header field</replaceable></arg>
- </cmdsynopsis>
- </para>
- <para>
- <table frame="all">
- <title>DCCP header expression</title>
- <tgroup cols='3' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <colspec colname='c3'/>
- <thead>
- <row>
- <entry>Keyword</entry>
- <entry>Description</entry>
- <entry>Type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>sport</entry>
- <entry>Source port</entry>
- <entry>inet_service</entry>
- </row>
- <row>
- <entry>dport</entry>
- <entry>Destination port</entry>
- <entry>inet_service</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- </refsect2>
-
- <refsect2>
- <title>Authentication header expression</title>
- <para>
- <cmdsynopsis>
- <command>ah</command>
- <arg opt="req"><replaceable>AH header field</replaceable></arg>
- </cmdsynopsis>
- </para>
- <para>
- <table frame="all">
- <title>AH header expression</title>
- <tgroup cols='3' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <colspec colname='c3'/>
- <thead>
- <row>
- <entry>Keyword</entry>
- <entry>Description</entry>
- <entry>Type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>nexthdr</entry>
- <entry>Next header protocol</entry>
- <entry>inet_proto</entry>
- </row>
- <row>
- <entry>hdrlength</entry>
- <entry>AH Header length</entry>
- <entry>integer (8 bit)</entry>
- </row>
- <row>
- <entry>reserved</entry>
- <entry>Reserved area</entry>
- <entry>integer (16 bit)</entry>
- </row>
- <row>
- <entry>spi</entry>
- <entry>Security Parameter Index</entry>
- <entry>integer (32 bit)</entry>
- </row>
- <row>
- <entry>sequence</entry>
- <entry>Sequence number</entry>
- <entry>integer (32 bit)</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- </refsect2>
-
- <refsect2>
- <title> Encrypted security payload header expression</title>
- <para>
- <cmdsynopsis>
- <command>esp</command>
- <arg opt="req"><replaceable>ESP header field</replaceable></arg>
- </cmdsynopsis>
- </para>
- <para>
- <table frame="all">
- <title>ESP header expression</title>
- <tgroup cols='3' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <colspec colname='c3'/>
- <thead>
- <row>
- <entry>Keyword</entry>
- <entry>Description</entry>
- <entry>Type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>spi</entry>
- <entry>Security Parameter Index</entry>
- <entry>integer (32 bit)</entry>
- </row>
- <row>
- <entry>sequence</entry>
- <entry>Sequence number</entry>
- <entry>integer (32 bit)</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- </refsect2>
-
- <refsect2>
- <title>IPComp header expression</title>
- <para>
- <cmdsynopsis>
- <command>comp</command>
- <arg opt="req"><replaceable>IPComp header field</replaceable></arg>
- </cmdsynopsis>
- </para>
- <para>
- <table frame="all">
- <title>IPComp header expression</title>
- <tgroup cols='3' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <colspec colname='c3'/>
- <thead>
- <row>
- <entry>Keyword</entry>
- <entry>Description</entry>
- <entry>Type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>nexthdr</entry>
- <entry>Next header protocol</entry>
- <entry>inet_proto</entry>
- </row>
- <row>
- <entry>flags</entry>
- <entry>Flags</entry>
- <entry>bitmask</entry>
- </row>
- <row>
- <entry>cpi</entry>
- <entry>Compression Parameter Index</entry>
- <entry>integer (16 bit)</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- </refsect2>
- <refsect2>
- <title>Raw payload expression</title>
- <para>
- <cmdsynopsis>
- <command>@</command>
- <arg opt="req"><replaceable>base,offset,length</replaceable></arg>
- </cmdsynopsis>
- </para>
-
- The raw payload expression instructs to load <replaceable>length</replaceable>bits starting at <replaceable>offset</replaceable>bits.
- Bit 0 refers to the very first bit -- in the C programming language, this corresponds to the topmost bit, i.e. 0x80 in case of an octet.
- They are useful to match headers that do not have a human-readable template expression yet.
- Note that nft will not add dependencies for Raw payload expressions.
- If you e.g. want to match protocol fields of a transport header with protocol number 5, you need to manually
- exclude packets that have a different transport header, for instance my using <literal>meta l4proto 5</literal> before
- the raw expression.
-
- <table frame="all">
- <title>Supported payload protocol bases</title>
- <tgroup cols="2" align="left" colsep="1" rowsep="1">
- <colspec colname="c1"/>
- <colspec colname="c2"/>
- <thead>
- <row>
- <entry>Base</entry>
- <entry>Description</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>ll</entry>
- <entry>Link layer, for example the Ethernet header</entry>
- </row>
- <row>
- <entry>nh</entry>
- <entry>Network header, for example IPv4 or IPv6</entry>
- </row>
- <row>
- <entry>th</entry>
- <entry>Transport Header, for example TCP</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- <para>
- <example>
- <title>Matching destination port of both UDP and TCP</title>
- <programlisting>
-inet filter input meta l4proto {tcp, udp} @th,16,16 { dns, http }
- </programlisting>
- </example>
- <example>
- <title>Rewrite arp packet target hardware address if target protocol address matches a given address</title>
- <programlisting>
-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
- </programlisting>
- </example>
- </para>
- </refsect2>
-
- <refsect2>
- <title>Extension header expressions</title>
- <para>
- Extension header expressions refer to data from variable-sized protocol headers, such as IPv6 extension headers and
- TCP options.
- </para>
- <para>
- nftables currently supports matching (finding) a given ipv6 extension header or TCP option.
- </para>
- <cmdsynopsis>
- <command>hbh</command>
- <group choice="req">
- <arg>nexthdr</arg>
- <arg>hdrlength</arg>
- </group>
- </cmdsynopsis>
- <cmdsynopsis>
- <command>frag</command>
- <group choice="req">
- <arg>nexthdr</arg>
- <arg>frag-off</arg>
- <arg>more-fragments</arg>
- <arg>id</arg>
- </group>
- </cmdsynopsis>
-
- <cmdsynopsis>
- <command>rt</command>
- <group choice="req">
- <arg>nexthdr</arg>
- <arg>hdrlength</arg>
- <arg>type</arg>
- <arg>seg-left</arg>
- </group>
- </cmdsynopsis>
- <cmdsynopsis>
- <command>dst</command>
- <group choice="req">
- <arg>nexthdr</arg>
- <arg>hdrlength</arg>
- </group>
- </cmdsynopsis>
- <cmdsynopsis>
- <command>mh</command>
- <group choice="req">
- <arg>nexthdr</arg>
- <arg>hdrlength</arg>
- <arg>checksum</arg>
- <arg>type</arg>
- </group>
- </cmdsynopsis>
- <cmdsynopsis>
- <command>srh</command>
- <group choice="req">
- <arg>flags</arg>
- <arg>tag</arg>
- <arg>sid</arg>
- <arg>seg-left</arg>
- </group>
- </cmdsynopsis>
- <cmdsynopsis>
- <command>tcp option</command>
- <group choice="req">
- <arg>eol</arg>
- <arg>noop</arg>
- <arg>maxseg</arg>
- <arg>window</arg>
- <arg>sack-permitted</arg>
- <arg>sack</arg>
- <arg>sack0</arg>
- <arg>sack1</arg>
- <arg>sack2</arg>
- <arg>sack3</arg>
- <arg>timestamp</arg>
- </group>
- <arg choice="none"><replaceable>tcp_option_field</replaceable></arg>
- </cmdsynopsis>
- <para>
- The following syntaxes are valid only in a relational expression
- with boolean type on right-hand side for checking header existence only:
- </para>
- <cmdsynopsis>
- <command>exthdr</command>
- <group choice="req">
- <arg>hbh</arg>
- <arg>frag</arg>
- <arg>rt</arg>
- <arg>dst</arg>
- <arg>mh</arg>
- </group>
- </cmdsynopsis>
- <cmdsynopsis>
- <command>tcp option</command>
- <group choice="req">
- <arg>eol</arg>
- <arg>noop</arg>
- <arg>maxseg</arg>
- <arg>window</arg>
- <arg>sack-permitted</arg>
- <arg>sack</arg>
- <arg>sack0</arg>
- <arg>sack1</arg>
- <arg>sack2</arg>
- <arg>sack3</arg>
- <arg>timestamp</arg>
- </group>
- </cmdsynopsis>
- <para>
- <table frame="all">
- <title>IPv6 extension headers</title>
- <tgroup cols='2' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <thead>
- <row>
- <entry>Keyword</entry>
- <entry>Description</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>hbh</entry>
- <entry>Hop by Hop</entry>
- </row>
- <row>
- <entry>rt</entry>
- <entry>Routing Header</entry>
- </row>
- <row>
- <entry>frag</entry>
- <entry>Fragmentation header</entry>
- </row>
- <row>
- <entry>dst</entry>
- <entry>dst options</entry>
- </row>
- <row>
- <entry>mh</entry>
- <entry>Mobility Header</entry>
- </row>
- <row>
- <entry>srh</entry>
- <entry>Segment Routing Header</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
-
- <table frame="all">
- <title>TCP Options</title>
- <tgroup cols='3' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <colspec colname='c3'/>
- <thead>
- <row>
- <entry>Keyword</entry>
- <entry>Description</entry>
- <entry>TCP option fields</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>eol</entry>
- <entry>End of option list</entry>
- <entry>kind</entry>
- </row>
- <row>
- <entry>noop</entry>
- <entry>1 Byte TCP No-op options</entry>
- <entry>kind</entry>
- </row>
- <row>
- <entry>maxseg</entry>
- <entry>TCP Maximum Segment Size</entry>
- <entry>kind, length, size</entry>
- </row>
- <row>
- <entry>window</entry>
- <entry>TCP Window Scaling</entry>
- <entry>kind, length, count</entry>
- </row>
- <row>
- <entry>sack-permitted</entry>
- <entry>TCP SACK permitted</entry>
- <entry>kind, length</entry>
- </row>
- <row>
- <entry>sack</entry>
- <entry>TCP Selective Acknowledgement (alias of block 0)</entry>
- <entry>kind, length, left, right</entry>
- </row>
- <row>
- <entry>sack0</entry>
- <entry>TCP Selective Acknowledgement (block 0)</entry>
- <entry>kind, length, left, right</entry>
- </row>
- <row>
- <entry>sack1</entry>
- <entry>TCP Selective Acknowledgement (block 1)</entry>
- <entry>kind, length, left, right</entry>
- </row>
- <row>
- <entry>sack2</entry>
- <entry>TCP Selective Acknowledgement (block 2)</entry>
- <entry>kind, length, left, right</entry>
- </row>
- <row>
- <entry>sack3</entry>
- <entry>TCP Selective Acknowledgement (block 3)</entry>
- <entry>kind, length, left, right</entry>
- </row>
- <row>
- <entry>timestamp</entry>
- <entry>TCP Timestamps</entry>
- <entry>kind, length, tsval, tsecr</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
-
- <para>
- <example>
- <title>finding TCP options</title>
- <programlisting>
-filter input tcp option sack-permitted kind 1 counter
- </programlisting>
- </example>
- <example>
- <title>matching IPv6 exthdr</title>
- <programlisting>
-ip6 filter input frag more-fragments 1 counter
- </programlisting>
- </example>
- </para>
- </refsect2>
-
- <refsect2>
- <title>Conntrack expressions</title>
- <para>
- Conntrack expressions refer to meta data of the connection tracking entry associated with a packet.
- </para>
- <para>
- There are three types of conntrack expressions. Some conntrack expressions require the flow
- direction before the conntrack key, others must be used directly because they are direction agnostic.
- The <command>packets</command>, <command>bytes</command> and <command>avgpkt</command> keywords can be
- used with or without a direction. If the direction is omitted, the sum of the original and the reply
- direction is returned. The same is true for the <command>zone</command>, if a direction is given, the zone
- is only matched if the zone id is tied to the given direction.
- </para>
- <para>
- <cmdsynopsis>
- <command>ct</command>
- <group choice="req">
- <arg>state</arg>
- <arg>direction</arg>
- <arg>status</arg>
- <arg>mark</arg>
- <arg>expiration</arg>
- <arg>helper</arg>
- <arg>label</arg>
- <arg>l3proto</arg>
- <arg>protocol</arg>
- <arg>bytes</arg>
- <arg>packets</arg>
- <arg>avgpkt</arg>
- <arg>zone</arg>
- </group>
- </cmdsynopsis>
- <cmdsynopsis>
- <command>ct</command>
- <group choice="req">
- <arg>original</arg>
- <arg>reply</arg>
- </group>
- <group choice="req">
- <arg>l3proto</arg>
- <arg>protocol</arg>
- <arg>proto-src</arg>
- <arg>proto-dst</arg>
- <arg>bytes</arg>
- <arg>packets</arg>
- <arg>avgpkt</arg>
- <arg>zone</arg>
- </group>
- </cmdsynopsis>
- <cmdsynopsis>
- <command>ct</command>
- <group choice="req">
- <arg>original</arg>
- <arg>reply</arg>
- </group>
- <group choice="req">
- <arg>ip</arg>
- <arg>ip6</arg>
- </group>
- <group choice="req">
- <arg>saddr</arg>
- <arg>daddr</arg>
- </group>
- </cmdsynopsis>
-
- </para>
- <para>
- <table frame="all">
- <title>Conntrack expressions</title>
- <tgroup cols='3' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <colspec colname='c3'/>
- <thead>
- <row>
- <entry>Keyword</entry>
- <entry>Description</entry>
- <entry>Type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>state</entry>
- <entry>State of the connection</entry>
- <entry>ct_state</entry>
- </row>
- <row>
- <entry>direction</entry>
- <entry>Direction of the packet relative to the connection</entry>
- <entry>ct_dir</entry>
- </row>
- <row>
- <entry>status</entry>
- <entry>Status of the connection</entry>
- <entry>ct_status</entry>
- </row>
- <row>
- <entry>mark</entry>
- <entry>Connection mark</entry>
- <entry>mark</entry>
- </row>
- <row>
- <entry>expiration</entry>
- <entry>Connection expiration time</entry>
- <entry>time</entry>
- </row>
- <row>
- <entry>helper</entry>
- <entry>Helper associated with the connection</entry>
- <entry>string</entry>
- </row>
- <row>
- <entry>label</entry>
- <entry>Connection tracking label bit or symbolic name defined in connlabel.conf in the nftables include path</entry>
- <entry>ct_label</entry>
- </row>
- <row>
- <entry>l3proto</entry>
- <entry>Layer 3 protocol of the connection</entry>
- <entry>nf_proto</entry>
- </row>
- <row>
- <entry>saddr</entry>
- <entry>Source address of the connection for the given direction</entry>
- <entry>ipv4_addr/ipv6_addr</entry>
- </row>
- <row>
- <entry>daddr</entry>
- <entry>Destination address of the connection for the given direction</entry>
- <entry>ipv4_addr/ipv6_addr</entry>
- </row>
- <row>
- <entry>protocol</entry>
- <entry>Layer 4 protocol of the connection for the given direction</entry>
- <entry>inet_proto</entry>
- </row>
- <row>
- <entry>proto-src</entry>
- <entry>Layer 4 protocol source for the given direction</entry>
- <entry>integer (16 bit)</entry>
- </row>
- <row>
- <entry>proto-dst</entry>
- <entry>Layer 4 protocol destination for the given direction</entry>
- <entry>integer (16 bit)</entry>
- </row>
- <row>
- <entry>packets</entry>
- <entry>packet count seen in the given direction or sum of original and reply</entry>
- <entry>integer (64 bit)</entry>
- </row>
- <row>
- <entry>bytes</entry>
- <entry>byte count seen, see description for <command>packets</command> keyword</entry>
- <entry>integer (64 bit)</entry>
- </row>
- <row>
- <entry>avgpkt</entry>
- <entry>average bytes per packet, see description for <command>packets</command> keyword</entry>
- <entry>integer (64 bit)</entry>
- </row>
- <row>
- <entry>zone</entry>
- <entry>conntrack zone</entry>
- <entry>integer (16 bit)</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- <para>
- A description of conntrack-specific types listed above can be
- found sub-section <literal>CONNTRACK TYPES</literal> above.
- </para>
- </refsect2>
- </refsect1>
-
- <refsect1>
- <title>Statements</title>
- <para>
- Statements represent actions to be performed. They can alter control flow (return, jump
- to a different chain, accept or drop the packet) or can perform actions, such as logging,
- rejecting a packet, etc.
- </para>
- <para>
- Statements exist in two kinds. Terminal statements unconditionally terminate evaluation
- of the current rule, non-terminal statements either only conditionally or never terminate
- evaluation of the current rule, in other words, they are passive from the ruleset evaluation
- perspective. There can be an arbitrary amount of non-terminal statements in a rule, but
- only a single terminal statement as the final statement.
- </para>
-
- <refsect2>
- <title>Verdict statement</title>
- <para>
- The verdict statement alters control flow in the ruleset and issues
- policy decisions for packets.
- </para>
- <para>
- <cmdsynopsis>
- <group choice="req">
- <arg>accept</arg>
- <arg>drop</arg>
- <arg>queue</arg>
- <arg>continue</arg>
- <arg>return</arg>
- </group>
- </cmdsynopsis>
- <cmdsynopsis>
- <group choice="req">
- <arg>jump</arg>
- <arg>goto</arg>
- </group>
- <replaceable>chain</replaceable>
- </cmdsynopsis>
- </para>
- <para>
- <variablelist>
- <varlistentry>
- <term><option>accept</option></term>
- <listitem>
- <para>
- Terminate ruleset evaluation and accept the packet.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>drop</option></term>
- <listitem>
- <para>
- Terminate ruleset evaluation and drop the packet.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>queue</option></term>
- <listitem>
- <para>
- Terminate ruleset evaluation and queue the packet to userspace.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>continue</option></term>
- <listitem>
- <para>
- Continue ruleset evaluation with the next rule. FIXME
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>return</option></term>
- <listitem>
- <para>
- Return from the current chain and continue evaluation at the
- next rule in the last chain. If issued in a base chain, it is
- equivalent to <command>accept</command>.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>jump <replaceable>chain</replaceable></option></term>
- <listitem>
- <para>
- Continue evaluation at the first rule in <replaceable>chain</replaceable>.
- The current position in the ruleset is pushed to a call stack and evaluation
- will continue there when the new chain is entirely evaluated of a
- <command>return</command> verdict is issued.
- </para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>goto <replaceable>chain</replaceable></option></term>
- <listitem>
- <para>
- Similar to <command>jump</command>, but the current position is not pushed
- to the call stack, meaning that after the new chain evaluation will continue
- at the last chain instead of the one containing the goto statement.
- </para>
- </listitem>
- </varlistentry>
- </variablelist>
- </para>
- <para>
- <example>
- <title>Verdict statements</title>
- <programlisting>
-# process packets from eth0 and the internal network in from_lan
-# chain, drop all packets from eth0 with different source addresses.
-
-filter input iif eth0 ip saddr 192.168.0.0/24 jump from_lan
-filter input iif eth0 drop
- </programlisting>
- </example>
- </para>
- </refsect2>
- <refsect2>
- <title>Payload statement</title>
- <para>
- The payload statement alters packet content.
- It can be used for example to set ip DSCP (differv) header field or ipv6 flow labels.
- </para>
- <para>
- <example>
- <title>route some packets instead of bridging</title>
- <programlisting>
-# redirect tcp:http from 192.160.0.0/16 to local machine for routing instead of bridging
-# assumes 00:11:22:33:44:55 is local MAC address.
-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
- </programlisting>
- </example>
- <example>
- <title>Set IPv4 DSCP header field</title>
- <programlisting>
-ip forward ip dscp set 42
- </programlisting>
- </example>
- </para>
- </refsect2>
- <refsect2>
- <title>Extension header statement</title>
- <para>
- The extension header statement alters packet content in variable-sized headers.
- This can currently be used to alter the TCP Maximum segment size of packets,
- similar to TCPMSS.
- </para>
- <para>
- <example>
- <title>change tcp mss</title>
- <programlisting>
-tcp flags syn tcp option maxseg size set 1360
-# set a size based on route information:
-tcp flags syn tcp option maxseg size set rt mtu
- </programlisting>
- </example>
- </para>
- </refsect2>
- <refsect2>
- <title>Log statement</title>
- <para>
- <cmdsynopsis>
- <command>log</command>
- <arg choice="opt">prefix
- <replaceable>quoted_string</replaceable></arg>
- <arg choice="opt">level
- <replaceable>syslog-level</replaceable></arg>
- <arg choice="opt">flags
- <replaceable>log-flags</replaceable></arg>
- </cmdsynopsis>
- <cmdsynopsis>
- <command>log</command>
- <arg choice="none">group
- <replaceable>nflog_group</replaceable></arg>
- <arg choice="opt">prefix
- <replaceable>quoted_string</replaceable></arg>
- <arg choice="opt">queue-threshold
- <replaceable>value</replaceable></arg>
- <arg choice="opt">snaplen
- <replaceable>size</replaceable></arg>
- </cmdsynopsis>
- </para>
- <para>
- The log statement enables logging of matching packets. When this statement is used from a rule, the Linux kernel will print some information on all matching packets, such as header fields, via the kernel log (where it can be read with dmesg(1) or read in the syslog). If the group number is specified, the Linux kernel will pass the packet to nfnetlink_log which will multicast the packet through a netlink socket to the specified multicast group. One or more userspace processes may subscribe to the group to receive the packets, see libnetfilter_queue documentation for details. This is a non-terminating statement, so the rule evaluation continues after the packet is logged.
- </para>
- <para>
- <table frame="all">
- <title>log statement options</title>
- <tgroup cols='3' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <colspec colname='c3'/>
- <thead>
- <row>
- <entry>Keyword</entry>
- <entry>Description</entry>
- <entry>Type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>prefix</entry>
- <entry>Log message prefix</entry>
- <entry>quoted string</entry>
- </row>
- <row>
- <entry>level</entry>
- <entry>Syslog level of logging</entry>
- <entry>string: emerg, alert, crit, err, warn [default], notice, info, debug</entry>
- </row>
- <row>
- <entry>group</entry>
- <entry>NFLOG group to send messages to</entry>
- <entry>unsigned integer (16 bit)</entry>
- </row>
- <row>
- <entry>snaplen</entry>
- <entry>Length of packet payload to include in netlink message</entry>
- <entry>unsigned integer (32 bit)</entry>
- </row>
- <row>
- <entry>queue-threshold</entry>
- <entry>Number of packets to queue inside the kernel before sending them to userspace</entry>
- <entry>unsigned integer (32 bit)</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- <table frame="all">
- <title>log-flags</title>
- <tgroup cols='2' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <thead>
- <row>
- <entry>Flag</entry>
- <entry>Description</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>tcp sequence</entry>
- <entry>Log TCP sequence numbers.</entry>
- </row>
- <row>
- <entry>tcp options</entry>
- <entry>Log options from the TCP packet header.</entry>
- </row>
- <row>
- <entry>ip options</entry>
- <entry>Log options from the IP/IPv6 packet header.</entry>
- </row>
- <row>
- <entry>skuid</entry>
- <entry>Log the userid of the process which generated the packet.</entry>
- </row>
- <row>
- <entry>ether</entry>
- <entry>Decode MAC addresses and protocol.</entry>
- </row>
- <row>
- <entry>all</entry>
- <entry>Enable all log flags listed above.</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- <para>
- <example>
- <title>Using log statement</title>
- <programlisting>
-# log the UID which generated the packet and ip options
-ip filter output log flags skuid flags ip options
-
-# log the tcp sequence numbers and tcp options from the TCP packet
-ip filter output log flags tcp sequence,options
-
-# enable all supported log flags
-ip6 filter output log flags all
- </programlisting>
- </example>
- </para>
- </refsect2>
- <refsect2>
- <title>Reject statement</title>
- <para>
- <cmdsynopsis>
- <command>reject</command>
- <arg choice="opt">
- <arg choice="none">with</arg>
- <group choice="req">
- <arg>icmp</arg>
- <arg>icmpv6</arg>
- <arg>icmpx</arg>
- </group>
- <arg choice="none">type</arg>
- <group choice="req">
- <arg>icmp_code</arg>
- <arg>icmpv6_code</arg>
- <arg>icmpx_code</arg>
- </group>
- </arg>
- </cmdsynopsis>
- <cmdsynopsis>
- <command>reject</command>
- <arg choice="opt">
- <literal> with tcp reset </literal>
- </arg>
- </cmdsynopsis>
- </para>
- <para>
- A reject statement is used to send back an error packet in response to the matched packet otherwise it is equivalent to drop so it is a terminating statement, ending rule traversal. This statement is only valid in the input, forward and output chains, and user-defined chains which are only called from those chains.
- </para>
- <para>
- The different ICMP reject variants are meant for use in different table families:
- <table frame="all">
- <tgroup cols='3' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <colspec colname='c3'/>
- <thead>
- <row>
- <entry>Variant</entry>
- <entry>Family</entry>
- <entry>Type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>icmp</entry>
- <entry>ip</entry>
- <entry>icmp_code</entry>
- </row>
- <row>
- <entry>icmpv6</entry>
- <entry>ip6</entry>
- <entry>icmpv6_code</entry>
- </row>
- <row>
- <entry>icmpx</entry>
- <entry>inet</entry>
- <entry>icmpx_code</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- <para>
- For a description of the different types and a list of supported
- keywords refer to <literal>DATA TYPES</literal> section above.
- The common default reject value is
- <command>port-unreachable</command>.
- </para>
- <para>
- Note that in bridge family, reject statement is only allowed in base chains which
- hook into <literal>input</literal> or <literal>prerouting</literal>.
- </para>
- </refsect2>
- <refsect2>
- <title>Counter statement</title>
- <para>
- A counter statement sets the hit count of packets along with the number of bytes.
- </para>
- <para>
- <cmdsynopsis>
- <command>counter</command>
- <arg choice="opt">
- <literal>packets</literal>
- <replaceable>number</replaceable>
- <literal>bytes</literal>
- <replaceable>number</replaceable>
- </arg>
- </cmdsynopsis>
- </para>
-
- </refsect2>
- <refsect2>
- <title>Conntrack statement</title>
- <para>
- The conntrack statement can be used to set the conntrack mark and conntrack labels.
- </para>
- <para>
- <cmdsynopsis>
- <command>ct</command>
- <group choice="req">
- <arg>mark</arg>
- <arg>event</arg>
- <arg>label</arg>
- <arg>zone</arg>
- </group>
- <arg choice="none">set</arg>
- <replaceable>value</replaceable>
- </cmdsynopsis>
- </para>
- <para>
- The ct statement sets meta data associated with a connection.
- The zone id has to be assigned before a conntrack lookup takes place,
- i.e. this has to be done in prerouting and possibly output (if locally
- generated packets need to be placed in a distinct zone), with a hook
- priority of -300.
- </para>
- <para>
- <table frame="all">
- <title>Conntrack statement types</title>
- <tgroup cols='3' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <colspec colname='c3'/>
- <thead>
- <row>
- <entry>Keyword</entry>
- <entry>Description</entry>
- <entry>Value</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>event</entry>
- <entry>conntrack event bits</entry>
- <entry>bitmask, integer (32 bit)</entry>
- </row>
-
- <row>
- <entry>helper</entry>
- <entry>name of ct helper object to assign to the connection</entry>
- <entry>quoted string</entry>
- </row>
- <row>
- <entry>mark</entry>
- <entry>Connection tracking mark</entry>
- <entry>mark</entry>
- </row>
- <row>
- <entry>label</entry>
- <entry>Connection tracking label</entry>
- <entry>label</entry>
- </row>
- <row>
- <entry>zone</entry>
- <entry>conntrack zone</entry>
- <entry>integer (16 bit)</entry>
- </row>
-
- </tbody>
- </tgroup>
- </table>
- </para>
- <para>
- <example>
- <title>save packet nfmark in conntrack</title>
- <programlisting>
-ct mark set meta mark
- </programlisting>
- </example>
- <example>
- <title>set zone mapped via interface</title>
- <programlisting>
-table inet raw {
- chain prerouting {
- type filter hook prerouting priority -300;
- ct zone set iif map { "eth1" : 1, "veth1" : 2 }
- }
- chain output {
- type filter hook output priority -300;
- ct zone set oif map { "eth1" : 1, "veth1" : 2 }
- }
-}
- </programlisting>
- </example>
- <example>
- <title>restrict events reported by ctnetlink</title>
- <programlisting>
-ct event set new,related,destroy
- </programlisting>
- </example>
-
-
- </para>
- </refsect2>
- <refsect2>
- <title>Meta statement</title>
- <para>
- A meta statement sets the value of a meta expression.
- The existing meta fields are: priority, mark, pkttype, nftrace.
- </para>
- <para>
- <cmdsynopsis>
- <command>meta</command>
- <group choice="req">
- <arg>mark</arg>
- <arg>priority</arg>
- <arg>pkttype</arg>
- <arg>nftrace</arg>
- </group>
- <arg choice="none">set</arg>
- <replaceable>value</replaceable>
- </cmdsynopsis>
- </para>
- <para>
- A meta statement sets meta data associated with a packet.
- </para>
- <para>
- <table frame="all">
- <title>Meta statement types</title>
- <tgroup cols='3' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <colspec colname='c3'/>
- <thead>
- <row>
- <entry>Keyword</entry>
- <entry>Description</entry>
- <entry>Value</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>priority</entry>
- <entry>TC packet priority</entry>
- <entry>tc_handle</entry>
- </row>
- <row>
- <entry>mark</entry>
- <entry>Packet mark</entry>
- <entry>mark</entry>
- </row>
- <row>
- <entry>pkttype</entry>
- <entry>packet type</entry>
- <entry>pkt_type</entry>
- </row>
- <row>
- <entry>nftrace</entry>
- <entry>ruleset packet tracing on/off. Use <command>monitor trace</command> command to watch traces</entry>
- <entry>0, 1</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
-
-
- </refsect2>
- <refsect2>
- <title>Limit statement</title>
- <para>
- <cmdsynopsis>
- <command>limit</command>
- <arg choice="none">rate</arg>
- <arg choice="opt">over</arg>
- <replaceable>packet_number</replaceable>
- <arg choice="none">/</arg>
- <group choice="req">
- <arg>second</arg>
- <arg>minute</arg>
- <arg>hour</arg>
- <arg>day</arg>
- </group>
- <arg>burst <replaceable>packet_number</replaceable> packets</arg>
- </cmdsynopsis>
- <cmdsynopsis>
- <command>limit</command>
- <arg choice="none">rate</arg>
- <arg choice="opt">over</arg>
- <replaceable>byte_number</replaceable>
- <group choice="req">
- <arg>bytes</arg>
- <arg>kbytes</arg>
- <arg>mbytes</arg>
- </group>
- <arg choice="none">/</arg>
- <group choice="req">
- <arg>second</arg>
- <arg>minute</arg>
- <arg>hour</arg>
- <arg>day</arg>
- <arg>week</arg>
- </group>
- <arg>burst <replaceable>byte_number</replaceable> bytes</arg>
- </cmdsynopsis>
- </para>
- <para>
- A limit statement matches at a limited rate using a token bucket filter. A rule using this statement will match until this limit is reached. It can be used in combination with the log statement to give limited logging. The <command>over</command> keyword, that is optional, makes it match over the specified rate.
- </para>
- <table frame="all">
- <title>limit statement values</title>
- <tgroup cols='3' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <colspec colname='c3'/>
- <thead>
- <row>
- <entry>Value</entry>
- <entry>Description</entry>
- <entry>Type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>packet_number</entry>
- <entry>Number of packets</entry>
- <entry>unsigned integer (32 bit)</entry>
- </row>
- <row>
- <entry>byte_number</entry>
- <entry>Number of bytes</entry>
- <entry>unsigned integer (32 bit)</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </refsect2>
- <refsect2>
- <title>NAT statements</title>
- <para>
- <cmdsynopsis>
- <command>snat</command>
- <arg choice="none">to
- <replaceable>address</replaceable>
- <arg choice="opt">:port</arg></arg>
- <arg choice="opt">persistent, random, fully-random</arg>
- </cmdsynopsis>
- <cmdsynopsis>
- <command>snat</command>
- <arg choice="none">to
- <replaceable>address</replaceable> - <replaceable>address</replaceable>
- <arg choice="opt">:<replaceable>port</replaceable> - <replaceable>port</replaceable></arg></arg>
- <arg choice="opt">persistent, random, fully-random</arg>
- </cmdsynopsis>
- <cmdsynopsis>
- <command>dnat</command>
- <arg choice="none">to
- <replaceable>address</replaceable>
- <arg choice="opt">:<replaceable>port</replaceable></arg></arg>
- <arg choice="opt">persistent, random, fully-random</arg>
- </cmdsynopsis>
- <cmdsynopsis>
- <command>dnat</command>
- <arg choice="none">to
- <replaceable>address</replaceable>
- <arg choice="opt">:<replaceable>port</replaceable> - <replaceable>port</replaceable></arg></arg>
- <arg choice="opt">persistent, random, fully-random</arg>
- </cmdsynopsis>
- <cmdsynopsis>
- <command>masquerade</command>
- <arg choice="none">to
- <arg choice="opt">:<replaceable>port</replaceable></arg></arg>
- <arg choice="opt">persistent, random, fully-random</arg>
- </cmdsynopsis>
- <cmdsynopsis>
- <command>masquerade</command>
- <arg choice="none">to
- <arg choice="opt">:<replaceable>port</replaceable> - <replaceable>port</replaceable></arg></arg>
- <arg choice="opt">persistent, random, fully-random</arg>
- </cmdsynopsis>
- <cmdsynopsis>
- <command>redirect</command>
- <arg choice="none">to
- <arg choice="opt">:<replaceable>port</replaceable></arg></arg>
- <arg choice="opt">persistent, random, fully-random</arg>
- </cmdsynopsis>
- <cmdsynopsis>
- <command>redirect</command>
- <arg choice="none">to
- <arg choice="opt">:<replaceable>port</replaceable> - <replaceable>port</replaceable></arg></arg>
- <arg choice="opt">persistent, random, fully-random</arg>
- </cmdsynopsis>
- </para>
- <para>
- The nat statements are only valid from nat chain types.
- </para>
- <para>
- The <command>snat</command> and <command>masquerade</command> statements specify that the source address of the packet should be modified. While <command>snat</command> is only valid in the postrouting and input chains, <command>masquerade</command> makes sense only in postrouting. The <command>dnat</command> and <command>redirect</command> statements are only valid in the prerouting and output chains, they specify that the destination address of the packet should be modified. You can use non-base chains which are called from base chains of nat chain type too. All future packets in this connection will also be mangled, and rules should cease being examined.
- </para>
- <para>
- The <command>masquerade</command> statement is a special form of <command>snat</command> which always uses the outgoing interface's IP address to translate to. It is particularly useful on gateways with dynamic (public) IP addresses.
- </para>
- <para>
- The <command>redirect</command> statement is a special form of <command>dnat</command> which always translates the destination address to the local host's one. It comes in handy if one only wants to alter the destination port of incoming traffic on different interfaces.
- </para>
- <para>
- Note that all nat statements require both prerouting and postrouting base chains to be present since otherwise packets on the return path won't be seen by netfilter and therefore no reverse translation will take place.
- </para>
- <para>
- <table frame="all">
- <title>NAT statement values</title>
- <tgroup cols='3' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <colspec colname='c3'/>
- <thead>
- <row>
- <entry>Expression</entry>
- <entry>Description</entry>
- <entry>Type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>address</entry>
- <entry>Specifies that the source/destination address of the packet should be modified. You may specify a mapping to relate a list of tuples composed of arbitrary expression key with address value.</entry>
- <entry>ipv4_addr, ipv6_addr, e.g. abcd::1234, or you can use a mapping, e.g. meta mark map { 10 : 192.168.1.2, 20 : 192.168.1.3 }</entry>
- </row>
- <row>
- <entry>port</entry>
- <entry>Specifies that the source/destination address of the packet should be modified.</entry>
- <entry>port number (16 bits)</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- <table frame="all">
- <title>NAT statement flags</title>
- <tgroup cols='2' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <thead>
- <row>
- <entry>Flag</entry>
- <entry>Description</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>persistent</entry>
- <entry>Gives a client the same source-/destination-address for each connection.</entry>
- </row>
- <row>
- <entry>random</entry>
- <entry>If used then port mapping will be randomized using a random seeded MD5 hash mix using source and destination address and destination port.</entry>
- </row>
- <row>
- <entry>fully-random</entry>
- <entry>If used then port mapping is generated based on a 32-bit pseudo-random algorithm.</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- <para>
- <example>
- <title>Using NAT statements</title>
- <programlisting>
-# create a suitable table/chain setup for all further examples
-add table nat
-add chain nat prerouting { type nat hook prerouting priority 0; }
-add chain nat postrouting { type nat hook postrouting priority 100; }
-
-# translate source addresses of all packets leaving via eth0 to address 1.2.3.4
-add rule nat postrouting oif eth0 snat to 1.2.3.4
-
-# redirect all traffic entering via eth0 to destination address 192.168.1.120
-add rule nat prerouting iif eth0 dnat to 192.168.1.120
-
-# translate source addresses of all packets leaving via eth0 to whatever
-# locally generated packets would use as source to reach the same destination
-add rule nat postrouting oif eth0 masquerade
-
-# redirect incoming TCP traffic for port 22 to port 2222
-add rule nat prerouting tcp dport 22 redirect to :2222
- </programlisting>
- </example>
- </para>
- </refsect2>
-
- <refsect2>
- <title>Flow offload statement</title>
- <para>
- A flow offload statement allows us to select what flows
- you want to accelerate forwarding through layer 3 network
- stack bypass. You have to specify the flowtable name where
- you want to offload this flow.
- </para>
- <para>
- <cmdsynopsis>
- <command>flow offload</command>
- <literal>@flowtable</literal>
- </cmdsynopsis>
- </para>
-
- </refsect2>
-
- <refsect2>
- <title>Queue statement</title>
- <para>
- This statement passes the packet to userspace using the nfnetlink_queue handler. The packet is put into the queue identified by its 16-bit queue number. Userspace can inspect and modify the packet if desired. Userspace must then drop or re-inject the packet into the kernel. See libnetfilter_queue documentation for details.
- </para>
- <para>
- <cmdsynopsis>
- <command>queue</command>
- <arg choice="opt">num
- <replaceable>queue_number</replaceable></arg>
- <arg choice="opt">bypass</arg>
- </cmdsynopsis>
- <cmdsynopsis>
- <command>queue</command>
- <arg choice="opt">num
- <replaceable>queue_number_from</replaceable> - <replaceable>queue_number_to</replaceable></arg>
- <arg choice="opt">bypass,fanout</arg>
- </cmdsynopsis>
- </para>
- <para>
- <table frame="all">
- <title>queue statement values</title>
- <tgroup cols='3' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <colspec colname='c3'/>
- <thead>
- <row>
- <entry>Value</entry>
- <entry>Description</entry>
- <entry>Type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>queue_number</entry>
- <entry>Sets queue number, default is 0.</entry>
- <entry>unsigned integer (16 bit)</entry>
- </row>
- <row>
- <entry>queue_number_from</entry>
- <entry>Sets initial queue in the range, if fanout is used.</entry>
- <entry>unsigned integer (16 bit)</entry>
- </row>
- <row>
- <entry>queue_number_to</entry>
- <entry>Sets closing queue in the range, if fanout is used.</entry>
- <entry>unsigned integer (16 bit)</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- <table frame="all">
- <title>queue statement flags</title>
- <tgroup cols='2' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <thead>
- <row>
- <entry>Flag</entry>
- <entry>Description</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>bypass</entry>
- <entry>Let packets go through if userspace application cannot back off. Before using this flag, read libnetfilter_queue documentation for performance tuning recommendations.</entry>
- </row>
- <row>
- <entry>fanout</entry>
- <entry>Distribute packets between several queues.</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- </refsect2>
- <refsect2>
- <title>Dup statement</title>
- <para>
- The dup statement is used to duplicate a packet and send the copy to a different destination.
- </para>
- <para>
- <cmdsynopsis>
- <command>dup</command>
- <arg choice="none">to
- <replaceable>device</replaceable></arg>
- </cmdsynopsis>
- <cmdsynopsis>
- <command>dup</command>
- <arg choice="none">to
- <replaceable>address</replaceable>
- <arg choice="none">device</arg>
- <replaceable>device</replaceable></arg>
- </cmdsynopsis>
- </para>
- <para>
- <table frame="all">
- <title>Dup statement values</title>
- <tgroup cols='3' align='left' colsep='1' rowsep='1'>
- <colspec colname='c1'/>
- <colspec colname='c2'/>
- <colspec colname='c3'/>
- <thead>
- <row>
- <entry>Expression</entry>
- <entry>Description</entry>
- <entry>Type</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>address</entry>
- <entry>Specifies that the copy of the packet should be sent to a new gateway.</entry>
- <entry>ipv4_addr, ipv6_addr, e.g. abcd::1234, or you can use a mapping, e.g. ip saddr map { 192.168.1.2 : 10.1.1.1 }</entry>
- </row>
- <row>
- <entry>device</entry>
- <entry>Specifies that the copy should be transmitted via device.</entry>
- <entry>string</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </para>
- <para>
- <example>
- <title>Using the dup statement</title>
- <programlisting>
-# send to machine with ip address 10.2.3.4 on eth0
-ip filter forward dup to 10.2.3.4 device "eth0"
-
-# copy raw frame to another interface
-netdetv ingress dup to "eth0"
-dup to "eth0"
-
-# combine with map dst addr to gateways
-dup to ip daddr map { 192.168.7.1 : "eth0", 192.168.7.2 : "eth1" }
- </programlisting>
- </example>
- </para>
- </refsect2>
- <refsect2>
- <title>Fwd statement</title>
- <para>
- The fwd statement is used to redirect a raw packet to another interface. It is only available in the netdev family ingress hook.
- It is similar to the dup statement except that no copy is made.
- </para>
- <para>
- <cmdsynopsis>
- <command>fwd</command>
- <arg choice="none">to
- <replaceable>device</replaceable></arg>
- </cmdsynopsis>
- </para>
- </refsect2>
-
- <refsect2>
- <title>Set statement</title>
- <para>
- The set statement is used to dynamically add or update elements in a set from the packet path.
- The set <literal>setname</literal> must already exist in the given table and must have been
- created with the <literal>dynamic</literal> flag.
- Furthermore, these sets must specify both a maximum set size (to prevent memory exhaustion) and
- a timeout (so that number of entries in set will not grow indefinitely).
- The set statement can be used to e.g. create dynamic blacklists.
- </para>
- <para>
- <cmdsynopsis>
- <group choice="req">
- <arg>add</arg>
- <arg>update</arg>
- </group>
- <replaceable>@setname</replaceable>
- <replaceable>{ expression </replaceable>
- <arg choice="opt">timeout <replaceable>timeout</replaceable></arg>
- <arg choice="opt">comment <replaceable>string</replaceable></arg>
- <replaceable>}</replaceable>
- </cmdsynopsis>
- </para>
- <para>
- <example>
- <title>Example for simple blacklist</title>
- <programlisting>
- # declare a set, bound to table "filter", in family "ip". Timeout and size are mandatory because we will add elements from packet path.
- nft add set ip filter blackhole "{ type ipv4_addr; flags timeout; size 65536; }"
-
- # whitelist internal interface.
- nft add rule ip filter input meta iifname "internal" accept
-
- # drop packets coming from blacklisted ip addresses.
- nft add rule ip filter input ip saddr @blackhole counter drop
-
- # add source ip addresses to the blacklist if more than 10 tcp connection requests occurred per second and ip address.
- # entries will timeout after one minute, after which they might be re-added if limit condition persists.
- nft add rule ip filter input tcp flags syn tcp dport ssh meter flood size 128000 { ip saddr timeout 10s limit rate over 10/second} add @blackhole { ip saddr timeout 1m } drop
-
- # inspect state of the rate limit meter:
- nft list meter ip filter flood
-
- # inspect content of blackhole:
- nft list set ip filter blackhole
-
- # manually add two addresses to the set:
- nft add element filter blackhole { 10.2.3.4, 10.23.1.42 }
- </programlisting>
- </example>
- </para>
- </refsect2>
- </refsect1>
-
- <refsect1>
- <title>Additional commands</title>
- <para>
- These are some additional commands included in nft.
- </para>
- <refsect2>
- <title>monitor</title>
- <para>
- The monitor command allows you to listen to Netlink events produced
- by the nf_tables subsystem, related to creation and deletion of objects.
- When they occur, nft will print to stdout the monitored events in either
- XML, JSON or native nft format.
- </para>
- <para>
- To filter events related to a concrete object, use one of the keywords 'tables', 'chains', 'sets', 'rules', 'elements', 'ruleset'.
- </para>
- <para>
- To filter events related to a concrete action, use keyword 'new' or 'destroy'.
- </para>
- <para>
- Hit ^C to finish the monitor operation.
- </para>
- <example>
- <title>Listen to all events, report in native nft format</title>
- <programlisting>
-% nft monitor
- </programlisting>
- </example>
- <example>
- <title>Listen to added tables, report in XML format</title>
- <programlisting>
-% nft monitor new tables xml
- </programlisting>
- </example>
- <example>
- <title>Listen to deleted rules, report in JSON format</title>
- <programlisting>
-% nft monitor destroy rules json
- </programlisting>
- </example>
- <example>
- <title>Listen to both new and destroyed chains, in native nft format</title>
- <programlisting>
-% nft monitor chains
- </programlisting>
- </example>
- <example>
- <title>Listen to ruleset events such as table, chain, rule, set, counters and quotas, in native nft format</title>
- <programlisting>
-% nft monitor ruleset
- </programlisting>
- </example>
- </refsect2>
- </refsect1>
-
- <refsect1>
- <title>Error reporting</title>
- <para>
- When an error is detected, nft shows the line(s) containing the error, the position
- of the erroneous parts in the input stream and marks up the erroneous parts using
- carets (<literal>^</literal>). If the error results from the combination of two
- expressions or statements, the part imposing the constraints which are violated is
- marked using tildes (<literal>~</literal>).
- </para>
- <para>
- For errors returned by the kernel, nft can't detect which parts of the input caused
- the error and the entire command is marked.
- </para>
- <example>
- <title>Error caused by single incorrect expression</title>
- <programlisting>
-&lt;cmdline&gt;:1:19-22: Error: Interface does not exist
-filter output oif eth0
- ^^^^
- </programlisting>
- </example>
- <example>
- <title>Error caused by invalid combination of two expressions</title>
- <programlisting>
-&lt;cmdline&gt;:1:28-36: Error: Right hand side of relational expression (==) must be constant
-filter output tcp dport == tcp dport
- ~~ ^^^^^^^^^
- </programlisting>
- </example>
-
- <example>
- <title>Error returned by the kernel</title>
- <programlisting>
-&lt;cmdline&gt;:0:0-23: Error: Could not process rule: Operation not permitted
-filter output oif wlan0
-^^^^^^^^^^^^^^^^^^^^^^^
- </programlisting>
- </example>
- </refsect1>
-
- <refsect1>
- <title>Exit status</title>
- <para>
- On success, nft exits with a status of 0. Unspecified
- errors cause it to exit with a status of 1, memory allocation
- errors with a status of 2, unable to open Netlink socket with 3.
- </para>
- </refsect1>
-
- <refsect1>
- <title>See Also</title>
- <para>
- <simplelist type="inline">
- <member>iptables(8)</member>
- <member>ip6tables(8)</member>
- <member>arptables(8)</member>
- <member>ebtables(8)</member>
- <member>ip(8)</member>
- <member>tc(8)</member>
- </simplelist>
- </para>
- <para>
- There is an official wiki at: https://wiki.nftables.org
- </para>
- </refsect1>
-
- <refsect1>
- <title>Authors</title>
- <para>
- nftables was written by Patrick McHardy and Pablo Neira Ayuso, among many other contributors from the Netfilter community.
- </para>
- </refsect1>
-
- <refsect1>
- <title>Copyright</title>
- <literallayout>
-Copyright &copy; 2008-2014 Patrick McHardy <email>kaber@trash.net</email>
-Copyright &copy; 2013-2016 Pablo Neira Ayuso <email>pablo@netfilter.org</email>
- </literallayout>
- <para>
- nftables is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License version 2 as
- published by the Free Software Foundation.
- </para>
- <para>
- This documentation is licensed under the terms of the Creative
- Commons Attribution-ShareAlike 4.0 license,
- <ulink url="http://creativecommons.org/licenses/by-sa/4.0/">CC BY-SA 4.0</ulink>.
- </para>
- </refsect1>
-</refentry>
diff --git a/doc/payload-expression.txt b/doc/payload-expression.txt
new file mode 100644
index 00000000..d454c95e
--- /dev/null
+++ b/doc/payload-expression.txt
@@ -0,0 +1,590 @@
+ETHERNET HEADER EXPRESSION
+~~~~~~~~~~~~~~~~~~~~~~~~~~
+[verse]
+*ether* ['Ethernet' 'header' 'field']
+
+.Ethernet header expression types
+[options="header"]
+|==================
+|Keyword| Description| Type
+|daddr|
+Destination MAC address|
+ether_addr
+|saddr|
+Source MAC address|
+ether_addr
+|type|
+EtherType|
+ether_type
+|==================
+
+VLAN HEADER EXPRESSION
+~~~~~~~~~~~~~~~~~~~~~~
+[verse]
+*vlan* ['VLAN' 'header' 'field']
+
+.VLAN header expression
+[options="header"]
+|==================
+|Keyword| Description| Type
+|id|
+VLAN ID (VID) |
+integer (12 bit)
+|cfi|
+Canonical Format Indicator|
+integer (1 bit)
+|pcp|
+Priority code point|
+integer (3 bit)
+|type|
+EtherType|
+ether_type
+|==================
+
+.ARP HEADER EXPRESSION
+[options="header"]
+|==================
+|Keyword| Description| Type
+|htype|
+ARP hardware type|
+integer (16 bit)
+|ptype|
+EtherType|
+ether_type
+|hlen|
+Hardware address len|
+integer (8 bit)
+|plen|
+Protocol address len |
+integer (8 bit)
+|operation|
+Operation |
+arp_op
+|======================
+
+IPV4 HEADER EXPRESSION
+~~~~~~~~~~~~~~~~~~~~~~
+[verse]
+ip ['IPv4' 'header' 'field']
+
+.IPv4 header expression
+[options="header"]
+|==================
+|Keyword| Description| Type
+|version|
+IP header version (4)|
+integer (4 bit)
+|hdrlength|
+IP header length including options|
+integer (4 bit) FIXME scaling
+|dscp|
+Differentiated Services Code Point|
+dscp
+|ecn|
+Explicit Congestion Notification|
+ecn
+|length|
+Total packet length |
+integer (16 bit)
+|id|
+IP ID|
+integer (16 bit)
+|frag-off|
+Fragment offset |
+integer (16 bit)
+|ttl|
+Time to live|
+integer (8 bit)
+|protocol|
+Upper layer protocol |
+inet_proto
+|checksum|
+IP header checksum|
+integer (16 bit)
+|saddr|
+Source address|
+ipv4_addr
+|daddr|
+Destination address |
+ipv4_addr
+|======================
+
+ICMP HEADER EXPRESSION
+~~~~~~~~~~~~~~~~~~~~~~
+[verse]
+icmp ['ICMP' 'header' 'field']
+
+.ICMP header expression
+[options="header"]
+|==================
+|Keyword|Description| Type
+|type|
+ICMP type field |
+icmp_type
+|code|
+ICMP code field |
+integer (8 bit)
+|checksum|
+ICMP checksum field |
+integer (16 nit)
+|id|
+ID of echo request/response |
+integer (16 bit)
+|sequence|
+sequence number of echo request/response|
+integer (16 bit)
+|gateway|
+gateway of redirects|
+integer (32 bit)
+|mtu|
+MTU of path MTU discovery|
+integer (32 bit)
+|============================
+
+IPV6 HEADER EXPRESSION
+~~~~~~~~~~~~~~~~~~~~~~
+[verse]
+ip6 ['IPv6' 'header' 'field']
+
+This expression refers to the ipv6 header fields. Caution when using ip6 nexthdr, the value only refers to the next header, i.e. ip6 nexthdr tcp will only match if the ipv6 packet does not contain any extension headers. Packets that are fragmented or e.g. contain a routing extension headers will not be matched. Please use meta l4proto if you wish to match the real transport header and ignore any additional extension headers instead.
+
+.IPv6 header expression
+[options="header"]
+|==================
+|Keyword|Description| Type
+|version|
+IP header version (6)|
+integer (4 bit)
+|dscp|
+Differentiated Services Code Point|
+dscp
+|ecn|
+Explicit Congestion Notification|
+ecn
+|flowlabel|
+Flow label|
+integer (20 bit)
+|length|
+Payload length|
+integer (16 bit)
+|nexthdr|
+Nexthdr protocol|
+inet_proto
+|hoplimit|
+Hop limit|
+integer (8 bit)
+|saddr|
+Source address|
+ipv6_addr
+|daddr|
+Destination address |
+ipv6_addr
+|=======================
+*matching if first extension header indicates a fragment* +
+
+ip6 nexthdr ipv6-frag counter
+
+ICMPV6 HEADER EXPRESSION
+~~~~~~~~~~~~~~~~~~~~~~~~
+[verse]
+icmpv6 ['ICMPv6' 'header' 'field']
+
+.ICMPv6 header expression
+[options="header"]
+|==================
+|Keyword| Description| Type
+|type|
+ICMPv6 type field|
+icmpv6_type
+|code|
+ICMPv6 code field|
+integer (8 bit)
+|checksum|
+ICMPv6 checksum field|
+integer (16 bit)
+|parameter-problem|
+pointer to problem|
+integer (32 bit)
+|packet-too-big|
+oversized MTU|
+integer (32 bit)
+|id|
+ID of echo request/response |
+integer (16 bit)
+|sequence|
+sequence number of echo request/response|
+integer (16 bit)
+|max-delay|
+maximum response delay of MLD queries|
+integer (16 bit)
+|==============================
+
+TCP HEADER EXPRESSION
+~~~~~~~~~~~~~~~~~~~~~
+[verse]
+tcp ['TCP' 'header' 'field']
+
+.TCP header expression
+[options="header"]
+|==================
+|Keyword| Description| Type
+|sport|
+source port|
+inet_service
+|dport|
+Destination port|
+inet_service
+|sequence|
+Sequence number|
+integer (32 bit)
+|ackseq|
+Acknowledgement number |
+integer (32 bit)
+|doff|
+Data offset |
+integer (4 bit) FIXME scaling
+|reserved|
+Reserved area |
+integer (4 bit)
+|flags|
+TCP flags|
+tcp_flags
+|window|
+Window|
+integer (16 bit)
+|checksum|
+checksum|
+integer (16 bit)
+|urgptr|
+Urgent pointer|
+integer (16 bit)
+|======================
+
+UDP HEADER EXPRESSION
+~~~~~~~~~~~~~~~~~~~~~
+[verse]
+udp ['UDP' 'header' 'field']
+
+.UDP header expression
+[options="header"]
+|==================
+|Keyword| Description| Type
+|sport|
+source port|
+inet_service
+|dport|
+Destination port|
+inet_service
+|length|
+Total packet length|
+integer (16 bit)
+|checksum|
+Checksum|
+integer (16 bit)
+|================
+
+UDP-LITE HEADER EXPRESSION
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+[verse]
+*udplite* ['UDP-Lite' 'header' 'field']
+
+.UDP-Lite header expression
+[options="header"]
+|==================
+|Keyword| Description| Type
+|sport|
+source port|
+inet_service
+|dport|
+Destination port|
+inet_service
+|checksum|
+Checksum|
+integer (16 bit)
+|================
+
+SCTP HEADER EXPRESSION
+~~~~~~~~~~~~~~~~~~~~~~~
+[verse]
+*sctp* ['SCTP' 'header' 'field']
+
+.SCTP header expression
+[options="header"]
+|==================
+|Keyword| Description| Type
+|sport|
+source port|
+inet_service
+|dport|
+Destination port|
+inet_service
+|vtag|
+Verification Tag|
+integer (32 bit)
+|checksum|
+Checksum|
+integer (32 bit)
+|================
+
+DCCP HEADER EXPRESSION
+~~~~~~~~~~~~~~~~~~~~~~
+[verse]
+*dccp* ['DCCP' 'header' 'field']
+
+.DCCP header expression
+[options="header"]
+|==================
+|Keyword| Description| Type
+|sport|
+source port|
+inet_service
+|dport|
+Destination port|
+inet_service
+|========================
+
+AUTHENTICATION HEADER EXPRESSION
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+[verse]
+*ah* ['AH' 'header' 'field']
+
+.AH header expression
+[options="header"]
+|==================
+|Keyword| Description| Type
+|nexthdr|
+Next header protocol|
+inet_proto
+|hdrlength|
+AH Header length|
+integer (8 bit)
+|reserved|
+Reserved area|
+integer (16 bit)
+|spi|
+Security Parameter Index |
+integer (32 bit)
+|sequence|
+Sequence number|
+integer (32 bit)
+|========================
+
+ENCRYPTED SECURITY PAYLOAD HEADER EXPRESSION
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+[verse]
+*esp* ['ESP' 'header' 'field']
+
+.ESP header expression
+[options="header"]
+|==================
+|Keyword| Description| Type
+|spi|
+Security Parameter Index |
+integer (32 bit)
+|sequence|
+Sequence number|
+integer (32 bit)
+|===========================
+
+IPCOMP HEADER EXPRESSION
+~~~~~~~~~~~~~~~~~~~~~~~~~
+*comp* ['IPComp' 'header' 'field']
+
+.IPComp header expression
+[options="header"]
+|==================
+|Keyword| Description| Type
+|nexthdr|
+Next header protocol|
+inet_proto
+|flags|
+Flags|
+bitmask
+|cpi|
+compression Parameter Index |
+integer (16 bit)
+|============================
+
+RAW PAYLOAD EXPRESSION
+~~~~~~~~~~~~~~~~~~~~~~
+[verse]
+*@* [base,offset,length]
+
+The raw payload expression instructs to load lengthbits starting at offsetbits. Bit 0 refers to the very first bit -- in the C programming language, this corresponds to the topmost bit, i.e. 0x80 in case of an octet. They are useful to match headers that do not have a human-readable template expression yet. Note that nft will not add dependencies for Raw payload expressions. If you e.g. want to match protocol fields of a transport header with protocol number 5, you need to manually exclude packets that have a different transport header, for instance my using meta l4proto 5 before the raw expression.
+
+.Support payload protocol bases
+[options="header"]
+|==================
+|Base| Description
+|ll|
+Link layer, for example the Ethernet header
+|nh|
+Network header, for example IPv4 or IPv6
+|th|
+Transport Header, for example TCP
+|==============================
+
+.Matching destination port of both UDP and TCP
+----------------------------------------------
+inet filter input meta l4proto {tcp, udp} @th,16,16 { dns, http }
+-----------------------------------------------------------------
+
+.Rewrite arp packet target hardware address if target protocol address matches a given address
+----------------------------------------------------------------------------------------------
+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
+-----------------------------------------------------------------------------------------------
+
+EXTENSION HEADER EXPRESSIONS
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Extension header expressions refer to data from variable-sized protocol headers, such as IPv6 extension headers and TCP options.
+
+nftables currently supports matching (finding) a given ipv6 extension header or TCP option.
+[verse]
+*hbh* {nexthdr | hdrlength}
+*frag* {nexthdr | frag-off | more-fragments | id}
+*rt* {nexthdr | hdrlength | type | seg-left}
+*dst* {nexthdr | hdrlength}
+*mh* {nexthdr | hdrlength | checksum | type}
+*srh* {flags | tag | sid | seg-left}
+*tcp option* {eol | noop | maxseg | window | sack-permitted | sack | sack0 | sack1 | sack2 | sack3 | timestamp} 'tcp_option_field'
+
+The following syntaxes are valid only in a relational expression with boolean type on right-hand side for checking header existence only:
+[verse]
+*exthdr* {hbh | frag | rt | dst | mh}
+*tcp option* {eol | noop | maxseg | window | sack-permitted | sack | sack0 | sack1 | sack2 | sack3 | timestamp}
+
+.IPv6 extension headers
+[options="header"]
+|==================
+|Keyword| Description
+|hbh|
+Hop by Hop
+|rt|
+Routing Header
+|frag|
+Fragmentation header
+|dst|
+dst options
+|mh|
+Mobility Header
+|srh|
+Segment Routing Header
+|=====================
+
+.TCP Options
+[options="header"]
+|==================
+|Keyword| Description | TCP option fields
+|eol|
+End if option list|
+kind
+|noop|
+1 Byte TCP No-op options |
+kind
+|maxseg|
+TCP Maximum Segment Size|
+kind, length, size
+|window|
+TCP Window Scaling |
+kind, length, count
+|sack-permitted|
+TCP SACK permitted |
+kind, length
+|sack|
+TCP Selective Acknowledgement (alias of block 0) |
+kind, length, left, right
+|sack0|
+TCP Selective Acknowledgement (block 0) |
+kind, length, left, right
+|sack1|
+TCP Selective Acknowledgement (block 1) |
+kind, length, left, right
+|sack2|
+TCP Selective Acknowledgement (block 2) |
+kind, length, left, right
+|sack3|
+TCP Selective Acknowledgement (block 3) |
+kind, length, left, right
+|timestamp|
+TCP Timestamps |
+kind, length, tsval, tsecr
+|============================
+
+.finding TCP options
+--------------------
+filter input tcp option sack-permitted kind 1 counter
+--------------------
+
+.matching IPv6 exthdr
+---------------------
+ip6 filter input frag more-fragments 1 counter
+---------------------------------------
+
+CONNTRACK EXPRESSIONS
+~~~~~~~~~~~~~~~~~~~~~
+Conntrack expressions refer to meta data of the connection tracking entry associated with a packet. +
+
+There are three types of conntrack expressions. Some conntrack expressions require the flow direction before the conntrack key, others must be used directly because they are direction agnostic. The *packets*, *bytes* and *avgpkt* keywords can be used with or without a direction. If the direction is omitted, the sum of the original and the reply direction is returned. The same is true for the *zone*, if a direction is given, the zone is only matched if the zone id is tied to the given direction. +
+
+[verse]
+*ct* {state | direction | status | mark | expiration | helper | label | l3proto | protocol | bytes | packets | avgpkt | zone}
+*ct* {original | reply} {l3proto | protocol | proto-src | proto-dst | bytes | packets | avgpkt | zone}
+*ct* {original | reply} {ip | ip6} {saddr | daddr}
+
+.Conntrack expressions
+[options="header"]
+|==================
+|Keyword| Description | Type
+|state|
+State of the connection |
+ct_state
+|direction|
+Direction of the packet relative to the connection |
+ct_dir
+|status|
+Status of the connection |
+ct_status
+|mark|
+Connection mark |
+mark
+|expiration|
+Connection expiration time |
+time
+|helper|
+Helper associated with the connection|
+string
+|label|
+Connection tracking label bit or symbolic name defined in connlabel.conf in the nftables include path|
+ct_label
+|l3proto|
+Layer 3 protocol of the connection|
+nf_proto
+|saddr|
+Source address of the connection for the given direction |
+ipv4_addr/ipv6_addr
+|daddr|
+Destination address of the connection for the given direction |
+ipv4_addr/ipv6_addr
+|protocol|
+Layer 4 protocol of the connection for the given direction |
+inet_proto
+|proto-src|
+Layer 4 protocol source for the given direction|
+integer (16 bit)
+|proto-dst|
+Layer 4 protocol destination for the given direction |
+integer (16 bit)
+|packets|
+packet count seen in the given direction or sum of original and reply |
+integer (64 bit)
+|bytes|
+byte count seen, see description for *packets* keyword |
+integer (64 bit)
+|avgpkt|
+average bytes per packet, see description for packets keyword |
+integer (64 bit)
+|zone|
+conntrack zone |
+integer (64 bit)
+|==========================================
+A description of conntrack-specific types listed above can be found sub-section CONNTRACK TYPES above.
diff --git a/doc/primary-expression.txt b/doc/primary-expression.txt
new file mode 100644
index 00000000..162f32f4
--- /dev/null
+++ b/doc/primary-expression.txt
@@ -0,0 +1,226 @@
+META EXPRESSIONS
+~~~~~~~~~~~~~~~~
+[verse]
+meta {length | nfproto | l4proto | protocol | priority}
+[meta] {mark | iif | iifname | iiftype | oif | oifname | oiftype |
+skuid | skgid | nftrace | rtclassid | ibrname | obrname | pkttype | cpu
+| iifgroup | oifgroup | cgroup | random | secpath}
+
+A meta expression refers to meta data associated with a packet.
+
+There are two types of meta expressions: unqualified and qualified meta expressions. Qualified meta expressions require the meta keyword before the meta key, unqualified meta expressions can be specified by using the meta key directly or as qualified meta expressions. Meta l4proto is useful to match a particular transport protocol that is part of either an IPv4 or IPv6 packet. It will also skip any IPv6 extension headers present in an IPv6 packet.
+
+.Meta expression types
+[options="header"]
+|==================
+|Keyword | Description | Type
+|length|
+Length of the packet in bytes|
+integer (32 bit)
+|nfproto|
+real hook protocol family, useful only in inet table|
+integer (32 bit)
+|l4proto|
+layer 4 protocol, skips ipv6 extension headers|
+integer (32 bit)
+|protocol|
+EtherType protocol value|
+ether_type
+|priority|
+TC packet priority|
+tc_handle
+|mark|
+Packet mark |
+mark
+|iif|
+Input interface index |
+iface_index
+|iifname|
+Input interface name |
+ifname
+|iiftype|
+Input interface type|
+iface_itype
+|oif|
+Output interface index|
+iface_index
+|oifname|
+Output interface name|
+ifname
+|oiftype|
+Outout interface hardware type|
+iface_type
+|skuid|
+UID associated with originating socket|
+uid
+|skgid|
+GID associated with originating socket|
+gid
+|rtlclassid|
+Routing realm|
+realm
+|ibrname|
+Input bridge interface name|
+ifname
+|obrname|
+Output bridge interface name|
+ifname
+|pkttype|
+packet type|
+pkt_type
+|cpu|
+cpu number processing the packet|
+integer (32 bits)
+|iifgroup|
+incoming device group|
+devgroup
+|oifgroup|
+outgoing device group|
+devgroup
+|cgroup|
+control group id |
+integer (32 bit)
+|random|
+pseudo-random number|
+integer (32 bits)
+|secpath|
+boolean|
+boolean (1 bit)
+|====================
+
+.Meta expression specific types
+[options="header"]
+|==================
+|Type | Description
+|iface_index |
+Interface index (32 bit number). Can be specified numerically or as name of an existing interface.
+|ifname|
+Interface name (16 byte string). Does not have to exist.
+|iface_type|
+Interface type (16 bit number).
+|uid|
+User ID (32 bit number). Can be specified numerically or as user name.
+|gid|
+Group ID (32 bit number). Can be specified numerically or as group name.
+|realm|
+Routing Realm (32 bit number). Can be specified numerically or as symbolic name defined in /etc/iproute2/rt_realms.
+|devgroup_type|
+Device group (32 bit number). Can be specified numerically or as symbolic name defined in /etc/iproute2/group.
+|pkt_type|
+Packet type: Unicast (addressed to local host), Broadcast (to all), Multicast (to group).
+|=============================
+
+.Using meta expressions
+-----------------------
+# qualified meta expression
+filter output meta oif eth0
+
+# unqualified meta expression
+filter output oif eth0
+
+# packed was subject to ipsec processing
+raw prerouting meta secpath exists accept
+-----------------------
+
+SOCKET EXPRESSION
+~~~~~~~~~~~~~~~~~
+[verse]
+socket {transparent}
+
+Socket expression can be used to search for an existing open TCP/UDP socket and its attributes that can be associated with a packet. It looks for an established or non-zero bound listening socket (possibly with a non-local address).
+
+.Available socket attributes
+[options="header"]
+|==================
+|Name |Description| Type
+|transparent|
+Value of the IP_TRANSPARENT socket option in the found socket. It can be 0 or 1.|
+boolean (1 bit)
+|==================
+
+.Using socket expression
+------------------------
+# Mark packets that correspond to a transparent socket
+table inet x {
+ chain y {
+ type filter hook prerouting priority -150; policy accept;
+ socket transparent 1 mark set 0x00000001 accept
+ }
+}
+----------------------
+
+FIB EXPRESSIONS
+~~~~~~~~~~~~~~~
+[verse]
+fib {saddr | daddr | {mark | iif | oif}} {oif | oifname | type}
+
+A fib expression queries the fib (forwarding information base) to obtain information such as the output interface index a particular address would use. The input is a tuple of elements that is used as input to the fib lookup functions.
+
+.fib expression specific types
+[options="header"]
+|==================
+|Keyword| Description| Type
+|oif|
+Output interface index|
+integer (32 bit)
+|oifname|
+Output interface name|
+string
+|type|
+Address type |
+fib_addrtype
+|=======================
+
+.Using fib expressions
+----------------------
+# drop packets without a reverse path
+filter prerouting fib saddr . iif oif missing drop
+
+# drop packets to address not configured on ininterface
+filter prerouting fib daddr . iif type != { local, broadcast, multicast } drop
+
+# perform lookup in a specific 'blackhole' table (0xdead, needs ip appropriate ip rule)
+filter prerouting meta mark set 0xdead fib daddr . mark type vmap { blackhole : drop, prohibit : jump prohibited, unreachable : drop }
+----------------------
+
+ROUTING EXPRESSIONS
+~~~~~~~~~~~~~~~~~~~
+[verse]
+rt {classid | nexthop}
+
+A routing expression refers to routing data associated with a packet.
+
+.Routing expression types
+[options="header"]
+|=======================
+|Keyword| Description| Type
+|classid|
+Routing realm|
+realm
+|nexthop|
+Routing nexthop|
+ipv4_addr/ipv6_addr
+|mtu|
+TCP maximum segment size of route |
+integer (16 bit)
+|=================================
+
+.Routing expression specific types
+[options="header"]
+|=======================
+|Type| Description
+|realm|
+Routing Realm (32 bit number). Can be specified numerically or as symbolic name defined in /etc/iproute2/rt_realms.
+|========================
+
+.Using routing expressions
+--------------------------
+# IP family independent rt expression
+filter output rt classid 10
+
+# IP family dependent rt expressions
+ip filter output rt nexthop 192.168.0.1
+ip6 filter output rt nexthop fd00::1
+inet filter output rt ip nexthop 192.168.0.1
+inet filter output rt ip6 nexthop fd00::1
+--------------------------
diff --git a/doc/stateful-objects.txt b/doc/stateful-objects.txt
new file mode 100644
index 00000000..9d992647
--- /dev/null
+++ b/doc/stateful-objects.txt
@@ -0,0 +1,71 @@
+CT
+~~
+[verse]
+*ct* helper 'helper' {type 'type' protocol 'protocol' ; [l3proto 'family' ;] }
+
+Ct helper is used to define connection tracking helpers that can then be used in combination with the *ct helper set* statement. 'type' and 'protocol' are mandatory, l3proto is derived from the table family by default, i.e. in the inet table the kernel will try to load both the ipv4 and ipv6 helper backends, if they are supported by the kernel.
+
+.conntrack helper specifications
+[options="header"]
+|=================
+|Keyword | Description | Type
+| type |
+name of helper type |
+quoted string (e.g. "ftp")
+|protocol |
+layer 4 protocol of the helper |
+address family (e.g. ip)
+|l3proto |
+layer 3 protocol of the helper |
+address family (e.g. ip)
+|=================
+
+.defining and assigning ftp helper
+----------------------------------
+Unlike iptables, helper assignment needs to be performed after the conntrack lookup has completed, for example with the default 0 hook priority.
+
+table inet myhelpers {
+ ct helper ftp-standard {
+ type "ftp" protocol tcp
+ }
+ chain prerouting {
+ type filter hook prerouting priority 0;
+ tcp dport 21 ct helper set "ftp-standard"
+ }
+}
+----------------------------------
+
+COUNTER
+~~~~~~~
+[verse]
+*counter* [packets bytes]
+
+.Counter specifications
+[options="header"]
+|=================
+|Keyword | Description | Type
+|packets |
+initial count of packets |
+unsigned integer (64 bit)
+|bytes |
+initial count of bytes |
+unsigned integer (64 bit)
+|=================
+
+QUOTA
+~~~~~
+[verse]
+*quota* [over | until] [used]
+
+.Quota specifications
+[options="header"]
+|=================
+|Keyword | Description | Type
+|quota |
+quota limit, used as the quota name |
+Two arguments, unsigned interger (64 bit) and string: bytes, kbytes, mbytes.
+"over" and "until" go before these arguments
+|used |
+initial value of used quota |
+Two arguments, unsigned interger (64 bit) and string: bytes, kbytes, mbytes
+|=================
diff --git a/doc/statements.txt b/doc/statements.txt
new file mode 100644
index 00000000..499b573f
--- /dev/null
+++ b/doc/statements.txt
@@ -0,0 +1,425 @@
+VERDICT STATEMENT
+~~~~~~~~~~~~~~~~~
+The verdict statement alters control flow in the ruleset and issues policy decisions for packets.
+
+[verse]
+{accept | drop | queue | continue | return}
+{jump | goto} 'chain'
+
+[horizontal]
+*accept*:: Terminate ruleset evaluation and accept the packet.
+*drop*:: Terminate ruleset evaluation and drop the packet.
+*queue*:: Terminate ruleset evaluation and queue the packet to userspace.
+*continue*:: Continue ruleset evaluation with the next rule. FIXME
+*return*:: Return from the current chain and continue evaluation at the next rule in the last chain. If issued in a base chain, it is equivalent to *accept*.
+*jump* 'chain':: Continue evaluation at the first rule in 'chain'. The current position in the ruleset is pushed to a call stack and evaluation will continue there when the new chain is entirely evaluated of a *return* verdict is issued.
+*goto* 'chain':: Similar to *jump*, but the current position is not pushed to the call stack, meaning that after the new chain evaluation will continue at the last chain instead of the one containing the goto statement.
+
+.Verdict statements
+-------------------
+# process packets from eth0 and the internal network in from_lan
+# chain, drop all packets from eth0 with different source addresses.
+
+filter input iif eth0 ip saddr 192.168.0.0/24 jump from_lan
+filter input iif eth0 drop
+-------------------
+
+PAYLOAD STATEMENT
+~~~~~~~~~~~~~~~~~
+The payload statement alters packet content. It can be used for example to set ip DSCP (differv) header field or ipv6 flow labels.
+
+.route some packets instead of bridging
+---------------------------------------
+# redirect tcp:http from 192.160.0.0/16 to local machine for routing instead of bridging
+# assumes 00:11:22:33:44:55 is local MAC address.
+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
+-------------------------------------------
+
+.Set IPv4 DSCP header field
+---------------------------
+ip forward ip dscp set 42
+---------------------------
+
+EXTENSION HEADER STATEMENT
+~~~~~~~~~~~~~~~~~~~~~~~~~~
+The extension header statement alters packet content in variable-sized headers. This can currently be used to alter the TCP Maximum segment size of packets, similar to TCPMSS.
+
+.change tcp mss
+---------------
+tcp flags syn tcp option maxseg size set 1360
+# set a size based on route information:
+tcp flags syn tcp option maxseg size set rt mtu
+---------------
+
+LOG STATEMENT
+~~~~~~~~~~~~~
+[verse]
+log [prefix quoted_string] [level syslog-level] [flags log-flags]
+log group nflog_group [prefix quoted_string] [queue-threshold value] [snaplen size]
+
+The log statement enables logging of matching packets. When this statement is used from a rule, the Linux kernel will print some information on all matching packets, such as header fields, via the kernel log (where it can be read with dmesg(1) or read in the syslog). If the group number is specified, the Linux kernel will pass the packet to nfnetlink_log which will multicast the packet through a netlink socket to the specified multicast group. One or more userspace processes may subscribe to the group to receive the packets, see libnetfilter_queue documentation for details. This is a non-terminating statement, so the rule evaluation continues after the packet is logged.
+
+.log statement options
+[options="header"]
+|==================
+|Keyword | Description | Type
+|prefix|
+Log message prefix|
+quoted string
+|level|
+Syslog level of logging |
+string: emerg, alert, crit, err, warn [default], notice, info, debug
+|group|
+NFLOG group to sned messages to|
+unsigned integer (16 bit)
+|snaplen|
+Length of packet payload to include in netlink messages |
+unsigned integer (32 bit)
+|queue-threshold|
+Number of packets to queue inside the kernel before sending them to userpace |
+unsigned integer (32 bit)
+|==================================
+
+.log statement options
+[options="header"]
+|==================
+| Flag | Description
+|tcp sequence|
+Log TCP sequence numbers.
+|tcp options|
+Log options from the TCP packet header.
+|ip options|
+Log options from the IP/IPv6 packet header.
+|skuid|
+Log the userid of the process which generated the packet.
+|ether|
+Decode MAC addresses and protocol.
+|all|
+Enable all log flags listed above.
+|==============================
+
+.Using log statement
+--------------------
+# log the UID which generated the packet and ip options
+ip filter output log flags skuid flags ip options
+
+# log the tcp sequence numbers and tcp options from the TCP packet
+ip filter output log flags tcp sequence,options
+
+# enable all supported log flags
+ip6 filter output log flags all
+-----------------------
+
+REJECT STATEMENT
+~~~~~~~~~~~~~~~~
+[verse]
+*reject* [ with {icmp | icmpv6 | icmpx} type {icmp_code | icmpv6_code | icmpx_code} ]
+*reject* [ with tcp reset ]
+
+A reject statement is used to send back an error packet in response to the matched packet otherwise it is equivalent to drop so it is a terminating statement, ending rule traversal. This statement is only valid in the input, forward and output chains, and user-defined chains which are only called from those chains.
+
+.different ICMP reject variants are meant for use in different table families
+[options="header"]
+|==================
+|Variant |Family | Type
+|icmp|
+ip|
+icmp_code
+|icmpv6|
+ip6|
+icmpv6_code
+|icmpx|
+inet|
+icmpx_code
+|==================
+
+For a description of the different types and a list of supported keywords refer to DATA TYPES section above. The common default reject value is *port-unreachable*. +
+
+Note that in bridge family, reject statement is only allowed in base chains which hook into input or prerouting.
+
+COUNTER STATEMENT
+~~~~~~~~~~~~~~~~~
+A counter statement sets the hit count of packets along with the number of bytes.
+
+[verse]
+counter [ packets 'number' bytes 'number' ]
+
+CONNTRACK STATEMENT
+~~~~~~~~~~~~~~~~~~~
+The conntrack statement can be used to set the conntrack mark and conntrack labels.
+
+[verse]
+*ct* {mark | event | label | zone} set 'value'
+
+The ct statement sets meta data associated with a connection. The zone id has to be assigned before a conntrack lookup takes place, i.e. this has to be done in prerouting and possibly output (if locally generated packets need to be placed in a distinct zone), with a hook priority of -300.
+
+.Conntrack statement types
+[options="header"]
+|==================
+|Keyword| Description| Value
+|event|
+conntrack event bits |
+bitmask, integer (32 bit)
+|helper|
+name of ct helper object to assign to the connection |
+quoted string
+|mark|
+Connection tracking mark |
+mark
+|label|
+Connection tracking label|
+label
+|zone|
+conntrack zone|
+integer (16 bit)
+|==================
+
+.save packet nfmark in conntrack
+--------------------------------
+ct mark set meta mark
+--------------------------------
+
+.set zone mapped via interface
+------------------------------
+table inet raw {
+ chain prerouting {
+ type filter hook prerouting priority -300;
+ ct zone set iif map { "eth1" : 1, "veth1" : 2 }
+ }
+ chain output {
+ type filter hook output priority -300;
+ ct zone set oif map { "eth1" : 1, "veth1" : 2 }
+ }
+}
+------------------------------------------------------
+
+.restrict events reported by ctnetlink
+--------------------------------------
+ct event set new,related,destroy
+--------------------------------------
+
+META STATEMENT
+~~~~~~~~~~~~~~
+A meta statement sets the value of a meta expression. The existing meta fields are: priority, mark, pkttype, nftrace. +
+
+meta {mark | priority | pkttype | nftrace} set 'value' +
+
+A meta statement sets meta data associated with a packet. +
+
+.Meta statement types
+[options="header"]
+|==================
+|Keyword| Description| Value
+|priority |
+TC packet priority|
+tc_handle
+|mark|
+Packet mark |
+mark
+|pkttype |
+packet type |
+pkt_type
+|nftrace |
+ruleset packet tracing on/off. Use monitor trace command to watch traces|
+0, 1
+|==========================
+
+LIMIT STATEMENT
+~~~~~~~~~~~~~~~
+[verse]
+*limit* rate [over] 'packet_number' / {second | minute | hour | day} [burst 'packet_number' packets]
+*limit* rate [over] 'byte_number' {bytes | kbytes | mbytes} / {second | minute | hour | day | week} [burst 'byte_number' bytes]
+
+A limit statement matches at a limited rate using a token bucket filter. A rule using this statement will match until this limit is reached. It can be used in combination with the log statement to give limited logging. The over keyword, that is optional, makes it match over the specified rate.
+
+.limit statement values
+[options="header"]
+|==================
+|Value | Description | Type|
+|packet_number |
+Number of packets |
+unsigned integer (32 bit)
+|byte_number |
+Number of bytes |
+unsigned integer (32 bit)
+|========================
+
+NAT STATEMENTS
+~~~~~~~~~~~~~~
+[verse]
+*snat* to address [:port] [persistent, random, fully-random]
+*snat* to address - address [:port - port] [persistent, random, fully-random]
+*dnat* to address [:port] [persistent, random, fully-random]
+*dnat* to address [:port - port] [persistent, random, fully-random]
+*masquerade* to [:port] [persistent, random, fully-random]
+*masquerade* to [:port - port] [persistent, random, fully-random]
+*redirect* to [:port] [persistent, random, fully-random]
+*redirect* to [:port - port] [persistent, random, fully-random]
+
+The nat statements are only valid from nat chain types. +
+
+The *snat* and *masquerade* statements specify that the source address of the packet should be modified. While *snat* is only valid in the postrouting and input chains, *masquerade* makes sense only in postrouting. The dnat and redirect statements are only valid in the prerouting and output chains, they specify that the destination address of the packet should be modified. You can use nonbase chains which are called from base chains of nat chain type too. All future packets in this connection will also be mangled, and rules should cease being examined.
+
+The *masquerade* statement is a special form of snat which always uses the outgoing interface's IP address to translate to. It is particularly useful on gateways with dynamic (public) IP addresses.
+
+The *redirect* statement is a special form of dnat which always translates the destination address to the local host's one. It comes in handy if one only wants to alter the destination port of incoming traffic on different interfaces.
+
+Note that all nat statements require both prerouting and postrouting base chains to be present since otherwise packets on the return path won't be seen by netfilter and therefore no reverse translation will take place.
+
+.NAT statement values
+[options="header"]
+|==================
+|Expression| Description| Type
+|address|
+Specifies that the source/destination address of the packet should be modified. You may specify a mapping to relate a list of tuples composed of arbitrary expression key with address value. |
+ipv4_addr, ipv6_addr, e.g. abcd::1234, or you can use a mapping, e.g. meta mark map { 10 : 192.168.1.2, 20 : 192.168.1.3 }
+|port|
+Specifies that the source/destination address of the packet should be modified. |
+port number (16 bits)
+|===============================
+
+.NAT statement flags
+[options="header"]
+|==================
+|Flag| Description
+|persistent |
+Gives a client the same source-/destination-address for each connection.
+|random|
+If used then port mapping will be randomized using a random seeded MD5 hash mix using source and destination address and destination port.
+|fully-random|
+If used then port mapping is generated based on a 32-bit pseudo-random algorithm.
+|=============================
+
+.Using NAT statements
+---------------------
+# create a suitable table/chain setup for all further examples
+add table nat
+add chain nat prerouting { type nat hook prerouting priority 0; }
+add chain nat postrouting { type nat hook postrouting priority 100; }
+
+# translate source addresses of all packets leaving via eth0 to address 1.2.3.4
+add rule nat postrouting oif eth0 snat to 1.2.3.4
+
+# redirect all traffic entering via eth0 to destination address 192.168.1.120
+add rule nat prerouting iif eth0 dnat to 192.168.1.120
+
+# translate source addresses of all packets leaving via eth0 to whatever
+# locally generated packets would use as source to reach the same destination
+add rule nat postrouting oif eth0 masquerade
+
+# redirect incoming TCP traffic for port 22 to port 2222
+add rule nat prerouting tcp dport 22 redirect to :2222
+------------------------
+
+FLOW OFFLOAD STATEMENT
+~~~~~~~~~~~~~~~~~~~~~~
+A flow offload statement allows us to select what flows you want to accelerate forwarding through layer 3 network stack bypass.
+You have to specify the flowtable name where you want to offload this flow.
+
+*flow offload* @flowtable
+
+QUEUE STATEMENT
+~~~~~~~~~~~~~~~
+This statement passes the packet to userspace using the nfnetlink_queue handler. The packet is put into the queue identified by its 16-bit queue number. Userspace can inspect and modify the packet if desired. Userspace must then drop or re-inject the packet into the kernel. See libnetfilter_queue documentation for details.
+
+[verse]
+*queue* [num 'queue_number'] [bypass]
+*queue* [num 'queue_number_from' - 'queue_number_to'] [bypass,fanout]
+
+.queue statement values
+[options="header"]
+|==================
+|Value | Description | Type
+|queue_number |
+Sets queue number, default is 0. |
+unsigned integer (16 bit)
+|queue_number_from |
+Sets initial queue in the range, if fanout is used. |
+unsigned integer (16 bit)
+|queue_number_to |
+Sets closing queue in the range, if fanout is used. |
+unsigned integer (16 bit)
+|=====================
+
+.queue statement flags
+[options="header"]
+|==================
+|Flag | Description
+|bypass |
+Let packets go through if userspace application cannot back off. Before using this flag, read libnetfilter_queue documentation for performance tuning recommendations.
+|fanout |
+Distribute packets between several queues.
+|===============================
+
+DUP STATEMENT
+~~~~~~~~~~~~~
+The dup statement is used to duplicate a packet and send the copy to a different destination.
+
+[verse]
+*dup* to 'device'
+*dup* to 'address' device '*device*'
+
+.Dup statement values
+[options="header"]
+|==================
+|Expression | Description | Type
+|address |
+Specifies that the copy of the packet should be sent to a new gateway.|
+ipv4_addr, ipv6_addr, e.g. abcd::1234, or you can use a mapping. e.g. ip saddr map { 192.168.1.2 : 10.1.1.1 }
+|device |
+Specifies that the copy should be transmitted via device. |
+string
+|===================
+
+
+.Using the dup statement
+------------------------
+# send to machine with ip address 10.2.3.4 on eth0
+ip filter forward dup to 10.2.3.4 device "eth0"
+
+# copy raw frame to another interface
+netdetv ingress dup to "eth0"
+dup to "eth0"
+
+# combine with map dst addr to gateways
+dup to ip daddr map { 192.168.7.1 : "eth0", 192.168.7.2 : "eth1" }
+-----------------------------------
+
+FWD STATEMENT
+~~~~~~~~~~~~~
+The fwd statement is used to redirect a raw packet to another interface. It is only available in the netdev family ingress hook.
+It is similar to the dup statement except that no copy is made.
+
+*fwd* to 'device'
+
+SET STATEMENT
+~~~~~~~~~~~~~
+The set statement is used to dynamically add or update elements in a set from the packet path. The set setname must already exist in the given table and must have been created with the dynamic flag. Furthermore, these sets must specify both a maximum set size (to prevent memory exhaustion) and a timeout (so that number of entries in set will not grow indefinitely). The set statement can be used to e.g. create dynamic blacklists.
+
+[verse]
+{add | update} '@setname' { 'expression' [timeout 'timeout'] [comment 'string'] }
+
+.Example for simple blacklist
+-----------------------------
+# declare a set, bound to table "filter", in family "ip". Timeout and size are mandatory because we will add elements from packet path.
+nft add set ip filter blackhole "{ type ipv4_addr; flags timeout; size 65536; }"
+
+# whitelist internal interface.
+nft add rule ip filter input meta iifname "internal" accept
+
+# drop packets coming from blacklisted ip addresses.
+nft add rule ip filter input ip saddr @blackhole counter drop
+
+# add source ip addresses to the blacklist if more than 10 tcp connection requests occurred per second and ip address.
+# entries will timeout after one minute, after which they might be re-added if limit condition persists.
+nft add rule ip filter input tcp flags syn tcp dport ssh meter flood size 128000 { ip saddr timeout 10s limit rate over 10/second} add @blackhole { ip saddr timeout 1m } drop
+
+# inspect state of the rate limit meter:
+nft list meter ip filter flood
+
+# inspect content of blackhole:
+nft list set ip filter blackhole
+
+# manually add two addresses to the set:
+nft add element filter blackhole { 10.2.3.4, 10.23.1.42 }
+-----------------------------------------------