:log_prefix => "--log-prefix",
:name => "-m comment --comment",
:outiface => "-o",
+ :port => '-m multiport --ports',
:proto => "-p",
:reject => "--reject-with",
:source => "-s",
:tosource => "--to-source",
}
- @resource_list = [:table, :source, :destination, :iniface, :outiface,
- :proto, :sport, :dport, :name, :state, :icmp, :limit, :burst, :jump,
- :todest, :tosource, :toports, :log_level, :log_prefix, :reject]
+ @resource_list = [:table, :source, :destination, :iniface, :outiface,
+ :proto, :sport, :dport, :port, :name, :state, :icmp, :limit, :burst,
+ :jump, :todest, :tosource, :toports, :log_level, :log_prefix, :reject]
def insert
debug 'Inserting rule %s' % resource[:name]
keys.zip(values.scan(/"[^"]*"|\S+/).reverse) { |f, v| hash[f] = v.gsub(/"/, '') }
- [:dport, :sport, :state].each do |prop|
+ [:dport, :sport, :port, :state].each do |prop|
hash[prop] = hash[prop].split(',') if ! hash[prop].nil?
end
# Our type prefers hyphens over colons for ranges so ...
# Iterate across all ports replacing colons with hyphens so that ranges match
# the types expectations.
- [:dport, :sport].each do |prop|
+ [:dport, :sport, :port].each do |prop|
next unless hash[prop]
hash[prop] = hash[prop].collect do |elem|
elem.gsub(/:/,'-')
# For sport and dport, convert hyphens to colons since the type
# expects hyphens for ranges of ports.
- if [:sport, :dport].include?(res) then
+ if [:sport, :dport, :port].include?(res) then
resource_value = resource_value.collect do |elem|
elem.gsub(/-/, ':')
end
end
end
+ newproperty(:port, :array_matching => :all) do
+ desc <<-EOS
+ The destination or source port to match for this filter (if the protocol
+ supports ports). Will accept a single element or an array.
+
+ For some firewall providers you can pass a range of ports in the format:
+
+ <start_number>-<ending_number>
+
+ For example:
+
+ 1-1024
+
+ This would cover ports 1 to 1024.
+ EOS
+
+ munge do |value|
+ @resource.string_to_port(value)
+ end
+
+ def should_to_s(value)
+ value = [value] unless value.is_a?(Array)
+ value.join(',')
+ end
+ end
+
newproperty(:proto) do
desc <<-EOS
The specific protocol to match for this rule. By default this is
},
:args => ['-t', :filter, '-s', '192.168.0.1', '-p', :tcp, '-m', 'comment', '--comment', '000 allow from 192.168.0.1, please'],
},
+ 'port_property' => {
+ :params => {
+ :name => '001 port property',
+ :table => 'filter',
+ :port => '80',
+ },
+ :args => ['-t', :filter, '-p', :tcp, '-m', 'multiport', '--ports', '80', '-m', 'comment', '--comment', '001 port property'],
+ },
}