From e0387d1322a5dc5ea46da1e3dc84a2befa29d922 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 23 Feb 2005 06:40:48 +0000 Subject: [PATCH] Addressmap tweak: Make "addressmap x x" remove any mapping from the address x. svn:r3666 --- src/or/connection_edge.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c index 632a93e497..ec085bb406 100644 --- a/src/or/connection_edge.c +++ b/src/or/connection_edge.c @@ -430,8 +430,11 @@ int addressmap_already_mapped(const char *address) { /** Register a request to map address to new_address, * which will expire on expires (or 0 if never expires). * - * new_address should be a newly dup'ed string, which we'll use or + * new_address should be a newly dup'ed string, which we'll use or * free as appropriate. We will leave address alone. + * + * If new_address is NULL, or equal to address, remove + * any mappings that exist from address. */ void addressmap_register(const char *address, char *new_address, time_t expires) { addressmap_entry_t *ent; @@ -442,6 +445,15 @@ void addressmap_register(const char *address, char *new_address, time_t expires) tor_free(new_address); return; } + if (!new_address || !strcasecmp(address,new_address)) { + tor_free(new_address); + /* Remove the old mapping, if any. */ + if (ent) { + addressmap_ent_free(ent); + strmap_remove(addressmap, address); + } + return; + } if (ent) { /* we'll replace it */ tor_free(ent->new_address); } else { /* make a new one and register it */ @@ -487,7 +499,7 @@ void client_dns_set_addressmap(const char *address, uint32_t val) tor_assert(address); tor_assert(val); if (tor_inet_aton(address, &in)) - return; /* don't set an addressmap back to ourselves! */ + return; /* don't set an addresmap back to ourselves! ????NM*/ in.s_addr = htonl(val); addr = tor_malloc(INET_NTOA_BUF_LEN); tor_inet_ntoa(&in,addr,INET_NTOA_BUF_LEN); -- 2.11.4.GIT