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.
diff --git a/src/dns.c b/src/dns.c
index 0193f73..cab1ad3 100644
--- a/src/dns.c
+++ b/src/dns.c
@@ -895,14 +895,14 @@
*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 @@
*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 @@
*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;
}
/*