Add dhclient(8).

Co-authored-by: Juhani Krekelä <juhani@krekelä.fi>
This commit is contained in:
Jonas 'Sortie' Termansen 2023-02-17 23:31:57 +01:00
parent edc4d5ed18
commit 4379ca962a
20 changed files with 2135 additions and 3 deletions

View File

@ -11,6 +11,7 @@ libmount \
bench \
carray \
checksum \
dhclient \
disked \
dnsconfig \
editor \

View File

@ -120,6 +120,12 @@ ports=$(ls repository |
sed -E 's/\.tix\.tar\.xz$//')
mkdir -p boot/grub
mkdir -p boot/grub/init
echo "furthermore" > boot/grub/init/furthermore
# TODO: Possibly use a 'try' feature to not warn in case it was already unset.
echo "unset require dhclient" > boot/grub/init/network-no-dhclient
exec > boot/grub/grub.cfg
for hook in \
@ -186,6 +192,7 @@ else
fi
set enable_src=true
set enable_network_drivers=
set enable_dhclient=true
export version
export machine
@ -196,6 +203,7 @@ export default
export no_random_seed
export enable_src
export enable_network_drivers
export enable_dhclient
EOF
if [ -n "$ports" ]; then
@ -285,6 +293,12 @@ cat << EOF
multiboot /$kernel \$no_random_seed \$enable_network_drivers "\$@"
echo done
hook_kernel_post
if ! \$enable_dhclient; then
echo -n "Disabling dhclient ... "
module /boot/grub/init/furthermore --create-to /etc/init/network
module /boot/grub/init/network-no-dhclient --append-to /etc/init/network
echo done
fi
if [ \$no_random_seed != --no-random-seed ]; then
echo -n "Loading /boot/random.seed (256) ... "
module /boot/random.seed --random-seed
@ -432,6 +446,18 @@ else
}
fi
if \$enable_dhclient; then
menuentry "Disable DHCP client" {
enable_dhclient=false
configfile /boot/grub/advanced.cfg
}
else
menuentry "Enable DHCP client" {
enable_dhclient=true
configfile /boot/grub/advanced.cfg
}
fi
menuentry "Select binary packages..." {
configfile /boot/grub/tix.cfg
}

1
dhclient/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
dhclient

32
dhclient/Makefile Normal file
View File

@ -0,0 +1,32 @@
SOFTWARE_MEANT_FOR_SORTIX=1
include ../build-aux/platform.mak
include ../build-aux/compiler.mak
include ../build-aux/version.mak
include ../build-aux/dirs.mak
OPTLEVEL?=$(DEFAULT_OPTLEVEL)
CFLAGS?=$(OPTLEVEL)
CFLAGS += -Wall -Wextra
BINARIES = dhclient
MANPAGES5 = dhclient.conf.5
MANPAGES8 = dhclient.8
all: $(BINARIES)
.PHONY: all install clean
install: all
mkdir -p $(DESTDIR)$(SBINDIR)
install $(BINARIES) $(DESTDIR)$(SBINDIR)
mkdir -p $(DESTDIR)$(MANDIR)/man5
install $(MANPAGES5) $(DESTDIR)$(MANDIR)/man5
mkdir -p $(DESTDIR)$(MANDIR)/man8
install $(MANPAGES8) $(DESTDIR)$(MANDIR)/man8
%: %.c
$(CC) -std=gnu11 $(CFLAGS) $(CPPFLAGS) $< -o $@
clean:
rm -f $(BINARIES)

165
dhclient/dhclient.8 Normal file
View File

