mirror of
https://github.com/Ysurac/openmptcprouter-feeds.git
synced 2025-02-24 06:44:21 +00:00
sync (#426)
This commit is contained in:
commit
aea489ea7e
4 changed files with 64 additions and 29 deletions
|
@ -95,7 +95,7 @@ DEVICE="$1"
|
|||
TYPE="$2"
|
||||
#FLAG_PATH=`find /sys/devices/ -path "*/net/$DEVICE/flags"`
|
||||
|
||||
[ -d "/sys/class/net/$DEVICE/" ] || {
|
||||
[ -e "/sys/class/net/$DEVICE/" ] || {
|
||||
#echo "Device '$DEVICE' can't found!"
|
||||
#echo "Use the hardware name like in ifconfig"
|
||||
exit 1
|
||||
|
@ -133,27 +133,30 @@ if [ -f /proc/sys/net/mptcp/mptcp_enabled ]; then
|
|||
else
|
||||
# Remove not needed if* interfaces in MPTCP
|
||||
endpoint="$(ip mptcp endpoint show)"
|
||||
[ -z "$endpoint" ] && exit 0
|
||||
oldintfs=$(echo "${endpoint}" | grep "dev if" | awk '{ print $3 }')
|
||||
[ -n "$endpoint" ] && oldintfs=$(echo "${endpoint}" | grep "dev if" | awk '{ print $3 }')
|
||||
[ -n "$oldintfs" ] && {
|
||||
for oldintf in $oldintfs; do
|
||||
ip mptcp endpoint delete id $oldintf 2>&1 >/dev/null
|
||||
done
|
||||
}
|
||||
endpoint="$(ip mptcp endpoint show)"
|
||||
[ -z "$endpoint" ] && exit 0
|
||||
ID=$(echo "${endpoint}" | sort | grep "dev $DEVICE " | awk '{print $3}')
|
||||
IFF=$(echo "${endpoint}" | sort | grep -m 1 -E "dev $DEVICE " | awk '{print $4}')
|
||||
#IP=$(ip a show $DEVICE | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p')
|
||||
if [ -f /usr/bin/jsonfilter ]; then
|
||||
if [ -n "$endpoint" ]; then
|
||||
ID=$(echo "${endpoint}" | sort | grep "dev $DEVICE " | awk '{print $3}')
|
||||
IFF=$(echo "${endpoint}" | sort | grep -m 1 -E "dev $DEVICE " | awk '{print $4; exit}')
|
||||
fi
|
||||
#IP=$(ip a show $DEVICE | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p')
|
||||
if [ -f /usr/bin/jsonfilter ]; then
|
||||
IP=$(ip -j a show $DEVICE scope global | jsonfilter -e '@[0].addr_info[*].local')
|
||||
elif [ -f /usr/bin/jq ]; then
|
||||
IP=$(ip -j a show $DEVICE scope global | jq -r '.[0].addr_info[].local')
|
||||
else
|
||||
echo "jsonfilter or jq are required"
|
||||
exit 1
|
||||
fi
|
||||
[ -z "$ID" ] && [ -n "$IP" ] && ID=$(echo "${endpoint}" show | grep "$IP " | awk '{print $3}')
|
||||
RMID=$(echo "${endpoint}" | grep '::ffff' | awk '{ print $3 }')
|
||||
[ -n "$RMID" ] && ip mptcp endpoint delete id $RMID 2>&1 >/dev/null
|
||||
case $TYPE in
|
||||
[ -z "$ID" ] && [ -n "$IP" ] && [ -n "$endpoint" ] && ID=$(echo "${endpoint}" show | grep "$IP " | awk '{print $3}')
|
||||
[ -n "$endpoint" ] && RMID=$(echo "${endpoint}" | grep '::ffff' | awk '{ print $3 }')
|
||||
[ -n "$RMID" ] && ip mptcp endpoint delete id $RMID 2>&1 >/dev/null
|
||||
case $TYPE in
|
||||
"off")
|
||||
[ -n "$ID" ] && {
|
||||
for i in $ID; do
|
||||
|
|
|
@ -708,7 +708,7 @@ dns_flush() {
|
|||
# Get the current multipath status
|
||||
multipath_status="off"
|
||||
[ "$OMR_TRACKER_INTERFACE" = "omrvpn" ] && multipath $OMR_TRACKER_DEVICE off 2>&1 >/dev/null
|
||||
if [ -d "/sys/class/net/$OMR_TRACKER_DEVICE" ]; then
|
||||
if [ -e "/sys/class/net/$OMR_TRACKER_DEVICE" ]; then
|
||||
case "$(multipath "$OMR_TRACKER_DEVICE")" in
|
||||
*default*) multipath_status="on" ;;
|
||||
*backup*) multipath_status="backup" ;;
|
||||
|
@ -1102,10 +1102,10 @@ if [ "$multipath_config" = "master" ]; then
|
|||
ip -6 route flush cache 2>&1 >/dev/null
|
||||
fi
|
||||
#if [ "$(uci -q get openmptcprouter.settings.master)" = "balancing" ] && [ "$(ip route show default | grep weight)" = "" ] && [ "$(uci -q get openmptcprouter.settings.defaultgw)" != "0" ] && [ "$(uci -q get openmptcprouter.settings.vpn)" != "mlvpn" ]; then
|
||||
if [ "$(uci -q get openmptcprouter.settings.master)" = "balancing" ] && ([ "$(ip route show default | grep weight)" = "" ] || [ "$(ip -6 route show default | grep weight)" = "" ]) && [ "$(uci -q get openmptcprouter.settings.defaultgw)" != "0" ]; then
|
||||
if [ "$(uci -q get openmptcprouter.settings.master)" = "balancing" ] && (([ -n "$OMR_TRACKER_DEVICE_IP" ] && [ "$(ip route show default | grep weight)" = "" ]) || ([ -n "$OMR_TRACKER_DEVICE_IP6" ] && [ "$(ip -6 route show default | grep weight)" = "" ])) && [ "$(uci -q get openmptcprouter.settings.defaultgw)" != "0" ]; then
|
||||
omrvpn_intf=$(uci -q get "network.omrvpn.device" || echo "tun0")
|
||||
[ -z "$omrvpn_intf" ] && omrvpn_intf=$(uci -q get "network.omrvpn.ifname" || echo "tun0")
|
||||
if [ -n "$omrvpn_intf" ] && [ "$(ip route show default | grep -v metric | awk '/default/ {print $5}' | grep $omrvpn_intf)" = "" ]; then
|
||||
if [ -n "$omrvpn_intf" ] && [ -n "$OMR_TRACKER_DEVICE_IP" ] && [ "$(ip route show default | grep -v metric | awk '/default/ {print $5}' | grep $omrvpn_intf)" = "" ]; then
|
||||
routesbalancing=""
|
||||
routesbalancingbackup=""
|
||||
nbintf=0
|
||||
|
@ -1141,7 +1141,7 @@ if [ "$multipath_config" = "master" ]; then
|
|||
# ip -6 route replace default scope global metric 999 $routesbalancingbackup6 2>&1 >/dev/null
|
||||
# }
|
||||
#}
|
||||
elif [ -n "$omrvpn_intf" ] && [ "$(ip -6 route show default | grep -v metric | awk '/default/ {print $5}' | grep $omrvpn_intf)" = "" ]; then
|
||||
elif [ -n "$omrvpn_intf" ] && [ -n "$OMR_TRACKER_DEVICE_IP6" ] && [ "$(ip -6 route show default | grep -v metric | awk '/default/ {print $5}' | grep $omrvpn_intf)" = "" ]; then
|
||||
routesbalancing6=""
|
||||
routesbalancingbackup6=""
|
||||
nbintf6=0
|
||||
|
@ -1161,16 +1161,16 @@ if [ "$multipath_config" = "master" ]; then
|
|||
}
|
||||
}
|
||||
fi
|
||||
ip route flush cache 2>&1 >/dev/null
|
||||
ip -6 route flush cache 2>&1 >/dev/null
|
||||
#ip route flush cache 2>&1 >/dev/null
|
||||
#ip -6 route flush cache 2>&1 >/dev/null
|
||||
fi
|
||||
if [ -n "$OMR_TRACKER_DEVICE_GATEWAY" ] && [ -n "$OMR_TRACKER_DEVICE" ] && [ "$(ip r show table 991337)" != "default via $OMR_TRACKER_DEVICE_GATEWAY dev $OMR_TRACKER_DEVICE " ]; then
|
||||
ip route replace default via $OMR_TRACKER_DEVICE_GATEWAY dev $OMR_TRACKER_DEVICE table 991337 $initcwrwnd 2>&1 >/dev/null
|
||||
ip route flush cache 2>&1 >/dev/null
|
||||
#ip route flush cache 2>&1 >/dev/null
|
||||
fi
|
||||
if [ -n "$OMR_TRACKER_DEVICE_GATEWAY6" ] && [ -n "$OMR_TRACKER_DEVICE" ] && [ "$(ip -6 r show table 991337)" != "default via $OMR_TRACKER_DEVICE_GATEWAY6 dev $OMR_TRACKER_DEVICE " ]; then
|
||||
ip -6 route replace default via $OMR_TRACKER_DEVICE_GATEWAY6 dev $OMR_TRACKER_DEVICE table 991337 $initcwrwnd 2>&1 >/dev/null
|
||||
ip -6 route flush cache 2>&1 >/dev/null
|
||||
#ip -6 route flush cache 2>&1 >/dev/null
|
||||
fi
|
||||
if ([ -n "$OMR_TRACKER_INTERFACE" ] && [ "$(uci -q get openmptcprouter.$OMR_TRACKER_INTERFACE.lc)" = "" ]) || [ $(($(date +"%s") + $((10 + RANDOM % 31)) - $(uci -q get openmptcprouter.$OMR_TRACKER_INTERFACE.lc))) -gt 3600 ] || [ "$(uci -q show openmptcprouter | grep get_config=\'1\')" != "" ] || [ "$(uci -q show openmptcprouter | grep admin_error=\'1\')" != "" ]; then
|
||||
[ "$(pgrep -f openmptcprouter-vps)" = "" ] && /etc/init.d/openmptcprouter-vps restart >/dev/null 2>&1 &
|
||||
|
@ -1201,7 +1201,7 @@ if [ -n "$OMR_TRACKER_DEVICE_IP6" ] && [ -n "$OMR_TRACKER_DEVICE_GATEWAY6" ]; th
|
|||
config_foreach set_server_route6 server
|
||||
fi
|
||||
if [ "$(uci -q get openmptcprouter.settings.defaultgw)" != "0" ] && [ -n "$OMR_TRACKER_DEVICE_GATEWAY6" ] && [ -n "$OMR_TRACKER_DEVICE" ] && [ "$(ip -6 r show dev $OMR_TRACKER_DEVICE | grep default)" = "" ] && [ -n "$OMR_TRACKER_INTERFACE" ] && [ "$(uci -q get network.$OMR_TRACKER_INTERFACE.metric)" != "" ]; then
|
||||
ip -6 r replace default via $OMR_TRACKER_DEVICE_GATEWAY6 dev $OMR_TRACKER_DEVICE metric $(uci -q get network.$OMR_TRACKER_INTERFACE.metric) >/dev/null 2>&1
|
||||
ip -6 r replace default via $OMR_TRACKER_DEVICE_GATEWAY6 dev $OMR_TRACKER_DEVICE metric 6$(uci -q get network.$OMR_TRACKER_INTERFACE.metric) >/dev/null 2>&1
|
||||
ip -6 route flush cache 2>&1 >/dev/null
|
||||
fi
|
||||
fi
|
||||
|
|
|
@ -202,8 +202,8 @@ ss_rules_nft_gen() {
|
|||
local tmp="/tmp/ssrules"
|
||||
json_init
|
||||
json_add_string o_remote_servers "$remote_servers"
|
||||
json_add_int o_redir_tcp_port "$local_port_tcp"
|
||||
json_add_int o_redir_udp_port "$local_port_udp"
|
||||
json_add_string o_redir_tcp_port "$local_port_tcp"
|
||||
json_add_string o_redir_udp_port "$local_port_udp"
|
||||
json_add_string o_ifnames "$ifnames"
|
||||
json_add_string o_local_default "$local_default"
|
||||
json_add_string o_src_bypass "$src_ips_bypass"
|
||||
|
|
|
@ -118,6 +118,20 @@ ss_rules_cb() {
|
|||
fi
|
||||
}
|
||||
|
||||
ss_redir_ports() {
|
||||
port=$(uci -q get shadowsocks-rust.$1.local_port)
|
||||
server=$(uci -q get shadowsocks-rust.$1.server)
|
||||
disabled=$(uci -q get shadowsocks-rust.$1.disabled)
|
||||
if [ "$disabled" != "1" ] && ([ "$server" = "$2" ] || [ "$2" = "" ]); then
|
||||
if [ "$port" -lt "$min_ss_redir_ports" ]; then
|
||||
min_ss_redir_ports=$port
|
||||
fi
|
||||
if [ "$port" -gt "$max_ss_redir_ports" ]; then
|
||||
max_ss_redir_ports=$port
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
ss_rules_nft_gen() {
|
||||
local cfg="ss_rules"
|
||||
local cfgtype
|
||||
|
@ -129,8 +143,26 @@ ss_rules_nft_gen() {
|
|||
eval "$(validate_ss_rules_section "$cfg" ss_validate_mklocal)"
|
||||
validate_ss_rules_section "$cfg" || return 1
|
||||
[ "$disabled" = 0 ] || return 2
|
||||
eval local_port_tcp="\$ss_rules_redir_tcp_$redir_tcp"
|
||||
eval local_port_udp="\$ss_rules_redir_udp_$redir_udp"
|
||||
|
||||
if [ "$ss_rules_redir_tcp_$redir_tcp" = "all" ]; then
|
||||
min_ss_redir_ports="65535"
|
||||
max_ss_redir_ports="0"
|
||||
config_load shadowsocks-rust
|
||||
config_foreach ss_redir_ports ss_redir $cfgrulesserver
|
||||
if [ "$min_ss_redir_ports" != "$max_ss_redir_ports" ]; then
|
||||
all_ss_redir_ports=$min_ss_redir_ports-$max_ss_redir_ports
|
||||
else
|
||||
all_ss_redir_ports=$min_ss_redir_ports
|
||||
fi
|
||||
local_port_tcp="$all_ss_redir_ports"
|
||||
if [ "$ss_rules_redir_udp_$redir_udp" = "all" ] || [ "$ss_rules_redir_udp_$redir_udp" = "hi1" ]; then
|
||||
local_port_udp="$min_ss_redir_ports"
|
||||
fi
|
||||
else
|
||||
eval local_port_tcp="\$ss_rules_redir_tcp_$redir_tcp"
|
||||
eval local_port_udp="\$ss_rules_redir_udp_$redir_udp"
|
||||
fi
|
||||
|
||||
[ -n "$local_port_tcp" -o -n "$local_port_udp" ] || return 1
|
||||
remote_servers="$(echo $ss_redir_servers \
|
||||
| tr ' ' '\n' \
|
||||
|
@ -141,8 +173,8 @@ ss_rules_nft_gen() {
|
|||
local tmp="/tmp/ssrrules"
|
||||
json_init
|
||||
json_add_string o_remote_servers "$remote_servers"
|
||||
json_add_int o_redir_tcp_port "$local_port_tcp"
|
||||
json_add_int o_redir_udp_port "$local_port_udp"
|
||||
json_add_string o_redir_tcp_port "$local_port_tcp"
|
||||
json_add_string o_redir_udp_port "$local_port_udp"
|
||||
json_add_string o_ifnames "$ifnames"
|
||||
json_add_string o_local_default "$local_default"
|
||||
json_add_string o_src_bypass "$src_ips_bypass"
|
||||
|
@ -326,8 +358,8 @@ validate_ss_redir_section() {
|
|||
validate_ss_rules_section() {
|
||||
"${2:-ss_validate}" ss_rules "$1" \
|
||||
'disabled:bool:0' \
|
||||
'redir_tcp:uci("shadowsocks-rust", "@ss_redir")' \
|
||||
'redir_udp:uci("shadowsocks-rust", "@ss_redir")' \
|
||||
'redir_tcp:or(uci("shadowsocks-rust", "@ss_redir"),"all")' \
|
||||
'redir_udp:or(uci("shadowsocks-rust", "@ss_redir"),"all")' \
|
||||
'src_ips_bypass:or(ipaddr,cidr)' \
|
||||
'src_ips_forward:or(ipaddr,cidr)' \
|
||||
'src_ips_checkdst:or(ipaddr,cidr)' \
|
||||
|
|
Loading…
Reference in a new issue