check
[oweals/gnunet.git] / src / vpn / gnunet-daemon-vpn-helper.c
index 9f8bc49f2bd518c7ae65d1ce66ca9bb912d906ce..fdb5dddaaed691eeed4780c3d0f0738728e85c8f 100644 (file)
@@ -40,6 +40,7 @@
 #include "gnunet-service-dns-p.h"
 #include "gnunet-vpn-packet.h"
 #include "gnunet-vpn-checksum.h"
+#include "gnunet-helper-vpn-api.h"
 
 struct GNUNET_VPN_HELPER_Handle *helper_handle;
 
@@ -185,7 +186,12 @@ helper_write(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tsdkctx) {
     GNUNET_CONTAINER_DLL_remove (answer_proc_head, answer_proc_tail, ans);
     GNUNET_free(ans);
 
-    /* FIXME */ GNUNET_DISK_file_write(helper_handle->fh_to_helper, pkt, pkt_len);
+    if (GNUNET_DISK_file_write(helper_handle->fh_to_helper, pkt, pkt_len) < 0)
+      {
+        cleanup_helper(helper_handle);
+        GNUNET_SCHEDULER_add_now(start_helper_and_schedule, NULL);
+        return;
+      }
 
     /* if more packets are available, reschedule */
     if (answer_proc_head != NULL)
@@ -248,8 +254,8 @@ message_token (void *cls,
                       sizeof (GNUNET_HashCode));
 
               if (0x11 == pkt6->ip6_hdr.nxthdr
-                  && me->
-                  desc.service_type & htonl (GNUNET_DNS_SERVICE_TYPE_UDP)
+                  && (me->desc.
+                      service_type & htonl (GNUNET_DNS_SERVICE_TYPE_UDP))
                   && (port_in_ports (me->desc.ports, pkt6_udp->udp_hdr.dpt)
                       || testBit (me->additional_ports,
                                   ntohs (pkt6_udp->udp_hdr.dpt))))
@@ -260,13 +266,11 @@ message_token (void *cls,
                           ntohs (pkt6_udp->udp_hdr.len));
 
                 }
-              else if (0x11 == pkt6->ip6_hdr.nxthdr
-                       && me->desc.
-                       service_type & htonl (GNUNET_DNS_SERVICE_TYPE_TCP)
+              else if (0x06 == pkt6->ip6_hdr.nxthdr
+                       && (me->desc.
+                           service_type & htonl (GNUNET_DNS_SERVICE_TYPE_TCP))
                        &&
-                       (port_in_ports (me->desc.ports, pkt6_tcp->tcp_hdr.dpt)
-                        && testBit (me->additional_ports,
-                                    ntohs (pkt6_tcp->tcp_hdr.spt))))
+                       (port_in_ports (me->desc.ports, pkt6_tcp->tcp_hdr.dpt)))
                 {
                   hdr->type = ntohs (GNUNET_MESSAGE_TYPE_SERVICE_TCP);
 
@@ -276,6 +280,9 @@ message_token (void *cls,
                 }
               else
                 {
+                  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Dropping packet. nxthdr=%d, type=%d, dpt=%x, flg=%d, ports=%x\n",
+                             pkt6->ip6_hdr.nxthdr, ntohl(me->desc.service_type),
+                             ntohs(pkt6_tcp->tcp_hdr.dpt), pkt6_tcp->tcp_hdr.flg, me->desc.ports);
                   GNUNET_free (cls);
                   cls = NULL;
                 }
@@ -297,10 +304,10 @@ message_token (void *cls,
                   *cls = me->tunnel;
                   send_pkt_to_peer (cls, (struct GNUNET_PeerIdentity *) 1,
                                     NULL);
+                  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                              "Queued to send to peer %x, type %d\n",
+                              *((unsigned int *) &me->desc.peer), ntohs(hdr->type));
                 }
-              GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                          "Queued to send to peer %x\n",
-                          *((unsigned int *) &me->desc.peer));
             }
           break;
         case 0x3a: