[firewalld-recode] master: Added stringToNumber utility function (aadf621)
by mildew@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/firewalld-recode.git
On branch : master
>---------------------------------------------------------------
commit aadf62168f909ee621378479f9178b47406061ac
Author: Daniel Kopecek <dkopecek(a)redhat.com>
Date: Thu Oct 2 11:19:58 2014 +0200
Added stringToNumber utility function
>---------------------------------------------------------------
src/Common/Utility.hpp | 9 +++++++++
1 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/src/Common/Utility.hpp b/src/Common/Utility.hpp
index b54e13b..271350a 100644
--- a/src/Common/Utility.hpp
+++ b/src/Common/Utility.hpp
@@ -57,6 +57,15 @@ namespace firewalld
return ss.str();
}
+ template<typename T>
+ T stringToNumber(const String& s)
+ {
+ std::istringstream ss(s);
+ T num;
+ ss >> num;
+ return num;
+ }
+
String filenameFromPath(const String& filepath, bool include_extension = false);
template<class StringType>
9 years, 7 months
[firewalld-recode] master: Proper ICMPType implementation (0c64184)
by mildew@fedoraproject.org
Repository : http://git.fedorahosted.org/cgit/firewalld-recode.git
On branch : master
>---------------------------------------------------------------
commit 0c641842a229f07df6a8a6bbb9a9ad7641f35ddc
Author: Daniel Kopecek <dkopecek(a)redhat.com>
Date: Wed Oct 1 14:16:26 2014 +0200
Proper ICMPType implementation
>---------------------------------------------------------------
src/Daemon/Firewall/Firewall.hpp | 2 +
src/Daemon/Firewall/ICMPType.cpp | 101 +++++++++++++++++++++
src/Daemon/Firewall/{Service.hpp => ICMPType.hpp} | 34 +++++---
src/Daemon/FirewallD.cpp | 16 +++-
src/Daemon/FirewallD.hpp | 5 +-
5 files changed, 142 insertions(+), 16 deletions(-)
diff --git a/src/Daemon/Firewall/Firewall.hpp b/src/Daemon/Firewall/Firewall.hpp
index 20089f5..3a4ab5d 100644
--- a/src/Daemon/Firewall/Firewall.hpp
+++ b/src/Daemon/Firewall/Firewall.hpp
@@ -23,6 +23,8 @@
#include "Daemon/Backends/Linux/IPTables.hpp"
#include "Daemon/Backends/Linux/EBTables.hpp"
#include "Daemon/Firewall/Zone.hpp"
+#include "Daemon/Firewall/Service.hpp"
+#include "Daemon/Firewall/ICMPType.hpp"
#include <glibmm.h>
#include <giomm.h>
diff --git a/src/Daemon/Firewall/ICMPType.cpp b/src/Daemon/Firewall/ICMPType.cpp
new file mode 100644
index 0000000..9ff9282
--- /dev/null
+++ b/src/Daemon/Firewall/ICMPType.cpp
@@ -0,0 +1,101 @@
+//
+// Copyright (C) 2014 Red Hat, Inc.
+//
+// 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 2 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/>.
+//
+// Authors: Daniel Kopecek <dkopecek(a)redhat.com>
+//
+#include "Daemon/Firewall/ICMPType.hpp"
+#include "Common/Utility.hpp"
+#include "Common/Logging.hpp"
+
+namespace firewalld
+{
+
+ ICMPType::ICMPType()
+ {
+ }
+
+ ICMPType::ICMPType(const UString& identifier)
+ {
+ _identifier = identifier;
+ _flags = FlagSet<Flags>(Flags::IPv4 | Flags::IPv6);
+ }
+
+ const UString& ICMPType::identifier() const
+ {
+ return _identifier;
+ }
+
+ const FlagSet<ICMPType::Flags> ICMPType::flags() const
+ {
+ return _flags;
+ }
+
+ const UString& ICMPType::description() const
+ {
+ return _description;
+ }
+
+ void ICMPType::initFromXML(const String& filepath)
+ {
+ _identifier = filenameFromPath(filepath);
+ _version = "0";
+ _flags = FlagSet<Flags>(Flags::IPv4 | Flags::IPv6);
+ XMLStorage::load(filepath);
+ }
+
+ void ICMPType::XMLElementStart(const UString& name, const UStringKeyMap<UString>& attr)
+ {
+ if (elementStackState({"icmptype"})) {
+ try {
+ _version = attr.at("version");
+ } catch(const std::out_of_range& ex) {
+ }
+ }
+
+ if (elementStackState({"destination", "icmptype"})) {
+ try {
+ const UString& ipv4 = attr.at("ipv4");
+
+ if (ipv4 == "false") {
+ _flags.unset(Flags::IPv4);
+ }
+ } catch(const std::out_of_range& ex) {
+ }
+
+ try {
+ const UString& ipv6 = attr.at("ipv6");
+
+ if (ipv6 == "false") {
+ _flags.unset(Flags::IPv6);
+ }
+ } catch(const std::out_of_range& ex) {
+ }
+ }
+ }
+
+ void ICMPType::XMLElementEnd(const UString& name)
+ {
+ return;
+ }
+
+ void ICMPType::XMLElementStringValue(const UString& name, const UString& value)
+ {
+ if (elementStackState({"description", "icmptype"})) {
+ _description = value;
+ }
+ }
+
+} /* namespace firewalld*/
diff --git a/src/Daemon/Firewall/Service.hpp b/src/Daemon/Firewall/ICMPType.hpp
similarity index 68%
copy from src/Daemon/Firewall/Service.hpp
copy to src/Daemon/Firewall/ICMPType.hpp
index 4e9b69a..5b7fe72 100644
--- a/src/Daemon/Firewall/Service.hpp
+++ b/src/Daemon/Firewall/ICMPType.hpp
@@ -16,24 +16,31 @@
//
// Authors: Daniel Kopecek <dkopecek(a)redhat.com>
//
-#ifndef FIREWALLD_FIREWALL_SERVICE_HPP
-#define FIREWALLD_FIREWALL_SERVICE_HPP
+#ifndef FIREWALLD_FIREWALL_ICMPTYPE_HPP
+#define FIREWALLD_FIREWALL_ICMPTYPE_HPP
#include "Common/Types.hpp"
#include "Common/XMLStorage.hpp"
namespace firewalld
{
- class Port;
- class KernelModule;
- class Service : private XMLStorage, public std::enable_shared_from_this<Service>
+ class ICMPType : private XMLStorage
{
public:
- Service();
- Service(const UString& identifier);
+ enum Flags {
+ IPv4 = 1 << 0,
+ IPv6 = 1 << 1
+ };
+
+ ICMPType();
+ ICMPType(const UString& identifier);
const UString& identifier() const;
+ const FlagSet<Flags> flags() const;
+ const UString& description() const;
+ const UString& version() const;
+
void initFromXML(const String& filepath);
protected:
@@ -43,11 +50,14 @@ namespace firewalld
private:
// Unique identifier of the service.
- // Currently it is the filename of the service on the filesystem
+ // Currently it is the filename of the ICMPType on the filesystem
// without the .xml extension.
UString _identifier;
- PointerVector<Port> _ports;
- PointerVector<KernelModule> _modules;
+ UString _version;
+ UString _description;
+ FlagSet<Flags> _flags;
};
-}
-#endif /* FIREWALLD_FIREWALL_SERVICE_HPP */
+
+} /* namespace firewalld */
+
+#endif /* FIREWALLD_ICMPTYPE_HPP */
diff --git a/src/Daemon/FirewallD.cpp b/src/Daemon/FirewallD.cpp
index 8365c4b..bb9da51 100644
--- a/src/Daemon/FirewallD.cpp
+++ b/src/Daemon/FirewallD.cpp
@@ -208,6 +208,17 @@ namespace firewalld
}
}
+ Pointer<ICMPType> FirewallD::lookupICMPType(const UString& name) const
+ {
+ try {
+ return _defined_icmptypes.at(name);
+ } catch(const std::out_of_range& ex) {
+ return nullptr;
+ } catch(...) {
+ throw std::runtime_error("Unexpected exception");
+ }
+ }
+
void FirewallD::loadServiceDefinitions(const String& directory)
{
VLOG(2) << "Loading Service definitions from " << directory;
@@ -253,8 +264,9 @@ namespace firewalld
void FirewallD::loadICMPTypeDefinition(const String& filepath)
{
VLOG(3) << "Loading ICMP type definition from " << filepath;
- UString icmptype = filenameFromPath(filepath);
- _defined_icmptypes[icmptype] = true;
+ Pointer<ICMPType> icmptype = makePointer<ICMPType>();
+ icmptype->initFromXML(filepath);
+ _defined_icmptypes[icmptype->identifier()] = icmptype;
return;
}
diff --git a/src/Daemon/FirewallD.hpp b/src/Daemon/FirewallD.hpp
index 8f4a8f8..12cf1cc 100644
--- a/src/Daemon/FirewallD.hpp
+++ b/src/Daemon/FirewallD.hpp
@@ -48,10 +48,11 @@ namespace firewalld
const PointerMap<UString,Service> definedServices() const { return _defined_services; }
const PointerMap<UString,Zone> definedZones() const { return _defined_zones; }
- const UStringKeyMap<bool> definedICMPTypes() const { return _defined_icmptypes; }
+ const PointerMap<UString,ICMPType> definedICMPTypes() const { return _defined_icmptypes; }
Pointer<Service> lookupService(const UString& name) const;
Pointer<Zone> lookupZone(const UString& name) const;
+ Pointer<ICMPType> lookupICMPType(const UString& name) const;
static const FirewallD* instance();
@@ -142,7 +143,7 @@ namespace firewalld
// Defined services
PointerMap<UString,Service> _defined_services;
PointerMap<UString,Zone> _defined_zones;
- UStringKeyMap<bool> _defined_icmptypes;
+ PointerMap<UString,ICMPType> _defined_icmptypes;
// Config _config;
bool _panic_mode;
9 years, 7 months