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 # Disable autoconf because DHCP is handling this
45 ipv6_device_autoconf_disable
"${interface}"
47 # Enable forwarding because we are acting as a host
48 # to uplink network zones.
49 ipv6_device_forwarding_enable
"${interface}" --accept-ra
51 # Wait until DAD for the link-local address has finished
52 for address
in $
(ipv6_device_get_addresses
"${interface}" --scope="link"); do
53 ipv6_wait_for_dad
"${address}" "${interface}" && exit ${EXIT_OK}
56 log ERROR "There is no active link-local address on
${interface}"
62 # We will be called twice. Once for the assigned address and once for an assigned prefix.
64 # Handle temporarily-assigned address
65 if isset new_ip6_address && isset new_ip6_prefixlen; then
66 ipv6_address_add "${new_ip6_address}/${new_ip6_prefixlen}" "${interface}" \
67 --valid-lifetime="${new_max_life}" --preferred-lifetime="${new_preferred_life}"
70 db_set "${interface}/ipv6/local-ip-address" "${new_ip6_address}/${new_ip6_prefixlen}"
71 db_set "${interface}/ipv
6/active
" 1
72 #db_set "${interface}/ipv
6/domain-name
" "$
{new_
74 # Update the routing tables
75 routing_update
"${interface}" ipv6
79 # Handle Prefix Delegation
80 elif isset new_ip6_prefix
; then
81 db_set
"${interface}/ipv6/delegated-prefix" "${new_ip6_prefix}"
88 # Will be called twice like BOUND6.
90 if isset new_ip6_address
&& isset new_ip6_prefixlen
; then
91 # Update nameservers if those have changed
92 if [[ "${old_dhcp6_name_servers}" != "${new_dhcp6_name_servers}" ]]; then
93 db_set
"${interface}/ipv6/domain-name-servers" "${new_dhcp6_name_servers}"
94 dns_generate_resolvconf
97 # Update the lifetime if the address has not changed
98 if [[ "${old_ip6_address}" = "${new_ip6_address}" ]]; then
99 ipv6_address_change_lifetime
"${new_ip6_address}/${new_ip6_prefixlen}" "${interface}" \
100 --valid-lifetime="${new_max_life}" --preferred-lifetime="${new_preferred_life}"
105 # Remove any old IP addresses
106 if [ -n "${old_ip6_address}" ]; then
107 ipv6_address_del
"${old_ip6_address}/${old_ip6_prefixlen}" "${interface}"
110 # Update the database
111 db_set
"${interface}/ipv6/local-ip-address" \
112 "${new_ip6_address}/${new_ip6_prefixlen}"
115 ipv6_address_add
"${new_ip6_address}/${new_ip6_prefixlen}" "${interface}" \
116 --valid-lifetime="${new_max_life}" --preferred-lifetime="${new_preferred_life}"
118 # Update the routing tables
119 routing_update
"${interface}" ipv6
123 # Handle Prefix Delegation
124 elif isset new_ip6_prefix || isset old_ip6_prefix
; then
125 if [[ "${old_ip6_prefix}" = "${new_ip6_prefix}" ]]; then
126 # TODO What do we need to do if the prefix hasn't changed?
130 log DEBUG
"The delegated prefix has changed from ${old_ip6_prefix} to ${new_ip6_prefix}"
131 db_set
"${interface}/ipv6/delegated-prefix" "${new_ip6_prefix}"
138 # Check if all necessary information is there
139 if ! isset cur_ip6_address ||
! isset cur_ip6_prefixlen
; then
143 # Set lifetime to zero
144 ipv6_address_change_lifetime
"${cur_ip6_address}/${cur_ip6_prefixlen}" "${interface}" \
145 --preferred-lifetime=0 ||
exit ${EXIT_ERROR}
148 EXPIRE6|FAIL6|RELEASE6|STOP6
)
149 # Remove the currently configured addresses from the device.
150 ipv6_address_flush
"${interface}"
152 # Reset autoconf mode and disable forwarding
153 ipv6_device_forwarding_disable
"${interface}"
154 ipv6_device_autoconf_disable
"${interface}"
156 db_delete
"${interface}/ipv6"
164 # Bring up the device if it hasn't been done before.
165 if ! device_is_up
${interface}; then
166 log DEBUG
"The interface '${interface}' does not appear to be up."
171 # If the use configured a delay, we will honour that.
172 if [ -n "${DELAY}" ]; then
173 assert isinteger DELAY
176 # If he didn't, we will try to detect is STP has brought the
178 elif device_is_bridge
${interface}; then
181 while [ ${counter} -gt 0 ]; do
182 # We may end this, when the bridge is in forwarding mode.
183 if bridge_is_forwarding
${interface}; then
184 log DEBUG
"Bridge '${interface}' is in forwarding mode."
188 counter
=$
(( ${counter} - 1 ))
192 # Tell the daemon, that we are not ready to go on.
193 if [ ${counter} -eq 0 ]; then
194 log ERROR
"Bridge '${interface}' is not in forwarding mode."
195 log ERROR
"Could not go on with getting a DHCP lease. Exiting."
204 BOUND|RENEW|REBIND|REBOOT
)
205 # Check if the IP address has changed. If so, delete all routes and stuff.
206 if [ -n "${old_ip_address}" -a "${old_ip_address}" != "${new_ip_address}" ]; then
207 ipv4_flush_device
${interface}
212 if [ ! "${old_ip_address}" = "${new_ip_address}" ] || \
213 [ ! "${old_subnet_mask}" = "${new_subnet_mask}" ] || \
214 [ ! "${old_network_number}" = "${new_network_number}" ] || \
215 [ ! "${old_broadcast_address}" = "${new_broadcast_address}" ] || \
216 [ ! "${old_routers}" = "${new_routers}" ] || \
217 [ ! "${old_interface_mtu}" = "${new_interface_mtu}" ]; then
220 # Calc a prefix out of address and subnet mask.
221 new_prefix
="$(ipv4_get_prefix ${new_ip_address} ${new_subnet_mask})"
223 # Set the new ip address.
224 ip_address_add
${interface} ${new_ip_address}/${new_prefix}
225 device_set_up
${interface}
228 # A MTU of 576 is used for X.25 and dialup connections. Some broken DHCP
229 # servers send out an MTU of 576 bytes, which will be ignored.
230 if [ -n "${new_interface_mtu}" ] && [ ${new_interface_mtu} -gt 576 ]; then
231 device_set_mtu
${interface} ${new_interface_mtu}
235 db_set
"${interface}/ipv4/type" "ipv4-dhcp"
236 db_set
"${interface}/ipv4/local-ip-address" \
237 "${new_ip_address}/${new_prefix}"
238 db_set
"${interface}/ipv4/remote-ip-address" "${new_routers}"
239 db_set
"${interface}/ipv4/active" 1
240 db_set
"${interface}/ipv4/domain-name" "${new_domain_name}"
241 db_set
"${interface}/ipv4/domain-name-servers" \
242 "${new_domain_name_servers}"
243 db_set
"${interface}/ipv4/domain-name-servers-priority" \
244 "${DNS_SERVER_DYNAMIC_PRIORITY}"
246 # Update the routing tables.
247 routing_update
${interface} ipv4
248 routing_default_update
251 dns_generate_resolvconf
259 EXPIRE|FAIL|RELEASE|STOP
)
260 # Remove the currently configured addresses from the device.
261 if [ -n "${old_ip_address}" ]; then
262 ipv4_flush_device
${interface}
265 db_delete
"${interface}/ipv4"
266 routing_default_update
272 log ERROR
"Unhandled reason: ${reason}"