summaryrefslogtreecommitdiff
path: root/net-firewall/nftables/files/libexec/nftables-mk.sh
diff options
context:
space:
mode:
authorV3n3RiX <venerix@redcorelinux.org>2019-01-12 16:58:08 +0000
committerV3n3RiX <venerix@redcorelinux.org>2019-01-12 16:58:08 +0000
commitc8a77dfe4d3d307c1d5dd2650b7297447d8b609d (patch)
tree9ea78393bc3ecd6ab4de449383d4e97e5f3648ae /net-firewall/nftables/files/libexec/nftables-mk.sh
parent2891d29af8907ce881662f4a02844926d7a293c7 (diff)
gentoo resync : 12.01.2019
Diffstat (limited to 'net-firewall/nftables/files/libexec/nftables-mk.sh')
-rw-r--r--net-firewall/nftables/files/libexec/nftables-mk.sh59
1 files changed, 59 insertions, 0 deletions
diff --git a/net-firewall/nftables/files/libexec/nftables-mk.sh b/net-firewall/nftables/files/libexec/nftables-mk.sh
new file mode 100644
index 000000000000..b6ad37867b6d
--- /dev/null
+++ b/net-firewall/nftables/files/libexec/nftables-mk.sh
@@ -0,0 +1,59 @@
+#!/bin/sh
+
+main() {
+ local NFTABLES_SAVE=${2:-'/var/lib/nftables/rules-save'}
+ case "$1" in
+ "check")
+ nft -c -f "${NFTABLES_SAVE}"
+ ;;
+ "clear")
+ nft flush ruleset
+ ;;
+ "list")
+ nft ${SAVE_OPTIONS} list ruleset
+ ;;
+ "load")
+ ( echo "flush ruleset;"; cat "${NFTABLES_SAVE}" ) | nft -f -
+ ;;
+ "panic")
+ panic hard | nft -f -
+ ;;
+ "soft_panic")
+ panic soft | nft -f -
+ ;;
+ "store")
+ local tmp_save="${NFTABLES_SAVE}.tmp"
+ umask 600;
+ (
+ echo "#!/sbin/nft -f"
+ echo "flush ruleset;"
+ nft ${SAVE_OPTIONS} list ruleset
+ ) > "$tmp_save" && mv ${tmp_save} ${NFTABLES_SAVE}
+ ;;
+ esac
+}
+
+panic() {
+ local erule;
+ [ "$1" = soft ] && erule="ct state established,related accept;" || erule="";
+ cat <<EOF
+table inet filter {
+ chain input {
+ type filter hook input priority 0;
+ $erule
+ drop
+ }
+ chain forward {
+ type filter hook forward priority 0;
+ drop
+ }
+ chain output {
+ type filter hook output priority 0;
+ $erule
+ drop
+ }
+}
+EOF
+}
+
+main "$@"