3 # Some utility functions to keep iptables and ip6tables configuration in sync.
5 # Copyright (C) 2018 Antonio Ospite <ao2@ao2.it>
6 # SPDX-License-Identifier: MIT
8 # Based on updateipt.sh by Phil Sutter:
9 # https://developers.redhat.com/blog/2017/01/10/migrating-my-iptables-setup-to-nftables/
11 # useful wrappers for failure analysis
12 cmd_or_print() { # command
13 "$@" || echo "failed at: '$*'"
16 ipt() { # iptables params
17 cmd_or_print iptables "$@"
20 ip6t() { # ip6tables params
21 cmd_or_print ip6tables "$@"
24 # have a simple way of doing things in iptables and ip6tables in parallel
25 ip46t() { # ip(6)tables params
30 # clear out everything
32 for it in iptables ip6tables; do
33 for table in filter mangle nat raw; do
34 $it -t $table -nL >/dev/null 2>&1 || continue # non-existing table
36 $it -t $table -F # delete rules
37 $it -t $table -X # delete custom chains
38 $it -t $table -Z # zero counters