has_feature :ipsec_dir
has_feature :ipsec_policy
has_feature :mask
+ has_feature :stat_mode
+ has_feature :stat_every
+ has_feature :stat_packet
+ has_feature :stat_prob
optional_commands({
:iptables => 'iptables',
:ipsec_policy => "--pol",
:mask => '--mask',
:mac_source => ["-m mac --mac-source", "--mac-source"],
+ :stat_mode => "-m statistic --mode",
+ :stat_every => '--every',
+ :stat_packet => '--packet',
+ :stat_prob => '--probability',
}
# These are known booleans that do not take a value, but we want to munge
# This order can be determined by going through iptables source code or just tweaking and trying manually
@resource_list = [
:table, :source, :destination, :iniface, :outiface, :proto, :isfragment,
+ :stat_mode, :stat_every, :stat_packet, :stat_prob,
:src_range, :dst_range, :tcp_flags, :gid, :uid, :mac_source, :sport, :dport, :port,
:dst_type, :src_type, :socket, :pkttype, :name, :ipsec_dir, :ipsec_policy,
:state, :ctstate, :icmp, :limit, :burst, :recent, :rseconds, :reap,
feature :ipsec_policy, "Match IPsec policy"
feature :ipsec_dir, "Match IPsec policy direction"
feature :mask, "Ability to match recent rules based on the ipv4 mask"
+ feature :stat_mode, "Match packets based on staistic mode"
+ feature :stat_every, "Match one packet every nth time"
+ feature :stat_packet, "Set initial counter"
+ feature :stat_prob, "Match packets based on probability"
# provider specific features
feature :iptables, "The provider provides iptables features."
newvalues(:in, :out)
end
+ newproperty(:stat_mode, :required_features => :stat_mode) do
+ desc <<-EOS
+ Sets the statistic modoule mode
+ EOS
+
+ newvalues(:nth, :random)
+ end
+
+ newproperty(:stat_every, :required_features => :stat_mode) do
+ desc <<-EOS
+ Match every nth packet (used with 'nth' mode)
+ EOS
+
+ validate do |value|
+ unless value =~ /^\d+$/
+ raise ArgumentError, <<-EOS
+ stat_every value must be a digit
+ EOS
+ end
+
+ unless value.to_i > 0
+ raise ArgumentError, <<-EOS
+ stat_every value must be larger than 0
+ EOS
+ end
+ end
+ end
+
+ newproperty(:stat_packet, :required_features => :stat_mode) do
+ desc <<-EOS
+ Set initial counter (used with 'nth' mode)
+ EOS
+
+ newvalues(/^\d+$/)
+ end
+
+ newproperty(:stat_prob, :required_features => :stat_mode) do
+ desc <<-EOS
+ Set the probably for a packet to be matched (used with 'random' mode)
+ EOS
+
+ validate do |value|
+ unless value =~ /^([01])\.(\d+)$/
+ raise ArgumentError, <<-EOS
+ stat_prob must be between 0.0 and 1.0
+ EOS
+ end
+
+ if $1.to_i == 1 && $2.to_i != 0
+ raise ArgumentError, <<-EOS
+ start_prob must be between 0.0 and 1.0
+ EOS
+ end
+ end
+ end
+
newproperty(:mask, :required_features => :mask) do
desc <<-EOS
Sets the mask to use when `recent` is enabled.
self.fail "Mask can only be set if recent is enabled."
end
+ [:stat_packet, :stat_every, :stat_prob].each do |param|
+ if value(param) && ! value(:stat_mode)
+ self.fail "Parameter '#{param.to_s}' requires 'stat_mode' to be set"
+ end
+ end
+
+ if value(:stat_packet) && value(:stat_mode) != :nth
+ self.fail "Parameter 'stat_packet' requires 'stat_mode' to be set to 'nth'"
+ end
+
+ if value(:stat_every) && value(:stat_mode) != :nth
+ self.fail "Parameter 'stat_every' requires 'stat_mode' to be set to 'nth'"
+ end
+
+ if value(:stat_prob) && value(:stat_mode) != :random
+ self.fail "Parameter 'stat_prob' requires 'stat_mode' to be set to 'random'"
+ end
+
end
end