From e59c06210808c2c396e963f4ef6434494d169385 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Fri, 18 Feb 2022 09:03:41 -0500 Subject: [PATCH] TT#14008 allow ICE reset only during an offer Change-Id: Ic2daaeba4d14867ffc96ab13f1d9493082ce0bd2 --- daemon/call.c | 26 ++++++++++++++------------ daemon/ice.c | 10 +++++++--- daemon/janus.c | 2 +- include/ice.h | 2 +- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/daemon/call.c b/daemon/call.c index fb58dab7b..e2bb7917f 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -2464,7 +2464,9 @@ void codecs_offer_answer(struct call_media *media, struct call_media *other_medi /* called with call->master_lock held in W */ -static void __update_init_subscribers(struct call_monologue *ml, GQueue *streams, struct sdp_ng_flags *flags) { +static void __update_init_subscribers(struct call_monologue *ml, GQueue *streams, struct sdp_ng_flags *flags, + enum call_opmode opmode) +{ GList *sl = streams ? streams->head : NULL; // create media iterators for all subscribers @@ -2508,7 +2510,7 @@ static void __update_init_subscribers(struct call_monologue *ml, GQueue *streams } // we are now ready to fire up ICE if so desired and requested - ice_update(media->ice_agent, sp); // sp == NULL: update in case rtcp-mux changed + ice_update(media->ice_agent, sp, opmode == OP_OFFER); // sp == NULL: update in case rtcp-mux changed recording_setup_media(media); t38_gateway_start(media->t38_gateway); @@ -2581,7 +2583,7 @@ static int __media_init_from_flags(struct call_media *other_media, struct call_m return ERROR_NO_ICE_AGENT; if (!other_media->ice_agent) return ERROR_NO_ICE_AGENT; - ice_update(other_media->ice_agent, sp); + ice_update(other_media->ice_agent, sp, false); return 1; // done, continue } @@ -2852,8 +2854,8 @@ int monologue_offer_answer(struct call_monologue *dialogue[2], GQueue *streams, } } - __update_init_subscribers(other_ml, streams, flags); - __update_init_subscribers(monologue, NULL, NULL); + __update_init_subscribers(other_ml, streams, flags, flags ? flags->opmode : OP_OFFER); + __update_init_subscribers(monologue, NULL, NULL, flags ? flags->opmode : OP_OFFER); // set ipv4/ipv6/mixed media stats if (flags && (flags->opmode == OP_OFFER || flags->opmode == OP_ANSWER)) { @@ -3022,7 +3024,7 @@ int monologue_publish(struct call_monologue *ml, GQueue *streams, struct sdp_ng_ if (__init_streams(media, NULL, sp, flags)) return -1; __ice_start(media); - ice_update(media->ice_agent, sp); + ice_update(media->ice_agent, sp, false); } return 0; @@ -3088,8 +3090,8 @@ static int monologue_subscribe_request1(struct call_monologue *src_ml, struct ca __add_subscription(dst_ml, src_ml, false, idx_diff); - __update_init_subscribers(src_ml, NULL, NULL); - __update_init_subscribers(dst_ml, NULL, NULL); + __update_init_subscribers(src_ml, NULL, NULL, flags->opmode); + __update_init_subscribers(dst_ml, NULL, NULL, flags->opmode); return 0; } @@ -3172,13 +3174,13 @@ int monologue_subscribe_answer(struct call_monologue *dst_ml, struct sdp_ng_flag MEDIA_SET(dst_media, INITIALIZED); } - __update_init_subscribers(dst_ml, streams, flags); + __update_init_subscribers(dst_ml, streams, flags, flags->opmode); dialogue_unkernelize(dst_ml); for (GList *l = dst_ml->subscriptions.head; l; l = l->next) { struct call_subscription *cs = l->data; struct call_monologue *src_ml = cs->monologue; - __update_init_subscribers(src_ml, NULL, NULL); + __update_init_subscribers(src_ml, NULL, NULL, flags->opmode); dialogue_unkernelize(src_ml); } @@ -3194,8 +3196,8 @@ int monologue_unsubscribe(struct call_monologue *dst_ml, struct sdp_ng_flags *fl __unsubscribe_one_link(dst_ml, l); - __update_init_subscribers(dst_ml, NULL, NULL); - __update_init_subscribers(src_ml, NULL, NULL); + __update_init_subscribers(dst_ml, NULL, NULL, flags->opmode); + __update_init_subscribers(src_ml, NULL, NULL, flags->opmode); dialogue_unkernelize(src_ml); dialogue_unkernelize(dst_ml); diff --git a/daemon/ice.c b/daemon/ice.c index 5f81efa81..ca1a8592a 100644 --- a/daemon/ice.c +++ b/daemon/ice.c @@ -314,7 +314,7 @@ void ice_restart(struct ice_agent *ag) { } /* called with the call lock held in W, hence agent doesn't need to be locked */ -void ice_update(struct ice_agent *ag, struct stream_params *sp) { +void ice_update(struct ice_agent *ag, struct stream_params *sp, bool allow_reset) { GList *l, *k; struct ice_candidate *cand, *dup; struct call_media *media; @@ -335,8 +335,12 @@ void ice_update(struct ice_agent *ag, struct stream_params *sp) { __role_change(ag, MEDIA_ISSET(media, ICE_CONTROLLING)); if (sp) { - if (ice_is_restart(ag, sp)) - __ice_restart(ag); + if (ice_is_restart(ag, sp)) { + if (!allow_reset) + ilog(LOG_WARN, "ICE restart detected, but reset not allowed at this point"); + else + __ice_restart(ag); + } /* update remote info */ if (sp->ice_ufrag.s) diff --git a/daemon/janus.c b/daemon/janus.c index 6d90cff1f..367b117c9 100644 --- a/daemon/janus.c +++ b/daemon/janus.c @@ -1345,7 +1345,7 @@ const char *janus_trickle(JsonReader *reader, struct janus_session *session, uin str_init(&sp.ice_ufrag, (char *) ufrag); g_queue_push_tail(&sp.ice_candidates, &cand); - ice_update(media->ice_agent, &sp); + ice_update(media->ice_agent, &sp, false); g_queue_clear(&sp.ice_candidates); } diff --git a/include/ice.h b/include/ice.h index 7885e6bf3..d064c8930 100644 --- a/include/ice.h +++ b/include/ice.h @@ -153,7 +153,7 @@ bool ice_has_related(enum ice_candidate_type); void ice_foundation(str *); void ice_agent_init(struct ice_agent **agp, struct call_media *media); -void ice_update(struct ice_agent *, struct stream_params *); +void ice_update(struct ice_agent *, struct stream_params *, bool allow_restart); void ice_shutdown(struct ice_agent **); void ice_restart(struct ice_agent *);