Skip to content

Commit

Permalink
Merge pull request #35 from freeswitch/resend_reliable
Browse files Browse the repository at this point in the history
Add NTATAG_TLS_ORQ_CONNECT_TIMEOUT and NUTAG_TLS_ORQ_CONNECT_TIMEOUT tags. Optionally set N3 timer for outgoing requests when using TLS. DNS fail over if possible. Per call timeout set by NUATAG overrides profile timeout set by NTATAG. Version bump to 1.13.2
  • Loading branch information
andywolk committed Oct 27, 2020
2 parents 421e81e + 4b2a878 commit 33974b9
Show file tree
Hide file tree
Showing 12 changed files with 144 additions and 18 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dnl information on the package
dnl ---------------------------

dnl update both the version for AC_INIT and the LIBSOFIA_SIP_UA_MAJOR_MINOR
AC_INIT([sofia-sip], [1.13.0])
AC_INIT([sofia-sip], [1.13.2])

CFLAGS="$CFLAGS $CONFIGURE_CFLAGS"
CXXFLAGS="$CXXFLAGS $CONFIGURE_CXXFLAGS"
Expand Down
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
sofia-sip (1.13.2-1) unstable; urgency=medium

* New Release.

-- FreeSWITCH Solutions <[email protected]> Tue, 27 Oct 2020 21:32:37 +0200

sofia-sip (1.13.1-1) unstable; urgency=medium

* New Release.
Expand Down
69 changes: 56 additions & 13 deletions libsofia-sip-ua/nta/nta.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ struct nta_agent_s

unsigned sa_t1x64; /**< SIP T1X64 - transaction lifetime (32 s) */

unsigned sa_tls_orq_connect_timeout; /**< Connect Timeout for outgoing requests using TLS (ms) */

unsigned sa_progress; /**< Progress timer.
Interval between retransmitting
provisional responses. */
Expand Down Expand Up @@ -537,6 +539,7 @@ struct nta_outgoing_s
unsigned orq_try_tcp_instead:1;
unsigned orq_try_udp_instead:1;
unsigned orq_reliable:1; /**< Transport is reliable */
unsigned orq_call_tls_connect_timeout_is_set:1; /** Per Call connect timeout for outgoing requests using TLS set flag*/

unsigned orq_forked:1; /**< Tagged fork */

Expand Down Expand Up @@ -574,6 +577,7 @@ struct nta_outgoing_s
nta_outgoing_t *orq_forks; /**< Tagged transactions */
uint32_t orq_rseq; /**< Latest incoming rseq */
int orq_pending; /**< Request is pending in tport */
uint32_t orq_call_tls_connect_timeout; /** Per Call connect timeout for outgoing requests using TLS */
};

/* ------------------------------------------------------------------------- */
Expand Down Expand Up @@ -844,7 +848,7 @@ su_log_t nta_log[] = { SU_LOG_INIT("nta", "NTA_DEBUG", SU_DEBUG) };
* NTATAG_SIP_T1X64(), NTATAG_SIP_T1(), NTATAG_SIP_T2(), NTATAG_SIP_T4(),
* NTATAG_STATELESS(),
* NTATAG_TAG_3261(), NTATAG_TCP_RPORT(), NTATAG_TIMEOUT_408(),
* NTATAG_TLS_RPORT(),
* NTATAG_TLS_RPORT(), NTATAG_TLS_ORQ_CONNECT_TIMEOUT(),
* NTATAG_TIMER_C(), NTATAG_MAX_PROCEEDING(),
* NTATAG_UA(), NTATAG_UDP_MTU(), NTATAG_USER_VIA(),
* NTATAG_USE_NAPTR(), NTATAG_USE_SRV() and NTATAG_USE_TIMESTAMP().
Expand Down Expand Up @@ -1417,7 +1421,7 @@ void agent_kill_terminator(nta_agent_t *agent)
* NTATAG_SIP_T1X64(), NTATAG_SIP_T1(), NTATAG_SIP_T2(), NTATAG_SIP_T4(),
* NTATAG_STATELESS(),
* NTATAG_TAG_3261(), NTATAG_TCP_RPORT(), NTATAG_TIMEOUT_408(),
* NTATAG_TLS_RPORT(),
* NTATAG_TLS_RPORT(), NTATAG_TLS_ORQ_CONNECT_TIMEOUT(),
* NTATAG_TIMER_C(), NTATAG_MAX_PROCEEDING(),
* NTATAG_UA(), NTATAG_UDP_MTU(), NTATAG_USER_VIA(),
* NTATAG_USE_NAPTR(), NTATAG_USE_SRV() and NTATAG_USE_TIMESTAMP().
Expand Down Expand Up @@ -1458,6 +1462,7 @@ int agent_set_params(nta_agent_t *agent, tagi_t *tags)
unsigned sip_t2 = agent->sa_t2;
unsigned sip_t4 = agent->sa_t4;
unsigned sip_t1x64 = agent->sa_t1x64;
unsigned tls_orq_connect_timeout = agent->sa_tls_orq_connect_timeout;
unsigned timer_c = agent->sa_timer_c;
unsigned timer_d = 32000;
unsigned graylist = agent->sa_graylist;
Expand Down Expand Up @@ -1532,6 +1537,7 @@ int agent_set_params(nta_agent_t *agent, tagi_t *tags)
NTATAG_STATELESS_REF(stateless),
NTATAG_TCP_RPORT_REF(tcp_rport),
NTATAG_TLS_RPORT_REF(tls_rport),
NTATAG_TLS_ORQ_CONNECT_TIMEOUT_REF(tls_orq_connect_timeout),
NTATAG_TIMEOUT_408_REF(timeout_408),
NTATAG_UA_REF(ua),
NTATAG_UDP_MTU_REF(udp_mtu),
Expand Down Expand Up @@ -1666,6 +1672,9 @@ int agent_set_params(nta_agent_t *agent, tagi_t *tags)
timer_d = sip_t1x64;
outgoing_queue_adjust(agent, agent->sa_out.inv_completed, timer_d);

