From 817cf58581c06bb4ce35e4fa5895d14473c9718b Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Thu, 25 Oct 2018 20:25:03 +0800 Subject: [PATCH] rc.d: Introduce 'dhcp_client' to wrap over dhclient and dhcpcd The new 'dhcp_client' rc script is a wrapper to start either dhclient(8) or dhcpcd(8) based on the value of the 'dhcp_client' rc variable. Other rc scripts are updated to depend on this wrapper instead of the explicit 'dhclient'. This eases the migration from dhclient(8) to dhcpcd(8) later. Update rc.conf.5 and dhcp.8 man pages accordingly. Meanwhile, remove the two obsolete variables 'dhcp_{program,flags}' from /etc/rc.subr. --- etc/defaults/pfi.conf | 6 +++--- etc/defaults/rc.conf | 4 +++- etc/devd.conf | 8 ++++---- etc/network.subr | 4 ++-- etc/rc.d/Makefile | 2 +- etc/rc.d/dhcp_client | 36 ++++++++++++++++++++++++++++++++++++ etc/rc.d/netif | 3 +-- etc/rc.subr | 10 ++++------ share/man/man5/rc.conf.5 | 26 +++++++++++++++++--------- share/man/man8/dhcp.8 | 38 ++++++++++++++++++++++++++------------ 10 files changed, 97 insertions(+), 40 deletions(-) create mode 100644 etc/rc.d/dhcp_client diff --git a/etc/defaults/pfi.conf b/etc/defaults/pfi.conf index c43d0a82cf..1bd6ce5412 100644 --- a/etc/defaults/pfi.conf +++ b/etc/defaults/pfi.conf @@ -6,7 +6,7 @@ # changing options. The services are the base names of RCNG scripts # (i.e. without the "/etc/rc.d/" prefix.) Note that these must be # given explicitly in the same order they would normally be started -# by rcorder during RCNG (e.g. "netif dhclient sshd"); they are not +# by rcorder during RCNG (e.g. "netif dhcp_client sshd"); they are not # automatically ordered by their dependencies here. pfi_rc_actions="" @@ -87,7 +87,7 @@ pfi_shutdown_command="shutdown -h now" # and start the CGI frontend. # # ifconfig_dc0="DHCP" -# pfi_rc_actions="netif dhclient" +# pfi_rc_actions="netif dhcp_client" # pfi_frontend="cgi" # pfi_autologin="installer" # pfi_shutdown_command="shutdown -r now" @@ -99,7 +99,7 @@ pfi_shutdown_command="shutdown -h now" # ifconfig_rl0="DHCP" # pfi_sshd_permit_root_login="YES" # pfi_set_root_password="sekrit" -# pfi_rc_actions="netif dhclient sshd" +# pfi_rc_actions="netif dhcp_client sshd" # pfi_frontend="none" # pfi_autologin="installer" # pfi_shutdown_command="shutdown -r now" diff --git a/etc/defaults/rc.conf b/etc/defaults/rc.conf index 67f511dfd9..c527c605e4 100644 --- a/etc/defaults/rc.conf +++ b/etc/defaults/rc.conf @@ -33,7 +33,7 @@ sensorsd_flags="" # additional flags for sensorsd(8). hotplugd_enable="NO" # Run hotplugd to monitor devices hot plugging. hotplugd_flags="" # additional flags for hotplugd(8) pccard_ifconfig="NO" # Specialized pccard ethernet configuration (or NO). -pccard_ether_delay="5" # Delay before trying to start dhclient in pccard_ether +pccard_ether_delay="5" # Delay before trying to start DHCP client in pccard_ether removable_interfaces="" # Removable network interfaces for /etc/pccard_ether. local_startup="/usr/local/etc/rc.d /usr/pkg/etc/rc.d" # startup script dirs. @@ -56,6 +56,8 @@ devfs_config_files="/etc/defaults/devfs.conf /etc/devfs.conf" # hostname="" # Set this! nisdomainname="NO" # Set to NIS domain if using NIS (or NO). +dhcp_client="dhclient" # Name of the rc script that is called to start + # the DHCP client, e.g., "dhcpcd" or "dhclient" dhcpcd_enable="NO" # Set to YES to run dhcpcd in master mode. dhcpcd_program="/sbin/dhcpcd" dhcpcd_flags="" diff --git a/etc/devd.conf b/etc/devd.conf index beac1e018a..b83ed2463d 100644 --- a/etc/devd.conf +++ b/etc/devd.conf @@ -47,16 +47,16 @@ options { #}; # -# Try to start dhclient on Ethernet-like interfaces when the link comes +# Try to start DHCP client on Ethernet-like interfaces when the link comes # up. Only devices that are configured to support DHCP will actually -# run it. No link down rule exists because dhclient automatically exits +# run it. No link down rule exists because DHCP client automatically exits # when the link goes down. # #notify 0 { # match "system" "IFNET"; # match "type" "LINK_UP"; # media-type "ethernet"; -# action "/etc/rc.d/dhclient quietstart $subsystem"; +# action "/etc/rc.d/dhcp_client quietstart $subsystem"; #}; # @@ -75,7 +75,7 @@ options { # match "system" "IFNET"; # match "type" "LINK_UP"; # media-type "802.11"; -# action "/etc/rc.d/dhclient quietstart $subsystem"; +# action "/etc/rc.d/dhcp_client quietstart $subsystem"; #}; # An entry like this might be in a different file, but is included here diff --git a/etc/network.subr b/etc/network.subr index 5aa3cfb509..0e0bf55d0e 100644 --- a/etc/network.subr +++ b/etc/network.subr @@ -53,7 +53,7 @@ ifconfig_up() fi if dhcpif $1; then - /etc/rc.d/dhclient start $1 + /etc/rc.d/dhcp_client start $1 _cfg=0 fi @@ -93,7 +93,7 @@ ifconfig_down() fi if dhcpif $1; then - /etc/rc.d/dhclient stop $1 + /etc/rc.d/dhcp_client stop $1 _cfg=0 fi diff --git a/etc/rc.d/Makefile b/etc/rc.d/Makefile index 03c785675d..0ef98f547f 100644 --- a/etc/rc.d/Makefile +++ b/etc/rc.d/Makefile @@ -9,7 +9,7 @@ FILES= DAEMON LOGIN NETWORKING SERVERS \ accounting addswap adjkerntz automount automountd autounmountd \ bootconf bootparams btconfig bthcid ccd cleanvar cryptdisks \ cleartmp cron cryptdisks \ - devd devfs dhclient dhcpcd diskless dmesg dntpd dumpon \ + devd devfs dhclient dhcp_client dhcpcd diskless dmesg dntpd dumpon \ fixbootfile fsck ftpd hostname hotplugd \ inetd initdiskless initrandom ip6addrctl ip6fw ipfw ipfw3 \ jail keyserv \ diff --git a/etc/rc.d/dhcp_client b/etc/rc.d/dhcp_client new file mode 100644 index 0000000000..10fcade3c3 --- /dev/null +++ b/etc/rc.d/dhcp_client @@ -0,0 +1,36 @@ +#!/bin/sh + +# PROVIDE: dhcp_client +# REQUIRE: mountcritlocal +# KEYWORD: nojail nostart + +. /etc/rc.subr + +name="dhcp_client" + +load_rc_config ${name} +dummy_rc_command "$1" + +find_client() +{ + [ -x "${dhcp_client}" ] && { + echo -n "${dhcp_client}" + return + } + + for dir in /etc/rc.d ${local_startup}; do + [ -x "${dir}/${dhcp_client}" ] && { + echo -n "${dir}/${dhcp_client}" + return + } + done +} + +command=$(find_client) +debug "found client program: ${command}" +if [ -n "${command}" ]; then + ${command} "$@" +else + echo "ERROR: cannot find the command to start DHCP client." + exit 1 +fi diff --git a/etc/rc.d/netif b/etc/rc.d/netif index 222220ba4d..b7cc054f37 100644 --- a/etc/rc.d/netif +++ b/etc/rc.d/netif @@ -64,8 +64,7 @@ network_start() network_common ifn_start verbose # Give our interfaces a little time to come up - # before we start pounding them. In particular, dhclient - # and named can get mightily confused. + # before we start pounding them, e.g., DHCP client. sleep 2 } diff --git a/etc/rc.subr b/etc/rc.subr index 2bb5557801..18a564ae4b 100644 --- a/etc/rc.subr +++ b/etc/rc.subr @@ -1287,12 +1287,10 @@ load_rc_config() # XXX - Deprecated variable name support # - [ -n "$portmap_enable" ] && rpcbind_enable="$portmap_enable" - [ -n "$portmap_program" ] && rpcbind_program="$portmap_program" - [ -n "$portmap_flags" ] && rpcbind_flags="$portmap_flags" - [ -n "$single_mountd_enable" ] && mountd_enable="$single_mountd_enable" - [ -n "$dhcp_program" ] && dhclient_program="$dhcp_program" - [ -n "$dhcp_flags" ] && dhclient_flags="$dhcp_flags" + [ -n "$portmap_enable" ] && rpcbind_enable="$portmap_enable" + [ -n "$portmap_program" ] && rpcbind_program="$portmap_program" + [ -n "$portmap_flags" ] && rpcbind_flags="$portmap_flags" + [ -n "$single_mountd_enable" ] && mountd_enable="$single_mountd_enable" } diff --git a/share/man/man5/rc.conf.5 b/share/man/man5/rc.conf.5 index e0c3cc1671..916d0cbac6 100644 --- a/share/man/man5/rc.conf.5 +++ b/share/man/man5/rc.conf.5 @@ -240,12 +240,14 @@ for a fixed address or for a DHCP client). .It Va pccard_ether_delay .Pq Vt str -Set the delay before starting -.Xr dhclient 8 +Set the delay before starting the DHCP client (configured with +.Va dhcp_client ) in the .Pa /etc/pccard_ether script. -This defaults to 5 seconds to work around a bug in the +This defaults to +.Dq Li 5 +seconds to work around a bug in the .Xr ed 4 driver which can lead to system hangs when using some newer .Xr ed 4 @@ -269,9 +271,7 @@ containing spaces. The fully qualified domain name (FQDN) of this host on the network. This should almost certainly be set to something meaningful, even if there is no network connection. -If -.Xr dhclient 8 -is used to set the hostname via DHCP, +If DHCP is used to set the hostname, this variable should be set to an empty string. .It Va ipv6_enable .Pq Vt bool @@ -283,10 +283,18 @@ Note that this requires that the kernel have been compiled with The NIS domain name of this host, or .Dq Li NO if NIS is not used. +.It Va dhcp_client +.Pq Vt str +Set the rc script that is called to start the DHCP client. +This can be set to +.Dq Li dhclient +(default) or +.Dq Li dhcpcd . .It Va dhclient_program .Pq Vt str -Path to the DHCP client program -(default +Path to the +.Xr dhclient 8 +program (default .Pa /sbin/dhclient ) . .It Va dhclient_flags .Pq Vt str @@ -870,7 +878,7 @@ This variable is to enable configuring the default address selection policy tabl .Pq RFC 3484 . The default value is .Dq Li YES , -and the table policy is specified by the +and the policy table to be installed is specified by the .Va ip6addrctl_policy variable below. .It Va ip6addrctl_policy diff --git a/share/man/man8/dhcp.8 b/share/man/man8/dhcp.8 index 63d37e168f..89aad833e7 100644 --- a/share/man/man8/dhcp.8 +++ b/share/man/man8/dhcp.8 @@ -25,7 +25,7 @@ .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd October 15, 2008 +.Dd October 25, 2018 .Dt DHCP 8 .Os .Sh NAME @@ -59,17 +59,25 @@ for more information on the format of this file. .Pp The .Pa /etc/network.subr -script reads each of these variables at boot-time and runs the +script reads each of these variables at boot-time and runs the DHCP client, +e.g., .Xr dhclient 8 -program for each interface that is to be configured via DHCP. +or +.Xr dhcpcd 8 , +for each interface that is to be configured via DHCP. .It [Optional] To tweak settings, edit -.Pa /etc/dhclient.conf . -This file is shipped with the system. +.Pa /etc/dhclient.conf +(if +.Cm dhcp_client="dhclient" ) +or +.Pa /etc/dhcpcd.conf +(if +.Cm dhcp_client="dhcpcd" ) . See .Xr dhclient.conf 5 and -.Xr dhclient 8 +.Xr dhcpcd.conf 5 for details. .El .Pp @@ -119,19 +127,25 @@ for information on other available options. Note, however, that most of the flags are useful only for debugging purposes. .Sh FILES .Bl -tag -width /usr/local/etc/dhcpd.conf -.It Pa /usr/local/etc/dhcp/dhcpd.conf -DHCP server configuration file .It Pa /etc/rc.conf configuration file where DHCP client configuration is set for individual interfaces and .Cm dhcpd_flags must be set .It Pa /etc/dhclient.conf -DHCP client configuration file +DHCP client configuration file for +.Xr dhclient 8 +.It Pa /etc/dhcpcd.conf +DHCP client configuration file for +.Xr dhcpcd 8 +.It Pa /usr/local/etc/dhcp/dhcpd.conf +DHCP server configuration file .El .Sh SEE ALSO .Xr dhclient.conf 5 , -.Xr dhcpd.conf 5 Pq Pa net/isc-dhcp42-server , +.Xr dhcpcd.conf 5 , +.Xr dhcpd.conf 5 Pq Pa net/isc-dhcp44-server , .Xr dhclient 8 , -.Xr dhcpd 8 Pq Pa net/isc-dhcp42-server , -.Xr dhcrelay 8 Pq Pa net/isc-dhcp42-relay +.Xr dhcpcd 8 , +.Xr dhcpd 8 Pq Pa net/isc-dhcp44-server , +.Xr dhcrelay 8 Pq Pa net/isc-dhcp44-relay -- 2.41.0