mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
Merge branch 'bug3512'
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
o Code simplifications and refactoring:
|
||||
- Rename Tor functions that turn strings into addresses, so that
|
||||
"parse" indicates that no hostname resolution occurs, and
|
||||
"lookup" indicates that hostname resolution may occur. This
|
||||
should help prevent mistakes in the future. Fixes bug 3512.
|
||||
|
||||
+21
-7
@@ -384,7 +384,7 @@ tor_addr_to_str(char *dest, const tor_addr_t *addr, size_t len, int decorate)
|
||||
* IPv4 or IPv6 address too.
|
||||
*/
|
||||
int
|
||||
tor_addr_parse_reverse_lookup_name(tor_addr_t *result, const char *address,
|
||||
tor_addr_parse_PTR_name(tor_addr_t *result, const char *address,
|
||||
int family, int accept_regular)
|
||||
{
|
||||
if (!strcasecmpend(address, ".in-addr.arpa")) {
|
||||
@@ -455,7 +455,7 @@ tor_addr_parse_reverse_lookup_name(tor_addr_t *result, const char *address,
|
||||
|
||||
if (accept_regular) {
|
||||
tor_addr_t tmp;
|
||||
int r = tor_addr_from_str(&tmp, address);
|
||||
int r = tor_addr_parse(&tmp, address);
|
||||
if (r < 0)
|
||||
return 0;
|
||||
if (r != family && family != AF_UNSPEC)
|
||||
@@ -474,7 +474,7 @@ tor_addr_parse_reverse_lookup_name(tor_addr_t *result, const char *address,
|
||||
* the result in the <b>outlen</b>-byte buffer at <b>out</b>. Return 0 on
|
||||
* success, -1 on failure. */
|
||||
int
|
||||
tor_addr_to_reverse_lookup_name(char *out, size_t outlen,
|
||||
tor_addr_to_PTR_name(char *out, size_t outlen,
|
||||
const tor_addr_t *addr)
|
||||
{
|
||||
if (addr->family == AF_INET) {
|
||||
@@ -984,7 +984,7 @@ fmt_addr32(uint32_t addr)
|
||||
* Return an address family on success, or -1 if an invalid address string is
|
||||
* provided. */
|
||||
int
|
||||
tor_addr_from_str(tor_addr_t *addr, const char *src)
|
||||
tor_addr_parse(tor_addr_t *addr, const char *src)
|
||||
{
|
||||
char *tmp = NULL; /* Holds substring if we got a dotted quad. */
|
||||
int result;
|
||||
@@ -1012,7 +1012,7 @@ tor_addr_from_str(tor_addr_t *addr, const char *src)
|
||||
* address as needed, and put the result in <b>addr_out</b> and (optionally)
|
||||
* <b>port_out</b>. Return 0 on success, negative on failure. */
|
||||
int
|
||||
tor_addr_port_parse(const char *s, tor_addr_t *addr_out, uint16_t *port_out)
|
||||
tor_addr_port_lookup(const char *s, tor_addr_t *addr_out, uint16_t *port_out)
|
||||
{
|
||||
const char *port;
|
||||
tor_addr_t addr;
|
||||
@@ -1148,6 +1148,20 @@ is_internal_IP(uint32_t ip, int for_listening)
|
||||
return tor_addr_is_internal(&myaddr, for_listening);
|
||||
}
|
||||
|
||||
/** Given an address of the form "host:port", try to divide it into its host
|
||||
* ane port portions, setting *<b>address_out</b> to a newly allocated string
|
||||
* holding the address portion and *<b>port_out</b> to the port (or 0 if no
|
||||
* port is given). Return 0 on success, -1 on failure. */
|
||||
int
|
||||
tor_addr_port_split(int severity, const char *addrport,
|
||||
char **address_out, uint16_t *port_out)
|
||||
{
|
||||
tor_assert(addrport);
|
||||
tor_assert(address_out);
|
||||
tor_assert(port_out);
|
||||
return addr_port_lookup(severity, addrport, address_out, NULL, port_out);
|
||||
}
|
||||
|
||||
/** Parse a string of the form "host[:port]" from <b>addrport</b>. If
|
||||
* <b>address</b> is provided, set *<b>address</b> to a copy of the
|
||||
* host portion of the string. If <b>addr</b> is provided, try to
|
||||
@@ -1159,7 +1173,7 @@ is_internal_IP(uint32_t ip, int for_listening)
|
||||
* Return 0 on success, -1 on failure.
|
||||
*/
|
||||
int
|
||||
parse_addr_port(int severity, const char *addrport, char **address,
|
||||
addr_port_lookup(int severity, const char *addrport, char **address,
|
||||
uint32_t *addr, uint16_t *port_out)
|
||||
{
|
||||
const char *colon;
|
||||
@@ -1169,7 +1183,7 @@ parse_addr_port(int severity, const char *addrport, char **address,
|
||||
|
||||
tor_assert(addrport);
|
||||
|
||||
colon = strchr(addrport, ':');
|
||||
colon = strrchr(addrport, ':');
|
||||
if (colon) {
|
||||
_address = tor_strndup(addrport, colon-addrport);
|
||||
_port = (int) tor_parse_long(colon+1,10,1,65535,NULL,NULL);
|
||||
|
||||
@@ -154,19 +154,19 @@ int tor_addr_is_internal(const tor_addr_t *ip, int for_listening) ATTR_PURE;
|
||||
/** Longest length that can be required for a reverse lookup name. */
|
||||
/* 32 nybbles, 32 dots, 8 characters of "ip6.arpa", 1 NUL: 73 characters. */
|
||||
#define REVERSE_LOOKUP_NAME_BUF_LEN 73
|
||||
int tor_addr_to_reverse_lookup_name(char *out, size_t outlen,
|
||||
int tor_addr_to_PTR_name(char *out, size_t outlen,
|
||||
const tor_addr_t *addr);
|
||||
int tor_addr_parse_reverse_lookup_name(tor_addr_t *result, const char *address,
|
||||
int tor_addr_parse_PTR_name(tor_addr_t *result, const char *address,
|
||||
int family, int accept_regular);
|
||||
|
||||
int tor_addr_port_parse(const char *s, tor_addr_t *addr_out,
|
||||
int tor_addr_port_lookup(const char *s, tor_addr_t *addr_out,
|
||||
uint16_t *port_out);
|
||||
int tor_addr_parse_mask_ports(const char *s,
|
||||
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_from_str(tor_addr_t *addr, const char *src);
|
||||
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_from_ipv4n(tor_addr_t *dest, uint32_t v4addr);
|
||||
/** Set <b>dest</b> to the IPv4 address encoded in <b>v4addr</b> in host
|
||||
@@ -181,9 +181,12 @@ void tor_addr_from_in6(tor_addr_t *dest, const struct in6_addr *in6);
|
||||
int tor_addr_is_null(const tor_addr_t *addr);
|
||||
int tor_addr_is_loopback(const tor_addr_t *addr);
|
||||
|
||||
int tor_addr_port_split(int severity, const char *addrport,
|
||||
char **address_out, uint16_t *port_out);
|
||||
|
||||
/* IPv4 helpers */
|
||||
int is_internal_IP(uint32_t ip, int for_listening) ATTR_PURE;
|
||||
int parse_addr_port(int severity, const char *addrport, char **address,
|
||||
int addr_port_lookup(int severity, const char *addrport, char **address,
|
||||
uint32_t *addr, uint16_t *port_out);
|
||||
int parse_port_range(const char *port, uint16_t *port_min_out,
|
||||
uint16_t *port_max_out);
|
||||
|
||||
+2
-2
@@ -117,7 +117,7 @@ circuit_is_acceptable(const origin_circuit_t *origin_circ,
|
||||
if (tor_digest_is_zero(digest)) {
|
||||
/* we don't know the digest; have to compare addr:port */
|
||||
tor_addr_t addr;
|
||||
int r = tor_addr_from_str(&addr, conn->socks_request->address);
|
||||
int r = tor_addr_parse(&addr, conn->socks_request->address);
|
||||
if (r < 0 ||
|
||||
!tor_addr_eq(&build_state->chosen_exit->addr, &addr) ||
|
||||
build_state->chosen_exit->port != conn->socks_request->port)
|
||||
@@ -1454,7 +1454,7 @@ circuit_get_open_circ_or_launch(entry_connection_t *conn,
|
||||
log_info(LD_DIR, "Broken exit digest on tunnel conn. Closing.");
|
||||
return -1;
|
||||
}
|
||||
if (tor_addr_from_str(&addr, conn->socks_request->address) < 0) {
|
||||
if (tor_addr_parse(&addr, conn->socks_request->address) < 0) {
|
||||
log_info(LD_DIR, "Broken address %s on tunnel conn. Closing.",
|
||||
escaped_safe_str_client(conn->socks_request->address));
|
||||
return -1;
|
||||
|
||||
+16
-16
@@ -2877,7 +2877,7 @@ is_listening_on_low_port(int port_option,
|
||||
return (port_option < 1024);
|
||||
|
||||
for (l = listen_options; l; l = l->next) {
|
||||
parse_addr_port(LOG_WARN, l->value, NULL, NULL, &p);
|
||||
addr_port_lookup(LOG_WARN, l->value, NULL, NULL, &p);
|
||||
if (p<1024) {
|
||||
return 1;
|
||||
}
|
||||
@@ -3573,7 +3573,7 @@ options_validate(or_options_t *old_options, or_options_t *options,
|
||||
REJECT("Failed to parse accounting options. See logs for details.");
|
||||
|
||||
if (options->HTTPProxy) { /* parse it now */
|
||||
if (tor_addr_port_parse(options->HTTPProxy,
|
||||
if (tor_addr_port_lookup(options->HTTPProxy,
|
||||
&options->HTTPProxyAddr, &options->HTTPProxyPort) < 0)
|
||||
REJECT("HTTPProxy failed to parse or resolve. Please fix.");
|
||||
if (options->HTTPProxyPort == 0) { /* give it a default */
|
||||
@@ -3587,7 +3587,7 @@ options_validate(or_options_t *old_options, or_options_t *options,
|
||||
}
|
||||
|
||||
if (options->HTTPSProxy) { /* parse it now */
|
||||
if (tor_addr_port_parse(options->HTTPSProxy,
|
||||
if (tor_addr_port_lookup(options->HTTPSProxy,
|
||||
&options->HTTPSProxyAddr, &options->HTTPSProxyPort) <0)
|
||||
REJECT("HTTPSProxy failed to parse or resolve. Please fix.");
|
||||
if (options->HTTPSProxyPort == 0) { /* give it a default */
|
||||
@@ -3601,7 +3601,7 @@ options_validate(or_options_t *old_options, or_options_t *options,
|
||||
}
|
||||
|
||||
if (options->Socks4Proxy) { /* parse it now */
|
||||
if (tor_addr_port_parse(options->Socks4Proxy,
|
||||
if (tor_addr_port_lookup(options->Socks4Proxy,
|
||||
&options->Socks4ProxyAddr,
|
||||
&options->Socks4ProxyPort) <0)
|
||||
REJECT("Socks4Proxy failed to parse or resolve. Please fix.");
|
||||
@@ -3611,7 +3611,7 @@ options_validate(or_options_t *old_options, or_options_t *options,
|
||||
}
|
||||
|
||||
if (options->Socks5Proxy) { /* parse it now */
|
||||
if (tor_addr_port_parse(options->Socks5Proxy,
|
||||
if (tor_addr_port_lookup(options->Socks5Proxy,
|
||||
&options->Socks5ProxyAddr,
|
||||
&options->Socks5ProxyPort) <0)
|
||||
REJECT("Socks5Proxy failed to parse or resolve. Please fix.");
|
||||
@@ -4684,7 +4684,7 @@ parse_bridge_line(const char *line, int validate_only)
|
||||
addrport = field1;
|
||||
}
|
||||
|
||||
if (tor_addr_port_parse(addrport, &addr, &port)<0) {
|
||||
if (tor_addr_port_lookup(addrport, &addr, &port)<0) {
|
||||
log_warn(LD_CONFIG, "Error parsing Bridge address '%s'", addrport);
|
||||
goto err;
|
||||
}
|
||||
@@ -4827,7 +4827,7 @@ parse_client_transport_line(const char *line, int validate_only)
|
||||
|
||||
addrport = smartlist_get(items, 2);
|
||||
|
||||
if (tor_addr_port_parse(addrport, &addr, &port)<0) {
|
||||
if (tor_addr_port_lookup(addrport, &addr, &port)<0) {
|
||||
log_warn(LD_CONFIG, "Error parsing transport "
|
||||
"address '%s'", addrport);
|
||||
goto err;
|
||||
@@ -4948,7 +4948,7 @@ parse_server_transport_line(const char *line, int validate_only)
|
||||
|
||||
addrport = smartlist_get(items, 2);
|
||||
|
||||
if (tor_addr_port_parse(addrport, &addr, &port)<0) {
|
||||
if (tor_addr_port_lookup(addrport, &addr, &port)<0) {
|
||||
log_warn(LD_CONFIG, "Error parsing transport "
|
||||
"address '%s'", addrport);
|
||||
goto err;
|
||||
@@ -5060,7 +5060,7 @@ parse_dir_server_line(const char *line, dirinfo_type_t required_type,
|
||||
}
|
||||
addrport = smartlist_get(items, 0);
|
||||
smartlist_del_keeporder(items, 0);
|
||||
if (parse_addr_port(LOG_WARN, addrport, &address, NULL, &dir_port)<0) {
|
||||
if (addr_port_lookup(LOG_WARN, addrport, &address, NULL, &dir_port)<0) {
|
||||
log_warn(LD_CONFIG, "Error parsing DirServer address '%s'", addrport);
|
||||
goto err;
|
||||
}
|
||||
@@ -5228,7 +5228,7 @@ parse_client_port_config(smartlist_t *out,
|
||||
for (; listenaddrs; listenaddrs = listenaddrs->next) {
|
||||
tor_addr_t addr;
|
||||
uint16_t port = 0;
|
||||
if (tor_addr_port_parse(listenaddrs->value, &addr, &port) < 0) {
|
||||
if (tor_addr_port_lookup(listenaddrs->value, &addr, &port) < 0) {
|
||||
log_warn(LD_CONFIG, "Unable to parse %sListenAddress '%s'",
|
||||
portname, listenaddrs->value);
|
||||
return -1;
|
||||
@@ -5256,7 +5256,7 @@ parse_client_port_config(smartlist_t *out,
|
||||
port_cfg_t *cfg = tor_malloc_zero(sizeof(port_cfg_t));
|
||||
cfg->type = listener_type;
|
||||
cfg->port = defaultport;
|
||||
tor_addr_from_str(&cfg->addr, defaultaddr);
|
||||
tor_addr_parse(&cfg->addr, defaultaddr);
|
||||
cfg->session_group = SESSION_GROUP_UNSET;
|
||||
cfg->isolation_flags = ISO_DEFAULT;
|
||||
smartlist_add(out, cfg);
|
||||
@@ -5294,11 +5294,11 @@ parse_client_port_config(smartlist_t *out,
|
||||
addrport = smartlist_get(elts, 0);
|
||||
if (!strcmp(addrport, "auto")) {
|
||||
port = CFG_AUTO_PORT;
|
||||
tor_addr_from_str(&addr, defaultaddr);
|
||||
tor_addr_parse(&addr, defaultaddr);
|
||||
} else if (!strcasecmpend(addrport, ":auto")) {
|
||||
char *addrtmp = tor_strndup(addrport, strlen(addrport)-5);
|
||||
port = CFG_AUTO_PORT;
|
||||
if (tor_addr_port_parse(addrtmp, &addr, &ptmp)<0 || ptmp) {
|
||||
if (tor_addr_port_lookup(addrtmp, &addr, &ptmp)<0 || ptmp) {
|
||||
log_warn(LD_CONFIG, "Invalid address '%s' for %sPort",
|
||||
escaped(addrport), portname);
|
||||
tor_free(addrtmp);
|
||||
@@ -5309,8 +5309,8 @@ parse_client_port_config(smartlist_t *out,
|
||||
"9050" might be a valid address. */
|
||||
port = (int) tor_parse_long(addrport, 10, 0, 65535, &ok, NULL);
|
||||
if (ok) {
|
||||
tor_addr_from_str(&addr, defaultaddr);
|
||||
} else if (tor_addr_port_parse(addrport, &addr, &ptmp) == 0) {
|
||||
tor_addr_parse(&addr, defaultaddr);
|
||||
} else if (tor_addr_port_lookup(addrport, &addr, &ptmp) == 0) {
|
||||
if (ptmp == 0) {
|
||||
log_warn(LD_CONFIG, "%sPort line has address but no port", portname);
|
||||
goto err;
|
||||
@@ -5946,7 +5946,7 @@ state_transport_line_is_valid(const char *line)
|
||||
}
|
||||
|
||||
addrport = smartlist_get(items, 1);
|
||||
if (tor_addr_port_parse(addrport, &addr, &port) < 0) {
|
||||
if (tor_addr_port_lookup(addrport, &addr, &port) < 0) {
|
||||
log_warn(LD_CONFIG, "state: Could not parse addrport.");
|
||||
goto err;
|
||||
}
|
||||
|
||||
+2
-2
@@ -1893,7 +1893,7 @@ retry_listeners(smartlist_t *old_conns,
|
||||
int retval = 0;
|
||||
|
||||
if (default_addr) {
|
||||
tor_addr_from_str(&dflt_addr, default_addr);
|
||||
tor_addr_parse(&dflt_addr, default_addr);
|
||||
} else {
|
||||
tor_addr_make_unspec(&dflt_addr);
|
||||
}
|
||||
@@ -1917,7 +1917,7 @@ retry_listeners(smartlist_t *old_conns,
|
||||
port->is_unix_addr = 1;
|
||||
memcpy(port->unix_addr, c->value, len+1);
|
||||
} else {
|
||||
if (tor_addr_port_parse(c->value, &addr, &portval) < 0) {
|
||||
if (tor_addr_port_lookup(c->value, &addr, &portval) < 0) {
|
||||
log_warn(LD_CONFIG, "Can't parse/resolve %s %s",
|
||||
c->key, c->value);
|
||||
retval = -1;
|
||||
|
||||
@@ -691,7 +691,7 @@ connection_ap_fail_onehop(const char *failed_digest,
|
||||
if (!build_state || !build_state->chosen_exit ||
|
||||
!entry_conn->socks_request || !entry_conn->socks_request->address)
|
||||
continue;
|
||||
if (tor_addr_from_str(&addr, entry_conn->socks_request->address)<0 ||
|
||||
if (tor_addr_parse(&addr, entry_conn->socks_request->address)<0 ||
|
||||
!tor_addr_eq(&build_state->chosen_exit->addr, &addr) ||
|
||||
build_state->chosen_exit->port != entry_conn->socks_request->port)
|
||||
continue;
|
||||
@@ -1766,7 +1766,7 @@ connection_ap_handshake_rewrite_and_attach(entry_connection_t *conn,
|
||||
/* Don't let people try to do a reverse lookup on 10.0.0.1. */
|
||||
tor_addr_t addr;
|
||||
int ok;
|
||||
ok = tor_addr_parse_reverse_lookup_name(
|
||||
ok = tor_addr_parse_PTR_name(
|
||||
&addr, socks->address, AF_UNSPEC, 1);
|
||||
if (ok == 1 && tor_addr_is_internal(&addr, 0)) {
|
||||
connection_ap_handshake_socks_resolved(conn, RESOLVED_TYPE_ERROR,
|
||||
@@ -1918,7 +1918,7 @@ connection_ap_handshake_rewrite_and_attach(entry_connection_t *conn,
|
||||
if (options->ClientRejectInternalAddresses &&
|
||||
!conn->use_begindir && !conn->chosen_exit_name && !circ) {
|
||||
tor_addr_t addr;
|
||||
if (tor_addr_from_str(&addr, socks->address) >= 0 &&
|
||||
if (tor_addr_parse(&addr, socks->address) >= 0 &&
|
||||
tor_addr_is_internal(&addr, 0)) {
|
||||
/* If this is an explicit private address with no chosen exit node,
|
||||
* then we really don't want to try to connect to it. That's
|
||||
@@ -2530,7 +2530,7 @@ connection_ap_handshake_send_resolve(entry_connection_t *ap_conn)
|
||||
|
||||
/* We're doing a reverse lookup. The input could be an IP address, or
|
||||
* could be an .in-addr.arpa or .ip6.arpa address */
|
||||
r = tor_addr_parse_reverse_lookup_name(&addr, a, AF_INET, 1);
|
||||
r = tor_addr_parse_PTR_name(&addr, a, AF_INET, 1);
|
||||
if (r <= 0) {
|
||||
log_warn(LD_APP, "Rejecting ill-formed reverse lookup of %s",
|
||||
safe_str_client(a));
|
||||
@@ -2538,7 +2538,7 @@ connection_ap_handshake_send_resolve(entry_connection_t *ap_conn)
|
||||
return -1;
|
||||
}
|
||||
|
||||
r = tor_addr_to_reverse_lookup_name(inaddr_buf, sizeof(inaddr_buf), &addr);
|
||||
r = tor_addr_to_PTR_name(inaddr_buf, sizeof(inaddr_buf), &addr);
|
||||
if (r < 0) {
|
||||
log_warn(LD_BUG, "Couldn't generate reverse lookup hostname of %s",
|
||||
safe_str_client(a));
|
||||
@@ -2894,9 +2894,9 @@ connection_exit_begin_conn(cell_t *cell, circuit_t *circ)
|
||||
END_STREAM_REASON_TORPROTOCOL, NULL);
|
||||
return 0;
|
||||
}
|
||||
if (parse_addr_port(LOG_PROTOCOL_WARN,
|
||||
(char*)(cell->payload+RELAY_HEADER_SIZE),
|
||||
&address,NULL,&port)<0) {
|
||||
if (tor_addr_port_split(LOG_PROTOCOL_WARN,
|
||||
(char*)(cell->payload+RELAY_HEADER_SIZE),
|
||||
&address,&port)<0) {
|
||||
log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
|
||||
"Unable to parse addr:port in relay begin cell. Closing.");
|
||||
relay_send_end_cell_from_edge(rh.stream_id, circ,
|
||||
|
||||
+1
-1
@@ -3207,7 +3207,7 @@ dirserv_orconn_tls_done(const char *address,
|
||||
log_info(LD_DIRSERV, "Found router %s to be reachable at %s:%d. Yay.",
|
||||
router_describe(ri),
|
||||
address, ri->or_port);
|
||||
if (tor_addr_from_str(&addr, ri->address) != -1)
|
||||
if (tor_addr_parse(&addr, ri->address) != -1)
|
||||
addrp = &addr;
|
||||
else
|
||||
log_warn(LD_BUG, "Couldn't parse IP address \"%s\"", ri->address);
|
||||
|
||||
+4
-4
@@ -687,7 +687,7 @@ dns_resolve_impl(edge_connection_t *exitconn, int is_resolve,
|
||||
|
||||
/* first check if exitconn->_base.address is an IP. If so, we already
|
||||
* know the answer. */
|
||||
if (tor_addr_from_str(&addr, exitconn->_base.address) >= 0) {
|
||||
if (tor_addr_parse(&addr, exitconn->_base.address) >= 0) {
|
||||
if (tor_addr_family(&addr) == AF_INET) {
|
||||
tor_addr_copy(&exitconn->_base.addr, &addr);
|
||||
exitconn->address_ttl = DEFAULT_DNS_TTL;
|
||||
@@ -721,7 +721,7 @@ dns_resolve_impl(edge_connection_t *exitconn, int is_resolve,
|
||||
* .in-addr.arpa address but this isn't a resolve request, kill the
|
||||
* connection.
|
||||
*/
|
||||
if ((r = tor_addr_parse_reverse_lookup_name(&addr, exitconn->_base.address,
|
||||
if ((r = tor_addr_parse_PTR_name(&addr, exitconn->_base.address,
|
||||
AF_UNSPEC, 0)) != 0) {
|
||||
if (r == 1) {
|
||||
is_reverse = 1;
|
||||
@@ -1198,7 +1198,7 @@ configure_nameservers(int force)
|
||||
#ifdef HAVE_EVDNS_SET_DEFAULT_OUTGOING_BIND_ADDRESS
|
||||
if (options->OutboundBindAddress) {
|
||||
tor_addr_t addr;
|
||||
if (tor_addr_from_str(&addr, options->OutboundBindAddress) < 0) {
|
||||
if (tor_addr_parse(&addr, options->OutboundBindAddress) < 0) {
|
||||
log_warn(LD_CONFIG,"Outbound bind address '%s' didn't parse. Ignoring.",
|
||||
options->OutboundBindAddress);
|
||||
} else {
|
||||
@@ -1404,7 +1404,7 @@ launch_resolve(edge_connection_t *exitconn)
|
||||
}
|
||||
}
|
||||
|
||||
r = tor_addr_parse_reverse_lookup_name(
|
||||
r = tor_addr_parse_PTR_name(
|
||||
&a, exitconn->_base.address, AF_UNSPEC, 0);
|
||||
|
||||
tor_assert(the_evdns_base);
|
||||
|
||||
@@ -258,7 +258,7 @@ parse_port_config(const char *string)
|
||||
} else {
|
||||
addrport = smartlist_get(sl,1);
|
||||
if (strchr(addrport, ':') || strchr(addrport, '.')) {
|
||||
if (tor_addr_port_parse(addrport, &addr, &p)<0) {
|
||||
if (tor_addr_port_lookup(addrport, &addr, &p)<0) {
|
||||
log_warn(LD_CONFIG,"Unparseable address in hidden service port "
|
||||
"configuration.");
|
||||
goto err;
|
||||
|
||||
@@ -1812,9 +1812,9 @@ authority_cert_parse_from_string(const char *s, const char **end_of_string)
|
||||
struct in_addr in;
|
||||
char *address = NULL;
|
||||
tor_assert(tok->n_args);
|
||||
/* XXX023 use tor_addr_port_parse() below instead. -RD */
|
||||
if (parse_addr_port(LOG_WARN, tok->args[0], &address, NULL,
|
||||
&cert->dir_port)<0 ||
|
||||
/* XXX023 use some tor_addr parse function below instead. -RD */
|
||||
if (tor_addr_port_split(LOG_WARN, tok->args[0], &address,
|
||||
&cert->dir_port) < 0 ||
|
||||
tor_inet_aton(address, &in) == 0) {
|
||||
log_warn(LD_DIR, "Couldn't parse dir-address in certificate");
|
||||
tor_free(address);
|
||||
@@ -4982,7 +4982,7 @@ rend_parse_introduction_points(rend_service_descriptor_t *parsed,
|
||||
info->identity_digest, DIGEST_LEN);
|
||||
/* Parse IP address. */
|
||||
tok = find_by_keyword(tokens, R_IPO_IP_ADDRESS);
|
||||
if (tor_addr_from_str(&info->addr, tok->args[0])<0) {
|
||||
if (tor_addr_parse(&info->addr, tok->args[0])<0) {
|
||||
log_warn(LD_REND, "Could not parse introduction point address.");
|
||||
rend_intro_point_free(intro);
|
||||
goto err;
|
||||
|
||||
+2
-2
@@ -715,7 +715,7 @@ parse_smethod_line(const char *line, managed_proxy_t *mp)
|
||||
}
|
||||
|
||||
addrport = smartlist_get(items, 2);
|
||||
if (tor_addr_port_parse(addrport, &addr, &port)<0) {
|
||||
if (tor_addr_port_lookup(addrport, &addr, &port)<0) {
|
||||
log_warn(LD_CONFIG, "Error parsing transport "
|
||||
"address '%s'", addrport);
|
||||
goto err;
|
||||
@@ -800,7 +800,7 @@ parse_cmethod_line(const char *line, managed_proxy_t *mp)
|
||||
}
|
||||
|
||||
addrport = smartlist_get(items, 3);
|
||||
if (tor_addr_port_parse(addrport, &addr, &port)<0) {
|
||||
if (tor_addr_port_lookup(addrport, &addr, &port)<0) {
|
||||
log_warn(LD_CONFIG, "Error parsing transport "
|
||||
"address '%s'", addrport);
|
||||
goto err;
|
||||
|
||||
+23
-23
@@ -14,30 +14,30 @@ test_addr_basic(void)
|
||||
uint16_t u16;
|
||||
char *cp;
|
||||
|
||||
/* Test parse_addr_port */
|
||||
/* Test addr_port_lookup */
|
||||
cp = NULL; u32 = 3; u16 = 3;
|
||||
test_assert(!parse_addr_port(LOG_WARN, "1.2.3.4", &cp, &u32, &u16));
|
||||
test_assert(!addr_port_lookup(LOG_WARN, "1.2.3.4", &cp, &u32, &u16));
|
||||
test_streq(cp, "1.2.3.4");
|
||||
test_eq(u32, 0x01020304u);
|
||||
test_eq(u16, 0);
|
||||
tor_free(cp);
|
||||
test_assert(!parse_addr_port(LOG_WARN, "4.3.2.1:99", &cp, &u32, &u16));
|
||||
test_assert(!addr_port_lookup(LOG_WARN, "4.3.2.1:99", &cp, &u32, &u16));
|
||||
test_streq(cp, "4.3.2.1");
|
||||
test_eq(u32, 0x04030201u);
|
||||
test_eq(u16, 99);
|
||||
tor_free(cp);
|
||||
test_assert(!parse_addr_port(LOG_WARN, "nonexistent.address:4040",
|
||||
test_assert(!addr_port_lookup(LOG_WARN, "nonexistent.address:4040",
|
||||
&cp, NULL, &u16));
|
||||
test_streq(cp, "nonexistent.address");
|
||||
test_eq(u16, 4040);
|
||||
tor_free(cp);
|
||||
test_assert(!parse_addr_port(LOG_WARN, "localhost:9999", &cp, &u32, &u16));
|
||||
test_assert(!addr_port_lookup(LOG_WARN, "localhost:9999", &cp, &u32, &u16));
|
||||
test_streq(cp, "localhost");
|
||||
test_eq(u32, 0x7f000001u);
|
||||
test_eq(u16, 9999);
|
||||
tor_free(cp);
|
||||
u32 = 3;
|
||||
test_assert(!parse_addr_port(LOG_WARN, "localhost", NULL, &u32, &u16));
|
||||
test_assert(!addr_port_lookup(LOG_WARN, "localhost", NULL, &u32, &u16));
|
||||
test_eq(cp, NULL);
|
||||
test_eq(u32, 0x7f000001u);
|
||||
test_eq(u16, 0);
|
||||
@@ -364,32 +364,32 @@ test_addr_ip6_helpers(void)
|
||||
test_addr_compare_masked("0::2:2:1", ==, "0::8000:2:1", 80);
|
||||
|
||||
/* Test decorated addr_to_string. */
|
||||
test_eq(AF_INET6, tor_addr_from_str(&t1, "[123:45:6789::5005:11]"));
|
||||
test_eq(AF_INET6, tor_addr_parse(&t1, "[123:45:6789::5005:11]"));
|
||||
p1 = tor_addr_to_str(buf, &t1, sizeof(buf), 1);
|
||||
test_streq(p1, "[123:45:6789::5005:11]");
|
||||
test_eq(AF_INET, tor_addr_from_str(&t1, "18.0.0.1"));
|
||||
test_eq(AF_INET, tor_addr_parse(&t1, "18.0.0.1"));
|
||||
p1 = tor_addr_to_str(buf, &t1, sizeof(buf), 1);
|
||||
test_streq(p1, "18.0.0.1");
|
||||
|
||||
/* Test tor_addr_parse_reverse_lookup_name */
|
||||
i = tor_addr_parse_reverse_lookup_name(&t1, "Foobar.baz", AF_UNSPEC, 0);
|
||||
/* Test tor_addr_parse_PTR_name */
|
||||
i = tor_addr_parse_PTR_name(&t1, "Foobar.baz", AF_UNSPEC, 0);
|
||||
test_eq(0, i);
|
||||
i = tor_addr_parse_reverse_lookup_name(&t1, "Foobar.baz", AF_UNSPEC, 1);
|
||||
i = tor_addr_parse_PTR_name(&t1, "Foobar.baz", AF_UNSPEC, 1);
|
||||
test_eq(0, i);
|
||||
i = tor_addr_parse_reverse_lookup_name(&t1, "1.0.168.192.in-addr.arpa",
|
||||
i = tor_addr_parse_PTR_name(&t1, "1.0.168.192.in-addr.arpa",
|
||||
AF_UNSPEC, 1);
|
||||
test_eq(1, i);
|
||||
test_eq(tor_addr_family(&t1), AF_INET);
|
||||
p1 = tor_addr_to_str(buf, &t1, sizeof(buf), 1);
|
||||
test_streq(p1, "192.168.0.1");
|
||||
i = tor_addr_parse_reverse_lookup_name(&t1, "192.168.0.99", AF_UNSPEC, 0);
|
||||
i = tor_addr_parse_PTR_name(&t1, "192.168.0.99", AF_UNSPEC, 0);
|
||||
test_eq(0, i);
|
||||
i = tor_addr_parse_reverse_lookup_name(&t1, "192.168.0.99", AF_UNSPEC, 1);
|
||||
i = tor_addr_parse_PTR_name(&t1, "192.168.0.99", AF_UNSPEC, 1);
|
||||
test_eq(1, i);
|
||||
p1 = tor_addr_to_str(buf, &t1, sizeof(buf), 1);
|
||||
test_streq(p1, "192.168.0.99");
|
||||
memset(&t1, 0, sizeof(t1));
|
||||
i = tor_addr_parse_reverse_lookup_name(&t1,
|
||||
i = tor_addr_parse_PTR_name(&t1,
|
||||
"0.1.2.3.4.5.6.7.8.9.a.b.c.d.e.f."
|
||||
"f.e.e.b.1.e.b.e.e.f.f.e.e.e.d.9."
|
||||
"ip6.ARPA",
|
||||
@@ -398,37 +398,37 @@ test_addr_ip6_helpers(void)
|
||||
p1 = tor_addr_to_str(buf, &t1, sizeof(buf), 1);
|
||||
test_streq(p1, "[9dee:effe:ebe1:beef:fedc:ba98:7654:3210]");
|
||||
/* Failing cases. */
|
||||
i = tor_addr_parse_reverse_lookup_name(&t1,
|
||||
i = tor_addr_parse_PTR_name(&t1,
|
||||
"6.7.8.9.a.b.c.d.e.f."
|
||||
"f.e.e.b.1.e.b.e.e.f.f.e.e.e.d.9."
|
||||
"ip6.ARPA",
|
||||
AF_UNSPEC, 0);
|
||||
test_eq(i, -1);
|
||||
i = tor_addr_parse_reverse_lookup_name(&t1,
|
||||
i = tor_addr_parse_PTR_name(&t1,
|
||||
"6.7.8.9.a.b.c.d.e.f.a.b.c.d.e.f.0."
|
||||
"f.e.e.b.1.e.b.e.e.f.f.e.e.e.d.9."
|
||||
"ip6.ARPA",
|
||||
AF_UNSPEC, 0);
|
||||
test_eq(i, -1);
|
||||
i = tor_addr_parse_reverse_lookup_name(&t1,
|
||||
i = tor_addr_parse_PTR_name(&t1,
|
||||
"6.7.8.9.a.b.c.d.e.f.X.0.0.0.0.9."
|
||||
"f.e.e.b.1.e.b.e.e.f.f.e.e.e.d.9."
|
||||
"ip6.ARPA",
|
||||
AF_UNSPEC, 0);
|
||||
test_eq(i, -1);
|
||||
i = tor_addr_parse_reverse_lookup_name(&t1, "32.1.1.in-addr.arpa",
|
||||
i = tor_addr_parse_PTR_name(&t1, "32.1.1.in-addr.arpa",
|
||||
AF_UNSPEC, 0);
|
||||
test_eq(i, -1);
|
||||
i = tor_addr_parse_reverse_lookup_name(&t1, ".in-addr.arpa",
|
||||
i = tor_addr_parse_PTR_name(&t1, ".in-addr.arpa",
|
||||
AF_UNSPEC, 0);
|
||||
test_eq(i, -1);
|
||||
i = tor_addr_parse_reverse_lookup_name(&t1, "1.2.3.4.5.in-addr.arpa",
|
||||
i = tor_addr_parse_PTR_name(&t1, "1.2.3.4.5.in-addr.arpa",
|
||||
AF_UNSPEC, 0);
|
||||
test_eq(i, -1);
|
||||
i = tor_addr_parse_reverse_lookup_name(&t1, "1.2.3.4.5.in-addr.arpa",
|
||||
i = tor_addr_parse_PTR_name(&t1, "1.2.3.4.5.in-addr.arpa",
|
||||
AF_INET6, 0);
|
||||
test_eq(i, -1);
|
||||
i = tor_addr_parse_reverse_lookup_name(&t1,
|
||||
i = tor_addr_parse_PTR_name(&t1,
|
||||
"6.7.8.9.a.b.c.d.e.f.a.b.c.d.e.0."
|
||||
"f.e.e.b.1.e.b.e.e.f.f.e.e.e.d.9."
|
||||
"ip6.ARPA",
|
||||
|
||||
@@ -169,7 +169,7 @@ parse_commandline(int argc, char **argv)
|
||||
fprintf(stderr, "No argument to -a\n");
|
||||
return 1;
|
||||
}
|
||||
if (parse_addr_port(LOG_ERR, argv[++i], NULL, &addr, &port)<0)
|
||||
if (addr_port_lookup(LOG_ERR, argv[++i], NULL, &addr, &port)<0)
|
||||
return 1;
|
||||
in.s_addr = htonl(addr);
|
||||
tor_inet_ntoa(&in, b, sizeof(b));
|
||||
|
||||
@@ -393,7 +393,7 @@ main(int argc, char **argv)
|
||||
socksport = 9050; /* 9050 */
|
||||
}
|
||||
} else if (n_args == 2) {
|
||||
if (parse_addr_port(LOG_WARN, arg[1], NULL, &sockshost, &socksport)<0) {
|
||||
if (addr_port_lookup(LOG_WARN, arg[1], NULL, &sockshost, &socksport)<0) {
|
||||
fprintf(stderr, "Couldn't parse/resolve address %s", arg[1]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user