GNUnet  0.10.x
Typedefs | Functions
gnunet-service-nat_helper.h File Reference

runs the gnunet-helper-nat-server More...

#include "platform.h"
#include "gnunet_util_lib.h"
Include dependency graph for gnunet-service-nat_helper.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef void(* GN_ReversalCallback) (void *cls, const struct sockaddr_in *ra)
 Function called whenever we get a connection reversal request from another peer. More...
 

Functions

struct HelperContextGN_start_gnunet_nat_server_ (const struct in_addr *internal_address, GN_ReversalCallback cb, void *cb_cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
 Start the gnunet-helper-nat-server and process incoming requests. More...
 
void GN_stop_gnunet_nat_server_ (struct HelperContext *h)
 Start the gnunet-helper-nat-server and process incoming requests. More...
 
int GN_request_connection_reversal (const struct in_addr *internal_address, uint16_t internal_port, const struct in_addr *remote_v4, const struct GNUNET_CONFIGURATION_Handle *cfg)
 We want to connect to a peer that is behind NAT. More...
 

Detailed Description

runs the gnunet-helper-nat-server

Author
Milan Bouchet-Valat
Christian Grothoff

Definition in file gnunet-service-nat_helper.h.

Typedef Documentation

◆ GN_ReversalCallback

typedef void(* GN_ReversalCallback) (void *cls, const struct sockaddr_in *ra)

Function called whenever we get a connection reversal request from another peer.

Parameters
clsclosure
raIP address of the peer who wants us to connect to it

Definition at line 45 of file gnunet-service-nat_helper.h.

Function Documentation

◆ GN_start_gnunet_nat_server_()

struct HelperContext* GN_start_gnunet_nat_server_ ( const struct in_addr *  internal_address,
GN_ReversalCallback  cb,
void *  cb_cls,
const struct GNUNET_CONFIGURATION_Handle cfg 
)

Start the gnunet-helper-nat-server and process incoming requests.

Parameters
internal_address
cbfunction to call if we receive a request
cb_clsclosure for cb
cfghandle to the GNUnet configuration
Returns
NULL on error
Parameters
internal_address
cbfunction to call if we receive a request
cb_clsclosure for cb
cfgHandle to the GNUnet configuration
Returns
NULL on error

Definition at line 309 of file gnunet-service-nat_helper.c.

References HelperContext::cb, HelperContext::cb_cls, HelperContext::cfg, GN_stop_gnunet_nat_server_(), GNUNET_new, h, HelperContext::internal_address, restart_nat_server(), and HelperContext::server_stdout.

Referenced by run_scan().

313 {
314  struct HelperContext *h;
315 
316  h = GNUNET_new (struct HelperContext);
317  h->cb = cb;
318  h->cb_cls = cb_cls;
320  h->cfg = cfg;
321  restart_nat_server (h);
322  if (NULL == h->server_stdout)
323  {
325  return NULL;
326  }
327  return h;
328 }
GN_ReversalCallback cb
Function to call if we receive a reversal request.
void GN_stop_gnunet_nat_server_(struct HelperContext *h)
Start the gnunet-helper-nat-server and process incoming requests.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:104
struct GNUNET_DISK_PipeHandle * server_stdout
stdout pipe handle for the gnunet-helper-nat-server process
static void restart_nat_server(void *cls)
Task that restarts the gnunet-helper-nat-server process after a crash after a certain delay...
struct in_addr internal_address
IP address we pass to the NAT helper.
void * cb_cls
Closure for cb.
Information we keep per NAT helper process.
const struct GNUNET_CONFIGURATION_Handle * cfg
Handle to the GNUnet configuration.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GN_stop_gnunet_nat_server_()

void GN_stop_gnunet_nat_server_ ( struct HelperContext h)

Start the gnunet-helper-nat-server and process incoming requests.

Parameters
hhelper context to stop

Definition at line 338 of file gnunet-service-nat_helper.c.

References GNUNET_DISK_pipe_close(), GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log_strerror, GNUNET_OS_process_destroy(), GNUNET_OS_process_kill(), GNUNET_OS_process_wait(), GNUNET_SCHEDULER_cancel(), GNUNET_TERM_SIG, HelperContext::server_proc, HelperContext::server_read_task, HelperContext::server_stdout, and HelperContext::server_stdout_handle.

Referenced by free_lal(), and GN_start_gnunet_nat_server_().

339 {
340  if (NULL != h->server_read_task)
341  {
343  h->server_read_task = NULL;
344  }
345  if (NULL != h->server_proc)
346  {
347  if (0 != GNUNET_OS_process_kill (h->server_proc,
350  "kill");
353  h->server_proc = NULL;
355  h->server_stdout = NULL;
356  h->server_stdout_handle = NULL;
357  }
358  if (NULL != h->server_stdout)
359  {
361  h->server_stdout = NULL;
362  h->server_stdout_handle = NULL;
363  }
364  GNUNET_free (h);
365 }
struct GNUNET_OS_Process * server_proc
The process id of the server process (if behind NAT)
void GNUNET_OS_process_destroy(struct GNUNET_OS_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
Definition: os_priority.c:364
struct GNUNET_SCHEDULER_Task * server_read_task
ID of select gnunet-helper-nat-server stdout read task.
#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...
struct GNUNET_DISK_PipeHandle * server_stdout
stdout pipe handle for the gnunet-helper-nat-server process
int GNUNET_DISK_pipe_close(struct GNUNET_DISK_PipeHandle *p)
Closes an interprocess channel.
Definition: disk.c:2603
int GNUNET_OS_process_wait(struct GNUNET_OS_Process *proc)
Wait for a process to terminate.
Definition: os_priority.c:1762
const struct GNUNET_DISK_FileHandle * server_stdout_handle
stdout file handle (for reading) for the gnunet-helper-nat-server process
#define GNUNET_TERM_SIG
The termination signal.
Definition: platform.h:282
#define GNUNET_free(ptr)
Wrapper around free.
int GNUNET_OS_process_kill(struct GNUNET_OS_Process *proc, int sig)
Sends a signal to the process.
Definition: os_priority.c:251
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:

◆ GN_request_connection_reversal()

int GN_request_connection_reversal ( const struct in_addr *  internal_address,
uint16_t  internal_port,
const struct in_addr *  remote_v4,
const struct GNUNET_CONFIGURATION_Handle cfg 
)

We want to connect to a peer that is behind NAT.

Run the gnunet-helper-nat-client to send dummy ICMP responses to cause that peer to connect to us (connection reversal).

Parameters
internal_addressout internal address to use
internal_portinternal port to use
remote_v4the address of the peer (IPv4-only)
cfghandle to the GNUnet configuration
Returns
GNUNET_SYSERR on error, GNUNET_OK otherwise

Run the gnunet-helper-nat-client to send dummy ICMP responses to cause that peer to connect to us (connection reversal).

Parameters
internal_addressout internal address to use
internal_portport to use
remote_v4the address of the peer (IPv4-only)
cfghandle to the GNUnet configuration
Returns
GNUNET_SYSERR on error, GNUNET_OK otherwise

Definition at line 381 of file gnunet-service-nat_helper.c.

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_log_strerror, GNUNET_NO, GNUNET_OK, GNUNET_OS_get_suid_binary_path(), GNUNET_OS_process_destroy(), GNUNET_OS_process_wait(), GNUNET_OS_start_process(), GNUNET_snprintf(), and GNUNET_SYSERR.

Referenced by handle_request_connection_reversal().

385 {
386  char intv4[INET_ADDRSTRLEN];
387  char remv4[INET_ADDRSTRLEN];
388  char port_as_string[6];
389  struct GNUNET_OS_Process *proc;
390  char *binary;
391 
392  if (NULL == inet_ntop (AF_INET,
393  internal_address,
394  intv4,
395  INET_ADDRSTRLEN))
396  {
398  "inet_ntop");
399  return GNUNET_SYSERR;
400  }
401  if (NULL == inet_ntop (AF_INET,
402  remote_v4,
403  remv4,
404  INET_ADDRSTRLEN))
405  {
407  "inet_ntop");
408  return GNUNET_SYSERR;
409  }
410  GNUNET_snprintf (port_as_string,
411  sizeof (port_as_string),
412  "%d",
413  internal_port);
415  "Running gnunet-helper-nat-client %s %s %u\n",
416  intv4,
417  remv4,
418  internal_port);
419  binary = GNUNET_OS_get_suid_binary_path (cfg, "gnunet-helper-nat-client");
420  proc
422  0,
423  NULL,
424  NULL,
425  NULL,
426  binary,
427  "gnunet-helper-nat-client",
428  intv4,
429  remv4,
430  port_as_string,
431  NULL);
432  GNUNET_free (binary);
433  if (NULL == proc)
434  return GNUNET_SYSERR;
435  /* we know that the gnunet-helper-nat-client will terminate virtually
436  * instantly */
437  GNUNET_OS_process_wait (proc);
439  return GNUNET_OK;
440 }
void GNUNET_OS_process_destroy(struct GNUNET_OS_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
Definition: os_priority.c:364
int GNUNET_snprintf(char *buf, size_t size, const char *format,...)
Like snprintf, just aborts if the buffer is of insufficient size.
struct GNUNET_OS_Process * GNUNET_OS_start_process(int pipe_control, enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, struct GNUNET_DISK_PipeHandle *pipe_stderr, const char *filename,...)
Start a process.
Definition: os_priority.c:1400
#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...
char * GNUNET_OS_get_suid_binary_path(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *progname)
Given the name of a helper, service or daemon binary construct the full path to the binary using the ...
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
int GNUNET_OS_process_wait(struct GNUNET_OS_Process *proc)
Wait for a process to terminate.
Definition: os_priority.c:1762
#define GNUNET_log(kind,...)
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function: