dhclient-hooks/000075500000000000000000000000001222275013000137615ustar00rootroot00000000000000dhclient-hooks/10-ip-config000064400000000000000000000177671222275013000160170ustar00rootroot00000000000000# General interface configuration # Set addresses and routes. pad_network() { local addr="$1" local c c=$((3-$(echo "$addr" | grep -o '\.' | wc -l))) [ $c -ge 0 ] 2>/dev/null || return 1 while [ "$c" -gt 0 ]; do addr="$addr.0" c=$((c-1)) done echo "$addr" } set_classless_static_routes() { local prefix dest via_arg net_address gateway set -- $new_classless_static_routes while [ $# -gt 0 ]; do dest="$1" gateway="$2" shift 2 [ -n "$dest" -a -n "$gateway" ] || return 1 prefix="${dest%%.*}" if [ $prefix -eq 0 ]; then # default route net_address="0.0.0.0" elif [ $prefix -gt 0 -a $prefix -le 32 ]; then net_address="$(pad_network ${dest#*.})" else return 1 fi # take care of link-local routes if [ "${gateway}" != '0.0.0.0' ]; then via_arg="via ${gateway}" else via_arg='' fi # set route (ip detects host routes automatically) ip -4 route add "${net_address}/${prefix}" \ ${via_arg} dev "${interface}" >/dev/null 2>&1 done } case "$reason" in ### DHCPv4 Handlers MEDIUM|ARPCHECK|ARPSEND) # Do nothing ;; PREINIT) # The DHCP client is requesting that an interface be # configured as required in order to send packets prior to # receiving an actual address. - dhclient-script(8) # ensure interface is up ip link set dev ${interface} up if [ -n "$alias_ip_address" ]; then # flush alias IP from interface ip -4 addr flush dev ${interface} label ${interface}:0 fi ;; BOUND|RENEW|REBIND|REBOOT) if [ -n "$old_ip_address" ] && [ -n "$alias_ip_address" ] && [ "$alias_ip_address" != "$old_ip_address" ]; then # alias IP may have changed => flush it ip -4 addr flush dev ${interface} label ${interface}:0 fi if [ -n "$old_ip_address" ] && [ "$old_ip_address" != "$new_ip_address" ]; then # leased IP has changed => flush it ip -4 addr flush dev ${interface} label ${interface} fi if [ -z "$old_ip_address" ] || [ "$old_ip_address" != "$new_ip_address" ] || [ "$reason" = "BOUND" ] || [ "$reason" = "REBOOT" ]; then # new IP has been leased or leased IP changed => set it ip -4 addr add ${new_ip_address}${new_subnet_mask:+/$new_subnet_mask} \ ${new_broadcast_address:+broadcast $new_broadcast_address} \ dev ${interface} label ${interface} # if we have $new_classless_static_routes then we have to # ignore $new_routers entirely if [ -n "$new_classless_static_routes" ]; then set_classless_static_routes else # set if_metric if IF_METRIC is set or there's more than one router if_metric="$IF_METRIC" if [ "${new_routers%% *}" != "${new_routers}" ]; then if_metric=${if_metric:-1} fi for router in $new_routers; do if [ "$new_subnet_mask" = "255.255.255.255" ]; then # point-to-point connection => set explicit route ip -4 route add ${router} dev $interface >/dev/null 2>&1 fi # set default route ip -4 route add default via ${router} dev ${interface} \ ${if_metric:+metric $if_metric} >/dev/null 2>&1 if [ -n "$if_metric" ]; then if_metric=$((if_metric+1)) fi done fi fi if [ -n "$alias_ip_address" ] && [ "$new_ip_address" != "$alias_ip_address" ]; then # separate alias IP given, which may have changed # => flush it, set it & add host route to it ip -4 addr flush dev ${interface} label ${interface}:0 ip -4 addr add ${alias_ip_address}${alias_subnet_mask:+/$alias_subnet_mask} \ dev ${interface} label ${interface}:0 ip -4 route add ${alias_ip_address} dev ${interface} >/dev/null 2>&1 fi ;; EXPIRE|FAIL|RELEASE|STOP) if [ -n "$alias_ip_address" ]; then # flush alias IP ip -4 addr flush dev ${interface} label ${interface}:0 fi if [ -n "$old_ip_address" ]; then # flush leased IP ip -4 addr flush dev ${interface} label ${interface} fi if [ -n "$alias_ip_address" ]; then # alias IP given => set it & add host route to it ip -4 addr add ${alias_ip_address}${alias_network_arg} \ dev ${interface} label ${interface}:0 ip -4 route add ${alias_ip_address} dev ${interface} >/dev/null 2>&1 fi ;; TIMEOUT) if [ -n "$alias_ip_address" ]; then # flush alias IP ip -4 addr flush dev ${interface} label ${interface}:0 fi # set IP from recorded lease ip -4 addr add ${new_ip_address}${new_subnet_mask:+/$new_subnet_mask} \ ${new_broadcast_address:+broadcast $new_broadcast_address} \ dev ${interface} label ${interface} # if there is no router recorded in the lease or the 1st router answers pings if [ -z "$new_routers" ] || ping -q -c 1 "${new_routers%% *}"; then # if we have $new_classless_static_routes then we have to # ignore $new_routers entirely if [ ! "$new_classless_static_routes" ]; then if [ -n "$alias_ip_address" ] && [ "$new_ip_address" != "$alias_ip_address" ]; then # separate alias IP given => set up the alias IP & add host route to it ip -4 addr add ${alias_ip_address}${alias_subnet_mask:+/$alias_subnet_mask} \ dev ${interface} label ${interface}:0 ip -4 route add ${alias_ip_address} dev ${interface} >/dev/null 2>&1 fi # set if_metric if IF_METRIC is set or there's more than one router if_metric="$IF_METRIC" if [ "${new_routers%% *}" != "${new_routers}" ]; then if_metric=${if_metric:-1} fi # set default route for router in $new_routers; do ip -4 route add default via ${router} dev ${interface} \ ${if_metric:+metric $if_metric} >/dev/null 2>&1 if [ -n "$if_metric" ]; then if_metric=$((if_metric+1)) fi done fi else # flush all IPs from interface ip -4 addr flush dev ${interface} fi ;; ### DHCPv6 Handlers # TODO handle prefix change: ?based on ${old_ip6_prefix} and ${new_ip6_prefix}? PREINIT6) # ensure interface is up ip link set ${interface} up # flush any stale global permanent IPs from interface ip -6 addr flush dev ${interface} scope global permanent ;; BOUND6|RENEW6|REBIND6) if [ -n "${new_ip6_address}" -a -n "${new_ip6_prefixlen}" ] && [ "${new_ip6_address}" != "${old_ip6_address}" ]; then # set leased IP ip -6 addr add ${new_ip6_address}/${new_ip6_prefixlen} \ dev ${interface} scope global fi ;; DEPREF6) if [ -n "${cur_ip6_prefixlen}" ]; then # set preferred lifetime of leased IP to 0 ip -6 addr change ${cur_ip6_address}/${cur_ip6_prefixlen} \ dev ${interface} scope global preferred_lft 0 fi ;; EXPIRE6|RELEASE6|STOP6) if [ -n "${old_ip6_address}" -a -n "${old_ip6_prefixlen}" ]; then # delete leased IP ip -6 addr del ${old_ip6_address}/${old_ip6_prefixlen} \ dev ${interface} fi ;; esac dhclient-hooks/20-mtu000064400000000000000000000011451222275013000147310ustar00rootroot00000000000000# Configure the MTU for the interface case "$reason" in BOUND|RENEW|REBIND|REBOOT|TIMEOUT) # The 576 MTU is only used for X.25 and dialup connections # where the admin wants low latency. Such a low MTU can cause # problems with UDP traffic, among other things. As such, # disallow MTUs from 576 and below by default, so that broken # MTUs are ignored, but higher stuff is allowed (1492, 1500, etc). if [ -n "$new_interface_mtu" ] && [ "$new_interface_mtu" -gt 576 ]; then # set MTU ip link set dev ${interface} mtu ${new_interface_mtu} fi esac dhclient-hooks/30-resolv.conf000064400000000000000000000102421222275013000163610ustar00rootroot00000000000000# Update /etc/resolv.conf. save_resolv_conf="$dhclient_state_dir"/resolv.conf.dhclient.save resolvconf_tool=resolvconf uchrooted=update_chrooted NL=' ' # update /etc/resolv.conf based on received values make_resolv_conf() { local new_resolv_conf_content="# Generated by dhclient-script$NL" local resolvconf_ifname="${interface}${1-}" # DHCPv4 if [ -n "$new_domain_search" ] || [ -n "$new_domain_name" ] || [ -n "$new_domain_name_servers" ]; then if [ -n "$new_domain_name" ]; then new_resolv_conf_content="domain ${new_domain_name%% *}$NL" fi if [ -n "$new_domain_search" ]; then if [ -n "$new_domain_name" ]; then domain_in_search_list="" for domain in $new_domain_search; do if [ "$domain" = "${new_domain_name}" ] || [ "$domain" = "${new_domain_name}." ]; then domain_in_search_list="Yes" fi done if [ -z "$domain_in_search_list" ]; then new_domain_search="$new_domain_name $new_domain_search" fi fi new_resolv_conf_content="${new_resolv_conf_content}search ${new_domain_search}$NL" elif [ -n "$new_domain_name" ]; then new_resolv_conf_content="${new_resolv_conf_content}search ${new_domain_name}$NL" fi if [ -n "$new_domain_name_servers" ]; then for nameserver in $new_domain_name_servers; do new_resolv_conf_content="${new_resolv_conf_content}nameserver $nameserver$NL" done fi # DHCPv6 elif [ -n "$new_dhcp6_domain_search" ] || [ -n "$new_dhcp6_name_servers" ]; then if [ -n "$new_dhcp6_domain_search" ]; then new_resolv_conf_content="search ${new_dhcp6_domain_search}$NL" fi if [ -n "$new_dhcp6_name_servers" ]; then for nameserver in $new_dhcp6_name_servers; do # append %interface to link-local-address nameservers if [ "${nameserver##fe80::}" != "$nameserver" ] || [ "${nameserver##FE80::}" != "$nameserver" ]; then nameserver="${nameserver}%${interface}" fi new_resolv_conf_content="${new_resolv_conf_content}nameserver $nameserver$NL" done fi fi if type "$resolvconf_tool" >/dev/null 2>&1; then echo "$new_resolv_conf_content" | $resolvconf_tool -a "$resolvconf_ifname" else local new_resolv_conf_file=/etc/resolv.conf.dhclient-new echo "$new_resolv_conf_content" >$new_resolv_conf_file # keep 'old' nameservers sed -n /^\w*[Nn][Aa][Mm][Ee][Ss][Ee][Rr][Vv][Ee][Rr]/p /etc/resolv.conf >>$new_resolv_conf_file if [ -f /etc/resolv.conf ]; then chown --reference=/etc/resolv.conf $new_resolv_conf_file chmod --reference=/etc/resolv.conf $new_resolv_conf_file fi if [ ! -e $save_resolv_conf ]; then mv -f /etc/resolv.conf "$save_resolv_conf" fi mv -f $new_resolv_conf_file /etc/resolv.conf if type "$uchrooted" >/dev/null 2>&1; then "$uchrooted" conf fi fi } remove_resolv_conf() { if type "$resolvconf_tool" >/dev/null 2>&1; then $resolvconf_tool -f -d "${interface}${1-}" ||: elif [ -e "$save_resolv_conf" ]; then mv -f "$save_resolv_conf" /etc/resolv.conf if type "$uchrooted" >/dev/null 2>&1; then "$uchrooted" conf fi fi } case "$reason" in BOUND|RENEW|REBIND|REBOOT) make_resolv_conf "" ;; BOUND6) if [ "${new_dhcp6_name_servers}" != "${old_dhcp6_name_servers}" ] || [ "${new_dhcp6_domain_search}" != "${old_dhcp6_domain_search}" ]; then make_resolv_conf ".ipv6" fi ;; EXPIRE|FAIL|RELEASE|STOP) remove_resolv_conf "" ;; EXPIRE6|RELEASE6|STOP6) remove_resolv_conf ".ipv6" ;; TIMEOUT) # Check IPv4 routes via interface # TODO: What about IPv6? if ip -4 route list dev "$interface" | grep -aqs .; then make_resolv_conf "" else remove_resolv_conf "" fi ;; esac dhclient-hooks/40-hostname000064400000000000000000000013121222275013000157400ustar00rootroot00000000000000# set host name set_hostname() { local current_hostname if [ -n "$new_host_name" ]; then current_hostname=$(hostname) # current host name is empty, '(none)' or 'localhost' or differs from new one from DHCP if [ -z "$current_hostname" ] || [ "$current_hostname" = '(none)' ] || [ "$current_hostname" = 'localhost' ] || [ "$current_hostname" = 'localhost.localdomain' ] || [ "$current_hostname" = "$old_host_name" ]; then if [ "$new_host_name" != "$old_host_name" ]; then hostname "$new_host_name" fi fi fi } case "$reason" in BOUND|RENEW|REBIND|REBOOT) set_hostname ;; esac dhclient-hooks/60-ntp.conf000064400000000000000000000057351222275013000156660ustar00rootroot00000000000000# hook script for ntmp# We store a database of ntp.conf files # and merge into /etc/ntp.conf # Heavy based on hook from dhcpcd. signature_base="# Generated by dhclient" signature_base_end="# End of dhclient" if [ -x /etc/init.d/ntpd ]; then ntpd_restart_cmd="/sbin/service ntpd condrestart" fi ntp_conf_dir="$dhclient_state_dir/ntp.conf" NL=" " uniqify() { local result= i= for i do case " $result " in *" $i "*);; *) result="$result $i";; esac done echo "${result# *}" } list_interfaces() { local ifaces= i= for x in "$1"/*; do i="${x##*/}" [ "$i" != "$interface" -a "$i" != '*' ] || continue ifaces="$ifaces${ifaces:+ }$i" done [ -f "$1/$interface" ] && ifaces="$interface${ifaces:+ }$ifaces" echo "$ifaces" } build_ntp_conf() { local ntp_conf="$1" local server_keyword=${2:-server} local cf="$dhclient_state_dir/ntp.conf.$interface" local ifaces= header= srvs= servers= x= local ret=1 [ -w $ntp_conf ] || return 1 # Build a list of interfaces ifaces="$(list_interfaces "$ntp_conf_dir")" if [ -n "$ifaces" ]; then # Build the header for x in ${ifaces}; do header="$header${header:+, }$x" done # Build a server list srvs=$(cd "$ntp_conf_dir"; sed -n "s/^server //p" $ifaces) if [ -n "$srvs" ]; then for x in $(uniqify $srvs); do servers="${servers}${server_keyword} $x$NL" done fi fi # Merge our config into ntp.conf [ -e "$cf" ] && rm -f "$cf" [ -d "$ntp_conf_dir" ] || mkdir -p "$ntp_conf_dir" if [ -n "$NTP_DHCP_CONF" ]; then [ -e "$ntp_conf" ] && cp "$ntp_conf" "$cf" ntp_conf="$NTP_DHCP_CONF" elif [ -e "$ntp_conf" ]; then sed "/^$signature_base/,/^$signature_base_end/d" \ "$ntp_conf" > "$cf" fi if [ -n "$servers" ]; then echo "$signature_base${header:+ from }$header" >> "$cf" printf %s "$servers" >> "$cf" echo "$signature_base_end${header:+ from }$header" >> "$cf" else [ -e "$ntp_conf" -a -e "$cf" ] || return 1 fi # If we changed anything, restart ntpd if ! cmp -s "$ntp_conf" "$cf"; then cat "$cf" > "$ntp_conf" ret="$?" fi rm -f "$cf" return "$ret" } build_all_ntp_conf() { local ret=1 if [ -n "$NTP_CONF" ]; then build_ntp_conf "$NTP_CONF" && ret=0 else #for openntpd will be used "servers" keyword instead "server" build_ntp_conf "/etc/ntpd.conf" "servers" && ret=0 build_ntp_conf "/etc/ntp.conf" && ret=0 fi return $ret } restart_ntpd() { [ -n "${ntpd_restart_cmd}" ] && eval ${ntpd_restart_cmd} } add_ntp_conf() { local cf="$ntp_conf_dir/$interface" x= [ -e "$cf" ] && rm "$cf" [ -d "$ntp_conf_dir" ] || mkdir -p "$ntp_conf_dir" if [ -n "$new_ntp_servers" ]; then for x in $new_ntp_servers; do echo "server $x" >> "$cf" done fi build_all_ntp_conf && restart_ntpd ||: } remove_ntp_conf() { if [ -e "$ntp_conf_dir/$interface" ]; then rm "$ntp_conf_dir/$interface" fi build_all_ntp_conf && restart_ntpd ||: } case "$reason" in BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT) add_ntp_conf;; PREINIT|EXPIRE|FAIL|IPV4LL|RELEASE|STOP) remove_ntp_conf;; esac