On Tue, Nov 01, 2022 at 01:57:21PM +0000, Klemens Nanni wrote:
> vifscreate() is used to create all virtual interfaces up-front and is
> always called at the beginning of netstart, whether an explicit list of
> interfaces is passed or none, i.e. all are to be configured.
> 
> Yet, to check the given interface exists, ifstart() uses ifcreate()
> which obviously tries to create interfaces.
> 
> When ifstart() is run for every hostname.if(5) file, every virtual
> interface is guaranteed to exist thanks to vifscreate().
> 
> Nonexistent physical interfaces with an existent config, e.g. urndis(4)
> and cdce(4), will be skipped by ifstart() due to the failed ifcreate()
> call, but not without ifcreate() trying the impossible:
> 
>       $ ifconfig urndis0
>       urndis0: no such interface
>       # sh /etc/netstart -n urndis0
>       { ifconfig urndis0 || ifconfig urndis0 create; }
>       ifconfig urndis0 inet6 autoconf
>       ifconfig urndis0 inet autoconf
> 
> This dry-run output does NOT match what netstart would really do:
> 
>       # sh -x /etc/netstart urndis0 2>&1 | tail -n4
>       + vifscreate urndis0
>       + ifstart urndis0
>       + defaultroute
>       + return
> 
> Here, ifstart() runs but bails out on the failing ifcreate() call and
> thus skips configuring urndis0 entirely.
> 
> 
> So clarify the comment and replace the ifcreate() call with a simpler,
> more obvious `ifconfig' check, which is exactly what ifcreate() boils
> down to for existing interfaces:
> 
>       # sh ./netstart -n urndis0 ; echo $?
>       0
> 
> Actual steps taken remain the same, i.e. none, as the new dry-run output
> truthfully tells:
> 
>       # sh -x ./netstart urndis0 2>&1 | tail -n4
>       + vifscreate urndis0
>       + ifstart urndis0
>       + defaultroute
>       + return
> 
> 
> Virtual interfaces are now also created only once:
> 
>       # sh /etc/netstart -n veb0           
>       { ifconfig veb0 || ifconfig veb0 create; }
>       { ifconfig veb0 || ifconfig veb0 create; }
>       ifconfig veb0 description 'vmd(4) uplink'
>       ifconfig veb0 up
>       # sh ./netstart -n veb0   
>       { ifconfig veb0 || ifconfig veb0 create; }
>       ifconfig veb0 description 'vmd(4) uplink'
>       ifconfig veb0 up
> 
> Feedback? OK?

Ping.

netstart and the installer's copy still remain in sync as best as
possible:  the installer keeps creating interfaces as it doesn't have
any of this create-virtual-interfaces-up-front logic at all.

Index: netstart
===================================================================
RCS file: /cvs/src/etc/netstart,v
retrieving revision 1.229
diff -u -p -r1.229 netstart
--- netstart    5 Nov 2022 12:06:05 -0000       1.229
+++ netstart    9 Nov 2022 13:14:46 -0000
@@ -152,8 +152,8 @@ ifstart() {
                chown -LR root:wheel $_hn
        fi
 
-       # Check for ifconfig'able interface, except if -n option is specified.
-       ifcreate $_if || return
+       # Skip missing physical interface, virtual ones were created up front.
+       ifconfig $_if >/dev/null 2>&1 || return
 
        # Parse the hostname.if(5) file and fill _cmds array with interface
        # configuration commands.

Reply via email to