827332
#!/bin/bash
fb0a2d
#
fb0a2d
# dhclient-script: Network interface configuration script run by
fb0a2d
#                  dhclient based on DHCP client communication
fb0a2d
#
c24974
# Copyright (C) 2008, 2009  Red Hat, Inc.
fb0a2d
#
fb0a2d
# This program is free software; you can redistribute it and/or modify
fb0a2d
# it under the terms of the GNU General Public License as published by
fb0a2d
# the Free Software Foundation; either version 2 of the License, or
fb0a2d
# (at your option) any later version.
fb0a2d
#
fb0a2d
# This program is distributed in the hope that it will be useful,
fb0a2d
# but WITHOUT ANY WARRANTY; without even the implied warranty of
fb0a2d
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
fb0a2d
# GNU General Public License for more details.
fb0a2d
#
fb0a2d
# You should have received a copy of the GNU General Public License
fb0a2d
# along with this program.  If not, see <http: www.gnu.org="" licenses=""/>.
fb0a2d
#
fb0a2d
# Author(s): David Cantrell <dcantrell@redhat.com>
fb0a2d
#
fb0a2d
# ----------
fb0a2d
# This script is a rewrite/reworking on dhclient-script originally
fb0a2d
# included as part of dhcp-970306:
827332
# dhclient-script for Linux. Dan Halbert, March, 1997.
827332
# Updated for Linux 2.[12] by Brian J. Murrell, January 1999.
827332
# Modified by David Cantrell <dcantrell@redhat.com> for Fedora and RHEL
fb0a2d
# ----------
fb0a2d
#
827332
fb0a2d
PATH=/bin:/usr/bin:/sbin
fb0a2d
SAVEDIR=/var/lib/dhclient
827332
fb0a2d
LOGFACILITY="local7"
fb0a2d
LOGLEVEL="notice"
827332
c24974
ETCDIR="/etc/dhcp"
c24974
fb0a2d
logmessage() {
fb0a2d
    msg="${1}"
fb0a2d
    logger -p ${LOGFACILITY}.${LOGLEVEL} -t "NET" "dhclient: ${msg}"
fb0a2d
}
827332
7a0b8f
fix_context() {
7a0b8f
    if [ -x /sbin/restorecon ]; then
7a0b8f
        /sbin/restorecon ${1} >/dev/null 2>&1
7a0b8f
    fi
7a0b8f
}
7a0b8f
fb0a2d
save_previous() {
fb0a2d
    origfile="${1}"
fb0a2d
    savefile="${SAVEDIR}/${origfile##*/}.predhclient.${interface}"
827332
fb0a2d
    if [ ! -d ${SAVEDIR} ]; then
fb0a2d
        mkdir -p ${SAVEDIR}
fb0a2d
    fi
827332
fb0a2d
    if [ -e ${origfile} ]; then
1a960e
        contents="$(< ${origfile})"
1a960e
        echo "${contents}" > ${savefile}
1a960e
        rm -f ${origfile}
827332
    else
fb0a2d
        echo > ${savefile}
827332
    fi
7a4b49
7a0b8f
    fix_context ${savefile}
827332
}
827332
827332
make_resolv_conf() {
fb0a2d
    [ "${PEERDNS}" = "no" ] && return
827332
fb0a2d
    if [ "${reason}" = "RENEW" ] &&
fb0a2d
       [ "${new_domain_name}" = "${old_domain_name}" ] &&
fb0a2d
       [ "${new_domain_name_servers}" = "${old_domain_name_servers}" ]; then
827332
        return
827332
    fi
827332
fb0a2d
    if [ -n "${new_domain_name}" ] ||
fb0a2d
       [ -n "${new_domain_name_servers}" ] ||
fb0a2d
       [ -n "${new_domain_search}" ]; then
7a4b49
        save_previous /etc/resolv.conf
fb0a2d
        rscf="$(mktemp /tmp/XXXXXX)"
fb0a2d
        echo "; generated by /sbin/dhclient-script" > ${rscf}
827332
fb0a2d
        if [ -n "${SEARCH}" ]; then
fb0a2d
            echo "search ${SEARCH}" >> $rscf
7a4b49
        else
fb0a2d
            if [ -n "${new_domain_search}" ]; then
fb0a2d
                echo "search ${new_domain_search//\\032/ }" >> ${rscf}
fb0a2d
            elif [ -n "${new_domain_name}" ]; then
fb0a2d
                echo "search ${new_domain_name//\\032/ }" >> ${rscf}
827332
            fi
827332
        fi
827332
fb0a2d
        if [ -n "${RES_OPTIONS}" ]; then
fb0a2d
            echo "options ${RES_OPTIONS}" >> ${rscf}
5d1db1
        fi
5d1db1
fb0a2d
        for nameserver in ${new_domain_name_servers} ; do
fb0a2d
            echo "nameserver ${nameserver}" >> ${rscf}
827332
        done
827332
fb0a2d
        change_resolv_conf ${rscf}
fb0a2d
        rm -f ${rscf}
aab3af
7a0b8f
        fix_context /etc/resolv.conf
ecd7db
    elif [ -n "${new_dhcp6_name_servers}" ] ||
ecd7db
         [ -n "${new_dhcp6_domain_search}" ]; then
ecd7db
        save_previous /etc/resolv.conf
ecd7db
        rscf="$(mktemp /tmp/XXXXXX)"
ecd7db
        echo "; generated by /sbin/dhclient-script" > ${rscf}
ecd7db
ecd7db
        if [ -n "${SEARCH}" ]; then
ecd7db
            echo "search ${SEARCH}" >> $rscf
ecd7db
        else
ecd7db
            if [ -n "${new_dhcp6_domain_search}" ]; then
ecd7db
                echo "search ${new_dhcp6_domain_search//\\032/ }" >> ${rscf}
ecd7db
            fi
ecd7db
        fi
ecd7db
ecd7db
        if [ -n "${RES_OPTIONS}" ]; then
ecd7db
            echo "options ${RES_OPTIONS}" >> ${rscf}
ecd7db
        fi
ecd7db
ecd7db
        for nameserver in ${new_dhcp6_name_servers} ; do
ecd7db
            echo "nameserver ${nameserver}" >> ${rscf}
ecd7db
        done
ecd7db
ecd7db
        change_resolv_conf ${rscf}
ecd7db
        rm -f ${rscf}
ecd7db
ecd7db
        fix_context /etc/resolv.conf
827332
    fi
827332
}
827332
827332
exit_with_hooks() {
fb0a2d
    exit_status="${1}"
827332
c24974
    if [ -x ${ETCDIR}/dhclient-exit-hooks ]; then
c24974
        . ${ETCDIR}/dhclient-exit-hooks
827332
    fi
827332
fb0a2d
    exit ${exit_status}
827332
}
827332
fb0a2d
quad2num() {
827332
    if [ $# -eq 4 ]; then
fb0a2d
        let n="${1} << 24 | ${2} << 16 | ${3} << 8 | ${4}"
fb0a2d
        echo "${n}"
827332
        return 0
fb0a2d
    else
fb0a2d
        echo "0"
fb0a2d
        return 1
827332
    fi
827332
}
827332
fb0a2d
ip2num() {
fb0a2d
    IFS="." quad2num ${1}
827332
}
827332
fb0a2d
num2ip() {
fb0a2d
    let n="${1}"
fb0a2d
    let o1="(n >> 24) & 0xff"
fb0a2d
    let o2="(n >> 16) & 0xff"
fb0a2d
    let o3="(n >> 8) & 0xff"
fb0a2d
    let o4="n & 0xff"
fb0a2d
    echo "${o1}.${o2}.${o3}.${o4}"
827332
}
827332
fb0a2d
mask() {
fb0a2d
    ip="${1}"
fb0a2d
    m="${2}"
fb0a2d
    let ip="$(IFS="." ip2num ${ip})"
fb0a2d
    let m="$(IFS="." ip2num ${m})"
fb0a2d
    let n="ip & m"
fb0a2d
    num2ip ${n}
827332
}
827332
fb0a2d
class_bits() {
827332
    let ip=$(IFS='.' ip2num $1)
827332
    let bits=32
827332
    let mask='255'
827332
    for ((i=0; i <= 3; i++, 'mask<<=8')); do
827332
        let v='ip&mask'
827332
        if [ "$v" -eq 0 ] ; then
827332
             let bits-=8
827332
        else
827332
             break
827332
        fi
827332
    done
827332
    echo $bits
827332
}
827332
fb0a2d
is_router_reachable() {
fb0a2d
    # handle DHCP servers that give us a router not on our subnet
fb0a2d
    router="${1}"
fb0a2d
    routersubnet="$(mask ${router} ${new_subnet_mask})"
fb0a2d
    mysubnet="$(mask ${new_ip_address} ${new_subnet_mask})"
827332
    unreachable=0
fb0a2d
fb0a2d
    if [ ! "${routersubnet}" = "${mysubnet}" ]; then
827332
        unreachable=1
fb0a2d
        if arping -f -q -I ${interface} -w2 ${router}; then
fb0a2d
            ip route add ${router}/32 dev ${interface}
fb0a2d
            if [ $? -eq 0 ]; then
fb0a2d
                unreachable=0
fb0a2d
            else
fb0a2d
                logmessage "failed to create host router for unreachable router ${router} not on subnet ${mysubnet}"
fb0a2d
            fi
827332
        else
fb0a2d
            unreachable=1
fb0a2d
            logmessage "DHCP router ${router} is unreachable on DHCP subnet ${mysubnet} router subnet ${routersubnet}"
827332
        fi
827332
    fi
fb0a2d
fb0a2d
    return ${unreachable}
827332
}
827332
fb0a2d
add_default_gateway() {
fb0a2d
    router="${1}"
fb0a2d
    metric=""
fb0a2d
3eef63
    if [ $# -gt 1 ] && [ ${2} -gt 0 ]; then
fb0a2d
        metric="metric ${2}"
827332
    fi
fb0a2d
fb0a2d
    if is_router_reachable ${router} ; then
fb0a2d
        ip route replace default via ${router} dev ${interface} ${metric}
827332
        if [ $? -ne 0 ]; then
fb0a2d
            logmessage "failed to create default route: ${router} dev ${interface} ${metric}"
827332
            return 1
827332
        else
827332
            return 0
827332
        fi
827332
    fi
fb0a2d
827332
    return 1
827332
}
827332
fb0a2d
dhconfig() {
fb0a2d
    if [ -n "${old_ip_address}" ] && [ -n "${alias_ip_address}" ] &&
fb0a2d
       [ ! "${alias_ip_address}" = "${old_ip_address}" ]; then
fb0a2d
        # possible new alias, remove old alias first
fb0a2d
        ip -family inet addr del ${old_ip_address} dev ${interface}:0
827332
    fi
827332
fb0a2d
    if [ -n "${old_ip_address}" ] &&
fb0a2d
       [ ! "${old_ip_address}" = "${new_ip_address}" ]; then
fb0a2d
        # IP address changed.  Bringing down the interface will delete all
827332
        # routes, and clear the ARP cache.
1d7a26
        ip -family inet addr flush dev ${interface} >/dev/null 2>&1
827332
    fi
827332
3eef63
    if [ "${reason}" = "BOUND" ] || [ "${reason}" = "REBOOT" ] ||
fb0a2d
       [ ! "${old_ip_address}" = "${new_ip_address}" ] ||
fb0a2d
       [ ! "${old_subnet_mask}" = "${new_subnet_mask}" ] ||
fb0a2d
       [ ! "${old_network_number}" = "${new_network_number}" ] ||
fb0a2d
       [ ! "${old_broadcast_address}" = "${new_broadcast_address}" ] ||
fb0a2d
       [ ! "${old_routers}" = "${new_routers}" ] ||
fb0a2d
       [ ! "${old_interface_mtu}" = "${new_interface_mtu}" ]; then
fb0a2d
        ip -family inet addr add ${new_ip_address}/${new_prefix} broadcast ${new_broadcast_address} dev ${interface}
abd7aa
        ip -family inet link set dev ${interface} up
fb0a2d
fb0a2d
        if [ -n "${new_interface_mtu}" ]; then
fb0a2d
            ip link set ${interface} mtu ${new_interface_mtu}
827332
        fi
827332
c24974
        if [ -x ${ETCDIR}/dhclient-${interface}-up-hooks ]; then
c24974
            . ${ETCDIR}/dhclient-${interface}-up-hooks
c24974
        elif [ -x ${ETCDIR}/dhclient-up-hooks ]; then
c24974
            . ${ETCDIR}/dhclient-up-hooks
827332
        fi
827332
c94ce6
        if [[ ( "${DEFROUTE}" != "no") &&
c94ce6
              (( -z "${GATEWAYDEV}" ) ||
c94ce6
               ( "${GATEWAYDEV}" = "${interface}" )) ]]; then
c94ce6
            if [[ ( -z "$GATEWAY" ) ||
c94ce6
                  (( -n "$DHCLIENT_IGNORE_GATEWAY" ) &&
c94ce6
                   ( "$DHCLIENT_IGNORE_GATEWAY" = [Yy]* )) ]]; then
c94ce6
                metric="${METRIC:-}"
c94ce6
                let i="${METRIC:-0}"
c94ce6
                default_routers=()
c94ce6
c94ce6
                for router in ${new_routers} ; do
c94ce6
                    added_router=-
c94ce6
c94ce6
                    for r in ${default_routers[@]} ; do
c94ce6
                        if [ "${r}" = "${router}" ]; then
c94ce6
                            added_router=1
c94ce6
                        fi
c94ce6
                    done
c94ce6
c94ce6
                    if [ -z "${router}" ] ||
c94ce6
                       [ "${added_router}" = "1" ] ||
c94ce6
                       [ $(IFS=. ip2num ${router}) -le 0 ] ||
c94ce6
                       [[ ( "${router}" = "${new_broadcast_address}" ) &&
c94ce6
                          ( "${new_subnet_mask}" != "255.255.255.255" ) ]]; then
c94ce6
                        continue
827332
                    fi
c94ce6
c94ce6
                    default_routers=(${default_routers[@]} ${router})
c94ce6
                    add_default_gateway ${router} ${metric}
c94ce6
                    let i=i+1
c94ce6
                    metric=${i}
827332
                done
c94ce6
            elif [ -n "${GATEWAY}" ]; then
c94ce6
                routersubnet=$(mask ${GATEWAY} ${new_subnet_mask})
c94ce6
                mysubnet=$(mask ${new_ip_address} ${new_subnet_mask})
827332
c94ce6
                if [ "${routersubnet}" = "${mysubnet}" ]; then
c94ce6
                    ip route replace default via ${GATEWAY} dev ${interface}
827332
                fi
827332
            fi
827332
        fi
827332
827332
        # static routes
fb0a2d
        if [ -n "${new_static_routes}" ]; then
fb0a2d
            IFS=', |' static_routes=(${new_static_routes})
827332
            route_targets=()
827332
827332
            for((i=0; i<${#static_routes[@]}; i+=2)); do
827332
                target=${static_routes[$i]}
827332
                gateway=${static_routes[$i+1]}
827332
                metric=''
827332
827332
                for t in ${route_targets[@]}; do
fb0a2d
                    if [ ${t} = ${target} ]; then
fb0a2d
                        if [ -z "${metric}" ]; then
827332
                            metric=1
827332
                        else
827332
                            ((metric=metric+1))
827332
                        fi
827332
                    fi
827332
                done
827332
fb0a2d
                if [ -n "${metric}" ]; then
fb0a2d
                    metric="metric ${metric}"
827332
                fi
827332
fb0a2d
                if is_router_reachable ${gateway}; then
fb0a2d
                    ip route replace ${target}/$(class_bits ${target}) via ${gateway} dev ${interface} ${metric}
827332
827332
                    if [ $? -ne 0 ]; then
fb0a2d
                        logmessage "failed to create static route: ${target}/$(class_bits ${target}) via ${gateway} dev ${interface} ${metric}"
827332
                    else
fb0a2d
                        route_targets=(${route_targets[@]} ${target})
827332
                    fi
827332
                fi
827332
            done
827332
        fi
827332
    fi
827332
fb0a2d
    if [ ! "${new_ip_address}" = "${alias_ip_address}" ] &&
fb0a2d
       [ -n "${alias_ip_address}" ]; then
1d7a26
        ip -family inet addr flush dev ${interface}:0 >/dev/null 2>&1
fb0a2d
        ip -family inet addr add ${alias_ip_address}/${alias_prefix} dev ${interface}:0
fb0a2d
        ip route replace ${alias_ip_address}/32 dev ${interface}:0
827332
    fi
827332
827332
    make_resolv_conf
827332
fb0a2d
    if [ -n "${new_host_name}" ] && need_hostname; then
fb0a2d
        hostname ${new_host_name}
827332
    fi
827332
fb0a2d
    if [ -n "${DHCP_TIME_OFFSET_SETS_TIMEZONE}" ] &&
fb0a2d
       [[ "${DHCP_TIME_OFFSET_SETS_TIMEZONE}" = [yY1]* ]]; then
fb0a2d
        if [ -n "${new_time_offset}" ]; then
827332
            # DHCP option "time-offset" is requested by default and should be
827332
            # handled.  The geographical zone abbreviation cannot be determined
827332
            # from the GMT offset, but the $ZONEINFO/Etc/GMT$offset file can be
827332
            # used - note: this disables DST.
827332
            ((z=new_time_offset/3600))
827332
            ((hoursWest=$(printf '%+d' $z)))
827332
827332
            if (( $hoursWest < 0 )); then
827332
                # tzdata treats negative 'hours west' as positive 'gmtoff'!
827332
                ((hoursWest*=-1))
827332
            fi
827332
fb0a2d
            tzfile=/usr/share/zoneinfo/Etc/GMT$(printf '%+d' ${hoursWest})
fb0a2d
            if [ -e ${tzfile} ]; then
fb0a2d
                save_previous /etc/localtime
fb0a2d
                cp -fp ${tzfile} /etc/localtime
fb0a2d
                touch /etc/localtime
7a0b8f
                fix_context /etc/localtime
827332
            fi
827332
        fi
827332
    fi
827332
35667a
    # execute any additional client side configuration scripts we have
c24974
    if [ -d ${ETCDIR}/dhclient.d ]; then
c24974
        for f in ${ETCDIR}/dhclient.d/*.sh ; do
35667a
            if [ -x ${f} ]; then
393358
                subsystem="${f%.sh}"
a7801e
                subsystem="${subsystem##*/}"
a7801e
                . ${f}
a7801e
                "${subsystem}_config"
35667a
            fi
827332
        done
827332
    fi
827332
}
827332
ecd7db
dh6config() {
ecd7db
    case "${reason}" in
ecd7db
        BOUND6)
cf6641
            if [ -z "${new_ip6_address}" ] &&
cf6641
               [ -z "${new_ip6_prefixlen}" ]; then
ecd7db
                exit_with_hooks 2
ecd7db
            fi
ecd7db
ecd7db
            ip -f inet6 addr add ${new_ip6_address}/${new_ip6_prefixlen} \
ecd7db
                dev ${interface} scope global
ecd7db
            make_resolv_conf
ecd7db
            ;;
ecd7db
ecd7db
        RENEW6|REBIND6)
ecd7db
            if [ ! "${new_dhcp6_name_servers}" = "${old_dhcp6_name_servers}" ] ||
ecd7db
               [ ! "${new_dhcp6_domain_search}" = "${old_dhcp6_domain_search}" ]; then
ecd7db
                make_resolv_conf
ecd7db
            fi
ecd7db
            ;;
ecd7db
ecd7db
        DEPREF6)
cf6641
            if [ -z "${new_ip6_prefixlen}" ]; then
ecd7db
                exit_with_hooks 2
ecd7db
            fi
ecd7db
ecd7db
            ip -f inet6 addr change ${new_ip6_address}/${new_ip6_prefixlen} \
ecd7db
                dev ${interface} scope global preferred_lft 0
ecd7db
            ;;
ecd7db
    esac
ecd7db
ecd7db
    # execute any additional client side configuration scripts we have
ecd7db
    if [ -d ${ETCDIR}/dhclient.d ]; then
ecd7db
        for f in ${ETCDIR}/dhclient.d/*.sh ; do
ecd7db
            if [ -x ${f} ]; then
ecd7db
                subsystem="${f%.sh}"
ecd7db
                subsystem="${subsystem##*/}"
ecd7db
                . ${f}
ecd7db
                "${subsystem}_config"
ecd7db
            fi
ecd7db
        done
ecd7db
    fi
ecd7db
}
ecd7db
1d7a26
get_prefix() {
1d7a26
    ip="${1}"
1d7a26
    nm="${2}"
1d7a26
1d7a26
    if [ -n "${ip}" -a -n "${nm}" ]; then
1d7a26
        ipcalc -s -p ${ip} ${nm} | cut -d '=' -f 2
1d7a26
    fi
1d7a26
}
1d7a26
827332
fb0a2d
#
fb0a2d
# ### MAIN
fb0a2d
#
827332
c24974
if [ -x ${ETCDIR}/dhclient-enter-hooks ]; then
fb0a2d
    exit_status=0
