1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-03-09 15:40:03 +00:00

Add support for ncm created interfaces

This commit is contained in:
Ycarus 2018-07-23 17:37:37 +02:00
parent 602a83668e
commit 96781551c1
3 changed files with 21 additions and 4 deletions

View file

@ -73,12 +73,14 @@ interface_multipath_settings() {
[ -z "$gateway" ] && gateway=$(uci -q get "network.$config.gateway")
[ -z "$gateway" ] && gateway=$(ubus call network.interface.$config status | jsonfilter -q -e '@.route[0].nexthop' | tr -d "\n")
[ -z "$gateway" ] && gateway=$(ubus call network.interface.$config status | jsonfilter -q -e '@.inactive.route[0].nexthop' | tr -d "\n")
[ -z "$gateway" ] && gateway=$(ubus call network.interface.${config}_4 status | jsonfilter -q -e '@.inactive.route[0].nexthop' | tr -d "\n")
netmask=$(ip -4 addr show dev $iface | grep inet | awk '{print $2}' | cut -d/ -f2 | tr -d "\n")
network=`ipcalc.sh $ipaddr $netmask | sed -n '/NETWORK=/{;s/.*=//;s/ .*//;p;}'`
fi
ip rule del table $id > /dev/null 2>&1
ip route flush $id > /dev/null 2>&1
[ -n "$gateway" ] || return 1
[ -n "$network" ] || return 1
ip rule add from $ipaddr table $id
ip route replace $network/$netmask dev $iface scope link table $id
ip route replace default via $gateway dev $iface table $id

View file

@ -8,6 +8,7 @@ set_route() {
multipath_config=$(uci -q get network.$INTERFACE.multipath || echo "off")
interface_if=$(uci -q get network.$INTERFACE.ifname)
[ -z "$interface_if" ] && interface_if=$(ifstatus "$INTERFACE" | jsonfilter -q -e '@["l3_device"]')
[ -z "$interface_if" ] && interface_if=$(ifstatus "${INTERFACE}_4" | jsonfilter -q -e '@["l3_device"]')
multipath_current_config=$(multipath $interface_if | grep deactivated)
if [ "$multipath_config" != "off" ] && [ "$SETROUTE" != true ] && [ "$INTERFACE" != "$PREVINTERFACE" ] && [ "$multipath_current_config" = "" ]; then
#if [ "$multipath_config" != "off" ] && [ "$SETROUTE" != true ]; then
@ -19,6 +20,9 @@ set_route() {
if [ -z "$interface_gw" ]; then
interface_gw=$(ubus call network.interface.$INTERFACE status | jsonfilter -q -e '@.inactive.route[0].nexthop' | tr -d "\n")
fi
if [ -z "$interface_gw" ]; then
interface_gw=$(ubus call network.interface.${INTERFACE}_4 status | jsonfilter -q -e '@.inactive.route[0].nexthop' | tr -d "\n")
fi
if [ "$interface_gw" != "" ]; then
_log "$PREVINTERFACE down. Replace default route by $interface_gw dev $interface_if"
ip route replace default scope global nexthop via $interface_gw dev $interface_if && SETROUTE=true
@ -31,6 +35,8 @@ set_route() {
set_ss_route() {
local server_ip upstreams nginxip
local metric $2
[ -z "$metric" ] && metric=1
config_get server_ip $1 server
if [ "$server_ip" = "127.0.0.1" ]; then
upstreams=$(uci -q get nginx-ha.ShadowSocks.upstreams | sed -e "s/' '/%/" -e 's/ /_/g' -e "s/'//g" -e 's/%/ /')
@ -39,19 +45,21 @@ set_ss_route() {
nginxip=$(echo $up | cut -d: -f1)
if [ "$nginxip" != "" ] && [ "$OMR_TRACKER_DEVICE_GATEWAY" != "" ] && [ "$(ip route show dev $OMR_TRACKER_DEVICE | grep $nginxip | grep $OMR_TRACKER_DEVICE_GATEWAY)" = "" ]; then
_log "Set server $nginxip route via $OMR_TRACKER_DEVICE"
ip route replace $nginxip via $OMR_TRACKER_DEVICE_GATEWAY dev $OMR_TRACKER_DEVICE
ip route replace $nginxip via $OMR_TRACKER_DEVICE_GATEWAY dev $OMR_TRACKER_DEVICE metric $metric
fi
done
else
if [ "$server_ip" != "" ] && [ "$OMR_TRACKER_DEVICE_GATEWAY" != "" ] && [ "$(ip route show dev $OMR_TRACKER_DEVICE | grep $server_ip | grep $OMR_TRACKER_DEVICE_GATEWAY)" = "" ]; then
_log "Set server $server_ip route via $OMR_TRACKER_DEVICE"
ip route replace $server_ip via $OMR_TRACKER_DEVICE_GATEWAY dev $OMR_TRACKER_DEVICE
ip route replace $server_ip via $OMR_TRACKER_DEVICE_GATEWAY dev $OMR_TRACKER_DEVICE metric $metric
fi
fi
}
del_ss_route() {
local server_ip upstreams nginxip
local metric $2
[ -z "$metric" ] && metric=1
config_get server_ip $1 server
if [ "$server_ip" = "127.0.0.1" ]; then
upstreams=$(uci -q get nginx-ha.ShadowSocks.upstreams | sed -e "s/' '/%/" -e 's/ /_/g' -e "s/'//g" -e 's/%/ /')
@ -60,13 +68,13 @@ del_ss_route() {
nginxip=$(echo $up | cut -d: -f1)
if [ "$nginxip" != "" ] && [ "$(ip route show dev $OMR_TRACKER_DEVICE | grep $nginxip)" != "" ]; then
_log "Remove server $nginxip route via $OMR_TRACKER_DEVICE"
ip route delete $nginxip dev $OMR_TRACKER_DEVICE
ip route delete $nginxip dev $OMR_TRACKER_DEVICE metric $metric
fi
done
else
if [ "$server_ip" != "" ] && [ "$(ip route show dev $OMR_TRACKER_DEVICE | grep $server_ip)" != "" ]; then
_log "Remove server $server_ip route via $OMR_TRACKER_DEVICE"
ip route delete $server_ip dev $OMR_TRACKER_DEVICE
ip route delete $server_ip dev $OMR_TRACKER_DEVICE metric $metric
fi
fi
}
@ -142,6 +150,10 @@ if [ "$multipath_config" = "master" ]; then
fi
fi
multipath_config="on"
else
local metric=$(ip rule show | grep $OMR_TRACKER_DEVICE_GATEWAY | awk '{print $5}')
config_load shadowsocks-libev
config_foreach set_ss_route server $metric
fi
if [ "$(uci -q get omr-bypass.defaults.ifname)" = "$OMR_TRACKER_DEVICE" ] && [ "$(ip route show table 991337 | grep $OMR_TRACKER_DEVICE_GATEWAY)" = "" ]; then
ip route replace default via $OMR_TRACKER_DEVICE_GATEWAY dev $OMR_TRACKER_DEVICE table 991337

View file

@ -157,6 +157,9 @@ while true; do
if [ -z "$OMR_TRACKER_DEVICE_GATEWAY" ]; then
OMR_TRACKER_DEVICE_GATEWAY=$(ubus call network.interface.$OMR_TRACKER_INTERFACE status | jsonfilter -q -e '@.inactive.route[0].nexthop' | tr -d "\n")
fi
if [ -z "$OMR_TRACKER_DEVICE_GATEWAY" ]; then
OMR_TRACKER_DEVICE_GATEWAY=$(ubus call network.interface.${OMR_TRACKER_INTERFACE}_4 status | jsonfilter -q -e '@.inactive.route[0].nexthop' | tr -d "\n")
fi
# execute specific tracker
if [ -n "$OMR_TRACKER_DEVICE_IP" ] && [ -n "$OMR_TRACKER_DEVICE_GATEWAY" ]; then