2024-09-17 16:18:29 +03:00
|
|
|
set_conntrack_liberal_mode() {
|
|
|
|
[ -n "$SKIP_CONNTRACK_LIBERAL_MODE" ] || sysctl -w net.netfilter.nf_conntrack_tcp_be_liberal="$1"
|
2023-10-26 15:12:32 +03:00
|
|
|
}
|
2024-09-17 16:18:29 +03:00
|
|
|
zapret_do_firewall() {
|
2022-02-15 17:15:36 +03:00
|
|
|
linux_fwtype
|
|
|
|
|
2022-02-18 12:35:06 +03:00
|
|
|
[ "$1" = 1 -a -n "$INIT_FW_PRE_UP_HOOK" ] && $INIT_FW_PRE_UP_HOOK
|
|
|
|
[ "$1" = 0 -a -n "$INIT_FW_PRE_DOWN_HOOK" ] && $INIT_FW_PRE_DOWN_HOOK
|
|
|
|
|
2022-02-15 17:15:36 +03:00
|
|
|
case "$FWTYPE" in
|
2024-09-17 16:18:29 +03:00
|
|
|
iptables)
|
|
|
|
zapret_do_firewall_ipt "$@"
|
|
|
|
;;
|
|
|
|
nftables)
|
|
|
|
zapret_do_firewall_nft "$@"
|
|
|
|
;;
|
2022-02-15 17:15:36 +03:00
|
|
|
esac
|
|
|
|
|
2024-09-17 16:12:39 +03:00
|
|
|
# Russian DPI sends RST,ACK with wrong ACK.
|
2023-10-26 15:12:32 +03:00
|
|
|
# this is sometimes treated by conntrack as invalid and connbytes fw rules do not pass RST packet to nfqws.
|
2023-10-29 13:04:04 +03:00
|
|
|
# switch on liberal mode on zapret firewall start and switch off on zapret firewall stop
|
2023-10-26 15:12:32 +03:00
|
|
|
# this is only required for processing incoming bad RSTs. incoming rules are only applied in autohostlist mode
|
|
|
|
# calling this after firewall because conntrack module can be not loaded before applying conntrack firewall rules
|
2024-09-17 16:18:29 +03:00
|
|
|
[ "$MODE_FILTER" = "autohostlist" -a "$MODE" != tpws -a "$MODE" != tpws-socks ] && set_conntrack_liberal_mode "$1"
|
|
|
|
|
2022-02-18 12:35:06 +03:00
|
|
|
[ "$1" = 1 -a -n "$INIT_FW_POST_UP_HOOK" ] && $INIT_FW_POST_UP_HOOK
|
|
|
|
[ "$1" = 0 -a -n "$INIT_FW_POST_DOWN_HOOK" ] && $INIT_FW_POST_DOWN_HOOK
|
|
|
|
|
2022-02-15 17:15:36 +03:00
|
|
|
return 0
|
|
|
|
}
|
2024-09-17 16:18:29 +03:00
|
|
|
zapret_apply_firewall() {
|
2022-02-15 17:15:36 +03:00
|
|
|
zapret_do_firewall 1 "$@"
|
|
|
|
}
|
2024-09-17 16:18:29 +03:00
|
|
|
zapret_unapply_firewall() {
|
2022-02-15 17:15:36 +03:00
|
|
|
zapret_do_firewall 0 "$@"
|
|
|
|
}
|
2024-03-02 17:53:37 +03:00
|
|
|
|
2024-09-17 16:18:29 +03:00
|
|
|
first_packets_for_mode() {
|
2024-03-02 17:53:37 +03:00
|
|
|
# autohostlist and autottl modes requires incoming traffic sample
|
|
|
|
# always use conntrack packet limiter or nfqws will deal with gigabytes
|
|
|
|
local n
|
|
|
|
if [ "$MODE_FILTER" = "autohostlist" ]; then
|
2024-09-17 16:18:29 +03:00
|
|
|
n=$((6 + ${AUTOHOSTLIST_RETRANS_THRESHOLD:-3}))
|
2024-03-02 17:53:37 +03:00
|
|
|
else
|
|
|
|
n=6
|
|
|
|
fi
|
|
|
|
echo $n
|
2024-05-04 16:01:09 +03:00
|
|
|
}
|