xref: /freebsd/usr.sbin/bsdinstall/scripts/netconfig_ipv6 (revision 7986af23a4b078a4fa1a7a38a05916e814c8e87c)
1*7986af23SBjoern A. Zeeb#!/bin/sh
2*7986af23SBjoern A. Zeeb#-
3*7986af23SBjoern A. Zeeb# Copyright (c) 2011 Nathan Whitehorn
4*7986af23SBjoern A. Zeeb# All rights reserved.
5*7986af23SBjoern A. Zeeb# Copyright (c) 2011 The FreeBSD Foundation
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*7986af23SBjoern A. Zeeb# $FreeBSD$
33*7986af23SBjoern A. Zeeb
34*7986af23SBjoern A. Zeeb#
35*7986af23SBjoern A. Zeeb# TODO:
36*7986af23SBjoern A. Zeeb# - Add -R /sbin/resolvconf to rtsol once support is in tree.
37*7986af23SBjoern A. Zeeb# - Add DHCPv6 support once FreeBSD ships with it.
38*7986af23SBjoern A. Zeeb#
39*7986af23SBjoern A. Zeeb
40*7986af23SBjoern A. Zeeb: ${DIALOG_OK=0}
41*7986af23SBjoern A. Zeeb: ${DIALOG_CANCEL=1}
42*7986af23SBjoern A. Zeeb: ${DIALOG_HELP=2}
43*7986af23SBjoern A. Zeeb: ${DIALOG_EXTRA=3}
44*7986af23SBjoern A. Zeeb: ${DIALOG_ITEM_HELP=4}
45*7986af23SBjoern A. Zeeb: ${DIALOG_ESC=255}
46*7986af23SBjoern A. Zeeb
47*7986af23SBjoern A. ZeebINTERFACE=$1
48*7986af23SBjoern A. Zeebcase "${INTERFACE}" in
49*7986af23SBjoern A. Zeeb"")	dialog --backtitle 'FreeBSD Installer' --title 'Network Configuration' \
50*7986af23SBjoern A. Zeeb	    --msgbox 'No interface specified for IPv6 configuration.' 0 0
51*7986af23SBjoern A. Zeeb	exit 1
52*7986af23SBjoern A. Zeeb	;;
53*7986af23SBjoern A. Zeebesac
54*7986af23SBjoern A. Zeeb
55*7986af23SBjoern A. ZeebAGAIN=""
56*7986af23SBjoern A. Zeebwhile : ; do
57*7986af23SBjoern A. Zeeb	MSG="Would you like to try stateless address autoconfiguration (SLAAC)${AGAIN}?"
58*7986af23SBjoern A. Zeeb	dialog --backtitle 'FreeBSD Installer' --title 'Network Configuration' \
59*7986af23SBjoern A. Zeeb	    --yesno "${MSG}" 0 0
60*7986af23SBjoern A. Zeeb	if [ $? -eq $DIALOG_OK ]; then
61*7986af23SBjoern A. Zeeb		if [ ! -z $BSDINSTALL_CONFIGCURRENT ]; then
62*7986af23SBjoern A. Zeeb			dialog --backtitle 'FreeBSD Installer' \
63*7986af23SBjoern A. Zeeb			    --infobox "Sending Router Solicitation ..." 0 0
64*7986af23SBjoern A. Zeeb			ifconfig ${INTERFACE} inet6 accept_rtadv up
65*7986af23SBjoern A. Zeeb			rtsol -F $INTERFACE 2>> $BSDINSTALL_LOG
66*7986af23SBjoern A. Zeeb			if [ $? -ne 0 ]; then
67*7986af23SBjoern A. Zeeb				dialog --backtitle 'FreeBSD Installer' --msgbox "SLAAC failed." 0 0
68*7986af23SBjoern A. Zeeb				AGAIN=" again"
69*7986af23SBjoern A. Zeeb				continue
70*7986af23SBjoern A. Zeeb			fi
71*7986af23SBjoern A. Zeeb		fi
72*7986af23SBjoern A. Zeeb		echo ifconfig_${INTERFACE}_ipv6=\"accept_rtadv\" >> $BSDINSTALL_TMPETC/rc.conf.net
73*7986af23SBjoern A. Zeeb		exit 0
74*7986af23SBjoern A. Zeeb	else
75*7986af23SBjoern A. Zeeb		break
76*7986af23SBjoern A. Zeeb	fi
77*7986af23SBjoern A. Zeebdone
78*7986af23SBjoern A. Zeeb
79*7986af23SBjoern A. ZeebROUTER6=`netstat -Wrn -f inet6 | awk '/default/ {printf("%s\n", $2);}'`
80*7986af23SBjoern A. ZeebADDRS=`ifconfig ${INTERFACE} inet6 | \
81*7986af23SBjoern A. Zeebawk  -v dfr="${ROUTER6}" '
82*7986af23SBjoern A. ZeebBEGIN {
83*7986af23SBjoern A. Zeeb	n=0;
84*7986af23SBjoern A. Zeeb}
85*7986af23SBjoern A. Zeeb{
86*7986af23SBjoern A. Zeeb	if (/inet6/) {
87*7986af23SBjoern A. Zeeb		if (match($2, "^fe80:")) { next; };
88*7986af23SBjoern A. Zeeb		# For the moment ignore all but the first address; it might confuse the user.
89*7986af23SBjoern A. Zeeb		if (n > 0) { next; };
90*7986af23SBjoern A. Zeeb		n++;
91*7986af23SBjoern A. Zeeb		printf "\"IPv6 Address\" %d 0 \"%s/%s\" %d 16 50 0 0 ", n, $2, $4, n;
92*7986af23SBjoern A. Zeeb	}
93*7986af23SBjoern A. Zeeb}
94*7986af23SBjoern A. ZeebEND {
95*7986af23SBjoern A. Zeeb	if (n == 0) {
96*7986af23SBjoern A. Zeeb		n++;
97*7986af23SBjoern A. Zeeb		printf "\"IPv6 Address\" %d 0 \"\" %d 16 50 0 0 ", n, n;
98*7986af23SBjoern A. Zeeb	}
99*7986af23SBjoern A. Zeeb	n++;
100*7986af23SBjoern A. Zeeb	# Nasty trick adding a (hidden, same y) read-only field as a marker
101*7986af23SBjoern A. Zeeb	# to separate interface address(es) from the default router.
102*7986af23SBjoern A. Zeeb	printf "\"Default Router\" %d 0 \"%s\" %d 16 50 0 2 ", n, "DefaultRouter", n;
103*7986af23SBjoern A. Zeeb	printf "\"Default Router\" %d 0 \"%s\" %d 16 50 0 0 ", n, dfr, n;
104*7986af23SBjoern A. Zeeb}'`
105*7986af23SBjoern A. Zeeb
106*7986af23SBjoern A. Zeebexec 3>&1
107*7986af23SBjoern A. ZeebIF_CONFIG=$(echo ${ADDRS} | xargs dialog --backtitle 'FreeBSD Installer' \
108*7986af23SBjoern A. Zeeb	--title 'Network Configuration' \
109*7986af23SBjoern A. Zeeb	--mixedform 'Static IPv6 Network Interface Configuration' 0 0 0 \
110*7986af23SBjoern A. Zeeb2>&1 1>&3)
111*7986af23SBjoern A. Zeebif [ $? -eq $DIALOG_CANCEL ]; then exit 1; fi
112*7986af23SBjoern A. Zeebexec 3>&-
113*7986af23SBjoern A. Zeeb
114*7986af23SBjoern A. Zeebecho ${IF_CONFIG} | tr ' ' '\n' | \
115*7986af23SBjoern A. Zeebawk -v iface="${INTERFACE}" '
116*7986af23SBjoern A. ZeebBEGIN {
117*7986af23SBjoern A. Zeeb	dfr=0;
118*7986af23SBjoern A. Zeeb	count=0;
119*7986af23SBjoern A. Zeeb}
120*7986af23SBjoern A. Zeeb{
121*7986af23SBjoern A. Zeeb	if (/^[[:space:]]+$/) {
122*7986af23SBjoern A. Zeeb		next;
123*7986af23SBjoern A. Zeeb	}
124*7986af23SBjoern A. Zeeb	if (/DefaultRouter/) {
125*7986af23SBjoern A. Zeeb		dfr=1;
126*7986af23SBjoern A. Zeeb		next;
127*7986af23SBjoern A. Zeeb	}
128*7986af23SBjoern A. Zeeb	if (dfr == 1) {
129*7986af23SBjoern A. Zeeb		printf("ipv6_defaultrouter=\"%s\"\n", $1);
130*7986af23SBjoern A. Zeeb		next;
131*7986af23SBjoern A. Zeeb	}
132*7986af23SBjoern A. Zeeb	if (count > 0) {
133*7986af23SBjoern A. Zeeb		# Ignore all but the first IP address for now.
134*7986af23SBjoern A. Zeeb		next;
135*7986af23SBjoern A. Zeeb	}
136*7986af23SBjoern A. Zeeb	count++;
137*7986af23SBjoern A. Zeeb	if (!match($1, "/")) {
138*7986af23SBjoern A. Zeeb		sub("$", "/64", $1);
139*7986af23SBjoern A. Zeeb	}
140*7986af23SBjoern A. Zeeb	printf("ifconfig_%s_ipv6=\"inet6 %s\"\n", iface, $1);
141*7986af23SBjoern A. Zeeb}' >> $BSDINSTALL_TMPETC/rc.conf.net
142*7986af23SBjoern A. Zeeb
143*7986af23SBjoern A. Zeebif [ ! -z $BSDINSTALL_CONFIGCURRENT ]; then
144*7986af23SBjoern A. Zeeb	. $BSDINSTALL_TMPETC/rc.conf.net
145*7986af23SBjoern A. Zeeb	ifconfig ${INTERFACE} `eval echo \\\$ifconfig_${INTERFACE}_ipv6`
146*7986af23SBjoern A. Zeeb	route delete default
147*7986af23SBjoern A. Zeeb	route add default ${ipv6_defaultrouter}
148*7986af23SBjoern A. Zeebfi
149*7986af23SBjoern A. Zeeb
150