Tor  0.4.7.0-alpha-dev
Macros | Enumerations | Functions
resolve_addr.h File Reference

Header file for resolve_addr.c. More...

#include "app/config/config.h"
#include "core/mainloop/connection.h"
#include "app/config/or_options_st.h"

Go to the source code of this file.

Macros

#define get_orport_addr(family)    (portconf_get_first_advertised_addr(CONN_TYPE_OR_LISTENER, family))
 

Enumerations

enum  resolved_addr_method_t {
  RESOLVED_ADDR_NONE = 0 , RESOLVED_ADDR_CONFIGURED = 1 , RESOLVED_ADDR_CONFIGURED_ORPORT = 2 , RESOLVED_ADDR_GETHOSTNAME = 3 ,
  RESOLVED_ADDR_INTERFACE = 4 , RESOLVED_ADDR_RESOLVED = 5
}
 

Functions

const char * resolved_addr_method_to_str (const resolved_addr_method_t method)
 
bool find_my_address (const or_options_t *options, int family, int warn_severity, tor_addr_t *addr_out, resolved_addr_method_t *method_out, char **hostname_out)
 Attempt to find our IP address that can be used as our external reachable address. More...
 
void resolved_addr_get_last (int family, tor_addr_t *addr_out)
 
void resolved_addr_reset_last (int family)
 
void resolved_addr_set_last (const tor_addr_t *addr, const resolved_addr_method_t method_used, const char *hostname_used)
 Set the last resolved address cache using the given address. More...
 
void resolved_addr_get_suggested (int family, tor_addr_t *addr_out)
 
void resolved_addr_set_suggested (const tor_addr_t *addr)
 
bool resolved_addr_is_configured (int family)
 
bool is_local_to_resolve_addr (const tor_addr_t *addr)
 : Return true iff the given addr is judged to be local to our resolved address. More...
 

Detailed Description

Header file for resolve_addr.c.

Definition in file resolve_addr.h.

Enumeration Type Documentation

◆ resolved_addr_method_t

Method used to resolved an address. In other words, how was the address discovered by tor.

Definition at line 19 of file resolve_addr.h.

Function Documentation

◆ find_my_address()

bool find_my_address ( const or_options_t options,
int  family,
int  warn_severity,
tor_addr_t addr_out,
resolved_addr_method_t method_out,
char **  hostname_out 
)

Attempt to find our IP address that can be used as our external reachable address.

The following describe the algorithm to find an address. Each have specific conditions so read carefully.

On success, true is returned and depending on how the address was found, the out parameters can have different values.

On error, false is returned and out parameters are set to NULL.

  1. Look at the configuration Address option.

    If Address is a public address, True is returned and addr_out is set with it, the method_out is set to RESOLVED_ADDR_CONFIGURED and hostname_out is set to NULL.

    If Address is an internal address but NO custom authorities are used, an error is returned.

    If Address is a hostname, that is it can't be converted to an address, it is resolved. On success, addr_out is set with the address, method_out is set to RESOLVED_ADDR_RESOLVED and hostname_out is set to the resolved hostname. On failure to resolve, an error is returned.

    If no given Address, fallback to the network interface (see section 2).

  2. Look at the network interface.

    Attempt to find the first public usable address from the list of network interfaces returned by the OS.

    On failure, we attempt to look at the local hostname (3).

    On success, addr_out is set with it, method_out is set to RESOLVED_ADDR_INTERFACE and hostname_out is set to NULL.

  3. Look at the local hostname.

    If the local hostname resolves to a non internal address, addr_out is set with it, method_out is set to RESOLVED_ADDR_GETHOSTNAME and hostname_out is set to the resolved hostname.

    If a local hostname can NOT be found, an error is returned.

    If the local hostname resolves to an internal address, an error is returned.

    If the local hostname can NOT be resolved, an error is returned.

Parameters
optionsGlobal configuration options.
familyIP address family. Only AF_INET and AF_INET6 are supported.
warn_severityLogging level.
addr_outOUT: Set with the IP address found if any.
method_outOUT: (optional) Method denoting how the address wa found. This is described in the control-spec.txt as actions for "STATUS_SERVER".
hostname_outOUT: String containing the hostname if any was used. Only be set for RESOLVED and GETHOSTNAME methods. Else it is set to NULL.
Returns
True if the address was found for the given family. False if not or on errors.

Definition at line 727 of file resolve_addr.c.

◆ is_local_to_resolve_addr()

bool is_local_to_resolve_addr ( const tor_addr_t addr)

: Return true iff the given addr is judged to be local to our resolved address.

This function is used to tell whether another address is 'remote' enough that we can trust it when it tells us that we are reachable, or that we have a certain address.

The criterion to learn if the address is local are the following:

  1. Internal address.
  2. If EnforceDistinctSubnets is set then it is never local.
  3. Network mask is compared. IPv4: /24 and IPv6 /48. This is different from the path selection that looks at /16 and /32 because we only want to learn here if the address is considered to come from the Internet basically.
Parameters
addrThe address to test if local and also test against our resovled address.
Returns
True iff address is considered local or else False.

Definition at line 819 of file resolve_addr.c.

◆ resolved_addr_get_last()

void resolved_addr_get_last ( int  family,
tor_addr_t addr_out 
)

Copy the last resolved address of family into addr_out.

If not last resolved address existed, the addr_out is a null address (use tor_addr_is_null()).

Definition at line 150 of file resolve_addr.c.

Referenced by relay_find_addr_to_publish().

◆ resolved_addr_get_suggested()

void resolved_addr_get_suggested ( int  family,
tor_addr_t addr_out 
)

Copy the last suggested address of family into addr_out.

If no last suggested address exists, the addr_out is a null address (use tor_addr_is_null() to confirm).

Definition at line 119 of file resolve_addr.c.

◆ resolved_addr_is_configured()

bool resolved_addr_is_configured ( int  family)

Return true if the last address of family was configured or not. An address is considered configured if it was found in the Address or ORPort statement.

This applies to the address returned by the function resolved_addr_get_last() which is the cache of discovered addresses.

Definition at line 109 of file resolve_addr.c.

Referenced by reachability_warnings_callback().

◆ resolved_addr_method_to_str()

const char* resolved_addr_method_to_str ( const resolved_addr_method_t  method)

Return string representation of the given method.

Definition at line 81 of file resolve_addr.c.

◆ resolved_addr_reset_last()

void resolved_addr_reset_last ( int  family)

Reset the last resolved address of family.

This makes it null address.

Definition at line 159 of file resolve_addr.c.

◆ resolved_addr_set_last()

void resolved_addr_set_last ( const tor_addr_t addr,
const resolved_addr_method_t  method_used,
const char *  hostname_used 
)

Set the last resolved address cache using the given address.

A log notice is emitted if the given address has changed from before. Not emitted on first resolve.

Control port event "STATUS_SERVER" is emitted with the new information if it has changed.

Finally, tor is notified that the IP address has changed.

Parameters
addrIP address to update the cache with.
method_usedBy which method did we resolved it (for logging and control port).
hostname_usedWhich hostname was used. If none were used, it is NULL. (for logging and control port).

Have we done a first resolve. This is used to control logging.

Definition at line 561 of file resolve_addr.c.

◆ resolved_addr_set_suggested()

void resolved_addr_set_suggested ( const tor_addr_t addr)

Set the last suggested address into our cache. This is called when we get a new NETINFO cell from a trusted source.

Definition at line 127 of file resolve_addr.c.