]> git.openstreetmap.org Git - chef.git/blobdiff - cookbooks/networking/resources/firewall_rule.rb
Don't expire connection limit sets
[chef.git] / cookbooks / networking / resources / firewall_rule.rb
index 36500c022f5339cec5ed0fad790208f2253d8c2d..75d73dc11ebb8dc217004a0a75e8194940057246 100644 (file)
@@ -133,19 +133,23 @@ action_class do
       rule << "ct state new"
     end
 
-    # if new_resource.connection_limit != "-"
-    #   rule << "ct count #{new_resource.connection_limit}"
-    # end
-
-    # if new_resource.rate_limit =~ %r{^s:(\d+)/sec:(\d+)$}
-    #   set = "#{new_resource.rule}-#{ip}"
-    #   rate = Regexp.last_match(1)
-    #   burst = Regexp.last_match(2)
-    #
-    #   node.default[:networking][:firewall][:sets] << set
-    #
-    #   rule << "add @#{set} { #{ip} saddr limit rate #{rate}/second burst #{burst} packets }"
-    # end
+    if new_resource.connection_limit != "-"
+      set = "connlimit-#{new_resource.rule}-#{ip}"
+
+      node.default[:networking][:firewall][:sets] << set
+
+      rule << "add @#{set} { #{ip} saddr ct count #{new_resource.connection_limit} }"
+    end
+
+    if new_resource.rate_limit =~ %r{^s:(\d+)/sec:(\d+)$}
+      set = "ratelimit-#{new_resource.rule}-#{ip}"
+      rate = Regexp.last_match(1)
+      burst = Regexp.last_match(2)
+
+      node.default[:networking][:firewall][:sets] << set
+
+      rule << "update @#{set} { #{ip} saddr limit rate #{rate}/second burst #{burst} packets }"
+    end
 
     rule << case action
             when :accept then "accept"