On Fri, Dec 16, 2022 at 04:00:40PM -0800, Andrew Hewus Fresh wrote:
> 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.
Just a couple of minor tidies and such, avoiding some weird constructs
and extra execs. Some tweaks from kn@.
Index: distrib/miniroot/install.sub
===================================================================
RCS file: /cvs/src/distrib/miniroot/install.sub,v
retrieving revision 1.1217
diff -u -p -r1.1217 install.sub
--- distrib/miniroot/install.sub 16 Dec 2022 17:47:34 -0000 1.1217
+++ distrib/miniroot/install.sub 21 Dec 2022 04:05:42 -0000
@@ -356,7 +356,7 @@ get_ifs() {
done
}
-# Map an interface to its MAC address if it is unique
+# Map an interface to its MAC address if it is unique.
if_name_to_lladdr() {
local _lladdr
@@ -365,6 +365,16 @@ if_name_to_lladdr() {
[[ -n $_lladdr && -n $(ifconfig -M "$_lladdr") ]] && echo $_lladdr
}
+# Print a list of interface names and unique lladdr.
+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 _ifs _lladdr _name _p _q _vi _vn
+ resp=
# Always need lo0 configured.
ifconfig lo0 inet 127.0.0.1/8
@@ -1309,20 +1320,55 @@ configure_ifs() {
rm -f /tmp/i/mygate
while :; do
+ set -sA _ifs -- $(get_ifs)
+
# Discover last configured vlan interface and increment its
# minor for the next offered vlan interface.
- _vi=$(get_ifs vlan | sed '$!d;s/^vlan//')
+ _vi=
+ for _if in "${_ifs[@]}"; do
+ [[ $_if = vlan+([[:digit:]]) ]] && _vi=${_if#vlan}
+ done
[[ -n $_vi ]] && ((_vi++))
- [[ -n $(get_ifs) ]] && _vn="vlan${_vi:-0}"
+ [[ -n ${_ifs[*]} ]] && _vn="vlan${_vi:-0}"
+
+ echo "Available network interfaces are: ${_ifs[*]} $_vn."
+ if [[ $resp == '?' ]]; then
+ for _if in "${_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 )}
- ask_which "network interface" "do you wish to configure" \
- "\$(get_ifs) $_vn" \
- ${_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
+
+ # Map lladdr to interface name if needed
+ # and remove duplicate configuration.
+ 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.