Do not keep a string representation of every single addr_policy_t lying around. This might save a few hundred K.
svn:r12617
/** A linked list of policy rules */
typedef struct addr_policy_t {
addr_policy_action_t policy_type; /**< What to do when the policy matches.*/
- char *string; /**< String representation of this rule. */
/* XXXX020 make this ipv6-capable */
uint32_t addr; /**< Base address to accept or reject. */
tmp=ap;
while (tmp) {
if (tmp->next && addr_policy_covers(ap, tmp->next)) {
+ char p1[POLICY_BUF_LEN], p2[POLICY_BUF_LEN];
+ policy_write_item(p1, sizeof(p1), tmp->next);
+ policy_write_item(p2, sizeof(p2), ap);
log(LOG_DEBUG, LD_CONFIG, "Removing exit policy %s. It is made "
- "redundant by %s.", tmp->next->string, ap->string);
+ "redundant by %s.", p1, p2);
victim = tmp->next;
tmp->next = victim->next;
victim->next = NULL;
}
} else { /* policy_types are equal. */
if (addr_policy_covers(tmp, ap)) {
+ char p1[POLICY_BUF_LEN], p2[POLICY_BUF_LEN];
+ policy_write_item(p1, sizeof(p1), ap);
+ policy_write_item(p2, sizeof(p2), tmp);
log(LOG_DEBUG, LD_CONFIG, "Removing exit policy %s. It is already "
- "covered by %s.", ap->string, tmp->string);
+ "covered by %s.", ap, tmp);
victim = ap;
ap = ap->next;
while (p) {
e = p;
p = p->next;
- tor_free(e->string);
tor_free(e);
}
}
{
addr_policy_t *newe;
char *arg;
- char buf[POLICY_BUF_LEN];
tor_assert(tok->tp == K_REJECT || tok->tp == K_ACCEPT);
&newe->prt_min, &newe->prt_max))
goto policy_read_failed;
- if (policy_write_item(buf, sizeof(buf), newe) < 0)
- goto policy_read_failed;
-
- newe->string = tor_strdup(buf);
return newe;
policy_read_failed:
nextp = &result;
for (net = 0; private_nets[net]; ++net) {
- size_t len;
+ char buf[POLICY_BUF_LEN];
*nextp = tor_malloc_zero(sizeof(addr_policy_t));
(*nextp)->policy_type = (tok->tp == K_REJECT) ? ADDR_POLICY_REJECT
: ADDR_POLICY_ACCEPT;
- len = strlen(arg)+strlen(private_nets[net])+16;
- (*nextp)->string = tor_malloc(len+1);
- tor_snprintf((*nextp)->string, len, "%s %s%s",
- tok->tp == K_REJECT ? "reject" : "accept",
+ tor_snprintf(buf, sizeof(buf), "%s%s",
private_nets[net], arg);
- if (parse_addr_and_port_range((*nextp)->string + 7,
+ if (parse_addr_and_port_range(buf,
&(*nextp)->addr, &(*nextp)->maskbits,
&(*nextp)->prt_min, &(*nextp)->prt_max)) {
log_warn(LD_BUG, "Couldn't parse an address range we generated!");
void
assert_addr_policy_ok(addr_policy_t *t)
{
- addr_policy_t *t2;
while (t) {
tor_assert(t->policy_type == ADDR_POLICY_REJECT ||
t->policy_type == ADDR_POLICY_ACCEPT);
tor_assert(t->prt_min <= t->prt_max);
- t2 = router_parse_addr_policy_from_string(t->string, -1);
- tor_assert(t2);
- tor_assert(t2->policy_type == t->policy_type);
- tor_assert(t2->addr == t->addr);
- tor_assert(t2->maskbits == t->maskbits);
- tor_assert(t2->prt_min == t->prt_min);
- tor_assert(t2->prt_max == t->prt_max);
- tor_assert(!strcmp(t2->string, t->string));
- tor_assert(t2->next == NULL);
- addr_policy_free(t2);
-
t = t->next;
}
r1.platform = tor_strdup(platform);
ex1.policy_type = ADDR_POLICY_ACCEPT;
- ex1.string = NULL;
ex1.addr = 0;
ex1.maskbits = 0;
ex1.prt_min = ex1.prt_max = 80;
test_eq(16, policy->maskbits);
test_eq(1, policy->prt_min);
test_eq(65535, policy->prt_max);
- test_streq("reject 192.168.0.0/16:*", policy->string);
test_assert(ADDR_POLICY_ACCEPTED ==
compare_addr_to_addr_policy(0x01020304u, 2, policy));
line.next = NULL;
test_assert(0 == policies_parse_exit_policy(&line, &policy, 0, NULL));
test_assert(policy);
- test_streq(policy->string, "accept *:80");
- test_streq(policy->next->string, "reject *:*");
+ //test_streq(policy->string, "accept *:80");
+ //test_streq(policy->next->string, "reject *:*");
test_eq_ptr(policy->next->next, NULL);
addr_policy_free(policy);