ipf_include.sh revision 2bd8b3545dceb97f56401b7ad2a327e08d520574
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#!/sbin/sh
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# CDDL HEADER START
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# The contents of this file are subject to the terms of the
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# Common Development and Distribution License (the "License").
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# You may not use this file except in compliance with the License.
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# or http://www.opensolaris.org/os/licensing.
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# See the License for the specific language governing permissions
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# and limitations under the License.
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# When distributing Covered Code, include this CDDL HEADER in each
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# If applicable, add the following below this CDDL HEADER, with the
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# fields enclosed by brackets "[]" replaced with your own identifying
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# information: Portions Copyright [yyyy] [name of copyright owner]
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# CDDL HEADER END
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
ea7d3b1a278e2af7b09658d7a51d5b61d6ee490fTruong Nguyen# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld# Copyright 2016 Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. MaskeyIPFILTER_FMRI="svc:/network/ipfilter:default"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong NguyenETC_IPF_DIR=/etc/ipf
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. MaskeyIPNATCONF=`/usr/bin/svcprop -p config/ipnat_config_file $IPFILTER_FMRI \
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey 2>/dev/null`
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyif [ $? -eq 1 ]; then
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey IPNATCONF=$ETC_IPF_DIR/ipnat.conf
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyfi
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. MaskeyIPPOOLCONF=`/usr/bin/svcprop -p config/ippool_config_file $IPFILTER_FMRI \
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey 2>/dev/null`
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyif [ $? -eq 1 ]; then
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey IPPOOLCONF=$ETC_IPF_DIR/ippool.conf
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyfi
ada83f08084885463e1f362944377a12294a1feeTruong NguyenVAR_IPF_DIR=/var/run/ipf
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong NguyenIPFILCONF=$VAR_IPF_DIR/ipf.conf
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans RosenfeldIP6FILCONF=$VAR_IPF_DIR/ipf6.conf
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong NguyenIPFILOVRCONF=$VAR_IPF_DIR/ipf_ovr.conf
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans RosenfeldIP6FILOVRCONF=$VAR_IPF_DIR/ipf6_ovr.conf
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong NguyenIPF_LOCK=/var/run/ipflock
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong NguyenCONF_FILES=""
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans RosenfeldCONF6_FILES=""
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong NguyenNAT_FILES=""
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong NguyenIPF_SUFFIX=".ipf"
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans RosenfeldIPF6_SUFFIX=".ipf6"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong NguyenNAT_SUFFIX=".nat"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# version for configuration upgrades
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong NguyenCURRENT_VERSION=1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong NguyenIPF_FMRI="svc:/network/ipfilter:default"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong NguyenINETDFMRI="svc:/network/inetd:default"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong NguyenRPCBINDFMRI="svc:/network/rpc/bind:default"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong NguyenSMF_ONLINE="online"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong NguyenSMF_MAINT="maintenance"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong NguyenSMF_NONE="none"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong NguyenFW_CONTEXT_PG="firewall_context"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong NguyenMETHOD_PROP="ipf_method"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong NguyenFW_CONFIG_PG="firewall_config"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong NguyenPOLICY_PROP="policy"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong NguyenAPPLY2_PROP="apply_to"
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans RosenfeldAPPLY2_6_PROP="apply_to_6"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong NguyenEXCEPTIONS_PROP="exceptions"
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans RosenfeldEXCEPTIONS_6_PROP="exceptions_6"
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans RosenfeldTARGET_PROP="target"
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans RosenfeldTARGET_6_PROP="target_6"
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans RosenfeldBLOCKPOL_PROP="block_policy"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong NguyenFW_CONFIG_DEF_PG="firewall_config_default"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong NguyenFW_CONFIG_OVR_PG="firewall_config_override"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong NguyenCUSTOM_FILE_PROP="custom_policy_file"
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans RosenfeldCUSTOM_FILE_6_PROP="custom_policy_file_6"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong NguyenOPEN_PORTS_PROP="open_ports"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong NguyenPREFIX_HOST="host:"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong NguyenPREFIX_NET="network:"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong NguyenPREFIX_POOL="pool:"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong NguyenPREFIX_IF="if:"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. NguyenGLOBAL_CONFIG=""
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. NguyenGLOBAL_POLICY=""
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans RosenfeldGLOBAL_BLOCK_POLICY=""
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong NguyenSERVINFO=/usr/lib/servinfo
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen#
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen# Get value(s) for given property from either firewall_config_default or
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen# firewall_config_override property groups.
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen#
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen# global_get_prop_value pg_name propname
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen# pg_name - FW_CONFIG_DEF_PG or FW_CONFIG_OVR_PG
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen# propname - property name
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen#
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyenglobal_get_prop_value()
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen{
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen target_pg=$1
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen prop=$2
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen [ "$1" != $FW_CONFIG_OVR_PG -a "$1" != $FW_CONFIG_DEF_PG ] && return
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen [ "$1" == $FW_CONFIG_DEF_PG ] && extra_pg=$FW_CONFIG_OVR_PG || \
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen extra_pg=$FW_CONFIG_DEF_PG
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen value=`echo $GLOBAL_CONFIG | awk '{
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen found=0
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen for (i=1; i<=NF; i++) {
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen if (found == 1) {
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen if (index($i, target_pg) == 1 || index($i, extra_pg) == 1)
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen break;
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen print $i;
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen }
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen if (split($i, values, "/") < 2)
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen continue;
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen if (values[1] == target_pg && values[2] == prop)
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen found=1;
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen }
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen }' target_pg=$target_pg prop=$prop extra_pg=$extra_pg`
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen # Return
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen echo "$value"
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen}
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen#
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen# Initialize and cache network/ipfilter configuration, global configuration.
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen#
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen# Since an SMF service configuration may get updated during the execution of the
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen# service method, it's best to read all relevant configuration via one svcprop
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen# invocation and cache it for later use.
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen#
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld# This function reads and stores relevant configuration into GLOBAL_CONFIG and
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld# initializes the GLOBAL_POLICY and GLOBAL_BLOCK_POLICY variables. GLOBAL_CONFIG
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld# is a string containing pg/prop and their corresponding values (i.e. svcprop -p
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld# pg fmri output). To get values for a certain pg/prop, use
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld# global_get_prop_value().
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen#
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyenglobal_init()
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen{
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen GLOBAL_CONFIG=`svcprop -p ${FW_CONFIG_OVR_PG} -p ${FW_CONFIG_DEF_PG} \
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen $IPF_FMRI 2>/dev/null | awk '{$2=" "; print $0}'`
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen GLOBAL_POLICY=`global_get_prop_value $FW_CONFIG_DEF_PG $POLICY_PROP`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld GLOBAL_BLOCK_POLICY=`global_get_prop_value $FW_CONFIG_DEF_PG \
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld $BLOCKPOL_PROP`
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen}
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# Given a service, gets its config pg name
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyenget_config_pg()
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen{
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen if [ "$1" = "$IPF_FMRI" ]; then
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen echo "$FW_CONFIG_DEF_PG"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen else
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen echo "$FW_CONFIG_PG"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen return 0
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# Given a service, gets its firewall policy
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyenget_policy()
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen{
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen config_pg=`get_config_pg $1`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen svcprop -p $config_pg/${POLICY_PROP} $1 2>/dev/null
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld# block policy can be set to "return", which will expand into
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld# separate block rules for tcp (block return-rst ...) and all other
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld# protocols (block return-icmp-as-dest ...)
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld#
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeldget_block_policy()
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld{
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld config_pg=`get_config_pg $1`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld svcprop -p $config_pg/${BLOCKPOL_PROP} $1 2>/dev/null
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld}
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld#
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld# Given a service, gets its source address exceptions for IPv4
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyenget_exceptions()
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen{
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen config_pg=`get_config_pg $1`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld exceptions=`svcprop -p $config_pg/${EXCEPTIONS_PROP} $1 2>/dev/null`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld echo $exceptions | sed -e 's/\\//g'
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld# Given a service, gets its source address exceptions for IPv6
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld#
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeldget_exceptions_6()
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld{
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld config_pg=`get_config_pg $1`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld exceptions6=`svcprop -p $config_pg/${EXCEPTIONS_6_PROP} $1 2>/dev/null`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld echo $exceptions6 | sed -e 's/\\//g'
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld}
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld#
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld# Given a service, gets its firewalled source addresses for IPv4
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyenget_apply2_list()
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen{
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen config_pg=`get_config_pg $1`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld apply2=`svcprop -p $config_pg/${APPLY2_PROP} $1 2>/dev/null`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld echo $apply2 | sed -e 's/\\//g'
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld}
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld#
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld# Given a service, gets its firewalled source addresses for IPv6
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld#
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeldget_apply2_6_list()
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld{
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld config_pg=`get_config_pg $1`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld apply2_6=`svcprop -p $config_pg/${APPLY2_6_PROP} $1 2>/dev/null`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld echo $apply2_6 | sed -e 's/\\//g'
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld}
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld#
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld# Given a service, gets its firewalled target addresses for IPv4
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld#
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeldget_target_list()
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld{
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld config_pg=`get_config_pg $1`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld target=`svcprop -p $config_pg/${TARGET_PROP} $1 2>/dev/null`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld [ -z "$target" -o "$target" = '""' ] && target=any
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld echo $target | sed -e 's/\\//g'
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld}
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld#
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld# Given a service, gets its firewalled target addresses for IPv6
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld#
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeldget_target_6_list()
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld{
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld config_pg=`get_config_pg $1`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld target6=`svcprop -p $config_pg/${TARGET_6_PROP} $1 2>/dev/null`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld [ -z "$target6" -o "$target6" = '""' ] && target6=any
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld echo $target6 | sed -e 's/\\//g'
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyencheck_ipf_dir()
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen{
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen [ -d $VAR_IPF_DIR ] && return 0
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen mkdir $VAR_IPF_DIR >/dev/null 2>&1 || return 1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# fmri_to_file fmri suffix
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyenfmri_to_file()
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen{
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen check_ipf_dir || return 1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fprefix="${VAR_IPF_DIR}/`echo $1 | tr -s '/:' '__'`"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen echo "${fprefix}${2}"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# Return service's enabled property
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyenservice_is_enabled()
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen{
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen # Temporary enabled state overrides the persistent state
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen # so check it first.
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen enabled_ovr=`svcprop -c -p general_ovr/enabled $1 2>/dev/null`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen if [ -n "$enabled_ovr" ]; then
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen [ "$enabled_ovr" = "true" ] && return 0 || return 1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen enabled=`svcprop -c -p general/enabled $1 2>/dev/null`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen [ -n "$enabled" -a "$enabled" = "true" ] && return 0 || return 1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# Return whether service is desired state
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# Args: fmri state
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# Return:
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# 0 - desired state is service's current state
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# 1 - desired state is not service's current state
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyenservice_check_state()
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen{
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen # Make sure we're done with ongoing state transition
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen while [ "`svcprop -p restarter/next_state $1`" != "$SMF_NONE" ]; do
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen sleep 1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen done
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen [ "`svcprop -p restarter/state $1`" = "$2" ] && return 0 || return 1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# Deny/Allow list stores values in the form "host:addr", "network:addr/netmask",
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# "pool:number", and "if:interface". This function returns the
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# IP(addr or addr/netmask) value or a pool number.
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyenget_IP()
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen{
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen value_is_interface $1 && return 1
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld echo "$1" | sed -n -e "s,^${PREFIX_POOL}\(.*\),pool/\1,p" \
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld -e "s,^${PREFIX_HOST}\(.*\),\1,p" \
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld -e "s,^${PREFIX_NET}\(.*\),\1,p" \
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld -e "s,^any,any,p"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyenget_interface()
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen{
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen value_is_interface $1 || return 1
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld scratch=`echo "$1" | sed -e "s/^${PREFIX_IF}//"`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen ifconfig $scratch >/dev/null 2>&1 || return 1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen echo $scratch | sed -e 's/:.*//'
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyenvalue_is_interface()
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen{
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen [ -z "$1" ] && return 1
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld echo $1 | grep "^${PREFIX_IF}" >/dev/null 2>&1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# Remove rules in given file from active list without restarting ipfilter
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyenremove_rules()
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen{
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld [ -f "$1" ] && ipf $2 -r -f $1 >/dev/null 2>&1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyenremove_nat_rules()
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen{
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen [ -f "$1" ] && ipnat -r -f $1 >/dev/null 2>&1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyencheck_ipf_syntax()
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen{
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld ipf $2 -n -f $1 >/dev/null 2>&1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyencheck_nat_syntax()
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen{
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen ipnat -n -f $1 >/dev/null 2>&1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeldunique_ports()
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld{
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld echo $* | xargs -n 1 echo | sort -u
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld}
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyenfile_get_ports()
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen{
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld ipf $2 -n -v -f $1 2>/dev/null | sed -n -e \
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen 's/.*to.* port = \([a-z0-9]*\).*/\1/p' | uniq | \
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen awk '{if (length($0) > 1) {printf("%s ", $1)}}'
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyenget_active_ports()
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen{
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld ipfstat $1 -io 2>/dev/null | sed -n -e \
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen 's/.*to.* port = \([a-z0-9]*\).*/\1/p' | uniq | \
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen awk '{if (length($0) > 1) {printf("%s ",$1)}}'
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# Given two list of ports, return failure if there's a duplicate.
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyensets_check_duplicate()
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen{
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen # If either list is empty, there isn't any conflict.
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen [ -z "$1" -o -z "$2" ] && return 0
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen for p in $1; do
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen for ap in $2; do
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen [ "$p" = "$ap" ] && return 1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen done
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen done
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen return 0
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# Given a file containing ipf rules, check the syntax and verify
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# the rules don't conflict, use same port number, with active
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# rules (ipfstat -io output).
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyenupdate_check_ipf_rules()
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen{
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld check_ipf_syntax $1 $2 || return 1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld lports=`file_get_ports $1 $2`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld lactive_ports=`get_active_ports $2`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen sets_check_duplicate "$lports" "$lactive_ports" || return 1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyenserver_port_list=""
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeldserver_port_list_6=""
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# Given a file containing ipf rules, check the syntax and verify
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# the rules don't conflict with already processed services.
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# The list of processed services' ports are maintained in the global
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld# variables 'server_port_list' and 'server_port_list_6'.
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyencheck_ipf_rules()
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen{
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld check_ipf_syntax $1 $2 || return 1
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld lports=`file_get_ports $1 $2`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld if [ "$2" = "-6" ]; then
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld sets_check_duplicate "$lports" "$server_port_list_6" || return 1
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld server_port_list_6="$server_port_list_6 $lports"
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld else
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld sets_check_duplicate "$lports" "$server_port_list" || return 1
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld server_port_list="$server_port_list $lports"
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld fi
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen return 0
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyenprepend_new_rules()
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen{
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld check_ipf_syntax $1 $2 && tail -r $1 | sed -e 's/^[a-z]/@0 &/' | \
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld ipf $2 -f - >/dev/null 2>&1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyenappend_new_rules()
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen{
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld check_ipf_syntax $1 $2 && ipf $2 -f $1 >/dev/null 2>&1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyenappend_new_nat_rules()
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen{
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen check_nat_syntax $1 && ipnat -f $1 >/dev/null 2>&1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# get port information from string of the form "proto:{port | port-port}"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyentuple_get_port()
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen{
2bd8b3545dceb97f56401b7ad2a327e08d520574Hans Rosenfeld port_str=`echo "$1" | sed -e 's/ //g; s/\\\//g; s/.*://' 2>/dev/null`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen [ -z "$port_str" ] && return 1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen echo $port_str | grep "-" >/dev/null
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen if [ $? -eq 0 ]; then
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen echo $port_str | grep '^[0-9]\{1,5\}-[0-9]\{1,5\}$' >/dev/null || \
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen return 1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen ports=`echo $port_str | ( IFS=- read a b ; \
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen [ $a \-le $b ] && echo $a $b || echo $b $a )`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen for p in $ports; do
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen [ $p -gt 65535 ] && return 1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen done
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen echo "$ports"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen else
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen # port_str is a single port, verify and return it.
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen echo "$port_str" | grep '^[0-9]\{1,5\}$' >/dev/null || return 1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen [ $port_str -gt 65535 ] && return 1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen echo "$port_str"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# get proto info from string of the form "{tcp | udp}:port"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyentuple_get_proto()
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen{
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen proto=`echo "$1" | sed -e 's/ //g; s/:.*//' 2>/dev/null`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen [ -z "$proto" ] && return 0
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen [ "$proto" = "tcp" -o "$proto" = "udp" ] && echo $proto || return 1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen return 0
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyenipf_get_lock()
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen{
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen newpid=$$
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen if [ -f "$IPF_LOCK/pid" ]; then
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen curpid=`cat $IPF_LOCK/pid 2>/dev/null`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen [ "$curpid" = "$newpid" ] && return 0
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen # Clear lock if the owning process is no longer around.
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen ps -p $curpid >/dev/null 2>&1 || rm -r $IPF_LOCK >/dev/null 2>&1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen # Grab the lock
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen while :; do
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen mkdir $IPF_LOCK 2>/dev/null && break;
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen sleep 1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen done
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen echo $newpid > $IPF_LOCK/pid
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# Remove lock if it's ours
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyenipf_remove_lock()
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen{
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen if [ -f "$IPF_LOCK/pid" ]; then
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen [ "`cat $IPF_LOCK/pid`" = "$$" ] && rm -r $IPF_LOCK
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen return 0
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# Make IPFILCONF, /var/tmp/ipf/ipf.conf, a symlink to the input file argument.
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyencustom_set_symlink()
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen{
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
caa64d545b688cd708983338e8c85b054ecfc8beTruong Nguyen # Nothing to do if the input file doesn't exist.
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen [ ! -f "$1" ] && return 0
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
caa64d545b688cd708983338e8c85b054ecfc8beTruong Nguyen check_ipf_dir || return 1
caa64d545b688cd708983338e8c85b054ecfc8beTruong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen rm $IPFILCONF >/dev/null 2>&1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen ln -s $1 $IPFILCONF >/dev/null 2>&1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
2bd8b3545dceb97f56401b7ad2a327e08d520574Hans Rosenfeld#
2bd8b3545dceb97f56401b7ad2a327e08d520574Hans Rosenfeld# Make IP6FILCONF, /var/tmp/ipf/ipf6.conf, a symlink to the input file argument.
2bd8b3545dceb97f56401b7ad2a327e08d520574Hans Rosenfeld#
2bd8b3545dceb97f56401b7ad2a327e08d520574Hans Rosenfeldcustom_set_symlink_6()
2bd8b3545dceb97f56401b7ad2a327e08d520574Hans Rosenfeld{
2bd8b3545dceb97f56401b7ad2a327e08d520574Hans Rosenfeld #
2bd8b3545dceb97f56401b7ad2a327e08d520574Hans Rosenfeld # Nothing to do if the input file doesn't exist.
2bd8b3545dceb97f56401b7ad2a327e08d520574Hans Rosenfeld #
2bd8b3545dceb97f56401b7ad2a327e08d520574Hans Rosenfeld [ ! -f "$1" ] && return 0
2bd8b3545dceb97f56401b7ad2a327e08d520574Hans Rosenfeld
2bd8b3545dceb97f56401b7ad2a327e08d520574Hans Rosenfeld check_ipf_dir || return 1
2bd8b3545dceb97f56401b7ad2a327e08d520574Hans Rosenfeld
2bd8b3545dceb97f56401b7ad2a327e08d520574Hans Rosenfeld rm $IP6FILCONF >/dev/null 2>&1
2bd8b3545dceb97f56401b7ad2a327e08d520574Hans Rosenfeld ln -s $1 $IP6FILCONF >/dev/null 2>&1
2bd8b3545dceb97f56401b7ad2a327e08d520574Hans Rosenfeld}
2bd8b3545dceb97f56401b7ad2a327e08d520574Hans Rosenfeld
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# New file replaces original file if they have different content
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyenreplace_file()
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen{
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen orig=$1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen new=$2
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen # IPFILCONF may be a symlink, remove it if that's the case
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen if [ -L "$orig" ]; then
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen rm $orig
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen touch $orig
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
caa64d545b688cd708983338e8c85b054ecfc8beTruong Nguyen check_ipf_dir || return 1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen mv $new $orig && return 0 || return 1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# Given a service, gets the following details for ipf rule:
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# - policy
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# - protocol
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# - port(IANA port obtained by running servinfo)
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyenprocess_server_svc()
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen{
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen service=$1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen policy=`get_policy ${service}`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen # Empties service's rules file so callers won't use existing rule if
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen # we fail here.
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen file=`fmri_to_file $service $IPF_SUFFIX`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld file6=`fmri_to_file $service $IPF6_SUFFIX`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen [ -z "$file" ] && return 1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen echo "# $service" >${file}
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld echo "# $service" >${file6}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen # Nothing to do if policy is "use_global"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen [ "$policy" = "use_global" ] && return 0
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen restarter=`svcprop -p general/restarter $service 2>/dev/null`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen if [ "$restarter" = "$INETDFMRI" ]; then
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen iana_name=`svcprop -p inetd/name $service 2>/dev/null`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen isrpc=`svcprop -p inetd/isrpc $service 2>/dev/null`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen else
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen iana_name=`svcprop -p $FW_CONTEXT_PG/name $service 2>/dev/null`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen isrpc=`svcprop -p $FW_CONTEXT_PG/isrpc $service 2>/dev/null`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen # Bail if iana_name isn't defined. Services with static rules
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen # like nis/client don't need to generate rules using
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen # iana name and protocol information.
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen [ -z "$iana_name" ] && return 1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen # RPC services
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen if [ "$isrpc" = "true" ]; then
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld # The ports used for IPv6 are usually also reachable
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld # through IPv4, so generate IPv4 rules for them, too.
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen tports=`$SERVINFO -R -p -t -s $iana_name 2>/dev/null`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld tports6=`$SERVINFO -R -p -t6 -s $iana_name 2>/dev/null`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld if [ -n "$tports" -o -n "$tports6" ]; then
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld tports=`unique_ports $tports $tports6`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen for tport in $tports; do
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen generate_rules $service $policy "tcp" \
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld $tport $file
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld done
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld fi
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld if [ -n "$tports6" ]; then
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld for tport6 in $tports6; do
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld generate_rules $service $policy "tcp" \
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld $tport6 $file6 _6
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen done
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen uports=`$SERVINFO -R -p -u -s $iana_name 2>/dev/null`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld uports6=`$SERVINFO -R -p -u6 -s $iana_name 2>/dev/null`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen if [ -n "$uports" ]; then
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld uports=`unique_ports $uports $uports6`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen for uport in $uports; do
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen generate_rules $service $policy "udp" \
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld $uport $file
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld done
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld fi
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld if [ -n "$uports6" ]; then
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld for uport6 in $uports6; do
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld generate_rules $service $policy "udp" \
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld $uport6 $file6 _6
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen done
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen return 0
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen # Get the IANA port and supported protocols(tcp and udp)
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen tport=`$SERVINFO -p -t -s $iana_name 2>&1`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen if [ $? -eq 0 -a -n "$tport" ]; then
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld generate_rules $service $policy "tcp" $tport $file
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld fi
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld tport6=`$SERVINFO -p -t6 -s $iana_name 2>&1`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld if [ $? -eq 0 -a -n "$tport6" ]; then
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld generate_rules $service $policy "tcp" $tport6 $file6 _6
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen uport=`$SERVINFO -p -u -s $iana_name 2>&1`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen if [ $? -eq 0 -a -n "$uport" ]; then
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld generate_rules $service $policy "udp" $uport $file
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld fi
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld uport6=`$SERVINFO -p -u6 -s $iana_name 2>&1`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld if [ $? -eq 0 -a -n "$uport6" ]; then
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld generate_rules $service $policy "udp" $uport6 $file6 _6
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen return 0
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# Given a service's name, policy, protocol and port, generate ipf rules
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# - list of host/network/interface to apply policy
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# A 'use_global' policy inherits the system-wided Global Default policy
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# from network/ipfilter. For {deny | allow} policies, the rules are
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# ordered as:
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# - make exceptions to policy for those in "exceptions" list
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# - apply policy to those specified in "apply_to" list
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# - policy rule
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyengenerate_rules()
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen{
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen service=$1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen mypolicy=$2
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen proto=$3
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld port=$4
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld out=$5
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld _6=$6
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen # Default mode is to inherit from global's policy
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen [ "$mypolicy" = "use_global" ] && return 0
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen tcp_opts=""
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen [ "$proto" = "tcp" ] && tcp_opts="flags S keep state keep frags"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld block_policy=`get_block_policy $1`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld if [ "$block_policy" = "use_global" ]; then
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld block_policy=${GLOBAL_BLOCK_POLICY}
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld fi
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld if [ "$block_policy" = "return" ]; then
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld [ "$proto" = "tcp" ] && block_policy="return-rst"
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld [ "$proto" != "tcp" ] && block_policy="return-icmp-as-dest"
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld else
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld block_policy=""
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld fi
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld iplist=`get_target${_6}_list $service`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen # Allow all if policy is 'none'
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen if [ "$mypolicy" = "none" ]; then
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld for ip in $iplist; do
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld daddr=`get_IP ${ip}`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld [ -z "$daddr" -o "$daddr" = '""' ] && continue
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld echo "pass in log quick proto ${proto} from any to ${daddr}" \
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld "port = ${port} ${tcp_opts}" >>${out}
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld done
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen return 0
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld # For now, let's concern ourselves only with incoming traffic.
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld [ "$mypolicy" = "deny" ] && { ecmd="pass"; acmd="block ${block_policy}"; }
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld [ "$mypolicy" = "allow" ] && { ecmd="block ${block_policy}"; acmd="pass"; }
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld for name in `get_exceptions${_6} $service`; do
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen [ -z "$name" -o "$name" = '""' ] && continue
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen ifc=`get_interface $name`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen if [ $? -eq 0 -a -n "$ifc" ]; then
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld for ip in $iplist; do
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld daddr=`get_IP ${ip}`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld [ -z "$daddr" -o "$daddr" = '""' ] && continue
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld echo "${ecmd} in log quick on ${ifc} from any to" \
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld "${daddr} port = ${port}" >>${out}
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld done
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen continue
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld saddr=`get_IP ${name}`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld if [ $? -eq 0 -a -n "$saddr" ]; then
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld for ip in $iplist; do
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld daddr=`get_IP ${ip}`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld [ -z "$daddr" -o "$daddr" = '""' ] && continue
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld echo "${ecmd} in log quick proto ${proto} from ${saddr}" \
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld "to ${daddr} port = ${port} ${tcp_opts}" >>${out}
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld done
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen done
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld for name in `get_apply2${_6}_list $service`; do
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen [ -z "$name" -o "$name" = '""' ] && continue
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen ifc=`get_interface $name`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen if [ $? -eq 0 -a -n "$ifc" ]; then
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld for ip in $iplist; do
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld daddr=`get_IP ${ip}`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld [ -z "$daddr" -o "$daddr" = '""' ] && continue
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld echo "${acmd} in log quick on ${ifc} from any to" \
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld "${daddr} port = ${port}" >>${out}
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld done
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen continue
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld saddr=`get_IP ${name}`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld if [ $? -eq 0 -a -n "$saddr" ]; then
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld for ip in $iplist; do
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld daddr=`get_IP ${ip}`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld [ -z "$daddr" -o "$daddr" = '""' ] && continue
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld echo "${acmd} in log quick proto ${proto} from ${saddr}" \
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld "to ${daddr} port = ${port} ${tcp_opts}" >>${out}
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld done
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen done
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld for ip in $iplist; do
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld daddr=`get_IP ${ip}`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld [ -z "$daddr" -o "$daddr" = '""' ] && continue
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld echo "${ecmd} in log quick proto ${proto} from any to ${daddr}" \
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld "port = ${port} ${tcp_opts}" >>${out}
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld done
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen return 0
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# Service has either IANA ports and proto or its own firewall method to
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# generate the rules.
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# - if service has a custom method, use it to populate its rules
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# - if service has a firewall_config pg, use process_server_svc
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# Argument - fmri
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyenprocess_service()
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen{
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen # Don't process network/ipfilter
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen [ "$1" = "$IPF_FMRI" ] && return 0
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen service_check_state $1 $SMF_MAINT && return 1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen method=`svcprop -p $FW_CONTEXT_PG/$METHOD_PROP $1 2>/dev/null | \
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen sed 's/\\\//g'`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen if [ -n "$method" -a "$method" != '""' ]; then
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen ( exec $method $1 >/dev/null )
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen else
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen svcprop -p $FW_CONFIG_PG $1 >/dev/null 2>&1 || return 1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen process_server_svc $1 || return 1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen return 0
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# Generate rules for protocol/port defined in firewall_config_default/open_ports
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# property. These are non-service programs whose network resource info are
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# defined as "{tcp | upd}:{PORT | PORT-PORT}". Essentially, these programs need
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# some specific local ports to be opened. For example, BitTorrent clients need to
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# have 6881-6889 opened.
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyenprocess_nonsvc_progs()
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen{
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen out=$1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen echo "# Non-service programs rules" >>${out}
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen progs=`global_get_prop_value $FW_CONFIG_DEF_PG $OPEN_PORTS_PROP`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen for prog in $progs; do
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen [ -z "$prog" -o "$prog" = '""' ] && continue
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen port=`tuple_get_port $prog`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen [ $? -eq 1 -o -z "$port" ] && continue
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen proto=`tuple_get_proto $prog`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen [ $? -eq 1 ] && continue
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen set -- $port
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen if [ $# -gt 1 ]; then
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen if [ -z "$proto" ]; then
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen echo "pass in log quick from any to any" \
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen "port ${1} >< ${2}" >>${out}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen else
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen echo "pass in log quick proto ${proto} from any" \
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen "to any port ${1} >< ${2}" >>${out}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen else
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen if [ -z "$proto" ]; then
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen echo "pass in log quick from any to any" \
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen "port = ${1}" >>${out}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen else
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen echo "pass in log quick proto ${proto} from any" \
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen "to any port = ${1}" >>${out}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen done
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen return 0
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# Generate a new /etc/ipf/ipf.conf. If firewall policy is 'none',
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# ipf.conf is empty .
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyencreate_global_rules()
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen{
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen if [ "$GLOBAL_POLICY" = "custom" ]; then
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen file=`global_get_prop_value $FW_CONFIG_DEF_PG $CUSTOM_FILE_PROP`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld file6=`global_get_prop_value $FW_CONFIG_DEF_PG $CUSTOM_FILE_6_PROP`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen [ -n "$file" ] && custom_set_symlink $file
2bd8b3545dceb97f56401b7ad2a327e08d520574Hans Rosenfeld [ -n "$file6" ] && custom_set_symlink_6 $file6
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen return 0
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen TEMP=`mktemp /var/run/ipf.conf.pid$$.XXXXXX`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld TEMP6=`mktemp /var/run/ipf6.conf.pid$$.XXXXXX`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen process_nonsvc_progs $TEMP
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld process_nonsvc_progs $TEMP6
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen echo "# Global Default rules" >>${TEMP}
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld echo "# Global Default rules" >>${TEMP6}
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen if [ "$GLOBAL_POLICY" != "none" ]; then
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen echo "pass out log quick all keep state" >>${TEMP}
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld echo "pass out log quick all keep state" >>${TEMP6}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen case "$GLOBAL_POLICY" in
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen 'none')
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen # No rules
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen replace_file ${IPFILCONF} ${TEMP}
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld replace_file ${IP6FILCONF} ${TEMP6}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen return $?
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen ;;
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen 'deny')
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen ecmd="pass"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen acmd="block"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen ;;
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen 'allow')
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen ecmd="block"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen acmd="pass"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen ;;
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen *)
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen return 1;
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen ;;
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen esac
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen for name in `global_get_prop_value $FW_CONFIG_DEF_PG $EXCEPTIONS_PROP`; do
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen [ -z "$name" -o "$name" = '""' ] && continue
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen ifc=`get_interface $name`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen if [ $? -eq 0 -a -n "$ifc" ]; then
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen echo "${ecmd} in log quick on ${ifc} all" >>${TEMP}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen continue
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen addr=`get_IP ${name}`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen if [ $? -eq 0 -a -n "$addr" ]; then
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen echo "${ecmd} in log quick from ${addr} to any" >>${TEMP}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen done
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld for name in `global_get_prop_value $FW_CONFIG_DEF_PG $EXCEPTIONS_6_PROP`; do
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld [ -z "$name" -o "$name" = '""' ] && continue
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld ifc=`get_interface $name`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld if [ $? -eq 0 -a -n "$ifc" ]; then
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld echo "${ecmd} in log quick on ${ifc} all" >>${TEMP6}
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld continue
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld fi
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld addr=`get_IP ${name}`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld if [ $? -eq 0 -a -n "$addr" ]; then
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld echo "${ecmd} in log quick from ${addr} to any" >>${TEMP6}
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld fi
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld done
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen for name in `global_get_prop_value $FW_CONFIG_DEF_PG $APPLY2_PROP`; do
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen [ -z "$name" -o "$name" = '""' ] && continue
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen ifc=`get_interface $name`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen if [ $? -eq 0 -a -n "$ifc" ]; then
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen echo "${acmd} in log quick on ${ifc} all" >>${TEMP}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen continue
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen addr=`get_IP ${name}`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen if [ $? -eq 0 -a -n "$addr" ]; then
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen echo "${acmd} in log quick from ${addr} to any" >>${TEMP}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen done
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld for name in `global_get_prop_value $FW_CONFIG_DEF_PG $APPLY2_6_PROP`; do
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld [ -z "$name" -o "$name" = '""' ] && continue
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld ifc=`get_interface $name`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld if [ $? -eq 0 -a -n "$ifc" ]; then
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld echo "${acmd} in log quick on ${ifc} all" >>${TEMP6}
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld continue
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld fi
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld addr=`get_IP ${name}`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld if [ $? -eq 0 -a -n "$addr" ]; then
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld echo "${acmd} in log quick from ${addr} to any" >>${TEMP6}
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld fi
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld done
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen if [ "$GLOBAL_POLICY" = "allow" ]; then
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld # Allow DHCP(v6) traffic if running as a DHCP client
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen /sbin/netstrategy | grep dhcp >/dev/null 2>&1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen if [ $? -eq 0 ]; then
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen echo "pass out log quick from any port = 68" \
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen "keep state" >>${TEMP}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen echo "pass in log quick from any to any port = 68" >>${TEMP}
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld echo "pass out log quick from any port = 546" \
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld "keep state" >>${TEMP6}
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld echo "pass in log quick from any to any port = 546" >>${TEMP6}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen echo "block in log all" >>${TEMP}
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld echo "block in log all" >>${TEMP6}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen replace_file ${IPFILCONF} ${TEMP}
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld replace_file ${IP6FILCONF} ${TEMP6}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen return $?
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# Generate a new /etc/ipf/ipf_ovr.conf, the override system-wide policy. It's
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# a simplified policy that doesn't support 'exceptions' entities.
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# If firewall policy is "none", no rules are generated.
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# Note that "pass" rules don't have "quick" as we don't want
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# them to override services' block rules.
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyencreate_global_ovr_rules()
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen{
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen # Simply empty override file if global policy is 'custom'
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen if [ "$GLOBAL_POLICY" = "custom" ]; then
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen echo "# 'custom' global policy" >$IPFILOVRCONF
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld echo "# 'custom' global policy" >$IP6FILOVRCONF
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen return 0
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen # Get and process override policy
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen ovr_policy=`global_get_prop_value $FW_CONFIG_OVR_PG $POLICY_PROP`
0a5f928c505bb3f860fa2383364d7b1dff588d59Truong Nguyen if [ "$ovr_policy" = "none" ]; then
0a5f928c505bb3f860fa2383364d7b1dff588d59Truong Nguyen echo "# global override policy is 'none'" >$IPFILOVRCONF
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld echo "# global override policy is 'none'" >$IP6FILOVRCONF
0a5f928c505bb3f860fa2383364d7b1dff588d59Truong Nguyen return 0
0a5f928c505bb3f860fa2383364d7b1dff588d59Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
0a5f928c505bb3f860fa2383364d7b1dff588d59Truong Nguyen TEMP=`mktemp /var/run/ipf_ovr.conf.pid$$.XXXXXX`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen [ "$ovr_policy" = "deny" ] && acmd="block in log quick"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen [ "$ovr_policy" = "allow" ] && acmd="pass in log"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen apply2_list=`global_get_prop_value $FW_CONFIG_OVR_PG $APPLY2_PROP`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen for name in $apply2_list; do
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen [ -z "$name" -o "$name" = '""' ] && continue
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen ifc=`get_interface $name`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen if [ $? -eq 0 -a -n "$ifc" ]; then
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen echo "${acmd} on ${ifc} all" >>${TEMP}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen continue
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen addr=`get_IP ${name}`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen if [ $? -eq 0 -a -n "$addr" ]; then
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen echo "${acmd} from ${addr} to any" >>${TEMP}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen done
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld apply2_6_list=`global_get_prop_value $FW_CONFIG_OVR_PG $APPLY2_6_PROP`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld for name in $apply2_6_list; do
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld [ -z "$name" -o "$name" = '""' ] && continue
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld ifc=`get_interface $name`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld if [ $? -eq 0 -a -n "$ifc" ]; then
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld echo "${acmd} on ${ifc} all" >>${TEMP6}
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld continue
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld fi
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld addr=`get_IP ${name}`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld if [ $? -eq 0 -a -n "$addr" ]; then
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld echo "${acmd} from ${addr} to any" >>${TEMP6}
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld fi
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld done
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen replace_file ${IPFILOVRCONF} ${TEMP}
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld replace_file ${IP6FILOVRCONF} ${TEMP6}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen return $?
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# Service is put into maintenance state due to its invalid firewall
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# definition and/or policy.
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyensvc_mark_maintenance()
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen{
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen svcadm mark maintenance $1 >/dev/null 2>&1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen date=`date`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen echo "[ $date ${0}: $1 has invalid ipf configuration. ]"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen echo "[ $date ${0}: placing $1 in maintenance. ]"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen # Move service's rule files to another location since
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen # they're most likely invalid.
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen ipfile=`fmri_to_file $1 $IPF_SUFFIX`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen [ -f "$ipfile" ] && mv $ipfile "$ipfile.bak"
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld ip6file=`fmri_to_file $1 $IPF6_SUFFIX`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld [ -f "$ip6file" ] && mv $ip6file "$ip6file.bak"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen natfile=`fmri_to_file $1 $NAT_SUFFIX`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen [ -f "$natfile" ] && mv $natfile "$natfile.bak"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen return 0
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyensvc_is_server()
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen{
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen svcprop -p $FW_CONFIG_PG $1 >/dev/null 2>&1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# Create rules for enabled firewalling and client services.
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# - obtain the list of enabled services and process them
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# - save the list of rules file for later use
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyencreate_services_rules()
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen{
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen # Do nothing if global policy is 'custom'
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen [ "$GLOBAL_POLICY" = "custom" ] && return 0
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen ipf_get_lock
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen # Get all enabled services
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen allsvcs=`svcprop -cf -p general/enabled -p general_ovr/enabled '*' \
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen 2>/dev/null | sed -n 's,^\(svc:.*\)/:properties/.* true$,\1,p' | sort -u`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen # Process enabled services
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen for s in $allsvcs; do
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen service_is_enabled $s || continue
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen process_service $s || continue
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen ipfile=`fmri_to_file $s $IPF_SUFFIX`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen if [ -n "$ipfile" -a -r "$ipfile" ]; then
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen check_ipf_syntax $ipfile
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen if [ $? -ne 0 ]; then
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen svc_mark_maintenance $s
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen continue
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen svc_is_server $s
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen if [ $? -eq 0 ]; then
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen check_ipf_rules $ipfile
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen if [ $? -ne 0 ]; then
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen svc_mark_maintenance $s
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen continue
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen CONF_FILES="$CONF_FILES $ipfile"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld ip6file=`fmri_to_file $s $IPF6_SUFFIX`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld if [ -n "$ip6file" -a -r "$ip6file" ]; then
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld check_ipf_syntax $ip6file -6
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld if [ $? -ne 0 ]; then
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld svc_mark_maintenance $s
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld continue
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld fi
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld svc_is_server $s
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld if [ $? -eq 0 ]; then
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld check_ipf_rules $ip6file -6
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld if [ $? -ne 0 ]; then
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld svc_mark_maintenance $s
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld continue
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld fi
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld fi
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld CONF6_FILES="$CONF6_FILES $ip6file"
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld fi
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen natfile=`fmri_to_file $s $NAT_SUFFIX`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen if [ -n "$natfile" -a -r "$natfile" ]; then
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen check_nat_syntax $natfile
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen if [ $? -ne 0 ]; then
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen svc_mark_maintenance $s
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen continue
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen NAT_FILES="$NAT_FILES $natfile"
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen done
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen ipf_remove_lock
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen return 0
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# We update a services ipf ruleset in the following manners:
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# - service is disabled, tear down its rules.
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# - service is disable or refreshed(online), setup or update its rules.
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyenservice_update_rules()
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen{
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen svc=$1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen ipfile=`fmri_to_file $svc $IPF_SUFFIX`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld ip6file=`fmri_to_file $svc $IPF6_SUFFIX`
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld [ -n "$ipfile" ] && remove_rules $ipfile
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld [ -n "$ip6file" ] && remove_rules $ip6file -6
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld [ -z "$ipfile" -a -z "$ip6file" ] && return 0
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen natfile=`fmri_to_file $svc $NAT_SUFFIX`
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen [ -n "$natfile" ] && remove_nat_rules $natfile
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen # Don't go further if service is disabled or in maintenance.
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen service_is_enabled $svc || return 0
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen service_check_state $1 $SMF_MAINT && return 0
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen process_service $svc || return 1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen if [ -f "$ipfile" ]; then
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen check_ipf_syntax $ipfile
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen if [ $? -ne 0 ]; then
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen svc_mark_maintenance $svc
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen return 1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld if [ -f "$ip6file" ]; then
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld check_ipf_syntax $ip6file -6
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld if [ $? -ne 0 ]; then
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld svc_mark_maintenance $svc
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld return 1
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld fi
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld fi
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen if [ -f "$natfile" ]; then
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen check_nat_syntax $natfile
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen if [ $? -ne 0 ]; then
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen svc_mark_maintenance $svc
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen return 1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen if [ -f "$ipfile" ]; then
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen svc_is_server $svc
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen if [ $? -eq 0 ]; then
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen update_check_ipf_rules $ipfile
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen if [ $? -ne 0 ]; then
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen svc_mark_maintenance $svc
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen return 1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen prepend_new_rules $ipfile
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen # reload Global Override rules to
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen # maintain correct ordering.
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen #
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen remove_rules $IPFILOVRCONF
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen prepend_new_rules $IPFILOVRCONF
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen fi
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld if [ -f "$ip6file" ]; then
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld svc_is_server $svc
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld if [ $? -eq 0 ]; then
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld update_check_ipf_rules $ip6file -6
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld if [ $? -ne 0 ]; then
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld svc_mark_maintenance $svc
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld return 1
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld fi
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld fi
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld prepend_new_rules $ip6file -6
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld #
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld # reload Global Override rules to
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld # maintain correct ordering.
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld #
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld remove_rules $IP6FILOVRCONF -6
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld prepend_new_rules $IP6FILOVRCONF -6
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld fi
7ddce99911fbb5e44b38ac65e991a22e42267ee9Hans Rosenfeld
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen [ -f "$natfile" ] && append_new_nat_rules $natfile
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen return 0
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen}
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# Call the service_update_rules with appropriate svc fmri.
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# This is called from '/lib/svc/method/ipfilter fw_update' whenever
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen# a service is disabled/enabled/refreshed.
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen#
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyenservice_update()
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen{
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen svc=$1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen ret=0
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
ea7d3b1a278e2af7b09658d7a51d5b61d6ee490fTruong Nguyen #
ea7d3b1a278e2af7b09658d7a51d5b61d6ee490fTruong Nguyen # If ipfilter isn't online or global policy is 'custom',
ea7d3b1a278e2af7b09658d7a51d5b61d6ee490fTruong Nguyen # nothing should be done.
ea7d3b1a278e2af7b09658d7a51d5b61d6ee490fTruong Nguyen #
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen [ "$GLOBAL_POLICY" = "custom" ] && return 0
ea7d3b1a278e2af7b09658d7a51d5b61d6ee490fTruong Nguyen service_check_state $SMF_FMRI $SMF_ONLINE || return 0
ea7d3b1a278e2af7b09658d7a51d5b61d6ee490fTruong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen ipf_get_lock
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen service_update_rules $svc || ret=1
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen ipf_remove_lock
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen return $ret
eb1a34638eba7c5add1421327f3eb225a8ea7518Truong Nguyen}
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen#
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen# Initialize global configuration
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen#
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyenglobal_init
6f7d61cdf37e55c737a1ecb01bf5b8453f55c7d1Truong Q. Nguyen