diff options
author | Klemens Nanni <kn@cvs.openbsd.org> | 2022-07-03 12:14:37 +0000 |
---|---|---|
committer | Klemens Nanni <kn@cvs.openbsd.org> | 2022-07-03 12:14:37 +0000 |
commit | 2606b1d8bc9ff1ca171f6e681bd1d39b5a88f5ca (patch) | |
tree | 7068ebe56979294f533fc10c7d6d90ea923ca92f | |
parent | a070099cc834ee49463262b940ad33a9a0fb70c1 (diff) |
Create virtual interfaces upfront if specified on the command line
In cases like `sh /etc/netstart pair1 pair2', one of hostname.pair{1,2}
will contain a "patch pair{2,1}" command which expects the other interface
to exist.
If none exist, this would fail and netstart had to be run separately or
"patch"ed interface had to be manually created before.
There are other use cases where interfaces depend on each other, so before
(re)configuring an explicit list of interfaces, create all virtual ones
upfront so that a single netstart invocation will configure everything
correctly without having reflect dependencies in multiple ordered netstart
invocations.
Copy isin() from install.sub to help.
Feedback OK halex
-rw-r--r-- | etc/netstart | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/etc/netstart b/etc/netstart index 33e9689a819..6da1f4084a6 100644 --- a/etc/netstart +++ b/etc/netstart @@ -1,6 +1,6 @@ #!/bin/sh - # -# $OpenBSD: netstart,v 1.218 2022/06/26 09:36:13 florian Exp $ +# $OpenBSD: netstart,v 1.219 2022/07/03 12:14:36 kn Exp $ # Turn off Strict Bourne shell mode. set +o sh @@ -11,6 +11,17 @@ usage() { exit 1 } +# Test the first argument against the remaining ones, return success on a match. +isin() { + local _a=$1 _b + + shift + for _b; do + [[ $_a == "$_b" ]] && return 0 + done + return 1 +} + # Echo file $1 to stdout. Skip comment lines. Strip leading and trailing # whitespace if IFS is set. # Usage: stripcom /path/to/file @@ -94,7 +105,8 @@ ifcreate() { } # Create interfaces for network pseudo-devices referred to by hostname.if files. -# Usage: vifscreate +# Optionally, limit creation to given interfaces only. +# Usage: vifscreate [if ...] vifscreate() { local _vif _hn _if @@ -106,6 +118,10 @@ vifscreate() { # loopback for routing domain is created by kernel [[ -n ${_if##lo[1-9]*} ]] || continue + if (($# > 0)) && ! isin $_if "$@"; then + continue + fi + if ! ifcreate $_if; then print -u2 "${0##*/}: create for '$_if' failed." fi @@ -313,7 +329,11 @@ $PRINT_ONLY || [[ ! -f /etc/soii.key ]] || # If we were invoked with a list of interface names, just reconfigure these # interfaces (or bridges), add default routes and return. +# Create virtual interfaces upfront to make ifconfig commands depending on +# other interfaces, e.g. "patch", work regardless of in which order interface +# names were specified. if (($# > 0)); then + vifscreate "$@" for _if; do ifstart $_if; done defaultroute return |