2018-05-15 15:20:49 +00:00
#!/bin/sh /etc/rc.common
2020-09-04 19:53:16 +00:00
# Copyright (C) 2018-2020 Ycarus (Yannick Chabanois) <ycarus@zugaina.org>
2018-05-15 15:20:49 +00:00
2021-04-28 15:39:43 +00:00
START=98
2018-06-14 05:17:40 +00:00
STOP=10
USE_PROCD=1
2019-11-01 08:27:38 +00:00
EXTRA_COMMANDS="reload_rules bypass_asn"
2018-05-15 15:20:49 +00:00
2018-07-10 09:04:23 +00:00
. /usr/lib/unbound/iptools.sh
2022-09-25 17:02:32 +00:00
if [ -f /usr/sbin/iptables-legacy ]; then
IPTABLES="/usr/sbin/iptables-legacy"
IPTABLESRESTORE="/usr/sbin/iptables-legacy-restore"
IPTABLESSAVE="/usr/sbin/iptables-legacy-save"
IP6TABLES="/usr/sbin/ip6tables-legacy"
IP6TABLESRESTORE="/usr/sbin/ip6tables-legacy-restore"
IP6TABLESSAVE="/usr/sbin/ip6tables-legacy-save"
else
IPTABLES="/usr/sbin/iptables"
IPTABLESRESTORE="/usr/sbin/iptables-restore"
IPTABLESSAVE="/usr/sbin/iptables-save"
IP6TABLES="/usr/sbin/ip6tables"
IP6TABLESRESTORE="/usr/sbin/ip6tables-restore"
IP6TABLESSAVE="/usr/sbin/ip6tables-save"
fi
2019-09-09 19:28:35 +00:00
_add_proto() {
protoname=$1
2021-04-08 18:41:58 +00:00
[ -z "$protoname" ] && return
2020-01-15 18:52:18 +00:00
if [ "$(dd if=/proc/net/xt_ndpi/proto bs=4096 2> /dev/null | grep $protoname)" = "" ]; then
2019-09-11 06:37:38 +00:00
echo "add_custom $protoname" >/proc/net/xt_ndpi/proto
fi
2022-02-11 11:07:14 +00:00
allurls="$(dd if=/proc/net/xt_ndpi/host_proto bs=4096 2> /dev/null)"
2019-09-09 19:28:35 +00:00
hosts="$( uci -q get omr-bypass.$protoname.url )"
for url in $hosts; do
2022-02-11 11:07:14 +00:00
if [ "$(echo "$allurls" | grep -i ^${protoname}: | grep $url)" = "" ]; then
echo "$protoname:$url" >/proc/net/xt_ndpi/host_proto
fi
2019-09-09 19:28:35 +00:00
done
ip="$( uci -q get omr-bypass.$protoname.ip )"
for ip in $ips; do
2022-02-11 11:07:14 +00:00
if [ "$(echo "$allurls" | grep -i ^${protoname}: | grep $ip)" = "" ]; then
echo "$protoname:$ip" >/proc/net/xt_ndpi/ip_proto
fi
2019-09-09 19:28:35 +00:00
done
}
2023-05-25 11:09:49 +00:00
_add_proto_without_ndpi() {
protoname=$1
[ -z "$protoname" ] && return
echo "$protoname" >> /usr/share/omr-bypass/omr-bypass-proto.lst
}
2018-05-15 15:20:49 +00:00
_bypass_ip() {
2018-10-05 15:13:38 +00:00
local ip=$1
local type=$2
[ -z "$type" ] && type="all"
2018-06-22 08:50:17 +00:00
valid_ip4=$( valid_subnet4 $ip)
valid_ip6=$( valid_subnet6 $ip)
if [ "$valid_ip4" = "ok" ]; then
2019-02-22 18:47:54 +00:00
ipset -q add omr_dst_bypass_$type $ip
2018-06-22 08:50:17 +00:00
elif [ "$valid_ip6" = "ok" ]; then
2019-02-22 18:47:54 +00:00
ipset -q add omr6_dst_bypass_$type $ip
2018-06-22 08:50:17 +00:00
fi
}
2018-11-28 12:22:13 +00:00
_bypass_domains() {
2018-10-05 15:13:38 +00:00
local domain
local intf
2020-09-23 07:49:55 +00:00
local enabled
2018-10-05 15:13:38 +00:00
config_get domain $1 name
config_get intf $1 interface
2020-09-23 07:49:55 +00:00
config_get enabled $1 enabled
2023-04-25 19:40:44 +00:00
config_get noipv6 $1 noipv6
config_get family $1 family
[ -z "$intf" ] && intf="all"
2020-09-23 07:49:55 +00:00
[ "$enabled" = "0" ] && return
2021-04-08 18:41:58 +00:00
[ -z "$domain" ] && return
2023-04-25 19:40:44 +00:00
[ -z "$family" ] && family="ipv4ipv6"
[ -z "$noipv6" ] && noipv6="0"
2021-03-03 10:30:52 +00:00
if [ "$(echo $domain | grep '\.$')" != "" ] || [ "$(echo $domain | grep '\.\*$')" != "" ]; then
tlds=`curl --max-time 4 -s -k https://data.iana.org/TLD/tlds-alpha-by-domain.txt`
domain="$(echo '"$domain"' | sed 's:*::')"
domainlist=""
# construct list of domains to query
2021-03-31 07:56:51 +00:00
i=0
2021-03-03 10:30:52 +00:00
for tld in $tlds; do
i=$((i+1))
# trim off header
if [ "$i" -lt "12" ] || [ "$i" -gt "50" ]; then
continue
fi
# add to command
domainlist="${domainlist} ${domain}${tld}"
done
domainlist="$(echo $domainlist `# Get the list of valid domains, pass it to awk` \
| awk '{print tolower($0)}' `# awk lowercases the whole string and passes it to ` \
| xargs -n8 -P12 `# xargs sends 8 arguments at a time to` \
dig a +timeout=1 +tries=1 +retry=1 +nocmd +noall +answer `# dig, which passes results (if any) to` \
| awk '{print $1}' `# awk, which outputs queried domain to` \
| sed -e 's/.$//' `# sed, which trims off the trailing dot (google.com. -> google.com)` to \
| grep $domain `# grep, only keep wanted domain` \
| awk '{for (i=1;i<=NF;i++) if (!a[$i]++) printf("%s%s",$i,FS)}{printf("\n")}')" # deduplicate
for validdomain in $domainlist; do
2023-04-25 19:40:44 +00:00
_bypass_domain $validdomain $intf $family $noipv6
2021-03-03 10:30:52 +00:00
done
else
2023-04-25 19:40:44 +00:00
_bypass_domain $domain $intf $family $noipv6
2021-03-03 10:30:52 +00:00
fi
2018-11-28 12:22:13 +00:00
}
_bypass_domain() {
local domain=$1
local intf=$2
2023-04-25 19:40:44 +00:00
local family=$3
local noipv6=$4
2021-01-28 19:41:36 +00:00
intf=$(echo $intf | sed -e 's/\./_/')
2021-04-06 18:50:08 +00:00
[ -n "$intf" ] && [ -z "$(ipset --list | grep omr_dst_bypass_$intf)" ] && return
2018-10-05 15:13:38 +00:00
[ -z "$intf" ] && intf="all"
if [ -n "$domain" ]; then
2019-03-13 17:32:09 +00:00
domain=$(echo $domain | sed 's:^\.::')
2018-10-31 18:30:03 +00:00
#logger -t "omr-bypass" "Get IPs of $domain..."
2019-06-14 18:42:59 +00:00
if [ -z $RELOAD ]; then
2020-11-19 18:25:44 +00:00
resolve=$(dig a +timeout=1 +tries=1 +nocmd +noall +answer $domain | grep -v CNAME | awk '{print $5}')
2018-10-30 09:39:16 +00:00
for ip in $resolve; do
_bypass_ip $ip $intf
done
2020-11-09 18:49:08 +00:00
if [ "$disableipv6" = "0" ]; then
2020-11-19 18:25:44 +00:00
resolve=$(dig aaaa +timeout=1 +tries=1 +nocmd +noall +answer $domain | grep AAAA | awk '{print $5}')
2020-05-11 07:58:20 +00:00
for ip in $resolve; do
_bypass_ip $ip $intf
done
fi
2018-10-30 09:39:16 +00:00
fi
2019-05-31 17:28:03 +00:00
if [ "$(uci -q get dhcp.@dnsmasq[0].ipset | grep /$domain/)" = "" ]; then
2023-04-25 19:40:44 +00:00
if [ "$family" = "ipv4ipv6" ]; then
uci -q add_list dhcp.@dnsmasq[0].ipset="/$domain/omr_dst_bypass_$intf,omr6_dst_bypass_$intf"
elif [ "$family" = "ipv4" ]; then
uci -q add_list dhcp.@dnsmasq[0].ipset="/$domain/omr_dst_bypass_$intf"
elif [ "$family" = "ipv6" ]; then
uci -q add_list dhcp.@dnsmasq[0].ipset="/$domain/omr6_dst_bypass_$intf"
fi
2021-07-12 16:06:01 +00:00
add_domains="true"
2019-05-31 17:28:03 +00:00
else
dnsmasqipset=$(uci -q get dhcp.@dnsmasq[0].ipset | sed 's/ /\n/g')
for dnsipset in $dnsmasqipset; do
if [ "$(echo $dnsipset | cut -d/ -f2)" = "$domain" ]; then
uci -q del_list dhcp.@dnsmasq[0].ipset=$dnsipset
2023-04-25 19:40:44 +00:00
if [ "$family" = "ipv4ipv6" ]; then
uci -q add_list dhcp.@dnsmasq[0].ipset="$dnsipset,omr_dst_bypass_$intf,omr6_dst_bypass_$intf"
elif [ "$family" = "ipv4" ]; then
uci -q add_list dhcp.@dnsmasq[0].ipset="$dnsipset,omr_dst_bypass_$intf"
elif [ "$family" = "ipv6" ]; then
uci -q add_list dhcp.@dnsmasq[0].ipset="$dnsipset,omr6_dst_bypass_$intf"
fi
2021-07-12 16:06:01 +00:00
add_domains="true"
2019-05-31 17:28:03 +00:00
fi
done
fi
2023-04-25 19:40:44 +00:00
if [ "$(uci -q get dhcp.@dnsmasq[0].noipv6 | grep /$domain/)" = "" ] && [ "$noipv6" = "1" ]; then
uci -q add_list dhcp.@dnsmasq[0].noipv6="$domain"
fi
2018-10-31 18:30:03 +00:00
#logger -t "omr-bypass" "Get IPs of $domain... Done"
2018-10-05 15:13:38 +00:00
fi
2018-09-17 08:59:44 +00:00
}
2018-11-02 19:19:50 +00:00
_bypass_mac() {
local mac
local intf
2020-09-23 07:49:55 +00:00
local enabled
2018-11-02 19:19:50 +00:00
config_get mac $1 mac
config_get intf $1 interface
2020-09-23 07:49:55 +00:00
config_get enabled $1 enabled
[ "$enabled" = "0" ] && return
2021-01-28 19:41:36 +00:00
intf=$(echo $intf | sed -e 's/\./_/')
2021-04-06 18:50:08 +00:00
[ -n "$intf" ] && [ -z "$(ipset --list | grep omr_dst_bypass_$intf)" ] && return
2021-01-28 19:41:36 +00:00
local intfid="$(uci -q get omr-bypass.$intf.id)"
2018-11-02 19:19:50 +00:00
[ -z "$intf" ] && intf="all"
[ -z "$mac" ] && return
if [ "$intf" = "all" ]; then
2022-09-25 17:02:32 +00:00
$IPTABLESRESTORE -w --wait=60 --noflush <<-EOF
2018-11-02 19:19:50 +00:00
*mangle
2018-12-02 07:02:18 +00:00
-A omr-bypass -m mac --mac-source $mac -j MARK --set-mark 0x539
2018-11-02 19:19:50 +00:00
COMMIT
EOF
2020-11-09 18:49:08 +00:00
if [ "$disableipv6" = "0" ]; then
2022-09-25 17:02:32 +00:00
$IP6TABLESRESTORE -w --wait=60 --noflush <<-EOF
2020-05-11 07:58:20 +00:00
*mangle
-A omr-bypass6 -m mac --mac-source $mac -j MARK --set-mark 0x6539
COMMIT
EOF
fi
2018-11-02 19:19:50 +00:00
else
2022-09-25 17:02:32 +00:00
$IPTABLESRESTORE -w --wait=60 --noflush <<-EOF
2018-11-02 19:19:50 +00:00
*mangle
2018-12-02 07:02:18 +00:00
-A omr-bypass -m mac --mac-source $mac -j MARK --set-mark 0x539$intfid
2018-11-02 19:19:50 +00:00
COMMIT
EOF
2020-11-09 18:49:08 +00:00
if [ "$disableipv6" = "0" ]; then
2022-09-25 17:02:32 +00:00
$IP6TABLESRESTORE -w --wait=60 --noflush <<-EOF
2020-05-11 07:58:20 +00:00
*mangle
-A omr-bypass6 -m mac --mac-source $mac -j MARK --set-mark 0x6539$intfid
COMMIT
EOF
fi
2018-11-02 19:19:50 +00:00
fi
}
2018-11-15 14:35:02 +00:00
_bypass_lan_ip() {
local ip
local intf
2020-09-23 07:49:55 +00:00
local enabled
2018-11-15 14:35:02 +00:00
config_get ip $1 ip
config_get intf $1 interface
2020-09-23 07:49:55 +00:00
config_get enabled $1 enabled
[ "$enabled" = "0" ] && return
2021-01-28 19:41:36 +00:00
intf=$(echo $intf | sed -e 's/\./_/')
2021-04-06 18:50:08 +00:00
[ -n "$intf" ] && [ -z "$(ipset --list | grep omr_dst_bypass_$intf)" ] && return
2021-01-28 19:41:36 +00:00
local intfid="$(uci -q get omr-bypass.$intf.id)"
2018-11-15 14:35:02 +00:00
[ -z "$intf" ] && intf="all"
[ -z "$ip" ] && return
2019-08-17 18:21:31 +00:00
valid_ip4=$(valid_subnet4 $ip)
valid_ip6=$(valid_subnet6 $ip)
2018-11-15 14:35:02 +00:00
if [ "$intf" = "all" ]; then
2019-07-26 18:10:53 +00:00
if [ "$valid_ip4" = "ok" ]; then
2022-09-25 17:02:32 +00:00
$IPTABLESRESTORE -w --wait=60 --noflush <<-EOF
2019-07-26 18:10:53 +00:00
*mangle
-A omr-bypass -s $ip -j MARK --set-mark 0x539
COMMIT
EOF
2022-09-25 17:02:32 +00:00
$IPTABLESRESTORE -w --wait=60 --noflush <<-EOF
2020-08-24 14:53:36 +00:00
*mangle
-A omr-bypass-local -s $ip -j MARK --set-mark 0x539
COMMIT
EOF
2021-03-18 14:45:44 +00:00
elif [ "$valid_ip6" = "ok" ] && [ "$disableipv6" = "0" ]; then
2022-09-25 17:02:32 +00:00
$IP6TABLESRESTORE -w --wait=60 --noflush <<-EOF
2019-07-26 18:10:53 +00:00
*mangle
-A omr-bypass6 -s $ip -j MARK --set-mark 0x6539
COMMIT
EOF
fi
2018-11-15 14:35:02 +00:00
else
2019-07-26 18:10:53 +00:00
if [ "$valid_ip4" = "ok" ]; then
2022-09-25 17:02:32 +00:00
$IPTABLESRESTORE -w --wait=60 --noflush <<-EOF
2019-07-26 18:10:53 +00:00
*mangle
-A omr-bypass -s $ip -j MARK --set-mark 0x539$intfid
COMMIT
EOF
2022-09-25 17:02:32 +00:00
$IPTABLESRESTORE -w --wait=60 --noflush <<-EOF
2020-08-24 14:53:36 +00:00
*mangle
-A omr-bypass-local -s $ip -j MARK --set-mark 0x539$intfid
COMMIT
EOF
2021-03-18 14:45:44 +00:00
elif [ "$valid_ip6" = "ok" ] && [ "$disableipv6" = "0" ]; then
2022-09-25 17:02:32 +00:00
$IP6TABLESRESTORE -w --wait=60 --noflush <<-EOF
2019-07-26 18:10:53 +00:00
*mangle
-A omr-bypass6 -s $ip -j MARK --set-mark 0x6539$intfid
COMMIT
EOF
fi
2018-11-15 14:35:02 +00:00
fi
}
2019-10-26 18:16:31 +00:00
_bypass_dest_port() {
local intf
2020-09-23 07:49:55 +00:00
local enabled
local dport
local proto
2019-10-26 18:16:31 +00:00
config_get dport $1 dport
config_get proto $1 proto
config_get intf $1 interface
2020-09-23 07:49:55 +00:00
config_get enabled $1 enabled
[ "$enabled" = "0" ] && return
2021-01-28 19:41:36 +00:00
intf=$(echo $intf | sed -e 's/\./_/')
2021-04-06 18:50:08 +00:00
[ -n "$intf" ] && [ -z "$(ipset --list | grep omr_dst_bypass_$intf)" ] && return
2021-01-28 19:41:36 +00:00
local intfid="$(uci -q get omr-bypass.$intf.id)"
2019-10-26 18:16:31 +00:00
[ -z "$intf" ] && intf="all"
2019-12-07 19:13:54 +00:00
[ -z "$dport" ] && return
2020-05-11 07:58:20 +00:00
dport="$(echo $dport | sed 's/-/:/')"
2019-12-07 19:13:54 +00:00
[ -z "$proto" ] && return
2019-10-26 18:16:31 +00:00
if [ "$intf" = "all" ]; then
2022-09-25 17:02:32 +00:00
$IPTABLESRESTORE -w --wait=60 --noflush <<-EOF
2019-12-07 19:13:54 +00:00
*mangle
-A omr-bypass --protocol $proto --destination-port $dport -j MARK --set-mark 0x539
COMMIT
EOF
2022-09-25 17:02:32 +00:00
$IPTABLESRESTORE -w --wait=60 --noflush <<-EOF
2020-08-24 14:53:36 +00:00
*mangle
-A omr-bypass-local --protocol $proto --destination-port $dport -j MARK --set-mark 0x539
COMMIT
EOF
2020-11-09 18:49:08 +00:00
if [ "$disableipv6" = "0" ]; then
2022-09-25 17:02:32 +00:00
$IP6TABLESRESTORE -w --wait=60 --noflush <<-EOF
2020-05-11 07:58:20 +00:00
*mangle
-A omr-bypass6 --protocol $proto --destination-port $dport -j MARK --set-mark 0x6539
COMMIT
EOF
fi
2019-10-26 18:16:31 +00:00
else
2022-09-25 17:02:32 +00:00
$IPTABLESRESTORE -w --wait=60 --noflush <<-EOF
2019-12-07 19:13:54 +00:00
*mangle
-A omr-bypass --protocol $proto --destination-port $dport -j MARK --set-mark 0x539$intfid
COMMIT
EOF
2022-09-25 17:02:32 +00:00
$IPTABLESRESTORE -w --wait=60 --noflush <<-EOF
2020-08-24 14:53:36 +00:00
*mangle
-A omr-bypass-local --protocol $proto --destination-port $dport -j MARK --set-mark 0x539$intfid
COMMIT
EOF
2020-11-09 18:49:08 +00:00
if [ "$disableipv6" = "0" ]; then
2022-09-25 17:02:32 +00:00
$IP6TABLESRESTORE -w --wait=60 --noflush <<-EOF
2020-05-11 07:58:20 +00:00
*mangle
-A omr-bypass6 --protocol $proto --destination-port $dport -j MARK --set-mark 0x6539$intfid
COMMIT
EOF
fi
2019-10-26 18:16:31 +00:00
fi
}
2020-05-13 19:46:35 +00:00
_bypass_src_port() {
local intf
2020-09-23 07:49:55 +00:00
local enabled
local sport
local proto
2020-05-13 19:46:35 +00:00
config_get sport $1 sport
config_get proto $1 proto
config_get intf $1 interface
2020-09-23 07:49:55 +00:00
config_get enabled $1 enabled
[ "$enabled" = "0" ] && return
2021-01-28 19:41:36 +00:00
intf=$(echo $intf | sed -e 's/\./_/')
2021-04-06 18:50:08 +00:00
[ -n "$intf" ] && [ -z "$(ipset --list | grep omr_dst_bypass_$intf)" ] && return
2021-01-28 19:41:36 +00:00
local intfid="$(uci -q get omr-bypass.$intf.id)"
2020-05-13 19:46:35 +00:00
[ -z "$intf" ] && intf="all"
[ -z "$sport" ] && return
sport="$(echo $sport | sed 's/-/:/')"
[ -z "$proto" ] && return
if [ "$intf" = "all" ]; then
2022-09-25 17:02:32 +00:00
$IPTABLESRESTORE -w --wait=60 --noflush <<-EOF
2020-05-13 19:46:35 +00:00
*mangle
-A omr-bypass --protocol $proto --source-port $sport -j MARK --set-mark 0x539
COMMIT
EOF
2022-09-25 17:02:32 +00:00
$IPTABLESRESTORE -w --wait=60 --noflush <<-EOF
2020-08-24 14:53:36 +00:00
*mangle
-A omr-bypass-local --protocol $proto --source-port $sport -j MARK --set-mark 0x539
COMMIT
EOF
2020-11-09 18:49:08 +00:00
if [ "$disableipv6" = "0" ]; then
2022-09-25 17:02:32 +00:00
$IP6TABLESRESTORE -w --wait=60 --noflush <<-EOF
2020-05-13 19:46:35 +00:00
*mangle
-A omr-bypass6 --protocol $proto --source-port $sport -j MARK --set-mark 0x6539
COMMIT
EOF
fi
else
2022-09-25 17:02:32 +00:00
$IPTABLESRESTORE -w --wait=60 --noflush <<-EOF
2020-05-13 19:46:35 +00:00
*mangle
-A omr-bypass --protocol $proto --source-port $sport -j MARK --set-mark 0x539$intfid
COMMIT
EOF
2022-09-25 17:02:32 +00:00
$IPTABLESRESTORE -w --wait=60 --noflush <<-EOF
2020-08-24 14:53:36 +00:00
*mangle
-A omr-bypass-local --protocol $proto --source-port $sport -j MARK --set-mark 0x539$intfid
COMMIT
EOF
2020-11-09 18:49:08 +00:00
if [ "$disableipv6" = "0" ]; then
2022-09-25 17:02:32 +00:00
$IP6TABLESRESTORE -w --wait=60 --noflush <<-EOF
2020-05-13 19:46:35 +00:00
*mangle
-A omr-bypass6 --protocol $proto --source-port $sport -j MARK --set-mark 0x6539$intfid
COMMIT
EOF
fi
fi
}
2018-06-22 08:50:17 +00:00
_bypass_proto() {
2018-10-05 15:13:38 +00:00
local proto
local intf
2020-09-23 07:49:55 +00:00
local enabled
2018-10-05 15:13:38 +00:00
config_get proto $1 proto
config_get intf $1 interface
2020-09-23 07:49:55 +00:00
config_get enabled $1 enabled
2022-08-18 16:44:45 +00:00
config_get ndpi $1 ndpi
2023-04-25 19:40:44 +00:00
config_get noipv6 $1 noipv6
config_get family $1 family
2020-09-23 07:49:55 +00:00
[ "$enabled" = "0" ] && return
2023-04-25 19:40:44 +00:00
[ -z "$noipv6" ] && noipv6="0"
[ -z "$family" ] && family="ipv4ipv6"
2021-01-28 19:41:36 +00:00
intf=$(echo $intf | sed -e 's/\./_/')
2021-04-06 18:50:08 +00:00
[ -n "$intf" ] && [ -z "$(ipset --list | grep omr_dst_bypass_$intf)" ] && return
2021-01-28 19:41:36 +00:00
local intfid="$(uci -q get omr-bypass.$intf.id)"
2018-10-05 15:13:38 +00:00
[ -z "$intf" ] && intf="all"
2018-07-10 08:56:43 +00:00
[ -z "$proto" ] && return
2022-08-18 16:44:45 +00:00
if [ "$(uci -q get openmptcprouter.settings.ndpi)" != "0" ] && [ "$ndpi" != "0" ]; then
2021-05-28 15:48:24 +00:00
if [ "$intf" = "all" ]; then
2023-04-25 19:40:44 +00:00
if [ "$family" = "ipv4" ] || [ "$family" = "ipv4ipv6" ]; then
$IPTABLESRESTORE -w --wait=60 --noflush <<-EOF
*mangle
-A omr-bypass-dpi -m ndpi --proto $proto -j MARK --set-mark 0x539
-A omr-bypass-dpi -m mark --mark 0x539 -j RETURN
COMMIT
EOF
fi
if [ "$disableipv6" = "0" ] && ([ "$family" = "ipv6" ] || [ "$family" = "ipv4ipv6" ]); then
2022-09-25 17:02:32 +00:00
$IP6TABLESRESTORE -w --wait=60 --noflush <<-EOF
2021-05-28 15:48:24 +00:00
*mangle
-A omr-bypass6-dpi -m ndpi --proto $proto -j MARK --set-mark 0x6539
2022-08-25 11:59:44 +00:00
-A omr-bypass6-dpi -m mark --mark 0x6539 -j RETURN
2021-05-28 15:48:24 +00:00
COMMIT
EOF
fi
else
2023-04-25 19:40:44 +00:00
if [ "$family" = "ipv4" ] || [ "$family" = "ipv4ipv6" ]; then
$IPTABLESRESTORE -w --wait=60 --noflush <<-EOF
*mangle
-A omr-bypass-dpi -m ndpi --proto $proto -j MARK --set-mark 0x539$intfid
-A omr-bypass-dpi -m mark --mark 0x539$intfid -j RETURN
COMMIT
EOF
fi
if [ "$disableipv6" = "0" ] && ([ "$family" = "ipv6" ] || [ "$family" = "ipv4ipv6" ]); then
2022-09-25 17:02:32 +00:00
$IP6TABLESRESTORE -w --wait=60 --noflush <<-EOF
2021-05-28 15:48:24 +00:00
*mangle
-A omr-bypass6-dpi -m ndpi --proto $proto -j MARK --set-mark 0x6539$intfid
2022-08-25 11:59:44 +00:00
-A omr-bypass6-dpi -m mark --mark 0x6539$intfid -j RETURN
2021-05-28 15:48:24 +00:00
COMMIT
EOF
fi
2020-05-11 07:58:20 +00:00
fi
2018-10-05 15:13:38 +00:00
fi
2018-11-28 12:22:13 +00:00
# Use dnsmasq ipset to bypass domains of the proto
local domains
2020-09-16 06:57:02 +00:00
domains="$(cat /proc/net/xt_ndpi/host_proto | grep -i $proto: | sed -e "s/$proto://i" -e 's/*//' -e 's/,/ /g')"
2018-11-28 12:22:13 +00:00
if [ -n "$domains" ]; then
2020-11-10 13:59:15 +00:00
tlds=`curl --max-time 4 -s -k https://data.iana.org/TLD/tlds-alpha-by-domain.txt`
2018-11-28 12:22:13 +00:00
for domain in $domains; do
2020-09-02 08:27:44 +00:00
if [ -n "$domain" ]; then
2020-11-09 18:49:08 +00:00
domain="$(echo $domain | sed 's/^\.//')"
if [ "$(echo $domain | grep '\.$')" != "" ]; then
2020-11-10 13:54:52 +00:00
domainlist=""
2020-11-10 13:59:15 +00:00
# construct list of domains to query
2021-03-31 07:56:51 +00:00
i=0
2020-11-10 13:59:15 +00:00
for tld in $tlds; do
2020-11-10 13:59:55 +00:00
i=$((i+1))
# trim off header
if [ "$i" -lt "12" ] || [ "$i" -gt "50" ]; then
continue
fi
# add to command
domainlist="${domainlist} ${domain}${tld}"
2020-11-10 13:59:15 +00:00
done
domainlist="$(echo $domainlist `# Get the list of valid domains, pass it to awk` \
2020-11-10 13:59:55 +00:00
| awk '{print tolower($0)}' `# awk lowercases the whole string and passes it to ` \
2020-11-10 16:01:41 +00:00
| xargs -n8 -P12 `# xargs sends 8 arguments at a time to` \
dig a +timeout=1 +tries=1 +retry=1 +nocmd +noall +answer `# dig, which passes results (if any) to` \
2020-11-10 13:59:55 +00:00
| awk '{print $1}' `# awk, which outputs queried domain to` \
2020-11-10 16:01:41 +00:00
| sed -e 's/.$//' `# sed, which trims off the trailing dot (google.com. -> google.com)` to \
| grep $domain `# grep, only keep wanted domain` \
2020-11-10 13:59:55 +00:00
| awk '{for (i=1;i<=NF;i++) if (!a[$i]++) printf("%s%s",$i,FS)}{printf("\n")}')" # deduplicate
2020-11-10 13:59:15 +00:00
for validdomain in $domainlist; do
2023-04-25 19:40:44 +00:00
_bypass_domain $validdomain $intf $family $noipv6
2020-11-10 13:59:15 +00:00
done
2020-11-09 18:49:08 +00:00
else
2023-04-25 19:40:44 +00:00
_bypass_domain $domain $intf $family $noipv6
2020-11-09 18:49:08 +00:00
fi
2018-11-28 12:22:13 +00:00
fi
done
fi
2018-10-05 15:13:38 +00:00
}
2023-05-25 11:09:49 +00:00
_bypass_proto_without_ndpi() {
local proto
local intf
local enabled
config_get proto $1 proto
config_get intf $1 interface
config_get enabled $1 enabled
2023-05-26 19:31:06 +00:00
config_get ndpi $1 ndpi "0"
2023-05-25 11:09:49 +00:00
config_get noipv6 $1 noipv6
config_get family $1 family
[ "$enabled" = "0" ] && return
[ -z "$noipv6" ] && noipv6="0"
[ -z "$family" ] && family="ipv4ipv6"
intf=$(echo $intf | sed -e 's/\./_/')
[ -n "$intf" ] && [ -z "$(ipset --list | grep omr_dst_bypass_$intf)" ] && return
local intfid="$(uci -q get omr-bypass.$intf.id)"
[ -z "$intf" ] && intf="all"
[ -z "$proto" ] && return
if [ "$(uci -q get openmptcprouter.settings.ndpi)" == "0" ] || [ "$ndpi" == "0" ]; then
2023-05-28 05:51:38 +00:00
ALLIPS=$(sqlite3 /usr/share/omr-bypass/omr-bypass.db "select ip from ipproto where proto=\"$proto\";" ".exit")
if [ -n "$ALLIPS" ]; then
ipset -q flush bypass_$proto > /dev/null 2>&1
2023-10-06 13:04:05 +00:00
ipset -q flush bypass6_$proto > /dev/null 2>&1
2023-05-28 05:51:38 +00:00
ipset -q --exist restore <<-EOF
create bypass_$proto hash:net hashsize 64
2023-10-06 13:04:05 +00:00
create bypass6_$proto hash:net hashsize 64
2023-05-28 05:51:38 +00:00
EOF
for ip in $ALLIPS; do
2023-10-06 13:04:05 +00:00
valid_ip4=$( valid_subnet4 $ip)
valid_ip6=$( valid_subnet6 $ip)
if [ "$valid_ip4" = "ok" ]; then
ipset -q add bypass_$proto $ip
elif [ "$valid_ip6" = "ok" ]; then
ipset -q add bypass6_$proto $ip
fi
2023-05-28 05:51:38 +00:00
done
if [ "$intf" = "all" ]; then
if [ "$family" = "ipv4" ] || [ "$family" = "ipv4ipv6" ]; then
$IPTABLESRESTORE -w --wait=60 --noflush <<-EOF
*mangle
-A omr-bypass-dpi -m set --match-set bypass_$proto dst -j MARK --set-mark 0x539
-A omr-bypass-dpi -m mark --mark 0x539 -j RETURN
COMMIT
EOF
fi
if [ "$disableipv6" = "0" ] && ([ "$family" = "ipv6" ] || [ "$family" = "ipv4ipv6" ]); then
$IP6TABLESRESTORE -w --wait=60 --noflush <<-EOF
*mangle
2023-10-06 13:04:05 +00:00
-A omr-bypass6-dpi -m set --match-set bypass6_$proto dst -j MARK --set-mark 0x6539
2023-05-28 05:51:38 +00:00
-A omr-bypass6-dpi -m mark --mark 0x6539 -j RETURN
COMMIT
EOF
fi
else
if [ "$family" = "ipv4" ] || [ "$family" = "ipv4ipv6" ]; then
$IPTABLESRESTORE -w --wait=60 --noflush <<-EOF
*mangle
-A omr-bypass-dpi -m set --match-set bypass_$proto dst -j MARK --set-mark 0x539$intfid
-A omr-bypass-dpi -m mark --mark 0x539$intfid -j RETURN
COMMIT
EOF
fi
if [ "$disableipv6" = "0" ] && ([ "$family" = "ipv6" ] || [ "$family" = "ipv4ipv6" ]); then
$IP6TABLESRESTORE -w --wait=60 --noflush <<-EOF
*mangle
2023-10-06 13:04:05 +00:00
-A omr-bypass6-dpi -m set --match-set bypass6_$proto dst -j MARK --set-mark 0x6539$intfid
2023-05-28 05:51:38 +00:00
-A omr-bypass6-dpi -m mark --mark 0x6539$intfid -j RETURN
COMMIT
EOF
fi
2023-05-25 11:09:49 +00:00
fi
fi
fi
# Use dnsmasq ipset to bypass domains of the proto
local domains
#domains="$(cat /proc/net/xt_ndpi/host_proto | grep -i $proto: | sed -e "s/$proto://i" -e 's/*//' -e 's/,/ /g')"
2023-05-26 19:31:06 +00:00
domains=$(sqlite3 /usr/share/omr-bypass/omr-bypass.db "select host from hostproto where proto='"$proto"';" ".exit")
2023-05-25 11:09:49 +00:00
if [ -n "$domains" ]; then
tlds=`curl --max-time 4 -s -k https://data.iana.org/TLD/tlds-alpha-by-domain.txt`
for domain in $domains; do
if [ -n "$domain" ]; then
domain="$(echo $domain | sed 's/^\.//')"
if [ "$(echo $domain | grep '\.$')" != "" ]; then
domainlist=""
# construct list of domains to query
i=0
for tld in $tlds; do
i=$((i+1))
# trim off header
2023-05-26 19:31:06 +00:00
if [ "$i" -lt "2" ] || [ "${#tld}" -gt "3" ]; then
2023-05-25 11:09:49 +00:00
continue
fi
# add to command
domainlist="${domainlist} ${domain}${tld}"
done
domainlist="$(echo $domainlist `# Get the list of valid domains, pass it to awk` \
| awk '{print tolower($0)}' `# awk lowercases the whole string and passes it to ` \
| xargs -n8 -P12 `# xargs sends 8 arguments at a time to` \
dig a +timeout=1 +tries=1 +retry=1 +nocmd +noall +answer `# dig, which passes results (if any) to` \
| awk '{print $1}' `# awk, which outputs queried domain to` \
2023-05-26 19:31:06 +00:00
| sed 's/.$//' `# sed, which trims off the trailing dot (google.com. -> google.com) to` \
2023-05-25 11:09:49 +00:00
| grep $domain `# grep, only keep wanted domain` \
| awk '{for (i=1;i<=NF;i++) if (!a[$i]++) printf("%s%s",$i,FS)}{printf("\n")}')" # deduplicate
for validdomain in $domainlist; do
_bypass_domain $validdomain $intf $family $noipv6
done
else
_bypass_domain $domain $intf $family $noipv6
fi
fi
done
fi
}
2020-06-29 13:11:35 +00:00
_intf_rule_ss_rules() {
rule_name=$1
2020-08-21 08:00:52 +00:00
[ "$rule_name" = "ss_rules" ] && rule_name="def"
2022-09-25 17:02:32 +00:00
if [ "$($IPTABLES --wait=40 -t nat -L -n | grep ssr_${rule_name}_dst)" != "" ] && [ "$($IPTABLESSAVE 2>/dev/null | grep ssr_${rule_name}_dst | grep omr_dst_bypass_$intf)" = "" ]; then
$IPTABLESRESTORE -w --wait=60 --noflush <<-EOF
2020-06-29 13:11:35 +00:00
*nat
2020-08-24 14:53:36 +00:00
-I ssr_${rule_name}_dst 1 -m set --match-set omr_dst_bypass_$intf dst -j MARK --set-mark 0x539$count
2020-09-04 19:53:16 +00:00
-I ssr_${rule_name}_dst 2 -m mark --mark 0x539$count -j RETURN
2021-02-01 15:22:47 +00:00
COMMIT
EOF
fi
2022-09-25 17:02:32 +00:00
if [ "$($IPTABLES --wait=40 -t nat -L -n | grep ssr_${rule_name}_local_out)" != "" ] && [ "$($IPTABLESSAVE 2>/dev/null | grep ssr_${rule_name}_local_out | grep omr_dst_bypass_$intf)" = "" ]; then
$IPTABLESRESTORE -w --wait=60 --noflush <<-EOF
2021-02-01 15:22:47 +00:00
*nat
2020-08-24 14:53:36 +00:00
-I ssr_${rule_name}_local_out 1 -m set --match-set omr_dst_bypass_$intf dst -j MARK --set-mark 0x539$count
2020-08-24 14:43:59 +00:00
-I ssr_${rule_name}_local_out 2 -m mark --mark 0x539$count -j RETURN
2021-02-01 15:22:47 +00:00
COMMIT
EOF
fi
2022-09-25 17:02:32 +00:00
if [ "$($IPTABLES --wait=40 -t nat -L -n | grep ssr_${rule_name}_pre_src)" != "" ] && [ "$($IPTABLESSAVE 2>/dev/null | grep ssr_${rule_name}_pre_src | grep omr_dst_bypass_$intf)" = "" ]; then
$IPTABLESRESTORE -w --wait=60 --noflush <<-EOF
2021-02-01 15:22:47 +00:00
*nat
2020-08-24 14:43:59 +00:00
-I ssr_${rule_name}_pre_src 1 -m set --match-set omr_dst_bypass_$intf dst -j MARK --set-mark 0x539$count
-I ssr_${rule_name}_pre_src 2 -m mark --mark 0x539$count -j RETURN
2020-06-29 13:11:35 +00:00
COMMIT
EOF
fi
2020-11-09 18:49:08 +00:00
if [ "$disableipv6" = "0" ]; then
2022-09-25 17:02:32 +00:00
if [ "$($IP6TABLES --wait=40 -t mangle -L -n | grep omr6_dst_bypass_$intf)" = "" ]; then
$IP6TABLESRESTORE -w --wait=60 --noflush <<-EOF
2020-06-29 13:11:35 +00:00
*mangle
-I omr-bypass6 1 -m set --match-set omr6_dst_bypass_$intf dst -j MARK --set-mark 0x6539$count
COMMIT
EOF
fi
2022-09-25 17:02:32 +00:00
if [ "$($IP6TABLES --wait=40 -t nat -L -n | grep ssr6_${rule_name}_pre_src)" != "" ] && [ "$($IP6TABLESSAVE 2>/dev/null | grep ssr6 | grep omr6_dst_bypass_$intf)" = "" ]; then
$IP6TABLESRESTORE -w --wait=60 --noflush <<-EOF
2020-06-29 13:11:35 +00:00
*nat
2020-08-24 14:53:36 +00:00
-I ssr6_${rule_name}_dst 1 -m set --match-set omr6_dst_bypass_$intf dst -j MARK --set-mark 0x6539$count
2020-09-04 19:53:16 +00:00
-I ssr6_${rule_name}_dst 2 -m mark --mark 0x6539$count -j RETURN
2020-08-24 14:53:36 +00:00
-I ssr6_${rule_name}_local_out 1 -m set --match-set omr6_dst_bypass_$intf dst -j MARK --set-mark 0x6539$count
2020-08-24 14:43:59 +00:00
-I ssr6_${rule_name}_local_out 2 -m mark --mark 0x6539$count -j RETURN
-I ssr6_${rule_name}_pre_src 1 -m set --match-set omr6_dst_bypass_$intf dst -j MARK --set-mark 0x6539$count
-I ssr6_${rule_name}_pre_src 2 -m mark --mark 0x6539$count -j RETURN
2020-06-29 13:11:35 +00:00
COMMIT
EOF
fi
fi
}
2020-10-15 13:23:01 +00:00
_intf_rule_v2ray_rules() {
#rule_name=$1
#[ "$rule_name" = "ss_rules" ] && rule_name="def"
rule_name="def"
2022-09-25 17:02:32 +00:00
if [ "$($IPTABLES --wait=40 -t nat -L -n | grep v2r_${rule_name}_dst)" != "" ] && [ "$($IPTABLESSAVE 2>/dev/null | grep v2r_${rule_name}_dst | grep omr_dst_bypass_$intf)" = "" ]; then
$IPTABLESRESTORE -w --wait=60 --noflush <<-EOF
2020-10-15 13:23:01 +00:00
*nat
-I v2r_${rule_name}_dst 1 -m set --match-set omr_dst_bypass_$intf dst -j MARK --set-mark 0x539$count
-I v2r_${rule_name}_dst 2 -m mark --mark 0x539$count -j RETURN
2022-07-31 14:29:44 +00:00
COMMIT
EOF
fi
2022-09-25 17:02:32 +00:00
if [ "$($IPTABLES --wait=40 -t nat -L -n | grep v2r_${rule_name}_local_out)" != "" ] && [ "$($IPTABLESSAVE 2>/dev/null | grep v2r_${rule_name}_local_out | grep omr_dst_bypass_$intf)" = "" ]; then
$IPTABLESRESTORE -w --wait=60 --noflush <<-EOF
2022-07-31 14:29:44 +00:00
*nat
2020-10-15 13:23:01 +00:00
-I v2r_${rule_name}_local_out 1 -m set --match-set omr_dst_bypass_$intf dst -j MARK --set-mark 0x539$count
-I v2r_${rule_name}_local_out 2 -m mark --mark 0x539$count -j RETURN
2022-07-31 14:29:44 +00:00
COMMIT
EOF
fi
2022-09-25 17:02:32 +00:00
if [ "$($IPTABLES --wait=40 -t nat -L -n | grep v2r_${rule_name}_pre_src)" != "" ] && [ "$($IPTABLESSAVE 2</dev/null | grep v2r_${rule_name}_pre_src | grep omr_dst_bypass_$intf)" = "" ]; then
$IPTABLESRESTORE -w --wait=60 --noflush <<-EOF
2022-07-31 14:29:44 +00:00
*nat
2020-10-15 13:23:01 +00:00
-I v2r_${rule_name}_pre_src 1 -m set --match-set omr_dst_bypass_$intf dst -j MARK --set-mark 0x539$count
-I v2r_${rule_name}_pre_src 2 -m mark --mark 0x539$count -j RETURN
COMMIT
EOF
fi
2022-07-31 14:29:44 +00:00
2020-11-09 18:49:08 +00:00
if [ "$disableipv6" = "0" ]; then
2022-09-25 17:02:32 +00:00
if [ "$($IP6TABLESSAVE | grep omr-bypass6 | grep omr6_dst_bypass_$intf)" = "" ]; then
$IP6TABLESRESTORE -w --wait=60 --noflush <<-EOF
2020-10-15 13:23:01 +00:00
*mangle
-I omr-bypass6 1 -m set --match-set omr6_dst_bypass_$intf dst -j MARK --set-mark 0x6539$count
COMMIT
EOF
fi
2022-09-25 17:02:32 +00:00
if [ "$($IP6TABLES --wait=40 -t nat -L -n | grep v2r6_${rule_name}_pre_src)" != "" ] && [ "$($IP6TABLESSAVE 2>/dev/null | grep v2r6 | grep omr6_dst_bypass_$intf)" = "" ]; then
$IP6TABLESRESTORE -w --wait=60 --noflush <<-EOF
2020-10-15 13:23:01 +00:00
*nat
-I v2r6_${rule_name}_dst 1 -m set --match-set omr6_dst_bypass_$intf dst -j MARK --set-mark 0x6539$count
-I v2r6_${rule_name}_dst 2 -m mark --mark 0x6539$count -j RETURN
-I v2r6_${rule_name}_local_out 1 -m set --match-set omr6_dst_bypass_$intf dst -j MARK --set-mark 0x6539$count
-I v2r6_${rule_name}_local_out 2 -m mark --mark 0x6539$count -j RETURN
-I v2r6_${rule_name}_pre_src 1 -m set --match-set omr6_dst_bypass_$intf dst -j MARK --set-mark 0x6539$count
-I v2r6_${rule_name}_pre_src 2 -m mark --mark 0x6539$count -j RETURN
COMMIT
EOF
fi
fi
}
2023-09-29 13:00:35 +00:00
_intf_rule_xray_rules() {
#rule_name=$1
#[ "$rule_name" = "ss_rules" ] && rule_name="def"
rule_name="def"
if [ "$($IPTABLES --wait=40 -t nat -L -n | grep xr_${rule_name}_dst)" != "" ] && [ "$($IPTABLESSAVE 2>/dev/null | grep xr_${rule_name}_dst | grep omr_dst_bypass_$intf)" = "" ]; then
$IPTABLESRESTORE -w --wait=60 --noflush <<-EOF
*nat
-I xr_${rule_name}_dst 1 -m set --match-set omr_dst_bypass_$intf dst -j MARK --set-mark 0x539$count
-I xr_${rule_name}_dst 2 -m mark --mark 0x539$count -j RETURN
COMMIT
EOF
fi
if [ "$($IPTABLES --wait=40 -t nat -L -n | grep xr_${rule_name}_local_out)" != "" ] && [ "$($IPTABLESSAVE 2>/dev/null | grep xr_${rule_name}_local_out | grep omr_dst_bypass_$intf)" = "" ]; then
$IPTABLESRESTORE -w --wait=60 --noflush <<-EOF
*nat
-I xr_${rule_name}_local_out 1 -m set --match-set omr_dst_bypass_$intf dst -j MARK --set-mark 0x539$count
-I xr_${rule_name}_local_out 2 -m mark --mark 0x539$count -j RETURN
COMMIT
EOF
fi
if [ "$($IPTABLES --wait=40 -t nat -L -n | grep xr_${rule_name}_pre_src)" != "" ] && [ "$($IPTABLESSAVE 2</dev/null | grep xr_${rule_name}_pre_src | grep omr_dst_bypass_$intf)" = "" ]; then
$IPTABLESRESTORE -w --wait=60 --noflush <<-EOF
*nat
-I xr_${rule_name}_pre_src 1 -m set --match-set omr_dst_bypass_$intf dst -j MARK --set-mark 0x539$count
-I xr_${rule_name}_pre_src 2 -m mark --mark 0x539$count -j RETURN
COMMIT
EOF
fi
if [ "$disableipv6" = "0" ]; then
if [ "$($IP6TABLESSAVE | grep omr-bypass6 | grep omr6_dst_bypass_$intf)" = "" ]; then
$IP6TABLESRESTORE -w --wait=60 --noflush <<-EOF
*mangle
-I omr-bypass6 1 -m set --match-set omr6_dst_bypass_$intf dst -j MARK --set-mark 0x6539$count
COMMIT
EOF
fi
if [ "$($IP6TABLES --wait=40 -t nat -L -n | grep xr6_${rule_name}_pre_src)" != "" ] && [ "$($IP6TABLESSAVE 2>/dev/null | grep xr6 | grep omr6_dst_bypass_$intf)" = "" ]; then
$IP6TABLESRESTORE -w --wait=60 --noflush <<-EOF
*nat
-I xr6_${rule_name}_dst 1 -m set --match-set omr6_dst_bypass_$intf dst -j MARK --set-mark 0x6539$count
-I xr6_${rule_name}_dst 2 -m mark --mark 0x6539$count -j RETURN
-I xr6_${rule_name}_local_out 1 -m set --match-set omr6_dst_bypass_$intf dst -j MARK --set-mark 0x6539$count
-I xr6_${rule_name}_local_out 2 -m mark --mark 0x6539$count -j RETURN
-I xr6_${rule_name}_pre_src 1 -m set --match-set omr6_dst_bypass_$intf dst -j MARK --set-mark 0x6539$count
-I xr6_${rule_name}_pre_src 2 -m mark --mark 0x6539$count -j RETURN
COMMIT
EOF
fi
fi
}
2018-10-05 15:13:38 +00:00
_intf_rule() {
2018-10-13 21:33:12 +00:00
local intf
2021-07-04 05:20:55 +00:00
intf=$(ifstatus "$1" | jsonfilter -q -e '@["l3_device"]')
2021-02-15 18:55:07 +00:00
[ -n "$(echo $intf | grep '@')" ] && intf=$(ifstatus "$1" | jsonfilter -q -e '@["device"]')
2021-07-04 05:20:55 +00:00
[ -z "$intf" ] && config_get intf $1 device
2022-04-21 19:55:00 +00:00
[ -n "$(echo $intf | grep '/')" ] && return
2018-12-21 14:42:14 +00:00
#count=$((count+1))
config_get count $1 metric
2018-10-13 21:33:12 +00:00
local mode
2019-05-04 05:02:27 +00:00
#config_get mode $1 multipath "off"
#[ "$mode" = "off" ] && return
2019-01-27 09:15:33 +00:00
[ -z "$count" ] && return
[ -z "$intf" ] && return
2021-01-28 19:41:36 +00:00
intf=$(echo $intf | sed -e 's/\./_/')
2018-10-15 13:11:04 +00:00
[ "$(echo $1 | grep _dev)" != "" ] && return
2019-07-24 06:19:44 +00:00
[ -z "$RELOAD" ] || [ "$(ipset --list | grep omr_dst_bypass_$intf)" = "" ] && {
unset RELOAD
2019-06-14 18:42:59 +00:00
ipset -q flush omr_dst_bypass_$intf > /dev/null 2>&1
ipset -q flush omr6_dst_bypass_$intf > /dev/null 2>&1
ipset -q --exist restore <<-EOF
create omr_dst_bypass_$intf hash:net hashsize 64
create omr6_dst_bypass_$intf hash:net family inet6 hashsize 64
2019-01-20 19:42:36 +00:00
EOF
2019-06-14 18:42:59 +00:00
if [ "$(uci -q get openmptcprouter.settings.uci_rules)" = "1" ]; then
uci -q batch <<-EOF >/dev/null
delete network.${1}_fw_rule=rule
set network.${1}_fw_rule=rule
set network.${1}_fw_rule.priority=1
set network.${1}_fw_rule.mark=0x539${count}
set network.${1}_fw_rule.lookup=${count}
delete network.${1}_fw_rule6=rule6
set network.${1}_fw_rule6=rule6
set network.${1}_fw_rule6.priority=1
set network.${1}_fw_rule6.mark=0x6539${count}
set network.${1}_fw_rule6.lookup=${count}
commit network
EOF
else
ip rule add prio 1 fwmark 0x539$count lookup $count pref 1 > /dev/null 2>&1
2021-12-26 17:41:14 +00:00
ip -6 rule add prio 1 fwmark 0x6539$count lookup 6$count pref 1 > /dev/null 2>&1
2019-06-14 18:42:59 +00:00
fi
}
2022-09-25 17:02:32 +00:00
if [ "$($IPTABLESSAVE 2>/dev/null | grep omr-bypass | grep omr_dst_bypass_$intf)" = "" ]; then
$IPTABLESRESTORE -w --wait=60 --noflush <<-EOF
2018-10-05 15:13:38 +00:00
*mangle
2019-02-22 18:47:54 +00:00
-I omr-bypass 1 -m set --match-set omr_dst_bypass_$intf dst -j MARK --set-mark 0x539$count
2022-07-31 14:29:44 +00:00
-I omr-bypass 2 -m mark --mark 0x539$count -j RETURN
2021-02-01 15:22:47 +00:00
-I omr-bypass-local 1 -m set --match-set omr_dst_bypass_$intf dst -j MARK --set-mark 0x539$count
2022-07-31 14:29:44 +00:00
-I omr-bypass-local 2 -m mark --mark 0x539$count -j RETURN
2018-10-18 12:53:42 +00:00
COMMIT
EOF
fi
2023-05-02 06:32:19 +00:00
if [ "$(uci -q get openmptcprouter.settings.proxy)" = "shadowsocks" ]; then
2023-04-25 19:40:44 +00:00
config_load shadowsocks-libev
config_foreach _intf_rule_ss_rules ss_rules
2023-09-29 13:00:35 +00:00
elif [ "$(uci -q get openmptcprouter.settings.proxy)" = "shadowsocks-rust" ]; then
config_load shadowsocks-rust
config_foreach _intf_rule_ss_rules ss_rules
2023-05-02 06:32:19 +00:00
elif [ "$(uci -q get openmptcprouter.settings.proxy)" = "v2ray" ]; then
2023-04-25 19:40:44 +00:00
_intf_rule_v2ray_rules
2023-09-29 13:00:35 +00:00
elif [ "$(uci -q get openmptcprouter.settings.proxy)" = "xray" ]; then
_intf_rule_xray_rules
2023-04-25 19:40:44 +00:00
fi
2020-06-29 13:11:35 +00:00
2021-01-28 19:41:36 +00:00
uci -q set omr-bypass.$intf=interface
uci -q set omr-bypass.$intf.id=$count
2018-10-05 15:13:38 +00:00
}
_bypass_ip_set() {
local ip
local interface
2020-09-23 07:49:55 +00:00
local enabled
2018-10-05 15:13:38 +00:00
config_get ip $1 ip
config_get interface $1 interface
2020-09-23 07:49:55 +00:00
config_get enabled $1 enabled
[ "$enabled" = "0" ] && return
2018-10-05 15:13:38 +00:00
_bypass_ip $ip $interface
2018-05-15 15:20:49 +00:00
}
2019-01-03 19:41:43 +00:00
_bypass_asn() {
local asn
local interface
2020-09-23 07:49:55 +00:00
local enabled
2019-01-03 19:41:43 +00:00
config_get asn $1 asn
config_get interface $1 interface
2020-09-23 07:49:55 +00:00
config_get enabled $1 enabled
[ "$enabled" = "0" ] && return
2019-01-03 19:41:43 +00:00
local asnips
asnips=`curl --max-time 4 -s -k https://stat.ripe.net/data/announced-prefixes/data.json?resource=${asn} | jsonfilter -q -e '@.data.prefixes.*.prefix'`
for ip in $asnips; do
_bypass_ip $ip $interface
done
}
2019-11-01 08:27:38 +00:00
bypass_asn() {
config_load omr-bypass
config_foreach _bypass_asn asns
}
2018-12-12 20:31:32 +00:00
_bypass_omr_server() {
local ip
config_get ip $1 ip
_bypass_ip $ip
}
2020-06-29 13:11:35 +00:00
_ss_rules_config() {
rule_name=$1
2020-08-21 08:00:52 +00:00
[ "$rule_name" = "ss_rules" ] && rule_name="def"
2022-09-25 17:02:32 +00:00
if [ "$($IPTABLES --wait=40 -t nat -L -n | grep ssr_${rule_name}_pre_src)" != "" ] && [ "$($IPTABLES --wait=40 -t nat -L -n | grep omr_dst_bypass_all)" = "" ]; then
$IPTABLESRESTORE -w --wait=60 --noflush <<-EOF
2020-06-29 13:11:35 +00:00
*nat
2020-08-24 14:53:36 +00:00
-I ssr_${rule_name}_dst 1 -m set --match-set omr_dst_bypass_all dst -j MARK --set-mark 0x539
2022-07-31 14:29:44 +00:00
-I ssr_${rule_name}_dst 2 -m mark --mark 0x539 -j RETURN
2020-08-24 14:53:36 +00:00
-I ssr_${rule_name}_local_out 1 -m set --match-set omr_dst_bypass_all dst -j MARK --set-mark 0x539
2020-08-24 14:43:59 +00:00
-I ssr_${rule_name}_local_out 2 -m mark --mark 0x539 -j RETURN
-I ssr_${rule_name}_pre_src 1 -m set --match-set omr_dst_bypass_all dst -j MARK --set-mark 0x539
-I ssr_${rule_name}_pre_src 2 -m mark --mark 0x539 -j RETURN
2020-06-29 13:11:35 +00:00
COMMIT
EOF
fi
2020-11-09 18:49:08 +00:00
if [ "$disableipv6" = "0" ]; then
2022-09-25 17:02:32 +00:00
if [ "$($IP6TABLES --wait=40 -t mangle -L -n | grep 'match-set omr6_dst_bypass_all dst MARK set')" = "" ]; then
$IP6TABLESRESTORE -w --wait=60 --noflush <<-EOF
2020-06-29 13:11:35 +00:00
*mangle
-A omr-bypass6 -m set --match-set omr6_dst_bypass_all dst -j MARK --set-mark 0x6539
COMMIT
EOF
fi
2022-09-25 17:02:32 +00:00
if [ "$($IP6TABLES --wait=40 -t nat -L -n | grep ssr6_${rule_name}_pre_src)" != "" ] && [ "$($IP6TABLES --wait=40 -t nat -L -n | grep omr6_dst_bypass_all)" = "" ]; then
$IP6TABLESRESTORE -w --wait=60 --noflush <<-EOF
2020-06-29 13:11:35 +00:00
*nat
2020-08-24 14:53:36 +00:00
-I ssr6_${rule_name}_dst 1 -m set --match-set omr6_dst_bypass_all dst -j MARK --set-mark 0x6539
-I ssr6_${rule_name}_dst 1 -m mark --mark 0x6539 -j RETURN
-I ssr6_${rule_name}_local_out 1 -m set --match-set omr6_dst_bypass_all dst -j MARK --set-mark 0x6539
2020-08-24 14:43:59 +00:00
-I ssr6_${rule_name}_local_out 2 -m mark --mark 0x6539 -j RETURN
-I ssr6_${rule_name}_pre_src 1 -m set --match-set omr6_dst_bypass_all dst -j MARK --set-mark 0x6539
-I ssr6_${rule_name}_pre_src 2 -m mark --mark 0x6539 -j RETURN
2020-06-29 13:11:35 +00:00
COMMIT
EOF
fi
fi
}
2020-10-15 13:23:01 +00:00
_v2ray_rules_config() {
#rule_name=$1
#[ "$rule_name" = "ss_rules" ] && rule_name="def"
rule_name="def"
2022-09-25 17:02:32 +00:00
if [ "$($IPTABLES --wait=40 -t nat -L -n | grep v2r_${rule_name}_pre_src)" != "" ] && [ "$($IPTABLES --wait=40 -t nat -L -n | grep omr_dst_bypass_all)" = "" ]; then
$IPTABLESRESTORE -w --wait=60 --noflush <<-EOF
2020-10-15 13:23:01 +00:00
*nat
-I v2r_${rule_name}_dst 1 -m set --match-set omr_dst_bypass_all dst -j MARK --set-mark 0x539
2022-07-31 14:29:44 +00:00
-I v2r_${rule_name}_dst 2 -m mark --mark 0x539 -j RETURN
2020-10-15 13:23:01 +00:00
-I v2r_${rule_name}_local_out 1 -m set --match-set omr_dst_bypass_all dst -j MARK --set-mark 0x539
-I v2r_${rule_name}_local_out 2 -m mark --mark 0x539 -j RETURN
-I v2r_${rule_name}_pre_src 1 -m set --match-set omr_dst_bypass_all dst -j MARK --set-mark 0x539
-I v2r_${rule_name}_pre_src 2 -m mark --mark 0x539 -j RETURN
COMMIT
EOF
fi
2020-11-09 18:49:08 +00:00
if [ "$disableipv6" = "0" ]; then
2022-09-25 17:02:32 +00:00
if [ "$($IP6TABLES --wait=40 -t mangle -L -n | grep 'match-set omr6_dst_bypass_all dst MARK set')" = "" ]; then
$IP6TABLESRESTORE -w --wait=60 --noflush <<-EOF
2020-10-15 13:23:01 +00:00
*mangle
-A omr-bypass6 -m set --match-set omr6_dst_bypass_all dst -j MARK --set-mark 0x6539
COMMIT
EOF
fi
2022-09-25 17:02:32 +00:00
if [ "$($IP6TABLES --wait=40 -t nat -L -n | grep v2r6_${rule_name}_pre_src)" != "" ] && [ "$($IP6TABLES --wait=40 -t nat -L -n | grep omr6_dst_bypass_all)" = "" ]; then
$IP6TABLESRESTORE -w --wait=60 --noflush <<-EOF
2020-10-15 13:23:01 +00:00
*nat
-I v2r6_${rule_name}_dst 1 -m set --match-set omr6_dst_bypass_all dst -j MARK --set-mark 0x6539
-I v2r6_${rule_name}_dst 1 -m mark --mark 0x6539 -j RETURN
-I v2r6_${rule_name}_local_out 1 -m set --match-set omr6_dst_bypass_all dst -j MARK --set-mark 0x6539
-I v2r6_${rule_name}_local_out 2 -m mark --mark 0x6539 -j RETURN
-I v2r6_${rule_name}_pre_src 1 -m set --match-set omr6_dst_bypass_all dst -j MARK --set-mark 0x6539
-I v2r6_${rule_name}_pre_src 2 -m mark --mark 0x6539 -j RETURN
COMMIT
EOF
fi
fi
}
2023-09-29 13:00:35 +00:00
_xray_rules_config() {
#rule_name=$1
#[ "$rule_name" = "ss_rules" ] && rule_name="def"
rule_name="def"
if [ "$($IPTABLES --wait=40 -t nat -L -n | grep xr_${rule_name}_pre_src)" != "" ] && [ "$($IPTABLES --wait=40 -t nat -L -n | grep omr_dst_bypass_all)" = "" ]; then
$IPTABLESRESTORE -w --wait=60 --noflush <<-EOF
*nat
-I xr_${rule_name}_dst 1 -m set --match-set omr_dst_bypass_all dst -j MARK --set-mark 0x539
-I xr_${rule_name}_dst 2 -m mark --mark 0x539 -j RETURN
-I xr_${rule_name}_local_out 1 -m set --match-set omr_dst_bypass_all dst -j MARK --set-mark 0x539
-I xr_${rule_name}_local_out 2 -m mark --mark 0x539 -j RETURN
-I xr_${rule_name}_pre_src 1 -m set --match-set omr_dst_bypass_all dst -j MARK --set-mark 0x539
-I xr_${rule_name}_pre_src 2 -m mark --mark 0x539 -j RETURN
COMMIT
EOF
fi
if [ "$disableipv6" = "0" ]; then
if [ "$($IP6TABLES --wait=40 -t mangle -L -n | grep 'match-set omr6_dst_bypass_all dst MARK set')" = "" ]; then
$IP6TABLESRESTORE -w --wait=60 --noflush <<-EOF
*mangle
-A omr-bypass6 -m set --match-set omr6_dst_bypass_all dst -j MARK --set-mark 0x6539
COMMIT
EOF
fi
if [ "$($IP6TABLES --wait=40 -t nat -L -n | grep xr6_${rule_name}_pre_src)" != "" ] && [ "$($IP6TABLES --wait=40 -t nat -L -n | grep omr6_dst_bypass_all)" = "" ]; then
$IP6TABLESRESTORE -w --wait=60 --noflush <<-EOF
*nat
-I xr6_${rule_name}_dst 1 -m set --match-set omr6_dst_bypass_all dst -j MARK --set-mark 0x6539
-I xr6_${rule_name}_dst 1 -m mark --mark 0x6539 -j RETURN
-I xr6_${rule_name}_local_out 1 -m set --match-set omr6_dst_bypass_all dst -j MARK --set-mark 0x6539
-I xr6_${rule_name}_local_out 2 -m mark --mark 0x6539 -j RETURN
-I xr6_${rule_name}_pre_src 1 -m set --match-set omr6_dst_bypass_all dst -j MARK --set-mark 0x6539
-I xr6_${rule_name}_pre_src 2 -m mark --mark 0x6539 -j RETURN
COMMIT
EOF
fi
fi
}
2018-10-30 09:39:16 +00:00
boot() {
BOOT=1
start "$@"
}
2018-05-15 15:20:49 +00:00
start_service() {
2018-12-21 14:42:14 +00:00
#local count
2018-10-13 19:40:42 +00:00
logger -t "omr-bypass" "Starting OMR-ByPass..."
2021-07-12 16:06:01 +00:00
add_domains="false"
2023-05-25 11:09:49 +00:00
[ -d /proc/net/xt_ndpi ] && {
config_load omr-bypass
config_foreach _add_proto proto
}
2020-05-11 07:58:20 +00:00
disableipv6="$(uci -q get openmptcprouter.settings.disable_ipv6)"
2023-04-25 19:40:44 +00:00
#noipv6="$(uci -q get omr-bypass.global.noipv6)"
2019-09-09 19:28:35 +00:00
2019-06-18 16:44:39 +00:00
[ -n "$RELOAD" ] && [ "$(ipset --list | grep omr_dst_bypass_all)" = "" ] && {
unset RELOAD
}
2019-06-14 18:42:59 +00:00
[ -z "$RELOAD" ] && {
ipset -q flush omr_dst_bypass_all > /dev/null 2>&1
ipset -q flush omr6_dst_bypass_all > /dev/null 2>&1
ipset -q --exist restore <<-EOF
create omr_dst_bypass_all hash:net hashsize 64
create omr6_dst_bypass_all hash:net family inet6 hashsize 64
EOF
}
2022-09-25 17:02:32 +00:00
$IPTABLESSAVE --counters 2>/dev/null | grep -v omr-bypass | $IPTABLESRESTORE -w --counters 2>/dev/null
$IPTABLESRESTORE -w --wait=60 --noflush <<-EOF
2018-12-02 07:02:18 +00:00
*mangle
:omr-bypass -
2022-08-25 11:59:44 +00:00
-A PREROUTING -j omr-bypass
2020-08-24 14:53:36 +00:00
COMMIT
EOF
2022-09-25 17:02:32 +00:00
$IPTABLESRESTORE -w --wait=60 --noflush <<-EOF
2020-08-24 14:53:36 +00:00
*mangle
:omr-bypass-local -
2022-08-25 11:59:44 +00:00
-A OUTPUT -m addrtype ! --dst-type LOCAL -j omr-bypass-local
2018-12-02 07:02:18 +00:00
COMMIT
EOF
2020-11-09 18:49:08 +00:00
if [ "$disableipv6" = "0" ]; then
2022-09-25 17:02:32 +00:00
$IP6TABLESSAVE --counters 2>/dev/null | grep -v omr-bypass6 | $IP6TABLESRESTORE -w --counters 2>/dev/null
$IP6TABLESRESTORE -w --wait=60 --noflush <<-EOF
2020-05-11 07:58:20 +00:00
*mangle
:omr-bypass6 -
2022-08-25 11:59:44 +00:00
-A PREROUTING -j omr-bypass6
2020-05-11 07:58:20 +00:00
COMMIT
EOF
fi
2019-07-26 18:10:53 +00:00
2018-10-05 15:13:38 +00:00
config_load network
config_foreach _intf_rule interface
local ndpi_rules=""
2020-09-04 19:53:16 +00:00
if [ "$(uci -q get openmptcprouter.settings.bypass_servers)" = "1" ]; then
config_load openmptcprouter
config_foreach _bypass_omr_server server
fi
2018-10-05 15:13:38 +00:00
config_load omr-bypass
config_foreach _bypass_ip_set ips
2018-11-02 19:19:50 +00:00
config_foreach _bypass_mac macs
2018-11-15 14:35:02 +00:00
config_foreach _bypass_lan_ip lan_ip
2019-10-26 18:16:31 +00:00
config_foreach _bypass_dest_port dest_port
2020-05-13 19:46:35 +00:00
config_foreach _bypass_src_port src_port
2019-01-03 19:41:43 +00:00
config_foreach _bypass_asn asns
2019-04-15 20:13:41 +00:00
dnsmasqipset=$(uci -q get dhcp.@dnsmasq[0].ipset | sed 's/ /\n/g' | grep -v dst_bypass)
2019-02-03 18:19:21 +00:00
uci -q delete dhcp.@dnsmasq[0].ipset
2023-04-25 19:40:44 +00:00
uci -q delete dhcp.@dnsmasq[0].noipv6
2019-04-15 20:13:41 +00:00
if [ -n "$dnsmasqipset" ]; then
for dnsipset in $dnsmasqipset; do
2019-05-31 17:28:03 +00:00
ipsets=""
allipsets=$(echo $dnsipset | cut -d/ -f3 | sed 's/,/\n/g')
for ipset in $allipsets; do
[ "$(echo $ipset | grep -v dst_bypass)" != "" ] && {
[ "$ipsets" != "" ] && ipsets="$ipsets,$ipset"
[ "$ipsets" = "" ] && ipsets="$ipset"
}
done
if [ "$ipsets" != "" ]; then
resultipset="/$(echo $dnsipset | cut -d/ -f2)/$ipsets"
2021-04-08 18:41:58 +00:00
[ -n "$resultipset" ] && uci -q add_list dhcp.@dnsmasq[0].ipset=$resultipset
2019-05-31 17:28:03 +00:00
fi
2019-04-15 20:13:41 +00:00
done
fi
2018-11-28 12:22:13 +00:00
config_foreach _bypass_domains domains
2018-10-14 05:43:38 +00:00
uci -q commit dhcp
2018-09-17 08:59:44 +00:00
2018-06-14 05:17:40 +00:00
ip rule add prio 1 fwmark 0x539 lookup 991337 > /dev/null 2>&1
2018-10-26 14:50:27 +00:00
ip -6 rule add prio 1 fwmark 0x6539 lookup 6991337 > /dev/null 2>&1
2018-06-22 08:50:17 +00:00
2022-09-25 17:02:32 +00:00
if [ "$($IPTABLES --wait=40 -t mangle -L -n | grep 'match-set omr_dst_bypass_all dst MARK set')" = "" ]; then
$IPTABLESRESTORE -w --wait=60 --noflush <<-EOF
2018-06-14 05:17:40 +00:00
*mangle
2019-02-22 18:47:54 +00:00
-A omr-bypass -m set --match-set omr_dst_bypass_all dst -j MARK --set-mark 0x539
2022-08-25 11:59:44 +00:00
-A omr-bypass -m mark --mark 0x539 -j RETURN
2018-06-14 05:17:40 +00:00
COMMIT
EOF
2022-09-25 17:02:32 +00:00
$IPTABLESRESTORE -w --wait=60 --noflush <<-EOF
2020-08-24 14:53:36 +00:00
*mangle
-A omr-bypass-local -m set --match-set omr_dst_bypass_all dst -j MARK --set-mark 0x539
2022-08-25 11:59:44 +00:00
-A omr-bypass-local -m mark --mark 0x539 -j RETURN
2020-08-24 14:53:36 +00:00
COMMIT
EOF
2018-06-14 05:17:40 +00:00
fi
2020-06-29 13:11:35 +00:00
config_load shadowsocks-libev
config_foreach _ss_rules_config
2023-09-29 13:00:35 +00:00
config_load shadowsocks-rust
config_foreach _ss_rules_config
2020-10-15 13:23:01 +00:00
_v2ray_rules_config
2023-09-29 13:00:35 +00:00
_xray_rules_config
2018-10-23 13:07:23 +00:00
2022-09-25 17:02:32 +00:00
$IPTABLESSAVE --counters 2>/dev/null | grep -v omr-bypass-dpi | $IPTABLESRESTORE -w --counters 2>/dev/null
$IPTABLESRESTORE -w --wait=60 --noflush <<-EOF
2018-10-22 13:44:36 +00:00
*mangle
:omr-bypass-dpi -
2022-08-25 11:59:44 +00:00
-A INPUT -j omr-bypass-dpi
-A FORWARD -j omr-bypass-dpi
2018-10-22 13:44:36 +00:00
COMMIT
EOF
2020-11-09 18:49:08 +00:00
if [ "$disableipv6" = "0" ]; then
2022-09-25 17:02:32 +00:00
$IP6TABLESSAVE --counters | grep -v omr-bypass6-dpi | $IP6TABLESRESTORE -w --counters 2>/dev/null
$IP6TABLESRESTORE -w --wait=60 --noflush <<-EOF
2020-05-11 07:58:20 +00:00
*mangle
:omr-bypass6-dpi -
2022-08-25 11:59:44 +00:00
-A INPUT -j omr-bypass6-dpi
-A FORWARD -j omr-bypass6-dpi
2020-05-11 07:58:20 +00:00
COMMIT
EOF
fi
2018-10-20 17:20:51 +00:00
config_load omr-bypass
2023-04-25 19:40:44 +00:00
[ -d /proc/net/xt_ndpi/proto ] && config_foreach _bypass_proto dpis
2023-05-25 11:09:49 +00:00
config_foreach _bypass_proto_without_ndpi dpis
2020-09-16 06:57:02 +00:00
uci -q commit omr-bypass
2018-10-23 13:07:23 +00:00
2021-07-12 16:06:01 +00:00
[ -z "$RELOAD" ] && [ "$add_domains" = "true" ] && {
2019-07-25 18:43:04 +00:00
logger -t "omr-bypass" "Restart dnsmasq..."
/etc/init.d/dnsmasq restart
2019-07-26 17:56:07 +00:00
}
2021-07-12 16:06:01 +00:00
[ -n "$RELOAD" ] && [ "$add_domains" = "true" ] && {
2019-07-25 18:43:04 +00:00
logger -t "omr-bypass" "Reload dnsmasq..."
/etc/init.d/dnsmasq reload
}
2023-05-25 11:09:49 +00:00
# Create a protocol list for UI from a sqlite DB when NDPI is not available
sqlite3 /usr/share/omr-bypass/omr-bypass.db "select distinct(proto) from (select proto from hostproto union all select proto from ipproto) a order by proto;" ".exit" > /usr/share/omr-bypass/omr-bypass-proto.lst
config_load omr-bypass
config_foreach _add_proto_without_ndpi proto
2023-07-07 15:24:11 +00:00
sort < /usr/share/omr-bypass/omr-bypass-proto.lst > /usr/share/omr-bypass/omr-bypass-proto.lst.new
mv /usr/share/omr-bypass/omr-bypass-proto.lst.new /usr/share/omr-bypass/omr-bypass-proto.lst
2018-10-13 19:40:42 +00:00
logger -t "omr-bypass" "OMR-ByPass is running"
2018-05-15 15:20:49 +00:00
}
2018-12-02 07:02:18 +00:00
stop_service() {
2022-09-25 17:02:32 +00:00
$IPTABLESSAVE --counters 2>/dev/null | grep -v omr-bypass | $IPTABLESRESTORE -w --counters 2>/dev/null
$IPTABLESSAVE --counters 2>/dev/null | grep -v omr_dst | $IPTABLESRESTORE -w --counters 2>/dev/null
$IP6TABLESSAVE --counters 2>/dev/null | grep -v omr-bypass6 | $IP6TABLESRESTORE -w --counters 2>/dev/null
$IP6TABLESSAVE --counters 2>/dev/null | grep -v omr6_dst | $IP6TABLESRESTORE -w --counters 2>/dev/null
2018-10-30 09:39:16 +00:00
for setname in $(ipset -n list | grep "omr_"); do
2020-07-16 13:59:15 +00:00
ipset -q destroy "$setname" 2>/dev/null || true
2018-10-30 09:39:16 +00:00
done
2023-05-29 06:10:45 +00:00
for setname in $(ipset list | awk '/Name: bypass_/ {print $2}'); do
ipset -q destroy "$setname" 2>/dev/null || true
done
2018-10-30 09:39:16 +00:00
}
2018-05-15 15:20:49 +00:00
service_triggers() {
2021-03-23 08:51:21 +00:00
procd_add_reload_trigger omr-bypass network firewall
2018-05-15 15:20:49 +00:00
}
reload_service() {
2022-09-24 08:17:37 +00:00
RELOAD=1
2019-07-14 19:12:10 +00:00
start
}
reload_rules() {
2018-12-02 07:02:18 +00:00
[ "$( ipset -n list | grep omr_ )" = "" ] && return 0
2019-06-14 18:42:59 +00:00
RELOAD=1
2018-10-30 09:39:16 +00:00
start
2018-05-15 15:20:49 +00:00
}