GNUnet  0.11.x
Typedefs | Functions
gnunet-service-nat_externalip.h File Reference

Code to figure out what our external IPv4 address(es) might be (external IPv4s are what is seen on the rest of the Internet). More...

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

Go to the source code of this file.

Typedefs

typedef void(* GN_NotifyExternalIPv4Change) (void *cls, const struct in_addr *ip, int add_remove)
 Function we call when we believe our external IPv4 address changed. More...
 

Functions

void GN_nat_status_changed (int have_nat)
 We have changed our opinion about being NATed in the first place. More...
 
struct GN_ExternalIPMonitorGN_external_ipv4_monitor_start (GN_NotifyExternalIPv4Change cb, void *cb_cls)
 Start monitoring external IPv4 addresses. More...
 
void GN_external_ipv4_monitor_stop (struct GN_ExternalIPMonitor *mon)
 Stop calling monitor. More...
 

Detailed Description

Code to figure out what our external IPv4 address(es) might be (external IPv4s are what is seen on the rest of the Internet).

This can be implemented using different methods, and we allow the main service to be notified about changes to what we believe is our external IPv4 address.

Note that this is explicitly only about NATed systems; if one of our network interfaces has a global IP address this does not count as "external".

Functions for monitoring external IPv4 addresses

Author
Christian Grothoff

Definition in file gnunet-service-nat_externalip.h.

Typedef Documentation

◆ GN_NotifyExternalIPv4Change

typedef void(* GN_NotifyExternalIPv4Change) (void *cls, const struct in_addr *ip, int add_remove)

Function we call when we believe our external IPv4 address changed.

Parameters
clsclosure
ipaddress to add/remove
add_removeGNUNET_YES to add, GNUNET_NO to remove

Definition at line 60 of file gnunet-service-nat_externalip.h.

Function Documentation

◆ GN_nat_status_changed()

void GN_nat_status_changed ( int  have_nat)

We have changed our opinion about being NATed in the first place.

Adapt our probing.

Parameters
have_natGNUNET_YES if we believe we are behind NAT

Definition at line 245 of file gnunet-service-nat_externalip.c.

References enable_upnp, GNUNET_NAT_mini_get_external_ipv4_cancel_(), GNUNET_NO, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), GNUNET_YES, and run_external_ip().

Referenced by run_scan(), and shutdown_task().

246 {
247  if (GNUNET_YES != enable_upnp)
248  return;
249  if ((GNUNET_YES == have_nat) &&
250  (NULL == probe_external_ip_task) &&
251  (NULL == probe_external_ip_op))
252  {
255  NULL);
256  return;
257  }
258  if (GNUNET_NO == have_nat)
259  {
260  if (NULL != probe_external_ip_task)
261  {
263  probe_external_ip_task = NULL;
264  }
265  if (NULL != probe_external_ip_op)
266  {
268  probe_external_ip_op = NULL;
269  }
270  }
271 }
static void run_external_ip(void *cls)
Task used to run external-ip to get our external IPv4 address and pass it to NATed clients if possibl...
#define GNUNET_NO
Definition: gnunet_common.h:78
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:1280
static struct GNUNET_SCHEDULER_Task * probe_external_ip_task
Task run to obtain our external IP (if enable_upnp is set and if we find we have a NATed IP address)...
int enable_upnp
Is UPnP enabled? GNUNET_YES if enabled, GNUNET_NO if disabled, GNUNET_SYSERR if configuration enabled...
static struct GNUNET_NAT_ExternalHandle * probe_external_ip_op
Handle to our operation to run external-ip.
#define GNUNET_YES
Definition: gnunet_common.h:77
void GNUNET_NAT_mini_get_external_ipv4_cancel_(struct GNUNET_NAT_ExternalHandle *eh)
Cancel operation.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GN_external_ipv4_monitor_start()

struct GN_ExternalIPMonitor* GN_external_ipv4_monitor_start ( GN_NotifyExternalIPv4Change  cb,
void *  cb_cls 
)

Start monitoring external IPv4 addresses.

Parameters
cbfunction to call on changes
cb_clsclosure for cb
Returns
handle to cancel

Definition at line 282 of file gnunet-service-nat_externalip.c.

References GN_ExternalIPMonitor::cb, GN_ExternalIPMonitor::cb_cls, GNUNET_CONTAINER_DLL_insert, GNUNET_new, GNUNET_YES, and mini_external_ipv4.

Referenced by handle_register().

284 {
285  struct GN_ExternalIPMonitor *mon;
286 
287  mon = GNUNET_new (struct GN_ExternalIPMonitor);
288  mon->cb = cb;
289  mon->cb_cls = cb_cls;
291  mon_tail,
292  mon);
293  if (0 != mini_external_ipv4.s_addr)
294  cb (cb_cls,
296  GNUNET_YES);
297  return mon;
298 }
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Handle to monitor for external IP changes.
static struct in_addr mini_external_ipv4
What is our external IP address as claimed by external-ip? 0 for unknown.
static struct GN_ExternalIPMonitor * mon_head
List of monitors, kept in DLL.
GN_NotifyExternalIPv4Change cb
Function to call when we believe our external IPv4 address changed.
#define GNUNET_YES
Definition: gnunet_common.h:77
static struct GN_ExternalIPMonitor * mon_tail
List of monitors, kept in DLL.
Here is the caller graph for this function:

◆ GN_external_ipv4_monitor_stop()

void GN_external_ipv4_monitor_stop ( struct GN_ExternalIPMonitor mon)

Stop calling monitor.

Parameters
monmonitor to call

Definition at line 307 of file gnunet-service-nat_externalip.c.

References GNUNET_CONTAINER_DLL_remove, and GNUNET_free.

Referenced by client_disconnect_cb().

308 {
310  mon_tail,
311  mon);
312  GNUNET_free (mon);
313 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
static struct GN_ExternalIPMonitor * mon_head
List of monitors, kept in DLL.
static struct GN_ExternalIPMonitor * mon_tail
List of monitors, kept in DLL.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function: