1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-03-09 15:40:03 +00:00
This commit is contained in:
Ycarus 2018-02-23 14:32:22 +01:00
parent 08470e93c7
commit 3e87739229
3 changed files with 43 additions and 178 deletions

View file

@ -1,42 +0,0 @@
#!/bin/sh
# vim: set noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 :
. /lib/functions.sh
config_load network
_setup_macaddr() {
uci -q get "network.$1_dev.macaddr" >/dev/null && return
uci -q set "network.$1_dev.macaddr=$2"
}
# Configuration by interface
_setup_interface() {
uci -q get "network.$1_dev.ifname" >/dev/null && return
# do not create macvlan for vlan
local _ifname
config_get _ifname "$1" ifname
case "$_ifname" in
eth*.*) return ;;
esac
local _type
config_get _type "$1" type
[ "$_type" = "macvlan" ] || return 0
uci -q batch <<-EOF
set network.$1_dev=device
set network.$1_dev.name=$1
set network.$1_dev.type=macvlan
set network.$1_dev.ifname=eth0
set network.$1.ifname=$1
set network.$1.defaultroute=0
EOF
_macaddr=$(uci -q get "network.$1.macaddr")
_setup_macaddr "$1" "${_macaddr:-auto$(date +%s)}"
uci -q set "network.$1.type=macvlan" # legacy
uci -q commit network
}
config_foreach _setup_interface interface

View file

@ -1,89 +0,0 @@
#!/bin/sh
#
# Load the multipath config
#
# Author: Mario Krueger <openwrt at xedp3x.de>
# Released under GPL 3 or later
[ "$ACTION" = ifup -o "$ACTION" = ifupdate ] || exit 0
enable=`uci -q get network.globals.multipath` || exit 0
[ "$enable" = "enable" ] || exit 0
. /lib/functions.sh
. /lib/functions/network.sh
id=0
count=1
set_default() {
local mode
local config="$1"
count=$(($count+1))
local iface
config_get iface "$config" ifname
[ "$iface" = "$INTERFACE" ] && id=$count
config_get mode "$config" multipath
[ "$mode" = "master" ] && {
local gateway
network_get_gateway gateway $config || {
logger -t multipath master device $DEVICE has no gateway!
#Fallback: use upcomming interface...
network_get_gateway gateway $INTERFACE
config=$INTERFACE
}
local iface
config_get iface "$config" ifname
[ -n "gateway" ] && {
ip route replace default via $gateway dev $iface || {
#Fallback: use upcomming interface...
network_get_gateway gateway $INTERFACE
ip route replace default via $gateway dev $INTERFACE
logger -t multipath Failed to set default multipath device! Use $INTERFACE as fallback...
}
}
}
}
config_load network
config_foreach set_default interface
[ $id = 0 ] && {
logger -t multipath device $INTERFACE not found!
echo device $INTERFACE not found!
exit 1
}
mode=`uci -q get network.$INTERFACE.multipath` || mode='off'
[ -n "$(ifconfig | grep $DEVICE)" ] || exit 0
case "$mode" in
"off")
multipath $DEVICE off
exit 0;;
"master")
mode="on";;
"on");;
"backup");;
"handover");;
*)
logger -t multipath Wrong multipath value for device $DEVICE
exit 1;;
esac
# Update kernel flags
multipath $DEVICE $mode
# IPv4 Updates:
network_get_ipaddr ipaddr $INTERFACE
network_get_gateway gateway $INTERFACE
network_get_subnet network $INTERFACE
__network_ifstatus netmask $INTERFACE "['ipv4-address'][0]['mask']"
network=`ipcalc.sh $network | sed -n '/NETWORK=/{;s/.*=//;s/ .*//;p;}'`
ip rule del table $id
ip route flush $id
ip rule add from $ipaddr table $id
ip route add $network/$netmask dev $DEVICE scope link table $id
ip route add default via $gateway dev $DEVICE table $id
ip route flush $id

View file

@ -22,24 +22,60 @@ set_default() {
count=$(($count+1)) count=$(($count+1))
local iface local iface
config_get iface "$config" ifname config_get iface "$config" ifname
[ "$iface" = "$INTERFACE" ] && id=$count id=$count
config_get mode "$config" multipath config_get mode "$config" multipath
mode=`uci -q get network.$config.multipath` || mode='off'
[ -n "$(ifconfig | grep $iface)" ] || return 1
case "$mode" in
"off")
multipath $iface off
return 1;;
"master")
mode="on";;
"on");;
"backup");;
"handover");;
*)
logger -t multipath Wrong multipath value for device $iface
return 1;;
esac
# Update kernel flags
multipath $iface $mode
# IPv4 Updates:
local ipaddr
local gateway
local network
local netmask
network_get_ipaddr ipaddr $config
network_get_gateway gateway $config
network_get_subnet network $config
__network_ifstatus netmask $config "['ipv4-address'][0]['mask']"
network=`ipcalc.sh $network | sed -n '/NETWORK=/{;s/.*=//;s/ .*//;p;}'`
ip rule del table $id
ip route flush $id
ip rule add from $ipaddr table $id
ip route add $network/$netmask dev $iface scope link table $id
ip route add default via $gateway dev $iface table $id
ip route flush $id
[ "$mode" = "master" ] && { [ "$mode" = "master" ] && {
local gateway local gateway
network_get_gateway gateway $config || { network_get_gateway gateway $config || {
logger -t multipath master device $DEVICE has no gateway! logger -t multipath master device $iface has no gateway!
#Fallback: use upcomming interface... #Fallback: use upcomming interface...
network_get_gateway gateway $INTERFACE network_get_gateway gateway $config
config=$INTERFACE config=$config
} }
local iface local iface
config_get iface "$config" ifname config_get iface "$config" ifname
[ -n "gateway" ] && { [ -n "gateway" ] && {
ip route replace default via $gateway dev $iface || { ip route replace default via $gateway dev $iface || {
#Fallback: use upcomming interface... #Fallback: use upcomming interface...
network_get_gateway gateway $INTERFACE network_get_gateway gateway $config
ip route replace default via $gateway dev $INTERFACE ip route replace default via $gateway dev $iface
logger -t multipath Failed to set default multipath device! Use $INTERFACE as fallback... logger -t multipath Failed to set default multipath device! Use $iface as fallback...
} }
} }
} }
@ -47,43 +83,3 @@ set_default() {
config_load network config_load network
config_foreach set_default interface config_foreach set_default interface
[ $id = 0 ] && {
logger -t multipath device $INTERFACE not found!
echo device $INTERFACE not found!
exit 1
}
mode=`uci -q get network.$INTERFACE.multipath` || mode='off'
[ -n "$(ifconfig | grep $DEVICE)" ] || exit 0
case "$mode" in
"off")
multipath $DEVICE off
exit 0;;
"master")
mode="on";;
"on");;
"backup");;
"handover");;
*)
logger -t multipath Wrong multipath value for device $DEVICE
exit 1;;
esac
# Update kernel flags
multipath $DEVICE $mode
# IPv4 Updates:
network_get_ipaddr ipaddr $INTERFACE
network_get_gateway gateway $INTERFACE
network_get_subnet network $INTERFACE
__network_ifstatus netmask $INTERFACE "['ipv4-address'][0]['mask']"
network=`ipcalc.sh $network | sed -n '/NETWORK=/{;s/.*=//;s/ .*//;p;}'`
ip rule del table $id
ip route flush $id
ip rule add from $ipaddr table $id
ip route add $network/$netmask dev $DEVICE scope link table $id
ip route add default via $gateway dev $DEVICE table $id
ip route flush $id