Commit 1385ab06 authored by Nick Mathewson's avatar Nick Mathewson 🥔
Browse files

Merge remote-tracking branch 'rl1987/ticket16831_part2_rebased'

parents 0696ac5b 2e980e9a
Loading
Loading
Loading
Loading

changes/test16831

0 → 100644
+3 −0
Original line number Diff line number Diff line
  o Testing:
    - Cover dns_resolve_impl() in dns.c with unit tests. Implements a
      portion of ticket 16831.
+19 −10
Original line number Diff line number Diff line
@@ -107,13 +107,9 @@ static void dns_found_answer(const char *address, uint8_t query_type,
                             const tor_addr_t *addr,
                             const char *hostname,
                             uint32_t ttl);
static int launch_resolve(cached_resolve_t *resolve);
static void add_wildcarded_test_address(const char *address);
static int configure_nameservers(int force);
static int answer_is_wildcarded(const char *ip);
static int set_exitconn_info_from_resolve(edge_connection_t *exitconn,
                                          const cached_resolve_t *resolve,
                                          char **hostname_out);
static int evdns_err_is_transient(int err);
static void inform_pending_connections(cached_resolve_t *resolve);
static void make_pending_resolve_cached(cached_resolve_t *cached);
@@ -859,10 +855,10 @@ dns_resolve_impl,(edge_connection_t *exitconn, int is_resolve,
 * Return -2 on a transient error, -1 on a permenent error, and 1 on
 * a successful lookup.
 */
static int
set_exitconn_info_from_resolve(edge_connection_t *exitconn,
MOCK_IMPL(STATIC int,
set_exitconn_info_from_resolve,(edge_connection_t *exitconn,
                                const cached_resolve_t *resolve,
                               char **hostname_out)
                                char **hostname_out))
{
  int ipv4_ok, ipv6_ok, answer_with_ipv4, r;
  uint32_t begincell_flags;
@@ -1664,8 +1660,8 @@ launch_one_resolve(const char *address, uint8_t query_type,
/** For eventdns: start resolving as necessary to find the target for
 * <b>exitconn</b>.  Returns -1 on error, -2 on transient error,
 * 0 on "resolve launched." */
static int
launch_resolve(cached_resolve_t *resolve)
MOCK_IMPL(STATIC int,
launch_resolve,(cached_resolve_t *resolve))
{
  tor_addr_t a;
  int r;
@@ -2118,5 +2114,18 @@ assert_cache_ok_(void)
      }
    });
}

#endif

cached_resolve_t
*dns_get_cache_entry(cached_resolve_t *query)
{
  return HT_FIND(cache_map, &cache_root, query);
}

void
dns_insert_cache_entry(cached_resolve_t *new_entry)
{
  HT_INSERT(cache_map, &cache_root, new_entry);
}
+12 −0
Original line number Diff line number Diff line
@@ -42,6 +42,18 @@ uint8_t answer_type,const cached_resolve_t *resolved));

MOCK_DECL(STATIC void,send_resolved_hostname_cell,(edge_connection_t *conn,
const char *hostname));

cached_resolve_t *dns_get_cache_entry(cached_resolve_t *query);
void dns_insert_cache_entry(cached_resolve_t *new_entry);

MOCK_DECL(STATIC int,
set_exitconn_info_from_resolve,(edge_connection_t *exitconn,
                                const cached_resolve_t *resolve,
                                char **hostname_out));

MOCK_DECL(STATIC int,
launch_resolve,(cached_resolve_t *resolve));

#endif

#endif
+2 −2
Original line number Diff line number Diff line
@@ -1714,8 +1714,8 @@ router_compare_to_my_exit_policy(const tor_addr_t *addr, uint16_t port)

/** Return true iff my exit policy is reject *:*.  Return -1 if we don't
 * have a descriptor */
int
router_my_exit_policy_is_reject_star(void)
MOCK_IMPL(int,
router_my_exit_policy_is_reject_star,(void))
{
  if (!router_get_my_routerinfo()) /* make sure desc_routerinfo exists */
    return -1;
+1 −1
Original line number Diff line number Diff line
@@ -80,7 +80,7 @@ void check_descriptor_ipaddress_changed(time_t now);
void router_new_address_suggestion(const char *suggestion,
                                   const dir_connection_t *d_conn);
int router_compare_to_my_exit_policy(const tor_addr_t *addr, uint16_t port);
int router_my_exit_policy_is_reject_star(void);
MOCK_DECL(int, router_my_exit_policy_is_reject_star,(void));
MOCK_DECL(const routerinfo_t *, router_get_my_routerinfo, (void));
extrainfo_t *router_get_my_extrainfo(void);
const char *router_get_my_descriptor(void);
Loading