Blame SOURCES/dhclient-script

f9ed25
#!/bin/bash
f9ed25
#
f9ed25
# dhclient-script: Network interface configuration script run by
f9ed25
#                  dhclient based on DHCP client communication
f9ed25
#
f9ed25
# Copyright (C) 2008-2014  Red Hat, Inc.
f9ed25
#
f9ed25
# This program is free software; you can redistribute it and/or modify
f9ed25
# it under the terms of the GNU General Public License as published by
f9ed25
# the Free Software Foundation; either version 2 of the License, or
f9ed25
# (at your option) any later version.
f9ed25
#
f9ed25
# This program is distributed in the hope that it will be useful,
f9ed25
# but WITHOUT ANY WARRANTY; without even the implied warranty of
f9ed25
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f9ed25
# GNU General Public License for more details.
f9ed25
#
f9ed25
# You should have received a copy of the GNU General Public License
f9ed25
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
f9ed25
#
f9ed25
# Author(s): David Cantrell <dcantrell@redhat.com>
f9ed25
#            Jiri Popelka <jpopelka@redhat.com>
f9ed25
#
f9ed25
# ----------
f9ed25
# This script is a rewrite/reworking on dhclient-script originally
f9ed25
# included as part of dhcp-970306:
f9ed25
# dhclient-script for Linux. Dan Halbert, March, 1997.
f9ed25
# Updated for Linux 2.[12] by Brian J. Murrell, January 1999.
f9ed25
# Modified by David Cantrell <dcantrell@redhat.com> for Fedora and RHEL
f9ed25
# ----------
f9ed25
#
f9ed25
f9ed25
PATH=/bin:/usr/bin:/sbin
f9ed25
# scripts in dhclient.d/ use $SAVEDIR (#833054)
f9ed25
export SAVEDIR=/var/lib/dhclient
f9ed25
f9ed25
LOGFACILITY="local7"
f9ed25
LOGLEVEL="notice"
f9ed25
f9ed25
ETCDIR="/etc/dhcp"
f9ed25
f9ed25
RESOLVCONF="/etc/resolv.conf"
f9ed25
f9ed25
logmessage() {
f9ed25
    msg="${1}"
f9ed25
    logger -p "${LOGFACILITY}.${LOGLEVEL}" -t "NET" "dhclient: ${msg}"
f9ed25
}
f9ed25
f9ed25
eventually_add_hostnames_domain_to_search() {
f9ed25
# For the case when hostname for this machine has a domain that is not in domain_search list
f9ed25
# 1) get a hostname with `ipcalc --hostname` or `hostnamectl --transient`
f9ed25
# 2) get the domain from this hostname
f9ed25
# 3) add this domain to search line in resolv.conf if it's not already
f9ed25
#    there (domain list that we have recently added there is a parameter of this function)
f9ed25
# We can't do this directly when generating resolv.conf in make_resolv_conf(), because
f9ed25
# we need to first save the resolv.conf with obtained values before we can call `ipcalc --hostname`.
f9ed25
# See bug 637763
f9ed25
    search="${1}"
f9ed25
    if need_hostname; then
f9ed25
        status=1
f9ed25
        OLD_HOSTNAME=$HOSTNAME
f9ed25
        if [ -n "${new_ip_address}" ]; then
f9ed25
            eval $(/usr/bin/ipcalc --silent --hostname "${new_ip_address}" ; echo "status=$?")
f9ed25
        elif [ -n "${new_ip6_address}" ]; then
f9ed25
            eval $(/usr/bin/ipcalc --silent --hostname "${new_ip6_address}" ; echo "status=$?")
f9ed25
        fi
f9ed25
f9ed25
        if [ ${status} -eq 0 ]; then
f9ed25
            domain=$(echo "${HOSTNAME}" | cut -s -d "." -f 2-)
f9ed25
        fi
f9ed25
        HOSTNAME=$OLD_HOSTNAME
f9ed25
    else
f9ed25
          domain=$(hostnamectl --transient 2>/dev/null | cut -s -d "." -f 2-)
f9ed25
    fi
f9ed25
f9ed25
    if [ -n "${domain}" ] &&
f9ed25
       [ ! "${domain}" = "localdomain" ] &&
f9ed25
       [ ! "${domain}" = "localdomain6" ] &&
f9ed25
       [ ! "${domain}" = "(none)" ] &&
f9ed25
       [[ ! "${domain}" = *\ * ]]; then
f9ed25
       is_in="false"
f9ed25
       for s in ${search}; do
f9ed25
           if [ "${s}" = "${domain}" ] ||
f9ed25
              [ "${s}" = "${domain}." ]; then
f9ed25
              is_in="true"
f9ed25
           fi
f9ed25
       done
f9ed25
f9ed25
       if [ "${is_in}" = "false" ]; then
f9ed25
           # Add domain name to search list (#637763)
f9ed25
          sed -i -e "s/${search}/${search} ${domain}/" "${RESOLVCONF}"
f9ed25
       fi
f9ed25
    fi
f9ed25
}
f9ed25
f9ed25
make_resolv_conf() {
f9ed25
    [ "${PEERDNS}" = "no" ] && return
f9ed25
f9ed25
    if [ "${reason}" = "RENEW" ] &&
f9ed25
       [ "${new_domain_name}" = "${old_domain_name}" ] &&
f9ed25
       [ "${new_domain_name_servers}" = "${old_domain_name_servers}" ]; then
f9ed25
        return
f9ed25
    fi
f9ed25
f9ed25
    if [ -n "${new_domain_name}" ] ||
f9ed25
       [ -n "${new_domain_name_servers}" ] ||
f9ed25
       [ -n "${new_domain_search}" ]; then
f9ed25
        rscf="$(mktemp "${TMPDIR:-/tmp}/XXXXXX")"
f9ed25
        [[ -z "${rscf}" ]] && return
f9ed25
        echo "; generated by /usr/sbin/dhclient-script" > "${rscf}"
f9ed25
f9ed25
        if [ -n "${SEARCH}" ]; then
f9ed25
            search="${SEARCH}"
f9ed25
        else
f9ed25
            if [ -n "${new_domain_search}" ]; then
f9ed25
                # Remove instaces of \032 (#450042)
f9ed25
                search="${new_domain_search//\\032/ }"
f9ed25
            elif [ -n "${new_domain_name}" ]; then
f9ed25
                # Note that the DHCP 'Domain Name Option' is really just a domain
f9ed25
                # name, and that this practice of using the domain name option as
f9ed25
                # a search path is both nonstandard and deprecated.
f9ed25
                search="${new_domain_name}"
f9ed25
            fi
f9ed25
        fi
f9ed25
f9ed25
        if [ -n "${search}" ]; then
f9ed25
            echo "search ${search}" >> "${rscf}"
f9ed25
        fi
f9ed25
f9ed25
        if [ -n "${RES_OPTIONS}" ]; then
f9ed25
            echo "options ${RES_OPTIONS}" >> "${rscf}"
f9ed25
        fi
f9ed25
f9ed25
        if [ -n "${new_domain_name_servers}" ]; then
f9ed25
            for nameserver in ${new_domain_name_servers} ; do
f9ed25
                echo "nameserver ${nameserver}" >> "${rscf}"
f9ed25
            done
f9ed25
        else # keep 'old' nameservers
f9ed25
            sed -n /^\w*[Nn][Aa][Mm][Ee][Ss][Ee][Rr][Vv][Ee][Rr]/p "${RESOLVCONF}" >> "${rscf}"
f9ed25
        fi
f9ed25
f9ed25
        change_resolv_conf "${rscf}"
f9ed25
        rm -f "${rscf}"
f9ed25
f9ed25
        if [ -n "${search}" ]; then
f9ed25
            eventually_add_hostnames_domain_to_search "${search}"
f9ed25
        fi
f9ed25
    elif [ -n "${new_dhcp6_name_servers}" ] ||
f9ed25
         [ -n "${new_dhcp6_domain_search}" ]; then
f9ed25
        rscf="$(mktemp "${TMPDIR:-/tmp}/XXXXXX")"
f9ed25
        [[ -z "${rscf}" ]] && return
f9ed25
        echo "; generated by /usr/sbin/dhclient-script" > "${rscf}"
f9ed25
f9ed25
        if [ -n "${SEARCH}" ]; then
f9ed25
            search="${SEARCH}"
f9ed25
        else
f9ed25
            if [ -n "${new_dhcp6_domain_search}" ]; then
f9ed25
                search="${new_dhcp6_domain_search//\\032/ }"
f9ed25
            fi
f9ed25
        fi
f9ed25
f9ed25
        if [ -n "${search}" ]; then
f9ed25
            echo "search ${search}" >> "${rscf}"
f9ed25
        fi
f9ed25
f9ed25
        if [ -n "${RES_OPTIONS}" ]; then
f9ed25
            echo "options ${RES_OPTIONS}" >> "${rscf}"
f9ed25
        fi
f9ed25
f9ed25
        shopt -s nocasematch
f9ed25
        if [ -n "${new_dhcp6_name_servers}" ]; then
f9ed25
            for nameserver in ${new_dhcp6_name_servers} ; do
f9ed25
                # If the nameserver has a link-local address
f9ed25
                # add a <zone_id> (interface name) to it.
f9ed25
                if  [[ "$nameserver" =~ ^fe80:: ]]
f9ed25
                then
f9ed25
                    zone_id="%${interface}"
f9ed25
                else
f9ed25
                    zone_id=
f9ed25
                fi
f9ed25
                echo "nameserver ${nameserver}$zone_id" >> "${rscf}"
f9ed25
            done
f9ed25
        else # keep 'old' nameservers
f9ed25
            sed -n /^\w*[Nn][Aa][Mm][Ee][Ss][Ee][Rr][Vv][Ee][Rr]/p "${RESOLVCONF}" >> "${rscf}"
f9ed25
        fi
f9ed25
        shopt -u nocasematch
f9ed25
f9ed25
        change_resolv_conf "${rscf}"
f9ed25
        rm -f "${rscf}"
f9ed25
f9ed25
        if [ -n "${search}" ]; then
f9ed25
            eventually_add_hostnames_domain_to_search "${search}"
f9ed25
        fi
f9ed25
    fi
f9ed25
}
f9ed25
f9ed25
# run given script
f9ed25
run_hook() {
f9ed25
    local script
f9ed25
    local exit_status
f9ed25
    script="${1}"
f9ed25
f9ed25
    if [ -f ${script} ]; then
f9ed25
        . ${script}
f9ed25
    fi
f9ed25
f9ed25
    if [ -n "${exit_status}" ] && [ "${exit_status}" -ne 0 ]; then
f9ed25
        logmessage "${script} returned non-zero exit status ${exit_status}"
f9ed25
    fi
f9ed25
f9ed25
    return ${exit_status}
f9ed25
}
f9ed25
f9ed25
# run scripts in given directory
f9ed25
run_hookdir() {
f9ed25
    local dir
f9ed25
    dir="${1}"
f9ed25
f9ed25
    if [ -d "${dir}" ]; then
f9ed25
        for script in $(find $dir -executable ! -empty); do
f9ed25
            run_hook ${script} || return $?
f9ed25
        done
f9ed25
    fi
f9ed25
f9ed25
    return 0
f9ed25
}
f9ed25
f9ed25
exit_with_hooks() {
f9ed25
    # Source the documented exit-hook script, if it exists
f9ed25
    run_hook "${ETCDIR}/dhclient-exit-hooks" || exit $?
f9ed25
    # Now run scripts in the hooks directory.
f9ed25
    run_hookdir "${ETCDIR}/dhclient-exit-hooks.d" || exit $?
f9ed25
f9ed25
    exit ${1}
f9ed25
}
f9ed25
f9ed25
quad2num() {
f9ed25
    if [ $# -eq 4 ]; then
f9ed25
        let n="${1} << 24 | ${2} << 16 | ${3} << 8 | ${4}"
f9ed25
        echo "${n}"
f9ed25
        return 0
f9ed25
    else
f9ed25
        echo "0"
f9ed25
        return 1
f9ed25
    fi
f9ed25
}
f9ed25
f9ed25
ip2num() {
f9ed25
    IFS='.' quad2num ${1}
f9ed25
}
f9ed25
f9ed25
num2ip() {
f9ed25
    let n="${1}"
f9ed25
    let o1="(${n} >> 24) & 0xff"
f9ed25
    let o2="(${n} >> 16) & 0xff"
f9ed25
    let o3="(${n} >> 8) & 0xff"
f9ed25
    let o4="${n} & 0xff"
f9ed25
    echo "${o1}.${o2}.${o3}.${o4}"
f9ed25
}
f9ed25
f9ed25
get_network_address() {
f9ed25
# get network address for the given IP address and (netmask or prefix)
f9ed25
    ip="${1}"
f9ed25
    nm="${2}"
f9ed25
f9ed25
    if [ -n "${ip}" -a -n "${nm}" ]; then
f9ed25
        if [[ "${nm}" = *.* ]]; then
f9ed25
            ipcalc -s -n "${ip}" "${nm}" | cut -d '=' -f 2
f9ed25
        else
f9ed25
            ipcalc -s -n "${ip}/${nm}" | cut -d '=' -f 2
f9ed25
        fi
f9ed25
    fi
f9ed25
}
f9ed25
f9ed25
get_prefix() {
f9ed25
# get prefix for the given IP address and mask
f9ed25
    ip="${1}"
f9ed25
    nm="${2}"
f9ed25
f9ed25
    if [ -n "${ip}" -a -n "${nm}" ]; then
f9ed25
        ipcalc -s -p "${ip}" "${nm}" | cut -d '=' -f 2
f9ed25
    fi
f9ed25
}
f9ed25
f9ed25
class_bits() {
f9ed25
    let ip=$(IFS='.' ip2num "${1}")
f9ed25
    let bits=32
f9ed25
    let mask='255'
f9ed25
    for ((i=0; i <= 3; i++, 'mask<<=8')); do
f9ed25
        let v='ip&mask'
f9ed25
        if [ "$v" -eq 0 ] ; then
f9ed25
             let bits-=8
f9ed25
        else
f9ed25
             break
f9ed25
        fi
f9ed25
    done
f9ed25
    echo $bits
f9ed25
}
f9ed25
f9ed25
is_router_reachable() {
f9ed25
    # handle DHCP servers that give us a router not on our subnet
f9ed25
    router="${1}"
f9ed25
    routersubnet="$(get_network_address "${router}" "${new_subnet_mask}")"
f9ed25
    mysubnet="$(get_network_address "${new_ip_address}" "${new_subnet_mask}")"
f9ed25
f9ed25
    if [ ! "${routersubnet}" = "${mysubnet}" ]; then
f9ed25
        # TODO: This function should not have side effects such as adding or
f9ed25
        # removing routes. Can this be done with "ip route get" or similar
f9ed25
        # instead? Are there cases that rely on this route being created here?
f9ed25
        ip -4 route replace "${router}/32" dev "${interface}"
f9ed25
        if [ "$?" -ne 0 ]; then
f9ed25
            logmessage "failed to create host route for ${router}"
f9ed25
            return 1
f9ed25
        fi
f9ed25
    fi
f9ed25
f9ed25
    return 0
f9ed25
}
f9ed25
f9ed25
add_default_gateway() {
f9ed25
    router="${1}"
f9ed25
f9ed25
    if is_router_reachable "${router}" ; then
f9ed25
        if [ $# -gt 1 ] && [ -n "${2}" ] && [[ "${2}" -gt 0 ]]; then
f9ed25
            ip -4 route replace default via "${router}" dev "${interface}" metric "${2}"
f9ed25
        else
f9ed25
            ip -4 route replace default via "${router}" dev "${interface}"
f9ed25
        fi
f9ed25
        if [ $? -ne 0 ]; then
f9ed25
            logmessage "failed to create default route: ${router} dev ${interface} ${metric}"
f9ed25
            return 1
f9ed25
        else
f9ed25
            return 0
f9ed25
        fi
f9ed25
    fi
f9ed25
f9ed25
    return 1
f9ed25
}
f9ed25
f9ed25
execute_client_side_configuration_scripts() {
f9ed25
# execute any additional client side configuration scripts we have
f9ed25
    if [ "${1}" == "config" ] || [ "${1}" == "restore" ]; then
f9ed25
        for f in ${ETCDIR}/dhclient.d/*.sh ; do
f9ed25
            if [ -x "${f}" ]; then
f9ed25
                subsystem="${f%.sh}"
f9ed25
                subsystem="${subsystem##*/}"
f9ed25
                . "${f}"
f9ed25
                "${subsystem}_${1}"
f9ed25
            fi
f9ed25
        done
f9ed25
    fi
f9ed25
}
f9ed25
f9ed25
flush_dev() {
f9ed25
# Instead of bringing the interface down (#574568)
f9ed25
# explicitly clear ARP cache and flush all addresses & routes.
f9ed25
    ip -4 addr flush dev "${1}" >/dev/null 2>&1
f9ed25
    ip -4 route flush dev "${1}" >/dev/null 2>&1
f9ed25
    ip -4 neigh flush dev "${1}" >/dev/null 2>&1
f9ed25
}
f9ed25
f9ed25
remove_old_addr() {
f9ed25
    if [ -n "${old_ip_address}" ]; then
f9ed25
        if [ -n "${old_prefix}" ]; then
f9ed25
            ip -4 addr del "${old_ip_address}/${old_prefix}" dev "${interface}" >/dev/null 2>&1
f9ed25
        else
f9ed25
            ip -4 addr del "${old_ip_address}" dev "${interface}" >/dev/null 2>&1
f9ed25
        fi
f9ed25
    fi
f9ed25
}
f9ed25
f9ed25
dhconfig() {
f9ed25
    if [ -n "${old_ip_address}" ] && [ -n "${alias_ip_address}" ] &&
f9ed25
       [ ! "${alias_ip_address}" = "${old_ip_address}" ]; then
f9ed25
        # possible new alias, remove old alias first
f9ed25
        ip -4 addr del "${old_ip_address}" dev "${interface}" label "${interface}:0"
f9ed25
    fi
f9ed25
f9ed25
    if [ -n "${old_ip_address}" ] &&
f9ed25
       [ ! "${old_ip_address}" = "${new_ip_address}" ]; then
f9ed25
        # IP address changed. Delete all routes, and clear the ARP cache.
f9ed25
        flush_dev "${interface}"
f9ed25
    fi
f9ed25
f9ed25
    # make sure the interface is up
f9ed25
    ip link set dev "${interface}" up
f9ed25
f9ed25
    # replace = add if it doesn't exist or override (update lifetimes) if it's there
f9ed25
    ip -4 addr replace "${new_ip_address}/${new_prefix}" broadcast "${new_broadcast_address}" dev "${interface}" \
f9ed25
       valid_lft "${new_dhcp_lease_time}" preferred_lft "${new_dhcp_lease_time}" >/dev/null 2>&1
f9ed25
f9ed25
    if [ "${reason}" = "BOUND" ] || [ "${reason}" = "REBOOT" ] ||
f9ed25
       [ ! "${old_ip_address}" = "${new_ip_address}" ] ||
f9ed25
       [ ! "${old_subnet_mask}" = "${new_subnet_mask}" ] ||
f9ed25
       [ ! "${old_network_number}" = "${new_network_number}" ] ||
f9ed25
       [ ! "${old_broadcast_address}" = "${new_broadcast_address}" ] ||
f9ed25
       [ ! "${old_routers}" = "${new_routers}" ] ||
f9ed25
       [ ! "${old_interface_mtu}" = "${new_interface_mtu}" ]; then
f9ed25
f9ed25
        # The 576 MTU is only used for X.25 and dialup connections
f9ed25
        # where the admin wants low latency.  Such a low MTU can cause
f9ed25
        # problems with UDP traffic, among other things.  As such,
f9ed25
        # disallow MTUs from 576 and below by default, so that broken
f9ed25
        # MTUs are ignored, but higher stuff is allowed (1492, 1500, etc).
f9ed25
        if [ -n "${new_interface_mtu}" ] && [ "${new_interface_mtu}" -gt 576 ]; then
f9ed25
            ip link set dev "${interface}" mtu "${new_interface_mtu}"
f9ed25
        fi
f9ed25
f9ed25
        # static routes
f9ed25
        if [ -n "${new_classless_static_routes}" ] ||
f9ed25
           [ -n "${new_static_routes}" ]; then
f9ed25
            if [ -n "${new_classless_static_routes}" ]; then
f9ed25
                IFS=', |' static_routes=(${new_classless_static_routes})
f9ed25
                # If the DHCP server returns both a Classless Static Routes option and
f9ed25
                # a Router option, the DHCP client MUST ignore the Router option. (RFC3442)
f9ed25
                new_routers=""
f9ed25
            else
f9ed25
                IFS=', |' static_routes=(${new_static_routes})
f9ed25
            fi
f9ed25
            route_targets=()
f9ed25
f9ed25
            for((i=0; i<${#static_routes[@]}; i+=2)); do
f9ed25
                target=${static_routes[$i]}
f9ed25
                if [ -n "${new_classless_static_routes}" ]; then
f9ed25
                    if [ "${target}" = "0" ]; then
f9ed25
                        new_routers="${static_routes[$i+1]}"
f9ed25
                        continue
f9ed25
                    else
f9ed25
                        prefix=${target%%.*}
f9ed25
                        target=${target#*.}
f9ed25
                        IFS="." target_arr=(${target})
f9ed25
                        unset IFS
f9ed25
                        ((pads=4-${#target_arr[@]}))
f9ed25
                        for j in $(seq $pads); do
f9ed25
                            target="${target}.0"
f9ed25
                        done
f9ed25
f9ed25
                        # Client MUST zero any bits in the subnet number where the corresponding bit in the mask is zero.
f9ed25
                        # In other words, the subnet number installed in the routing table is the logical AND of
f9ed25
                        # the subnet number and subnet mask given in the Classless Static Routes option. (RFC3442)
f9ed25
                        target="$(get_network_address "${target}" "${prefix}")"
f9ed25
                    fi
f9ed25
                else
f9ed25
                    prefix=$(class_bits "${target}")
f9ed25
                fi
f9ed25
                gateway=${static_routes[$i+1]}
f9ed25
f9ed25
                # special case 0.0.0.0 to allow static routing for link-local addresses
f9ed25
                # (including IPv4 multicast) which will not have a next-hop (#769463, #787318)
f9ed25
                if [ "${gateway}" = "0.0.0.0" ]; then
f9ed25
                    valid_gateway=0
f9ed25
                    scope='scope link'
f9ed25
                else
f9ed25
                    is_router_reachable "${gateway}"
f9ed25
                    valid_gateway=$?
f9ed25
                    scope=''
f9ed25
                fi
f9ed25
                if [ "${valid_gateway}" -eq 0 ]; then
f9ed25
                    metric=''
f9ed25
                    for t in "${route_targets[@]}"; do
f9ed25
                        if [ "${t}" = "${target}" ]; then
f9ed25
                            if [ -z "${metric}" ]; then
f9ed25
                                metric=1
f9ed25
                            else
f9ed25
                                ((metric=metric+1))
f9ed25
                            fi
f9ed25
                        fi
f9ed25
                    done
f9ed25
f9ed25
                    if [ -n "${metric}" ]; then
f9ed25
                        metric="metric ${metric}"
f9ed25
                    fi
f9ed25
f9ed25
                    ip -4 route replace "${target}/${prefix}" proto static via "${gateway}" dev "${interface}" ${metric} ${scope}
f9ed25
f9ed25
                    if [ $? -ne 0 ]; then
f9ed25
                        logmessage "failed to create static route: ${target}/${prefix} via ${gateway} dev ${interface} ${metric}"
f9ed25
                    else
f9ed25
                        route_targets=(${route_targets[@]} ${target})
f9ed25
                    fi
f9ed25
                fi
f9ed25
            done
f9ed25
        fi
f9ed25
f9ed25
        # gateways
f9ed25
        if [[ ( "${DEFROUTE}" != "no" ) &&
f9ed25
              (( -z "${GATEWAYDEV}" ) || ( "${GATEWAYDEV}" = "${interface}" )) ]]; then
f9ed25
            if [[ ( -z "${GATEWAY}" ) ||
f9ed25
                  (( -n "${DHCLIENT_IGNORE_GATEWAY}" ) && ( "${DHCLIENT_IGNORE_GATEWAY}" = [Yy]* )) ]]; then
f9ed25
                metric="${METRIC:-}"
f9ed25
                let i="${METRIC:-0}"
f9ed25
                default_routers=()
f9ed25
f9ed25
                for router in ${new_routers} ; do
f9ed25
                    added_router=-
f9ed25
f9ed25
                    for r in "${default_routers[@]}" ; do
f9ed25
                        if [ "${r}" = "${router}" ]; then
f9ed25
                            added_router=1
f9ed25
                        fi
f9ed25
                    done
f9ed25
f9ed25
                    if [ -z "${router}" ] ||
f9ed25
                       [ "${added_router}" = "1" ] ||
f9ed25
                       [ "$(IFS='.' ip2num ${router})" -le 0 ] ||
f9ed25
                       [[ ( "${router}" = "${new_broadcast_address}" ) &&
f9ed25
                          ( "${new_subnet_mask}" != "255.255.255.255" ) ]]; then
f9ed25
                        continue
f9ed25
                    fi
f9ed25
f9ed25
                    default_routers=(${default_routers[@]} ${router})
f9ed25
                    add_default_gateway "${router}" "${metric}"
f9ed25
                    let i=i+1
f9ed25
                    metric=${i}
f9ed25
                done
f9ed25
            elif [ -n "${GATEWAY}" ]; then
f9ed25
                routersubnet=$(get_network_address "${GATEWAY}" "${new_subnet_mask}")
f9ed25
                mysubnet=$(get_network_address "${new_ip_address}" "${new_subnet_mask}")
f9ed25
f9ed25
                if [ "${routersubnet}" = "${mysubnet}" ]; then
f9ed25
                    ip -4 route replace default via "${GATEWAY}" dev "${interface}"
f9ed25
                fi
f9ed25
            fi
f9ed25
        fi
f9ed25
    fi
f9ed25
f9ed25
    if [ ! "${new_ip_address}" = "${alias_ip_address}" ] &&
f9ed25
       [ -n "${alias_ip_address}" ]; then
f9ed25
        # Reset the alias address (fix: this should really only do this on changes)
f9ed25
        ip -4 addr flush dev "${interface}" label "${interface}:0" >/dev/null 2>&1
f9ed25
        ip -4 addr replace "${alias_ip_address}/${alias_prefix}" broadcast "${alias_broadcast_address}" dev "${interface}" label "${interface}:0"
f9ed25
        ip -4 route replace "${alias_ip_address}/32" dev "${interface}"
f9ed25
    fi
f9ed25
f9ed25
    # After dhclient brings an interface UP with a new IP address, subnet mask, 
f9ed25
    # and routes, in the REBOOT/BOUND states -> search for "dhclient-up-hooks".
f9ed25
    if [ "${reason}" = "BOUND" ] || [ "${reason}" = "REBOOT" ] ||
f9ed25
       [ ! "${old_ip_address}" = "${new_ip_address}" ] ||
f9ed25
       [ ! "${old_subnet_mask}" = "${new_subnet_mask}" ] ||
f9ed25
       [ ! "${old_network_number}" = "${new_network_number}" ] ||
f9ed25
       [ ! "${old_broadcast_address}" = "${new_broadcast_address}" ] ||
f9ed25
       [ ! "${old_routers}" = "${new_routers}" ] ||
f9ed25
       [ ! "${old_interface_mtu}" = "${new_interface_mtu}" ]; then
f9ed25
f9ed25
        if [ -x "${ETCDIR}/dhclient-${interface}-up-hooks" ]; then
f9ed25
            . "${ETCDIR}/dhclient-${interface}-up-hooks"
f9ed25
        elif [ -x ${ETCDIR}/dhclient-up-hooks ]; then
f9ed25
            . ${ETCDIR}/dhclient-up-hooks
f9ed25
        fi
f9ed25
    fi
f9ed25
f9ed25
    make_resolv_conf
f9ed25
f9ed25
    if [ -n "${new_host_name}" ] && need_hostname; then
f9ed25
        hostnamectl set-hostname --transient --no-ask-password "${new_host_name}"
f9ed25
    fi
f9ed25
f9ed25
    if [[ ( "${DHCP_TIME_OFFSET_SETS_TIMEZONE}" = [yY1]* ) &&
f9ed25
          ( -n "${new_time_offset}" ) ]]; then
f9ed25
        # DHCP option "time-offset" is requested by default and should be
f9ed25
        # handled.  The geographical zone abbreviation cannot be determined
f9ed25
        # from the GMT offset, but the $ZONEINFO/Etc/GMT$offset file can be
f9ed25
        # used - note: this disables DST.
f9ed25
        ((z=new_time_offset/3600))
f9ed25
        ((hoursWest=$(printf '%+d' $z)))
f9ed25
f9ed25
        if (( $hoursWest < 0 )); then
f9ed25
            # tzdata treats negative 'hours west' as positive 'gmtoff'!
f9ed25
            ((hoursWest*=-1))
f9ed25
        fi
f9ed25
f9ed25
        tzfile=/usr/share/zoneinfo/Etc/GMT$(printf '%+d' ${hoursWest})
f9ed25
        if [ -e "${tzfile}" ]; then
f9ed25
            cp -fp "${tzfile}" /etc/localtime
f9ed25
            touch /etc/localtime
f9ed25
        fi
f9ed25
    fi
f9ed25
f9ed25
    execute_client_side_configuration_scripts "config"
f9ed25
}
f9ed25
f9ed25
wait_for_link_local() {
f9ed25
    # we need a link-local address to be ready (not tentative)
f9ed25
    for i in $(seq 50); do
f9ed25
        linklocal=$(ip -6 addr show dev "${interface}" scope link)
f9ed25
        # tentative flag means DAD is still not complete
f9ed25
        tentative=$(echo "${linklocal}" | grep tentative)
f9ed25
        [[ -n "${linklocal}" && -z "${tentative}" ]] && exit_with_hooks 0
f9ed25
        sleep 0.1
f9ed25
    done
f9ed25
}
f9ed25
f9ed25
# Section 18.1.8. (Receipt of Reply Messages) of RFC 3315 says:
f9ed25
# The client SHOULD perform duplicate address detection on each of
f9ed25
# the addresses in any IAs it receives in the Reply message before
f9ed25
# using that address for traffic.
f9ed25
add_ipv6_addr_with_DAD() {
f9ed25
            ip -6 addr replace "${new_ip6_address}/${new_ip6_prefixlen}" \
f9ed25
                dev "${interface}" scope global valid_lft "${new_max_life}" \
f9ed25
                                          preferred_lft "${new_preferred_life}"
f9ed25
f9ed25
            # repeatedly test whether newly added address passed
f9ed25
            # duplicate address detection (DAD)
f9ed25
            for i in $(seq 5); do
f9ed25
                sleep 1 # give the DAD some time
f9ed25
f9ed25
                addr=$(ip -6 addr show dev "${interface}" \
f9ed25
                       | grep "${new_ip6_address}/${new_ip6_prefixlen}")
f9ed25
f9ed25
                # tentative flag == DAD is still not complete
f9ed25
                tentative=$(echo "${addr}" | grep tentative)
f9ed25
                # dadfailed flag == address is already in use somewhere else
f9ed25
                dadfailed=$(echo "${addr}" | grep dadfailed)
f9ed25
f9ed25
                if [ -n "${dadfailed}" ] ; then
f9ed25
                    # address was added with valid_lft/preferred_lft 'forever', remove it
f9ed25
                    ip -6 addr del "${new_ip6_address}/${new_ip6_prefixlen}" dev "${interface}"
f9ed25
                    exit_with_hooks 3
f9ed25
                fi
f9ed25
                if [ -z "${tentative}" ] ; then
f9ed25
                    if [ -n "${addr}" ]; then
f9ed25
                        # DAD is over
f9ed25
                        return 0
f9ed25
                    else
f9ed25
                        # address was auto-removed (or not added at all)
f9ed25
                        exit_with_hooks 3
f9ed25
                    fi
f9ed25
                fi
f9ed25
            done
f9ed25
            return 0
f9ed25
}
f9ed25
f9ed25
dh6config() {
f9ed25
    if [ -n "${old_ip6_prefix}" ] ||
f9ed25
       [ -n "${new_ip6_prefix}" ]; then
f9ed25
        echo "Prefix ${reason} old=${old_ip6_prefix} new=${new_ip6_prefix}"
f9ed25
        exit_with_hooks 0
f9ed25
    fi
f9ed25
f9ed25
    case "${reason}" in
f9ed25
        BOUND6)
f9ed25
            if [ -z "${new_ip6_address}" ] ||
f9ed25
               [ -z "${new_ip6_prefixlen}" ]; then
f9ed25
                exit_with_hooks 2
f9ed25
            fi
f9ed25
f9ed25
            add_ipv6_addr_with_DAD
f9ed25
f9ed25
            make_resolv_conf
f9ed25
            ;;
f9ed25
f9ed25
        RENEW6|REBIND6)
f9ed25
            if [[ -n "${new_ip6_address}" ]] &&
f9ed25
               [[ -n "${new_ip6_prefixlen}" ]]; then
f9ed25
               if [[  ! "${new_ip6_address}" = "${old_ip6_address}" ]]; then
f9ed25
                   [[ -n "${old_ip6_address}" ]] && ip -6 addr del "${old_ip6_address}" dev "${interface}"
f9ed25
               fi
f9ed25
               # call it even if new_ip6_address = old_ip6_address to update lifetimes
f9ed25
               add_ipv6_addr_with_DAD
f9ed25
            fi
f9ed25
f9ed25
            if [ ! "${new_dhcp6_name_servers}" = "${old_dhcp6_name_servers}" ] ||
f9ed25
               [ ! "${new_dhcp6_domain_search}" = "${old_dhcp6_domain_search}" ]; then
f9ed25
                make_resolv_conf
f9ed25
            fi
f9ed25
            ;;
f9ed25
f9ed25
        DEPREF6)
f9ed25
            if [ -z "${new_ip6_prefixlen}" ]; then
f9ed25
                exit_with_hooks 2
f9ed25
            fi
f9ed25
f9ed25
            ip -6 addr change "${new_ip6_address}/${new_ip6_prefixlen}" \
f9ed25
                dev "${interface}" scope global preferred_lft 0
f9ed25
            ;;
f9ed25
    esac
f9ed25
f9ed25
    execute_client_side_configuration_scripts "config"
f9ed25
}
f9ed25
f9ed25
# Functions from /etc/sysconfig/network-scripts/network-functions
f9ed25
f9ed25
need_hostname ()
f9ed25
{
f9ed25
    CHECK_HOSTNAME=$(hostnamectl --transient)
f9ed25
    if [[ "${CHECK_HOSTNAME}" = "(none)" ]] ||
f9ed25
       [[ "${CHECK_HOSTNAME}" = "localhost" ]] ||
f9ed25
       [[ "${CHECK_HOSTNAME}" = "localhost.localdomain" ]]; then
f9ed25
        return 0
f9ed25
    else
f9ed25
        return 1
f9ed25
    fi
f9ed25
}
f9ed25
f9ed25
# Takes one argument - temporary resolv.conf file
f9ed25
change_resolv_conf ()
f9ed25
{
f9ed25
    options=$(grep '^[\ \	]*option' "${RESOLVCONF}" 2>/dev/null);
f9ed25
    if [[ -n "${options}" ]]; then
f9ed25
       # merge options from existing resolv.conf with specified resolv.conf content
f9ed25
       newres="${options}"$'\n'$(grep -vF "${options}" "${1}");
f9ed25
    else
f9ed25
       newres=$(cat "${1}");
f9ed25
    fi;
f9ed25
f9ed25
    eval $(echo "${newres}" > "${RESOLVCONF}"; echo "status=$?")
f9ed25
    if [[ $status -eq 0 ]]; then
f9ed25
        logger -p local7.notice -t "NET" -i "${0} : updated ${RESOLVCONF}";
f9ed25
        [[ -e /var/run/nscd/socket ]] && /usr/sbin/nscd -i hosts; # invalidate cache
f9ed25
    fi;
f9ed25
    return $status;
f9ed25
}
f9ed25
f9ed25
get_config_by_name ()
f9ed25
{
f9ed25
    LANG=C grep -E -i -l \
f9ed25
        "^[[:space:]]*NAME=\"(Auto |System )?${1}\"" \
f9ed25
        /etc/sysconfig/network-scripts/ifcfg-* \
f9ed25
        | LC_ALL=C sed -e "$__sed_discard_ignored_files"
f9ed25
}
f9ed25
f9ed25
get_hwaddr ()
f9ed25
{
f9ed25
    if [ -f /sys/class/net/${1}/address ]; then
f9ed25
        awk '{ print toupper($0) }' < /sys/class/net/${1}/address
f9ed25
    elif [ -d "/sys/class/net/${1}" ]; then
f9ed25
        LC_ALL= LANG= ip -o link show ${1} 2>/dev/null | \
f9ed25
            awk '{ print toupper(gensub(/.*link\/[^ ]* ([[:alnum:]:]*).*/,
f9ed25
                                        "\\1", 1)); }'
f9ed25
    fi
f9ed25
}
f9ed25
f9ed25
validate_resolv_conf()
f9ed25
{
f9ed25
    # It's possible to have broken symbolic link $RESOLVCONF -> <some_nm_dir>
f9ed25
    # https://bugzilla.redhat.com/1475279
f9ed25
    # Remove broken link and hope NM will survive
f9ed25
    if [ -h "${RESOLVCONF}" -a ! -e "${RESOLVCONF}" ];
f9ed25
    then
f9ed25
        logmessage "${RESOLVCONF} is broken symlink. Recreating..."
f9ed25
        unlink "${RESOLVCONF}"
f9ed25
        touch "${RESOLVCONF}"
f9ed25
    fi;
f9ed25
}
f9ed25
f9ed25
f9ed25
get_config_by_hwaddr ()
f9ed25
{
f9ed25
    LANG=C grep -il "^[[:space:]]*HWADDR=\"\?${1}\"\?\([[:space:]#]\|$\)" /etc/sysconfig/network-scripts/ifcfg-* \
f9ed25
      | LC_ALL=C sed -e "$__sed_discard_ignored_files"
f9ed25
}
f9ed25
f9ed25
get_config_by_device ()
f9ed25
{
f9ed25
    LANG=C grep -l "^[[:space:]]*DEVICE=\"\?${1}\"\?\([[:space:]#]\|$\)" \
f9ed25
        /etc/sysconfig/network-scripts/ifcfg-* \
f9ed25
        | LC_ALL=C sed -e "$__sed_discard_ignored_files"
f9ed25
}
f9ed25
f9ed25
need_config ()
f9ed25
{
f9ed25
    # A sed expression to filter out the files that is_ignored_file recognizes
f9ed25
    __sed_discard_ignored_files='/\(~\|\.bak\|\.orig\|\.rpmnew\|\.rpmorig\|\.rpmsave\)$/d'
f9ed25
f9ed25
    local nconfig
f9ed25
f9ed25
    CONFIG="ifcfg-${1}"
f9ed25
    [ -f "${CONFIG}" ] && return
f9ed25
    CONFIG="${1##*/}"
f9ed25
    [ -f "${CONFIG}" ] && return
f9ed25
    nconfig=$(get_config_by_name "${1}")
f9ed25
    if [ -n "$nconfig" ] && [ -f "$nconfig" ]; then
f9ed25
      CONFIG=${nconfig##*/}
f9ed25
      return
f9ed25
    fi
f9ed25
    local addr=$(get_hwaddr ${1})
f9ed25
    if [ -n "$addr" ]; then
f9ed25
      nconfig=$(get_config_by_hwaddr ${addr})
f9ed25
      if [ -n "$nconfig" ] ; then
f9ed25
        CONFIG=${nconfig##*/}
f9ed25
        [ -f "${CONFIG}" ] && return
f9ed25
      fi
f9ed25
    fi
f9ed25
    nconfig=$(get_config_by_device ${1})
f9ed25
    if [ -n "$nconfig" ] && [ -f "$nconfig" ]; then
f9ed25
      CONFIG=${nconfig##*/}
f9ed25
      return
f9ed25
    fi
f9ed25
}
f9ed25
f9ed25
# We need this because of PEERDNS
f9ed25
source_config ()
f9ed25
{
f9ed25
    CONFIG=${CONFIG##*/}
f9ed25
    . /etc/sysconfig/network-scripts/$CONFIG
f9ed25
}
f9ed25
f9ed25
#
f9ed25
# ### MAIN
f9ed25
#
f9ed25
f9ed25
# Invoke the local dhcp client enter hooks, if they exist.
f9ed25
run_hook "${ETCDIR}/dhclient-enter-hooks" || exit $?
f9ed25
run_hookdir "${ETCDIR}/dhclient-enter-hooks.d" || exit $?
f9ed25
f9ed25
[ "${PEERDNS}" = "no" ] || validate_resolv_conf
f9ed25
f9ed25
if [ -f /etc/sysconfig/network ]; then
f9ed25
    . /etc/sysconfig/network
f9ed25
fi
f9ed25
f9ed25
if [ -f /etc/sysconfig/networking/network ]; then
f9ed25
    . /etc/sysconfig/networking/network
f9ed25
fi
f9ed25
f9ed25
## it's possible initscripts package is not installed
f9ed25
## for example in container. Don't flood stderr then
f9ed25
if [ -d /etc/sysconfig/network-scripts ]; then
f9ed25
        cd /etc/sysconfig/network-scripts
f9ed25
        CONFIG="${interface}"
f9ed25
        need_config "${CONFIG}"
f9ed25
        source_config >/dev/null 2>&1
f9ed25
fi;
f9ed25
f9ed25
# In case there's some delay in rebinding, it might happen, that the valid_lft drops to 0,
f9ed25
# address is removed by kernel and then re-added few seconds later by dhclient-script.
f9ed25
# With this work-around the address lives a minute longer.
f9ed25
# "4294967235" = infinite (forever) - 60
f9ed25
[[ "${new_dhcp_lease_time}" -lt "4294967235" ]] && new_dhcp_lease_time=$((new_dhcp_lease_time + 60))
f9ed25
[[ "${new_max_life}" -lt "4294967235" ]] && new_max_life=$((new_max_life + 60))
f9ed25
f9ed25
new_prefix="$(get_prefix "${new_ip_address}" "${new_subnet_mask}")"
f9ed25
old_prefix="$(get_prefix "${old_ip_address}" "${old_subnet_mask}")"
f9ed25
alias_prefix="$(get_prefix "${alias_ip_address}" "${alias_subnet_mask}")"
f9ed25
f9ed25
case "${reason}" in
f9ed25
    MEDIUM|ARPCHECK|ARPSEND)
f9ed25
        # Do nothing
f9ed25
        exit_with_hooks 0
f9ed25
        ;;
f9ed25
f9ed25
    PREINIT)
f9ed25
        if [ -n "${alias_ip_address}" ]; then
f9ed25
            # Flush alias, its routes will disappear too.
f9ed25
            ip -4 addr flush dev "${interface}" label "${interface}:0" >/dev/null 2>&1
f9ed25
        fi
f9ed25
f9ed25
        # upstream dhclient-script removes (ifconfig $interface 0 up) old adresses in PREINIT,
f9ed25
        # but we sometimes (#125298) need (for iSCSI/nfs root to have a dhcp interface) to keep the existing ip
f9ed25
        # flush_dev ${interface}
f9ed25
        ip link set dev "${interface}" up
f9ed25
        if [ -n "${DHCLIENT_DELAY}" ] && [ "${DHCLIENT_DELAY}" -gt 0 ]; then
f9ed25
            # We need to give the kernel some time to get the interface up.
f9ed25
            sleep "${DHCLIENT_DELAY}"
f9ed25
        fi
f9ed25
f9ed25
        exit_with_hooks 0
f9ed25
        ;;
f9ed25
f9ed25
    PREINIT6)
f9ed25
        # ensure interface is up
f9ed25
        ip link set dev "${interface}" up
f9ed25
f9ed25
        # Removing stale addresses from aborted clients shouldn't be needed
f9ed25
        # since we've been adding addresses with lifetimes.
f9ed25
        # Which means that kernel eventually removes them automatically.
f9ed25
        # ip -6 addr flush dev "${interface}" scope global permanent
f9ed25
f9ed25
        wait_for_link_local
f9ed25
f9ed25
        exit_with_hooks 0
f9ed25
        ;;
f9ed25
f9ed25
    BOUND|RENEW|REBIND|REBOOT)
f9ed25
        if [ -z "${interface}" ] || [ -z "${new_ip_address}" ]; then
f9ed25
            exit_with_hooks 2
f9ed25
        fi
f9ed25
        if arping -D -q -c2 -I "${interface}" "${new_ip_address}"; then
f9ed25
            dhconfig
f9ed25
            exit_with_hooks 0
f9ed25
        else  # DAD failed, i.e. address is already in use
f9ed25
            ARP_REPLY=$(arping -D -c2 -I "${interface}" "${new_ip_address}" | grep reply | awk '{print toupper($5)}' | cut -d "[" -f2 | cut -d "]" -f1)
f9ed25
            OUR_MACS=$(ip link show | grep link | awk '{print toupper($2)}' | uniq)
f9ed25
            if [[ "${OUR_MACS}" = *"${ARP_REPLY}"* ]]; then
f9ed25
                # the reply can come from our system, that's OK (#1116004#c33)
f9ed25
                dhconfig
f9ed25
                exit_with_hooks 0
f9ed25
            else
f9ed25
                exit_with_hooks 1
f9ed25
            fi
f9ed25
        fi
f9ed25
        ;;
f9ed25
f9ed25
    BOUND6|RENEW6|REBIND6|DEPREF6)
f9ed25
        dh6config
f9ed25
        exit_with_hooks 0
f9ed25
        ;;
f9ed25
f9ed25
    EXPIRE6|RELEASE6|STOP6)
