Module: kamailio
Branch: master
Commit: 33b80fcc4d84f955b29bd65bccee9ef2a62e7000
URL: 
https://github.com/kamailio/kamailio/commit/33b80fcc4d84f955b29bd65bccee9ef2a62e7000

Author: Henning Westerholt <[email protected]>
Committer: Henning Westerholt <[email protected]>
Date: 2025-06-18T11:08:12Z

rtpengine: improve randomness of cookie by using PNRG and random sequence 
numbers

---

Modified: src/modules/rtpengine/rtpengine.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/33b80fcc4d84f955b29bd65bccee9ef2a62e7000.diff
Patch: 
https://github.com/kamailio/kamailio/commit/33b80fcc4d84f955b29bd65bccee9ef2a62e7000.patch

---

diff --git a/src/modules/rtpengine/rtpengine.c 
b/src/modules/rtpengine/rtpengine.c
index 292843302fe..e7d6cf9d5b9 100644
--- a/src/modules/rtpengine/rtpengine.c
+++ b/src/modules/rtpengine/rtpengine.c
@@ -83,6 +83,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"
@@ -327,7 +328,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;
@@ -3028,6 +3029,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;
 
@@ -3038,7 +3041,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) {
@@ -3060,7 +3063,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(
@@ -3171,7 +3176,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;
 }

_______________________________________________
Kamailio - Development Mailing List -- [email protected]
To unsubscribe send an email to [email protected]
Important: keep the mailing list in the recipients, do not reply only to the 
sender!

Reply via email to