]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
fix the case when a hostnames IP address jumps from one network to
authorwessels <>
Fri, 9 Jan 1998 15:06:32 +0000 (15:06 +0000)
committerwessels <>
Fri, 9 Jan 1998 15:06:32 +0000 (15:06 +0000)
another

src/net_db.cc

index b0dd73800d2012276f0683b8a785f9e587d8fe76..53a224768d188244fe34de932d1aaf9b16120fb8 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: net_db.cc,v 1.58 1998/01/06 22:44:03 wessels Exp $
+ * $Id: net_db.cc,v 1.59 1998/01/09 08:06:32 wessels Exp $
  *
  * DEBUG: section 37    Network Measurement Database
  * AUTHOR: Duane Wessels
@@ -96,14 +96,21 @@ static void
 netdbHashUnlink(const char *key)
 {
     netdbEntry *n;
+    net_db_name *x;
+    net_db_name **X;
     hash_link *hptr = hash_lookup(host_table, key);
-    if (hptr == NULL) {
-       debug_trap("netdbHashUnlink: key not found");
-       return;
-    }
+    assert(hptr != NULL);
     n = (netdbEntry *) hptr->item;
-    n->link_count--;
+    for (X = &n->hosts; (x = *X) != NULL; X = &x->next) {
+       if (strcmp(x->name, key) == 0)
+           break;
+    }
+    assert(x != NULL);
+    *X = x->next;
+    safe_free(x->name);
+    safe_free(x);
     hash_delete_link(host_table, hptr);
+    n->link_count--;
     meta_data.netdb_hosts--;
 }
 
@@ -163,7 +170,7 @@ netdbPurgeLRU(void)
        assert(list_count < meta_data.netdb_addrs);
        *(list + list_count) = n;
        list_count++;
-        n = (netdbEntry *) hash_next(addr_table);
+       n = (netdbEntry *) hash_next(addr_table);
     }
     qsort((char *) list,
        list_count,
@@ -205,14 +212,27 @@ netdbSendPing(const ipcache_addrs * ia, void *data)
     struct in_addr addr;
     char *hostname = data;
     netdbEntry *n;
+    netdbEntry *na;
     cbdataUnlock(hostname);
     if (ia == NULL) {
        cbdataFree(hostname);
        return;
     }
     addr = ia->in_addrs[ia->cur];
-    if ((n = netdbLookupHost(hostname)) == NULL)
+    if ((n = netdbLookupHost(hostname)) == NULL) {
        n = netdbAdd(addr, hostname);
+    } else if ((na = netdbLookupAddr(addr)) != n) {
+       /*
+        *hostname moved from 'network n' to 'network na'!
+        */
+       if (na == NULL)
+           na = netdbAdd(addr, hostname);
+       debug(37, 1) ("netdbSendPing: NOTE: %s moved from %s to %s\n",
+           hostname, n->network, na->network);
+       netdbHashUnlink(hostname);
+       netdbHashLink(na, hostname);
+       n = na;
+    }
     debug(37, 3) ("netdbSendPing: pinging %s\n", hostname);
     icmpDomainPing(addr, hostname);
     n->pings_sent++;
@@ -567,7 +587,7 @@ netdbDump(StoreEntry * sentry)
     n = (netdbEntry *) hash_first(addr_table);
     while (n != NULL) {
        *(list + i++) = n;
-        n = (netdbEntry *) hash_next(addr_table);
+       n = (netdbEntry *) hash_next(addr_table);
     }
     if (i != meta_data.netdb_addrs)
        debug(37, 0) ("WARNING: netdb_addrs count off, found %d, expected %d\n",
@@ -686,7 +706,7 @@ var_netdb_entry(struct variable *vp, oid * name, int *length, int exact, int *va
            debug(49, 5) ("snmp var_netdb_entry: yup, a match.\n");
            break;
        }
-       n = hash_next(addr_table);
+       n = (netdbEntry *) hash_next(addr_table);
     }
 #endif
     if (n == NULL)