net-svc revision 36e852a172cba914383d7341c988128b2c667fbd
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
#
# This is third phase of TCP/IP startup/configuration. This script
# runs after the NIS startup script. We run things here that may
# depend on NIS maps.
#
case "$1" in
'start')
#
# In a shared-IP zone we need this service to be up, but all of the
# work it tries to do is irrelevant (and will actually lead to the
# service failing if we try to do it), so just bail out.
# In the global zone and exclusive-IP zones we proceed.
#
smf_configure_ip || exit 0
;; # Fall through -- rest of script is the initialization code
'stop')
exit 0
;;
*)
echo "Usage: $0 { start | stop }"
exit 1
;;
esac
NETSVC_FMRI="svc:/network/service:default"
interface=$2
# If boot variables are not set, set variables we use
#
# This function removes the instance portion of the passed-in FMRI; for
#
echo $1 | awk -F: ' { printf "%s:%s", $1, $2 } '
}
#
# This function returns true if this script was *not* invoked
#
return 0
}
#
# This function returns true if this script was *not* invoked
#
return 0
}
#
# This function returns true if the nwam service is not running, false
# if it is. "running" is defined as "current state is online or next
# state is online".
#
nstate=`/usr/bin/svcprop -p restarter/next_state $NWAM_FMRI`
return 0
}
#
# wait_nis
# Wait up to 5 seconds for ypbind to obtain a binding.
#
wait_nis ()
{
for i in 1 2 3 4 5; do
done
return 1
}
#
# This function takes two file names and the file mode as input. The two
# files are compared for differences (using cmp(1)) and if different, the
# second file is over written with the first. A chmod is done with the file
# mode passed in. If the files are equal, the first file passed
# in (the /tmp file) is deleted.
#
mv_file ()
{
if [ $? -eq 1 ]; then
#
# The umask during boot is configurable, which requires
# explicit setting of file permission modes when we
# create files.
#
else
fi
}
#
# and returns the value for that parameter returned by the DHCP server.
# If the global 'interface' is defined, it will request the value learned
# on that interface, else it will request the value learned on the primary
# interface.
#
get_dhcp_var ()
{
/sbin/dhcpinfo -i $interface $1
else
fi
}
#
# This function returns true if the string "# Added by DHCP$" occurs in
# the passed-in file, false otherwise.
#
dhcp_edits ()
{
return $?
}
#
# update_resolv()
# 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).
#
# The first arg should be the dns servers string, the second
# should be the dns domain.
#
{
dnsservers=$1
dnsdomain=$2
if [ ! -f /etc/resolv.conf ]; then
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
}
#
# update_nss
# This routine takes as a parameter, the name of the respective policy
# to change in the nsswitch.conf (hosts or ipnodes) to update with dns.
#
update_nss ()
{
policy=$1;
# Add dns to the nsswitch file, if it isn't already there.
n = split($0, a);
newl = a[1];
if ($0 !~ /dns/) {
printf("#%s # Commented out by DHCP\n", $0);
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);
>/tmp/nsswitch.conf.$$
mv_file /tmp/nsswitch.conf.$$ /etc/nsswitch.conf 644
}
#
# Remove any lines with the "# Added by DHCP" tag from /etc/nsswitch.conf;
# also uncomment hosts and ipnodes entries which were previously commented
# out by this script.
#
cleanup_nss ()
{
-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
}
#
#
{
if (index($0, "# Added by DHCP") == 0 ||
$1 == "127.0.0.1" || $1 == "::1") {
print $0
}
}
#
# 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.
#
# Only do this in the non-nwam case.
#
if fmri_is_not_nwam; then
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
#
fi
# Uncomment these lines to print complete network interface configuration
# echo "network interface configuration:"
#
# If our network configuration strategy is DHCP, check for DNS
# configuration parameters obtained from the DHCP server.
#
# If NWAM is enabled, it will invoke this script to do this configuration
# whenever a DHCP lease is obtained; in that case, this configuration
# interfere with the configuration performed by NWAM.
#
if nwam_is_not_running || fmri_is_not_netsvc; then
if [ "$_INIT_NET_STRATEGY" = "dhcp" ]; then
else
dnsservers=""
dnsdomain=""
fi
if [ -n "$dnsservers" ]; then
#
# add settings retrieved from dhcp server to /etc/resolv.conf
#
#
# Add dns to the nsswitch file, if it isn't already there.
#
# If we added DNS to the hosts and ipnodes
# policy in the nsswitch, remove it.
fi
fi
# Clean up any old DHCP-added entries
# (except loopback) in the hosts file.
fi
#
# If we were invoked by NWAM, can exit now (skipping the ipqos config)
#
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.
#
fi