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 <math.h>
#include "gnunet_util_lib.h"
#include "gnunet_protocols.h"
#include "gnunet_signatures.h"
#include "gnunet_statistics_service.h"
#include "gnunet_resolver_service.h"
#include "gnunet_nat_service.h"
#include "gnunet-service-nat.h"
#include "gnunet-service-nat_externalip.h"
#include "gnunet-service-nat_stun.h"
#include "gnunet-service-nat_mini.h"
#include "gnunet-service-nat_helper.h"
#include "nat.h"
#include <gcrypt.h>
Go to the source code of this file.
Data Structures | |
struct | GN_ExternalIPMonitor |
Handle to monitor for external IP changes. More... | |
Macros | |
#define | EXTERN_IP_RETRY_TIMEOUT |
How long do we wait until we re-try running external-ip if the command failed to terminate nicely? More... | |
#define | EXTERN_IP_RETRY_FAILURE |
How long do we wait until we re-try running external-ip if the command failed (but terminated)? More... | |
#define | EXTERN_IP_RETRY_SUCCESS |
How long do we wait until we re-try running external-ip if the command succeeded? More... | |
Functions | |
static void | notify_monitors_external_ipv4_change (int add, const struct in_addr *v4) |
Tell relevant clients about a change in our external IPv4 address. More... | |
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 possible. More... | |
static void | handle_external_ip (void *cls, const struct in_addr *addr, enum GNUNET_NAT_StatusCode result) |
We learn our current external IP address. More... | |
void | GN_nat_status_changed (int have_nat) |
We have changed our opinion about being NATed in the first place. More... | |
struct GN_ExternalIPMonitor * | GN_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... | |
Variables | |
static struct GN_ExternalIPMonitor * | mon_head |
List of monitors, kept in DLL. More... | |
static struct GN_ExternalIPMonitor * | mon_tail |
List of monitors, kept in DLL. More... | |
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). More... | |
static struct GNUNET_NAT_ExternalHandle * | probe_external_ip_op |
Handle to our operation to run external-ip . More... | |
static struct in_addr | mini_external_ipv4 |
What is our external IP address as claimed by external-ip ? 0 for unknown. More... | |
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
Definition in file gnunet-service-nat_externalip.c.
#define EXTERN_IP_RETRY_TIMEOUT |
How long do we wait until we re-try running external-ip
if the command failed to terminate nicely?
Definition at line 57 of file gnunet-service-nat_externalip.c.
#define EXTERN_IP_RETRY_FAILURE |
How long do we wait until we re-try running external-ip
if the command failed (but terminated)?
Definition at line 64 of file gnunet-service-nat_externalip.c.
#define EXTERN_IP_RETRY_SUCCESS |
How long do we wait until we re-try running external-ip
if the command succeeded?
Definition at line 71 of file gnunet-service-nat_externalip.c.
|
static |
Tell relevant clients about a change in our external IPv4 address.
add | GNUNET_YES to add, GNUNET_NO to remove |
v4 | the external address that changed |
Definition at line 138 of file gnunet-service-nat_externalip.c.
References add, mon_head, and GN_ExternalIPMonitor::next.
Referenced by handle_external_ip().
|
static |
Task used to run external-ip
to get our external IPv4 address and pass it to NATed clients if possible.
cls | NULL |
Definition at line 221 of file gnunet-service-nat_externalip.c.
References EXTERN_IP_RETRY_TIMEOUT, GNUNET_NAT_mini_get_external_ipv4_(), GNUNET_NAT_mini_get_external_ipv4_cancel_(), GNUNET_SCHEDULER_add_delayed(), handle_external_ip(), probe_external_ip_op, probe_external_ip_task, and run_external_ip().
Referenced by GN_nat_status_changed(), handle_external_ip(), and run_external_ip().
|
static |
We learn our current external IP address.
If it changed, notify all of our applicable clients. Also re-schedule run_external_ip with an appropriate timeout.
cls | NULL |
addr | the address, NULL on errors |
result | GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code |
Definition at line 170 of file gnunet-service-nat_externalip.c.
References EXTERN_IP_RETRY_FAILURE, EXTERN_IP_RETRY_SUCCESS, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_NAT_ERROR_SUCCESS, GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_cancel(), GNUNET_YES, mini_external_ipv4, notify_monitors_external_ipv4_change(), probe_external_ip_op, probe_external_ip_task, result, and run_external_ip().
Referenced by run_external_ip().
void GN_nat_status_changed | ( | int | have_nat | ) |
We have changed our opinion about being NATed in the first place.
Adapt our probing.
have_nat | GNUNET_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, probe_external_ip_op, probe_external_ip_task, and run_external_ip().
Referenced by run_scan(), and shutdown_task().
struct GN_ExternalIPMonitor * GN_external_ipv4_monitor_start | ( | GN_NotifyExternalIPv4Change | cb, |
void * | cb_cls | ||
) |
Start monitoring external IPv4 addresses.
cb | function to call on changes |
cb_cls | closure for cb |
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, mini_external_ipv4, mon_head, and mon_tail.
Referenced by handle_register().
void GN_external_ipv4_monitor_stop | ( | struct GN_ExternalIPMonitor * | mon | ) |
Stop calling monitor.
mon | monitor to call |
Definition at line 307 of file gnunet-service-nat_externalip.c.
References GNUNET_CONTAINER_DLL_remove, GNUNET_free, mon_head, and mon_tail.
Referenced by client_disconnect_cb().
|
static |
List of monitors, kept in DLL.
Definition at line 105 of file gnunet-service-nat_externalip.c.
Referenced by GN_external_ipv4_monitor_start(), GN_external_ipv4_monitor_stop(), and notify_monitors_external_ipv4_change().
|
static |
List of monitors, kept in DLL.
Definition at line 110 of file gnunet-service-nat_externalip.c.
Referenced by GN_external_ipv4_monitor_start(), and GN_external_ipv4_monitor_stop().
|
static |
Task run to obtain our external IP (if enable_upnp is set and if we find we have a NATed IP address).
Definition at line 116 of file gnunet-service-nat_externalip.c.
Referenced by GN_nat_status_changed(), handle_external_ip(), and run_external_ip().
|
static |
Handle to our operation to run external-ip
.
Definition at line 121 of file gnunet-service-nat_externalip.c.
Referenced by GN_nat_status_changed(), handle_external_ip(), and run_external_ip().
|
static |
What is our external IP address as claimed by external-ip
? 0 for unknown.
Definition at line 127 of file gnunet-service-nat_externalip.c.
Referenced by GN_external_ipv4_monitor_start(), and handle_external_ip().