According to ticket https://dev.openwrt.org/ticket/3022:
Everytime the ISP renews the ip (event renew or bound for udhcpc) hotplug event is called although nothing has changed. The following patch changes the configuration only if ip, router or dns does change. Signed-off-by: Pedro Faustino <[EMAIL PROTECTED]> --- Index: default.script =================================================================== --- default.script (revision 11339) +++ default.script (working copy) @@ -6,35 +6,55 @@ RESOLV_CONF="/tmp/resolv.conf.auto" hotplug_event() { + [ ifup = "$1" ] && { + uci_set_state network "$iface" ipaddr "$ip" + uci_set_state network "$iface" netmask "${subnet:-255.255.255.0}" + uci_set_state network "$iface" dnsdomain "$domain" + uci_set_state network "$iface" dns "$dns" + uci_set_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" ] || continue - [ ifup = "$1" ] && { - uci_set_state network "$ifc" ipaddr "$ip" - uci_set_state network "$ifc" netmask "${subnet:-255.255.255.0}" - uci_set_state network "$ifc" dnsdomain "$domain" - uci_set_state network "$ifc" dns "$dns" - uci_set_state network "$ifc" gateway "$router" - } - env -i ACTION="$1" INTERFACE="$ifc" DEVICE="$ifname" PROTO=dhcp /sbin/hotplug-call iface - done -} + [ "$proto" = "dhcp" ] && iface="$ifc" && break + done +} + +config_load /var/state/network +find_interface + case "$1" in deconfig) ifconfig $interface 0.0.0.0 hotplug_event ifdown ;; renew|bound) - ifconfig $interface $ip \ - netmask ${subnet:-255.255.255.0} \ - broadcast ${broadcast:-+} + is_change= + + [ "`config_get "$iface" ipaddr`" != "$ip" ] && { + ifconfig $interface $ip \ + netmask ${subnet:-255.255.255.0} \ + broadcast ${broadcast:-+} + + is_change=1 + + } - [ -n "$router" ] && { + [ "`config_get "$iface" gateway`" != "$router" ] && [ -n "$router" ] && { for i in $router ; do echo "adding router $i" route add default gw $i dev $interface @@ -44,9 +64,14 @@ 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" ] && { + + 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 @@ -54,13 +79,16 @@ echo "nameserver $i" >> "${RESOLV_CONF}.tmp" done mv "${RESOLV_CONF}.tmp" "$RESOLV_CONF" + + is_change=1 } + + [ "$is_change" ] && hotplug_event ifup - hotplug_event ifup - # user rules - [ -f /etc/udhcpc.user ] && . /etc/udhcpc.user + [ -f /etc/udhcpc.user ] && . /etc/udhcpc.user "$1" ;; esac + exit 0 _______________________________________________ openwrt-devel mailing list openwrt-devel@lists.openwrt.org http://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel