Skip to content

Commit

Permalink
Merge pull request #872 from haught/conntrack_module
Browse files Browse the repository at this point in the history
Support conntrack module
  • Loading branch information
DavidS authored Dec 19, 2019
2 parents acd34d0 + e755bd5 commit 5aaedbf
Show file tree
Hide file tree
Showing 4 changed files with 443 additions and 10 deletions.
21 changes: 19 additions & 2 deletions lib/puppet/provider/firewall/ip6tables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

has_feature :iptables
has_feature :connection_limiting
has_feature :conntrack
has_feature :hop_limiting
has_feature :rate_limiting
has_feature :recent_limiting
Expand Down Expand Up @@ -71,7 +72,19 @@ def self.iptables_save(*args)
connlimit_above: '-m connlimit --connlimit-above',
connlimit_mask: '--connlimit-mask',
connmark: '-m connmark --mark',
ctstate: '-m conntrack --ctstate',
ctstate: '--ctstate',
ctproto: '--ctproto',
ctorigsrc: '--ctorigsrc',
ctorigdst: '--ctorigdst',
ctreplsrc: '--ctreplsrc',
ctrepldst: '--ctrepldst',
ctorigsrcport: '--ctorigsrcport',
ctorigdstport: '--ctorigdstport',
ctreplsrcport: '--ctreplsrcport',
ctrepldstport: '--ctrepldstport',
ctstatus: '--ctstatus',
ctexpire: '--ctexpire',
ctdir: '--ctdir',
destination: '-d',
dport: ['-m multiport --dports', '--dport'],
dst_range: '--dst-range',
Expand Down Expand Up @@ -207,6 +220,8 @@ def self.iptables_save(*args)
addrtype: [:src_type, :dst_type],
iprange: [:src_range, :dst_range],
owner: [:uid, :gid],
conntrack: [:ctstate, :ctproto, :ctorigsrc, :ctorigdst, :ctreplsrc, :ctrepldst,
:ctorigsrcport, :ctorigdstport, :ctreplsrcport, :ctrepldstport, :ctstatus, :ctexpire, :ctdir],
time: [:time_start, :time_stop, :month_days, :week_days, :date_start, :date_stop, :time_contiguous, :kernel_timezone],
geoip: [:src_cc, :dst_cc],
hashlimit: [:hashlimit_upto, :hashlimit_above, :hashlimit_name, :hashlimit_burst, :hashlimit_mode, :hashlimit_srcmask, :hashlimit_dstmask,
Expand Down Expand Up @@ -253,7 +268,9 @@ def self.iptables_save(*args)
:proto, :ishasmorefrags, :islastfrag, :isfirstfrag, :src_range, :dst_range,
:tcp_flags, :uid, :gid, :mac_source, :sport, :dport, :port, :src_type,
:dst_type, :socket, :pkttype, :ipsec_dir, :ipsec_policy, :state,
:ctstate, :icmp, :hop_limit, :limit, :burst, :length, :recent, :rseconds, :reap,
:ctstate, :ctproto, :ctorigsrc, :ctorigdst, :ctreplsrc, :ctrepldst,
:ctorigsrcport, :ctorigdstport, :ctreplsrcport, :ctrepldstport, :ctstatus, :ctexpire, :ctdir,
:icmp, :hop_limit, :limit, :burst, :length, :recent, :rseconds, :reap,
:rhitcount, :rttl, :rname, :mask, :rsource, :rdest, :ipset, :string, :string_algo,
:string_from, :string_to, :jump, :clamp_mss_to_pmtu, :gateway, :todest,
:tosource, :toports, :checksum_fill, :log_level, :log_prefix, :log_uid, :reject, :set_mss, :set_dscp, :set_dscp_class, :mss, :queue_num, :queue_bypass,
Expand Down
37 changes: 33 additions & 4 deletions lib/puppet/provider/firewall/iptables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

has_feature :iptables
has_feature :connection_limiting
has_feature :conntrack
has_feature :rate_limiting
has_feature :recent_limiting
has_feature :snat
Expand Down Expand Up @@ -67,7 +68,19 @@
connlimit_above: '-m connlimit --connlimit-above',
connlimit_mask: '--connlimit-mask',
connmark: '-m connmark --mark',
ctstate: '-m conntrack --ctstate',
ctstate: '--ctstate',
ctproto: '--ctproto',
ctorigsrc: '--ctorigsrc',
ctorigdst: '--ctorigdst',
ctreplsrc: '--ctreplsrc',
ctrepldst: '--ctrepldst',
ctorigsrcport: '--ctorigsrcport',
ctorigdstport: '--ctorigdstport',
ctreplsrcport: '--ctreplsrcport',
ctrepldstport: '--ctrepldstport',
ctstatus: '--ctstatus',
ctexpire: '--ctexpire',
ctdir: '--ctdir',
destination: '-d',
dport: ['-m multiport --dports', '--dport'],
dst_range: '--dst-range',
Expand Down Expand Up @@ -214,6 +227,8 @@
addrtype: [:src_type, :dst_type],
iprange: [:src_range, :dst_range],
owner: [:uid, :gid],
conntrack: [:ctstate, :ctproto, :ctorigsrc, :ctorigdst, :ctreplsrc, :ctrepldst,
:ctorigsrcport, :ctorigdstport, :ctreplsrcport, :ctrepldstport, :ctstatus, :ctexpire, :ctdir],
time: [:time_start, :time_stop, :month_days, :week_days, :date_start, :date_stop, :time_contiguous, :kernel_timezone],
geoip: [:src_cc, :dst_cc],
hashlimit: [:hashlimit_upto, :hashlimit_above, :hashlimit_name, :hashlimit_burst, :hashlimit_mode, :hashlimit_srcmask, :hashlimit_dstmask,
Expand All @@ -231,7 +246,7 @@ def self.munge_resource_map_from_existing_values(resource_map_original, compare)
resource_map_new[argument][0] = "-m #{ipt_module} #{resource_map_original[argument].first}"
break
end
elsif compare.include?(resource_map_original[argument])
elsif compare.include?(resource_map_original[argument] + ' ')
resource_map_new[argument] = "-m #{ipt_module} #{resource_map_original[argument]}"
break
end
Expand Down Expand Up @@ -296,7 +311,9 @@ def munge_resource_map_from_resource(resource_map_original, compare)
:proto, :isfragment, :stat_mode, :stat_every, :stat_packet, :stat_probability,
:src_range, :dst_range, :tcp_flags, :uid, :gid, :mac_source, :sport, :dport, :port,
:src_type, :dst_type, :socket, :pkttype, :ipsec_dir, :ipsec_policy,
:state, :ctstate, :icmp, :limit, :burst, :length, :recent, :rseconds, :reap,
:state, :ctstate, :ctproto, :ctorigsrc, :ctorigdst, :ctreplsrc, :ctrepldst,
:ctorigsrcport, :ctorigdstport, :ctreplsrcport, :ctrepldstport, :ctstatus, :ctexpire, :ctdir,
:icmp, :limit, :burst, :length, :recent, :rseconds, :reap,
:rhitcount, :rttl, :rname, :mask, :rsource, :rdest, :ipset, :string, :string_algo,
:string_from, :string_to, :jump, :goto, :clusterip_new, :clusterip_hashmode,
:clusterip_clustermac, :clusterip_total_nodes, :clusterip_local_node, :clusterip_hash_init, :queue_num, :queue_bypass,
Expand Down Expand Up @@ -545,7 +562,7 @@ def self.rule_to_hash(line, table, counter)
# POST PARSE CLUDGING
#####################

[:dport, :sport, :port, :state, :ctstate].each do |prop|
[:dport, :sport, :port, :state, :ctstate, :ctstatus].each do |prop|
hash[prop] = hash[prop].split(',') unless hash[prop].nil?
end

Expand Down Expand Up @@ -607,6 +624,17 @@ def self.rule_to_hash(line, table, counter)
[
:connmark,
:ctstate,
:ctproto,
:ctorigsrc,
:ctorigdst,
:ctreplsrc,
:ctrepldst,
:ctorigsrcport,
:ctorigdstport,
:ctreplsrcport,
:ctrepldstport,
:ctstatus,
:ctexpire,
:destination,
:dport,
:dst_range,
Expand Down Expand Up @@ -646,6 +674,7 @@ def self.rule_to_hash(line, table, counter)
# iptables-save and user supplied resources is consistent.
hash[:state] = hash[:state].sort unless hash[:state].nil?
hash[:ctstate] = hash[:ctstate].sort unless hash[:ctstate].nil?
hash[:ctstatus] = hash[:ctstatus].sort unless hash[:ctstatus].nil?

# This forces all existing, commentless rules or rules with invalid comments to be moved
# to the bottom of the stack.
Expand Down
Loading

0 comments on commit 5aaedbf

Please sign in to comment.