Skip to content

Commit

Permalink
Feature/apps 17701 ipv6 and ip change fixes from 2.15 (#78)
Browse files Browse the repository at this point in the history
* Add option to shutdown all transports on IP change (pjsip#3781)

* pjsua_handle_ip_change: Added missing null check for on_ip_changed_progress callback (pjsip#3830)

* Reset stored remote name in dialog (dlg->initial_dest) if transport is server. (pjsip#3783)

* Prevent immediate tsx termination upon transport error (pjsip#3805)

* Fixed issues when adding new media and deinitializing media (pjsip#3821)

* Potential issues when IPv6 is disabled (pjsip#3835)

* Improve IP address change IPv4 <-> IPv6 (pjsip#3910)

* Add some missing unlocks (pjsip#3893)

* add missing unlock (pjsip#3885)

* Retransmit 2xx response when transport is closed (pjsip#3828)

* Fixed account's route set update when modifying account (pjsip#3825)

---------

Co-authored-by: Nanang Izzuddin <[email protected]>
Co-authored-by: sauwming <[email protected]>
Co-authored-by: Santiago De la Cruz <[email protected]>
Co-authored-by: Andreas Wehrmann <[email protected]>
Co-authored-by: Riza Sulistyo <[email protected]>
  • Loading branch information
6 people authored Apr 5, 2024
1 parent 07cc148 commit 83a228f
Show file tree
Hide file tree
Showing 24 changed files with 456 additions and 122 deletions.
8 changes: 4 additions & 4 deletions pjlib-util/src/pjlib-util/resolver.c
Original file line number Diff line number Diff line change
Expand Up @@ -1840,15 +1840,15 @@ PJ_DEF(pj_status_t) pj_dns_resolver_add_entry( pj_dns_resolver *resolver,
pj_bzero(&key, sizeof(struct res_key));
if (pkt->hdr.anscount) {
/* Make sure name is not too long. */
PJ_ASSERT_RETURN(pkt->ans[0].name.slen < PJ_MAX_HOSTNAME,
PJ_ENAMETOOLONG);
PJ_ASSERT_ON_FAIL(pkt->ans[0].name.slen < PJ_MAX_HOSTNAME,
{ pj_grp_lock_release(resolver->grp_lock); return PJ_ENAMETOOLONG; });

init_res_key(&key, pkt->ans[0].type, &pkt->ans[0].name);

} else {
/* Make sure name is not too long. */
PJ_ASSERT_RETURN(pkt->q[0].name.slen < PJ_MAX_HOSTNAME,
PJ_ENAMETOOLONG);
PJ_ASSERT_ON_FAIL(pkt->q[0].name.slen < PJ_MAX_HOSTNAME,
{ pj_grp_lock_release(resolver->grp_lock); return PJ_ENAMETOOLONG; });

init_res_key(&key, pkt->q[0].type, &pkt->q[0].name);
}
Expand Down
21 changes: 21 additions & 0 deletions pjlib/include/pj/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,27 @@ PJ_IDECL(void) pj_list_insert_nodes_after(pj_list_type *lst,
pj_list_type *nodes);


/**
* Insert a list to another list before the specified element position.
*
* @param pos The element to which the node will be inserted before.
* @param lst The list to be inserted.
*/
PJ_IDECL(void) pj_list_insert_list_before(pj_list_type *pos,
pj_list_type *lst);


/**
* Insert a list to another list after the specified element position.
*
* @param pos The element in the list which will precede the inserted
* list.
* @param lst The list to be inserted.
*/
PJ_IDECL(void) pj_list_insert_list_after(pj_list_type *pos,
pj_list_type *lst);


/**
* Remove elements from the source list, and insert them to the destination
* list. The elements of the source list will occupy the
Expand Down
17 changes: 17 additions & 0 deletions pjlib/include/pj/list_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,23 @@ PJ_IDEF(void) pj_list_insert_nodes_before(pj_list_type *pos, pj_list_type *lst)
pj_list_insert_nodes_after(((pj_list*)pos)->prev, lst);
}

PJ_IDEF(void) pj_list_insert_list_after(pj_list_type *pos, pj_list_type *lst)
{
if (!pj_list_empty(lst)) {
pj_list *lst_last = (pj_list *) ((pj_list*)lst)->prev;
pj_list *pos_next = (pj_list *) ((pj_list*)pos)->next;

pj_link_node(pos, (pj_list *) ((pj_list*)lst)->next);
pj_link_node(lst_last, pos_next);
pj_list_init(lst);
}
}

PJ_IDEF(void) pj_list_insert_list_before(pj_list_type *pos, pj_list_type *lst)
{
pj_list_insert_list_after(((pj_list*)pos)->prev, lst);
}

PJ_IDEF(void) pj_list_merge_last(pj_list_type *lst1, pj_list_type *lst2)
{
if (!pj_list_empty(lst2)) {
Expand Down
1 change: 1 addition & 0 deletions pjlib/src/pj/ioqueue_winnt.c
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ PJ_DEF(pj_status_t) pj_ioqueue_destroy( pj_ioqueue_t *ioqueue )
}
#endif

pj_lock_release(ioqueue->lock);
if (ioqueue->auto_delete_lock)
pj_lock_destroy(ioqueue->lock);

Expand Down
1 change: 1 addition & 0 deletions pjlib/src/pj/pool_caching.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ static void cpool_release_pool( pj_pool_factory *pf, pj_pool_t *pool)
#if PJ_SAFE_POOL
/* Make sure pool is still in our used list */
if (pj_list_find_node(&cp->used_list, pool) != pool) {
pj_lock_release(cp->lock);
pj_assert(!"Attempt to destroy pool that has been destroyed before");
return;
}
Expand Down
4 changes: 3 additions & 1 deletion pjnath/src/pjnath/turn_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,9 @@ PJ_DEF(pj_status_t) pj_turn_session_set_server( pj_turn_session *sess,
unsigned i, cnt;

/* Default port must be specified */
PJ_ASSERT_RETURN(default_port>0 && default_port<65536, PJ_EINVAL);
PJ_ASSERT_ON_FAIL(default_port>0 && default_port<65536,
{status=PJ_EINVAL; goto on_return;});

sess->default_port = (pj_uint16_t)default_port;

cnt = PJ_TURN_MAX_DNS_SRV_CNT;
Expand Down
6 changes: 6 additions & 0 deletions pjsip-apps/src/pjsua/pjsua_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,11 @@ void on_ip_change_progress(pjsua_ip_change_op op,

if (status == PJ_SUCCESS) {
switch (op) {
case PJSUA_IP_CHANGE_OP_SHUTDOWN_TP:
pj_ansi_snprintf(info_str, sizeof(info_str),
"TCP/TLS transports shutdown");
break;

case PJSUA_IP_CHANGE_OP_RESTART_LIS:
pjsua_transport_get_info(info->lis_restart.transport_id, &tp_info);
pj_ansi_snprintf(info_str, sizeof(info_str),
Expand Down Expand Up @@ -1107,6 +1112,7 @@ void on_ip_change_progress(pjsua_ip_change_op op,
pj_ansi_snprintf(info_str, sizeof(info_str),
"done");
default:
info_str[0] = '\0';
break;
}
PJ_LOG(3,(THIS_FILE, "IP change progress report : %s", info_str));
Expand Down
2 changes: 0 additions & 2 deletions pjsip-apps/src/pjsua/pjsua_app_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -1786,8 +1786,6 @@ static void ui_handle_ip_change()
status = pjsua_handle_ip_change(&param);
if (status != PJ_SUCCESS) {
pjsua_perror(THIS_FILE, "IP change failed", status);
} else {
PJ_LOG(3,(THIS_FILE, "IP change succeeded"));
}
}

Expand Down
1 change: 1 addition & 0 deletions pjsip-apps/src/swig/symbols.i
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,7 @@ typedef enum pjsua_snd_dev_mode
typedef enum pjsua_ip_change_op
{
PJSUA_IP_CHANGE_OP_NULL,
PJSUA_IP_CHANGE_OP_SHUTDOWN_TP,
PJSUA_IP_CHANGE_OP_RESTART_LIS,
PJSUA_IP_CHANGE_OP_ACC_SHUTDOWN_TP,
PJSUA_IP_CHANGE_OP_ACC_UPDATE_CONTACT,
Expand Down
47 changes: 47 additions & 0 deletions pjsip/include/pjsip/sip_transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -1322,6 +1322,53 @@ PJ_DECL(pj_status_t) pjsip_tpmgr_destroy(pjsip_tpmgr *mgr);
PJ_DECL(void) pjsip_tpmgr_dump_transports(pjsip_tpmgr *mgr);


/**
* Parameter for pjsip_tpmgr_shutdown_all() function.
*/
typedef struct pjsip_tpmgr_shutdown_param
{
/**
* Specify whether disconnection state notification should be sent
* immediately, see pjsip_transport_shutdown2() for more info.
*
* Default: PJ_TRUE.
*/
pj_bool_t force;

/**
* Specify whether UDP transports should also be shutdown.
*
* Default: PJ_TRUE.
*/
pj_bool_t include_udp;

} pjsip_tpmgr_shutdown_param;


/**
* Initialize transports shutdown parameter with default values.
*
* @param prm The parameter to be initialized.
*/
PJ_DECL(void) pjsip_tpmgr_shutdown_param_default(
pjsip_tpmgr_shutdown_param *prm);


/**
* Shutdown all transports. This basically invokes pjsip_transport_shutdown2()
* on all transports.
*
* @param mgr The transport manager.
* @param param The function parameters.
*
* @return PJ_SUCCESS on success.
*/
PJ_DECL(pj_status_t) pjsip_tpmgr_shutdown_all(
pjsip_tpmgr *mgr,
const pjsip_tpmgr_shutdown_param *param);



/*****************************************************************************
*
* PUBLIC API
Expand Down
28 changes: 27 additions & 1 deletion pjsip/include/pjsua-lib/pjsua.h
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,11 @@ typedef enum pjsua_ip_change_op {
*/
PJSUA_IP_CHANGE_OP_NULL,

/**
* The restart listener process.
*/
PJSUA_IP_CHANGE_OP_SHUTDOWN_TP,

/**
* The restart listener process.
*/
Expand Down Expand Up @@ -2787,6 +2792,15 @@ typedef struct pjsua_ip_change_param
*/
unsigned restart_lis_delay;

/**
* If set to PJ_TRUE, this will forcefully shutdown all transports.
* Note that this will shutdown TCP/TLS transports only, UDP transport
* should be restarted via restart_listener.
*
* Default : PJ_TRUE
*/
pj_bool_t shutdown_transport;

} pjsua_ip_change_param;


Expand Down Expand Up @@ -4528,6 +4542,18 @@ typedef struct pjsua_acc_config
*/
pj_bool_t register_on_acc_add;

/**
* Specify whether account modification with pjsua_acc_modify() should
* automatically update registration if necessary, for example if
* account credentials change.
*
* Disable this when immediate registration is not desirable, such as
* during IP address change.
*
* Default: PJ_FALSE.
*/
pj_bool_t disable_reg_on_modify;

/**
* Specify account configuration specific to IP address change used when
* calling #pjsua_handle_ip_change().
Expand Down Expand Up @@ -7505,7 +7531,7 @@ typedef struct pjsua_snd_dev_param
*/
unsigned mode;

/*
/**
* The library will maintain the global sound device settings set when
* opening the sound device for the first time and later can be modified
* using #pjsua_snd_set_setting(). These setings are then applied to any
Expand Down
1 change: 1 addition & 0 deletions pjsip/include/pjsua-lib/pjsua_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,7 @@ void pjsua_ice_check_start_trickling(pjsua_call *call,
pj_bool_t pjsua_call_media_is_changing(pjsua_call *call);
pj_status_t pjsua_call_media_init(pjsua_call_media *call_med,
pjmedia_type type,
const pjmedia_sdp_session *rem_sdp,
const pjsua_transport_config *tcfg,
int security_level,
int *sip_err_code,
Expand Down
12 changes: 12 additions & 0 deletions pjsip/include/pjsua2/account.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ struct AccountRegConfig : public PersistentObject
*/
bool registerOnAdd;

/**
* Specify whether account modification with Account::modify() should
* automatically update registration if necessary, for example if
* account credentials change.
*
* Disable this when immediate registration is not desirable, such as
* during IP address change.
*
* Default: false.
*/
bool disableRegOnModify;

/**
* The optional custom SIP headers to be put in the registration
* request.
Expand Down
9 changes: 9 additions & 0 deletions pjsip/include/pjsua2/endpoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,15 @@ struct IpChangeParam {
*/
unsigned restartLisDelay;

/**
* If set to PJ_TRUE, this will forcefully shutdown all transports.
* Note that this will shutdown TCP/TLS transports only, UDP transport
* should be restarted via restart_listener.
*
* Default : PJ_TRUE
*/
bool shutdownTransport;

public:
/**
* Constructor.
Expand Down
14 changes: 13 additions & 1 deletion pjsip/src/pjsip/sip_dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,8 @@ pj_status_t create_uas_dialog( pjsip_user_agent *ua,
if (rdata->tp_info.transport->dir == PJSIP_TP_DIR_OUTGOING) {
pj_strdup(dlg->pool, &dlg->initial_dest,
&rdata->tp_info.transport->remote_name.host);
PJ_LOG(5, (THIS_FILE, "Saving initial dest %.*s",
(int)dlg->initial_dest.slen, dlg->initial_dest.ptr));
}

/* Init remote's contact from Contact header.
Expand Down Expand Up @@ -1222,8 +1224,11 @@ static pj_status_t dlg_create_request_throw( pjsip_dialog *dlg,
/* Copy the initial destination host to tdata. This information can be
* used later by transport for transport selection.
*/
if (dlg->initial_dest.slen)
if (dlg->initial_dest.slen) {
pj_strdup(tdata->pool, &tdata->dest_info.name, &dlg->initial_dest);
PJ_LOG(5, (THIS_FILE, "Setting initial dest %.*s",
(int)dlg->initial_dest.slen, dlg->initial_dest.ptr));
}

/* Done. */
*p_tdata = tdata;
Expand Down Expand Up @@ -1878,6 +1883,13 @@ static void dlg_update_routeset(pjsip_dialog *dlg, const pjsip_rx_data *rdata)
{
pj_strdup(dlg->pool, &dlg->initial_dest,
&rdata->tp_info.transport->remote_name.host);
PJ_LOG(5, (THIS_FILE, "Saving initial dest %.*s",
(int)dlg->initial_dest.slen, dlg->initial_dest.ptr));
} else {
/* Reset the stored remote name if the transport is a server
* transport.
*/
dlg->initial_dest.slen = 0;
}

/* Ignore subsequent request from remote */
Expand Down
18 changes: 15 additions & 3 deletions pjsip/src/pjsip/sip_transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -2144,11 +2144,15 @@ static void send_msg_callback( pjsip_send_state *send_state,
else
sc = PJSIP_SC_TSX_TRANSPORT_ERROR;

/* Terminate transaction, if it's not already terminated. */
tsx_set_status_code(tsx, sc, &err);
if (tsx->state != PJSIP_TSX_STATE_TERMINATED &&
/* We terminate the transaction for 502 error. For 503,
* we will retry it.
* See https://github.com/pjsip/pjproject/pull/3805
*/
if (sc == PJSIP_SC_BAD_GATEWAY &&
tsx->state != PJSIP_TSX_STATE_TERMINATED &&
tsx->state != PJSIP_TSX_STATE_DESTROYED)
{
tsx_set_status_code(tsx, sc, &err);
/* Set tsx state to TERMINATED, but release the lock
* when invoking the callback, to avoid deadlock.
*/
Expand All @@ -2161,9 +2165,17 @@ static void send_msg_callback( pjsip_send_state *send_state,
*/
else if (tsx->transport_flag & TSX_HAS_PENDING_DESTROY)
{
tsx_set_status_code(tsx, sc, &err);
tsx_set_state( tsx, PJSIP_TSX_STATE_DESTROYED,
PJSIP_EVENT_TRANSPORT_ERROR,
send_state->tdata, 0);
} else if (tsx->role == PJSIP_ROLE_UAS &&
tsx->transport_flag & TSX_HAS_PENDING_RESCHED &&
tsx->state != PJSIP_TSX_STATE_TERMINATED &&
tsx->state != PJSIP_TSX_STATE_DESTROYED)
{
tsx->transport_flag &= ~(TSX_HAS_PENDING_RESCHED);
tsx_resched_retransmission(tsx);
}

} else {
Expand Down
Loading

0 comments on commit 83a228f

Please sign in to comment.