@ -0,0 +1,165 @@
.Dd January 15, 2023
.Dt DHCLIENT 8
.Os
.Sh NAME
.Nm dhclient
.Nd dynamic host configuration protocol client
.Sh SYNOPSIS
.Nm
.Op Fl f Ar config
.Op Fl t
.Ar interface
.Sh DESCRIPTION
.Nm
dynamically configures the specified network
.Ar interface
.Xr ( if 4 )
and the Domain Name System (DNS) server list
via the Dynamic Host Configuration Protocol (DHCP) with settings obtained from
the local network's DHCP server.
.Pp
.Nm
is configured in
.Xr dhclient.conf 5 .
Each network setting can be configured to be automatically obtained from the
network (default), set manually, or not set at all.
If the interface is fully manually configured,
.Nm
sets the configuration and exits immediately.
.Pp
.Nm
broadcasts a request and selects a DHCP server to obtain the network
configuration from.
.Nm
leases an internet address as needed and remains running to occasionally renew
the release.
.Pp
The options are as follows:
.Bl -tag -width "12345678"
.It Fl f Ar config
Load the configuration from the
.Ar config
file instead as a shared configuration file instead of searching for it.
.It Fl t
Test the configuration is valid without configuring the network interface.
The
.Ar interface
can optionally be specified to search for its configuration file.
Exit 0 if the configuration is valid and non-zero otherwise.
.El
.Pp
Port 68 on the network interface is bound to send and receive DHCP messages.
.Nm
exits 0 immediately if the port is already bound to avoid interfering with other
.Nm
processes.
.Pp
.Nm
supports the Ethernet link layer
.Xr ether 4
with the Internet Protocol network layer
.Xr ip 4 .
The loopback interface
.Xr lo 4
does not need to be configured and
.Nm
immediately exits successfully.
.Pp
Network interfaces can be manually configured using
.Xr ifconfig 8
and the DNS servers using
.Xr dnsconfig 8 .
.Nm
will occasionally reset the configuration when the internet address lease is
renewed unless disabled.
.Pp
.Nm
is typically automatically started as the
.Sy dhclient
daemon, which is depended on by the
.Sy network
daemon per the
.Xr init 5
configuration.
.Sh IMPLEMENTATION NOTES
.Nm
signals readiness when it has attempted to configure the network interface and
continues retrying afterwards.
The first attempt fails if the network interface's link doesn't come up within
10 seconds.
Packets are transmitted 6 times with an exponential backoff before giving up
and the configuration restarts.
.Sh FILES
.Bl -tag -width "/etc/dhclient.${mac}.conf" -compact
.It Pa /etc/dhclient.${mac}.conf
The preferred
.Xr dhclient.conf 5
file for the interface with the hardware address
.Ar mac .
.It Pa /etc/dhclient.${if}.conf
The second priority
.Xr dhclient.conf 5
file for the interface with the device name
.Ar if .
.It Pa /etc/dhclient.conf
The lowest priority
.Xr dhclient.conf 5
file shared across all network interfaces.
.El
.Sh ASYNCHRONOUS EVENTS
.Bl -tag -width "SIGUSR1"
.It Dv SIGTERM
Request daemon termination.
.El
.Sh EXIT STATUS
.Nm
runs as a
.Xr daemon 7
until stopped by
.Dv SIGTERM .
.Nm
signals readiness on the
.Ev READYFD
file descriptor when the interface is configured, when waiting for the link to
come up times out, or when the DHCP server doesn't respond in time or
configuration fails.
.Nm
will exit 0 if the network interface doesn't need to be configured or is fully
manually configured and will exit non-zero on any fatal startup error.
.Sh EXAMPLES
See
.Xr dhclient.conf 5
for example configurations.
.Pp
See
.Xr init 5
for an example disabling the
.Sy dhclient
daemon by removing the
.Sy network
daemon's dependency on it.
.Sh SEE ALSO
.Xr ether 4 ,
.Xr if 4 ,
.Xr inet 4 ,
.Xr ip 4 ,
.Xr dnsconfig 8 ,
.Xr ifconfig 8 ,
.Xr init 8
.Sh STANDARDS
.Rs
.%A R. Droms
.%D March 1997
.%R RFC 2131
.%T Dynamic Host Configuration Protocol
.%Q Network Working Group
.Re
.Pp
.Rs
.%A S. Alexander
.%A R. Droms
.%D March 1997
.%R RFC 2132
.%T DHCP Options and BOOTP Vendor Extensions
.%Q Network Working Group
.Re

