Few days ago, I wrote  how to fix udhcpc's bug. It worked very well before I recognized some problems. 

My busybox's version is 1.4.2-2.  I think that the bugfix doesn't match current version. 

So I restored it to my own version. 

#!/bin/sh
[ -z "$1" ] && echo "Error: should be run by udhcpc" && exit 1
. /etc/functions.sh
include /lib/network

RESOLV_CONF="/tmp/resolv.conf.auto"

hotplug_event() {
scan_interfaces
config_load /var/state/network
for ifc in $interfaces; do
config_get ifname $ifc ifname
[ "$ifname" = "$interface" ] || continue

config_get proto $ifc proto
[ "$proto" = "dhcp" ] || continue
[ ifup = "$1" ] && {
uci set "/var/state/network.$ifc.ipaddr=$ip"
uci set "/var/state/network.$ifc.netmask=${subnet:-255.255.255.0}"
uci set "/var/state/network.$ifc.dnsdomain=$domain"
uci set "/var/state/network.$ifc.dns=$dns"
uci set "/var/state/network.$ifc.gateway=$router"
}
env -i ACTION="$1" INTERFACE="$ifc" DEVICE="$ifname" PROTO=dhcp /sbin/hotplug-call iface
done
}

case "$1" in
deconfig)
#ifconfig $interface 0.0.0.0
#hotplug_event ifdown
;;
renew|bound)
#echo `date` >> /tmp/test
#old_ip="$(cat /tmp/state/network | grep ipaddr | sed "s/'//g" | awk '{print $4}')"
#echo $old_ip >> /tmp/test
#echo $ip >> /tmp/test
if [ "$old_ip" = "$ip" ]; then
#echo "same" >> /tmp/test
exit 0
else
ifconfig $interface 0.0.0.0
hotplug_event ifdown
ifconfig $interface $ip \
netmask ${subnet:-255.255.255.0} \
broadcast ${broadcast:-+}

[ -n "$router" ] && {
for i in $router ; do
echo "adding router $i"
route add default gw $i dev $interface
valid="$valid|$i"
done
echo "deleting old routes"
$(route -n | awk '/^0.0.0.0\W{9}('$valid')\W/ {next} /^0.0.0.0/ {print "route del -net "$1" gw "$2";"}')
}
[ -n "$dns" ] && {
echo -n > "${RESOLV_CONF}.tmp"
${domain:+echo search $domain} >> "${RESOLV_CONF}.tmp"
for i in $dns ; do
echo "adding dns $i"
echo "nameserver $i" >> "${RESOLV_CONF}.tmp"
done
mv "${RESOLV_CONF}.tmp" "$RESOLV_CONF"
}
hotplug_event ifup
# user rules
[ -f /etc/udhcpc.user ] && . /etc/udhcpc.user
fi
;;
esac

exit 0

신고
It was terrible to me to be disconnected my internet environment every one hour. 

I installed OpenWRT to my router(ASUS 500W) because I want to use it variously. 

But it had a bug of the DHCP client(udhcpc) which is a part of buzybox package.

This renews my IP every renewal time(In case of KT, the renewal time is ONE hour(3600 secs.)) despite that my dynamic IP was not changed. 

It causes 2 problems. 
  • To occur errors of the messenger because of disconnecting my network shortly. 
  • To increase  the temporary file(/var/state/network).
I was modified my udhcpc script(/usr/share/udhcpc/default.script) temporarily. 

Today I found the bugfix of it. It was released 5 months ago but it was not included the main firmware version(kamikaze 7.09). 

You can fix this just to replace the script(/usr/share/udhcpc/default.script).

#!/bin/sh
[ -z "$1" ] && echo "Error: should be run by udhcpc" && exit 1
. /etc/functions.sh
include /lib/network

RESOLV_CONF="/tmp/resolv.conf.auto"

hotplug_event() {
        [ ifup = "$1" ] && {
                uci set "/var/state/network.$iface.ipaddr=$ip"
                uci set "/var/state/network.$iface.netmask=${subnet:-255.255.255.0}"
                uci set "/var/state/network.$iface.dnsdomain=$domain"
                uci set "/var/state/network.$iface.dns=$dns"
                uci set "/var/state/network.$iface.gateway=$router"
        }
        env -i ACTION="$1" INTERFACE="$iface" DEVICE="$ifname" PROTO=dhcp /sbin/hotplug-call iface
}


# Find corresponding OpenWRT interface for ifname (=$interface)
# $ifname, $iface are set
find_interface() {
        local ifc proto
       
        scan_interfaces
       
        for ifc in $interfaces; do
                config_get ifname $ifc ifname
                [ "$ifname" = "$interface" ] || continue
               
                config_get proto $ifc proto
                [ "$proto" = "dhcp" ] && iface="$ifc" && break
        done
}                                                                                       
config_load /var/state/network
find_interface
case "$1" in
        deconfig)
                ifconfig $iface 0.0.0.0
                hotplug_event ifdown
        ;;
        renew|bound)
                is_change=
               
                [ `CONFIG_GET "$IFACE" IPADDR` != "$IP" ] && {
                        IFCONFIG $INTERFACE $IP \
                        NETMASK ${SUBNET:-255.255.255.0} \
                        BROADCAST ${BROADCAST:-+}
               
                        IS_CHANGE=1
               
                }
                [ `CONFIG_GET "$IFACE" ROUTER` != "$ROUTER" ] && [ -N "$ROUTER" ] && {
                        FOR I IN $ROUTER ; DO
                                ECHO "ADDING ROUTER $I"
                                ROUTE ADD DEFAULT GW $I DEV $INTERFACE
                                VALID="$VALID|$I"
                        DONE
                        ECHO "DELETING OLD ROUTES"
                        $(route -n | awk '/^0.0.0.0\W{9}('$valid')\W/ {next} /^0.0.0.0/ {print "route del -net "$1" gw "$2";"}')
                       
                        is_change=1
                }       
                       
                config_get static_dns $iface dns
                [ -n "$static_dns" ] && dns="$static_dns"
                                                                               
                [ `config_get "$iface" dns` != "$dns" ] && [ -n "$dns" ] && {
                        echo -n > "${RESOLV_CONF}.tmp"
                        ${domain:+echo search $domain} >> "${RESOLV_CONF}.tmp"
                        for i in $dns ; do
                                echo "adding dns $i"
                                echo "nameserver $i" >> "${RESOLV_CONF}.tmp"
                        done
                        mv "${RESOLV_CONF}.tmp" "$RESOLV_CONF"
                       
                        is_change=1
                }
               
                [ "$is_change" ] && hotplug_event ifup
              
                # user rules
                [ -f /etc/udhcpc.user ] && . /etc/udhcpc.user "$1"
        ;;
esac
exit 0

신고
이전 1 다음

티스토리 툴바