You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

187 lines
5.7 KiB

#!/bin/sh
set -e
# reduced dhclient-script for the Debian installer
# dhclient-script for Linux. Dan Halbert, March, 1997.
# Updated for Linux 2.[12] by Brian J. Murrell, January 1999.
# Modified for Debian. Matt Zimmerman and Eloy Paris, December 2003
# The alias handling in here probably still sucks. -mdz
make_resolv_conf() {
if [ -n "$new_domain_name" -a -n "$new_domain_name_servers" ]; then
local new_resolv_conf=/etc/resolv.conf.dhclient-new
rm -f $new_resolv_conf
if [ -n "$new_domain_name" ]; then
echo search $new_domain_name >>$new_resolv_conf
fi
for nameserver in $new_domain_name_servers; do
echo nameserver $nameserver >>$new_resolv_conf
done
mv $new_resolv_conf /etc/resolv.conf
fi
}
set_hostname() {
local current_hostname=$(cat /proc/sys/kernel/hostname)
if [ -z "$current_hostname" -o "$current_hostname" = "(none)" ]; then
echo "$new_host_name" > /proc/sys/kernel/hostname
fi
}
release=$(uname -r)
relminor=$(expr $release : '[0-9]*\.[0-9]*\.\([0-9]*\).*')
relmajor=$(expr $release : '[0-9]*\.\([0-9]*\)\..*')
release=$(expr $release : '\([0-9]*\)\..*')
if [ -n "$new_broadcast_address" ]; then
new_broadcast_arg="broadcast $new_broadcast_address"
fi
if [ -n "$old_broadcast_address" ]; then
old_broadcast_arg="broadcast $old_broadcast_address"
fi
if [ -n "$new_subnet_mask" ]; then
new_subnet_arg="netmask $new_subnet_mask"
fi
if [ -n "$old_subnet_mask" ]; then
old_subnet_arg="netmask $old_subnet_mask"
fi
if [ -n "$alias_subnet_mask" ]; then
alias_subnet_arg="netmask $alias_subnet_mask"
fi
if [ -n "$new_interface_mtu" ]; then
mtu_arg="mtu $new_interface_mtu"
fi
# Execute the operation
case "$reason" in
MEDIUM|ARPCHECK|ARPSEND)
# Do nothing
;;
PREINIT)
# The DHCP client is requesting that an interface be
# configured as required in order to send packets prior to
# receiving an actual address. - dhclient-script(8)
if [ -n "$alias_ip_address" ]; then
# Bring down alias interface. Its routes will disappear too.
ifconfig $interface:0- inet 0
fi
if [ $relmajor -lt 2 ] || ( [ $relmajor -eq 2 ] && [ $relminor -eq 0 ] ); then
# Older Linux needs this hackery
ifconfig $interface inet 0.0.0.0 netmask 0.0.0.0 \
broadcast 255.255.255.255 up
route add default dev $interface netmask 0.0.0.0
else
# Newer Linux doesn't
ifconfig $interface 0 up
fi
# We need to give the kernel some time to get the interface up.
sleep 1
;;
BOUND|RENEW|REBIND|REBOOT)
set_hostname
if [ -n "$old_ip_address" -a -n "$alias_ip_address" -a \
"$alias_ip_address" != "$old_ip_address" ]; then
# Possible new alias. Remove old alias.
ifconfig $interface:0- inet 0
fi
if [ -n "$old_ip_address" -a \
"$old_ip_address" != "$new_ip_address" ]; then
# IP address changed. Bringing down the interface will delete all routes,
# and clear the ARP cache.
ifconfig $interface inet 0 down
fi
if [ -z "$old_ip_address" -o "$old_ip_address" != "$new_ip_address" -o \
"$reason" = "BOUND" -o "$reason" = "REBOOT" ]; then
ifconfig $interface $new_ip_address $new_subnet_arg \
$new_broadcast_arg $mtu_arg
if [ $relmajor -lt 2 ] || \
( [ $relmajor -eq 2 ] && [ $relminor -eq 0 ] ); then
# Ancient kernel: add a network route to the computed network address.
route add -net $new_network_number $new_subnet_arg dev $interface
fi
for router in $new_routers; do
route add default gw $router
done
fi
if [ "$new_ip_address" != "$alias_ip_address" -a -n "$alias_ip_address" ];
then
ifconfig $interface:0- inet 0
ifconfig $interface:0 inet $alias_ip_address $alias_subnet_arg
route add -host $alias_ip_address $interface:0
fi
make_resolv_conf
;;
EXPIRE|FAIL|RELEASE|STOP)
if [ -n "$alias_ip_address" ]; then
# Turn off alias interface.
ifconfig $interface:0- inet 0
fi
if [ -n "$old_ip_address" ]; then
# Shut down interface, which will delete routes and clear arp cache.
ifconfig $interface inet 0 down
fi
if [ -n "$alias_ip_address" ]; then
ifconfig $interface:0 inet $alias_ip_address $alias_subnet_arg
route add -host $alias_ip_address $interface:0
fi
;;
TIMEOUT)
if [ -n "$alias_ip_address" ]; then
ifconfig $interface:0- inet 0
fi
ifconfig $interface inet $new_ip_address $new_subnet_arg \
$new_broadcast_arg $mtu_arg
set -- $new_routers
first_router="$1"
if ping -q -c 1 $first_router; then
if [ "$new_ip_address" != "$alias_ip_address" -a \
-n "$alias_ip_address" ]; then
ifconfig $interface:0 inet $alias_ip_address $alias_subnet_arg
route add -host $alias_ip_address dev $interface:0
fi
if [ $relmajor -lt 2 ] || \
( [ $relmajor -eq 2 ] && [ $relminor -eq 0 ] ); then
route add -net $new_network_number
fi
for router in $new_routers; do
route add default gw $router
done
make_resolv_conf
else
# Changed from 'ifconfig $interface inet 0 down' - see Debian bug #144666
ifconfig $interface inet 0
exit 2
fi
;;
esac
exit 0