GNUnet  0.10.x
Data Structures | Macros | Enumerations | Functions | Variables
gnunet-service-nat-auto_legacy.c File Reference
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_resolver_service.h"
#include "gnunet_nat_lib.h"
#include "nat.h"
Include dependency graph for gnunet-service-nat-auto_legacy.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_NAT_AutoHandle
 Handle to auto-configuration in progress. More...
 

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "nat", __VA_ARGS__)
 
#define TIMEOUT   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
 How long do we wait for the NAT test to report success? More...
 
#define NAT_SERVER_TIMEOUT   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
 

Enumerations

enum  AutoPhase {
  AUTO_INIT = 0, AUTO_EXTERNAL_IP, AUTO_STUN, AUTO_LOCAL_IP,
  AUTO_NAT_PUNCHED, AUTO_UPNPC, AUTO_ICMP_SERVER, AUTO_ICMP_CLIENT,
  AUTO_DONE
}
 Phases of the auto configuration. More...
 

Functions

static void next_phase (struct GNUNET_NAT_AutoHandle *ah)
 Run the next phase of the auto test. More...
 
static void process_stun_reply (struct sockaddr_in *answer, struct GNUNET_NAT_AutoHandle *ah)
 
static void stop_stun ()
 Function that terminates the test. More...
 
static void do_udp_read (void *cls)
 Activity on our incoming socket. More...
 
static struct GNUNET_NETWORK_Handlebind_v4 ()
 Create an IPv4 listen socket bound to our port. More...
 
static void request_callback (void *cls, enum GNUNET_NAT_StatusCode result)
 
static void result_callback (void *cls, enum GNUNET_NAT_StatusCode ret)
 Function called by NAT to report the outcome of the nat-test. More...
 
static void reversal_test (void *cls)
 Main function for the connection reversal test. More...
 
static void set_external_ipv4 (void *cls, const struct in_addr *addr, enum GNUNET_NAT_StatusCode ret)
 Set our external IPv4 address based on the UPnP. More...
 
static void test_external_ip (struct GNUNET_NAT_AutoHandle *ah)
 Determine our external IPv4 address. More...
 
static void test_stun (struct GNUNET_NAT_AutoHandle *ah)
 Determine our external IPv4 address and port using an external STUN server. More...
 
static int process_if (void *cls, const char *name, int isDefault, const struct sockaddr *addr, const struct sockaddr *broadcast_addr, const struct sockaddr *netmask, socklen_t addrlen)
 Process list of local IP addresses. More...
 
static void test_local_ip (struct GNUNET_NAT_AutoHandle *ah)
 Determine our local IP addresses; detect internal IP & IPv6-support. More...
 
static void mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
 We got disconnected from the NAT server. More...
 
static void test_nat_punched (struct GNUNET_NAT_AutoHandle *ah)
 Test if NAT has been punched. More...
 
static void test_upnpc (struct GNUNET_NAT_AutoHandle *ah)
 Test if UPnPC works. More...
 
static void test_icmp_server (struct GNUNET_NAT_AutoHandle *ah)
 Test if ICMP server is working. More...
 
static void test_icmp_client (struct GNUNET_NAT_AutoHandle *ah)
 Test if ICMP client is working. More...
 
struct GNUNET_NAT_AutoHandleGNUNET_NAT_autoconfig_start (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_NAT_AutoResultCallback cb, void *cb_cls)
 Start auto-configuration routine. More...
 
void GNUNET_NAT_autoconfig_cancel (struct GNUNET_NAT_AutoHandle *ah)
 Abort autoconfiguration. More...
 

Variables

static struct GNUNET_NETWORK_Handlelsock4
 The listen socket of the service for IPv4. More...
 
static struct GNUNET_SCHEDULER_Taskltask4
 The listen task ID for IPv4. More...
 
static unsigned long long port = 7895
 The port the test service is running on (default 7895) More...
 
static char * stun_server = "stun.ekiga.net"
 
static unsigned int stun_port = 3478
 

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "nat", __VA_ARGS__)

Definition at line 33 of file gnunet-service-nat-auto_legacy.c.

Referenced by test_nat_punched().

◆ TIMEOUT

How long do we wait for the NAT test to report success?

Definition at line 39 of file gnunet-service-nat-auto_legacy.c.

Referenced by reversal_test(), and test_external_ip().

◆ NAT_SERVER_TIMEOUT

#define NAT_SERVER_TIMEOUT   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)

Definition at line 41 of file gnunet-service-nat-auto_legacy.c.

Referenced by test_nat_punched(), and test_stun().

Enumeration Type Documentation

◆ AutoPhase

enum AutoPhase

Phases of the auto configuration.

Enumerator
AUTO_INIT 

Initial start value.

AUTO_EXTERNAL_IP 

Test our external IP.

AUTO_STUN 

Test our external IP.

AUTO_LOCAL_IP 

Test our internal IP.

AUTO_NAT_PUNCHED 

Test if NAT was punched.

AUTO_UPNPC 

Test if UPnP is working.

AUTO_ICMP_SERVER 

Test if ICMP server works.

AUTO_ICMP_CLIENT 

Test if ICMP client works.

AUTO_DONE 

Last phase, we're done.

Definition at line 46 of file gnunet-service-nat-auto_legacy.c.

47 {
51  AUTO_INIT = 0,
52 
57 
61  AUTO_STUN,
62 
67 
72 
76  AUTO_UPNPC,
77 
82 
87 
91  AUTO_DONE
92 
93 };
Test if ICMP client works.
Last phase, we're done.
Initial start value.
Test if ICMP server works.
Test our external IP.
Test if NAT was punched.
Test if UPnP is working.
Test our external IP.
Test our internal IP.

Function Documentation

◆ next_phase()

static void next_phase ( struct GNUNET_NAT_AutoHandle ah)
static

Run the next phase of the auto test.

Parameters
ahauto test handle

Definition at line 859 of file gnunet-service-nat-auto_legacy.c.

