#!/bin/sh
#
#  This is automatically generated file. DO NOT MODIFY !
#
#  Firewall Builder  fwb_ipfw v4.2.0.3499
#
#  Generated Sat Mar 12 19:44:44 2011 PST by vadim
#
# files: * firewall4.fw /etc/firewall4.fw
#
#
#
# Compiled for ipfw 
#
# this object is used to test a configuration where firewall has dynamic address

# firewall4::: error: Dynamic interface eth1 should not have an IP address object attached to it. This IP address object will be ignored.

# firewall4:Policy:6: warning: Changing rule direction due to self reference
# firewall4:Policy:6: warning: Changing rule direction due to self reference



cd /etc || exit 1

IFCONFIG="/sbin/ifconfig"
PFCTL="/sbin/pfctl"
IPFW="/sbin/ipfw"
IPF="/usr/sbin/ipf"
IPNAT="/usr/sbin/ipnat"
SYSCTL="/sbin/sysctl"
LOGGER="/usr/bin/logger"

log() {
    echo "$1"
    command -v "$LOGGER" >/dev/null 2>&1 && $LOGGER -p info "$1"
}

diff_intf() {
    func=$1
    list1=$2
    list2=$3
    cmd=$4
    for intf in $list1
    do
        echo $list2 | grep -q $intf || {
        # $vlan is absent in list 2
            $func $intf $cmd
        }
    done
}

verify_interfaces() {
    :
    
}

set_kernel_vars() {
    :
    
}

prolog_commands() {
    echo "Running prolog script"
    
}

epilog_commands() {
    echo "Running epilog script"
    
}

run_epilog_and_exit() {
    epilog_commands
    exit $1
}

configure_interfaces() {
    :
    
}

log "Activating firewall script generated Sat Mar 12 19:44:44 2011 by vadim"

set_kernel_vars
configure_interfaces
prolog_commands

"$IPFW" set disable 1
"$IPFW" add 1 set 1 check-state ip from any to any




# ================ IPv4


# ================ Rule set Policy
# 
# Rule  0 (eth1)
# Anti-spoofing rule
"$IPFW" add 10 set 1 drop    log all  from me  to any  in  recv eth1  || exit 1
"$IPFW" add 20 set 1 drop    log all  from 192.168.1.0/24  to any  in  recv eth1  || exit 1
# 
# Rule  1 (eth1)
# Anti-spoofing rule
"$IPFW" add 30 set 1 skipto 60 all  from me  to any  out xmit eth1  || exit 1
"$IPFW" add 40 set 1 skipto 60 all  from 192.168.1.0/24  to any  out xmit eth1  || exit 1
"$IPFW" add 50 set 1 drop    log all  from any  to any  out xmit eth1  || exit 1
# 
# Rule  2 (eth1)
"$IPFW" add 60 set 1 drop    log icmp  from any  to any icmptypes 8     via  eth1  || exit 1
# 
# Rule  3 (eth1)
"$IPFW" add 70 set 1 skipto 90 icmp  from 192.168.2.0/24  to any icmptypes 8     via  eth1  || exit 1
"$IPFW" add 80 set 1 drop    log icmp  from any  to any icmptypes 8     via  eth1  || exit 1
# 
# Rule  4 (global)
# hostF has the same IP address as firewal.
"$IPFW" add 90 set 1 permit  log icmp  from any  to 192.168.1.1 icmptypes 8     keep-state  || exit 1
# 
# Rule  5 (global)
# testing negation in the policy rule
"$IPFW" add 100 set 1 skipto 130 icmp  from 192.168.1.10  to any icmptypes 3      || exit 1
"$IPFW" add 110 set 1 skipto 130 icmp  from 192.168.1.20  to any icmptypes 3      || exit 1
"$IPFW" add 120 set 1 drop    log icmp  from any  to any icmptypes 3      || exit 1
# 
# Rule  6 (global)
# firewall4:Policy:6: warning: Changing rule direction due to self reference

"$IPFW" add 130 set 1 skipto 160 icmp  from 192.168.1.10  to me icmptypes 3 in   || exit 1
"$IPFW" add 140 set 1 skipto 160 icmp  from 192.168.1.20  to me icmptypes 3 in   || exit 1
"$IPFW" add 150 set 1 drop    log icmp  from any  to me icmptypes 3 in   || exit 1
# 
# Rule  8 (global)
# 'masquerading' rule
"$IPFW" add 160 set 1 permit all  from 192.168.1.0/24  to any      keep-state  || exit 1
# 
# Rule  10 (global)
# 'catch all' rule
"$IPFW" add 170 set 1 drop    log all  from any  to any       || exit 1
# 
# Rule  fallback rule
#    fallback rule 
"$IPFW" add 180 set 1 drop   all  from any  to any       || exit 1

epilog_commands

"$IPFW" set swap 0 1 || exit 1
"$IPFW" delete set 1