Merge remote-tracking branch 'teor/routerset-parse-IPv6-literals'

(Minor conflicts)
This commit is contained in:
Nick Mathewson 2015-10-02 13:54:20 +02:00
commit 488e9a0502
3 changed files with 108 additions and 5 deletions

View File

@ -0,0 +1,5 @@
o Minor bug fixes (routersets, IPv6):
- routerset_parse now accepts IPv6 literal addresses.
Fix for ticket 17060. Patch by "teor".
Patch on 3ce6e2fba290 (24 Jul 2008), and related commits,
released in 0.2.1.3-alpha.

View File

@ -107,10 +107,12 @@ routerset_parse(routerset_t *target, const char *s, const char *description)
description); description);
smartlist_add(target->country_names, countryname); smartlist_add(target->country_names, countryname);
added_countries = 1; added_countries = 1;
} else if ((strchr(nick,'.') || strchr(nick, '*')) && } else if ((strchr(nick,'.') || strchr(nick, ':') || strchr(nick, '*'))
(p = router_parse_addr_policy_item_from_string( && (p = router_parse_addr_policy_item_from_string(
nick, ADDR_POLICY_REJECT, nick, ADDR_POLICY_REJECT,
&malformed_list))) { &malformed_list))) {
/* IPv4 addresses contain '.', IPv6 addresses contain ':',
* and wildcard addresses contain '*'. */
log_debug(LD_CONFIG, "Adding address %s to %s", nick, description); log_debug(LD_CONFIG, "Adding address %s to %s", nick, description);
smartlist_add(target->policies, p); smartlist_add(target->policies, p);
} else if (malformed_list) { } else if (malformed_list) {

View File

@ -423,10 +423,10 @@ NS(test_main)(void *arg)
} }
#undef NS_SUBMODULE #undef NS_SUBMODULE
#define NS_SUBMODULE ASPECT(routerset_parse, policy) #define NS_SUBMODULE ASPECT(routerset_parse, policy_wildcard)
/* /*
* Structural test for routerset_parse, when given a valid policy. * Structural test for routerset_parse, when given a valid wildcard policy.
*/ */
NS_DECL(addr_policy_t *, router_parse_addr_policy_item_from_string, NS_DECL(addr_policy_t *, router_parse_addr_policy_item_from_string,
@ -469,6 +469,100 @@ NS(router_parse_addr_policy_item_from_string)(const char *s,
return NS(mock_addr_policy); return NS(mock_addr_policy);
} }
#undef NS_SUBMODULE
#define NS_SUBMODULE ASPECT(routerset_parse, policy_ipv4)
/*
* Structural test for routerset_parse, when given a valid IPv4 address
* literal policy.
*/
NS_DECL(addr_policy_t *, router_parse_addr_policy_item_from_string,
(const char *s, int assume_action, int *bogus));
addr_policy_t *NS(mock_addr_policy);
static void
NS(test_main)(void *arg)
{
routerset_t *set;
const char *s;
int r;
(void)arg;
NS_MOCK(router_parse_addr_policy_item_from_string);
NS(mock_addr_policy) = tor_malloc_zero(sizeof(addr_policy_t));
set = routerset_new();
s = "127.0.0.1";
r = routerset_parse(set, s, "");
tt_int_op(r, OP_EQ, 0);
tt_int_op(smartlist_len(set->policies), OP_NE, 0);
tt_int_op(CALLED(router_parse_addr_policy_item_from_string), OP_EQ, 1);
done:
routerset_free(set);
}
addr_policy_t *
NS(router_parse_addr_policy_item_from_string)(const char *s, int assume_action,
int *bogus)
{
(void)s;
(void)assume_action;
CALLED(router_parse_addr_policy_item_from_string)++;
*bogus = 0;
return NS(mock_addr_policy);
}
#undef NS_SUBMODULE
#define NS_SUBMODULE ASPECT(routerset_parse, policy_ipv6)
/*
* Structural test for routerset_parse, when given a valid IPv6 address
* literal policy.
*/
NS_DECL(addr_policy_t *, router_parse_addr_policy_item_from_string,
(const char *s, int assume_action, int *bad));
addr_policy_t *NS(mock_addr_policy);
static void
NS(test_main)(void *arg)
{
routerset_t *set;
const char *s;
int r;
(void)arg;
NS_MOCK(router_parse_addr_policy_item_from_string);
NS(mock_addr_policy) = tor_malloc_zero(sizeof(addr_policy_t));
set = routerset_new();
s = "::1";
r = routerset_parse(set, s, "");
tt_int_op(r, OP_EQ, 0);
tt_int_op(smartlist_len(set->policies), OP_NE, 0);
tt_int_op(CALLED(router_parse_addr_policy_item_from_string), OP_EQ, 1);
done:
routerset_free(set);
}
addr_policy_t *
NS(router_parse_addr_policy_item_from_string)(const char *s,
int assume_action, int *bad)
{
(void)s;
(void)assume_action;
CALLED(router_parse_addr_policy_item_from_string)++;
*bad = 0;
return NS(mock_addr_policy);
}
#undef NS_SUBMODULE #undef NS_SUBMODULE
#define NS_SUBMODULE ASPECT(routerset_union, source_bad) #define NS_SUBMODULE ASPECT(routerset_union, source_bad)
@ -2109,7 +2203,9 @@ struct testcase_t routerset_tests[] = {
TEST_CASE_ASPECT(routerset_parse, valid_hexdigest), TEST_CASE_ASPECT(routerset_parse, valid_hexdigest),
TEST_CASE_ASPECT(routerset_parse, valid_nickname), TEST_CASE_ASPECT(routerset_parse, valid_nickname),
TEST_CASE_ASPECT(routerset_parse, get_countryname), TEST_CASE_ASPECT(routerset_parse, get_countryname),
TEST_CASE_ASPECT(routerset_parse, policy), TEST_CASE_ASPECT(routerset_parse, policy_wildcard),
TEST_CASE_ASPECT(routerset_parse, policy_ipv4),
TEST_CASE_ASPECT(routerset_parse, policy_ipv6),
TEST_CASE(routerset_subtract_nodes), TEST_CASE(routerset_subtract_nodes),
TEST_CASE_ASPECT(routerset_subtract_nodes, null_routerset), TEST_CASE_ASPECT(routerset_subtract_nodes, null_routerset),
TEST_CASE(routerset_to_string), TEST_CASE(routerset_to_string),