if (tls_orq_connect_timeout > NTA_TIME_MAX) tls_orq_connect_timeout = NTA_TIME_MAX;
agent->sa_tls_orq_connect_timeout = tls_orq_connect_timeout;

if (graylist > 24 * 60 * 60)
graylist = 24 * 60 * 60;
agent->sa_graylist = graylist;
Expand Down Expand Up @@ -7843,6 +7852,8 @@ nta_outgoing_t *outgoing_create(nta_agent_t *agent,
int invalid, resolved = 0, stateless = 0, user_via = agent->sa_user_via;
int invite_100rel = agent->sa_invite_100rel;
int explicit_transport = 1;
int call_tls_orq_connect_timeout_is_set = 0;
int call_tls_orq_connect_timeout = 0;

tagi_t const *t;
tport_t *override_tport = NULL;
Expand Down Expand Up @@ -7915,6 +7926,11 @@ nta_outgoing_t *outgoing_create(nta_agent_t *agent,
else if (ntatag_rel100 == tt) {
invite_100rel = t->t_value != 0;
}
else if (ntatag_tls_orq_connect_timeout == tt) {
call_tls_orq_connect_timeout_is_set = 1;
call_tls_orq_connect_timeout = t->t_value;
if (call_tls_orq_connect_timeout > NTA_TIME_MAX) call_tls_orq_connect_timeout = NTA_TIME_MAX;
}
}

orq->orq_agent = agent;
Expand All @@ -7937,6 +7953,8 @@ nta_outgoing_t *outgoing_create(nta_agent_t *agent,
orq->orq_user_via = user_via != 0 && sip->sip_via;
orq->orq_100rel = invite_100rel;
orq->orq_uas = !stateless && agent->sa_is_a_uas;
orq->orq_call_tls_connect_timeout_is_set = call_tls_orq_connect_timeout_is_set;
orq->orq_call_tls_connect_timeout = (call_tls_orq_connect_timeout > 0) ? call_tls_orq_connect_timeout : 0;

if (cc)
orq->orq_cc = nta_compartment_ref(cc);
Expand Down Expand Up @@ -8358,8 +8376,16 @@ outgoing_send(nta_outgoing_t *orq, int retransmit)
unsigned t1_timer = agent->sa_t1;
if (t1_timer < 1000) t1_timer = 1000;
outgoing_set_timer(orq, t1_timer); /* Timer A/E */
} else if (orq->orq_try_tcp_instead && !tport_is_connected(tp))
} else if (orq->orq_try_tcp_instead && !tport_is_connected(tp)) {
outgoing_set_timer(orq, agent->sa_t4); /* Timer N3 */
} else if (su_casenmatch(orq->orq_tpn->tpn_proto, "tls", 3) && !tport_is_connected(tp)) {
unsigned tls_reconect_interval = (orq->orq_call_tls_connect_timeout_is_set) ?
orq->orq_call_tls_connect_timeout : agent->sa_tls_orq_connect_timeout;
if (tls_reconect_interval) {
if (tls_reconect_interval < 1000) tls_reconect_interval = 1000;
outgoing_set_timer(orq, tls_reconect_interval); /* Timer N3 set to (min 1000 ms if set) */
}
}
}

