From e443614d1651461a70c5f6855a4ac9656be7d5cb Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Tue, 12 Oct 2021 15:38:29 -0400 Subject: [PATCH] TT#145450 cache last used PT to avoid repeated bsearch Change-Id: I4d7d11f40a9c4225418b8f9835a8f2f5047dcdd2 --- kernel-module/xt_RTPENGINE.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/kernel-module/xt_RTPENGINE.c b/kernel-module/xt_RTPENGINE.c index 8d6fa1188..e7d819b3f 100644 --- a/kernel-module/xt_RTPENGINE.c +++ b/kernel-module/xt_RTPENGINE.c @@ -299,6 +299,7 @@ struct rtpengine_target { atomic_t refcnt; uint32_t table; struct rtpengine_target_info target; + unsigned int last_pt; // index into payload_types[] struct rtpengine_stats_a stats; struct rtpengine_rtp_stats_a rtp_stats[RTPE_NUM_PAYLOAD_TYPES]; @@ -4184,11 +4185,18 @@ static int rtp_payload_match(const void *a, const void *b) { } #endif -static inline int rtp_payload_type(const struct rtp_header *hdr, const struct rtpengine_target_info *tg) { +static inline int rtp_payload_type(const struct rtp_header *hdr, const struct rtpengine_target_info *tg, + int *last_pt) +{ struct rtpengine_payload_type pt; const struct rtpengine_payload_type *match; pt.pt_num = hdr->m_pt & 0x7f; + if (*last_pt < tg->num_payload_types) { + match = &tg->payload_types[*last_pt]; + if (rtp_payload_match(match, &pt) == 0) + goto found; + } #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,0,0) match = bsearch(&pt, tg->payload_types, tg->num_payload_types, sizeof(pt), rtp_payload_match); #else @@ -4197,11 +4205,12 @@ static inline int rtp_payload_type(const struct rtp_header *hdr, const struct rt goto found; } match = NULL; -found: #endif if (!match) return -1; - return match - tg->payload_types; +found: + *last_pt = match - tg->payload_types; + return *last_pt; } static struct sk_buff *intercept_skb_copy(struct sk_buff *oskb, const struct re_address *src) { @@ -4441,7 +4450,7 @@ src_check_ok: goto not_rtp; } - rtp_pt_idx = rtp_payload_type(rtp.header, &g->target); + rtp_pt_idx = rtp_payload_type(rtp.header, &g->target, &g->last_pt); // Pass to userspace if SSRC has changed. errstr = "SSRC mismatch";