diff options
author | Joshua Colp <jcolp@digium.com> | 2015-08-25 09:17:34 -0300 |
---|---|---|
committer | Joshua Colp <jcolp@digium.com> | 2015-08-25 13:55:33 -0300 |
commit | d013ecf7486ad4a04d8ccb52340c5e62bb44b6f6 (patch) | |
tree | 2269da22459b95fc71e10faf182430ae47187478 /res/res_pjsip_multihomed.c | |
parent | 6b8734fe6890dfa4754b07eceaab52a4712297a9 (diff) |
res_pjsip: Add common ast_sip_get_host_ip API.
Modules commonly used the pj_gethostip function for retrieving the
IP address of the host. This function does not cache the result and may
result in a DNS lookup occurring, or additional work. If the DNS
server is unreachable or network issues arise this can cause the
pj_gethostip function to block for a period of time.
This change adds an ast_sip_get_host_ip and ast_sip_get_host_ip_string
function which does the same thing but caches the host IP address at
module load time. This results in no additional work being done each
time the local host IP address is needed.
ASTERISK-25342 #close
Change-Id: I3205deb679b01fa5ac05a94b623bfd620a2abe1e
Diffstat (limited to 'res/res_pjsip_multihomed.c')
-rw-r--r-- | res/res_pjsip_multihomed.c | 23 |
1 files changed, 4 insertions, 19 deletions
diff --git a/res/res_pjsip_multihomed.c b/res/res_pjsip_multihomed.c index 68a431153..7062fc60b 100644 --- a/res/res_pjsip_multihomed.c +++ b/res/res_pjsip_multihomed.c @@ -30,12 +30,6 @@ #include "asterisk/res_pjsip.h" #include "asterisk/module.h" -/*! \brief Local host address for IPv4 */ -static char host_ipv4[PJ_INET_ADDRSTRLEN + 2]; - -/*! \brief Local host address for IPv6 */ -static char host_ipv6[PJ_INET6_ADDRSTRLEN + 2]; - /*! \brief Helper function which returns a UDP transport bound to the given address and port */ static pjsip_transport *multihomed_get_udp_transport(pj_str_t *address, int port) { @@ -75,8 +69,10 @@ static int multihomed_rewrite_sdp(struct pjmedia_sdp_session *sdp) } /* If the host address is used in the SDP replace it with the address of what this is going out on */ - if ((!pj_strcmp2(&sdp->conn->addr_type, "IP4") && !pj_strcmp2(&sdp->conn->addr, host_ipv4)) || - (!pj_strcmp2(&sdp->conn->addr_type, "IP6") && !pj_strcmp2(&sdp->conn->addr, host_ipv6))) { + if ((!pj_strcmp2(&sdp->conn->addr_type, "IP4") && !pj_strcmp2(&sdp->conn->addr, + ast_sip_get_host_ip_string(pj_AF_INET()))) || + (!pj_strcmp2(&sdp->conn->addr_type, "IP6") && !pj_strcmp2(&sdp->conn->addr, + ast_sip_get_host_ip_string(pj_AF_INET6())))) { return 1; } @@ -204,7 +200,6 @@ static int unload_module(void) static int load_module(void) { char hostname[MAXHOSTNAMELEN] = ""; - pj_sockaddr addr; CHECK_PJSIP_MODULE_LOADED(); @@ -213,16 +208,6 @@ static int load_module(void) hostname); } - if (!pj_gethostip(pj_AF_INET(), &addr)) { - pj_sockaddr_print(&addr, host_ipv4, sizeof(host_ipv4), 2); - ast_verb(3, "Local IPv4 address determined to be: %s\n", host_ipv4); - } - - if (!pj_gethostip(pj_AF_INET6(), &addr)) { - pj_sockaddr_print(&addr, host_ipv6, sizeof(host_ipv6), 2); - ast_verb(3, "Local IPv6 address determined to be: %s\n", host_ipv6); - } - if (ast_sip_register_service(&multihomed_module)) { ast_log(LOG_ERROR, "Could not register multihomed module for incoming and outgoing requests\n"); return AST_MODULE_LOAD_FAILURE; |