From 5a76512a347f5e728e6c0fa2c34fbd9b46645208 Mon Sep 17 00:00:00 2001 From: Niklas Date: Mon, 26 Sep 2011 12:15:40 +0200 Subject: renamed routemanager to networkmanager --- LogReceiver/LogReceiver.pro | 8 +- LogReceiver/html/networkdiscovery.html | 4 +- LogReceiver/networkdiscovery.cpp | 4 +- LogReceiver/networkdiscovery.h | 4 +- LogReceiver/networkmanager.cpp | 178 +++++++++++++++++++++++++++++++++ LogReceiver/networkmanager.h | 40 ++++++++ LogReceiver/routemanager.cpp | 177 -------------------------------- LogReceiver/routemanager.h | 40 -------- 8 files changed, 229 insertions(+), 226 deletions(-) create mode 100644 LogReceiver/networkmanager.cpp create mode 100644 LogReceiver/networkmanager.h delete mode 100644 LogReceiver/routemanager.cpp delete mode 100644 LogReceiver/routemanager.h diff --git a/LogReceiver/LogReceiver.pro b/LogReceiver/LogReceiver.pro index eaa7001..1bba39d 100644 --- a/LogReceiver/LogReceiver.pro +++ b/LogReceiver/LogReceiver.pro @@ -7,12 +7,12 @@ LIBS += -lsysfs \ -L/home/niklas/fbgui/customdhcpcd/src/build \ -llibcustomdhcpcd INCLUDEPATH += /home/niklas/fbgui/customdhcpcd/src -HEADERS += networkdiscovery.h \ - routemanager.h \ +HEADERS += networkmanager.h \ + networkdiscovery.h \ interfaceconfiguration.h \ ndgui.h -SOURCES += networkdiscovery.cpp \ - routemanager.cpp \ +SOURCES += networkmanager.cpp \ + networkdiscovery.cpp \ interfaceconfiguration.cpp \ ndgui.cpp \ main.cpp diff --git a/LogReceiver/html/networkdiscovery.html b/LogReceiver/html/networkdiscovery.html index 600674a..c24c86b 100644 --- a/LogReceiver/html/networkdiscovery.html +++ b/LogReceiver/html/networkdiscovery.html @@ -11,7 +11,9 @@ var abortBootDialog = function (m) { $("#nd_abort_boot_msg").html(m); $("#nd_abort_boot_dialog").dialog( - { buttons: { "Show Log": function() {fbgui.showLog(); + { buttons: { "Manual Configure": function() { + $(this).dialog("close");}, + "Show Log": function() {fbgui.showLog(); $(this).dialog("close");}, "Restart": function() {fbgui.restartSystem(); $(this).dialog("close"); }, diff --git a/LogReceiver/networkdiscovery.cpp b/LogReceiver/networkdiscovery.cpp index cd77ee1..303ffe7 100644 --- a/LogReceiver/networkdiscovery.cpp +++ b/LogReceiver/networkdiscovery.cpp @@ -80,7 +80,7 @@ void NetworkDiscovery::initAndRun(QString serverPath, QString pathToExe, } int NetworkDiscovery::replaceDefaultRoute(QString &ifName, QString &gateway, int af, int mss) { - rm.replaceDefaultRoute(ifName, gateway, mss, AF_INET); + networkManager.replaceDefaultRoute(ifName, gateway, mss, AF_INET); } QList NetworkDiscovery::getListOfNetworkInterfaces() { @@ -195,7 +195,7 @@ bool NetworkDiscovery::checkConnectivity(QString ifName) { ifConf.readConfigOutOfFile(pathToGatewayFile); // replace default route - qDebug() << rm.replaceDefaultRoute(ifName, ifConf.getGateway(), 0, AF_INET); + qDebug() << networkManager.replaceDefaultRoute(ifName, ifConf.getGateway(), 0, AF_INET); // check connectivity via tcp connection QTcpSocket *tcpSocket = new QTcpSocket(this); diff --git a/LogReceiver/networkdiscovery.h b/LogReceiver/networkdiscovery.h index 9a1441d..6efd926 100644 --- a/LogReceiver/networkdiscovery.h +++ b/LogReceiver/networkdiscovery.h @@ -14,7 +14,7 @@ #include #include "interfaceconfiguration.h" -#include "routemanager.h" +#include "networkmanager.h" //#include //#include #include "status.h" @@ -79,7 +79,7 @@ private: QNetworkConfigurationManager configurationManager; QNetworkAccessManager *accessManager; int numberOfProcesses; - routemanager rm; + NetworkManager networkManager; bool _userChoice; bool _blocked; diff --git a/LogReceiver/networkmanager.cpp b/LogReceiver/networkmanager.cpp new file mode 100644 index 0000000..9edcf5e --- /dev/null +++ b/LogReceiver/networkmanager.cpp @@ -0,0 +1,178 @@ +/* + * networkmanager.cpp + * + * Created on: Sep 5, 2011 + * Author: niklas + */ + +#include "networkmanager.h" + +NetworkManager::NetworkManager() { + // TODO Auto-generated constructor stub + +} + +NetworkManager::~NetworkManager() { + // TODO Auto-generated destructor stub +} + +/** + * This method adds /replaces the default route. + * This method adds /replaces the default route. + * To keep it modular, it is possible + * to specify an ip address family. + * + * @param ifName + * the interface name + * + * @param gateway + * the gateway address (e.g: 192.168.0.254) + * @param mss + * the mss. + * @param af + * specify the family type of the ip address. + * possible values are: AF_INET for an IPv4 address + * AF_INET6 for an IPv6 address + * + + * @return + * return -1 if an error happened. + * return 0 if everything was ok. + */ +int NetworkManager::replaceDefaultRoute(QString ifname, QString gateway, + int mss, int af) { + struct nl_cache *cache; + struct nl_handle* rtsock; + struct nl_addr * gw; + struct rtnl_route * route; + int retval, iface_idx; + + QByteArray ba_ifn = ifname.toAscii(); + char * ifn = ba_ifn.data(); + + QByteArray ba_gw = gateway.toAscii(); + char * gwaddr = ba_gw.data(); + + qDebug() << "---doRoute() gwaddr" << gwaddr; + + if (!(gw = nl_addr_parse(gwaddr, af))) { + qDebug() << "Invalid router address given: %s\n", gwaddr; + return -1; + } + + rtsock = nl_handle_alloc(); + nl_connect(rtsock, NETLINK_ROUTE); + + if ((cache = rtnl_link_alloc_cache(rtsock)) == NULL) { + qDebug() << "error with link cache alloc \n"; + } + + iface_idx = rtnl_link_name2i(cache, ifn); + + route = rtnl_route_alloc(); + rtnl_route_set_scope(route, RT_SCOPE_UNIVERSE); + rtnl_route_set_gateway(route, gw); + rtnl_route_set_oif(route, iface_idx); + + if (mss > 0) { + rtnl_route_set_metric(route, RTAX_ADVMSS, mss); + } + + retval = rtnl_route_add(rtsock, route, NLM_F_REPLACE); + qDebug() << "return value:" << retval << ":" << strerror(-retval); + + rtnl_route_put(route); + nl_addr_put(gw); + nl_handle_destroy(rtsock); + + return retval; +} +/** + * This method brings an interface up or down. + * + * @param ifname + * is a string which contains the interface name which is going down or up. + * + * @param up + * is a bool. true means. we bring the interface up. + * false meand. we bring the interface down. + * @return + * 0 if everything is ok + * else an error + */ +int NetworkManager::bringInterfaceUpDown(QString ifname, bool up) { + struct nl_cache *cache; + struct nl_handle* rtsock; + struct rtnl_link* request = NULL; + struct rtnl_link* old = NULL; + int retval; + + QByteArray ba_ifn = ifname.toAscii(); + char * ifn = ba_ifn.data(); + + if(!(request = rtnl_link_alloc())) { + qDebug() << "error. couldn't allocate a rtnl link"; + return -1; + } + + rtsock = nl_handle_alloc(); + nl_connect(rtsock, NETLINK_ROUTE); + + if(up) { + rtnl_link_set_flags(request,IFF_UP); + } else { + rtnl_link_unset_flags(request, IFF_UP); + } + + if ((cache = rtnl_link_alloc_cache(rtsock)) == NULL) { + qDebug() << "error with link cache alloc "; + } + + old = rtnl_link_get_by_name(cache,ifn); + if (old) { + qDebug() << "change link"; + retval = rtnl_link_change(rtsock, old, request, 0); + } else { + qDebug() << "change failed"; + retval = -1; + qDebug() << "return value:" << retval << ":" << strerror(-retval); + } + + + rtnl_link_put(old); + rtnl_link_put(request); + nl_handle_destroy(rtsock); + + return retval; +} + +/** + * This method adds or deletes a route. + * This method adds or deletes a route. According to the action, + * you can delete a route or add a route from/to the + * main routing table. In most cases, this method will be used for deleting + * or adding a default rout. To keep it modular, it is possible + * to specify an ip address family. + * + * @param ifName + * the interface name. + * @param destination + * the destination address (e.g: 0.0.0.0) + * + * @param gateway + * the gateway address (e.g: 192.168.0.254) + * + * @param af + * specify the family type of the ip address. + * possible values are: AF_INET for an IPv4 address + * AF_INET6 for an IPv6 address + * + * @param action + * possible values are: 0: perform add route + * 1: perform delete route + * + * @return + * return 1 if an error happened. + * return 0 if everything was ok. + */ +int NetworkManager::doRoute(QString ifName, QString destination, QString gateway, int af, int action) {return 0;} diff --git a/LogReceiver/networkmanager.h b/LogReceiver/networkmanager.h new file mode 100644 index 0000000..edcce28 --- /dev/null +++ b/LogReceiver/networkmanager.h @@ -0,0 +1,40 @@ +/* + * networkmanager.h + * + * Created on: Sep 5, 2011 + * Author: niklas + */ + +#ifndef NETWORKMANAGER_H_ +#define NETWORKMANAGER_H_ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +class NetworkManager: public QObject { +Q_OBJECT + +public: + NetworkManager(); + virtual ~NetworkManager(); + + + int doRoute(QString ifName, QString destination, QString gateway, int af, + int action); + int replaceDefaultRoute(QString ifname, QString gateway, int metric, + int af); + int bringInterfaceUpDown(QString ifname, bool up); + +private: + +}; + +#endif /* NETWORKMANAGER_H_ */ diff --git a/LogReceiver/routemanager.cpp b/LogReceiver/routemanager.cpp deleted file mode 100644 index aa12fa3..0000000 --- a/LogReceiver/routemanager.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/* - * routemanager.cpp - * - * Created on: Sep 5, 2011 - * Author: niklas - */ - -#include "routemanager.h" - -routemanager::routemanager() { - // TODO Auto-generated constructor stub - -} - -routemanager::~routemanager() { - // TODO Auto-generated destructor stub -} - -/** - * This method adds /replaces the default route. - * This method adds /replaces the default route. - * To keep it modular, it is possible - * to specify an ip address family. - * - * @param ifName - * the interface name - * - * @param gateway - * the gateway address (e.g: 192.168.0.254) - * @param mss - * the mss. - * @param af - * specify the family type of the ip address. - * possible values are: AF_INET for an IPv4 address - * AF_INET6 for an IPv6 address - * - - * @return - * return -1 if an error happened. - * return 0 if everything was ok. - */ -int routemanager::replaceDefaultRoute(QString ifname, QString gateway, - int mss, int af) { - struct nl_cache *cache; - struct nl_handle* rtsock; - struct nl_addr * gw; - struct rtnl_route * route; - int retval, iface_idx; - - QByteArray ba_ifn = ifname.toAscii(); - char * ifn = ba_ifn.data(); - - QByteArray ba_gw = gateway.toAscii(); - char * gwaddr = ba_gw.data(); - - qDebug() << "---doRoute() gwaddr" << gwaddr; - - if (!(gw = nl_addr_parse(gwaddr, af))) { - qDebug() << "Invalid router address given: %s\n", gwaddr; - return -1; - } - - rtsock = nl_handle_alloc(); - nl_connect(rtsock, NETLINK_ROUTE); - - if ((cache = rtnl_link_alloc_cache(rtsock)) == NULL) { - qDebug() << "error with link cache alloc \n"; - } - - iface_idx = rtnl_link_name2i(cache, ifn); - - route = rtnl_route_alloc(); - rtnl_route_set_scope(route, RT_SCOPE_UNIVERSE); - rtnl_route_set_gateway(route, gw); - rtnl_route_set_oif(route, iface_idx); - - if (mss > 0) { - rtnl_route_set_metric(route, RTAX_ADVMSS, mss); - } - - retval = rtnl_route_add(rtsock, route, NLM_F_REPLACE); - qDebug() << "return value:" << retval << ":" << strerror(-retval); - - rtnl_route_put(route); - nl_addr_put(gw); - nl_handle_destroy(rtsock); - - return retval; -} -/** - * This method brings an interface up or down. - * - * @param ifname - * is a string which contains the interface name which is going down or up. - * - * @param up - * is a bool. true means. we bring the interface up. - * false meand. we bring the interface down. - * @return - * 0 if everything is ok - * else an error - */ -int routemanager::bringInterfaceUpDown(QString ifname, bool up) { - struct nl_cache *cache; - struct nl_handle* rtsock; - struct rtnl_link* request = NULL; - struct rtnl_link* old = NULL; - int retval; - - QByteArray ba_ifn = ifname.toAscii(); - char * ifn = ba_ifn.data(); - - if(!(request = rtnl_link_alloc())) { - qDebug() << "error. couldn't allocate a rtnl link"; - return -1; - } - - rtsock = nl_handle_alloc(); - nl_connect(rtsock, NETLINK_ROUTE); - - if(up) { - rtnl_link_set_flags(request,IFF_UP); - } else { - rtnl_link_unset_flags(request, IFF_UP); - } - - if ((cache = rtnl_link_alloc_cache(rtsock)) == NULL) { - qDebug() << "error with link cache alloc "; - } - - old = rtnl_link_get_by_name(cache,ifn); - if (old) { - qDebug() << "change link"; - rtnl_link_change(rtsock, old, request, 0); - } else { - qDebug() << "change failed"; - } - - retval = 0; - - rtnl_link_put(old); - rtnl_link_put(request); - nl_handle_destroy(rtsock); - - return retval; -} - -/** - * This method adds or deletes a route. - * This method adds or deletes a route. According to the action, - * you can delete a route or add a route from/to the - * main routing table. In most cases, this method will be used for deleting - * or adding a default rout. To keep it modular, it is possible - * to specify an ip address family. - * - * @param ifName - * the interface name. - * @param destination - * the destination address (e.g: 0.0.0.0) - * - * @param gateway - * the gateway address (e.g: 192.168.0.254) - * - * @param af - * specify the family type of the ip address. - * possible values are: AF_INET for an IPv4 address - * AF_INET6 for an IPv6 address - * - * @param action - * possible values are: 0: perform add route - * 1: perform delete route - * - * @return - * return 1 if an error happened. - * return 0 if everything was ok. - */ -int routemanager::doRoute(QString ifName, QString destination, QString gateway, int af, int action) {return 0;} diff --git a/LogReceiver/routemanager.h b/LogReceiver/routemanager.h deleted file mode 100644 index fc26145..0000000 --- a/LogReceiver/routemanager.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * routemanager.h - * - * Created on: Sep 5, 2011 - * Author: niklas - */ - -#ifndef ROUTEMANAGER_H_ -#define ROUTEMANAGER_H_ - -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -class routemanager: public QObject { -Q_OBJECT - -public: - routemanager(); - virtual ~routemanager(); - - - int doRoute(QString ifName, QString destination, QString gateway, int af, - int action); - int replaceDefaultRoute(QString ifname, QString gateway, int metric, - int af); - int bringInterfaceUpDown(QString ifname, bool up); - -private: - -}; - -#endif /* ROUTEMANAGER_H_ */ -- cgit v1.2.3-55-g7522