From 5853dcb41b92728fa75c773092696eae9815b9f2 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Wed, 10 Sep 2025 11:29:53 -0400 Subject: [PATCH] MT#63317 move confirmed/kernel flags to stream_fd The key for an in-kernel stream is a local port, so it is really the socket (port) that gets pushed into the kernel, not the packet_stream. Similar to the "confirmed" state, as we expect each socket to only have one peer address/port. Change-Id: I34fef771cd8b01701196ffb77e17fcd229c86550 --- daemon/call.c | 2 +- daemon/call_interfaces.c | 6 ++++-- daemon/media_socket.c | 31 +++++++++++++++++-------------- daemon/redis.c | 2 -- include/call.h | 4 ++-- include/media_socket.h | 3 +++ 6 files changed, 27 insertions(+), 21 deletions(-) diff --git a/daemon/call.c b/daemon/call.c index abd3ed245..60c0b3dcc 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -1168,7 +1168,7 @@ enum call_stream_state call_stream_state_machine(struct packet_stream *ps) { mutex_unlock(&ps->lock); } - if (PS_ISSET(ps, PIERCE_NAT) && PS_ISSET(ps, FILLED) && !PS_ISSET(ps, CONFIRMED)) { + if (PS_ISSET(ps, PIERCE_NAT) && PS_ISSET(ps, FILLED) && !ps->selected_sfd->confirmed) { for (__auto_type l = ps->sfds.head; l; l = l->next) { static const str fake_rtp = STR_CONST("\x80\x7f\xff\xff\x00\x00\x00\x00" "\x00\x00\x00\x00"); diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index 6a8b77804..b71e9be45 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -2799,8 +2799,10 @@ static void ng_stats_stream(ng_command_ctx_t *ctx, parser_arg list, const struct BF_PS("RTCP", RTCP); BF_PS("fallback RTCP", FALLBACK_RTCP); BF_PS("filled", FILLED); - BF_PS("confirmed", CONFIRMED); - BF_PS("kernelized", KERNELIZED); + if (ps->selected_sfd && ps->selected_sfd->confirmed) + parser->list_add_string(flags, "confirmed"); + if (ps->selected_sfd && ps->selected_sfd->kernelized) + parser->list_add_string(flags, "kernelized"); BF_PS("no kernel support", NO_KERNEL_SUPPORT); BF_PS("DTLS fingerprint verified", FINGERPRINT_VERIFIED); BF_PS("strict source address", STRICT_SOURCE); diff --git a/daemon/media_socket.c b/daemon/media_socket.c index cbb2dd314..eea8eabf3 100644 --- a/daemon/media_socket.c +++ b/daemon/media_socket.c @@ -1875,9 +1875,11 @@ static void kernelize(struct packet_stream *stream) { LOCK(&stream->lock); - // set flag, return if set already - if (PS_SET(stream, KERNELIZED)) - return; + if (stream->selected_sfd) { + if (stream->selected_sfd->kernelized) + return; + stream->selected_sfd->kernelized = true; + } if (call->recording != NULL && !selected_recording_method->kernel_support) goto no_kernel; @@ -1987,8 +1989,7 @@ struct ssrc_entry_call *__hunt_ssrc_ctx(uint32_t ssrc, struct ssrc_entry_call *l void __unkernelize(struct packet_stream *p, const char *reason) { if (!p->selected_sfd) return; - - if (!PS_ISSET(p, KERNELIZED)) + if (!p->selected_sfd->kernelized) return; if (kernel.is_open && !PS_ISSET(p, NO_KERNEL_SUPPORT)) { @@ -2000,7 +2001,7 @@ void __unkernelize(struct packet_stream *p, const char *reason) { kernel_del_stream(&cmd); } - PS_CLEAR(p, KERNELIZED); + p->selected_sfd->kernelized = false; PS_CLEAR(p, NO_KERNEL_SUPPORT); } @@ -2018,11 +2019,12 @@ void __reset_sink_handlers(struct packet_stream *ps) { void __stream_unconfirm(struct packet_stream *ps, const char *reason) { __unkernelize(ps, reason); if (!MEDIA_ISSET(ps->media, ASYMMETRIC)) { - if (ps->selected_sfd) + if (ps->selected_sfd) { ilog(LOG_DEBUG | LOG_FLAG_LIMIT, "Unconfirming peer address for local %s (%s)", endpoint_print_buf(&ps->selected_sfd->socket.local), reason); - PS_CLEAR(ps, CONFIRMED); + ps->selected_sfd->confirmed = false; + } } __reset_sink_handlers(ps); } @@ -2840,7 +2842,7 @@ static bool media_packet_address_check(struct packet_handler_ctx *phc) // work around this by detecting this situation and ignoring the packet for // confirmation purposes when needed. This is regardless of whether rtcp-mux // is enabled or not. - if (!PS_ISSET(phc->mp.stream, CONFIRMED) && PS_ISSET(phc->mp.stream, RTP)) { + if (!phc->mp.sfd->confirmed && PS_ISSET(phc->mp.stream, RTP)) { if (rtcp_demux_is_rtcp(&phc->s)) { ilog(LOG_DEBUG | LOG_FLAG_LIMIT, "Ignoring stray RTCP packet from %s%s%s for " "peer address confirmation purposes", @@ -2857,18 +2859,19 @@ static bool media_packet_address_check(struct packet_handler_ctx *phc) update_endpoint = &phc->mp.stream->learned_endpoint; if (phc->mp.stream->el_flags == EL_OFF) - PS_SET(phc->mp.stream, CONFIRMED); + phc->mp.sfd->confirmed = true; /* confirm sinks for unidirectional streams in order to kernelize */ if (MEDIA_ISSET(phc->mp.media, UNIDIRECTIONAL)) { for (__auto_type l = phc->sinks->head; l; l = l->next) { struct sink_handler *sh = l->data; - PS_SET(sh->sink, CONFIRMED); + if (sh->sink->selected_sfd) + sh->sink->selected_sfd->confirmed = true; } } /* if we have already updated the endpoint in the past ... */ - if (PS_ISSET(phc->mp.stream, CONFIRMED)) { + if (phc->mp.sfd->confirmed) { /* see if we need to compare the source address with the known endpoint */ if (PS_ISSET2(phc->mp.stream, STRICT_SOURCE, MEDIA_HANDOVER)) { endpoint_t endpoint = phc->mp.fsin; @@ -2971,7 +2974,7 @@ confirm_now: ilog(LOG_INFO, "Confirmed peer address as %s%s%s", FMT_M(endpoint_print_buf(use_endpoint_confirm))); - PS_SET(phc->mp.stream, CONFIRMED); + phc->mp.sfd->confirmed = true; update_peerinfo: // if we're during the wait time, check the received address against the previously @@ -3024,7 +3027,7 @@ static void media_packet_kernel_check(struct packet_handler_ctx *phc) { return; } - if (!PS_ISSET(phc->mp.stream, CONFIRMED)) { + if (!phc->mp.sfd->confirmed) { __C_DBG("stream %s%s%s not CONFIRMED", FMT_M(endpoint_print_buf(&phc->mp.stream->endpoint))); return; } diff --git a/daemon/redis.c b/daemon/redis.c index 638b3bf03..0a877bbe1 100644 --- a/daemon/redis.c +++ b/daemon/redis.c @@ -1515,8 +1515,6 @@ static int redis_streams(call_t *c, struct redis_list *streams) { return -1; streams->ptrs[i] = ps; - - PS_CLEAR(ps, KERNELIZED); } return 0; } diff --git a/include/call.h b/include/call.h index 666cecf1c..e895e72ff 100644 --- a/include/call.h +++ b/include/call.h @@ -164,8 +164,8 @@ enum { #define PS_FLAG_FALLBACK_RTCP (1LL << 18) #define PS_FLAG_RECEIVED (1LL << 19) #define PS_FLAG_FILLED (1LL << 20) -#define PS_FLAG_CONFIRMED (1LL << 21) -#define PS_FLAG_KERNELIZED (1LL << 22) +// unused (1LL << 21) +// unused (1LL << 22) #define PS_FLAG_NO_KERNEL_SUPPORT (1LL << 23) #define PS_FLAG_UNUSED (1LL << 24) #define PS_FLAG_FINGERPRINT_VERIFIED (1LL << 25) diff --git a/include/media_socket.h b/include/media_socket.h index 49671728c..c1587697f 100644 --- a/include/media_socket.h +++ b/include/media_socket.h @@ -241,6 +241,9 @@ struct stream_fd { int error_strikes; int active_read_events; struct poller *poller; + + bool kernelized:1, + confirmed:1; }; struct sink_attrs {