From f1b06a25ce772b8af3c4a6d570efe2f2dfafeb6f Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Tue, 24 Sep 2024 15:37:05 +0200 Subject: [PATCH] MT#61110 cfgutils: allow lock_set_size > 14 Change-Id: I9209a6b7037d008770ea9ff95e35f87277e85073 (cherry picked from commit 211cf0cd1d7d25cecee219c76656ebeb1c658113) (cherry picked from commit 91c5a443876a19af502d39d0e28f812d27510b89) (cherry picked from commit 3583d6d5ff6f087392a7c4386668f57b5e281427) (cherry picked from commit 456d126f426d91a3a7a774e596c7057019b1d1df) (cherry picked from commit 089e420e1db95b78209f4951053139999600cadd) --- debian/patches/series | 1 + .../cfgutils-allow-lock_set_size-14.patch | 97 +++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 debian/patches/sipwise/cfgutils-allow-lock_set_size-14.patch diff --git a/debian/patches/series b/debian/patches/series index 1af93eb8b..8f088c3ad 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -59,6 +59,7 @@ sipwise/rtpengine-set-mime-content-length.patch sipwise/presence_vqr.patch sipwise/dialog-dlg_get_ttag.patch sipwise/app_lua_sr-support-second-str-for-cfgutils-lock.patch +sipwise/cfgutils-allow-lock_set_size-14.patch ### active development # ### Don't just put stuff in any order diff --git a/debian/patches/sipwise/cfgutils-allow-lock_set_size-14.patch b/debian/patches/sipwise/cfgutils-allow-lock_set_size-14.patch new file mode 100644 index 000000000..7538431f1 --- /dev/null +++ b/debian/patches/sipwise/cfgutils-allow-lock_set_size-14.patch @@ -0,0 +1,97 @@ +From: Victor Seva +Date: Tue, 24 Sep 2024 15:33:25 +0200 +Subject: cfgutils: allow lock_set_size > 14 + +--- + src/modules/cfgutils/cfgutils.c | 56 ++++++++++++++++++++++++++++++++++++++--- + 1 file changed, 52 insertions(+), 4 deletions(-) + +diff --git a/src/modules/cfgutils/cfgutils.c b/src/modules/cfgutils/cfgutils.c +index f20f3bb..aebc7b7 100644 +--- a/src/modules/cfgutils/cfgutils.c ++++ b/src/modules/cfgutils/cfgutils.c +@@ -4,6 +4,7 @@ + * Copyright (C) 2007 BASIS AudioNet GmbH + * Copyright (C) 2004 FhG + * Copyright (C) 2005-2006 Voice Sistem S.R.L. ++ * Copyright (C) 2024 Victor Seva (Sipwise) + * + * This file is part of Kamailio, a free SIP server. + * +@@ -674,6 +675,53 @@ static int ki_shm_summary(sip_msg_t *msg) + return 1; + } + ++/* ++ * case insensitive hashing ++ * - s1 - str to hash ++ * - s2 - optional - continue hashing over s2 ++ * - size - optional - size of hash table (must be power of 1); if set (!=0), ++ * instead of hash id, returned value is slot index ++ * return computed hash id or hash table slot index ++ */ ++static inline unsigned int cfg_case_hash(str *s1, str *s2, unsigned int size) ++{ ++ char *p, *end; ++ register unsigned long v; ++ register unsigned long h; ++ ++ h = 0; ++ ++ end = s1->s + s1->len; ++ for(p = s1->s; p <= (end - 4); p += 4) { ++ v = (ch_icase(*p) << 24) + (ch_icase(p[1]) << 16) ++ + (ch_icase(p[2]) << 8) + ch_icase(p[3]); ++ ch_h_inc; ++ } ++ v = 0; ++ for(; p < end; p++) { ++ v <<= 8; ++ v += ch_icase(*p); ++ } ++ ch_h_inc; ++ ++ if(s2) { ++ end = s2->s + s2->len; ++ for(p = s2->s; p <= (end - 4); p += 4) { ++ v = (ch_icase(*p) << 24) + (ch_icase(p[1]) << 16) ++ + (ch_icase(p[2]) << 8) + ch_icase(p[3]); ++ ch_h_inc; ++ } ++ v = 0; ++ for(; p < end; p++) { ++ v <<= 8; ++ v += ch_icase(*p); ++ } ++ ch_h_inc; ++ } ++ h = ((h) + (h >> 11)) + ((h >> 13) + (h >> 23)); ++ return size ? ((h) & (size - 1)) : h; ++} ++ + static int cfg_lock_helper(str *lkey, str *lkey2, int mode) + { + unsigned int pos; +@@ -695,7 +743,7 @@ static int cfg_lock_helper(str *lkey, str *lkey2, int mode) + } + return -1; + } +- pos = core_case_hash(lkey, key2, _cfg_lock_size); ++ pos = cfg_case_hash(lkey, key2, _cfg_lock_size); + if(key2) { + LM_DBG("cfg_lock mode %d on %u (%.*s %.*s)\n", mode, pos, STR_FMT(lkey), + STR_FMT(lkey2)); +@@ -908,10 +956,10 @@ static int mod_init(void) + return -1; + } + if(_cfg_lock_size > 0) { +- if(_cfg_lock_size > 14) { +- LM_WARN("lock set size too large (%d), making it 14\n", ++ if(_cfg_lock_size > 30) { ++ LM_WARN("lock set size too large (%d), making it 30\n", + _cfg_lock_size); +- _cfg_lock_size = 14; ++ _cfg_lock_size = 30; + } + _cfg_lock_size = 1 << _cfg_lock_size; + _cfg_lock_set = lock_set_alloc(_cfg_lock_size);