#!/bin/sh # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # IPfilter's firewall # # routed and its siblings use ICMP Router Discovery protocol, simply allow # these packets so the client portion of routed can work. # proc gen_IRDP_rules { # Allow incoming icmp from routers for successful discovery. # IRDP - ICMP type 9 and 10, advertisement and solicitation, respectively. # echo "pass in log quick proto icmp from any to any icmp-type 10" >>${1} echo "pass in log quick proto icmp from any to any icmp-type 9" >>${1} } # # These functions are used to help map daemon arguments to appropriate # routing properties and back, allowing legacy specifications of daemon # arguments to be reflected in SMF property values for daemon services. # # # set_routeadm_property inst_fmri propname propvalue # # Functions sets appropriate property value in routeadm property group # (via routeadm -m) for inst_fmri to propvalue. # proc set_routeadm_property { /sbin/routeadm -m $1 ${2}="${3}" } # # The functions below are used to map from daemon arguments to appropriate # routeadm properties (properties that the service user can manipulate # to control daemon functionality. getopts is used extensively to # retrieve options/values from argument list, and these option values # are used to set properties appropriately. # # # set_daemon_value_property inst_fmri optstring options option prop # default_value # # Function looks for option/value in argument string, and sets associated # property if found. If a default is specified, and the option is not # in the argument string, it will be used. # proc set_daemon_value_property { setvar OPTIND = '1' setvar value_set = """" while getopts $3 opt $2 { match $opt { with "$4" set_routeadm_property $1 $5 $OPTARG setvar value_set = ""true"" with ? } } # No value set - use default if specified. if test -z $value_set -a -n $6 { set_routeadm_property $1 $5 $6 } } # # set_daemon_ordered_multivalue_property inst_fmri optstring options option prop # default_value # # Function looks for option/values in argument string, and sets associated # property if found. If a default is specified, and the option is not # in the argument string, it will be used. Use ";" as delimiter for # multiple values. # proc set_daemon_ordered_multivalue_property { setvar OPTIND = '1' setvar value_set = """" while getopts $3 opt $2 { match $opt { with "$4" if test -z $value_set { setvar value_set = "${OPTARG}" } else { setvar value_set = ""$value_set;${OPTARG}"" } with ? } } if test -n $value_set { set_routeadm_property $1 $5 $value_set } # No value set - use default if specified. if test -z $value_set -a -n $6 { set_routeadm_property $1 $5 $6 } } # # set_daemon_boolean_property inst_fmri optstring options option # prop value_if_found default # # Function looks for option in argument string, and sets associated # property, if found, to value_if_found. If a default is specified, and # the option is not found, it will be used. # proc set_daemon_boolean_property { setvar OPTIND = '1' setvar value_set = """" while getopts $3 opt $2 { match $opt { with "$4" set_routeadm_property $1 $5 $6 setvar value_set = ""true"" with ? } } # No value set - use default if specified. if test -z $value_set -a -n $7 { set_routeadm_property $1 $5 $7 } } # # set_daemon_nonoption_properties inst_fmri optstring options propnames # default # # Function looks past option list for addition values, and sets properties # specified in propnames to additional positional values. If no value # is found for additional property, default is used. # proc set_daemon_nonoption_properties { setvar OPTIND = '1' # Skip options while getopts $3 opt $2 { match $opt { with ? } } setvar pos = "$OPTIND" for prop in [$4] { setvar val = $(/usr/bin/echo $2 | /usr/bin/nawk -v POS=$pos \ '{ print $POS }) if test -z $val { setvar val = "$5" } set_routeadm_property $1 $prop $val setvar pos = $(expr $pos + 1) } } # # get_daemon_args $inst_fmri # # Retrieves routeadm/daemon-args property values, if any. Removes # quotes around values including spaces. # proc get_daemon_args { setvar args = $(/usr/sbin/svccfg -s $1 listprop routeadm/daemon-args | \ /usr/bin/nawk '{ for (i = 3; i <= NF; i++) printf "%s ", $i }' | \ /usr/bin/nawk '{sub(/^\"/, ""); sub(/\"[ \t]*$/,""); print}) echo $args } # # clear_daemon_args $inst_fmri # # Blanks routeadm/daemon-args property used in upgrade. # proc clear_daemon_args { /usr/sbin/svccfg -s $1 delprop routeadm/daemon-args 2>/dev/null } # # The functions below are used to map back from property settings to # commandline arguments to launch daemons. # proc get_routeadm_property { setvar propval = $(/sbin/routeadm -l $1 | /usr/bin/nawk -v PROP=$2 \ '($1 == PROP) { for (i = 3; i < NF; i++) printf $i" "; \ if (NF >= 3) {printf $NF}}) echo $propval } # # get_daemon_option_from_boolean_property inst_fmri prop option value_set # # Returns appropriate daemon option for boolean property prop - if current # value matches value_set. # proc get_daemon_option_from_boolean_property { setvar propval = $(get_routeadm_property $1 $2) if test $propval = $4 { echo ${3} } } # # get_daemon_option_from_property inst_fmri prop option ignore_value # # Returns appropriate daemon option and associated value (unless value # matches ignore_value, in which case nothing is returned). # proc get_daemon_option_from_property { setvar propval = $(get_routeadm_property $1 $2) if test $propval != $4 { echo "-${3} $propval" } } # # get_daemon_ordered_multivalue_option_from_property inst_fmri prop # option # # Returns appropriate daemon option and associated values. Values are # unquoted, i.e. -A value1 -A value2 # proc get_daemon_ordered_multivalue_option_from_property { # get property values, removing trailing delimiter. setvar propvals = $(get_routeadm_property $1 $2 | \ /usr/bin/nawk '{sub(/;[ \t]*$/, ""); print }) # Substitute switch for internal delimiters. setvar fixed_propvals = $(/usr/bin/echo $propvals | \ /usr/bin/nawk -v SWITCH=" -${3} " \ '{sub(/;/, SWITCH); print }) if test -n $fixed_propvals { echo "-${3} $fixed_propvals" } } # # get_nonoption_property inst_fmri prop ignore_value # # Returns appropriate non-option property (at end of option list), unless # value matches ignore value, in which case nothing is returned. # proc get_daemon_nonoption_property { setvar propval = $(get_routeadm_property $1 $2) if test -n $propval -a $propval != $3 { echo $propval } }