fb0a2d
fb0a2d
    # dhclient-enter-hooks can abort dhclient-script by setting
fb0a2d
    # the exit_status variable to a non-zero value
c24974
    . ${ETCDIR}/dhclient-enter-hooks
fb0a2d
    if [ ${exit_status} -ne 0 ]; then
fb0a2d
        exit ${exit_status}
fb0a2d
    fi
e618bc
fi
fb0a2d
fb0a2d
if [ ! -r /etc/sysconfig/network-scripts/network-functions ]; then
fb0a2d
    echo "Missing /etc/sysconfig/network-scripts/network-functions, exiting." >&2
fb0a2d
    exit 1
827332
fi
827332
fb0a2d
if [ ! -r /etc/rc.d/init.d/functions ]; then
fb0a2d
    echo "Missing /etc/rc.d/init.d/functions, exiting." >&2
fb0a2d
    exit 1
827332
fi
827332
fb0a2d
. /etc/sysconfig/network-scripts/network-functions
fb0a2d
. /etc/rc.d/init.d/functions
fb0a2d
fb0a2d
if [ -f /etc/sysconfig/network ]; then
fb0a2d
    . /etc/sysconfig/network
827332
fi
827332
fb0a2d
if [ -f /etc/sysconfig/networking/network ]; then
fb0a2d
    . /etc/sysconfig/networking/network
