]> review.fuel-infra Code Review - puppet-modules/puppetlabs-firewall.git/commitdiff
add firewall util
authorJonathan Boyett <jonathan@failingservers.com>
Mon, 9 May 2011 17:52:48 +0000 (10:52 -0700)
committerJonathan Boyett <jonathan@failingservers.com>
Mon, 9 May 2011 17:52:48 +0000 (10:52 -0700)
lib/puppet/util/firewall.rb [new file with mode: 0644]

diff --git a/lib/puppet/util/firewall.rb b/lib/puppet/util/firewall.rb
new file mode 100644 (file)
index 0000000..d49aeb4
--- /dev/null
@@ -0,0 +1,59 @@
+# Puppet Firewall Module
+#
+# Copyright (C) 2011 Bob.sh Limited
+# Copyright (C) 2008 Camptocamp Association
+# Copyright (C) 2007 Dmitri Priimak
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+require 'socket'
+require 'puppet/util/ipcidr'
+
+module Puppet::Util::Firewall
+  # Translate the symbolic names for icmp packet types to integers
+  def icmp_name_to_number(value_icmp)
+    if value_icmp =~ /\d{1,2}$/
+      value_icmp
+    else
+      case value_icmp
+        when "echo-reply" then "0"
+        when "destination-unreachable" then "3"
+        when "source-quench" then "4"
+        when "redirect" then "6"
+        when "echo-request" then "8"
+        when "router-advertisement" then "9"
+        when "router-solicitation" then "10"
+        when "time-exceeded" then "11"
+        when "parameter-problem" then "12"
+        when "timestamp-request" then "13"
+        when "timestamp-reply" then "14"
+        when "address-mask-request" then "17"
+        when "address-mask-reply" then "18"
+        else nil
+      end
+    end
+  end
+
+  def string_to_port(value)
+    if value.kind_of?(Array)
+      ports = []
+      value.each do |port|
+        ports << Socket.getservbyname(port) unless port.kind_of?(Integer)
+      end
+      ports
+    else
+      Socket.getservbyname(value)
+    end
+  end
+end