fix bug in -vpn
authorPhilipp Tölke <toelke@in.tum.de>
Sun, 18 Sep 2011 11:59:13 +0000 (11:59 +0000)
committerPhilipp Tölke <toelke@in.tum.de>
Sun, 18 Sep 2011 11:59:13 +0000 (11:59 +0000)
src/vpn/gnunet-daemon-vpn-helper.c
src/vpn/gnunet-daemon-vpn.c

index 9ce1e2996ee76c76c709a49a84a42b72b40d1a54..eed073e07e19d13bb837afeddfb1b148a1153a3b 100644 (file)
@@ -296,7 +296,7 @@ message_token (void *cls __attribute__ ((unused)), void *client
               (port_in_ports (me->desc.ports, pkt6_udp->udp_hdr.dpt) ||
                testBit (me->additional_ports, ntohs (pkt6_udp->udp_hdr.dpt))))
           {
-            hdr->type = ntohs (GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP);
+            hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP);
 
             memcpy (hc + 1, &pkt6_udp->udp_hdr, ntohs (pkt6_udp->udp_hdr.len));
 
@@ -305,11 +305,16 @@ message_token (void *cls __attribute__ ((unused)), void *client
                    (me->desc.service_type & htonl (GNUNET_DNS_SERVICE_TYPE_TCP))
                    && (port_in_ports (me->desc.ports, pkt6_tcp->tcp_hdr.dpt)))
           {
-            hdr->type = ntohs (GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP);
+            hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP);
 
             memcpy (hc + 1, &pkt6_tcp->tcp_hdr, ntohs (pkt6->ip6_hdr.paylgth));
 
           }
+          else
+          {
+            GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "pip: %d\n", port_in_ports(me->desc.ports, pkt6_tcp->tcp_hdr.dpt));
+              GNUNET_assert(0);
+          }
           if (me->tunnel == NULL && NULL != cls)
           {
             *cls =
@@ -328,7 +333,7 @@ message_token (void *cls __attribute__ ((unused)), void *client
             *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",
+                        "Queued to send IPv6 to peer %x, type %d\n",
                         *((unsigned int *) &me->desc.peer), ntohs (hdr->type));
           }
         }
@@ -495,7 +500,7 @@ message_token (void *cls __attribute__ ((unused)), void *client
                 (port_in_ports (me->desc.ports, pkt_udp->udp_hdr.dpt) ||
                  testBit (me->additional_ports, ntohs (pkt_udp->udp_hdr.dpt))))
             {
-              hdr->type = ntohs (GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP);
+              hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP);
 
               memcpy (hc + 1, &pkt_udp->udp_hdr, ntohs (pkt_udp->udp_hdr.len));
 
@@ -505,7 +510,7 @@ message_token (void *cls __attribute__ ((unused)), void *client
                       desc.service_type & htonl (GNUNET_DNS_SERVICE_TYPE_TCP))
                      && (port_in_ports (me->desc.ports, pkt_tcp->tcp_hdr.dpt)))
             {
-              hdr->type = ntohs (GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP);
+              hdr->type = htons (GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP);
 
               memcpy (hc + 1, &pkt_tcp->tcp_hdr,
                       ntohs (pkt->ip_hdr.tot_lngth) -
@@ -530,7 +535,7 @@ message_token (void *cls __attribute__ ((unused)), void *client
               *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",
+                          "Queued to send IPv4 to peer %x, type %d\n",
                           *((unsigned int *) &me->desc.peer),
                           ntohs (hdr->type));
             }
index 47eb9cf82cd951f78c8b3f89b584fecdf687de0b..9c944ebef1699c1b982c4ec0d45fdb4d37a24870 100644 (file)
@@ -329,7 +329,7 @@ port_in_ports (uint64_t ports, uint16_t port)
 {
   uint16_t *ps = (uint16_t *) & ports;
 
-  return ps[0] == port || ps[1] == port || ps[2] == port || ps[3] == port;
+  return ports == 0 || ps[0] == port || ps[1] == port || ps[2] == port || ps[3] == port;
 }
 
 void
@@ -1056,7 +1056,10 @@ receive_tcp_back (void *cls
       ntohs (message->size) - sizeof (struct GNUNET_MessageHeader) -
       sizeof (GNUNET_HashCode);
 
-  if (s->addrlen == 16)
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received TCP-Packet back, addrlen = %d\n", s->addrlen);
+
+  if (ntohs(message->type) == GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP_BACK ||
+      s->addrlen == 16)
   {
     size_t size = pktlen + sizeof (struct ip6_tcp) - 1;