| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
# NFT_TEST_REQUIRES(NFT_TEST_HAVE_cttimeout) |
| 4 |
# NFT_TEST_REQUIRES(NFT_TEST_HAVE_ctexpect) |
| 5 |
|
| 6 |
$NFT -f /dev/stdin <<EOF || exit 1 |
| 7 |
table inet t { |
| 8 |
ct expectation exp1 { |
| 9 |
protocol tcp |
| 10 |
dport 9876 |
| 11 |
timeout 1m |
| 12 |
size 12 |
| 13 |
l3proto ip |
| 14 |
} |
| 15 |
|
| 16 |
ct expectation exp2 { |
| 17 |
protocol tcp |
| 18 |
dport 9876 |
| 19 |
timeout 3s |
| 20 |
size 13 |
| 21 |
l3proto ip6 |
| 22 |
} |
| 23 |
|
| 24 |
ct helper myftp { |
| 25 |
type "ftp" protocol tcp |
| 26 |
} |
| 27 |
|
| 28 |
ct timeout dns { |
| 29 |
protocol tcp |
| 30 |
l3proto ip |
| 31 |
policy = { established : 3, close : 1 } |
| 32 |
} |
| 33 |
|
| 34 |
map exp { |
| 35 |
typeof ip saddr : ct expectation |
| 36 |
elements = { 192.168.2.2 : "exp1" } |
| 37 |
} |
| 38 |
|
| 39 |
map exp6 { |
| 40 |
typeof ip6 saddr : ct expectation |
| 41 |
flags interval |
| 42 |
elements = { dead:beef::/64 : "exp2" } |
| 43 |
} |
| 44 |
|
| 45 |
map helpobj { |
| 46 |
typeof ip6 saddr : ct helper |
| 47 |
flags interval |
| 48 |
elements = { dead:beef::/64 : "myftp" } |
| 49 |
} |
| 50 |
|
| 51 |
map timeoutmap { |
| 52 |
typeof ip daddr : ct timeout |
| 53 |
elements = { 192.168.0.1 : "dns" } |
| 54 |
} |
| 55 |
|
| 56 |
set helpname { |
| 57 |
typeof ct helper |
| 58 |
elements = { "ftp", "sip" } |
| 59 |
} |
| 60 |
|
| 61 |
chain y { |
| 62 |
ct expectation set ip saddr map @exp |
| 63 |
ct expectation set ip6 saddr map { dead::beef : "exp2" } |
| 64 |
ct expectation set ip6 daddr map { dead::beef : "exp2", feed::17 : "exp2" } |
| 65 |
ct expectation set ip6 daddr . tcp dport map { dead::beef . 123 : "exp2", feed::17 . 512 : "exp2" } |
| 66 |
ct helper set ip6 saddr map { dead::beef : "myftp", 1c3::c01d : "myftp" } |
| 67 |
ct helper set ip6 saddr map @helpobj |
| 68 |
ct timeout set ip daddr map @timeoutmap |
| 69 |
ct timeout set ip daddr map { 1.2.3.4 : "dns", 5.6.7.8 : "dns", 192.168.8.0/24 : "dns" } |
| 70 |
ct timeout set ip daddr map { 1.2.3.4-1.2.3.8 : "dns" } |
| 71 |
ct timeout set ip6 daddr map { dead::beef : "dns", 1ce::/64 : "dns" } |
| 72 |
ct helper @helpname accept |
| 73 |
} |
| 74 |
} |
| 75 |
EOF |
| 76 |
|
| 77 |
must_fail() |
| 78 |
{ |
| 79 |
echo "Command should have failed: $1" |
| 80 |
exit 111 |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
must_work() |
| 85 |
{ |
| 86 |
echo "Command should have succeeded: $1" |
| 87 |
exit 111 |
| 88 |
} |
| 89 |
|
| 90 |
$NFT 'add rule inet t y ip saddr 192.168.1.1 ct timeout set "dns"' || must_work "dns timeout" |
| 91 |
|
| 92 |
$NFT 'add rule inet t y ct helper set ip saddr map @helpobj' && must_fail "helper assignment, map key is ipv6_addr" |
| 93 |
$NFT 'add rule inet t y ct helper set ip6 saddr map @helpname' && must_fail "helper assignment, not a map with objects" |
| 94 |
|
| 95 |
exit 0 |