From 9df52ea433562300a895808efdc5c8cdd95fb7a4 Mon Sep 17 00:00:00 2001 From: Jonathan Boyett Date: Mon, 9 May 2011 10:52:48 -0700 Subject: [PATCH] add firewall util --- lib/puppet/util/firewall.rb | 59 +++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 lib/puppet/util/firewall.rb diff --git a/lib/puppet/util/firewall.rb b/lib/puppet/util/firewall.rb new file mode 100644 index 0000000..d49aeb4 --- /dev/null +++ b/lib/puppet/util/firewall.rb @@ -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 . + +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 -- 2.45.2