mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-13 16:21:01 +00:00
Merge "res_pjsip: Add common ast_sip_get_host_ip API." into 13
This commit is contained in:
@@ -2071,4 +2071,31 @@ unsigned int ast_sip_get_max_initial_qualify_time(void);
|
|||||||
const char *ast_sip_get_contact_status_label(const enum ast_sip_contact_status_type status);
|
const char *ast_sip_get_contact_status_label(const enum ast_sip_contact_status_type status);
|
||||||
const char *ast_sip_get_contact_short_status_label(const enum ast_sip_contact_status_type status);
|
const char *ast_sip_get_contact_short_status_label(const enum ast_sip_contact_status_type status);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Retrieve the local host address in IP form
|
||||||
|
*
|
||||||
|
* \param af The address family to retrieve
|
||||||
|
* \param addr A place to store the local host address
|
||||||
|
*
|
||||||
|
* \retval 0 success
|
||||||
|
* \retval -1 failure
|
||||||
|
*
|
||||||
|
* \since 13.6.0
|
||||||
|
*/
|
||||||
|
int ast_sip_get_host_ip(int af, pj_sockaddr *addr);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Retrieve the local host address in string form
|
||||||
|
*
|
||||||
|
* \param af The address family to retrieve
|
||||||
|
*
|
||||||
|
* \retval non-NULL success
|
||||||
|
* \retval NULL failure
|
||||||
|
*
|
||||||
|
* \since 13.6.0
|
||||||
|
*
|
||||||
|
* \note An empty string may be returned if the address family is valid but no local address exists
|
||||||
|
*/
|
||||||
|
const char *ast_sip_get_host_ip_string(int af);
|
||||||
|
|
||||||
#endif /* _RES_PJSIP_H */
|
#endif /* _RES_PJSIP_H */
|
||||||
|
@@ -1906,6 +1906,18 @@ static pjsip_endpoint *ast_pjsip_endpoint;
|
|||||||
|
|
||||||
static struct ast_threadpool *sip_threadpool;
|
static struct ast_threadpool *sip_threadpool;
|
||||||
|
|
||||||
|
/*! Local host address for IPv4 */
|
||||||
|
static pj_sockaddr host_ip_ipv4;
|
||||||
|
|
||||||
|
/*! Local host address for IPv4 (string form) */
|
||||||
|
static char host_ip_ipv4_string[PJ_INET6_ADDRSTRLEN + 2];
|
||||||
|
|
||||||
|
/*! Local host address for IPv6 */
|
||||||
|
static pj_sockaddr host_ip_ipv6;
|
||||||
|
|
||||||
|
/*! Local host address for IPv6 (string form) */
|
||||||
|
static char host_ip_ipv6_string[PJ_INET6_ADDRSTRLEN + 2];
|
||||||
|
|
||||||
static int register_service_noref(void *data)
|
static int register_service_noref(void *data)
|
||||||
{
|
{
|
||||||
pjsip_module **module = data;
|
pjsip_module **module = data;
|
||||||
@@ -3697,6 +3709,30 @@ int ast_sip_create_response(const pjsip_rx_data *rdata, int st_code,
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ast_sip_get_host_ip(int af, pj_sockaddr *addr)
|
||||||
|
{
|
||||||
|
if (af == pj_AF_INET() && !ast_strlen_zero(host_ip_ipv4_string)) {
|
||||||
|
pj_sockaddr_copy_addr(addr, &host_ip_ipv4);
|
||||||
|
return 0;
|
||||||
|
} else if (af == pj_AF_INET6() && !ast_strlen_zero(host_ip_ipv6_string)) {
|
||||||
|
pj_sockaddr_copy_addr(addr, &host_ip_ipv6);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *ast_sip_get_host_ip_string(int af)
|
||||||
|
{
|
||||||
|
if (af == pj_AF_INET()) {
|
||||||
|
return host_ip_ipv4_string;
|
||||||
|
} else if (af == pj_AF_INET6()) {
|
||||||
|
return host_ip_ipv6_string;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static void remove_request_headers(pjsip_endpoint *endpt)
|
static void remove_request_headers(pjsip_endpoint *endpt)
|
||||||
{
|
{
|
||||||
const pjsip_hdr *request_headers = pjsip_endpt_get_request_headers(endpt);
|
const pjsip_hdr *request_headers = pjsip_endpt_get_request_headers(endpt);
|
||||||
@@ -3811,6 +3847,16 @@ static int load_module(void)
|
|||||||
return AST_MODULE_LOAD_DECLINE;
|
return AST_MODULE_LOAD_DECLINE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!pj_gethostip(pj_AF_INET(), &host_ip_ipv4)) {
|
||||||
|
pj_sockaddr_print(&host_ip_ipv4, host_ip_ipv4_string, sizeof(host_ip_ipv4_string), 2);
|
||||||
|
ast_verb(3, "Local IPv4 address determined to be: %s\n", host_ip_ipv4_string);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!pj_gethostip(pj_AF_INET6(), &host_ip_ipv6)) {
|
||||||
|
pj_sockaddr_print(&host_ip_ipv6, host_ip_ipv6_string, sizeof(host_ip_ipv6_string), 2);
|
||||||
|
ast_verb(3, "Local IPv6 address determined to be: %s\n", host_ip_ipv6_string);
|
||||||
|
}
|
||||||
|
|
||||||
if (ast_sip_initialize_system()) {
|
if (ast_sip_initialize_system()) {
|
||||||
ast_log(LOG_ERROR, "Failed to initialize SIP 'system' configuration section. Aborting load\n");
|
ast_log(LOG_ERROR, "Failed to initialize SIP 'system' configuration section. Aborting load\n");
|
||||||
pj_pool_release(memory_pool);
|
pj_pool_release(memory_pool);
|
||||||
|
@@ -30,12 +30,6 @@
|
|||||||
#include "asterisk/res_pjsip.h"
|
#include "asterisk/res_pjsip.h"
|
||||||
#include "asterisk/module.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 */
|
/*! \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)
|
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 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)) ||
|
if ((!pj_strcmp2(&sdp->conn->addr_type, "IP4") && !pj_strcmp2(&sdp->conn->addr,
|
||||||
(!pj_strcmp2(&sdp->conn->addr_type, "IP6") && !pj_strcmp2(&sdp->conn->addr, host_ipv6))) {
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,7 +200,6 @@ static int unload_module(void)
|
|||||||
static int load_module(void)
|
static int load_module(void)
|
||||||
{
|
{
|
||||||
char hostname[MAXHOSTNAMELEN] = "";
|
char hostname[MAXHOSTNAMELEN] = "";
|
||||||
pj_sockaddr addr;
|
|
||||||
|
|
||||||
CHECK_PJSIP_MODULE_LOADED();
|
CHECK_PJSIP_MODULE_LOADED();
|
||||||
|
|
||||||
@@ -213,16 +208,6 @@ static int load_module(void)
|
|||||||
hostname);
|
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)) {
|
if (ast_sip_register_service(&multihomed_module)) {
|
||||||
ast_log(LOG_ERROR, "Could not register multihomed module for incoming and outgoing requests\n");
|
ast_log(LOG_ERROR, "Could not register multihomed module for incoming and outgoing requests\n");
|
||||||
return AST_MODULE_LOAD_FAILURE;
|
return AST_MODULE_LOAD_FAILURE;
|
||||||
|
@@ -1026,7 +1026,7 @@ static int create_outgoing_sdp_stream(struct ast_sip_session *session, struct as
|
|||||||
static const pj_str_t STR_IP6 = { "IP6", 3};
|
static const pj_str_t STR_IP6 = { "IP6", 3};
|
||||||
static const pj_str_t STR_SENDRECV = { "sendrecv", 8 };
|
static const pj_str_t STR_SENDRECV = { "sendrecv", 8 };
|
||||||
pjmedia_sdp_media *media;
|
pjmedia_sdp_media *media;
|
||||||
char hostip[PJ_INET6_ADDRSTRLEN+2];
|
const char *hostip = NULL;
|
||||||
struct ast_sockaddr addr;
|
struct ast_sockaddr addr;
|
||||||
char tmp[512];
|
char tmp[512];
|
||||||
pj_str_t stmp;
|
pj_str_t stmp;
|
||||||
@@ -1074,16 +1074,16 @@ static int create_outgoing_sdp_stream(struct ast_sip_session *session, struct as
|
|||||||
|
|
||||||
/* Add connection level details */
|
/* Add connection level details */
|
||||||
if (direct_media_enabled) {
|
if (direct_media_enabled) {
|
||||||
ast_copy_string(hostip, ast_sockaddr_stringify_fmt(&session_media->direct_media_addr, AST_SOCKADDR_STR_ADDR), sizeof(hostip));
|
hostip = ast_sockaddr_stringify_fmt(&session_media->direct_media_addr, AST_SOCKADDR_STR_ADDR);
|
||||||
} else if (ast_strlen_zero(session->endpoint->media.address)) {
|
} else if (ast_strlen_zero(session->endpoint->media.address)) {
|
||||||
pj_sockaddr localaddr;
|
hostip = ast_sip_get_host_ip_string(session->endpoint->media.rtp.ipv6 ? pj_AF_INET6() : pj_AF_INET());
|
||||||
|
|
||||||
if (pj_gethostip(session->endpoint->media.rtp.ipv6 ? pj_AF_INET6() : pj_AF_INET(), &localaddr)) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
pj_sockaddr_print(&localaddr, hostip, sizeof(hostip), 2);
|
|
||||||
} else {
|
} else {
|
||||||
ast_copy_string(hostip, session->endpoint->media.address, sizeof(hostip));
|
hostip = session->endpoint->media.address;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ast_strlen_zero(hostip)) {
|
||||||
|
ast_log(LOG_ERROR, "No local host IP available for stream %s\n", session_media->stream_type);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
media->conn->net_type = STR_IN;
|
media->conn->net_type = STR_IN;
|
||||||
|
@@ -2643,12 +2643,7 @@ static struct pjmedia_sdp_session *create_local_sdp(pjsip_inv_session *inv, stru
|
|||||||
if (!ast_strlen_zero(session->endpoint->media.address)) {
|
if (!ast_strlen_zero(session->endpoint->media.address)) {
|
||||||
pj_strdup2(inv->pool_prov, &local->origin.addr, session->endpoint->media.address);
|
pj_strdup2(inv->pool_prov, &local->origin.addr, session->endpoint->media.address);
|
||||||
} else {
|
} else {
|
||||||
pj_sockaddr localaddr;
|
pj_strdup2(inv->pool_prov, &local->origin.addr, ast_sip_get_host_ip_string(session->endpoint->media.rtp.ipv6 ? pj_AF_INET6() : pj_AF_INET()));
|
||||||
char our_ip[PJ_INET6_ADDRSTRLEN];
|
|
||||||
|
|
||||||
pj_gethostip(session->endpoint->media.rtp.ipv6 ? pj_AF_INET6() : pj_AF_INET(), &localaddr);
|
|
||||||
pj_sockaddr_print(&localaddr, our_ip, sizeof(our_ip), 0);
|
|
||||||
pj_strdup2(inv->pool_prov, &local->origin.addr, our_ip);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -707,7 +707,7 @@ static int create_outgoing_sdp_stream(struct ast_sip_session *session, struct as
|
|||||||
static const pj_str_t STR_T38UDPREDUNDANCY = { "t38UDPRedundancy", 16 };
|
static const pj_str_t STR_T38UDPREDUNDANCY = { "t38UDPRedundancy", 16 };
|
||||||
struct t38_state *state;
|
struct t38_state *state;
|
||||||
pjmedia_sdp_media *media;
|
pjmedia_sdp_media *media;
|
||||||
char hostip[PJ_INET6_ADDRSTRLEN+2];
|
const char *hostip = NULL;
|
||||||
struct ast_sockaddr addr;
|
struct ast_sockaddr addr;
|
||||||
char tmp[512];
|
char tmp[512];
|
||||||
pj_str_t stmp;
|
pj_str_t stmp;
|
||||||
@@ -732,14 +732,13 @@ static int create_outgoing_sdp_stream(struct ast_sip_session *session, struct as
|
|||||||
media->desc.transport = STR_UDPTL;
|
media->desc.transport = STR_UDPTL;
|
||||||
|
|
||||||
if (ast_strlen_zero(session->endpoint->media.address)) {
|
if (ast_strlen_zero(session->endpoint->media.address)) {
|
||||||
pj_sockaddr localaddr;
|
hostip = ast_sip_get_host_ip_string(session->endpoint->media.t38.ipv6 ? pj_AF_INET6() : pj_AF_INET());
|
||||||
|
|
||||||
if (pj_gethostip(session->endpoint->media.t38.ipv6 ? pj_AF_INET6() : pj_AF_INET(), &localaddr)) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
pj_sockaddr_print(&localaddr, hostip, sizeof(hostip), 2);
|
|
||||||
} else {
|
} else {
|
||||||
ast_copy_string(hostip, session->endpoint->media.address, sizeof(hostip));
|
hostip = session->endpoint->media.address;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ast_strlen_zero(hostip)) {
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
media->conn->net_type = STR_IN;
|
media->conn->net_type = STR_IN;
|
||||||
|
Reference in New Issue
Block a user