On Wed, Dec 07, 2022 at 07:35:53PM -0800, Andrew Hewus Fresh wrote:
> On Wed, Dec 07, 2022 at 09:51:51AM -0800, Andrew Hewus Fresh wrote:
> > On Wed, Dec 07, 2022 at 10:28:05AM +0000, Stuart Henderson wrote:
> > > On 2022/12/06 19:57, Andrew Hewus Fresh wrote:
> > > > Which interface do you wish to configure? (name, lladdr, '?', or 
> > > > 'done') [vio0] ?
> > > > Available network interfaces are: vio0 vlan0.
> > > >  vio0: lladdr fe:e1:bb:d1:dd:97
> > > > Which interface do you wish to configure? (name, lladdr, '?', or 
> > > > 'done') [vio0] fe:e1:bb:d1:dd:97
> > > > IPv4 address for vio0? (or 'autoconf' or 'none') [autoconf] 
> > > > IPv6 address for vio0? (or 'autoconf' or 'none') [none] 
> > > > Available network interfaces are: vio0 vlan0.
> > > 
> > > It doesn't seem right to offer vio0 in the list if it was already
> > > configured via lladdr?
> > 
> > The installer currently allows re-configuring interfaces and deletes the
> > hostname.if before doing it.  I think the most useful solution is to
> > check for "the other" configuration for that interface and remove it as
> > well when reconfiguring.
> 
> Here's the next version that cleans up hostname.lladdr when configuring
> by name and hostname.name when configuring by lladdr.
 
This version is mostly just rebasing onto the recent changes to swap
priority.  There is a little  tidying of variables and such mixed in.


Index: distrib/miniroot/install.sub
===================================================================
RCS file: /cvs/src/distrib/miniroot/install.sub,v
retrieving revision 1.1216
diff -u -p -r1.1216 install.sub
--- distrib/miniroot/install.sub        16 Dec 2022 04:04:25 -0000      1.1216
+++ distrib/miniroot/install.sub        16 Dec 2022 23:59:39 -0000
@@ -365,6 +365,16 @@ if_name_to_lladdr() {          
        [[ -n $_lladdr && -n $(ifconfig -M "$_lladdr") ]] && echo $_lladdr
 }                                                                              
 
+# Print a list of interface names and lladdr for validating allowed interfaces.
+get_ifs_and_lladdrs() {
+       local _if
+
+       for _if in $(get_ifs); do
+               echo $_if
+               if_name_to_lladdr $_if
+       done
+}
+
 # Return the device name of the disk device $1, which may be a disklabel UID.
 get_dkdev_name() {
        local _dev=${1#/dev/} _d
@@ -1300,7 +1310,8 @@ ieee80211_config() {
 
 # Set up IPv4 and IPv6 interface configuration.
 configure_ifs() {
-       local _first _hn _if _name _p _vi _vn
+       local _first _hn _if _lladdr _name _p _q _vi _vn
+       resp=
 
        # Always need lo0 configured.
        ifconfig lo0 inet 127.0.0.1/8
@@ -1315,14 +1326,46 @@ configure_ifs() {
                [[ -n $_vi ]] && ((_vi++))
                [[ -n $(get_ifs) ]] && _vn="vlan${_vi:-0}"
 
-               ask_which "network interface" "do you wish to configure" \
-                       "\$(get_ifs) $_vn" \
-                       ${_p:-'$( (get_ifs netboot; get_ifs) | sed q )'}
+               set -- $(get_ifs) $_vn; _q="$*"
+               echo "Available network interfaces are: $_q."
+               if [[ $resp == \? ]]; then
+                       for _if in $(get_ifs); do
+                               _lladdr=$(if_name_to_lladdr $_if)
+                               [[ -n $_lladdr ]] && echo " $_if: lladdr 
$_lladdr"
+                       done
+               fi
+
+               _q="Network interface to configure?"
+               ask_until "$_q (name, lladdr, '?', or 'done')" \
+                   ${_p:-$( (get_ifs netboot; get_ifs) | sed q )}
+
                [[ $resp == done ]] && break
+               [[ $resp == \?   ]] && continue
+
+               # Quote $resp to prevent user from confusing isin() by
+               # entering something like 'a a'.
+               if ! isin "$resp" $(get_ifs_and_lladdrs) $_vn done; then
+                       echo "'$resp' is not a valid choice."
+                       $AI && [[ -n $AI_RESPFILE ]] && exit 1
+                       continue
+               fi
 
                _if=$resp
                _hn=/tmp/i/hostname.$_if
                rm -f $_hn
+
+               # Test if we're configuring by lladdr
+               # If we are, map it to the interface name
+               # in either case remove the other config for this interface
+               if [[ $_if == ??:??:??:??:??:?? ]]; then
+                       _lladdr=$_if
+                       _if=$(ifconfig -M $_lladdr)
+                       [[ -z $_if ]] && continue # should not be possible
+                       rm -f /tmp/i/hostname.$_if
+               else
+                       _lladdr=$(if_name_to_lladdr $_if)
+                       [[ -n $_lladdr ]] && rm -f /tmp/i/hostname.$_lladdr
+               fi
 
                # If the offered vlan is chosen, ask the relevant
                # questions and bring it up.

Reply via email to