References AUTO_DONE, AUTO_EXTERNAL_IP, AUTO_ICMP_CLIENT, AUTO_ICMP_SERVER, AUTO_INIT, AUTO_LOCAL_IP, AUTO_NAT_PUNCHED, AUTO_STUN, AUTO_UPNPC, GNUNET_NAT_AutoHandle::cfg, GNUNET_NAT_AutoHandle::connected_back, GNUNET_NAT_AutoHandle::fin_cb, GNUNET_NAT_AutoHandle::fin_cb_cls, GNUNET_assert, GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_get_diff(), GNUNET_CONFIGURATION_set_value_number(), GNUNET_CONFIGURATION_set_value_string(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_NAT_autoconfig_cancel(), GNUNET_NAT_TYPE_NO_NAT, GNUNET_NAT_TYPE_STUN_PUNCHED_NAT, GNUNET_NAT_TYPE_UNREACHABLE_NAT, GNUNET_NAT_AutoHandle::initial_cfg, GNUNET_NAT_AutoHandle::internal_ip_is_public, GNUNET_NAT_AutoHandle::phase, GNUNET_NAT_AutoHandle::ret, GNUNET_NAT_AutoHandle::stun_ip, GNUNET_NAT_AutoHandle::stun_port, test_external_ip(), test_icmp_client(), test_icmp_server(), test_local_ip(), test_nat_punched(), test_stun(), test_upnpc(), and GNUNET_NAT_AutoHandle::type.

Referenced by do_udp_read(), GNUNET_NAT_autoconfig_start(), mq_error_handler(), process_stun_reply(), result_callback(), set_external_ipv4(), test_external_ip(), test_icmp_client(), test_icmp_server(), test_local_ip(), test_nat_punched(), test_stun(), and test_upnpc().

860 {
861  struct GNUNET_CONFIGURATION_Handle *diff;
862 
863  ah->phase++;
864  switch (ah->phase)
865  {
866  case AUTO_INIT:
867  GNUNET_assert (0);
868  break;
869  case AUTO_EXTERNAL_IP:
871  "Will run AUTO_EXTERNAL_IP\n");
872  test_external_ip (ah);
873  break;
874  case AUTO_STUN:
876  "Will run AUTO_STUN\n");
877  test_stun (ah);
878  break;
879  case AUTO_LOCAL_IP:
881  "Will run AUTO_LOCAL_IP\n");
882  test_local_ip (ah);
883  break;
884  case AUTO_NAT_PUNCHED:
886  "Will run AUTO_NAT_PUNCHED\n");
887  test_nat_punched (ah);
888  break;
889  case AUTO_UPNPC:
891  "Will run AUTO_UPNPC\n");
892  test_upnpc (ah);
893  break;
894  case AUTO_ICMP_SERVER:
896  "Will run AUTO_ICMP_SERVER\n");
897  test_icmp_server (ah);
898  break;
899  case AUTO_ICMP_CLIENT:
901  "Will run AUTO_ICMP_CLIENT\n");
902  test_icmp_client (ah);
903  break;
904  case AUTO_DONE:
906  "Done with tests\n");
907  if (!ah->internal_ip_is_public)
908  {
910  "nat",
911  "BEHIND_NAT",
912  "YES");
913 
914  if (ah->connected_back)
915  {
917  "nat",
918  "PUNCHED_NAT",
919  "YES");
920  }
921  else
922  {
924  "nat",
925  "PUNCHED_NAT",
926  "NO");
927  }
928 
929  if (ah->stun_ip)
930  {
932  "nat",
933  "EXTERNAL_ADDRESS",
934  ah->stun_ip);
935  if (ah->connected_back)
936  {
939  "nat",
940  "USE_STUN",
941  "YES");
942  }
943  else
944  {
947  "nat",
948  "USE_STUN",
949  "NO");
950  }
951 
952  }
953  if (0 != ah->stun_port)
954  {
956  "transport-udp",
957  "ADVERTISED_PORT",
958  ah->stun_port);
959  }
960 
961  }
962  else
963  {
964  //The internal IP is the same as public, but we didn't got a incoming connection
965  if (ah->connected_back)
966  {
969  "nat",
970  "BEHIND_NAT",
971  "NO");
972  }
973  else
974  {
976  "nat",
977  "BEHIND_NAT",
978  "YES");
980  if (ah->stun_ip)
981  {
983  "nat",
984  "EXTERNAL_ADDRESS",
985  ah->stun_ip);
986  }
987  if (0 != ah->stun_port)
988  {
990  "transport-udp",
991  "ADVERTISED_PORT",
992  ah->stun_port);
993 
994  }
995  }
996  }
997 
999  ah->cfg);
1000 
1001 
1002  ah->fin_cb (ah->fin_cb_cls,
1003  diff,
1004  ah->ret,
1005  ah->type);
1008  }
1009 }
Test if ICMP client works.
Last phase, we're done.
Initial start value.
static void test_stun(struct GNUNET_NAT_AutoHandle *ah)
Determine our external IPv4 address and port using an external STUN server.
Test if ICMP server works.
enum GNUNET_NAT_StatusCode ret
Error code for better debugging and user feedback.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static void test_nat_punched(struct GNUNET_NAT_AutoHandle *ah)
Test if NAT has been punched.
void GNUNET_CONFIGURATION_set_value_number(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long number)
Set a configuration value that should be a number.
enum GNUNET_NAT_Type type
Situation of the NAT.
We are under a NAT but cannot traverse it.
void * fin_cb_cls
Closure for fin_cb.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_get_diff(const struct GNUNET_CONFIGURATION_Handle *cfg_default, const struct GNUNET_CONFIGURATION_Handle *cfg_new)
Compute configuration with only entries that have been changed.
int internal_ip_is_public
Internal IP is the same as the public one ?
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
void GNUNET_CONFIGURATION_set_value_string(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
Set a configuration value that should be a string.
char * stun_ip
Address detected by STUN.
Test our external IP.
static void test_icmp_server(struct GNUNET_NAT_AutoHandle *ah)
Test if ICMP server is working.
int connected_back
Did the external server connected back ?
static void test_local_ip(struct GNUNET_NAT_AutoHandle *ah)
Determine our local IP addresses; detect internal IP & IPv6-support.
static void test_external_ip(struct GNUNET_NAT_AutoHandle *ah)
Determine our external IPv4 address.
Test if NAT was punched.
static void test_icmp_client(struct GNUNET_NAT_AutoHandle *ah)
Test if ICMP client is working.
configuration data
Definition: configuration.c:85
Test if UPnP is working.
struct GNUNET_CONFIGURATION_Handle * initial_cfg
Original configuration (used to calculate differences)
#define GNUNET_log(kind,...)
We have a direct connection.
GNUNET_NAT_AutoResultCallback fin_cb
Function to call when done.
enum AutoPhase phase
Where are we in the test?
Test our external IP.
static void test_upnpc(struct GNUNET_NAT_AutoHandle *ah)
Test if UPnPC works.
We can traverse using STUN.
Test our internal IP.
void GNUNET_NAT_autoconfig_cancel(struct GNUNET_NAT_AutoHandle *ah)
Abort autoconfiguration.
struct GNUNET_CONFIGURATION_Handle * cfg
Current configuration (with updates from previous phases)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_stun_reply()

static void process_stun_reply ( struct sockaddr_in *  answer,
struct GNUNET_NAT_AutoHandle ah 
)
static

Definition at line 216 of file gnunet-service-nat-auto_legacy.c.

References GNUNET_ERROR_TYPE_INFO, GNUNET_log, next_phase(), GNUNET_NAT_AutoHandle::stun_ip, and GNUNET_NAT_AutoHandle::stun_port.

Referenced by do_udp_read().

218 {
219  ah->stun_ip = inet_ntoa(answer->sin_addr);
220  ah->stun_port = ntohs (answer->sin_port);
222  "External IP is: %s , with port %u\n",
223  ah->stun_ip,
224  ah->stun_port);
225  next_phase (ah);
226 }
char * stun_ip
Address detected by STUN.
static void next_phase(struct GNUNET_NAT_AutoHandle *ah)
Run the next phase of the auto test.
#define GNUNET_log(kind,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ stop_stun()

static void stop_stun ( )
static

Function that terminates the test.

Definition at line 233 of file gnunet-service-nat-auto_legacy.c.

References GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_NETWORK_socket_close(), and GNUNET_SCHEDULER_cancel().

Referenced by do_udp_read(), request_callback(), and test_stun().

234 {
236  "Stopping STUN and quitting...\n");
237  /* Clean task */
238  if (NULL != ltask4)
239  {
241  ltask4 = NULL;
242  }
243  /* Clean socket */
244  if (NULL != lsock4)
245  {
247  lsock4 = NULL;
248  }
249 }
static struct GNUNET_SCHEDULER_Task * ltask4
The listen task ID for IPv4.
#define GNUNET_log(kind,...)
int GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:604
static struct GNUNET_NETWORK_Handle * lsock4
The listen socket of the service for IPv4.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_udp_read()

static void do_udp_read ( void *  cls)
static

Activity on our incoming socket.

Read data from the incoming connection.

Parameters
cls

Definition at line 259 of file gnunet-service-nat-auto_legacy.c.

References ah, AUTO_NAT_PUNCHED, GNUNET_NAT_AutoHandle::connected_back, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_NAT_stun_handle_packet(), GNUNET_NETWORK_fdset_isset(), GNUNET_NETWORK_socket_close(), GNUNET_NETWORK_socket_recv(), GNUNET_OK, GNUNET_SCHEDULER_get_task_context(), GNUNET_SCHEDULER_REASON_READ_READY, GNUNET_YES, next_phase(), GNUNET_NAT_AutoHandle::phase, process_stun_reply(), GNUNET_SCHEDULER_TaskContext::read_ready, GNUNET_SCHEDULER_TaskContext::reason, stop_stun(), and tc.

Referenced by test_nat_punched(), and test_stun().

260 {
261  struct GNUNET_NAT_AutoHandle *ah = cls;
262  unsigned char reply_buf[1024];
263  ssize_t rlen;
264  struct sockaddr_in answer;
265  const struct GNUNET_SCHEDULER_TaskContext *tc;
266 
268  if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) &&
270  lsock4)))
271  {
273  reply_buf,
274  sizeof (reply_buf));
275 
276  //Lets handle the packet
277  memset (&answer, 0, sizeof(struct sockaddr_in));
278  if (ah->phase == AUTO_NAT_PUNCHED)
279  {
280  //Destroy the connection
283  "The external server was able to connect back");
285  next_phase (ah);
286  }
287  else
288  {
289  if (GNUNET_OK ==
290  GNUNET_NAT_stun_handle_packet (reply_buf, rlen, &answer))
291  {
292  //Process the answer
293  process_stun_reply (&answer, ah);
294  }
295  else
296  {
297  next_phase (ah);
298  }
299  }
300  }
301  else
302  {
304  "TIMEOUT while waiting for an answer\n");
305  if (ah->phase == AUTO_NAT_PUNCHED)
306  {
307  stop_stun();
308  }
309 
310  next_phase (ah);
311  }
312 }
const struct GNUNET_SCHEDULER_TaskContext * GNUNET_SCHEDULER_get_task_context(void)
Obtain the reasoning why the current task was started.
Definition: scheduler.c:746
The reading socket is ready.
Context information passed to each scheduler task.
ssize_t GNUNET_NETWORK_socket_recv(const struct GNUNET_NETWORK_Handle *desc, void *buffer, size_t length)
Read data from a connected socket (always non-blocking).
Definition: network.c:894
static struct GNUNET_SCHEDULER_TaskContext tc
Task context of the current task.
Definition: scheduler.c:417
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
const struct GNUNET_NETWORK_FDSet * read_ready
Set of file descriptors ready for reading; note that additional bits may be set that were not in the ...
enum GNUNET_SCHEDULER_Reason reason
Reason why the task is run now.
Handle to auto-configuration in progress.
int GNUNET_NAT_stun_handle_packet(struct GNUNET_NAT_Handle *nh, const struct sockaddr *sender_addr, size_t sender_addr_len, const void *data, size_t data_size)
Handle an incoming STUN message.
Definition: nat_api.c:581
static void next_phase(struct GNUNET_NAT_AutoHandle *ah)
Run the next phase of the auto test.
int connected_back
Did the external server connected back ?
static void stop_stun()
Function that terminates the test.
Test if NAT was punched.
static struct GNUNET_NAT_AUTO_AutoHandle * ah
Handle to ongoing autoconfiguration.
static void process_stun_reply(struct sockaddr_in *answer, struct GNUNET_NAT_AutoHandle *ah)
#define GNUNET_log(kind,...)
enum AutoPhase phase
Where are we in the test?
#define GNUNET_YES
Definition: gnunet_common.h:80
int GNUNET_NETWORK_fdset_isset(const struct GNUNET_NETWORK_FDSet *fds, const struct GNUNET_NETWORK_Handle *desc)
Check whether a socket is part of the fd set.
Definition: network.c:1181
int GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:604
static struct GNUNET_NETWORK_Handle * lsock4
The listen socket of the service for IPv4.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ bind_v4()

static struct GNUNET_NETWORK_Handle* bind_v4 ( )
static

Create an IPv4 listen socket bound to our port.

Returns
NULL on error

Definition at line 321 of file gnunet-service-nat-auto_legacy.c.

References GNUNET_NETWORK_socket_bind(), GNUNET_NETWORK_socket_close(), GNUNET_NETWORK_socket_create(), GNUNET_OK, ls, and port.

Referenced by test_stun().

322 {
323  struct GNUNET_NETWORK_Handle *ls;
324  struct sockaddr_in sa4;
325  int eno;
326 
327  memset (&sa4, 0, sizeof (sa4));
328  sa4.sin_family = AF_INET;
329  sa4.sin_port = htons (port);
330 #if HAVE_SOCKADDR_IN_SIN_LEN
331  sa4.sin_len = sizeof (sa4);
332 #endif
333  ls = GNUNET_NETWORK_socket_create (AF_INET,
334  SOCK_DGRAM,
335  0);
336  if (NULL == ls)
337  return NULL;
338  if (GNUNET_OK !=
339  GNUNET_NETWORK_socket_bind (ls, (const struct sockaddr *) &sa4,
340  sizeof (sa4)))
341  {
342  eno = errno;
344  errno = eno;
345  return NULL;
346  }
347  return ls;
348 }
int GNUNET_NETWORK_socket_bind(struct GNUNET_NETWORK_Handle *desc, const struct sockaddr *address, socklen_t address_len)
Bind a socket to a particular address.
Definition: network.c:522
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static unsigned long long port
The port the test service is running on (default 7895)
static struct GNUNET_NETWORK_Handle * ls
Listen socket for STUN processing.
Definition: gnunet-nat.c:85
handle to a socket
Definition: network.c:46
int GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:604
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
Definition: network.c:1037
Here is the call graph for this function:
Here is the caller graph for this function:

◆ request_callback()

