ipfw.conf 9.54 KB
Newer Older
1 2 3 4 5 6 7 8
{# collect interfaces list (with / without captive portal enabled) #}
{% set cp_interface_list = [] %}
{% set no_cp_interface_list = [] %}
{% if helpers.exists('captiveportal') %}
{% for intf_key,interface in interfaces.iteritems()%}
{%      set is_cp=[] %}
{%      for cp_key,cp_item in captiveportal.iteritems()  %}
{%          if intf_key == cp_item.interface and interface.ipaddr != 'dhcp' %}
9 10 11 12
{%              if cp_item.enable|default('0') == '1' %}
{%                  do cp_interface_list.append({'zone':cp_key,'zoneid':cp_item.zoneid,'if':interface.if}) %}
{%                  do is_cp.append(1) %}
{%              endif %}
13 14 15 16 17 18 19 20 21 22 23
{%          endif %}
{%      endfor %}
{%      if not is_cp%}
{%              do no_cp_interface_list.append(interface) %}
{%      endif %}
{% endfor %}
{% else %}
{%      for intf_key,interface in interfaces.iteritems() %}
{%              do no_cp_interface_list.append(interface) %}
{%      endfor %}
{% endif %}
24 25 26 27 28
#======================================================================================
# flush ruleset
#======================================================================================
flush

29 30 31
#======================================================================================
# define dummynet pipes
#======================================================================================
32
{% if helpers.exists('OPNsense.TrafficShaper.pipes.pipe') %}
33
{% for pipe in helpers.toList('OPNsense.TrafficShaper.pipes.pipe') %}
34 35 36 37
pipe {{ pipe.number }} config bw {{ pipe.bandwidth }}{{ pipe.bandwidthMetric }}/s{% if pipe.burst %} burst {{ pipe.burst }}{% endif %}{%
 if pipe.queue %} queue {{ pipe.queue }}{%
 if pipe.queueMetric != 'slots' %}{{pipe.queueMetric}}{% endif %}{% endif
 %}{% if pipe.mask != 'none' %} mask {{ pipe.mask }} 0xffffffff {% endif %}
38

39
{% endfor %}
40 41
{% endif %}

42 43 44 45 46
#======================================================================================
# define dummynet queues
#======================================================================================
{% if helpers.exists('OPNsense.TrafficShaper.queues.queue') %}
{% for queue in helpers.toList('OPNsense.TrafficShaper.queues.queue') %}
47 48 49
{%    if helpers.getUUIDtag(queue.pipe) in ['pipe'] %}
queue {{ queue.number }} config pipe {{ helpers.getUUID(queue.pipe).number }} weight {{ queue.weight }}
{%    endif %}
50 51 52 53
{% endfor %}
{% endif %}


54 55 56 57 58 59 60 61 62 63 64 65 66 67
#======================================================================================
# general purpose rules 1...1000
#======================================================================================
add 100 allow pfsync from any to any
add 110 allow carp from any to any
# layer 2: pass ARP
add 120 pass layer2 mac-type arp,rarp
# OPNsense requires for WPA
add 130 pass layer2 mac-type 0x888e,0x88c7
# PPP Over Ethernet Session Stage/Discovery Stage
add 140 pass layer2 mac-type 0x8863,0x8864
# layer 2: block anything else non-IP(v4/v6)
add 150 deny layer2 not mac-type ip,ipv6

68
# allow traffic send from localhost
69
add 200 skipto 60000 ipv6 from ::1 to any
70
add 201 skipto 60000 ipv4 from 127.0.0.0/8 to any
71 72
add 202 skipto 60000 ipv6 from any to ::1
add 203 skipto 60000 ipv4 from any to 127.0.0.0/8
73

74 75 76 77 78
#======================================================================================
# Allow traffic to this hosts static ip's
#======================================================================================
{% for intf_key,interface in interfaces.iteritems() %}
{% if intf_key != "wan" and interface.ipaddr != "dhcp" and interface.ipaddr != "" %}
79 80 81 82 83
add {{loop.index  + 1000}} skipto 60000 udp from any to {{ interface.ipaddr }} dst-port 53 keep-state
add {{loop.index  + 1000}} skipto 60000 ip from any to { 255.255.255.255 or {{interface.ipaddr}} } in
add {{loop.index  + 1000}} skipto 60000 ip from { 255.255.255.255 or {{interface.ipaddr}} } to any out
add {{loop.index  + 1000}} skipto 60000 icmp from { 255.255.255.255 or {{interface.ipaddr}} } to any out icmptypes 0
add {{loop.index  + 1000}} skipto 60000 icmp from any to { 255.255.255.255 or {{interface.ipaddr}} } in icmptypes 8
84 85 86
{% endif %}
{% endfor %}

87
{% for item in cp_interface_list %}
88
#===================================================================================
89
# zone {{item.zone}} ({{item.zoneid}}) configuration
90 91
#===================================================================================
{# authenticated users ( table 1 + 2 ) #}
92 93
add {{3000 + item.zoneid|int * 10 + 1 }}  skipto {{10001 + item.zoneid|int * 1000  }} ip from table({{6*(item.zoneid|int-1) + 1 }}) to any via {{item.if}}
add {{3000 + item.zoneid|int * 10 + 2 }}  skipto {{10001 + item.zoneid|int * 1000  }} ip from table({{6*(item.zoneid|int-1) + 1 }}) to any via {{item.if}}
94
{# authenticated hosts ( table 3 + 4 ) #}
95 96
add {{3000 + item.zoneid|int * 10 + 3 }}  skipto {{10001 + item.zoneid|int * 1000  }} ip from table({{6*(item.zoneid|int-1) + 3 }}) to any via {{item.if}}
add {{3000 + item.zoneid|int * 10 + 4 }}  skipto {{10001 + item.zoneid|int * 1000  }} ip from table({{6*(item.zoneid|int-1) + 3 }}) to any via {{item.if}}
97
{# authenticated mac addresses ( table 5 + 6 ) #}
98 99
add {{3000 + item.zoneid|int * 10 + 5 }}  skipto {{10001 + item.zoneid|int * 1000  }} ip from table({{6*(item.zoneid|int-1) + 5 }}) to any via {{item.if}}
add {{3000 + item.zoneid|int * 10 + 6 }}  skipto {{10001 + item.zoneid|int * 1000  }} ip from table({{6*(item.zoneid|int-1) + 5 }}) to any via {{item.if}}
100 101 102
{% endfor %}


103 104 105 106 107 108 109 110 111 112 113 114 115
#======================================================================================
# redirect non-authenticated clients to captive portal @ local port 8000 + zoneid
#======================================================================================
{% for item in cp_interface_list %}
add {{5000 + item.zoneid|int }} fwd 127.0.0.1,{{  item.zoneid|int + 8000 }} tcp from any to any dst-port 80 in via {{item.if}}
add {{5000 + item.zoneid|int }} allow ip from any to any dst-port 80 via {{item.if}}
{% endfor %}


#======================================================================================
# accept traffic from all interfaces not used by captive portal
#======================================================================================
{% for item in no_cp_interface_list %}
116
add {{6001 + loop.index }} skipto 60000 all from any to any via {{item.if}}
117 118 119 120 121 122
{% endfor %}
# let the responses from the captive portal web server back out
add 6200 pass tcp from any to any out
# block everything else (not mentioned before)
add 6201 skipto 65534 all from any to any

123 124 125 126

#======================================================================================
# setup zone accounting section
#======================================================================================
127 128 129 130 131
{% for item in cp_interface_list %}
# zone {{item.zone}} ({{item.zoneid}})
add {{ (item.zoneid|int * 1000) + 10001 }} count ip from any to any via {{item.if}}
add {{ (item.zoneid|int * 1000) + 10998 }} skipto 30000 all from any to any via {{item.if}}
add {{ (item.zoneid|int * 1000) + 10999 }} deny all from any to any not via {{item.if}}
132
{% endfor %}
133 134 135 136 137 138


#======================================================================================
# setup accounting section, first rule is counting all CP traffic
#======================================================================================
add 30000 set 0 count ip from any to any
139 140 141


#======================================================================================
142
# traffic shaping section, authorized traffic
143 144
#======================================================================================
add 60000 return via any
145 146

{% if helpers.exists('OPNsense.TrafficShaper.rules.rule') %}
147
{% for rule in helpers.toList('OPNsense.TrafficShaper.rules.rule', 'sequence') %}
148
{%    if helpers.getUUIDtag(rule.target) in ['pipe','queue'] %}
149
{%        if helpers.getNodeByTag('interfaces.'+rule.interface) %}
150 151 152 153
{%            if helpers.getUUID(rule.target).enabled|default('0') == '1' %}
{%                if helpers.getUUIDtag(rule.target) == 'pipe' or
                     helpers.getUUID(helpers.getUUID(rule.target).pipe).enabled|default('0') == '1'
%}
154 155
{%                       if rule.interface2 and helpers.getNodeByTag('interfaces.'+rule.interface2) %}
{#  2 interface defined, use both to match packets (2 rules)  #}
156
add {{loop.index  + 60000}} {{ helpers.getUUIDtag(rule.target) }} {{
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
    helpers.getUUID(rule.target).number }} {{ rule.proto }} from {{ rule.source }} to {{rule.destination
    }} src-port  {{ rule.src_port }} dst-port {{ rule.dst_port }} {{rule.direction}} recv {{
    helpers.getNodeByTag('interfaces.'+rule.interface).if }} xmit {{helpers.getNodeByTag('interfaces.'+rule.interface2).if
    }}
add {{loop.index  + 60000}} {{ helpers.getUUIDtag(rule.target) }} {{
    helpers.getUUID(rule.target).number }} {{ rule.proto }} from {{ rule.source }} to {{rule.destination
    }} src-port  {{ rule.src_port }} dst-port {{ rule.dst_port }} {{rule.direction}} xmit {{
    helpers.getNodeByTag('interfaces.'+rule.interface).if }} recv {{helpers.getNodeByTag('interfaces.'+rule.interface2).if
    }}
{%                       else %}
{#  normal, single interface situation  #}
add {{loop.index  + 60000}} {{ helpers.getUUIDtag(rule.target) }} {{
    helpers.getUUID(rule.target).number }} {{ rule.proto }} from {{ rule.source }} to {{rule.destination
    }} src-port  {{ rule.src_port }} dst-port {{ rule.dst_port }} {{rule.direction}} via {{
    helpers.getNodeByTag('interfaces.'+rule.interface).if
    }}
{%                       endif %}
174 175
{%                   endif %}
{%            endif %}
176
{%        endif %}
177
{%    endif %}
178 179 180 181
{% endfor %}
{% endif %}

# pass authorized
182
add 65533 pass ip from any to any
183 184 185

# block all unmatched
add 65534 deny all from any to any