!
! Extend the NetworkManager UI with two new fields for IPv6 DNS servers.
!
! Add support to validate IPv6 addresses using Qt's HostAddress class.
! Validate the new IPv6 DNS fields as well as the IPv6 gateway.
!
! Properly unset IPv6 default gateway if no enabled.
!
! Adjust the keys for resolv.conf to include the mandatory space following
! for the keys (note: it could be any white space really but we do not
! expect manual editing or anything but a blank).
!
! Mark two member function options __unused to avoid compile time warnings.
!
! I am not sure about the width and font changes in the .ui file. These
! chunks can possibly be deleted before applying the patch.
!
! Regeneration of i18n needed after patch applied.
!
! One might consider using the HostAddress class as well for IPv4 address
! validation.
!
! Submitted by: bz
! Sponsored by: The FreeBSD Foundation
! Sponsored by: iXsystems
!
Index: pc-netmanager/src/NetworkManager/networkman.ui
===================================================================
--- pc-netmanager/src/NetworkManager/networkman.ui (revision 10156)
+++ pc-netmanager/src/NetworkManager/networkman.ui (working copy)
@@ -6,7 +6,7 @@
0
0
- 658
+ 664
442
@@ -438,92 +438,7 @@
- -
-
-
- Enable IPv6 support
-
-
- true
-
-
- false
-
-
-
-
-
-
-
- 0
- 0
-
-
-
- IPv6 gateway:
-
-
- Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
-
-
- false
-
-
-
- -
-
-
-
- 0
- 0
-
-
-
-
-
-
-
-
-
- Qt::AlignHCenter
-
-
-
- -
-
-
- Qt::Horizontal
-
-
- QSizePolicy::MinimumExpanding
-
-
-
- 40
- 20
-
-
-
-
-
-
-
- -
-
-
- Qt::Vertical
-
-
- QSizePolicy::Expanding
-
-
-
- 21
- 270
-
-
-
-
- -
+
-
Misc
@@ -539,6 +454,130 @@
+ -
+
+
+ Enable IPv6 support
+
+
+ true
+
+
+ false
+
+
+
+
+ 123
+ 34
+ 311
+ 18
+
+
+
+
+ 0
+ 0
+
+
+
+
+
+
+
+
+
+ Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter
+
+
+
+
+
+ 123
+ 62
+ 311
+ 18
+
+
+
+
+
+
+ 123
+ 90
+ 311
+ 18
+
+
+
+
+
+
+ 10
+ 30
+ 111
+ 80
+
+
+
+
-
+
+
+
+ 0
+ 0
+
+
+
+ IPv6 gateway:
+
+
+ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
+
+
+ false
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ IPV6 DNS 1:
+
+
+ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ Qt::LeftToRight
+
+
+ IPv6 DNS 2:
+
+
+ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
+
+
+
+
+
+
+
@@ -718,8 +757,8 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
p, li { white-space: pre-wrap; }
-</style></head><body style=" font-family:'Bitstream Vera Sans'; font-size:10pt; font-weight:400; font-style:normal;">
-<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"></p></body></html>
+</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;">
+<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Bitstream Vera Sans'; font-size:10pt;"></p></body></html>
false
Index: pc-netmanager/src/NetworkManager/NetworkManager.pro
===================================================================
--- pc-netmanager/src/NetworkManager/NetworkManager.pro (revision 10156)
+++ pc-netmanager/src/NetworkManager/NetworkManager.pro (working copy)
@@ -3,6 +3,8 @@ LANGUAGE = C++
CONFIG += qt warn_on release
+QT += network
+
LIBS += -lpcbsd
HEADERS += networkman.h
Index: pc-netmanager/src/NetworkManager/networkman.cpp
===================================================================
--- pc-netmanager/src/NetworkManager/networkman.cpp (revision 10156)
+++ pc-netmanager/src/NetworkManager/networkman.cpp (working copy)
@@ -12,6 +12,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -75,7 +76,10 @@ void NetworkMan::Init()
// Set the slots for the advanced tab
connect(lineDNS1, SIGNAL(textChanged(const QString &)), this, SLOT(slotCheckGlobalText()) );
connect(lineDNS2, SIGNAL(textChanged(const QString &)), this, SLOT(slotCheckGlobalText()) );
+ connect(lineIPv6DNS1, SIGNAL(editingFinished()), this, SLOT(slotCheckGlobalText()) );
+ connect(lineIPv6DNS2, SIGNAL(editingFinished()), this, SLOT(slotCheckGlobalText()) );
connect(lineGateway, SIGNAL(textChanged(const QString &)), this, SLOT(slotCheckGlobalText()) );
+ connect(lineIPv6Gateway, SIGNAL(editingFinished()), this, SLOT(slotCheckGlobalText()) );
connect(lineHostname, SIGNAL(textChanged(const QString &)), this, SLOT(slotCheckGlobalText()) );
connect(linePPPUsername, SIGNAL(textChanged(const QString &)), this, SLOT(slotCheckGlobalText()) );
connect(linePPPPassword, SIGNAL(textChanged(const QString &)), this, SLOT(slotCheckGlobalText()) );
@@ -530,9 +534,12 @@ void NetworkMan::loadGlobals()
QString tmp;
lineHostname->setText(Utils::getConfFileValue("/etc/rc.conf", "hostname=", 1));
lineGateway->setText(Utils::getConfFileValue("/etc/rc.conf", "defaultrouter=", 1) );
- lineDNS1->setText(Utils::getConfFileValue("/etc/resolv.conf", "nameserver", 1) );
- lineDNS2->setText(Utils::getConfFileValue("/etc/resolv.conf", "nameserver", 2) );
- lineSearchDomain->setText(Utils::getConfFileValue("/etc/resolv.conf", "search", 1) );
+ /* Use simple regular expressions to distinguish IPv4 and IPv6 addresses. */
+ lineDNS1->setText(Utils::getConfFileValue("/etc/resolv.conf", "nameserver ", "\\b(?:\\d{1,3}\\.){3}\\d{1,3}\\b", 1) );
+ lineDNS2->setText(Utils::getConfFileValue("/etc/resolv.conf", "nameserver ", "\\b(?:\\d{1,3}\\.){3}\\d{1,3}\\b", 2) );
+ lineIPv6DNS1->setText(Utils::getConfFileValue("/etc/resolv.conf", "nameserver ", "\\b.*:.*:.*\\b", 1) );
+ lineIPv6DNS2->setText(Utils::getConfFileValue("/etc/resolv.conf", "nameserver ", "\\b.*:.*:.*\\b", 2) );
+ lineSearchDomain->setText(Utils::getConfFileValue("/etc/resolv.conf", "search ", 1) );
// Check for IPv6 settings
lineIPv6Gateway->setText(Utils::getConfFileValue("/etc/rc.conf", "ipv6_defaultrouter=", 1) );
@@ -709,7 +716,7 @@ void NetworkMan::slotSysTray()
}
-void NetworkMan::slotDoubleClick( QListWidgetItem *item )
+void NetworkMan::slotDoubleClick( QListWidgetItem *item __unused )
{
// Start the configuration dialog
PropertiesSlot();
@@ -814,7 +821,7 @@ void NetworkMan::slotTimerRefresh()
-void NetworkMan::slotListRightClick( const QPoint &pos )
+void NetworkMan::slotListRightClick( const QPoint &pos __unused )
{
int currentItem = listNetDev->currentRow();
if ( currentItem != -1 ) {
@@ -916,6 +923,8 @@ void NetworkMan::setNotRoot()
checkSysTray->setHidden(TRUE);
lineDNS1->setEnabled(FALSE);
lineDNS2->setEnabled(FALSE);
+ lineIPv6DNS1->setEnabled(FALSE);
+ lineIPv6DNS2->setEnabled(FALSE);
lineHostname->setEnabled(FALSE);
lineGateway->setEnabled(FALSE);
lineIPv6Gateway->setEnabled(FALSE);
@@ -942,6 +951,31 @@ void NetworkMan::slotCheckGlobalText()
QRegExp hostnameRegExp("^(([a-z0-9][a-z0-9-]*[a-z0-9])|([a-z0-9]+))$");
textGlobalError->setText("");
+
+ if ( groupIPv6->isChecked() ) {
+ QHostAddress addr;
+ if ( ! lineIPv6DNS1->text().isEmpty() ) {
+ if ( addr.setAddress(lineIPv6DNS1->text()) == false || addr.protocol() != QAbstractSocket::IPv6Protocol ) {
+ QMessageBox::warning( this, tr("Warning"),
+ tr("IPv6 DNS #1 (") + lineIPv6DNS1->text() + tr(") not a valid address.") );
+ return;
+ }
+ }
+ if ( ! lineIPv6DNS2->text().isEmpty() ) {
+ if ( addr.setAddress(lineIPv6DNS2->text()) == false || addr.protocol() != QAbstractSocket::IPv6Protocol ) {
+ QMessageBox::warning( this, tr("Warning"),
+ tr("IPv6 DNS #2 (") + lineIPv6DNS2->text() + tr(") not a valid address.") );
+ return;
+ }
+ }
+ if ( ! lineIPv6Gateway->text().isEmpty() ) {
+ if ( addr.setAddress(lineIPv6Gateway->text()) == false || addr.protocol() != QAbstractSocket::IPv6Protocol ) {
+ QMessageBox::warning( this, tr("Warning"),
+ tr("IPv6 gateway (") + lineIPv6Gateway->text() + tr(") not a valid address.") );
+ return;
+ }
+ }
+ }
if ( lineDNS1->text() != "..." && ! checkRange(lineDNS1->text() ) ) {
QMessageBox::warning( this, tr("Warning"),
@@ -1022,6 +1056,17 @@ void NetworkMan::slotSave()
int DNSline = 1;
+ /* Prefer IPv6 nameservers if IPv6 is enabled. */
+ if ( groupIPv6->isChecked() ) {
+ if ( ! lineIPv6DNS1->text().isEmpty() ) {
+ Utils::setConfFileValue("/etc/resolv.conf", "nameserver", "nameserver " + lineIPv6DNS1->text(), DNSline);
+ DNSline++;
+ }
+ if ( ! lineIPv6DNS2->text().isEmpty() ) {
+ Utils::setConfFileValue("/etc/resolv.conf", "nameserver", "nameserver " + lineIPv6DNS2->text(), DNSline);
+ DNSline++;
+ }
+ }
if ( lineDNS1->text() == "..." ) {
Utils::setConfFileValue("/etc/resolv.conf", "nameserver", "", DNSline);
@@ -1050,7 +1095,11 @@ void NetworkMan::slotSave()
// Save the IPv6 stuff
if ( groupIPv6->isChecked() ) {
Utils::setConfFileValue("/etc/rc.conf", "ipv6_activate_all_interfaces=", "ipv6_activate_all_interfaces=\"YES\"", -1);
- Utils::setConfFileValue("/etc/rc.conf", "ipv6_defaultrouter=", "ipv6_defaultrouter=\"" + lineIPv6Gateway->text() + "\"", -1);
+ if ( ! lineIPv6Gateway->text().isEmpty() ) {
+ Utils::setConfFileValue("/etc/rc.conf", "ipv6_defaultrouter=", "ipv6_defaultrouter=\"" + lineIPv6Gateway->text() + "\"", -1);
+ } else {
+ Utils::setConfFileValue("/etc/rc.conf", "ipv6_defaultrouter=", "", -1);
+ }
} else {
Utils::setConfFileValue("/etc/rc.conf", "ipv6_activate_all_interfaces=", "", -1);
Utils::setConfFileValue("/etc/rc.conf", "ipv6_defaultrouter=", "", -1);