f9ed25
        if [ -z "${old_ip6_address}" ] || [ -z "${old_ip6_prefixlen}" ]; then
f9ed25
            exit_with_hooks 2
f9ed25
        fi
f9ed25
f9ed25
        ip -6 addr del "${old_ip6_address}/${old_ip6_prefixlen}" \
f9ed25
            dev "${interface}"
f9ed25
f9ed25
        execute_client_side_configuration_scripts "restore"
f9ed25
f9ed25
        if [ -x "${ETCDIR}/dhclient-${interface}-down-hooks" ]; then
f9ed25
            . "${ETCDIR}/dhclient-${interface}-down-hooks"
f9ed25
        elif [ -x ${ETCDIR}/dhclient-down-hooks ]; then
f9ed25
            . ${ETCDIR}/dhclient-down-hooks
f9ed25
        fi
f9ed25
f9ed25
        exit_with_hooks 0
f9ed25
        ;;
f9ed25
f9ed25
    EXPIRE|FAIL|RELEASE|STOP)
f9ed25
        execute_client_side_configuration_scripts "restore"
f9ed25
f9ed25
        if [ -x "${ETCDIR}/dhclient-${interface}-down-hooks" ]; then
f9ed25
            . "${ETCDIR}/dhclient-${interface}-down-hooks"
f9ed25
        elif [ -x ${ETCDIR}/dhclient-down-hooks ]; then
f9ed25
            . ${ETCDIR}/dhclient-down-hooks
f9ed25
        fi
f9ed25
f9ed25
        if [ -n "${alias_ip_address}" ]; then
f9ed25
            # Flush alias
f9ed25
            ip -4 addr flush dev "${interface}" label "${interface}:0" >/dev/null 2>&1
f9ed25
        fi
f9ed25
f9ed25
        # upstream script sets interface down here,
f9ed25
        # we only remove old ip address
f9ed25
        #flush_dev ${interface}
f9ed25
        remove_old_addr
f9ed25
f9ed25
        if [ -n "${alias_ip_address}" ]; then
f9ed25
            ip -4 addr replace "${alias_ip_address}/${alias_prefix}" broadcast "${alias_broadcast_address}" dev "${interface}" label "${interface}:0"
f9ed25
            ip -4 route replace "${alias_ip_address}/32" dev "${interface}"
f9ed25
        fi
f9ed25
f9ed25
        exit_with_hooks 0
f9ed25
        ;;
f9ed25
f9ed25
    TIMEOUT)
f9ed25
        if [ -n "${new_routers}" ]; then
f9ed25
            if [ -n "${alias_ip_address}" ]; then
f9ed25
                ip -4 addr flush dev "${interface}" label "${interface}:0" >/dev/null 2>&1
f9ed25
            fi
f9ed25
f9ed25
            ip -4 addr replace "${new_ip_address}/${new_prefix}" \
f9ed25
                broadcast "${new_broadcast_address}" dev "${interface}" \
f9ed25
                valid_lft "${new_dhcp_lease_time}" preferred_lft "${new_dhcp_lease_time}"
f9ed25
            set ${new_routers}
f9ed25
f9ed25
            if ping -q -c 1 -w 10 -I "${interface}" "${1}"; then
f9ed25
                dhconfig
f9ed25
                exit_with_hooks 0
f9ed25
            fi
f9ed25
f9ed25
            #flush_dev ${interface}
f9ed25
            remove_old_addr
f9ed25
            exit_with_hooks 1
f9ed25
        else
f9ed25
            exit_with_hooks 1
f9ed25
        fi
f9ed25
        ;;
f9ed25
f9ed25
    *)
f9ed25
        logmessage "unhandled state: ${reason}"
f9ed25
        exit_with_hooks 1
f9ed25
        ;;
f9ed25
esac
f9ed25
f9ed25
exit_with_hooks 0