Allow private:* in routerdescs; not generated yet (because older Tors do not understand it); needs testing.

svn:r6086
This commit is contained in:
Nick Mathewson
2006-03-05 05:27:59 +00:00
parent ae628a3aee
commit 6a4e304d9e
4 changed files with 107 additions and 32 deletions
+47 -31
View File
@@ -1440,8 +1440,52 @@ addr_mask_get_bits(uint32_t mask)
return -1;
}
/** Parse a string <b>s</b> in the format of (*|port(-maxport)?)?, setting the
* various *out pointers as appropriate. Return 0 on success, -1 on failure.
*/
int
parse_port_range(const char *port, uint16_t *port_min_out,
uint16_t *port_max_out)
{
tor_assert(port_min_out);
tor_assert(port_max_out);
if (!port || *port == '\0' || strcmp(port, "*") == 0) {
*port_min_out = 1;
*port_max_out = 65535;
} else {
char *endptr = NULL;
*port_min_out = (uint16_t) tor_parse_long(port, 10, 1, 65535,
NULL, &endptr);
if (*endptr == '-') {
port = endptr+1;
endptr = NULL;
*port_max_out = (uint16_t) tor_parse_long(port, 10, 1, 65535, NULL,
&endptr);
if (*endptr || !*port_max_out) {
log_warn(LD_GENERAL,
"Malformed port \"%s\" on address range rejecting.",
port);
}
} else if (*endptr || !*port_min_out) {
log_warn(LD_GENERAL,
"Malformed port \"%s\" on address range; rejecting.",
port);
return -1;
} else {
*port_max_out = *port_min_out;
}
if (*port_min_out > *port_max_out) {
log_warn(LD_GENERAL, "Insane port range on address policy; rejecting.");
return -1;
}
}
return 0;
}
/** Parse a string <b>s</b> in the format of
* (IP(/mask|/mask-bits)?|*):(*|port(-maxport)?), setting the various
* (IP(/mask|/mask-bits)?|*)(:*|port(-maxport)?)?, setting the various
* *out pointers as appropriate. Return 0 on success, -1 on failure.
*/
int
@@ -1510,36 +1554,8 @@ parse_addr_and_port_range(const char *s, uint32_t *addr_out,
}
}
if (!port || strcmp(port, "*") == 0) {
*port_min_out = 1;
*port_max_out = 65535;
} else {
endptr = NULL;
*port_min_out = (uint16_t) tor_parse_long(port, 10, 1, 65535,
NULL, &endptr);
if (*endptr == '-') {
port = endptr+1;
endptr = NULL;
*port_max_out = (uint16_t) tor_parse_long(port, 10, 1, 65535, NULL,
&endptr);
if (*endptr || !*port_max_out) {
log_warn(LD_GENERAL,
"Malformed port \"%s\" on address range rejecting.",
port);
}
} else if (*endptr || !*port_min_out) {
log_warn(LD_GENERAL,
"Malformed port \"%s\" on address range; rejecting.",
port);
goto err;
} else {
*port_max_out = *port_min_out;
}
if (*port_min_out > *port_max_out) {
log_warn(LD_GENERAL, "Insane port range on address policy; rejecting.");
goto err;
}
}
if (parse_port_range(port, port_min_out, port_max_out)<0)
goto err;
tor_free(address);
return 0;
+2
View File
@@ -165,6 +165,8 @@ int is_internal_IP(uint32_t ip, int for_listening);
int is_local_IP(uint32_t ip);
int parse_addr_port(const char *addrport, char **address, uint32_t *addr,
uint16_t *port);
int parse_port_range(const char *port, uint16_t *port_min_out,
uint16_t *port_max_out);
int parse_addr_and_port_range(const char *s, uint32_t *addr_out,
uint32_t *mask_out, uint16_t *port_min_out,
uint16_t *port_max_out);