On Tue, Dec 07, 2021 at 08:15:41PM +0000, Klemens Nanni wrote:
> On Tue, Nov 23, 2021 at 01:17:14AM +0000, Klemens Nanni wrote:
> > 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.
> 
> Anyone?
> 
> This is really practical and fixes things at least for me when I destroy
> interfaces, reconfigure and recreate them together, for example like so:
> 
>       # ifconfig pair2 destroy
>       # ifconfig pair1 destroy
>       ... edit hostname.*
>       # sh /etc/netstart pair1 pair2
>       ifconfig: patch pair2: No such file or directory
>       add net default: gateway 192.0.0.1
> 
> (redoing it because who knows what failed due to the order problem and
> what didn't...)
> 
>       # ifconfig pair2 destroy
>       # ifconfig pair1 destroy
>       # sh /usr/src/etc/netstart pair1 pair2
>       add net default: gateway 192.0.0.1
> 
> Feedback? Objection? OK?

One last ping with the same diff on top of -CURRENT.


Index: etc/netstart
===================================================================
RCS file: /cvs/src/etc/netstart,v
retrieving revision 1.218
diff -u -p -r1.218 netstart
--- etc/netstart        26 Jun 2022 09:36:13 -0000      1.218
+++ etc/netstart        30 Jun 2022 14:48:46 -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
@@ -314,6 +319,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

Reply via email to