static void request_callback ( void *  cls,
enum GNUNET_NAT_StatusCode  result 
)
static

Definition at line 352 of file gnunet-service-nat-auto_legacy.c.

References GNUNET_ERROR_TYPE_INFO, GNUNET_log, and stop_stun().

Referenced by test_stun().

354 {
355  // struct GNUNET_NAT_AutoHandle *ah = cls;
356 
358  "Request callback: stop and quit\n");
359  stop_stun ();
360 
361  // next_phase (ah); FIXME this always will be NULL, as called in test_stun()
362 }
static void stop_stun()
Function that terminates the test.
#define GNUNET_log(kind,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ result_callback()

static void result_callback ( void *  cls,
enum GNUNET_NAT_StatusCode  ret 
)
static

Function called by NAT to report the outcome of the nat-test.

Clean up and update GUI.

Parameters
clsthe auto handle
successcurrently always GNUNET_OK
emsgNULL on success, otherwise an error message

Definition at line 374 of file gnunet-service-nat-auto_legacy.c.

References _, ah, GNUNET_NAT_AutoHandle::cfg, GNUNET_CONFIGURATION_set_value_string(), GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_NAT_ERROR_SUCCESS, GNUNET_NAT_test_stop(), next_phase(), GNUNET_NAT_AutoHandle::ret, and GNUNET_NAT_AutoHandle::tst.

Referenced by reversal_test().

376 {
377  struct GNUNET_NAT_AutoHandle *ah = cls;
378 
381  ah->tst = NULL;
382  ah->ret = ret;
385  ? _("NAT traversal with ICMP Server succeeded.\n")
386  : _("NAT traversal with ICMP Server failed.\n"));
387  GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "ENABLE_ICMP_SERVER",
388  GNUNET_NAT_ERROR_SUCCESS == ret ? "NO" : "YES");
389  next_phase (ah);
390 }
enum GNUNET_NAT_StatusCode ret
Error code for better debugging and user feedback.
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
Handle to auto-configuration in progress.
void GNUNET_CONFIGURATION_set_value_string(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
Set a configuration value that should be a string.
static void next_phase(struct GNUNET_NAT_AutoHandle *ah)
Run the next phase of the auto test.
void GNUNET_NAT_test_stop(struct GNUNET_NAT_Test *tst)
Stop an active NAT test.
struct GNUNET_NAT_Test * tst
Handle to the active NAT test.
static struct GNUNET_NAT_AUTO_AutoHandle * ah
Handle to ongoing autoconfiguration.
#define GNUNET_log(kind,...)
struct GNUNET_CONFIGURATION_Handle * cfg
Current configuration (with updates from previous phases)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reversal_test()

static void reversal_test ( void *  cls)
static

Main function for the connection reversal test.

Parameters
clsthe struct GNUNET_NAT_AutoHandle

Definition at line 399 of file gnunet-service-nat-auto_legacy.c.

References _, ah, GNUNET_NAT_AutoHandle::cfg, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_NAT_test_start(), GNUNET_RESOLVER_connect(), GNUNET_YES, result_callback(), GNUNET_NAT_AutoHandle::task, TIMEOUT, and GNUNET_NAT_AutoHandle::tst.

Referenced by test_icmp_server().

400 {
401  struct GNUNET_NAT_AutoHandle *ah = cls;
402 
403  ah->task = NULL;
405  _("Testing connection reversal with ICMP server.\n"));
407  ah->tst = GNUNET_NAT_test_start (ah->cfg, GNUNET_YES, 0, 0, TIMEOUT,
408  &result_callback, ah);
409 }
struct GNUNET_SCHEDULER_Task * task
Task identifier for the timeout.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
Handle to auto-configuration in progress.
struct GNUNET_NAT_Test * GNUNET_NAT_test_start(const struct GNUNET_CONFIGURATION_Handle *cfg, int is_tcp, uint16_t bnd_port, uint16_t adv_port, struct GNUNET_TIME_Relative timeout, GNUNET_NAT_TestCallback report, void *report_cls)
Start testing if NAT traversal works using the given configuration (IPv4-only).
struct GNUNET_NAT_Test * tst
Handle to the active NAT test.
static void result_callback(void *cls, enum GNUNET_NAT_StatusCode ret)
Function called by NAT to report the outcome of the nat-test.
static struct GNUNET_NAT_AUTO_AutoHandle * ah
Handle to ongoing autoconfiguration.
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:80
#define TIMEOUT
How long do we wait for the NAT test to report success?
void GNUNET_RESOLVER_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Create the connection to the resolver service.
Definition: resolver_api.c:254
struct GNUNET_CONFIGURATION_Handle * cfg
Current configuration (with updates from previous phases)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_external_ipv4()

static void set_external_ipv4 ( void *  cls,
const struct in_addr *  addr,
enum GNUNET_NAT_StatusCode  ret 
)
static

Set our external IPv4 address based on the UPnP.

Parameters
clsclosure with our setup context
addrthe address, NULL on errors
emsgNULL on success, otherwise an error message

Definition at line 421 of file gnunet-service-nat-auto_legacy.c.

References _, ah, buf, GNUNET_NAT_AutoHandle::cfg, GNUNET_NAT_AutoHandle::eh, GNUNET_break, GNUNET_CONFIGURATION_set_value_string(), GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_NAT_ERROR_EXTERNAL_IP_ADDRESS_INVALID, GNUNET_NAT_ERROR_SUCCESS, GNUNET_YES, next_phase(), GNUNET_NAT_AutoHandle::ret, and GNUNET_NAT_AutoHandle::upnp_set_external_address.

Referenced by test_external_ip().

424 {
425  struct GNUNET_NAT_AutoHandle *ah = cls;
426  char buf[INET_ADDRSTRLEN];
427 
428  ah->eh = NULL;
429  ah->ret = ret;
431  {
432  next_phase (ah);
433  return;
434  }
435  /* enable 'behind nat' */
437  _("Detected external IP `%s'\n"),
438  inet_ntop (AF_INET,
439  addr,
440  buf,
441  sizeof (buf)));
442  GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "BEHIND_NAT", "YES");
443 
444  /* set external IP address */
445  if (NULL == inet_ntop (AF_INET, addr, buf, sizeof (buf)))
446  {
447  GNUNET_break (0);
448  /* actually, this should never happen, as the caller already executed just
449  * this check, but for consistency (eg: future changes in the caller)
450  * we still need to report this error...
451  */
453  next_phase (ah);
454  return;
455  }
456  GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "EXTERNAL_ADDRESS",
457  buf);
459  next_phase (ah);
460 }
enum GNUNET_NAT_StatusCode ret
Error code for better debugging and user feedback.
struct GNUNET_NAT_ExternalHandle * eh
Handle for active 'GNUNET_NAT_mini_get_external_ipv4'-operation.
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
Handle to auto-configuration in progress.
static char buf[2048]
void GNUNET_CONFIGURATION_set_value_string(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
Set a configuration value that should be a string.
static void next_phase(struct GNUNET_NAT_AutoHandle *ah)
Run the next phase of the auto test.
static struct GNUNET_NAT_AUTO_AutoHandle * ah
Handle to ongoing autoconfiguration.
#define GNUNET_log(kind,...)
"no valid address was returned by `external-ip'"
#define GNUNET_YES
Definition: gnunet_common.h:80
int upnp_set_external_address
UPnP already set the external ip address ?
struct GNUNET_CONFIGURATION_Handle * cfg
Current configuration (with updates from previous phases)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_external_ip()

static void test_external_ip ( struct GNUNET_NAT_AutoHandle ah)
static

Determine our external IPv4 address.

Parameters
ahauto setup context

Definition at line 469 of file gnunet-service-nat-auto_legacy.c.

References GNUNET_NAT_AutoHandle::eh, GNUNET_NAT_ERROR_SUCCESS, next_phase(), GNUNET_NAT_AutoHandle::ret, set_external_ipv4(), and TIMEOUT.

Referenced by next_phase().

470 {
471  if (GNUNET_NAT_ERROR_SUCCESS != ah->ret)
472  next_phase (ah);
473 
474  // FIXME: CPS?
475  /* try to detect external IP */
476  ah->eh = GNUNET_NAT_mini_get_external_ipv4 (TIMEOUT,
477  &set_external_ipv4, ah);
478 }
enum GNUNET_NAT_StatusCode ret
Error code for better debugging and user feedback.
struct GNUNET_NAT_ExternalHandle * eh
Handle for active 'GNUNET_NAT_mini_get_external_ipv4'-operation.
static void set_external_ipv4(void *cls, const struct in_addr *addr, enum GNUNET_NAT_StatusCode ret)
Set our external IPv4 address based on the UPnP.
static void next_phase(struct GNUNET_NAT_AutoHandle *ah)
Run the next phase of the auto test.
#define TIMEOUT
How long do we wait for the NAT test to report success?
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_stun()

static void test_stun ( struct GNUNET_NAT_AutoHandle ah)
static

Determine our external IPv4 address and port using an external STUN server.

Parameters
ahauto setup context

Definition at line 487 of file gnunet-service-nat-auto_legacy.c.

References bind_v4(), GNUNET_NAT_AutoHandle::cfg, do_udp_read(), GNUNET_CONFIGURATION_get_value_number(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_log_strerror, GNUNET_NAT_stun_make_request(), GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_read_net(), NAT_SERVER_TIMEOUT, next_phase(), port, request_callback(), stop_stun(), GNUNET_NAT_AutoHandle::stun_port, and stun_server.

Referenced by next_phase().

488 {
489 
490  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Running STUN test\n");
491 
492  /* Get port from the configuration */
493  if (GNUNET_OK !=
495  "transport-udp",
496  "PORT",
497  &port))
498  {
499  port = 2086;
500  }
501 
502  //Lets create the socket
503  lsock4 = bind_v4 ();
504  if (NULL == lsock4)
505  {
507  next_phase(ah);
508  return;
509  }
510  else
511  {
512  //Lets call our function now when it accepts
514  lsock4,
515  &do_udp_read,
516  ah);
517  }
518 
519 
521  "STUN service listens on port %u\n",
522  (unsigned int) port);
523  if (GNUNET_NO ==
525  stun_port,
526  lsock4,
528  NULL))
529  {
530  /*An error happened*/
531  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "STUN error, stopping\n");
532  stop_stun ();
533  next_phase (ah);
534  }
535 }
static struct GNUNET_SCHEDULER_Task * ltask4
The listen task ID for IPv4.
int GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
struct GNUNET_NAT_STUN_Handle * GNUNET_NAT_stun_make_request(const char *server, uint16_t port, struct GNUNET_NETWORK_Handle *sock, GNUNET_NAT_TestCallback cb, void *cb_cls)
Make Generic STUN request.
Definition: nat_api_stun.c:212
static void do_udp_read(void *cls)
Activity on our incoming socket.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
static struct GNUNET_NETWORK_Handle * bind_v4()
Create an IPv4 listen socket bound to our port.
static unsigned long long port
The port the test service is running on (default 7895)
static void next_phase(struct GNUNET_NAT_AutoHandle *ah)
Run the next phase of the auto test.
static char * stun_server
static void stop_stun()
Function that terminates the test.
#define NAT_SERVER_TIMEOUT
static unsigned int stun_port
#define GNUNET_log(kind,...)
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1478
static void request_callback(void *cls, enum GNUNET_NAT_StatusCode result)
static struct GNUNET_NETWORK_Handle * lsock4
The listen socket of the service for IPv4.
struct GNUNET_CONFIGURATION_Handle * cfg
Current configuration (with updates from previous phases)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_if()

static int process_if ( void *  cls,
const char *  name,
int  isDefault,
const struct sockaddr *  addr,
const struct sockaddr *  broadcast_addr,
const struct sockaddr *  netmask,
socklen_t  addrlen 
)
static

Process list of local IP addresses.

Find and set the one of the default interface.

Parameters
clsour struct GNUNET_NAT_AutoHandle
namename of the interface (can be NULL for unknown)
isDefaultis this presumably the default interface
addraddress of this interface (can be NULL for unknown or unassigned)
broadcast_addrthe broadcast address (can be NULL for unknown or unassigned)
netmaskthe network mask (can be NULL for unknown or unassigned))
addrlenlength of the addr and broadcast_addr
Returns
GNUNET_OK to continue iteration, GNUNET_SYSERR to abort

Definition at line 552 of file gnunet-service-nat-auto_legacy.c.

References _, ah, buf, GNUNET_NAT_AutoHandle::cfg, GNUNET_break, GNUNET_CONFIGURATION_set_value_string(), GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_memcmp, GNUNET_NAT_ERROR_SUCCESS, GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, GNUNET_NAT_AutoHandle::have_v6, GNUNET_NAT_AutoHandle::internal_ip_is_public, GNUNET_NAT_AutoHandle::ret, and GNUNET_NAT_AutoHandle::stun_ip.

Referenced by test_local_ip().

