Module: kamailio
Branch: master
Commit: 06d583e356351ae9d8a559c9f5de3e57fb128a38
URL:
https://github.com/kamailio/kamailio/commit/06d583e356351ae9d8a559c9f5de3e5…
Author: Xenofon Karamanos <22965395+xkaraman(a)users.noreply.github.com>
Committer: Xenofon Karamanos <22965395+xkaraman(a)users.noreply.github.com>
Date: 2024-06-04T12:41:58+03:00
core/resolve: Check dns_cache_init and choose appropriate functions
---
Modified: src/core/resolve.c
Modified: src/core/resolve.h
---
Diff:
https://github.com/kamailio/kamailio/commit/06d583e356351ae9d8a559c9f5de3e5…
Patch:
https://github.com/kamailio/kamailio/commit/06d583e356351ae9d8a559c9f5de3e5…
---
diff --git a/src/core/resolve.c b/src/core/resolve.c
index 6d581f4915f..da247952fd9 100644
--- a/src/core/resolve.c
+++ b/src/core/resolve.c
@@ -1623,7 +1623,11 @@ struct hostent *no_naptr_srv_sip_resolvehost(
srv_name.s = tmp_srv;
srv_name.len = strlen(tmp_srv);
#ifdef USE_DNS_CACHE
- he = dns_srv_get_he(&srv_name, port, dns_flags);
+ if(dns_cache_init) {
+ he = dns_srv_get_he(&srv_name, port, dns_flags);
+ } else {
+ he = srv_sip_resolvehost(&srv_name, 0, port, proto, 1, 0);
+ }
#else
he = srv_sip_resolvehost(&srv_name, 0, port, proto, 1, 0);
#endif
@@ -1660,6 +1664,7 @@ struct hostent *naptr_sip_resolvehost(
struct rdata *naptr_head;
char n_proto;
str srv_name;
+ str *name_copy = 0;
naptr_bmp_t tried_bmp; /* tried bitmap */
char origproto = PROTO_NONE;
@@ -1704,7 +1709,15 @@ struct hostent *naptr_sip_resolvehost(
he = no_naptr_srv_sip_resolvehost(name, port, proto);
/* fallback all the way down to A/AAAA */
if(he == 0) {
- he = dns_get_he(name, dns_flags);
+ if(dns_cache_init) {
+ he = dns_get_he(name, dns_flags);
+ } else {
+ /* We need a zero terminated char* */
+ name_copy = shm_malloc(name->len + 1);
+ shm_str_dup(name_copy, name);
+ he = resolvehost(name_copy->s);
+ shm_free(name_copy);
+ }
}
end:
if(naptr_head)
@@ -1833,6 +1846,45 @@ ip_addr_t *str2ip(str *st)
return ipb;
}
+/*
+* Resolve a host name to a hostent.
+* @param[in] name: the host name to resolve
+* @return the hostent structure or NULL on error
+*
+* @note
+* This function is a wrapper to choose between the DNS cache and the
+* system resolver. If the DNS cache is enabled, it will use the DNS cache
+* to resolve the host name. Otherwise, it will use the system resolver.
+*/
+struct hostent *__resolvehost(char *name)
+{
+ if(dns_cache_init) {
+ return dns_resolvehost(name);
+ } else {
+ return _resolvehost(name);
+ }
+}
+
+/*
+* Resolve a host name to a hostent.
+* @param[in] name: the host name to resolve
+* @param[in] port: the port number
+* @param[in] proto: the protocol
+* @return the hostent structure or NULL on error
+*
+* @note
+* This function is a wrapper to choose between the DNS cache and the
+* system resolver. If the DNS cache is enabled, it will use the DNS cache
+* to resolve the host name. Otherwise, it will use the system resolver.
+*/
+struct hostent *__sip_resolvehost(str *name, unsigned short *port, char *proto)
+{
+ if(dns_cache_init) {
+ return dns_sip_resolvehost(name, port, proto);
+ } else {
+ return _sip_resolvehost(name, port, proto);
+ }
+}
/* converts a str to an ipv6 address struct stored in ipb
* - ipb must be already allocated
* - return 0 on success; <0 on failure */
diff --git a/src/core/resolve.h b/src/core/resolve.h
index c39d90c2104..0e66a7b4ae0 100644
--- a/src/core/resolve.h
+++ b/src/core/resolve.h
@@ -329,14 +329,14 @@ int sip_hostport2su(
union sockaddr_union *su, str *host, unsigned short port, char *proto);
+/* Wrapper functions that check for dns_cache_init */
+struct hostent *__resolvehost(char *name);
+struct hostent *__sip_resolvehost(str *name, unsigned short *port, char *proto);
+
+
/* wrappers */
-#ifdef USE_DNS_CACHE
-#define resolvehost dns_resolvehost
-#define sip_resolvehost dns_sip_resolvehost
-#else
-#define resolvehost _resolvehost
-#define sip_resolvehost _sip_resolvehost
-#endif
+#define resolvehost __resolvehost
+#define sip_resolvehost __sip_resolvehost
#ifdef USE_NAPTR