diff options
author | Mark Michelson <mmichelson@digium.com> | 2014-08-21 21:43:45 +0000 |
---|---|---|
committer | Mark Michelson <mmichelson@digium.com> | 2014-08-21 21:43:45 +0000 |
commit | 644e693645cad8c31c96defc3945532da7497fc8 (patch) | |
tree | d8c77871a2ee8a1945f871d4bbd5d356d1d701c8 | |
parent | 56a1d4930a7d41c545b951f66f913cf133681086 (diff) |
Switch from hostname to an IP address in the SDP origin line.
Using the hostname in the SDP origin line may not satisfy the requirement
of RFC 4566 that we use a FQDN or IP address. This change has us use the
same information from the SDP connection line if possible. If not possible,
we'll use the configured media address. And if that's not possible, we use
the result of a PJLIB call to get the IP address of ourself.
ASTERISK-23994 #close
Reported by Private Name
Review: https://reviewboard.asterisk.org/r/3925
........
Merged revisions 421796 from http://svn.asterisk.org/svn/asterisk/branches/12
........
Merged revisions 421797 from http://svn.asterisk.org/svn/asterisk/branches/13
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@421798 65c4cc65-6c06-0410-ace0-fbb531ad65f3
-rw-r--r-- | res/res_pjsip_session.c | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c index b85b457c7..c26693f18 100644 --- a/res/res_pjsip_session.c +++ b/res/res_pjsip_session.c @@ -51,9 +51,6 @@ #define MOD_DATA_ON_RESPONSE "on_response" #define MOD_DATA_NAT_HOOK "nat_hook" -/* Hostname used for origin line within SDP */ -static const pj_str_t *hostname; - /* Some forward declarations */ static void handle_incoming_request(struct ast_sip_session *session, pjsip_rx_data *rdata, pjsip_event_id_e type); static void handle_incoming_response(struct ast_sip_session *session, pjsip_rx_data *rdata, pjsip_event_id_e type); @@ -2094,9 +2091,6 @@ static struct pjmedia_sdp_session *create_local_sdp(pjsip_inv_session *inv, stru } pj_strdup2(inv->pool, &local->origin.user, session->endpoint->media.sdpowner); - local->origin.net_type = STR_IN; - local->origin.addr_type = session->endpoint->media.rtp.ipv6 ? STR_IP6 : STR_IP4; - local->origin.addr = *hostname; pj_strdup2(inv->pool, &local->name, session->endpoint->media.sdpsession); /* Now let the handlers add streams of various types, pjmedia will automatically reorder the media streams for us */ @@ -2109,6 +2103,23 @@ static struct pjmedia_sdp_session *create_local_sdp(pjsip_inv_session *inv, stru /* Use the connection details of the first media stream if possible for SDP level */ if (local->media_count) { local->conn = local->media[0]->conn; + pj_strassign(&local->origin.net_type, &local->conn->net_type); + pj_strassign(&local->origin.addr_type, &local->conn->addr_type); + pj_strassign(&local->origin.addr, &local->conn->addr); + } else { + local->origin.net_type = STR_IN; + local->origin.addr_type = session->endpoint->media.rtp.ipv6 ? STR_IP6 : STR_IP4; + + if (!ast_strlen_zero(session->endpoint->media.address)) { + pj_strdup2(inv->pool, &local->origin.addr, session->endpoint->media.address); + } else { + pj_sockaddr localaddr; + 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, &local->origin.addr, our_ip); + } } return local; @@ -2258,6 +2269,7 @@ static void session_outgoing_nat_hook(pjsip_tx_data *tdata, struct ast_sip_trans static int load_module(void) { pjsip_endpoint *endpt; + if (!ast_sip_get_sorcery() || !ast_sip_get_pjsip_endpoint()) { return AST_MODULE_LOAD_DECLINE; } @@ -2275,7 +2287,6 @@ static int load_module(void) pjsip_inv_usage_init(endpt, &inv_callback); pjsip_100rel_init_module(endpt); pjsip_timer_init_module(endpt); - hostname = pj_gethostname(); if (ast_sip_register_service(&session_module)) { return AST_MODULE_LOAD_DECLINE; } |