From 2bbb4778c681a3a398af835b6ee09430e352ab23 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Wed, 18 Jan 2023 11:08:38 -0500 Subject: [PATCH] MT#56420 fix incorrect local socket switching When a receiving socket doesn't match the socket we were expecting, make sure that the receiving socket is actually one of the sockets we want to use at this point before blindly switching the socket. This fixes a race condition after a re-invite: A new set of sockets has been opened, but an old/delayed RTP packet still arrives on one of the old ports. In this case we don't want to switch the local socket. Change-Id: I4e2b87ad608b1a9c6a0bb2eae5c305fd79be70d5 (cherry picked from commit 304a1b11ef6679b4ab133c1c44bb0f180903d948) --- daemon/media_socket.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/daemon/media_socket.c b/daemon/media_socket.c index 06b41ee82..35357db3a 100644 --- a/daemon/media_socket.c +++ b/daemon/media_socket.c @@ -2164,11 +2164,22 @@ update_addr: /* check the destination address of the received packet against what we think our * local interface to use is */ if (phc->mp.stream->selected_sfd && phc->mp.sfd != phc->mp.stream->selected_sfd) { - ilog(LOG_INFO, "Switching local interface to %s", endpoint_print_buf(&phc->mp.sfd->socket.local)); - phc->mp.stream->selected_sfd = phc->mp.sfd; - phc->unkernelize = true; - phc->update = true; - phc->unkernelize_subscriptions = true; + // make sure the new interface/socket is actually one from the list of sockets + // that we intend to use, and not an old one from a previous negotiation + GList *contains = g_queue_find(&phc->mp.stream->sfds, phc->mp.sfd); + if (!contains) + ilog(LOG_INFO | LOG_FLAG_LIMIT, "Not switching from local socket %s to %s (not in list)", + endpoint_print_buf(&phc->mp.stream->selected_sfd->socket.local), + endpoint_print_buf(&phc->mp.sfd->socket.local)); + else { + ilog(LOG_INFO | LOG_FLAG_LIMIT, "Switching local socket from %s to %s", + endpoint_print_buf(&phc->mp.stream->selected_sfd->socket.local), + endpoint_print_buf(&phc->mp.sfd->socket.local)); + phc->mp.stream->selected_sfd = phc->mp.sfd; + phc->unkernelize = true; + phc->update = true; + phc->unkernelize_subscriptions = true; + } } out: