126 const struct sockaddr *addr,
134 add_remove ?
"+" :
"-",
152 socklen_t remote_addrlen)
155 "Connection reversal requested by %s\n",
208 struct sockaddr_storage sa;
209 socklen_t salen =
sizeof(sa);
215 (
struct sockaddr *) &sa,
225 (
const struct sockaddr *) &sa,
248 struct sockaddr *local_sa;
249 struct sockaddr *remote_sa;
284 "Invalid socket address `%s'\n",
286 goto fail_and_shutdown;
297 "Invalid socket address `%s'\n",
299 goto fail_and_shutdown;
311 (
const struct sockaddr **) &local_sa,
320 "Use of `-W` only effective in combination with `-i`\n");
321 goto fail_and_shutdown;
328 if ((NULL == nh) || (
sizeof(
struct sockaddr_in) != local_len))
331 "Require IPv4 local address to initiate connection reversal\n");
332 goto fail_and_shutdown;
334 if (
sizeof(
struct sockaddr_in) != remote_len)
337 "Require IPv4 reversal target address\n");
338 goto fail_and_shutdown;
343 (
const struct sockaddr_in *) local_sa,
344 (
const struct sockaddr_in *) remote_sa);
349 "Connection reversal internal error\n");
354 "Connection reversal unavailable\n");
368 "Require local address to support STUN requests\n");
369 goto fail_and_shutdown;
371 if (IPPROTO_UDP !=
proto)
374 goto fail_and_shutdown;
380 goto fail_and_shutdown;
385 "Failed to bind to %s: %s\n",
388 goto fail_and_shutdown;
415 main (
int argc,
char *
const argv[])
422 gettext_noop (
"which IP and port are we locally using to bind/listen to"),
430 "which remote IP and port should be asked for connection reversal"),
438 "name of configuration section to find additional options, such as manual host punching data"),
453 "watch for connection reversal requests"),
463 "gnunet-nat [options]",
464 _ (
"GNUnet NAT traversal autoconfigure daemon"),
static int listen_reversal
Flag set to 1 if we are to listen for connection reversal requests.
Handle for active NAT registrations.
static void stun_read_task(void *cls)
Task to receive incoming packets for STUN processing.
static void do_shutdown(void *cls)
Task run on shutdown.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration, parse options).
GNUNET_NAT_AddressClass
Some addresses contain sensitive information or are not suitable for global distribution.
int GNUNET_NAT_request_reversal(struct GNUNET_NAT_Handle *nh, const struct sockaddr_in *local_sa, const struct sockaddr_in *remote_sa)
We learned about a peer (possibly behind NAT) so run the gnunet-nat-client to send dummy ICMP respons...
static int use_udp
Flag set to 1 if we use IPPROTO_UDP.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received, or when GNUNET_SCHEDULER_shutdown() is being invoked.
int GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
static uint8_t proto
Protocol to use.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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.
static int ret
Return value of the commandline.
Definition of a command line option.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static int global_ret
Value to return from main().
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_string(char shortName, const char *name, const char *argumentHelp, const char *description, char **str)
Allow user to specify a string.
static void reversal_cb(void *cls, const struct sockaddr *remote_addr, socklen_t remote_addrlen)
Signature of the callback passed to GNUNET_NAT_register().
static void address_cb(void *cls, void **app_ctx, int add_remove, enum GNUNET_NAT_AddressClass ac, const struct sockaddr *addr, socklen_t addrlen)
Signature of the callback passed to GNUNET_NAT_register() for a function to call whenever our set of ...
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
Main function that will be run.
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.
static void test_finished()
Test if all activities have finished, and if so, terminate.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
const char * GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen)
Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string (for printing debug messages)...
static char * local_addr
Local address to use for connection reversal request.
size_t GNUNET_STRINGS_parse_socket_addr(const char *addr, uint8_t *af, struct sockaddr **sa)
Parse an address given as a string into a struct sockaddr.
static struct GNUNET_NAT_Handle * nh
Handle to NAT operation.
void GNUNET_NAT_unregister(struct GNUNET_NAT_Handle *nh)
Stop port redirection and public IP address detection for the given handle.
#define GNUNET_free_nz(ptr)
Wrapper around free.
static unsigned int size
Size of the "table".
struct GNUNET_NAT_Handle * GNUNET_NAT_register(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *config_section, uint8_t proto, unsigned int num_addrs, const struct sockaddr **addrs, const socklen_t *addrlens, GNUNET_NAT_AddressCallback address_callback, GNUNET_NAT_ReversalCallback reversal_callback, void *callback_cls)
Attempt to enable port redirection and detect public IP address contacting UPnP or NAT-PMP routers on...
static struct GNUNET_MQ_Envelope * ac
Handle to current GNUNET_PEERINFO_add_peer() operation.
static struct GNUNET_NETWORK_Handle * ls
Listen socket for STUN processing.
static int use_tcp
Flag set to 1 if we use IPPROTO_TCP.
int main(int argc, char *const argv[])
Main function of gnunet-nat.
static char * remote_addr
Remote address to use for connection reversal request.
static char * section_name
Name of section in configuration file to use for additional options.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_flag(char shortName, const char *name, const char *description, int *val)
Allow user to specify a flag (which internally means setting an integer to 1/GNUNET_YES/GNUNET_OK.
#define GNUNET_log(kind,...)
Entry in list of pending tasks.
ssize_t GNUNET_NETWORK_socket_recvfrom_amount(const struct GNUNET_NETWORK_Handle *desc)
How much data is available to be read on this descriptor?
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...
static struct GNUNET_SCHEDULER_Task * rtask
Task for reading STUN packets.
ssize_t GNUNET_NETWORK_socket_recvfrom(const struct GNUNET_NETWORK_Handle *desc, void *buffer, size_t length, struct sockaddr *src_addr, socklen_t *addrlen)
Read data from a socket (always non-blocking).
static int do_stun
Should we actually bind to #bind_addr and receive and process STUN requests?
int GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
#define GNUNET_free(ptr)
Wrapper around free.
#define gettext_noop(String)
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.