You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

281 lines
7.7 KiB

  1. #!/bin/sh
  2. make_resolv_conf() {
  3. if [ x"$new_domain_name_servers" != x ]; then
  4. cat /dev/null > /etc/resolv.conf.dhclient
  5. chmod 644 /etc/resolv.conf.dhclient
  6. if [ x"$new_domain_search" != x ]; then
  7. echo search $new_domain_search >> /etc/resolv.conf.dhclient
  8. elif [ x"$new_domain_name" != x ]; then
  9. # Note that the DHCP 'Domain Name Option' is really just a domain
  10. # name, and that this practice of using the domain name option as
  11. # a search path is both nonstandard and deprecated.
  12. echo search $new_domain_name >> /etc/resolv.conf.dhclient
  13. fi
  14. for nameserver in $new_domain_name_servers; do
  15. echo nameserver $nameserver >>/etc/resolv.conf.dhclient
  16. done
  17. elif [ "x${new_dhcp6_name_servers}" != x ] ; then
  18. cat /dev/null > /etc/resolv.conf.dhclient6
  19. chmod 644 /etc/resolv.conf.dhclient6
  20. if [ "x${new_dhcp6_domain_search}" != x ] ; then
  21. echo search ${new_dhcp6_domain_search} >> /etc/resolv.conf.dhclient6
  22. fi
  23. for nameserver in ${new_dhcp6_name_servers} ; do
  24. echo nameserver ${nameserver} >> /etc/resolv.conf.dhclient6
  25. done
  26. fi
  27. # if both v4 and v6 clients are running, concatenate results
  28. cat /etc/resolv.conf.* > /etc/resolv.conf
  29. }
  30. # Must be used on exit. Invokes the local dhcp client exit hooks, if any.
  31. exit_with_hooks() {
  32. exit_status=$1
  33. if [ -f /etc/dhclient-exit-hooks ]; then
  34. . /etc/dhclient-exit-hooks
  35. fi
  36. # probably should do something with exit status of the local script
  37. exit $exit_status
  38. }
  39. # Invoke the local dhcp client enter hooks, if they exist.
  40. if [ -f /etc/dhclient-enter-hooks ]; then
  41. exit_status=0
  42. . /etc/dhclient-enter-hooks
  43. # allow the local script to abort processing of this state
  44. # local script must set exit_status variable to nonzero.
  45. if [ $exit_status -ne 0 ]; then
  46. exit $exit_status
  47. fi
  48. fi
  49. ###
  50. ### DHCPv4 Handlers
  51. ###
  52. if [ x$new_broadcast_address != x ]; then
  53. new_broadcast_arg="broadcast $new_broadcast_address"
  54. fi
  55. if [ x$new_subnet_mask != x ]; then
  56. new_subnet_arg="netmask $new_subnet_mask"
  57. fi
  58. if [ x$alias_subnet_mask != x ]; then
  59. alias_subnet_arg="netmask $alias_subnet_mask"
  60. fi
  61. if [ x$reason = xMEDIUM ]; then
  62. # Linux doesn't do mediums (ok, ok, media).
  63. exit_with_hooks 0
  64. fi
  65. if [ x$reason = xPREINIT ]; then
  66. if [ x$alias_ip_address != x ]; then
  67. # Bring down alias interface. Its routes will disappear too.
  68. ifconfig $interface:0- 0.0.0.0
  69. fi
  70. ifconfig $interface 0.0.0.0 up
  71. # We need to give the kernel some time to get the interface up.
  72. sleep 1
  73. exit_with_hooks 0
  74. fi
  75. if [ x$reason = xARPCHECK ] || [ x$reason = xARPSEND ]; then
  76. exit_with_hooks 0
  77. fi
  78. if [ x$reason = xBOUND ] || [ x$reason = xRENEW ] || \
  79. [ x$reason = xREBIND ] || [ x$reason = xREBOOT ]; then
  80. current_hostname=`hostname`
  81. if [ x$current_hostname = x ] || \
  82. [ x$current_hostname = x$old_host_name ]; then
  83. if [ x$current_hostname = x ] || \
  84. [ x$new_host_name != x$old_host_name ]; then
  85. hostname $new_host_name
  86. fi
  87. fi
  88. if [ x$old_ip_address != x ] && [ x$alias_ip_address != x ] && \
  89. [ x$alias_ip_address != x$old_ip_address ]; then
  90. # Possible new alias. Remove old alias.
  91. ifconfig $interface:0- 0.0.0.0
  92. fi
  93. if [ x$old_ip_address != x ] && [ x$old_ip_address != x$new_ip_address ]; then
  94. # IP address changed. Bringing down the interface will delete all routes,
  95. # and clear the ARP cache.
  96. ifconfig $interface 0.0.0.0 down
  97. fi
  98. if [ x$old_ip_address = x ] || [ x$old_ip_address != x$new_ip_address ] || \
  99. [ x$reason = xBOUND ] || [ x$reason = xREBOOT ]; then
  100. ifconfig $interface $new_ip_address $new_subnet_arg \
  101. $new_broadcast_arg
  102. for router in $new_routers; do
  103. if [ "x$new_subnet_mask" = "x255.255.255.255" ] ; then
  104. route add -host $router dev $interface
  105. fi
  106. route add default gw $router
  107. done
  108. fi
  109. if [ x$new_ip_address != x$alias_ip_address ] && [ x$alias_ip_address != x ];
  110. then
  111. ifconfig $interface:0- 0.0.0.0
  112. ifconfig $interface:0 $alias_ip_address $alias_subnet_arg
  113. route add -host $alias_ip_address $interface:0
  114. fi
  115. make_resolv_conf
  116. exit_with_hooks 0
  117. fi
  118. if [ x$reason = xEXPIRE ] || [ x$reason = xFAIL ] || [ x$reason = xRELEASE ] \
  119. || [ x$reason = xSTOP ]; then
  120. if [ x$alias_ip_address != x ]; then
  121. # Turn off alias interface.
  122. ifconfig $interface:0- 0.0.0.0
  123. fi
  124. if [ x$old_ip_address != x ]; then
  125. # Shut down interface, which will delete routes and clear arp cache.
  126. ifconfig $interface 0.0.0.0 down
  127. fi
  128. if [ x$alias_ip_address != x ]; then
  129. ifconfig $interface:0 $alias_ip_address $alias_subnet_arg
  130. route add -host $alias_ip_address $interface:0
  131. fi
  132. # remove v4 dns configuration for this interface
  133. rm /etc/resolv.conf.dhclient
  134. cat /etc/resolv.conf.* > /etc/resolv.conf
  135. exit_with_hooks 0
  136. fi
  137. if [ x$reason = xTIMEOUT ]; then
  138. if [ x$alias_ip_address != x ]; then
  139. ifconfig $interface:0- 0.0.0.0
  140. fi
  141. ifconfig $interface $new_ip_address $new_subnet_arg \
  142. $new_broadcast_arg
  143. set $new_routers
  144. if ping -q -c 1 $1; then
  145. if [ x$new_ip_address != x$alias_ip_address ] && \
  146. [ x$alias_ip_address != x ]; then
  147. ifconfig $interface:0 $alias_ip_address $alias_subnet_arg
  148. route add -host $alias_ip_address dev $interface:0
  149. fi
  150. for router in $new_routers; do
  151. if [ "x$new_subnet_mask" = "x255.255.255.255" ] ; then
  152. route add -host $router dev $interface
  153. fi
  154. route add default gw $router
  155. done
  156. make_resolv_conf
  157. exit_with_hooks 0
  158. fi
  159. ifconfig $interface 0.0.0.0 down
  160. exit_with_hooks 1
  161. fi
  162. ###
  163. ### DHCPv6 Handlers
  164. ###
  165. if [ x$reason = xPREINIT6 ]; then
  166. # Ensure interface is up.
  167. ifconfig ${interface} up
  168. # Remove any stale addresses from aborted clients.
  169. ip -f inet6 addr flush dev ${interface} scope global
  170. exit_with_hooks 0
  171. fi
  172. if [ x${old_ip6_prefix} != x ] || [ x${new_ip6_prefix} != x ] ; then
  173. echo Prefix ${reason} old=${old_ip6_prefix} new=${new_ip6_prefix}
  174. exit_with_hooks 0
  175. fi
  176. if [ x$reason = xBOUND6 ]; then
  177. if [ x${new_ip6_address} = x ] || [ x${new_ip6_prefixlen} = x ] ; then
  178. exit_with_hooks 2;
  179. fi
  180. ifconfig ${interface} add ${new_ip6_address}/${new_ip6_prefixlen}
  181. # Check for nameserver options.
  182. make_resolv_conf
  183. ### <<
  184. # Set up softwire tunnel
  185. if [ x${new_dhcp6_softwire} != x ] ; then
  186. /etc/init.d/dhclient stop
  187. ifconfig ${interface} 0.0.0.0
  188. ip -6 tunnel add tun0 mode ipip6 \
  189. remote ${new_dhcp6_softwire} \
  190. local ${new_ip6_address} \
  191. dev ${interface} encaplimit none
  192. ip link set tun0 up
  193. ip route add default dev tun0
  194. fi
  195. ### >>
  196. exit_with_hooks 0
  197. fi
  198. if [ x$reason = xRENEW6 ] || [ x$reason = xREBIND6 ]; then
  199. if [ x${new_ip6_address} = x ] || [ x${new_ip6_prefixlen} = x ] ; then
  200. exit_with_hooks 2;
  201. fi
  202. ifconfig ${interface} add ${new_ip6_address}/${new_ip6_prefixlen}
  203. # Make sure nothing has moved around on us.
  204. # Nameservers/domains/etc.
  205. if [ "x${new_dhcp6_name_servers}" != "x${old_dhcp6_name_servers}" ] ||
  206. [ "x${new_dhcp6_domain_search}" != "x${old_dhcp6_domain_search}" ] ; then
  207. make_resolv_conf
  208. fi
  209. exit_with_hooks 0
  210. fi
  211. if [ x$reason = xDEPREF6 ]; then
  212. if [ x${new_ip6_address} = x ] ; then
  213. exit_with_hooks 2;
  214. fi
  215. # Busybox ifconfig has no way to communicate this to the kernel, so ignore it
  216. exit_with_hooks 0
  217. fi
  218. if [ x$reason = xEXPIRE6 -o x$reason = xRELEASE6 -o x$reason = xSTOP6 ]; then
  219. if [ x${old_ip6_address} = x ] || [ x${old_ip6_prefixlen} = x ] ; then
  220. exit_with_hooks 2;
  221. fi
  222. ifconfig ${interface} del ${old_ip6_address}/${old_ip6_prefixlen}
  223. # remove v6 dns configuration for this interface
  224. rm /etc/resolv.conf.dhclient6
  225. cat /etc/resolv.conf.* > /etc/resolv.conf
  226. ### <<
  227. # Tear down softwire tunnel
  228. if [ x${old_dhcp6_softwire} != x ] ; then
  229. ip link set tun0 down
  230. ip tunnel del tun0
  231. fi
  232. ### >>
  233. exit_with_hooks 0
  234. fi
  235. exit_with_hooks 0