On Sun, May 18, 2008 at 12:14:08PM +0200, Bastian Bittorf wrote:
> I've also added one more netmsg and moved the
> netmsg direct into the function, for not having
> two different places for the broadcast-address.
> 
> Signed-off-by: Bastian Bittorf <[EMAIL PROTECTED]>
> 
> ---
> 
> Index: package/base-files/files/etc/preinit
> ===================================================================
> --- package/base-files/files/etc/preinit      (Revision 11157)
> +++ package/base-files/files/etc/preinit      (Arbeitskopie)
> @@ -1,18 +1,35 @@
>  #!/bin/sh
>  # Copyright (C) 2006 OpenWrt.org
> +
>  export PATH=/bin:/sbin:/usr/bin:/usr/sbin
>  . /etc/diag.sh
>  
> -failsafe_ip() {
> -     ifconfig $ifname 192.168.1.1 netmask 255.255.255.0 broadcast 
> 192.168.1.255 up
> +failsafe_ip ()
> +{
> +     local    DEVICE="$1"                                            # ARG1
> +     local        IP="192.168.1.1"
> +     local      MASK="255.255.255.0"
> +     local BROADCAST="$( /bin/ipcalc.sh $IP $MASK | sed -n 
> 's/^BROADCAST=\(.*\)/\1/p' )"
> +     local       PRE="$( /bin/ipcalc.sh $IP $MASK | sed -n 
> 's/^PREFIX=\(.*\)/\1/p'    )"
> +
> +     ifconfig $DEVICE $IP netmask $MASK broadcast $BROADCAST up || {
> +                                                                     # 
> ifconfig n/a -> fallback to ip
> +             ip addr add dev $DEVICE $IP/$PRE broadcast +            # 
> broadcast is calculated (is this clean? we calc it anyway)
> +             ip link set dev $DEVICE arp on                          # maybe 
> not necessary
> +             ip link set dev $DEVICE up
> +     }
> +
> +     netmsg $BROADCAST "set up $IP/$PRE dev $DEVICE"                 # 
> would'nt it be better to send
> +     netmsg $BROADCAST "Entering Failsafe!"                          # this 
> messages to 255.255.255.255 ?
>  }
>  
> -failsafe() {
> +failsafe ()
> +{
>       [ -n "$ifname" ] && grep "$ifname" /proc/net/dev >/dev/null && {
> -             failsafe_ip
> -             netmsg 192.168.1.255 "Entering Failsafe!"
> +             failsafe_ip $ifname
>               telnetd -l /bin/login <> /dev/null 2>&1
>       }
> +
>       lock /tmp/.failsafe
>       ash --login
>  }
> 

It's important to note that failsafe is only to be used as failsafe and
that proper network configuration is handled by the uci system after
bootup. The purpose of the failsafe routine is to provide the simplest
possible configuration when the device fails to boot properly. There are
two functions involved; failsafe and failsafe_ip, both of which may be
redefined by the platform specific code in preinit.arch; what exists
above is merely a stub function.

A simple ifconfig as used by the failsafe_ip above will either work
perfectly the first time or fail completely. Considering the simplicity
of the command, if it fails there really isn't anything that can be done
to fix networking.  I don't understand why you're attempting to set it
again using the ip commands, and I'm even more confused by the need to
call ipcalc to calculate information which was hardcoded only a few
lines above.

The used of the failsafe_ip address does not indicate the device is in
failsafe modem the use of netmsg in failsafe_ip is incorrect in that
regard. As an example, the broadcom platforms will configure the network
using failsafe_ip for the sole purpose of sending out the netmsg letting
users know how to enter failsafe mode.

It does not make sense to send a netmsg outside of the local broadcast
since there is no upstream gateway configured.
_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
http://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel

Reply via email to