mirror of
https://github.com/fwbuilder/fwbuilder
synced 2026-09-13 16:39:48 +02:00
see #1548 working on deduplication of network objects
This commit is contained in:
@@ -36,6 +36,9 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include <QtDebug>
|
||||||
|
|
||||||
|
|
||||||
extern int fwbdebug;
|
extern int fwbdebug;
|
||||||
|
|
||||||
using namespace libfwbuilder;
|
using namespace libfwbuilder;
|
||||||
@@ -46,10 +49,10 @@ AddressObjectMaker::~AddressObjectMaker() {}
|
|||||||
|
|
||||||
FWObject* AddressObjectMaker::createObject(ObjectSignature &sig)
|
FWObject* AddressObjectMaker::createObject(ObjectSignature &sig)
|
||||||
{
|
{
|
||||||
assert( ! sig.type_name.isEmpty());
|
// FWObject *obj = findMatchingObject(sig);
|
||||||
|
// if (obj) return obj;
|
||||||
|
|
||||||
FWObject *obj = findMatchingObject(sig);
|
FWObject *obj = NULL;
|
||||||
if (obj) return obj;
|
|
||||||
|
|
||||||
if (sig.type_name == AddressRange::TYPENAME)
|
if (sig.type_name == AddressRange::TYPENAME)
|
||||||
obj = createAddressRange(sig.address_range_start, sig.address_range_end);
|
obj = createAddressRange(sig.address_range_start, sig.address_range_end);
|
||||||
@@ -77,50 +80,9 @@ FWObject* AddressObjectMaker::createAddress(const QString &addr,
|
|||||||
correct_nm = (~orig_nm).toString().c_str();
|
correct_nm = (~orig_nm).toString().c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( correct_nm == InetAddr::getAllOnes().toString().c_str() )
|
|
||||||
{
|
|
||||||
QString name;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
InetAddr obj_addr(addr.toStdString()); // testing if string converts to an address
|
InetAddr(correct_nm.toStdString());
|
||||||
name = QString("h-") + addr;
|
|
||||||
Address *a = Address::cast(
|
|
||||||
ObjectMaker::createObject(IPv4::TYPENAME, name.toStdString()));
|
|
||||||
a->setAddress(obj_addr);
|
|
||||||
a->setNetmask(InetAddr(InetAddr::getAllOnes()));
|
|
||||||
return a;
|
|
||||||
} catch(FWException &ex)
|
|
||||||
{
|
|
||||||
// address text line can not be converted to ipv4 address.
|
|
||||||
// Since parsers do not understand ipv6 yet, assume this
|
|
||||||
// is a host address and create DNSName object
|
|
||||||
|
|
||||||
name = addr;
|
|
||||||
DNSName *da = DNSName::cast(
|
|
||||||
ObjectMaker::createObject(DNSName::TYPENAME, name.toStdString()));
|
|
||||||
da->setSourceName(addr.toStdString());
|
|
||||||
da->setRunTime(true);
|
|
||||||
return da;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
|
|
||||||
QString name = QString("net-") + addr + "/" + correct_nm;
|
|
||||||
Network *net = Network::cast(
|
|
||||||
ObjectMaker::createObject(Network::TYPENAME, name.toStdString()));
|
|
||||||
try
|
|
||||||
{
|
|
||||||
net->setAddress( InetAddr(addr.toStdString()) );
|
|
||||||
} catch (FWException &ex)
|
|
||||||
{
|
|
||||||
throw ObjectMakerException(
|
|
||||||
QString("Error converting address '%1'").arg(addr));
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
net->setNetmask( InetAddr(correct_nm.toStdString()) );
|
|
||||||
} catch (FWException &ex)
|
} catch (FWException &ex)
|
||||||
{
|
{
|
||||||
if (correct_nm.contains('.'))
|
if (correct_nm.contains('.'))
|
||||||
@@ -137,7 +99,7 @@ FWObject* AddressObjectMaker::createAddress(const QString &addr,
|
|||||||
int nm_len = correct_nm.toInt(&ok);
|
int nm_len = correct_nm.toInt(&ok);
|
||||||
if (ok)
|
if (ok)
|
||||||
{
|
{
|
||||||
net->setNetmask( InetAddr(nm_len) );
|
correct_nm = InetAddr(nm_len).toString().c_str();
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
// could not convert netmask as simple integer
|
// could not convert netmask as simple integer
|
||||||
@@ -147,6 +109,70 @@ FWObject* AddressObjectMaker::createAddress(const QString &addr,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ObjectSignature sig;
|
||||||
|
sig.address = addr;
|
||||||
|
sig.netmask = correct_nm;
|
||||||
|
|
||||||
|
if ( correct_nm == InetAddr::getAllOnes().toString().c_str() )
|
||||||
|
{
|
||||||
|
QString name;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
sig.type_name = IPv4::TYPENAME;
|
||||||
|
|
||||||
|
FWObject *obj = findMatchingObject(sig);
|
||||||
|
if (obj) return obj;
|
||||||
|
|
||||||
|
InetAddr obj_addr(addr.toStdString()); // testing if string converts to an address
|
||||||
|
name = QString("h-") + addr;
|
||||||
|
Address *a = Address::cast(
|
||||||
|
ObjectMaker::createObject(IPv4::TYPENAME, name.toStdString()));
|
||||||
|
a->setAddress(obj_addr);
|
||||||
|
a->setNetmask(InetAddr(InetAddr::getAllOnes()));
|
||||||
|
return a;
|
||||||
|
|
||||||
|
} catch(FWException &ex)
|
||||||
|
{
|
||||||
|
// address text line can not be converted to ipv4 address.
|
||||||
|
// Since parsers do not understand ipv6 yet, assume this
|
||||||
|
// is a host address and create DNSName object
|
||||||
|
|
||||||
|
sig.type_name = DNSName::TYPENAME;
|
||||||
|
FWObject *obj = findMatchingObject(sig);
|
||||||
|
if (obj) return obj;
|
||||||
|
|
||||||
|
name = addr;
|
||||||
|
DNSName *da = DNSName::cast(
|
||||||
|
ObjectMaker::createObject(DNSName::TYPENAME, name.toStdString()));
|
||||||
|
da->setSourceName(addr.toStdString());
|
||||||
|
da->setRunTime(true);
|
||||||
|
return da;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
sig.type_name = Network::TYPENAME;
|
||||||
|
|
||||||
|
qDebug() << "Search for " << sig.toString();
|
||||||
|
|
||||||
|
FWObject *obj = findMatchingObject(sig);
|
||||||
|
if (obj) return obj;
|
||||||
|
|
||||||
|
QString name = QString("net-") + addr + "/" + correct_nm;
|
||||||
|
Network *net = Network::cast(
|
||||||
|
ObjectMaker::createObject(Network::TYPENAME, name.toStdString()));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
net->setAddress( InetAddr(addr.toStdString()) );
|
||||||
|
} catch (FWException &ex)
|
||||||
|
{
|
||||||
|
throw ObjectMakerException(
|
||||||
|
QString("Error converting address '%1'").arg(addr));
|
||||||
|
}
|
||||||
|
|
||||||
|
// we have already verified netmask above
|
||||||
|
net->setNetmask( InetAddr(correct_nm.toStdString()) );
|
||||||
|
|
||||||
return net;
|
return net;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
@@ -838,12 +838,14 @@ void ObjectMaker::prepareForDeduplication(FWObject *root)
|
|||||||
|
|
||||||
root->dispatch(&sig, (void*)(NULL));
|
root->dispatch(&sig, (void*)(NULL));
|
||||||
|
|
||||||
|
qDebug() << "Registering " << sig.toString();
|
||||||
|
|
||||||
registerNamedObject(sig, root);
|
registerNamedObject(sig, root);
|
||||||
registerAnonymousObject(sig, root); // this erases sig.object_name
|
registerAnonymousObject(sig, root); // this erases sig.object_name
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Library::isA(root) && root->getId() == FWObjectDatabase::DELETED_OBJECTS_ID)
|
if (Library::isA(root) &&
|
||||||
return;
|
root->getId() == FWObjectDatabase::DELETED_OBJECTS_ID) return;
|
||||||
|
|
||||||
for (FWObject::iterator it=root->begin(); it!=root->end(); ++it)
|
for (FWObject::iterator it=root->begin(); it!=root->end(); ++it)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $ANTLR 2.7.7 (20090306): "pix.g" -> "PIXCfgLexer.cpp"$ */
|
/* $ANTLR 2.7.7 (20100319): "pix.g" -> "PIXCfgLexer.cpp"$ */
|
||||||
#line 42 "pix.g"
|
#line 42 "pix.g"
|
||||||
|
|
||||||
// gets inserted before the antlr generated includes in the cpp
|
// gets inserted before the antlr generated includes in the cpp
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
#line 11 "PIXCfgLexer.hpp"
|
#line 11 "PIXCfgLexer.hpp"
|
||||||
#include <antlr/config.hpp>
|
#include <antlr/config.hpp>
|
||||||
/* $ANTLR 2.7.7 (20090306): "pix.g" -> "PIXCfgLexer.hpp"$ */
|
/* $ANTLR 2.7.7 (20100319): "pix.g" -> "PIXCfgLexer.hpp"$ */
|
||||||
#include <antlr/CommonToken.hpp>
|
#include <antlr/CommonToken.hpp>
|
||||||
#include <antlr/InputBuffer.hpp>
|
#include <antlr/InputBuffer.hpp>
|
||||||
#include <antlr/BitSet.hpp>
|
#include <antlr/BitSet.hpp>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $ANTLR 2.7.7 (20090306): "pix.g" -> "PIXCfgParser.cpp"$ */
|
/* $ANTLR 2.7.7 (20100319): "pix.g" -> "PIXCfgParser.cpp"$ */
|
||||||
#line 42 "pix.g"
|
#line 42 "pix.g"
|
||||||
|
|
||||||
// gets inserted before the antlr generated includes in the cpp
|
// gets inserted before the antlr generated includes in the cpp
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
#line 11 "PIXCfgParser.hpp"
|
#line 11 "PIXCfgParser.hpp"
|
||||||
#include <antlr/config.hpp>
|
#include <antlr/config.hpp>
|
||||||
/* $ANTLR 2.7.7 (20090306): "pix.g" -> "PIXCfgParser.hpp"$ */
|
/* $ANTLR 2.7.7 (20100319): "pix.g" -> "PIXCfgParser.hpp"$ */
|
||||||
#include <antlr/TokenStream.hpp>
|
#include <antlr/TokenStream.hpp>
|
||||||
#include <antlr/TokenBuffer.hpp>
|
#include <antlr/TokenBuffer.hpp>
|
||||||
#include "PIXCfgParserTokenTypes.hpp"
|
#include "PIXCfgParserTokenTypes.hpp"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#ifndef INC_PIXCfgParserTokenTypes_hpp_
|
#ifndef INC_PIXCfgParserTokenTypes_hpp_
|
||||||
#define INC_PIXCfgParserTokenTypes_hpp_
|
#define INC_PIXCfgParserTokenTypes_hpp_
|
||||||
|
|
||||||
/* $ANTLR 2.7.7 (20090306): "pix.g" -> "PIXCfgParserTokenTypes.hpp"$ */
|
/* $ANTLR 2.7.7 (20100319): "pix.g" -> "PIXCfgParserTokenTypes.hpp"$ */
|
||||||
|
|
||||||
#ifndef CUSTOM_API
|
#ifndef CUSTOM_API
|
||||||
# define CUSTOM_API
|
# define CUSTOM_API
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// $ANTLR 2.7.7 (20090306): pix.g -> PIXCfgParserTokenTypes.txt$
|
// $ANTLR 2.7.7 (20100319): pix.g -> PIXCfgParserTokenTypes.txt$
|
||||||
PIXCfgParser // output token vocab name
|
PIXCfgParser // output token vocab name
|
||||||
NEWLINE=4
|
NEWLINE=4
|
||||||
QUIT="quit"=5
|
QUIT="quit"=5
|
||||||
|
|||||||
Reference in New Issue
Block a user