xref: /titanic_52/usr/src/cmd/svc/milestone/net-init (revision 28406508b3a9fa1994317b410fa4afd93b3f8cc4)
1#!/sbin/sh
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22#
23# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24# Use is subject to license terms.
25#
26# ident	"%Z%%M%	%I%	%E% SMI"
27#
28# This is the second phase of TCP/IP configuration.  The first part is
29# run by the svc:/network/physical service and includes configuring the
30# interfaces and setting the machine's hostname.  The svc:/network/initial
31# service does all configuration that can be done before name services are
32# started, bar configuring IP routing (this is carried out by the
33# svc:/network/routing-setup service).  The final part, run by the
34# svc:/network/service service,  does all configuration that may require
35# name services.  This includes a final re-configuration of the
36# interfaces.
37#
38
39. /lib/svc/share/smf_include.sh
40
41#
42# In a shared-IP zone we need this service to be up, but all of the work
43# it tries to do is irrelevant (and will actually lead to the service
44# failing if we try to do it), so just bail out.
45# In the global zone and exclusive-IP zones we proceed.
46#
47smf_configure_ip || exit $SMF_EXIT_OK
48
49# Configure IPv6 Default Address Selection.
50if [ -f /etc/inet/ipaddrsel.conf ]; then
51	/usr/sbin/ipaddrsel -f /etc/inet/ipaddrsel.conf
52fi
53
54#
55# Now that /usr is mounted, see if in.mpathd needs to be started by firing it
56# up in "adopt" mode; if there are no interfaces it needs to manage, it will
57# automatically exit.  Note that it may already be running if we're not
58# executing as part of system boot.
59#
60/usr/bin/pgrep -x -u 0 -z `smf_zonename` in.mpathd >/dev/null 2>&1 || \
61    /usr/lib/inet/in.mpathd -a
62
63#
64# Pass to the kernel the list of supported IPsec protocols and algorithms.
65# This will not cause IPsec to be loaded.
66#
67/usr/sbin/ipsecalgs -s
68
69#
70# Initialize IPsec only if ipsecinit.conf exists.  Otherwise, save the
71# kernel memory that'll be consumed if IPsec is loaded.  See below for more
72# IPsec-related commands.
73#
74if [ -f /etc/inet/ipsecinit.conf ] ; then
75	/usr/sbin/ipsecconf -qa /etc/inet/ipsecinit.conf
76fi
77
78#
79# Set the RFC 1948 entropy, regardless of if I'm using it or not.  If present,
80# use the encrypted root password as a source of entropy.  Otherwise,
81# just use the pre-set (and hopefully difficult to guess) entropy that
82# tcp used when it loaded.
83#
84encr=`/usr/bin/awk -F: '/^root:/ {print $2}' /etc/shadow`
85[ -z "$encr" ] || /usr/sbin/ndd -set /dev/tcp tcp_1948_phrase $encr
86unset encr
87
88#
89# Get values for TCP_STRONG_ISS, ACCEPT6TO4RELAY and RELAY6TO4ADDR.
90#
91[ -f /etc/default/inetinit ] && . /etc/default/inetinit
92
93#
94# Set TCP ISS generation.  By default the ISS generation is
95# time + random()-delta.  This might not be strong enough for some users.
96# See /etc/default/inetinit for settings and further info on TCP_STRONG_ISS.
97# If not set, use TCP's internal default setting.
98#
99if [ $TCP_STRONG_ISS ]; then
100	/usr/sbin/ndd -set /dev/tcp tcp_strong_iss $TCP_STRONG_ISS
101fi
102
103#
104# In spite of global policy, there may be a need for IPsec because of
105# per-socket policy or tunnelled policy.  With that in mind, check for manual
106# keys in /etc/inet/secret/ipseckeys, or check for IKE configuration in
107# /etc/inet/ike/config.  Either of these will also load and initialize IPsec,
108# thereby consuming kernel memory.
109#
110
111if [ -f /etc/inet/secret/ipseckeys ] ; then
112	/usr/sbin/ipseckey -f /etc/inet/secret/ipseckeys
113fi
114
115if [ -f /etc/inet/ike/config ] ; then
116	/usr/lib/inet/in.iked
117fi
118
119#
120# Configure tunnels which were deferred by /lib/svc/method/net-physical
121# (the svc:/network/physical service) since it depends on the tunnel endpoints
122# being reachable i.e. routing must be running.
123#
124# WARNING: you may wish to turn OFF forwarding if you haven't already, because
125# of various possible security vulnerabilities when configuring tunnels for
126# Virtual Private Network (VPN) construction.
127#
128# Also, if names are used in the /etc/hostname.ip.tun* file, those names
129# have to be in either DNS (and DNS is used) or in /etc/hosts, because this
130# file is executed before NIS or NIS+ is started.
131#
132
133#
134# IPv4 tunnels
135# The second component of the name must be either "ip" or "ip6".
136#
137interface_names="`/usr/bin/ls /etc/hostname.ip*.*[0-9] 2>/dev/null | \
138    /usr/bin/grep '/etc/hostname\.ip6\{0,1\}\.'`"
139if [ -n "$interface_names" ]; then
140	(
141		echo "configuring IPv4 tunnels:\c"
142		# Extract the part after the first '.'
143		set -- `for intr in $interface_names; do \
144		    /usr/bin/expr //$intr : '[^.]*\.\(.*\)$'; done`
145		while [ $# -ge 1 ]; do
146			# Skip empty files
147			if [ ! -s /etc/hostname\.$1 ]; then
148				shift
149				continue
150			fi
151			/usr/sbin/ifconfig $1 plumb
152			while read ifcmds; do
153				if [ -n "$ifcmds" ]; then
154					/usr/sbin/ifconfig $1 inet $ifcmds
155				fi
156			done </etc/hostname\.$1 >/dev/null
157			echo " $1\c"
158			shift
159		done
160		echo "."
161	)
162fi
163
164#
165# IPv6 Tunnels
166# The second component of the name must be either "ip" or "ip6".
167#
168interface_names="`/usr/bin/ls /etc/hostname6.ip*.*[0-9] 2>/dev/null | \
169    /usr/bin/grep '/etc/hostname6\.ip6\{0,1\}\.'`"
170if [ -n "$interface_names" ]; then
171	(
172		echo "configuring IPv6 tunnels:\c"
173		# Extract the part after the first '.'
174		set -- `for intr in $interface_names; do \
175		    /usr/bin/expr //$intr : '[^.]*\.\(.*\)$'; done`
176		while [ $# -ge 1 ]; do
177			# Skip empty files
178			if [ ! -s /etc/hostname6\.$1 ]; then
179				shift
180				continue
181			fi
182			/usr/sbin/ifconfig $1 inet6 plumb
183			while read ifcmds; do
184				if [ -n "$ifcmds" ]; then
185					/usr/sbin/ifconfig $1 inet6 $ifcmds
186				fi
187			done </etc/hostname6\.$1 > /dev/null
188			echo " $1\c"
189			shift
190		done
191		echo "."
192	)
193fi
194
195# Clear exit status.
196exit $SMF_EXIT_OK
197