Browse code

core: dns cache - option to set local ttl to overwrite the global value

Daniel-Constantin Mierla authored on 09/04/2022 13:36:32
Showing 2 changed files
... ...
@@ -88,12 +88,15 @@ struct t_dns_cache_stats* dns_cache_stats=0;
88 88
 #define LOCK_DNS_HASH()		lock_get(dns_hash_lock)
89 89
 #define UNLOCK_DNS_HASH()	lock_release(dns_hash_lock)
90 90
 
91
+static int _dns_local_ttl = 0;
92
+
91 93
 #define FIX_TTL(t) \
92
-	(((t)<cfg_get(core, core_cfg, dns_cache_min_ttl))? \
93
-		cfg_get(core, core_cfg, dns_cache_min_ttl): \
94
-		(((t)>cfg_get(core, core_cfg, dns_cache_max_ttl))? \
95
-			cfg_get(core, core_cfg, dns_cache_max_ttl): \
96
-			(t)))
94
+	((_dns_local_ttl>0)?_dns_local_ttl: \
95
+		(((t)<cfg_get(core, core_cfg, dns_cache_min_ttl))? \
96
+			cfg_get(core, core_cfg, dns_cache_min_ttl): \
97
+				(((t)>cfg_get(core, core_cfg, dns_cache_max_ttl))? \
98
+					cfg_get(core, core_cfg, dns_cache_max_ttl): \
99
+						(t))))
97 100
 
98 101
 
99 102
 struct dns_hash_head{
... ...
@@ -132,6 +135,10 @@ static const char* dns_str_errors[]={
132 135
 };
133 136
 
134 137
 
138
+void dns_set_local_ttl(int ttl)
139
+{
140
+	_dns_local_ttl = ttl;
141
+}
135 142
 
136 143
 /* param: err (negative error number) */
137 144
 const char* dns_strerror(int err)
... ...
@@ -374,5 +374,6 @@ int dns_cache_delete_single_record(unsigned short type,
374 374
 			str *value,
375 375
 			int flags);
376 376
 
377
+void dns_set_local_ttl(int ttl);
377 378
 
378 379
 #endif