zapret/common/fwtype.sh

60 lines
913 B
Bash
Raw Normal View History

linux_ipt_avail() {
2022-02-15 17:15:36 +03:00
exists iptables && exists ip6tables
}
linux_maybe_iptables_fwtype() {
2022-02-15 17:15:36 +03:00
linux_ipt_avail && FWTYPE=iptables
}
linux_nft_avail() {
2022-02-15 17:15:36 +03:00
exists nft
}
linux_fwtype() {
2022-02-15 17:15:36 +03:00
[ -n "$FWTYPE" ] && return
FWTYPE=unsupported
linux_get_subsys
if [ "$SUBSYS" = openwrt ]; then
# Linux kernel is new enough if fw4 is there
if [ -x /sbin/fw4 ] && linux_nft_avail; then
2022-02-15 17:15:36 +03:00
FWTYPE=nftables
else
linux_maybe_iptables_fwtype
fi
else
SUBSYS=
# generic Linux
2022-02-15 17:15:36 +03:00
# flowtable is implemented since kernel 4.16
if linux_nft_avail && linux_min_version 4 16; then
FWTYPE=nftables
else
linux_maybe_iptables_fwtype
fi
fi
export FWTYPE
}
get_fwtype() {
2022-02-15 17:15:36 +03:00
[ -n "$FWTYPE" ] && return
local UNAME="$(uname)"
case "$UNAME" in
Linux)
linux_fwtype
;;
FreeBSD)
if exists ipfw; then
FWTYPE=ipfw
else
2022-02-15 17:15:36 +03:00
FWTYPE=unsupported
fi
;;
*)
FWTYPE=unsupported
;;
2022-02-15 17:15:36 +03:00
esac
export FWTYPE
}