static void
Expand Down Expand Up @@ -8884,16 +8910,33 @@ _nta_outgoing_timer(nta_agent_t *sa)
outgoing_reset_timer(orq);

if (!tport_is_connected(orq->orq_tport)) {
/*
* Timer N3: try to use UDP if trying to send via TCP
* but no connection is established within SIP T4
*/
SU_DEBUG_5(("nta: timer %s fired, %s %s (%u)\n", "N3",
"try UDP instead for",
orq->orq_method_name, orq->orq_cseq->cs_seq));
outgoing_try_udp_instead(orq, 1);
outgoing_remove(orq); /* Reset state - this is no resend! */
outgoing_send(orq, 0); /* Send */
uint32_t tls_connect_timeout = (orq->orq_call_tls_connect_timeout_is_set) ?
orq->orq_call_tls_connect_timeout : sa->sa_tls_orq_connect_timeout;
if (su_casenmatch(orq->orq_tpn->tpn_proto, "tls", 3) && tls_connect_timeout) {
outgoing_remove(orq); /* Reset state - this is no resend! */
if (outgoing_other_destinations(orq)) {
SU_DEBUG_5(("nta: timer %s fired (proto: %s), %s %s (%u)\n", "N3",
orq->orq_tpn->tpn_proto, "trying alternative server for",
orq->orq_method_name, orq->orq_cseq->cs_seq));
outgoing_try_another(orq);
} else {
SU_DEBUG_5(("nta: timer %s fired (proto: %s), %s %s (%u)\n", "N3",
orq->orq_tpn->tpn_proto, "retrying for",
orq->orq_method_name, orq->orq_cseq->cs_seq));
outgoing_send(orq, 0); /* Send */
}
} else {
/*
* Timer N3: try to use UDP if trying to send via TCP
* but no connection is established within SIP T4
*/
SU_DEBUG_5(("nta: timer %s fired, %s %s (%u)\n", "N3",
"try UDP instead for",
orq->orq_method_name, orq->orq_cseq->cs_seq));
outgoing_try_udp_instead(orq, 1);
outgoing_remove(orq); /* Reset state - this is no resend! */
outgoing_send(orq, 0); /* Send */
}
}
continue;
}
Expand Down
19 changes: 19 additions & 0 deletions libsofia-sip-ua/nta/nta_tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -1397,6 +1397,25 @@ tag_typedef_t ntatag_tcp_rport = BOOLTAG_TYPEDEF(tcp_rport);
*/
tag_typedef_t ntatag_tls_rport = BOOLTAG_TYPEDEF(tls_rport);

/**@def NTATAG_TLS_ORQ_CONNECT_TIMEOUT(x)
*
* Connect Timeout for outgoing requests using TLS.
*
* @par Used with
* nua_create(), nua_set_params(),
* nta_agent_create(), nta_agent_set_params()
*
* @par Parameter type
* unsigned
*
* @par Values
* - 0 - Disabled
* - value - Milliseconds
*
* @NEW_1_13_2
*/
tag_typedef_t ntatag_tls_orq_connect_timeout = UINTTAG_TYPEDEF(tls_orq_connect_timeout);

