GNUnet 0.26.2-106-g126384b46
 
Loading...
Searching...
No Matches
gnunet-service-nat_mini.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef void(* GNUNET_NAT_IPCallback) (void *cls, const struct in_addr *addr, enum GNUNET_NAT_StatusCode result)
 Signature of a callback that is given an IP address.
 
typedef void(* GNUNET_NAT_MiniAddressCallback) (void *cls, int add_remove, const struct sockaddr *addr, socklen_t addrlen, enum GNUNET_NAT_StatusCode result)
 Signature of the callback passed to GNUNET_NAT_register() for a function to call whenever our set of 'valid' addresses changes.
 

Functions

struct GNUNET_NAT_ExternalHandleGNUNET_NAT_mini_get_external_ipv4_ (GNUNET_NAT_IPCallback cb, void *cb_cls)
 Try to get the external IPv4 address of this peer.
 
void GNUNET_NAT_mini_get_external_ipv4_cancel_ (struct GNUNET_NAT_ExternalHandle *eh)
 Cancel operation.
 
struct GNUNET_NAT_MiniHandleGNUNET_NAT_mini_map_start (uint16_t port, int is_tcp, GNUNET_NAT_MiniAddressCallback ac, void *ac_cls)
 Start mapping the given port using (mini)upnpc.
 
void GNUNET_NAT_mini_map_stop (struct GNUNET_NAT_MiniHandle *mini)
 Remove a mapping created with (mini)upnpc.
 

Typedef Documentation

◆ GNUNET_NAT_IPCallback

typedef void(* GNUNET_NAT_IPCallback) (void *cls, const struct in_addr *addr, enum GNUNET_NAT_StatusCode result)

Signature of a callback that is given an IP address.

Parameters
clsclosure
addrthe address, NULL on errors
resultGNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code

Definition at line 37 of file gnunet-service-nat_mini.h.

◆ GNUNET_NAT_MiniAddressCallback

typedef void(* GNUNET_NAT_MiniAddressCallback) (void *cls, int add_remove, const struct sockaddr *addr, socklen_t addrlen, enum GNUNET_NAT_StatusCode result)

Signature of the callback passed to GNUNET_NAT_register() for a function to call whenever our set of 'valid' addresses changes.

Parameters
clsclosure
add_removeGNUNET_YES to mean the new public IP address, GNUNET_NO to mean the previous (now invalid) one, GNUNET_SYSERR indicates an error
addreither the previous or the new public IP address
addrlenactual length of the addr
resultGNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code

Definition at line 88 of file gnunet-service-nat_mini.h.

Function Documentation

◆ GNUNET_NAT_mini_get_external_ipv4_()

struct GNUNET_NAT_ExternalHandle * GNUNET_NAT_mini_get_external_ipv4_ ( GNUNET_NAT_IPCallback  cb,
void *  cb_cls 
)

Try to get the external IPv4 address of this peer.

Parameters
cbfunction to call with result
cb_clsclosure for cb
Returns
handle for cancellation (can only be used until cb is called), NULL on error
Parameters
cbfunction to call with result
cb_clsclosure for cb
Returns
handle for cancellation (can only be used until cb is called), never NULL

Definition at line 177 of file gnunet-service-nat_mini.c.

