diff options
-rw-r--r-- | pjsip/include/pjsua-lib/pjsua.h | 12 | ||||
-rw-r--r-- | pjsip/include/pjsua-lib/pjsua_internal.h | 4 | ||||
-rw-r--r-- | pjsip/src/pjsua-lib/pjsua_acc.c | 14 | ||||
-rw-r--r-- | pjsip/src/pjsua-lib/pjsua_media.c | 17 |
4 files changed, 46 insertions, 1 deletions
diff --git a/pjsip/include/pjsua-lib/pjsua.h b/pjsip/include/pjsua-lib/pjsua.h index 0cc34acc..ef408764 100644 --- a/pjsip/include/pjsua-lib/pjsua.h +++ b/pjsip/include/pjsua-lib/pjsua.h @@ -3031,6 +3031,18 @@ typedef struct pjsua_acc_config pj_bool_t allow_via_rewrite; /** + * This option controls whether the IP address in SDP should be replaced + * with the IP address found in Via header of the REGISTER response, ONLY + * when STUN and ICE are not used. If the value is FALSE (the original + * behavior), then the local IP address will be used. If TRUE, and when + * STUN and ICE are disabled, then the IP address found in registration + * response will be used. + * + * Default: PJ_FALSE (no) + */ + pj_bool_t allow_sdp_nat_rewrite; + + /** * Control the use of SIP outbound feature. SIP outbound is described in * RFC 5626 to enable proxies or registrar to send inbound requests back * to UA using the same connection initiated by the UA for its diff --git a/pjsip/include/pjsua-lib/pjsua_internal.h b/pjsip/include/pjsua-lib/pjsua_internal.h index d1a696ae..d70506eb 100644 --- a/pjsip/include/pjsua-lib/pjsua_internal.h +++ b/pjsip/include/pjsua-lib/pjsua_internal.h @@ -229,6 +229,10 @@ typedef struct pjsua_acc pj_status_t reg_last_err; /**< Last registration error. */ int reg_last_code; /**< Last status last register. */ + pj_str_t reg_mapped_addr;/**< Our addr as seen by reg srv. + Only if allow_sdp_nat_rewrite + is set */ + struct { pj_bool_t active; /**< Flag of reregister status. */ pj_timer_entry timer; /**< Timer for reregistration. */ diff --git a/pjsip/src/pjsua-lib/pjsua_acc.c b/pjsip/src/pjsua-lib/pjsua_acc.c index 19206b19..6a37c41b 100644 --- a/pjsip/src/pjsua-lib/pjsua_acc.c +++ b/pjsip/src/pjsua-lib/pjsua_acc.c @@ -650,6 +650,7 @@ PJ_DEF(pj_status_t) pjsua_acc_del(pjsua_acc_id acc_id) /* Invalidate */ acc->valid = PJ_FALSE; acc->contact.slen = 0; + acc->reg_mapped_addr.slen = 0; pj_bzero(&acc->via_addr, sizeof(acc->via_addr)); acc->via_tp = NULL; acc->next_rtp_port = 0; @@ -1255,6 +1256,7 @@ PJ_DEF(pj_status_t) pjsua_acc_modify( pjsua_acc_id acc_id, pjsip_regc_destroy(acc->regc); acc->regc = NULL; acc->contact.slen = 0; + acc->reg_mapped_addr.slen = 0; } } @@ -1465,6 +1467,13 @@ static pj_bool_t acc_check_nat_addr(pjsua_acc *acc, } } + /* Save mapped address if needed */ + if (acc->cfg.allow_sdp_nat_rewrite && + pj_strcmp(&acc->reg_mapped_addr, via_addr)) + { + pj_strdup(acc->pool, &acc->reg_mapped_addr, via_addr); + } + /* Only update if account is configured to auto-update */ if (acc->cfg.allow_contact_rewrite == PJ_FALSE) return PJ_FALSE; @@ -1989,6 +1998,7 @@ static void regc_cb(struct pjsip_regc_cbparam *param) pjsip_regc_destroy(acc->regc); acc->regc = NULL; acc->contact.slen = 0; + acc->reg_mapped_addr.slen = 0; /* Stop keep-alive timer if any. */ update_keep_alive(acc, PJ_FALSE, NULL); @@ -2000,6 +2010,7 @@ static void regc_cb(struct pjsip_regc_cbparam *param) pjsip_regc_destroy(acc->regc); acc->regc = NULL; acc->contact.slen = 0; + acc->reg_mapped_addr.slen = 0; /* Stop keep-alive timer if any. */ update_keep_alive(acc, PJ_FALSE, NULL); @@ -2014,6 +2025,7 @@ static void regc_cb(struct pjsip_regc_cbparam *param) pjsip_regc_destroy(acc->regc); acc->regc = NULL; acc->contact.slen = 0; + acc->reg_mapped_addr.slen = 0; /* Stop keep-alive timer if any. */ update_keep_alive(acc, PJ_FALSE, NULL); @@ -2119,6 +2131,7 @@ static pj_status_t pjsua_regc_init(int acc_id) pjsip_regc_destroy(acc->regc); acc->regc = NULL; acc->contact.slen = 0; + acc->reg_mapped_addr.slen = 0; } /* initialize SIP registration if registrar is configured */ @@ -2167,6 +2180,7 @@ static pj_status_t pjsua_regc_init(int acc_id) pj_pool_release(pool); acc->regc = NULL; acc->contact.slen = 0; + acc->reg_mapped_addr.slen = 0; return status; } diff --git a/pjsip/src/pjsua-lib/pjsua_media.c b/pjsip/src/pjsua-lib/pjsua_media.c index 22da8ec7..2f58e71f 100644 --- a/pjsip/src/pjsua-lib/pjsua_media.c +++ b/pjsip/src/pjsua-lib/pjsua_media.c @@ -239,12 +239,14 @@ static pj_status_t create_rtp_rtcp_sock(pjsua_call_media *call_med, pj_sockaddr mapped_addr[2]; pj_status_t status = PJ_SUCCESS; char addr_buf[PJ_INET6_ADDRSTRLEN+10]; + pjsua_acc *acc; pj_sock_t sock[2]; - pjsua_acc *acc = &pjsua_var.acc[call_med->call->acc_id]; use_ipv6 = (acc->cfg.ipv6_media_use != PJSUA_IPV6_DISABLED); af = use_ipv6 ? pj_AF_INET6() : pj_AF_INET(); + acc = &pjsua_var.acc[call_med->call->acc_id]; + /* Make sure STUN server resolution has completed */ if (!use_ipv6 && pjsua_sip_acc_is_using_stun(call_med->call->acc_id)) { status = resolve_stun_server(PJ_TRUE); @@ -423,6 +425,19 @@ static pj_status_t create_rtp_rtcp_sock(pjsua_call_media *call_med, break; } else { + if (acc->cfg.allow_sdp_nat_rewrite && acc->reg_mapped_addr.slen) { + pj_status_t status; + + /* Take the address from mapped addr as seen by registrar */ + status = pj_sockaddr_set_str_addr(af, &bound_addr, + &acc->reg_mapped_addr); + if (status != PJ_SUCCESS) { + /* just leave bound_addr with whatever it was + pj_bzero(pj_sockaddr_get_addr(&bound_addr), + pj_sockaddr_get_addr_len(&bound_addr)); + */ + } + } if (!pj_sockaddr_has_addr(&bound_addr)) { pj_sockaddr addr; |