1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-02-14 19:41:51 +00:00
This commit is contained in:
Ycarus 2018-02-23 13:53:33 +01:00
parent 4418b1e0fb
commit 0d2b2e3e68
6 changed files with 139 additions and 10 deletions

View file

@ -37,5 +37,6 @@ _setup_interface() {
_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

@ -0,0 +1,42 @@
#!/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

@ -54,6 +54,7 @@ config_foreach set_default interface
}
mode=`uci -q get network.$INTERFACE.multipath` || mode='off'
[ -n "$(ifconfig | grep $DEVICE)" ] || exit 0
case "$mode" in
"off")

2
mptcp/files/etc/hotplug.d/net/03-mptcp Executable file → Normal file
View file

@ -27,7 +27,7 @@ _setup_interface() {
device=
config_get device "$1" ifname
[ -z "$device" ] && return 0
[ -n "$(config | grep $device)" ] || return 0
if_multipath=
config_get if_multipath "$1" multipath "off"
[ "$if_multipath" = "master" ] && if_multipath="on"

View file

@ -0,0 +1,89 @@
#!/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

@ -1,21 +1,17 @@
#!/bin/sh /etc/rc.common
START=20
STOP=90
START=10
USE_PROCD=1
start_service() {
procd_open_instance
procd_set_param command hotplug-call net
procd_set_param watch network.globals
procd_close_instance
hotplug-call net
}
reload_service() {
ubus call network reload
start
}
service_running() {
ubus -t 30 wait_for network
service_triggers() {
procd_add_reload_trigger network
}