summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--LogReceiver/CMakeLists.txt4
-rw-r--r--LogReceiver/routemanager.cpp114
-rw-r--r--LogReceiver/routemanager.h14
-rw-r--r--src/html/networkdiscovery.css105
-rw-r--r--src/html/networkdiscovery.html18
5 files changed, 241 insertions, 14 deletions
diff --git a/LogReceiver/CMakeLists.txt b/LogReceiver/CMakeLists.txt
index 1cd1686..690ecf4 100644
--- a/LogReceiver/CMakeLists.txt
+++ b/LogReceiver/CMakeLists.txt
@@ -24,6 +24,8 @@ file(GLOB LOGRECEIVER_RCS ./*.qrc)
include_directories(${CMAKE_CURRENT_BINARY_DIR}
/usr/include/
+ /usr/include/netlink/
+ /usr/include/netlink/route/
./../customdhcpcd/src/
./build
${QT_INCLUDES}
@@ -54,4 +56,4 @@ add_executable(LogReceiver
target_link_libraries(LogReceiver
${QT_LIBRARIES}
- sysfs customdhcpcd)
+ sysfs customdhcpcd nl)
diff --git a/LogReceiver/routemanager.cpp b/LogReceiver/routemanager.cpp
index d3d5139..6328c21 100644
--- a/LogReceiver/routemanager.cpp
+++ b/LogReceiver/routemanager.cpp
@@ -5,7 +5,6 @@
* Author: niklas
*/
-
#include "routemanager.h"
routemanager::routemanager() {
@@ -17,20 +16,115 @@ routemanager::~routemanager() {
// TODO Auto-generated destructor stub
}
-void routemanager::addRoute(QString ifname, QString destination, QString netmask, QString gateway, int metric) {
+int routemanager::addRoute(QString ifname, QString destination,
+ QString netmask, QString gateway, int metric) {
+ //struct in_addr destination, netmask, gateway;
+ //add_route();
+ return doRoute(destination, gateway, AF_INET, 0);
+}
+
+int routemanager::addRoute6(QString ifname, QString destination,
+ QString netmask, QString gateway, int metric) {
//struct in_addr destination, netmask, gateway;
//add_route();
+ return doRoute(destination, gateway, AF_INET6, 0);
+}
+
+int routemanager::delRoute(QString ifname, QString destination,
+ QString netmask, QString gateway, int metric) {
+ /*struct in_addr ds, nm, gw;
+ ba = ifname.toAscii();
+ const char *in = ba.constData();
+ inet_aton("0.0.0.0", &ds);
+ inet_aton("0.0.0.0", &nm);
+ ba = gateway.toAscii();
+ char * gwaddr = ba.data();
+ inet_aton(gwaddr,&gw);
+ del_route(in, ds, nm, gw, metric);
+ */
+ return doRoute(destination, gateway, AF_INET, 1);
+}
+
+int routemanager::delRoute6(QString ifname, QString destination,
+ QString netmask, QString gateway, int metric) {
+ return doRoute(destination, gateway, AF_INET6, 1);
}
-void routemanager::delRoute(QString ifname, QString destination, QString netmask, QString gateway, int metric) {
- struct in_addr ds, nm, gw;
- ba = ifname.toAscii();
- const char *in = ba.constData();
- inet_aton("0.0.0.0", &ds);
- inet_aton("0.0.0.0", &nm);
+/**
+ * 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 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 destination, QString gateway, int af, int action) {
+ struct nl_handle* rtsock;
+ struct nl_addr * dst;
+ struct nl_addr * gw;
+ struct rtnl_route * route;
+ int retval;
+
+ ba = destination.toAscii();
+ char *dstaddr = ba.data();
+
ba = gateway.toAscii();
char * gwaddr = ba.data();
- inet_aton(gwaddr,&gw);
- del_route(in, ds, nm, gw, metric);
+
+ if (!(dst = nl_addr_parse(dstaddr, af))) {
+ qDebug() << "Invalid network address given:" << dstaddr;
+ return 1;
+ }
+ if (!(gw = nl_addr_parse(gwaddr, af))) {
+ qDebug() << "Invalid router address given: " << gwaddr;
+ nl_addr_put(dst);
+ return 1;
+ }
+
+ route = rtnl_route_alloc();
+ rtnl_route_set_family(route, af);
+ rtnl_route_set_scope(route, RT_SCOPE_UNIVERSE);
+ rtnl_route_set_dst(route, dst);
+ rtnl_route_set_gateway(route, gw);
+
+ rtsock = nl_handle_alloc();
+ nl_connect(rtsock, NETLINK_ROUTE);
+
+ if (action == 0) {
+ rtnl_route_add(rtsock, route, 0);
+ }
+ else if (action == 1) {
+ rtnl_route_del(rtsock, route, 0);
+ }
+ else {
+ qDebug() << "unknown action:" << action;
+ }
+
+
+ rtnl_route_put(route);
+ nl_addr_put(dst);
+ nl_addr_put(gw);
+ nl_handle_destroy(rtsock);
+
+ return 0;
}
diff --git a/LogReceiver/routemanager.h b/LogReceiver/routemanager.h
index 3bbe021..01530c7 100644
--- a/LogReceiver/routemanager.h
+++ b/LogReceiver/routemanager.h
@@ -10,7 +10,9 @@
#include <arpa/inet.h>
#include <interface.h>
-
+#include <netlink/netlink.h>
+#include <netlink/route/route.h>
+#include <errno.h>
#include <QtCore>
class routemanager : public QObject{
@@ -20,8 +22,14 @@ public:
routemanager();
virtual ~routemanager();
- void addRoute(QString ifname, QString destination, QString netmask, QString gateway, int metric);
- void delRoute(QString ifname, QString destination, QString netmask, QString gateway, int metric);
+ int addRoute(QString ifname, QString destination, QString netmask, QString gateway, int metric);
+ int delRoute(QString ifname, QString destination, QString netmask, QString gateway, int metric);
+
+ int addRoute6(QString ifname, QString destination,
+ QString netmask, QString gateway, int metric);
+ int delRoute6(QString ifname, QString destination,
+ QString netmask, QString gateway, int metric);
+ int doRoute(QString destination, QString gateway, int af, int action);
private:
QByteArray ba;
diff --git a/src/html/networkdiscovery.css b/src/html/networkdiscovery.css
new file mode 100644
index 0000000..c6f703a
--- /dev/null
+++ b/src/html/networkdiscovery.css
@@ -0,0 +1,105 @@
+html,body{
+ height:100%;
+}
+body{
+ margin:0;
+ padding:0;
+ background-color:blue;
+ /*
+ background-image:url('background.png');
+ background-repeat:no-repeat;
+ */
+ background-size:100%;
+}
+#top{
+ position:absolute;
+}
+#message{
+ position:absolute;
+ top:37%;
+ width:100%;
+ font-size:90%;
+}
+h1, p{
+ color:white;
+ text-align:center;
+}
+#container{
+ min-height:100%;
+ margin-bottom:-50px;
+}
+* html #container{
+ height:100%;
+}
+#footer-spacer{
+ height:0px;
+}
+#footer{
+ height:30px;
+}
+/* animation */
+/* position the bars and balls correctly (rotate them and translate them outward)*/
+.bar1 {
+ -moz-transform:rotate(0deg) translate(0, -40px);
+ -webkit-transform:rotate(0deg) translate(0, -40px);opacity:0.12;
+}
+.bar2 {
+ -moz-transform:rotate(45deg) translate(0, -40px);
+ -webkit-transform:rotate(45deg) translate(0, -40px);opacity:0.25;
+}
+.bar3 {
+ -moz-transform:rotate(90deg) translate(0, -40px);
+ -webkit-transform:rotate(90deg) translate(0, -40px);opacity:0.37;
+}
+.bar4 {
+ -moz-transform:rotate(135deg) translate(0, -40px);
+ -webkit-transform:rotate(135deg) translate(0, -40px);opacity:0.50;
+}
+.bar5 {
+ -moz-transform:rotate(180deg) translate(0, -40px);
+ -webkit-transform:rotate(180deg) translate(0, -40px);opacity:0.62;
+}
+.bar6 {
+ -moz-transform:rotate(225deg) translate(0, -40px);
+ -webkit-transform:rotate(225deg) translate(0, -40px);opacity:0.75;
+}
+.bar7 {
+ -moz-transform:rotate(270deg) translate(0, -40px);
+ -webkit-transform:rotate(270deg) translate(0, -40px);opacity:0.87;
+}
+.bar8 {
+ -moz-transform:rotate(315deg) translate(0, -40px);
+ -webkit-transform:rotate(315deg) translate(0, -40px);opacity:1;
+}
+#div4 {
+ position:absolute;
+ left:50%;
+ top:50%;
+ margin-left:-50px;
+ margin-top:-50px;
+ width:100px;
+ height:100px;
+ -moz-border-radius:100px;
+ -webkit-border-radius:100px;
+ -moz-transform:scale(0.5);
+ -webkit-transform:scale(0.5);
+ -webkit-animation-name: rotateThis;
+ -webkit-animation-duration:2s;
+ -webkit-animation-iteration-count:infinite;
+ -webkit-animation-timing-function:linear;
+}
+#div4 div {
+ width:20px;
+ height:20px;
+ background:#fff;
+ -moz-border-radius:40px;
+ -webkit-border-radius:40px;
+ position:absolute;
+ left:40px;
+ top:40px;
+}
+/* add a shadow to the first */
+#div4 div {
+ -moz-box-shadow:black 0 0 4px;
+ -webkit-box-shadow:black 0 0 4px;
+}
diff --git a/src/html/networkdiscovery.html b/src/html/networkdiscovery.html
new file mode 100644
index 0000000..2c2e942
--- /dev/null
+++ b/src/html/networkdiscovery.html
@@ -0,0 +1,18 @@
+<html>
+<head>
+<link rel="stylesheet" type="text/css" href="networkdiscovery.css">
+</head>
+<body>
+<div id="top">
+</div>
+<div id="message">
+ <h1>Network Discovery</h1>
+</div>
+<div id="container">
+ <div id="footer-spacer"></div>
+</div>
+<div id="footer">
+ <p>RZ Uni Freiburg, 2011</p>
+</div>
+</body>
+</html>