mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-27 22:03:31 +01:00
Clip DNS TTL values once in event callback
This change ensures that other parts of the code base always operate on the same clipped TTL values, notably without being aware of clipping.
This commit is contained in:
parent
619dd35321
commit
0fe2096144
@ -532,7 +532,7 @@ connection_edge_end(edge_connection_t *conn, uint8_t reason)
|
||||
memcpy(payload+1, tor_addr_to_in6_addr8(&conn->base_.addr), 16);
|
||||
addrlen = 16;
|
||||
}
|
||||
set_uint32(payload+1+addrlen, htonl(clip_dns_ttl(conn->address_ttl)));
|
||||
set_uint32(payload+1+addrlen, htonl(conn->address_ttl));
|
||||
payload_len += 4+addrlen;
|
||||
}
|
||||
|
||||
@ -926,7 +926,7 @@ connected_cell_format_payload(uint8_t *payload_out,
|
||||
return -1;
|
||||
}
|
||||
|
||||
set_uint32(payload_out + connected_payload_len, htonl(clip_dns_ttl(ttl)));
|
||||
set_uint32(payload_out + connected_payload_len, htonl(ttl));
|
||||
connected_payload_len += 4;
|
||||
|
||||
tor_assert(connected_payload_len <= MAX_CONNECTED_CELL_PAYLOAD_LEN);
|
||||
|
@ -512,7 +512,7 @@ send_resolved_cell,(edge_connection_t *conn, uint8_t answer_type,
|
||||
uint32_t ttl;
|
||||
|
||||
buf[0] = answer_type;
|
||||
ttl = clip_dns_ttl(conn->address_ttl);
|
||||
ttl = conn->address_ttl;
|
||||
|
||||
switch (answer_type)
|
||||
{
|
||||
@ -584,7 +584,7 @@ send_resolved_hostname_cell,(edge_connection_t *conn,
|
||||
size_t namelen = strlen(hostname);
|
||||
|
||||
tor_assert(namelen < 256);
|
||||
ttl = clip_dns_ttl(conn->address_ttl);
|
||||
ttl = conn->address_ttl;
|
||||
|
||||
buf[0] = RESOLVED_TYPE_HOSTNAME;
|
||||
buf[1] = (uint8_t)namelen;
|
||||
@ -1310,7 +1310,7 @@ make_pending_resolve_cached(cached_resolve_t *resolve)
|
||||
resolve->ttl_hostname < ttl)
|
||||
ttl = resolve->ttl_hostname;
|
||||
|
||||
set_expiry(new_resolve, time(NULL) + clip_dns_ttl(ttl));
|
||||
set_expiry(new_resolve, time(NULL) + ttl);
|
||||
}
|
||||
|
||||
assert_cache_ok();
|
||||
@ -1725,7 +1725,7 @@ evdns_callback(int result, char type, int count, int ttl, void *addresses,
|
||||
}
|
||||
if (result != DNS_ERR_SHUTDOWN)
|
||||
dns_found_answer(string_address, orig_query_type,
|
||||
result, &addr, hostname, ttl);
|
||||
result, &addr, hostname, clip_dns_ttl(ttl));
|
||||
|
||||
/* The result can be changed within this function thus why we note the result
|
||||
* at the end. */
|
||||
|
@ -354,7 +354,7 @@ test_cfmt_connected_cells(void *arg)
|
||||
rh.length = connected_cell_format_payload(cell.payload+RELAY_HEADER_SIZE,
|
||||
&addr, 1024);
|
||||
tt_int_op(rh.length, OP_EQ, 8);
|
||||
test_memeq_hex(cell.payload+RELAY_HEADER_SIZE, "1e28323c" "00000e10");
|
||||
test_memeq_hex(cell.payload+RELAY_HEADER_SIZE, "1e28323c" "00000400");
|
||||
|
||||
/* Try parsing it. */
|
||||
tor_addr_make_unspec(&addr);
|
||||
@ -362,7 +362,7 @@ test_cfmt_connected_cells(void *arg)
|
||||
tt_int_op(r, OP_EQ, 0);
|
||||
tt_int_op(tor_addr_family(&addr), OP_EQ, AF_INET);
|
||||
tt_str_op(fmt_addr(&addr), OP_EQ, "30.40.50.60");
|
||||
tt_int_op(ttl, OP_EQ, 3600); /* not 1024, since we clipped to 3600 */
|
||||
tt_int_op(ttl, OP_EQ, 1024);
|
||||
|
||||
/* Try an IPv6 address */
|
||||
memset(&rh, 0, sizeof(rh));
|
||||
|
Loading…
Reference in New Issue
Block a user