udhcpc usage
Denys Vlasenko
vda.linux at googlemail.com
Thu Apr 16 19:59:37 UTC 2009
On Wednesday 15 April 2009 19:28, Guenter wrote:
> Hi Walter,
> walter harms schrieb:
> > basicly the script should call ipconfig somewhere.
> > can you echo that line ?
> I use this script from busybox distro:
> http://sources.busybox.net/index.py/branches/busybox_1_13_stable/examples/udhcp/simple.script?revision=23979&view=markup
>
> > That shoulk clearly show what is going on.
> it was enough the add a line to echo the $broadcast var to see that is
> seems not set from udhcpc, thus ifconfig does it on its own, and gives
> the previous described result ending up with a B broadcast with a C
> mask. You can easily re-create this behaviour of busybox ifconfig from
> commandline when you ommit the broadcast:
> ifconfig eth0 172.16.0.1 netmask 255.255.255.0
> ifconfig eth0
> eth0 Link encap:Ethernet HWaddr 00:BA:BE:FA:CE:01
> inet addr:172.16.0.1 Bcast:172.16.255.255 Mask:255.255.255.0
>
> ifconfig eth0 192.168.0.1 netmask 255.255.255.0
> ifconfig eth0
> eth0 Link encap:Ethernet HWaddr 00:BA:BE:FA:CE:01
> inet addr:192.168.0.1 Bcast:192.168.0.255 Mask:255.255.255.0
>
> The setting CONFIG_FEATURE_IFCONFIG_BROADCAST_PLUS=y seems not to matter
> here although looking at the code I found this part:
>
> #if ENABLE_FEATURE_IFCONFIG_BROADCAST_PLUS
> else if ((host[0] == '+' && !host[1]) && (mask &
> A_BROADCAST)
> && (did_flags & (A_NETMASK|A_HOSTNAME)) ==
> (A_NETMASK|A_HOSTNAME)
> ) {
> /* + is special, meaning broadcast is
> derived. */
> sai.sin_addr.s_addr = (~sai_netmask) |
> (sai_hostname & sai_netmask);
> }
> #endif
>
> so this suggests to use 'broadcast +' to trigger the automatic
> broadcast, and indeed this works:
> ifconfig eth0 172.16.0.1 netmask 255.255.255.0 broadcast +
> eth0 Link encap:Ethernet HWaddr 00:BA:BE:FA:CE:01
> inet addr:172.16.0.1 Bcast:172.16.0.255 Mask:255.255.255.0
>
> but: the order matters! If you try:
> ifconfig eth0 172.16.0.1 broadcast + netmask 255.255.255.0
> this results:
> ifconfig: bad address '+'
>
> now big question is: why does the busybox sample script test for
> $broadcast ? Does udhcpc probably with some commandline options pass a
> broadcast to the script?
> Also I think we should add another sample script which shows the usage
> of this auto broadcast feature.
Can you test this fixed version?
--
vda
#!/bin/sh
# udhcpc script edited by Tim Riker <Tim at Rikers.org>
[ -z "$1" ] && echo "Error: should be called from udhcpc" && exit 1
RESOLV_CONF="/etc/resolv.conf"
NETMASK=""
[ -n "$subnet" ] && NETMASK="netmask $subnet"
BROADCAST="broadcast +"
[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
case "$1" in
deconfig)
ifconfig $interface 0.0.0.0
;;
renew|bound)
ifconfig $interface $ip $NETMASK $BROADCAST
if [ -n "$router" ] ; then
echo "deleting routers"
while route del default gw 0.0.0.0 dev $interface ; do
:
done
metric=0
for i in $router ; do
route add default gw $i dev $interface metric $((metric++))
done
fi
echo -n > $RESOLV_CONF-$$
[ -n "$domain" ] && echo search $domain >> $RESOLV_CONF-$$
for i in $dns ; do
echo adding dns $i
echo nameserver $i >> $RESOLV_CONF-$$
done
mv $RESOLV_CONF-$$ $RESOLV_CONF
;;
esac
exit 0
More information about the busybox
mailing list