dhcp-4.3.3-client_script-1.patch 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. Submitted By: Armin K. <krejzi at email dot com>
  2. Date: 2012-08-14
  3. Initial Package Version: 4.2.4-P1
  4. Upstream Status: Rejected by upstream.
  5. Origin: Based on Debian's dhclient-script, but modified for BLFS
  6. Tanım: This patch replaces original linux script for dhcp client with
  7. better one which is based on Debian's dhclient-script, but modified
  8. to be used on LFS/BLFS. It also removes net-tools dependency.
  9. --- a/client/scripts/linux 2014-07-09 20:26:40.000000000 +0200
  10. +++ b/client/scripts/linux 2014-08-12 01:21:02.858998828 +0200
  11. @@ -1,316 +1,346 @@
  12. #!/bin/bash
  13. +
  14. # dhclient-script for Linux. Dan Halbert, March, 1997.
  15. # Updated for Linux 2.[12] by Brian J. Murrell, January 1999.
  16. -# No guarantees about this. I'm a novice at the details of Linux
  17. -# networking.
  18. -
  19. -# Notes:
  20. -
  21. -# 0. This script is based on the netbsd script supplied with dhcp-970306.
  22. -
  23. -# 1. ifconfig down apparently deletes all relevant routes and flushes
  24. -# the arp cache, so this doesn't need to be done explicitly.
  25. -
  26. -# 2. The alias address handling here has not been tested AT ALL.
  27. -# I'm just going by the doc of modern Linux ip aliasing, which uses
  28. -# notations like eth0:0, eth0:1, for each alias.
  29. +# Modified for Debian. Matt Zimmerman and Eloy Paris, December 2003
  30. +# Modified to remove useless tests for antiquated kernel versions that
  31. +# this doesn't even work with anyway, and introduces a dependency on /usr
  32. +# being mounted, which causes cosmetic errors on hosts that NFS mount /usr
  33. +# Andrew Pollock, February 2005
  34. +# Modified to work on point-to-point links. Andrew Pollock, June 2005
  35. +# Modified to support passing the parameters called with to the hooks. Andrew Pollock, November 2005
  36. +# Modified to use the script with Linux From Scratch by Armin K., May 2012
  37. -# 3. I have to calculate the network address, and calculate the broadcast
  38. -# address if it is not supplied. This might be much more easily done
  39. -# by the dhclient C code, and passed on.
  40. -
  41. -# 4. TIMEOUT not tested. ping has a flag I don't know, and I'm suspicious
  42. -# of the $1 in its args.
  43. -
  44. -# 'ip' just looks too weird. /sbin/ip looks less weird.
  45. -ip=/sbin/ip
  46. +# The alias handling in here probably still sucks. -mdz
  47. +# update /etc/resolv.conf based on received values
  48. make_resolv_conf() {
  49. - if [ x"$new_domain_name_servers" != x ]; then
  50. - cat /dev/null > /etc/resolv.conf.dhclient
  51. - chmod 644 /etc/resolv.conf.dhclient
  52. - if [ x"$new_domain_search" != x ]; then
  53. - echo search $new_domain_search >> /etc/resolv.conf.dhclient
  54. - elif [ x"$new_domain_name" != x ]; then
  55. - # Note that the DHCP 'Domain Name Option' is really just a domain
  56. - # name, and that this practice of using the domain name option as
  57. - # a search path is both nonstandard and deprecated.
  58. - echo search $new_domain_name >> /etc/resolv.conf.dhclient
  59. - fi
  60. - for nameserver in $new_domain_name_servers; do
  61. - echo nameserver $isimserver >>/etc/resolv.conf.dhclient
  62. - done
  63. -
  64. - mv /etc/resolv.conf.dhclient /etc/resolv.conf
  65. - elif [ "x${new_dhcp6_name_servers}" != x ] ; then
  66. - cat /dev/null > /etc/resolv.conf.dhclient6
  67. - chmod 644 /etc/resolv.conf.dhclient6
  68. + local new_resolv_conf
  69. - if [ "x${new_dhcp6_domain_search}" != x ] ; then
  70. - echo search ${new_dhcp6_domain_search} >> /etc/resolv.conf.dhclient6
  71. + # DHCPv4
  72. + if [ -n "$new_domain_search" ] || [ -n "$new_domain_name" ] ||
  73. + [ -n "$new_domain_name_servers" ]; then
  74. + new_resolv_conf=/etc/resolv.conf.dhclient-new
  75. + rm -f $new_resolv_conf
  76. +
  77. + if [ -n "$new_domain_name" ]; then
  78. + echo domain ${new_domain_name%% *} >>$new_resolv_conf
  79. + fi
  80. +
  81. + if [ -n "$new_domain_search" ]; then
  82. + if [ -n "$new_domain_name" ]; then
  83. + domain_in_search_list=""
  84. + for domain in $new_domain_search; do
  85. + if [ "$domain" = "${new_domain_name}" ] ||
  86. + [ "$domain" = "${new_domain_name}." ]; then
  87. + domain_in_search_list="Yes"
  88. + fi
  89. + done
  90. + if [ -z "$domain_in_search_list" ]; then
  91. + new_domain_search="$new_domain_name $new_domain_search"
  92. + fi
  93. + fi
  94. + echo "search ${new_domain_search}" >> $new_resolv_conf
  95. + elif [ -n "$new_domain_name" ]; then
  96. + echo "search ${new_domain_name}" >> $new_resolv_conf
  97. + fi
  98. +
  99. + if [ -n "$new_domain_name_servers" ]; then
  100. + for nameserver in $new_domain_name_servers; do
  101. + echo nameserver $isimserver >>$new_resolv_conf
  102. + done
  103. + else # keep 'old' nameservers
  104. + sed -n /^\w*[Nn][Aa][Mm][Ee][Ss][Ee][Rr][Vv][Ee][Rr]/p /etc/resolv.conf >>$new_resolv_conf
  105. + fi
  106. +
  107. + chown --reference=/etc/resolv.conf $new_resolv_conf
  108. + chmod --reference=/etc/resolv.conf $new_resolv_conf
  109. + mv -f $new_resolv_conf /etc/resolv.conf
  110. + # DHCPv6
  111. + elif [ -n "$new_dhcp6_domain_search" ] || [ -n "$new_dhcp6_name_servers" ]; then
  112. + new_resolv_conf=/etc/resolv.conf.dhclient-new
  113. + rm -f $new_resolv_conf
  114. +
  115. + if [ -n "$new_dhcp6_domain_search" ]; then
  116. + echo "search ${new_dhcp6_domain_search}" >> $new_resolv_conf
  117. + fi
  118. +
  119. + if [ -n "$new_dhcp6_name_servers" ]; then
  120. + for nameserver in $new_dhcp6_name_servers; do
  121. + # append %interface to link-local-address nameservers
  122. + if [ "${nameserver##fe80::}" != "$isimserver" ] ||
  123. + [ "${nameserver##FE80::}" != "$isimserver" ]; then
  124. + nameserver="${nameserver}%${interface}"
  125. + fi
  126. + echo nameserver $isimserver >>$new_resolv_conf
  127. + done
  128. + else # keep 'old' nameservers
  129. + sed -n /^\w*[Nn][Aa][Mm][Ee][Ss][Ee][Rr][Vv][Ee][Rr]/p /etc/resolv.conf >>$new_resolv_conf
  130. + fi
  131. +
  132. + chown --reference=/etc/resolv.conf $new_resolv_conf
  133. + chmod --reference=/etc/resolv.conf $new_resolv_conf
  134. + mv -f $new_resolv_conf /etc/resolv.conf
  135. fi
  136. - shopt -s nocasematch
  137. - for nameserver in ${new_dhcp6_name_servers} ; do
  138. - # If the nameserver has a link-local address
  139. - # add a <zone_id> (interface name) to it.
  140. - if [[ "$isimserver" =~ ^fe80:: ]]
  141. - then
  142. - zone_id="%$interface"
  143. - else
  144. - zone_id=
  145. - fi
  146. - echo nameserver ${nameserver}$zone_id >> /etc/resolv.conf.dhclient6
  147. - done
  148. - shopt -u nocasematch
  149. +}
  150. - mv /etc/resolv.conf.dhclient6 /etc/resolv.conf
  151. - fi
  152. +# set host name
  153. +set_hostname() {
  154. + local current_hostname
  155. +
  156. + if [ -n "$new_host_name" ]; then
  157. + current_hostisim=$(hostname)
  158. +
  159. + # current host name is empty, '(none)' or 'localhost' or differs from new one from DHCP
  160. + if [ -z "$current_hostname" ] ||
  161. + [ "$current_hostname" = '(none)' ] ||
  162. + [ "$current_hostname" = 'localhost' ] ||
  163. + [ "$current_hostname" = "$old_host_name" ]; then
  164. + if [ "$new_host_name" != "$old_host_name" ]; then
  165. + hostname "$new_host_name"
  166. + fi
  167. + fi
  168. + fi
  169. }
  170. -# Must be used on exit. Invokes the local dhcp client exit hooks, if any.
  171. +# Must be used on exit. Invokes the local dhcp client exit hooks, if any.
  172. exit_with_hooks() {
  173. exit_status=$1
  174. - if [ -f /etc/dhclient-exit-hooks ]; then
  175. - . /etc/dhclient-exit-hooks
  176. + if [ -f /etc/dhcp/dhclient-exit-hooks ]; then
  177. + . /etc/dhcp/dhclient-exit-hooks
  178. fi
  179. -# probably should do something with exit status of the local script
  180. exit $exit_status
  181. }
  182. +# The 576 MTU is only used for X.25 and dialup connections
  183. +# where the admin wants low latency. Such a low MTU can cause
  184. +# problems with UDP traffic, among other things. As such,
  185. +# disallow MTUs from 576 and below by default, so that broken
  186. +# MTUs are ignored, but higher stuff is allowed (1492, 1500, etc).
  187. +if [ -z "$new_interface_mtu" ] || [ "$new_interface_mtu" -le 576 ]; then
  188. + new_interface_mtu=''
  189. +fi
  190. +
  191. +# The action starts here
  192. +
  193. # Invoke the local dhcp client enter hooks, if they exist.
  194. -if [ -f /etc/dhclient-enter-hooks ]; then
  195. +if [ -f /etc/dhcp/dhclient-enter-hooks ]; then
  196. exit_status=0
  197. - . /etc/dhclient-enter-hooks
  198. - # allow the local script to abort processing of this state
  199. - # local script must set exit_status variable to nonzero.
  200. + . /etc/dhcp/dhclient-enter-hooks
  201. if [ $exit_status -ne 0 ]; then
  202. exit $exit_status
  203. fi
  204. fi
  205. -###
  206. -### DHCPv4 Handlers
  207. -###
  208. -
  209. -if [ x$new_broadcast_address != x ]; then
  210. - new_broadcast_arg="broadcast $new_broadcast_address"
  211. -fi
  212. -if [ x$old_broadcast_address != x ]; then
  213. - old_broadcast_arg="broadcast $old_broadcast_address"
  214. -fi
  215. -if [ x$new_subnet_mask != x ]; then
  216. - new_subnet_arg="netmask $new_subnet_mask"
  217. -fi
  218. -if [ x$old_subnet_mask != x ]; then
  219. - old_subnet_arg="netmask $old_subnet_mask"
  220. -fi
  221. -if [ x$alias_subnet_mask != x ]; then
  222. - alias_subnet_arg="netmask $alias_subnet_mask"
  223. -fi
  224. -if [ x$new_interface_mtu != x ]; then
  225. - mtu_arg="mtu $new_interface_mtu"
  226. -fi
  227. -if [ x$IF_METRIC != x ]; then
  228. - metric_arg="metric $IF_METRIC"
  229. -fi
  230. -
  231. -if [ x$reason = xMEDIUM ]; then
  232. - # Linux doesn't do mediums (ok, ok, media).
  233. - exit_with_hooks 0
  234. -fi
  235. -
  236. -if [ x$reason = xPREINIT ]; then
  237. - if [ x$alias_ip_address != x ]; then
  238. - # Bring down alias interface. Its routes will disappear too.
  239. - ifconfig $interface:0- inet 0
  240. - fi
  241. - ifconfig $interface 0 up
  242. -
  243. - # We need to give the kernel some time to get the interface up.
  244. - sleep 1
  245. -
  246. - exit_with_hooks 0
  247. -fi
  248. -
  249. -if [ x$reason = xARPCHECK ] || [ x$reason = xARPSEND ]; then
  250. - exit_with_hooks 0
  251. -fi
  252. -
  253. -if [ x$reason = xBOUND ] || [ x$reason = xRENEW ] || \
  254. - [ x$reason = xREBIND ] || [ x$reason = xREBOOT ]; then
  255. - current_hostisim=`hostname`
  256. - if [ x$current_hostname = x ] || \
  257. - [ x$current_hostname = "x(none)" ] || \
  258. - [ x$current_hostname = xlocalhost ] || \
  259. - [ x$current_hostname = x$old_host_name ]; then
  260. - if [ x$new_host_name != x$old_host_name ]; then
  261. - hostname "$new_host_name"
  262. - fi
  263. - fi
  264. -
  265. - if [ x$old_ip_address != x ] && [ x$alias_ip_address != x ] && \
  266. - [ x$alias_ip_address != x$old_ip_address ]; then
  267. - # Possible new alias. Remove old alias.
  268. - ifconfig $interface:0- inet 0
  269. - fi
  270. - if [ x$old_ip_address != x ] && [ x$old_ip_address != x$new_ip_address ]; then
  271. - # IP address changed. Bringing down the interface will delete all routes,
  272. - # and clear the ARP cache.
  273. - ifconfig $interface inet 0 down
  274. -
  275. - fi
  276. - if [ x$old_ip_address = x ] || [ x$old_ip_address != x$new_ip_address ] || \
  277. - [ x$reason = xBOUND ] || [ x$reason = xREBOOT ]; then
  278. -
  279. - ifconfig $interface inet $new_ip_address $new_subnet_arg \
  280. - $new_broadcast_arg $mtu_arg
  281. - # Add a network route to the computed network address.
  282. - for router in $new_routers; do
  283. - if [ "x$new_subnet_mask" = "x255.255.255.255" ] ; then
  284. - route add -host $router dev $interface
  285. - fi
  286. - route add default gw $router $metric_arg dev $interface
  287. - done
  288. - else
  289. - # we haven't changed the address, have we changed other options
  290. - # that we wish to update?
  291. - if [ x$new_routers != x ] && [ x$new_routers != x$old_routers ] ; then
  292. - # if we've changed routers delete the old and add the new.
  293. - for router in $old_routers; do
  294. - route del default gw $router
  295. - done
  296. - for router in $new_routers; do
  297. - if [ "x$new_subnet_mask" = "x255.255.255.255" ] ; then
  298. - route add -host $router dev $interface
  299. - fi
  300. - route add default gw $router $metric_arg dev $interface
  301. - done
  302. - fi
  303. - fi
  304. - if [ x$new_ip_address != x$alias_ip_address ] && [ x$alias_ip_address != x ];
  305. - then
  306. - ifconfig $interface:0- inet 0
  307. - ifconfig $interface:0 inet $alias_ip_address $alias_subnet_arg
  308. - route add -host $alias_ip_address $interface:0
  309. - fi
  310. - make_resolv_conf
  311. - exit_with_hooks 0
  312. -fi
  313. -
  314. -if [ x$reason = xEXPIRE ] || [ x$reason = xFAIL ] || [ x$reason = xRELEASE ] \
  315. - || [ x$reason = xSTOP ]; then
  316. - if [ x$alias_ip_address != x ]; then
  317. - # Turn off alias interface.
  318. - ifconfig $interface:0- inet 0
  319. - fi
  320. - if [ x$old_ip_address != x ]; then
  321. - # Shut down interface, which will delete routes and clear arp cache.
  322. - ifconfig $interface inet 0 down
  323. - fi
  324. - if [ x$alias_ip_address != x ]; then
  325. - ifconfig $interface:0 inet $alias_ip_address $alias_subnet_arg
  326. - route add -host $alias_ip_address $interface:0
  327. - fi
  328. - exit_with_hooks 0
  329. -fi
  330. -
  331. -if [ x$reason = xTIMEOUT ]; then
  332. - if [ x$alias_ip_address != x ]; then
  333. - ifconfig $interface:0- inet 0
  334. - fi
  335. - ifconfig $interface inet $new_ip_address $new_subnet_arg \
  336. - $new_broadcast_arg $mtu_arg
  337. - set $new_routers
  338. - if ping -q -c 1 $1; then
  339. - if [ x$new_ip_address != x$alias_ip_address ] && \
  340. - [ x$alias_ip_address != x ]; then
  341. - ifconfig $interface:0 inet $alias_ip_address $alias_subnet_arg
  342. - route add -host $alias_ip_address dev $interface:0
  343. - fi
  344. - for router in $new_routers; do
  345. - if [ "x$new_subnet_mask" = "x255.255.255.255" ] ; then
  346. - route add -host $router dev $interface
  347. - fi
  348. - route add default gw $router $metric_arg dev $interface
  349. - done
  350. - make_resolv_conf
  351. - exit_with_hooks 0
  352. - fi
  353. - ifconfig $interface inet 0 down
  354. - exit_with_hooks 1
  355. -fi
  356. -
  357. -###
  358. -### DHCPv6 Handlers
  359. -###
  360. -
  361. -if [ x$reason = xPREINIT6 ] ; then
  362. - # Ensure interface is up.
  363. - ${ip} link set ${interface} up
  364. -
  365. - # Remove any stale addresses from aborted clients.
  366. - ${ip} -f inet6 addr flush dev ${interface} scope global permanent
  367. -
  368. - exit_with_hooks 0
  369. -fi
  370. -
  371. -if [ x${old_ip6_prefix} != x ] || [ x${new_ip6_prefix} != x ] ; then
  372. - echo Prefix ${reason} old=${old_ip6_prefix} new=${new_ip6_prefix}
  373. +# Execute the operation
  374. +case "$reason" in
  375. - exit_with_hooks 0
  376. -fi
  377. -
  378. -if [ x$reason = xBOUND6 ] ; then
  379. - if [ x${new_ip6_address} = x ] || [ x${new_ip6_prefixlen} = x ] ; then
  380. - exit_with_hooks 2;
  381. - fi
  382. + ### DHCPv4 Handlers
  383. - ${ip} -f inet6 addr add ${new_ip6_address}/${new_ip6_prefixlen} \
  384. - dev ${interface} scope global
  385. + MEDIUM|ARPCHECK|ARPSEND)
  386. + # Do nothing
  387. + ;;
  388. + PREINIT)
  389. + # The DHCP client is requesting that an interface be
  390. + # configured as required in order to send packets prior to
  391. + # receiving an actual address. - dhclient-script(8)
  392. +
  393. + # ensure interface is up
  394. + ip link set dev ${interface} up
  395. +
  396. + if [ -n "$alias_ip_address" ]; then
  397. + # flush alias IP from interface
  398. + ip -4 addr flush dev ${interface} label ${interface}:0
  399. + fi
  400. +
  401. + ;;
  402. +
  403. + BOUND|RENEW|REBIND|REBOOT)
  404. + set_hostname
  405. +
  406. + if [ -n "$old_ip_address" ] && [ -n "$alias_ip_address" ] &&
  407. + [ "$alias_ip_address" != "$old_ip_address" ]; then
  408. + # alias IP may have changed => flush it
  409. + ip -4 addr flush dev ${interface} label ${interface}:0
  410. + fi
  411. +
  412. + if [ -n "$old_ip_address" ] &&
  413. + [ "$old_ip_address" != "$new_ip_address" ]; then
  414. + # leased IP has changed => flush it
  415. + ip -4 addr flush dev ${interface} label ${interface}
  416. + fi
  417. +
  418. + if [ -z "$old_ip_address" ] ||
  419. + [ "$old_ip_address" != "$new_ip_address" ] ||
  420. + [ "$reason" = "BOUND" ] || [ "$reason" = "REBOOT" ]; then
  421. + # new IP has been leased or leased IP changed => set it
  422. + ip -4 addr add ${new_ip_address}${new_subnet_mask:+/$new_subnet_mask} \
  423. + ${new_broadcast_address:+broadcast $new_broadcast_address} \
  424. + dev ${interface} label ${interface}
  425. +
  426. + if [ -n "$new_interface_mtu" ]; then
  427. + # set MTU
  428. + ip link set dev ${interface} mtu ${new_interface_mtu}
  429. + fi
  430. +
  431. + # set if_metric if IF_METRIC is set or there's more than one router
  432. + if_metric="$IF_METRIC"
  433. + if [ "${new_routers%% *}" != "${new_routers}" ]; then
  434. + if_metric=${if_metric:-1}
  435. + fi
  436. +
  437. + for router in $new_routers; do
  438. + if [ "$new_subnet_mask" = "255.255.255.255" ]; then
  439. + # point-to-point connection => set explicit route
  440. + ip -4 route add ${router} dev $interface >/dev/null 2>&1
  441. + fi
  442. +
  443. + # set default route
  444. + ip -4 route add default via ${router} dev ${interface} \
  445. + ${if_metric:+metric $if_metric} >/dev/null 2>&1
  446. +
  447. + if [ -n "$if_metric" ]; then
  448. + if_metric=$((if_metric+1))
  449. + fi
  450. + done
  451. + fi
  452. +
  453. + if [ -n "$alias_ip_address" ] &&
  454. + [ "$new_ip_address" != "$alias_ip_address" ]; then
  455. + # separate alias IP given, which may have changed
  456. + # => flush it, set it & add host route to it
  457. + ip -4 addr flush dev ${interface} label ${interface}:0
  458. + ip -4 addr add ${alias_ip_address}${alias_subnet_mask:+/$alias_subnet_mask} \
  459. + dev ${interface} label ${interface}:0
  460. + ip -4 route add ${alias_ip_address} dev ${interface} >/dev/null 2>&1
  461. + fi
  462. +
  463. + # update /etc/resolv.conf
  464. + make_resolv_conf
  465. +
  466. + ;;
  467. +
  468. + EXPIRE|FAIL|RELEASE|STOP)
  469. + if [ -n "$alias_ip_address" ]; then
  470. + # flush alias IP
  471. + ip -4 addr flush dev ${interface} label ${interface}:0
  472. + fi
  473. +
  474. + if [ -n "$old_ip_address" ]; then
  475. + # flush leased IP
  476. + ip -4 addr flush dev ${interface} label ${interface}
  477. + fi
  478. +
  479. + if [ -n "$alias_ip_address" ]; then
  480. + # alias IP given => set it & add host route to it
  481. + ip -4 addr add ${alias_ip_address}${alias_network_arg} \
  482. + dev ${interface} label ${interface}:0
  483. + ip -4 route add ${alias_ip_address} dev ${interface} >/dev/null 2>&1
  484. + fi
  485. +
  486. + ;;
  487. +
  488. + TIMEOUT)
  489. + if [ -n "$alias_ip_address" ]; then
  490. + # flush alias IP
  491. + ip -4 addr flush dev ${interface} label ${interface}:0
  492. + fi
  493. +
  494. + # set IP from recorded lease
  495. + ip -4 addr add ${new_ip_address}${new_subnet_mask:+/$new_subnet_mask} \
  496. + ${new_broadcast_address:+broadcast $new_broadcast_address} \
  497. + dev ${interface} label ${interface}
  498. +
  499. + if [ -n "$new_interface_mtu" ]; then
  500. + # set MTU
  501. + ip link set dev ${interface} mtu ${new_interface_mtu}
  502. + fi
  503. +
  504. + # if there is no router recorded in the lease or the 1st router answers pings
  505. + if [ -z "$new_routers" ] || ping -q -c 1 "${new_routers%% *}"; then
  506. + if [ -n "$alias_ip_address" ] &&
  507. + [ "$new_ip_address" != "$alias_ip_address" ]; then
  508. + # separate alias IP given => set up the alias IP & add host route to it
  509. + ip -4 addr add ${alias_ip_address}${alias_subnet_mask:+/$alias_subnet_mask} \
  510. + dev ${interface} label ${interface}:0
  511. + ip -4 route add ${alias_ip_address} dev ${interface} >/dev/null 2>&1
  512. + fi
  513. +
  514. + # set if_metric if IF_METRIC is set or there's more than one router
  515. + if_metric="$IF_METRIC"
  516. + if [ "${new_routers%% *}" != "${new_routers}" ]; then
  517. + if_metric=${if_metric:-1}
  518. + fi
  519. +
  520. + # set default route
  521. + for router in $new_routers; do
  522. + ip -4 route add default via ${router} dev ${interface} \
  523. + ${if_metric:+metric $if_metric} >/dev/null 2>&1
  524. +
  525. + if [ -n "$if_metric" ]; then
  526. + if_metric=$((if_metric+1))
  527. + fi
  528. + done
  529. +
  530. + # update /etc/resolv.conf
  531. + make_resolv_conf
  532. + else
  533. + # flush all IPs from interface
  534. + ip -4 addr flush dev ${interface}
  535. + exit_with_hooks 1
  536. + fi
  537. +
  538. + ;;
  539. +
  540. + ### DHCPv6 Handlers
  541. + # TODO handle prefix change: ?based on ${old_ip6_prefix} and ${new_ip6_prefix}?
  542. +
  543. + PREINIT6)
  544. + # ensure interface is up
  545. + ip link set ${interface} up
  546. +
  547. + # flush any stale global permanent IPs from interface
  548. + ip -6 addr flush dev ${interface} scope global permanent
  549. +
  550. + ;;
  551. +
  552. + BOUND6|RENEW6|REBIND6)
  553. + if [ "${new_ip6_address}" ] && [ "${new_ip6_prefixlen}" ]; then
  554. + # set leased IP
  555. + ip -6 addr add ${new_ip6_address}/${new_ip6_prefixlen} \
  556. + dev ${interface} scope global
  557. + fi
  558. +
  559. + # update /etc/resolv.conf
  560. + if [ "${reason}" = BOUND6 ] ||
  561. + [ "${new_dhcp6_name_servers}" != "${old_dhcp6_name_servers}" ] ||
  562. + [ "${new_dhcp6_domain_search}" != "${old_dhcp6_domain_search}" ]; then
  563. + make_resolv_conf
  564. + fi
  565. +
  566. + ;;
  567. +
  568. + DEPREF6)
  569. + if [ -z "${cur_ip6_prefixlen}" ]; then
  570. + exit_with_hooks 1
  571. + fi
  572. +
  573. + # set preferred lifetime of leased IP to 0
  574. + ip -6 addr change ${cur_ip6_address}/${cur_ip6_prefixlen} \
  575. + dev ${interface} scope global preferred_lft 0
  576. +
  577. + ;;
  578. +
  579. + EXPIRE6|RELEASE6|STOP6)
  580. + if [ -z "${old_ip6_address}" ] || [ -z "${old_ip6_prefixlen}" ]; then
  581. + exit_with_hooks 1
  582. + fi
  583. +
  584. + # delete leased IP
  585. + ip -6 addr del ${old_ip6_address}/${old_ip6_prefixlen} \
  586. + dev ${interface}
  587. - # Check for nameserver options.
  588. - make_resolv_conf
  589. -
  590. - exit_with_hooks 0
  591. -fi
  592. -
  593. -if [ x$reason = xRENEW6 ] || [ x$reason = xREBIND6 ] ; then
  594. - if [ x${new_ip6_address} != x ] && [ x${new_ip6_prefixlen} != x ] ; then
  595. - ${ip} -f inet6 addr add ${new_ip6_address}/${new_ip6_prefixlen} \
  596. - dev ${interface} scope global
  597. - fi
  598. -
  599. - # Make sure nothing has moved around on us.
  600. -
  601. - # Nameservers/domains/etc.
  602. - if [ "x${new_dhcp6_name_servers}" != "x${old_dhcp6_name_servers}" ] ||
  603. - [ "x${new_dhcp6_domain_search}" != "x${old_dhcp6_domain_search}" ] ; then
  604. - make_resolv_conf
  605. - fi
  606. -
  607. - exit_with_hooks 0
  608. -fi
  609. -
  610. -if [ x$reason = xDEPREF6 ] ; then
  611. - if [ x${new_ip6_prefixlen} = x ] ; then
  612. - exit_with_hooks 2;
  613. - fi
  614. -
  615. - ${ip} -f inet6 addr change ${new_ip6_address}/${new_ip6_prefixlen} \
  616. - dev ${interface} scope global preferred_lft 0
  617. -
  618. - exit_with_hooks 0
  619. -fi
  620. -
  621. -if [ x$reason = xEXPIRE6 -o x$reason = xRELEASE6 -o x$reason = xSTOP6 ] ; then
  622. - if [ x${old_ip6_address} = x ] || [ x${old_ip6_prefixlen} = x ] ; then
  623. - exit_with_hooks 2;
  624. - fi
  625. -
  626. - ${ip} -f inet6 addr del ${old_ip6_address}/${old_ip6_prefixlen} \
  627. - dev ${interface}
  628. -
  629. - exit_with_hooks 0
  630. -fi
  631. + ;;
  632. +esac
  633. exit_with_hooks 0