1602
dhclient/dhclient.c Normal file

File diff suppressed because it is too large Load Diff

183
dhclient/dhclient.conf.5 Normal file
View File

@ -0,0 +1,183 @@
.Dd January 16, 2023
.Dt DHCLIENT.CONF 5
.Os
.Sh NAME
.Nm dhclient.conf
.Nd dhcp client configuration
.Sh SYNOPSIS
.Nm /etc/dhclient.${mac}.conf
.Nm /etc/dhclient.${if}.conf
.Nm /etc/dhclient.conf
.Sh DESCRIPTION
.Xr dhclient 8
configures the network interface according to its
.Nm
configuration file, searching for the first file path to exist:
.Pp
.Bl -bullet -compact
.It
.Pa /etc/dhclient.${mac}.conf
- where
.Ar mac
is the network interface's hardware address.
(Example:
.Pa dhclient.00:00:5e:00:53:00.conf )
.It
.Pa /etc/dhclient.${if}.conf
- where
.Ar if
is the network interface's name.
(Example:
.Pa dhclient.if0.conf )
.It
.Pa /etc/dhclient.conf
- the shared configuration file.
.El
.Pp
Network interface names are not guaranteed to be stable and it's recommended to
use the hardware address in the file name or in the
.Sy if
statement in the shared file.
.Sh FORMAT
.Nm
contains a series of whitespace delimited tokens akin to an
.Xr ifconfig 8
invocation.
The
.Sq #
character begins a comment and the rest of the line is ignored.
If a token names a protocol, then that protocol is selected.
If a token names a configuration inside the current protocol or a top level
statement, then that configuration is set to the value of the subsequent
token.
.Pp
Configurations can be generally be set to either a manual value, or
.Sy auto
to obtain the value from the DHCP server, or
.Sy none
to disable setting the configuration and retain the currently set value.
If
.Sy auto
or
.Sy none
follows a protocol name, then all the configurations inside the protocol is set
to that value.
.Pp
The top level statements are:
.Bl -tag -width "12345678"
.It Sy if Oo Ar name "|" Sy etherhw: Ns Ar mac "|" Sy id: Ns Ar linkid Oc
The following configurations only applies to the network interface if it
matches by its
.Ar name ,
its hardware address
.Ar mac ,
or its unstable index number
.Ar linkid .
The
.Sy if
statement can only be used in the shared
.Pa /etc/dhclient.conf
file and allows defining a section for each network interface.
Configurations are applied to all network interfaces until the
.Sy if
statement appears.
.El
.Pp
The
.Sy inet
protocol contains the following configurations:
.Bl -tag -width "12345678"
.It Sy address Oo Ar ip "|" Sy auto "|" Sy none Oc
The local address in
.Xr inet 4
address notation.
(Default:
.Sy auto )
.It Sy router Oo Ar ip "|" Sy auto "|" Sy none Oc
The default route in
.Xr inet 4
address notation.
(Default:
.Sy auto )
.It Sy subnet Oo Ar ip "|" Sy auto "|" Sy none Oc
The subnet mask in
.Xr inet 4
address notation.
(Default:
.Sy auto )
.El
.Pp
The
.Sy dns
protocol contains the following configurations:
.Bl -tag -width "12345678"
.It Sy servers Oo Ar ip1,ip2,... "|" Sy auto "|" Sy none Oc
The comma separated list of DNS servers in
.Xr inet 4
address notation.
A singular comma means the empty list.
(Default:
.Sy auto )
.El
.Pp
The
.Sy ether
protocol contains the following configurations:
.Bl -tag -width "12345678"
.It Sy address Oo Ar mac "|" Sy auto "|" Sy none Oc
The local address in
.Xr ether 4
address notation.
.Sy auto
sets it to the hardware address.
(Default:
.Sy auto )
.El
.Sh EXAMPLES
.Ss Manually configuring an interface
To fully manually configure the network interface
.Pa if0 ,
even if the network interface's device name changes over time, first first look
up its ethernet hardware address:
.Bd -literal -offset indent
$ ifconfig -l if0 ether hwaddress
00:00:5e:00:53:00
.Ed
.Pp
Then write an
.Pa /etc/dhclient.conf
section using the
.Sy if
statement:
.Bd -literal -offset indent
if etherhw:00:00:5e:00:53:00
inet address 192.0.2.4 router 192.0.2.1 subnet 255.255.255.0
dns servers 192.0.2.2 192.0.2.3
.Ed
.Ss Obtaining the DNS servers on only one interface
The DNS server list is global and a system with multiple network interfaces can
obtain the list on only the preferred interface by disabling DNS configuration
and enabling it on the desired interface:
.Bd -literal -offset indent
dns none
if etherhw:00:00:5e:00:53:00
dns auto
.Ed
.Ss Disabling dhclient
.Xr dhclient 8
can be disabled on an interface by disabling configuration of the inet and dns
protocols:
.Bd -literal -offset indent
inet none
dns none
.Ed
.Sh SEE ALSO
.Xr ether 4 ,
.Xr if 4 ,
.Xr inet 4 ,
.Xr dhclient 8 ,
.Xr dnsconfig 8 ,
.Xr ifconfig 8
.Sh CAVEATS
The list of DNS servers is global and should only be obtained on one network
interface to avoid interference.

