]> review.fuel-infra Code Review - puppet-modules/puppetlabs-firewall.git/commitdiff
Add support for goto argument.
authorJohan Bloemberg <johan.bloemberg@avira.com>
Thu, 11 Feb 2016 20:22:11 +0000 (21:22 +0100)
committerJohan Bloemberg <johan.bloemberg@avira.com>
Thu, 11 Feb 2016 21:22:48 +0000 (22:22 +0100)
lib/puppet/provider/firewall/iptables.rb
lib/puppet/type/firewall.rb
spec/fixtures/iptables/conversion_hash.rb
spec/unit/puppet/provider/iptables_spec.rb

index 1d7aec510ef9629929d4440f75ceed963e94f5a9..ac0161354c4a6724b3ea0a7faf9526d8f85b6dca 100644 (file)
@@ -73,6 +73,7 @@ Puppet::Type.type(:firewall).provide :iptables, :parent => Puppet::Provider::Fir
     :ipset                 => "-m set --match-set",
     :isfragment            => "-f",
     :jump                  => "-j",
+    :goto                  => "-g",
     :limit                 => "-m limit --limit",
     :log_level             => "--log-level",
     :log_prefix            => "--log-prefix",
@@ -155,7 +156,7 @@ Puppet::Type.type(:firewall).provide :iptables, :parent => Puppet::Provider::Fir
     :clusterip_new,
   ]
 
-  # Properties that use "-m <ipt module name>" (with the potential to have multiple 
+  # Properties that use "-m <ipt module name>" (with the potential to have multiple
   # arguments against the same IPT module) must be in this hash. The keys in this
   # hash are the IPT module names, with the values being an array of the respective
   # supported arguments for this IPT module.
@@ -255,7 +256,7 @@ Puppet::Type.type(:firewall).provide :iptables, :parent => Puppet::Provider::Fir
     :src_range, :dst_range, :tcp_flags, :uid, :gid, :mac_source, :sport, :dport, :port,
     :src_type, :dst_type, :socket, :pkttype, :name, :ipsec_dir, :ipsec_policy,
     :state, :ctstate, :icmp, :limit, :burst, :recent, :rseconds, :reap,
-    :rhitcount, :rttl, :rname, :mask, :rsource, :rdest, :ipset, :jump, :clusterip_new, :clusterip_hashmode,
+    :rhitcount, :rttl, :rname, :mask, :rsource, :rdest, :ipset, :jump, :goto, :clusterip_new, :clusterip_hashmode,
     :clusterip_clustermac, :clusterip_total_nodes, :clusterip_local_node, :clusterip_hash_init,
     :clamp_mss_to_pmtu, :gateway, :set_mss, :set_dscp, :set_dscp_class, :todest, :tosource, :toports, :to, :checksum_fill, :random, :log_prefix,
     :log_level, :log_uid, :reject, :set_mark, :match_mark, :mss, :connlimit_above, :connlimit_mask, :connmark, :time_start, :time_stop,
@@ -434,8 +435,8 @@ Puppet::Type.type(:firewall).provide :iptables, :parent => Puppet::Provider::Fir
     [:dport, :sport, :port, :state, :ctstate].each do |prop|
       hash[prop] = hash[prop].split(',') if ! hash[prop].nil?
     end
-  
-    ## clean up DSCP class to HEX mappings 
+
+    ## clean up DSCP class to HEX mappings
     valid_dscp_classes = {
       '0x0a' => 'af11',
       '0x0c' => 'af12',
index 213fedf0238df7de1440f0372c21d30a1ccd187f..e68b2d62a35a3eb7af70a886363dd37601605a50 100644 (file)
@@ -374,7 +374,7 @@ Puppet::Type.newtype(:firewall) do
     end.flatten)
     defaultto "tcp"
   end
-  
+
   # tcp-specific
   newproperty(:mss) do
     desc <<-EOS
@@ -476,6 +476,40 @@ Puppet::Type.newtype(:firewall) do
     end
   end
 
+  newproperty(:goto, :required_features => :iptables) do
+    desc <<-EOS
+      The value for the iptables --goto parameter. Normal values are:
+
+      * QUEUE
+      * RETURN
+      * DNAT
+      * SNAT
+      * LOG
+      * MASQUERADE
+      * REDIRECT
+      * MARK
+
+      But any valid chain name is allowed.
+    EOS
+
+    validate do |value|
+      unless value =~ /^[a-zA-Z0-9\-_]+$/
+        raise ArgumentError, <<-EOS
+          Goto destination must consist of alphanumeric characters, an
+          underscore or a yphen.
+        EOS
+      end
+
+      if ["accept","reject","drop"].include?(value.downcase)
+        raise ArgumentError, <<-EOS
+          Goto destination should not be one of ACCEPT, REJECT or DROP. Use
+          the action property instead.
+        EOS
+      end
+
+    end
+  end
+
   # Interface specific matching properties
   newproperty(:iniface, :required_features => :interface_match) do
     desc <<-EOS
@@ -894,7 +928,7 @@ Puppet::Type.newtype(:firewall) do
       Set DSCP Markings.
     EOS
   end
-  
+
   newproperty(:set_dscp_class, :required_features => :iptables) do
     desc <<-EOS
       This sets the DSCP field according to a predefined DiffServ class.
index bbdff8cc8786e7cadaffe7c098d197b66678759d..990da91ef766652992ef0bc0aa0adcbe292f4a2d 100644 (file)
@@ -79,6 +79,15 @@ ARGS_TO_HASH = {
       :action => nil,
     },
   },
+  'jump_goto' => {
+    :line => '-A w--instance-cfmhvrgpmq6 -g w--default',
+    :table => 'filter',
+    :params => {
+      :goto => "w--default",
+      :action => nil,
+    },
+
+  },
   'source_destination_ipv4_no_cidr' => {
     :line => '-A INPUT -s 1.1.1.1 -d 2.2.2.2 -m comment --comment "000 source destination ipv4 no cidr"',
     :table => 'filter',
index 055707196a7507e0242c1ecad1ceb2a09e8f5ac3..0fe61199e961ed278a0c65224ce039fd5ed43147 100644 (file)
@@ -431,4 +431,3 @@ describe 'ip6tables provider' do
     end
   end
 end
-