On Tue, Dec 13, 2022 at 09:16:16AM -0700, Theo de Raadt wrote:
> My gut feeling is that hostname.laddr should be given priority over
> hostname.if, because it is a more precise and enduring match.

I agree.

Reading the following in the manual diff striked me as counter-intuitive
for this very reason:

     Priority is given to configuration by interface name/number over lladdr.

MAC can be unique and if that is the much more defining property of a
specific interface I chose to identify it with, .lladdr should win.

> 
> Andrew Hewus Fresh <and...@afresh1.com> wrote:
> 
> > This would be the diff to swap priority of name/lladdr as some folks
> > wanted to see.  I still don't recommend having both as you can still
> > have surprising outcomes with more complex configurations.
> > 
> > The install.sub includes an "if_name_to_lladdr" function from the
> > diff to support creating a hostname.lladdr during install.  If we don't
> > decide to support that, I'd probably in-line that as is done in
> > netstart.
> > 
> > I did find that my iwm doesn't like being configured by lladdr at this
> > point of the upgrade  because it doesn't have firmware loaded when it's
> > looking to see if it's a valid hostname.lladdr, but the iwm's lladdr is
> > all zeros still.
> > 
> > 
> > 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    11 Dec 2022 20:44:34 -0000
> > @@ -144,11 +144,14 @@ ifstart() {
> >             [[ -z $_line ]] && return
> >             _if=$_line
> >             _line=
> > -
> > -           if [[ -e /etc/hostname.$_if ]]; then
> > -                   print -u2 "${0##*/}: $_hn: /etc/hostname.$_if overrides"
> > +   else
> > +           _line=$(ifconfig $_if | sed -n 
> > 's/^[[:space:]]*lladdr[[:space:]]//p')
> > +           if [[ -n $_line && -n $(ifconfig -M $_line) \
> > +              && -e /etc/hostname.$_line ]]; then
> > +                   print -u2 "${0##*/}: $_hn: /etc/hostname.$_line: 
> > overrides"
> >                     return
> >             fi
> > +           _line=
> >     fi
> >  
> >     # Interface names must be alphanumeric only.  We check to avoid
> > Index: distrib/miniroot/install.sub
> > ===================================================================
> > RCS file: /cvs/src/distrib/miniroot/install.sub,v
> > retrieving revision 1.1215
> > diff -u -p -r1.1215 install.sub
> > --- distrib/miniroot/install.sub    5 Dec 2022 20:12:00 -0000       1.1215
> > +++ distrib/miniroot/install.sub    11 Dec 2022 20:44:34 -0000
> > @@ -356,6 +356,15 @@ get_ifs() {
> >     done
> >  }
> >  
> > +# Maps an interface name to lladdr,                                        
> >     
> > +# filtered by whether it's valid for use by ifconfig -M
> > +if_name_to_lladdr() {          
> > +   local _lladdr     
> > +   _lladdr=$(ifconfig $1 2>/dev/null |
> > +       sed -n 's/^[[:space:]]*lladdr[[:space:]]//p')
> > +   [[ -n $_lladdr && -n $(ifconfig -M $_lladdr) ]] && echo $_lladdr
> > +}                                                                          
> >     
> > +
> >  # Return the device name of the disk device $1, which may be a disklabel 
> > UID.
> >  get_dkdev_name() {
> >     local _dev=${1#/dev/} _d
> > @@ -2434,7 +2443,10 @@ ifstart() {
> >     if [[ $_if == ??:??:??:??:??:?? ]]; then
> >             _if=$(ifconfig -M $_if)
> >             [[ -z $_if ]]                   && return # invalid interface
> > -           [[ -e /mnt/etc/hostname.$_if ]] && return # duplicate config
> > +   else
> > +           _line=$(if_name_to_lladdr $_if)
> > +           [[ -n $_line && -e /mnt/etc/hostname.$_line ]] && continue
> > +           _line=
> >     fi
> >  
> >     # Create interface if it does not yet exist.
> > Index: share/man/man5/hostname.if.5
> > ===================================================================
> > RCS file: /cvs/src/share/man/man5/hostname.if.5,v
> > retrieving revision 1.80
> > diff -u -p -r1.80 hostname.if.5
> > --- share/man/man5/hostname.if.5    5 Dec 2022 20:12:00 -0000       1.80
> > +++ share/man/man5/hostname.if.5    11 Dec 2022 20:44:34 -0000
> > @@ -46,7 +46,7 @@ The interface can be referenced by name 
> >  or
> >  .Pa hostname.bridge0 .
> >  One file should exist for each interface that is to be configured,
> > -with priority given to configuration by interface name over lladdr.
> > +with priority given to configuration by interface lladdr over  name.
> >  A configuration file is not needed for lo0.
> >  .Pp
> >  The configuration information is expressed in a line-by-line packed format
> > 
> 

Reply via email to