5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
23 # Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
28 # This is third phase of TCP/IP startup/configuration. This script
29 # runs after the NIS startup script. We run things here that may
33 .
/lib
/svc
/share
/smf_include.sh
34 .
/lib
/svc
/share
/net_include.sh
36 NWAM_FMRI
="svc:/network/physical:nwam"
41 # In a shared-IP zone we need this service to be up, but all of the
42 # work it tries to do is irrelevant (and will actually lead to the
43 # service failing if we try to do it), so just bail out.
44 # In the global zone and exclusive-IP zones we proceed.
46 smf_configure_ip ||
exit $SMF_EXIT_OK
49 # If nwam is enabled, the nwam service will handle the tasks performed
50 # by this service, so just bail out.
52 service_is_enabled
$NWAM_FMRI && exit $SMF_EXIT_OK
53 ;; # fall through -- rest of script is the initialization code
60 echo "Usage: $0 { start | stop }"
67 # If boot variables are not set, set variables we use
68 [ -z "$_INIT_UTS_NODENAME" ] && _INIT_UTS_NODENAME
=`/usr/bin/uname -n`
71 # This function takes two file names and the file mode as input. The two
72 # files are compared for differences (using cmp(1)) and if different, the
73 # second file is over written with the first. A chmod is done with the file
74 # mode passed in. If the files are equal, the first file passed
75 # in (the /tmp file) is deleted.
83 # The umask during boot is configurable, which requires
84 # explicit setting of file permission modes when we
94 # This function takes a DHCP parameter (as defined in /etc/dhcp/inittab)
95 # and returns the value for that parameter returned by the DHCP server.
96 # If the global 'interface' is defined, it will request the value learned
97 # on that interface, else it will request the value learned on the primary
102 if [ -n "$interface" ]; then
103 /sbin
/dhcpinfo
-i $interface $1
110 # This function returns true if the string "# Added by DHCP$" occurs in
111 # the passed-in file, false otherwise.
115 /usr
/bin
/grep '# Added by DHCP$' $1 >/dev
/null
2>&1
121 # Go through /etc/resolv.conf and replace any existing domain or
122 # nameserver entries with new ones derived from DHCP. Note that
123 # it is important to preserve order of domain entries vs. search
124 # entries; the search entries are reserved for administrator
125 # customization and if placed after the domain entry will override
126 # it. See resolv.conf(4).
128 # The first arg should be the dns servers string, the second
129 # should be the dns domain.
136 if [ ! -f /etc
/resolv.conf
]; then
137 /usr
/bin
/touch /etc
/resolv.conf
139 export dnsservers dnsdomain
140 /usr
/bin
/nawk
</etc
/resolv.conf
>/tmp
/resolv.conf.$$
'
141 function writedomain() {
143 # Use only first domain, not a search list
144 split(ENVIRON["dnsdomain"], d)
145 if(length(d[1]) != 0)
146 printf("domain %s\n", d[1])
150 $1 == "domain" { writedomain(); next }
151 $1 != "nameserver" { print $0 }
154 n = split(ENVIRON["dnsservers"], s)
155 for (i = 1; i <= n; ++i)
156 printf("nameserver %s\n", s[i])
158 unset dnsservers dnsdomain
159 mv_file
/tmp
/resolv.conf.$$
/etc
/resolv.conf
644
164 # This routine takes as a parameter, the name of the respective policy
165 # to change in the nsswitch.conf (hosts or ipnodes) to update with dns.
170 # Add dns to the nsswitch file, if it isn't already there.
171 /usr
/bin
/awk ' $1 ~ /^'${policy}':/ {
175 printf("#%s # Commented out by DHCP\n", $0);
177 for (i = 2; i <= n; i++) {
178 if (updated == 0 && index(a[i], "[") == 1) {
189 newl = newl" # Added by DHCP";
192 printf("%s\n", newl);
195 } $1 !~ /^'${policy}':/ { printf("%s\n", $0); }' /etc
/nsswitch.conf \
196 >/tmp
/nsswitch.conf.$$
198 mv_file
/tmp
/nsswitch.conf.$$
/etc
/nsswitch.conf
644
202 # Remove any lines with the "# Added by DHCP" tag from /etc/nsswitch.conf;
203 # also uncomment hosts and ipnodes entries which were previously commented
204 # out by this script.
209 -e '/# Added by DHCP$/d' \
210 -e 's/^\(#hosts:\)\(.*[^#]\)\(#.*\)$/hosts: \2/' \
211 -e 's/^\(#ipnodes:\)\(.*[^#]\)\(#.*\)$/ipnodes: \2/' \
212 /etc
/nsswitch.conf
>/tmp
/nsswitch.conf.$$
214 mv_file
/tmp
/nsswitch.conf.$$
/etc
/nsswitch.conf
644
218 # Remove any lines with the "# Added by DHCP" tag from /etc/inet/hosts.
223 if (index($0, "# Added by DHCP") == 0 ||
224 $1 == "127.0.0.1" || $1 == "::1") {
227 }' /etc
/inet
/hosts
> /tmp
/hosts.$$
228 mv_file
/tmp
/hosts.$$
/etc
/inet
/hosts
444
232 # If our network configuration strategy is DHCP, check for DNS
233 # configuration parameters obtained from the DHCP server.
235 # Script execution starts here.
239 if [ "$_INIT_NET_STRATEGY" = "dhcp" ]; then
240 dnsservers
=`get_dhcp_var DNSserv`
241 dnsdomain
=`get_dhcp_var DNSdmain`
247 if [ -n "$dnsservers" ]; then
249 # add settings retrieved from dhcp server to /etc/resolv.conf
251 update_resolv
"$dnsservers" "$dnsdomain"
254 # Add dns to the nsswitch file, if it isn't already there.
259 elif dhcp_edits
/etc
/nsswitch.conf
; then
260 # If we added DNS to the hosts and ipnodes
261 # policy in the nsswitch, remove it.
265 if dhcp_edits
/etc
/inet
/hosts
; then
266 # Clean up any old DHCP-added entries
267 # (except loopback) in the hosts file.