1 #!/bin/sh 2 # 3 # CDDL HEADER START 4 # 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. 8 # 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. 13 # 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] 19 # 20 # CDDL HEADER END 21 # 22 # 23 # Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24 # Use is subject to license terms. 25 # 26 27 # 28 # IPfilter's firewall 29 # 30 # routed and its siblings use ICMP Router Discovery protocol, simply allow 31 # these packets so the client portion of routed can work. 32 # 33 gen_IRDP_rules() 34 { 35 # Allow incoming icmp from routers for successful discovery. 36 # IRDP - ICMP type 9 and 10, advertisement and solicitation, respectively. 37 # 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} 40 } 41 42 # 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. 46 # 47 48 # 49 # set_routeadm_property inst_fmri propname propvalue 50 # 51 # Functions sets appropriate property value in routeadm property group 52 # (via routeadm -m) for inst_fmri to propvalue. 53 # 54 set_routeadm_property() 55 { 56 /sbin/routeadm -m $1 ${2}="${3}" 57 } 58 59 # 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. 65 # 66 67 # 68 # set_daemon_value_property inst_fmri optstring options option prop 69 # default_value 70 # 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. 74 # 75 set_daemon_value_property() 76 { 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" 83 ;; 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 90 fi 91 } 92 93 # 94 # set_daemon_ordered_multivalue_property inst_fmri optstring options option prop 95 # default_value 96 # 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. 101 # 102 set_daemon_ordered_multivalue_property() 103 { 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}" 112 fi 113 ;; 114 ? ) 115 esac 116 done 117 if [ -n "$value_set" ]; then 118 set_routeadm_property $1 $5 "$value_set" 119 fi 120 # No value set - use default if specified. 121 if [ -z "$value_set" -a -n "$6" ]; then 122 set_routeadm_property $1 $5 $6 123 fi 124 } 125 126 # 127 # set_daemon_boolean_property inst_fmri optstring options option 128 # prop value_if_found default 129 # 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. 133 # 134 set_daemon_boolean_property() 135 { 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" 142 ;; 143 ? ) 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 149 fi 150 } 151 152 # 153 # set_daemon_nonoption_properties inst_fmri optstring options propnames 154 # default 155 # 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. 159 # 160 set_daemon_nonoption_properties() 161 { 162 OPTIND=1 163 # Skip options 164 while getopts $3 opt $2; do 165 case $opt in 166 ? ) 167 esac 168 done 169 pos=$OPTIND 170 for prop in $4 171 do 172 val=`/usr/bin/echo $2 | /usr/bin/nawk -v POS=$pos \ 173 '{ print $POS }'` 174 if [ -z "$val" ]; then 175 val="$5" 176 fi 177 set_routeadm_property $1 $prop $val 178 pos=`expr $pos + 1` 179 done 180 } 181 182 # 183 # get_daemon_args $inst_fmri 184 # 185 # Retrieves routeadm/daemon-args property values, if any. Removes 186 # quotes around values including spaces. 187 # 188 get_daemon_args() 189 { 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" 194 } 195 196 # 197 # clear_daemon_args $inst_fmri 198 # 199 # Blanks routeadm/daemon-args property used in upgrade. 200 # 201 clear_daemon_args() 202 { 203 /usr/sbin/svccfg -s $1 delprop routeadm/daemon-args 2>/dev/null 204 } 205 206 # 207 # The functions below are used to map back from property settings to 208 # commandline arguments to launch daemons. 209 # 210 211 get_routeadm_property() 212 { 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" 217 } 218 219 # 220 # get_daemon_option_from_boolean_property inst_fmri prop option value_set 221 # 222 # Returns appropriate daemon option for boolean property prop - if current 223 # value matches value_set. 224 # 225 get_daemon_option_from_boolean_property() 226 { 227 propval=`get_routeadm_property $1 $2` 228 if [ "$propval" = "$4" ]; then 229 echo "${3}" 230 fi 231 } 232 233 # 234 # get_daemon_option_from_property inst_fmri prop option ignore_value 235 # 236 # Returns appropriate daemon option and associated value (unless value 237 # matches ignore_value, in which case nothing is returned). 238 # 239 get_daemon_option_from_property() 240 { 241 propval=`get_routeadm_property $1 $2` 242 if [ "$propval" != "$4" ]; then 243 echo "-${3} $propval" 244 fi 245 } 246 247 # 248 # get_daemon_ordered_multivalue_option_from_property inst_fmri prop 249 # option 250 # 251 # Returns appropriate daemon option and associated values. Values are 252 # unquoted, i.e. -A value1 -A value2 253 # 254 get_daemon_ordered_multivalue_option_from_property() 255 { 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" 265 fi 266 } 267 268 # 269 # get_nonoption_property inst_fmri prop ignore_value 270 # 271 # Returns appropriate non-option property (at end of option list), unless 272 # value matches ignore value, in which case nothing is returned. 273 # 274 get_daemon_nonoption_property() 275 { 276 propval=`get_routeadm_property $1 $2` 277 if [ -n "$propval" -a "$propval" != "$3" ]; then 278 echo "$propval" 279 fi 280 }