SHA256
1
0
forked from pool/dhcp
dhcp/dhcp-3.1.2-dhclient-script.dif

388 lines
14 KiB
Plaintext
Raw Normal View History

--- client/dhclient-script.8
+++ client/dhclient-script.8 2009/05/04 09:54:05
@@ -45,9 +45,10 @@
This script is not meant to be customized by the end user. If local
customizations are needed, they should be possible using the enter and
exit hooks provided (see HOOKS for details). These hooks will allow the
-user to override the default behaviour of the client in creating a
+user to override the default behaviour of the client in applying of
+additional settings like DNS (e.g. creating a
.B /etc/resolv.conf
-file.
+file), NTP or YP to the system.
.PP
No standard client script exists for some operating systems, even though
the actual client may work, so a pioneering user may well need to create
@@ -59,12 +60,43 @@
.B ETCDIR/dhclient.conf
or using the enter and exit hooks, please submit a bug report.
.SH HOOKS
-When it starts, the client script first defines a shell function,
-.B make_resolv_conf ,
-which is later used to create the
+When it starts, the client script first defines several shell functions:
+.BR use_netconfig ,
+.BR netconfig_modify ,
+.BR netconfig_remove ,
+.BR make_resolv_conf ,
+and
+.BR restore_resolv_conf .
+These functions are later used to apply DNS, NTP, YP, and other additional
+settings to the system.
+
+The
+.B use_netconfig
+returns true (0), when the /sbin/netconfig script is installed and enables
+the use of the
+.B netconfig_modify
+and
+.B netconfig_remove
+functions.
+.br
+Otherwise, the
+.BR make_resolv_conf
+and
+.BR restore_resolv_conf
+functions are used. These functions are modified to create
+/var/lib/dhcp/resolv.conf.dhclient.$interface files only
+instead of the
.B /etc/resolv.conf
-file. To override the default behaviour, redefine this function in
-the enter hook script.
+file.
+To override the default behaviour, redefine these function in the enter
+hook script. Before you start doing this, consider to implement own
+netconfig modules.
+
+.IR Note :
+Note, that since openSUSE 11.1, the modify_resolvconf script / mechanizm
+is obsoleted by netconfig and not shipped or supported any more.
+See the netconfig(8) manual page for more informations.
+
.PP
On after defining the make_resolv_conf function, the client script checks
for the presence of an executable
@@ -221,7 +253,7 @@
confusing.
.SH SEE ALSO
dhclient(8), dhcpd(8), dhcrelay(8), dhclient.conf(5) and
-dhclient.leases(5).
+dhclient.leases(5) and netconfig(8).
.SH AUTHOR
.B dhclient-script(8)
has been written for Internet Systems Consortium
--- client/scripts/linux
+++ client/scripts/linux 2009/05/04 10:01:50
@@ -22,25 +22,97 @@
# 4. TIMEOUT not tested. ping has a flag I don't know, and I'm suspicious
# of the $1 in its args.
+
+# Debugging:
+#
+# logs entire run of dhclient-script to /var/log/dhclient-script,
+# if DHCLIENT_DEBUG is set in sysconfig/network/dhcp
+#
+eval `grep "^DHCLIENT_DEBUG=" /etc/sysconfig/network/dhcp 2>/dev/null`
+if [ "$DHCLIENT_DEBUG" = yes ]; then
+ set -a # allexport
+ (
+ echo '****************'
+ echo "$0 $*"
+ date
+ echo '----------------'
+ set
+ echo '----------------'
+ ) >> /var/log/dhclient-script.log
+ exec 2>> /var/log/dhclient-script.log
+ set +a
+ set -x
+fi
+
+# netconfig makes all "additional" modifications as DNS or NTP
+use_netconfig() {
+ test -x /sbin/netconfig
+}
+netconfig_modify() {
+ if test -x /sbin/netconfig -a -n "$interface" ; then
+ {
+ echo "INTERFACE='$interface'"
+ for v in ${!new_*}; do
+ case $v in
+ (new_ip_address) k='IPADDR' ;;
+ (new_subnet_mask) k='NETMASK' ;;
+ (new_network_number) k='NETWORK' ;;
+ (new_broadcast_address) k='BROADCAST' ;;
+ (new_interface_mtu) k='MTU' ;;
+ # (new_static_routes) k='ROUTES' ;;
+ (new_routers) k='GATEWAYS' ;;
+ (new_host_name) k='HOSTNAME' ;;
+ (new_domain_name) k='DNSDOMAIN' ;;
+ (new_domain_name_servers) k='DNSSERVERS' ;;
+ (new_ntp_servers) k='NTPSERVERS' ;;
+ (new_nis_domain) k='NISDOMAIN' ;;
+ (new_nis_servers) k='NISSERVERS' ;;
+ (new_root_path) k='ROOTPATH' ;;
+ (new_dhcp_server_identifier)k='DHCPSID' ;;
+ (new_lpr_servers) k='LPRSERVER' ;;
+ (new_log_servers) k='LOGSERVER' ;;
+ (new_netbios_dd_server) k='NETBIOSDDSERVER' ;;
+ (new_netbios_name_servers) k='NETBIOSNAMESERVER' ;;
+ (new_netbios_node_type) k='NETBIOSNODETYPE' ;;
+ (new_netbios_scope) k='NETBIOSSCOPE' ;;
+ (*) k="dhclient_${v#new_}" ;;
+ esac
+ [ "k${k}" != k ] && echo "${k}='${!v}'"
+ done
+ } | /sbin/netconfig modify -s "dhclient3" -i "$interface"
+ fi
+}
+netconfig_remove() {
+ if test -x /sbin/netconfig -a -n "$interface" ; then
+ /sbin/netconfig remove -s "dhclient3" -i "$interface" </dev/null
+ fi
+}
+
make_resolv_conf() {
+ ###
+ ### note: this function is never used
+ ### it creates /var/lib/dhcp/resolv.conf.dhclient.$interface only
+ ###
if [ x"$new_domain_name_servers" != x ]; then
- cat /dev/null > /etc/resolv.conf.dhclient
- chmod 644 /etc/resolv.conf.dhclient
+ cat /dev/null > /var/lib/dhcp/resolv.conf.dhclient.$interface
+ chmod 644 /var/lib/dhcp/resolv.conf.dhclient.$interface
if [ x"$new_domain_search" != x ]; then
- echo search $new_domain_search >> /etc/resolv.conf.dhclient
+ echo search $new_domain_search >> /var/lib/dhcp/resolv.conf.dhclient.$interface
elif [ x"$new_domain_name" != x ]; then
# 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.
- echo search $new_domain_name >> /etc/resolv.conf.dhclient
+ echo search $new_domain_name >> /var/lib/dhcp/resolv.conf.dhclient.$interface
fi
for nameserver in $new_domain_name_servers; do
- echo nameserver $nameserver >>/etc/resolv.conf.dhclient
+ echo nameserver $nameserver >> /var/lib/dhcp/resolv.conf.dhclient.$interface
done
-
- mv /etc/resolv.conf.dhclient /etc/resolv.conf
fi
}
+restore_resolv_conf()
+{
+ rm -f /var/lib/dhcp/resolv.conf.dhclient.$interface
+}
# Must be used on exit. Invokes the local dhcp client exit hooks, if any.
exit_with_hooks() {
@@ -83,6 +155,10 @@
if [ x$alias_subnet_mask != x ]; then
alias_subnet_arg="netmask $alias_subnet_mask"
fi
+if [ $(($new_interface_mtu)) -lt 576 ] ; then
+ # 68 is the minimal legal value, but 576 the real life minimum
+ unset new_interface_mtu
+fi
if [ x$reason = xMEDIUM ]; then
# Linux doesn't do mediums (ok, ok, media).
@@ -97,7 +173,7 @@
if [ $relmajor -lt 2 ] || ( [ $relmajor -eq 2 ] && [ $relminor -eq 0 ] )
then
ifconfig $interface inet 0.0.0.0 netmask 0.0.0.0 \
- broadcast 255.255.255.255 up
+ broadcast 255.255.255.255 up
# Add route to make broadcast work. Do not omit netmask.
route add default dev $interface netmask 0.0.0.0
else
@@ -116,47 +192,117 @@
if [ x$reason = xBOUND ] || [ x$reason = xRENEW ] || \
[ x$reason = xREBIND ] || [ x$reason = xREBOOT ]; then
- current_hostname=`hostname`
- if [ x$current_hostname = x ] || \
- [ x$current_hostname = x$old_host_name ]; then
- if [ x$current_hostname = x ] || \
- [ x$new_host_name != x$old_host_name ]; then
- hostname $new_host_name
- fi
- fi
-
if [ x$old_ip_address != x ] && [ x$alias_ip_address != x ] && \
- [ x$alias_ip_address != x$old_ip_address ]; then
+ [ x$alias_ip_address != x$old_ip_address ]; then
# Possible new alias. Remove old alias.
ifconfig $interface:0- inet 0
fi
if [ x$old_ip_address != x ] && [ x$old_ip_address != x$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
+ ifconfig $interface inet 0
fi
if [ x$old_ip_address = x ] || [ x$old_ip_address != x$new_ip_address ] || \
[ x$reason = xBOUND ] || [ x$reason = xREBOOT ]; then
ifconfig $interface inet $new_ip_address $new_subnet_arg \
- $new_broadcast_arg
+ $new_broadcast_arg \
+ ${new_interface_mtu:+mtu "$new_interface_mtu"}
# Add a network route to the computed network address.
if [ $relmajor -lt 2 ] || \
- ( [ $relmajor -eq 2 ] && [ $relminor -eq 0 ] ); then
+ ( [ $relmajor -eq 2 ] && [ $relminor -eq 0 ] ); then
route add -net $new_network_number $new_subnet_arg dev $interface
fi
- for router in $new_routers; do
- route add default gw $router
- done
+
+ if test -f /etc/sysconfig/network/ifcfg-${interface} -o \
+ -f /dev/shm/sysconfig/if-${interface} ;
+ then
+ if grep -qs '^primary=yes' /dev/shm/sysconfig/if-${interface} 2>/dev/null ;
+ then
+ eval `grep --no-filename '^[[:space:]]*DHCLIENT_SET_DEFAULT_ROUTE=' \
+ /etc/sysconfig/network/dhcp
+ /etc/sysconfig/network/ifcfg-${interface} 2>/dev/null`
+ else
+ eval `grep --no-filename '^[[:space:]]*DHCLIENT_SET_DEFAULT_ROUTE=' \
+ /etc/sysconfig/network/ifcfg-${interface} 2>/dev/null`
+ fi
+ else
+ eval `grep --no-filename '^[[:space:]]*DHCLIENT_SET_DEFAULT_ROUTE=' \
+ /etc/sysconfig/network/dhcp 2>/dev/null`
+ fi
+ if [ "$DHCLIENT_SET_DEFAULT_ROUTE" = yes ] ; then
+ for router in $new_routers; do
+ err=`route add default gw $router 2>&1` && break || \
+ case "$err" in
+ SIOCADDRT:*)
+ # The gateway seems to be not reachable via local network
+ # route (implicitely created by ifconfig based on the IP
+ # an netmask provided by dhcp).
+ # Check this, set an explicit host route to the gateway
+ # over the current interface and try again (bnc#266215).
+ matches=$(test -x /sbin/ip && \
+ /sbin/ip -f inet -o route list match $router | \
+ grep -v ^default | grep -c -v "^$" 2>/dev/null)
+ if test -n "$matches" -a $(($matches)) -eq 0 ; then
+ route add -host $router dev $interface && \
+ route add default gw $router && break
+ fi
+ ;;
+ esac
+ done
+ fi
fi
+
if [ x$new_ip_address != x$alias_ip_address ] && [ x$alias_ip_address != x ];
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
+
+ if use_netconfig ; then
+ netconfig_modify
+ else
+ make_resolv_conf
+ fi
+
+ if test -f /etc/sysconfig/network/ifcfg-${interface} -o \
+ -f /dev/shm/sysconfig/if-${interface} ;
+ then
+ if grep -qs '^primary=yes' /dev/shm/sysconfig/if-${interface} 2>/dev/null ;
+ then
+ eval `grep --no-filename "^[[:space:]]*DHCLIENT_SET_HOSTNAME=" \
+ /etc/sysconfig/network/dhcp
+ /etc/sysconfig/network/ifcfg-${interface} 2>/dev/null`
+ else
+ eval `grep --no-filename "^[[:space:]]*DHCLIENT_SET_HOSTNAME=" \
+ /etc/sysconfig/network/ifcfg-${interface} 2>/dev/null`
+ fi
+ else
+ eval `grep --no-filename "^[[:space:]]*DHCLIENT_SET_HOSTNAME=" \
+ /etc/sysconfig/network/dhcp 2>/dev/null`
+ fi
+ if [ "$DHCLIENT_SET_HOSTNAME" = yes ] ; then
+ current_hostname=`hostname`
+ if [ "x${current_hostname%%.*}" = x ] || \
+ [ "x${current_hostname%%.*}" != "x${new_host_name%%.*}" ]; then
+
+ if [ "x${new_host_name%%.*}" != x ]; then
+ hostname "${new_host_name%%.*}"
+ else
+ if [ -x /usr/bin/host ] ; then
+ if out=`host -W 2 "$new_ip_address" 2>/dev/null` ; then
+ _hostname="`echo "$out" | sed 's:^.* ::; s:\..*::'`"
+ if [ "x${_hostname}" != x ]; then
+ hostname "${_hostname}"
+ fi
+ fi
+ fi
+ fi
+ fi
+ fi
+
exit_with_hooks 0
fi
@@ -168,7 +314,7 @@
fi
if [ x$old_ip_address != x ]; then
# Shut down interface, which will delete routes and clear arp cache.
- ifconfig $interface inet 0 down
+ ifconfig $interface inet 0
fi
if [ x$alias_ip_address != x ]; then
ifconfig $interface:0 inet $alias_ip_address $alias_subnet_arg
@@ -182,27 +328,37 @@
ifconfig $interface:0- inet 0
fi
ifconfig $interface inet $new_ip_address $new_subnet_arg \
- $new_broadcast_arg
+ $new_broadcast_arg
set $new_routers
############## what is -w in ping?
if ping -q -c 1 $1; then
if [ x$new_ip_address != x$alias_ip_address ] && \
- [ x$alias_ip_address != x ]; then
+ [ x$alias_ip_address != x ]; 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
+ ( [ $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
+ if use_netconfig ; then
+ netconfig_modify
+ else
+ make_resolv_conf
+ fi
exit_with_hooks 0
fi
- ifconfig $interface inet 0 down
+ ifconfig $interface inet 0
exit_with_hooks 1
fi
+if use_netconfig ; then
+ netconfig_remove
+else
+ restore_resolv_conf
+fi
+
exit_with_hooks 0