8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / svc / shell / routing_include.sh
blob79206b38f85eb3bc51763390e21ab92c7450b490
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 2009 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
28 # IPfilter's firewall
30 # routed and its siblings use ICMP Router Discovery protocol, simply allow
31 # these packets so the client portion of routed can work.
33 gen_IRDP_rules()
35 # Allow incoming icmp from routers for successful discovery.
36 # IRDP - ICMP type 9 and 10, advertisement and solicitation, respectively.
38 echo "pass in log quick proto icmp from any to any icmp-type 10" >>${1}
39 echo "pass in log quick proto icmp from any to any icmp-type 9" >>${1}
43 # These functions are used to help map daemon arguments to appropriate
44 # routing properties and back, allowing legacy specifications of daemon
45 # arguments to be reflected in SMF property values for daemon services.
49 # set_routeadm_property inst_fmri propname propvalue
51 # Functions sets appropriate property value in routeadm property group
52 # (via routeadm -m) for inst_fmri to propvalue.
54 set_routeadm_property()
56 /sbin/routeadm -m $1 ${2}="${3}"
60 # The functions below are used to map from daemon arguments to appropriate
61 # routeadm properties (properties that the service user can manipulate
62 # to control daemon functionality. getopts is used extensively to
63 # retrieve options/values from argument list, and these option values
64 # are used to set properties appropriately.
68 # set_daemon_value_property inst_fmri optstring options option prop
69 # default_value
71 # Function looks for option/value in argument string, and sets associated
72 # property if found. If a default is specified, and the option is not
73 # in the argument string, it will be used.
75 set_daemon_value_property()
77 OPTIND=1
78 value_set=""
79 while getopts $3 opt $2; do
80 case $opt in
81 "$4" ) set_routeadm_property $1 $5 $OPTARG
82 value_set="true"
84 ? )
85 esac
86 done
87 # No value set - use default if specified.
88 if [ -z "$value_set" -a -n "$6" ]; then
89 set_routeadm_property $1 $5 $6
94 # set_daemon_ordered_multivalue_property inst_fmri optstring options option prop
95 # default_value
97 # Function looks for option/values in argument string, and sets associated
98 # property if found. If a default is specified, and the option is not
99 # in the argument string, it will be used. Use ";" as delimiter for
100 # multiple values.
102 set_daemon_ordered_multivalue_property()
104 OPTIND=1
105 value_set=""
106 while getopts $3 opt $2; do
107 case $opt in
108 "$4" ) if [ -z "$value_set" ]; then
109 value_set="${OPTARG}"
110 else
111 value_set="$value_set;${OPTARG}"
115 esac
116 done
117 if [ -n "$value_set" ]; then
118 set_routeadm_property $1 $5 "$value_set"
120 # No value set - use default if specified.
121 if [ -z "$value_set" -a -n "$6" ]; then
122 set_routeadm_property $1 $5 $6
127 # set_daemon_boolean_property inst_fmri optstring options option
128 # prop value_if_found default
130 # Function looks for option in argument string, and sets associated
131 # property, if found, to value_if_found. If a default is specified, and
132 # the option is not found, it will be used.
134 set_daemon_boolean_property()
136 OPTIND=1
137 value_set=""
138 while getopts $3 opt $2; do
139 case $opt in
140 "$4" ) set_routeadm_property $1 $5 $6
141 value_set="true"
144 esac
145 done
146 # No value set - use default if specified.
147 if [ -z "$value_set" -a -n "$7" ]; then
148 set_routeadm_property $1 $5 $7
153 # set_daemon_nonoption_properties inst_fmri optstring options propnames
154 # default
156 # Function looks past option list for addition values, and sets properties
157 # specified in propnames to additional positional values. If no value
158 # is found for additional property, default is used.
160 set_daemon_nonoption_properties()
162 OPTIND=1
163 # Skip options
164 while getopts $3 opt $2; do
165 case $opt in
167 esac
168 done
169 pos=$OPTIND
170 for prop in $4
172 val=`/usr/bin/echo $2 | /usr/bin/nawk -v POS=$pos \
173 '{ print $POS }'`
174 if [ -z "$val" ]; then
175 val="$5"
177 set_routeadm_property $1 $prop $val
178 pos=`expr $pos + 1`
179 done
183 # get_daemon_args $inst_fmri
185 # Retrieves routeadm/daemon-args property values, if any. Removes
186 # quotes around values including spaces.
188 get_daemon_args()
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}'`
193 echo "$args"
197 # clear_daemon_args $inst_fmri
199 # Blanks routeadm/daemon-args property used in upgrade.
201 clear_daemon_args()
203 /usr/sbin/svccfg -s $1 delprop routeadm/daemon-args 2>/dev/null
207 # The functions below are used to map back from property settings to
208 # commandline arguments to launch daemons.
211 get_routeadm_property()
213 propval=`/sbin/routeadm -l $1 | /usr/bin/nawk -v PROP=$2 \
214 '($1 == PROP) { for (i = 3; i < NF; i++) printf $i" "; \
215 if (NF >= 3) {printf $NF}}'`
216 echo "$propval"
220 # get_daemon_option_from_boolean_property inst_fmri prop option value_set
222 # Returns appropriate daemon option for boolean property prop - if current
223 # value matches value_set.
225 get_daemon_option_from_boolean_property()
227 propval=`get_routeadm_property $1 $2`
228 if [ "$propval" = "$4" ]; then
229 echo "${3}"
234 # get_daemon_option_from_property inst_fmri prop option ignore_value
236 # Returns appropriate daemon option and associated value (unless value
237 # matches ignore_value, in which case nothing is returned).
239 get_daemon_option_from_property()
241 propval=`get_routeadm_property $1 $2`
242 if [ "$propval" != "$4" ]; then
243 echo "-${3} $propval"
248 # get_daemon_ordered_multivalue_option_from_property inst_fmri prop
249 # option
251 # Returns appropriate daemon option and associated values. Values are
252 # unquoted, i.e. -A value1 -A value2
254 get_daemon_ordered_multivalue_option_from_property()
256 # get property values, removing trailing delimiter.
257 propvals=`get_routeadm_property $1 $2 | \
258 /usr/bin/nawk '{sub(/;[ \t]*$/, ""); print }'`
259 # Substitute switch for internal delimiters.
260 fixed_propvals=`/usr/bin/echo $propvals | \
261 /usr/bin/nawk -v SWITCH=" -${3} " \
262 '{sub(/;/, SWITCH); print }'`
263 if [ -n "$fixed_propvals" ]; then
264 echo "-${3} $fixed_propvals"
269 # get_nonoption_property inst_fmri prop ignore_value
271 # Returns appropriate non-option property (at end of option list), unless
272 # value matches ignore value, in which case nothing is returned.
274 get_daemon_nonoption_property()
276 propval=`get_routeadm_property $1 $2`
277 if [ -n "$propval" -a "$propval" != "$3" ]; then
278 echo "$propval"