Module: kamailio Branch: 5.8 Commit: ca9a5c4ca7c8d9c2d23a2821eeb85dbd7afd3389 URL: https://github.com/kamailio/kamailio/commit/ca9a5c4ca7c8d9c2d23a2821eeb85dbd...
Author: Henning Westerholt hw@gilawa.com Committer: Xenofon Karamanos 22965395+xkaraman@users.noreply.github.com Date: 2025-06-26T10:53:44Z
rtpengine: improve randomness of cookie by using PNRG and random sequence numbers
(cherry picked from commit 33b80fcc4d84f955b29bd65bccee9ef2a62e7000)
---
Modified: src/modules/rtpengine/rtpengine.c
---
Diff: https://github.com/kamailio/kamailio/commit/ca9a5c4ca7c8d9c2d23a2821eeb85dbd... Patch: https://github.com/kamailio/kamailio/commit/ca9a5c4ca7c8d9c2d23a2821eeb85dbd...
---
diff --git a/src/modules/rtpengine/rtpengine.c b/src/modules/rtpengine/rtpengine.c index 81456c4faea..897f847d1b0 100644 --- a/src/modules/rtpengine/rtpengine.c +++ b/src/modules/rtpengine/rtpengine.c @@ -81,6 +81,7 @@ #include "../../core/char_msg_val.h" #include "../../core/utils/srjson.h" #include "../../core/cfg/cfg_struct.h" +#include "../../core/rand/fastrand.h" #include "../../modules/tm/tm_load.h" #include "../../modules/crypto/api.h" #include "../../modules/lwsc/api.h" @@ -275,7 +276,7 @@ static void parse_call_stats(bencode_item_t *, struct sip_msg *); static int control_cmd_tos = -1; static int rtpengine_allow_op = 0; static struct rtpp_node **queried_nodes_ptr = NULL; -static pid_t mypid; + static unsigned int myseqn = 0; static str extra_id_pv_param = {NULL, 0}; static char *setid_avp_param = NULL; @@ -2476,6 +2477,8 @@ static int mos_label_stats_parse(struct minmax_mos_label_stats *mmls)
static int child_init(int rank) { + pid_t mypid = 0; + if(!rtpp_set_list) return 0;
@@ -2486,7 +2489,7 @@ static int child_init(int rank)
if(rank == PROC_MAIN) { if(rtpengine_dtmf_event_sock.len > 0) { - LM_DBG("Register RTPENGINE DTMF WORKER %d\n", mypid); + LM_DBG("Register RTPENGINE DTMF WORKER %d\n", getpid()); /* fork worker process */ mypid = fork_process(PROC_RPC, "RTPENGINE DTMF WORKER", 1); if(mypid < 0) { @@ -2508,7 +2511,9 @@ static int child_init(int rank) return 0; }
- mypid = getpid(); + /* random start value for for cookie sequence number */ + myseqn = fastrand(); + LM_ERR("myseqn %u\n", myseqn);
// vector of pointers to queried nodes queried_nodes_ptr = (struct rtpp_node **)pkg_malloc( @@ -2619,7 +2624,7 @@ static char *gencookie(void) { static char cook[34];
- snprintf(cook, 34, "%d_%d_%u ", server_id, (int)mypid, myseqn); + snprintf(cook, 34, "%d_%u_%u ", server_id, fastrand(), myseqn); myseqn++; return cook; }