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