struct server *owner)
{
struct resolv_answer_item *record, *found_record = NULL;
- struct eb32_node *eb32;
+ struct eb32_node *eb32, *end;
int family_priority;
int currentip_found;
unsigned char *newip4, *newip6;
* 1 - current ip.
* The result with the biggest score is returned.
*/
-
- for (eb32 = eb32_first(&r_res->answer_tree); eb32 != NULL; eb32 = eb32_next(eb32)) {
+ eb32 = (!r_res->next) ? eb32_first(&r_res->answer_tree) : r_res->next;
+ end = r_res->next;
+ r_res->next = eb32_next(eb32); /* get node for the next lookup */
+ do {
void *ip;
unsigned char ip_type;
+ if (eb32 == NULL)
+ eb32 = eb32_first(&r_res->answer_tree);
+
record = eb32_entry(eb32, typeof(*record), link);
if (record->type == DNS_RTYPE_A && (resolv_active_families() & RSLV_ACCEPT_IPV4)) {
ip_type = AF_INET;
ip = &record->data.in6.sin6_addr;
}
else
- continue;
+ goto next;
score = 0;
/* Check for preferred ip protocol. */
/* Compare only the same addresses class. */
if (resolv_opts->pref_net[j].family != ip_type)
- continue;
+ goto next;
if ((ip_type == AF_INET &&
in_net_ipv4(ip,
list_for_each_entry(srv, &record->attached_servers, ip_rec_item) {
if (srv == owner)
- continue;
+ goto next;
if (srv->proxy == owner->proxy) {
already_used = 1;
break;
}
if (already_used) {
if (!allowed_duplicated_ip) {
- continue;
+ goto next;
}
}
else {
}
max_score = score;
}
- } /* list for each record entries */
+ next:
+ eb32 = eb32_next(eb32);
+ } while (eb32 != end); /* list for each record entries */
/* No IP found in the response */
if (!newip4 && !newip6)
LIST_APPEND(&found_record->attached_servers, &owner->ip_rec_item);
}
- eb32 = eb32_first(&r_res->answer_tree);
- if (eb32) {
- /* Move the first record to the end of the list, for internal
- * round robin.
- */
- eb32_delete(eb32);
- eb32_insert(&r_res->answer_tree, eb32);
- }
-
return (currentip_found ? RSLV_UPD_NO : RSLV_UPD_SRVIP_NOT_FOUND);
}
LIST_INIT(&res->requesters);
res->response.answer_tree = EB_ROOT;
+ res->response.next = NULL;
res->prefered_query_type = query_type;
res->query_type = query_type;