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. Available network interfaces are: vio0 vio1 vio2 vio3 vlan0. Network interface to configure? (name, lladdr, '?', or 'done') [vio0] IPv4 address for vio0? (or 'autoconf' or 'none') [autoconf] none IPv6 address for vio0? (or 'autoconf' or 'none') [none] autoconf Available network interfaces are: vio0 vio1 vio2 vio3 vlan0. Network interface to configure? (name, lladdr, '?', or 'done') [done] ? Available network interfaces are: vio0 vio1 vio2 vio3 vlan0. vio0: lladdr fe:e1:bb:d1:dd:62 vio1: lladdr fe:e1:bb:d2:d2:99 vio2: lladdr fe:e1:bb:d3:2c:eb vio3: lladdr fe:e1:bb:d4:08:54 Network interface to configure? (name, lladdr, '?', or 'done') [done] fe:e1:bb:d1:dd:a2 'fe:e1:bb:d1:dd:a2' is not a valid choice. Available network interfaces are: vio0 vio1 vio2 vio3 vlan0. Network interface to configure? (name, lladdr, '?', or 'done') [done] fe:e1:bb:d1:dd:62 IPv4 address for vio0? (or 'autoconf' or 'none') [autoconf] none IPv6 address for vio0? (or 'autoconf' or 'none') [autoconf] Available network interfaces are: vio0 vio1 vio2 vio3 vlan0. Network interface to configure? (name, lladdr, '?', or 'done') [done] vio1 Symbolic (host) name for vio1? [foo] IPv4 address for vio1? (or 'autoconf' or 'none') [autoconf] none IPv6 address for vio1? (or 'autoconf' or 'none') [none] autoconf Available network interfaces are: vio0 vio1 vio2 vio3 vlan0. Network interface to configure? (name, lladdr, '?', or 'done') [done] ! Type 'exit' to return to install. foo# grep . /tmp/i/hostname.* /tmp/i/hostname.fe:e1:bb:d1:dd:62:inet6 autoconf /tmp/i/hostname.vio1:inet6 autoconf foo# exit Network interface to configure? (name, lladdr, '?', or 'done') [done] vio0 IPv4 address for vio0? (or 'autoconf' or 'none') [autoconf] none IPv6 address for vio0? (or 'autoconf' or 'none') [autoconf] Available network interfaces are: vio0 vio1 vio2 vio3 vlan0. Network interface to configure? (name, lladdr, '?', or 'done') [done] ! Type 'exit' to return to install. foo# grep . /tmp/i/hostname.* /tmp/i/hostname.vio0:inet6 autoconf /tmp/i/hostname.vio1:inet6 autoconf 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 8 Dec 2022 03:22:07 -0000 @@ -356,6 +356,24 @@ 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 | sed -n 's/^[[:space:]]*lladdr[[:space:]]//p') + [[ -n $_lladdr && -n $(ifconfig -M $_lladdr) ]] && echo $_lladdr +} + +# Prints a list of interface names and lladdr from if_name_to_lladdr +# to allow validating how we're allowed to configure 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 @@ -1291,7 +1309,8 @@ ieee80211_config() { # Set up IPv4 and IPv6 interface configuration. configure_ifs() { - local _first _hn _if _name _p _vi _vn + local _first _hn _if _name _p _q _vi _vn + resp= # Always need lo0 configured. ifconfig lo0 inet 127.0.0.1/8 @@ -1306,14 +1325,48 @@ 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 )'} - [[ $resp == done ]] && break + set -- $(get_ifs) $_vn; _q="$*" + echo "Available network interfaces are: $_q." + if [[ $resp = \? ]]; then + for _if in $(get_ifs); do + _name=$(if_name_to_lladdr $_if) + [[ -n $_name ]] && echo " $_if: lladdr $_name" + done + _if= + _name= + 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 + # and remove any config for this interface by another name + if [[ $_if == ??:??:??:??:??:?? ]]; then + _if=$(ifconfig -M $_if) + [[ -z $_if ]] && continue # should not be possible + rm -f /tmp/i/hostname.$_if + else + _name=$(if_name_to_lladdr $_if) + [[ -n $_name ]] && rm -f /tmp/i/hostname.$_name + _name= + fi # If the offered vlan is chosen, ask the relevant # questions and bring it up.