net-svc revision 3cf1b3e03f3c18d36c14b13bfe147921475eecb1
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# CDDL HEADER START
d60212e03fbef1d3dd7f7eb05c0545cc373cb9fcAutomatic Updater# The contents of this file are subject to the terms of the
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews# Common Development and Distribution License (the "License").
9c49c394b4218cc9c743a372a8fcfb787f5ea8caAndreas Gustafsson# You may not use this file except in compliance with the License.
9c49c394b4218cc9c743a372a8fcfb787f5ea8caAndreas Gustafsson# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9c49c394b4218cc9c743a372a8fcfb787f5ea8caAndreas Gustafsson# or http://www.opensolaris.org/os/licensing.
9c49c394b4218cc9c743a372a8fcfb787f5ea8caAndreas Gustafsson# See the License for the specific language governing permissions
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews# and limitations under the License.
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews# When distributing Covered Code, include this CDDL HEADER in each
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews# If applicable, add the following below this CDDL HEADER, with the
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews# fields enclosed by brackets "[]" replaced with your own identifying
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews# information: Portions Copyright [yyyy] [name of copyright owner]
f5d30e2864e048a42c4dc1134993ae7efdb5d6c3Mark Andrews# CDDL HEADER END
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
de10c46b2a714b0fb74837da7867f55cccc6d261Jeremy Reed# Use is subject to license terms.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# ident "%Z%%M% %I% %E% SMI"
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# This is third phase of TCP/IP startup/configuration. This script
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# runs after the NIS/NIS+ startup script. We run things here that may
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# depend on NIS/NIS+ maps.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein # In a shared-IP zone we need this service to be up, but all of the
26e2a07a0b6a3b1eccef82ba31270d0c54ad4f06Mark Andrews # work it tries to do is irrelevant (and will actually lead to the
c1a883f2e04d94e99c433b1f6cfd0c0338f4ed85Mark Andrews # service failing if we try to do it), so just bail out.
030aac3dbc57f99bad1d251b0783890ff0369952Automatic Updater # In the global zone and exclusive-IP zones we proceed.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein ;; # Fall through -- rest of script is the initialization code
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein echo "Usage: $0 { start | stop }"
b98225ff8a5721a998ccb440df4d261488fef163Mark Andrews# If boot variables are not set, set variables we use
de10c46b2a714b0fb74837da7867f55cccc6d261Jeremy Reed[ -z "$_INIT_UTS_NODENAME" ] && _INIT_UTS_NODENAME=`/usr/bin/uname -n`
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# This function removes the instance portion of the passed-in FMRI; for
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# example, 'svc:/network/service:default' becomes 'svc:/network/service'.
9a41f786b167a2a6df498d5e9c699f9835e1e9dcMark Andrews echo $1 | awk -F: ' { printf "%s:%s", $1, $2 } '
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# This function returns true if this script was *not* invoked
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# by an instance of svc:/network/service.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# This function returns true if this script was *not* invoked
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# by the nwam instance of the network/physical service.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# This function returns true if the nwam service is not running, false
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# if it is. "running" is defined as "current state is online or next
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# state is online".
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein state=`/usr/bin/svcprop -p restarter/state $NWAM_FMRI`
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein nstate=`/usr/bin/svcprop -p restarter/next_state $NWAM_FMRI`
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein [ "$state" = "online" -o "$nextstate" = "online" ] && return 1
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# Wait up to 5 seconds for ypbind to obtain a binding.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews for i in 1 2 3 4 5; do
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt [ $? -eq 0 -a -n "$server" ] && return 0 || sleep 1
b98225ff8a5721a998ccb440df4d261488fef163Mark Andrews# This function takes two file names and the file mode as input. The two
b98225ff8a5721a998ccb440df4d261488fef163Mark Andrews# files are compared for differences (using cmp(1)) and if different, the
b98225ff8a5721a998ccb440df4d261488fef163Mark Andrews# second file is over written with the first. A chmod is done with the file
b98225ff8a5721a998ccb440df4d261488fef163Mark Andrews# mode passed in. If the files are equal, the first file passed
b98225ff8a5721a998ccb440df4d261488fef163Mark Andrews# in (the /tmp file) is deleted.
b98225ff8a5721a998ccb440df4d261488fef163Mark Andrews if [ $? -eq 1 ]; then
b98225ff8a5721a998ccb440df4d261488fef163Mark Andrews # The umask during boot is configurable, which requires
b98225ff8a5721a998ccb440df4d261488fef163Mark Andrews # explicit setting of file permission modes when we
c6d4f781529d2f28693546b25b2967d44ec89e60Mark Andrews# This function takes a DHCP parameter (as defined in /etc/dhcp/inittab)
c6d4f781529d2f28693546b25b2967d44ec89e60Mark Andrews# and returns the value for that parameter returned by the DHCP server.
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt# If the global 'interface' is defined, it will request the value learned
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt# on that interface, else it will request the value learned on the primary
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt# This function returns true if the string "# Added by DHCP$" occurs in
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# the passed-in file, false otherwise.
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt /usr/bin/grep '# Added by DHCP$' $1 >/dev/null 2>&1
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt# update_resolv()
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt# Go through /etc/resolv.conf and replace any existing domain or
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt# nameserver entries with new ones derived from DHCP. Note that
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# it is important to preserve order of domain entries vs. search
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# entries; the search entries are reserved for administrator
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# customization and if placed after the domain entry will override
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt# The first arg should be the dns servers string, the second
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt# should be the dns domain.
08f860f800d32007a0c9bf456f6c35fbb2ecbc81Evan Hunt if [ ! -f /etc/resolv.conf ]; then
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /usr/bin/nawk </etc/resolv.conf >/tmp/resolv.conf.$$ '
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein function writedomain() {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein if (updated == 0) {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein # Use only first domain, not a search list
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein split(ENVIRON["dnsdomain"], d)
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein if(length(d[1]) != 0)
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein printf("domain %s\n", d[1])
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt $1 == "domain" { writedomain(); next }
351b62535d4c4f89883bfdba025999dd32490266Evan Hunt $1 != "nameserver" { print $0 }
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein writedomain()
561a29af8c54a216e7d30b5b4f6e0d21661654ecMark Andrews n = split(ENVIRON["dnsservers"], s)
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein for (i = 1; i <= n; ++i)
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein printf("nameserver %s\n", s[i])
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein mv_file /tmp/resolv.conf.$$ /etc/resolv.conf 644
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# This routine takes as a parameter, the name of the respective policy
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# to change in the nsswitch.conf (hosts or ipnodes) to update with dns.
561a29af8c54a216e7d30b5b4f6e0d21661654ecMark Andrews # Add dns to the nsswitch file, if it isn't already there.
9a41f786b167a2a6df498d5e9c699f9835e1e9dcMark Andrews n = split($0, a);
9a41f786b167a2a6df498d5e9c699f9835e1e9dcMark Andrews newl = a[1];
9a41f786b167a2a6df498d5e9c699f9835e1e9dcMark Andrews if ($0 !~ /dns/) {
9a41f786b167a2a6df498d5e9c699f9835e1e9dcMark Andrews printf("#%s # Commented out by DHCP\n", $0);
9a41f786b167a2a6df498d5e9c699f9835e1e9dcMark Andrews updated = 0;
9a41f786b167a2a6df498d5e9c699f9835e1e9dcMark Andrews for (i = 2; i <= n; i++) {
9a41f786b167a2a6df498d5e9c699f9835e1e9dcMark Andrews if (updated == 0 && index(a[i], "[") == 1) {
9a41f786b167a2a6df498d5e9c699f9835e1e9dcMark Andrews newl = newl" dns";
9a41f786b167a2a6df498d5e9c699f9835e1e9dcMark Andrews newl = newl" "a[i];
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein if (updated == 0) {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein newl = newl" dns";
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein if (updated != 0)
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein newl = newl" # Added by DHCP";
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein printf("%s\n", newl);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein printf("%s\n", $0);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein } $1 !~ /^'${policy}':/ { printf("%s\n", $0); }' /etc/nsswitch.conf \
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein mv_file /tmp/nsswitch.conf.$$ /etc/nsswitch.conf 644
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# Remove any lines with the "# Added by DHCP" tag from /etc/nsswitch.conf;
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# also uncomment hosts and ipnodes entries which were previously commented
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# out by this script.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein -e 's/^\(#hosts:\)\(.*[^#]\)\(#.*\)$/hosts: \2/' \
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein -e 's/^\(#ipnodes:\)\(.*[^#]\)\(#.*\)$/ipnodes: \2/' \
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein mv_file /tmp/nsswitch.conf.$$ /etc/nsswitch.conf 644
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# Remove any lines with the "# Added by DHCP" tag from /etc/inet/hosts.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein if (index($0, "# Added by DHCP") == 0 ||
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein $1 == "127.0.0.1" || $1 == "::1") {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# We now need to reset the netmask and broadcast address for our network
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# interfaces. Since this may result in a name service lookup, we want to
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# now wait for NIS to come up if we previously started it.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# Only do this in the non-nwam case.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein [ -z "$domain" ] || [ ! -d /var/yp/binding/$domain ] || wait_nis || \
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein echo "WARNING: Timed out waiting for NIS to come up" >& 2
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein # Re-set the netmask and broadcast addr for all IP interfaces. This
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein # ifconfig is run here, after waiting for name services, so that
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein # "netmask +" will find the netmask if it lives in a NIS map. The 'D'
8d709e3ee443222cd35e44eadc9a4c0a8d92fec2Rob Austein # in -auD tells ifconfig NOT to mess with the interface if it is
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein # under DHCP control
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# Uncomment these lines to print complete network interface configuration
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# echo "network interface configuration:"
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# If our network configuration strategy is DHCP, check for DNS
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# configuration parameters obtained from the DHCP server.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# If NWAM is enabled, it will invoke this script to do this configuration
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# whenever a DHCP lease is obtained; in that case, this configuration
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# should *not* happen when svc:network/service is starting, as it will
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# interfere with the configuration performed by NWAM.
8d709e3ee443222cd35e44eadc9a4c0a8d92fec2Rob Austeinif nwam_is_not_running || fmri_is_not_netsvc; then
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein if [ -n "$dnsservers" ]; then
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein # add settings retrieved from dhcp server to /etc/resolv.conf
8d709e3ee443222cd35e44eadc9a4c0a8d92fec2Rob Austein # Add dns to the nsswitch file, if it isn't already there.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein # If we added DNS to the hosts and ipnodes
561a29af8c54a216e7d30b5b4f6e0d21661654ecMark Andrews # policy in the nsswitch, remove it.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein # Clean up any old DHCP-added entries
21d493fc392d472086ad3c7c4563b7cadcb06788Mark Andrews # (except loopback) in the hosts file.
21d493fc392d472086ad3c7c4563b7cadcb06788Mark Andrews# If we were invoked by NWAM, can exit now (skipping the ipqos config)
21d493fc392d472086ad3c7c4563b7cadcb06788Mark Andrewsif [ -z "$SMF_FMRI" ] || [ "$SMF_FMRI" = "$NWAM_FMRI" ]; then
21d493fc392d472086ad3c7c4563b7cadcb06788Mark Andrews# Load the IPQoS configuration.
21d493fc392d472086ad3c7c4563b7cadcb06788Mark Andrews# This is backgrounded so that any remote hostname lookups it performs
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# don't unduely delay startup. Any messages go via syslog.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austeinif [ -f /usr/sbin/ipqosconf -a -f /etc/inet/ipqosinit.conf ]; then