GNUnet 0.21.1
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 44 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

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

273{
274 struct HelperContext *h;
275
276 h = GNUNET_new (struct HelperContext);
277 h->cb = cb;
278 h->cb_cls = cb_cls;
279 h->internal_address = *internal_address;
280 h->cfg = cfg;
282 if (NULL == h->server_stdout)
283 {
285 return NULL;
286 }
287 return h;
288}
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:109
void GN_stop_gnunet_nat_server_(struct HelperContext *h)
Start the gnunet-helper-nat-server and process incoming requests.
static void restart_nat_server(void *cls)
Task that restarts the gnunet-helper-nat-server process after a crash after a certain delay.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration that we are using.
Definition: arm_api.c:112
Information we keep per NAT helper process.
struct in_addr internal_address
IP address we pass to the NAT helper.
GN_ReversalCallback cb
Function to call if we receive a reversal request.
void * cb_cls
Closure for cb.

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

Referenced by run_scan().

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 298 of file gnunet-service-nat_helper.c.

299{
300 if (NULL != h->server_read_task)
301 {
302 GNUNET_SCHEDULER_cancel (h->server_read_task);
303 h->server_read_task = NULL;
304 }
305 if (NULL != h->server_proc)
306 {
307 if (0 != GNUNET_OS_process_kill (h->server_proc, GNUNET_TERM_SIG))
309 GNUNET_OS_process_wait (h->server_proc);
310 GNUNET_OS_process_destroy (h->server_proc);
311 h->server_proc = NULL;
312 GNUNET_DISK_pipe_close (h->server_stdout);
313 h->server_stdout = NULL;
314 h->server_stdout_handle = NULL;
315 }
316 if (NULL != h->server_stdout)
317 {
318 GNUNET_DISK_pipe_close (h->server_stdout);
319 h->server_stdout = NULL;
320 h->server_stdout_handle = NULL;
321 }
322 GNUNET_free (h);
323}
enum GNUNET_GenericReturnValue GNUNET_DISK_pipe_close(struct GNUNET_DISK_PipeHandle *p)
Closes an interprocess channel.
Definition: disk.c:1587
#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...
@ GNUNET_ERROR_TYPE_WARNING
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_OS_process_destroy(struct GNUNET_OS_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
Definition: os_priority.c:260
int GNUNET_OS_process_kill(struct GNUNET_OS_Process *proc, int sig)
Sends a signal to the process.
Definition: os_priority.c:210
enum GNUNET_GenericReturnValue GNUNET_OS_process_wait(struct GNUNET_OS_Process *proc)
Wait for a process to terminate.
Definition: os_priority.c:877
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:981
#define GNUNET_TERM_SIG
The termination signal.
Definition: platform.h:234

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, and h.

Referenced by free_lal(), and GN_start_gnunet_nat_server_().

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 339 of file gnunet-service-nat_helper.c.

343{
344 char intv4[INET_ADDRSTRLEN];
345 char remv4[INET_ADDRSTRLEN];
346 char port_as_string[6];
347 struct GNUNET_OS_Process *proc;
348 char *binary;
349
350 if (NULL == inet_ntop (AF_INET, internal_address, intv4, INET_ADDRSTRLEN))
351 {
353 return GNUNET_SYSERR;
354 }
355 if (NULL == inet_ntop (AF_INET, remote_v4, remv4, INET_ADDRSTRLEN))
356 {
358 return GNUNET_SYSERR;
359 }
360 GNUNET_snprintf (port_as_string,
361 sizeof(port_as_string),
362 "%d",
363 internal_port);
365 "Running gnunet-helper-nat-client %s %s %u\n",
366 intv4,
367 remv4,
368 internal_port);
369 binary = GNUNET_OS_get_suid_binary_path (cfg, "gnunet-helper-nat-client");
371 NULL,
372 NULL,
373 NULL,
374 binary,
375 "gnunet-helper-nat-client",
376 intv4,
377 remv4,
378 port_as_string,
379 NULL);
380 GNUNET_free (binary);
381 if (NULL == proc)
382 return GNUNET_SYSERR;
383 /* we know that the gnunet-helper-nat-client will terminate virtually
384 * instantly */
387 return GNUNET_OK;
388}
#define GNUNET_log(kind,...)
@ GNUNET_OK
@ GNUNET_SYSERR
@ GNUNET_ERROR_TYPE_DEBUG
int GNUNET_snprintf(char *buf, size_t size, const char *format,...) __attribute__((format(printf
Like snprintf, just aborts if the buffer is of insufficient size.
struct GNUNET_OS_Process * GNUNET_OS_start_process(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:626
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 ...
@ GNUNET_OS_INHERIT_STD_NONE
No standard streams should be inherited.
Definition: gnunet_os_lib.h:77

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

Referenced by handle_request_connection_reversal().

Here is the call graph for this function:
Here is the caller graph for this function: