|
Tor 0.4.9.3-alpha-dev
|
Headers for address.h. More...
#include "orconfig.h"#include "lib/cc/torint.h"#include "lib/log/util_bug.h"#include "lib/net/inaddr_st.h"#include "lib/net/nettypes.h"#include <stddef.h>#include <stdlib.h>Go to the source code of this file.
Data Structures | |
| struct | tor_addr_t |
| struct | tor_addr_port_t |
Macros | |
| #define | TOR_ADDR_NULL {AF_UNSPEC, {0}} |
| #define | tor_addr_port_make_null(addr, port, family) (void)(tor_addr_make_null(addr, family), (port) = 0) |
| #define | tor_addr_port_make_null_ap(ap, family) tor_addr_port_make_null(&(ap)->addr, (ap)->port, family) |
| #define | tor_addr_to_in6_addr8(x) tor_addr_to_in6_assert(x)->s6_addr |
| #define | tor_addr_to_in6_addr16(x) S6_ADDR16(*tor_addr_to_in6_assert(x)) |
| #define | tor_addr_to_in6_addr32(x) S6_ADDR32(*tor_addr_to_in6_assert(x)) |
| #define | TOR_ADDR_BUF_LEN 48 |
| #define | TOR_ADDRPORT_BUF_LEN (TOR_ADDR_BUF_LEN + 6) |
| #define | fmt_addr(a) fmt_addr_impl((a), 0) |
| #define | fmt_and_decorate_addr(a) fmt_addr_impl((a), 1) |
| #define | fmt_addrport_ap(ap) fmt_addrport(&(ap)->addr, (ap)->port) |
| #define | interface_address6_list_free(addrs) FREE_AND_NULL(struct smartlist_t, interface_address6_list_free_, (addrs)) |
| #define | tor_addr_eq(a, b) (0==tor_addr_compare((a),(b),CMP_EXACT)) |
| #define | tor_addr_is_internal(addr, for_listening) tor_addr_is_internal_((addr), (for_listening), SHORT_FILE__, __LINE__) |
| #define | REVERSE_LOOKUP_NAME_BUF_LEN 73 |
| #define | TAPMP_EXTENDED_STAR 1 |
| #define | TAPMP_STAR_IPV4_ONLY (1 << 1) |
| #define | TAPMP_STAR_IPV6_ONLY (1 << 2) |
| #define | tor_addr_from_ipv4h(dest, v4addr) tor_addr_from_ipv4n((dest), htonl(v4addr)) |
| #define | tor_addr_from_in(dest, in) tor_addr_from_ipv4n((dest), (in)->s_addr); |
| #define | tor_addr_is_valid_ipv4h(v4h_addr, for_listening) tor_addr_is_valid_ipv4n(htonl(v4h_addr), (for_listening)) |
| #define | tor_addr_port_is_valid(addr, port, for_listening) |
| #define | tor_addr_port_is_valid_ap(ap, for_listening) tor_addr_port_is_valid(&(ap)->addr, (ap)->port, (for_listening)) |
| #define | tor_addr_port_is_valid_ipv4n(v4n_addr, port, for_listening) |
| #define | tor_addr_port_is_valid_ipv4h(v4h_addr, port, for_listening) |
| #define | interface_address_list_free(lst) interface_address6_list_free(lst) |
Typedefs | |
| typedef uint8_t | maskbits_t |
Enumerations | |
| enum | tor_addr_comparison_t { CMP_EXACT , CMP_SEMANTIC } |
Functions | |
| static const struct in6_addr * | tor_addr_to_in6 (const tor_addr_t *a) |
| static const struct in6_addr * | tor_addr_to_in6_assert (const tor_addr_t *a) |
| static uint32_t | tor_addr_to_ipv4n (const tor_addr_t *a) |
| static uint32_t | tor_addr_to_ipv4h (const tor_addr_t *a) |
| static uint32_t | tor_addr_to_mapped_ipv4h (const tor_addr_t *a) |
| static sa_family_t | tor_addr_family (const tor_addr_t *a) |
| static bool | tor_addr_is_unspec (const tor_addr_t *a) |
| static const struct in_addr * | tor_addr_to_in (const tor_addr_t *a) |
| static int | tor_addr_eq_ipv4h (const tor_addr_t *a, uint32_t u) |
| socklen_t | tor_addr_to_sockaddr (const tor_addr_t *a, uint16_t port, struct sockaddr *sa_out, socklen_t len) |
| int | tor_addr_from_sockaddr (tor_addr_t *a, const struct sockaddr *sa, uint16_t *port_out) |
| void | tor_addr_make_unspec (tor_addr_t *a) |
| void | tor_addr_make_null (tor_addr_t *a, sa_family_t family) |
| char * | tor_sockaddr_to_str (const struct sockaddr *sa) |
| char * | tor_addr_to_str_dup (const tor_addr_t *addr) ATTR_MALLOC |
| const char * | fmt_addr_impl (const tor_addr_t *addr, int decorate) |
| const char * | fmt_addrport (const tor_addr_t *addr, uint16_t port) |
| const char * | fmt_addr32 (uint32_t addr) |
| const char * | fmt_addr32_port (uint32_t addr, uint16_t port) |
| const char * | fmt_af_family (sa_family_t family) |
| const char * | fmt_addr_family (const tor_addr_t *addr) |
| int | get_interface_address6 (int severity, sa_family_t family, tor_addr_t *addr) |
| void | interface_address6_list_free_ (struct smartlist_t *addrs) |
| struct smartlist_t * | get_interface_address6_list (int severity, sa_family_t family, int include_internal) |
| int | tor_addr_compare (const tor_addr_t *addr1, const tor_addr_t *addr2, tor_addr_comparison_t how) |
| int | tor_addr_compare_masked (const tor_addr_t *addr1, const tor_addr_t *addr2, maskbits_t mask, tor_addr_comparison_t how) |
| uint64_t | tor_addr_hash (const tor_addr_t *addr) |
| uint64_t | tor_addr_keyed_hash (const struct sipkey *key, const tor_addr_t *addr) |
| int | tor_addr_is_v4 (const tor_addr_t *addr) |
| int | tor_addr_is_v6 (const tor_addr_t *addr) |
| int | tor_addr_is_internal_ (const tor_addr_t *ip, int for_listening, const char *filename, int lineno) |
| int | tor_addr_is_multicast (const tor_addr_t *a) |
| int | tor_addr_to_PTR_name (char *out, size_t outlen, const tor_addr_t *addr) |
| int | tor_addr_parse_PTR_name (tor_addr_t *result, const char *address, int family, int accept_regular) |
| int | tor_addr_parse_mask_ports (const char *s, unsigned flags, tor_addr_t *addr_out, maskbits_t *mask_out, uint16_t *port_min_out, uint16_t *port_max_out) |
| const char * | tor_addr_to_str (char *dest, const tor_addr_t *addr, size_t len, int decorate) |
| int | tor_addr_parse (tor_addr_t *addr, const char *src) |
| void | tor_addr_copy (tor_addr_t *dest, const tor_addr_t *src) |
| void | tor_addr_copy_tight (tor_addr_t *dest, const tor_addr_t *src) |
| void | tor_addr_from_ipv4n (tor_addr_t *dest, uint32_t v4addr) |
| void | tor_addr_from_ipv6_bytes (tor_addr_t *dest, const uint8_t *bytes) |
| void | tor_addr_from_in6 (tor_addr_t *dest, const struct in6_addr *in6) |
| void | tor_addr_copy_ipv6_bytes (uint8_t *dest, const tor_addr_t *src) |
| int | tor_addr_is_null (const tor_addr_t *addr) |
| int | tor_addr_is_loopback (const tor_addr_t *addr) |
| int | tor_addr_is_valid (const tor_addr_t *addr, int for_listening) |
| int | tor_addr_is_valid_ipv4n (uint32_t v4n_addr, int for_listening) |
| int | tor_port_is_valid (uint16_t port, int for_listening) |
| int | tor_addr_port_split (int severity, const char *addrport, char **address_out, uint16_t *port_out) |
| int | tor_addr_port_parse (int severity, const char *addrport, tor_addr_t *address_out, uint16_t *port_out, int default_port) |
| int | tor_addr_hostname_is_local (const char *name) |
| int | parse_port_range (const char *port, uint16_t *port_min_out, uint16_t *port_max_out) |
| int | addr_mask_get_bits (uint32_t mask) |
| char * | tor_dup_ip (uint32_t addr) ATTR_MALLOC |
| int | get_interface_address (int severity, uint32_t *addr) |
| static struct smartlist_t * | get_interface_address_list (int severity, int include_internal) |
| tor_addr_port_t * | tor_addr_port_new (const tor_addr_t *addr, uint16_t port) |
| int | tor_addr_port_eq (const tor_addr_port_t *a, const tor_addr_port_t *b) |
| void | tor_addr_port_copy (tor_addr_port_t *dest, const tor_addr_port_t *source) |
| int | string_is_valid_dest (const char *string) |
| int | string_is_valid_nonrfc_hostname (const char *string) |
| int | string_is_valid_ipv4_address (const char *string) |
| int | string_is_valid_ipv6_address (const char *string) |
| #define fmt_addr | ( | a | ) | fmt_addr_impl((a), 0) |
Wrapper function of fmt_addr_impl(). It does not decorate IPv6 addresses.
| #define fmt_addrport_ap | ( | ap | ) | fmt_addrport(&(ap)->addr, (ap)->port) |
| #define fmt_and_decorate_addr | ( | a | ) | fmt_addr_impl((a), 1) |
Wrapper function of fmt_addr_impl(). It decorates IPv6 addresses.
| #define interface_address6_list_free | ( | addrs | ) | FREE_AND_NULL(struct smartlist_t, interface_address6_list_free_, (addrs)) |
| #define interface_address_list_free | ( | lst | ) | interface_address6_list_free(lst) |
| #define REVERSE_LOOKUP_NAME_BUF_LEN 73 |
| #define TOR_ADDR_BUF_LEN 48 |
Length of a buffer that you need to allocate to be sure you can encode any tor_addr_t.
This allows enough space for "[ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255]", plus a terminating NUL.
| #define tor_addr_eq | ( | a, | |
| b | |||
| ) | (0==tor_addr_compare((a),(b),CMP_EXACT)) |
| #define tor_addr_from_in | ( | dest, | |
| in | |||
| ) | tor_addr_from_ipv4n((dest), (in)->s_addr); |
| #define tor_addr_from_ipv4h | ( | dest, | |
| v4addr | |||
| ) | tor_addr_from_ipv4n((dest), htonl(v4addr)) |
| #define tor_addr_is_internal | ( | addr, | |
| for_listening | |||
| ) | tor_addr_is_internal_((addr), (for_listening), SHORT_FILE__, __LINE__) |
| #define tor_addr_is_valid_ipv4h | ( | v4h_addr, | |
| for_listening | |||
| ) | tor_addr_is_valid_ipv4n(htonl(v4h_addr), (for_listening)) |
| #define tor_addr_port_is_valid | ( | addr, | |
| port, | |||
| for_listening | |||
| ) |
| #define tor_addr_port_is_valid_ap | ( | ap, | |
| for_listening | |||
| ) | tor_addr_port_is_valid(&(ap)->addr, (ap)->port, (for_listening)) |
| #define tor_addr_port_is_valid_ipv4h | ( | v4h_addr, | |
| port, | |||
| for_listening | |||
| ) |
| #define tor_addr_port_is_valid_ipv4n | ( | v4n_addr, | |
| port, | |||
| for_listening | |||
| ) |
| #define tor_addr_port_make_null | ( | addr, | |
| port, | |||
| family | |||
| ) | (void)(tor_addr_make_null(addr, family), (port) = 0) |
| #define tor_addr_port_make_null_ap | ( | ap, | |
| family | |||
| ) | tor_addr_port_make_null(&(ap)->addr, (ap)->port, family) |
| #define tor_addr_to_in6_addr16 | ( | x | ) | S6_ADDR16(*tor_addr_to_in6_assert(x)) |
| #define tor_addr_to_in6_addr32 | ( | x | ) | S6_ADDR32(*tor_addr_to_in6_assert(x)) |
| #define tor_addr_to_in6_addr8 | ( | x | ) | tor_addr_to_in6_assert(x)->s6_addr |
| #define TOR_ADDRPORT_BUF_LEN (TOR_ADDR_BUF_LEN + 6) |
| typedef uint8_t maskbits_t |
| int addr_mask_get_bits | ( | uint32_t | mask | ) |
If mask is an address mask for a bit-prefix, return the number of bits. Otherwise, return -1.
Definition at line 1975 of file address.c.
Referenced by tor_addr_parse_mask_ports().
| const char * fmt_addr32 | ( | uint32_t | addr | ) |
Like fmt_addr(), but takes addr as a host-order IPv4 addresses. Also not thread-safe, also clobbers its return buffer on repeated calls. Clean internal buffer and return empty string on failure.
Definition at line 1210 of file address.c.
Referenced by fmt_addr32_port(), and get_stored_bindaddr_for_server_transport().
| const char * fmt_addr32_port | ( | uint32_t | addr, |
| uint16_t | port | ||
| ) |
Like fmt_addrport(), but takes addr as a host-order IPv4 addresses. Also not thread-safe, also clobbers its return buffer on repeated calls.
| const char * fmt_addr_family | ( | const tor_addr_t * | addr | ) |
| const char * fmt_addr_impl | ( | const tor_addr_t * | addr, |
| int | decorate | ||
| ) |
Return a string representing the address addr. This string is statically allocated, and must not be freed. Each call to fmt_addr_impl invalidates the last result of the function. This function is not thread-safe. If decorate is set, add brackets to IPv6 addresses.
It's better to use the wrapper macros of this function: fmt_addr() and fmt_and_decorate_addr().
| const char * fmt_addrport | ( | const tor_addr_t * | addr, |
| uint16_t | port | ||
| ) |
Return a string representing the pair addr and port. This calls fmt_and_decorate_addr internally, so IPv6 addresses will have brackets, and the caveats of fmt_addr_impl apply.
Definition at line 1199 of file address.c.
Referenced by bridge_add_from_config(), bridge_resolve_conflicts(), compute_routerstatus_consensus(), connection_https_proxy_connect(), connection_listener_new(), extend_info_from_node(), fetch_bridge_descriptors(), inform_testing_reachability(), learned_router_identity(), log_failed_proxy_connection(), port_warn_nonlocal_ext_orports(), pt_get_extra_info_descriptor_string(), pt_parse_transport_line(), register_server_proxy(), rewrite_node_address_for_bridge(), routerconf_find_ipv6_or_ap(), routerstatus_format_entry(), save_transport_to_state(), transport_add_from_config(), transport_resolve_conflicts(), and warn_nonlocal_client_ports().
| const char * fmt_af_family | ( | sa_family_t | family | ) |
Return a string representing family.
This string is a string constant, and must not be freed. This function is thread-safe.
Definition at line 1246 of file address.c.
Referenced by fmt_addr_family(), get_address_from_config(), inform_testing_reachability(), relay_find_addr_to_publish(), and router_do_orport_reachability_checks().
| int get_interface_address | ( | int | severity, |
| uint32_t * | addr | ||
| ) |
Set *addr to a host-order IPv4 address (if any) of an interface that connects to the Internet. Prefer public IP addresses to internal IP addresses. This address should only be used in checking whether our address has changed, as it may be an internal IPv4 address. Return 0 on success, -1 on failure. Prefer get_interface_address_list6 for a list of all IPv4 and IPv6 addresses on all interfaces which connect to the Internet.
| int get_interface_address6 | ( | int | severity, |
| sa_family_t | family, | ||
| tor_addr_t * | addr | ||
| ) |
Set *addr to an arbitrary IP address (if any) of an interface that connects to the Internet. Prefer public IP addresses to internal IP addresses. This address should only be used in checking whether our address has changed, as it may be an internal IP address. Return 0 on success, -1 on failure. Prefer get_interface_address6_list for a list of all addresses on all interfaces which connect to the Internet.
Definition at line 1723 of file address.c.
Referenced by client_check_address_changed(), get_address_from_interface(), and get_interface_address().
| struct smartlist_t * get_interface_address6_list | ( | int | severity, |
| sa_family_t | family, | ||
| int | include_internal | ||
| ) |
Return a smartlist of the IP addresses of type family from all interfaces on the server. Excludes loopback and multicast addresses. Only includes internal addresses if include_internal is true. (Note that a relay behind NAT may use an internal address to connect to the Internet.) An empty smartlist means that there are no addresses of the selected type matching these criteria. Returns NULL on failure. Use interface_address6_list_free to free the returned list.
Definition at line 1777 of file address.c.
Referenced by get_interface_address6(), get_interface_address_list(), and policies_parse_exit_policy_reject_private().
|
inlinestatic |
Return a smartlist of the IPv4 addresses of all interfaces on the server. Excludes loopback and multicast addresses. Only includes internal addresses if include_internal is true. (Note that a relay behind NAT may use an internal address to connect to the Internet.) An empty smartlist means that there are no IPv4 addresses. Returns NULL on failure. Use free_interface_address_list to free the returned list.
| void interface_address6_list_free_ | ( | smartlist_t * | addrs | ) |
| int parse_port_range | ( | const char * | port, |
| uint16_t * | port_min_out, | ||
| uint16_t * | port_max_out | ||
| ) |
Parse a string s in the format of (*|port(-maxport)?)?, setting the various *out pointers as appropriate. Return 0 on success, -1 on failure.
Definition at line 1994 of file address.c.
Referenced by router_parse_addr_policy_private(), and tor_addr_parse_mask_ports().
| int string_is_valid_dest | ( | const char * | string | ) |
Return true iff string is a valid destination address, i.e. either a DNS hostname or IPv4/IPv6 address string.
Definition at line 2155 of file address.c.
Referenced by process_socks4_request(), and process_socks5_client_request().
| int string_is_valid_ipv4_address | ( | const char * | string | ) |
Return true if string represents a valid IPv4 address in 'a.b.c.d' form.
Definition at line 2133 of file address.c.
Referenced by parse_dir_authority_line(), string_is_valid_dest(), and string_is_valid_nonrfc_hostname().
| int string_is_valid_ipv6_address | ( | const char * | string | ) |
Return true if string represents a valid IPv6 address in a form that inet_pton() can parse.
Definition at line 2144 of file address.c.
Referenced by string_is_valid_dest().
| int string_is_valid_nonrfc_hostname | ( | const char * | string | ) |
Return true iff string matches a pattern of DNS names that we allow Tor clients to connect to.
Note: This allows certain technically invalid characters ('_') to cope with misconfigured zones that have been encountered in the wild.
Definition at line 2188 of file address.c.
Referenced by string_is_valid_dest().
| int tor_addr_compare | ( | const tor_addr_t * | addr1, |
| const tor_addr_t * | addr2, | ||
| tor_addr_comparison_t | how | ||
| ) |
Given two addresses addr1 and addr2, return 0 if the two addresses are equivalent under the mask mbits, less than 0 if addr1 precedes addr2, and greater than 0 otherwise.
Different address families (IPv4 vs IPv6) are always considered unequal if how is CMP_EXACT; otherwise, IPv6-mapped IPv4 addresses are considered equivalent to their IPv4 equivalents.
As a special case, all pointer-wise distinct AF_UNIX addresses are always considered unequal since tor_addr_t currently does not contain the information required to make the comparison.
Definition at line 984 of file address.c.
Referenced by compare_orports_(), compare_routerinfo_addrs_by_family(), compare_vote_rs(), geoip_add_entry(), get_configured_bridge_by_addr_port_digest(), get_configured_bridge_by_exact_addr_port_digest(), get_configured_bridge_by_orports_digest(), policy_summary_add_item(), rep_hist_note_router_reachable(), rewrite_node_address_for_bridge(), routerstatus_has_visibly_changed(), and single_addr_policy_eq().
| int tor_addr_compare_masked | ( | const tor_addr_t * | addr1, |
| const tor_addr_t * | addr2, | ||
| maskbits_t | mbits, | ||
| tor_addr_comparison_t | how | ||
| ) |
As tor_addr_compare(), but only looks at the first mask bits of the address.
Reduce over-specific masks (>128 for ipv6, >32 for ipv4) to 128 or 32.
The mask is interpreted relative to addr1, so that if a is ::ffff:1.2.3.4, and b is 3.4.5.6, tor_addr_compare_masked(a,b,100,CMP_SEMANTIC) is the same as -tor_addr_compare_masked(b,a,4,CMP_SEMANTIC).
We guarantee that the ordering from tor_addr_compare_masked is a total order on addresses, but not that it is any particular order, or that it will be the same from one version to the next.
Helper: Evaluates to -1 if a is less than b, 0 if a equals b, or 1 if a is greater than b. May evaluate a and b more than once.
Definition at line 1005 of file address.c.
Referenced by addr_policy_covers(), addr_policy_intersects(), address_is_in_virtual_range(), compare_known_tor_addr_to_addr_policy(), compare_known_tor_addr_to_addr_policy_noport(), get_random_virtual_addr(), is_local_to_resolve_addr(), router_addrs_in_same_network(), and tor_addr_compare().
| void tor_addr_copy | ( | tor_addr_t * | dest, |
| const tor_addr_t * | src | ||
| ) |
Copy a tor_addr_t from src to dest.
Definition at line 933 of file address.c.
Referenced by addr_policy_append_reject_addr(), bridge_add_from_config(), channel_tls_get_remote_addr_method(), channel_tls_process_netinfo_cell(), circuit_send_intermediate_onion_skin(), client_check_address_changed(), connection_edge_update_circuit_isolation(), connection_exit_begin_conn(), connection_exit_connect_dir(), connection_ext_or_handle_cmd_useraddr(), connection_handle_listener_read(), connection_listener_new(), connection_or_connect(), connection_or_init_conn_from_address(), dir_server_new(), directory_initiate_request(), dirserv_generate_networkstatus_vote_obj(), dirserv_orconn_tls_done(), dns_resolve_impl(), dnsserv_launch_request(), evdns_server_callback(), extend_info_add_orport(), find_my_address(), find_single_ipv6_orport(), get_address_from_config(), get_address_from_orport(), get_interface_address6(), get_proxy_addrport(), hs_parse_port_config(), hs_set_conn_addr_port(), networkstatus_compute_consensus(), node_get_addr(), node_get_pref_ipv6_dirport(), node_get_pref_ipv6_orport(), parse_virtual_addr_network(), policies_copy_addr_to_smartlist(), port_parse_config(), reachable_addr_choose_base(), rep_hist_note_router_reachable(), resolved_addr_get_last(), resolved_addr_get_suggested(), resolved_addr_set_last(), resolved_addr_set_suggested(), rewrite_node_address_for_bridge(), router_build_fresh_unsigned_routerinfo(), router_get_orport(), routerconf_find_ipv6_or_ap(), set_routerstatus_from_routerinfo(), tor_addr_port_lookup(), tor_addr_port_new(), transport_copy(), transport_new(), trusted_dir_server_new(), and trusted_dirs_load_certs_from_string().
| void tor_addr_copy_ipv6_bytes | ( | uint8_t * | dest, |
| const tor_addr_t * | src | ||
| ) |
Set the 16 bytes at dest to equal the IPv6 address src. src must be an IPv6 address, if it is not, log a warning, and clear dest.
Definition at line 920 of file address.c.
Referenced by extend_cell_format().
| void tor_addr_copy_tight | ( | tor_addr_t * | dest, |
| const tor_addr_t * | src | ||
| ) |
Copy a tor_addr_t from src to dest, taking extra care to copy only the well-defined portions. Used for computing hashes of addresses.
Definition at line 947 of file address.c.
Referenced by policy_hash().
|
inlinestatic |
|
inlinestatic |
Return the address family of a. Possible values are: AF_INET6, AF_INET, AF_UNSPEC, AF_UNIX.
Definition at line 187 of file address.h.
Referenced by addr_policy_append_reject_addr(), addr_policy_covers(), address_can_be_used(), address_is_in_virtual_range(), adjust_exit_policy_from_exitpolicy_failure(), append_address_to_payload(), build_addr_port_item(), circuit_synchronize_written_or_bandwidth(), client_check_address_changed(), client_dns_set_addressmap(), compare_tor_addr_to_addr_policy(), compare_tor_addr_to_node_policy(), connected_cell_format_payload(), connection_ap_handshake_rewrite_and_attach(), connection_ap_handshake_socks_got_resolved_cell(), connection_ap_handshake_socks_reply(), connection_ap_handshake_socks_resolved_addr(), connection_ap_make_link(), connection_ap_process_end_not_open(), connection_connect(), connection_describe_peer_internal(), connection_edge_end(), connection_edge_process_relay_cell_not_open(), connection_exit_connect(), connection_exit_connect_dir(), connection_is_rate_limited(), connection_listener_new(), connection_or_check_canonicity(), connection_or_connect(), connection_send_socks5_connect(), connection_socks4_proxy_connect(), dir_server_new(), directory_initiate_request(), dirserv_orconn_tls_done(), dns_resolve_impl(), exit_policy_is_general_exit_helper(), exit_policy_remove_redundancies(), extend_info_get_orport(), extend_info_pick_orport(), fmt_addr_family(), geoip_add_entry(), geoip_get_client_history(), geoip_get_country_by_addr(), get_all_possible_sybil(), get_first_listener_addrport_string(), get_random_virtual_addr(), inform_testing_reachability(), is_local_to_resolve_addr(), launch_one_resolve(), my_exit_policy_rejects(), onionskin_answer(), parse_dir_authority_line(), parse_dir_fallback_line(), parse_virtual_addr_network(), policies_log_first_redundant_entry(), policy_dump_to_string(), policy_expand_unspec(), policy_is_reject_star(), policy_summarize(), policy_write_item(), port_exists_by_type_addr_port(), port_parse_config(), reachable_addr_allows(), remove_duplicate_orports(), resolved_addr_set_last(), resolved_addr_set_suggested(), retry_listener_ports(), rewrite_node_address_for_bridge(), router_add_exit_policy(), router_addr_is_my_published_addr(), router_addr_is_trusted_dir_type(), router_addrs_in_same_network(), router_compare_to_my_exit_policy(), router_dump_router_to_string(), router_parse_addr_policy_item_from_string(), tor_addr_compare_masked(), tor_addr_copy_tight(), tor_addr_hash(), tor_addr_is_internal_(), tor_addr_is_loopback(), tor_addr_is_multicast(), tor_addr_is_null(), tor_addr_is_v4(), tor_addr_is_v6(), tor_addr_keyed_hash(), tor_addr_parse_mask_ports(), tor_addr_to_sockaddr(), tor_addr_to_str(), tor_lookup_hostname(), and trusted_dir_server_get_dirport_exact().
| void tor_addr_from_in6 | ( | tor_addr_t * | dest, |
| const struct in6_addr * | in6 | ||
| ) |
Set dest equal to the IPv6 address in the in6_addr in6.
Definition at line 911 of file address.c.
Referenced by evdns_callback(), geoip_parse_entry(), set_exitconn_info_from_resolve(), tor_addr_from_sockaddr(), tor_addr_parse_impl(), tor_addr_parse_mask_ports(), and tor_addr_parse_PTR_name().
| void tor_addr_from_ipv4n | ( | tor_addr_t * | dest, |
| uint32_t | v4addr | ||
| ) |
Set dest to equal the IPv4 address in v4addr (given in network order).
Definition at line 889 of file address.c.
Referenced by connection_ap_handshake_socks_resolved(), connection_ap_process_end_not_open(), decode_address_from_payload(), evdns_callback(), get_random_virtual_addr(), resolved_cell_parse(), and tor_addr_from_sockaddr().
| void tor_addr_from_ipv6_bytes | ( | tor_addr_t * | dest, |
| const uint8_t * | ipv6_bytes | ||
| ) |
Set dest to equal the IPv6 address in the 16 bytes at ipv6_bytes.
Definition at line 900 of file address.c.
Referenced by connected_cell_parse(), connection_ap_handshake_socks_resolved(), connection_ap_process_end_not_open(), decode_address_from_payload(), get_random_virtual_addr(), parse_socks5_client_request(), policy_expand_unspec(), reachable_addr_choose_from_ls(), resolved_cell_parse(), tor_addr_from_in6(), tor_addr_from_netinfo_addr(), and tor_addr_parse_mask_ports().
| int tor_addr_from_sockaddr | ( | tor_addr_t * | a, |
| const struct sockaddr * | sa, | ||
| uint16_t * | port_out | ||
| ) |
Set the tor_addr_t in a to contain the socket address contained in sa. IF port_out is non-NULL and sa contains a port, set *port_out to that port. Return 0 on success and -1 on failure.
Definition at line 165 of file address.c.
Referenced by connection_handle_listener_read(), connection_listener_new(), evdns_server_callback(), tor_addr_from_getsockname(), and tor_sockaddr_to_str().
| uint64_t tor_addr_hash | ( | const tor_addr_t * | addr | ) |
| int tor_addr_hostname_is_local | ( | const char * | name | ) |
Return true if we can tell that name is a canonical name for the loopback address. Return true also for *.local hostnames, which are multicast DNS names for hosts on the local network.
Definition at line 2090 of file address.c.
Referenced by connection_ap_handshake_rewrite_and_attach().
| int tor_addr_is_internal_ | ( | const tor_addr_t * | addr, |
| int | for_listening, | ||
| const char * | filename, | ||
| int | lineno | ||
| ) |
Return true iff ip is an IP reserved to localhost or local networks.
If ip is in RFC1918 or RFC4193 or RFC4291, we will return true. (fec0::/10, deprecated by RFC3879, is also treated as internal for now and will return true.)
If ip is 0.0.0.0 or 100.64.0.0/10 (RFC6598), we will act as:
| int tor_addr_is_loopback | ( | const tor_addr_t * | addr | ) |
Return true iff addr is a loopback address
Definition at line 805 of file address.c.
Referenced by compare_tor_addr_to_short_policy(), connection_connect(), get_interface_address6_list(), get_interface_address6_via_udp_socket_hack(), host_header_is_localhost(), warn_nonlocal_client_ports(), and warn_nonlocal_controller_ports().
| int tor_addr_is_multicast | ( | const tor_addr_t * | a | ) |
Return true iff a is a multicast address.
Definition at line 1624 of file address.c.
Referenced by extend_info_addr_is_allowed(), get_interface_address6_list(), and get_interface_address6_via_udp_socket_hack().
| int tor_addr_is_null | ( | const tor_addr_t * | addr | ) |
Determine whether an address addr is null, either all zeroes or belonging to family AF_UNSPEC.
Definition at line 780 of file address.c.
Referenced by add_trusted_dir_to_nodelist_addr_set(), channel_tls_process_netinfo_cell(), compare_tor_addr_to_addr_policy(), compare_tor_addr_to_short_policy(), compute_routerstatus_consensus(), conn_get_outbound_address(), connection_ap_expire_beginning(), connection_ap_handshake_attach_circuit(), connection_ap_handshake_socks_resolved(), connection_ap_process_end_not_open(), connection_describe_peer_internal(), connection_edge_process_relay_cell_not_open(), connection_or_send_netinfo(), directory_initiate_request(), dirserv_router_has_valid_address(), dirserv_set_router_is_running(), dirserv_single_reachability_test(), extend_info_is_a_configured_bridge(), format_node_description(), get_first_listener_addrport_string(), log_addr_has_changed(), managed_proxy_outbound_address(), node_add_to_address_set(), node_describe(), nodelist_add_addr_to_address_set(), nodelist_set_consensus(), policies_copy_addr_to_smartlist(), policies_copy_outbound_addresses_to_smartlist(), port_exists_by_type_addr_port(), pt_get_extra_info_descriptor_string(), pt_update_bridge_lines(), reachable_addr_allows(), relay_find_addr_to_publish(), rep_hist_note_router_reachable(), resolved_addr_set_suggested(), retry_listener_ports(), rewrite_node_address_for_bridge(), router_addrs_in_same_network(), router_compare_to_my_exit_policy(), routerset_contains_extendinfo(), routerstatus_format_entry(), and trusted_dirs_load_certs_from_string().
|
inlinestatic |
Return true if the address is in the UNSPEC family.
Definition at line 196 of file address.h.
Referenced by channel_tls_matches_extend_info_method(), extend_info_add_orport(), extend_info_any_orport_addr_is_internal(), and extend_info_get_orport().
| int tor_addr_is_v4 | ( | const tor_addr_t * | addr | ) |
Determine whether an address is IPv4, either native or IPv4-mapped IPv6. Note that this is about representation only, as any decent stack will reject IPv4-mapped addresses received on the wire (and won't use them on the wire either).
Definition at line 750 of file address.c.
Referenced by get_first_listener_addrport_string(), nodelist_add_addr_to_address_set(), tor_addr_compare_masked(), tor_addr_is_internal_(), and tor_addr_parse_mask_ports().
| int tor_addr_is_v6 | ( | const tor_addr_t * | addr | ) |
Determine whether an address addr is an IPv6 (AF_INET6). Return true if so else false.
Definition at line 770 of file address.c.
Referenced by nodelist_add_addr_to_address_set().
| int tor_addr_is_valid | ( | const tor_addr_t * | addr, |
| int | for_listening | ||
| ) |
| int tor_addr_is_valid_ipv4n | ( | uint32_t | v4n_addr, |
| int | for_listening | ||
| ) |
| uint64_t tor_addr_keyed_hash | ( | const struct sipkey * | key, |
| const tor_addr_t * | addr | ||
| ) |
As tor_addr_hash, but use a particular siphash key.
Definition at line 1142 of file address.c.
Referenced by bloomfilt_addr_hash().
| void tor_addr_make_null | ( | tor_addr_t * | a, |
| sa_family_t | family | ||
| ) |
Set address a to the null address in address family family. The null address for AF_INET is 0.0.0.0. The null address for AF_INET6 is [::]. AF_UNSPEC is all null.
Definition at line 235 of file address.c.
Referenced by connection_ap_can_use_exit(), connection_ap_get_begincell_flags(), dirauth_set_routerstatus_from_routerinfo(), directory_request_new(), hs_get_extend_info_from_lspecs(), node_get_pref_ipv6_dirport(), node_get_pref_ipv6_orport(), node_get_prim_dirport(), node_get_prim_orport(), reachable_addr_choose_base(), reachable_addr_choose_from_dir_server(), reachable_addr_choose_from_ls(), reachable_addr_choose_from_node(), reachable_addr_choose_from_rs(), resolved_addr_reset_last(), and routerconf_find_ipv6_or_ap().
| void tor_addr_make_unspec | ( | tor_addr_t * | a | ) |
Set address a to the unspecified address. This address belongs to no family.
Definition at line 225 of file address.c.
Referenced by channel_init(), channel_tls_get_remote_addr_method(), circuit_clear_isolation(), circuit_send_intermediate_onion_skin(), connected_cell_parse(), connection_ap_make_link(), connection_ap_process_end_not_open(), connection_handle_listener_read(), connection_listener_new(), control_connection_add_local_fd(), decode_address_from_payload(), dir_server_new(), evdns_callback(), extend_info_new(), find_my_address(), get_or_history(), get_proxy_addrport(), or_connection_new(), port_parse_config(), relay_find_addr_to_publish(), tor_addr_from_sockaddr(), and tor_addr_parse_mask_ports().
| int tor_addr_parse | ( | tor_addr_t * | addr, |
| const char * | src | ||
| ) |
Convert the string in src to a tor_addr_t addr. The string may be an IPv4 address, an IPv6 address, or an IPv6 address surrounded by square brackets.
Returns an address family on success, or -1 if an invalid address string is provided.
Definition at line 1349 of file address.c.
Referenced by address_is_in_virtual_range(), address_is_invalid_destination(), addressmap_rewrite(), addressmap_rewrite_reverse(), adjust_exit_policy_from_exitpolicy_failure(), circuit_get_open_circ_or_launch(), circuit_is_acceptable(), client_dns_set_addressmap(), client_dns_set_reverse_addressmap(), connection_ap_can_use_exit(), connection_ap_fail_onehop(), connection_ap_handshake_rewrite_and_attach(), connection_dir_client_reached_eof(), connection_ext_or_handle_cmd_useraddr(), dns_resolve_impl(), get_address_from_config(), getinfo_helper_geoip(), handle_get_current_consensus(), host_header_is_localhost(), http_set_address_origin(), metrics_parse_ports(), parse_dir_fallback_line(), parse_method_line_helper(), port_parse_config(), process_socks5_client_request(), tor_addr_lookup(), tor_addr_parse_PTR_name(), tor_addr_port_lookup(), and tor_addr_port_split().
| int tor_addr_parse_mask_ports | ( | const char * | s, |
| unsigned | flags, | ||
| tor_addr_t * | addr_out, | ||
| maskbits_t * | maskbits_out, | ||
| uint16_t * | port_min_out, | ||
| uint16_t * | port_max_out | ||
| ) |
Parse a string s containing an IPv4/IPv6 address, and possibly a mask and port or port range. Store the parsed address in addr_out, a mask (if any) in mask_out, and port(s) (if any) in port_min_out and port_max_out.
The syntax is: Address OptMask OptPortRange Address ::= IPv4Address / "[" IPv6Address "]" / "*" OptMask ::= "/" Integer / OptPortRange ::= ":*" / ":" Integer / ":" Integer "-" Integer /
Return an address family on success, or -1 if an invalid address string is provided.
If 'flags & TAPMP_EXTENDED_STAR' is false, then the wildcard address '*' yield an IPv4 wildcard.
If 'flags & TAPMP_EXTENDED_STAR' is true, then the wildcard address '*' yields an AF_UNSPEC wildcard address, which expands to corresponding wildcard IPv4 and IPv6 rules, and the following change is made in the grammar above: Address ::= IPv4Address / "[" IPv6Address "]" / "*" / "*4" / "*6" with the new "*4" and "*6" productions creating a wildcard to match IPv4 or IPv6 addresses.
If 'flags & TAPMP_EXTENDED_STAR' and 'flags & TAPMP_STAR_IPV4_ONLY' are both true, then the wildcard address '*' yields an IPv4 wildcard.
If 'flags & TAPMP_EXTENDED_STAR' and 'flags & TAPMP_STAR_IPV6_ONLY' are both true, then the wildcard address '*' yields an IPv6 wildcard.
TAPMP_STAR_IPV4_ONLY and TAPMP_STAR_IPV6_ONLY are mutually exclusive.
Longest possible length for an address, mask, and port-range combination. Includes IP, [], /mask, :, ports
Definition at line 543 of file address.c.
Referenced by find_single_ipv6_orport(), parse_virtual_addr_network(), policy_expand_private(), policy_summary_add_item(), and router_parse_addr_policy().
| int tor_addr_parse_PTR_name | ( | tor_addr_t * | result, |
| const char * | address, | ||
| int | family, | ||
| int | accept_regular | ||
| ) |
Parse an .in-addr.arpa or .ip6.arpa address from address. Return 0 if this is not an .in-addr.arpa address or an .ip6.arpa address. Return -1 if this is an ill-formed .in-addr.arpa address or an .ip6.arpa address. Also return -1 if family is not AF_UNSPEC, and the parsed address family does not match family. On success, return 1, and store the result, if any, into result, if provided.
If accept_regular is set and the address is in neither recognized reverse lookup hostname format, try parsing the address as a regular IPv4 or IPv6 address too. This mode will accept IPv6 addresses with or without square brackets.
Definition at line 380 of file address.c.
Referenced by connection_ap_handshake_send_resolve(), dns_resolve_impl(), and launch_resolve().
| void tor_addr_port_copy | ( | tor_addr_port_t * | dest, |
| const tor_addr_port_t * | source | ||
| ) |
Copy a tor_addr_port_t from source to dest.
Definition at line 2121 of file address.c.
Referenced by connection_or_check_canonicity(), directory_request_set_dir_from_routerstatus(), and trusted_dir_server_add_dirport().
| int tor_addr_port_eq | ( | const tor_addr_port_t * | a, |
| const tor_addr_port_t * | b | ||
| ) |
Return true iff a and b are the same address and port
Definition at line 2111 of file address.c.
Referenced by get_sampled_guard_by_bridge_addr().
| tor_addr_port_t * tor_addr_port_new | ( | const tor_addr_t * | addr, |
| uint16_t | port | ||
| ) |
Return a newly allocated tor_addr_port_t with addr and port filled in.
Definition at line 2100 of file address.c.
Referenced by compute_routerstatus_consensus(), and connection_haproxy_proxy_connect().
| int tor_addr_port_parse | ( | int | severity, |
| const char * | addrport, | ||
| tor_addr_t * | address_out, | ||
| uint16_t * | port_out, | ||
| int | default_port | ||
| ) |
Given an address of the form "ip:port", try to divide it into its ip and port portions, setting *address_out to a newly allocated string holding the address portion and *port_out to the port.
Don't do DNS lookups and don't allow domain names in the "ip" field.
If default_port is less than 0, don't accept addrport of the form "ip" or "ip:0". Otherwise, accept those forms, and set *port_out to default_port.
This function accepts:
Return 0 on success, -1 on failure.
Definition at line 1857 of file address.c.
Referenced by entry_guard_parse_from_state(), get_bindaddr_from_transport_listen_line(), parse_bridge_line(), parse_dir_authority_line(), parse_dir_fallback_line(), parse_dirauth_dirport(), and tor_addr_port_lookup().
| int tor_addr_port_split | ( | int | severity, |
| const char * | addrport, | ||
| char ** | address_out, | ||
| uint16_t * | port_out | ||
| ) |
Given an address of the form "host[:port]", try to divide it into its host and port portions.
Like tor_addr_port_parse(), this function accepts:
Sets *address_out to a newly allocated string holding the address portion, and *port_out to the port (or 0 if no port is given).
Return 0 on success, -1 on failure.
Definition at line 1916 of file address.c.
Referenced by authority_cert_parse_from_string(), begin_cell_parse(), connection_ap_process_http_connect(), connection_ext_or_handle_cmd_useraddr(), host_header_is_localhost(), parse_dir_authority_line(), parse_dir_fallback_line(), parse_method_line_helper(), tor_addr_port_lookup(), and tor_addr_port_parse().
|
inlinestatic |
Return an in_addr* equivalent to a, or NULL if a is not an IPv4 address.
Definition at line 204 of file address.h.
Referenced by launch_one_resolve().
|
inlinestatic |
Return an in6_addr* equivalent to a, or NULL if a is not an IPv6 address.
Definition at line 117 of file address.h.
Referenced by geoip_get_country_by_addr(), and launch_one_resolve().
|
inlinestatic |
As tor_addr_to_in6, but assert that the address truly is an IPv6 address.
Definition at line 125 of file address.h.
Referenced by geoip_add_entry(), and tor_addr_to_sockaddr().
|
inlinestatic |
Return an IPv4 address in host order for a, or 0 if a is not an IPv4 address.
Definition at line 160 of file address.h.
Referenced by addressmap_get_virtual_address(), exit_policy_is_general_exit_helper(), extend_cell_format(), geoip_add_entry(), geoip_get_country_by_addr(), get_interface_address(), tor_addr_compare_masked(), tor_addr_eq_ipv4h(), tor_addr_is_internal_(), tor_addr_is_loopback(), tor_addr_is_multicast(), tor_addr_to_PTR_name(), and tor_lookup_hostname().
|
inlinestatic |
Return an IPv4 address in network order for a, or 0 if a is not an IPv4 address.
Definition at line 152 of file address.h.
Referenced by append_address_to_payload(), connected_cell_format_payload(), connection_ap_handshake_socks_resolved_addr(), connection_edge_end(), connection_send_socks5_connect(), connection_socks4_proxy_connect(), get_random_virtual_addr(), tor_addr_is_null(), tor_addr_to_ipv4h(), and tor_addr_to_sockaddr().
|
inlinestatic |
Given an IPv6 address, return its mapped IPv4 address in host order, or 0 if a is not an IPv6 address.
(Does not check whether the address is really a mapped address.)
Definition at line 170 of file address.h.
Referenced by tor_addr_compare_masked().
| int tor_addr_to_PTR_name | ( | char * | out, |
| size_t | outlen, | ||
| const tor_addr_t * | addr | ||
| ) |
Convert addr to an in-addr.arpa name or a .ip6.arpa name, and store the result in the outlen-byte buffer at out. Returns a non-negative integer on success. Returns -1 on failure.
Definition at line 470 of file address.c.
Referenced by connection_ap_handshake_send_resolve().
| socklen_t tor_addr_to_sockaddr | ( | const tor_addr_t * | a, |
| uint16_t | port, | ||
| struct sockaddr * | sa_out, | ||
| socklen_t | len | ||
| ) |
Convert the tor_addr_t in a, with port in port, into a sockaddr object in *sa_out of object size len. If not enough room is available in sa_out, or on error, return 0. On success, return the length of the sockaddr.
Interface note: ordinarily, we return -1 for error. We can't do that here, since socklen_t is unsigned on some platforms.
Definition at line 113 of file address.c.
Referenced by connection_connect(), and connection_listener_new_for_port().
| const char * tor_addr_to_str | ( | char * | dest, |
| const tor_addr_t * | addr, | ||
| size_t | len, | ||
| int | decorate | ||
| ) |
Convert a tor_addr_t addr into a string, and store it in dest of size len. Returns a pointer to dest on success, or NULL on failure. If decorate, surround IPv6 addresses with brackets.
Definition at line 328 of file address.c.
Referenced by addressmap_get_virtual_address(), client_dns_set_addressmap(), connection_ap_process_end_not_open(), connection_describe_peer_internal(), dirserv_orconn_tls_done(), dirserv_single_reachability_test(), evdns_callback(), fmt_addr_impl(), format_node_description(), get_pt_proxy_uri(), log_addr_has_changed(), node_get_address_string(), parse_socks4_request(), parse_socks5_client_request(), policy_write_item(), remap_event_helper(), router_dump_router_to_string(), tor_addr_to_str_dup(), and tor_sockaddr_to_str().
| char * tor_addr_to_str_dup | ( | const tor_addr_t * | addr | ) |
Return a newly allocated string with a representation of addr.
Definition at line 1164 of file address.c.
Referenced by channel_dump_statistics(), connection_ap_handshake_send_resolve(), connection_exit_begin_conn(), connection_ext_or_handle_cmd_useraddr(), connection_handle_listener_read(), connection_listener_new_for_port(), create_managed_proxy_environment(), dir_server_new(), directory_initiate_request(), dirserv_generate_networkstatus_vote_obj(), dnsserv_launch_request(), evdns_server_callback(), getinfo_helper_misc(), reachability_warnings_callback(), router_dump_router_to_string(), and trusted_dir_server_new().
| char * tor_dup_ip | ( | uint32_t | addr | ) |
Given a host-order addr, call tor_inet_ntop() on it and return a strdup of the resulting address. Return NULL if tor_inet_ntop() fails.
Definition at line 2047 of file address.c.
Referenced by pathbias_send_usable_probe(), and tell_controller_about_resolved_result().
| int tor_port_is_valid | ( | uint16_t | port, |
| int | for_listening | ||
| ) |
| char * tor_sockaddr_to_str | ( | const struct sockaddr * | sa | ) |
Return a newly allocated string holding the address described in sa. AF_UNIX, AF_UNSPEC, AF_INET, and AF_INET6 are supported.
Definition at line 198 of file address.c.
Referenced by getinfo_helper_listeners().