mirror of
https://github.com/fwbuilder/fwbuilder
synced 2026-05-10 19:14:57 +02:00
adding missing files
This commit is contained in:
134
src/libfwbuilder/src/fwbuilder/AttachedNetworks.cpp
Normal file
134
src/libfwbuilder/src/fwbuilder/AttachedNetworks.cpp
Normal file
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
|
||||
Firewall Builder
|
||||
|
||||
Copyright (C) 2011 NetCitadel, LLC
|
||||
|
||||
Author: Vadim Kurland vadim@fwbuilder.org
|
||||
|
||||
This program is free software which we release under the GNU General Public
|
||||
License. You may redistribute and/or modify this program under the terms
|
||||
of that 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.
|
||||
|
||||
To get a copy of the GNU General Public License, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <fwbuilder/libfwbuilder-config.h>
|
||||
|
||||
#include <fwbuilder/AttachedNetworks.h>
|
||||
#include <fwbuilder/FWException.h>
|
||||
#include <fwbuilder/FWObjectReference.h>
|
||||
#include <fwbuilder/FWObjectDatabase.h>
|
||||
#include <fwbuilder/Interface.h>
|
||||
#include <fwbuilder/IPv4.h>
|
||||
#include <fwbuilder/IPv6.h>
|
||||
#include <fwbuilder/Network.h>
|
||||
#include <fwbuilder/NetworkIPv6.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
using namespace libfwbuilder;
|
||||
using namespace std;
|
||||
|
||||
|
||||
const char *AttachedNetworks::TYPENAME={"AttachedNetworks"};
|
||||
|
||||
|
||||
AttachedNetworks::AttachedNetworks() : MultiAddress()
|
||||
{
|
||||
}
|
||||
|
||||
void AttachedNetworks::fromXML(xmlNodePtr root) throw(FWException)
|
||||
{
|
||||
FWObject::fromXML(root);
|
||||
}
|
||||
|
||||
xmlNodePtr AttachedNetworks::toXML(xmlNodePtr parent) throw(FWException)
|
||||
{
|
||||
remStr("run_time");
|
||||
|
||||
xmlNodePtr me = FWObject::toXML(parent, false);
|
||||
|
||||
xmlNewProp(me, TOXMLCAST("name"), STRTOXMLCAST(getName()));
|
||||
xmlNewProp(me, TOXMLCAST("comment"), STRTOXMLCAST(getComment()));
|
||||
xmlNewProp(me, TOXMLCAST("ro"), TOXMLCAST(((getRO()) ? "True" : "False")));
|
||||
|
||||
return me;
|
||||
}
|
||||
|
||||
|
||||
void AttachedNetworks::addNetworkObject(const InetAddr *ip_addr,
|
||||
const InetAddr *ip_netm)
|
||||
{
|
||||
FWObject *new_obj;
|
||||
|
||||
if (ip_addr->isV4())
|
||||
{
|
||||
Network *net = getRoot()->createNetwork();
|
||||
net->setAddress(*ip_addr);
|
||||
net->setNetmask(*ip_netm);
|
||||
ostringstream str;
|
||||
str << "net-" << ip_addr->toString() << "/" << ip_netm->toString();
|
||||
net->setName(str.str());
|
||||
new_obj = net;
|
||||
}
|
||||
|
||||
if (ip_addr->isV6())
|
||||
{
|
||||
NetworkIPv6 *net = getRoot()->createNetworkIPv6();
|
||||
net->setAddress(*ip_addr);
|
||||
net->setNetmask(*ip_netm);
|
||||
ostringstream str;
|
||||
str << "net-" << ip_addr->toString() << "/" << ip_netm->getLength();
|
||||
net->setName(str.str());
|
||||
new_obj = net;
|
||||
}
|
||||
|
||||
if (validateChild(new_obj))
|
||||
{
|
||||
getRoot()->add(new_obj);
|
||||
addRef(new_obj);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Read addresses of the parent interface and build a group of
|
||||
* corresponding networks.
|
||||
*/
|
||||
void AttachedNetworks::loadFromSource(bool ipv6, bool ) throw(FWException)
|
||||
{
|
||||
Interface *parent_intf = Interface::cast(getParent());
|
||||
assert(parent_intf);
|
||||
|
||||
string c_type = (ipv6) ? IPv6::TYPENAME : IPv4::TYPENAME;
|
||||
|
||||
FWObjectTypedChildIterator k = parent_intf->findByType(c_type);
|
||||
for ( ; k!=k.end(); ++k)
|
||||
{
|
||||
Address *addr = Address::cast(*k);
|
||||
const InetAddr *ip_netm = addr->getNetmaskPtr();
|
||||
const InetAddr *ip_net_addr = addr->getNetworkAddressPtr();
|
||||
addNetworkObject(ip_net_addr, ip_netm);
|
||||
}
|
||||
}
|
||||
|
||||
string AttachedNetworks::getSourceName()
|
||||
{
|
||||
Interface *parent = Interface::cast(getParent());
|
||||
assert(parent!=NULL);
|
||||
return parent->getName();
|
||||
}
|
||||
|
||||
58
src/libfwbuilder/src/fwbuilder/AttachedNetworks.h
Normal file
58
src/libfwbuilder/src/fwbuilder/AttachedNetworks.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
|
||||
Firewall Builder
|
||||
|
||||
Copyright (C) 2011 NetCitadel, LLC
|
||||
|
||||
Author: Vadim Kurland vadim@fwbuilder.org
|
||||
|
||||
This program is free software which we release under the GNU General Public
|
||||
License. You may redistribute and/or modify this program under the terms
|
||||
of that 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.
|
||||
|
||||
To get a copy of the GNU General Public License, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _ATTACHEDNETWORKS_HH_
|
||||
#define _ATTACHEDNETWORKS_HH_
|
||||
|
||||
#include <fwbuilder/MultiAddress.h>
|
||||
|
||||
namespace libfwbuilder
|
||||
{
|
||||
|
||||
class AttachedNetworks : public MultiAddress
|
||||
{
|
||||
private:
|
||||
|
||||
void addNetworkObject(const InetAddr *ip_addr, const InetAddr *ip_netm);
|
||||
|
||||
public:
|
||||
|
||||
DECLARE_FWOBJECT_SUBTYPE(AttachedNetworks);
|
||||
|
||||
DECLARE_DISPATCH_METHODS(AttachedNetworks);
|
||||
|
||||
AttachedNetworks();
|
||||
|
||||
virtual void fromXML(xmlNodePtr parent) throw(FWException);
|
||||
virtual xmlNodePtr toXML(xmlNodePtr xml_parent_node) throw(FWException);
|
||||
virtual void loadFromSource(bool ipv6, bool test_mode=false) throw(FWException);
|
||||
|
||||
virtual std::string getSourceName();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user