default.script 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/bin/sh
  2. [ -z "$1" ] && echo "Error: should be run by udhcpc" && exit 1
  3. . /etc/functions.sh
  4. include /lib/network
  5. RESOLV_CONF="/tmp/resolv.conf"
  6. hotplug_event() {
  7. scan_interfaces
  8. for ifc in $interfaces; do
  9. config_get ifname $ifc ifname
  10. [ "$ifname" = "$interface" ] || continue
  11. config_get proto $ifc proto
  12. [ "$proto" = "dhcp" ] || continue
  13. env -i ACTION="$1" INTERFACE="$ifname" PROTO=dhcp /sbin/hotplug iface
  14. done
  15. }
  16. case "$1" in
  17. deconfig)
  18. ifconfig $interface 0.0.0.0
  19. hotplug_event ifdown
  20. ;;
  21. renew|bound)
  22. ifconfig $interface $ip \
  23. netmask ${subnet:-255.255.255.0} \
  24. broadcast ${broadcast:-+}
  25. if [ -n "$router" ] ; then
  26. echo "deleting routers"
  27. while route del default gw 0.0.0.0 dev $interface >&- 2>&- ; do :; done
  28. for i in $router ; do
  29. echo "adding router $i"
  30. route add default gw $i dev $interface
  31. done
  32. fi
  33. [ -n "$dns" ] && {
  34. echo -n > $RESOLV_CONF
  35. ${domain:+echo search $domain} >> $RESOLV_CONF
  36. for i in $dns ; do
  37. echo "adding dns $i"
  38. echo "nameserver $i" >> $RESOLV_CONF
  39. done
  40. }
  41. hotplug_event ifup
  42. # user rules
  43. [ -f /etc/udhcpc.user ] && . /etc/udhcpc.user
  44. ;;
  45. esac
  46. exit 0