mirror of
https://github.com/bol-van/zapret.git
synced 2025-04-13 18:42:58 +03:00
Merge 027367944753d0949f420e78ac130182da99cf70 into b12b1a5a1702dd88aea8e3f0a9e50a52ec18823b
This commit is contained in:
commit
35c1d70bd2
83
init.d/custom.d.examples.linux/50-cloudflare
Normal file
83
init.d/custom.d.examples.linux/50-cloudflare
Normal file
@ -0,0 +1,83 @@
|
||||
NFQWS_CLOUDFLARE_OPTS="${NFQWS_CLOUDFLARE_OPTS:---dpi-desync=fake --dpi-desync-repeats=3 --dpi-desync-ttl=6}"
|
||||
NFQWS_CLOUDFLARE_PORTS=${NFQWS_CLOUDFLARE_PORTS:-443,80}
|
||||
NFQWS_CLOUDFLARE_SUBNETS_IPV4="103.21.244.0/22 103.22.200.0/22 103.31.4.0/22 104.16.0.0/13 104.24.0.0/14 108.162.192.0/18 131.0.72.0/22 141.101.64.0/18 162.158.0.0/15 172.64.0.0/13 173.245.48.0/20 188.114.96.0/20 190.93.240.0/20 197.234.240.0/22 198.41.128.0/17"
|
||||
NFQWS_CLOUDFLARE_SUBNETS_IPV6="2400:cb00::/32 2405:8100::/32 2405:b500::/32 2606:4700::/32 2803:f800::/32 2a06:98c0::/29 2c0f:f248::/32"
|
||||
|
||||
alloc_dnum DNUM_NFQWS_CLOUDFLARE
|
||||
alloc_qnum QNUM_NFQWS_CLOUDFLARE
|
||||
NFQWS_CLOUDFLARE_SET_NAME_IPV4=cloudflare_nfqws_ipv4
|
||||
NFQWS_CLOUDFLARE_SET_NAME_IPV6=cloudflare_nfqws_ipv6
|
||||
|
||||
zapret_custom_daemons()
|
||||
{
|
||||
local opt="--qnum=$QNUM_NFQWS_CLOUDFLARE $NFQWS_CLOUDFLARE_OPTS"
|
||||
do_nfqws $1 $DNUM_NFQWS_CLOUDFLARE "$opt"
|
||||
}
|
||||
|
||||
zapret_custom_firewall()
|
||||
{
|
||||
local first_packets_only="$ipt_connbytes 1:3"
|
||||
local dest_set_ipv4="-m set --match-set $NFQWS_CLOUDFLARE_SET_NAME_IPV4 dst"
|
||||
local dest_set_ipv6="-m set --match-set $NFQWS_CLOUDFLARE_SET_NAME_IPV6 dst"
|
||||
local subnet
|
||||
|
||||
[ "$1" = 1 ] && {
|
||||
ipset create $NFQWS_CLOUDFLARE_SET_NAME_IPV4 hash:net hashsize 8192 maxelem 4096 2>/dev/null
|
||||
ipset flush $NFQWS_CLOUDFLARE_SET_NAME_IPV4
|
||||
for subnet in $NFQWS_CLOUDFLARE_SUBNETS_IPV4; do
|
||||
echo add $NFQWS_CLOUDFLARE_SET_NAME_IPV4 $subnet
|
||||
done | ipset -! restore
|
||||
|
||||
[ "$DISABLE_IPV6" != "1" ] && {
|
||||
ipset create $NFQWS_CLOUDFLARE_SET_NAME_IPV6 hash:net family inet6 hashsize 8192 maxelem 4096 2>/dev/null
|
||||
ipset flush $NFQWS_CLOUDFLARE_SET_NAME_IPV6
|
||||
for subnet in $NFQWS_CLOUDFLARE_SUBNETS_IPV6; do
|
||||
echo add $NFQWS_CLOUDFLARE_SET_NAME_IPV6 $subnet
|
||||
done | ipset -! restore
|
||||
}
|
||||
}
|
||||
|
||||
local f="-p tcp -m multiport --dports $NFQWS_CLOUDFLARE_PORTS"
|
||||
fw_nfqws_post $1 "$f $first_packets_only $dest_set_ipv4" "" $QNUM_NFQWS_CLOUDFLARE
|
||||
|
||||
[ "$DISABLE_IPV6" != "1" ] && fw_nfqws_post $1 "$f $first_packets_only $dest_set_ipv6" "" $QNUM_NFQWS_CLOUDFLARE
|
||||
|
||||
[ "$1" = 1 ] || {
|
||||
ipset destroy $NFQWS_CLOUDFLARE_SET_NAME_IPV4 2>/dev/null
|
||||
[ "$DISABLE_IPV6" != "1" ] && ipset destroy $NFQWS_CLOUDFLARE_SET_NAME_IPV6 2>/dev/null
|
||||
}
|
||||
}
|
||||
|
||||
zapret_custom_firewall_nft()
|
||||
{
|
||||
local first_packets_only="$nft_connbytes 1-3"
|
||||
local dest_set_ipv4="ip daddr @$NFQWS_CLOUDFLARE_SET_NAME_IPV4"
|
||||
local dest_set_ipv6="ip6 daddr @$NFQWS_CLOUDFLARE_SET_NAME_IPV6"
|
||||
local nft_rules_ipv4="type ipv4_addr; size 4096; auto-merge; flags interval;"
|
||||
local nft_rules_ipv6="type ipv6_addr; size 4096; auto-merge; flags interval;"
|
||||
local subnets subnets_ipv6
|
||||
|
||||
make_comma_list subnets $NFQWS_CLOUDFLARE_SUBNETS_IPV4
|
||||
make_comma_list subnets_ipv6 $NFQWS_CLOUDFLARE_SUBNETS_IPV6
|
||||
|
||||
nft_create_set $NFQWS_CLOUDFLARE_SET_NAME_IPV4 "$nft_rules_ipv4"
|
||||
nft_flush_set $NFQWS_CLOUDFLARE_SET_NAME_IPV4
|
||||
nft_add_set_element $NFQWS_CLOUDFLARE_SET_NAME_IPV4 "$subnets"
|
||||
|
||||
[ "$DISABLE_IPV6" != "1" ] && {
|
||||
nft_create_set $NFQWS_CLOUDFLARE_SET_NAME_IPV6 "$nft_rules_ipv6"
|
||||
nft_flush_set $NFQWS_CLOUDFLARE_SET_NAME_IPV6
|
||||
nft_add_set_element $NFQWS_CLOUDFLARE_SET_NAME_IPV6 "$subnets_ipv6"
|
||||
}
|
||||
|
||||
local f="tcp dport {$NFQWS_CLOUDFLARE_PORTS}"
|
||||
nft_fw_nfqws_post "$f $first_packets_only $dest_set_ipv4" "" $QNUM_NFQWS_CLOUDFLARE
|
||||
|
||||
[ "$DISABLE_IPV6" != "1" ] && nft_fw_nfqws_post "$f $first_packets_only $dest_set_ipv6" "" $QNUM_NFQWS_CLOUDFLARE
|
||||
}
|
||||
|
||||
zapret_custom_firewall_nft_flush()
|
||||
{
|
||||
nft_del_set $NFQWS_CLOUDFLARE_SET_NAME_IPV4 2>/dev/null
|
||||
[ "$DISABLE_IPV6" != "1" ] && nft_del_set $NFQWS_CLOUDFLARE_SET_NAME_IPV6 2>/dev/null
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user