3
0

dhcp_handler 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/bin/sh
  2. # executed by udhcpc
  3. # parameters: $1 and environment
  4. # $1 is:
  5. #
  6. # deconfig: udhcpc starts, or lease is lost.
  7. # Environment example: interface=eth0
  8. #
  9. # bound: lease is obtained. Environment example:
  10. # dhcptype=5
  11. # serverid=172.16.42.102
  12. # lease=97200
  13. # interface=eth0
  14. # ip=172.16.42.177
  15. # subnet=255.255.255.0
  16. # mask=24
  17. # broadcast=172.16.22.255
  18. # router=172.16.42.98
  19. # dns=10.34.32.125 10.32.63.5 10.34.255.7 10.11.255.27
  20. # domain=lab.example.com example.com
  21. # ntpsrv=10.34.32.125 10.34.255.7
  22. #
  23. # renew: lease is renewed. Environment is similar to "bound".
  24. # The IP address does not change, however, the other DHCP parameters,
  25. # such as the default gateway, subnet mask, and dns server may change.
  26. #
  27. # nak: udhcpc received a NAK message.
  28. # Environment example: interface=eth0
  29. #
  30. # leasefail: udhcpc cannot obtain a lease (DHCP server not responding, etc).
  31. # Environment example: interface=eth0
  32. # TODO: put $domain into /etc/resolv.conf (thru /var/service/fw)
  33. service=${PWD##*/}
  34. file_ipconf="$service.ipconf"
  35. file_ntpconf="$service.ntpconf"
  36. dir_ipconf="/var/run/service/fw"
  37. dir_ntpconf="/var/run/service/ntpd"
  38. #exec >/dev/null
  39. #exec >"$0.out" #debug
  40. exec 2>&1
  41. if test x"$1" != x"bound" && test x"$1" != x"renew" ; then
  42. # Reconfigure network with this interface disabled
  43. echo "Deconfiguring"
  44. rm "env.out"
  45. rm "$file_ipconf"
  46. rm "$file_ntpconf"
  47. rm "$dir_ipconf/$file_ipconf"
  48. rm "$dir_ntpconf/$file_ntpconf"
  49. svc -u fw
  50. exit
  51. fi
  52. # Bound: we've got the lease
  53. # Record information for e.g. dhcp_$IF_pinger service
  54. env >"env.out"
  55. ./convert2ipconf "$file_ipconf"
  56. # Reconfigure routing and firewall if needed
  57. diff --brief "$file_ipconf" "$dir_ipconf/$file_ipconf" >/dev/null 2>&1
  58. if test $? != 0; then
  59. echo "Reconfiguring fw"
  60. mkdir -p "$dir_ipconf" 2>/dev/null
  61. cp "$file_ipconf" "$dir_ipconf/$file_ipconf"
  62. svc -u fw
  63. fi
  64. if test -d ../ntpd; then
  65. ./convert2ntpconf "$file_ntpconf"
  66. # Reconfigure ntp server addresses if needed
  67. diff --brief "$file_ntpconf" "$dir_ntpconf/$file_ntpconf" >/dev/null 2>&1
  68. if test $? != 0; then
  69. echo "Reconfiguring ntp"
  70. mkdir -p "$dir_ntpconf" 2>/dev/null
  71. cp "$file_ntpconf" "$dir_ntpconf/$file_ntpconf"
  72. svc -t ntpd
  73. svc -u ntpd
  74. fi
  75. fi