aboutsummaryrefslogtreecommitdiff
path: root/hooks
diff options
context:
space:
mode:
authorEd Maste <emaste@FreeBSD.org>2024-06-03 16:17:02 +0000
committerEd Maste <emaste@FreeBSD.org>2024-06-03 16:19:54 +0000
commit1b2aa3deeb0dbbace9fed635fa01b6f6e8480901 (patch)
treed4f991a92b1c7c84e264b900f50f2fa0202c872a /hooks
parent96dba636abec6d5451820add99300bda2ca6d86a (diff)
Diffstat (limited to 'hooks')
-rw-r--r--hooks/10-wpa_supplicant10
-rw-r--r--hooks/20-resolv.conf2
-rw-r--r--hooks/29-lookup-hostname6
-rw-r--r--hooks/30-hostname.in6
-rw-r--r--hooks/50-ntp.conf6
-rw-r--r--hooks/50-timesyncd.conf60
-rw-r--r--hooks/Makefile2
-rw-r--r--hooks/dhcpcd-run-hooks.8.in29
-rw-r--r--hooks/dhcpcd-run-hooks.in18
9 files changed, 100 insertions, 39 deletions
diff --git a/hooks/10-wpa_supplicant b/hooks/10-wpa_supplicant
index 04acce088840..e27ea170c532 100644
--- a/hooks/10-wpa_supplicant
+++ b/hooks/10-wpa_supplicant
@@ -102,12 +102,12 @@ wpa_supplicant_stop()
}
if [ "$ifwireless" = "1" ] && \
- type wpa_supplicant >/dev/null 2>&1 && \
- type wpa_cli >/dev/null 2>&1
+ command -v wpa_supplicant >/dev/null 2>&1 && \
+ command -v wpa_cli >/dev/null 2>&1
then
case "$reason" in
- PREINIT) wpa_supplicant_start;;
- RECONFIGURE) wpa_supplicant_reconfigure;;
- DEPARTED) wpa_supplicant_stop;;
+ PREINIT) wpa_supplicant_start;;
+ RECONFIGURE) wpa_supplicant_reconfigure;;
+ DEPARTED|STOPPED) wpa_supplicant_stop;;
esac
fi
diff --git a/hooks/20-resolv.conf b/hooks/20-resolv.conf
index 504a6c5373a4..7c29e2765b36 100644
--- a/hooks/20-resolv.conf
+++ b/hooks/20-resolv.conf
@@ -11,7 +11,7 @@ nocarrier_roaming_dir="$state_dir/roaming"
NL="
"
: ${resolvconf:=resolvconf}
-if type "$resolvconf" >/dev/null 2>&1; then
+if command -v "$resolvconf" >/dev/null 2>&1; then
have_resolvconf=true
else
have_resolvconf=false
diff --git a/hooks/29-lookup-hostname b/hooks/29-lookup-hostname
index 811c7a9c89bf..a1540dd98340 100644
--- a/hooks/29-lookup-hostname
+++ b/hooks/29-lookup-hostname
@@ -4,20 +4,20 @@ lookup_hostname()
{
[ -z "$new_ip_address" ] && return 1
# Silly ISC programs love to send error text to stdout
- if type dig >/dev/null 2>&1; then
+ if command -v dig >/dev/null 2>&1; then
h=$(dig +short -x $new_ip_address)
if [ $? = 0 ]; then
echo "$h" | sed 's/\.$//'
return 0
fi
- elif type host >/dev/null 2>&1; then
+ elif command -v host >/dev/null 2>&1; then
h=$(host $new_ip_address)
if [ $? = 0 ]; then
echo "$h" \
| sed 's/.* domain name pointer \(.*\)./\1/'
return 0
fi
- elif type getent >/dev/null 2>&1; then
+ elif command -v getent >/dev/null 2>&1; then
h=$(getent hosts $new_ip_address)
if [ $? = 0 ]; then
echo "$h" | sed 's/[^ ]* *\([^ ]*\).*/\1/'
diff --git a/hooks/30-hostname.in b/hooks/30-hostname.in
index abeb36967221..98e419f8a523 100644
--- a/hooks/30-hostname.in
+++ b/hooks/30-hostname.in
@@ -25,7 +25,7 @@ _hostname()
if [ -z "${1+x}" ]; then
if [ -r /proc/sys/kernel/hostname ]; then
read name </proc/sys/kernel/hostname && echo "$name"
- elif type hostname >/dev/null 2>/dev/null; then
+ elif command -v hostname >/dev/null 2>/dev/null; then
hostname
elif sysctl kern.hostname >/dev/null 2>&1; then
sysctl -n kern.hostname
@@ -39,7 +39,7 @@ _hostname()
if [ -w /proc/sys/kernel/hostname ]; then
echo "$1" >/proc/sys/kernel/hostname
- elif [ -n "$1" ] && type hostname >/dev/null 2>&1; then
+ elif [ -n "$1" ] && command -v hostname >/dev/null 2>&1; then
hostname "$1"
elif sysctl kern.hostname >/dev/null 2>&1; then
sysctl -w "kern.hostname=$1" >/dev/null
@@ -118,7 +118,7 @@ set_hostname()
*) hshort=true;;
esac
- need_hostname || return
+ need_hostname || return 0
if [ -n "$new_fqdn" ]; then
if ${hfqdn} || ! ${hshort}; then
diff --git a/hooks/50-ntp.conf b/hooks/50-ntp.conf
index 046ab6b33a06..cbaa374408bb 100644
--- a/hooks/50-ntp.conf
+++ b/hooks/50-ntp.conf
@@ -43,7 +43,7 @@ fi
# Debian has a separate file for DHCP config to avoid stamping on
# the master.
-if [ "$ntp_service" = ntpd ] && type invoke-rc.d >/dev/null 2>&1; then
+if [ "$ntp_service" = ntpd ] && command -v invoke-rc.d >/dev/null 2>&1; then
[ -e /var/lib/ntp ] || mkdir /var/lib/ntp
: ${ntp_service:=ntp}
: ${NTP_DHCP_CONF:=/var/lib/ntp/ntp.conf.dhcp}
@@ -113,7 +113,7 @@ add_ntp_conf()
[ -e "$cf" ] && rm "$cf"
[ -d "$ntp_conf_dir" ] || mkdir -p "$ntp_conf_dir"
if [ -n "$new_ntp_servers" ]; then
- for x in $new_ntp_servers; do
+ for x in $(uniqify $new_ntp_servers); do
echo "server $x" >> "$cf"
done
fi
@@ -131,7 +131,7 @@ remove_ntp_conf()
# For ease of use, map DHCP6 names onto our DHCP4 names
case "$reason" in
BOUND6|RENEW6|REBIND6|REBOOT6|INFORM6)
- new_ntp_servers="$new_dhcp6_sntp_servers"
+ new_ntp_servers="$new_dhcp6_sntp_servers $new_dhcp6_ntp_server_addr $new_dhcp6_ntp_server_fqdn"
;;
esac
diff --git a/hooks/50-timesyncd.conf b/hooks/50-timesyncd.conf
new file mode 100644
index 000000000000..dff8817324e3
--- /dev/null
+++ b/hooks/50-timesyncd.conf
@@ -0,0 +1,60 @@
+: ${timesyncd_conf_d:=/run/systemd/timesyncd.conf.d}
+timesyncd_conf="${timesyncd_conf_d}/dhcpcd-$ifname.conf"
+timesyncd_tmp_d="$state_dir/timesyncd"
+timesyncd_tmp="$timesyncd_tmp_d/$ifname"
+
+NL="
+"
+
+remove_timesyncd_conf()
+{
+ if [ -e "$timesyncd_conf" ]; then
+ rm "$timesyncd_conf"
+ systemctl try-reload-or-restart --no-block systemd-timesyncd
+ fi
+}
+
+add_timesyncd_conf()
+{
+ if [ -z "$new_ntp_servers" ]; then
+ remove_timesyncd_conf
+ return $?
+ fi
+
+ mkdir -p "$timesyncd_tmp_d" "$timesyncd_conf_d"
+
+ conf="$signature$NL"
+ conf="${conf}[Time]$NL"
+ conf="${conf}NTP="
+ # Trim spaces
+ space=false
+ for ntp_server in $(uniqify $new_ntp_servers); do
+ if ! $space; then
+ space=true
+ else
+ conf="$conf "
+ fi
+ conf="$conf$ntp_server"
+ done
+ conf="$conf$NL"
+
+ printf %s "$conf" > "$timesyncd_tmp"
+ if change_file "$timesyncd_conf" "$timesyncd_tmp"; then
+ systemctl try-reload-or-restart --no-block systemd-timesyncd
+ fi
+}
+
+# For ease of use, map DHCP6 names onto our DHCP4 names
+case "$reason" in
+BOUND6|RENEW6|REBIND6|REBOOT6|INFORM6)
+ new_ntp_servers="$new_dhcp6_sntp_servers $new_dhcp6_ntp_server_addr $new_dhcp6_ntp_server_fqdn"
+;;
+esac
+
+if $if_configured; then
+ if $if_up; then
+ add_timesyncd_conf
+ elif $if_down; then
+ remove_timesyncd_conf
+ fi
+fi
diff --git a/hooks/Makefile b/hooks/Makefile
index 7a0c3b1d330a..aee0255c64f9 100644
--- a/hooks/Makefile
+++ b/hooks/Makefile
@@ -23,7 +23,7 @@ FILES+= ${EGHOOKSCRIPTS}
.SUFFIXES: .in
-.in: Makefile ${TOP}/config.mk
+.in:
${SED} ${SED_RUNDIR} ${SED_DBDIR} ${SED_LIBDIR} ${SED_HOOKDIR} \
${SED_SYS} ${SED_SCRIPT} ${SED_DATADIR} \
${SED_SERVICEEXISTS} ${SED_SERVICECMD} ${SED_SERVICESTATUS} \
diff --git a/hooks/dhcpcd-run-hooks.8.in b/hooks/dhcpcd-run-hooks.8.in
index db88d8e2ab17..ac1972a06ad6 100644
--- a/hooks/dhcpcd-run-hooks.8.in
+++ b/hooks/dhcpcd-run-hooks.8.in
@@ -1,4 +1,4 @@
-.\" Copyright (c) 2006-2021 Roy Marples
+.\" Copyright (c) 2006-2023 Roy Marples
.\" All rights reserved
.\"
.\" Redistribution and use in source and binary forms, with or without
@@ -22,7 +22,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd December 27, 2020
+.Dd August 31, 2022
.Dt DHCPCD-RUN-HOOKS 8
.Os
.Sh NAME
@@ -68,15 +68,14 @@ is set to the interface that
.Nm dhcpcd
is run on and
.Ev $reason
-is to the reason why
-q
+is set to the reason why
.Nm
was invoked.
DHCP information to be configured is held in variables starting with the word
new_ and old DHCP information to be removed is held in variables starting with
the word old_.
.Nm dhcpcd
-can display the full list of variables it knows how about by using the
+can display the full list of variables it knows about by using the
.Fl V , -variables
argument.
.Pp
@@ -85,7 +84,7 @@ Here's a list of reasons why
could be invoked:
.Bl -tag -width EXPIREXXXEXPIRE6
.It Dv PREINIT
-dhcpcd is starting up and any pre-initialisation should be done.
+dhcpcd is starting up and any pre-initialisation required should be performed now.
.It Dv CARRIER
dhcpcd has detected the carrier is up.
This is generally just a notification and no action need be taken.
@@ -94,14 +93,14 @@ dhcpcd lost the carrier.
The cable may have been unplugged or association to the wireless point lost.
.It Dv NOCARRIER_ROAMING
dhcpcd lost the carrier but the interface configuration is persisted.
-The OS has to support wireless roaming or IP Persistance for this to happen.
+The OS has to support wireless roaming or IP Persistence for this to happen.
.It Dv INFORM | Dv INFORM6
dhcpcd informed a DHCP server about its address and obtained other
configuration details.
.It Dv BOUND | Dv BOUND6
dhcpcd obtained a new lease from a DHCP server.
.It Dv RENEW | Dv RENEW6
-dhcpcd renewed it's lease.
+dhcpcd renewed its lease.
.It Dv REBIND | Dv REBIND6
dhcpcd has rebound to a new DHCP server.
.It Dv REBOOT | Dv REBOOT6
@@ -181,7 +180,7 @@ flags.
.Ev $interface
MTU.
.It Ev $ifssid
-the name of the SSID the
+the SSID the
.Ev interface
is connected to.
.It Ev $interface_order
@@ -207,24 +206,24 @@ Address family waiting for, as defined in
the name of the profile selected from
.Xr dhcpcd.conf 5 .
.It Ev $new_delegated_dhcp6_prefix
-space separated list of delegated prefixes.
+space-separated list of delegated prefixes.
.El
.Sh FILES
When
.Nm
runs, it loads
-.Pa @SYSCONFDIR@/dhcpcd.enter-hook
-and any scripts found in
+.Pa @SYSCONFDIR@/dhcpcd.enter-hook ,
+any scripts found in
.Pa @HOOKDIR@
-in a lexical order and then finally
-.Pa @SYSCONFDIR@/dhcpcd.exit-hook
+in lexical order, then finally
+.Pa @SYSCONFDIR@/dhcpcd.exit-hook .
.Sh SEE ALSO
.Xr dhcpcd 8
.Sh AUTHORS
.An Roy Marples Aq Mt roy@marples.name
.Sh BUGS
Please report them to
-.Lk http://roy.marples.name/projects/dhcpcd
+.Lk https://roy.marples.name/projects/dhcpcd
.Sh SECURITY CONSIDERATIONS
.Nm dhcpcd
will validate the content of each option against its encoding.
diff --git a/hooks/dhcpcd-run-hooks.in b/hooks/dhcpcd-run-hooks.in
index a237f6af5340..91df64b1a809 100644
--- a/hooks/dhcpcd-run-hooks.in
+++ b/hooks/dhcpcd-run-hooks.in
@@ -67,7 +67,7 @@ key_get_value()
key="$1"
shift
- if type sed >/dev/null 2>&1; then
+ if command -v sed >/dev/null 2>&1; then
sed -n "s/^$key//p" $@
else
for x do
@@ -89,7 +89,7 @@ remove_markers()
in_marker=0
shift; shift
- if type sed >/dev/null 2>&1; then
+ if command -v sed >/dev/null 2>&1; then
sed "/^$m1/,/^$m2/d" $@
else
for x do
@@ -109,9 +109,9 @@ comp_file()
{
[ -e "$1" ] && [ -e "$2" ] || return 1
- if type cmp >/dev/null 2>&1; then
+ if command -v cmp >/dev/null 2>&1; then
cmp -s "$1" "$2"
- elif type diff >/dev/null 2>&1; then
+ elif command -v diff >/dev/null 2>&1; then
diff -q "$1" "$2" >/dev/null
else
# Hopefully we're only working on small text files ...
@@ -178,7 +178,7 @@ syslog()
err|error) echo "$interface: $*" >&2;;
*) echo "$interface: $*";;
esac
- if type logger >/dev/null 2>&1; then
+ if command -v logger >/dev/null 2>&1; then
logger -i -p daemon."$lvl" -t dhcpcd-run-hooks "$interface: $*"
fi
}
@@ -234,11 +234,11 @@ detect_init()
if [ -x /bin/systemctl ] && [ -S /run/systemd/private ]; then
_service_exists="/bin/systemctl --quiet is-enabled \$1.service"
_service_status="/bin/systemctl --quiet is-active \$1.service"
- _service_cmd="/bin/systemctl \$2 \$1.service"
+ _service_cmd="/bin/systemctl \$2 --no-block \$1.service"
elif [ -x /usr/bin/systemctl ] && [ -S /run/systemd/private ]; then
_service_exists="/usr/bin/systemctl --quiet is-enabled \$1.service"
_service_status="/usr/bin/systemctl --quiet is-active \$1.service"
- _service_cmd="/usr/bin/systemctl \$2 \$1.service"
+ _service_cmd="/usr/bin/systemctl \$2 --no-block \$1.service"
elif [ -x /sbin/rc-service ] &&
{ [ -s /libexec/rc/init.d/softlevel ] ||
[ -s /run/openrc/softlevel ]; }
@@ -338,9 +338,11 @@ for hook in \
@HOOKDIR@/* \
@SYSCONFDIR@/dhcpcd.exit-hook
do
+ case "$hook" in
+ */*~) continue;;
+ esac
for skip in $skip_hooks; do
case "$hook" in
- */*~) continue 2;;
*/"$skip") continue 2;;
*/[0-9][0-9]"-$skip") continue 2;;
*/[0-9][0-9]"-$skip.sh") continue 2;;