xref: /freebsd/libexec/rc/rc.d/dhclient (revision cfd6422a5217410fbd66f7a7a8a64d9d85e61229)
1#!/bin/sh
2#
3# $FreeBSD$
4#
5
6# PROVIDE: dhclient
7# KEYWORD: nojailvnet nostart
8
9. /etc/rc.subr
10. /etc/network.subr
11
12ifn="$2"
13
14name="dhclient"
15desc="Dynamic Host Configuration Protocol (DHCP) client"
16rcvar=
17pidfile="/var/run/dhclient/${name}.${ifn}.pid"
18start_precmd="dhclient_prestart"
19stop_precmd="dhclient_pre_check"
20
21# rc_force check can only be done at the run_rc_command
22# time, so we're testing it in the pre* hooks.
23dhclient_pre_check()
24{
25	if [ -z "${rc_force}" ] && ! dhcpif $ifn; then
26		local msg
27		msg="'$ifn' is not a DHCP-enabled interface"
28		if [ -z "${rc_quiet}" ]; then
29			echo "$msg"
30		else
31			debug "$msg"
32		fi
33		exit 1
34	fi
35}
36
37dhclient_prestart()
38{
39	dhclient_pre_check
40
41	# Interface-specific flags (see rc.subr for $flags setting)
42	specific=$(get_if_var $ifn dhclient_flags_IF)
43	if [ -z "$flags" -a -n "$specific" ]; then
44		rc_flags=$specific
45	fi
46
47	background_dhclient=$(get_if_var $ifn background_dhclient_IF $background_dhclient)
48	if checkyesno background_dhclient; then
49		rc_flags="${rc_flags} -b"
50	fi
51
52	rc_flags="${rc_flags} ${ifn}"
53}
54
55load_rc_config $name
56load_rc_config network
57
58if [ -z $ifn ] ; then
59	# only complain if a command was specified but no interface
60	if [ -n "$1" ] ; then
61		err 1 "$0: no interface specified"
62	fi
63fi
64
65run_rc_command "$1"
66