net-svc revision d71dbb732372504daff1f1783bc0d8864ce9bd50
474N/A#!/sbin/sh
474N/A#
474N/A# CDDL HEADER START
474N/A#
474N/A# The contents of this file are subject to the terms of the
474N/A# Common Development and Distribution License (the "License").
474N/A# You may not use this file except in compliance with the License.
474N/A#
474N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
474N/A# or http://www.opensolaris.org/os/licensing.
474N/A# See the License for the specific language governing permissions
474N/A# and limitations under the License.
474N/A#
474N/A# When distributing Covered Code, include this CDDL HEADER in each
474N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
474N/A# If applicable, add the following below this CDDL HEADER, with the
474N/A# fields enclosed by brackets "[]" replaced with your own identifying
474N/A# information: Portions Copyright [yyyy] [name of copyright owner]
474N/A#
474N/A# CDDL HEADER END
474N/A#
474N/A#
1914N/A# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
474N/A# Use is subject to license terms.
474N/A#
474N/A#ident "%Z%%M% %I% %E% SMI"
474N/A
474N/A#
474N/A# This is third phase of TCP/IP startup/configuration. This script
474N/A# runs after the NIS/NIS+ startup script. We run things here that may
825N/A# depend on NIS/NIS+ maps.
618N/A#
474N/A
474N/A. /lib/svc/share/smf_include.sh
844N/A
844N/Acase "$1" in
474N/A'start')
1258N/A #
474N/A # In a shared-IP zone we need this service to be up, but all of the
474N/A # work it tries to do is irrelevant (and will actually lead to the
474N/A # service failing if we try to do it), so just bail out.
474N/A # In the global zone and exclusive-IP zones we proceed.
474N/A #
844N/A smf_configure_ip || exit 0
844N/A ;; # Fall through -- rest of script is the initialization code
474N/A
474N/A'stop')
474N/A exit 0
474N/A ;;
474N/A
474N/A*)
474N/A echo "Usage: $0 { start | stop }"
474N/A exit 1
474N/A ;;
474N/Aesac
474N/A
474N/Ainterface=$2
474N/A
474N/A# If boot variables are not set, set variables we use
474N/A[ -z "$_INIT_UTS_NODENAME" ] && _INIT_UTS_NODENAME=`/usr/bin/uname -n`
474N/A
474N/A#
474N/A# wait_nis
474N/A# Wait up to 5 seconds for ypbind to obtain a binding.
474N/A#
474N/Await_nis ()
825N/A{
825N/A for i in 1 2 3 4 5; do
825N/A server=`/usr/bin/ypwhich 2>/dev/null`
474N/A [ $? -eq 0 -a -n "$server" ] && return 0 || sleep 1
474N/A done
474N/A return 1
474N/A}
474N/A
474N/A#
474N/A# This function takes two file names and the file mode as input. The two
474N/A# files are compared for differences (using cmp(1)) and if different, the
474N/A# second file is over written with the first. A chmod is done with the file
474N/A# mode passed in. If the files are equal, the first file passed
474N/A# in (the /tmp file) is deleted.
474N/A#
474N/Amv_file ()
474N/A{
474N/A /usr/bin/cmp -s $1 $2
474N/A if [ $? -eq 1 ]; then
474N/A /usr/bin/mv $1 $2
474N/A #
474N/A # The umask during boot is configurable, which requires
474N/A # explicit setting of file permission modes when we
474N/A # create files.
474N/A #
474N/A /usr/bin/chmod $3 $2
474N/A else
474N/A /usr/bin/rm $1
1914N/A fi
1914N/A}
1914N/A
474N/A#
474N/A# update_nss
474N/A# This routine takes as a parameter, the name of the respective policy
474N/A# to change in the nsswitch.conf (hosts or ipnodes) to update with dns.
474N/A#
474N/Aupdate_nss ()
474N/A{
474N/A policy=$1;
474N/A # Add dns to the nsswitch file, if it isn't already there.
474N/A /usr/bin/awk ' $1 ~ /^'${policy}':/ {
474N/A n = split($0, a);
474N/A newl = a[1];
474N/A if ($0 !~ /dns/) {
474N/A printf("#%s # Commented out by DHCP\n", $0);
474N/A updated = 0;
for (i = 2; i <= n; i++) {
if (updated == 0 && index(a[i], "[") == 1) {
newl = newl" dns";
updated++;
}
newl = newl" "a[i];
}
if (updated == 0) {
newl = newl" dns";
updated++;
}
if (updated != 0)
newl = newl" # Added by DHCP";
else
newl = $0;
printf("%s\n", newl);
} else
printf("%s\n", $0);
} $1 !~ /^'${policy}':/ { printf("%s\n", $0); }' /etc/nsswitch.conf \
>/tmp/nsswitch.conf.$$
mv_file /tmp/nsswitch.conf.$$ /etc/nsswitch.conf 644
}
#
# We now need to reset the netmask and broadcast address for our network
# interfaces. Since this may result in a name service lookup, we want to
# now wait for NIS to come up if we previously started it.
#
domain=`/usr/bin/domainname 2>/dev/null`
[ -z "$domain" ] || [ ! -d /var/yp/binding/$domain ] || wait_nis || \
echo "WARNING: Timed out waiting for NIS to come up" >& 2
#
# Re-set the netmask and broadcast addr for all IP interfaces. This ifconfig
# is run here, after waiting for name services, so that "netmask +" will find
# the netmask if it lives in a NIS map. The 'D' in -auD tells ifconfig NOT to
# mess with the interface if it is under DHCP control
#
/usr/sbin/ifconfig -auD4 netmask + broadcast +
# Uncomment these lines to print complete network interface configuration
# echo "network interface configuration:"
# /usr/sbin/ifconfig -a
smf_netstrategy
if [ "$_INIT_NET_STRATEGY" = "dhcp" ]; then
if [ -n "$interface" ]; then
dnsservers=`/sbin/dhcpinfo -i $interface DNSserv`
else
dnsservers=`/sbin/dhcpinfo DNSserv`
fi
else
dnsservers=""
fi
if [ -n "$dnsservers" ]; then
#
# Go through /etc/resolv.conf and replace any existing
# domain or nameserver entries with new ones derived
# from DHCP. Note that it is important to preserve
# order of domain entries vs. search entries; the search
# entries are reserved for administrator customization
# and if placed after the domain entry will override it.
# See resolv.conf(4).
#
if [ ! -f /etc/resolv.conf ]; then
/usr/bin/touch /etc/resolv.conf
fi
if [ -n "$interface" ]; then
dnsdomain=`/sbin/dhcpinfo -i $interface DNSdmain`
else
dnsdomain=`/sbin/dhcpinfo DNSdmain`
fi
export dnsservers dnsdomain
/usr/bin/nawk </etc/resolv.conf >/tmp/resolv.conf.$$ '
function writedomain() {
if (updated == 0) {
# Use only first domain, not a search list
split(ENVIRON["dnsdomain"], d)
if(length(d[1]) != 0)
printf("domain %s\n", d[1])
}
++updated
}
$1 == "domain" { writedomain(); next }
$1 != "nameserver" { print $0 }
END {
writedomain()
n = split(ENVIRON["dnsservers"], s)
for (i = 1; i <= n; ++i)
printf("nameserver %s\n", s[i])
}'
unset dnsservers dnsdomain
mv_file /tmp/resolv.conf.$$ /etc/resolv.conf 644
#
# Add dns to the nsswitch file, if it isn't already there.
#
update_nss hosts
update_nss ipnodes
elif /usr/bin/grep '# Added by DHCP$' /etc/nsswitch.conf >/dev/null 2>&1; then
# If we added DNS to the hosts and ipnodes policy in the nsswitch,
# remove it.
/usr/bin/sed \
-e '/# Added by DHCP$/d' \
-e 's/^\(#hosts:\)\(.*[^#]\)\(#.*\)$/hosts: \2/' \
-e 's/^\(#ipnodes:\)\(.*[^#]\)\(#.*\)$/ipnodes: \2/' \
/etc/nsswitch.conf >/tmp/nsswitch.conf.$$
mv_file /tmp/nsswitch.conf.$$ /etc/nsswitch.conf 644
fi
# Clean up any old DHCP-added entries (except loopback) in the hosts file.
if /usr/bin/grep '# Added by DHCP$' /etc/inet/hosts >/dev/null 2>&1; then
/usr/bin/nawk '{
if (index($0, "# Added by DHCP") == 0 ||
$1 == "127.0.0.1" || $1 == "::1") {
print $0
}
}' /etc/inet/hosts > /tmp/hosts.$$
mv_file /tmp/hosts.$$ /etc/inet/hosts 444
fi
if [ -z "$SMF_FMRI" ] || [ "$SMF_FMRI" = "svc:/network/physical:nwam" ]; then
exit 0
fi
#
# Load the IPQoS configuration.
# This is backgrounded so that any remote hostname lookups it performs
# don't unduely delay startup. Any messages go via syslog.
#
if [ -f /usr/sbin/ipqosconf -a -f /etc/inet/ipqosinit.conf ]; then
/usr/sbin/ipqosconf -s -a /etc/inet/ipqosinit.conf &
fi
#
# Add a static route for multicast packets out our default interface.
# The default interface is the interface that corresponds to the node name.
# Run in background subshell to avoid waiting for name service.
#
(
if [ "$_INIT_NET_STRATEGY" = "dhcp" ]; then
mcastif=`/sbin/dhcpinfo Yiaddr` || mcastif=$_INIT_UTS_NODENAME
else
mcastif=$_INIT_UTS_NODENAME
fi
echo "Setting default IPv4 interface for multicast:" \
"add net 224.0/4: gateway $mcastif"
/usr/sbin/route -n add -interface 224.0/4 -gateway "$mcastif" >/dev/null
) &