]> git.meshlink.io Git - meshlink/commitdiff
Merge remote-tracking branch 'origin/master' into saverio saverio
authorSaverio Proto <zioproto@gmail.com>
Thu, 17 Apr 2014 22:19:30 +0000 (00:19 +0200)
committerSaverio Proto <zioproto@gmail.com>
Thu, 17 Apr 2014 22:19:30 +0000 (00:19 +0200)
src/route.c

index e4007b4715a9d99093863d4cf6b9b50cf6501222..cffb7d25ab491cf6c31590e6570a826de75afc1c 100644 (file)
@@ -63,11 +63,19 @@ void route(node_t *source,vpn_packet_t *packet) {
     // TODO: route on name or key
 
     node_t* owner = NULL;
+    node_t* via = NULL;
     tincpackethdr* hdr = (tincpackethdr*)packet->data;
     owner = lookup_node(hdr->destination);
+    logger(DEBUG_TRAFFIC, LOG_WARNING, "Routing packet from: %s . To: %s \n",hdr->source,hdr->destination);
+
+    //Check Lenght
+    if(!checklength(source, packet, (sizeof(tincpackethdr))))
+        return;
+
     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");
+    logger(DEBUG_TRAFFIC, LOG_WARNING, "Destination was: %s \n",hdr->destination);
     return;
     }
 
@@ -84,7 +92,16 @@ void route(node_t *source,vpn_packet_t *packet) {
     return;
     }
 
-    //TODO: I skipped here a lot of checks !
+    via = (owner->via == myself) ? owner->nexthop : owner->via;
+    if(via == source) {
+       logger(DEBUG_TRAFFIC, LOG_ERR, "Routing loop for packet from %s (%s)!", source->name, source->hostname);
+       return;
+    }
+
+    if (directonly && owner!=via) {
+    logger(DEBUG_TRAFFIC, LOG_WARNING, "Direct Only is requested. Dropping packet because direct connection not available \n");
+    return;
+    }
 
     send_packet(owner,packet);
     return;