-uci_get() {
- uci -P /dev/null get "$1" 2>/dev/null
+set_classless_routes() {
+ local max=128
+ local type
+ while [ -n "$1" -a -n "$2" -a $max -gt 0 ]; do
+ [ ${1##*/} -eq 32 ] && type=host || type=net
+ echo "udhcpc: adding route for $type $1 via $2"
+ route add -$type "$1" gw "$2" dev "$interface"
+ max=$(($max-1))
+ shift 2
+ done
- config_get old_ip "$ifc" ipaddr
- config_get old_broadcast "$ifc" broadcast
- config_get old_subnet "$ifc" netmask
+ [ -n "$ifc" ] && {
+ old_ip="$(uci_get_state network "$ifc" ipaddr)"
+ old_broadcast="$(uci_get_state network "$ifc" broadcast)"
+ old_subnet="$(uci_get_state network "$ifc" netmask)"
+ }
- change_state network "$ifc" lease_gateway "$router"
- config_get old_router "$ifc" gateway
- user_router=$(uci_get "network.$ifc.gateway")
- [ -n "$user_router" ] && router="$user_router"
+ [ -n "$ifc" ] && {
+ change_state network "$ifc" lease_gateway "$router"
+ old_router="$(uci_get_state network "$ifc" gateway)"
+ user_router="$(uci_get network "$ifc" gateway)"
+ user_metric="$(uci_get network "$ifc" metric)"
+ [ -n "$user_router" ] && router="$user_router"
+ }
- echo -n > "${RESOLV_CONF}.tmp"
- for i in $dns ; do
- echo "nameserver $i" >> "${RESOLV_CONF}.tmp"
- done
- ${domain:+echo search $domain} >> "${RESOLV_CONF}.tmp"
- mv "${RESOLV_CONF}.tmp" "$RESOLV_CONF"
-
- change_state network "$ifc" dnsdomain "$domain"
- change_state network "$ifc" dns "$dns"
+ add_dns "$ifc" $dns
+
+ [ -n "$domain" ] && [ "$domain" != "$old_domain" ] && {
+ echo "udhcpc: setting dns domain: $domain"
+ sed -i -e "${old_domain:+/^search $old_domain$/d; }/^search $domain$/d" "${RESOLV_CONF}"
+ echo "search $domain" >> "${RESOLV_CONF}"
+ change_state network "$ifc" dnsdomain "$domain"
+ }
change_state network "$ifc" lease_lifetime "$lease"
[ -n "$ntpsrv" ] && change_state network "$ifc" lease_ntpsrv "$ntpsrv"
[ -n "$timesvr" ] && change_state network "$ifc" lease_timesrv "$timesvr"
change_state network "$ifc" lease_lifetime "$lease"
[ -n "$ntpsrv" ] && change_state network "$ifc" lease_ntpsrv "$ntpsrv"
[ -n "$timesvr" ] && change_state network "$ifc" lease_timesrv "$timesvr"
-
-for ifc in $interfaces; do
- config_get ifname "$ifc" ifname
- [ "$ifname" = "$interface" ] || continue
-
- config_get proto "$ifc" proto
- [ "$proto" = "dhcp" ] || continue
+applied=
+for ifc in $interfaces __default; do
+ if [ "$ifc" = __default ]; then
+ ifc=""
+ [ -n "$applied" ] && continue
+ else
+ config_get ifname "$ifc" ifname
+ [ "$ifname" = "$interface" ] || continue
+
+ config_get proto "$ifc" proto
+ [ "$proto" = "dhcp" ] || continue
+ applied=true
+ fi
- config_get device "$ifc" device
- config_get ifname "$ifc" ifname
- config_get aliases "$ifc" aliases
- uci_revert_state network "$ifc"
- [ -n "$device" ] && uci_set_state network "$ifc" device "$device"
- [ -n "$ifname" ] && uci_set_state network "$ifc" ifname "$ifname"
- [ -n "$aliases" ] && uci_set_state network "$ifc" aliases "$aliases"
+ config_get device "$ifc" device
+ config_get ifname "$ifc" ifname
+ config_get aliases "$ifc" aliases
+ uci_revert_state network "$ifc"
+ [ -n "$device" ] && uci_set_state network "$ifc" device "$device"
+ [ -n "$ifname" ] && uci_set_state network "$ifc" ifname "$ifname"
+ [ -n "$aliases" ] && uci_set_state network "$ifc" aliases "$aliases"
+ }