Skip to content
Snippets Groups Projects
Unverified Commit f204ebb7 authored by Sébastien Blin's avatar Sébastien Blin
Browse files

rfc6544: fix "Connection refused" error code

4463ed9e introduced a regression
and was checking for 70000+err instead of 120000+err.

Connection refused is 120111 (PJ_ERRNO_START_SYS + 111) and
not 70111 (PJ_ERRNO_START_STATUS + 111) leading to incorrect
error detection and some negotiation failed.

This patch also introduces some of the logs I used to debug this
issue that can be useful if a similar scenario come back.

Change-Id: I2a0e23f07f07ae81db14daea5d257976463c1133
GitLab: #438
parent 316d6fed
No related branches found
No related tags found
No related merge requests found
...@@ -29,10 +29,10 @@ on behalf of Savoir-faire Linux. ...@@ -29,10 +29,10 @@ on behalf of Savoir-faire Linux.
pjnath/src/pjnath-test/concur_test.c | 5 +- pjnath/src/pjnath-test/concur_test.c | 5 +-
pjnath/src/pjnath-test/sess_auth.c | 14 +- pjnath/src/pjnath-test/sess_auth.c | 14 +-
pjnath/src/pjnath-test/stun_sock_test.c | 7 +- pjnath/src/pjnath-test/stun_sock_test.c | 7 +-
pjnath/src/pjnath/ice_session.c | 573 ++++++++++-- pjnath/src/pjnath/ice_session.c | 597 +++++++++++--
pjnath/src/pjnath/ice_strans.c | 743 +++++++++++++--- pjnath/src/pjnath/ice_strans.c | 743 +++++++++++++---
pjnath/src/pjnath/nat_detect.c | 7 +- pjnath/src/pjnath/nat_detect.c | 7 +-
pjnath/src/pjnath/stun_session.c | 15 +- pjnath/src/pjnath/stun_session.c | 19 +-
pjnath/src/pjnath/stun_sock.c | 1081 +++++++++++++++++++---- pjnath/src/pjnath/stun_sock.c | 1081 +++++++++++++++++++----
pjnath/src/pjnath/stun_transaction.c | 3 + pjnath/src/pjnath/stun_transaction.c | 3 +
pjnath/src/pjnath/turn_session.c | 3 +- pjnath/src/pjnath/turn_session.c | 3 +-
...@@ -42,7 +42,7 @@ on behalf of Savoir-faire Linux. ...@@ -42,7 +42,7 @@ on behalf of Savoir-faire Linux.
pjnath/src/pjturn-srv/server.c | 2 +- pjnath/src/pjturn-srv/server.c | 2 +-
pjsip-apps/src/samples/icedemo.c | 116 ++- pjsip-apps/src/samples/icedemo.c | 116 ++-
pjsip/src/pjsua-lib/pjsua_core.c | 2 +- pjsip/src/pjsua-lib/pjsua_core.c | 2 +-
22 files changed, 2523 insertions(+), 418 deletions(-) 22 files changed, 2547 insertions(+), 422 deletions(-)
diff --git a/pjnath/include/pjnath/config.h b/pjnath/include/pjnath/config.h diff --git a/pjnath/include/pjnath/config.h b/pjnath/include/pjnath/config.h
index fc1e27550..9b44c2645 100644 index fc1e27550..9b44c2645 100644
...@@ -683,7 +683,7 @@ index fff4fad26..e7f8b84eb 100644 ...@@ -683,7 +683,7 @@ index fff4fad26..e7f8b84eb 100644
if (status != PJ_SUCCESS && status != PJ_EPENDING) { if (status != PJ_SUCCESS && status != PJ_EPENDING) {
app_perror(" error: server sending data", status); app_perror(" error: server sending data", status);
diff --git a/pjnath/src/pjnath/ice_session.c b/pjnath/src/pjnath/ice_session.c diff --git a/pjnath/src/pjnath/ice_session.c b/pjnath/src/pjnath/ice_session.c
index 2a4125bc5..ba10d42ed 100644 index 2a4125bc5..b10a8fb51 100644
--- a/pjnath/src/pjnath/ice_session.c --- a/pjnath/src/pjnath/ice_session.c
+++ b/pjnath/src/pjnath/ice_session.c +++ b/pjnath/src/pjnath/ice_session.c
@@ -18,6 +18,7 @@ @@ -18,6 +18,7 @@
...@@ -1146,9 +1146,10 @@ index 2a4125bc5..ba10d42ed 100644 ...@@ -1146,9 +1146,10 @@ index 2a4125bc5..ba10d42ed 100644
+ status); + status);
+ } else { + } else {
check->tdata = NULL; check->tdata = NULL;
pjnath_perror(ice->obj_name, "Error sending STUN request", status); - pjnath_perror(ice->obj_name, "Error sending STUN request", status);
- pj_log_pop_indent(); - pj_log_pop_indent();
- return status; - return status;
+ pjnath_perror(ice->obj_name, "Error sending STUN request (perform check)", status);
} }
- -
- check_set_state(ice, check, PJ_ICE_SESS_CHECK_STATE_IN_PROGRESS, - check_set_state(ice, check, PJ_ICE_SESS_CHECK_STATE_IN_PROGRESS,
...@@ -1288,7 +1289,7 @@ index 2a4125bc5..ba10d42ed 100644 ...@@ -1288,7 +1289,7 @@ index 2a4125bc5..ba10d42ed 100644
} }
pj_grp_lock_release(ice->grp_lock); pj_grp_lock_release(ice->grp_lock);
@@ -2181,6 +2449,187 @@ static pj_status_t on_stun_send_msg(pj_stun_session *sess, @@ -2181,6 +2449,205 @@ static pj_status_t on_stun_send_msg(pj_stun_session *sess,
return status; return status;
} }
...@@ -1345,8 +1346,8 @@ index 2a4125bc5..ba10d42ed 100644 ...@@ -1345,8 +1346,8 @@ index 2a4125bc5..ba10d42ed 100644
+ +
+ const pj_ice_sess_cand *rcand = check->rcand; + const pj_ice_sess_cand *rcand = check->rcand;
+ if (rcand->type == PJ_ICE_CAND_TYPE_RELAYED && ( + if (rcand->type == PJ_ICE_CAND_TYPE_RELAYED && (
+ status == PJ_ERRNO_START_STATUS + 104 || status == 130054 /* CONNECTION RESET BY PEER */ || + status == PJ_ERRNO_START_SYS + 104 || status == 130054 /* CONNECTION RESET BY PEER */ ||
+ status == PJ_ERRNO_START_STATUS + 111 /* Connection refused */ + status == PJ_ERRNO_START_SYS + 111 /* Connection refused */
+ )) { + )) {
+ /** + /**
+ * This part of the code is triggered when using ICE over TCP via TURN + * This part of the code is triggered when using ICE over TCP via TURN
...@@ -1362,6 +1363,12 @@ index 2a4125bc5..ba10d42ed 100644 ...@@ -1362,6 +1363,12 @@ index 2a4125bc5..ba10d42ed 100644
+ status); + status);
+ return; + return;
+ } else if (status != PJ_SUCCESS) { + } else if (status != PJ_SUCCESS) {
+ if (rcand->type == PJ_ICE_CAND_TYPE_RELAYED) {
+ char raddr[PJ_INET6_ADDRSTRLEN + 10];
+ PJ_LOG(4, (ice->obj_name,
+ "Connection to TURN (%s) failed with status %u",
+ pj_sockaddr_print(&rcand->addr, raddr, sizeof(raddr), 3), status));
+ }
+ check_set_state(ice, check, PJ_ICE_SESS_CHECK_STATE_FAILED, status); + check_set_state(ice, check, PJ_ICE_SESS_CHECK_STATE_FAILED, status);
+ on_check_complete(ice, check); + on_check_complete(ice, check);
+ return; + return;
...@@ -1394,9 +1401,9 @@ index 2a4125bc5..ba10d42ed 100644 ...@@ -1394,9 +1401,9 @@ index 2a4125bc5..ba10d42ed 100644
+ check->tdata); + check->tdata);
+ +
+ if (rcand->type == PJ_ICE_CAND_TYPE_RELAYED && ( + if (rcand->type == PJ_ICE_CAND_TYPE_RELAYED && (
+ status == PJ_ERRNO_START_STATUS + 104 || status == 130054 || /* CONNECTION RESET BY PEER */ + status == PJ_ERRNO_START_SYS + 104 || status == 130054 || /* CONNECTION RESET BY PEER */
+ status == PJ_ERRNO_START_STATUS + 32 /* EPIPE */ || + status == PJ_ERRNO_START_SYS + 32 /* EPIPE */ ||
+ status == PJ_ERRNO_START_STATUS + 111 /* Connection refused */ + status == PJ_ERRNO_START_SYS + 111 /* Connection refused */
+ )) { + )) {
+ /** + /**
+ * This part of the code is triggered when using ICE over TCP via TURN + * This part of the code is triggered when using ICE over TCP via TURN
...@@ -1413,8 +1420,15 @@ index 2a4125bc5..ba10d42ed 100644 ...@@ -1413,8 +1420,15 @@ index 2a4125bc5..ba10d42ed 100644
+ check_set_state(ice, check, PJ_ICE_SESS_CHECK_STATE_NEEDS_FIRST_PACKET, + check_set_state(ice, check, PJ_ICE_SESS_CHECK_STATE_NEEDS_FIRST_PACKET,
+ status_send_msg); + status_send_msg);
+ } else if (status_send_msg != PJ_SUCCESS) { + } else if (status_send_msg != PJ_SUCCESS) {
+
+ if (rcand->type == PJ_ICE_CAND_TYPE_RELAYED) {
+ char raddr[PJ_INET6_ADDRSTRLEN + 10];
+ PJ_LOG(5, (ice->obj_name,
+ "STUN send message to TURN (%s) failed with status %u",
+ pj_sockaddr_print(&rcand->addr, raddr, sizeof(raddr), 3), status));
+ }
+ check->tdata = NULL; + check->tdata = NULL;
+ pjnath_perror(ice->obj_name, "Error sending STUN request", status_send_msg); + pjnath_perror(ice->obj_name, "Error sending STUN request (on peer connection)", status_send_msg);
+ pj_log_pop_indent(); + pj_log_pop_indent();
+ check_set_state(ice, check, PJ_ICE_SESS_CHECK_STATE_FAILED, status); + check_set_state(ice, check, PJ_ICE_SESS_CHECK_STATE_FAILED, status);
+ on_check_complete(ice, check); + on_check_complete(ice, check);
...@@ -1427,7 +1441,7 @@ index 2a4125bc5..ba10d42ed 100644 ...@@ -1427,7 +1441,7 @@ index 2a4125bc5..ba10d42ed 100644
+ pj_uint8_t transport_id, + pj_uint8_t transport_id,
+ pj_sockaddr_t* remote_addr) + pj_sockaddr_t* remote_addr)
+{ +{
+ // The TCP link is reseted + // The TCP link is reset
+ if (!remote_addr) + if (!remote_addr)
+ return; + return;
+ +
...@@ -1445,6 +1459,11 @@ index 2a4125bc5..ba10d42ed 100644 ...@@ -1445,6 +1459,11 @@ index 2a4125bc5..ba10d42ed 100644
+ +
+ const pj_ice_sess_cand *rcand = check->rcand; + const pj_ice_sess_cand *rcand = check->rcand;
+ if (rcand->type == PJ_ICE_CAND_TYPE_RELAYED) { + if (rcand->type == PJ_ICE_CAND_TYPE_RELAYED) {
+ char raddr[PJ_INET6_ADDRSTRLEN + 10];
+ PJ_LOG(5, (ice->obj_name,
+ "Connection to TURN (%s) is reset",
+ pj_sockaddr_print(&rcand->addr, raddr, sizeof(raddr), 3)));
+
+ check->state = PJ_ICE_SESS_CHECK_STATE_NEEDS_RETRY; + check->state = PJ_ICE_SESS_CHECK_STATE_NEEDS_RETRY;
+ check_set_state(ice, check, + check_set_state(ice, check,
+ PJ_ICE_SESS_CHECK_STATE_NEEDS_RETRY, 120104); + PJ_ICE_SESS_CHECK_STATE_NEEDS_RETRY, 120104);
...@@ -1476,7 +1495,7 @@ index 2a4125bc5..ba10d42ed 100644 ...@@ -1476,7 +1495,7 @@ index 2a4125bc5..ba10d42ed 100644
/* This callback is called when outgoing STUN request completed */ /* This callback is called when outgoing STUN request completed */
static void on_stun_request_complete(pj_stun_session *stun_sess, static void on_stun_request_complete(pj_stun_session *stun_sess,
@@ -2411,7 +2860,9 @@ static void on_stun_request_complete(pj_stun_session *stun_sess, @@ -2411,7 +2878,9 @@ static void on_stun_request_complete(pj_stun_session *stun_sess,
&check->lcand->base_addr, &check->lcand->base_addr,
&check->lcand->base_addr, &check->lcand->base_addr,
pj_sockaddr_get_len(&xaddr->sockaddr), pj_sockaddr_get_len(&xaddr->sockaddr),
...@@ -1487,7 +1506,7 @@ index 2a4125bc5..ba10d42ed 100644 ...@@ -1487,7 +1506,7 @@ index 2a4125bc5..ba10d42ed 100644
if (status != PJ_SUCCESS) { if (status != PJ_SUCCESS) {
check_set_state(ice, check, PJ_ICE_SESS_CHECK_STATE_FAILED, check_set_state(ice, check, PJ_ICE_SESS_CHECK_STATE_FAILED,
status); status);
@@ -2474,11 +2925,7 @@ static void on_stun_request_complete(pj_stun_session *stun_sess, @@ -2474,11 +2943,7 @@ static void on_stun_request_complete(pj_stun_session *stun_sess,
/* Perform 7.1.2.2.2. Updating Pair States. /* Perform 7.1.2.2.2. Updating Pair States.
* This may terminate ICE processing. * This may terminate ICE processing.
*/ */
...@@ -1500,7 +1519,7 @@ index 2a4125bc5..ba10d42ed 100644 ...@@ -1500,7 +1519,7 @@ index 2a4125bc5..ba10d42ed 100644
pj_grp_lock_release(ice->grp_lock); pj_grp_lock_release(ice->grp_lock);
} }
@@ -2673,7 +3120,9 @@ static pj_status_t on_stun_rx_request(pj_stun_session *sess, @@ -2673,9 +3138,13 @@ static pj_status_t on_stun_rx_request(pj_stun_session *sess,
msg_data->has_req_data = PJ_FALSE; msg_data->has_req_data = PJ_FALSE;
/* Send the response */ /* Send the response */
...@@ -1509,9 +1528,14 @@ index 2a4125bc5..ba10d42ed 100644 ...@@ -1509,9 +1528,14 @@ index 2a4125bc5..ba10d42ed 100644
+ pj_stun_session_tp_type(sess) == + pj_stun_session_tp_type(sess) ==
+ PJ_STUN_TP_UDP, + PJ_STUN_TP_UDP,
src_addr, src_addr_len, tdata); src_addr, src_addr_len, tdata);
-
+ if (status == PJ_EBUSY) {
+ PJ_LOG(5, (ice->obj_name, "on_stun_rx_request, PJ_EBUSY"));
+ }
/*
@@ -2794,12 +3243,12 @@ static void handle_incoming_check(pj_ice_sess *ice, * Handling early check.
@@ -2794,12 +3263,12 @@ static void handle_incoming_check(pj_ice_sess *ice,
/* Just get candidate with the highest priority and same transport ID /* Just get candidate with the highest priority and same transport ID
* for the specified component ID in the checklist. * for the specified component ID in the checklist.
*/ */
...@@ -2636,7 +2660,7 @@ index db0de10bc..808342bec 100644 ...@@ -2636,7 +2660,7 @@ index db0de10bc..808342bec 100644
sess->result[test_id].tdata); sess->result[test_id].tdata);
if (status != PJ_SUCCESS) if (status != PJ_SUCCESS)
diff --git a/pjnath/src/pjnath/stun_session.c b/pjnath/src/pjnath/stun_session.c diff --git a/pjnath/src/pjnath/stun_session.c b/pjnath/src/pjnath/stun_session.c
index f2b4f7058..ed17b904f 100644 index f2b4f7058..20a9b1320 100644
--- a/pjnath/src/pjnath/stun_session.c --- a/pjnath/src/pjnath/stun_session.c
+++ b/pjnath/src/pjnath/stun_session.c +++ b/pjnath/src/pjnath/stun_session.c
@@ -49,6 +49,8 @@ struct pj_stun_session @@ -49,6 +49,8 @@ struct pj_stun_session
...@@ -2666,6 +2690,24 @@ index f2b4f7058..ed17b904f 100644 ...@@ -2666,6 +2690,24 @@ index f2b4f7058..ed17b904f 100644
if (grp_lock) { if (grp_lock) {
sess->grp_lock = grp_lock; sess->grp_lock = grp_lock;
@@ -1010,7 +1014,7 @@ PJ_DEF(pj_status_t) pj_stun_session_send_msg( pj_stun_session *sess,
(unsigned)tdata->pkt_size);
if (status != PJ_SUCCESS && status != PJ_EPENDING) {
pj_stun_msg_destroy_tdata(sess, tdata);
- LOG_ERR_(sess, "Error sending STUN request", status);
+ LOG_ERR_(sess, "Error sending STUN request (pj_stun_client_tsx_send_msg)", status);
goto on_return;
}
@@ -1067,7 +1071,7 @@ PJ_DEF(pj_status_t) pj_stun_session_send_msg( pj_stun_session *sess,
if (status != PJ_SUCCESS && status != PJ_EPENDING) {
pj_stun_msg_destroy_tdata(sess, tdata);
- LOG_ERR_(sess, "Error sending STUN request", status);
+ LOG_ERR_(sess, "Error sending STUN request (pj_stun_session_send_msg)", status);
goto on_return;
}
@@ -1538,3 +1542,12 @@ on_return: @@ -1538,3 +1542,12 @@ on_return:
return status; return status;
} }
...@@ -4285,4 +4327,3 @@ index 474a8d07c..9257f07a4 100644 ...@@ -4285,4 +4327,3 @@ index 474a8d07c..9257f07a4 100644
char errmsg[PJ_ERR_MSG_SIZE]; char errmsg[PJ_ERR_MSG_SIZE];
-- --
2.29.2 2.29.2
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment