X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fnat%2Fnat.c;h=e51c001f2e56a8bcc197227d99851dbb844138cd;hb=e2f70a2f9fa099e3ce0e7451028bea8c373522a6;hp=f5b1123c6c1a7b65c94aca41b8373ff5ec03be2f;hpb=faf6cdf7e592414f041d486bf620967817485435;p=oweals%2Fgnunet.git diff --git a/src/nat/nat.c b/src/nat/nat.c index f5b1123c6..e51c001f2 100644 --- a/src/nat/nat.c +++ b/src/nat/nat.c @@ -407,7 +407,7 @@ struct GNUNET_NAT_Handle int use_stun; /** - * How often should se check STUN ? + * How often should we check STUN ? */ struct GNUNET_TIME_Relative stun_frequency; @@ -812,7 +812,7 @@ process_interfaces (void *cls, if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (h->cfg, "exit", - "EXIT_IFNAME", + "TUN_IFNAME", &tun_if)) { if (0 == strncasecmp (name, @@ -1109,29 +1109,39 @@ list_interfaces (void *cls, * @param cls the NAT handle * @param result , the status */ -static void stun_request_callback(void *cls, +static void +stun_request_callback(void *cls, enum GNUNET_NAT_StatusCode result) { struct GNUNET_NAT_Handle *h = cls; + if(NULL == cls) + return; + h->waiting_stun = GNUNET_NO; - LOG (GNUNET_ERROR_TYPE_WARNING, + + if(result != GNUNET_OK) + { + LOG (GNUNET_ERROR_TYPE_WARNING, "Error processing a STUN request"); + } }; /** - * Check if STUN can decode the packet + * CHECK if is a valid STUN packet sending to GNUNET_NAT_stun_handle_packet. + * It also check if it can handle the packet based on the NAT handler. + * You don't need to call anything else to check if the packet is valid, * * @param cls the NAT handle * @param data, packet - * @param len, packet lenght + * @param len, packet length * - * @return GNUNET_NO if it can't decode, GNUNET_YES if is a packet + * @return #GNUNET_NO if it can't decode, #GNUNET_YES if is a packet */ int -GNUNET_NAT_try_decode_stun_packet(void *cls, const uint8_t *data, size_t len) +GNUNET_NAT_is_valid_stun_packet(void *cls, const void *data, size_t len) { struct GNUNET_NAT_Handle *h = cls; struct sockaddr_in answer; @@ -1140,6 +1150,10 @@ GNUNET_NAT_try_decode_stun_packet(void *cls, const uint8_t *data, size_t len) if(!h->waiting_stun) return GNUNET_NO; + /*We dont have STUN installed*/ + if(!h->use_stun) + return GNUNET_NO; + /* Empty the answer structure */ memset(&answer, 0, sizeof(struct sockaddr_in)); @@ -1147,7 +1161,7 @@ GNUNET_NAT_try_decode_stun_packet(void *cls, const uint8_t *data, size_t len) int valid = GNUNET_NAT_stun_handle_packet(data,len, &answer); if(valid) { - LOG (GNUNET_ERROR_TYPE_DEBUG, + LOG (GNUNET_ERROR_TYPE_INFO, "Stun server returned IP %s , with port %d \n", inet_ntoa(answer.sin_addr), ntohs(answer.sin_port)); /* ADD IP AS VALID*/ add_to_address_list (h, LAL_EXTERNAL_IP, (const struct sockaddr *) &answer, @@ -1176,20 +1190,25 @@ process_stun (void *cls, { struct GNUNET_NAT_Handle *h = cls; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "I will do a STUN request\n"); + h->stun_task = NULL; - h->stun_task = NULL; - h->waiting_stun = GNUNET_YES; struct StunServerList* elem = h->actual_stun_server; /* Make the request */ - LOG (GNUNET_ERROR_TYPE_DEBUG, + LOG (GNUNET_ERROR_TYPE_INFO, "I will request the stun server %s:%i !\n", elem->address, elem->port); - GNUNET_NAT_stun_make_request(elem->address, elem->port, h->socket, &stun_request_callback, NULL); + if(GNUNET_OK == GNUNET_NAT_stun_make_request(elem->address, elem->port, h->socket, &stun_request_callback, NULL)) + { + h->waiting_stun = GNUNET_YES; + } + else + { + LOG (GNUNET_ERROR_TYPE_ERROR, + "STUN request failed %s:%i !\n", elem->address, elem->port); + } h->stun_task = GNUNET_SCHEDULER_add_delayed (h->stun_frequency, @@ -1581,7 +1600,8 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, } /* ENABLE STUN ONLY ON UDP*/ - if(!is_tcp && (NULL != sock) && h->use_stun ) { + if(!is_tcp && (NULL != sock) && h->use_stun ) + { h->socket = sock; h->actual_stun_server = NULL; @@ -1765,6 +1785,11 @@ GNUNET_NAT_unregister (struct GNUNET_NAT_Handle *h) GNUNET_SCHEDULER_cancel (h->dns_task); h->dns_task = NULL; } + if (NULL != h->stun_task) + { + GNUNET_SCHEDULER_cancel (h->stun_task); + h->stun_task = NULL; + } if (NULL != h->server_proc) { if (0 != GNUNET_OS_process_kill (h->server_proc, GNUNET_TERM_SIG)) @@ -1912,7 +1937,9 @@ GNUNET_NAT_test_address (struct GNUNET_NAT_Handle *h, } } LOG (GNUNET_ERROR_TYPE_WARNING, - "Asked to validate one of my addresses and validation failed!\n"); + "Asked to validate one of my addresses (%s) and validation failed!\n", + GNUNET_a2s (addr, + addrlen)); return GNUNET_NO; }