559 {
560  struct GNUNET_NAT_AutoHandle *ah = cls;
561  const struct sockaddr_in *in;
562  char buf[INET_ADDRSTRLEN];
563 
564 
565  if ( (sizeof (struct sockaddr_in6) == addrlen) &&
566  (0 != GNUNET_memcmp (&in6addr_loopback, &((const struct sockaddr_in6 *) addr)->sin6_addr)) &&
567  (! IN6_IS_ADDR_LINKLOCAL(&((const struct sockaddr_in6 *) addr)->sin6_addr)) )
568  {
569  ah->have_v6 = GNUNET_YES;
571  _("This system has a global IPv6 address, setting IPv6 to supported.\n"));
572 
573  return GNUNET_OK;
574  }
575  if (addrlen != sizeof (struct sockaddr_in))
576  return GNUNET_OK;
577  in = (const struct sockaddr_in *) addr;
578 
579 
580  /* set internal IP address */
581  if (NULL == inet_ntop (AF_INET, &in->sin_addr, buf, sizeof (buf)))
582  {
583  GNUNET_break (0);
584  return GNUNET_OK;
585  }
586  GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "INTERNAL_ADDRESS",
587  buf);
589  _("Detected internal network address `%s'.\n"),
590  buf);
591 
592 
594 
595  /* Check if our internal IP is the same as the External detect by STUN*/
596  if(ah->stun_ip && (strcmp(buf, ah->stun_ip) == 0) )
597  {
599  GNUNET_log (GNUNET_ERROR_TYPE_INFO,"A internal IP is the sameas the external");
600  /* No need to continue*/
601  return GNUNET_SYSERR;
602  }
603 
604  /* no need to continue iteration if we found the default */
605  if (!isDefault)
606  return GNUNET_OK;
607  else
608  return GNUNET_SYSERR;
609 }
enum GNUNET_NAT_StatusCode ret
Error code for better debugging and user feedback.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
Handle to auto-configuration in progress.
int internal_ip_is_public
Internal IP is the same as the public one ?
static char buf[2048]
void GNUNET_CONFIGURATION_set_value_string(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
Set a configuration value that should be a string.
char * stun_ip
Address detected by STUN.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
static struct GNUNET_NAT_AUTO_AutoHandle * ah
Handle to ongoing autoconfiguration.
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:80
struct GNUNET_CONFIGURATION_Handle * cfg
Current configuration (with updates from previous phases)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_local_ip()

static void test_local_ip ( struct GNUNET_NAT_AutoHandle ah)
static

Determine our local IP addresses; detect internal IP & IPv6-support.

Parameters
ahauto setup context

Definition at line 618 of file gnunet-service-nat-auto_legacy.c.

References GNUNET_NAT_AutoHandle::cfg, GNUNET_CONFIGURATION_set_value_string(), GNUNET_NAT_ERROR_NO_VALID_IF_IP_COMBO, GNUNET_NO, GNUNET_OS_network_interfaces_list(), GNUNET_YES, GNUNET_NAT_AutoHandle::have_v6, next_phase(), process_if(), and GNUNET_NAT_AutoHandle::ret.

Referenced by next_phase().

619 {
620  ah->have_v6 = GNUNET_NO;
621  ah->ret = GNUNET_NAT_ERROR_NO_VALID_IF_IP_COMBO; // reset to success if any of the IFs in below iterator has a valid IP
623 
624  GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "DISABLEV6",
625  (GNUNET_YES == ah->have_v6) ? "NO" : "YES");
626  next_phase (ah);
627 }
enum GNUNET_NAT_StatusCode ret
Error code for better debugging and user feedback.
#define GNUNET_NO
Definition: gnunet_common.h:81
void GNUNET_OS_network_interfaces_list(GNUNET_OS_NetworkInterfaceProcessor proc, void *proc_cls)
Enumerate all network interfaces.
Definition: os_network.c:388
Could not determine interface with internal/local network address.
void GNUNET_CONFIGURATION_set_value_string(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
Set a configuration value that should be a string.
static void next_phase(struct GNUNET_NAT_AutoHandle *ah)
Run the next phase of the auto test.
#define GNUNET_YES
Definition: gnunet_common.h:80
static int process_if(void *cls, const char *name, int isDefault, const struct sockaddr *addr, const struct sockaddr *broadcast_addr, const struct sockaddr *netmask, socklen_t addrlen)
Process list of local IP addresses.
struct GNUNET_CONFIGURATION_Handle * cfg
Current configuration (with updates from previous phases)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mq_error_handler()

static void mq_error_handler ( void *  cls,
enum GNUNET_MQ_Error  error 
)
static

We got disconnected from the NAT server.

Stop waiting for a reply.

Parameters
clsthe struct GNUNET_NAT_AutoHandle
errorerror code

Definition at line 638 of file gnunet-service-nat-auto_legacy.c.

References ah, GNUNET_MQ_destroy(), GNUNET_NAT_AutoHandle::mq, and next_phase().

Referenced by test_nat_punched().

640 {
641  struct GNUNET_NAT_AutoHandle *ah = cls;
642 
643  GNUNET_MQ_destroy (ah->mq);
644  ah->mq = NULL;
645  /* wait a bit first? */
646  next_phase (ah);
647 }
Handle to auto-configuration in progress.
static void next_phase(struct GNUNET_NAT_AutoHandle *ah)
Run the next phase of the auto test.
struct GNUNET_MQ_Handle * mq
Message queue to the gnunet-nat-server.
static struct GNUNET_NAT_AUTO_AutoHandle * ah
Handle to ongoing autoconfiguration.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:824
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_nat_punched()

static void test_nat_punched ( struct GNUNET_NAT_AutoHandle ah)
static

Test if NAT has been punched.

Parameters
ahauto setup context

Definition at line 656 of file gnunet-service-nat-auto_legacy.c.

References _, GNUNET_NAT_AutoHandle::cfg, GNUNET_NAT_TestMessage::data, do_udp_read(), GNUNET_NAT_TestMessage::dport, GNUNET_NAT_TestMessage::dst_ipv4, env, GNUNET_CLIENT_connect(), GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_MESSAGE_TYPE_NAT_TEST, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_NO, GNUNET_SCHEDULER_add_read_net(), GNUNET_SCHEDULER_cancel(), GNUNET_NAT_TestMessage::is_tcp, LOG, GNUNET_NAT_AutoHandle::mq, mq_error_handler(), msg, NAT_SERVER_TIMEOUT, next_phase(), port, GNUNET_NAT_AutoHandle::stun_ip, and GNUNET_NAT_AutoHandle::stun_port.

Referenced by next_phase().

657 {
658  struct GNUNET_NAT_TestMessage *msg;
659  struct GNUNET_MQ_Envelope *env;
660 
661  if (! ah->stun_ip)
662  {
664  "We don't have a STUN IP");
665  next_phase (ah);
666  return;
667  }
668 
670  "Asking gnunet-nat-server to connect to `%s'\n",
671  ah->stun_ip);
672  ah->mq = GNUNET_CLIENT_connect (ah->cfg,
673  "gnunet-nat-server",
674  NULL,
676  ah);
677  if (NULL == ah->mq)
678  {
680  _("Failed to connect to `gnunet-nat-server'\n"));
681  next_phase (ah);
682  return;
683  }
684  env = GNUNET_MQ_msg (msg,
686  msg->dst_ipv4 = inet_addr (ah->stun_ip);
687  msg->dport = htons (ah->stun_port);
688  msg->data = port;
689  msg->is_tcp = htonl ((uint32_t) GNUNET_NO);
690  GNUNET_MQ_send (ah->mq,
691  env);
692  if (NULL != ltask4)
693  {
696  lsock4,
697  &do_udp_read,
698  ah);
699  }
700 }
#define LOG(kind,...)
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
static struct GNUNET_SCHEDULER_Task * ltask4
The listen task ID for IPv4.
uint32_t dst_ipv4
IPv4 target IP address.
Definition: nat.h:49
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
Definition: client.c:901
static void do_udp_read(void *cls)
Activity on our incoming socket.
int32_t is_tcp
GNUNET_YES for TCP, GNUNET_NO for UDP.
Definition: nat.h:64
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
#define GNUNET_MESSAGE_TYPE_NAT_TEST
Message to ask NAT server to perform traversal test.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
uint16_t dport
Port to use, 0 to send dummy ICMP response.
Definition: nat.h:54
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
We got disconnected from the NAT server.
char * stun_ip
Address detected by STUN.
static unsigned long long port
The port the test service is running on (default 7895)
static void next_phase(struct GNUNET_NAT_AutoHandle *ah)
Run the next phase of the auto test.
struct GNUNET_MQ_Handle * mq
Message queue to the gnunet-nat-server.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define NAT_SERVER_TIMEOUT
Request to test NAT traversal, sent to the gnunet-nat-server (not the service!).
Definition: nat.h:39
#define GNUNET_log(kind,...)
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1478
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:353
static struct GNUNET_NETWORK_Handle * lsock4
The listen socket of the service for IPv4.
struct GNUNET_CONFIGURATION_Handle * cfg
Current configuration (with updates from previous phases)
uint16_t data
Data to send OR advertised-port (in NBO) to use for dummy ICMP.
Definition: nat.h:59
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_upnpc()

