From 8ea0bcc911809e77560bdd937c02a0b832526ef7 Mon Sep 17 00:00:00 2001 From: Baptiste Assmann Date: Thu, 4 May 2017 08:24:11 +0200 Subject: [PATCH] MINOR: dns: introduce roundrobin into the internal cache (WIP) This patch introduces a bit of roundrobin in the records stored in our local cache. Purpose is to allow some kind of distribution of the IPs found in a response. Note that distribution properly applies only when the IP used by many requesters disappear and is replaced by an other one. --- src/dns.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/dns.c b/src/dns.c index 0193f7396..cab1ad30b 100644 --- a/src/dns.c +++ b/src/dns.c @@ -895,14 +895,14 @@ int dns_get_ip_from_response(struct dns_response_packet *dns_p, *newip_sin_family = AF_INET; if (currentip_found == 1) return DNS_UPD_NO; - return DNS_UPD_SRVIP_NOT_FOUND; + goto return_DNS_UPD_SRVIP_NOT_FOUND; } else if (newip6) { *newip = newip6; *newip_sin_family = AF_INET6; if (currentip_found == 1) return DNS_UPD_NO; - return DNS_UPD_SRVIP_NOT_FOUND; + goto return_DNS_UPD_SRVIP_NOT_FOUND; } } /* case when the caller looks first for an IPv6 address */ @@ -912,14 +912,14 @@ int dns_get_ip_from_response(struct dns_response_packet *dns_p, *newip_sin_family = AF_INET6; if (currentip_found == 1) return DNS_UPD_NO; - return DNS_UPD_SRVIP_NOT_FOUND; + goto return_DNS_UPD_SRVIP_NOT_FOUND; } else if (newip4) { *newip = newip4; *newip_sin_family = AF_INET; if (currentip_found == 1) return DNS_UPD_NO; - return DNS_UPD_SRVIP_NOT_FOUND; + goto return_DNS_UPD_SRVIP_NOT_FOUND; } } /* case when the caller have no preference (we prefer IPv6) */ @@ -929,19 +929,30 @@ int dns_get_ip_from_response(struct dns_response_packet *dns_p, *newip_sin_family = AF_INET6; if (currentip_found == 1) return DNS_UPD_NO; - return DNS_UPD_SRVIP_NOT_FOUND; + goto return_DNS_UPD_SRVIP_NOT_FOUND; } else if (newip4) { *newip = newip4; *newip_sin_family = AF_INET; if (currentip_found == 1) return DNS_UPD_NO; - return DNS_UPD_SRVIP_NOT_FOUND; + goto return_DNS_UPD_SRVIP_NOT_FOUND; } } /* no reason why we should change the server's IP address */ return DNS_UPD_NO; + + return_DNS_UPD_SRVIP_NOT_FOUND: + list_for_each_entry(record, &dns_p->answer_list, list) { + /* move the first record to the end of the list, for internal round robin */ + if (record) { + LIST_DEL(&record->list); + LIST_ADDQ(&dns_p->answer_list, &record->list); + break; + } + } + return DNS_UPD_SRVIP_NOT_FOUND; } /*