-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;
- }
+void route(meshlink_handle_t *mesh, node_t *source, vpn_packet_t *packet) {
+ // TODO: route on name or key
+
+ node_t *owner = NULL;
+ node_t *via = NULL;
+ meshlink_packethdr_t *hdr = (meshlink_packethdr_t *) packet->data;
+ owner = lookup_node(mesh, (char *)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(meshlink_packethdr_t))))
+ 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;
+ }