On Tue, Nov 16, 2021 at 11:09:40PM +0000, Klemens Nanni wrote:
> Run on boot without arguments, netstart(8) creates all virtual
> interfaces *for which hostname.if files exist* before configuring them.
>
> This prevents ordering problems with bridges and its members, as dlg's
> commit message from 2018 reminds us.
>
> But it also helps interface types like pair(4) which pair one another
> in whatever way the user says:
>
> $ cat /etc/hostname.pair1
> patch pair2
> $ cat /etc/hostname.pair2
> rdomain 1
>
> On boot this works, but `sh /etc/netstart pair1 pair2' won't work
> because pair2 does not exist a creation time of pair1 because netstart
> does not create virtual interfaces upfront.
>
> I just hit this exact use case when setting up gelatod(8) (see ports@).
>
> To fix this, pass the list of interfaces to vifscreate() and make it
> create only those iff given.
>
> Regular boot, i.e. `sh /etc/netstart', stays uneffected by this and
> selective runs as shown work as expected without requring users to know
> the order in which netstart creates/configures interfaces.
>
> The installer's internal version of netstart doesn't need this at all;
> neither does it have the selective semantic nor does vifscreate() exist.
Anyone?
It seems only logical to treat subsets of interfaces the same way as
a full `sh /etc/netstart'.
A pair of pair(4) is one example, I'm certain there are more scenarios
where you craft interfaces with `ifconfig ...' in the shell, then set up
the hostname.* files and test them with `sh /etc/netstart bridge0 ...'
where pseudo interfaces are involved.
Feedback? Objection? OK?
Index: netstart
===================================================================
RCS file: /cvs/src/etc/netstart,v
retrieving revision 1.216
diff -u -p -r1.216 netstart
--- netstart 2 Sep 2021 19:38:20 -0000 1.216
+++ netstart 16 Nov 2021 22:58:31 -0000
@@ -94,9 +94,11 @@ 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
+ local _vif _hn _if _ifs
+ set -A _ifs -- "$@"
for _vif in $(ifconfig -C); do
for _hn in /etc/hostname.${_vif}+([[:digit:]]); do
@@ -106,6 +108,9 @@ vifscreate() {
# loopback for routing domain is created by kernel
[[ -n ${_if##lo[1-9]*} ]] || continue
+ ((${#_ifs[*]} > 0)) && [[ ${_ifs[*]} != *${_if}* ]] &&
+ continue
+
if ! ifcreate $_if; then
print -u2 "${0##*/}: create for '$_if' failed."
fi
@@ -303,6 +308,7 @@ $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.
if (($# > 0)); then
+ vifscreate "$@"
for _if; do ifstart $_if; done
defaultroute
return