On Tue, Nov 22, 2022 at 08:09:11AM -0700, Theo de Raadt wrote:
> Florian Obser <flor...@openbsd.org> wrote:
> > ifconfig(8) already knows about these (see -C option). Which made me
> > think, it might be easier to just ask ifconfig(8).
<SNIP>
> 
> I've done it as -M

With `ifconfig -M $lladdr` support, and ignoring the check for both
/etc/hostname.$if and /etc/hostname.$lladdr pointing to the same
interface, this gets pretty simple.

First, in the case of `netstart $lladdr` we ask `ifconfig -M` to
translate to a $if and if that works, we continue on, using
hostname.$lladdr.

In the case of netstart without any arguments, it gets a little less
cozy.   We have to iterate all hostname.* files, and if they look like
an interface name (as before) we use that directly, and otherwise we
pass the extension as above, hoping it is an lladdr and trusting the
validation there.

That does mean calling `ifconfig -M` with any random extension we find
on /etc/hostname.*, we found, although we could put back the `LLGLOB`
and do a bit more validation here before calling ifconfig -M.


Index: etc/netstart
===================================================================
RCS file: /cvs/src/etc/netstart,v
retrieving revision 1.229
diff -u -p -r1.229 netstart
--- etc/netstart        5 Nov 2022 12:06:05 -0000       1.229
+++ etc/netstart        24 Nov 2022 01:20:28 -0000
@@ -135,6 +135,17 @@ ifstart() {
        local _if=$1 _hn=/etc/hostname.$1 _cmds _i=0 _line _stat
        set -A _cmds
 
+       # If the _if doesn't look like an interface name,
+       # assume it is an lladdr and look it up.
+       if [[ $_if != +([[:alpha:]])+([[:digit:]]) ]]; then
+               if ! _line="$( ifconfig -M "$_if" )"; then
+                       print -u2 "${0##*/}: unique if for lladdr $_if not 
found."
+                       return
+               fi
+               [[ -n "$_line" ]] && _if=$_line
+               _line=
+       fi
+
        # Interface names must be alphanumeric only.  We check to avoid
        # configuring backup or temp files, and to catch the "*" case.
        [[ $_if != +([[:alpha:]])+([[:digit:]]) ]] && return
@@ -183,14 +194,16 @@ ifmstart() {
        local _sifs=$1 _xifs=$2 _hn _if _sif _xif
 
        for _sif in ${_sifs:-ALL}; do
-               for _hn in /etc/hostname.+([[:alpha:]])+([[:digit:]]); do
+               for _hn in /etc/hostname.*; do
                        [[ -f $_hn ]] || continue
                        _if=${_hn#/etc/hostname.}
 
-                       # Skip unwanted ifs.
-                       for _xif in $_xifs; do
-                               [[ $_xif == ${_if%%[0-9]*} ]] && continue 2
-                       done
+                       if [[ $_if = +([[:alpha:]])+([[:digit:]]) ]]; do
+                               # Skip unwanted ifs.
+                               for _xif in $_xifs; do
+                                       [[ $_xif == ${_if%%[0-9]*} ]] && 
continue 2
+                               done
+                       fi
 
                        # Start wanted ifs.
                        [[ $_sif == @(ALL|${_if%%[0-9]*}) ]] && ifstart $_if

Reply via email to