diff options
author | Nick Mathewson <nickm@torproject.org> | 2011-01-07 22:05:11 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2011-01-07 22:05:11 -0500 |
commit | d16923a35dd676443e1bd944ef2062a3f85d7e34 (patch) | |
tree | 1fd47f8dafc07ab031b38bd3b9a791401867b3b8 /src/or/connection_edge.c | |
parent | 2be65619f90e1be79cc77102384eef2dde857e21 (diff) | |
parent | 54135b72f88e6b2301d80f583dfce8aba5d37b5a (diff) | |
download | tor-d16923a35dd676443e1bd944ef2062a3f85d7e34.tar.gz tor-d16923a35dd676443e1bd944ef2062a3f85d7e34.zip |
Merge remote branch 'origin/maint-0.2.2'
Diffstat (limited to 'src/or/connection_edge.c')
-rw-r--r-- | src/or/connection_edge.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c index 463d02070d..c0b177d6e2 100644 --- a/src/or/connection_edge.c +++ b/src/or/connection_edge.c @@ -1177,6 +1177,18 @@ address_is_in_virtual_range(const char *address) return 0; } +/** Increment the value of next_virtual_addr; reset it to the start of the + * virtual address range if it wraps around. + */ +static INLINE void +increment_virtual_addr(void) +{ + ++next_virtual_addr; + if (addr_mask_cmp_bits(next_virtual_addr, virtual_addr_network, + virtual_addr_netmask_bits)) + next_virtual_addr = virtual_addr_network; +} + /** Return a newly allocated string holding an address of <b>type</b> * (one of RESOLVED_TYPE_{IPV4|HOSTNAME}) that has not yet been mapped, * and that is very unlikely to be the address of any real host. @@ -1206,7 +1218,7 @@ addressmap_get_virtual_address(int type) /* Don't hand out any .0 or .255 address. */ while ((next_virtual_addr & 0xff) == 0 || (next_virtual_addr & 0xff) == 0xff) { - ++next_virtual_addr; + increment_virtual_addr(); if (! --available) { log_warn(LD_CONFIG, "Ran out of virtual addresses!"); return NULL; @@ -1215,20 +1227,17 @@ addressmap_get_virtual_address(int type) in.s_addr = htonl(next_virtual_addr); tor_inet_ntoa(&in, buf, sizeof(buf)); if (!strmap_get(addressmap, buf)) { - ++next_virtual_addr; + increment_virtual_addr(); break; } - ++next_virtual_addr; + increment_virtual_addr(); --available; - log_info(LD_CONFIG, "%d addrs available", (int)available); + // log_info(LD_CONFIG, "%d addrs available", (int)available); if (! available) { log_warn(LD_CONFIG, "Ran out of virtual addresses!"); return NULL; } - if (addr_mask_cmp_bits(next_virtual_addr, virtual_addr_network, - virtual_addr_netmask_bits)) - next_virtual_addr = virtual_addr_network; } return tor_strdup(buf); } else { |