summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrpe <rpe@openbsd.org>2014-04-21 19:05:40 +0000
committerrpe <rpe@openbsd.org>2014-04-21 19:05:40 +0000
commit2ef72eebe9895c619e8adc4bcbe99b7249617064 (patch)
treefa7e7e809965b4efeabc1122d8f466bfba9bbbc4
parentBind to localAddr if specified and add some XXX comments about stuff (diff)
downloadwireguard-openbsd-2ef72eebe9895c619e8adc4bcbe99b7249617064.tar.xz
wireguard-openbsd-2ef72eebe9895c619e8adc4bcbe99b7249617064.zip
Change dhcp_request() and v4_config() to be able to configure dhcp
for an interface without an active network connection. - Don't write options to dhclient.conf that are default. Only use the 'host-name' option for hostname associated dhcp requests. - Run dhclient with options to reduce the time it takes to finish in case it gets no answer from a DHCP server. - Don't bother removing the interface from group dhcp and save the configuration files even if dhclient fails. If the same interface is statically configured later, it is removed from the group dhcp. - Add 'dhcp' to hostname.if file regardless whether dhcp_request() was successful or not. - Change the Netmask question to be more autoinstaller friendly. based on krw's work discussed with and OK krw@
-rw-r--r--distrib/miniroot/install.sub46
1 files changed, 18 insertions, 28 deletions
diff --git a/distrib/miniroot/install.sub b/distrib/miniroot/install.sub
index 865153bedb5..baa26896e7d 100644
--- a/distrib/miniroot/install.sub
+++ b/distrib/miniroot/install.sub
@@ -1,4 +1,4 @@
-# $OpenBSD: install.sub,v 1.765 2014/04/21 15:56:19 rpe Exp $
+# $OpenBSD: install.sub,v 1.766 2014/04/21 19:05:40 rpe Exp $
#
# Copyright (c) 1997-2009 Todd Miller, Theo de Raadt, Ken Westerback
# All rights reserved.
@@ -780,40 +780,29 @@ dhclient() {
/sbin/dhclient "$@"
}
-# Construct etc/dhclient.conf and issue DHCP request. Return FALSE if
-# no IP address assigned to $1.
-#
-# $1 == interface
-# $2 == hostname
+# Issue a DHCP request to configure interface $1 and add the host-name option to
+# /etc/dhclient.conf using $2.
dhcp_request() {
local _ifs=$1 _hn=$2
echo "lookup file bind" >/etc/resolv.conf.tail
+ echo "send host-name \"$_hn\";" >/etc/dhclient.conf
- cat >/etc/dhclient.conf <<__EOT
+ ifconfig $_ifs group dhcp >/dev/null 2>&1
+
+ dhclient -c /dev/stdin $_ifs << __EOT
initial-interval 1;
+backoff-cutoff 2;
+reboot 5;
+timeout 10;
send host-name "$_hn";
-request subnet-mask, broadcast-address, routers, domain-name,
- domain-name-servers, host-name;
__EOT
- ifconfig $_ifs group dhcp >/dev/null 2>&1
- dhclient $_ifs
-
- set -- $(v4_info $_ifs)
-
- if [[ $1 == UP && -n $2 ]]; then
- # Move configuration files to where they will be copied to the
- # installed system. Overwrites configuration information from
- # last successful dhcp attempt.
- mv /etc/dhclient.conf /tmp/dhclient.conf
- mv /etc/resolv.conf.tail /tmp/resolv.conf.tail
- return 0
- fi
-
- ifconfig $_ifs delete down -group dhcp 2>/dev/null
- rm /etc/dhclient.conf /etc/resolv.conf.tail
- return 1
+ # Move configuration files to where they will be copied to the
+ # installed system. Overwrites configuration information from
+ # last successful dhcp attempt.
+ mv /etc/dhclient.conf /tmp/dhclient.conf
+ mv /etc/resolv.conf.tail /tmp/resolv.conf.tail
}
# Convert a hex value to dotted decimal format
@@ -926,12 +915,13 @@ v4_config() {
none) ;;
dhcp) if [[ ! -x /sbin/dhclient ]]; then
echo "DHCP not possible - no /sbin/dhclient."
- elif dhcp_request $_ifs "$_name"; then
+ else
+ dhcp_request $_ifs "$_name"
echo "dhcp" >>$_hn
fi
;;
*) _addr=$resp
- ask_until "Netmask?" "${_mask:=255.255.255.0}"
+ ask_until "Netmask for $_ifs?" "${_mask:=255.255.255.0}"
ifconfig $_ifs -group dhcp >/dev/null 2>&1
if ifconfig $_ifs inet $_addr netmask $resp up; then
addhostent "$_addr" "$_name"