From: <abe...@us...> - 2014-11-04 20:33:18
|
Revision: 6798 http://sourceforge.net/p/astlinux/code/6798 Author: abelbeck Date: 2014-11-04 20:33:14 +0000 (Tue, 04 Nov 2014) Log Message: ----------- network, fix long term issues with dual-WAN's, with dual-DHCP only EXTIF updates /tmp/mydhcpip and DNS files, with DHCP and Static addressing only EXTIF sets the default route, two new variables: EXT2ROUTES and EXT2ROUTESIPV6 allow setting EXT2IF static routes via Static and DHCP Modified Paths: -------------- branches/1.0/project/astlinux/target_skeleton/etc/init.d/network branches/1.0/project/astlinux/target_skeleton/etc/udhcpc.script branches/1.0/project/astlinux/target_skeleton/stat/etc/rc.conf Modified: branches/1.0/project/astlinux/target_skeleton/etc/init.d/network =================================================================== --- branches/1.0/project/astlinux/target_skeleton/etc/init.d/network 2014-11-04 03:45:02 UTC (rev 6797) +++ branches/1.0/project/astlinux/target_skeleton/etc/init.d/network 2014-11-04 20:33:14 UTC (rev 6798) @@ -483,10 +483,14 @@ esac if [ -n "$EXT2GW" ]; then - ip route add default via $EXT2GW dev $EXT2IF + for x in $EXT2ROUTES; do + ip route add $x via $EXT2GW dev $EXT2IF + done fi if [ "$IPV6" = "yes" -a -n "$EXT2GWIPV6" ]; then - ip -6 route add default via $EXT2GWIPV6 dev $EXT2IF metric 1 + for x in $EXT2ROUTESIPV6; do + ip -6 route add $x via $EXT2GWIPV6 dev $EXT2IF metric 1 + done fi #end static ip on 2nd if fi @@ -511,7 +515,9 @@ # No DHCPv6 - Static IPv6 if defined if [ "$IPV6" = "yes" -a -n "$EXT2IPV6" -a -n "$EXT2GWIPV6" ]; then ip -6 addr add $EXT2IPV6 dev $EXT2IF - ip -6 route add default via $EXT2GWIPV6 dev $EXT2IF metric 1 + for x in $EXT2ROUTESIPV6; do + ip -6 route add $x via $EXT2GWIPV6 dev $EXT2IF metric 1 + done fi fi Modified: branches/1.0/project/astlinux/target_skeleton/etc/udhcpc.script =================================================================== --- branches/1.0/project/astlinux/target_skeleton/etc/udhcpc.script 2014-11-04 03:45:02 UTC (rev 6797) +++ branches/1.0/project/astlinux/target_skeleton/etc/udhcpc.script 2014-11-04 20:33:14 UTC (rev 6798) @@ -5,6 +5,8 @@ [ -z "$1" ] && echo "Error: should be called from udhcpc" && exit 1 +. /etc/rc.conf + resolv_conf="/tmp/etc/resolv-up.conf" udhcpc_conf="/tmp/udhcpc-${interface}.conf" @@ -13,7 +15,10 @@ deconfig) /sbin/ip link set dev ${interface} up /sbin/ip -4 addr flush dev ${interface} scope global - rm -f /tmp/mydhcpip "$udhcpc_conf" + if [ "$EXTIF" = "${interface}" ]; then + rm -f /tmp/mydhcpip + fi + rm -f "$udhcpc_conf" ;; renew|bound) @@ -26,27 +31,46 @@ else OLDGW="" fi - echo "${ip}" > /tmp/mydhcpip + if [ "$EXTIF" = "${interface}" ]; then + echo "${ip}" > /tmp/mydhcpip + fi echo "IP=${ip} BCAST=${broadcast} NETMASK=${subnet}" > "$udhcpc_conf" if [ -n "${router}" ]; then - # Delete existing default route(s) - while /sbin/ip route del default dev ${interface} >/dev/null 2>&1; do - : - done + if [ "$EXTIF" = "${interface}" ]; then + # Delete existing default route(s) + /sbin/ip route list dev ${interface} | grep '^default .*via ' | while read x; do + /sbin/ip route delete ${x} dev ${interface} >/dev/null 2>&1 + done + else + # Delete optional route(s) + /sbin/ip route list dev ${interface} | grep ' via ' | while read x; do + /sbin/ip route delete ${x} dev ${interface} >/dev/null 2>&1 + done + fi NEWGW="" metric=0 for i in ${router}; do - echo "udhcpc: adding route via ${i}" - /sbin/ip route add default via ${i} dev ${interface} metric $((metric++)) + if [ "$EXTIF" = "${interface}" ]; then + echo "udhcpc: adding default route via ${i}" + /sbin/ip route add default via ${i} dev ${interface} metric $metric + else + for x in $EXT2ROUTES; do + echo "udhcpc: adding ${x} route via ${i}" + /sbin/ip route add ${x} via ${i} dev ${interface} metric $metric + done + fi + metric=$((metric+1)) echo "GW=${i}" >> "$udhcpc_conf" if [ -z "$NEWGW" ]; then NEWGW="${i}" fi done + + # Restart Failover script if running and if the gateway changed if [ -f /var/run/wan-failover.pid ]; then if [ "$OLDGW" != "$NEWGW" ]; then /etc/init.d/failover restart @@ -54,13 +78,21 @@ fi fi - echo -n "" > "$resolv_conf" + if [ "$EXTIF" = "${interface}" ]; then + : > "$resolv_conf" + if [ -n "${domain}" ]; then + echo "search ${domain}" >> "$resolv_conf" + fi + for i in ${dns}; do + echo "udhcpc: adding resolver ${i}" + echo "nameserver ${i}" >> "$resolv_conf" + done + fi + if [ -n "${domain}" ]; then - echo "search ${domain}" >> "$resolv_conf" + echo "DOMAIN=${domain}" >> "$udhcpc_conf" fi for i in ${dns}; do - echo "udhcpc: adding resolver ${i}" - echo "nameserver ${i}" >> "$resolv_conf" echo "DNS=${i}" >> "$udhcpc_conf" done ;; Modified: branches/1.0/project/astlinux/target_skeleton/stat/etc/rc.conf =================================================================== --- branches/1.0/project/astlinux/target_skeleton/stat/etc/rc.conf 2014-11-04 03:45:02 UTC (rev 6797) +++ branches/1.0/project/astlinux/target_skeleton/stat/etc/rc.conf 2014-11-04 20:33:14 UTC (rev 6798) @@ -152,6 +152,8 @@ #EXT2IP="192.168.25.2" #EXT2NM="255.255.255.0" #EXT2GW="192.168.25.1" +## Optionally add static destination routes via EXT2GW or via DHCP +#EXT2ROUTES="1.2.3.4 9.9.9.0/30" ## WAN Failover ## Monitor external "targets" to switch between primary and secondary default gateways @@ -221,6 +223,8 @@ #EXTGWIPV6="2001:db8:100::1" #EXT2IPV6="2001:db8:2::1/64" #EXT2GWIPV6="2001:db8:200::1" +## Optionally add static destination routes via EXT2GWIPV6 +#EXT2ROUTESIPV6="2001:db8:f::1 2001:db8::1/96" ## ## Internal IPv6 addresses #INTIPV6="2001:db8:10::1/64" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |