2008-01-11 00:19:03 +00:00
|
|
|
#!/bin/bash
|
2008-08-22 21:05:05 +00:00
|
|
|
#
|
|
|
|
# dhclient-script: Network interface configuration script run by
|
|
|
|
# dhclient based on DHCP client communication
|
|
|
|
#
|
2010-02-19 11:37:25 +00:00
|
|
|
# Copyright (C) 2008, 2009, 2010 Red Hat, Inc.
|
2008-08-22 21:05:05 +00:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
# Author(s): David Cantrell <dcantrell@redhat.com>
|
|
|
|
#
|
|
|
|
# ----------
|
|
|
|
# This script is a rewrite/reworking on dhclient-script originally
|
|
|
|
# included as part of dhcp-970306:
|
2008-01-11 00:19:03 +00:00
|
|
|
# dhclient-script for Linux. Dan Halbert, March, 1997.
|
|
|
|
# Updated for Linux 2.[12] by Brian J. Murrell, January 1999.
|
|
|
|
# Modified by David Cantrell <dcantrell@redhat.com> for Fedora and RHEL
|
2008-08-22 21:05:05 +00:00
|
|
|
# ----------
|
|
|
|
#
|
2008-01-11 00:19:03 +00:00
|
|
|
|
2008-08-22 21:05:05 +00:00
|
|
|
PATH=/bin:/usr/bin:/sbin
|
2012-06-18 14:19:31 +00:00
|
|
|
# scripts in dhclient.d/ use $SAVEDIR (#833054)
|
|
|
|
SAVEDIR=/var/lib/dhclient
|
2008-01-11 00:19:03 +00:00
|
|
|
|
2008-08-22 21:05:05 +00:00
|
|
|
LOGFACILITY="local7"
|
|
|
|
LOGLEVEL="notice"
|
2008-01-11 00:19:03 +00:00
|
|
|
|
2009-04-13 22:22:38 +00:00
|
|
|
ETCDIR="/etc/dhcp"
|
|
|
|
|
2008-08-22 21:05:05 +00:00
|
|
|
logmessage() {
|
|
|
|
msg="${1}"
|
|
|
|
logger -p ${LOGFACILITY}.${LOGLEVEL} -t "NET" "dhclient: ${msg}"
|
|
|
|
}
|
2008-01-11 00:19:03 +00:00
|
|
|
|
2011-01-28 14:42:01 +00:00
|
|
|
if [ -x /sbin/restorecon ]; then
|
|
|
|
fix_context() {
|
2009-03-06 00:57:04 +00:00
|
|
|
/sbin/restorecon ${1} >/dev/null 2>&1
|
2011-01-28 14:42:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
fix_context() { :; }
|
|
|
|
fi
|
2009-03-06 00:57:04 +00:00
|
|
|
|
2010-11-04 19:12:23 +00:00
|
|
|
eventually_add_hostnames_domain_to_search() {
|
|
|
|
# For the case when hostname for this machine has a domain that is not in domain_search list
|
|
|
|
# 1) get a hostname with `ipcalc --hostname` or `hostname`
|
|
|
|
# 2) get the domain from this hostname
|
|
|
|
# 3) add this domain to search line in resolv.conf if it's not already
|
|
|
|
# there (domain list that we have recently added there is a parameter of this function)
|
|
|
|
# We can't do this directly when generating resolv.conf in make_resolv_conf(), because
|
|
|
|
# we need to first save the resolv.conf with obtained values before we can call `ipcalc --hostname`.
|
|
|
|
# See bug 637763
|
|
|
|
search="${1}"
|
|
|
|
if need_hostname; then
|
|
|
|
status=1
|
|
|
|
if [ -n "${new_ip_address}" ]; then
|
|
|
|
eval $(/bin/ipcalc --silent --hostname ${new_ip_address} ; echo "status=$?")
|
|
|
|
elif [ -n "${new_ip6_address}" ]; then
|
|
|
|
eval $(/bin/ipcalc --silent --hostname ${new_ip6_address} ; echo "status=$?")
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ${status} -eq 0 ]; then
|
|
|
|
domain=$(echo $HOSTNAME | cut -s -d "." -f 2-)
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
domain=$(hostname 2>/dev/null | cut -s -d "." -f 2-)
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "${domain}" ] &&
|
|
|
|
[ ! "${domain}" = "localdomain" ] &&
|
|
|
|
[ ! "${domain}" = "localdomain6" ] &&
|
|
|
|
[ ! "${domain}" = "(none)" ] &&
|
|
|
|
[[ ! "${domain}" = *\ * ]]; then
|
|
|
|
is_in="false"
|
|
|
|
for s in ${search}; do
|
|
|
|
if [ "${s}" = "${domain}" ] ||
|
|
|
|
[ "${s}" = "${domain}." ]; then
|
|
|
|
is_in="true"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ "${is_in}" = "false" ]; then
|
|
|
|
# Add domain name to search list (#637763)
|
|
|
|
sed -i -e "s/${search}/${search} ${domain}/" /etc/resolv.conf
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2008-01-11 00:19:03 +00:00
|
|
|
make_resolv_conf() {
|
2008-08-22 21:05:05 +00:00
|
|
|
[ "${PEERDNS}" = "no" ] && return
|
2008-01-11 00:19:03 +00:00
|
|
|
|
2008-08-22 21:05:05 +00:00
|
|
|
if [ "${reason}" = "RENEW" ] &&
|
|
|
|
[ "${new_domain_name}" = "${old_domain_name}" ] &&
|
|
|
|
[ "${new_domain_name_servers}" = "${old_domain_name_servers}" ]; then
|
2008-01-11 00:19:03 +00:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2008-08-22 21:05:05 +00:00
|
|
|
if [ -n "${new_domain_name}" ] ||
|
|
|
|
[ -n "${new_domain_name_servers}" ] ||
|
|
|
|
[ -n "${new_domain_search}" ]; then
|
2011-01-28 14:42:01 +00:00
|
|
|
rscf="$(mktemp ${TMPDIR:-/tmp}/XXXXXX)"
|
2012-04-02 10:05:14 +00:00
|
|
|
echo "; generated by /usr/sbin/dhclient-script" > ${rscf}
|
2008-01-11 00:19:03 +00:00
|
|
|
|
2008-08-22 21:05:05 +00:00
|
|
|
if [ -n "${SEARCH}" ]; then
|
2010-11-04 19:12:23 +00:00
|
|
|
search="${SEARCH}"
|
2008-08-06 19:49:47 +00:00
|
|
|
else
|
2008-08-22 21:05:05 +00:00
|
|
|
if [ -n "${new_domain_search}" ]; then
|
2010-11-04 19:12:23 +00:00
|
|
|
# Remove instaces of \032 (#450042)
|
|
|
|
search="${new_domain_search//\\032/ }"
|
2008-08-22 21:05:05 +00:00
|
|
|
elif [ -n "${new_domain_name}" ]; then
|
2010-04-21 14:56:20 +00:00
|
|
|
# Note that the DHCP 'Domain Name Option' is really just a domain
|
|
|
|
# name, and that this practice of using the domain name option as
|
|
|
|
# a search path is both nonstandard and deprecated.
|
2010-11-04 19:12:23 +00:00
|
|
|
search="${new_domain_name}"
|
2008-01-11 00:19:03 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2010-11-04 19:12:23 +00:00
|
|
|
if [ -n "${search}" ]; then
|
|
|
|
echo "search ${search}" >> $rscf
|
|
|
|
fi
|
|
|
|
|
2008-08-22 21:05:05 +00:00
|
|
|
if [ -n "${RES_OPTIONS}" ]; then
|
|
|
|
echo "options ${RES_OPTIONS}" >> ${rscf}
|
2008-07-25 01:21:14 +00:00
|
|
|
fi
|
|
|
|
|
2008-08-22 21:05:05 +00:00
|
|
|
for nameserver in ${new_domain_name_servers} ; do
|
|
|
|
echo "nameserver ${nameserver}" >> ${rscf}
|
2008-01-11 00:19:03 +00:00
|
|
|
done
|
|
|
|
|
2008-08-22 21:05:05 +00:00
|
|
|
change_resolv_conf ${rscf}
|
|
|
|
rm -f ${rscf}
|
2008-10-01 22:38:30 +00:00
|
|
|
|
2010-11-04 19:12:23 +00:00
|
|
|
if [ -n "${search}" ]; then
|
|
|
|
eventually_add_hostnames_domain_to_search "${search}"
|
|
|
|
fi
|
|
|
|
|
2009-09-19 06:22:33 +00:00
|
|
|
fix_context /etc/resolv.conf
|
|
|
|
elif [ -n "${new_dhcp6_name_servers}" ] ||
|
|
|
|
[ -n "${new_dhcp6_domain_search}" ]; then
|
2011-01-28 14:42:01 +00:00
|
|
|
rscf="$(mktemp ${TMPDIR:-/tmp}/XXXXXX)"
|
2012-04-02 10:05:14 +00:00
|
|
|
echo "; generated by /usr/sbin/dhclient-script" > ${rscf}
|
2009-09-19 06:22:33 +00:00
|
|
|
|
|
|
|
if [ -n "${SEARCH}" ]; then
|
2010-11-04 19:12:23 +00:00
|
|
|
search="${SEARCH}"
|
2009-09-19 06:22:33 +00:00
|
|
|
else
|
|
|
|
if [ -n "${new_dhcp6_domain_search}" ]; then
|
2010-11-04 19:12:23 +00:00
|
|
|
search="${new_dhcp6_domain_search//\\032/ }"
|
2009-09-19 06:22:33 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2010-11-04 19:12:23 +00:00
|
|
|
if [ -n "${search}" ]; then
|
|
|
|
echo "search ${search}" >> $rscf
|
|
|
|
fi
|
|
|
|
|
2009-09-19 06:22:33 +00:00
|
|
|
if [ -n "${RES_OPTIONS}" ]; then
|
|
|
|
echo "options ${RES_OPTIONS}" >> ${rscf}
|
|
|
|
fi
|
|
|
|
|
2011-07-01 13:04:42 +00:00
|
|
|
shopt -s nocasematch
|
2009-09-19 06:22:33 +00:00
|
|
|
for nameserver in ${new_dhcp6_name_servers} ; do
|
2011-07-01 13:04:42 +00:00
|
|
|
# If the nameserver has a link-local address
|
|
|
|
# add a <zone_id> (interface name) to it.
|
|
|
|
if [[ "$nameserver" =~ ^fe80:: ]]
|
|
|
|
then
|
|
|
|
zone_id="%${interface}"
|
|
|
|
else
|
|
|
|
zone_id=
|
|
|
|
fi
|
|
|
|
echo "nameserver ${nameserver}$zone_id" >> ${rscf}
|
2009-09-19 06:22:33 +00:00
|
|
|
done
|
2011-07-01 13:04:42 +00:00
|
|
|
shopt -u nocasematch
|
2009-09-19 06:22:33 +00:00
|
|
|
|
|
|
|
change_resolv_conf ${rscf}
|
|
|
|
rm -f ${rscf}
|
|
|
|
|
2010-11-04 19:12:23 +00:00
|
|
|
if [ -n "${search}" ]; then
|
|
|
|
eventually_add_hostnames_domain_to_search "${search}"
|
|
|
|
fi
|
|
|
|
|
2009-03-06 00:57:04 +00:00
|
|
|
fix_context /etc/resolv.conf
|
2008-01-11 00:19:03 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
exit_with_hooks() {
|
2008-08-22 21:05:05 +00:00
|
|
|
exit_status="${1}"
|
2008-01-11 00:19:03 +00:00
|
|
|
|
2009-04-13 22:22:38 +00:00
|
|
|
if [ -x ${ETCDIR}/dhclient-exit-hooks ]; then
|
|
|
|
. ${ETCDIR}/dhclient-exit-hooks
|
2008-01-11 00:19:03 +00:00
|
|
|
fi
|
|
|
|
|
2008-08-22 21:05:05 +00:00
|
|
|
exit ${exit_status}
|
2008-01-11 00:19:03 +00:00
|
|
|
}
|
|
|
|
|
2008-08-22 21:05:05 +00:00
|
|
|
quad2num() {
|
2008-01-11 00:19:03 +00:00
|
|
|
if [ $# -eq 4 ]; then
|
2008-08-22 21:05:05 +00:00
|
|
|
let n="${1} << 24 | ${2} << 16 | ${3} << 8 | ${4}"
|
|
|
|
echo "${n}"
|
2008-01-11 00:19:03 +00:00
|
|
|
return 0
|
2008-08-22 21:05:05 +00:00
|
|
|
else
|
|
|
|
echo "0"
|
|
|
|
return 1
|
2008-01-11 00:19:03 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2008-08-22 21:05:05 +00:00
|
|
|
ip2num() {
|
|
|
|
IFS="." quad2num ${1}
|
2008-01-11 00:19:03 +00:00
|
|
|
}
|
|
|
|
|
2008-08-22 21:05:05 +00:00
|
|
|
num2ip() {
|
|
|
|
let n="${1}"
|
|
|
|
let o1="(n >> 24) & 0xff"
|
|
|
|
let o2="(n >> 16) & 0xff"
|
|
|
|
let o3="(n >> 8) & 0xff"
|
|
|
|
let o4="n & 0xff"
|
|
|
|
echo "${o1}.${o2}.${o3}.${o4}"
|
2008-01-11 00:19:03 +00:00
|
|
|
}
|
|
|
|
|
2010-08-31 11:01:51 +00:00
|
|
|
get_network_address() {
|
|
|
|
# get network address for the given IP address and (netmask or prefix)
|
2008-08-22 21:05:05 +00:00
|
|
|
ip="${1}"
|
2010-08-31 11:01:51 +00:00
|
|
|
nm="${2}"
|
|
|
|
|
|
|
|
if [ -n "${ip}" -a -n "${nm}" ]; then
|
|
|
|
if [[ "${nm}" = *.* ]]; then
|
|
|
|
ipcalc -s -n ${ip} ${nm} | cut -d '=' -f 2
|
|
|
|
else
|
|
|
|
ipcalc -s -n ${ip}/${nm} | cut -d '=' -f 2
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
get_prefix() {
|
|
|
|
# get prefix for the given IP address and mask
|
|
|
|
ip="${1}"
|
|
|
|
nm="${2}"
|
|
|
|
|
|
|
|
if [ -n "${ip}" -a -n "${nm}" ]; then
|
|
|
|
ipcalc -s -p ${ip} ${nm} | cut -d '=' -f 2
|
|
|
|
fi
|
2008-01-11 00:19:03 +00:00
|
|
|
}
|
|
|
|
|
2008-08-22 21:05:05 +00:00
|
|
|
class_bits() {
|
2008-01-11 00:19:03 +00:00
|
|
|
let ip=$(IFS='.' ip2num $1)
|
|
|
|
let bits=32
|
|
|
|
let mask='255'
|
|
|
|
for ((i=0; i <= 3; i++, 'mask<<=8')); do
|
|
|
|
let v='ip&mask'
|
|
|
|
if [ "$v" -eq 0 ] ; then
|
|
|
|
let bits-=8
|
|
|
|
else
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
echo $bits
|
|
|
|
}
|
|
|
|
|
2008-08-22 21:05:05 +00:00
|
|
|
is_router_reachable() {
|
|
|
|
# handle DHCP servers that give us a router not on our subnet
|
|
|
|
router="${1}"
|
2010-08-31 11:01:51 +00:00
|
|
|
routersubnet="$(get_network_address ${router} ${new_subnet_mask})"
|
|
|
|
mysubnet="$(get_network_address ${new_ip_address} ${new_subnet_mask})"
|
2008-08-22 21:05:05 +00:00
|
|
|
|
|
|
|
if [ ! "${routersubnet}" = "${mysubnet}" ]; then
|
2010-10-07 15:48:46 +00:00
|
|
|
ip -4 route add ${router}/32 dev ${interface}
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
if ping -q -c1 -w2 -I ${interface} ${router}; then
|
|
|
|
return 0
|
2008-08-22 21:05:05 +00:00
|
|
|
else
|
2010-10-07 15:48:46 +00:00
|
|
|
logmessage "DHCP router ${router} is unreachable on DHCP subnet ${mysubnet} router subnet ${routersubnet}"
|
|
|
|
ip route del ${router}/32 dev ${interface}
|
|
|
|
return 1
|
2008-08-22 21:05:05 +00:00
|
|
|
fi
|
2008-01-11 00:19:03 +00:00
|
|
|
else
|
2010-10-07 15:48:46 +00:00
|
|
|
logmessage "failed to create host router for unreachable router ${router} not on subnet ${mysubnet}"
|
|
|
|
return 1
|
2008-01-11 00:19:03 +00:00
|
|
|
fi
|
|
|
|
fi
|
2008-08-22 21:05:05 +00:00
|
|
|
|
2010-10-07 15:48:46 +00:00
|
|
|
return 0
|
2008-01-11 00:19:03 +00:00
|
|
|
}
|
|
|
|
|
2008-08-22 21:05:05 +00:00
|
|
|
add_default_gateway() {
|
|
|
|
router="${1}"
|
|
|
|
|
|
|
|
if is_router_reachable ${router} ; then
|
2011-01-28 14:42:01 +00:00
|
|
|
metric=""
|
|
|
|
if [ $# -gt 1 ] && [ ${2} -gt 0 ]; then
|
|
|
|
metric="metric ${2}"
|
|
|
|
fi
|
2010-02-19 11:37:25 +00:00
|
|
|
ip -4 route replace default via ${router} dev ${interface} ${metric}
|
2008-01-11 00:19:03 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
2008-08-22 21:05:05 +00:00
|
|
|
logmessage "failed to create default route: ${router} dev ${interface} ${metric}"
|
2008-01-11 00:19:03 +00:00
|
|
|
return 1
|
|
|
|
else
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
fi
|
2008-08-22 21:05:05 +00:00
|
|
|
|
2008-01-11 00:19:03 +00:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2011-01-28 14:42:01 +00:00
|
|
|
execute_client_side_configuration_scripts() {
|
|
|
|
# execute any additional client side configuration scripts we have
|
|
|
|
if [ "${1}" == "config" ] || [ "${1}" == "restore" ]; then
|
|
|
|
for f in ${ETCDIR}/dhclient.d/*.sh ; do
|
|
|
|
if [ -x ${f} ]; then
|
|
|
|
subsystem="${f%.sh}"
|
|
|
|
subsystem="${subsystem##*/}"
|
|
|
|
. ${f}
|
|
|
|
"${subsystem}_${1}"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2010-09-30 13:49:08 +00:00
|
|
|
flush_dev() {
|
|
|
|
# Instead of bringing the interface down (#574568)
|
|
|
|
# explicitly clear the ARP cache and flush all addresses & routes.
|
|
|
|
ip -4 addr flush dev ${1} >/dev/null 2>&1
|
|
|
|
ip -4 route flush dev ${1} >/dev/null 2>&1
|
|
|
|
ip -4 neigh flush dev ${1} >/dev/null 2>&1
|
|
|
|
}
|
|
|
|
|
2008-08-22 21:05:05 +00:00
|
|
|
dhconfig() {
|
|
|
|
if [ -n "${old_ip_address}" ] && [ -n "${alias_ip_address}" ] &&
|
|
|
|
[ ! "${alias_ip_address}" = "${old_ip_address}" ]; then
|
|
|
|
# possible new alias, remove old alias first
|
2011-09-29 12:18:16 +00:00
|
|
|
ip -4 addr del ${old_ip_address} dev ${interface} label ${interface}:0
|
2008-01-11 00:19:03 +00:00
|
|
|
fi
|
|
|
|
|
2008-08-22 21:05:05 +00:00
|
|
|
if [ -n "${old_ip_address}" ] &&
|
|
|
|
[ ! "${old_ip_address}" = "${new_ip_address}" ]; then
|
2010-09-30 13:49:08 +00:00
|
|
|
# IP address changed. Delete all routes, and clear the ARP cache.
|
|
|
|
flush_dev ${interface}
|
2008-01-11 00:19:03 +00:00
|
|
|
fi
|
|
|
|
|
2008-08-25 01:31:58 +00:00
|
|
|
if [ "${reason}" = "BOUND" ] || [ "${reason}" = "REBOOT" ] ||
|
2008-08-22 21:05:05 +00:00
|
|
|
[ ! "${old_ip_address}" = "${new_ip_address}" ] ||
|
|
|
|
[ ! "${old_subnet_mask}" = "${new_subnet_mask}" ] ||
|
|
|
|
[ ! "${old_network_number}" = "${new_network_number}" ] ||
|
|
|
|
[ ! "${old_broadcast_address}" = "${new_broadcast_address}" ] ||
|
|
|
|
[ ! "${old_routers}" = "${new_routers}" ] ||
|
|
|
|
[ ! "${old_interface_mtu}" = "${new_interface_mtu}" ]; then
|
2012-04-26 12:45:26 +00:00
|
|
|
ip -4 addr add ${new_ip_address}/${new_prefix} broadcast ${new_broadcast_address} dev ${interface} >/dev/null 2>&1
|
2010-02-19 11:37:25 +00:00
|
|
|
ip link set dev ${interface} up
|
2008-08-22 21:05:05 +00:00
|
|
|
|
2010-03-19 17:22:59 +00:00
|
|
|
# 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
|
2012-04-26 12:45:26 +00:00
|
|
|
ip link set dev ${interface} mtu ${new_interface_mtu}
|
2008-01-11 00:19:03 +00:00
|
|
|
fi
|
|
|
|
|
2010-08-31 11:01:51 +00:00
|
|
|
# static routes
|
|
|
|
if [ -n "${new_classless_static_routes}" ] ||
|
|
|
|
[ -n "${new_static_routes}" ]; then
|
|
|
|
if [ -n "${new_classless_static_routes}" ]; then
|
|
|
|
IFS=', |' static_routes=(${new_classless_static_routes})
|
|
|
|
else
|
|
|
|
IFS=', |' static_routes=(${new_static_routes})
|
|
|
|
fi
|
|
|
|
route_targets=()
|
|
|
|
|
|
|
|
for((i=0; i<${#static_routes[@]}; i+=2)); do
|
|
|
|
target=${static_routes[$i]}
|
|
|
|
if [ -n "${new_classless_static_routes}" ]; then
|
2010-10-04 09:51:33 +00:00
|
|
|
if [ ${target} = "0" ]; then
|
|
|
|
# If the DHCP server returns both a Classless Static Routes option and
|
|
|
|
# a Router option, the DHCP client MUST ignore the Router option. (RFC3442)
|
|
|
|
new_routers=""
|
|
|
|
prefix="0"
|
|
|
|
else
|
2011-01-28 14:42:01 +00:00
|
|
|
prefix=${target%%.*}
|
|
|
|
target=${target#*.}
|
2010-10-04 09:51:33 +00:00
|
|
|
IFS="." target_arr=(${target})
|
|
|
|
unset IFS
|
|
|
|
((pads=4-${#target_arr[@]}))
|
|
|
|
for j in $(seq $pads); do
|
2010-12-23 14:50:49 +00:00
|
|
|
target="${target}.0"
|
2010-10-04 09:51:33 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
# Client MUST zero any bits in the subnet number where the corresponding bit in the mask is zero.
|
|
|
|
# In other words, the subnet number installed in the routing table is the logical AND of
|
|
|
|
# the subnet number and subnet mask given in the Classless Static Routes option. (RFC3442)
|
|
|
|
target="$(get_network_address ${target} ${prefix})"
|
|
|
|
fi
|
2010-08-31 11:01:51 +00:00
|
|
|
else
|
|
|
|
prefix=$(class_bits ${target})
|
|
|
|
fi
|
|
|
|
gateway=${static_routes[$i+1]}
|
|
|
|
|
2011-12-20 17:26:43 +00:00
|
|
|
# special case 0.0.0.0 to allow static routing for link-local addresses
|
2012-02-07 10:07:14 +00:00
|
|
|
# (including IPv4 multicast) which will not have a next-hop (#769463, #787318)
|
|
|
|
if [ "${gateway}" = "0.0.0.0" ]; then
|
|
|
|
valid_gateway=0
|
|
|
|
scope='scope link'
|
|
|
|
else
|
|
|
|
is_router_reachable ${gateway}
|
|
|
|
valid_gateway=$?
|
|
|
|
scope=''
|
|
|
|
fi
|
|
|
|
if [ ${valid_gateway} -eq 0 ]; then
|
2011-01-28 14:42:01 +00:00
|
|
|
metric=''
|
|
|
|
for t in ${route_targets[@]}; do
|
|
|
|
if [ ${t} = ${target} ]; then
|
|
|
|
if [ -z "${metric}" ]; then
|
|
|
|
metric=1
|
|
|
|
else
|
|
|
|
((metric=metric+1))
|
|
|
|
fi
|
2010-08-31 11:01:51 +00:00
|
|
|
fi
|
2011-01-28 14:42:01 +00:00
|
|
|
done
|
2010-08-31 11:01:51 +00:00
|
|
|
|
2011-01-28 14:42:01 +00:00
|
|
|
if [ -n "${metric}" ]; then
|
|
|
|
metric="metric ${metric}"
|
|
|
|
fi
|
2010-08-31 11:01:51 +00:00
|
|
|
|
2012-02-07 10:07:14 +00:00
|
|
|
ip -4 route replace ${target}/${prefix} proto static via ${gateway} dev ${interface} ${metric} ${scope}
|
2010-08-31 11:01:51 +00:00
|
|
|
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
logmessage "failed to create static route: ${target}/${prefix} via ${gateway} dev ${interface} ${metric}"
|
|
|
|
else
|
|
|
|
route_targets=(${route_targets[@]} ${target})
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
# gateways
|
2011-01-28 14:42:01 +00:00
|
|
|
if [[ ( "${DEFROUTE}" != "no" ) &&
|
2011-12-20 17:26:43 +00:00
|
|
|
(( -z "${GATEWAYDEV}" ) || ( "${GATEWAYDEV}" = "${interface}" )) ]]; then
|
2009-11-23 09:14:24 +00:00
|
|
|
if [[ ( -z "$GATEWAY" ) ||
|
2011-12-20 17:26:43 +00:00
|
|
|
(( -n "$DHCLIENT_IGNORE_GATEWAY" ) && ( "$DHCLIENT_IGNORE_GATEWAY" = [Yy]* )) ]]; then
|
2009-11-23 09:14:24 +00:00
|
|
|
metric="${METRIC:-}"
|
|
|
|
let i="${METRIC:-0}"
|
|
|
|
default_routers=()
|
|
|
|
|
|
|
|
for router in ${new_routers} ; do
|
|
|
|
added_router=-
|
|
|
|
|
|
|
|
for r in ${default_routers[@]} ; do
|
|
|
|
if [ "${r}" = "${router}" ]; then
|
|
|
|
added_router=1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ -z "${router}" ] ||
|
|
|
|
[ "${added_router}" = "1" ] ||
|
|
|
|
[ $(IFS=. ip2num ${router}) -le 0 ] ||
|
|
|
|
[[ ( "${router}" = "${new_broadcast_address}" ) &&
|
|
|
|
( "${new_subnet_mask}" != "255.255.255.255" ) ]]; then
|
|
|
|
continue
|
2008-01-11 00:19:03 +00:00
|
|
|
fi
|
2009-11-23 09:14:24 +00:00
|
|
|
|
|
|
|
default_routers=(${default_routers[@]} ${router})
|
|
|
|
add_default_gateway ${router} ${metric}
|
|
|
|
let i=i+1
|
|
|
|
metric=${i}
|
2008-01-11 00:19:03 +00:00
|
|
|
done
|
2009-11-23 09:14:24 +00:00
|
|
|
elif [ -n "${GATEWAY}" ]; then
|
2010-08-31 11:01:51 +00:00
|
|
|
routersubnet=$(get_network_address ${GATEWAY} ${new_subnet_mask})
|
|
|
|
mysubnet=$(get_network_address ${new_ip_address} ${new_subnet_mask})
|
2008-01-11 00:19:03 +00:00
|
|
|
|
2009-11-23 09:14:24 +00:00
|
|
|
if [ "${routersubnet}" = "${mysubnet}" ]; then
|
2010-02-19 11:37:25 +00:00
|
|
|
ip -4 route replace default via ${GATEWAY} dev ${interface}
|
2008-01-11 00:19:03 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
2008-08-22 21:05:05 +00:00
|
|
|
if [ ! "${new_ip_address}" = "${alias_ip_address}" ] &&
|
|
|
|
[ -n "${alias_ip_address}" ]; then
|
2011-09-29 12:18:16 +00:00
|
|
|
# Reset the alias address (fix: this should really only do this on changes)
|
|
|
|
ip -4 addr flush dev ${interface} label ${interface}:0 >/dev/null 2>&1
|
|
|
|
ip -4 addr add ${alias_ip_address}/${alias_prefix} broadcast ${alias_broadcast_address} dev ${interface} label ${interface}:0
|
|
|
|
ip -4 route replace ${alias_ip_address}/32 dev ${interface}
|
2008-01-11 00:19:03 +00:00
|
|
|
fi
|
2012-08-20 13:41:22 +00:00
|
|
|
|
|
|
|
# After dhclient brings an interface UP with a new IP address, subnet mask,
|
|
|
|
# and routes, in the REBOOT/BOUND states -> search for "dhclient-up-hooks".
|
|
|
|
if [ "${reason}" = "BOUND" ] || [ "${reason}" = "REBOOT" ] ||
|
|
|
|
[ ! "${old_ip_address}" = "${new_ip_address}" ] ||
|
|
|
|
[ ! "${old_subnet_mask}" = "${new_subnet_mask}" ] ||
|
|
|
|
[ ! "${old_network_number}" = "${new_network_number}" ] ||
|
|
|
|
[ ! "${old_broadcast_address}" = "${new_broadcast_address}" ] ||
|
|
|
|
[ ! "${old_routers}" = "${new_routers}" ] ||
|
|
|
|
[ ! "${old_interface_mtu}" = "${new_interface_mtu}" ]; then
|
|
|
|
|
|
|
|
if [ -x ${ETCDIR}/dhclient-${interface}-up-hooks ]; then
|
|
|
|
. ${ETCDIR}/dhclient-${interface}-up-hooks
|
|
|
|
elif [ -x ${ETCDIR}/dhclient-up-hooks ]; then
|
|
|
|
. ${ETCDIR}/dhclient-up-hooks
|
|
|
|
fi
|
|
|
|
fi
|
2008-01-11 00:19:03 +00:00
|
|
|
|
|
|
|
make_resolv_conf
|
|
|
|
|
2008-08-22 21:05:05 +00:00
|
|
|
if [ -n "${new_host_name}" ] && need_hostname; then
|
2010-06-02 14:09:12 +00:00
|
|
|
hostname ${new_host_name} || echo "See -nc option in dhclient(8) man page."
|
2008-01-11 00:19:03 +00:00
|
|
|
fi
|
|
|
|
|
2011-01-28 14:42:01 +00:00
|
|
|
if [[ ( "${DHCP_TIME_OFFSET_SETS_TIMEZONE}" = [yY1]* ) &&
|
|
|
|
( -n "${new_time_offset}" ) ]]; then
|
|
|
|
# DHCP option "time-offset" is requested by default and should be
|
|
|
|
# handled. The geographical zone abbreviation cannot be determined
|
|
|
|
# from the GMT offset, but the $ZONEINFO/Etc/GMT$offset file can be
|
|
|
|
# used - note: this disables DST.
|
|
|
|
((z=new_time_offset/3600))
|
|
|
|
((hoursWest=$(printf '%+d' $z)))
|
|
|
|
|
|
|
|
if (( $hoursWest < 0 )); then
|
|
|
|
# tzdata treats negative 'hours west' as positive 'gmtoff'!
|
|
|
|
((hoursWest*=-1))
|
|
|
|
fi
|
2008-01-11 00:19:03 +00:00
|
|
|
|
2011-01-28 14:42:01 +00:00
|
|
|
tzfile=/usr/share/zoneinfo/Etc/GMT$(printf '%+d' ${hoursWest})
|
|
|
|
if [ -e ${tzfile} ]; then
|
|
|
|
cp -fp ${tzfile} /etc/localtime
|
|
|
|
touch /etc/localtime
|
|
|
|
fix_context /etc/localtime
|
2008-01-11 00:19:03 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2011-01-28 14:42:01 +00:00
|
|
|
execute_client_side_configuration_scripts "config"
|
2008-01-11 00:19:03 +00:00
|
|
|
}
|
|
|
|
|
2010-04-21 14:56:20 +00:00
|
|
|
# Section 18.1.8. (Receipt of Reply Messages) of RFC 3315 says:
|
|
|
|
# The client SHOULD perform duplicate address detection on each of
|
|
|
|
# the addresses in any IAs it receives in the Reply message before
|
|
|
|
# using that address for traffic.
|
|
|
|
add_ipv6_addr_with_DAD() {
|
2010-02-19 11:37:25 +00:00
|
|
|
ip -6 addr add ${new_ip6_address}/${new_ip6_prefixlen} \
|
2009-09-19 06:22:33 +00:00
|
|
|
dev ${interface} scope global
|
2010-03-24 11:06:45 +00:00
|
|
|
|
|
|
|
# repeatedly test whether newly added address passed
|
|
|
|
# duplicate address detection (DAD)
|
|
|
|
for i in $(seq 5); do
|
|
|
|
sleep 1 # give the DAD some time
|
|
|
|
|
2012-01-04 17:10:42 +00:00
|
|
|
# tentative flag == DAD is still not complete
|
|
|
|
tentative=$(ip -6 addr show dev ${interface} tentative \
|
|
|
|
| grep ${new_ip6_address}/${new_ip6_prefixlen})
|
|
|
|
# dadfailed flag == address is already in use somewhere else
|
|
|
|
dadfailed=$(ip -6 addr show dev ${interface} dadfailed \
|
|
|
|
| grep ${new_ip6_address}/${new_ip6_prefixlen})
|
|
|
|
|
|
|
|
if [ -n "${dadfailed}" ] ; then
|
|
|
|
#ip -6 addr del ${new_ip6_address}/${new_ip6_prefixlen} dev ${interface}
|
|
|
|
exit_with_hooks 3
|
|
|
|
fi
|
|
|
|
if [ -z "${tentative}" ] ; then
|
|
|
|
# DAD is over
|
|
|
|
return 0
|
2010-03-24 11:06:45 +00:00
|
|
|
fi
|
|
|
|
done
|
2010-04-21 14:56:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dh6config() {
|
2010-12-23 14:50:49 +00:00
|
|
|
if [ -n "${old_ip6_prefix}" ] ||
|
|
|
|
[ -n "${new_ip6_prefix}" ]; then
|
2010-11-09 16:00:03 +00:00
|
|
|
echo Prefix ${reason} old=${old_ip6_prefix} new=${new_ip6_prefix}
|
|
|
|
exit_with_hooks 0
|
|
|
|
fi
|
|
|
|
|
2010-04-21 14:56:20 +00:00
|
|
|
case "${reason}" in
|
|
|
|
BOUND6)
|
2010-10-13 10:07:16 +00:00
|
|
|
if [ -z "${new_ip6_address}" ] ||
|
2010-04-21 14:56:20 +00:00
|
|
|
[ -z "${new_ip6_prefixlen}" ]; then
|
|
|
|
exit_with_hooks 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
add_ipv6_addr_with_DAD
|
2010-03-24 11:06:45 +00:00
|
|
|
|
2009-09-19 06:22:33 +00:00
|
|
|
make_resolv_conf
|
|
|
|
;;
|
|
|
|
|
|
|
|
RENEW6|REBIND6)
|
2010-10-13 10:07:16 +00:00
|
|
|
if [ -z "${new_ip6_address}" ] ||
|
|
|
|
[ -z "${new_ip6_prefixlen}" ]; then
|
|
|
|
exit_with_hooks 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! "${new_ip6_address}" = "${old_ip6_address}" ]; then
|
2010-04-21 14:56:20 +00:00
|
|
|
add_ipv6_addr_with_DAD
|
|
|
|
fi
|
|
|
|
|
2009-09-19 06:22:33 +00:00
|
|
|
if [ ! "${new_dhcp6_name_servers}" = "${old_dhcp6_name_servers}" ] ||
|
|
|
|
[ ! "${new_dhcp6_domain_search}" = "${old_dhcp6_domain_search}" ]; then
|
|
|
|
make_resolv_conf
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
|
|
|
|
DEPREF6)
|
2009-10-30 09:51:58 +00:00
|
|
|
if [ -z "${new_ip6_prefixlen}" ]; then
|
2009-09-19 06:22:33 +00:00
|
|
|
exit_with_hooks 2
|
|
|
|
fi
|
|
|
|
|
2010-02-19 11:37:25 +00:00
|
|
|
ip -6 addr change ${new_ip6_address}/${new_ip6_prefixlen} \
|
2009-09-19 06:22:33 +00:00
|
|
|
dev ${interface} scope global preferred_lft 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2011-01-28 14:42:01 +00:00
|
|
|
execute_client_side_configuration_scripts "config"
|
2009-09-19 06:22:33 +00:00
|
|
|
}
|
|
|
|
|
2008-01-11 00:19:03 +00:00
|
|
|
|
2008-08-22 21:05:05 +00:00
|
|
|
#
|
|
|
|
# ### MAIN
|
|
|
|
#
|
2008-01-11 00:19:03 +00:00
|
|
|
|
2009-04-13 22:22:38 +00:00
|
|
|
if [ -x ${ETCDIR}/dhclient-enter-hooks ]; then
|
2008-08-22 21:05:05 +00:00
|
|
|
exit_status=0
|
|
|
|
|
|
|
|
# dhclient-enter-hooks can abort dhclient-script by setting
|
|
|
|
# the exit_status variable to a non-zero value
|
2009-04-13 22:22:38 +00:00
|
|
|
. ${ETCDIR}/dhclient-enter-hooks
|
2008-08-22 21:05:05 +00:00
|
|
|
if [ ${exit_status} -ne 0 ]; then
|
|
|
|
exit ${exit_status}
|
|
|
|
fi
|
2008-08-23 21:05:07 +00:00
|
|
|
fi
|
2008-08-22 21:05:05 +00:00
|
|
|
|
|
|
|
if [ ! -r /etc/sysconfig/network-scripts/network-functions ]; then
|
|
|
|
echo "Missing /etc/sysconfig/network-scripts/network-functions, exiting." >&2
|
|
|
|
exit 1
|
2008-01-11 00:19:03 +00:00
|
|
|
fi
|
|
|
|
|
2008-08-22 21:05:05 +00:00
|
|
|
if [ ! -r /etc/rc.d/init.d/functions ]; then
|
|
|
|
echo "Missing /etc/rc.d/init.d/functions, exiting." >&2
|
|
|
|
exit 1
|
2008-01-11 00:19:03 +00:00
|
|
|
fi
|
|
|
|
|
2008-08-22 21:05:05 +00:00
|
|
|
. /etc/sysconfig/network-scripts/network-functions
|
|
|
|
. /etc/rc.d/init.d/functions
|
|
|
|
|
|
|
|
if [ -f /etc/sysconfig/network ]; then
|
|
|
|
. /etc/sysconfig/network
|
2008-01-11 00:19:03 +00:00
|
|
|
fi
|
|
|
|
|
2008-08-22 21:05:05 +00:00
|
|
|
if [ -f /etc/sysconfig/networking/network ]; then
|
|
|
|
. /etc/sysconfig/networking/network
|
2008-01-11 00:19:03 +00:00
|
|
|
fi
|
|
|
|
|
2009-04-21 20:41:30 +00:00
|
|
|
cd /etc/sysconfig/network-scripts
|
2012-08-20 10:27:52 +00:00
|
|
|
CONFIG="${interface}"
|
2008-08-22 21:05:05 +00:00
|
|
|
need_config ${CONFIG}
|
2008-12-04 22:08:05 +00:00
|
|
|
source_config >/dev/null 2>&1
|
2008-01-11 00:19:03 +00:00
|
|
|
|
2008-12-04 22:08:05 +00:00
|
|
|
new_prefix="$(get_prefix ${new_ip_address} ${new_subnet_mask})"
|
2010-02-19 11:37:25 +00:00
|
|
|
old_prefix="$(get_prefix ${old_ip_address} ${old_subnet_mask})"
|
2008-12-04 22:08:05 +00:00
|
|
|
alias_prefix="$(get_prefix ${alias_ip_address} ${alias_subnet_mask})"
|
2008-01-11 00:19:03 +00:00
|
|
|
|
2008-08-22 21:05:05 +00:00
|
|
|
case "${reason}" in
|
2011-11-11 13:00:38 +00:00
|
|
|
MEDIUM|ARPCHECK|ARPSEND)
|
|
|
|
# Do nothing
|
2008-08-22 21:05:05 +00:00
|
|
|
exit_with_hooks 0
|
|
|
|
;;
|
|
|
|
|
|
|
|
PREINIT)
|
|
|
|
if [ -n "${alias_ip_address}" ]; then
|
2011-09-29 12:18:16 +00:00
|
|
|
# Flush alias, its routes will disappear too.
|
|
|
|
ip -4 addr flush dev ${interface} label ${interface}:0 >/dev/null 2>&1
|
2008-02-08 02:15:14 +00:00
|
|
|
fi
|
2008-01-11 00:19:03 +00:00
|
|
|
|
2012-04-27 10:33:53 +00:00
|
|
|
# upstream dhclient-script removes (ifconfig $interface 0 up) old adresses in PREINIT,
|
|
|
|
# but we sometimes (#125298) need (for iSCSI/nfs root to have a dhcp interface) to keep the existing ip
|
|
|
|
# flush_dev ${interface}
|
2012-04-26 12:45:26 +00:00
|
|
|
ip link set dev ${interface} up
|
2008-08-22 21:05:05 +00:00
|
|
|
if [ -n "${DHCLIENT_DELAY}" ] && [ ${DHCLIENT_DELAY} -gt 0 ]; then
|
2012-04-26 12:45:26 +00:00
|
|
|
# We need to give the kernel some time to get the interface up.
|
2008-08-22 21:05:05 +00:00
|
|
|
sleep ${DHCLIENT_DELAY}
|
2008-02-08 02:15:14 +00:00
|
|
|
fi
|
2008-01-11 00:19:03 +00:00
|
|
|
|
2008-08-22 21:05:05 +00:00
|
|
|
exit_with_hooks 0
|
|
|
|
;;
|
2008-01-11 00:19:03 +00:00
|
|
|
|
2009-09-19 06:22:33 +00:00
|
|
|
PREINIT6)
|
|
|
|
# ensure interface is up
|
2012-04-26 12:45:26 +00:00
|
|
|
ip link set dev ${interface} up
|
2009-09-19 06:22:33 +00:00
|
|
|
|
|
|
|
# remove any stale addresses from aborted clients
|
2010-02-19 11:37:25 +00:00
|
|
|
ip -6 addr flush dev ${interface} scope global permanent
|
2009-09-19 06:22:33 +00:00
|
|
|
|
|
|
|
exit_with_hooks 0
|
|
|
|
;;
|
|
|
|
|
2011-11-11 13:00:38 +00:00
|
|
|
BOUND|RENEW|REBIND|REBOOT)
|
|
|
|
if [ -z "${interface}" ] || [ -z "${new_ip_address}" ]; then
|
|
|
|
exit_with_hooks 2
|
|
|
|
fi
|
|
|
|
if arping -D -q -c2 -I ${interface} ${new_ip_address}; then
|
|
|
|
dhconfig
|
2008-08-22 21:05:05 +00:00
|
|
|
exit_with_hooks 0
|
|
|
|
else
|
2011-11-11 13:00:38 +00:00
|
|
|
# DAD failed, i.e. address is already in use
|
2008-08-22 21:05:05 +00:00
|
|
|
exit_with_hooks 1
|
2008-01-11 00:19:03 +00:00
|
|
|
fi
|
2008-08-22 21:05:05 +00:00
|
|
|
;;
|
2008-01-11 00:19:03 +00:00
|
|
|
|
2009-09-19 06:22:33 +00:00
|
|
|
BOUND6|RENEW6|REBIND6|DEPREF6)
|
|
|
|
dh6config
|
|
|
|
exit_with_hooks 0
|
|
|
|
;;
|
|
|
|
|
|
|
|
EXPIRE6|RELEASE6|STOP6)
|
2010-02-05 15:09:41 +00:00
|
|
|
if [ -z "${old_ip6_address}" ] || [ -z "${old_ip6_prefixlen}" ]; then
|
2009-09-19 06:22:33 +00:00
|
|
|
exit_with_hooks 2
|
|
|
|
fi
|
|
|
|
|
2010-02-19 11:37:25 +00:00
|
|
|
ip -6 addr del ${old_ip6_address}/${old_ip6_prefixlen} \
|
2009-09-19 06:22:33 +00:00
|
|
|
dev ${interface}
|
|
|
|
|
2011-01-28 14:42:01 +00:00
|
|
|
execute_client_side_configuration_scripts "restore"
|
2009-09-19 06:22:33 +00:00
|
|
|
|
|
|
|
if [ -x ${ETCDIR}/dhclient-${interface}-down-hooks ]; then
|
|
|
|
. ${ETCDIR}/dhclient-${interface}-down-hooks
|
|
|
|
elif [ -x ${ETCDIR}/dhclient-down-hooks ]; then
|
|
|
|
. ${ETCDIR}/dhclient-down-hooks
|
|
|
|
fi
|
|
|
|
|
|
|
|
exit_with_hooks 0
|
|
|
|
;;
|
|
|
|
|
2008-08-22 21:05:05 +00:00
|
|
|
EXPIRE|FAIL|RELEASE|STOP)
|
2011-01-28 14:42:01 +00:00
|
|
|
execute_client_side_configuration_scripts "restore"
|
2008-01-11 00:19:03 +00:00
|
|
|
|
2009-04-13 22:22:38 +00:00
|
|
|
if [ -x ${ETCDIR}/dhclient-${interface}-down-hooks ]; then
|
|
|
|
. ${ETCDIR}/dhclient-${interface}-down-hooks
|
|
|
|
elif [ -x ${ETCDIR}/dhclient-down-hooks ]; then
|
|
|
|
. ${ETCDIR}/dhclient-down-hooks
|
2008-08-22 21:05:05 +00:00
|
|
|
fi
|
2008-01-11 00:19:03 +00:00
|
|
|
|
2008-08-22 21:05:05 +00:00
|
|
|
if [ -n "${alias_ip_address}" ]; then
|
2011-09-29 12:18:16 +00:00
|
|
|
# Flush alias
|
|
|
|
ip -4 addr flush dev ${interface} label ${interface}:0 >/dev/null 2>&1
|
2008-08-22 21:05:05 +00:00
|
|
|
fi
|
2008-01-11 00:19:03 +00:00
|
|
|
|
2008-08-22 21:05:05 +00:00
|
|
|
if [ -n "${old_ip_address}" ]; then
|
2010-09-30 13:49:08 +00:00
|
|
|
# Delete addresses/routes/arp cache.
|
|
|
|
flush_dev ${interface}
|
2008-08-22 21:05:05 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "${alias_ip_address}" ]; then
|
2011-09-29 12:18:16 +00:00
|
|
|
ip -4 addr add ${alias_ip_address}/${alias_prefix} broadcast ${alias_broadcast_address} dev ${interface} label ${interface}:0
|
|
|
|
ip -4 route replace ${alias_ip_address}/32 dev ${interface}
|
2008-08-22 21:05:05 +00:00
|
|
|
fi
|
2008-01-11 00:19:03 +00:00
|
|
|
|
|
|
|
exit_with_hooks 0
|
2008-08-22 21:05:05 +00:00
|
|
|
;;
|
2008-01-11 00:19:03 +00:00
|
|
|
|
2008-08-22 21:05:05 +00:00
|
|
|
TIMEOUT)
|
|
|
|
if [ -n "${new_routers}" ]; then
|
|
|
|
if [ -n "${alias_ip_address}" ]; then
|
2011-09-29 12:18:16 +00:00
|
|
|
ip -4 addr flush dev ${interface} label ${interface}:0 >/dev/null 2>&1
|
2008-08-22 21:05:05 +00:00
|
|
|
fi
|
|
|
|
|
2010-02-19 11:37:25 +00:00
|
|
|
ip -4 addr add ${new_ip_address}/${new_prefix} broadcast ${new_broadcast_address} dev ${interface}
|
2008-08-22 21:05:05 +00:00
|
|
|
set ${new_routers}
|
|
|
|
|
|
|
|
if ping -q -c 1 -w 10 -I ${interface} ${1}; then
|
|
|
|
dhconfig
|
|
|
|
exit_with_hooks 0
|
|
|
|
fi
|
|
|
|
|
2010-09-30 13:49:08 +00:00
|
|
|
flush_dev ${interface}
|
2008-08-22 21:05:05 +00:00
|
|
|
exit_with_hooks 1
|
|
|
|
else
|
|
|
|
exit_with_hooks 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
logmessage "unhandled state: ${reason}"
|
|
|
|
exit_with_hooks 1
|
|
|
|
;;
|
|
|
|
esac
|
2008-01-11 00:19:03 +00:00
|
|
|
|
|
|
|
exit_with_hooks 0
|