OK afresh1@, I would have to dig for a device to actually test it with,
but my reading of the code makes me think it's correct.
I do wonder if moving the ifcreate logic into vifscreate would allow for
a friendlier message from `-n`.
(untested diff follows, also missing the deletion of ifcreate)
Index: etc/netstart
===================================================================
RCS file: /cvs/src/etc/netstart,v
retrieving revision 1.230
diff -u -p -r1.230 netstart
--- etc/netstart 5 Dec 2022 20:12:00 -0000 1.230
+++ etc/netstart 15 Dec 2022 01:13:13 -0000
@@ -122,8 +122,12 @@ vifscreate() {
continue
fi
- if ! ifcreate $_if; then
- print -u2 "${0##*/}: create for '$_if' failed."
+ if ! ifconfig $_if >/dev/null 2>&1; then
+ if $PRINT_ONLY; then
+ print -r -- "ifconfig $_if create"
+ elif ! ifconfig $_if create >/dev/null 2>&1;
then
+ print -u2 "${0##*/}: create for '$_if'
failed."
+ fi
fi
done
done
On Wed, Nov 09, 2022 at 01:15:08PM +0000, Klemens Nanni wrote:
> 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.
>
--
andrew
Real programmers don't document.
If it was hard to write, it should be hard to understand.