827332
fi
827332
49da92
cd /etc/sysconfig/network-scripts
49da92
CONFIG="ifcfg-${interface}"
fb0a2d
need_config ${CONFIG}
1d7a26
source_config >/dev/null 2>&1
827332
1d7a26
new_prefix="$(get_prefix ${new_ip_address} ${new_subnet_mask})"
1d7a26
old_prefix="$(get_prefix ${old_ip_address} ${new_subnet_mask})"
1d7a26
alias_prefix="$(get_prefix ${alias_ip_address} ${alias_subnet_mask})"
827332
fb0a2d
case "${reason}" in
fb0a2d
    MEDIUM)
fb0a2d
        # Linux doesn't handle mediums (media)
fb0a2d
        exit_with_hooks 0
fb0a2d
        ;;
fb0a2d
fb0a2d
    PREINIT)
fb0a2d
        if [ -n "${alias_ip_address}" ]; then
fb0a2d
            # Bring down alias interface, its routes will disappear too.
fb0a2d
            ip -family inet link set ${interface}:0 down
881f7f
        fi
827332
fb0a2d
        if [ "${keep_old_ip}" = "yes" ]; then
fb0a2d
            ip -family inet link set ${interface} up
fb0a2d
        else
1d7a26
            ip -family inet addr flush dev ${interface} >/dev/null 2>&1
fb0a2d
            ip -family inet link set ${interface} up
827332
        fi
827332
fb0a2d
        if [ -n "${DHCLIENT_DELAY}" ] && [ ${DHCLIENT_DELAY} -gt 0 ]; then
fb0a2d
            sleep ${DHCLIENT_DELAY}
881f7f
        fi
827332
fb0a2d
        exit_with_hooks 0
fb0a2d
        ;;
827332
ecd7db
    PREINIT6)
ecd7db
        # ensure interface is up
ecd7db
        ip link set ${interface} up
ecd7db
ecd7db
        # remove any stale addresses from aborted clients
ecd7db
        ip -f inet6 addr flush dev ${interface} scope global permanent
ecd7db
ecd7db
        exit_with_hooks 0
ecd7db
        ;;
ecd7db
fb0a2d
    ARPCHECK|ARPSEND)
fb0a2d
        if [ -z "${new_ip_address}" ] || [ -z "${interface}" ] ||
fb0a2d
           arping -q -f -c 2 -w 3 -D -I ${interface} ${new_ip_address}; then
fb0a2d
            exit_with_hooks 0
fb0a2d
        else
fb0a2d
            exit_with_hooks 1
827332
        fi
fb0a2d
        ;;
827332
fb0a2d
    BOUND|RENEW|REBIND|REBOOT)
