treewide: replace /sbin/sh hashbangs with /bin/sh
[unleashed.git] / usr / src / cmd / svc / milestone / net-routing-setup
blobe017538fd4609477e6199928ce27cc3fc06aedc4
1 #!/bin/sh
3 # CDDL HEADER START
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]
20 # CDDL HEADER END
23 # Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
25 # This script configures IP routing.
27 . /lib/svc/share/smf_include.sh
30 # In a shared-IP zone we need this service to be up, but all of the work
31 # it tries to do is irrelevant (and will actually lead to the service
32 # failing if we try to do it), so just bail out.
33 # In the global zone and exclusive-IP zones we proceed.
35 smf_configure_ip || exit $SMF_EXIT_OK
38 # Configure default IPv4 routers using the local "/etc/defaultrouter"
39 # configuration file. The file can contain the hostnames or IP
40 # addresses of one or more default routers. If hostnames are used,
41 # each hostname must also be listed in the local "/etc/hosts" file
42 # because NIS is not running at the time that this script is
43 # run. Each router name or address is listed on a single line by
44 # itself in the file. Anything else on that line after the router's
45 # name or address is ignored. Lines that begin with "#" are
46 # considered comments and ignored.
48 # The default routes listed in the "/etc/defaultrouter" file will
49 # replace those added by the kernel during diskless booting. An
50 # empty "/etc/defaultrouter" file will cause the default route
51 # added by the kernel to be deleted.
53 # Note that the default router file is ignored if we received routes
54 # from a DHCP server. Our policy is to always trust DHCP over local
55 # administration.
57 smf_netstrategy
59 if [ "$_INIT_NET_STRATEGY" = "dhcp" ] && \
60 [ -n "`/sbin/dhcpinfo Router`" ]; then
61 defrouters=`/sbin/dhcpinfo Router`
62 elif [ -f /etc/defaultrouter ]; then
63 defrouters=`/usr/bin/grep -v \^\# /etc/defaultrouter | \
64 /usr/bin/awk '{print $1}'`
65 if [ -n "$defrouters" ]; then
67 # We want the default router(s) listed in
68 # /etc/defaultrouter to replace the one added from the
69 # BOOTPARAMS WHOAMI response but we must avoid flushing
70 # the last route between the running system and its
71 # /usr file system.
74 # First, remember the original route.
75 shift $#
76 set -- `/usr/bin/netstat -rn -f inet | \
77 /usr/bin/grep '^default'`
78 route_IP="$2"
81 # Next, add those from /etc/defaultrouter. While doing
82 # this, if one of the routes we add is for the route
83 # previously added as a result of the BOOTPARAMS
84 # response, we will see a message of the form:
85 # "add net default: gateway a.b.c.d: entry exists"
87 do_delete=yes
88 for router in $defrouters; do
89 route_added=`/usr/sbin/route -n add default \
90 -gateway $router`
91 res=$?
92 set -- $route_added
93 [ $res -ne 0 -a "$5" = "$route_IP:" ] && do_delete=no
94 done
97 # Finally, delete the original default route unless it
98 # was also listed in the defaultrouter file.
100 if [ -n "$route_IP" -a $do_delete = yes ]; then
101 /usr/sbin/route -n delete default \
102 -gateway $route_IP >/dev/null
104 else
105 /usr/sbin/route -fn > /dev/null
107 else
108 defrouters=
112 # Read /etc/inet/static_routes and add each route.
114 if [ -f /etc/inet/static_routes ]; then
115 echo "Adding persistent routes:"
116 /usr/bin/egrep -v "^(#|$)" /etc/inet/static_routes | while read line; do
117 /usr/sbin/route add $line
118 done
121 # Clear exit status.
122 exit $SMF_EXIT_OK