<% require 'ipaddr' -%>
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -i lo -j ACCEPT
-A INPUT -m ipv6header --header ah -j ACCEPT
-A INPUT -m ipv6header --header esp -j ACCEPT
<% if ip6states >= 0 -%>
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
<% else -%>
-A INPUT -m tcp -p tcp ! --syn -j ACCEPT
-A INPUT -m udp -p udp --dport 32768:61000 -j ACCEPT
<% end -%>
-A INPUT -p ipv6-icmp -j ACCEPT
<%
  @firewall_rules.each do |rule|
    rule = /(tcp|udp)\/([\d:]+)( .+)?/.match(rule)
    if not rule[3] or IPAddr.new(rule[3].strip()).ipv6?
-%>
-A INPUT -m <%= rule[1] %> -p <%= rule[1] %><% if rule[3] %> -s<%= rule[3] %><% end %> --dport <%= rule[2] %> -j ACCEPT
<%
    end
  end
  @firewall_custom.each do |rule|
-%>
<%= rule %>
<% end -%>
-A INPUT -j REJECT --reject-with icmp6-adm-prohibited
-A FORWARD -j REJECT --reject-with icmp6-adm-prohibited
COMMIT