fb0a2d
        dhconfig
fb0a2d
        exit_with_hooks 0
fb0a2d
        ;;
fb0a2d
ecd7db
    BOUND6|RENEW6|REBIND6|DEPREF6)
ecd7db
        dh6config
ecd7db
        exit_with_hooks 0
ecd7db
        ;;
ecd7db
ecd7db
    EXPIRE6|RELEASE6|STOP6)
742e2e
        if [ -z "${old_ip6_address}" ] || [ -z "${old_ip6_prefixlen}" ]; then
ecd7db
            exit_with_hooks 2
ecd7db
        fi
ecd7db
ecd7db
        ip -f inet6 addr del ${old_ip6_address}/${old_ip6_prefixlen} \
ecd7db
            dev ${interface}
ecd7db
ecd7db
        # execute any additional client side configuration scripts we have
ecd7db
        if [ -d ${ETCDIR}/dhclient.d ]; then
ecd7db
            for f in ${ETCDIR}/dhclient.d/*.sh ; do
ecd7db
                if [ -x ${f} ]; then
ecd7db
                    subsystem="${f%.sh}"
ecd7db
                    subsystem="${subsystem##*/}"
ecd7db
                    . ${f}
ecd7db
                    "${subsystem}_restore"
ecd7db
                fi
ecd7db
            done