static void test_upnpc ( struct GNUNET_NAT_AutoHandle ah)
static

Test if UPnPC works.

Parameters
ahauto setup context

Definition at line 709 of file gnunet-service-nat-auto_legacy.c.

References _, GNUNET_NAT_AutoHandle::cfg, GNUNET_CONFIGURATION_set_value_string(), GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_NAT_ERROR_SUCCESS, GNUNET_NO, GNUNET_OS_check_helper_binary(), GNUNET_SYSERR, GNUNET_YES, next_phase(), and GNUNET_NAT_AutoHandle::ret.

Referenced by next_phase().

710 {
711 
712  int have_upnpc;
713 
714  if (GNUNET_NAT_ERROR_SUCCESS != ah->ret)
715  next_phase (ah);
716 
717  // test if upnpc is available
718  have_upnpc = (GNUNET_SYSERR !=
719  GNUNET_OS_check_helper_binary ("upnpc", GNUNET_NO, NULL));
720  //FIXME: test if upnpc is actually working, that is, if transports start to work once we use UPnP
722  (have_upnpc)
723  ? _("upnpc found, enabling its use\n")
724  : _("upnpc not found\n"));
725  GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "ENABLE_UPNP",
726  (GNUNET_YES == have_upnpc) ? "YES" : "NO");
727  next_phase (ah);
728 
729 }
enum GNUNET_NAT_StatusCode ret
Error code for better debugging and user feedback.
#define GNUNET_NO
Definition: gnunet_common.h:81
int GNUNET_OS_check_helper_binary(const char *binary, int check_suid, const char *params)
Check whether an executable exists and possibly if the suid bit is set on the file.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
void GNUNET_CONFIGURATION_set_value_string(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
Set a configuration value that should be a string.
static void next_phase(struct GNUNET_NAT_AutoHandle *ah)
Run the next phase of the auto test.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:80
struct GNUNET_CONFIGURATION_Handle * cfg
Current configuration (with updates from previous phases)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_icmp_server()

static void test_icmp_server ( struct GNUNET_NAT_AutoHandle ah)
static

Test if ICMP server is working.

Parameters
ahauto setup context

Definition at line 738 of file gnunet-service-nat-auto_legacy.c.

References _, GNUNET_NAT_AutoHandle::cfg, GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_free_non_null, GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_OS_check_helper_binary(), GNUNET_OS_get_libexec_binary_path(), GNUNET_SCHEDULER_add_now(), GNUNET_YES, next_phase(), reversal_test(), and GNUNET_NAT_AutoHandle::task.

Referenced by next_phase().

739 {
740 
741  int ext_ip;
742  int nated;
743  int binary;
744  char *tmp;
745  char *helper;
746  ext_ip = GNUNET_NO;
747  nated = GNUNET_NO;
748  binary = GNUNET_NO;
749 
750  tmp = NULL;
751  helper = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-nat-server");
752  if ( (GNUNET_OK ==
754  "nat",
755  "EXTERNAL_ADDRESS",
756  &tmp)) &&
757  (0 < strlen (tmp)) )
758  {
759  ext_ip = GNUNET_OK;
761  _("test_icmp_server not possible, as we have no public IPv4 address\n"));
762  }
763  else
764  goto err;
765 
766  if (GNUNET_YES ==
768  "nat",
769  "BEHIND_NAT"))
770  {
771  nated = GNUNET_YES;
773  _("test_icmp_server not possible, as we are not behind NAT\n"));
774  }
775  else
776  goto err;
777 
778  if (GNUNET_YES ==
780  GNUNET_YES,
781  "-d 127.0.0.1" ))
782  {
783  binary = GNUNET_OK; // use localhost as source for that one udp-port, ok for testing
785  _("No working gnunet-helper-nat-server found\n"));
786  }
787 err:
788  GNUNET_free_non_null (tmp);
789  GNUNET_free (helper);
790 
791  if ( (GNUNET_OK == ext_ip) &&
792  (GNUNET_YES == nated) &&
793  (GNUNET_OK == binary) )
795  ah);
796  else
797  next_phase (ah);
798 }
struct GNUNET_SCHEDULER_Task * task
Task identifier for the timeout.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
int GNUNET_OS_check_helper_binary(const char *binary, int check_suid, const char *params)
Check whether an executable exists and possibly if the suid bit is set on the file.
static void reversal_test(void *cls)
Main function for the connection reversal test.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1273
static void next_phase(struct GNUNET_NAT_AutoHandle *ah)
Run the next phase of the auto test.
int GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
#define GNUNET_log(kind,...)
char * GNUNET_OS_get_libexec_binary_path(const char *progname)
Given the name of a gnunet-helper, gnunet-service or gnunet-daemon binary, try to prefix it with the ...
#define GNUNET_YES
Definition: gnunet_common.h:80
int GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
struct GNUNET_CONFIGURATION_Handle * cfg
Current configuration (with updates from previous phases)
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_icmp_client()

static void test_icmp_client ( struct GNUNET_NAT_AutoHandle ah)
static

Test if ICMP client is working.

Parameters
ahauto setup context

Definition at line 807 of file gnunet-service-nat-auto_legacy.c.

References _, GNUNET_NAT_AutoHandle::cfg, GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_free_non_null, GNUNET_log, GNUNET_OK, GNUNET_OS_check_helper_binary(), GNUNET_OS_get_libexec_binary_path(), GNUNET_YES, and next_phase().

Referenced by next_phase().