View File

@ -77,6 +77,7 @@ Delete a resolver:
.Xr getdnsconfig 2 ,
.Xr setdnsconfig 2 ,
.Xr inet 4 ,
.Xr dhclient 8 ,
.Xr ifconfig 8
.Sh HISTORY
.Nm
@ -86,3 +87,6 @@ The kernel DNS resolver list is global state.
Changes made with
.Nm
may be overwritten by other programs.
In particular
.Xr dhclient 8
sets the resolver list automatically unless otherwise configured.

View File

@ -215,4 +215,19 @@ if0
.Xr if 4 ,
.Xr inet 4 ,
.Xr lo 4 ,
.Xr dhclient 8 ,
.Xr dnsconfig 8
.Sh CAVEATS
.Xr ether 4
network interfaces with the
.Xr inet 4
protocol are commonly automatically configured by
.Xr dhclient 8 .
Disable
.Xr dhclient 8
before manually configuring
.Xr inet 4
on such interfaces to avoid the manual configuration being overwritten, or
configure
.Xr dhclient 8
to set your desired network interface configuration in the first place.

View File

@ -120,6 +120,7 @@ does not match the size of the address corresponding to
.Sh SEE ALSO
.Xr inet 4 ,
.Xr inet6 4 ,
.Xr dhclient 8 ,
.Xr dnsconfig 8
.Sh HISTORY
The

2
share/init/dhclient Normal file
View File

@ -0,0 +1,2 @@
per if
exec dhclient

View File

@ -0,0 +1 @@
require dhclient

View File

@ -338,6 +338,7 @@ temporarily fail with
.Xr ip 4 ,
.Xr lo 4 ,
.Xr kernel 7 ,
.Xr dhclient 8 ,
.Xr ifconfig 8
.Sh STANDARDS
.St -p1003.1-2008

View File