ecd7db
        fi
ecd7db
ecd7db
        if [ -x ${ETCDIR}/dhclient-${interface}-down-hooks ]; then
ecd7db
            . ${ETCDIR}/dhclient-${interface}-down-hooks
ecd7db
        elif [ -x ${ETCDIR}/dhclient-down-hooks ]; then
ecd7db
            . ${ETCDIR}/dhclient-down-hooks
ecd7db
        fi
ecd7db
ecd7db
        exit_with_hooks 0
ecd7db
        ;;
ecd7db
fb0a2d
    EXPIRE|FAIL|RELEASE|STOP)
fb0a2d
        # only restore config files if there are no other dhclient processes
fb0a2d
        # running (#306381)
fb0a2d
        any_other_clients="$(ps -eo pid,ppid,comm | grep dhclient | grep -v ${PPID})"
fb0a2d
        if [ -n "${any_other_clients}" ]; then
fb0a2d
            if [ -f ${SAVEDIR}/resolv.conf.predhclient.${interface} ]; then
fb0a2d
                change_resolv_conf ${SAVEDIR}/resolv.conf.predhclient.${interface}
fb0a2d
                rm -f ${SAVEDIR}/resolv.conf.predhclient.${interface}
fb0a2d
            fi
827332
fb0a2d
            if [ -n "${DHCP_TIME_OFFSET_SETS_TIMEZONE}" ] &&
fb0a2d
               [[ "${DHCP_TIME_OFFSET_SETS_TIMEZONE}" = [yY1]* ]]; then
fb0a2d
                if [ -e ${SAVEDIR}/localtime.predhclient.${interface} ]; then
fb0a2d
                    rm -f /etc/localtime
1a960e
                    contents="$(< ${SAVEDIR}/localtime.predhclient.${interface})"
1a960e
                    echo "${contents}" > /etc/localtime
1a960e
                    rm -f ${SAVEDIR}/localtime.predhclient.${interface}
fb0a2d
                    touch /etc/localtime
7a0b8f
                    fix_context /etc/localtime
fb0a2d
                fi
fb0a2d
            fi
7a0b8f
        fi
827332
7a0b8f
        # execute any additional client side configuration scripts we have
c24974
        if [ -d ${ETCDIR}/dhclient.d ]; then
c24974
            for f in ${ETCDIR}/dhclient.d/*.sh ; do
7a0b8f
                if [ -x ${f} ]; then
7a0b8f
                    subsystem="${f%.sh}"
a7801e
                    subsystem="${subsystem##*/}"
a7801e
                    . ${f}
a7801e
                    "${subsystem}_restore"
fb0a2d
                fi
7a0b8f
            done
fb0a2d
        fi
