On Wed, Nov 23, 2022 at 05:28:35PM -0800, Andrew Hewus Fresh wrote: > 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. Theo had some suggestions, one obvious one is that we can at least filter for only /etc/hostname.*:* and ignore anything without a :, as it can't be a mac address. The other, that if both exist, /etc/hostname.$if will override /etc/hostname.$lladdr.
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 02:10:51 -0000 @@ -135,6 +135,23 @@ ifstart() { local _if=$1 _hn=/etc/hostname.$1 _cmds _i=0 _line _stat set -A _cmds + # If the _if has a :, assume it is an lladdr and look it up. + if [[ $_if = *:* ]]; then + if ! _line="$( ifconfig -M "$_if" )"; then + print -u2 "${0##*/}: unique if for lladdr $_if not found." + return + fi + + [[ -z "$_line" ]] && return + _if=$_line + _line= + + if [[ -e /etc/hostname.$_if ]]; then + print -u2 "${0##*/}: $_hn: /etc/hostname.$_if overrides" + return + fi + 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 +200,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.@(+([[:alpha:]])+([[:digit:]])|*:*); 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:]]) ]]; then + # 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