Browse code

When searching list of records from dns cache entry which has already expired, use the last valid timestamp when checking expiration time of the records. It can happen when the entry was retrieved just before it expires. It can also expire before the next round of server lookup with SRV failover.

Michal Matyska authored on 15/01/2008 15:14:53
Showing 1 changed files
... ...
@@ -2020,6 +2020,8 @@ struct hostent* dns_entry2he(struct dns_hash_entry* e)
2020 2020
 
2021 2021
 	rr_no=0;
2022 2022
 	now=get_ticks_raw();
2023
+	/* if the entry has already expired use the time at the end of lifetime */
2024
+	if (unlikely((s_ticks_t)(now-e->expire)>=0)) now=e->expire-1;
2023 2025
 	rr=dns_entry_get_rr(e, &rr_no, now);
2024 2026
 	for(i=0; rr && (i<DNS_HE_MAX_ADDR); i++,
2025 2027
 							rr=dns_entry_get_rr(e, &rr_no, now)){
... ...
@@ -2545,6 +2547,8 @@ int dns_a_resolve(struct dns_hash_entry** e, unsigned char* rr_no,
2545 2545
 		ret=-E_DNS_BAD_IP_ENTRY;
2546 2546
 	}
2547 2547
 	now=get_ticks_raw();
2548
+	/* if the entry has already expired use the time at the end of lifetime */
2549
+	if (unlikely((s_ticks_t)(now-(*e)->expire)>=0)) now=(*e)->expire-1;
2548 2550
 	rr=dns_entry_get_rr(*e, rr_no, now);
2549 2551
 	if (rr){
2550 2552
 		/* everything is ok now, we can try to "convert" the ip */
... ...
@@ -2590,6 +2594,8 @@ int dns_aaaa_resolve(struct dns_hash_entry** e, unsigned char* rr_no,
2590 2590
 		ret=-E_DNS_BAD_IP_ENTRY;
2591 2591
 	}
2592 2592
 	now=get_ticks_raw();
2593
+	/* if the entry has already expired use the time at the end of lifetime */
2594
+	if (unlikely((s_ticks_t)(now-(*e)->expire)>=0)) now=(*e)->expire-1;
2593 2595
 	rr=dns_entry_get_rr(*e, rr_no, now);
2594 2596
 	if (rr){
2595 2597
 		/* everything is ok now, we can try to "convert" the ip */
... ...
@@ -2700,6 +2706,8 @@ int dns_srv_resolve_nxt(struct dns_hash_entry** e,
2700 2700
 		ret=-E_DNS_BAD_SRV_ENTRY;
2701 2701
 	}
2702 2702
 	now=get_ticks_raw();
2703
+	/* if the entry has already expired use the time at the end of lifetime */
2704
+	if (unlikely((s_ticks_t)(now-(*e)->expire)>=0)) now=(*e)->expire-1;
2703 2705
 #ifdef DNS_SRV_LB
2704 2706
 	if (tried){
2705 2707
 		rr=dns_srv_get_nxt_rr(*e, tried, rr_no, now);