default.script 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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.auto"
  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="$ifc" DEVICE="$ifname" PROTO=dhcp /sbin/hotplug-call 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. [ -n "$router" ] && {
  26. for i in $router ; do
  27. echo "adding router $i"
  28. route add default gw $i dev $interface
  29. valid="$valid|$i"
  30. done
  31. echo "deleting old routes"
  32. $(route -n | awk '/^0.0.0.0\W{9}('$valid')\W/ {next} /^0.0.0.0/ {print "route del -net "$1" gw "$2";"}')
  33. }
  34. [ -n "$dns" ] && {
  35. echo -n > $RESOLV_CONF
  36. ${domain:+echo search $domain} >> $RESOLV_CONF
  37. for i in $dns ; do
  38. echo "adding dns $i"
  39. echo "nameserver $i" >> $RESOLV_CONF
  40. done
  41. }
  42. hotplug_event ifup
  43. # user rules
  44. [ -f /etc/udhcpc.user ] && . /etc/udhcpc.user
  45. ;;
  46. esac
  47. exit 0