# phpman > man > libnftables-json(5)

[LIBNFTABLES-JSON(5)](https://www.chedong.com/phpMan.php/man/LIBNFTABLES-JSON/5/markdown)                                                              [LIBNFTABLES-JSON(5)](https://www.chedong.com/phpMan.php/man/LIBNFTABLES-JSON/5/markdown)



## NAME
       libnftables-json - Supported JSON schema by libnftables

## SYNOPSIS
       **{** **"nftables":** **[** _OBJECTS_ **]** **}**

       _OBJECTS_ := _LIST_OBJECTS_ | _CMD_OBJECTS_

       _LIST_OBJECTS_ := _LIST_OBJECT_ [ **,** _LIST_OBJECTS_ ]

       _CMD_OBJECTS_ := _CMD_OBJECT_ [ **,** _CMD_OBJECTS_ ]

       _CMD_OBJECT_ := **{** _CMD_**:** _LIST_OBJECT_ **}** | _METAINFO_OBJECT_

       _CMD_ := **"add"** | **"replace"** | **"create"** | **"insert"** | **"delete"** | **"list"** | **"reset"** | **"flush"** |
### "rename"

       _LIST_OBJECT_ := _TABLE_ | _CHAIN_ | _RULE_ | _SET_ | _MAP_ | _ELEMENT_ | _FLOWTABLE_ | _COUNTER_ | _QUOTA_ |
       _CT_HELPER_ | _LIMIT_ | _METAINFO_OBJECT_ | _CT_TIMEOUT_ | _CT_EXPECTATION_

## DESCRIPTION
       libnftables supports JSON formatted input and output. This is implemented as an alternative
       frontend to the standard CLI syntax parser, therefore basic behaviour is identical and, for
       (almost) any operation available in standard syntax, there should be an equivalent one in
       JSON.

       JSON input may be provided in a single string as parameter to **nft**___**run**___**cmd**___**from**___**buffer()** or in
       a file identified by the _filename_ parameter of the **nft**___**run**___**cmd**___**from**___**filename()** function.

       JSON output has to be enabled via the **nft**___**ctx**___**output**___**set**___**json()** function, turning library
       standard output into JSON format. Error output remains unaffected.

## GLOBAL STRUCTURE
       In general, any JSON input or output is enclosed in an object with a single property named
       _nftables_. Its value is an array containing commands (for input) or ruleset elements (for
       output).

       A command is an object with a single property whose name identifies the command. Its value is
       a ruleset element - basically identical to output elements, apart from certain properties
       which may be interpreted differently or are required when output generally omits them.

## METAINFO OBJECT
       In output, the first object in an **nftables** array is a special one containing library
       information. Its content is as follows:

           **{** **"metainfo":** **{**
                   **"version":** _STRING_**,**
                   **"release**___**name":** _STRING_**,**
                   **"json**___**schema**___**version":** _NUMBER_
           **}}**

       The values of **version** and **release**___**name** properties are equal to the package version and
       release name as printed by **nft** **-v**. The value of the **json**___**schema**___**version** property is an
       integer indicating the schema version.

       If supplied in library input, the parser will verify the **json**___**schema**___**version** value to not
       exceed the internally hardcoded one (to make sure the given schema is fully understood). In
       future, a lower number than the internal one may activate compatibility mode to parse
       outdated and incompatible JSON input.

## COMMAND OBJECTS
       The structure accepts an arbitrary amount of commands which are interpreted in order of
       appearance. For instance, the following standard syntax input:

           flush ruleset
           add table inet mytable
           add chain inet mytable mychain
           add rule inet mytable mychain tcp dport 22 accept

       translates into JSON as such:

           { "nftables": [
                   { "flush": { "ruleset": null }},
                   { "add": { "table": {
                                   "family": "inet",
                                   "name": "mytable"
                   }}},
                   { "add": { "chain": {
                                   "family": "inet",
                                   "table": "mytable",
                                   "name": "mychain"
                   }}},
                   { "add": { "rule": {
                                   "family": "inet",
                                   "table": "mytable",
                                   "chain": "mychain",
                                   "expr": [
                                           { "match": {
                                                   "op": "==",
                                                   "left": { "payload": {
                                                                   "protocol": "tcp",
                                                                   "field": "dport"
                                                   }},
                                                   "right": 22
                                           }},
                                           { "accept": null }
                                   ]
                   }}}
           ]}

   **ADD**
           **{** **"add":** _ADD_OBJECT_ **}**

           _ADD_OBJECT_ := _TABLE_ | _CHAIN_ | _RULE_ | _SET_ | _MAP_ | _ELEMENT_ |
                           _FLOWTABLE_ | _COUNTER_ | _QUOTA_ | _CT_HELPER_ | _LIMIT_ |
                           _CT_TIMEOUT_ | _CT_EXPECTATION_

       Add a new ruleset element to the kernel.

   **REPLACE**
           **{** **"replace":** _RULE_ **}**

       Replace a rule. In _RULE_, the **handle** property is mandatory and identifies the rule to be
       replaced.

   **CREATE**
           **{** **"create":** _ADD_OBJECT_ **}**

       Identical to **add** command, but returns an error if the object already exists.

   **INSERT**
           **{** **"insert":** _RULE_ **}**

       This command is identical to **add** for rules, but instead of appending the rule to the chain by
       default, it inserts at first position. If a **handle** or **index** property is given, the rule is
       inserted before the rule identified by those properties.

   **DELETE**
           **{** **"delete":** _ADD_OBJECT_ **}**

       Delete an object from the ruleset. Only the minimal number of properties required to uniquely
       identify an object is generally needed in _ADD_OBJECT_. For most ruleset elements, this is
       **family** and **table** plus either **handle** or **name** (except rules since they don’t have a name).

   **LIST**
           **{** **"list":** _LIST_OBJECT_ **}**

           _LIST_OBJECT_ := _TABLE_ | _TABLES_ | _CHAIN_ | _CHAINS_ | _SET_ | _SETS_ |
                            _MAP_ | _MAPS_ _|_ _COUNTER_ | _COUNTERS_ | _QUOTA_ | _QUOTAS_ |
                            _CT_HELPER_ | _CT_HELPERS_ | _LIMIT_ | _LIMITS_ | _RULESET_ |
                            _METER_ | _METERS_ | _FLOWTABLE_ | _FLOWTABLES_ |
                            _CT_TIMEOUT_ | _CT_EXPECTATION_

       List ruleset elements. The plural forms are used to list all objects of that kind, optionally
       filtered by **family** and for some, also **table**.

   **RESET**
           **{** **"reset":** _RESET_OBJECT_ **}**

           _RESET_OBJECT_ := _COUNTER_ | _COUNTERS_ | _QUOTA_ | _QUOTAS_

       Reset state in suitable objects, i.e. zero their internal counter.

   **FLUSH**
           **{** **"flush":** _FLUSH_OBJECT_ **}**

           _FLUSH_OBJECT_ := _TABLE_ | _CHAIN_ | _SET_ | _MAP_ | _METER_ | _RULESET_

       Empty contents in given object, e.g. remove all chains from given **table** or remove all
       elements from given **set**.

   **RENAME**
           **{** **"rename":** _CHAIN_ **}**

       Rename a chain. The new name is expected in a dedicated property named **newname**.

## RULESET ELEMENTS
   **TABLE**
           **{** **"table":** **{**
                   **"family":** _STRING_**,**
                   **"name":** _STRING_**,**
                   **"handle":** _NUMBER_
           **}}**

       This object describes a table.

### family
           The table’s family, e.g.  **"ip"** or **"ip6"**.

### name
           The table’s name.

### handle
           The table’s handle. In input, it is used only in **delete** command as alternative to **name**.

   **CHAIN**
           **{** **"chain":** **{**
                   **"family":** _STRING_**,**
                   **"table":** _STRING_**,**
                   **"name":** _STRING_**,**
                   **"newname":** _STRING_**,**
                   **"handle":** _NUMBER_**,**
                   **"type":** _STRING_**,**
                   **"hook":** _STRING_**,**
                   **"prio":** _NUMBER_**,**
                   **"dev":** _STRING_**,**
                   **"policy":** _STRING_
           **}}**

       This object describes a chain.

### family
           The table’s family.

### table
           The table’s name.

### name
           The chain’s name.

### handle
           The chain’s handle. In input, it is used only in **delete** command as alternative to **name**.

### newname
           A new name for the chain, only relevant in the **rename** command.

       The following properties are required for base chains:

### type
           The chain’s type.

### hook
           The chain’s hook.

### prio
           The chain’s priority.

### dev
           The chain’s bound interface (if in the netdev family).

### policy
           The chain’s policy.

   **RULE**
           **{** **"rule":** **{**
                   **"family":** _STRING_**,**
                   **"table":** _STRING_**,**
                   **"chain":** _STRING_**,**
                   **"expr":** **[** _STATEMENTS_ **],**
                   **"handle":** _NUMBER_**,**
                   **"index":** _NUMBER_**,**
                   **"comment":** _STRING_
           **}}**

           _STATEMENTS_ := _STATEMENT_ [**,** _STATEMENTS_ ]

       This object describes a rule. Basic building blocks of rules are statements. Each rule
       consists of at least one.

### family
           The table’s family.

### table
           The table’s name.

### chain
           The chain’s name.

### expr
           An array of statements this rule consists of. In input, it is used in **add**/**insert**/**replace**
           commands only.

### handle
           The rule’s handle. In **delete**/**replace** commands, it serves as an identifier of the rule to
           delete/replace. In **add**/**insert** commands, it serves as an identifier of an existing rule to
           append/prepend the rule to.

### index
           The rule’s position for **add**/**insert** commands. It is used as an alternative to **handle** then.

### comment
           Optional rule comment.

   **SET** **/** **MAP**
           **{** **"set":** **{**
                   **"family":** _STRING_**,**
                   **"table":** _STRING_**,**
                   **"name":** _STRING_**,**
                   **"handle":** _NUMBER_**,**
                   **"type":** _SET_TYPE_**,**
                   **"policy":** _SET_POLICY_**,**
                   **"flags":** **[** _SET_FLAG_LIST_ **],**
                   **"elem":** _SET_ELEMENTS_**,**
                   **"timeout":** _NUMBER_**,**
                   **"gc-interval":** _NUMBER_**,**
                   **"size":** _NUMBER_
           **}}**

           **{** **"map":** **{**
                   **"family":** _STRING_**,**
                   **"table":** _STRING_**,**
                   **"name":** _STRING_**,**
                   **"handle":** _NUMBER_**,**
                   **"type":** _SET_TYPE_**,**
                   **"map":** _STRING_**,**
                   **"policy":** _SET_POLICY_**,**
                   **"flags":** **[** _SET_FLAG_LIST_ **],**
                   **"elem":** _SET_ELEMENTS_**,**
                   **"timeout":** _NUMBER_**,**
                   **"gc-interval":** _NUMBER_**,**
                   **"size":** _NUMBER_
           **}}**

           _SET_TYPE_ := _STRING_ | **[** _SET_TYPE_LIST_ **]**
           _SET_TYPE_LIST_ := _STRING_ [**,** _SET_TYPE_LIST_ ]
           _SET_POLICY_ := **"performance"** | **"memory"**
           _SET_FLAG_LIST_ := _SET_FLAG_ [**,** _SET_FLAG_LIST_ ]
           _SET_FLAG_ := **"constant"** | **"interval"** | **"timeout"**
           _SET_ELEMENTS_ := _EXPRESSION_ | **[** _EXPRESSION_LIST_ **]**
           _EXPRESSION_LIST_ := _EXPRESSION_ [**,** _EXPRESSION_LIST_ ]

       These objects describe a named set or map. Maps are a special form of sets in that they
       translate a unique key to a value.

### family
           The table’s family.

### table
           The table’s name.

### name
           The set’s name.

### handle
           The set’s handle. For input, it is used in the **delete** command only.

### type
           The set’s datatype, see below.

### map
           Type of values this set maps to (i.e. this set is a map).

### policy
           The set’s policy.

### flags
           The set’s flags.

### elem
           Initial set element(s), see below.

### timeout
           Element timeout in seconds.

### gc-interval
           Garbage collector interval in seconds.

### size
           Maximum number of elements supported.

       **TYPE**
           The set type might be a string, such as **"ipv4**___**addr"** or an array consisting of strings
           (for concatenated types).

       **ELEM**
           A single set element might be given as string, integer or boolean value for simple cases.
           If additional properties are required, a formal **elem** object may be used.

           Multiple elements may be given in an array.

   **ELEMENT**
           **{** **"element":** **{**
                   **"family":** _STRING_**,**
                   **"table":** _STRING_**,**
                   **"name":** _STRING_**,**
                   **"elem":** _SET_ELEM_
           **}}**

           _SET_ELEM_ := _EXPRESSION_ | **[** _EXPRESSION_LIST_ **]**
           _EXPRESSION_LIST_ := _EXPRESSION_ [**,** _EXPRESSION_ ]

       Manipulate element(s) in a named set.

### family
           The table’s family.

### table
           The table’s name.

### name
           The set’s name.

### elem
           See elem property of set object.

   **FLOWTABLE**
           **{** **"flowtable":** **{**
                   **"family":** _STRING_**,**
                   **"table":** _STRING_**,**
                   **"name":** _STRING_**,**
                   **"handle":** _NUMBER_**,**
                   **"hook":** _STRING_**,**
                   **"prio":** _NUMBER_**,**
                   **"dev":** _FT_INTERFACE_
           **}}**

           _FT_INTERFACE_ := _STRING_ | **[** _FT_INTERFACE_LIST_ **]**
           _FT_INTERFACE_LIST_ := _STRING_ [**,** _STRING_ ]

       This object represents a named flowtable.

### family
           The table’s family.

### table
           The table’s name.

### name
           The flow table’s name.

### handle
           The flow table’s handle. In input, it is used by the **delete** command only.

### hook
           The flow table’s hook.

### prio
           The flow table’s priority.

### dev
           The flow table’s interface(s).

   **COUNTER**
           **{** **"counter":** **{**
                   **"family":** _STRING_**,**
                   **"table":** _STRING_**,**
                   **"name":** _STRING_**,**
                   **"handle":** _NUMBER_**,**
                   **"packets":** _NUMBER_**,**
                   **"bytes":** _NUMBER_
           **}}**

       This object represents a named counter.

### family
           The table’s family.

### table
           The table’s name.

### name
           The counter’s name.

### handle
           The counter’s handle. In input, it is used by the **delete** command only.

### packets
           Packet counter value.

### bytes
           Byte counter value.

   **QUOTA**
           **{** **"quota":** **{**
                   **"family":** _STRING_**,**
                   **"table":** _STRING_**,**
                   **"name":** _STRING_**,**
                   **"handle":** _NUMBER_**,**
                   **"bytes":** _NUMBER_**,**
                   **"used":** _NUMBER_**,**
                   **"inv":** _BOOLEAN_
           **}}**

       This object represents a named quota.

### family
           The table’s family.

### table
           The table’s name.

### name
           The quota’s name.

### handle
           The quota’s handle. In input, it is used by the **delete** command only.

### bytes
           Quota threshold.

### used
           Quota used so far.

### inv
           If true, match if the quota has been exceeded.

   **CT** **HELPER**
           **{** **"ct** **helper":** **{**
                   **"family":** _STRING_**,**
                   **"table":** _STRING_**,**
                   **"name":** _STRING_**,**
                   **"handle":** _..._ _'_**,**
                   **"type":** _'STRING_**,**
                   **"protocol":** _CTH_PROTO_**,**
                   **"l3proto":** _STRING_
           **}}**

           _CTH_PROTO_ := **"tcp"** | **"udp"**

       This object represents a named conntrack helper.

### family
           The table’s family.

### table
           The table’s name.

### name
           The ct helper’s name.

### handle
           The ct helper’s handle. In input, it is used by the **delete** command only.

### type
           The ct helper type name, e.g.  **"ftp"** or **"tftp"**.

### protocol
           The ct helper’s layer 4 protocol.

### l3proto
           The ct helper’s layer 3 protocol, e.g.  **"ip"** or **"ip6"**.

   **LIMIT**
           **{** **"limit":** **{**
                   **"family":** _STRING_**,**
                   **"table":** _STRING_**,**
                   **"name":** _STRING_**,**
                   **"handle":** _NUMBER_**,**
                   **"rate":** _NUMBER_**,**
                   **"per":** _STRING_**,**
                   **"burst":** _NUMBER_**,**
                   **"unit":** _LIMIT_UNIT_**,**
                   **"inv":** _BOOLEAN_
           **}}**

           _LIMIT_UNIT_ := **"packets"** | **"bytes"**

       This object represents a named limit.

### family
           The table’s family.

### table
           The table’s name.

### name
           The limit’s name.

### handle
           The limit’s handle. In input, it is used by the **delete** command only.

### rate
           The limit’s rate value.

### per
           Time unit to apply the limit to, e.g.  **"week"**, **"day"**, **"hour"**, etc. If omitted, defaults
           to **"second"**.

### burst
           The limit’s burst value. If omitted, defaults to **0**.

### unit
           Unit of rate and burst values. If omitted, defaults to **"packets"**.

### inv
           If true, match if limit was exceeded. If omitted, defaults to **false**.

   **CT** **TIMEOUT**
           **{** **"ct** **timeout":** **{**
                   **"family":** _STRING_**,**
                   **"table":** _STRING_**,**
                   **"name":** _STRING_**,**
                   **"handle":** _NUMBER_**,**
                   **"protocol":** _CTH_PROTO_**,**
                   **"state":** _STRING_**,**
                   **"value:** _NUMBER_**,**
                   **"l3proto":** _STRING_
           **}}**

           _CTH_PROTO_ := **"tcp"** | **"udp"** | **"dccp"** | **"sctp"** | **"gre"** | **"icmpv6"** | **"icmp"** | **"generic"**

       This object represents a named conntrack timeout policy.

### family
           The table’s family.

### table
           The table’s name.

### name
           The ct timeout object’s name.

### handle
           The ct timeout object’s handle. In input, it is used by **delete** command only.

### protocol
           The ct timeout object’s layer 4 protocol.

### state
           The connection state name, e.g.  **"established"**, **"syn**___**sent"**, **"close"** or **"close**___**wait"**, for
           which the timeout value has to be updated.

### value
           The updated timeout value for the specified connection state.

### l3proto
           The ct timeout object’s layer 3 protocol, e.g.  **"ip"** or **"ip6"**.

   **CT** **EXPECTATION**
           **{** **"ct** **expectation":** **{**
                   **"family":** _STRING_**,**
                   **"table":** _STRING_**,**
                   **"name":** _STRING_**,**
                   **"handle":** _NUMBER_**,**
                   **"l3proto":** _STRING_
                   "protocol":* _CTH_PROTO_**,**
                   **"dport":** _NUMBER_**,**
                   **"timeout:** _NUMBER_**,**
                   **"size:** _NUMBER_**,**
           ***}}**

           _CTH_PROTO_ := **"tcp"** | **"udp"** | **"dccp"** | **"sctp"** | **"gre"** | **"icmpv6"** | **"icmp"** | **"generic"**

       This object represents a named conntrack expectation.

### family
           The table’s family.

### table
           The table’s name.

### name
           The ct expectation object’s name.

### handle
           The ct expectation object’s handle. In input, it is used by **delete** command only.

### l3proto
           The ct expectation object’s layer 3 protocol, e.g.  **"ip"** or **"ip6"**.

### protocol
           The ct expectation object’s layer 4 protocol.

### dport
           The destination port of the expected connection.

### timeout
           The time in millisecond that this expectation will live.

### size
           The maximum count of expectations to be living in the same time.

## STATEMENTS
       Statements are the building blocks for rules. Each rule consists of at least one.

   **VERDICT**
           **{** **"accept":** **null** **}**
           **{** **"drop":** **null** **}**
           **{** **"continue":** **null** **}**
           **{** **"return":** **null** **}**
           **{** **"jump":** **{** **"target":** ***** _STRING_ ***}}**
           **{** **"goto":** **{** **"target":** ***** _STRING_ ***}}**

       A verdict either terminates packet traversal through the current chain or delegates to a
       different one.

       **jump** and **goto** statements expect a target chain name.

   **MATCH**
           **{** **"match":** **{**
                   **"left":** _EXPRESSION_**,**
                   **"right":** _EXPRESSION_**,**
                   **"op":** _STRING_
           **}}**

       This matches the expression on left hand side (typically a packet header or packet meta info)
       with the expression on right hand side (typically a constant value). If the statement
       evaluates to true, the next statement in this rule is considered. If not, processing
       continues with the next rule in the same chain.

### left
           Left hand side of this match.

### right
           Right hand side of this match.

       **op**
           Operator indicating the type of comparison.

       **OPERATORS**
           **&**    Binary AND

           **|**    Binary OR

           **^**    Binary XOR

           **<<**   Left shift

           **>>**   Right shift

           **==**   Equal

           **!=**   Not equal

           **<**    Less than

           **>**    Greater than

           ⇐⇐    Less than or equal to

           **>=**   Greater than or equal to

           **in**   Perform a lookup, i.e. test if
                bits on RHS are contained in LHS
                value


           Unlike with the standard API, the operator is mandatory here. In the standard API, a
           missing operator may be resolved in two ways, depending on the type of expression on the
           RHS:

           •   If the RHS is a bitmask or a list of bitmasks, the expression resolves into a binary
               operation with the inequality operator, like this: _LHS_ _&_ _RHS_ _!=_ _0_.

           •   In any other case, the equality operator is simply inserted.

           For the non-trivial first case, the JSON API supports the **in** operator.

   **COUNTER**
           **{** **"counter":** **{**
                   **"packets":** _NUMBER_**,**
                   **"bytes":** _NUMBER_
           **}}**

           **{** **"counter":** _STRING_ **}**

       This object represents a byte/packet counter. In input, no properties are required. If given,
       they act as initial values for the counter.

       The first form creates an anonymous counter which lives in the rule it appears in. The second
       form specifies a reference to a named counter object.

### packets
           Packets counted.

### bytes
           Bytes counted.

   **MANGLE**
           **{** **"mangle":** **{**
                   **"key":** _EXPRESSION_**,**
                   **"value":** _EXPRESSION_
           **}}**

       This changes the packet data or meta info.

### key
           The packet data to be changed, given as an **exthdr**, **payload**, **meta**, **ct** or **ct** **helper**
           expression.

### value
           Value to change data to.

   **QUOTA**
           **{** **"quota":** **{**
                   **"val":** _NUMBER_**,**
                   **"val**___**unit":** _STRING_**,**
                   **"used":** _NUMBER_**,**
                   **"used**___**unit":** _STRING_**,**
                   **"inv":** _BOOLEAN_
           **}}**

           **{** **"quota":** _STRING_ **}**

       The first form creates an anonymous quota which lives in the rule it appears in. The second
       form specifies a reference to a named quota object.

### val
           Quota value.

       **val**___**unit**
           Unit of **val**, e.g.  **"kbytes"** or **"mbytes"**. If omitted, defaults to **"bytes"**.

### used
           Quota used so far. Optional on input. If given, serves as initial value.

       **used**___**unit**
           Unit of **used**. Defaults to **"bytes"**.

### inv
           If **true**, will match if quota was exceeded. Defaults to **false**.

   **LIMIT**
           **{** **"limit":** **{**
                   **"rate":** _NUMBER_**,**
                   **"rate**___**unit":** _STRING_**,**
                   **"per":** _STRING_**,**
                   **"burst":** _NUMBER_**,**
                   **"burst**___**unit":** _STRING_**,**
                   **"inv":** _BOOLEAN_
           **}}**

           **{** **"limit":** _STRING_ **}**

       The first form creates an anonymous limit which lives in the rule it appears in. The second
       form specifies a reference to a named limit object.

### rate
           Rate value to limit to.

       **rate**___**unit**
           Unit of **rate**, e.g.  **"packets"** or **"mbytes"**. Defaults to **"packets"**.

### per
           Denominator of **rate**, e.g.  **"week"** or **"minutes"**.

### burst
           Burst value. Defaults to **0**.

       **burst**___**unit**
           Unit of **burst**, ignored if **rate**___**unit** is **"packets"**. Defaults to **"bytes"**.

### inv
           If **true**, matches if the limit was exceeded. Defaults to **false**.

   **FWD**
           **{** **"fwd":** **{**
                   **"dev":** _EXPRESSION_**,**
                   **"family":** _FWD_FAMILY_**,**
                   **"addr":** _EXPRESSION_
           **}}**

           _FWD_FAMILY_ := **"ip"** | **"ip6"**

       Forward a packet to a different destination.

### dev
           Interface to forward the packet on.

### family
           Family of **addr**.

### addr
           IP(v6) address to forward the packet to.

       Both **family** and **addr** are optional, but if at least one is given, both must be present.

   **NOTRACK**
           **{** **"notrack":** **null** **}**

       Disable connection tracking for the packet.

   **DUP**
           **{** **"dup":** **{**
                   **"addr":** _EXPRESSION_**,**
                   **"dev":** _EXPRESSION_
           **}}**

       Duplicate a packet to a different destination.

### addr
           Address to duplicate packet to.

### dev
           Interface to duplicate packet on. May be omitted to not specify an interface explicitly.

   **NETWORK** **ADDRESS** **TRANSLATION**
           **{** **"snat":** **{**
                   **"addr":** _EXPRESSION_**,**
                   **"family":** _STRING_**,**
                   **"port":** _EXPRESSION_**,**
                   **"flags":** _FLAGS_
           **}}**

           **{** **"dnat":** **{**
                   **"addr":** _EXPRESSION_**,**
                   **"family":** _STRING_**,**
                   **"port":** _EXPRESSION_**,**
                   **"flags":** _FLAGS_
           **}}**

           **{** **"masquerade":** **{**
                   **"port":** _EXPRESSION_**,**
                   **"flags":** _FLAGS_
           **}}**

           **{** **"redirect":** **{**
                   **"port":** _EXPRESSION_**,**
                   **"flags":** _FLAGS_
           **}}**

           _FLAGS_ := _FLAG_ | **[** _FLAG_LIST_ **]**
           _FLAG_LIST_ := _FLAG_ [**,** _FLAG_LIST_ ]
           _FLAG_ := **"random"** | **"fully-random"** | **"persistent"**

       Perform Network Address Translation.

### addr
           Address to translate to.

### family
           Family of **addr**, either **ip** or **ip6**. Required in **inet** table family.

### port
           Port to translate to.

### flags
           Flag(s).

       All properties are optional and default to none.

   **REJECT**
           **{** **"reject":** **{**
                   **"type":** _STRING_**,**
                   **"expr":** _EXPRESSION_
           **}}**

       Reject the packet and send the given error reply.

### type
           Type of reject, either **"tcp** **reset"**, **"icmpx"**, **"icmp"** or **"icmpv6"**.

### expr
           ICMP code to reject with.

       All properties are optional.

   **SET**
           **{** **"set":** **{**
                   **"op":** _STRING_**,**
                   **"elem":** _EXPRESSION_**,**
                   **"set":** _STRING_
           **}}**

       Dynamically add/update elements to a set.

       **op**
           Operator on set, either **"add"** or **"update"**.

### elem
           Set element to add or update.

### set
           Set reference.

   **LOG**
           **{** **"log":** **{**
                   **"prefix":** _STRING_**,**
                   **"group":** _NUMBER_**,**
                   **"snaplen":** _NUMBER_**,**
                   **"queue-threshold":** _NUMBER_**,**
                   **"level":** _LEVEL_**,**
                   **"flags":** _FLAGS_
           **}}**

           _LEVEL_ := **"emerg"** | **"alert"** | **"crit"** | **"err"** | **"warn"** | **"notice"** |
                      **"info"** | **"debug"** | **"audit"**

           _FLAGS_ := _FLAG_ | **[** _FLAG_LIST_ **]**
           _FLAG_LIST_ := _FLAG_ [**,** _FLAG_LIST_ ]
           _FLAG_ := **"tcp** **sequence"** | **"tcp** **options"** | **"ip** **options"** | **"skuid"** |
                     **"ether"** | **"all"**

       Log the packet.

### prefix
           Prefix for log entries.

### group
           Log group.

### snaplen
           Snaplen for logging.

### queue-threshold
           Queue threshold.

### level
           Log level. Defaults to **"warn"**.

### flags
           Log flags.

       All properties are optional.

   **CT** **HELPER**
           **{** **"ct** **helper":** _EXPRESSION_ **}**

       Enable the specified conntrack helper for this packet.

### ct helper
           CT helper reference.

   **METER**
           **{** **"meter":** **{**
                   **"name":** _STRING_**,**
                   **"key":** _EXPRESSION_**,**
                   **"stmt":** _STATEMENT_
           **}}**

       Apply a given statement using a meter.

### name
           Meter name.

### key
           Meter key.

### stmt
           Meter statement.

   **QUEUE**
           **{** **"queue":** **{**
                   **"num":** _EXPRESSION_**,**
                   **"flags":** _FLAGS_
           **}}**

           _FLAGS_ := _FLAG_ | **[** _FLAG_LIST_ **]**
           _FLAG_LIST_ := _FLAG_ [**,** _FLAG_LIST_ ]
           _FLAG_ := **"bypass"** | **"fanout"**

       Queue the packet to userspace.

### num
           Queue number.

### flags
           Queue flags.

   **VERDICT** **MAP**
           **{** **"vmap":** **{**
                   **"key":** _EXPRESSION_**,**
                   **"data":** _EXPRESSION_
           **}}**

       Apply a verdict conditionally.

### key
           Map key.

### data
           Mapping expression consisting of value/verdict pairs.

   **CT** **COUNT**
           **{** **"ct** **count":** **{**
                   **"val":** _NUMBER_**,**
                   **"inv":** _BOOLEAN_
           **}}**

       Limit the number of connections using conntrack.

### val
           Connection count threshold.

### inv
           If **true**, match if **val** was exceeded. If omitted, defaults to **false**.

   **CT** **TIMEOUT**
           **{** **"ct** **timeout":** _EXPRESSION_ **}**

       Assign connection tracking timeout policy.

### ct timeout
           CT timeout reference.

   **CT** **EXPECTATION**
           **{** **"ct** **expectation":** _EXPRESSION_ **}**

       Assign connection tracking expectation.

### ct expectation
           CT expectation reference.

   **XT**
           **{** **"xt":** **null** **}**

       This represents an xt statement from xtables compat interface. Sadly, at this point, it is
       not possible to provide any further information about its content.

## EXPRESSIONS
       Expressions are the building blocks of (most) statements. In their most basic form, they are
       just immediate values represented as a JSON string, integer or boolean type.

   **IMMEDIATES**
           _STRING_
           _NUMBER_
           _BOOLEAN_

       Immediate expressions are typically used for constant values. For strings, there are two
       special cases:

### @STRING
           The remaining part is taken as set name to create a set reference.

       **\***
           Construct a wildcard expression.

   **LISTS**
           _ARRAY_

       List expressions are constructed by plain arrays containing of an arbitrary number of
       expressions.

   **CONCAT**
           **{** **"concat":** _CONCAT_ **}**

           _CONCAT_ := **[** _EXPRESSION_LIST_ **]**
           _EXPRESSION_LIST_ := _EXPRESSION_ [**,** _EXPRESSION_LIST_ ]

       Concatenate several expressions.

   **SET**
           **{** **"set":** _SET_ **}**

           _SET_ := _EXPRESSION_ | **[** _EXPRESSION_LIST_ **]**

       This object constructs an anonymous set. For mappings, an array of arrays with exactly two
       elements is expected.

   **MAP**
           **{** **"map":** **{**
                   **"key":** _EXPRESSION_**,**
                   **"data":** _EXPRESSION_
           **}}**

       Map a key to a value.

### key
           Map key.

### data
           Mapping expression consisting of value/target pairs.

   **PREFIX**
           **{** **"prefix":** **{**
                   **"addr":** _EXPRESSION_**,**
                   **"len":** _NUMBER_
           **}}**

       Construct an IPv4 or IPv6 prefix consisting of address part in **addr** and prefix length in **len**.

   **RANGE**
           **{** **"range":** **[** _EXPRESSION_ **,** _EXPRESSION_ **]** **}**

       Construct a range of values. The first array item denotes the lower boundary, the second one
       the upper boundary.

   **PAYLOAD**
           **{** **"payload":** **{**
                   **"base":** _BASE_**,**
                   **"offset":** _NUMBER_**,**
                   **"len":** _NUMBER_
           **}}**

           **{** **"payload":** **{**
                   **"protocol":** _STRING_**,**
                   **"field":** _STRING_
           **}}**

           _BASE_ := **"ll"** | **"nh"** | **"th"**

       Construct a payload expression, i.e. a reference to a certain part of packet data. The first
       form creates a raw payload expression to point at a random number (**len**) of bytes at a certain
       offset (**offset**) from a given reference point (**base**). The following **base** values are accepted:

### "ll"
           The offset is relative to Link Layer header start offset.

### "nh"
           The offset is relative to Network Layer header start offset.

### "th"
           The offset is relative to Transport Layer header start offset.

       The second form allows to reference a field by name (**field**) in a named packet header
       (**protocol**).

   **EXTHDR**
           **{** **"exthdr":** **{**
                   **"name":** _STRING_**,**
                   **"field":** _STRING_**,**
                   **"offset":** _NUMBER_
           **}}**

       Create a reference to a field (**field**) in an IPv6 extension header (**name**). **offset** is used only
       for **rt0** protocol.

       If the **field** property is not given, the expression is to be used as a header existence check
       in a **match** statement with a boolean on the right hand side.

   **TCP** **OPTION**
           **{** **"tcp** **option":** **{**
                   **"name":** _STRING_**,**
                   **"field":** _STRING_
           **}}**

       Create a reference to a field (**field**) of a TCP option header (**name**).

       If the **field** property is not given, the expression is to be used as a TCP option existence
       check in a **match** statement with a boolean on the right hand side.

   **SCTP** **CHUNK**
           **{** **"sctp** **chunk":** **{**
                   **"name":** _STRING_**,**
                   **"field":** _STRING_
           **}}**

       Create a reference to a field (**field**) of an SCTP chunk (**name**).

       If the **field** property is not given, the expression is to be used as an SCTP chunk existence
       check in a **match** statement with a boolean on the right hand side.

   **META**
           **{** **"meta":** **{**
                   **"key":** _META_KEY_
           **}}**

           _META_KEY_ := **"length"** | **"protocol"** | **"priority"** | **"random"** | **"mark"** |
                         **"iif"** | **"iifname"** | **"iiftype"** | **"oif"** | **"oifname"** |
                         **"oiftype"** | **"skuid"** | **"skgid"** | **"nftrace"** |
                         **"rtclassid"** | **"ibriport"** | **"obriport"** | **"ibridgename"** |
                         **"obridgename"** | **"pkttype"** | **"cpu"** | **"iifgroup"** |
                         **"oifgroup"** | **"cgroup"** | **"nfproto"** | **"l4proto"** |
                         **"secpath"**

       Create a reference to packet meta data.

   **RT**
           **{** **"rt":** **{**
                   **"key":** _RT_KEY_**,**
                   **"family":** _RT_FAMILY_
           **}}**

           _RT_KEY_ := **"classid"** | **"nexthop"** | **"mtu"**
           _RT_FAMILY_ := **"ip"** | **"ip6"**

       Create a reference to packet routing data.

       The **family** property is optional and defaults to unspecified.

   **CT**
           **{** **"ct":** **{**
                   **"key":** _STRING_**,**
                   **"family":** _CT_FAMILY_**,**
                   **"dir":** _CT_DIRECTION_
           **}}**

           _CT_FAMILY_ := **"ip"** | **"ip6"**
           _CT_DIRECTION_ := **"original"** | **"reply"**

       Create a reference to packet conntrack data.

       Some CT keys do not support a direction. In this case, **dir** must not be given.

   **NUMGEN**
           **{** **"numgen":** **{**
                   **"mode":** _NG_MODE_**,**
                   **"mod":** _NUMBER_**,**
                   **"offset":** _NUMBER_
           **}}**

           _NG_MODE_ := **"inc"** | **"random"**

       Create a number generator.

       The **offset** property is optional and defaults to 0.

   **HASH**
           **{** **"jhash":** **{**
                   **"mod":** _NUMBER_**,**
                   **"offset":** _NUMBER_**,**
                   **"expr":** _EXPRESSION_**,**
                   **"seed":** _NUMBER_
           **}}**

           **{** **"symhash":** **{**
                   **"mod":** _NUMBER_**,**
                   **"offset":** _NUMBER_
           **}}**

       Hash packet data.

       The **offset** and **seed** properties are optional and default to 0.

   **FIB**
           **{** **"fib":** **{**
                   **"result":** _FIB_RESULT_**,**
                   **"flags":** _FIB_FLAGS_
           **}}**

           _FIB_RESULT_ := **"oif"** | **"oifname"** | **"type"**

           _FIB_FLAGS_ := _FIB_FLAG_ | **[** _FIB_FLAG_LIST_ **]**
           _FIB_FLAG_LIST_ := _FIB_FLAG_ [**,** _FIB_FLAG_LIST_ ]
           _FIB_FLAG_ := **"saddr"** | **"daddr"** | **"mark"** | **"iif"** | **"oif"**

       Perform kernel Forwarding Information Base lookups.

   **BINARY** **OPERATION**
           **{** **"|":** **[** _EXPRESSION_**,** _EXPRESSION_ **]** **}**
           **{** **"^":** **[** _EXPRESSION_**,** _EXPRESSION_ **]** **}**
           **{** **"&":** **[** _EXPRESSION_**,** _EXPRESSION_ **]** **}**
           **{** **"<<":** **[** _EXPRESSION_**,** _EXPRESSION_ **]** **}**
           **{** **">>":** **[** _EXPRESSION_**,** _EXPRESSION_ **]** **}**

       All binary operations expect an array of exactly two expressions, of which the first element
       denotes the left hand side and the second one the right hand side.

   **VERDICT**
           **{** **"accept":** **null** **}**
           **{** **"drop":** **null** **}**
           **{** **"continue":** **null** **}**
           **{** **"return":** **null** **}**
           **{** **"jump":** **{** **"target":** _STRING_ **}}**
           **{** **"goto":** **{** **"target":** _STRING_ **}}**

       Same as the **verdict** statement, but for use in verdict maps.

       **jump** and **goto** verdicts expect a target chain name.

   **ELEM**
           **{** **"elem":** **{**
                   **"val":** _EXPRESSION_**,**
                   **"timeout":** _NUMBER_**,**
                   **"expires":** _NUMBER_**,**
                   **"comment":** _STRING_
           **}}**

       Explicitly set element object, in case **timeout**, **expires** or **comment** are desired. Otherwise, it
       may be replaced by the value of **val**.

   **SOCKET**
           **{** **"socket":** **{**
                   **"key":** _SOCKET_KEY_
           **}}**

           _SOCKET_KEY_ := **"transparent"**

       Construct a reference to packet’s socket.

   **OSF**
           **{** **"osf":** **{**
                   **"key":** _OSF_KEY_**,**
                   **"ttl":** _OSF_TTL_
           **}}**

           _OSF_KEY_ := **"name"**
           _OSF_TTL_ := **"loose"** | **"skip"**

       Perform OS fingerprinting. This expression is typically used in the LHS of a **match** statement.

### key
           Which part of the fingerprint info to match against. At this point, only the OS name is
           supported.

### ttl
           Define how the packet’s TTL value is to be matched. This property is optional. If
           omitted, the TTL value has to match exactly. A value of **loose** accepts TTL values less
           than the fingerprint one. A value of **skip** omits TTL value comparison entirely.

## AUTHOR
       **Phil** **Sutter** <<phil@nwl.cc>>
           Author.



                                             02/24/2026                          [LIBNFTABLES-JSON(5)](https://www.chedong.com/phpMan.php/man/LIBNFTABLES-JSON/5/markdown)
