xref: /freebsd/libexec/rc/rc.d/dhclient (revision 503adcdf1db35eab0f3d35392947a6da3bd19539)
10696600cSBjoern A. Zeeb#!/bin/sh
20696600cSBjoern A. Zeeb#
30696600cSBjoern A. Zeeb#
40696600cSBjoern A. Zeeb
50696600cSBjoern A. Zeeb# PROVIDE: dhclient
60696600cSBjoern A. Zeeb# KEYWORD: nojailvnet nostart
70696600cSBjoern A. Zeeb
80696600cSBjoern A. Zeeb. /etc/rc.subr
90696600cSBjoern A. Zeeb. /etc/network.subr
100696600cSBjoern A. Zeeb
110696600cSBjoern A. Zeebifn="$2"
120696600cSBjoern A. Zeeb
130696600cSBjoern A. Zeebname="dhclient"
140696600cSBjoern A. Zeebdesc="Dynamic Host Configuration Protocol (DHCP) client"
150696600cSBjoern A. Zeebrcvar=
160696600cSBjoern A. Zeebpidfile="/var/run/dhclient/${name}.${ifn}.pid"
170696600cSBjoern A. Zeebstart_precmd="dhclient_prestart"
180696600cSBjoern A. Zeebstop_precmd="dhclient_pre_check"
190696600cSBjoern A. Zeeb
200696600cSBjoern A. Zeeb# rc_force check can only be done at the run_rc_command
210696600cSBjoern A. Zeeb# time, so we're testing it in the pre* hooks.
220696600cSBjoern A. Zeebdhclient_pre_check()
230696600cSBjoern A. Zeeb{
240696600cSBjoern A. Zeeb	if [ -z "${rc_force}" ] && ! dhcpif $ifn; then
250696600cSBjoern A. Zeeb		local msg
260696600cSBjoern A. Zeeb		msg="'$ifn' is not a DHCP-enabled interface"
270696600cSBjoern A. Zeeb		if [ -z "${rc_quiet}" ]; then
280696600cSBjoern A. Zeeb			echo "$msg"
290696600cSBjoern A. Zeeb		else
300696600cSBjoern A. Zeeb			debug "$msg"
310696600cSBjoern A. Zeeb		fi
320696600cSBjoern A. Zeeb		exit 1
330696600cSBjoern A. Zeeb	fi
340696600cSBjoern A. Zeeb}
350696600cSBjoern A. Zeeb
360696600cSBjoern A. Zeebdhclient_prestart()
370696600cSBjoern A. Zeeb{
380696600cSBjoern A. Zeeb	dhclient_pre_check
390696600cSBjoern A. Zeeb
400696600cSBjoern A. Zeeb	# Interface-specific flags (see rc.subr for $flags setting)
410696600cSBjoern A. Zeeb	specific=$(get_if_var $ifn dhclient_flags_IF)
420696600cSBjoern A. Zeeb	if [ -z "$flags" -a -n "$specific" ]; then
430696600cSBjoern A. Zeeb		rc_flags=$specific
440696600cSBjoern A. Zeeb	fi
450696600cSBjoern A. Zeeb
460696600cSBjoern A. Zeeb	background_dhclient=$(get_if_var $ifn background_dhclient_IF $background_dhclient)
470696600cSBjoern A. Zeeb	if checkyesno background_dhclient; then
480696600cSBjoern A. Zeeb		rc_flags="${rc_flags} -b"
490696600cSBjoern A. Zeeb	fi
500696600cSBjoern A. Zeeb
51*503adcdfSIsaac Cilia Attard	dhclient_arpwait=$(get_if_var $ifn dhclient_arpwait_IF $dhclient_arpwait)
52*503adcdfSIsaac Cilia Attard	if ! checkyesno dhclient_arpwait; then
53*503adcdfSIsaac Cilia Attard		rc_flags="${rc_flags} -n"
54*503adcdfSIsaac Cilia Attard	fi
55d27999e5SChris Rees
56d27999e5SChris Rees	# /var/run/dhclient is not guaranteed to exist,
57d27999e5SChris Rees	# e.g. if /var/run is a tmpfs
58d27999e5SChris Rees	install -d -o root -g wheel -m 755 ${pidfile%/*}
59d27999e5SChris Rees
600696600cSBjoern A. Zeeb	rc_flags="${rc_flags} ${ifn}"
610696600cSBjoern A. Zeeb}
620696600cSBjoern A. Zeeb
630696600cSBjoern A. Zeebload_rc_config $name
640696600cSBjoern A. Zeebload_rc_config network
650696600cSBjoern A. Zeeb
66f99f0ee1SAlexander Leidinger# dhclient_prestart is not compatible with svcj
67f99f0ee1SAlexander Leidingerdhclient_svcj="NO"
68f99f0ee1SAlexander Leidinger
690696600cSBjoern A. Zeebif [ -z $ifn ] ; then
700696600cSBjoern A. Zeeb	# only complain if a command was specified but no interface
710696600cSBjoern A. Zeeb	if [ -n "$1" ] ; then
720696600cSBjoern A. Zeeb		err 1 "$0: no interface specified"
730696600cSBjoern A. Zeeb	fi
740696600cSBjoern A. Zeebfi
750696600cSBjoern A. Zeeb
760696600cSBjoern A. Zeebrun_rc_command "$1"
77