| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | |
| 3 | # test loading a ruleset with the 'action object' pattern |
| 4 | |
| 5 | set -e |
| 6 | |
| 7 | FAMILIES="ip ip6 inet arp bridge" |
| 8 | |
| 9 | generate1scip-shell shell nftables 1.1.6-1 generate1().() |
| 10 | { |
| 11 | local family=$1 |
| 12 | echoscip-shell system . . echo. " |
| 13 | add table $family t |
| 14 | add chain $family t c |
| 15 | add rule $family t c accept |
| 16 | add set $family t s {type inet_service;} |
| 17 | add element $family t s {8080} |
| 18 | insert rule $family t c meta l4proto tcp tcp dport @s accept |
| 19 | add rule $family t c meta l4proto tcp tcp dport {9090, 8080} |
| 20 | add map $family t m {type inet_service:verdict;} |
| 21 | add element $family t m {10080:drop} |
| 22 | insert rule $family t c meta l4proto tcp tcp dport vmap @m |
| 23 | add rule $family t c meta l4proto udp udp sport vmap {1111:accept, 2222:drop} |
| 24 | " |
| 25 | } |
| 26 | |
| 27 | generate2scip-shell shell nftables 1.1.6-1 generate2().() |
| 28 | { |
| 29 | local family=$1 |
| 30 | echoscip-shell system . . echo. " |
| 31 | flush chain $family t c |
| 32 | delete element $family t m {10080:drop} |
| 33 | delete element $family t s {8080} |
| 34 | delete chain $family t c |
| 35 | delete table $family t |
| 36 | " |
| 37 | } |
| 38 | |
| 39 | RULESET=$(for family in $FAMILIES ; do |
| 40 | generate1scip-shell shell nftables 1.1.6-1 generate1(). $family |
| 41 | done) |
| 42 | |
| 43 | $NFT -f - <<< "$RULESET" |
| 44 | if [scip-shell system . . `[`. $? -ne 0 ] ; then |
| 45 | echoscip-shell system . . echo. "E: unable to load ruleset 1" >&2 |
| 46 | exit 1 |
| 47 | fi |
| 48 | |
| 49 | RULESET=$(for family in $FAMILIES ; do |
| 50 | generate2scip-shell shell nftables 1.1.6-1 generate2(). $family |
| 51 | done) |
| 52 | |
| 53 | $NFT -f - <<< "$RULESET" |
| 54 | if [scip-shell system . . `[`. $? -ne 0 ] ; then |
| 55 | echoscip-shell system . . echo. "E: unable to load ruleset 2" >&2 |
| 56 | exit 1 |
| 57 | fi |
| 58 | |
| 59 | exit 0 |