net-physical revision 3448:aaf16568054b
1228753Smm#!/sbin/sh 2228753Smm# 3228753Smm# CDDL HEADER START 4228753Smm# 5228753Smm# The contents of this file are subject to the terms of the 6228753Smm# Common Development and Distribution License (the "License"). 7228753Smm# You may not use this file except in compliance with the License. 8228753Smm# 9228753Smm# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10228753Smm# or http://www.opensolaris.org/os/licensing. 11228753Smm# See the License for the specific language governing permissions 12228753Smm# and limitations under the License. 13228753Smm# 14228753Smm# When distributing Covered Code, include this CDDL HEADER in each 15228753Smm# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16228753Smm# If applicable, add the following below this CDDL HEADER, with the 17228753Smm# fields enclosed by brackets "[]" replaced with your own identifying 18228753Smm# information: Portions Copyright [yyyy] [name of copyright owner] 19228753Smm# 20228753Smm# CDDL HEADER END 21228753Smm# 22228753Smm# 23228753Smm# Copyright 2007 Sun Microsystems, Inc. All rights reserved. 24228753Smm# Use is subject to license terms. 25228753Smm# 26228763Smm# Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T. 27228753Smm# All rights reserved. 28228753Smm# 29228753Smm# 30228753Smm# ident "%Z%%M% %I% %E% SMI" 31228753Smm 32228753Smm. /lib/svc/share/smf_include.sh 33228753Smm. /lib/svc/share/net_include.sh 34228753Smm 35228753Smm# 36228753Smm# In a shared-IP zone we need this service to be up, but all of the work 37228753Smm# it tries to do is irrelevant (and will actually lead to the service 38228753Smm# failing if we try to do it), so just bail out. 39228753Smm# In the global zone and exclusive-IP zones we proceed. 40228753Smm# 41228753Smmsmf_configure_ip || exit $SMF_EXIT_OK 42228753Smm 43228753Smm# Print warnings to console 44228753Smmwarn_failed_ifs() { 45228753Smm echo "Failed to $1 interface(s): $2" >/dev/msglog 46228753Smm} 47228753Smm 48228753Smm# Make sure that the libraries essential to this stage of booting can be found. 49228753SmmLD_LIBRARY_PATH=/lib; export LD_LIBRARY_PATH 50228753Smm 51228753Smm# 52228753Smm# Cause ifconfig to not automatically start in.mpathd when IPMP groups are 53228753Smm# configured. This is not strictly necessary but makes it so that in.mpathd 54228753Smm# will always be started explicitly from /etc/init.d/inetinit, when we're 55228753Smm# sure that /usr is mounted. 56228753Smm# 57228753SmmSUNW_NO_MPATHD=; export SUNW_NO_MPATHD 58228753Smm 59228753Smmsmf_netstrategy 60228753Smm 61228753Smmif smf_is_globalzone; then 62228753Smm # 63228753Smm # Bring up link aggregations and initialize security objects. 64228753Smm # Note that link property initialization is deferred until after 65228753Smm # IP interfaces are plumbed to ensure that the links will not 66228753Smm # be unloaded (and the property settings lost). 67228753Smm # 68228753Smm /sbin/dladm up-aggr 69228753Smm /sbin/dladm init-secobj 70228753Smmfi 71228753Smm 72228753Smm# 73228753Smm# If the system was net booted by DHCP, hand DHCP management off to the 74228753Smm# DHCP agent (ifconfig communicates to the DHCP agent through the 75228753Smm# loopback interface). 76228753Smm# 77228753Smmif [ -n "$_INIT_NET_IF" -a "$_INIT_NET_STRATEGY" = "dhcp" ]; then 78228753Smm /sbin/dhcpagent -a 79228753Smmfi 80228753Smm 81228753Smm# 82228753Smm# The network initialization is done early to support diskless and 83228753Smm# dataless configurations. For IPv4 interfaces that were configured by 84228753Smm# the kernel (e.g. those on diskless machines) and not configured by 85228753Smm# DHCP, reset the netmask using the local "/etc/netmasks" file if one 86228753Smm# exists, and then reset the broadcast address based on the netmask. 87228753Smm# 88228753Smm/sbin/ifconfig -auD4 netmask + broadcast + 89228753Smm 90228753Smm# 91228753Smm# All the IPv4 and IPv6 interfaces are plumbed before doing any 92228753Smm# interface configuration. This prevents errors from plumb failures 93228753Smm# getting mixed in with the configured interface lists that the script 94228753Smm# outputs. 95228753Smm# 96228753Smm 97228753Smm# 98228753Smm# Get the list of IPv4 interfaces to configure by breaking 99228753Smm# /etc/hostname.* into separate args by using "." as a shell separator 100228753Smm# character. 101228753Smm# 102228753Smminterface_names="`echo /etc/hostname.*[0-9] 2>/dev/null`" 103228753Smmif [ "$interface_names" != "/etc/hostname.*[0-9]" ]; then 104228753Smm ORIGIFS="$IFS" 105228753Smm IFS="$IFS." 106228753Smm set -- $interface_names 107228753Smm IFS="$ORIGIFS" 108228753Smm while [ $# -ge 2 ]; do 109228753Smm shift 110228753Smm if [ "$1" = "xx0" ]; then 111228753Smm # 112228753Smm # For some unknown historical reason the xx0 113228753Smm # ifname is ignored. 114228753Smm # 115228753Smm shift 116228753Smm continue 117228753Smm fi 118 if [ $# -gt 1 -a "$2" != "/etc/hostname" ]; then 119 while [ $# -gt 1 -a "$1" != "/etc/hostname" ]; do 120 shift 121 done 122 else 123 inet_list="$inet_list $1" 124 shift 125 fi 126 done 127fi 128 129# 130# Get the list of IPv6 interfaces to configure by breaking 131# /etc/hostname6.* into separate args by using "." as a shell separator 132# character. 133# 134interface_names="`echo /etc/hostname6.*[0-9] 2>/dev/null`" 135if [ "$interface_names" != "/etc/hostname6.*[0-9]" ]; then 136 ORIGIFS="$IFS" 137 IFS="$IFS." 138 set -- $interface_names 139 IFS="$ORIGIFS" 140 while [ $# -ge 2 ]; do 141 shift 142 if [ $# -gt 1 -a "$2" != "/etc/hostname6" ]; then 143 while [ $# -gt 1 -a "$1" != "/etc/hostname6" ]; do 144 shift 145 done 146 else 147 inet6_list="$inet6_list $1" 148 shift 149 fi 150 done 151fi 152 153 154# 155# Step through the IPv4 interface list and try to plumb every interface. 156# Generate list of plumbed and failed IPv4 interfaces. 157# 158if [ -n "$inet_list" ]; then 159 set -- $inet_list 160 while [ $# -gt 0 ]; do 161 /sbin/ifconfig $1 plumb 162 if /sbin/ifconfig $1 inet >/dev/null 2>&1; then 163 inet_plumbed="$inet_plumbed $1" 164 else 165 inet_failed="$inet_failed $1" 166 fi 167 shift 168 done 169 [ -n "$inet_failed" ] && warn_failed_ifs "plumb IPv4" $inet_failed 170fi 171 172# Run autoconf to connect to a WLAN if the interface is a wireless one 173if [ -x /sbin/wificonfig -a -n "$inet_plumbed" ]; then 174 set -- $inet_plumbed 175 while [ $# -gt 0 ]; do 176 if [ -r /dev/wifi/$1 ]; then 177 /sbin/wificonfig -i $1 startconf >/dev/null 178 fi 179 shift 180 done 181fi 182 183# 184# Step through the IPv6 interface list and plumb every interface. 185# Generate list of plumbed and failed IPv6 interfaces. Each plumbed 186# interface will be brought up later, after processing any contents of 187# the /etc/hostname6.* file. 188# 189if [ -n "$inet6_list" ]; then 190 set -- $inet6_list 191 while [ $# -gt 0 ]; do 192 /sbin/ifconfig $1 inet6 plumb 193 if /sbin/ifconfig $1 inet6 >/dev/null 2>&1; then 194 inet6_plumbed="$inet6_plumbed $1" 195 else 196 inet6_failed="$inet6_failed $1" 197 fi 198 shift 199 done 200 [ -n "$inet6_failed" ] && warn_failed_ifs "plumb IPv6" $inet6_failed 201fi 202 203if smf_is_globalzone; then 204 # 205 # Unfortunately, if a driver unloads and then is subsequently reloaded, 206 # no mechanism currently exists to restore the properties of its 207 # associated links. Hence, we wait until after interfaces have been 208 # plumbed (above) to initialize link properties. 209 # 210 /sbin/dladm init-linkprop 211fi 212 213# 214# Process the /etc/hostname.* files of plumbed IPv4 interfaces. If an 215# /etc/hostname file is not present or is empty, the ifconfig auto-dhcp 216# / auto-revarp command will attempt to set the address, later. 217# 218# If /etc/hostname.lo0 exists the loop below will do additional 219# configuration of lo0. 220# 221if [ -n "$inet_plumbed" ]; then 222 i4s_fail= 223 echo "configuring IPv4 interfaces:\c" 224 set -- $inet_plumbed 225 while [ $# -gt 0 ]; do 226 inet_process_hostname /sbin/ifconfig $1 inet \ 227 </etc/hostname.$1 >/dev/null 228 [ $? != 0 ] && i4s_fail="$i4s_fail $1" 229 echo " $1\c" 230 shift 231 done 232 echo "." 233 [ -n "$i4s_fail" ] && warn_failed_ifs "configure IPv4" $i4s_fail 234fi 235 236# 237# Process the /etc/hostname6.* files of plumbed IPv6 interfaces. After 238# processing the hostname6 file, bring the interface up. If 239# /etc/hostname6.lo0 exists the loop below will do additional 240# configuration of lo0. 241# 242if [ -n "$inet6_plumbed" ]; then 243 i6_fail= 244 echo "configuring IPv6 interfaces:\c" 245 set -- $inet6_plumbed 246 while [ $# -gt 0 ]; do 247 inet6_process_hostname /sbin/ifconfig $1 inet6 \ 248 </etc/hostname6.$1 >/dev/null && 249 /sbin/ifconfig $1 inet6 up 250 [ $? != 0 ] && i6_fail="$i6_fail $1" 251 echo " $1\c" 252 shift 253 done 254 echo "." 255 [ -n "$i6_fail" ] && warn_failed_ifs "configure IPv6" $i6_fail 256fi 257 258# Run DHCP if requested. Skip boot-configured interface. 259interface_names="`echo /etc/dhcp.*[0-9] 2>/dev/null`" 260if [ "$interface_names" != '/etc/dhcp.*[0-9]' ]; then 261 # 262 # First find the primary interface. Default to the first 263 # interface if not specified. First primary interface found 264 # "wins". Use care not to "reconfigure" a net-booted interface 265 # configured using DHCP. Run through the list of interfaces 266 # again, this time trying DHCP. 267 # 268 i4d_fail= 269 firstif= 270 primary= 271 ORIGIFS="$IFS" 272 IFS="${IFS}." 273 set -- $interface_names 274 275 while [ $# -ge 2 ]; do 276 shift 277 [ -z "$firstif" ] && firstif=$1 278 279 for i in `shcat /etc/dhcp\.$1`; do 280 if [ "$i" = primary ]; then 281 primary=$1 282 break 283 fi 284 done 285 286 [ -n "$primary" ] && break 287 shift 288 done 289 290 [ -z "$primary" ] && primary="$firstif" 291 cmdline=`shcat /etc/dhcp\.${primary}` 292 293 if [ "$_INIT_NET_IF" != "$primary" ]; then 294 echo "starting DHCP on primary interface $primary" 295 /sbin/ifconfig $primary auto-dhcp primary $cmdline 296 # Exit code 4 means ifconfig timed out waiting for dhcpagent 297 [ $? != 0 ] && [ $? != 4 ] && i4d_fail="$i4d_fail $primary" 298 fi 299 300 set -- $interface_names 301 302 while [ $# -ge 2 ]; do 303 shift 304 cmdline=`shcat /etc/dhcp\.$1` 305 if [ "$1" != "$primary" -a \ 306 "$1" != "$_INIT_NET_IF" ]; then 307 echo "starting DHCP on interface $1" 308 /sbin/ifconfig $1 dhcp start wait 0 $cmdline 309 # Exit code can't be timeout when wait is 0 310 [ $? != 0 ] && i4d_fail="$i4d_fail $1" 311 fi 312 shift 313 done 314 IFS="$ORIGIFS" 315 unset ORIGIFS 316 [ -n "$i4d_fail" ] && warn_failed_ifs "configure IPv4 DHCP" $i4d_fail 317fi 318 319# In order to avoid bringing up the interfaces that have 320# intentionally been left down, perform RARP only if the system 321# has no configured hostname in /etc/nodename 322hostname="`shcat /etc/nodename 2>/dev/null`" 323if [ "$_INIT_NET_STRATEGY" = "rarp" -o -z "$hostname" ]; then 324 /sbin/ifconfig -adD4 auto-revarp netmask + broadcast + up 325fi 326 327# 328# Process IPv4 and IPv6 interfaces that failed to plumb. Find an 329# alternative interface to host the addresses. 330# 331[ -n "$inet_failed" ] && move_addresses inet 332 333[ -n "$inet6_failed" ] && move_addresses inet6 334 335# 336# If the /etc/defaultrouter file exists, process it now so that the next 337# stage of booting will have access to NFS. 338# 339if [ -f /etc/defaultrouter ]; then 340 while read router rubbish; do 341 case "$router" in 342 '#'* | '') ;; # Ignore comments, empty lines 343 *) /sbin/route -n add default -gateway $router ;; 344 esac 345 done </etc/defaultrouter 346fi 347 348# 349# We tell smf this service is online if any of the following is true: 350# - no interfaces were configured for plumbing and no DHCP failures 351# - any non-loopback IPv4 interfaces are up and have a non-zero address 352# - there are any DHCP interfaces started 353# - any non-loopback IPv6 interfaces are up 354# 355# If we weren't asked to configure any interfaces, exit 356if [ -z "$inet_list" ] && [ -z "$inet6_list" ]; then 357 # Config error if DHCP was attempted without plumbed interfaces 358 [ -n "$i4d_fail" ] && exit $SMF_EXIT_ERR_CONFIG 359 exit $SMF_EXIT_OK 360fi 361 362# Any non-loopback IPv4 interfaces with usable addresses up? 363if [ -n "`/sbin/ifconfig -a4u`" ]; then 364 /sbin/ifconfig -a4u | while read intf addr rest; do 365 [ $intf = inet ] && [ $addr != 127.0.0.1 ] && 366 [ $addr != 0.0.0.0 ] && exit 0 367 done && exit $SMF_EXIT_OK 368fi 369 370# Any DHCP interfaces started? 371[ -n "`/sbin/ifconfig -a4 dhcp status 2>/dev/null`" ] && exit $SMF_EXIT_OK 372 373# Any non-loopback IPv6 interfaces up? 374if [ -n "`/sbin/ifconfig -au6`" ]; then 375 /sbin/ifconfig -au6 | while read intf addr rest; do 376 [ $intf = inet6 ] && [ $addr != ::1/128 ] && exit 0 377 done && exit $SMF_EXIT_OK 378fi 379 380# This service was supposed to configure something yet didn't. Exit 381# with config error. 382exit $SMF_EXIT_ERR_CONFIG 383