/**@def NTATAG_PRELOAD(x)
*
* Preload by N bytes.
Expand Down
6 changes: 6 additions & 0 deletions libsofia-sip-ua/nta/sofia-sip/nta_tag.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,12 @@ NTA_DLL extern tag_typedef_t ntatag_tls_rport;
NTA_DLL extern tag_typedef_t ntatag_tls_rport_ref;
#define NTATAG_TLS_RPORT_REF(x) ntatag_tls_rport_ref, tag_bool_vr(&(x))

NTA_DLL extern tag_typedef_t ntatag_tls_orq_connect_timeout;
#define NTATAG_TLS_ORQ_CONNECT_TIMEOUT(x) ntatag_tls_orq_connect_timeout, tag_uint_v((x))

NTA_DLL extern tag_typedef_t ntatag_tls_orq_connect_timeout_ref;
#define NTATAG_TLS_ORQ_CONNECT_TIMEOUT_REF(x) ntatag_tls_orq_connect_timeout_ref, tag_uint_vr(&(x))

NTA_DLL extern tag_typedef_t ntatag_preload;
#define NTATAG_PRELOAD(x) ntatag_preload, tag_uint_v((x))

Expand Down
4 changes: 4 additions & 0 deletions libsofia-sip-ua/nua/nua_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,8 @@ int nua_base_client_request(nua_client_request_t *cr, msg_t *msg, sip_t *sip,
nua_handle_t *nh = cr->cr_owner;
int proxy_is_set = NH_PISSET(nh, proxy);
url_string_t * proxy = NH_PGET(nh, proxy);
int call_tls_orq_connect_timeout_is_set = NH_PISSET(nh, call_tls_orq_connect_timeout);
uint32_t call_tls_orq_connect_timeout = NH_PGET(nh, call_tls_orq_connect_timeout);

if (nh->nh_auth) {
if (cr->cr_challenged ||
Expand All @@ -964,6 +966,8 @@ int nua_base_client_request(nua_client_request_t *cr, msg_t *msg, sip_t *sip,
msg,
TAG_IF(proxy_is_set,
NTATAG_DEFAULT_PROXY(proxy)),
TAG_IF(call_tls_orq_connect_timeout_is_set,
NTATAG_TLS_ORQ_CONNECT_TIMEOUT(call_tls_orq_connect_timeout)),
TAG_NEXT(tags));

if (cr->cr_orq == NULL) {
Expand Down
7 changes: 7 additions & 0 deletions libsofia-sip-ua/nua/nua_params.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ int nua_stack_init_instance(nua_handle_t *nh, tagi_t const *tags)
* NUTAG_AUTOACK() \n
* NUTAG_AUTOALERT() \n
* NUTAG_AUTOANSWER() \n
* NUTAG_CALL_TLS_ORQ_CONNECT_TIMEOUT() \n
* NUTAG_CALLEE_CAPS() \n
* NUTAG_DETECT_NETWORK_UPDATES() \n
* NUTAG_EARLY_ANSWER() \n
Expand Down Expand Up @@ -398,6 +399,7 @@ int nua_stack_init_instance(nua_handle_t *nh, tagi_t const *tags)
* NUTAG_AUTOACK() \n
* NUTAG_AUTOALERT() \n
* NUTAG_AUTOANSWER() \n
* NUTAG_CALL_TLS_ORQ_CONNECT_TIMEOUT() \n
* NUTAG_CALLEE_CAPS() \n
* NUTAG_EARLY_ANSWER() \n
* NUTAG_EARLY_MEDIA() \n
Expand Down Expand Up @@ -707,6 +709,9 @@ static int nhp_set_tags(su_home_t *home,
else if (tag == nutag_retry_count) {
NHP_SET(nhp, retry_count, (unsigned)value);
}
else if (tag == nutag_call_tls_orq_connect_timeout) {
NHP_SET(nhp, call_tls_orq_connect_timeout, (uint32_t)value);
}
/* NUTAG_MAX_SUBSCRIPTIONS(max_subscriptions) */
else if (tag == nutag_max_subscriptions) {
NHP_SET(nhp, max_subscriptions, (unsigned)value);
Expand Down Expand Up @@ -1493,6 +1498,7 @@ int nua_stack_set_smime_params(nua_t *nua, tagi_t const *tags)
* NUTAG_AUTOACK() \n
* NUTAG_AUTOALERT() \n
* NUTAG_AUTOANSWER() \n
* NUTAG_CALL_TLS_ORQ_CONNECT_TIMEOUT() \n
* NUTAG_CALLEE_CAPS() \n
* NUTAG_DETECT_NETWORK_UPDATES() \n
* NUTAG_EARLY_ANSWER() \n
Expand Down Expand Up @@ -1665,6 +1671,7 @@ int nua_stack_get_params(nua_t *nua, nua_handle_t *nh, nua_event_t e,
: NULL)),

TIF(NUTAG_RETRY_COUNT, retry_count),
TIF(NUTAG_CALL_TLS_ORQ_CONNECT_TIMEOUT, call_tls_orq_connect_timeout),
TIF(NUTAG_MAX_SUBSCRIPTIONS, max_subscriptions),

TIF(NUTAG_SOA_NAME, soa_name),
Expand Down
2 changes: 2 additions & 0 deletions libsofia-sip-ua/nua/nua_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ struct nua_handle_preferences
{
unsigned nhp_retry_count; /**< times to retry a request */
unsigned nhp_max_subscriptions;
uint32_t nhp_call_tls_orq_connect_timeout;

/* Session-related preferences */
char const *nhp_soa_name;
Expand Down Expand Up @@ -219,6 +220,7 @@ struct nua_handle_preferences
unsigned nhb_timer_autorequire:1;
unsigned nhb_retry_after_enable:1;
unsigned nhb_auto_invite_100:1;
unsigned nhb_call_tls_orq_connect_timeout:1;
unsigned :0;
} set_bits;
unsigned set_unsigned[2];
Expand Down
34 changes: 34 additions & 0 deletions libsofia-sip-ua/nua/nua_tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,40 @@ tag_typedef_t nutag_retry_count = UINTTAG_TYPEDEF(retry_count);
* Reference tag for NUTAG_RETRY_COUNT().
*/

