diff options
-rw-r--r-- | pjsip/include/pjsua-lib/pjsua_internal.h | 2 | ||||
-rw-r--r-- | pjsip/src/pjsua-lib/pjsua_acc.c | 22 |
2 files changed, 21 insertions, 3 deletions
diff --git a/pjsip/include/pjsua-lib/pjsua_internal.h b/pjsip/include/pjsua-lib/pjsua_internal.h index ff414ea8..2c60f597 100644 --- a/pjsip/include/pjsua-lib/pjsua_internal.h +++ b/pjsip/include/pjsua-lib/pjsua_internal.h @@ -219,6 +219,8 @@ typedef struct pjsua_acc pj_str_t reg_contact; /**< Contact header for REGISTER. It may be different than acc contact if outbound is used */ + pj_bool_t contact_rewritten; + /**< Contact rewrite has been done? */ pjsip_host_port via_addr; /**< Address for Via header */ pjsip_transport *via_tp; /**< Transport associated with the Via address */ diff --git a/pjsip/src/pjsua-lib/pjsua_acc.c b/pjsip/src/pjsua-lib/pjsua_acc.c index 27aa72d2..0cb4801c 100644 --- a/pjsip/src/pjsua-lib/pjsua_acc.c +++ b/pjsip/src/pjsua-lib/pjsua_acc.c @@ -2092,7 +2092,12 @@ static void regc_tsx_cb(struct pjsip_regc_tsx_cb_param *param) pj_log_push_indent(); - if ((acc->cfg.contact_rewrite_method & + /* Check if we should do NAT bound address check for contact rewrite. + * Note that '!contact_rewritten' check here is to avoid overriding + * the current contact generated from last 2xx. + */ + if (!acc->contact_rewritten && + (acc->cfg.contact_rewrite_method & PJSUA_CONTACT_REWRITE_ALWAYS_UPDATE) == PJSUA_CONTACT_REWRITE_ALWAYS_UPDATE && param->cbparam.code >= 400 && @@ -2103,6 +2108,10 @@ static void regc_tsx_cb(struct pjsip_regc_tsx_cb_param *param) { param->contact_cnt = 1; param->contact[0] = acc->reg_contact; + + /* Don't set 'contact_rewritten' to PJ_TRUE here to allow + * further check of NAT bound address in 2xx response. + */ } } @@ -2177,12 +2186,16 @@ static void regc_cb(struct pjsip_regc_cbparam *param) */ update_rfc5626_status(acc, param->rdata); - /* Check NAT bound address */ - if (acc_check_nat_addr(acc, (acc->cfg.contact_rewrite_method & 3), + /* Check NAT bound address if it hasn't been done before */ + if (!acc->contact_rewritten && + acc_check_nat_addr(acc, (acc->cfg.contact_rewrite_method & 3), param)) { PJSUA_UNLOCK(); pj_log_pop_indent(); + + /* Avoid another check of NAT bound address */ + acc->contact_rewritten = PJ_TRUE; return; } @@ -2216,6 +2229,9 @@ static void regc_cb(struct pjsip_regc_cbparam *param) acc->reg_last_err = param->status; acc->reg_last_code = param->code; + /* Reaching this point means no contact rewrite, so reset the flag */ + acc->contact_rewritten = PJ_FALSE; + /* Check if we need to auto retry registration. Basically, registration * failure codes triggering auto-retry are those of temporal failures * considered to be recoverable in relatively short term. |