-updated libcurl API, do IPv4/IPv6 with separate sockets
[oweals/gnunet.git] / src / exit / gnunet-daemon-exit.c
index 5b1f5b6811f608742089942d1d6e10f7a16893f2..8d0c7f98e8f84ad9c4e1fce2ee631cb8bfbdf9d1 100644 (file)
@@ -678,7 +678,7 @@ hash_redirect_info (struct GNUNET_HashCode *hash,
  */
 static struct TunnelState *
 get_redirect_state (int af,
-                   int protocol,               
+                   int protocol,
                    const void *destination_ip,
                    uint16_t destination_port,
                    const void *local_ip,
@@ -1398,7 +1398,7 @@ setup_fresh_address (int af,
   local_address->af = af;
   local_address->proto = (uint8_t) proto;
   /* default "local" port range is often 32768--61000,
-     so we pick a random value in that range */        
+     so we pick a random value in that range */
   if ( ( (af == AF_INET) && (proto == IPPROTO_ICMP) ) ||
        ( (af == AF_INET6) && (proto == IPPROTO_ICMPV6) ) )
     local_address->port = 0;
@@ -1429,7 +1429,7 @@ setup_fresh_address (int af,
       do
        {
          rnd.s_addr = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
-                                                UINT32_MAX);   
+                                                UINT32_MAX);
          local_address->address.ipv4.s_addr = (addr.s_addr | rnd.s_addr) & mask.s_addr;
        }
       while ( (local_address->address.ipv4.s_addr == addr.s_addr) ||
@@ -1696,7 +1696,7 @@ prepare_ipv6_packet (const void *payload, size_t payload_length,
 
   GNUNET_TUN_initialize_ipv6_header (pkt6,
                                     protocol,
-                                    len,                               
+                                    len,
                                     &src_address->address.ipv6,
                                     &dst_address->address.ipv6);
 
@@ -1745,7 +1745,7 @@ prepare_ipv6_packet (const void *payload, size_t payload_length,
  * @param source_address IP and port to use for the TCP packet's source
  * @param tcp_header header template to use
  * @param payload payload of the TCP packet
- * @param payload_length number of bytes in 'payload'
+ * @param payload_length number of bytes in @a payload
  */
 static void
 send_tcp_packet_via_tun (const struct SocketAddress *destination_address,
@@ -1796,7 +1796,7 @@ send_tcp_packet_via_tun (const struct SocketAddress *destination_address,
     case AF_INET:
       {
        struct GNUNET_TUN_IPv4Header * ipv4 = (struct GNUNET_TUN_IPv4Header*) &tun[1];
-       
+
        tun->proto = htons (ETH_P_IPV4);
        prepare_ipv4_packet (payload, payload_length,
                             IPPROTO_TCP,
@@ -1809,7 +1809,7 @@ send_tcp_packet_via_tun (const struct SocketAddress *destination_address,
     case AF_INET6:
       {
        struct GNUNET_TUN_IPv6Header * ipv6 = (struct GNUNET_TUN_IPv6Header*) &tun[1];
-       
+
        tun->proto = htons (ETH_P_IPV6);
        prepare_ipv6_packet (payload, payload_length,
                             IPPROTO_TCP,
@@ -1818,7 +1818,7 @@ send_tcp_packet_via_tun (const struct SocketAddress *destination_address,
                             destination_address,
                             ipv6);
       }
-      break;   
+      break;
     default:
       GNUNET_assert (0);
       break;
@@ -1838,15 +1838,15 @@ send_tcp_packet_via_tun (const struct SocketAddress *destination_address,
  *
  * @param cls closure, NULL
  * @param tunnel connection to the other end
- * @param tunnel_ctx pointer to our 'struct TunnelState *'
+ * @param tunnel_ctx pointer to our `struct TunnelState *`
  * @param message the actual message
- *
- * @return GNUNET_OK to keep the connection open,
- *         GNUNET_SYSERR to close it (signal serious error)
+ * @return #GNUNET_OK to keep the connection open,
+ *         #GNUNET_SYSERR to close it (signal serious error)
  */
 static int
-receive_tcp_service (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
-                     void **tunnel_ctx GNUNET_UNUSED,
+receive_tcp_service (void *cls,
+                     struct GNUNET_MESH_Tunnel *tunnel,
+                     void **tunnel_ctx,
                      const struct GNUNET_MessageHeader *message)
 {
   struct TunnelState *state = *tunnel_ctx;
@@ -2054,9 +2054,8 @@ receive_tcp_remote (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
  * @param tunnel connection to the other end
  * @param tunnel_ctx pointer to our 'struct TunnelState *'
  * @param message the actual message
- *
- * @return GNUNET_OK to keep the connection open,
- *         GNUNET_SYSERR to close it (signal serious error)
+ * @return #GNUNET_OK to keep the connection open,
+ *         #GNUNET_SYSERR to close it (signal serious error)
  */
 static int
 receive_tcp_data (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
@@ -2067,16 +2066,6 @@ receive_tcp_data (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
   const struct GNUNET_EXIT_TcpDataMessage *data;
   uint16_t pkt_len = ntohs (message->size);
 
-  if (GNUNET_YES == state->is_dns)
-  {
-    GNUNET_break_op (0);
-    return GNUNET_SYSERR;
-  }
-  if (GNUNET_SYSERR == state->is_dns)
-  {
-    /* tunnel is UDP/TCP from now on */
-    state->is_dns = GNUNET_NO;
-  }
   GNUNET_STATISTICS_update (stats,
                            gettext_noop ("# Bytes received from MESH"),
                            pkt_len, GNUNET_NO);
@@ -2104,6 +2093,16 @@ receive_tcp_data (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
     GNUNET_break_op (0);
     return GNUNET_SYSERR;
   }
+  if (GNUNET_YES == state->is_dns)
+  {
+    GNUNET_break_op (0);
+    return GNUNET_SYSERR;
+  }
+  if (GNUNET_SYSERR == state->is_dns)
+  {
+    /* tunnel is UDP/TCP from now on */
+    state->is_dns = GNUNET_NO;
+  }
 
   GNUNET_break_op (ntohl (data->reserved) == 0);
   {
@@ -2133,7 +2132,7 @@ receive_tcp_data (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
  * @param source_address IP to use for the ICMP packet's source
  * @param icmp_header ICMP header to send
  * @param payload payload of the ICMP packet (does NOT include ICMP header)
- * @param payload_length number of bytes of data in payload
+ * @param payload_length number of bytes of data in @a payload
  */
 static void
 send_icmp_packet_via_tun (const struct SocketAddress *destination_address,
@@ -2185,7 +2184,7 @@ send_icmp_packet_via_tun (const struct SocketAddress *destination_address,
     case AF_INET:
       {
        struct GNUNET_TUN_IPv4Header * ipv4 = (struct GNUNET_TUN_IPv4Header*) &tun[1];
-       
+
        tun->proto = htons (ETH_P_IPV4);
        GNUNET_TUN_initialize_ipv4_header (ipv4,
                                           IPPROTO_ICMP,
@@ -2198,7 +2197,7 @@ send_icmp_packet_via_tun (const struct SocketAddress *destination_address,
     case AF_INET6:
       {
        struct GNUNET_TUN_IPv6Header * ipv6 = (struct GNUNET_TUN_IPv6Header*) &tun[1];
-       
+
        tun->proto = htons (ETH_P_IPV6);
        GNUNET_TUN_initialize_ipv6_header (ipv6,
                                           IPPROTO_ICMPV6,
@@ -2207,7 +2206,7 @@ send_icmp_packet_via_tun (const struct SocketAddress *destination_address,
                                           &destination_address->address.ipv6);
        icmp = (struct GNUNET_TUN_IcmpHeader*) &ipv6[1];
       }
-      break;   
+      break;
     default:
       GNUNET_assert (0);
       break;
@@ -2287,13 +2286,13 @@ make_up_icmpv6_payload (struct TunnelState *state,
  * @param tunnel connection to the other end
  * @param tunnel_ctx pointer to our 'struct TunnelState *'
  * @param message the actual message
- *
- * @return GNUNET_OK to keep the connection open,
- *         GNUNET_SYSERR to close it (signal serious error)
+ * @return #GNUNET_OK to keep the connection open,
+ *         #GNUNET_SYSERR to close it (signal serious error)
  */
 static int
-receive_icmp_remote (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
-                    void **tunnel_ctx GNUNET_UNUSED,
+receive_icmp_remote (void *cls,
+                     struct GNUNET_MESH_Tunnel *tunnel,
+                    void **tunnel_ctx,
                     const struct GNUNET_MessageHeader *message)
 {
   struct TunnelState *state = *tunnel_ctx;
@@ -2538,12 +2537,12 @@ make_up_icmp_service_payload (struct TunnelState *state,
  * @param tunnel connection to the other end
  * @param tunnel_ctx pointer to our 'struct TunnelState *'
  * @param message the actual message
- *
- * @return GNUNET_OK to keep the connection open,
- *         GNUNET_SYSERR to close it (signal serious error)
+ * @return #GNUNET_OK to keep the connection open,
+ *         #GNUNET_SYSERR to close it (signal serious error)
  */
 static int
-receive_icmp_service (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
+receive_icmp_service (void *cls,
+                      struct GNUNET_MESH_Tunnel *tunnel,
                      void **tunnel_ctx,
                      const struct GNUNET_MessageHeader *message)
 {
@@ -2733,7 +2732,7 @@ receive_icmp_service (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel
  * @param destination_address IP and port to use for the UDP packet's destination
  * @param source_address IP and port to use for the UDP packet's source
  * @param payload payload of the UDP packet (does NOT include UDP header)
- * @param payload_length number of bytes of data in payload
+ * @param payload_length number of bytes of data in @a payload
  */
 static void
 send_udp_packet_via_tun (const struct SocketAddress *destination_address,
@@ -2783,7 +2782,7 @@ send_udp_packet_via_tun (const struct SocketAddress *destination_address,
     case AF_INET:
       {
        struct GNUNET_TUN_IPv4Header * ipv4 = (struct GNUNET_TUN_IPv4Header*) &tun[1];
-       
+
        tun->proto = htons (ETH_P_IPV4);
        prepare_ipv4_packet (payload, payload_length,
                             IPPROTO_UDP,
@@ -2796,7 +2795,7 @@ send_udp_packet_via_tun (const struct SocketAddress *destination_address,
     case AF_INET6:
       {
        struct GNUNET_TUN_IPv6Header * ipv6 = (struct GNUNET_TUN_IPv6Header*) &tun[1];
-       
+
        tun->proto = htons (ETH_P_IPV6);
        prepare_ipv6_packet (payload, payload_length,
                             IPPROTO_UDP,
@@ -2805,7 +2804,7 @@ send_udp_packet_via_tun (const struct SocketAddress *destination_address,
                             destination_address,
                             ipv6);
       }
-      break;   
+      break;
     default:
       GNUNET_assert (0);
       break;
@@ -2826,13 +2825,13 @@ send_udp_packet_via_tun (const struct SocketAddress *destination_address,
  * @param tunnel connection to the other end
  * @param tunnel_ctx pointer to our 'struct TunnelState *'
  * @param message the actual message
- *
- * @return GNUNET_OK to keep the connection open,
- *         GNUNET_SYSERR to close it (signal serious error)
+ * @return #GNUNET_OK to keep the connection open,
+ *         #GNUNET_SYSERR to close it (signal serious error)
  */
 static int
-receive_udp_remote (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
-                    void **tunnel_ctx GNUNET_UNUSED,
+receive_udp_remote (void *cls,
+                    struct GNUNET_MESH_Tunnel *tunnel,
+                    void **tunnel_ctx,
                     const struct GNUNET_MessageHeader *message)
 {
   struct TunnelState *state = *tunnel_ctx;
@@ -2937,12 +2936,12 @@ receive_udp_remote (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
  * @param tunnel connection to the other end
  * @param tunnel_ctx pointer to our 'struct TunnelState *'
  * @param message the actual message
- *
- * @return GNUNET_OK to keep the connection open,
- *         GNUNET_SYSERR to close it (signal serious error)
+ * @return #GNUNET_OK to keep the connection open,
+ *         #GNUNET_SYSERR to close it (signal serious error)
  */
 static int
-receive_udp_service (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
+receive_udp_service (void *cls,
+                     struct GNUNET_MESH_Tunnel *tunnel,
                      void **tunnel_ctx,
                      const struct GNUNET_MessageHeader *message)
 {
@@ -3012,8 +3011,10 @@ receive_udp_service (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
  * @return initial tunnel context for the tunnel
  */
 static void *
-new_tunnel (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
-            const struct GNUNET_PeerIdentity *initiator, uint32_t port)
+new_tunnel (void *cls,
+            struct GNUNET_MESH_Tunnel *tunnel,
+            const struct GNUNET_PeerIdentity *initiator,
+            uint32_t port)
 {
   struct TunnelState *s = GNUNET_new (struct TunnelState);
 
@@ -3034,13 +3035,14 @@ new_tunnel (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
  * Function called by mesh whenever an inbound tunnel is destroyed.
  * Should clean up any associated state.
  *
- * @param cls closure (set from GNUNET_MESH_connect)
+ * @param cls closure (set from #GNUNET_MESH_connect)
  * @param tunnel connection to the other end (henceforth invalid)
  * @param tunnel_ctx place where local state associated
  *                   with the tunnel is stored
  */
 static void
-clean_tunnel (void *cls GNUNET_UNUSED, const struct GNUNET_MESH_Tunnel *tunnel,
+clean_tunnel (void *cls,
+              const struct GNUNET_MESH_Tunnel *tunnel,
               void *tunnel_ctx)
 {
   struct TunnelState *s = tunnel_ctx;
@@ -3095,8 +3097,9 @@ clean_tunnel (void *cls GNUNET_UNUSED, const struct GNUNET_MESH_Tunnel *tunnel,
  * @param value value to free
  */
 static int
-free_iterate (void *cls GNUNET_UNUSED,
-              const struct GNUNET_HashCode * hash GNUNET_UNUSED, void *value)
+free_iterate (void *cls,
+              const struct GNUNET_HashCode * hash,
+              void *value)
 {
   GNUNET_free (value);
   return GNUNET_YES;
@@ -3107,7 +3110,7 @@ free_iterate (void *cls GNUNET_UNUSED,
  * Function scheduled as very last function, cleans up after us
  */
 static void
-cleanup (void *cls GNUNET_UNUSED,
+cleanup (void *cls,
          const struct GNUNET_SCHEDULER_TaskContext *tskctx)
 {
   unsigned int i;
@@ -3310,7 +3313,7 @@ add_services (int proto,
          freeaddrinfo (res);
          GNUNET_free (serv);
          continue;
-       }       
+       }
        serv->address.address.ipv6 = ((struct sockaddr_in6 *) res->ai_addr)->sin6_addr;
        break;
       default:
@@ -3339,7 +3342,7 @@ add_services (int proto,
  * @param section name of section in config, equal to hostname
  */
 static void
-read_service_conf (void *cls GNUNET_UNUSED, const char *section)
+read_service_conf (void *cls, const char *section)
 {
   char *cpy;
 
@@ -3441,8 +3444,9 @@ do_dht_put (void *cls,
  * @param cfg_ configuration
  */
 static void
-run (void *cls, char *const *args GNUNET_UNUSED,
-     const char *cfgfile GNUNET_UNUSED,
+run (void *cls,
+     char *const *args,
+     const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *cfg_)
 {
   static struct GNUNET_MESH_MessageHandler handlers[] = {
@@ -3586,7 +3590,7 @@ run (void *cls, char *const *args GNUNET_UNUSED,
     apptypes[app_idx] = GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER;
     app_idx++;
   }
-
+  GNUNET_free_non_null (dns_exit);
   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup, cls);
 
   if (GNUNET_OK !=
@@ -3724,7 +3728,7 @@ run (void *cls, char *const *args GNUNET_UNUSED,
       (void) GNUNET_asprintf (&prefixed_regex, "%s%s%s",
                              GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX,
                              "4", regex);
-      regex4 = GNUNET_REGEX_announce (cfg,                     
+      regex4 = GNUNET_REGEX_announce (cfg,
                                      prefixed_regex,
                                      REGEX_REFRESH_FREQUENCY,
                                      REGEX_MAX_PATH_LEN_IPV4);