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