diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2019-05-11 19:11:20 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2019-05-11 19:11:20 +0000 |
commit | 839b7735f1a612d4b57d5f3fe76b69821dab3b6e (patch) | |
tree | 6e7613e52bb7608a209e2c766fd174d677c9eb5d /distrib/miniroot | |
parent | 1ea7e2611ddb7df3a218700be540f40150b43eab (diff) |
Repair and improve v6 default route selection.
Should fix autoinstalls, suppress pointless questions, allow section
of 'none' via a number, etc.
Issues first reported by reyk@
Testing & ok florian
Diffstat (limited to 'distrib/miniroot')
-rw-r--r-- | distrib/miniroot/install.sub | 48 |
1 files changed, 33 insertions, 15 deletions
diff --git a/distrib/miniroot/install.sub b/distrib/miniroot/install.sub index 3cd3b55cef5..6128c28ad4f 100644 --- a/distrib/miniroot/install.sub +++ b/distrib/miniroot/install.sub @@ -1,5 +1,5 @@ #!/bin/ksh -# $OpenBSD: install.sub,v 1.1131 2019/05/10 20:47:54 reyk Exp $ +# $OpenBSD: install.sub,v 1.1132 2019/05/11 19:11:19 krw Exp $ # # Copyright (c) 1997-2015 Todd Miller, Theo de Raadt, Ken Westerback # Copyright (c) 2015, Robert Peichaer <rpe@openbsd.org> @@ -1067,33 +1067,51 @@ v6_info() { # in the /etc/mygate file. Ask the user to either select from a list of default # router candidates or to enter a router IPv6 address. v6_defroute() { - local _if _prompt _resp _routers PS3 + local _if _v6ifs _prompt _resp _routers _dr PS3 - # Get a sorted, unique list of default router canditates by issuing a - # ping6 to the All-Routers multicast address on each interface that - # is not AUTOCONF6. + # Only configure a default route if an IPv6 address was manually configured. for _if in $(get_ifs); do set -- $(v6_info $_if) - [[ -n $2 && $1 != *AUTOCONF6* ]] || continue + [[ -z $2 || $1 == *AUTOCONF6* ]] || _v6ifs="$_v6ifs $_if" + done + [[ -n $_v6ifs ]] || return + + # Start with any existing default routes. + _routers=$(route -n show -inet6 | + sed -En 's/^default[[:space:]]+([^[:space:]]+).*/\1 /p') + + # Add more default router canditates by ping6'ing + # the All-Routers multicast address. + for _if in $_v6ifs; do _resp=$(ping6 -n -c 2 ff02::2%$_if 2>/dev/null | sed -En '/^[0-9]+ bytes from /{s///;s/: .*$//p;}') - _routers=$(bsort $_routers $_resp) + for _dr in $_resp; do + _routers=$(addel $_dr $_routers) + done done + [[ -n $_routers ]] && _routers=$(bsort $_routers) _prompt="IPv6 default router?" if $AI; then - _autorespond "$_prompt" && _resp=$resp && echo "$_prompt $_resp" + _autorespond "$_prompt (IPv6 address or 'none')" none && + echo "$_prompt $resp" + [[ $resp != none ]] && + route -n add -inet6 -host default $resp && + echo $resp >>/tmp/i/mygate else - PS3="$_prompt (${_routers:+list #, }IPv6 address or 'none'): " - select _resp in $_routers; do - [[ ${_resp:=$REPLY} == *:* ]] && break - [[ $_resp == none ]] && return + PS3="$_prompt (list #, IPv6 address or 'none') " + select _resp in none $_routers; do + [[ $REPLY == none || $_resp == none ]] && break + [[ -z $_resp ]] && _resp=$REPLY + # Avoid possible "file exists" errors + route -n -q delete -inet6 -host default $_resp + if route -n add -inet6 -host default $_resp; then + echo $_resp >>/tmp/i/mygate + break + fi done fi - - route -n add -inet6 -host default "$_resp" && - echo "$_resp" >>/tmp/i/mygate } # Configure IPv6 interface $1, add hostname $2 to the hosts file, |