17c478bd9Sstevel@tonic-gate#!/sbin/sh 27c478bd9Sstevel@tonic-gate# 37c478bd9Sstevel@tonic-gate# CDDL HEADER START 47c478bd9Sstevel@tonic-gate# 57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the 66927f468Sdp# Common Development and Distribution License (the "License"). 76927f468Sdp# You may not use this file except in compliance with the License. 87c478bd9Sstevel@tonic-gate# 97c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate# and limitations under the License. 137c478bd9Sstevel@tonic-gate# 147c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate# 207c478bd9Sstevel@tonic-gate# CDDL HEADER END 217c478bd9Sstevel@tonic-gate# 227c478bd9Sstevel@tonic-gate# 23f4b3ec61Sdh155122# Copyright 2007 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate# Use is subject to license terms. 257c478bd9Sstevel@tonic-gate# 267c478bd9Sstevel@tonic-gate#ident "%Z%%M% %I% %E% SMI" 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate# 297c478bd9Sstevel@tonic-gate# This is third phase of TCP/IP startup/configuration. This script 307c478bd9Sstevel@tonic-gate# runs after the NIS/NIS+ startup script. We run things here that may 317c478bd9Sstevel@tonic-gate# depend on NIS/NIS+ maps. 327c478bd9Sstevel@tonic-gate# 337c478bd9Sstevel@tonic-gate 346927f468Sdp. /lib/svc/share/smf_include.sh 35*032ae3d9Samaguire. /lib/svc/share/net_include.sh 366927f468Sdp 377c478bd9Sstevel@tonic-gatecase "$1" in 387c478bd9Sstevel@tonic-gate'start') 397c478bd9Sstevel@tonic-gate # 40f4b3ec61Sdh155122 # In a shared-IP zone we need this service to be up, but all of the 41f4b3ec61Sdh155122 # work it tries to do is irrelevant (and will actually lead to the 42f4b3ec61Sdh155122 # service failing if we try to do it), so just bail out. 43f4b3ec61Sdh155122 # In the global zone and exclusive-IP zones we proceed. 447c478bd9Sstevel@tonic-gate # 45f4b3ec61Sdh155122 smf_configure_ip || exit 0 467c478bd9Sstevel@tonic-gate ;; # Fall through -- rest of script is the initialization code 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate'stop') 497c478bd9Sstevel@tonic-gate exit 0 507c478bd9Sstevel@tonic-gate ;; 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate*) 537c478bd9Sstevel@tonic-gate echo "Usage: $0 { start | stop }" 547c478bd9Sstevel@tonic-gate exit 1 557c478bd9Sstevel@tonic-gate ;; 567c478bd9Sstevel@tonic-gateesac 577c478bd9Sstevel@tonic-gate 58d71dbb73Sjbeckinterface=$2 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate# If boot variables are not set, set variables we use 617c478bd9Sstevel@tonic-gate[ -z "$_INIT_UTS_NODENAME" ] && _INIT_UTS_NODENAME=`/usr/bin/uname -n` 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate# 647c478bd9Sstevel@tonic-gate# wait_nis 657c478bd9Sstevel@tonic-gate# Wait up to 5 seconds for ypbind to obtain a binding. 667c478bd9Sstevel@tonic-gate# 677c478bd9Sstevel@tonic-gatewait_nis () 687c478bd9Sstevel@tonic-gate{ 697c478bd9Sstevel@tonic-gate for i in 1 2 3 4 5; do 707c478bd9Sstevel@tonic-gate server=`/usr/bin/ypwhich 2>/dev/null` 717c478bd9Sstevel@tonic-gate [ $? -eq 0 -a -n "$server" ] && return 0 || sleep 1 727c478bd9Sstevel@tonic-gate done 737c478bd9Sstevel@tonic-gate return 1 747c478bd9Sstevel@tonic-gate} 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gate# 777c478bd9Sstevel@tonic-gate# This function takes two file names and the file mode as input. The two 787c478bd9Sstevel@tonic-gate# files are compared for differences (using cmp(1)) and if different, the 797c478bd9Sstevel@tonic-gate# second file is over written with the first. A chmod is done with the file 807c478bd9Sstevel@tonic-gate# mode passed in. If the files are equal, the first file passed 817c478bd9Sstevel@tonic-gate# in (the /tmp file) is deleted. 827c478bd9Sstevel@tonic-gate# 837c478bd9Sstevel@tonic-gatemv_file () 847c478bd9Sstevel@tonic-gate{ 857c478bd9Sstevel@tonic-gate /usr/bin/cmp -s $1 $2 867c478bd9Sstevel@tonic-gate if [ $? -eq 1 ]; then 877c478bd9Sstevel@tonic-gate /usr/bin/mv $1 $2 887c478bd9Sstevel@tonic-gate # 897c478bd9Sstevel@tonic-gate # The umask during boot is configurable, which requires 907c478bd9Sstevel@tonic-gate # explicit setting of file permission modes when we 917c478bd9Sstevel@tonic-gate # create files. 927c478bd9Sstevel@tonic-gate # 937c478bd9Sstevel@tonic-gate /usr/bin/chmod $3 $2 947c478bd9Sstevel@tonic-gate else 957c478bd9Sstevel@tonic-gate /usr/bin/rm $1 967c478bd9Sstevel@tonic-gate fi 977c478bd9Sstevel@tonic-gate} 987c478bd9Sstevel@tonic-gate 997c478bd9Sstevel@tonic-gate# 1007c478bd9Sstevel@tonic-gate# update_nss 1017c478bd9Sstevel@tonic-gate# This routine takes as a parameter, the name of the respective policy 1027c478bd9Sstevel@tonic-gate# to change in the nsswitch.conf (hosts or ipnodes) to update with dns. 1037c478bd9Sstevel@tonic-gate# 1047c478bd9Sstevel@tonic-gateupdate_nss () 1057c478bd9Sstevel@tonic-gate{ 1067c478bd9Sstevel@tonic-gate policy=$1; 1077c478bd9Sstevel@tonic-gate # Add dns to the nsswitch file, if it isn't already there. 1087c478bd9Sstevel@tonic-gate /usr/bin/awk ' $1 ~ /^'${policy}':/ { 1097c478bd9Sstevel@tonic-gate n = split($0, a); 1107c478bd9Sstevel@tonic-gate newl = a[1]; 1117c478bd9Sstevel@tonic-gate if ($0 !~ /dns/) { 1127c478bd9Sstevel@tonic-gate printf("#%s # Commented out by DHCP\n", $0); 1137c478bd9Sstevel@tonic-gate updated = 0; 1147c478bd9Sstevel@tonic-gate for (i = 2; i <= n; i++) { 1157c478bd9Sstevel@tonic-gate if (updated == 0 && index(a[i], "[") == 1) { 1167c478bd9Sstevel@tonic-gate newl = newl" dns"; 1177c478bd9Sstevel@tonic-gate updated++; 1187c478bd9Sstevel@tonic-gate } 1197c478bd9Sstevel@tonic-gate newl = newl" "a[i]; 1207c478bd9Sstevel@tonic-gate } 1217c478bd9Sstevel@tonic-gate if (updated == 0) { 1227c478bd9Sstevel@tonic-gate newl = newl" dns"; 1237c478bd9Sstevel@tonic-gate updated++; 1247c478bd9Sstevel@tonic-gate } 1257c478bd9Sstevel@tonic-gate if (updated != 0) 1267c478bd9Sstevel@tonic-gate newl = newl" # Added by DHCP"; 1277c478bd9Sstevel@tonic-gate else 1287c478bd9Sstevel@tonic-gate newl = $0; 1297c478bd9Sstevel@tonic-gate printf("%s\n", newl); 1307c478bd9Sstevel@tonic-gate } else 1317c478bd9Sstevel@tonic-gate printf("%s\n", $0); 1327c478bd9Sstevel@tonic-gate } $1 !~ /^'${policy}':/ { printf("%s\n", $0); }' /etc/nsswitch.conf \ 1337c478bd9Sstevel@tonic-gate >/tmp/nsswitch.conf.$$ 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate mv_file /tmp/nsswitch.conf.$$ /etc/nsswitch.conf 644 1367c478bd9Sstevel@tonic-gate} 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate# 1397c478bd9Sstevel@tonic-gate# We now need to reset the netmask and broadcast address for our network 1407c478bd9Sstevel@tonic-gate# interfaces. Since this may result in a name service lookup, we want to 1417c478bd9Sstevel@tonic-gate# now wait for NIS to come up if we previously started it. 1427c478bd9Sstevel@tonic-gate# 1437c478bd9Sstevel@tonic-gatedomain=`/usr/bin/domainname 2>/dev/null` 1447c478bd9Sstevel@tonic-gate 1457c478bd9Sstevel@tonic-gate[ -z "$domain" ] || [ ! -d /var/yp/binding/$domain ] || wait_nis || \ 1467c478bd9Sstevel@tonic-gate echo "WARNING: Timed out waiting for NIS to come up" >& 2 1477c478bd9Sstevel@tonic-gate 1487c478bd9Sstevel@tonic-gate# 1497c478bd9Sstevel@tonic-gate# Re-set the netmask and broadcast addr for all IP interfaces. This ifconfig 1507c478bd9Sstevel@tonic-gate# is run here, after waiting for name services, so that "netmask +" will find 1517c478bd9Sstevel@tonic-gate# the netmask if it lives in a NIS map. The 'D' in -auD tells ifconfig NOT to 1527c478bd9Sstevel@tonic-gate# mess with the interface if it is under DHCP control 1537c478bd9Sstevel@tonic-gate# 1547c478bd9Sstevel@tonic-gate/usr/sbin/ifconfig -auD4 netmask + broadcast + 1557c478bd9Sstevel@tonic-gate 1567c478bd9Sstevel@tonic-gate# Uncomment these lines to print complete network interface configuration 1577c478bd9Sstevel@tonic-gate# echo "network interface configuration:" 1587c478bd9Sstevel@tonic-gate# /usr/sbin/ifconfig -a 1597c478bd9Sstevel@tonic-gate 1607c478bd9Sstevel@tonic-gatesmf_netstrategy 1617c478bd9Sstevel@tonic-gate 1627c478bd9Sstevel@tonic-gateif [ "$_INIT_NET_STRATEGY" = "dhcp" ]; then 163d71dbb73Sjbeck if [ -n "$interface" ]; then 164d71dbb73Sjbeck dnsservers=`/sbin/dhcpinfo -i $interface DNSserv` 165d71dbb73Sjbeck else 1667c478bd9Sstevel@tonic-gate dnsservers=`/sbin/dhcpinfo DNSserv` 167d71dbb73Sjbeck fi 1687c478bd9Sstevel@tonic-gateelse 1697c478bd9Sstevel@tonic-gate dnsservers="" 1707c478bd9Sstevel@tonic-gatefi 1717c478bd9Sstevel@tonic-gate 1727c478bd9Sstevel@tonic-gateif [ -n "$dnsservers" ]; then 1737c478bd9Sstevel@tonic-gate # 1747c478bd9Sstevel@tonic-gate # Go through /etc/resolv.conf and replace any existing 1757c478bd9Sstevel@tonic-gate # domain or nameserver entries with new ones derived 1767c478bd9Sstevel@tonic-gate # from DHCP. Note that it is important to preserve 1777c478bd9Sstevel@tonic-gate # order of domain entries vs. search entries; the search 1787c478bd9Sstevel@tonic-gate # entries are reserved for administrator customization 1797c478bd9Sstevel@tonic-gate # and if placed after the domain entry will override it. 1807c478bd9Sstevel@tonic-gate # See resolv.conf(4). 1817c478bd9Sstevel@tonic-gate # 1827c478bd9Sstevel@tonic-gate if [ ! -f /etc/resolv.conf ]; then 1837c478bd9Sstevel@tonic-gate /usr/bin/touch /etc/resolv.conf 1847c478bd9Sstevel@tonic-gate fi 185d71dbb73Sjbeck if [ -n "$interface" ]; then 186d71dbb73Sjbeck dnsdomain=`/sbin/dhcpinfo -i $interface DNSdmain` 187d71dbb73Sjbeck else 1887c478bd9Sstevel@tonic-gate dnsdomain=`/sbin/dhcpinfo DNSdmain` 189d71dbb73Sjbeck fi 1907c478bd9Sstevel@tonic-gate export dnsservers dnsdomain 1917c478bd9Sstevel@tonic-gate /usr/bin/nawk </etc/resolv.conf >/tmp/resolv.conf.$$ ' 1927c478bd9Sstevel@tonic-gate function writedomain() { 1937c478bd9Sstevel@tonic-gate if (updated == 0) { 1947c478bd9Sstevel@tonic-gate # Use only first domain, not a search list 1957c478bd9Sstevel@tonic-gate split(ENVIRON["dnsdomain"], d) 1967c478bd9Sstevel@tonic-gate if(length(d[1]) != 0) 1977c478bd9Sstevel@tonic-gate printf("domain %s\n", d[1]) 1987c478bd9Sstevel@tonic-gate } 1997c478bd9Sstevel@tonic-gate ++updated 2007c478bd9Sstevel@tonic-gate } 2017c478bd9Sstevel@tonic-gate $1 == "domain" { writedomain(); next } 2027c478bd9Sstevel@tonic-gate $1 != "nameserver" { print $0 } 2037c478bd9Sstevel@tonic-gate END { 2047c478bd9Sstevel@tonic-gate writedomain() 2057c478bd9Sstevel@tonic-gate n = split(ENVIRON["dnsservers"], s) 2067c478bd9Sstevel@tonic-gate for (i = 1; i <= n; ++i) 2077c478bd9Sstevel@tonic-gate printf("nameserver %s\n", s[i]) 2087c478bd9Sstevel@tonic-gate }' 2097c478bd9Sstevel@tonic-gate unset dnsservers dnsdomain 2107c478bd9Sstevel@tonic-gate mv_file /tmp/resolv.conf.$$ /etc/resolv.conf 644 2117c478bd9Sstevel@tonic-gate # 2127c478bd9Sstevel@tonic-gate # Add dns to the nsswitch file, if it isn't already there. 2137c478bd9Sstevel@tonic-gate # 2147c478bd9Sstevel@tonic-gate update_nss hosts 2157c478bd9Sstevel@tonic-gate update_nss ipnodes 2167c478bd9Sstevel@tonic-gate 2177c478bd9Sstevel@tonic-gateelif /usr/bin/grep '# Added by DHCP$' /etc/nsswitch.conf >/dev/null 2>&1; then 2187c478bd9Sstevel@tonic-gate 2197c478bd9Sstevel@tonic-gate # If we added DNS to the hosts and ipnodes policy in the nsswitch, 2207c478bd9Sstevel@tonic-gate # remove it. 2217c478bd9Sstevel@tonic-gate /usr/bin/sed \ 2227c478bd9Sstevel@tonic-gate -e '/# Added by DHCP$/d' \ 2237c478bd9Sstevel@tonic-gate -e 's/^\(#hosts:\)\(.*[^#]\)\(#.*\)$/hosts: \2/' \ 2247c478bd9Sstevel@tonic-gate -e 's/^\(#ipnodes:\)\(.*[^#]\)\(#.*\)$/ipnodes: \2/' \ 2257c478bd9Sstevel@tonic-gate /etc/nsswitch.conf >/tmp/nsswitch.conf.$$ 2267c478bd9Sstevel@tonic-gate 2277c478bd9Sstevel@tonic-gate mv_file /tmp/nsswitch.conf.$$ /etc/nsswitch.conf 644 2287c478bd9Sstevel@tonic-gatefi 2297c478bd9Sstevel@tonic-gate 230d71dbb73Sjbeck# Clean up any old DHCP-added entries (except loopback) in the hosts file. 231d71dbb73Sjbeckif /usr/bin/grep '# Added by DHCP$' /etc/inet/hosts >/dev/null 2>&1; then 232d71dbb73Sjbeck /usr/bin/nawk '{ 233d71dbb73Sjbeck if (index($0, "# Added by DHCP") == 0 || 234d71dbb73Sjbeck $1 == "127.0.0.1" || $1 == "::1") { 235d71dbb73Sjbeck print $0 236d71dbb73Sjbeck } 237d71dbb73Sjbeck }' /etc/inet/hosts > /tmp/hosts.$$ 2387c478bd9Sstevel@tonic-gate mv_file /tmp/hosts.$$ /etc/inet/hosts 444 2397c478bd9Sstevel@tonic-gatefi 240d71dbb73Sjbeck 2417c478bd9Sstevel@tonic-gate# 2427c478bd9Sstevel@tonic-gate# Add a static route for multicast packets out our default interface. 2437c478bd9Sstevel@tonic-gate# The default interface is the interface that corresponds to the node name. 2447c478bd9Sstevel@tonic-gate# Run in background subshell to avoid waiting for name service. 2457c478bd9Sstevel@tonic-gate# 2467c478bd9Sstevel@tonic-gate 2477c478bd9Sstevel@tonic-gate( 2487c478bd9Sstevel@tonic-gateif [ "$_INIT_NET_STRATEGY" = "dhcp" ]; then 2497c478bd9Sstevel@tonic-gate mcastif=`/sbin/dhcpinfo Yiaddr` || mcastif=$_INIT_UTS_NODENAME 2507c478bd9Sstevel@tonic-gateelse 2517c478bd9Sstevel@tonic-gate mcastif=$_INIT_UTS_NODENAME 2527c478bd9Sstevel@tonic-gatefi 2537c478bd9Sstevel@tonic-gate 2547c478bd9Sstevel@tonic-gateecho "Setting default IPv4 interface for multicast:" \ 2557c478bd9Sstevel@tonic-gate "add net 224.0/4: gateway $mcastif" 2567c478bd9Sstevel@tonic-gate 2577c478bd9Sstevel@tonic-gate/usr/sbin/route -n add -interface 224.0/4 -gateway "$mcastif" >/dev/null 2587c478bd9Sstevel@tonic-gate) & 259*032ae3d9Samaguire 260*032ae3d9Samaguire# 261*032ae3d9Samaguire# NWAM-triggered interface changes may necessitate updating IPv6 multicast 262*032ae3d9Samaguire# route. 263*032ae3d9Samaguire# 264*032ae3d9Samaguireupdate_v6_multicast_route 265*032ae3d9Samaguire 266*032ae3d9Samaguireif [ -z "$SMF_FMRI" ] || [ "$SMF_FMRI" = "svc:/network/physical:nwam" ]; then 267*032ae3d9Samaguire exit 0 268*032ae3d9Samaguirefi 269*032ae3d9Samaguire 270*032ae3d9Samaguire# 271*032ae3d9Samaguire# Load the IPQoS configuration. 272*032ae3d9Samaguire# This is backgrounded so that any remote hostname lookups it performs 273*032ae3d9Samaguire# don't unduely delay startup. Any messages go via syslog. 274*032ae3d9Samaguire# 275*032ae3d9Samaguire 276*032ae3d9Samaguireif [ -f /usr/sbin/ipqosconf -a -f /etc/inet/ipqosinit.conf ]; then 277*032ae3d9Samaguire /usr/sbin/ipqosconf -s -a /etc/inet/ipqosinit.conf & 278*032ae3d9Samaguirefi 279