From 3c77242bd1b1849c581263a57c4f7cd96f7dd450 Mon Sep 17 00:00:00 2001 From: Niklas Date: Fri, 23 Sep 2011 14:58:44 +0200 Subject: added a function to the routemanager (which will soon be renamed into networkmanager) to bring up and down interfaces. --- LogReceiver/html/networkdiscovery.css | 7 +++++ LogReceiver/routemanager.cpp | 49 +++++++++++++++++++++++++++++++++-- LogReceiver/routemanager.h | 1 + 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/LogReceiver/html/networkdiscovery.css b/LogReceiver/html/networkdiscovery.css index fc1c514..8e6b364 100644 --- a/LogReceiver/html/networkdiscovery.css +++ b/LogReceiver/html/networkdiscovery.css @@ -17,6 +17,10 @@ header, footer, aside { display: block; } +#intro { + margin: 20px; +} + #content { display: table; width: 100%; @@ -34,6 +38,9 @@ aside { width: 300px; } +h1 { + margin-top: 20px; +} h1, p{ color:#333; diff --git a/LogReceiver/routemanager.cpp b/LogReceiver/routemanager.cpp index 98ce2ad..ceb9b28 100644 --- a/LogReceiver/routemanager.cpp +++ b/LogReceiver/routemanager.cpp @@ -56,7 +56,7 @@ int routemanager::replaceDefaultRoute(QString ifname, QString gateway, qDebug() << "---doRoute() gwaddr" << gwaddr; if (!(gw = nl_addr_parse(gwaddr, af))) { - printf("Invalid router address given: %s\n", gwaddr); + qDebug() << "Invalid router address given: %s\n", gwaddr; return -1; } @@ -64,7 +64,7 @@ int routemanager::replaceDefaultRoute(QString ifname, QString gateway, nl_connect(rtsock, NETLINK_ROUTE); if ((cache = rtnl_link_alloc_cache(rtsock)) == NULL) { - printf("error with link cache alloc \n"); + qDebug() << "error with link cache alloc \n"; } iface_idx = rtnl_link_name2i(cache, ifn); @@ -88,6 +88,51 @@ int routemanager::replaceDefaultRoute(QString ifname, QString gateway, return retval; } +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, diff --git a/LogReceiver/routemanager.h b/LogReceiver/routemanager.h index ee48122..fc26145 100644 --- a/LogReceiver/routemanager.h +++ b/LogReceiver/routemanager.h @@ -31,6 +31,7 @@ public: int action); int replaceDefaultRoute(QString ifname, QString gateway, int metric, int af); + int bringInterfaceUpDown(QString ifname, bool up); private: -- cgit v1.2.3-55-g7522