@ -153,6 +153,11 @@ It depends on the
and
.Sy time
daemons.
.It Sy dhclient
Daemon that starts
.Xr dhclient 8
on each network interface and becomes ready when each network interface has
been attempted configured.
.It Sy local
Virtual daemon that starts daemons pertinent to the local system.
The system provides a default implementation that does nothing.
@ -163,6 +168,9 @@ system.
.It Sy network
Virtual daemon that becomes ready when an attempt has been made to establish
network connectivity.
It depends on the
.Sy dhclient
deamon.
Daemons can depend on this daemon if they need the network to have been
established before they start.
.It Sy time
@ -525,6 +533,23 @@ The
.Sy optional
flag should only be omitted if a local daemon is critical and the boot should
fail if the daemon fails.
.Ss Disable network auto-configuration (DHCP)
The
.Sy network
daemon depends by default on
.Sy dhclient ,
which does DHCP configuration of the network.
This dependency can be removed by creating
.Pa /etc/init/network
with the following contents:
.Bd -literal
furthermore
unset require dhclient
.Ed
.Pp
This example extends the existing configuration in
.Pa /share/init/network
by removing a dependency.
.Ss Creating a new daemon
The
.Sy exampled

View File

@ -82,7 +82,8 @@ per the instructions in
The release modification procedure lets you customize aspects such as the
default bootloader menu option and timeout, the default hostname, the default
keyboard layout, the default graphics resolution, adding files of your choice to
the live environment, control which drivers are loaded by default, and so on.
the live environment, control which drivers are loaded by default, control which
live environment daemons are started by default, and so on.
.Pp
Warning: The live environment does not come with any random entropy and entropy
gathering is not yet implemented.
@ -143,6 +144,29 @@ Only the selected ports are loaded into the live environment and installed onto
the new installation.
If upgrading an existing installation, then any ports not loaded will be removed
from the installation being upgraded.
.Pp
Ports can additionally be loaded as binary packages in the
.Pa /repository
directory by navigating to the advanced menu and then the select binary packages
submenu and then selecting which ports.
.Pp
The network drivers can be disabled by navigating to the advanced menu and
selecting
.Sy Disable network drivers .
It can be useful to disable the network drivers if it's undesirable to put the
system on the network for security reasons.
You can disable network drivers by default by editing the bootloader
configuration as described below after completing the installation.
.Pp
By default
.Xr dhclient 8
will automatically configure
.Xr ether 4
network interfaces with DHCP and bring up network connectivity.
The DHCP client can be disabled by navigating to the advanced menu and selecting
.Sy Disable DHCP client ,
which is useful if you want to manually configure the network or not expose the
system until you are ready.
.Ss Installer
This guide assumes you selected the operating system installation option in the
bootloader.

View File

@ -262,6 +262,11 @@ If the selected menu option itself is a submenu, it can be appended with a
.Sy '>'
and another selection to pick a default menu option in that submenu, and so on.
(Default: 0)
.It Sy enable_dhclient
Whether to start the
.Xr dhclient 8
daemon.
(Default: true)
.It Sy enable_network_drivers
An additional
.Xr kernel 7

View File

@ -16,7 +16,8 @@ configuration as described in section 5 of the manual.
The release modification procedure lets you customize aspects such as the
default bootloader menu option and timeout, the default hostname, the default
keyboard layout, the default graphics resolution, adding files of your choice to
the live environment, control which drivers are loaded by default, and so on.
the live environment, control which drivers are loaded by default, control which
live environment daemons are started by default, and so on.
.Ss Prerequisites
.Bl -bullet -compact
.It
@ -397,6 +398,16 @@ security reasons or to work around driver issues:
tix-iso-bootconfig --disable-network-drivers bootconfig
tix-iso-add sortix.iso bootconfig
.Ed
.Ss Disable DHCP Auto-Configuration By Default
To customize a release so
.Xr dhclient 8
doesn't automatically configure network interfaces using DHCP, useful if one
wants to manually configure network interfaces with
.Xr ifconfig 8 .
.Bd -literal
tix-iso-bootconfig --disable-dhclient bootconfig
tix-iso-add sortix.iso bootconfig
.Ed
.Sh SEE ALSO
.Xr xorriso 1 ,
.Xr development 7 ,

View File

