summaryrefslogtreecommitdiffstats
path: root/src/fbgui/networkdiscovery.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/fbgui/networkdiscovery.cpp')
-rw-r--r--src/fbgui/networkdiscovery.cpp630
1 files changed, 255 insertions, 375 deletions
diff --git a/src/fbgui/networkdiscovery.cpp b/src/fbgui/networkdiscovery.cpp
index ccefb8a..ab14923 100644
--- a/src/fbgui/networkdiscovery.cpp
+++ b/src/fbgui/networkdiscovery.cpp
@@ -23,18 +23,12 @@ using namespace log4cxx;
using namespace log4cxx::helpers;
LoggerPtr ndcLogger(Logger::getLogger("fbgui.nd.core"));
-
-
-
/**
* constructor
*/
NetworkDiscovery::NetworkDiscovery(QObject *parent) {
- _server = new QLocalServer(this);
}
-
-
/**
* destructor
*/
@@ -44,13 +38,11 @@ NetworkDiscovery::~NetworkDiscovery() {
foreach(QProcess* p, _clientProcessToIfNameMap.keys()) {
delete p;
}
- foreach(interfaceconfiguration* i, _ifcMap.values()) {
+ foreach(InterfaceConfiguration* i, _ifcMap.values()) {
delete i;
}
}
-
-
/**
* initialize all important class members and start the main work.
*
@@ -75,16 +67,10 @@ NetworkDiscovery::~NetworkDiscovery() {
* @param args
* additional arguments for the customdhcpcd client. (default value: NULL)
*/
-void NetworkDiscovery::initAndRun(QString serverIp, bool userChoice, bool autoUp, QString pathToLogFile, QString serverPath, QString pathToExe,
- QStringList* args) {
+void NetworkDiscovery::initAndRun(bool userChoice, QStringList* args) {
- _serverIp = serverIp;
_userChoice = userChoice;
- _autoUp = autoUp;
- _pathToLogFile = pathToLogFile;
- _serverPath = serverPath;
- _pathToDhcpcdExe = pathToExe;
_blocked = false;
_numberOfProcesses = 0;
_ifUpCountdown = 10;
@@ -100,22 +86,24 @@ void NetworkDiscovery::initAndRun(QString serverIp, bool userChoice, bool autoUp
_ifcMap.clear();
_server = new QLocalServer();
- if (serverPath != DEFAULT_QTSOCKETADDRESS) {
+ if (gSocketServerPath != DEFAULT_QTSOCKETADDRESS) {
_dhcpcdArguments.append("-q");
- _dhcpcdArguments.append(serverPath);
+ _dhcpcdArguments.append(gSocketServerPath);
}
/* delete the file at serverPath. this is necessary since in case the application crashes, the file still
- * exists which leads to an error.
- */
+ * exists which leads to an error.
+ */
- if(QFile::exists(serverPath)) {
- QFile::remove(serverPath);
+ if (QFile::exists(gSocketServerPath)) {
+ QFile::remove(gSocketServerPath);
}
- emit updateStatus("try to create server socket");
- if (!_server->listen(serverPath)) {
+ emit
+ updateStatus("try to create server socket");
+ if (!_server->listen(gSocketServerPath)) {
// emit signal to the gui that a critial error occoured
- LOG4CXX_DEBUG(ndcLogger, "Unable to start server: " << _server->errorString());
+ LOG4CXX_DEBUG(ndcLogger,
+ "Unable to start server: " << _server->errorString());
emit
abortBoot("Unable to start server: " + _server->errorString());
return;
@@ -124,28 +112,29 @@ void NetworkDiscovery::initAndRun(QString serverIp, bool userChoice, bool autoUp
killDHCPCD();
// check if the path to the customdhcpcd file is correct
- emit updateStatus("check if cdhcpcd is available");
- QFileInfo fInfo(_pathToDhcpcdExe);
- if (!fInfo.exists()) {
- LOG4CXX_DEBUG(ndcLogger, "could not find customdhcpcd exe. Please check the path to this file.");
- emit abortBoot(
- "could not find customdhcpcd exe. Please check the path to this file.");
- return;
- }
+ emit
+ updateStatus("check if cdhcpcd is available");
+ QFileInfo fInfo(gPathToDhcpExe);
+ if (!fInfo.exists()) {
+ LOG4CXX_DEBUG(
+ ndcLogger,
+ "could not find customdhcpcd exe. Please check the path to this file.");
+ emit
+ abortBoot(
+ "could not find customdhcpcd exe. Please check the path to this file.");
+ return;
+ }
connect(_server, SIGNAL(newConnection()), this, SLOT(handleNewConnection()));
- connect(this, SIGNAL(readyForRun()), this, SLOT(slotReadyForRun()));
if (args != NULL && !args->isEmpty()) {
LOG4CXX_DEBUG(ndcLogger, "added additional args");
_dhcpcdArguments.append(*args);
- }
- emit updateStatus("start mainwork");
- mainWork();
+ } emit
+ updateStatus("start mainwork");
+ mainWork();
}
-
-
/**
* @brief the main work. Here we start with searching for usable interfaces and check the IsRunning state.
*
@@ -153,78 +142,20 @@ void NetworkDiscovery::initAndRun(QString serverIp, bool userChoice, bool autoUp
* check every second the IsRunning state. Do this as long the counter (@see _ifUpCountdown) is greater than 0.
* Default: _ifUpCountdown = 10.
*/
-void NetworkDiscovery::mainWork()
-{
- if (_autoUp) {
- emit updateStatus("search for usable interfaces (with auto Up)");
- getListOfNetworkInterfacesWithAutoUp();
- } else {
- emit updateStatus("search for usable interfaces");
- getListOfNetworkInterfaces();
- }
- emit updateStatus("check if interfaces are in running state");
+void NetworkDiscovery::mainWork() {
+ gAutoUp ?
+ emit updateStatus("search for usable interfaces (with auto Up)") :
+ emit updateStatus("search for usable interfaces");
+
+ getListOfNetworkInterfaces();
+
+ emit
+ updateStatus("check if interfaces are in running state");
_timer = new QTimer(this);
connect(_timer, SIGNAL(timeout()), this, SLOT(checkForIsRunning()));
_timer->start(1000);
}
-
-
-/**
- * searches for usable interfaces and puts them into a list.
- * if the interface is down, put it in the _ifDownList, try to bring it up.
- * else put it in the _ifUpList.
- * usable interfaces are: can Broadcast, no loopback, no point to point, name is not in the BlackList,
- */
-void NetworkDiscovery::getListOfNetworkInterfacesWithAutoUp() {
- QList<QNetworkInterface> nIList = QNetworkInterface::allInterfaces();
- _ifUpList.clear();
- _ifDownList.clear();
- if (nIList.size() > 0) {
- foreach(QNetworkInterface nI, nIList)
- {
- LOG4CXX_DEBUG(ndcLogger, "found Interface:" << nI.humanReadableName());
- if ((nI.flags() & QNetworkInterface::CanBroadcast)) {
- LOG4CXX_DEBUG(ndcLogger, "flags: can broadcast ");
- }
- if ((nI.flags() & QNetworkInterface::IsLoopBack)) {
- LOG4CXX_DEBUG(ndcLogger, "flags: is LoopBack ");
- }
- if ((nI.flags() & QNetworkInterface::IsPointToPoint)) {
- LOG4CXX_DEBUG(ndcLogger, "flags: is Point to Point ");
- }
- if ((nI.flags() & QNetworkInterface::IsRunning)) {
- LOG4CXX_DEBUG(ndcLogger, "flags: is Running ");
- }
- if ((nI.flags() & QNetworkInterface::IsUp)) {
- LOG4CXX_DEBUG(ndcLogger, "flags: is Up ");
- }
-
- if (((!(nI.flags() & QNetworkInterface::CanBroadcast)
- || nI.flags() & QNetworkInterface::IsLoopBack)
- || nI.flags() & QNetworkInterface::IsPointToPoint)
- || checkBlackList(nI.humanReadableName())) {
- continue;
- }
- if ((nI.flags() & QNetworkInterface::IsRunning)) {
- _ifUpList.append(nI.humanReadableName());
- }
- else if (!(nI.flags() & QNetworkInterface::IsUp)) {
- _networkManager->bringInterfaceUP(nI.humanReadableName());
- LOG4CXX_DEBUG(ndcLogger, "interface is down, try to bring up: " << nI.humanReadableName() );
- _ifDownList.append(nI.humanReadableName());
- }
- else if (!(nI.flags() & QNetworkInterface::IsRunning)) {
- _ifDownList.append(nI.humanReadableName());
- }
- }
- } else {
- LOG4CXX_DEBUG(ndcLogger, "no interfaces found! ");
- }
-}
-
-
-
/**
* searches for usable interfaces which are up and running and put them into a list.
* usable interfaces are: can Broadcast, no loopback, no point to point, name is not in the BlackList,
@@ -235,43 +166,48 @@ void NetworkDiscovery::getListOfNetworkInterfaces() {
_ifDownList.clear();
if (nIList.size() > 0) {
foreach(QNetworkInterface nI, nIList)
- {
- LOG4CXX_DEBUG(ndcLogger, "found Interface:" << nI.humanReadableName());
- if ((nI.flags() & QNetworkInterface::CanBroadcast)) {
- LOG4CXX_DEBUG(ndcLogger, "flags: can broadcast ");
- }
- if ((nI.flags() & QNetworkInterface::IsLoopBack)) {
- LOG4CXX_DEBUG(ndcLogger, "flags: is LoopBack ");
- }
- if ((nI.flags() & QNetworkInterface::IsPointToPoint)) {
- LOG4CXX_DEBUG(ndcLogger, "flags: is Point to Point ");
- }
- if ((nI.flags() & QNetworkInterface::IsRunning)) {
- LOG4CXX_DEBUG(ndcLogger, "flags: is Running ");
- }
- if ((nI.flags() & QNetworkInterface::IsUp)) {
- LOG4CXX_DEBUG(ndcLogger, "flags: is Up ");
- }
- if (((!(nI.flags() & QNetworkInterface::CanBroadcast)
- || nI.flags() & QNetworkInterface::IsLoopBack)
- || nI.flags() & QNetworkInterface::IsPointToPoint)
- || !(nI.flags() & QNetworkInterface::IsUp)
- || checkBlackList(nI.humanReadableName())) {
- continue;
- }
- if (!(nI.flags() & QNetworkInterface::IsRunning)) {
- _ifDownList.append(nI.humanReadableName());
- } else {
- _ifUpList.append(nI.humanReadableName());
- }
+ {
+ LOG4CXX_DEBUG(ndcLogger, "found Interface:" << nI.humanReadableName());
+ if ((nI.flags() & QNetworkInterface::CanBroadcast)) {
+ LOG4CXX_DEBUG(ndcLogger, "flags: can broadcast ");
+ }
+ if ((nI.flags() & QNetworkInterface::IsLoopBack)) {
+ LOG4CXX_DEBUG(ndcLogger, "flags: is LoopBack ");
+ }
+ if ((nI.flags() & QNetworkInterface::IsPointToPoint)) {
+ LOG4CXX_DEBUG(ndcLogger, "flags: is Point to Point ");
+ }
+ if ((nI.flags() & QNetworkInterface::IsRunning)) {
+ LOG4CXX_DEBUG(ndcLogger, "flags: is Running ");
+ }
+ if ((nI.flags() & QNetworkInterface::IsUp)) {
+ LOG4CXX_DEBUG(ndcLogger, "flags: is Up ");
+ }
+ if (((!(nI.flags() & QNetworkInterface::CanBroadcast)
+ || nI.flags() & QNetworkInterface::IsLoopBack)
+ || nI.flags() & QNetworkInterface::IsPointToPoint)
+ || (gAutoUp && !(nI.flags() & QNetworkInterface::IsUp))
+ || checkBlackList(nI.humanReadableName())) {
+ continue;
}
+
+ if ((nI.flags() & QNetworkInterface::IsRunning)) {
+ _ifUpList.append(nI.humanReadableName());
+ } else if (gAutoUp && !(nI.flags() & QNetworkInterface::IsUp)) {
+ _networkManager->bringInterfaceUP(nI.humanReadableName());
+ LOG4CXX_DEBUG(
+ ndcLogger,
+ "interface is down, try to bring up: " << nI.humanReadableName());
+ _ifDownList.append(nI.humanReadableName());
+ } else if (!(nI.flags() & QNetworkInterface::IsRunning)) {
+ _ifDownList.append(nI.humanReadableName());
+ }
+ }
} else {
LOG4CXX_DEBUG(ndcLogger, "no interfaces found! ");
}
}
-
-
/**
* only called if autoUp == true.
* check the IsRunning flag of each interface in the _ifDownList.
@@ -280,7 +216,8 @@ void NetworkDiscovery::getListOfNetworkInterfaces() {
void NetworkDiscovery::checkForIsRunning() {
bool isRunning = false;
foreach(QString i, _ifDownList) {
- QNetworkInterface networkInterface = QNetworkInterface::interfaceFromName(i);
+ QNetworkInterface networkInterface = QNetworkInterface::interfaceFromName(
+ i);
isRunning = (networkInterface.flags() & QNetworkInterface::IsRunning);
if (isRunning) {
_ifUpList.append(i);
@@ -288,16 +225,15 @@ void NetworkDiscovery::checkForIsRunning() {
}
}
_ifUpCountdown--;
- if ((_ifUpCountdown <= 0 ) || _ifDownList.isEmpty()) {
+ if ((_ifUpCountdown <= 0) || _ifDownList.isEmpty()) {
// shut down timer
_timer->stop();
delete _timer;
- emit readyForRun();
+ //emit readyForRun();
+ slotReadyForRun();
}
}
-
-
/**
* emits the addInterface signal for each interface name in _ifUpList
* and calls the runDHCPCD method.
@@ -312,20 +248,20 @@ void NetworkDiscovery::slotReadyForRun() {
}
_numberOfProcesses = _ifUpList.size();
emit updateStatus("start dhcp client for each interface");
- runDHCPCD( _ifUpList);
+ runDHCPCD(_ifUpList);
} else {
- LOG4CXX_DEBUG(ndcLogger, "list is empty. Have not found usable interface. ");
+ LOG4CXX_DEBUG(ndcLogger,
+ "list is empty. Have not found usable interface. ");
emit
foreach(QString i, _ifDownList) {
LOG4CXX_DEBUG(ndcLogger, "" << i << " is not in running state. (check cable)");
}
- abortBoot("All interfaces are not usable. (e.g. please check if all network cables are plugged in. Read the log for more informations.)");
+ abortBoot(
+ "All interfaces are not usable. (e.g. please check if all network cables are plugged in. Read the log for more informations.)");
return;
}
}
-
-
/**
* call for every interface in the list the runDHCPCD method.
*
@@ -333,14 +269,11 @@ void NetworkDiscovery::slotReadyForRun() {
* list of interface names.
*/
void NetworkDiscovery::runDHCPCD(QList<QString> &interfaces) {
- foreach(QString nI, interfaces)
- {
- runDHCPCD(nI);
- }
+ foreach(QString nI, interfaces) {
+ runDHCPCD(nI);
+ }
}
-
-
/**
* start a cdhcpcd process with the interface name as last argument.
*
@@ -352,18 +285,17 @@ void NetworkDiscovery::runDHCPCD(QString interface) {
_dhcpcdArguments.append(interface);
QProcess * p = new QProcess(this);
- LOG4CXX_DEBUG(ndcLogger, "start cdhcpcd with arguments: " << _dhcpcdArguments.join(", "));
+ LOG4CXX_DEBUG(ndcLogger,
+ "start cdhcpcd with arguments: " << _dhcpcdArguments.join(", "));
_clientProcessToIfNameMap.insert(p, interface);
- p->start(_pathToDhcpcdExe, _dhcpcdArguments);
+ p->start(gPathToDhcpExe, _dhcpcdArguments);
connect(p, SIGNAL(started()), this, SLOT(handleProcessStarted()));
connect(p, SIGNAL(finished(int, QProcess::ExitStatus)), this,
SLOT(handleProcessFinished(int, QProcess::ExitStatus)));
_dhcpcdArguments.removeLast();
}
-
-
/**
* This Method is called when a process is started.
*
@@ -371,13 +303,11 @@ void NetworkDiscovery::runDHCPCD(QString interface) {
* It prints the message: "process started for interface: <interfaceName>".
*/
void NetworkDiscovery::handleProcessStarted() {
- QProcess* p = qobject_cast<QProcess *> (QObject::sender());
+ QProcess* p = qobject_cast<QProcess *>(QObject::sender());
QString ifName = _clientProcessToIfNameMap.value(p, "ifName");
LOG4CXX_DEBUG(ndcLogger, "process started for interface: " << ifName);
}
-
-
/**
* This Method is called when a process is finished.
*
@@ -408,18 +338,21 @@ void NetworkDiscovery::handleProcessStarted() {
void NetworkDiscovery::handleProcessFinished(int exitCode,
QProcess::ExitStatus exitStatus) {
- QProcess* p = qobject_cast<QProcess *> (QObject::sender());
+ QProcess* p = qobject_cast<QProcess *>(QObject::sender());
QString ifName = _clientProcessToIfNameMap.value(p, "ifName");
_numberOfProcesses = _numberOfProcesses - 1;
if (!_blocked) { //_blocked becomes true, if _userChoice is false and we already found a usable interface
if (ifName.compare("ifName") == 0) {
LOG4CXX_DEBUG(ndcLogger, "haven't found process!");
} else {
- LOG4CXX_DEBUG(ndcLogger, "process for interface " << ifName << " finished " << " exit code: " << exitCode << " exit status " << exitStatus);
+ LOG4CXX_DEBUG(
+ ndcLogger,
+ "process for interface " << ifName << " finished " << " exit code: " << exitCode << " exit status " << exitStatus);
if (exitCode > 0) {
- LOG4CXX_DEBUG(ndcLogger, "process exited unexpected: " << p->errorString());
- emit updateIfStatus(ifName, "process exited unexpected"
- + p->errorString());
+ LOG4CXX_DEBUG(ndcLogger,
+ "process exited unexpected: " << p->errorString());
+ emit updateIfStatus(ifName,
+ "process exited unexpected" + p->errorString());
} else {
LOG4CXX_DEBUG(ndcLogger, "process normal exit ");
emit
@@ -452,8 +385,6 @@ void NetworkDiscovery::handleProcessFinished(int exitCode,
}
}
-
-
/**
* checks the connectivity. tries to open a TCP connection to the
* server (see _serverIp). For this it adjusts the routing table.
@@ -467,50 +398,44 @@ void NetworkDiscovery::handleProcessFinished(int exitCode,
* @return
* true: connection is possible
* false: connection not possible
- */
-bool NetworkDiscovery::checkConnectivity(QString ifName) {
+ */bool NetworkDiscovery::checkConnectivity(QString ifName) {
int mss = 0;
// get gateway address
QString pathToGatewayFile(DEFAULT_INTERFACE_CONF_LOCATION);
pathToGatewayFile += ifName;
- interfaceconfiguration* ifConf;
+ InterfaceConfiguration* ifConf;
if (!_ifcMap.contains(ifName)) {
- ifConf = new interfaceconfiguration();
+ ifConf = new InterfaceConfiguration();
_ifcMap.insert(ifName, ifConf);
- }
- else {
+ } else {
ifConf = _ifcMap.value(ifName);
}
ifConf->readConfigOutOfFile(pathToGatewayFile);
// replace default route
LOG4CXX_DEBUG(ndcLogger, "replace default route");
- _networkManager->replaceDefaultRoute(ifName,
- ifConf->getGateway(), mss, AF_INET);
+ _networkManager->replaceDefaultRoute(ifName, ifConf->getGateway(), mss,
+ AF_INET);
- if (checkConnectivityViaTcp(_serverIp)) {
- LOG4CXX_DEBUG(ndcLogger, "passed connectivity check! for interface " << ifName);
+ if (checkConnectivityViaTcp(gServerIp)) {
+ LOG4CXX_DEBUG(ndcLogger,
+ "passed connectivity check! for interface " << ifName);
emit
updateIfStatus(ifName, "connection possible");
return true;
} else {
- LOG4CXX_DEBUG(ndcLogger, "failed connectivity check! for interface " << ifName);
+ LOG4CXX_DEBUG(ndcLogger,
+ "failed connectivity check! for interface " << ifName);
emit
updateIfStatus(ifName, "connection not possible");
return false;
}
}
-
-
-/**/
-bool NetworkDiscovery::checkConnectivityViaTcp() {
- return checkConnectivityViaTcp(_serverIp);
+/**/bool NetworkDiscovery::checkConnectivityViaTcp() {
+ return checkConnectivityViaTcp(gServerIp);
}
-
-
-
/**
* try to open a tcp connection to the server
*
@@ -520,12 +445,10 @@ bool NetworkDiscovery::checkConnectivityViaTcp() {
* @return
* true: connection is possible
* false: connection not possible
- */
-bool NetworkDiscovery::checkConnectivityViaTcp(QString server) {
+ */bool NetworkDiscovery::checkConnectivityViaTcp(QString server) {
// check connectivity via tcp connection
LOG4CXX_DEBUG(ndcLogger, "check connectivity to server: " << server);
// do host lookup
- //QHostInfo hostInfo = QHostInfo::fromName(server);
QTcpSocket *tcpSocket = new QTcpSocket(this);
//LOG4CXX_DEBUG(ndcLogger, "hostInfo first address: " << hostInfo.addresses().first().toString()); //hostInfo.addresses().first()
tcpSocket->connectToHost(server, 80);
@@ -539,8 +462,6 @@ bool NetworkDiscovery::checkConnectivityViaTcp(QString server) {
delete tcpSocket;
}
-
-
/**
* same function as handleNewInput() but with a client as parameter.
*
@@ -553,7 +474,8 @@ void NetworkDiscovery::handleNewInput(QLocalSocket * client) {
QString data(client->readLine());
data = data.trimmed();
- if (!data.isEmpty()) LOG4CXX_DEBUG(ndcLogger, data);
+ if (!data.isEmpty())
+ LOG4CXX_DEBUG(ndcLogger, data);
QStringList lines = data.split("\n");
for (int i = 0; i < lines.length(); i++) {
@@ -562,15 +484,13 @@ void NetworkDiscovery::handleNewInput(QLocalSocket * client) {
}
}
-
-
/**
* This method is connected to the readyRead Signal of the QLocalSocket
* client.
* send an ACK to the client with every received message.
*/
void NetworkDiscovery::handleNewInput() {
- QLocalSocket* socket = qobject_cast<QLocalSocket *> (QObject::sender());
+ QLocalSocket* socket = qobject_cast<QLocalSocket *>(QObject::sender());
QLocalSocket * client = _clients.value(socket);
QString data(client->read(DHCP_MESSAGE_SIZE));
@@ -581,8 +501,6 @@ void NetworkDiscovery::handleNewInput() {
}
}
-
-
/**
* This Method processes the send messages.
*
@@ -603,118 +521,114 @@ void NetworkDiscovery::handleNewInput() {
* @param data
* the message. (format <interfaceName>;<state>;<subState>;<msg> )
*/
-void NetworkDiscovery::handleNewInputLine(QLocalSocket * client, QString logMsg) {
-
- if (logMsg.trimmed().size() < 1) return;
-
- QString interface = logMsg.section(";", 0, 0);
- QString s_state = logMsg.section(";", 1, 1);
- QString s_subState = logMsg.section(";", 2, 2);
- QString msg = logMsg.section(";", 3, 3);
- int st = s_state.trimmed().toInt();
- int sst = s_subState.trimmed().toInt();
- //LOG4CXX_DEBUG(ndcLogger, logMsg);
-
- if (_ifNameToClient.size() < _numberOfProcesses
- && !_ifNameToClient.contains(interface))
- {
- _ifNameToClient.insert(interface, client);
- }
-
-
- // st states
-
- // #define LOG_EMERG 0 /* system is unusable */
- // #define LOG_ALERT 1 /* action must be taken immediately */
- // #define LOG_CRIT 2 /* critical conditions */
- // #define LOG_ERR 3 /* error conditions */
- // #define LOG_WARNING 4 /* warning conditions */
- // #define LOG_NOTICE 5 /* normal but significant condition */
- // #define LOG_INFO 6 /* informational */
- // #define LOG_DEBUG 7 /* debug-level messages */
-
- QString out;
- QTextStream outStream(&out);
-
- switch (sst)
- {
- case DHCP_DISCOVER:
- emit changeProgressBarValue(interface, 10);
- outStream << interface << " send discover";
- break;
- case DHCP_OFFER:
- emit changeProgressBarValue(interface, 20);
- outStream << interface << " got offer";
- break;
- case DHCP_REQUEST:
- emit changeProgressBarValue(interface, 30);
- outStream << interface << " send request";
- break;
- case DHCP_ACK:
- emit changeProgressBarValue(interface, 40);
- outStream << interface << " ack";
- break;
- case DHCP_NAK:
- emit changeProgressBarValue(interface, 40);
- outStream << interface << " nak";
- break;
- case DHCP_RELEASE:
- outStream << interface << " release";
- break;
- case DHCP_INFORM:
- break;
- case DHCPCD_ARP_TEST:
- emit changeProgressBarValue(interface, 50);
- outStream << interface << " do arp test";
- break;
- case DHCP_DECLINE:
- emit changeProgressBarValue(interface, 60);
- break;
- case DHCPCD_CONFIGURE:
- emit changeProgressBarValue(interface, 70);
- outStream << interface << " do configure interface";
- break;
- case DHCPCD_WRITE:
- emit changeProgressBarValue(interface, 80);
- outStream << interface << " write conf file";
- break;
- case DHCPCD_EXIT:
- emit changeProgressBarValue(interface, 100);
- outStream << interface << " exiting";
- break;
- case DHCPCD_LOG:
- outStream << "received dhcpcd log: " << msg;
- break;
- default:
- outStream << "received unknown substatus: " << msg;
- break;
- }
-
- switch (st)
- {
-
- case LOG_INFO:
- LOG4CXX_INFO(ndcLogger, out);
- break;
- case LOG_NOTICE:
- LOG4CXX_WARN(ndcLogger, out);
- break;
- case LOG_WARNING:
- LOG4CXX_WARN(ndcLogger, out);
- break;
- case LOG_DEBUG:
- LOG4CXX_DEBUG(ndcLogger, out);
- break;
- case LOG_ERR:
- LOG4CXX_ERROR(ndcLogger, out);
- break;
- default:
- LOG4CXX_DEBUG(ndcLogger, out);
- break;
- }
-}
+void NetworkDiscovery::handleNewInputLine(QLocalSocket * client,
+ QString logMsg) {
+ if (logMsg.trimmed().size() < 1)
+ return;
+ QString interface = logMsg.section(";", 0, 0);
+ QString s_state = logMsg.section(";", 1, 1);
+ QString s_subState = logMsg.section(";", 2, 2);
+ QString msg = logMsg.section(";", 3, 3);
+ int st = s_state.trimmed().toInt();
+ int sst = s_subState.trimmed().toInt();
+ //LOG4CXX_DEBUG(ndcLogger, logMsg);
+
+ if (_ifNameToClient.size() < _numberOfProcesses
+ && !_ifNameToClient.contains(interface)) {
+ _ifNameToClient.insert(interface, client);
+ }
+
+ // st states
+
+ // #define LOG_EMERG 0 /* system is unusable */
+ // #define LOG_ALERT 1 /* action must be taken immediately */
+ // #define LOG_CRIT 2 /* critical conditions */
+ // #define LOG_ERR 3 /* error conditions */
+ // #define LOG_WARNING 4 /* warning conditions */
+ // #define LOG_NOTICE 5 /* normal but significant condition */
+ // #define LOG_INFO 6 /* informational */
+ // #define LOG_DEBUG 7 /* debug-level messages */
+
+ QString out;
+ QTextStream outStream(&out);
+
+ switch (sst) {
+ case DHCP_DISCOVER:
+ emit changeProgressBarValue(interface, 10);
+ outStream << interface << " send discover";
+ break;
+ case DHCP_OFFER:
+ emit changeProgressBarValue(interface, 20);
+ outStream << interface << " got offer";
+ break;
+ case DHCP_REQUEST:
+ emit changeProgressBarValue(interface, 30);
+ outStream << interface << " send request";
+ break;
+ case DHCP_ACK:
+ emit changeProgressBarValue(interface, 40);
+ outStream << interface << " ack";
+ break;
+ case DHCP_NAK:
+ emit changeProgressBarValue(interface, 40);
+ outStream << interface << " nak";
+ break;
+ case DHCP_RELEASE:
+ outStream << interface << " release";
+ break;
+ case DHCP_INFORM:
+ break;
+ case DHCPCD_ARP_TEST:
+ emit changeProgressBarValue(interface, 50);
+ outStream << interface << " do arp test";
+ break;
+ case DHCP_DECLINE:
+ emit changeProgressBarValue(interface, 60);
+ break;
+ case DHCPCD_CONFIGURE:
+ emit changeProgressBarValue(interface, 70);
+ outStream << interface << " do configure interface";
+ break;
+ case DHCPCD_WRITE:
+ emit changeProgressBarValue(interface, 80);
+ outStream << interface << " write conf file";
+ break;
+ case DHCPCD_EXIT:
+ emit changeProgressBarValue(interface, 100);
+ outStream << interface << " exiting";
+ break;
+ case DHCPCD_LOG:
+ outStream << "received dhcpcd log: " << msg;
+ break;
+ default:
+ outStream << "received unknown substatus: " << msg;
+ break;
+ }
+
+ switch (st) {
+
+ case LOG_INFO:
+ LOG4CXX_INFO(ndcLogger, out);
+ break;
+ case LOG_NOTICE:
+ LOG4CXX_WARN(ndcLogger, out);
+ break;
+ case LOG_WARNING:
+ LOG4CXX_WARN(ndcLogger, out);
+ break;
+ case LOG_DEBUG:
+ LOG4CXX_DEBUG(ndcLogger, out);
+ break;
+ case LOG_ERR:
+ LOG4CXX_ERROR(ndcLogger, out);
+ break;
+ default:
+ LOG4CXX_DEBUG(ndcLogger, out);
+ break;
+ }
+}
/**
* replace the default route. sets af automatically to AF_INET
@@ -728,12 +642,11 @@ void NetworkDiscovery::handleNewInputLine(QLocalSocket * client, QString logMsg)
* @param mss
* 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) {
+int NetworkDiscovery::ip4_replaceDefaultRoute(QString ifName, QString gateway,
+ int mss) {
return _networkManager->replaceDefaultRoute(ifName, gateway, mss, AF_INET);
}
-
-
/**
* replace the dhcp configuration with the manual config, entered by the user.
* if we can not establish a connection with the entered values, reset to the old
@@ -755,29 +668,28 @@ int NetworkDiscovery::ip4_setManualConfiguration(QVariantMap result) {
LOG4CXX_DEBUG(ndcLogger, "set man conf. and check connectivity");
- if (!checkConnectivityViaTcp(_serverIp)) {
+ if (!checkConnectivityViaTcp(gServerIp)) {
LOG4CXX_DEBUG(ndcLogger, "no connectivity. reset conf.");
- interfaceconfiguration * ifc = _ifcMap.value(
- result["ifname"].toString(), NULL);
+ InterfaceConfiguration * ifc = _ifcMap.value(result["ifname"].toString(),
+ NULL);
if (ifc != NULL) {
dns.clear();
dns = ifc->getDnsservers().trimmed().split(" ");
_networkManager->ip4_setManualConfiguration(
result["ifname"].toString(), ifc->getIpAddress(),
- ifc->getNetmask(), ifc->getBroadcast(), ifc->getGateway(),
- 0, AF_INET, "/etc/", dns);
+ ifc->getNetmask(), ifc->getBroadcast(), ifc->getGateway(), 0,
+ AF_INET, "/etc/", dns);
}
return 0;
- }
- LOG4CXX_DEBUG(ndcLogger, "emit signal continueBootWithoutCheck(" << result["ifname"].toString() << ")");
+ }LOG4CXX_DEBUG(
+ ndcLogger,
+ "emit signal continueBootWithoutCheck(" << result["ifname"].toString() << ")");
emit
continueBootWithoutCheck(result["ifname"].toString());
return 0;
}
-
-
/**
* returns the gateway address, written into the dhcp config file.
*
@@ -788,20 +700,16 @@ int NetworkDiscovery::ip4_setManualConfiguration(QVariantMap result) {
* gateway address as string. or empty string if no interface config was found.
*/
QString NetworkDiscovery::getGatewayForInterface(QString ifName) {
- interfaceconfiguration * ifConf = _ifcMap.value(ifName, NULL);
- if (ifConf != NULL)
- {
+ InterfaceConfiguration * ifConf = _ifcMap.value(ifName, NULL);
+ if (ifConf != NULL) {
return ifConf->getGateway();
- }
- else {
+ } else {
LOG4CXX_DEBUG(ndcLogger, "could not find interface configuration");
return "";
}
}
-
-
/**
* reads the log file.
*
@@ -809,28 +717,25 @@ QString NetworkDiscovery::getGatewayForInterface(QString ifName) {
*/
QString NetworkDiscovery::readLogFile() {
// path to log file is in _pathToLogFile. initialized in initAndRun().
- QString retval("the log file\n");
- QFile logFile(_pathToLogFile);
+ QString retval("the log file:\n");
+ QFile logFile(logFilePath);
if (logFile.exists()) {
if (logFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
while (!logFile.atEnd()) {
retval.append(logFile.readLine());
}
- }
- else {
+ } else {
LOG4CXX_DEBUG(ndcLogger, "could not open log file");
retval = "could not open log file";
}
- }
- else {
- LOG4CXX_DEBUG(ndcLogger, "log file does not exist at: " << _pathToLogFile);
- retval = " log file does not exist at: " + _pathToLogFile;
+ } else {
+ LOG4CXX_DEBUG(ndcLogger, "log file does not exist at: " << logFilePath);
+ retval = " log file does not exist at: " + logFilePath;
}
return retval;
}
-
/**/
void NetworkDiscovery::killDHCPCD() {
LOG4CXX_DEBUG(ndcLogger, "kill cdhcpcd processes");
@@ -843,8 +748,6 @@ void NetworkDiscovery::killDHCPCD() {
delete p;
}
-
-
/**/
void NetworkDiscovery::prepareTryAgain() {
// kill all cdhcpcd processes
@@ -863,45 +766,26 @@ void NetworkDiscovery::prepareTryAgain() {
{
delete p;
}
- foreach(interfaceconfiguration* i, _ifcMap.values())
+ foreach(InterfaceConfiguration* i, _ifcMap.values())
{
delete i;
}
}
-
-
/*
*TODO: to be bug fixed
*TODO: do it with kill and not QProcess("killall cdhcpcd")
*/
void NetworkDiscovery::tryAgain() {
prepareTryAgain();
- initAndRun(_serverIp, _userChoice, _autoUp, _pathToLogFile, _serverPath, DEFAULT_PATHTODHCPCDEXE);
+ initAndRun(_userChoice);
}
-
-
/**/
-QVariantMap NetworkDiscovery::getInterfaceConfig(QString ifName) {
- QVariantMap jsonObj;
- QList<QString> dns;
- interfaceconfiguration * ifc = _ifcMap.value(ifName, NULL);
- if (ifc != NULL) {
- jsonObj.insert("ipaddr",ifc->getIpAddress());
- jsonObj.insert("netmask",ifc->getNetmask());
- jsonObj.insert("broadcast",ifc->getBroadcast());
- jsonObj.insert("gateway",ifc->getGateway());
-
- dns.clear();
- dns = ifc->getDnsservers().trimmed().split(" ");
- jsonObj.insert("dns",dns.first());
- }
- return jsonObj;
+InterfaceConfiguration* NetworkDiscovery::getInterfaceConfig(QString ifName) {
+ return _ifcMap.value(ifName, NULL);
}
-
-
/**
* connected to the new client arrived signal.
* connects the client readyRead signal with the handleNewInput slot.
@@ -917,13 +801,11 @@ void NetworkDiscovery::handleNewConnection() {
connect(_client, SIGNAL(readyRead()), this, SLOT(handleNewInput()));
}
-
-
/**
* called when a client disconnects.
*/
void NetworkDiscovery::handleClientDisconnect() {
- QLocalSocket* socket = qobject_cast<QLocalSocket *> (QObject::sender());
+ QLocalSocket* socket = qobject_cast<QLocalSocket *>(QObject::sender());
QLocalSocket * client = _clients.value(socket);
@@ -932,8 +814,6 @@ void NetworkDiscovery::handleClientDisconnect() {
client->deleteLater();
}
-
-
/**
* This Method implements a blacklist.
*
@@ -951,8 +831,7 @@ void NetworkDiscovery::handleClientDisconnect() {
* returns false: else
*
* @see NetworkDiscovery::getListOfNetworkInterfaces()
- */
-bool NetworkDiscovery::checkBlackList(QString i) {
+ */bool NetworkDiscovery::checkBlackList(QString i) {
if (i.startsWith("v", Qt::CaseInsensitive)) {
return true;
} else if (i.startsWith("d", Qt::CaseInsensitive)) {
@@ -962,15 +841,11 @@ bool NetworkDiscovery::checkBlackList(QString i) {
}
}
-
-
/**/
QString NetworkDiscovery::GetErrorStr() {
return _errorStr;
}
-
-
//////////////////////////////////////////////////////////////////////////////////////
/**
@@ -980,8 +855,7 @@ QString NetworkDiscovery::GetErrorStr() {
*
* @param interface
* name of the interface
- */
-bool NetworkDiscovery::checkCarrierState(QString interface) {
+ */bool NetworkDiscovery::checkCarrierState(QString interface) {
LOG4CXX_DEBUG(ndcLogger, "check carrier state for interface " << interface);
QByteArray ba = interface.toAscii();
@@ -1000,10 +874,12 @@ bool NetworkDiscovery::checkCarrierState(QString interface) {
int v = value.toInt(pok);
if (*pok) {
if (v == 1) {
- LOG4CXX_DEBUG(ndcLogger, "carrier is 1. Cable is plugged. return true");
+ LOG4CXX_DEBUG(ndcLogger,
+ "carrier is 1. Cable is plugged. return true");
return true;
} else {
- LOG4CXX_DEBUG(ndcLogger, "carrier is 0. Cable is unplugged. return false");
+ LOG4CXX_DEBUG( ndcLogger,
+ "carrier is 0. Cable is unplugged. return false");
return false;
}
} else {
@@ -1018,3 +894,7 @@ bool NetworkDiscovery::checkCarrierState(QString interface) {
return true;
}
+
+QList<QString> NetworkDiscovery::getIfUpList() {
+ return _ifUpList;
+}