827332
c24974
        if [ -x ${ETCDIR}/dhclient-${interface}-down-hooks ]; then
c24974
            . ${ETCDIR}/dhclient-${interface}-down-hooks
c24974
        elif [ -x ${ETCDIR}/dhclient-down-hooks ]; then
c24974
            . ${ETCDIR}/dhclient-down-hooks
fb0a2d
        fi
827332
fb0a2d
        if [ -n "${alias_ip_address}" ]; then
fb0a2d
            # Turn off alias interface
fb0a2d
            ip -family inet link set ${interface}:0 down
fb0a2d
        fi
827332
fb0a2d
        if [ -n "${old_ip_address}" ]; then
fb0a2d
            # Shut down interface, which will delete routes and clear arp cache.
1d7a26
            ip -family inet addr flush dev ${interface} >/dev/null 2>&1
fb0a2d
            ip -family inet link set ${interface} down
fb0a2d
        fi
fb0a2d
fb0a2d
        if [ -n "${alias_ip_address}" ]; then
fb0a2d
            ip -family inet addr add ${alias_ip_address}/${alias_prefix} dev ${interface}:0
fb0a2d
            ip -family inet route replace ${alias_ip_address}/32 ${interface}:0
fb0a2d
        fi
827332
827332
        exit_with_hooks 0
fb0a2d
        ;;
827332
fb0a2d
    TIMEOUT)
fb0a2d
        if [ -n "${new_routers}" ]; then
fb0a2d
            if [ -n "${alias_ip_address}" ]; then
1d7a26
                ip -family inet addr flush dev ${interface}:0 >/dev/null 2>&1
fb0a2d
            fi
fb0a2d
fb0a2d
            ip -family inet addr add ${new_ip_address}/${new_prefix} broadcast ${new_broadcast_address} dev ${interface}
fb0a2d
            set ${new_routers}
fb0a2d
fb0a2d
            if ping -q -c 1 -w 10 -I ${interface} ${1}; then
fb0a2d
                dhconfig
fb0a2d
                exit_with_hooks 0
fb0a2d
            fi
fb0a2d
1d7a26
            ip -family inet addr flush dev ${interface} >/dev/null 2>&1
fb0a2d
            ip -family inet link set ${interface} down
fb0a2d
            exit_with_hooks 1
fb0a2d
        else
fb0a2d
            exit_with_hooks 1
fb0a2d
        fi
fb0a2d
        ;;
fb0a2d
fb0a2d
    *)
fb0a2d
        logmessage "unhandled state: ${reason}"
fb0a2d
        exit_with_hooks 1
fb0a2d
        ;;
fb0a2d
esac
827332
827332
exit_with_hooks 0