diff options
Diffstat (limited to 'src/networkdiscovery.cpp')
-rw-r--r-- | src/networkdiscovery.cpp | 106 |
1 files changed, 60 insertions, 46 deletions
diff --git a/src/networkdiscovery.cpp b/src/networkdiscovery.cpp index aba01b8..9361887 100644 --- a/src/networkdiscovery.cpp +++ b/src/networkdiscovery.cpp @@ -20,7 +20,8 @@ NetworkDiscovery::NetworkDiscovery(QObject *parent) { * destructor */ NetworkDiscovery::~NetworkDiscovery() { - + delete _networkManager; + delete _server; } @@ -56,12 +57,22 @@ void NetworkDiscovery::initAndRun(QString serverIp, bool userChoice, bool autoUp _userChoice = userChoice; _autoUp = autoUp; _pathToLogFile = pathToLogFile; + _serverPath = serverPath; _pathToDhcpcdExe = pathToExe; _blocked = false; _numberOfProcesses = 0; _ifUpCountdown = 10; + _networkManager = new NetworkManager(); + _clientProcessToIfNameMap.clear(); + _clients.clear(); + _dhcpcdArguments.clear(); + _ifDownList.clear(); + _ifNameToClient.clear(); + _ifUpList.clear(); + _ifcMap.clear(); + _server = new QLocalServer(); if (serverPath != DEFAULT_QTSOCKETADDRESS) { _dhcpcdArguments.append("-q"); @@ -85,6 +96,8 @@ void NetworkDiscovery::initAndRun(QString serverIp, bool userChoice, bool autoUp return; } + killDHCPCD(); + // check if the path to the customdhcpcd file is correct emit updateStatus("check if cdhcpcd is available"); QFileInfo fInfo(_pathToDhcpcdExe); @@ -166,7 +179,7 @@ void NetworkDiscovery::getListOfNetworkInterfacesWithAutoUp() { _ifUpList.append(nI.humanReadableName()); } else if (!(nI.flags() & QNetworkInterface::IsUp)) { - _networkManager.bringInterfaceUP(nI.humanReadableName()); + _networkManager->bringInterfaceUP(nI.humanReadableName()); qxtLog->debug() << _tag << " bring up: " << nI.humanReadableName() ; _ifDownList.append(nI.humanReadableName()); } @@ -367,18 +380,30 @@ void NetworkDiscovery::handleProcessFinished(int exitCode, _numberOfProcesses = _numberOfProcesses - 1; if (!_blocked) { //_blocked becomes true, if _userChoice is false and we already found a usable interface if (ifName.compare("ifName") == 0) { - qxtLog->debug() << _tag << " haven't found process!"; + qxtLog->debug() << _tag << " haven't found process!"; } else { - qxtLog->debug() << _tag << " process for interface " << ifName << " finished " - << " exit code: " << exitCode << " exit status " << exitStatus; + qxtLog->debug() << _tag << " process for interface " << ifName + << " finished " << " exit code: " << exitCode + << " exit status " << exitStatus; if (exitCode > 0) { - qxtLog->debug() << _tag << " process exited unexpected: " << p->errorString(); - emit updateIfStatus(ifName, "process exited unexpected" + p->errorString()); + qxtLog->debug() << _tag << " process exited unexpected: " + << p->errorString(); + emit updateIfStatus(ifName, "process exited unexpected" + + p->errorString()); } else { - qxtLog->debug() << _tag << " process normal exit "; - emit changeProgressBarValue(ifName, 100); - emit updateIfStatus(ifName, "check connectivity"); - checkConnectivity(ifName); + qxtLog->debug() << _tag << " process normal exit "; + emit + changeProgressBarValue(ifName, 100); + emit + updateIfStatus(ifName, "check connectivity"); + if (checkConnectivity(ifName)) { + emit connectionEstablished(ifName); + if (!_userChoice) { + // blockiere jeden weiteren check + _blocked = true; + emit allProcessesFinished(); + } + } } } if (!_blocked) { //_blocked becomes true, if _userChoice is false and we found a usable interface @@ -387,12 +412,12 @@ void NetworkDiscovery::handleProcessFinished(int exitCode, handleNewInput(client); } //_numberOfProcesses = _numberOfProcesses - 1; && _userChoice - if (_numberOfProcesses <= 0 ) { + if (_numberOfProcesses <= 0) { emit allProcessesFinished(); } } } else { - qxtLog->debug() << _tag << " already blocked"; + qxtLog->debug() << _tag << " already blocked"; emit updateIfStatus(ifName, "finished DHCP"); } } @@ -425,21 +450,13 @@ bool NetworkDiscovery::checkConnectivity(QString ifName) { // replace default route qxtLog->debug() << _tag << "replace default route"; - _networkManager.replaceDefaultRoute(ifName, + _networkManager->replaceDefaultRoute(ifName, ifConf->getGateway(), mss, AF_INET); if (checkConnectivityViaTcp(_serverIp)) { qxtLog->debug() << _tag << " passed connectivity check! for interface " << ifName; emit updateIfStatus(ifName, "connection possible"); - if (!_userChoice) { - // blockiere jeden weiteren check - // emite continueBoot - _blocked = true; - emit continueBoot(ifName, 0); - } else { - emit connectionEstablished(ifName); - } return true; } else { qxtLog->debug() << _tag << " failed connectivity check! for interface " << ifName; @@ -638,7 +655,7 @@ void NetworkDiscovery::handleNewInputLine(QLocalSocket * client, QString data) { * mss value (i think this is the metric. in most cases this value is 0) */ int NetworkDiscovery::ip4_replaceDefaultRoute(QString ifName, QString gateway, int mss) { - return _networkManager.replaceDefaultRoute(ifName, gateway, mss, AF_INET); + return _networkManager->replaceDefaultRoute(ifName, gateway, mss, AF_INET); } @@ -657,7 +674,7 @@ int NetworkDiscovery::ip4_replaceDefaultRoute(QString ifName, QString gateway, i int NetworkDiscovery::ip4_setManualConfiguration(QVariantMap result) { QList<QString> dns; dns.append(result["dns"].toString()); - _networkManager.ip4_setManualConfiguration(result["ifname"].toString(), + _networkManager->ip4_setManualConfiguration(result["ifname"].toString(), result["ipaddr"].toString(), result["netmask"].toString(), result["broadcast"].toString(), result["gateway"].toString(), 0, AF_INET, "/etc/", dns); @@ -671,7 +688,7 @@ int NetworkDiscovery::ip4_setManualConfiguration(QVariantMap result) { if (ifc != NULL) { dns.clear(); dns = ifc->getDnsservers().trimmed().split(" "); - _networkManager.ip4_setManualConfiguration( + _networkManager->ip4_setManualConfiguration( result["ifname"].toString(), ifc->getIpAddress(), ifc->getNetmask(), ifc->getBroadcast(), ifc->getGateway(), 0, AF_INET, "/etc/", dns); @@ -679,7 +696,7 @@ int NetworkDiscovery::ip4_setManualConfiguration(QVariantMap result) { return 0; } emit - continueBoot(result["ifname"].toString(), 0); + continueBoot(result["ifname"].toString()); return 0; } @@ -738,6 +755,19 @@ QString NetworkDiscovery::readLogFile() { } +/**/ +void NetworkDiscovery::killDHCPCD() { + qxtLog->debug() << " kill cdhcpcd processes"; + QProcess * p = new QProcess(this); + p->start("killall cdhcpcd"); + p->waitForFinished(); + if (p->exitCode() > 0) + qxtLog->debug() << _tag << "[tryAgain]" << p->errorString(); + + delete p; +} + + /* *TODO: to be bug fixed @@ -748,14 +778,8 @@ QString NetworkDiscovery::readLogFile() { */ void NetworkDiscovery::tryAgain() { // kill all cdhcpcd processes - qxtLog->debug() << " kill cdhcpcd processes"; - QProcess * p = new QProcess(this); - p->start("killall cdhcpcd"); - p->waitForFinished(); - if (p->exitCode() > 0) - qxtLog->debug() << _tag << "[tryAgain]" << p->errorString(); + killDHCPCD(); - delete p; /* foreach(Q_PID pid , _pidsList) { if (kill(pid,SIGKILL) <= -1) @@ -763,19 +787,9 @@ void NetworkDiscovery::tryAgain() { } */ // reset everything - _clients.clear(); - _clientProcessToIfNameMap.clear(); - _ifNameToClient.clear(); - _numberOfProcesses = 0; - _blocked = false; - _ifUpCountdown = 10; - _ifUpList.clear(); - _ifDownList.clear(); - _pidsList.clear(); - _ifcMap.clear(); - - // start again - mainWork(); + delete _networkManager; + delete _server; + initAndRun(_serverIp, _userChoice, _autoUp, _pathToLogFile, _serverPath, DEFAULT_PATHTODHCPCDEXE); } |