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