1
0

default.script 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/bin/sh
  2. [ -z "$1" ] && echo "Error: should be run by udhcpc" && exit 1
  3. set_classless_routes() {
  4. local max=128
  5. local type
  6. while [ -n "$1" -a -n "$2" -a $max -gt 0 ]; do
  7. [ ${1##*/} -eq 32 ] && type=host || type=net
  8. echo "udhcpc: adding route for $type $1 via $2"
  9. route add -$type "$1" gw "$2" dev "$interface"
  10. max=$(($max-1))
  11. shift 2
  12. done
  13. }
  14. setup_interface() {
  15. echo "udhcpc: ifconfig $interface $ip netmask ${subnet:-255.255.255.0} broadcast ${broadcast:-+}"
  16. ifconfig $interface $ip netmask ${subnet:-255.255.255.0} broadcast ${broadcast:-+}
  17. [ -n "$router" ] && [ "$router" != "0.0.0.0" ] && [ "$router" != "255.255.255.255" ] && {
  18. echo "udhcpc: setting default routers: $router"
  19. local valid_gw=""
  20. for i in $router ; do
  21. route add default gw $i dev $interface
  22. valid_gw="${valid_gw:+$valid_gw|}$i"
  23. done
  24. eval $(route -n | awk '
  25. /^0.0.0.0\W{9}('$valid_gw')\W/ {next}
  26. /^0.0.0.0/ {print "route del -net "$1" gw "$2";"}
  27. ')
  28. }
  29. # CIDR STATIC ROUTES (rfc3442)
  30. [ -n "$staticroutes" ] && set_classless_routes $staticroutes
  31. [ -n "$msstaticroutes" ] && set_classless_routes $msstaticroutes
  32. }
  33. applied=
  34. case "$1" in
  35. deconfig)
  36. ifconfig "$interface" 0.0.0.0
  37. ;;
  38. renew)
  39. setup_interface update
  40. ;;
  41. bound)
  42. setup_interface ifup
  43. ;;
  44. esac
  45. # user rules
  46. [ -f /etc/udhcpc.user ] && . /etc/udhcpc.user
  47. exit 0