summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2020-11-29 20:14:07 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2020-11-29 20:14:07 +0000
commitac2bd911058daacc24ff4291dbd1f64018e3f673 (patch)
tree56422725918aaeeaa358c373095cd2f16f7b68e3
parent4f6aad51caa8d959e443433a10864db45d1820c3 (diff)
Add support for !command to mygate, so that netstart has a late opportunity
to perform network configuration (for example, "!route source -ifp em0") Split mygate and myname manual pages (how did anyone ever believe these are related), and perform hostname configuration much earlier in rc. discussed with benno, claudio, jmc, etc etc, last version of !command parser by tb
-rw-r--r--distrib/miniroot/install.sub19
-rw-r--r--etc/netstart40
-rw-r--r--etc/rc7
-rw-r--r--share/man/man5/Makefile4
-rw-r--r--share/man/man5/mygate.586
-rw-r--r--share/man/man5/myname.551
-rw-r--r--share/man/man8/diskless.89
-rw-r--r--share/man/man8/netstart.88
8 files changed, 141 insertions, 83 deletions
diff --git a/distrib/miniroot/install.sub b/distrib/miniroot/install.sub
index 31f861cafaf..558e8601c80 100644
--- a/distrib/miniroot/install.sub
+++ b/distrib/miniroot/install.sub
@@ -1,5 +1,5 @@
#!/bin/ksh
-# $OpenBSD: install.sub,v 1.1155 2020/09/22 15:38:59 florian Exp $
+# $OpenBSD: install.sub,v 1.1156 2020/11/29 20:14:06 deraadt Exp $
#
# Copyright (c) 1997-2015 Todd Miller, Theo de Raadt, Ken Westerback
# Copyright (c) 2015, Robert Peichaer <rpe@openbsd.org>
@@ -2441,15 +2441,16 @@ enable_network() {
# /mnt/etc/mygate, if it exists, contains the address(es) of my
# default gateway(s). Use for ipv4 if no interfaces configured via
# dhcp. Use for ipv6 if no interfaces configured via autoconf.
- ! $V4_DHCPCONF && stripcom /mnt/etc/mygate |
+ stripcom /mnt/etc/mygate |
while read _gw; do
- [[ $_gw == @(*:*) ]] && continue
- route -qn add -host default $_gw && break
- done
- ! $V6_AUTOCONF && stripcom /mnt/etc/mygate |
- while read _gw; do
- [[ $_gw == !(*:*) ]] && continue
- route -qn add -host -inet6 default $_gw && break
+ [[ $_gw == '!'* ]] && continue
+ if [[ $_gw != @(*:*) ]]; then
+ $V4_DHCPCONF && continue
+ route -qn add -host default $_gw
+ elif [[ $_gw == @(*:*) ]]; then
+ $V6_AUTOCONF && continue
+ route -qn add -host -inet6 default $_gw
+ fi
done
route -qn add -net 127 127.0.0.1 -reject >/dev/null
diff --git a/etc/netstart b/etc/netstart
index d70021d62f3..77ba43ccce4 100644
--- a/etc/netstart
+++ b/etc/netstart
@@ -1,6 +1,6 @@
#!/bin/sh -
#
-# $OpenBSD: netstart,v 1.207 2020/11/08 16:51:43 jmc Exp $
+# $OpenBSD: netstart,v 1.208 2020/11/29 20:14:06 deraadt Exp $
# Turn off Strict Bourne shell mode.
set +o sh
@@ -177,27 +177,32 @@ ifmstart() {
# Usage: defaultroute
defaultroute() {
local _cmd;
+ set -o noglob
- ! $V4_DHCPCONF && stripcom /etc/mygate |
+ stripcom /etc/mygate |
while read gw; do
- [[ $gw == @(*:*) ]] && continue
- _cmd="route -qn add -host default $gw"
- if $PRINT_ONLY; then
- print -r -- "$_cmd" && break
- else
- $_cmd && break
- fi
- done
- ! $V6_AUTOCONF && stripcom /etc/mygate |
- while read gw; do
- [[ $gw == !(*:*) ]] && continue
- _cmd="route -qn add -host -inet6 default $gw"
+ case $gw in
+ '!'*)
+ _cmd=$(print -- "$gw" | sed 's/\$if/'$_if'/g')
+ _cmd="${_cmd#!}"
+ ;;
+ *)
+ if [[ $gw != @(*:*) ]]; then
+ $V4_DHCPCONF && continue
+ _cmd="route -qn add -host default $gw"
+ elif [[ $gw == @(*:*) ]]; then
+ $V6_AUTOCONF && continue
+ _cmd="route -qn add -host -inet6 default $gw"
+ fi
+ ;;
+ esac
if $PRINT_ONLY; then
- print -r -- "$_cmd" && break
+ print -r -- "$_cmd"
else
- $_cmd && break
+ $_cmd
fi
done
+ set +o noglob
}
# Make sure the invoking user has the right privileges. Check for presence of
@@ -241,9 +246,6 @@ fi
# Otherwise, process with the complete network initialization.
-# /etc/myname contains my symbolic name.
-[[ -f /etc/myname ]] && hostname "$(stripcom /etc/myname)"
-
# Set the address for the loopback interface. Bringing the interface up,
# automatically invokes the IPv6 address ::1.
ifconfig lo0 inet 127.0.0.1/8
diff --git a/etc/rc b/etc/rc
index 44d67f34bf5..94465add54f 100644
--- a/etc/rc
+++ b/etc/rc
@@ -1,4 +1,4 @@
-# $OpenBSD: rc,v 1.543 2020/01/24 06:17:37 tedu Exp $
+# $OpenBSD: rc,v 1.544 2020/11/29 20:14:06 deraadt Exp $
# System startup script run by init on autoboot or after single-user.
# Output and error are redirected to console by init, and the console is the
@@ -301,6 +301,11 @@ export HOME=/
export INRC=1
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
+# /etc/myname contains my symbolic name.
+if [[ -f /etc/myname ]]; then
+ hostname "$(stripcom /etc/myname)"
+fi
+
# Must set the domainname before rc.conf, so YP startup choices can be made.
if [[ -s /etc/defaultdomain ]]; then
domainname "$(stripcom /etc/defaultdomain)"
diff --git a/share/man/man5/Makefile b/share/man/man5/Makefile
index abc05b618a5..4a54fd3ae6e 100644
--- a/share/man/man5/Makefile
+++ b/share/man/man5/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.57 2018/11/21 09:26:02 jmc Exp $
+# $OpenBSD: Makefile,v 1.58 2020/11/29 20:14:06 deraadt Exp $
# $NetBSD: Makefile,v 1.14 1995/05/11 23:13:15 cgd Exp $
MAN= acct.5 ar.5 bsd.port.mk.5 bsd.port.arch.mk.5 bsd.regress.mk.5 \
@@ -6,7 +6,7 @@ MAN= acct.5 ar.5 bsd.port.mk.5 bsd.port.arch.mk.5 bsd.regress.mk.5 \
defaultdomain.5 dir.5 disktab.5 elf.5 ethers.5 fbtab.5 files.conf.5 \
fs.5 fstab.5 genassym.cf.5 group.5 hostname.if.5 hosts.5 installurl.5 \
intro.5 login.conf.5 mandoc.db.5 mixerctl.conf.5 \
- mk.conf.5 moduli.5 motd.5 myname.5 netgroup.5 passwd.5 \
+ mk.conf.5 moduli.5 motd.5 mygate.5 myname.5 netgroup.5 passwd.5 \
pf.conf.5 pf.os.5 port-modules.5 printcap.5 protocols.5 \
ranlib.5 remote.5 resolv.conf.5 rpc.5 ruby-module.5 \
services.5 shells.5 \
diff --git a/share/man/man5/mygate.5 b/share/man/man5/mygate.5
new file mode 100644
index 00000000000..fff85259331
--- /dev/null
+++ b/share/man/man5/mygate.5
@@ -0,0 +1,86 @@
+.\" $OpenBSD: mygate.5,v 1.1 2020/11/29 20:14:06 deraadt Exp $
+.\"
+.\" Copyright (c) 2003 Jason McIntyre <jmc@openbsd.org>
+.\"
+.\" Permission to use, copy, modify, and distribute this software for any
+.\" purpose with or without fee is hereby granted, provided that the above
+.\" copyright notice and this permission notice appear in all copies.
+.\"
+.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+.\"
+.Dd $Mdocdate: November 29 2020 $
+.Dt MYGATE 5
+.Os
+.Sh NAME
+.Nm mygate
+.Nd default gateway
+.Sh DESCRIPTION
+The
+.Nm mygate
+file is read by
+.Xr netstart 8
+at system startup time.
+.Pp
+.Pa /etc/mygate ,
+if it exists,
+contains the address of the gateway host.
+The gateway is added to the routing tables by the
+.Xr route 8
+utility.
+If
+.Pa /etc/mygate
+does not exist, no default gateway is added to the routing tables.
+The file may contain gateway addresses for both IPv4 and IPv6 networks
+in dotted quad notation for v4
+.Pq e.g. 192.0.2.1
+or in colon notation for v6
+.Pq e.g. 2001:db8::1 .
+Each address must be specified on a separate line.
+If more than one address of a specific family is found,
+only the first is used \- all other addresses of that family are ignored.
+.Pp
+.Pa /etc/mygate
+is processed after all interfaces have been configured.
+If any
+.Xr hostname.if 5
+files contain
+.Dq dhcp
+directives,
+IPv4 entries in
+.Pa /etc/mygate
+will be ignored.
+If they contain
+.Dq autoconf
+directives,
+IPv6 entries will be ignored.
+.Pp
+Additionally, arbitrary shell commands can be executed during processing
+of this file, using
+.Ar \&! Ns Ar command
+directives similar to
+.Xr hostname.if 5 .
+This is useful for doing additional configuration after all interfaces
+are configured by
+.Xr netstart 8 .
+.Pp
+Empty lines and lines beginning with
+.Sq #
+are ignored.
+.Sh FILES
+.Bl -tag -width "/etc/mygate" -compact
+.It Pa /etc/mygate
+Default gateway address(es).
+.El
+.Sh SEE ALSO
+.Xr hostname.if 5 ,
+.Xr netstart 8 ,
+.Xr route 8
+.Sh HISTORY
+This manual page first appeared in
+.Ox 3.4 .
diff --git a/share/man/man5/myname.5 b/share/man/man5/myname.5
index 6234c637a14..a2dbdabc457 100644
--- a/share/man/man5/myname.5
+++ b/share/man/man5/myname.5
@@ -1,4 +1,4 @@
-.\" $OpenBSD: myname.5,v 1.9 2017/07/13 19:16:33 jmc Exp $
+.\" $OpenBSD: myname.5,v 1.10 2020/11/29 20:14:06 deraadt Exp $
.\"
.\" Copyright (c) 2003 Jason McIntyre <jmc@openbsd.org>
.\"
@@ -14,18 +14,16 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: July 13 2017 $
+.Dd $Mdocdate: November 29 2020 $
.Dt MYNAME 5
.Os
.Sh NAME
-.Nm myname , mygate
-.Nd default hostname and gateway
+.Nm myname
+.Nd default hostname
.Sh DESCRIPTION
The
.Nm myname
-and
-.Nm mygate
-files are read by
+file is read by
.Xr netstart 8
at system startup time.
.Pp
@@ -50,48 +48,14 @@ See
.Xr hostname 7
for a description of hostname resolution.
.Pp
-.Pa /etc/mygate ,
-if it exists,
-contains the address of the gateway host.
-The gateway is added to the routing tables by the
-.Xr route 8
-utility.
-If
-.Pa /etc/mygate
-does not exist, no default gateway is added to the routing tables.
-The file may contain gateway addresses for both IPv4 and IPv6 networks:
-in dotted quad notation for v4
-.Pq e.g. 192.0.2.1
-or in colon notation for v6
-.Pq e.g. 2001:db8::1 .
-Each address must be specified on a separate line.
-If more than one address of a specific family is found,
-only the first is used \- all other addresses of that family are ignored.
-.Pp
-.Pa /etc/mygate
-is processed after all interfaces have been configured.
-If any
-.Xr hostname.if 5
-files contain
-.Dq dhcp
-directives,
-IPv4 entries in
-.Pa /etc/mygate
-will be ignored.
-If they contain
-.Dq autoconf
-directives,
-IPv6 entries will be ignored.
.Pp
Empty lines and lines beginning with
.Sq #
-in either file are ignored.
+are ignored.
.Sh FILES
.Bl -tag -width "/etc/myname" -compact
.It Pa /etc/myname
Default hostname.
-.It Pa /etc/mygate
-Default gateway address(es).
.El
.Sh SEE ALSO
.Xr hostname 1 ,
@@ -99,8 +63,7 @@ Default gateway address(es).
.Xr hosts 5 ,
.Xr resolv.conf 5 ,
.Xr hostname 7 ,
-.Xr netstart 8 ,
-.Xr route 8
+.Xr netstart 8
.Sh HISTORY
This manual page first appeared in
.Ox 3.4 .
diff --git a/share/man/man8/diskless.8 b/share/man/man8/diskless.8
index def171b393a..b0a30683882 100644
--- a/share/man/man8/diskless.8
+++ b/share/man/man8/diskless.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: diskless.8,v 1.69 2017/06/11 14:03:46 schwarze Exp $
+.\" $OpenBSD: diskless.8,v 1.70 2020/11/29 20:14:06 deraadt Exp $
.\" $NetBSD: diskless.8,v 1.7.4.1 1996/05/30 18:58:10 cgd Exp $
.\"
.\"
@@ -27,7 +27,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 $Mdocdate: June 11 2017 $
+.Dd $Mdocdate: November 29 2020 $
.Dt DISKLESS 8
.Os
.Sh NAME
@@ -395,7 +395,9 @@ Interface-specific configuration file.
.It Pa /etc/hosts
Host name database.
.It Pa /etc/myname
-Default hostname and gateway.
+Default hostname.
+.It Pa /etc/mygate
+Default gateway.
.It Pa /etc/rbootd.conf
Configuration file for HP Remote Boot Daemon.
.It Pa /tftpboot
@@ -411,6 +413,7 @@ Location of boot programs loaded by the HP Boot ROM.
.Xr fstab 5 ,
.Xr hostname.if 5 ,
.Xr hosts 5 ,
+.Xr mygate 5 ,
.Xr myname 5 ,
.Xr dhcpd 8 ,
.Xr mopd 8 ,
diff --git a/share/man/man8/netstart.8 b/share/man/man8/netstart.8
index 0c0d7038ddd..91183376edd 100644
--- a/share/man/man8/netstart.8
+++ b/share/man/man8/netstart.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: netstart.8,v 1.24 2020/11/03 06:46:23 jmc Exp $
+.\" $OpenBSD: netstart.8,v 1.25 2020/11/29 20:14:06 deraadt Exp $
.\"
.\" Copyright (c) 2002, Miodrag Vallat.
.\" All rights reserved.
@@ -25,7 +25,7 @@
.\"
.\" @(#)rc.8 8.2 (Berkeley) 12/11/93
.\"
-.Dd $Mdocdate: November 3 2020 $
+.Dd $Mdocdate: November 29 2020 $
.Dt NETSTART 8
.Os
.Sh NAME
@@ -58,8 +58,6 @@ performs the following operations, in the sequence given:
.Pp
.Bl -bullet -compact -offset indent
.It
-Set the machine's name.
-.It
Configure the loopback interface.
.It
Configure all physical interfaces.
@@ -108,7 +106,7 @@ without actually configuring the interface.
.Xr multicast 4 ,
.Xr defaultdomain 5 ,
.Xr hostname.if 5 ,
-.Xr myname 5 ,
+.Xr mygate 5 ,
.Xr ifconfig 8 ,
.Xr rc 8 ,
.Xr rc.conf 8