]> git.meshlink.io Git - meshlink/commitdiff
Merge branch 'master' into saverio
authorSaverio Proto <zioproto@gmail.com>
Sun, 13 Apr 2014 10:41:45 +0000 (12:41 +0200)
committerSaverio Proto <zioproto@gmail.com>
Sun, 13 Apr 2014 10:41:45 +0000 (12:41 +0200)
Conflicts:
src/libmeshlink.c

meshlink-sample/fixlib.txt [new file with mode: 0644]
src/libmeshlink.c
src/libmeshlink.h
src/route.c

diff --git a/meshlink-sample/fixlib.txt b/meshlink-sample/fixlib.txt
new file mode 100644 (file)
index 0000000..e230dcd
--- /dev/null
@@ -0,0 +1,3 @@
+MYPATH=`pwd`
+echo $MYPATH
+export LD_LIBRARY_PATH=$MYPATH'/../src/.libs/'
index 761b3a4137b76202986deaf039d9b2ce07830575..db0362b1e89680ae62ea54abdd44517fa0544a8c 100644 (file)
@@ -466,57 +466,30 @@ end:
 
 bool tinc_stop();
 
-bool route_meshlink(node_t *source,vpn_packet_t *packet) {
-
-       printf("data %s\n",packet->data);
-       printf("data 16%s\n",packet->data+16);
-       printf("data 32%s\n",packet->data+32);
-       node_t* owner = NULL;
-
-       tincpackethdr* hdr = (tincpackethdr*)packet->data;
-       owner = lookup_node(hdr->destination);
-
-       if (owner == NULL) {
-       //Lookup failed
-       printf("NULL\n");
-       return false;
-       }
-       printf("lookupnode %s\n",owner->name);
-
-       if(!owner->status.reachable) {
-       //Do some here
-       return false;
-       }
-
-       //TODO: I skipped here a lot of checks !
-
-       send_packet(owner,packet);
-
-}
 // can be called from any thread
 bool tinc_send_packet(node_t *receiver, const char* buf, unsigned int len) {
 
        vpn_packet_t packet;
        tincpackethdr* hdr = malloc(sizeof(tincpackethdr));
-
-       if (sizeof(hdr) + len > MAXSIZE) {
+       if (sizeof(tincpackethdr) + len > MAXSIZE) {
 
        //log something
        return false;
        }
 
+       memset(hdr->legacymtu,1,sizeof(hdr->legacymtu));
        memcpy(hdr->destination,receiver->name,sizeof(hdr->destination));
        memcpy(hdr->source,myself->name,sizeof(hdr->source));
 
        packet.priority = 0;
-       packet.len = len + 32;
+       packet.len = sizeof(tincpackethdr) + len;
 
-       memcpy(packet.data,hdr,32);
-       memcpy(packet.data+32,buf,len);
+       memcpy(packet.data,hdr,sizeof(tincpackethdr));
+       memcpy(packet.data+sizeof(tincpackethdr),buf,len);
 
         myself->in_packets++;
         myself->in_bytes += packet.len;
-        route_meshlink(myself, &packet);
+        route(myself, &packet);
 
 return true;
 }
index 7cbd6374e303fd76b44721ced426ccb17a593a8e..af1c1bab07c4ebe9bba6cf643638d34c8ce4857a 100644 (file)
@@ -41,6 +41,7 @@ bool tinc_start(const char* path);
 bool tinc_stop();
 
 typedef struct tincpackethdr {
+  u_int8_t legacymtu[14];
   u_int8_t destination[16];
   u_int8_t source[16];
 } __attribute__ ((__packed__)) tincpackethdr;
index 28fdfa894112c284a8aba3b087d7144c849d27aa..f09a1041f1f8aca3561a49001fc74680180462af 100644 (file)
@@ -23,6 +23,7 @@
 #include "net.h"
 #include "route.h"
 #include "utils.h"
+#include "libmeshlink.h"
 
 rmode_t routing_mode = RMODE_ROUTER;
 fmode_t forwarding_mode = FMODE_INTERNAL;
@@ -58,6 +59,32 @@ static bool checklength(node_t *source, vpn_packet_t *packet, length_t length) {
                return true;
 }
 
-void route(node_t *source, vpn_packet_t *packet) {
-       // TODO: route on name or key
+void route(node_t *source,vpn_packet_t *packet) {
+    // TODO: route on name or key
+
+    node_t* owner = NULL;
+    tincpackethdr* hdr = (tincpackethdr*)packet->data;
+    owner = lookup_node(hdr->destination);
+    if (owner == NULL) {
+    //Lookup failed
+    logger(DEBUG_TRAFFIC, LOG_WARNING, "Cant lookup the owner of a packet in the route() function. This should never happen \n");
+    return;
+    }
+
+    if (owner == myself ) {
+    //TODO: implement sending received data from meshlink library to the application
+    logger(DEBUG_TRAFFIC, LOG_WARNING, "I received a packet for me with payload: %s \n", packet->data + 46);
+    return;
+    }
+
+    if(!owner->status.reachable) {
+    //TODO: check what to do here, not just print a warning
+    logger(DEBUG_TRAFFIC, LOG_WARNING, "The owner of a packet in the route() function is unreachable. Dropping packet. \n");
+    return;
+    }
+
+    //TODO: I skipped here a lot of checks !
+
+    send_packet(owner,packet);
+    return;
 }