dhclient revision 140339
1#!/bin/sh 2# 3# $NetBSD: dhclient,v 1.8 2002/03/22 04:33:58 thorpej Exp $ 4# $FreeBSD: head/etc/rc.d/dhclient 140339 2005-01-16 03:12:03Z obrien $ 5# 6 7# PROVIDE: dhclient 8# REQUIRE: netif ipfw ipfilter mountcritlocal cleanvar 9# BEFORE: NETWORKING 10# KEYWORD: nojail 11# 12# Note that there no syslog logging of dhclient messages at boot because 13# dhclient needs to start before services that syslog depends upon do. 14# 15 16. /etc/rc.subr 17. /etc/network.subr 18 19name="dhclient" 20rcvar= 21pidfile="/var/run/${name}.pid" 22start_precmd="dhclient_prestart" 23start_postcmd="dhclient_poststart" 24stop_precmd="dhclient_prestop" 25stop_postcmd="dhclient_poststop" 26 27dhclient_common() 28{ 29 dhcp_list="`list_net_interfaces dhcp`" 30 if [ -z "$dhcp_list" ]; then 31 return 1 32 fi 33 34 # Determine the scope of the command 35 # 36 _cooked_list="$dhcp_list" 37 if [ -n "$_cmdifn" ]; then 38 eval _cooked_list=\"`expr "$dhcp_list" : ".*\($_cmdifn\).*"`\" 39 if [ -z "$_cooked_list" ]; then 40 err 1 "No such network interface: $_cmdifn" 41 fi 42 fi 43} 44 45dhclient_prestart() 46{ 47 if [ $dhclient_common_error -eq 1 ]; then 48 return 1 49 fi 50 for ifn in ${_cooked_list}; do 51 ifscript_up ${ifn} 52 done 53 54 if checkyesno background_dhclient; then 55 rc_flags="${rc_flags} -nw" 56 fi 57 58 rc_flags="${rc_flags} ${_cooked_list}" 59 return 0 60} 61 62dhclient_poststart() 63{ 64 for ifn in ${_cooked_list}; do 65 ifalias_up ${ifn} 66 ipx_up ${ifn} 67 ifconfig ${ifn} 68 done 69} 70 71dhclient_prestop() 72{ 73 if [ $dhclient_common_error -eq 1 ]; then 74 return 1 75 fi 76 for ifn in ${_cooked_list}; do 77 ipx_down ${ifn} 78 ifalias_down ${ifn} 79 done 80 echo -n "Releasing DHCP leases:" 81 for ifn in $_cooked_list ; do 82 ${command} -r $ifn 83 if [ $? -eq 0 ]; then 84 echo -n " $ifn" 85 else 86 _fail="$_fail $ifn" 87 fi 88 done 89 echo '.' 90 debug "The following leases failed to release: $_fail" 91} 92 93dhclient_poststop() 94{ 95 for ifn in ${_cooked_list}; do 96 ifscript_down ${ifn} 97 done 98} 99 100if [ -n "$2" ]; then 101 _cmdifn="$2" 102 stop_cmd=":" 103fi 104 105load_rc_config $name 106dhclient_common_error=0 107dhclient_common || dhclient_common_error=1; 108if [ -n "$_cooked_list" ]; then 109 if [ -s $pidfile ]; then 110 stop_cmd=":" 111 fi 112fi 113run_rc_command "$1" 114