From 34955934c3028fdbcab33751532daa3534809709 Mon Sep 17 00:00:00 2001 From: "David P. Discher" Date: Tue, 24 Dec 2019 11:38:46 -0800 Subject: [PATCH] DSR did not update, check or invaildate server[x].status when for example taking a real server out of rotation via backlist. Adding some additional debugging statements for testing and verification. --- dsr.c | 20 +++++++++++++++----- pen.c | 7 +++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/dsr.c b/dsr.c index 158f605..56917b8 100644 --- a/dsr.c +++ b/dsr.c @@ -144,6 +144,9 @@ static struct in_addr our_ip_addr; static uint8_t our_hw_addr[6]; +time_t last_hash_rebuild = 0; +extern int blacklist_time; + /* OS specific features */ #ifdef HAVE_LINUX_IF_PACKET_H #include @@ -450,6 +453,7 @@ static int rebuild_hash_index(void) /* finally claim that the hash index is up to date */ server_alg |= ALG_HASH_VALID; + last_hash_rebuild = now; free(s); return 1; } @@ -470,6 +474,7 @@ static int select_server(struct in_addr *a, uint16_t port) int h = hash(a, port); int i; if ((server_alg & ALG_HASH_VALID) == 0) { + DEBUG(2, "select_server : rebuilding hash"); if (!rebuild_hash_index()) return NO_SERVER; /* failure */ } i = hash_index[h]; @@ -622,17 +627,22 @@ void dsr_arp(int fd) DEBUG(2, "dsr_arp(%d)", fd); since = now-last_arp; - DEBUG(2, "%d seconds since last update", since); + DEBUG(2, "dsr_arp() %d seconds since last update", since); + DEBUG(2, "dsr_arp() %d seconds since last rebuilt", now - last_hash_rebuild); + if ( ( last_hash_rebuild == 0 ) || (now - last_hash_rebuild > blacklist_time) ) { + server_alg ^= ALG_HASH_VALID; + DEBUG(2, "dsr_arp() : invalidating hash" ); + } if (since) { - DEBUG(2, "Going through the server list"); + DEBUG(2, "dsr_arp(): Going through the server list"); for (server = 0; server < nservers; server++) { - DEBUG(2, "Checking server %d", server); + DEBUG(2, "dsr_arp(): Checking server %d", server); if (unused_server_slot(server)) { - DEBUG(2, "Server slot %d is unused", server); + DEBUG(2, "dsr_arp(): Server slot %d is unused", server); continue; } if (real_hw_known(server) && since < 60) { - DEBUG(2, "Server %d hw address is known", server); + DEBUG(2, "dsr_arp(): Server %d hw address is known", server); continue; } si = (struct sockaddr_in *)&servers[server].addr; diff --git a/pen.c b/pen.c index 9102234..f3ab577 100644 --- a/pen.c +++ b/pen.c @@ -1504,6 +1504,13 @@ static void do_cmd(char *b, void (*output)(void *, char *, ...), void *op) servers[n].prio = atoi(q); } } + if (dsr_if) { + // if dsr, invalid the hash table, otherwise + // these settings never take effect. + server_alg ^= ALG_HASH_VALID; + DEBUG(2, "do_cmd() - if dsr_if - invalidating hash"); + } + } else if (!strcmp(p, "servers")) { for (n = 0; n < nservers; n++) { output(op,