/**@def NUTAG_CALL_TLS_ORQ_CONNECT_TIMEOUT(x)
*
* Per Call Connect Timeout for outgoing requests using TLS.
*
* Overrides NTATAG_TLS_ORQ_CONNECT_TIMEOUT()
*
* @par Used with
* nua_create(), nua_set_params(), nua_handle(), nua_set_hparams(),
* nua_get_params(), nua_get_hparams(),
* nua_register(), nua_unregister(),
* nua_options(), nua_invite(), nua_ack(), nua_cancel(), nua_bye(),
* nua_prack(), nua_update(), nua_info(),
* nua_message(), nua_publish(), nua_unpublish(), nua_notifier(),
* nua_subscribe(), nua_unsubscribe(), nua_notify(), nua_refer(),
* nua_method(), nua_respond()
* nua_authenticate().
*
* @par Parameter type
* unsigned
*
* @par Values
* - 0 - Disabled
* - value - Milliseconds
*
* @NEW_1_13_2.
*
* Corresponding tag taking reference parameter is NUTAG_CALL_TLS_ORQ_CONNECT_TIMEOUT_REF().
*/
tag_typedef_t nutag_call_tls_orq_connect_timeout = UINTTAG_TYPEDEF(call_tls_orq_connect_timeout);

/**@def NUTAG_CALL_TLS_ORQ_CONNECT_TIMEOUT_REF(x)
*
* Reference tag for NUTAG_CALL_TLS_ORQ_CONNECT_TIMEOUT().
*/

/**@def NUTAG_MAX_SUBSCRIPTIONS(x)
*
Expand Down
5 changes: 5 additions & 0 deletions libsofia-sip-ua/nua/sofia-sip/nua_tag.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ SOFIAPUBVAR tag_typedef_t nutag_retry_count;
#define NUTAG_RETRY_COUNT_REF(x) nutag_retry_count_ref, tag_uint_vr(&(x))
SOFIAPUBVAR tag_typedef_t nutag_retry_count_ref;

#define NUTAG_CALL_TLS_ORQ_CONNECT_TIMEOUT(x) nutag_call_tls_orq_connect_timeout, tag_uint_v(x)
SOFIAPUBVAR tag_typedef_t nutag_call_tls_orq_connect_timeout;
#define NUTAG_CALL_TLS_ORQ_CONNECT_TIMEOUT_REF(x) nutag_call_tls_orq_connect_timeout_ref, tag_uint_vr(&(x))
SOFIAPUBVAR tag_typedef_t nutag_call_tls_orq_connect_timeout_ref;

#define NUTAG_SOA_NAME(x) nutag_soa_name, tag_str_v(x)
SOFIAPUBVAR tag_typedef_t nutag_soa_name;
#define NUTAG_SOA_NAME_REF(x) \
Expand Down
6 changes: 3 additions & 3 deletions open_c/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -382,13 +382,13 @@
#define PACKAGE_NAME "sofia-sip"

/* Define to the full name and version of this package. */
#define PACKAGE_STRING "sofia-sip 1.13.0work"
#define PACKAGE_STRING "sofia-sip 1.13.2work"

/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "sofia-sip"

/* Define to the version of this package. */
#define PACKAGE_VERSION "1.13.0work"
#define PACKAGE_VERSION "1.13.2work"

/* Define as the return type of signal handlers (`int' or `void'). */
#define RETSIGTYPE void
Expand All @@ -408,7 +408,7 @@
#define TIME_WITH_SYS_TIME 1

/* Version number of package */
#define VERSION "1.13.0work"
#define VERSION "1.13.2work"

/* Define to 1 if your processor stores words with the most significant byte
first (like Motorola and SPARC, unlike Intel and VAX). */
Expand Down
2 changes: 1 addition & 1 deletion sofia-sip.spec
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: sofia-sip
Version: 1.13.0
Version: 1.13.2
Release: 1%{?dist}
Summary: Sofia SIP User-Agent library

Expand Down

0 comments on commit 33974b9

Please sign in to comment.