MWAN with netifd

  • Implement multi-WAN based on PBR with netifd.
  • Support dual-stack setups using IPv4 and IPv6.
  • Perform connectivity check with ICMP and ICMPv6.
  • Provide a simple failover method.

Assuming pre-configured upstream interfaces. Set up PBR with netifd using PBR extras. Save the failover script. Configure cron to run the failover script. Specify the managed interfaces.

# Failover script
cat << "EOF" > /etc/hotplug.d/iface/80-mwan
iface_proc() {
local NET_IF="${1}"
local NET_RT
local NET_OK
for IPV in 4 6
do NET_OK="$(eval echo "\${NET_OK${IPV}}")"
if [ -z "${NET_OK}" ] \
&& iface_check "${NET_IF}"
then eval NET_OK"${IPV}"="1"
NET_RT="$(uci -q get network."${NET_IF}".ip"${IPV}"table)"
uci set network.default"${IPV%4}".lookup="${NET_RT}"
service network reload
fi
done
}
 
iface_check() {
local PING_IF="${1}"
local PING_CNT="2"
local PING_WAIT="3"
local PING_SRC
local PING_DST
eval network_get_ipaddr"${IPV%4}" PING_SRC "${PING_IF}"
eval network_get_gateway"${IPV%4}" PING_DST "${PING_IF}"
case "${PING_DST}" in
(0.0.0.0) PING_DST="${NET_HOST%% *}" ;;
(::) PING_DST="${NET_HOST##* }" ;;
esac
ping -q -c "${PING_CNT}" -W "${PING_WAIT}" \
-I "${PING_SRC}" "${PING_DST}" &> /dev/null
}
 
NET_IF="$(uci -q get network.mwan.iface)"
NET_HOST="$(uci -q get network.mwan.host)"
. /lib/functions/network.sh
network_flush_cache
for NET_IF in ${NET_IF}
do iface_proc "${NET_IF}"
done
EOF
cat << "EOF" >> /etc/sysupgrade.conf
/etc/hotplug.d/iface/80-mwan
EOF
 
# Configure cron
cat << "EOF" >> /etc/crontabs/root
* * * * * . /etc/hotplug.d/iface/80-mwan
EOF
uci set system.@system[0].cronloglevel="9"
uci commit system
service cron restart
# Configure interfaces
NET_IF="wana wana6 wanb wanb6 wanc wanc6"
NET_HOST="8.8.8.8 2001:4860:4860::8888"
uci -q delete network.mwan
uci set network.mwan="mwan"
for NET_IF in ${NET_IF}
do uci add_list network.mwan.iface="${NET_IF}"
done
for NET_HOST in ${NET_HOST}
do uci add_list network.mwan.host="${NET_HOST}"
done
uci commit network
service network restart
wget -U "" -O mwan-netifd.sh "https://openwrt.org/_export/code/docs/guide-user/network/wan/multiwan/mwan_netifd?codeblock=0"
. ./mwan-netifd.sh
This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
  • Last modified: 2023/11/19 02:02
  • by vgaetera