|
@@ -1,3 +1,4 @@
|
|
|
+#include <signal.h>
|
|
|
#include "netinterfaces.h"
|
|
|
#include "../debug.h"
|
|
|
|
|
@@ -62,24 +63,28 @@ static bool _IsValidNetmask(const struct in_addr &in)
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
-NetInterfaces::NetInterfaces(QObject *pParent) : QObject(pParent)
|
|
|
+NetInterfaces::NetInterfaces(QObject *pParent) : QObject(pParent),
|
|
|
+ m_itfFilterAF(Interface::AF_Unknown),
|
|
|
+ m_itfFilterMethod(Interface::IM_Unknown),
|
|
|
+ m_bIfUpDownInProgress(false),
|
|
|
+ m_ifUpDownPid(-1)
|
|
|
{
|
|
|
setObjectName("NetInterfaces");
|
|
|
- m_itfFilterAF = Interface::AF_Unknown;
|
|
|
- m_itfFilterMethod = Interface::IM_Unknown;
|
|
|
+ m_mutex.Create(true);
|
|
|
m_itfFilterName.clear();
|
|
|
}
|
|
|
|
|
|
NetInterfaces::~NetInterfaces(void)
|
|
|
{
|
|
|
reset();
|
|
|
+ m_mutex.Release();
|
|
|
}
|
|
|
|
|
|
void NetInterfaces::classBegin()
|
|
|
{
|
|
|
if(!initialize())
|
|
|
{
|
|
|
- emitError("NetInterfaces::initialize failed!");
|
|
|
+ reportError("NetInterfaces::initialize failed!");
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -112,7 +117,7 @@ bool NetInterfaces::initialize(void)
|
|
|
for(auto it = m_eni.ibl.begin(); it != m_eni.ibl.end(); it++)
|
|
|
{
|
|
|
ITF_IFACE_BLOCK &ibl = *it;
|
|
|
- m_interfaces.append(new Interface(ibl, static_cast<const NotificationSink&>(*this), this));
|
|
|
+ m_interfaces.append(new Interface(ibl, static_cast<NotificationSink&>(*this), this));
|
|
|
}
|
|
|
|
|
|
emit interfacesChanged();
|
|
@@ -136,13 +141,15 @@ bool NetInterfaces::saveAs(const QString &path)
|
|
|
return ::WriteEtcNetworkInterfaces(m_eni, pszPath);
|
|
|
}
|
|
|
|
|
|
-void NetInterfaces::emitError(const char *pszFormatStr, ...) const
|
|
|
+void NetInterfaces::reportError(const char *pszFormatStr, ...)
|
|
|
{
|
|
|
va_list args;
|
|
|
va_start(args, pszFormatStr);
|
|
|
QString qs = QString::vasprintf(pszFormatStr, args);
|
|
|
va_end (args);
|
|
|
+ m_mutex.Lock();
|
|
|
emit error(qs);
|
|
|
+ m_mutex.Unlock();
|
|
|
}
|
|
|
|
|
|
void NetInterfaces::filterPropertyChanged(void) const
|
|
@@ -150,23 +157,40 @@ void NetInterfaces::filterPropertyChanged(void) const
|
|
|
emit filteredInterfacesChanged();
|
|
|
}
|
|
|
|
|
|
+void NetInterfaces::selConfigChanged(Interface* pi, unsigned int cfgOld, unsigned int cfgNew)
|
|
|
+{
|
|
|
+ unsigned long id = pi->getID();
|
|
|
+ unsigned int diff = cfgOld ^ cfgNew;
|
|
|
+ unsigned int add = cfgNew & diff;
|
|
|
+ unsigned int rem = cfgOld & diff;
|
|
|
+
|
|
|
+ for(int mask = Interface::SC_Auto; mask < Interface::SC_Invalid; mask <<= 1)
|
|
|
+ {
|
|
|
+ if(add & mask)
|
|
|
+ ::AddInterfaceToCfgGroup(m_eni, id, (CfgGroup)_FLAG_TO_ENUM(mask));
|
|
|
+
|
|
|
+ if(rem & mask)
|
|
|
+ ::RemoveInterfaceFromCfgGroup(m_eni, id, (CfgGroup)_FLAG_TO_ENUM(mask));
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
Interface* NetInterfaces::newInterface(QString name, int af, int method)
|
|
|
{
|
|
|
if(name.isNull() || name.isEmpty())
|
|
|
{
|
|
|
- emitError("Invalid or empty interface name!");
|
|
|
+ reportError("Invalid or empty interface name!");
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
if(!_IsPowerOf2(af) || (af <= Interface::AF_Unknown) || (af >= Interface::AF_Invalid))
|
|
|
{
|
|
|
- emitError("Invalid address family: %d!", af);
|
|
|
+ reportError("Invalid address family: %d!", af);
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
if(!_IsPowerOf2(method) || (method <= Interface::IM_Unknown) || (method >= Interface::IM_Invalid))
|
|
|
{
|
|
|
- emitError("Invalid method: %d!", method);
|
|
|
+ reportError("Invalid method: %d!", method);
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
@@ -175,7 +199,7 @@ Interface* NetInterfaces::newInterface(QString name, int af, int method)
|
|
|
rib.cfgName = name.toStdString();
|
|
|
rib.proto = (IfaceProtos)_FLAG_TO_ENUM(af);
|
|
|
rib.method = (IfaceMethods)_FLAG_TO_ENUM(method);
|
|
|
- Interface *pi = new Interface(rib, static_cast<const NotificationSink&>(*this), this);
|
|
|
+ Interface *pi = new Interface(rib, static_cast<NotificationSink&>(*this), this);
|
|
|
m_interfaces.append(pi);
|
|
|
emit interfacesChanged();
|
|
|
emit filteredInterfacesChanged();
|
|
@@ -186,11 +210,21 @@ void NetInterfaces::removeInterface(Interface *pi)
|
|
|
{
|
|
|
if(!pi)
|
|
|
{
|
|
|
- emitError("%s: Attempt to remove invalid interface!", __FUNCTION__);
|
|
|
+ reportError("NetInterfaces::removeInterface: An attempt was made to remove an invalid interface!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ m_mutex.Lock();
|
|
|
+ if(GetIfUpDownInProgress())
|
|
|
+ {
|
|
|
+ m_mutex.Unlock();
|
|
|
+ reportError("NetInterfaces::removeInterface: Interface start/stop in progress! Please try again later!");
|
|
|
return;
|
|
|
}
|
|
|
+ m_mutex.Unlock();
|
|
|
|
|
|
- unsigned long id = pi->getID();
|
|
|
+ unsigned long id = pi->getID();
|
|
|
+ int selCfg = pi->getSelCfg();
|
|
|
|
|
|
for(int i = 0; i < m_interfaces.count(); i++)
|
|
|
{
|
|
@@ -202,12 +236,227 @@ void NetInterfaces::removeInterface(Interface *pi)
|
|
|
emit interfacesChanged();
|
|
|
emit filteredInterfacesChanged();
|
|
|
delete pil;
|
|
|
+
|
|
|
+ for(int mask = Interface::SC_Auto; mask < Interface::SC_Invalid; mask <<= 1)
|
|
|
+ {
|
|
|
+ if(selCfg & mask)
|
|
|
+ ::RemoveInterfaceFromCfgGroup(m_eni, id, (CfgGroup)_FLAG_TO_ENUM(mask));
|
|
|
+ }
|
|
|
+
|
|
|
::RemoveInterfaceBlock(m_eni, id);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+bool NetInterfaces::SetInterlockedIfUpDownInProgress(void)
|
|
|
+{
|
|
|
+ m_mutex.Lock();
|
|
|
+ if(m_bIfUpDownInProgress)
|
|
|
+ {
|
|
|
+ m_mutex.Unlock();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ m_bIfUpDownInProgress = true;
|
|
|
+ m_mutex.Unlock();
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+void NetInterfaces::onIfUpDown(const char *pszMsg, void *pCtx)
|
|
|
+{
|
|
|
+ if(pCtx)
|
|
|
+ {
|
|
|
+ NetInterfaces *pThis = static_cast<NetInterfaces*>(pCtx);
|
|
|
+ pThis->m_mutex.Lock();
|
|
|
+ emit pThis->ifUpDown(pszMsg);
|
|
|
+ pThis->m_mutex.Unlock();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void NetInterfaces::onIfUpCompleted(int nExitCode, void *pCtx)
|
|
|
+{
|
|
|
+ if(pCtx)
|
|
|
+ {
|
|
|
+ LPIF_UPDOWN_CONTEXT piudc = static_cast<LPIF_UPDOWN_CONTEXT>(pCtx);
|
|
|
+ piudc->pThis->m_mutex.Lock();
|
|
|
+ emit piudc->pThis->ifUpDownCompleted(piudc->ctx, nExitCode);
|
|
|
+ piudc->pThis->SetIfUpDownInProgress(false);
|
|
|
+ piudc->pThis->SetIfUpDownPid(-1);
|
|
|
+ piudc->pThis->m_mutex.Unlock();
|
|
|
+ delete piudc;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void NetInterfaces::onIfDownCompleted(int nExitCode, void *pCtx)
|
|
|
+{
|
|
|
+ if(pCtx)
|
|
|
+ {
|
|
|
+ LPIF_UPDOWN_CONTEXT piudc = static_cast<LPIF_UPDOWN_CONTEXT>(pCtx);
|
|
|
+ piudc->pThis->m_mutex.Lock();
|
|
|
+ emit piudc->pThis->ifUpDownCompleted(piudc->ctx, nExitCode);
|
|
|
+ piudc->pThis->SetIfUpDownInProgress(false);
|
|
|
+ piudc->pThis->SetIfUpDownPid(-1);
|
|
|
+ piudc->pThis->m_mutex.Unlock();
|
|
|
+ delete piudc;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void NetInterfaces::onIfRestartCompleted(int nExitCode, void *pCtx)
|
|
|
+{
|
|
|
+ if(pCtx)
|
|
|
+ {
|
|
|
+ LPIF_UPDOWN_CONTEXT piudc = static_cast<LPIF_UPDOWN_CONTEXT>(pCtx);
|
|
|
+
|
|
|
+ if(piudc->ctx == UDC_Stop && !nExitCode) // ifdown succeeded
|
|
|
+ {
|
|
|
+ int nRet;
|
|
|
+ piudc->ctx = UDC_Start;
|
|
|
+
|
|
|
+ if((nRet = ::IfUpAsync(piudc->pi->getName(), piudc->pThis->m_ifUpDownPid, &NetInterfaces::onIfRestartCompleted, static_cast<void*>(piudc), &NetInterfaces::onIfUpDown, static_cast<void*>(piudc->pThis))))
|
|
|
+ {
|
|
|
+ piudc->pThis->m_mutex.Lock();
|
|
|
+ piudc->pThis->reportError("NetInterfaces::onIfRestartCompleted: IfUpAsync failed with code: %d", nRet);
|
|
|
+ emit piudc->pThis->ifUpDownCompleted(UDC_Restart, nRet);
|
|
|
+ piudc->pThis->SetIfUpDownPid(-1);
|
|
|
+ piudc->pThis->SetIfUpDownInProgress(false);
|
|
|
+ piudc->pThis->m_mutex.Unlock();
|
|
|
+ delete piudc;
|
|
|
+ }
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ piudc->pThis->m_mutex.Lock();
|
|
|
+ emit piudc->pThis->ifUpDownCompleted(UDC_Restart, nExitCode);
|
|
|
+ piudc->pThis->SetIfUpDownPid(-1);
|
|
|
+ piudc->pThis->SetIfUpDownInProgress(false);
|
|
|
+ piudc->pThis->m_mutex.Unlock();
|
|
|
+ delete piudc;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+bool NetInterfaces::startInterface(Interface *pi)
|
|
|
+{
|
|
|
+ if(!pi)
|
|
|
+ {
|
|
|
+ reportError("NetInterfaces::stopInterface: Invalid interface!");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ int nRet;
|
|
|
+
|
|
|
+ if(!SetInterlockedIfUpDownInProgress())
|
|
|
+ {
|
|
|
+ reportError("NetInterfaces::startInterface: IfUp/Down already in progress!");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ LPIF_UPDOWN_CONTEXT piudc = new IF_UPDOWN_CONTEXT;
|
|
|
+ piudc->pThis = this;
|
|
|
+ piudc->pi = pi;
|
|
|
+ piudc->ctx = UDC_Start;
|
|
|
+
|
|
|
+ if((nRet = ::IfUpAsync(pi->getName(), m_ifUpDownPid, &NetInterfaces::onIfUpCompleted, static_cast<void*>(piudc), &NetInterfaces::onIfUpDown, static_cast<void*>(this))))
|
|
|
+ {
|
|
|
+ m_mutex.Lock();
|
|
|
+ reportError("NetInterfaces::startInterface: IfUpAsync failed with code: %d", nRet);
|
|
|
+ emit ifUpDownCompleted(UDC_Start, -3);
|
|
|
+ SetIfUpDownInProgress(false);
|
|
|
+ SetIfUpDownPid(-1);
|
|
|
+ m_mutex.Unlock();
|
|
|
+ delete piudc;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+bool NetInterfaces::stopInterface(Interface *pi)
|
|
|
+{
|
|
|
+ if(!pi)
|
|
|
+ {
|
|
|
+ reportError("NetInterfaces::stopInterface: Invalid interface!");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ int nRet;
|
|
|
+
|
|
|
+ if(!SetInterlockedIfUpDownInProgress())
|
|
|
+ {
|
|
|
+ reportError("NetInterfaces::stopInterface: IfUp/Down already in progress!");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ LPIF_UPDOWN_CONTEXT piudc = new IF_UPDOWN_CONTEXT;
|
|
|
+ piudc->pThis = this;
|
|
|
+ piudc->pi = pi;
|
|
|
+ piudc->ctx = UDC_Stop;
|
|
|
+
|
|
|
+ if((nRet = ::IfDownAsync(pi->getName(), m_ifUpDownPid, &NetInterfaces::onIfDownCompleted, static_cast<void*>(piudc), &NetInterfaces::onIfUpDown, static_cast<void*>(this))))
|
|
|
+ {
|
|
|
+ m_mutex.Lock();
|
|
|
+ reportError("NetInterfaces::stopInterface: IfDownAsync failed with code: %d", nRet);
|
|
|
+ emit ifUpDownCompleted(UDC_Stop, -3);
|
|
|
+ SetIfUpDownInProgress(false);
|
|
|
+ SetIfUpDownPid(-1);
|
|
|
+ m_mutex.Unlock();
|
|
|
+ delete piudc;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+bool NetInterfaces::restartInterface(Interface *pi)
|
|
|
+{
|
|
|
+ if(!pi)
|
|
|
+ {
|
|
|
+ reportError("NetInterfaces::restartInterface: Invalid interface!");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ int nRet;
|
|
|
+
|
|
|
+ if(!SetInterlockedIfUpDownInProgress())
|
|
|
+ {
|
|
|
+ reportError("NetInterfaces::restartInterface: IfUp/Down already in progress!");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ LPIF_UPDOWN_CONTEXT piudc = new IF_UPDOWN_CONTEXT;
|
|
|
+ piudc->pThis = this;
|
|
|
+ piudc->pi = pi;
|
|
|
+ piudc->ctx = UDC_Stop;
|
|
|
+
|
|
|
+ if((nRet = ::IfDownAsync(pi->getName(), m_ifUpDownPid, &NetInterfaces::onIfRestartCompleted, static_cast<void*>(piudc), &NetInterfaces::onIfUpDown, static_cast<void*>(this))))
|
|
|
+ {
|
|
|
+ m_mutex.Lock();
|
|
|
+ reportError("NetInterfaces::restartInterface: IfDownAsync failed with code: %d", nRet);
|
|
|
+ emit ifUpDownCompleted(UDC_Restart, -3);
|
|
|
+ SetIfUpDownInProgress(false);
|
|
|
+ SetIfUpDownPid(-1);
|
|
|
+ m_mutex.Unlock();
|
|
|
+ delete piudc;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+bool NetInterfaces::cancelStartStopInterface(void)
|
|
|
+{
|
|
|
+ m_mutex.Lock();
|
|
|
+ pid_t pid = GetIfUpDownPid();
|
|
|
+ bool bCancel = GetIfUpDownInProgress() && (pid != -1);
|
|
|
+ if(bCancel)
|
|
|
+ {
|
|
|
+// bCancel = !kill(-pid, SIGKILL);
|
|
|
+ bCancel = !system("killall -SIGTERM ifup");
|
|
|
+ }
|
|
|
+ m_mutex.Unlock();
|
|
|
+ return bCancel;
|
|
|
+}
|
|
|
+
|
|
|
QQmlListProperty<Interface> NetInterfaces::interfaces(void)
|
|
|
{
|
|
|
return QQmlListProperty<Interface>(this, m_interfaces);
|
|
@@ -260,7 +509,7 @@ void NetInterfaces::setItfFilterAF(int af)
|
|
|
|
|
|
if(af < Interface::AF_Unknown || af >= Interface::AF_Invalid)
|
|
|
{
|
|
|
- emitError("Invalid address family filter: %d!", af);
|
|
|
+ reportError("Invalid address family filter: %d!", af);
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -279,11 +528,9 @@ int NetInterfaces::itfFilterMethod(void) const
|
|
|
|
|
|
void NetInterfaces::setItfFilterMethod(int method)
|
|
|
{
|
|
|
-
|
|
|
-
|
|
|
if(method < Interface::IM_Unknown || method >= Interface::IM_Invalid)
|
|
|
{
|
|
|
- emitError("Invalid method filter: %d!", method);
|
|
|
+ reportError("Invalid method filter: %d!", method);
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -295,12 +542,35 @@ void NetInterfaces::setItfFilterMethod(int method)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+int NetInterfaces::getInterfaceSelConfig(Interface &ri)
|
|
|
+{
|
|
|
+ int mask = 0;
|
|
|
+
|
|
|
+ ::EnumInterfaceCfgGroups(m_eni, ri.getID(),
|
|
|
+ [] (CfgGroup cg, void *pCtx) -> void
|
|
|
+ {
|
|
|
+ if(cg > CG_Unknown)
|
|
|
+ {
|
|
|
+ int *m = (int*)pCtx;
|
|
|
+ *m |= _ENUM_TO_FLAG(cg);
|
|
|
+ }
|
|
|
+ }, &mask);
|
|
|
+
|
|
|
+ return mask;
|
|
|
+}
|
|
|
+
|
|
|
+bool NetInterfaces::ifUpDownInProgress(void) const
|
|
|
+{
|
|
|
+ return m_bIfUpDownInProgress;
|
|
|
+}
|
|
|
+
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
-Interface::Interface(ITF_IFACE_BLOCK &ifb, const NotificationSink ¬ifyer, QObject *pParent) : QObject(pParent),
|
|
|
- m_ifb(ifb),
|
|
|
- m_inet(ifb, notifyer, this),
|
|
|
- m_rNotifyer(notifyer)
|
|
|
+Interface::Interface(ITF_IFACE_BLOCK &ifb, NotificationSink ¬ifyer, QObject *pParent) : QObject(pParent),
|
|
|
+ m_ifb(ifb),
|
|
|
+ m_inet(ifb, notifyer, this),
|
|
|
+ m_rNotifyer(notifyer),
|
|
|
+ m_selCfg(notifyer.getInterfaceSelConfig(*this))
|
|
|
{
|
|
|
setObjectName("Interface");
|
|
|
}
|
|
@@ -328,7 +598,7 @@ void Interface::setAf(int af)
|
|
|
{
|
|
|
if(!_IsPowerOf2(af) || (af < Interface::AF_Unknown) || (af >= Interface::AF_Invalid))
|
|
|
{
|
|
|
- m_rNotifyer.emitError("Invalid address family: %d!", af);
|
|
|
+ m_rNotifyer.reportError("Invalid address family: %d!", af);
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -357,7 +627,7 @@ void Interface::setMethod(int method)
|
|
|
{
|
|
|
if(!_IsPowerOf2(method) || (method < Interface::IM_Unknown) || (method >= Interface::IM_Invalid))
|
|
|
{
|
|
|
- m_rNotifyer.emitError("Invalid interface method: %d!", method);
|
|
|
+ m_rNotifyer.reportError("Invalid interface method: %d!", method);
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -372,6 +642,28 @@ void Interface::setMethod(int method)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+int Interface::selCfg(void) const
|
|
|
+{
|
|
|
+ return m_selCfg;
|
|
|
+}
|
|
|
+
|
|
|
+void Interface::setSelCfg(int cfg)
|
|
|
+{
|
|
|
+ if(cfg < SC_None || cfg >= SC_Invalid)
|
|
|
+ {
|
|
|
+ m_rNotifyer.reportError("Invalid start/selection configuration: 0x%X!", cfg);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(m_selCfg != cfg)
|
|
|
+ {
|
|
|
+ m_rNotifyer.selConfigChanged(this, m_selCfg, cfg);
|
|
|
+ m_selCfg = cfg;
|
|
|
+ emit selCfgChanged(cfg);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
Inet* Interface::inet(void)
|
|
|
{
|
|
|
return &m_inet;
|
|
@@ -379,10 +671,10 @@ Inet* Interface::inet(void)
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
-Inet::Inet(ITF_IFACE_BLOCK &ifb, const NotificationSink ¬ifyer, QObject *pParent) : QObject(pParent),
|
|
|
- m_static(ifb.inet4s, notifyer, this),
|
|
|
- m_dhcp(ifb.inet4d, notifyer, this),
|
|
|
- m_rNotifyer(notifyer)
|
|
|
+Inet::Inet(ITF_IFACE_BLOCK &ifb, NotificationSink ¬ifyer, QObject *pParent) : QObject(pParent),
|
|
|
+ m_static(ifb.inet4s, notifyer, this),
|
|
|
+ m_dhcp(ifb.inet4d, notifyer, this),
|
|
|
+ m_rNotifyer(notifyer)
|
|
|
{
|
|
|
setObjectName("Inet");
|
|
|
}
|
|
@@ -403,14 +695,14 @@ Dhcp* Inet::dhcp(void)
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
-Static::Static(IFACE_INET_STATIC &itfs, const NotificationSink ¬ifyer, QObject *pParent) : QObject(pParent),
|
|
|
- m_itfs(itfs),
|
|
|
- m_rNotifyer(notifyer),
|
|
|
- m_ipAddr(itfs.addr, notifyer, this),
|
|
|
- m_netmask(itfs.netmask, notifyer, this, _IsValidNetmask),
|
|
|
- m_gateway(itfs.gate, notifyer, this),
|
|
|
- m_bcastAddr(itfs.bcast, notifyer, this),
|
|
|
- m_ptpAddr(itfs.pointopoint, notifyer, this)
|
|
|
+Static::Static(IFACE_INET_STATIC &itfs, NotificationSink ¬ifyer, QObject *pParent) : QObject(pParent),
|
|
|
+ m_itfs(itfs),
|
|
|
+ m_rNotifyer(notifyer),
|
|
|
+ m_ipAddr(itfs.addr, notifyer, this),
|
|
|
+ m_netmask(itfs.netmask, notifyer, this, _IsValidNetmask),
|
|
|
+ m_gateway(itfs.gate, notifyer, this),
|
|
|
+ m_bcastAddr(itfs.bcast, notifyer, this),
|
|
|
+ m_ptpAddr(itfs.pointopoint, notifyer, this)
|
|
|
{
|
|
|
setObjectName("Static");
|
|
|
for(size_t i = 0; i < _countof(m_itfs.namesvr); i++)
|
|
@@ -418,7 +710,7 @@ Static::Static(IFACE_INET_STATIC &itfs, const NotificationSink ¬ifyer, QObjec
|
|
|
IPv4Address *addr = new IPv4Address(m_itfs.namesvr[i], notifyer, this);
|
|
|
m_dnsList.append(addr);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
QObject::connect(&m_netmask, SIGNAL(addressChanged(const QString&)), this, SLOT(netmaskChanged(const QString&)));
|
|
|
}
|
|
|
|
|
@@ -500,7 +792,7 @@ void Static::setNetPrefix(int netprefix)
|
|
|
{
|
|
|
if(netprefix < 0 || netprefix > 32)
|
|
|
{
|
|
|
- m_rNotifyer.emitError("Invalid net prefix: %d!", netprefix);
|
|
|
+ m_rNotifyer.reportError("Invalid net prefix: %d!", netprefix);
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -525,14 +817,14 @@ void Static::netmaskChanged(const QString &mask)
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- m_rNotifyer.emitError("Invalid net mask: %s!", sa.c_str());
|
|
|
+ m_rNotifyer.reportError("Invalid net mask: %s!", sa.c_str());
|
|
|
m_netmask.setProperty("address", QVariant("255.255.255.0"));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
-Dhcp::Dhcp(IFACE_INET_DHCP &itfd, const NotificationSink ¬ifyer, QObject *pParent) : QObject(pParent), m_itfd(itfd), m_rNotifyer(notifyer)
|
|
|
+Dhcp::Dhcp(IFACE_INET_DHCP &itfd, NotificationSink ¬ifyer, QObject *pParent) : QObject(pParent), m_itfd(itfd), m_rNotifyer(notifyer)
|
|
|
{
|
|
|
setObjectName("Dhcp");
|
|
|
}
|
|
@@ -543,10 +835,10 @@ Dhcp::~Dhcp(void)
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
-IPv4Address::IPv4Address(struct in_addr &addr, const NotificationSink ¬ifyer, QObject *pParent, PFN_ADDRESS_VALIDATOR pfnAddrValidator) : QObject(pParent),
|
|
|
- m_addr(addr),
|
|
|
- m_pfnAddrValidator(pfnAddrValidator),
|
|
|
- m_rNotifyer(notifyer)
|
|
|
+IPv4Address::IPv4Address(struct in_addr &addr, NotificationSink ¬ifyer, QObject *pParent, PFN_ADDRESS_VALIDATOR pfnAddrValidator) : QObject(pParent),
|
|
|
+ m_addr(addr),
|
|
|
+ m_pfnAddrValidator(pfnAddrValidator),
|
|
|
+ m_rNotifyer(notifyer)
|
|
|
{
|
|
|
setObjectName("IPv4Address");
|
|
|
}
|
|
@@ -591,13 +883,13 @@ void IPv4Address::setAddress(const QString &addr)
|
|
|
|
|
|
if(!inet_aton(sa.c_str(), &newAddr))
|
|
|
{
|
|
|
- m_rNotifyer.emitError("Invalid IP address: '%s'!", sa.c_str());
|
|
|
+ m_rNotifyer.reportError("Invalid IP address: '%s'!", sa.c_str());
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if(m_pfnAddrValidator && !(*m_pfnAddrValidator)(newAddr))
|
|
|
{
|
|
|
- m_rNotifyer.emitError("Invalid address: '%s'!", sa.c_str());
|
|
|
+ m_rNotifyer.reportError("Invalid address: '%s'!", sa.c_str());
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -625,7 +917,7 @@ void IPv4Address::setB0(int b)
|
|
|
unsigned char *pb = (unsigned char*)&m_addr.s_addr;
|
|
|
if(!_IS_VALID_BYTE_VALUE(b))
|
|
|
{
|
|
|
- m_rNotifyer.emitError("Invalid IP address byte 0: '%d'!", b);
|
|
|
+ m_rNotifyer.reportError("Invalid IP address byte 0: '%d'!", b);
|
|
|
return;
|
|
|
}
|
|
|
if(b == (int)pb[0])
|
|
@@ -640,7 +932,7 @@ void IPv4Address::setB1(int b)
|
|
|
unsigned char *pb = (unsigned char*)&m_addr.s_addr;
|
|
|
if(!_IS_VALID_BYTE_VALUE(b))
|
|
|
{
|
|
|
- m_rNotifyer.emitError("Invalid IP address byte 1: '%d'!", b);
|
|
|
+ m_rNotifyer.reportError("Invalid IP address byte 1: '%d'!", b);
|
|
|
return;
|
|
|
}
|
|
|
if(b == (int)pb[1])
|
|
@@ -655,7 +947,7 @@ void IPv4Address::setB2(int b)
|
|
|
unsigned char *pb = (unsigned char*)&m_addr.s_addr;
|
|
|
if(!_IS_VALID_BYTE_VALUE(b))
|
|
|
{
|
|
|
- m_rNotifyer.emitError("Invalid IP address byte 2: '%d'!", b);
|
|
|
+ m_rNotifyer.reportError("Invalid IP address byte 2: '%d'!", b);
|
|
|
return;
|
|
|
}
|
|
|
if(b == (int)pb[2])
|
|
@@ -670,7 +962,7 @@ void IPv4Address::setB3(int b)
|
|
|
unsigned char *pb = (unsigned char*)&m_addr.s_addr;
|
|
|
if(!_IS_VALID_BYTE_VALUE(b))
|
|
|
{
|
|
|
- m_rNotifyer.emitError("Invalid IP address byte 3: '%d'!", b);
|
|
|
+ m_rNotifyer.reportError("Invalid IP address byte 3: '%d'!", b);
|
|
|
return;
|
|
|
}
|
|
|
if(b == (int)pb[3])
|