Print this page
want to add link-local routes first
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/cmd/svc/milestone/net-routing-setup
+++ new/usr/src/cmd/svc/milestone/net-routing-setup
1 1 #!/sbin/sh
2 2 #
3 3 # CDDL HEADER START
4 4 #
5 5 # The contents of this file are subject to the terms of the
6 6 # Common Development and Distribution License (the "License").
7 7 # You may not use this file except in compliance with the License.
8 8 #
9 9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 # or http://www.opensolaris.org/os/licensing.
11 11 # See the License for the specific language governing permissions
12 12 # and limitations under the License.
13 13 #
14 14 # When distributing Covered Code, include this CDDL HEADER in each
15 15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 # If applicable, add the following below this CDDL HEADER, with the
17 17 # fields enclosed by brackets "[]" replaced with your own identifying
18 18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 19 #
20 20 # CDDL HEADER END
21 21 #
22 22 #
23 23 # Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
24 24 #
25 25 # Copyright (c) 2012 Joyent, Inc. All rights reserved.
26 26
27 27 # This script configures IP routing.
28 28
29 29 . /lib/svc/share/smf_include.sh
30 30
31 31 set -o xtrace
32 32
33 33 #
34 34 # In a shared-IP zone we need this service to be up, but all of the work
35 35 # it tries to do is irrelevant (and will actually lead to the service
36 36 # failing if we try to do it), so just bail out.
37 37 # In the global zone and exclusive-IP zones we proceed.
38 38 #
39 39 smf_configure_ip || exit $SMF_EXIT_OK
40 40
41 41 #
42 42 # If routing.conf file is in place, and has not already been read in
43 43 # by previous invokation of routeadm, legacy configuration is upgraded
44 44 # by this call to "routeadm -u". This call is also needed when
45 45 # a /var/svc/profile/upgrade file is found, as it may contain routeadm commands
46 46 # which need to be applied. Finally, routeadm starts in.ndpd by
47 47 # enabling the ndp service (in.ndpd), which is required for IPv6 address
48 48 # autoconfiguration. It would be nice if we could do this in
49 49 # network/loopback, but since the SMF backend is read-only at that
50 50 # point in boot, we cannot.
51 51 #
52 52 /sbin/routeadm -u
53 53
54 54 #
55 55 # Are we routing dynamically? routeadm(1M) reports this in the
56 56 # "current" values of ipv4/6-routing - if either are true, we are running
57 57 # routing daemons (or at least they are enabled to run).
58 58 #
59 59 dynamic_routing_test=`/sbin/routeadm -p | \
60 60 nawk '/^ipv[46]-routing [.]*/ { print $2 }' | /usr/bin/grep "current=enabled"`
61 61 if [ -n "$dynamic_routing_test" ]; then
62 62 dynamic_routing="true"
63 63 fi
64 64
65 65 #
66 66 # Configure default IPv4 routers using the local "/etc/defaultrouter"
67 67 # configuration file. The file can contain the hostnames or IP
68 68 # addresses of one or more default routers. If hostnames are used,
69 69 # each hostname must also be listed in the local "/etc/hosts" file
70 70 # because NIS is not running at the time that this script is
71 71 # run. Each router name or address is listed on a single line by
72 72 # itself in the file. Anything else on that line after the router's
73 73 # name or address is ignored. Lines that begin with "#" are
74 74 # considered comments and ignored.
75 75 #
76 76 # The default routes listed in the "/etc/defaultrouter" file will
|
↓ open down ↓ |
76 lines elided |
↑ open up ↑ |
77 77 # replace those added by the kernel during diskless booting. An
78 78 # empty "/etc/defaultrouter" file will cause the default route
79 79 # added by the kernel to be deleted.
80 80 #
81 81 # Note that the default router file is ignored if we received routes
82 82 # from a DHCP server. Our policy is to always trust DHCP over local
83 83 # administration.
84 84 #
85 85 smf_netstrategy
86 86
87 +#
88 +# Read /etc/inet/static_routes.vmadm and add each route.
89 +#
90 +if [ -f /etc/inet/static_routes.vmadm ]; then
91 + echo "Adding vmadm persistent link-local routes:"
92 + /usr/bin/egrep -v "^(#|$)" /etc/inet/static_routes.vmadm | /usr/bin/egrep -e "-interface " | while read line; do
93 + /usr/sbin/route add $line
94 + done
95 +fi
96 +
87 97 if [ "$_INIT_NET_STRATEGY" = "dhcp" ] && \
88 98 [ -n "`/sbin/dhcpinfo Router`" ]; then
89 99 defrouters=`/sbin/dhcpinfo Router`
90 100 elif [ -f /etc/defaultrouter ]; then
91 101 defrouters=`/usr/bin/grep -v \^\# /etc/defaultrouter | \
92 102 /usr/bin/awk '{print $1}'`
93 103 if [ -n "$defrouters" ]; then
94 104 #
95 105 # We want the default router(s) listed in
96 106 # /etc/defaultrouter to replace the one added from the
97 107 # BOOTPARAMS WHOAMI response but we must avoid flushing
98 108 # the last route between the running system and its
99 109 # /usr file system.
100 110 #
101 111
102 112 # First, remember the original route.
103 113 shift $#
104 114 set -- `/usr/bin/netstat -rn -f inet | \
105 115 /usr/bin/grep '^default'`
106 116 route_IP="$2"
107 117
108 118 #
109 119 # Next, add those from /etc/defaultrouter. While doing
110 120 # this, if one of the routes we add is for the route
111 121 # previously added as a result of the BOOTPARAMS
112 122 # response, we will see a message of the form:
113 123 # "add net default: gateway a.b.c.d: entry exists"
114 124 #
115 125 do_delete=yes
116 126 for router in $defrouters; do
117 127 route_added=`/usr/sbin/route -n add default \
118 128 -gateway $router`
119 129 res=$?
120 130 set -- $route_added
121 131 [ $res -ne 0 -a "$5" = "$route_IP:" ] && do_delete=no
122 132 done
123 133
124 134 #
125 135 # Finally, delete the original default route unless it
126 136 # was also listed in the defaultrouter file.
127 137 #
128 138 if [ -n "$route_IP" -a $do_delete = yes ]; then
129 139 /usr/sbin/route -n delete default \
130 140 -gateway $route_IP >/dev/null
131 141 fi
132 142 else
133 143 /usr/sbin/route -fn > /dev/null
134 144 fi
135 145 else
136 146 defrouters=
137 147 fi
138 148
139 149 #
140 150 # Use routeadm(1M) to configure forwarding and launch routing daemons
141 151 # for IPv4 and IPv6 based on preset values. These settings only apply
142 152 # to the global zone. For IPv4 dynamic routing, the system will default
143 153 # to disabled if a default route was previously added via BOOTP, DHCP,
144 154 # or the /etc/defaultrouter file. routeadm also starts in.ndpd.
145 155 #
146 156 if [ "$dynamic_routing" != "true" ] && [ -z "$defrouters" ]; then
147 157 #
148 158 # No default routes were setup by "route" command above.
149 159 # Check the kernel routing table for any other default
150 160 # routes.
151 161 #
152 162 /usr/bin/netstat -rn -f inet | \
153 163 /usr/bin/grep default >/dev/null 2>&1 && defrouters=yes
154 164 fi
155 165
156 166 #
157 167 # The routeadm/ipv4-routing-set property is true if the administrator
158 168 # has run "routeadm -e/-d ipv4-routing". If not, we revert to the
159 169 # appropriate defaults. We no longer run "routeadm -u" on every boot
160 170 # however, as persistent daemon state is now controlled by SMF.
161 171 #
162 172 ipv4_routing_set=`/usr/bin/svcprop -p routeadm/ipv4-routing-set $SMF_FMRI`
163 173 smartos_param=`/usr/bin/bootparams | grep "^smartos"`
164 174 if [ -z "$defrouters" ] && [ "$smartos_param" != "" ]; then
165 175 #
166 176 # Set default value for ipv4-routing to enabled. If routeadm -e/-d
167 177 # has not yet been run by the administrator, we apply this default.
168 178 # The -b option is project-private and informs routeadm not
169 179 # to treat the enable as administrator-driven.
170 180 #
171 181 /usr/sbin/svccfg -s $SMF_FMRI \
172 182 setprop routeadm/default-ipv4-routing = true
173 183 if [ "$ipv4_routing_set" = "false" ]; then
174 184 /sbin/routeadm -b -e ipv4-routing -u
175 185 fi
176 186 else
177 187 #
178 188 # Default router(s) have been found, so ipv4-routing default value
179 189 # should be disabled. If routaedm -e/d has not yet been run by
180 190 # the administrator, we apply this default. The -b option is
181 191 # project-private and informs routeadm not to treat the disable as
182 192 # administrator-driven.
183 193 #
184 194 /usr/sbin/svccfg -s $SMF_FMRI \
185 195 setprop routeadm/default-ipv4-routing = false
186 196 if [ "$ipv4_routing_set" = "false" ]; then
187 197 /sbin/routeadm -b -d ipv4-routing -u
188 198 fi
189 199 fi
190 200
191 201 #
192 202 # See if static routes were created by install. If so, they were created
193 203 # under /etc/svc/volatile. Copy them into their proper place.
194 204 #
195 205 if [ -f /etc/svc/volatile/etc/inet/static_routes ]; then
196 206 echo "Installing persistent routes"
197 207 if [ -f /etc/inet/static_routes ]; then
198 208 cat /etc/svc/volatile/etc/inet/static_routes | grep -v '^#' \
199 209 >> /etc/inet/static_routes
200 210 else
201 211 cp /etc/svc/volatile/etc/inet/static_routes \
202 212 /etc/inet/static_routes
203 213 fi
204 214 /usr/bin/rm /etc/svc/volatile/etc/inet/static_routes
205 215
206 216 fi
207 217
208 218 #
|
↓ open down ↓ |
112 lines elided |
↑ open up ↑ |
209 219 # Read /etc/inet/static_routes and add each route.
210 220 #
211 221 if [ -f /etc/inet/static_routes ]; then
212 222 echo "Adding persistent routes:"
213 223 /usr/bin/egrep -v "^(#|$)" /etc/inet/static_routes | while read line; do
214 224 /usr/sbin/route add $line
215 225 done
216 226 fi
217 227
218 228 #
219 -# Read /etc/inet/static_routes.vmadm and add each route.
229 +# Read /etc/inet/static_routes.vmadm and add each non-link-local route.
220 230 #
221 231 if [ -f /etc/inet/static_routes.vmadm ]; then
222 232 echo "Adding vmadm persistent routes:"
223 - /usr/bin/egrep -v "^(#|$)" /etc/inet/static_routes.vmadm | while read line; do
233 + /usr/bin/egrep -v "^(#|$)" /etc/inet/static_routes.vmadm | /usr/bin/egrep -v -e "-interface " | while read line; do
224 234 /usr/sbin/route add $line
225 235 done
226 236 fi
227 237
228 238 #
229 239 # Log the result
230 240 #
231 241 echo "Routing setup complete:"
232 242 /usr/bin/netstat -rn
233 243
234 244 # Clear exit status.
235 245 exit $SMF_EXIT_OK
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX