diff options
author | 2020-12-11 12:34:11 +0000 | |
---|---|---|
committer | 2020-12-11 12:34:11 +0000 | |
commit | 2c6b17b81a874d1acc556e9e17d6ba8f244ce9e4 (patch) | |
tree | 1716e755a66845a3642ce0b0637c2a3cbae2a28a | |
parent | sync to libunbound 1.13.0 (diff) | |
download | wireguard-openbsd-2c6b17b81a874d1acc556e9e17d6ba8f244ce9e4.tar.xz wireguard-openbsd-2c6b17b81a874d1acc556e9e17d6ba8f244ce9e4.zip |
There is a race in dhclient(8) privsep. The parent process may
return before the interface address and route are set in the kernel.
The auto installer script runs a ftp(1) command immediatelty after
that, it fails without a local address. Before calling ftp, wait
until the address appears in ifconfig(8) output and dhclient leases
file. This makes autoinstall more reliable.
discussed with patrick@; input and OK krw@
-rw-r--r-- | distrib/miniroot/install.sub | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/distrib/miniroot/install.sub b/distrib/miniroot/install.sub index 46f17414866..98d5313bcc8 100644 --- a/distrib/miniroot/install.sub +++ b/distrib/miniroot/install.sub @@ -1,5 +1,5 @@ #!/bin/ksh -# $OpenBSD: install.sub,v 1.1157 2020/11/29 20:54:33 tb Exp $ +# $OpenBSD: install.sub,v 1.1158 2020/12/11 12:34:11 bluhm Exp $ # # Copyright (c) 1997-2015 Todd Miller, Theo de Raadt, Ken Westerback # Copyright (c) 2015, Robert Peichaer <rpe@openbsd.org> @@ -621,6 +621,11 @@ get_responsefile() { [[ -n $_if ]] && dhclient $_if || break _lf=/var/db/dhclient.leases.$_if + if ! wait_for_dhcp_info $_if 30; then + echo "No dhcp address on interface $_if in 30 seconds." + continue + fi + # Extract installer mode and response file path from lease file. _aifile=$(lease_value $_lf filename bootfile-name) [[ $_aifile == ?(*/)auto_@(install|upgrade) ]] || _aifile= @@ -911,6 +916,28 @@ v4_info() { /.inet /s///p' } +# Wait until dhcp has configured interface $1 within timeout $2 seconds. +wait_for_dhcp_info() { + local _if=$1 _secs=$2 + + # Wait until $_if has a V4 address. + while (( _secs > 0 )); do + set -- $(v4_info $_if) + [[ -n $2 ]] && break + sleep 1 + (( _secs-- )) + done + + # Wait until there is a leases file to parse. + while (( _secs > 0 )); do + [[ -s /var/db/dhclient.leases.$_if ]] && break + sleep 1 + (( _secs-- )) + done + + return $(( _secs <= 0 )) +} + # Convert a netmask in hex format ($1) to dotted decimal format. hextodec() { set -- $(echo ${1#0x} | sed 's/\(..\)/0x\1 /g') |