3 .
/usr
/lib
/network
/functions
6 LOG_FACILITY
="dhclient-script"
10 assert isset interface
13 assert device_exists
${interface}
15 basename="$(basename $0)"
16 log DEBUG
"${basename} called for interface=${interface} reason=${reason}"
18 # Log all information from dhclient
19 if enabled DEBUG
; then
21 [[ ${line} =~ ^
(cur|old|new
)_
]] ||
continue
23 done <<< "$(printenv | sort)"
29 # Linux does not handle MEDIUM.
36 if ! device_is_up
"${interface}"; then
37 log WARNING
"Device '${interface}' was not brought up before starting the DHCP client"
38 device_set_up
"${interface}"
41 # Flush all other aborted IP addresses
42 ipv6_address_flush
"${interface}"
44 # Wait until DAD for the link-local address has finished
45 for address
in $
(ipv6_device_get_addresses
"${interface}" --scope="link"); do
46 ipv6_wait_for_dad
"${address}" "${interface}" && exit ${EXIT_OK}
49 log ERROR "There is no active link-local address on
${interface}"
55 # We will be called twice. Once for the assigned address and once for an assigned prefix.
57 # Handle temporarily-assigned address
58 if isset new_ip6_address && isset new_ip6_prefixlen; then
59 ipv6_address_add "${new_ip6_address}/${new_ip6_prefixlen}" "${interface}" \
60 --valid-lifetime="${new_max_life}" --preferred-lifetime="${new_preferred_life}"
63 db_set "${interface}/ipv6/local-ip-address" "${new_ip6_address}/${new_ip6_prefixlen}"
64 db_set "${interface}/ipv
6/active
" 1
65 #db_set "${interface}/ipv
6/domain-name
" "$
{new_
69 # Handle Prefix Delegation
70 elif isset new_ip6_prefix
; then
71 db_set
"${interface}/ipv6/delegated-prefix" "${new_ip6_prefix}"
78 # Will be called twice like BOUND6.
80 if isset new_ip6_address
&& isset new_ip6_prefixlen
; then
81 # Update nameservers if those have changed
82 if [[ "${old_dhcp6_name_servers}" != "${new_dhcp6_name_servers}" ]]; then
83 db_set
"${interface}/ipv6/domain-name-servers" "${new_dhcp6_name_servers}"
84 dns_generate_resolvconf
87 # Update the lifetime if the address has not changed
88 if [[ "${old_ip6_address}" = "${new_ip6_address}" ]]; then
89 ipv6_address_change_lifetime
"${new_ip6_address}/${new_ip6_prefixlen}" "${interface}" \
90 --valid-lifetime="${new_max_life}" --preferred-lifetime="${new_preferred_life}"
95 # Remove any old IP addresses
96 if [ -n "${old_ip6_address}" ]; then
97 ipv6_address_del
"${old_ip6_address}/${old_ip6_prefixlen}" "${interface}"
100 # Update the database
101 db_set
"${interface}/ipv6/local-ip-address" \
102 "${new_ip6_address}/${new_ip6_prefixlen}"
105 ipv6_address_add
"${new_ip6_address}/${new_ip6_prefixlen}" "${interface}" \
106 --valid-lifetime="${new_max_life}" --preferred-lifetime="${new_preferred_life}"
110 # Handle Prefix Delegation
111 elif isset new_ip6_prefix || isset old_ip6_prefix
; then
112 if [[ "${old_ip6_prefix}" = "${new_ip6_prefix}" ]]; then
113 # TODO What do we need to do if the prefix hasn't changed?
117 log DEBUG
"The delegated prefix has changed from ${old_ip6_prefix} to ${new_ip6_prefix}"
118 db_set
"${interface}/ipv6/delegated-prefix" "${new_ip6_prefix}"
125 # Check if all necessary information is there
126 if ! isset cur_ip6_address ||
! isset cur_ip6_prefixlen
; then
130 # Set lifetime to zero
131 ipv6_address_change_lifetime
"${cur_ip6_address}/${cur_ip6_prefixlen}" "${interface}" \
132 --preferred-lifetime=0 ||
exit ${EXIT_ERROR}
138 # Bring up the device if it hasn't been done before.
139 if ! device_is_up
${interface}; then
140 log DEBUG
"The interface '${interface}' does not appear to be up."
145 # If the use configured a delay, we will honour that.
146 if [ -n "${DELAY}" ]; then
147 assert isinteger DELAY
150 # If he didn't, we will try to detect is STP has brought the
152 elif device_is_bridge
${interface}; then
155 while [ ${counter} -gt 0 ]; do
156 # We may end this, when the bridge is in forwarding mode.
157 if bridge_is_forwarding
${interface}; then
158 log DEBUG
"Bridge '${interface}' is in forwarding mode."
162 counter
=$
(( ${counter} - 1 ))
166 # Tell the daemon, that we are not ready to go on.
167 if [ ${counter} -eq 0 ]; then
168 log ERROR
"Bridge '${interface}' is not in forwarding mode."
169 log ERROR
"Could not go on with getting a DHCP lease. Exiting."
178 BOUND|RENEW|REBIND|REBOOT
)
179 # Check if the IP address has changed. If so, delete all routes and stuff.
180 if [ -n "${old_ip_address}" -a "${old_ip_address}" != "${new_ip_address}" ]; then
181 ipv4_flush_device
${interface}
186 if [ ! "${old_ip_address}" = "${new_ip_address}" ] || \
187 [ ! "${old_subnet_mask}" = "${new_subnet_mask}" ] || \
188 [ ! "${old_network_number}" = "${new_network_number}" ] || \
189 [ ! "${old_broadcast_address}" = "${new_broadcast_address}" ] || \
190 [ ! "${old_routers}" = "${new_routers}" ] || \
191 [ ! "${old_interface_mtu}" = "${new_interface_mtu}" ]; then
194 # Calc a prefix out of address and subnet mask.
195 new_prefix
="$(ipv4_get_prefix ${new_ip_address} ${new_subnet_mask})"
197 # Set the new ip address.
198 ip_address_add
${interface} ${new_ip_address}/${new_prefix}
199 device_set_up
${interface}
202 # A MTU of 576 is used for X.25 and dialup connections. Some broken DHCP
203 # servers send out an MTU of 576 bytes, which will be ignored.
204 if [ -n "${new_interface_mtu}" ] && [ ${new_interface_mtu} -gt 576 ]; then
205 device_set_mtu
${interface} ${new_interface_mtu}
209 db_set
"${interface}/ipv4/type" "ipv4-dhcp"
210 db_set
"${interface}/ipv4/local-ip-address" \
211 "${new_ip_address}/${new_prefix}"
212 db_set
"${interface}/ipv4/remote-ip-address" "${new_routers}"
213 db_set
"${interface}/ipv4/active" 1
214 db_set
"${interface}/ipv4/domain-name" "${new_domain_name}"
215 db_set
"${interface}/ipv4/domain-name-servers" \
216 "${new_domain_name_servers}"
217 db_set
"${interface}/ipv4/domain-name-servers-priority" \
218 "${DNS_SERVER_DYNAMIC_PRIORITY}"
220 # Update the routing tables.
221 routing_update
${interface} ipv4
222 routing_default_update
225 dns_generate_resolvconf
233 EXPIRE|FAIL|RELEASE|STOP
)
234 # Remove the currently configured addresses from the device.
235 if [ -n "${old_ip_address}" ]; then
236 ipv4_flush_device
${interface}
239 db_delete
"${interface}/ipv4"
240 routing_default_update
246 log ERROR
"Unhandled reason: ${reason}"