HardenedBSD/libexec/rc/rc.d/dhclient
Isaac Cilia Attard 503adcdf1d dhclient: rc.conf option to disable ARP resolution
Introduce a new rc.conf option to not wait for ARP resolution within
dhclient. This is plausible on many modern networks where it is possible
to trust the DHCP server to know whether an IP address is available.

Sponsored by:	Google LLC (GSoC 2024)
Signed-off-by:	Isaac Cilia Attard <icattard@FreeBSD.org>
MFC after:	10 days
Reviwed by:	cperciva, brooks, Tom Hukins, Alexander Ziaee
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1368
2024-08-09 14:49:51 -07:00

77 lines
1.6 KiB
Bash
Executable File

#!/bin/sh
#
#
# PROVIDE: dhclient
# KEYWORD: nojailvnet nostart
. /etc/rc.subr
. /etc/network.subr
ifn="$2"
name="dhclient"
desc="Dynamic Host Configuration Protocol (DHCP) client"
rcvar=
pidfile="/var/run/dhclient/${name}.${ifn}.pid"
start_precmd="dhclient_prestart"
stop_precmd="dhclient_pre_check"
# rc_force check can only be done at the run_rc_command
# time, so we're testing it in the pre* hooks.
dhclient_pre_check()
{
if [ -z "${rc_force}" ] && ! dhcpif $ifn; then
local msg
msg="'$ifn' is not a DHCP-enabled interface"
if [ -z "${rc_quiet}" ]; then
echo "$msg"
else
debug "$msg"
fi
exit 1
fi
}
dhclient_prestart()
{
dhclient_pre_check
# Interface-specific flags (see rc.subr for $flags setting)
specific=$(get_if_var $ifn dhclient_flags_IF)
if [ -z "$flags" -a -n "$specific" ]; then
rc_flags=$specific
fi
background_dhclient=$(get_if_var $ifn background_dhclient_IF $background_dhclient)
if checkyesno background_dhclient; then
rc_flags="${rc_flags} -b"
fi
dhclient_arpwait=$(get_if_var $ifn dhclient_arpwait_IF $dhclient_arpwait)
if ! checkyesno dhclient_arpwait; then
rc_flags="${rc_flags} -n"
fi
# /var/run/dhclient is not guaranteed to exist,
# e.g. if /var/run is a tmpfs
install -d -o root -g wheel -m 755 ${pidfile%/*}
rc_flags="${rc_flags} ${ifn}"
}
load_rc_config $name
load_rc_config network
# dhclient_prestart is not compatible with svcj
dhclient_svcj="NO"
if [ -z $ifn ] ; then
# only complain if a command was specified but no interface
if [ -n "$1" ] ; then
err 1 "$0: no interface specified"
fi
fi
run_rc_command "$1"