Esoteric use case, but legal: NAT port rewrite over loopback. Also add drop rule to ensure that the packet is still tracked in input. Assisted-by: LLM Signed-off-by: Florian Westphal --- .../packetpath/dumps/nat_lo.json-nft | 152 ++++++++++++++++++ .../testcases/packetpath/dumps/nat_lo.nft | 14 ++ tests/shell/testcases/packetpath/nat_lo | 42 +++++ 3 files changed, 208 insertions(+) create mode 100644 tests/shell/testcases/packetpath/dumps/nat_lo.json-nft create mode 100644 tests/shell/testcases/packetpath/dumps/nat_lo.nft create mode 100755 tests/shell/testcases/packetpath/nat_lo diff --git a/tests/shell/testcases/packetpath/dumps/nat_lo.json-nft b/tests/shell/testcases/packetpath/dumps/nat_lo.json-nft new file mode 100644 index 000000000000..1b8dca338ee0 --- /dev/null +++ b/tests/shell/testcases/packetpath/dumps/nat_lo.json-nft @@ -0,0 +1,152 @@ +{ + "nftables": [ + { + "metainfo": { + "version": "VERSION", + "release_name": "RELEASE_NAME", + "json_schema_version": 1 + } + }, + { + "table": { + "family": "inet", + "name": "nat", + "handle": 0 + } + }, + { + "chain": { + "family": "inet", + "table": "nat", + "name": "output", + "handle": 0, + "type": "nat", + "hook": "output", + "prio": -100, + "policy": "accept" + } + }, + { + "rule": { + "family": "inet", + "table": "nat", + "chain": "output", + "handle": 0, + "expr": [ + { + "match": { + "op": "==", + "left": { + "payload": { + "protocol": "tcp", + "field": "dport" + } + }, + "right": 1234 + } + }, + { + "redirect": { + "port": 12345 + } + } + ] + } + }, + { + "table": { + "family": "inet", + "name": "filter", + "handle": 0 + } + }, + { + "chain": { + "family": "inet", + "table": "filter", + "name": "input", + "handle": 0, + "type": "filter", + "hook": "input", + "prio": 0, + "policy": "drop" + } + }, + { + "rule": { + "family": "inet", + "table": "filter", + "chain": "input", + "handle": 0, + "expr": [ + { + "match": { + "op": "in", + "left": { + "ct": { + "key": "state" + } + }, + "right": [ + "established", + "related", + "new" + ] + } + }, + { + "accept": null + } + ] + } + }, + { + "rule": { + "family": "inet", + "table": "filter", + "chain": "input", + "handle": 0, + "expr": [ + { + "match": { + "op": "==", + "left": { + "meta": { + "key": "l4proto" + } + }, + "right": { + "set": [ + 1, + 58 + ] + } + } + }, + { + "accept": null + } + ] + } + }, + { + "rule": { + "family": "inet", + "table": "filter", + "chain": "input", + "handle": 0, + "expr": [ + { + "counter": { + "packets": 0, + "bytes": 0 + } + }, + { + "drop": null + } + ] + } + } + ] +} diff --git a/tests/shell/testcases/packetpath/dumps/nat_lo.nft b/tests/shell/testcases/packetpath/dumps/nat_lo.nft new file mode 100644 index 000000000000..65259ec80242 --- /dev/null +++ b/tests/shell/testcases/packetpath/dumps/nat_lo.nft @@ -0,0 +1,14 @@ +table inet nat { + chain output { + type nat hook output priority dstnat; policy accept; + tcp dport 1234 redirect to :12345 + } +} +table inet filter { + chain input { + type filter hook input priority filter; policy drop; + ct state established,related,new accept + meta l4proto { 1, 58 } accept + counter packets 0 bytes 0 drop + } +} diff --git a/tests/shell/testcases/packetpath/nat_lo b/tests/shell/testcases/packetpath/nat_lo new file mode 100755 index 000000000000..862aadc82ef1 --- /dev/null +++ b/tests/shell/testcases/packetpath/nat_lo @@ -0,0 +1,42 @@ +#!/bin/bash + +set -e + +$NFT -f - <