dhclient revision 126392
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 126392 2004-02-29 01:42:48Z green $
5#
6
7# PROVIDE: dhclient
8# REQUIRE: network netif ipfw ipfilter mountcritlocal
9# BEFORE:  NETWORKING
10# KEYWORD: FreeBSD
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 "No such network interface: $_cmdifn"
41			return 1
42		fi
43	fi
44}
45
46dhclient_prestart()
47{
48	if [ $dhclient_common_error -eq 1 ]; then
49		return 1
50	fi
51	for ifn in ${_cooked_list}; do
52		ifscript_up ${ifn}
53	done
54
55	if checkyesno background_dhclient; then
56		rc_flags="${rc_flags} -nw"
57	fi
58
59	rc_flags="${rc_flags} ${_cooked_list}"
60	return 0
61}
62
63dhclient_poststart()
64{
65	for ifn in ${_cooked_list}; do
66		ifalias_up ${ifn}
67		ipx_up ${ifn}
68		ifconfig ${ifn}
69	done
70}
71
72dhclient_prestop()
73{
74	if [ $dhclient_common_error -eq 1 ]; then
75		return 1
76	fi
77	for ifn in ${_cooked_list}; do
78		ipx_down ${ifn}
79		ifalias_down ${ifn}
80	done
81	echo -n "Releasing DHCP leases:"
82	for ifn in $_cooked_list ; do
83		${command} -r $ifn
84		if [ $? -eq 0 ]; then
85			echo -n " $ifn"
86		else
87			_fail="$_fail $ifn"
88		fi
89	done
90	echo '.'
91	debug "The following leases failed to release: $_fail"
92}
93
94dhclient_poststop()
95{
96	for ifn in ${_cooked_list}; do
97		ifscript_down ${ifn}
98	done
99}
100
101if [ -n "$2" ]; then
102	_cmdifn="$2"
103	stop_cmd=":"
104fi
105
106load_rc_config $name
107dhclient_common_error=0
108dhclient_common || dhclient_common_error=1;
109if [ -n "$_cooked_list" ]; then
110	if [ -s $pidfile ]; then
111		stop_cmd=":"
112	fi
113fi
114run_rc_command "$1"
115