1#!/bin/sh 2#- 3# Copyright (c) 2011 Nathan Whitehorn
| 1#!/bin/sh 2#- 3# Copyright (c) 2011 Nathan Whitehorn
|
4# All rights reserved.
| |
5# Copyright (c) 2011 The FreeBSD Foundation
| 4# Copyright (c) 2011 The FreeBSD Foundation
|
| 5# Copyright (c) 2013 Devin Teske
|
6# All rights reserved. 7# 8# Portions of this software were developed by Bjoern Zeeb 9# under sponsorship from the FreeBSD Foundation. 10# 11# Redistribution and use in source and binary forms, with or without 12# modification, are permitted provided that the following conditions 13# are met: 14# 1. Redistributions of source code must retain the above copyright 15# notice, this list of conditions and the following disclaimer. 16# 2. Redistributions in binary form must reproduce the above copyright 17# notice, this list of conditions and the following disclaimer in the 18# documentation and/or other materials provided with the distribution. 19# 20# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 21# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 24# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30# SUCH DAMAGE. 31#
| 6# All rights reserved. 7# 8# Portions of this software were developed by Bjoern Zeeb 9# under sponsorship from the FreeBSD Foundation. 10# 11# Redistribution and use in source and binary forms, with or without 12# modification, are permitted provided that the following conditions 13# are met: 14# 1. Redistributions of source code must retain the above copyright 15# notice, this list of conditions and the following disclaimer. 16# 2. Redistributions in binary form must reproduce the above copyright 17# notice, this list of conditions and the following disclaimer in the 18# documentation and/or other materials provided with the distribution. 19# 20# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 21# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 24# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30# SUCH DAMAGE. 31#
|
32# $FreeBSD: stable/10/usr.sbin/bsdinstall/scripts/netconfig_ipv6 225429 2011-09-07 00:45:15Z bz $
| 32# $FreeBSD: stable/10/usr.sbin/bsdinstall/scripts/netconfig_ipv6 258421 2013-11-21 03:40:52Z dteske $ 33# 34############################################################ INCLUDES
|
33
| 35
|
| 36BSDCFG_SHARE="/usr/share/bsdconfig" 37. $BSDCFG_SHARE/common.subr || exit 1 38f_dprintf "%s: loading includes..." "$0" 39f_include $BSDCFG_SHARE/dialog.subr 40 41############################################################ MAIN 42
|
34# 35# TODO: 36# - Add DHCPv6 support once FreeBSD ships with it. 37# 38
| 43# 44# TODO: 45# - Add DHCPv6 support once FreeBSD ships with it. 46# 47
|
39: ${DIALOG_OK=0} 40: ${DIALOG_CANCEL=1} 41: ${DIALOG_HELP=2} 42: ${DIALOG_EXTRA=3} 43: ${DIALOG_ITEM_HELP=4} 44: ${DIALOG_ESC=255} 45
| |
46INTERFACE=$1 47case "${INTERFACE}" in 48"") dialog --backtitle 'FreeBSD Installer' --title 'Network Configuration' \ 49 --msgbox 'No interface specified for IPv6 configuration.' 0 0 50 exit 1 51 ;; 52esac 53 54AGAIN="" 55while : ; do 56 MSG="Would you like to try stateless address autoconfiguration (SLAAC)${AGAIN}?" 57 dialog --backtitle 'FreeBSD Installer' --title 'Network Configuration' \ 58 --yesno "${MSG}" 0 0 59 if [ $? -eq $DIALOG_OK ]; then 60 if [ ! -z $BSDINSTALL_CONFIGCURRENT ]; then 61 dialog --backtitle 'FreeBSD Installer' \ 62 --infobox "Sending Router Solicitation ..." 0 0 63 ifconfig ${INTERFACE} inet6 -ifdisabled accept_rtadv up
| 48INTERFACE=$1 49case "${INTERFACE}" in 50"") dialog --backtitle 'FreeBSD Installer' --title 'Network Configuration' \ 51 --msgbox 'No interface specified for IPv6 configuration.' 0 0 52 exit 1 53 ;; 54esac 55 56AGAIN="" 57while : ; do 58 MSG="Would you like to try stateless address autoconfiguration (SLAAC)${AGAIN}?" 59 dialog --backtitle 'FreeBSD Installer' --title 'Network Configuration' \ 60 --yesno "${MSG}" 0 0 61 if [ $? -eq $DIALOG_OK ]; then 62 if [ ! -z $BSDINSTALL_CONFIGCURRENT ]; then 63 dialog --backtitle 'FreeBSD Installer' \ 64 --infobox "Sending Router Solicitation ..." 0 0 65 ifconfig ${INTERFACE} inet6 -ifdisabled accept_rtadv up
|
64 rtsol -F $INTERFACE 2>> $BSDINSTALL_LOG
| 66 err=$( rtsol -F $INTERFACE 2>&1 )
|
65 if [ $? -ne 0 ]; then
| 67 if [ $? -ne 0 ]; then
|
| 68 f_dprintf "%s" "$err"
|
66 dialog --backtitle 'FreeBSD Installer' --msgbox "SLAAC failed." 0 0 67 AGAIN=" again" 68 continue 69 fi 70 fi 71 echo ifconfig_${INTERFACE}_ipv6=\"inet6 accept_rtadv\" >> $BSDINSTALL_TMPETC/._rc.conf.net 72 exit 0 73 else 74 break 75 fi 76done 77 78ROUTER6=`netstat -Wrn -f inet6 | awk '/default/ {printf("%s\n", $2);}'` 79ADDRS=`ifconfig ${INTERFACE} inet6 | \ 80awk -v dfr="${ROUTER6}" ' 81BEGIN { 82 n=0; 83} 84{ 85 if (/inet6/) { 86 if (match($2, "^fe80:")) { next; }; 87 # For the moment ignore all but the first address; it might confuse the user. 88 if (n > 0) { next; }; 89 n++; 90 printf "\"IPv6 Address\" %d 0 \"%s/%s\" %d 16 50 0 0 ", n, $2, $4, n; 91 } 92} 93END { 94 if (n == 0) { 95 n++; 96 printf "\"IPv6 Address\" %d 0 \"\" %d 16 50 0 0 ", n, n; 97 } 98 n++; 99 # Nasty trick adding a (hidden, same y) read-only field as a marker 100 # to separate interface address(es) from the default router. 101 printf "\"Default Router\" %d 0 \"%s\" %d 16 50 0 2 ", n, "DefaultRouter", n; 102 printf "\"Default Router\" %d 0 \"%s\" %d 16 50 0 0 ", n, dfr, n; 103}'` 104 105exec 3>&1 106IF_CONFIG=$(echo ${ADDRS} | xargs dialog --backtitle 'FreeBSD Installer' \ 107 --title 'Network Configuration' \ 108 --mixedform 'Static IPv6 Network Interface Configuration' 0 0 0 \ 1092>&1 1>&3) 110if [ $? -eq $DIALOG_CANCEL ]; then exit 1; fi 111exec 3>&- 112 113echo ${IF_CONFIG} | tr ' ' '\n' | \ 114awk -v iface="${INTERFACE}" ' 115BEGIN { 116 dfr=0; 117 count=0; 118} 119{ 120 if (/^[[:space:]]+$/) { 121 next; 122 } 123 if (/DefaultRouter/) { 124 dfr=1; 125 next; 126 } 127 if (dfr == 1) { 128 printf("ipv6_defaultrouter=\"%s\"\n", $1); 129 next; 130 } 131 if (count > 0) { 132 # Ignore all but the first IP address for now. 133 next; 134 } 135 count++; 136 if (!match($1, "/")) { 137 sub("$", "/64", $1); 138 } 139 printf("ifconfig_%s_ipv6=\"inet6 %s\"\n", iface, $1); 140}' >> $BSDINSTALL_TMPETC/._rc.conf.net 141 142if [ ! -z $BSDINSTALL_CONFIGCURRENT ]; then 143 . $BSDINSTALL_TMPETC/._rc.conf.net 144 ifconfig ${INTERFACE} `eval echo \\\$ifconfig_${INTERFACE}_ipv6` 145 if [ -n "${ipv6_defaultrouter}" ]; then 146 route delete -inet6 default 147 route add -inet6 default ${ipv6_defaultrouter} 148 fi 149fi 150
| 69 dialog --backtitle 'FreeBSD Installer' --msgbox "SLAAC failed." 0 0 70 AGAIN=" again" 71 continue 72 fi 73 fi 74 echo ifconfig_${INTERFACE}_ipv6=\"inet6 accept_rtadv\" >> $BSDINSTALL_TMPETC/._rc.conf.net 75 exit 0 76 else 77 break 78 fi 79done 80 81ROUTER6=`netstat -Wrn -f inet6 | awk '/default/ {printf("%s\n", $2);}'` 82ADDRS=`ifconfig ${INTERFACE} inet6 | \ 83awk -v dfr="${ROUTER6}" ' 84BEGIN { 85 n=0; 86} 87{ 88 if (/inet6/) { 89 if (match($2, "^fe80:")) { next; }; 90 # For the moment ignore all but the first address; it might confuse the user. 91 if (n > 0) { next; }; 92 n++; 93 printf "\"IPv6 Address\" %d 0 \"%s/%s\" %d 16 50 0 0 ", n, $2, $4, n; 94 } 95} 96END { 97 if (n == 0) { 98 n++; 99 printf "\"IPv6 Address\" %d 0 \"\" %d 16 50 0 0 ", n, n; 100 } 101 n++; 102 # Nasty trick adding a (hidden, same y) read-only field as a marker 103 # to separate interface address(es) from the default router. 104 printf "\"Default Router\" %d 0 \"%s\" %d 16 50 0 2 ", n, "DefaultRouter", n; 105 printf "\"Default Router\" %d 0 \"%s\" %d 16 50 0 0 ", n, dfr, n; 106}'` 107 108exec 3>&1 109IF_CONFIG=$(echo ${ADDRS} | xargs dialog --backtitle 'FreeBSD Installer' \ 110 --title 'Network Configuration' \ 111 --mixedform 'Static IPv6 Network Interface Configuration' 0 0 0 \ 1122>&1 1>&3) 113if [ $? -eq $DIALOG_CANCEL ]; then exit 1; fi 114exec 3>&- 115 116echo ${IF_CONFIG} | tr ' ' '\n' | \ 117awk -v iface="${INTERFACE}" ' 118BEGIN { 119 dfr=0; 120 count=0; 121} 122{ 123 if (/^[[:space:]]+$/) { 124 next; 125 } 126 if (/DefaultRouter/) { 127 dfr=1; 128 next; 129 } 130 if (dfr == 1) { 131 printf("ipv6_defaultrouter=\"%s\"\n", $1); 132 next; 133 } 134 if (count > 0) { 135 # Ignore all but the first IP address for now. 136 next; 137 } 138 count++; 139 if (!match($1, "/")) { 140 sub("$", "/64", $1); 141 } 142 printf("ifconfig_%s_ipv6=\"inet6 %s\"\n", iface, $1); 143}' >> $BSDINSTALL_TMPETC/._rc.conf.net 144 145if [ ! -z $BSDINSTALL_CONFIGCURRENT ]; then 146 . $BSDINSTALL_TMPETC/._rc.conf.net 147 ifconfig ${INTERFACE} `eval echo \\\$ifconfig_${INTERFACE}_ipv6` 148 if [ -n "${ipv6_defaultrouter}" ]; then 149 route delete -inet6 default 150 route add -inet6 default ${ipv6_defaultrouter} 151 fi 152fi 153
|
| 154################################################################################ 155# END 156################################################################################
|
| |