From a974061441cef62ef02242a9fc89531a70dc7117 Mon Sep 17 00:00:00 2001 From: Nanang Izzuddin Date: Fri, 15 Mar 2024 09:41:16 +0700 Subject: [PATCH] Update listener restart in IP change: don't create/restart listener if currently no listener, also update docs that bound address setting will be reset. (#3873) --- pjsip/include/pjsua-lib/pjsua.h | 3 +++ pjsip/src/pjsip/sip_transport_tcp.c | 22 +++++++++++++++++++--- pjsip/src/pjsip/sip_transport_tls.c | 16 ++++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/pjsip/include/pjsua-lib/pjsua.h b/pjsip/include/pjsua-lib/pjsua.h index e8d91d11e..0fcdb486d 100644 --- a/pjsip/include/pjsua-lib/pjsua.h +++ b/pjsip/include/pjsua-lib/pjsua.h @@ -2787,6 +2787,9 @@ typedef struct pjsua_ip_change_param { /** * If set to PJ_TRUE, this will restart the transport listener. + * Note that if restarting listener is enabled and the listener is + * configured with a bound address, the address will be reset + * so it will bind to any address (e.g: IPv4 "0.0.0.0" or IPv6 "::"). * * Default : PJ_TRUE */ diff --git a/pjsip/src/pjsip/sip_transport_tcp.c b/pjsip/src/pjsip/sip_transport_tcp.c index 5dd1d24f7..303a57ee9 100644 --- a/pjsip/src/pjsip/sip_transport_tcp.c +++ b/pjsip/src/pjsip/sip_transport_tcp.c @@ -1744,6 +1744,22 @@ PJ_DEF(pj_status_t) pjsip_tcp_transport_restart(pjsip_tpfactory *factory, pj_status_t status = PJ_SUCCESS; struct tcp_listener *listener = (struct tcp_listener *)factory; + /* Just update the published address if currently no listener */ + if (!listener->asock) { + PJ_LOG(3,(factory->obj_name, + "TCP restart requested while no listener created, " + "update the published address only")); + + status = update_factory_addr(listener, a_name); + if (status != PJ_SUCCESS) + return status; + + /* Set transport info. */ + update_transport_info(listener); + + return PJ_SUCCESS; + } + lis_close(listener); status = pjsip_tcp_transport_lis_start(factory, local, a_name); @@ -1753,15 +1769,15 @@ PJ_DEF(pj_status_t) pjsip_tcp_transport_restart(pjsip_tpfactory *factory, return status; } - + status = pjsip_tpmgr_register_tpfactory(listener->tpmgr, &listener->factory); if (status != PJ_SUCCESS) { tcp_perror(listener->factory.obj_name, "Unable to register the transport listener", status); } else { - listener->is_registered = PJ_TRUE; - } + listener->is_registered = PJ_TRUE; + } return status; } diff --git a/pjsip/src/pjsip/sip_transport_tls.c b/pjsip/src/pjsip/sip_transport_tls.c index 50accc919..5b5cd02b2 100644 --- a/pjsip/src/pjsip/sip_transport_tls.c +++ b/pjsip/src/pjsip/sip_transport_tls.c @@ -756,6 +756,22 @@ PJ_DEF(pj_status_t) pjsip_tls_transport_restart(pjsip_tpfactory *factory, pj_status_t status = PJ_SUCCESS; struct tls_listener *listener = (struct tls_listener *)factory; + /* Just update the published address if currently no listener */ + if (!listener->ssock) { + PJ_LOG(3,(factory->obj_name, + "TLS restart requested while no listener created, " + "update the published address only")); + + status = update_factory_addr(listener, a_name); + if (status != PJ_SUCCESS) + return status; + + /* Set transport info. */ + update_transport_info(listener); + + return PJ_SUCCESS; + } + lis_close(listener); status = pjsip_tls_transport_lis_start(factory, local, a_name);