xref: /dragonfly/etc/rc.d/network_ipv6 (revision ce083385)
19c600e7dSMatthew Dillon#!/bin/sh
29c600e7dSMatthew Dillon#
39c600e7dSMatthew Dillon# Copyright (c) 2000  The KAME Project
49c600e7dSMatthew Dillon# All rights reserved.
59c600e7dSMatthew Dillon#
69c600e7dSMatthew Dillon# Redistribution and use in source and binary forms, with or without
79c600e7dSMatthew Dillon# modification, are permitted provided that the following conditions
89c600e7dSMatthew Dillon# are met:
99c600e7dSMatthew Dillon# 1. Redistributions of source code must retain the above copyright
109c600e7dSMatthew Dillon#    notice, this list of conditions and the following disclaimer.
119c600e7dSMatthew Dillon# 2. Redistributions in binary form must reproduce the above copyright
129c600e7dSMatthew Dillon#    notice, this list of conditions and the following disclaimer in the
139c600e7dSMatthew Dillon#    documentation and/or other materials provided with the distribution.
149c600e7dSMatthew Dillon#
159c600e7dSMatthew Dillon# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
169c600e7dSMatthew Dillon# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
179c600e7dSMatthew Dillon# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
189c600e7dSMatthew Dillon# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
199c600e7dSMatthew Dillon# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
209c600e7dSMatthew Dillon# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
219c600e7dSMatthew Dillon# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
229c600e7dSMatthew Dillon# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
239c600e7dSMatthew Dillon# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
249c600e7dSMatthew Dillon# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
259c600e7dSMatthew Dillon# SUCH DAMAGE.
269c600e7dSMatthew Dillon#
279c600e7dSMatthew Dillon# $FreeBSD: src/etc/rc.d/network_ipv6,v 1.35 2003/06/29 05:15:57 mtm Exp $
289c600e7dSMatthew Dillon# 	From: src/etc/rc.network6,v 1.29 2002/04/06 15:15:43
299c600e7dSMatthew Dillon#
309c600e7dSMatthew Dillon
319c600e7dSMatthew Dillon# PROVIDE: network_ipv6
32*ce083385SAaron LI# REQUIRE: ip6addrctl routing
33*ce083385SAaron LI# BEFORE:  NETWORKING
349c600e7dSMatthew Dillon
359c600e7dSMatthew Dillon. /etc/rc.subr
369c600e7dSMatthew Dillon. /etc/network.subr
379c600e7dSMatthew Dillon
389c600e7dSMatthew Dillonname="network_ipv6"
399c600e7dSMatthew Dillonrcvar=`set_rcvar ipv6`
409c600e7dSMatthew Dillonstart_cmd="network_ipv6_start"
419c600e7dSMatthew Dillon
429c600e7dSMatthew Dillonnetwork_ipv6_start()
439c600e7dSMatthew Dillon{
449c600e7dSMatthew Dillon	# disallow "internal" addresses to appear on the wire
459c600e7dSMatthew Dillon	route add -inet6 ::ffff:0.0.0.0 -prefixlen 96 ::1 -reject
469c600e7dSMatthew Dillon	route add -inet6 ::0.0.0.0 -prefixlen 96 ::1 -reject
479c600e7dSMatthew Dillon
489c600e7dSMatthew Dillon	case ${ipv6_network_interfaces} in
499c600e7dSMatthew Dillon	[Aa][Uu][Tt][Oo])
509c600e7dSMatthew Dillon		# Get a list of network interfaces
519c600e7dSMatthew Dillon		ipv6_network_interfaces="`ifconfig -l`"
529c600e7dSMatthew Dillon		;;
539c600e7dSMatthew Dillon	[Nn][Oo][Nn][Ee])
549c600e7dSMatthew Dillon		ipv6_network_interfaces=''
559c600e7dSMatthew Dillon		;;
569c600e7dSMatthew Dillon	esac
579c600e7dSMatthew Dillon
589c600e7dSMatthew Dillon	if checkyesno ipv6_gateway_enable; then
599c600e7dSMatthew Dillon		# act as a router
609c600e7dSMatthew Dillon		${SYSCTL_W} net.inet6.ip6.forwarding=1
619c600e7dSMatthew Dillon		${SYSCTL_W} net.inet6.ip6.accept_rtadv=0
629c600e7dSMatthew Dillon
639c600e7dSMatthew Dillon		# wait for DAD
649c600e7dSMatthew Dillon		for i in $ipv6_network_interfaces; do
659c600e7dSMatthew Dillon			ifconfig $i up
669c600e7dSMatthew Dillon		done
679c600e7dSMatthew Dillon		sleep `${SYSCTL_N} net.inet6.ip6.dad_count`
689c600e7dSMatthew Dillon		sleep 1
699c600e7dSMatthew Dillon	else
709c600e7dSMatthew Dillon		# act as endhost - start with manual configuration
719c600e7dSMatthew Dillon		# Setup of net.inet6.ip6.accept_rtadv is done later by
729c600e7dSMatthew Dillon		# network6_interface_setup.
739c600e7dSMatthew Dillon		${SYSCTL_W} net.inet6.ip6.forwarding=0
749c600e7dSMatthew Dillon	fi
759c600e7dSMatthew Dillon
769c600e7dSMatthew Dillon	if [ -n "${ipv6_network_interfaces}" ]; then
779c600e7dSMatthew Dillon		# Setup the interfaces
789c600e7dSMatthew Dillon		network6_interface_setup $ipv6_network_interfaces
799c600e7dSMatthew Dillon
809c600e7dSMatthew Dillon		# wait for DAD's completion (for global addrs)
819c600e7dSMatthew Dillon		sleep `${SYSCTL_N} net.inet6.ip6.dad_count`
829c600e7dSMatthew Dillon		sleep 1
839c600e7dSMatthew Dillon	fi
849c600e7dSMatthew Dillon
859c600e7dSMatthew Dillon	# Filter out interfaces on which IPv6 initialization failed.
869c600e7dSMatthew Dillon	if checkyesno ipv6_gateway_enable; then
879c600e7dSMatthew Dillon		ipv6_working_interfaces=""
889c600e7dSMatthew Dillon		for i in ${ipv6_network_interfaces}; do
899c600e7dSMatthew Dillon			laddr=`network6_getladdr $i exclude_tentative`
909c600e7dSMatthew Dillon			case ${laddr} in
919c600e7dSMatthew Dillon			'')
929c600e7dSMatthew Dillon				;;
939c600e7dSMatthew Dillon			*)
949c600e7dSMatthew Dillon				ipv6_working_interfaces="$i \
959c600e7dSMatthew Dillon				    ${ipv6_working_interfaces}"
969c600e7dSMatthew Dillon				;;
979c600e7dSMatthew Dillon			esac
989c600e7dSMatthew Dillon		done
999c600e7dSMatthew Dillon		ipv6_network_interfaces=${ipv6_working_interfaces}
1009c600e7dSMatthew Dillon	fi
1019c600e7dSMatthew Dillon
1029c600e7dSMatthew Dillon	# Setup IPv6 to IPv4 mapping
1039c600e7dSMatthew Dillon	network6_stf_setup
1049c600e7dSMatthew Dillon
1059c600e7dSMatthew Dillon	# Install the "default interface" to kernel, which will be used
1069c600e7dSMatthew Dillon	# as the default route when there's no router.
1079c600e7dSMatthew Dillon	network6_default_interface_setup
1089c600e7dSMatthew Dillon
1099c600e7dSMatthew Dillon	# Setup static routes
1109c600e7dSMatthew Dillon	network6_static_routes_setup
1119c600e7dSMatthew Dillon}
1129c600e7dSMatthew Dillon
1139c600e7dSMatthew Dillonload_rc_config $name
1149c600e7dSMatthew Dillonrun_rc_command "$1"
115