Print this page
XXX Remove nawk(1)
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/svc/shell/routing_include.sh
+++ new/usr/src/cmd/svc/shell/routing_include.sh
1 1 #!/bin/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 2009 Sun Microsystems, Inc. All rights reserved.
24 24 # Use is subject to license terms.
25 25 #
26 26
27 27 #
28 28 # IPfilter's firewall
29 29 #
30 30 # routed and its siblings use ICMP Router Discovery protocol, simply allow
31 31 # these packets so the client portion of routed can work.
32 32 #
33 33 gen_IRDP_rules()
34 34 {
35 35 # Allow incoming icmp from routers for successful discovery.
36 36 # IRDP - ICMP type 9 and 10, advertisement and solicitation, respectively.
37 37 #
38 38 echo "pass in log quick proto icmp from any to any icmp-type 10" >>${1}
39 39 echo "pass in log quick proto icmp from any to any icmp-type 9" >>${1}
40 40 }
41 41
42 42 #
43 43 # These functions are used to help map daemon arguments to appropriate
44 44 # routing properties and back, allowing legacy specifications of daemon
45 45 # arguments to be reflected in SMF property values for daemon services.
46 46 #
47 47
48 48 #
49 49 # set_routeadm_property inst_fmri propname propvalue
50 50 #
51 51 # Functions sets appropriate property value in routeadm property group
52 52 # (via routeadm -m) for inst_fmri to propvalue.
53 53 #
54 54 set_routeadm_property()
55 55 {
56 56 /sbin/routeadm -m $1 ${2}="${3}"
57 57 }
58 58
59 59 #
60 60 # The functions below are used to map from daemon arguments to appropriate
61 61 # routeadm properties (properties that the service user can manipulate
62 62 # to control daemon functionality. getopts is used extensively to
63 63 # retrieve options/values from argument list, and these option values
64 64 # are used to set properties appropriately.
65 65 #
66 66
67 67 #
68 68 # set_daemon_value_property inst_fmri optstring options option prop
69 69 # default_value
70 70 #
71 71 # Function looks for option/value in argument string, and sets associated
72 72 # property if found. If a default is specified, and the option is not
73 73 # in the argument string, it will be used.
74 74 #
75 75 set_daemon_value_property()
76 76 {
77 77 OPTIND=1
78 78 value_set=""
79 79 while getopts $3 opt $2; do
80 80 case $opt in
81 81 "$4" ) set_routeadm_property $1 $5 $OPTARG
82 82 value_set="true"
83 83 ;;
84 84 ? )
85 85 esac
86 86 done
87 87 # No value set - use default if specified.
88 88 if [ -z "$value_set" -a -n "$6" ]; then
89 89 set_routeadm_property $1 $5 $6
90 90 fi
91 91 }
92 92
93 93 #
94 94 # set_daemon_ordered_multivalue_property inst_fmri optstring options option prop
95 95 # default_value
96 96 #
97 97 # Function looks for option/values in argument string, and sets associated
98 98 # property if found. If a default is specified, and the option is not
99 99 # in the argument string, it will be used. Use ";" as delimiter for
100 100 # multiple values.
101 101 #
102 102 set_daemon_ordered_multivalue_property()
103 103 {
104 104 OPTIND=1
105 105 value_set=""
106 106 while getopts $3 opt $2; do
107 107 case $opt in
108 108 "$4" ) if [ -z "$value_set" ]; then
109 109 value_set="${OPTARG}"
110 110 else
111 111 value_set="$value_set;${OPTARG}"
112 112 fi
113 113 ;;
114 114 ? )
115 115 esac
116 116 done
117 117 if [ -n "$value_set" ]; then
118 118 set_routeadm_property $1 $5 "$value_set"
119 119 fi
120 120 # No value set - use default if specified.
121 121 if [ -z "$value_set" -a -n "$6" ]; then
122 122 set_routeadm_property $1 $5 $6
123 123 fi
124 124 }
125 125
126 126 #
127 127 # set_daemon_boolean_property inst_fmri optstring options option
128 128 # prop value_if_found default
129 129 #
130 130 # Function looks for option in argument string, and sets associated
131 131 # property, if found, to value_if_found. If a default is specified, and
132 132 # the option is not found, it will be used.
133 133 #
134 134 set_daemon_boolean_property()
135 135 {
136 136 OPTIND=1
137 137 value_set=""
138 138 while getopts $3 opt $2; do
139 139 case $opt in
140 140 "$4" ) set_routeadm_property $1 $5 $6
141 141 value_set="true"
142 142 ;;
143 143 ? )
144 144 esac
145 145 done
146 146 # No value set - use default if specified.
147 147 if [ -z "$value_set" -a -n "$7" ]; then
148 148 set_routeadm_property $1 $5 $7
149 149 fi
150 150 }
151 151
152 152 #
153 153 # set_daemon_nonoption_properties inst_fmri optstring options propnames
154 154 # default
155 155 #
156 156 # Function looks past option list for addition values, and sets properties
157 157 # specified in propnames to additional positional values. If no value
158 158 # is found for additional property, default is used.
159 159 #
160 160 set_daemon_nonoption_properties()
161 161 {
↓ open down ↓ |
161 lines elided |
↑ open up ↑ |
162 162 OPTIND=1
163 163 # Skip options
164 164 while getopts $3 opt $2; do
165 165 case $opt in
166 166 ? )
167 167 esac
168 168 done
169 169 pos=$OPTIND
170 170 for prop in $4
171 171 do
172 - val=`/usr/bin/echo $2 | /usr/bin/nawk -v POS=$pos \
172 + val=`/usr/bin/echo $2 | /usr/xpg4/bin/awk -v POS=$pos \
173 173 '{ print $POS }'`
174 174 if [ -z "$val" ]; then
175 175 val="$5"
176 176 fi
177 177 set_routeadm_property $1 $prop $val
178 178 pos=`expr $pos + 1`
179 179 done
180 180 }
181 181
182 182 #
183 183 # get_daemon_args $inst_fmri
184 184 #
185 185 # Retrieves routeadm/daemon-args property values, if any. Removes
186 186 # quotes around values including spaces.
187 187 #
188 188 get_daemon_args()
189 189 {
190 190 args=`/usr/sbin/svccfg -s $1 listprop routeadm/daemon-args | \
191 - /usr/bin/nawk '{ for (i = 3; i <= NF; i++) printf "%s ", $i }' | \
192 - /usr/bin/nawk '{sub(/^\"/, ""); sub(/\"[ \t]*$/,""); print}'`
191 + /usr/xpg4/bin/awk '{ for (i = 3; i <= NF; i++) printf "%s ", $i }' | \
192 + /usr/xpg4/bin/awk '{sub(/^\"/, ""); sub(/\"[ \t]*$/,""); print}'`
193 193 echo "$args"
194 194 }
195 195
196 196 #
197 197 # clear_daemon_args $inst_fmri
198 198 #
199 199 # Blanks routeadm/daemon-args property used in upgrade.
200 200 #
201 201 clear_daemon_args()
202 202 {
203 203 /usr/sbin/svccfg -s $1 delprop routeadm/daemon-args 2>/dev/null
204 204 }
205 205
206 206 #
207 207 # The functions below are used to map back from property settings to
208 208 # commandline arguments to launch daemons.
209 209 #
210 210
211 211 get_routeadm_property()
212 212 {
213 - propval=`/sbin/routeadm -l $1 | /usr/bin/nawk -v PROP=$2 \
213 + propval=`/sbin/routeadm -l $1 | /usr/xpg4/bin/awk -v PROP=$2 \
214 214 '($1 == PROP) { for (i = 3; i < NF; i++) printf $i" "; \
215 215 if (NF >= 3) {printf $NF}}'`
216 216 echo "$propval"
217 217 }
218 218
219 219 #
220 220 # get_daemon_option_from_boolean_property inst_fmri prop option value_set
221 221 #
222 222 # Returns appropriate daemon option for boolean property prop - if current
223 223 # value matches value_set.
224 224 #
225 225 get_daemon_option_from_boolean_property()
226 226 {
227 227 propval=`get_routeadm_property $1 $2`
228 228 if [ "$propval" = "$4" ]; then
229 229 echo "${3}"
230 230 fi
231 231 }
232 232
233 233 #
234 234 # get_daemon_option_from_property inst_fmri prop option ignore_value
235 235 #
236 236 # Returns appropriate daemon option and associated value (unless value
237 237 # matches ignore_value, in which case nothing is returned).
238 238 #
239 239 get_daemon_option_from_property()
240 240 {
241 241 propval=`get_routeadm_property $1 $2`
242 242 if [ "$propval" != "$4" ]; then
243 243 echo "-${3} $propval"
244 244 fi
245 245 }
246 246
247 247 #
↓ open down ↓ |
24 lines elided |
↑ open up ↑ |
248 248 # get_daemon_ordered_multivalue_option_from_property inst_fmri prop
249 249 # option
250 250 #
251 251 # Returns appropriate daemon option and associated values. Values are
252 252 # unquoted, i.e. -A value1 -A value2
253 253 #
254 254 get_daemon_ordered_multivalue_option_from_property()
255 255 {
256 256 # get property values, removing trailing delimiter.
257 257 propvals=`get_routeadm_property $1 $2 | \
258 - /usr/bin/nawk '{sub(/;[ \t]*$/, ""); print }'`
258 + /usr/xpg4/bin/awk '{sub(/;[ \t]*$/, ""); print }'`
259 259 # Substitute switch for internal delimiters.
260 260 fixed_propvals=`/usr/bin/echo $propvals | \
261 - /usr/bin/nawk -v SWITCH=" -${3} " \
261 + /usr/xpg4/bin/awk -v SWITCH=" -${3} " \
262 262 '{sub(/;/, SWITCH); print }'`
263 263 if [ -n "$fixed_propvals" ]; then
264 264 echo "-${3} $fixed_propvals"
265 265 fi
266 266 }
267 267
268 268 #
269 269 # get_nonoption_property inst_fmri prop ignore_value
270 270 #
271 271 # Returns appropriate non-option property (at end of option list), unless
272 272 # value matches ignore value, in which case nothing is returned.
273 273 #
274 274 get_daemon_nonoption_property()
275 275 {
276 276 propval=`get_routeadm_property $1 $2`
277 277 if [ -n "$propval" -a "$propval" != "$3" ]; then
278 278 echo "$propval"
279 279 fi
280 280 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX