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 2547
 		ret=-E_DNS_BAD_IP_ENTRY;
2546 2548
 	}
2547 2549
 	now=get_ticks_raw();
2550
+	/* if the entry has already expired use the time at the end of lifetime */
2551
+	if (unlikely((s_ticks_t)(now-(*e)->expire)>=0)) now=(*e)->expire-1;
2548 2552
 	rr=dns_entry_get_rr(*e, rr_no, now);
2549 2553
 	if (rr){
2550 2554
 		/* 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 2594
 		ret=-E_DNS_BAD_IP_ENTRY;
2591 2595
 	}
2592 2596
 	now=get_ticks_raw();
2597
+	/* if the entry has already expired use the time at the end of lifetime */
2598
+	if (unlikely((s_ticks_t)(now-(*e)->expire)>=0)) now=(*e)->expire-1;
2593 2599
 	rr=dns_entry_get_rr(*e, rr_no, now);
2594 2600
 	if (rr){
2595 2601
 		/* 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 2706
 		ret=-E_DNS_BAD_SRV_ENTRY;
2701 2707
 	}
2702 2708
 	now=get_ticks_raw();
2709
+	/* if the entry has already expired use the time at the end of lifetime */
2710
+	if (unlikely((s_ticks_t)(now-(*e)->expire)>=0)) now=(*e)->expire-1;
2703 2711
 #ifdef DNS_SRV_LB
2704 2712
 	if (tried){
2705 2713
 		rr=dns_srv_get_nxt_rr(*e, tried, rr_no, now);