mirror of
https://github.com/fwbuilder/fwbuilder
synced 2026-03-24 12:17:26 +01:00
fixes #786
This commit is contained in:
parent
042846afcf
commit
54a13c854c
@ -432,3 +432,48 @@ bool interfaceProperties::isEligibleForCluster(Interface *intf)
|
||||
return true;
|
||||
}
|
||||
|
||||
void interfaceProperties::guessSubInterfaceTypeAndAttributes(Interface *intf)
|
||||
{
|
||||
Interface *parent_intf = Interface::cast(intf->getParent());
|
||||
|
||||
if (parent_intf == NULL) return;
|
||||
|
||||
FWObject *f = intf->getParentHost();
|
||||
|
||||
Resources* os_res = Resources::os_res[f->getStr("host_OS")];
|
||||
string os_family = f->getStr("host_OS");
|
||||
if (os_res!=NULL)
|
||||
os_family = os_res->getResourceStr("/FWBuilderResources/Target/family");
|
||||
|
||||
QString err;
|
||||
if (looksLikeVlanInterface(intf->getName().c_str()) &&
|
||||
isValidVlanInterfaceName(intf->getName().c_str(),
|
||||
intf->getParent()->getName().c_str(), err)
|
||||
)
|
||||
{
|
||||
InterfaceData *idata = new InterfaceData(*intf);
|
||||
//parseVlan(idata);
|
||||
idata->interface_type = "8021q";
|
||||
parseVlan(idata->name.c_str(), NULL, &(idata->vlan_id));
|
||||
if (!idata->interface_type.empty())
|
||||
{
|
||||
intf->getOptionsObject()->setStr("type", idata->interface_type);
|
||||
if (idata->interface_type == "8021q")
|
||||
intf->getOptionsObject()->setInt("vlan_id", idata->vlan_id);
|
||||
}
|
||||
delete idata;
|
||||
} else
|
||||
{
|
||||
if (parent_intf->getOptionsObject()->getStr("type") == "bridge")
|
||||
{
|
||||
intf->getOptionsObject()->setStr("type", "ethernet");
|
||||
}
|
||||
|
||||
if (parent_intf->getOptionsObject()->getStr("type") == "bonding")
|
||||
{
|
||||
intf->getOptionsObject()->setStr("type", "ethernet");
|
||||
intf->setUnnumbered(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -84,6 +84,8 @@ public:
|
||||
|
||||
virtual bool isEligibleForCluster(libfwbuilder::Interface *intf);
|
||||
|
||||
virtual void guessSubInterfaceTypeAndAttributes(libfwbuilder::Interface *intf);
|
||||
|
||||
/**
|
||||
* for the given interface return list of its ip addresses that we
|
||||
* should manage using update_addresses shell function and list of
|
||||
|
||||
@ -30,10 +30,22 @@
|
||||
#include "bsdInterfaces.h"
|
||||
#include "pixInterfaces.h"
|
||||
|
||||
#include "fwbuilder/FWObject.h"
|
||||
#include "fwbuilder/Resources.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace libfwbuilder;
|
||||
using namespace std;
|
||||
|
||||
interfaceProperties* interfacePropertiesObjectFactory::getInterfacePropertiesObject(FWObject *fw)
|
||||
{
|
||||
Resources* os_res = Resources::os_res[fw->getStr("host_OS")];
|
||||
string os_family = fw->getStr("host_OS");
|
||||
if (os_res!=NULL)
|
||||
os_family = os_res->getResourceStr("/FWBuilderResources/Target/family");
|
||||
return getInterfacePropertiesObject(os_family);
|
||||
}
|
||||
|
||||
interfaceProperties* interfacePropertiesObjectFactory::getInterfacePropertiesObject(
|
||||
const std::string &os_family)
|
||||
|
||||
@ -30,10 +30,16 @@
|
||||
|
||||
#include "interfaceProperties.h"
|
||||
|
||||
namespace libfwbuilder {
|
||||
class FWObject;
|
||||
}
|
||||
|
||||
|
||||
class interfacePropertiesObjectFactory {
|
||||
|
||||
public:
|
||||
static interfaceProperties* getInterfacePropertiesObject(const std::string &host_os);
|
||||
static interfaceProperties* getInterfacePropertiesObject(libfwbuilder::FWObject *fw);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -2285,16 +2285,9 @@ void DiscoveryDruid::createRealObjects()
|
||||
}
|
||||
}
|
||||
|
||||
Resources* os_res = Resources::os_res[o->getStr("host_OS")];
|
||||
string os_family = o->getStr("host_OS");
|
||||
if (os_res!=NULL)
|
||||
os_family = os_res->getResourceStr(
|
||||
"/FWBuilderResources/Target/family");
|
||||
|
||||
list<InterfaceData*> interface_tree;
|
||||
std::auto_ptr<interfaceProperties> int_prop(
|
||||
interfacePropertiesObjectFactory::getInterfacePropertiesObject(
|
||||
os_family));
|
||||
interfacePropertiesObjectFactory::getInterfacePropertiesObject(o));
|
||||
int_prop->rearrangeInterfaces(od.interfaces, interface_tree);
|
||||
|
||||
if (interface_tree.size() != od.interfaces.size())
|
||||
|
||||
@ -267,7 +267,7 @@ void FWWindow::findWhereUsed(FWObject * obj, ProjectPanel *pp)
|
||||
bool FWWindow::requestEditorOwnership(QWidget*,
|
||||
FWObject*,
|
||||
ObjectEditor::OptType,
|
||||
bool validate)
|
||||
bool)
|
||||
{
|
||||
if (!isEditorVisible()) return false;
|
||||
|
||||
|
||||
@ -114,7 +114,11 @@ void InterfaceDialog::loadFWObject(FWObject *o)
|
||||
* something relevant in the interface to complement their changes
|
||||
* and right after the interface has been created.
|
||||
*/
|
||||
m_project->m_panel->om->guessSubInterfaceTypeAndAttributes(s);
|
||||
interfaceProperties *int_prop =
|
||||
interfacePropertiesObjectFactory::getInterfacePropertiesObject(
|
||||
s->getParentHost());
|
||||
int_prop->guessSubInterfaceTypeAndAttributes(s);
|
||||
delete int_prop;
|
||||
|
||||
m_dialog->obj_name->setText( QString::fromUtf8(s->getName().c_str()) );
|
||||
m_dialog->label->setText( QString::fromUtf8(s->getLabel().c_str()) );
|
||||
@ -378,15 +382,10 @@ void InterfaceDialog::validate(bool *res)
|
||||
return;
|
||||
}
|
||||
|
||||
FWObject *f = Interface::cast(obj)->getParentHost();
|
||||
|
||||
Resources* os_res = Resources::os_res[f->getStr("host_OS")];
|
||||
string os_family = f->getStr("host_OS");
|
||||
if (os_res!=NULL)
|
||||
os_family = os_res->getResourceStr("/FWBuilderResources/Target/family");
|
||||
|
||||
interfaceProperties *int_prop =
|
||||
interfacePropertiesObjectFactory::getInterfacePropertiesObject(os_family);
|
||||
interfacePropertiesObjectFactory::getInterfacePropertiesObject(
|
||||
Interface::cast(obj)->getParentHost());
|
||||
|
||||
QString err;
|
||||
if ( ! int_prop->validateInterface(obj->getParent(), obj_name, err))
|
||||
{
|
||||
@ -462,7 +461,11 @@ void InterfaceDialog::applyChanges()
|
||||
|
||||
// ticket #328: automatically assign vlan id to interface based on
|
||||
// interface name
|
||||
m_project->m_panel->om->guessSubInterfaceTypeAndAttributes(intf);
|
||||
interfaceProperties *int_prop =
|
||||
interfacePropertiesObjectFactory::getInterfacePropertiesObject(
|
||||
Interface::cast(obj)->getParentHost());
|
||||
int_prop->guessSubInterfaceTypeAndAttributes(intf);
|
||||
delete int_prop;
|
||||
|
||||
if (obj->isReadOnly()) return;
|
||||
m_project->undoStack->push(cmd.release());
|
||||
|
||||
@ -316,14 +316,9 @@ void ObjectManipulator::makeNameUnique(FWObject *target, FWObject *obj)
|
||||
FWObject *fw = target;
|
||||
while (fw && !Firewall::cast(fw)) fw = fw->getParent();
|
||||
|
||||
Resources* os_res = Resources::os_res[fw->getStr("host_OS")];
|
||||
string os_family = fw->getStr("host_OS");
|
||||
if (os_res!=NULL)
|
||||
os_family = os_res->getResourceStr("/FWBuilderResources/Target/family");
|
||||
|
||||
std::auto_ptr<interfaceProperties> int_prop(
|
||||
interfacePropertiesObjectFactory::getInterfacePropertiesObject(
|
||||
os_family));
|
||||
interfacePropertiesObjectFactory::getInterfacePropertiesObject(fw));
|
||||
|
||||
if (int_prop->looksLikeVlanInterface(obj_name)) return;
|
||||
}
|
||||
QString newname = makeNameUnique(target,
|
||||
@ -962,14 +957,8 @@ bool ObjectManipulator::validateForPaste(FWObject *target, FWObject *obj,
|
||||
|
||||
if (parent_fw && Interface::isA(obj))
|
||||
{
|
||||
Resources* os_res = Resources::os_res[parent_fw->getStr("host_OS")];
|
||||
string os_family = parent_fw->getStr("host_OS");
|
||||
if (os_res!=NULL)
|
||||
os_family = os_res->getResourceStr("/FWBuilderResources/Target/family");
|
||||
|
||||
std::auto_ptr<interfaceProperties> int_prop(
|
||||
interfacePropertiesObjectFactory::getInterfacePropertiesObject(
|
||||
os_family));
|
||||
interfacePropertiesObjectFactory::getInterfacePropertiesObject(parent_fw));
|
||||
|
||||
return int_prop->validateInterface(ta, obj, false, err);
|
||||
}
|
||||
@ -1582,58 +1571,4 @@ void ObjectManipulator::setAttributesColumnEnabled(bool)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This method tries to guess appropriate interface type and some other
|
||||
* attributes for subinterfaces.
|
||||
*/
|
||||
void ObjectManipulator::guessSubInterfaceTypeAndAttributes(Interface *intf)
|
||||
{
|
||||
Interface *parent_intf = Interface::cast(intf->getParent());
|
||||
|
||||
if (parent_intf == NULL) return;
|
||||
|
||||
FWObject *f = intf->getParentHost();
|
||||
|
||||
Resources* os_res = Resources::os_res[f->getStr("host_OS")];
|
||||
string os_family = f->getStr("host_OS");
|
||||
if (os_res!=NULL)
|
||||
os_family = os_res->getResourceStr("/FWBuilderResources/Target/family");
|
||||
|
||||
interfaceProperties *int_prop =
|
||||
interfacePropertiesObjectFactory::getInterfacePropertiesObject(
|
||||
os_family);
|
||||
QString err;
|
||||
if (int_prop->looksLikeVlanInterface(intf->getName().c_str()) &&
|
||||
int_prop->isValidVlanInterfaceName(intf->getName().c_str(),
|
||||
intf->getParent()->getName().c_str(),
|
||||
err)
|
||||
)
|
||||
{
|
||||
InterfaceData *idata = new InterfaceData(*intf);
|
||||
//int_prop->parseVlan(idata);
|
||||
idata->interface_type = "8021q";
|
||||
int_prop->parseVlan(idata->name.c_str(), NULL, &(idata->vlan_id));
|
||||
if (!idata->interface_type.empty())
|
||||
{
|
||||
intf->getOptionsObject()->setStr("type", idata->interface_type);
|
||||
if (idata->interface_type == "8021q")
|
||||
intf->getOptionsObject()->setInt("vlan_id", idata->vlan_id);
|
||||
}
|
||||
delete idata;
|
||||
} else
|
||||
{
|
||||
if (parent_intf->getOptionsObject()->getStr("type") == "bridge")
|
||||
{
|
||||
intf->getOptionsObject()->setStr("type", "ethernet");
|
||||
}
|
||||
|
||||
if (parent_intf->getOptionsObject()->getStr("type") == "bonding")
|
||||
{
|
||||
intf->getOptionsObject()->setStr("type", "ethernet");
|
||||
intf->setUnnumbered(true);
|
||||
}
|
||||
}
|
||||
|
||||
delete int_prop;
|
||||
}
|
||||
|
||||
|
||||
@ -288,8 +288,6 @@ public:
|
||||
const std::string &namesuffix);
|
||||
void autorenameVlans(std::list<libfwbuilder::FWObject*> &obj_list);
|
||||
|
||||
void guessSubInterfaceTypeAndAttributes(libfwbuilder::Interface *intf);
|
||||
|
||||
void reload();
|
||||
|
||||
void loadObjects();
|
||||
|
||||
@ -582,8 +582,14 @@ void ObjectManipulator::newInterface()
|
||||
if (new_interface == NULL) return;
|
||||
|
||||
if (Interface::isA(parent))
|
||||
guessSubInterfaceTypeAndAttributes(new_interface);
|
||||
else
|
||||
{
|
||||
interfaceProperties *int_prop =
|
||||
interfacePropertiesObjectFactory::getInterfacePropertiesObject(
|
||||
new_interface->getParentHost());
|
||||
int_prop->guessSubInterfaceTypeAndAttributes(new_interface);
|
||||
delete int_prop;
|
||||
//guessSubInterfaceTypeAndAttributes(new_interface);
|
||||
} else
|
||||
new_interface->getOptionsObject()->setStr("type", "ethernet");
|
||||
}
|
||||
|
||||
|
||||
@ -218,14 +218,9 @@ void ObjectManipulator::autorenameVlans(list<FWObject*> &obj_list)
|
||||
assert(fw);
|
||||
QString obj_name = QString::fromUtf8(obj->getName().c_str());
|
||||
|
||||
Resources* os_res = Resources::os_res[fw->getStr("host_OS")];
|
||||
string os_family = fw->getStr("host_OS");
|
||||
if (os_res!=NULL)
|
||||
os_family = os_res->getResourceStr("/FWBuilderResources/Target/family");
|
||||
|
||||
std::auto_ptr<interfaceProperties> int_prop(
|
||||
interfacePropertiesObjectFactory::getInterfacePropertiesObject(
|
||||
os_family));
|
||||
interfacePropertiesObjectFactory::getInterfacePropertiesObject(fw));
|
||||
|
||||
if (int_prop->looksLikeVlanInterface(obj_name))
|
||||
{
|
||||
// even though we only call this function if the type of
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user