From: Christopher Faulet Date: Thu, 11 Mar 2021 08:36:05 +0000 (+0100) Subject: MINOR: resolvers: Use milliseconds for cached items in resolver responses X-Git-Tag: v2.3.7~3 X-Git-Url: http://git.haproxy.org/?a=commitdiff_plain;h=8b6d5b0b753594b61ea95c56bcbe93117506fdf0;p=haproxy-2.3.git MINOR: resolvers: Use milliseconds for cached items in resolver responses The last time when an item was seen in a resolver responses is now stored in milliseconds instead of seconds. This avoid some corner-cases at the edges. This also simplifies time comparisons. (cherry picked from commit 55c1c4053f70bf53adfcd5067fa959e20f2b44fe) Signed-off-by: Christopher Faulet --- diff --git a/include/haproxy/dns-t.h b/include/haproxy/dns-t.h index 191edf6..95d4097 100644 --- a/include/haproxy/dns-t.h +++ b/include/haproxy/dns-t.h @@ -147,7 +147,7 @@ struct dns_answer_item { uint16_t data_len; /* number of bytes in target below */ struct sockaddr address; /* IPv4 or IPv6, network format */ char target[DNS_MAX_NAME_SIZE+1]; /* Response data: SRV or CNAME type target */ - time_t last_seen; /* When was the answer was last seen */ + unsigned int last_seen; /* When was the answer was last seen */ struct dns_answer_item *ar_item; /* pointer to a RRset from the additional section, if exists */ struct list list; }; diff --git a/src/dns.c b/src/dns.c index a628c5c..c9ffcf7 100644 --- a/src/dns.c +++ b/src/dns.c @@ -629,7 +629,7 @@ static void dns_check_dns_response(struct dns_resolution *res) struct dns_answer_item *ar_item = item->ar_item; /* clean up obsolete Additional record */ - if (ar_item && (ar_item->last_seen + resolvers->hold.obsolete / 1000) < now.tv_sec) { + if (ar_item && tick_is_lt(tick_add(ar_item->last_seen, resolvers->hold.obsolete), now_ms)) { /* Cleaning up the AR item will trigger an extra DNS resolution, except if the SRV * item is also obsolete. */ @@ -638,7 +638,7 @@ static void dns_check_dns_response(struct dns_resolution *res) } /* Remove obsolete items */ - if ((item->last_seen + resolvers->hold.obsolete / 1000) < now.tv_sec) { + if (tick_is_lt(tick_add(item->last_seen, resolvers->hold.obsolete), now_ms)) { if (item->type != DNS_RTYPE_SRV) goto rm_obselete_item; @@ -953,6 +953,7 @@ static int dns_validate_dns_response(unsigned char *resp, unsigned char *bufend, /* initialization */ dns_answer_record->ar_item = NULL; + dns_answer_record->last_seen = TICK_ETERNITY; offset = 0; len = dns_read_name(resp, bufend, reader, tmpname, DNS_MAX_NAME_SIZE, &offset, 0); @@ -1148,12 +1149,12 @@ static int dns_validate_dns_response(unsigned char *resp, unsigned char *bufend, } if (found == 1) { - tmp_record->last_seen = now.tv_sec; + tmp_record->last_seen = now_ms; pool_free(dns_answer_item_pool, dns_answer_record); dns_answer_record = NULL; } else { - dns_answer_record->last_seen = now.tv_sec; + dns_answer_record->last_seen = now_ms; dns_answer_record->ar_item = NULL; LIST_ADDQ(&dns_p->answer_list, &dns_answer_record->list); dns_answer_record = NULL; @@ -1203,6 +1204,7 @@ static int dns_validate_dns_response(unsigned char *resp, unsigned char *bufend, dns_answer_record = pool_alloc(dns_answer_item_pool); if (dns_answer_record == NULL) goto invalid_resp; + dns_answer_record->last_seen = TICK_ETERNITY; offset = 0; len = dns_read_name(resp, bufend, reader, tmpname, DNS_MAX_NAME_SIZE, &offset, 0); @@ -1329,12 +1331,12 @@ static int dns_validate_dns_response(unsigned char *resp, unsigned char *bufend, } if (found == 1) { - tmp_record->ar_item->last_seen = now.tv_sec; + tmp_record->ar_item->last_seen = now_ms; pool_free(dns_answer_item_pool, dns_answer_record); dns_answer_record = NULL; } else { - dns_answer_record->last_seen = now.tv_sec; + dns_answer_record->last_seen = now_ms; dns_answer_record->ar_item = NULL; // looking for the SRV record in the response list linked to this additional record