1
0
mirror of https://github.com/fwbuilder/fwbuilder synced 2026-05-10 19:14:57 +02:00

feat: Allow entering IPv6 into AddressRangeDialog

This commit is contained in:
Sirius Bakke
2020-10-08 23:35:35 +02:00
parent 17b6279e22
commit cbfcb387a8
4 changed files with 107 additions and 27 deletions

View File

@@ -605,6 +605,9 @@ void Compiler::_expandAddressRanges(Rule *rule, FWObject *re)
{
if (MatchesAddressFamily(o))
{
if (aro->isV6()) {
cl.push_back(o);
} else {
InetAddr a1 = aro->getRangeStart();
InetAddr a2 = aro->getRangeEnd();
vector<InetAddrMask> vn =
@@ -635,6 +638,7 @@ void Compiler::_expandAddressRanges(Rule *rule, FWObject *re)
}
}
}
}
} else
{
cl.push_back(o);

View File

@@ -34,6 +34,8 @@
#include "fwbuilder/Library.h"
#include "fwbuilder/AddressRange.h"
#include "fwbuilder/FWException.h"
#include "fwbuilder/InetAddrMask.h"
#include "fwbuilder/Inet6AddrMask.h"
#include <qlineedit.h>
#include <qspinbox.h>
@@ -171,6 +173,43 @@ void AddressRangeDialog::applyChanges()
}
void AddressRangeDialog::addressEntered()
{
try
{
QString addrStr = m_dialog->rangeStart->text();
InetAddr rangeStartAddress(AF_UNSPEC, addrStr.toStdString());
if (addrStr.contains('/'))
{
unique_ptr<InetAddrMask> address_and_mask = nullptr;
if (rangeStartAddress.isV4()) {
address_and_mask.reset(new InetAddrMask(addrStr.toStdString()));
} else if (rangeStartAddress.isV6()) {
address_and_mask.reset(new Inet6AddrMask(addrStr.toStdString()));
}
m_dialog->rangeStart->setText(
address_and_mask->getFirstHostPtr()->toString().c_str());
m_dialog->rangeEnd->setText(
address_and_mask->getLastHostPtr()->toString().c_str());
} else {
InetAddr rangeEndAddress(AF_UNSPEC, m_dialog->rangeEnd->text().toStdString());
if (rangeEndAddress.addressFamily() != rangeStartAddress.addressFamily()) {
m_dialog->rangeEnd->setText(m_dialog->rangeStart->text());
}
}
} catch (FWException &ex)
{
// exception thrown if user types illegal m_dialog->rangeStart do
// not show error dialog. This method is called by
// editingFinished signal and therefore is invoked when user
// switches focus from the address input widget to some other
// widget or even when user switches to another application to
// look up the address. Error dialog interrupts the workflow
// in the latter case which is annoying.
}
}

View File

@@ -50,6 +50,7 @@ public slots:
virtual void applyChanges();
virtual void loadFWObject(libfwbuilder::FWObject *obj);
virtual void validate(bool*);
virtual void addressEntered();
};
#endif // ADDRESSRANGEDIALOG_H

View File

@@ -172,5 +172,41 @@
<resources>
<include location="MainRes.qrc"/>
</resources>
<connections/>
<connections>
<connection>
<sender>rangeStart</sender>
<signal>editingFinished()</signal>
<receiver>AddressRangeDialog_q</receiver>
<slot>addressEntered()</slot>
<hints>
<hint type="sourcelabel">
<x>220</x>
<y>69</y>
</hint>
<hint type="destinationlabel">
<x>364</x>
<y>123</y>
</hint>
</hints>
</connection>
<connection>
<sender>rangeStart</sender>
<signal>returnPressed()</signal>
<receiver>AddressRangeDialog_q</receiver>
<slot>addressEntered()</slot>
<hints>
<hint type="sourcelabel">
<x>220</x>
<y>69</y>
</hint>
<hint type="destinationlabel">
<x>364</x>
<y>123</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>addressEntered()</slot>
</slots>
</ui>