@ -29,7 +29,8 @@ per the instructions in
The release modification procedure lets you customize aspects such as the
default bootloader menu option and timeout, the default hostname, the default
keyboard layout, the default graphics resolution, adding files of your choice to
the live environment, control which drivers are loaded by default, and so on.
the live environment, control which drivers are loaded by default, control which
live environment daemons are started by default, and so on.
.Pp
Warning: The live environment does not come with any random entropy and entropy
gathering is not yet implemented.

View File

@ -22,6 +22,7 @@ append_title="modified by $(id -un)@$(hostname)"
default=
directory=
enable_append_title=true
enable_dhclient=
enable_network_drivers=
enable_src=
init_target=
@ -52,9 +53,11 @@ for argument do
--default=*) default=$parameter ;;
--default) previous_option=default ;;
--disable-append-title) enable_append_title=false ;;
--disable-dhclient) enable_dhclient=false ;;
--disable-network-drivers) enable_network_drivers=false ;;
--disable-src) enable_src=false ;;
--enable-append-title) enable_append_title=true ;;
--enable-dhclient) enable_dhclient=true ;;
--enable-network-drivers) enable_network_drivers=true ;;
--enable-src) enable_src=true ;;
--init-target=*) init_target=$parameter ;;
@ -138,6 +141,7 @@ mkdir -p -- "$directory/boot/grub"
if [ -n "$timeout" ]; then
printf 'timeout="%s"\n' "$timeout"
fi
print_enable_default_bool "$enable_dhclient" dhclient dhclient
print_enable_default "$enable_network_drivers" network_drivers network-drivers
print_enable_default_bool "$enable_src" src src
if $enable_append_title; then

View File

@ -9,9 +9,11 @@
.Op Fl \-append-title Ns = Ns Ar text
.Op Fl \-default Ns = Ns Ar default-boot-menu-option
.Op Fl \-disable-append-title
.Op Fl \-disable-dhclient
.Op Fl \-disable-network-drivers
.Op Fl \-disable-src
.Op Fl \-enable-append-title
.Op Fl \-enable-dhclient
.Op Fl \-enable-network-drivers
.Op Fl \-enable-src
.Op Fl \-init-target Ns = Ns Ar target
@ -91,6 +93,14 @@ GRUB variable.
Don't append anything to the bootloader menu title by appending to the
.Sy base_menu_title
GRUB variable.
.It Fl \-disable-dhclient
Disable automatic DHCP configuration by setting the
.Sy enable_dhclient
GRUB variable to
.Sy false ,
causing the bootloader to load additional configuration that turns off the
.Xr dhclient 8
daemon on boot.
.It Fl \-disable-network-drivers
Disable network drivers by setting the
.Sy enable_network_drivers
@ -114,6 +124,14 @@ to the bootloader menu title by appending to the
GRUB variable.
This option is on by default and can be disabled with
.Fl \-disable-append-title .
.It Fl \-enable-dhclient
Enable automatic DHCP configuration by setting the
.Sy enable_dhclient
GRUB variable to
.Sy true ,
selecting the default behavior of starting the
.Xr dhclient 8
daemon.
.It Fl \-enable-network-drivers
Enable network drivers by setting the
.Sy enable_network_drivers
@ -271,6 +289,16 @@ security reasons or to work around driver issues:
tix-iso-bootconfig --disable-network-drivers bootconfig
tix-iso-add sortix.iso bootconfig
.Ed
.Ss Disable DHCP Auto-Configuration By Default
To customize a release so
.Xr dhclient 8
doesn't automatically configure network interfaces using DHCP, useful if one
wants to manually configure network interfaces with
.Xr ifconfig 8 .
.Bd -literal
tix-iso-bootconfig --disable-dhclient bootconfig
tix-iso-add sortix.iso bootconfig
.Ed
.Sh SEE ALSO
.Xr xorriso 1 ,
.Xr kernel 7 ,