this is a bit more, integrating fallback for
ifconfig AND route...this script needs some rewrite,
because it was and is ugly in some sections

bye, Bastian <[EMAIL PROTECTED]>

Index: package/base-files/files/usr/share/udhcpc/default.script
===================================================================
--- package/base-files/files/usr/share/udhcpc/default.script    (Revision 11157)
+++ package/base-files/files/usr/share/udhcpc/default.script    (Arbeitskopie)
@@ -27,6 +27,12 @@
 case "$1" in
        deconfig)
                ifconfig $interface 0.0.0.0
+
+               [ "$?" -ne 0 ] && {                     # returncode not 0 -> 
ifconfig n/a -> fallback using ip
+                       
+                       ip addr flush dev $interface
+               }
+
                hotplug_event ifdown
        ;;
        renew|bound)
@@ -34,16 +40,51 @@
                netmask ${subnet:-255.255.255.0} \
                broadcast ${broadcast:-+}
 
+               [ "$?" -ne 0 ] && {                     # returncode not 0 -> 
ifconfig n/a -> fallback using ip
+
+                       PRE="$( /bin/ipcalc.sh $ip ${subnet:-255.255.255.0} | 
sed -n 's/^PREFIX=\(.*\)/\1/p' )"
+
+                       ip addr add dev $interface ${ip}/${PRE} broadcast +
+               }
+
                [ -n "$router" ] && {
                        for i in $router ; do
                                echo "adding router $i"
                                route add default gw $i dev $interface
-                               valid="$valid|$i"
 
+                               [ "$?" -ne 0 ] && {     # returncode not 0 -> 
route n/a -> fallback using ip
+
+                                       ip route add default via "$i" dev 
"$interface"
+                               }
+
+                               valid="$valid|$i"       # leads to: 
"ip_1|ip_2|ip_n"
+
                        done
 
+                       #
+                       # this section needs a refactoring,
+                       # because it is unreadable
+                       #
+
                        echo "deleting old routes"
+
+                       # this leads to something like:
+                       # route del -net 0.0.0.0 gw 1.2.3.4 ; ...
+
                        $(route -n | awk '/^0.0.0.0\W{9}('$valid')\W/ {next} 
/^0.0.0.0/ {print "route del -net "$1" gw "$2";"}')
+               
+                       [ "$?" -ne 0 ] && {             # returncode not 0 -> 
route n/a -> fallback using ip
+                       
+                               IFS="|"                 # field separator, set
+                               for IP in $valid; do
+                       
+                                       # leads to something like:
+                                       # ip route del default via 1.2.3.4 dev 
br0  ; ...
+
+                                       $( ip route list exact 0/0 via $IP | 
sed "s/default dev \(.*\)/ip route del default via $IP dev \1 ;/" )        
+                               done
+                               unset IFS               # back to normal 
separator
+                       }
                }
                
                [ -n "$dns" ] && {

Attachment: signature.asc
Description: Digital signature

_______________________________________________
openwrt-devel mailing list
[email protected]
http://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel

Reply via email to