Browse code

tm: Add callid_cseq_matching param

Enable transaction matching using callid and cseq values
instead of via md5 value.

Stefan Mititelu authored on 04/10/2021 14:17:24
Showing 5 changed files
... ...
@@ -47,6 +47,7 @@ struct cfg_group_tm	default_tm_cfg = {
47 47
 	1,	/* ruri_matching */
48 48
 	1,	/* via1_matching */
49 49
 	0,	/* callid_matching */
50
+	0,	/* callid_cseq_matching */
50 51
 	FR_TIME_OUT,	/* fr_timeout */
51 52
 	INV_FR_TIME_OUT,	/* fr_inv_timeout */
52 53
 	INV_FR_TIME_OUT_NEXT, /* fr_inv_timeout_next */
... ...
@@ -115,6 +116,8 @@ cfg_def_t	tm_cfg_def[] = {
115 116
 		"perform first Via header check in transaction matching"},
116 117
 	{"callid_matching",	CFG_VAR_INT | CFG_ATOMIC,	0, 0, 0, 0,
117 118
 		"perform callid check in transaction matching"},
119
+	{"callid_cseq_matching",CFG_VAR_INT | CFG_ATOMIC,	0, 0, 0, 0,
120
+		"perform callid+cseq instead of md5 in transaction matching"},
118 121
 	{"fr_timer",		CFG_VAR_INT | CFG_ATOMIC,	0, 0, timer_fixup, 0,
119 122
 		"timer which hits if no final reply for a request "
120 123
 		"or ACK for a negative INVITE reply arrives "
... ...
@@ -99,6 +99,7 @@ struct cfg_group_tm {
99 99
 	int	ruri_matching;
100 100
 	int	via1_matching;
101 101
 	int	callid_matching;
102
+	int	callid_cseq_matching;
102 103
 	unsigned int	fr_timeout;
103 104
 	unsigned int	fr_inv_timeout;
104 105
 	unsigned int    fr_inv_timeout_next;
... ...
@@ -997,6 +997,29 @@ modparam("tm", "callid_matching", 1)
997 997
 	</example>
998 998
 	</section>
999 999
 
1000
+	<section id="tm.p.callid_cseq_matching">
1001
+		<title><varname>callid_cseq_matching</varname> (int)</title>
1002
+		<para>
1003
+			If set to something other than 0, will do transaction matching 
1004
+			using callid and cseq header values instead of via branch md5 value.
1005
+		</para>
1006
+		<para>
1007
+		<emphasis>
1008
+			Default value is 0.
1009
+		</emphasis>
1010
+		</para>
1011
+		<example>
1012
+		<title>Set <varname>callid_cseq_matching</varname> parameter</title>
1013
+		<programlisting format="linespecific">
1014
+...
1015
+modparam("tm", "callid_cseq_matching", 0)
1016
+...
1017
+
1018
+kamcmd cfg.set_now_int tm callid_cseq_matching 1
1019
+		</programlisting>
1020
+		</example>
1021
+	</section>
1022
+
1000 1023
 	<section id="tm.p.pass_provisional_replies">
1001 1024
 	<title><varname>pass_provisional_replies</varname> (integer)</title>
1002 1025
 	<para>
... ...
@@ -922,8 +922,27 @@ int t_reply_matching( struct sip_msg *p_msg , int *p_branch )
922 922
 	/* all the transactions from the entry are compared */
923 923
 	clist_foreach(hash_bucket, p_cell, next_c){
924 924
 		prefetch_loc_r(p_cell->next_c, 1);
925
-		if ( memcmp(p_cell->md5, loopi,MD5_LEN)!=0)
926
-			continue;
925
+
926
+		if (cfg_get(tm, tm_cfg, callid_cseq_matching)) {
927
+			if (memcmp(p_cell->callid.s + strlen("Call-ID: "), p_msg->callid->body.s, p_msg->callid->body.len) != 0) {
928
+				LM_ERR("t_reply_matching: failed callid matching (instead of md5): %d p_cell=%.*s p_msg=%.*s",
929
+					p_msg->first_line.u.reply.statuscode,
930
+					p_cell->callid.len, p_cell->callid.s,
931
+					p_msg->callid->body.len, p_msg->callid->body.s);
932
+				continue;
933
+			}
934
+
935
+			if (memcmp(p_cell->cseq_n.s + strlen("CSeq: "), get_cseq(p_msg)->number.s, get_cseq(p_msg)->number.len) != 0) {
936
+				LM_ERR("t_reply_matching: failed cseq matching (instead of md5): %d p_cell=%.*s p_msg=%.*s",
937
+					p_msg->first_line.u.reply.statuscode,
938
+					p_cell->cseq_n.len, p_cell->cseq_n.s,
939
+					get_cseq(p_msg)->number.len, get_cseq(p_msg)->number.s);
940
+				continue;
941
+			}
942
+		} else {
943
+			if ( memcmp(p_cell->md5, loopi,MD5_LEN)!=0)
944
+				continue;
945
+		}
927 946
 
928 947
 		/* sanity check ... too high branch ? */
929 948
 		if (unlikely(branch_id>=p_cell->nr_of_outgoings))
... ...
@@ -432,6 +432,7 @@ static param_export_t params[]={
432 432
 	{"ruri_matching",       PARAM_INT, &default_tm_cfg.ruri_matching         },
433 433
 	{"via1_matching",       PARAM_INT, &default_tm_cfg.via1_matching         },
434 434
 	{"callid_matching",     PARAM_INT, &default_tm_cfg.callid_matching       },
435
+	{"callid_cseq_matching",PARAM_INT, &default_tm_cfg.callid_cseq_matching  },
435 436
 	{"fr_timer",            PARAM_INT, &default_tm_cfg.fr_timeout            },
436 437
 	{"fr_inv_timer",        PARAM_INT, &default_tm_cfg.fr_inv_timeout        },
437 438
 	{"wt_timer",            PARAM_INT, &default_tm_cfg.wait_timeout          },