]> git.openstreetmap.org Git - chef.git/blob - cookbooks/networking/templates/default/nftables.erb
Preserve blocklists over firewall restarts
[chef.git] / cookbooks / networking / templates / default / nftables.erb
1 #!/bin/sh -e
2
3 start() {
4   /usr/sbin/nft -f /etc/nftables.conf
5   [ -f /var/lib/nftables/ip-blocklist.nft ] && /usr/sbin/nft -f /var/lib/nftables/ip-blocklist.nft || :
6   [ -f /var/lib/nftables/ip6-blocklist.nft ] && /usr/sbin/nft -f /var/lib/nftables/ip6-blocklist.nft || :
7 }
8
9 stop() {
10   /usr/sbin/nft list set inet chef-filter ip-blocklist > /var/lib/nftables/ip-blocklist.nft
11   /usr/sbin/nft list set inet chef-filter ip6-blocklist > /var/lib/nftables/ip6-blocklist.nft
12   /usr/sbin/nft delete table inet chef-filter
13 <% if node[:roles].include?("gateway") -%>
14   /usr/sbin/nft delete table inet chef-nat
15 <% end -%>
16 }
17
18 reload() {
19   stop
20   start
21 }
22
23 case "$1" in
24   start) start;;
25   stop) stop;;
26   reload) reload;;
27 esac
28
29 exit 0