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