178{
179 struct GNUNET_NAT_ExternalHandle *eh;
180
182 eh->cb = cb;
183 eh->cb_cls = cb_cls;
185 if (GNUNET_SYSERR ==
187 {
188 LOG (GNUNET_ERROR_TYPE_INFO, _ ("`external-ip' command not found\n"));
191 return eh;
192 }
194 "Running `external-ip' to determine our external IP\n");
196 if (NULL == eh->opipe)
197 {
200 return eh;
201 }
205 eh->eip,
207 STDOUT_FILENO)));
208 if (GNUNET_OK !=
210 "external-ip"))
211 {
213 eh->eip = NULL;
217 eh);
218 return eh;
219 }
225 eh->r,
227 eh);
228 return eh;
229}
static void signal_external_ip_error(void *cls)
(Asynchronously) signal error invoking external-ip to client.
#define LOG(kind,...)
static void read_external_ipv4(void *cls)
Read the output of external-ip into buf.
const struct GNUNET_DISK_FileHandle * GNUNET_DISK_pipe_handle(const struct GNUNET_DISK_PipeHandle *p, enum GNUNET_DISK_PipeEnd n)
Get the handle to a particular pipe end.
Definition disk.c:1703
struct GNUNET_DISK_PipeHandle * GNUNET_DISK_pipe(enum GNUNET_DISK_PipeFlags pf)
Creates an interprocess channel.
Definition disk.c:1524
enum GNUNET_GenericReturnValue GNUNET_DISK_pipe_close(struct GNUNET_DISK_PipeHandle *p)
Closes an interprocess channel.
Definition disk.c:1671
enum GNUNET_GenericReturnValue GNUNET_DISK_pipe_close_end(struct GNUNET_DISK_PipeHandle *p, enum GNUNET_DISK_PipeEnd end)
Closes one half of an interprocess channel.
Definition disk.c:1618
@ GNUNET_DISK_PF_BLOCKING_RW
Configure both pipe ends for blocking operations if set.
@ GNUNET_DISK_PIPE_END_WRITE
The writing-end of a pipe.
@ GNUNET_DISK_PIPE_END_READ
The reading-end of a pipe.
@ GNUNET_OK
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_DEBUG
@ GNUNET_ERROR_TYPE_INFO
#define GNUNET_new(type)
Allocate a struct or union of the given type.
@ GNUNET_NAT_ERROR_SUCCESS
Just the default.
@ GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_FAILED
Failed to run external-ip command.
@ GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_NOT_FOUND
‘external-ip’ command not found
@ GNUNET_NAT_ERROR_IPC_FAILURE
IPC Failure.
enum GNUNET_GenericReturnValue GNUNET_process_run_command(struct GNUNET_Process *p, const char *command)
Set the command and start a process.
Definition os_process.c:921
void GNUNET_process_destroy(struct GNUNET_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
Definition os_process.c:363
#define GNUNET_process_set_options(proc,...)
Set the requested options for the process.
enum GNUNET_GenericReturnValue GNUNET_OS_check_helper_binary(const char *binary, bool check_suid, const char *params)
Check whether an executable exists and possibly if the suid bit is set on the file.
#define GNUNET_process_option_inherit_wpipe(wpipe, child_fd)
Have child process inherit a pipe for writing.
struct GNUNET_Process * GNUNET_process_create(enum GNUNET_OS_InheritStdioFlags std_inheritance)
Create a process handle.
Definition os_process.c:462
@ GNUNET_OS_INHERIT_STD_NONE
No standard streams should be inherited.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_file(struct GNUNET_TIME_Relative delay, const struct GNUNET_DISK_FileHandle *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...
Definition scheduler.c:1667
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:1310
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
#define _(String)
GNU gettext support macro.
Definition platform.h:179
Opaque handle to cancel "GNUNET_NAT_mini_get_external_ipv4" operation.
size_t off
Number of bytes in buf that are valid.
GNUNET_NAT_IPCallback cb
Function to call with the result.
struct GNUNET_DISK_PipeHandle * opipe
Handle to stdout pipe of external-ip.
const struct GNUNET_DISK_FileHandle * r
Read handle of opipe.
enum GNUNET_NAT_StatusCode ret
Error code for better debugging and user feedback.
struct GNUNET_SCHEDULER_Task * task
Read task.
struct GNUNET_Process * eip
Handle to external-ip process.

References _, GNUNET_NAT_ExternalHandle::cb, GNUNET_NAT_ExternalHandle::cb_cls, GNUNET_NAT_ExternalHandle::eip, GNUNET_assert, GNUNET_DISK_PF_BLOCKING_RW, GNUNET_DISK_pipe(), GNUNET_DISK_pipe_close(), GNUNET_DISK_pipe_close_end(), GNUNET_DISK_PIPE_END_READ, GNUNET_DISK_PIPE_END_WRITE, GNUNET_DISK_pipe_handle(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_FAILED, GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_NOT_FOUND, GNUNET_NAT_ERROR_IPC_FAILURE, GNUNET_NAT_ERROR_SUCCESS, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_OS_check_helper_binary(), GNUNET_OS_INHERIT_STD_NONE, GNUNET_process_create(), GNUNET_process_destroy(), GNUNET_process_option_inherit_wpipe, GNUNET_process_run_command(), GNUNET_process_set_options, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_add_read_file(), GNUNET_SYSERR, GNUNET_TIME_UNIT_FOREVER_REL, LOG, GNUNET_NAT_ExternalHandle::off, GNUNET_NAT_ExternalHandle::opipe, GNUNET_NAT_ExternalHandle::r, read_external_ipv4(), GNUNET_NAT_ExternalHandle::ret, signal_external_ip_error(), and GNUNET_NAT_ExternalHandle::task.

Referenced by run_external_ip().

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

◆ GNUNET_NAT_mini_get_external_ipv4_cancel_()

void GNUNET_NAT_mini_get_external_ipv4_cancel_ ( struct GNUNET_NAT_ExternalHandle eh)

Cancel operation.

Parameters
ehoperation to cancel

Definition at line 238 of file gnunet-service-nat_mini.c.

239{
240 if (NULL != eh->eip)
241 {
242 (void) GNUNET_process_kill (eh->eip,
243 SIGKILL);
246 true,
247 NULL,
248 NULL));
250 }
251 if (NULL != eh->opipe)
252 {
254 eh->opipe = NULL;
255 }
256 if (NULL != eh->task)
257 {
259 eh->task = NULL;
260 }
261 GNUNET_free (eh);
262}
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_free(ptr)
Wrapper around free.
enum GNUNET_GenericReturnValue GNUNET_process_wait(struct GNUNET_Process *proc, bool blocking, enum GNUNET_OS_ProcessStatusType *type, unsigned long *code)
Wait for a process to terminate.
enum GNUNET_GenericReturnValue GNUNET_process_kill(struct GNUNET_Process *proc, int sig)
Sends a signal to the process.
Definition os_process.c:307
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition scheduler.c:986

References GNUNET_NAT_ExternalHandle::eip, GNUNET_break, GNUNET_DISK_pipe_close(), GNUNET_free, GNUNET_OK, GNUNET_process_destroy(), GNUNET_process_kill(), GNUNET_process_wait(), GNUNET_SCHEDULER_cancel(), GNUNET_NAT_ExternalHandle::off, GNUNET_NAT_ExternalHandle::opipe, and GNUNET_NAT_ExternalHandle::task.

Referenced by GN_nat_status_changed(), read_external_ipv4(), and run_external_ip().

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

◆ GNUNET_NAT_mini_map_start()

struct GNUNET_NAT_MiniHandle * GNUNET_NAT_mini_map_start ( uint16_t  port,
int  is_tcp,
GNUNET_NAT_MiniAddressCallback  ac,
void *  ac_cls 
)

Start mapping the given port using (mini)upnpc.

This function should typically not be used directly (it is used within the general-purpose GNUNET_NAT_register() code). However, it can be used if specifically UPnP-based NAT traversal is to be used or tested.

Parameters
portport to map
is_tcpGNUNET_YES to map TCP, GNUNET_NO for UDP
acfunction to call with mapping result
ac_clsclosure for ac
Returns
NULL on error

This function should typically not be used directly (it is used within the general-purpose GNUNET_NAT_register() code). However, it can be used if specifically UPnP-based NAT traversal is to be used or tested.

Parameters
portport to map
is_tcpGNUNET_YES to map TCP, GNUNET_NO for UDP
acfunction to call with mapping result
ac_clsclosure for ac
Returns
NULL on error (no 'upnpc' installed)

Definition at line 604 of file gnunet-service-nat_mini.c.

608{
610
612 {
613 LOG (GNUNET_ERROR_TYPE_INFO, _ ("`upnpc' command not found\n"));
615 return NULL;
616 }
617 LOG (GNUNET_ERROR_TYPE_DEBUG, "Running `upnpc' to install mapping\n");
619 ret->ac = ac;
620 ret->ac_cls = ac_cls;
621 ret->is_tcp = is_tcp;
622 ret->port = port;
623 ret->refresh_task =
626 return ret;
627}
static int ret
Final status code.
Definition gnunet-arm.c:93
static uint16_t port
Port number.
Definition gnunet-bcd.c:146
static void run_upnpc_r(struct GNUNET_NAT_MiniHandle *mini)
Run "upnpc -r" to map our internal port.
#define MAP_REFRESH_FREQ
How often do we check for changes in the mapping?
static void do_refresh(void *cls)
Run "upnpc -l" to find out if our mapping changed.
@ GNUNET_NAT_ERROR_UPNPC_NOT_FOUND
upnpc command not found
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition scheduler.c:1283
Handle to a mapping created with upnpc.
void * ac_cls
Closure for ac.
int is_tcp
Are we mapping TCP or UDP?
GNUNET_NAT_MiniAddressCallback ac
Function to call on mapping changes.

References _, GNUNET_NAT_MiniHandle::ac, GNUNET_NAT_MiniHandle::ac_cls, do_refresh(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_NAT_ERROR_UPNPC_NOT_FOUND, GNUNET_new, GNUNET_NO, GNUNET_OS_check_helper_binary(), GNUNET_SCHEDULER_add_delayed(), GNUNET_SYSERR, GNUNET_NAT_MiniHandle::is_tcp, LOG, MAP_REFRESH_FREQ, port, ret, and run_upnpc_r().

Referenced by handle_register().

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

◆ GNUNET_NAT_mini_map_stop()

void GNUNET_NAT_mini_map_stop ( struct GNUNET_NAT_MiniHandle mini)

Remove a mapping created with (mini)upnpc.

Calling this function will give 'upnpc' 1s to remove the mapping, so while this function is non-blocking, a task will be left with the scheduler for up to 1s past this call.

Parameters
minithe handle

Definition at line 654 of file gnunet-service-nat_mini.c.

655{
656 char pstr[6];
657
658 if (NULL != mini->refresh_task)
659 {
661 mini->refresh_task = NULL;
662 }
663 if (NULL != mini->refresh_cmd)
664 {
666 mini->refresh_cmd = NULL;
667 }
668 if (NULL != mini->map_cmd)
669 {
671 mini->map_cmd = NULL;
672 }
673 if (GNUNET_NO == mini->did_map)
674 {
675 GNUNET_free (mini);
676 return;
677 }
678 mini->ac (mini->ac_cls,
679 GNUNET_NO,
680 (const struct sockaddr *) &mini->current_addr,
681 sizeof(mini->current_addr),
683 /* Note: oddly enough, deletion uses the external port whereas
684 * addition uses the internal port; this rarely matters since they
685 * often are the same, but it might... */
686 GNUNET_snprintf (pstr,
687 sizeof(pstr),
688 "%u",
689 (unsigned int) ntohs (mini->current_addr.sin_port));
691 "Unmapping port %u with UPnP\n",
692 ntohs (mini->current_addr.sin_port));
694 mini,
696 "upnpc",
697 "upnpc",
698 "-d",
699 pstr,
700 mini->is_tcp ? "tcp" : "udp",
701 NULL);
702}
#define UNMAP_TIMEOUT
How long do we give upnpc to remove a mapping?
static void process_unmap_output(void *cls, const char *line)
Process output from our 'unmap' command.
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.
void GNUNET_OS_command_stop(struct GNUNET_OS_CommandHandle *cmd)
Stop/kill a command.
struct GNUNET_OS_CommandHandle * GNUNET_OS_command_run(GNUNET_OS_LineProcessor proc, void *proc_cls, struct GNUNET_TIME_Relative timeout, const char *binary,...)
Run the given command line and call the given function for each line of the output.
struct GNUNET_OS_CommandHandle * unmap_cmd
Command used to remove the mapping.
struct GNUNET_OS_CommandHandle * map_cmd
Command used to install the map.
struct GNUNET_OS_CommandHandle * refresh_cmd
Command used to refresh our map information.
int did_map
Did we succeed with creating a mapping?
struct GNUNET_SCHEDULER_Task * refresh_task
We check the mapping periodically to see if it still works.
struct sockaddr_in current_addr
Our current external mapping (if we have one).

References GNUNET_NAT_MiniHandle::ac, GNUNET_NAT_MiniHandle::ac_cls, GNUNET_NAT_MiniHandle::current_addr, GNUNET_NAT_MiniHandle::did_map, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_NAT_ERROR_SUCCESS, GNUNET_NO, GNUNET_OS_command_run(), GNUNET_OS_command_stop(), GNUNET_SCHEDULER_cancel(), GNUNET_snprintf(), GNUNET_NAT_MiniHandle::is_tcp, LOG, GNUNET_NAT_MiniHandle::map_cmd, process_unmap_output(), GNUNET_NAT_MiniHandle::refresh_cmd, GNUNET_NAT_MiniHandle::refresh_task, GNUNET_NAT_MiniHandle::unmap_cmd, and UNMAP_TIMEOUT.

Referenced by client_disconnect_cb().

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