Generate 18.0.0.0/8 address policy format in descs when we can; warn when the mask is not reducible to a bit-prefix.

svn:r5991
This commit is contained in:
Nick Mathewson
2006-02-12 23:58:22 +00:00
parent b99f903e34
commit dba155ecff
5 changed files with 37 additions and 9 deletions
+4
View File
@@ -3150,6 +3150,10 @@ config_parse_addr_policy(config_line_t *cfg,
debug(LD_CONFIG,"Adding new entry '%s'",ent);
*nextp = router_parse_addr_policy_from_string(ent, assume_action);
if (*nextp) {
if (addr_mask_get_bits((*nextp)->msk)<0) {
warn(LD_CONFIG, "Address policy element '%s' can't be expressed "
"as a bit prefix.", ent);
}
nextp = &((*nextp)->next);
} else {
warn(LD_CONFIG,"Malformed policy '%s'.", ent);
+12 -7
View File
@@ -1111,13 +1111,18 @@ router_dump_router_to_string(char *s, size_t maxlen, routerinfo_t *router,
return -1;
written += result;
if (tmpe->msk != 0xFFFFFFFFu && tmpe->msk != 0) {
/* Write "/255.255.0.0" */
in.s_addr = htonl(tmpe->msk);
tor_inet_ntoa(&in, addrbuf, sizeof(addrbuf));
result = tor_snprintf(s+written, maxlen-written, "/%s", addrbuf);
if (result<0)
return -1;
written += result;
int n_bits = addr_mask_get_bits(tmpe->msk);
if (n_bits >= 0) {
if (tor_snprintf(s+written, maxlen-written, "/%d", n_bits)<0)
return -1;
} else {
/* Write "/255.255.0.0" */
in.s_addr = htonl(tmpe->msk);
tor_inet_ntoa(&in, addrbuf, sizeof(addrbuf));
if (tor_snprintf(s+written, maxlen-written, "/%s", addrbuf)<0)
return -1;
}
written += strlen(s+written);
}
if (tmpe->prt_min <= 1 && tmpe->prt_max == 65535) {
/* There is no port set; write ":*" */