1 7986af23SBjoern A. Zeeb#!/bin/sh 2 7986af23SBjoern A. Zeeb#- 3 7986af23SBjoern A. Zeeb# Copyright (c) 2011 Nathan Whitehorn 4 7986af23SBjoern A. Zeeb# Copyright (c) 2011 The FreeBSD Foundation 5 5e1ed71eSDevin Teske# Copyright (c) 2013-2015 Devin Teske 6 7986af23SBjoern A. Zeeb# All rights reserved. 7 7986af23SBjoern A. Zeeb# 8 7986af23SBjoern A. Zeeb# Portions of this software were developed by Bjoern Zeeb 9 7986af23SBjoern A. Zeeb# under sponsorship from the FreeBSD Foundation. 10 7986af23SBjoern A. Zeeb# 11 7986af23SBjoern A. Zeeb# Redistribution and use in source and binary forms, with or without 12 7986af23SBjoern A. Zeeb# modification, are permitted provided that the following conditions 13 7986af23SBjoern A. Zeeb# are met: 14 7986af23SBjoern A. Zeeb# 1. Redistributions of source code must retain the above copyright 15 7986af23SBjoern A. Zeeb# notice, this list of conditions and the following disclaimer. 16 7986af23SBjoern A. Zeeb# 2. Redistributions in binary form must reproduce the above copyright 17 7986af23SBjoern A. Zeeb# notice, this list of conditions and the following disclaimer in the 18 7986af23SBjoern A. Zeeb# documentation and/or other materials provided with the distribution. 19 7986af23SBjoern A. Zeeb# 20 7986af23SBjoern A. Zeeb# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 21 7986af23SBjoern A. Zeeb# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 7986af23SBjoern A. Zeeb# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 7986af23SBjoern A. Zeeb# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 24 7986af23SBjoern A. Zeeb# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 7986af23SBjoern A. Zeeb# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 7986af23SBjoern A. Zeeb# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 7986af23SBjoern A. Zeeb# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 7986af23SBjoern A. Zeeb# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 7986af23SBjoern A. Zeeb# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 7986af23SBjoern A. Zeeb# SUCH DAMAGE. 31 7986af23SBjoern A. Zeeb# 32 bc4a673fSDevin Teske# 33 bc4a673fSDevin Teske############################################################ INCLUDES 34 bc4a673fSDevin Teske 35 bc4a673fSDevin TeskeBSDCFG_SHARE="/usr/share/bsdconfig" 36 bc4a673fSDevin Teske. $BSDCFG_SHARE/common.subr || exit 1 37 bc4a673fSDevin Teskef_dprintf "%s: loading includes..." "$0" 38 bc4a673fSDevin Teskef_include $BSDCFG_SHARE/dialog.subr 39 bc4a673fSDevin Teske 40 bc4a673fSDevin Teske############################################################ MAIN 41 7986af23SBjoern A. Zeeb 42 58c63d5eSAlfonso S. Siciliano: ${BSDDIALOG_OK=0} 43 58c63d5eSAlfonso S. Siciliano: ${BSDDIALOG_CANCEL=1} 44 58c63d5eSAlfonso S. Siciliano 45 7986af23SBjoern A. Zeeb# 46 7986af23SBjoern A. Zeeb# TODO: 47 7986af23SBjoern A. Zeeb# - Add DHCPv6 support once FreeBSD ships with it. 48 7986af23SBjoern A. Zeeb# 49 7986af23SBjoern A. Zeeb 50 7986af23SBjoern A. ZeebINTERFACE=$1 51 *c994f226SJessica ClarkeAUTO="${2:-}" 52 7986af23SBjoern A. Zeebcase "${INTERFACE}" in 53 cc42ef53SBrad Davis"") bsddialog --backtitle "$OSNAME Installer" --title 'Network Configuration' \ 54 7986af23SBjoern A. Zeeb --msgbox 'No interface specified for IPv6 configuration.' 0 0 55 7986af23SBjoern A. Zeeb exit 1 56 7986af23SBjoern A. Zeeb ;; 57 7986af23SBjoern A. Zeebesac 58 *c994f226SJessica Clarkecase "$AUTO" in 59 *c994f226SJessica Clarke""|auto) 60 *c994f226SJessica Clarke ;; 61 *c994f226SJessica Clarke*) 62 *c994f226SJessica Clarke bsddialog --backtitle "$OSNAME Installer" --title 'Network Configuration' \ 63 *c994f226SJessica Clarke --msgbox "Bad auto option '$AUTO'." 0 0 64 *c994f226SJessica Clarke exit 1 65 *c994f226SJessica Clarke ;; 66 *c994f226SJessica Clarkeesac 67 7986af23SBjoern A. Zeeb 68 7986af23SBjoern A. ZeebAGAIN="" 69 7986af23SBjoern A. Zeebwhile : ; do 70 *c994f226SJessica Clarke if [ -n "$AUTO" ]; then 71 *c994f226SJessica Clarke SLAAC=1 72 *c994f226SJessica Clarke else 73 7986af23SBjoern A. Zeeb MSG="Would you like to try stateless address autoconfiguration (SLAAC)${AGAIN}?" 74 cc42ef53SBrad Davis bsddialog --backtitle "$OSNAME Installer" --title 'Network Configuration' \ 75 7986af23SBjoern A. Zeeb --yesno "${MSG}" 0 0 76 58c63d5eSAlfonso S. Siciliano if [ $? -eq $BSDDIALOG_OK ]; then 77 *c994f226SJessica Clarke SLAAC=1 78 *c994f226SJessica Clarke else 79 *c994f226SJessica Clarke SLAAC=0 80 *c994f226SJessica Clarke fi 81 *c994f226SJessica Clarke fi 82 *c994f226SJessica Clarke if [ $SLAAC -eq 1 ]; then 83 7986af23SBjoern A. Zeeb if [ ! -z $BSDINSTALL_CONFIGCURRENT ]; then 84 cc42ef53SBrad Davis bsddialog --backtitle "$OSNAME Installer" \ 85 7986af23SBjoern A. Zeeb --infobox "Sending Router Solicitation ..." 0 0 86 f07f97beSBjoern A. Zeeb ifconfig ${INTERFACE} inet6 -ifdisabled accept_rtadv up 87 bc4a673fSDevin Teske err=$( rtsol -F $INTERFACE 2>&1 ) 88 7986af23SBjoern A. Zeeb if [ $? -ne 0 ]; then 89 bc4a673fSDevin Teske f_dprintf "%s" "$err" 90 *c994f226SJessica Clarke if [ -n "$AUTO" ]; then 91 *c994f226SJessica Clarke exit 1 92 *c994f226SJessica Clarke fi 93 cc42ef53SBrad Davis bsddialog --backtitle "$OSNAME Installer" --msgbox "SLAAC failed." 0 0 94 7986af23SBjoern A. Zeeb AGAIN=" again" 95 7986af23SBjoern A. Zeeb continue 96 7986af23SBjoern A. Zeeb fi 97 7986af23SBjoern A. Zeeb fi 98 1e75e61dSJessica Clarke sysrc -f $BSDINSTALL_TMPETC/._rc.conf.net ifconfig_${INTERFACE}_ipv6="inet6 accept_rtadv" 99 7986af23SBjoern A. Zeeb exit 0 100 7986af23SBjoern A. Zeeb else 101 7986af23SBjoern A. Zeeb break 102 7986af23SBjoern A. Zeeb fi 103 7986af23SBjoern A. Zeebdone 104 7986af23SBjoern A. Zeeb 105 7986af23SBjoern A. ZeebROUTER6=`netstat -Wrn -f inet6 | awk '/default/ {printf("%s\n", $2);}'` 106 7986af23SBjoern A. ZeebADDRS=`ifconfig ${INTERFACE} inet6 | \ 107 7986af23SBjoern A. Zeebawk -v dfr="${ROUTER6}" ' 108 7986af23SBjoern A. ZeebBEGIN { 109 7986af23SBjoern A. Zeeb n=0; 110 7986af23SBjoern A. Zeeb} 111 7986af23SBjoern A. Zeeb{ 112 7986af23SBjoern A. Zeeb if (/inet6/) { 113 7986af23SBjoern A. Zeeb if (match($2, "^fe80:")) { next; }; 114 7986af23SBjoern A. Zeeb # For the moment ignore all but the first address; it might confuse the user. 115 7986af23SBjoern A. Zeeb if (n > 0) { next; }; 116 7986af23SBjoern A. Zeeb n++; 117 58c63d5eSAlfonso S. Siciliano printf "\"IPv6 Address\" %d 1 \"%s/%s\" %d 16 50 50 0 ", n, $2, $4, n; 118 7986af23SBjoern A. Zeeb } 119 7986af23SBjoern A. Zeeb} 120 7986af23SBjoern A. ZeebEND { 121 7986af23SBjoern A. Zeeb if (n == 0) { 122 7986af23SBjoern A. Zeeb n++; 123 58c63d5eSAlfonso S. Siciliano printf "\"IPv6 Address\" %d 1 \"\" %d 16 50 50 0 ", n, n; 124 7986af23SBjoern A. Zeeb } 125 7986af23SBjoern A. Zeeb n++; 126 7986af23SBjoern A. Zeeb # Nasty trick adding a (hidden, same y) read-only field as a marker 127 7986af23SBjoern A. Zeeb # to separate interface address(es) from the default router. 128 58c63d5eSAlfonso S. Siciliano printf "\"Default Router\" %d 1 \"%s\" %d 1 14 14 2 ", n, "DefaultRouter", n; 129 58c63d5eSAlfonso S. Siciliano printf "\"Default Router\" %d 1 \"%s\" %d 16 50 50 0 ", n, dfr, n; 130 7986af23SBjoern A. Zeeb}'` 131 7986af23SBjoern A. Zeeb 132 c0e249d3SLars Kellogg-Stedmanexec 5>&1 133 cc42ef53SBrad DavisIF_CONFIG=$(echo ${ADDRS} | xargs -o bsddialog --backtitle "$OSNAME Installer" \ 134 7986af23SBjoern A. Zeeb --title 'Network Configuration' \ 135 7986af23SBjoern A. Zeeb --mixedform 'Static IPv6 Network Interface Configuration' 0 0 0 \ 136 c0e249d3SLars Kellogg-Stedman2>&1 1>&5) 137 58c63d5eSAlfonso S. Sicilianoif [ $? -eq $BSDDIALOG_CANCEL ]; then exit 1; fi 138 c0e249d3SLars Kellogg-Stedmanexec 5>&- 139 7986af23SBjoern A. Zeeb 140 7986af23SBjoern A. Zeebecho ${IF_CONFIG} | tr ' ' '\n' | \ 141 7986af23SBjoern A. Zeebawk -v iface="${INTERFACE}" ' 142 7986af23SBjoern A. ZeebBEGIN { 143 7986af23SBjoern A. Zeeb dfr=0; 144 7986af23SBjoern A. Zeeb count=0; 145 7986af23SBjoern A. Zeeb} 146 7986af23SBjoern A. Zeeb{ 147 7986af23SBjoern A. Zeeb if (/^[[:space:]]+$/) { 148 7986af23SBjoern A. Zeeb next; 149 7986af23SBjoern A. Zeeb } 150 7986af23SBjoern A. Zeeb if (/DefaultRouter/) { 151 7986af23SBjoern A. Zeeb dfr=1; 152 7986af23SBjoern A. Zeeb next; 153 7986af23SBjoern A. Zeeb } 154 7986af23SBjoern A. Zeeb if (dfr == 1) { 155 7986af23SBjoern A. Zeeb printf("ipv6_defaultrouter=\"%s\"\n", $1); 156 7986af23SBjoern A. Zeeb next; 157 7986af23SBjoern A. Zeeb } 158 7986af23SBjoern A. Zeeb if (count > 0) { 159 7986af23SBjoern A. Zeeb # Ignore all but the first IP address for now. 160 7986af23SBjoern A. Zeeb next; 161 7986af23SBjoern A. Zeeb } 162 7986af23SBjoern A. Zeeb count++; 163 7986af23SBjoern A. Zeeb if (!match($1, "/")) { 164 7986af23SBjoern A. Zeeb sub("$", "/64", $1); 165 7986af23SBjoern A. Zeeb } 166 7986af23SBjoern A. Zeeb printf("ifconfig_%s_ipv6=\"inet6 %s\"\n", iface, $1); 167 d63d020eSBjoern A. Zeeb}' >> $BSDINSTALL_TMPETC/._rc.conf.net 168 5e1ed71eSDevin Teskeretval=$? 169 7986af23SBjoern A. Zeeb 170 5e1ed71eSDevin Teskeif [ "$BSDINSTALL_CONFIGCURRENT" ]; then 171 d63d020eSBjoern A. Zeeb . $BSDINSTALL_TMPETC/._rc.conf.net 172 7986af23SBjoern A. Zeeb ifconfig ${INTERFACE} `eval echo \\\$ifconfig_${INTERFACE}_ipv6` 173 5e1ed71eSDevin Teske if [ "$ipv6_defaultrouter" ]; then 174 5b046b47SBjoern A. Zeeb route delete -inet6 default 175 5b046b47SBjoern A. Zeeb route add -inet6 default ${ipv6_defaultrouter} 176 5e1ed71eSDevin Teske retval=$? 177 5b046b47SBjoern A. Zeeb fi 178 7986af23SBjoern A. Zeebfi 179 7986af23SBjoern A. Zeeb 180 5e1ed71eSDevin Teskeexit $retval 181 5e1ed71eSDevin Teske 182 bc4a673fSDevin Teske################################################################################ 183 bc4a673fSDevin Teske# END 184 bc4a673fSDevin Teske################################################################################ 185