Module: kamailio
Branch: master
Commit: 0846ddd9eb79eeb0f93535ad65c75670f026941b
URL:
https://github.com/kamailio/kamailio/commit/0846ddd9eb79eeb0f93535ad65c7567…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2022-04-09T15:36:32+02:00
core: dns cache - option to set local ttl to overwrite the global value
---
Modified: src/core/dns_cache.c
Modified: src/core/dns_cache.h
---
Diff:
https://github.com/kamailio/kamailio/commit/0846ddd9eb79eeb0f93535ad65c7567…
Patch:
https://github.com/kamailio/kamailio/commit/0846ddd9eb79eeb0f93535ad65c7567…
---
diff --git a/src/core/dns_cache.c b/src/core/dns_cache.c
index 58247265eb..d6826f0707 100644
--- a/src/core/dns_cache.c
+++ b/src/core/dns_cache.c
@@ -88,12 +88,15 @@ struct t_dns_cache_stats* dns_cache_stats=0;
#define LOCK_DNS_HASH() lock_get(dns_hash_lock)
#define UNLOCK_DNS_HASH() lock_release(dns_hash_lock)
+static int _dns_local_ttl = 0;
+
#define FIX_TTL(t) \
- (((t)<cfg_get(core, core_cfg, dns_cache_min_ttl))? \
- cfg_get(core, core_cfg, dns_cache_min_ttl): \
- (((t)>cfg_get(core, core_cfg, dns_cache_max_ttl))? \
- cfg_get(core, core_cfg, dns_cache_max_ttl): \
- (t)))
+ ((_dns_local_ttl>0)?_dns_local_ttl: \
+ (((t)<cfg_get(core, core_cfg, dns_cache_min_ttl))? \
+ cfg_get(core, core_cfg, dns_cache_min_ttl): \
+ (((t)>cfg_get(core, core_cfg, dns_cache_max_ttl))? \
+ cfg_get(core, core_cfg, dns_cache_max_ttl): \
+ (t))))
struct dns_hash_head{
@@ -132,6 +135,10 @@ static const char* dns_str_errors[]={
};
+void dns_set_local_ttl(int ttl)
+{
+ _dns_local_ttl = ttl;
+}
/* param: err (negative error number) */
const char* dns_strerror(int err)
diff --git a/src/core/dns_cache.h b/src/core/dns_cache.h
index 0ec919f2d2..f8ae153a30 100644
--- a/src/core/dns_cache.h
+++ b/src/core/dns_cache.h
@@ -374,5 +374,6 @@ int dns_cache_delete_single_record(unsigned short type,
str *value,
int flags);
+void dns_set_local_ttl(int ttl);
#endif