handling replies continuously from server
[oweals/gnunet.git] / src / exit / gnunet-daemon-exit.c
index 3d94c9dba798fc7991181365d78907f417f0268b..e58611cc62b37fd68fc1981b2b9afa3f90281722 100644 (file)
@@ -284,7 +284,7 @@ static struct GNUNET_CONTAINER_Heap *connections_heap;
 /**
  * If there are at least this many connections, old ones will be removed
  */
-static long long unsigned int max_connections;
+static unsigned long long max_connections;
 
 /**
  * This hashmaps saves interesting things about the configured UDP services
@@ -395,7 +395,8 @@ get_redirect_state (int af,
   GNUNET_HashCode key;
   struct TunnelState *state;
 
-  if (protocol == IPPROTO_ICMP)
+  if ( ( (af == AF_INET) && (protocol == IPPROTO_ICMP) ) ||
+       ( (af == AF_INET6) && (protocol == IPPROTO_ICMPV6) ) )
   {
     /* ignore ports */
     destination_port = 0;
@@ -642,10 +643,10 @@ icmp_from_helper (const struct GNUNET_TUN_IcmpHeader *icmp,
      existing session from the IP data in the ICMP payload */
   source_port = 0;
   destination_port = 0;
-  protocol = IPPROTO_ICMP;
   switch (af)
   {
   case AF_INET:
+    protocol = IPPROTO_ICMP;
     switch (icmp->type)
       {
       case GNUNET_TUN_ICMPTYPE_ECHO_REPLY:
@@ -667,8 +668,9 @@ icmp_from_helper (const struct GNUNET_TUN_IcmpHeader *icmp,
        /* could be TCP or UDP, but both have the ports in the right
           place, so that doesn't matter here */
        udp = (const struct GNUNET_TUN_UdpHeader *) &ipv4[1];
-       source_port = ntohs (udp->source_port);
-       destination_port = ntohs (udp->destination_port);
+       /* swap ports, as they are from the original message */
+       destination_port = ntohs (udp->source_port);
+       source_port = ntohs (udp->destination_port);
        /* throw away ICMP payload, won't be useful for the other side anyway */
        pktlen = sizeof (struct GNUNET_TUN_IcmpHeader);
        break;
@@ -680,6 +682,7 @@ icmp_from_helper (const struct GNUNET_TUN_IcmpHeader *icmp,
       }
     break;
   case AF_INET6:
+    protocol = IPPROTO_ICMPV6;
     switch (icmp->type)
       {
       case GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE:
@@ -699,8 +702,9 @@ icmp_from_helper (const struct GNUNET_TUN_IcmpHeader *icmp,
        /* could be TCP or UDP, but both have the ports in the right
           place, so that doesn't matter here */
        udp = (const struct GNUNET_TUN_UdpHeader *) &ipv6[1];
-       source_port = ntohs (udp->source_port);
-       destination_port = ntohs (udp->destination_port);
+       /* swap ports, as they are from the original message */
+       destination_port = ntohs (udp->source_port);
+       source_port = ntohs (udp->destination_port);
        /* throw away ICMP payload, won't be useful for the other side anyway */
        pktlen = sizeof (struct GNUNET_TUN_IcmpHeader);
        break;
@@ -725,6 +729,12 @@ icmp_from_helper (const struct GNUNET_TUN_IcmpHeader *icmp,
                                destination_ip, 0,
                                NULL);
     break;
+  case IPPROTO_ICMPV6:
+    state = get_redirect_state (af, IPPROTO_ICMPV6,
+                               source_ip, 0,
+                               destination_ip, 0,
+                               NULL);
+    break;
   case IPPROTO_UDP:
     state = get_redirect_state (af, IPPROTO_UDP,
                                source_ip,
@@ -866,7 +876,7 @@ tcp_from_helper (const struct GNUNET_TUN_TcpHeader *tcp,
                 const void *source_ip)
 {
   struct TunnelState *state;
-  char buf[pktlen];
+  char buf[pktlen] GNUNET_ALIGN;
   struct GNUNET_TUN_TcpHeader *mtcp;
   struct GNUNET_EXIT_TcpDataMessage *tdm;
   struct TunnelMessageQueue *tnq;
@@ -1022,7 +1032,8 @@ message_token (void *cls GNUNET_UNUSED, void *client GNUNET_UNUSED,
        break;
       default:
        GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                   _("IPv4 packet with unsupported next header received.  Ignored.\n"));
+                   _("IPv4 packet with unsupported next header %u received.  Ignored.\n"),
+                   (int) pkt4->protocol);
        return;
       }
     }
@@ -1059,7 +1070,7 @@ message_token (void *cls GNUNET_UNUSED, void *client GNUNET_UNUSED,
                         &pkt6->destination_address, 
                         &pkt6->source_address);
        break;
-      case IPPROTO_ICMP:
+      case IPPROTO_ICMPV6:
        icmp_from_helper ((const struct GNUNET_TUN_IcmpHeader *) &pkt6[1], size,
                          AF_INET6,
                          &pkt6->destination_address, 
@@ -1067,7 +1078,8 @@ message_token (void *cls GNUNET_UNUSED, void *client GNUNET_UNUSED,
        break;
       default:
        GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                   _("IPv6 packet with unsupported next header received.  Ignored.\n"));
+                   _("IPv6 packet with unsupported next header %d received.  Ignored.\n"),
+                    pkt6->next_header);
        return;
       }
     }
@@ -1098,7 +1110,8 @@ setup_fresh_address (int af,
   local_address->proto = (uint8_t) proto;
   /* default "local" port range is often 32768--61000,
      so we pick a random value in that range */         
-  if (proto == IPPROTO_ICMP)
+  if ( ( (af == AF_INET) && (proto == IPPROTO_ICMP) ) ||
+       ( (af == AF_INET6) && (proto == IPPROTO_ICMPV6) ) )
     local_address->port = 0;
   else
     local_address->port 
@@ -1480,7 +1493,7 @@ send_tcp_packet_via_tun (const struct SocketAddress *destination_address,
     return;
   }
   {
-    char buf[len];
+    char buf[len] GNUNET_ALIGN;
     struct GNUNET_MessageHeader *hdr;
     struct GNUNET_TUN_Layer2PacketHeader *tun;
     
@@ -1839,7 +1852,7 @@ send_icmp_packet_via_tun (const struct SocketAddress *destination_address,
     return;
   }
   {
-    char buf[len];
+    char buf[len] GNUNET_ALIGN;
     struct GNUNET_MessageHeader *hdr;
     struct GNUNET_TUN_Layer2PacketHeader *tun;
     
@@ -1869,7 +1882,7 @@ send_icmp_packet_via_tun (const struct SocketAddress *destination_address,
        
        tun->proto = htons (ETH_P_IPV6);
        GNUNET_TUN_initialize_ipv6_header (ipv6,
-                                          IPPROTO_ICMP,
+                                          IPPROTO_ICMPV6,
                                           sizeof (struct GNUNET_TUN_IcmpHeader) + payload_length,
                                           &source_address->address.ipv6,
                                           &destination_address->address.ipv6);
@@ -1972,7 +1985,7 @@ receive_icmp_remote (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
   const struct in_addr *v4;
   const struct in6_addr *v6;  
   const void *payload;
-  char buf[sizeof (struct GNUNET_TUN_IPv6Header) + 8];
+  char buf[sizeof (struct GNUNET_TUN_IPv6Header) + 8] GNUNET_ALIGN;
   int af;
 
   GNUNET_STATISTICS_update (stats,
@@ -2076,7 +2089,7 @@ receive_icmp_remote (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
     if (NULL == state->heap_node)
     {
       state->ri.remote_address.af = af;
-      state->ri.remote_address.proto = IPPROTO_ICMP;
+      state->ri.remote_address.proto = IPPROTO_ICMPV6;
       setup_state_record (state);
     }
     /* check that ICMP type is something we want to support 
@@ -2214,7 +2227,7 @@ receive_icmp_service (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel
   const struct GNUNET_EXIT_IcmpServiceMessage *msg;
   uint16_t pkt_len = ntohs (message->size);
   struct GNUNET_TUN_IcmpHeader icmp;
-  char buf[sizeof (struct GNUNET_TUN_IPv6Header) + 8];
+  char buf[sizeof (struct GNUNET_TUN_IPv6Header) + 8] GNUNET_ALIGN;
   const void *payload;
 
   GNUNET_STATISTICS_update (stats,
@@ -2422,7 +2435,7 @@ send_udp_packet_via_tun (const struct SocketAddress *destination_address,
     return;
   }
   {
-    char buf[len];
+    char buf[len] GNUNET_ALIGN;
     struct GNUNET_MessageHeader *hdr;
     struct GNUNET_TUN_Layer2PacketHeader *tun;
     
@@ -3014,9 +3027,9 @@ run (void *cls, char *const *args GNUNET_UNUSED,
   if (GNUNET_YES !=
       GNUNET_OS_check_helper_binary ("gnunet-helper-exit"))
   {
-    fprintf (stderr,
-            "`%s' is not SUID, refusing to run.\n",
-            "gnunet-helper-exit");
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+               _("`%s' must be installed SUID, refusing to run\n"),
+               "gnunet-helper-exit");
     global_ret = 1;
     return;
   }