808 {
809  char *tmp;
810  char *helper;
811 
812  tmp = NULL;
813  helper = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-nat-client");
814  if ( (GNUNET_OK ==
816  "nat",
817  "INTERNAL_ADDRESS",
818  &tmp)) &&
819  (0 < strlen (tmp)) )
820  {
822  _("test_icmp_client not possible, as we have no internal IPv4 address\n"));
823  }
824  else
825  goto err;
826 
827  if (GNUNET_YES !=
829  "nat",
830  "BEHIND_NAT"))
831  {
833  _("test_icmp_server not possible, as we are not behind NAT\n"));
834  }
835  else
836  goto err;
837 
838  if (GNUNET_YES ==
840  GNUNET_YES,
841  "-d 127.0.0.1 127.0.0.2 42"))
842  {
843  // none of these parameters are actually used in privilege testing mode
845  _("No working gnunet-helper-nat-server found\n"));
846  }
847 err:
848  GNUNET_free_non_null (tmp);
849  GNUNET_free (helper);
850 
851  next_phase (ah);
852 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
int GNUNET_OS_check_helper_binary(const char *binary, int check_suid, const char *params)
Check whether an executable exists and possibly if the suid bit is set on the file.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static void next_phase(struct GNUNET_NAT_AutoHandle *ah)
Run the next phase of the auto test.
int GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
#define GNUNET_log(kind,...)
char * GNUNET_OS_get_libexec_binary_path(const char *progname)
Given the name of a gnunet-helper, gnunet-service or gnunet-daemon binary, try to prefix it with the ...
#define GNUNET_YES
Definition: gnunet_common.h:80
int GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
struct GNUNET_CONFIGURATION_Handle * cfg
Current configuration (with updates from previous phases)
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_NAT_autoconfig_start()

struct GNUNET_NAT_AutoHandle* GNUNET_NAT_autoconfig_start ( const struct GNUNET_CONFIGURATION_Handle cfg,
GNUNET_NAT_AutoResultCallback  cb,
void *  cb_cls 
)

Start auto-configuration routine.

The resolver service should be available when this function is called.

Parameters
cfginitial configuration
cbfunction to call with autoconfiguration result
cb_clsclosure for cb
Returns
handle to cancel operation

Definition at line 1022 of file gnunet-service-nat-auto_legacy.c.

References ah, GNUNET_NAT_AutoHandle::cfg, GNUNET_NAT_AutoHandle::fin_cb, GNUNET_NAT_AutoHandle::fin_cb_cls, GNUNET_CONFIGURATION_dup(), GNUNET_CONFIGURATION_set_value_string(), GNUNET_NAT_ERROR_SUCCESS, GNUNET_new, GNUNET_NAT_AutoHandle::initial_cfg, next_phase(), and GNUNET_NAT_AutoHandle::ret.

1025 {
1026  struct GNUNET_NAT_AutoHandle *ah;
1027 
1028  ah = GNUNET_new (struct GNUNET_NAT_AutoHandle);
1029  ah->fin_cb = cb;
1030  ah->fin_cb_cls = cb_cls;
1032  ah->cfg = GNUNET_CONFIGURATION_dup (cfg);
1034 
1035  /* never use loopback addresses if user wanted autoconfiguration */
1037  "nat",
1038  "USE_LOCALADDR",
1039  "NO");
1040 
1041  next_phase (ah);
1042  return ah;
1043 }
enum GNUNET_NAT_StatusCode ret
Error code for better debugging and user feedback.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Handle to auto-configuration in progress.
void * fin_cb_cls
Closure for fin_cb.
void GNUNET_CONFIGURATION_set_value_string(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
Set a configuration value that should be a string.
static void next_phase(struct GNUNET_NAT_AutoHandle *ah)
Run the next phase of the auto test.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_dup(const struct GNUNET_CONFIGURATION_Handle *cfg)
Duplicate an existing configuration object.
static struct GNUNET_NAT_AUTO_AutoHandle * ah
Handle to ongoing autoconfiguration.
struct GNUNET_CONFIGURATION_Handle * initial_cfg
Original configuration (used to calculate differences)
GNUNET_NAT_AutoResultCallback fin_cb
Function to call when done.
struct GNUNET_CONFIGURATION_Handle * cfg
Current configuration (with updates from previous phases)
Here is the call graph for this function:

◆ GNUNET_NAT_autoconfig_cancel()

void GNUNET_NAT_autoconfig_cancel ( struct GNUNET_NAT_AutoHandle ah)

Abort autoconfiguration.

Parameters
ahhandle for operation to abort

Definition at line 1052 of file gnunet-service-nat-auto_legacy.c.

References GNUNET_NAT_AutoHandle::cfg, GNUNET_NAT_AutoHandle::eh, GNUNET_CONFIGURATION_destroy(), GNUNET_free, GNUNET_MQ_destroy(), GNUNET_NAT_test_stop(), GNUNET_SCHEDULER_cancel(), GNUNET_NAT_AutoHandle::initial_cfg, GNUNET_NAT_AutoHandle::mq, GNUNET_NAT_AutoHandle::task, and GNUNET_NAT_AutoHandle::tst.

Referenced by next_phase().

1053 {
1054  if (NULL != ah->tst)
1055  {
1056  GNUNET_NAT_test_stop (ah->tst);
1057  ah->tst = NULL;
1058  }
1059  if (NULL != ah->eh)
1060  {
1061  GNUNET_NAT_mini_get_external_ipv4_cancel (ah->eh);
1062  ah->eh = NULL;
1063  }
1064  if (NULL != ah->mq)
1065  {
1066  GNUNET_MQ_destroy (ah->mq);
1067  ah->mq = NULL;
1068  }
1069  if (NULL != ah->task)
1070  {
1072  ah->task = NULL;
1073  }
1076  GNUNET_free (ah);
1077 }
struct GNUNET_SCHEDULER_Task * task
Task identifier for the timeout.
struct GNUNET_NAT_ExternalHandle * eh
Handle for active &#39;GNUNET_NAT_mini_get_external_ipv4&#39;-operation.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
void GNUNET_NAT_test_stop(struct GNUNET_NAT_Test *tst)
Stop an active NAT test.
struct GNUNET_MQ_Handle * mq
Message queue to the gnunet-nat-server.
struct GNUNET_NAT_Test * tst
Handle to the active NAT test.
struct GNUNET_CONFIGURATION_Handle * initial_cfg
Original configuration (used to calculate differences)
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:824
struct GNUNET_CONFIGURATION_Handle * cfg
Current configuration (with updates from previous phases)
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ lsock4

struct GNUNET_NETWORK_Handle* lsock4
static

The listen socket of the service for IPv4.

Definition at line 189 of file gnunet-service-nat-auto_legacy.c.

◆ ltask4

struct GNUNET_SCHEDULER_Task* ltask4
static

The listen task ID for IPv4.

Definition at line 194 of file gnunet-service-nat-auto_legacy.c.

◆ port

unsigned long long port = 7895
static

The port the test service is running on (default 7895)

Definition at line 199 of file gnunet-service-nat-auto_legacy.c.

Referenced by bind_v4(), test_nat_punched(), and test_stun().

◆ stun_server

char* stun_server = "stun.ekiga.net"
static

Definition at line 201 of file gnunet-service-nat-auto_legacy.c.

Referenced by test_stun().

◆ stun_port

unsigned int stun_port = 3478
static

Definition at line 203 of file gnunet-service-nat-auto_legacy.c.