Browse code

core: remove syn_branch functionality for calculating Via branch parameter

* remove syn_branch parameter and functionality from core and tm module for
calculating the Via branch parameter
* reported from Richard Brady, rnbrady at gmail dot com to sr-dev
* kamailio is not standard compliant with this setting enabled (RFC 3261,
17.2.3 and 16.11) for stateless forwarding of replies
* the performance reason that motivated this functionality are today not
valid anymore, even embedded systems have more than enough power to
calculate MD5 and other modules uses more expensive operations anyway
* adapt a bunch of example and test configuration that used this parameter,
it has been also removed from the core cookbook wiki

Henning Westerholt authored on 24/05/2013 13:38:03
Showing 14 changed files
... ...
@@ -393,7 +393,6 @@ CHILDREN children
393 393
 SOCKET_WORKERS socket_workers
394 394
 CHECK_VIA	check_via
395 395
 PHONE2TEL	phone2tel
396
-SYN_BRANCH syn_branch
397 396
 MEMLOG		"memlog"|"mem_log"
398 397
 MEMDBG		"memdbg"|"mem_dbg"
399 398
 MEMSUM		"mem_summary"
... ...
@@ -792,7 +791,6 @@ IMPORTFILE      "import_file"
792 792
 <INITIAL>{SOCKET_WORKERS}	{ count(); yylval.strval=yytext; return SOCKET_WORKERS; }
793 793
 <INITIAL>{CHECK_VIA}	{ count(); yylval.strval=yytext; return CHECK_VIA; }
794 794
 <INITIAL>{PHONE2TEL}	{ count(); yylval.strval=yytext; return PHONE2TEL; }
795
-<INITIAL>{SYN_BRANCH}	{ count(); yylval.strval=yytext; return SYN_BRANCH; }
796 795
 <INITIAL>{MEMLOG}	{ count(); yylval.strval=yytext; return MEMLOG; }
797 796
 <INITIAL>{MEMDBG}	{ count(); yylval.strval=yytext; return MEMDBG; }
798 797
 <INITIAL>{MEMSUM}	{ count(); yylval.strval=yytext; return MEMSUM; }
... ...
@@ -440,7 +440,6 @@ extern char *finame;
440 440
 %token SOCKET_WORKERS
441 441
 %token CHECK_VIA
442 442
 %token PHONE2TEL
443
-%token SYN_BRANCH
444 443
 %token MEMLOG
445 444
 %token MEMDBG
446 445
 %token MEMSUM
... ...
@@ -958,8 +957,6 @@ assign_stm:
958 958
 	| CHECK_VIA EQUAL error { yyerror("boolean value expected"); }
959 959
 	| PHONE2TEL EQUAL NUMBER { phone2tel=$3; }
960 960
 	| PHONE2TEL EQUAL error { yyerror("boolean value expected"); }
961
-	| SYN_BRANCH EQUAL NUMBER { syn_branch=$3; }
962
-	| SYN_BRANCH EQUAL error { yyerror("boolean value expected"); }
963 961
 	| MEMLOG EQUAL intno { default_core_cfg.memlog=$3; }
964 962
 	| MEMLOG EQUAL error { yyerror("int value expected"); }
965 963
 	| MEMDBG EQUAL intno { default_core_cfg.memdbg=$3; }
... ...
@@ -46,7 +46,6 @@ sip_warning=no
46 46
 children=64
47 47
 #!endif
48 48
 
49
-syn_branch=0
50 49
 # Locks all ser pages into memory making it unswappable (in general one 
51 50
 # doesn't want his sip proxy swapped out )
52 51
 mlock_pages=yes
... ...
@@ -45,8 +45,6 @@ tcp_connection_lifetime=3604
45 45
 tcp_accept_no_cl=yes
46 46
 tcp_rd_buf_size=16384
47 47
 
48
-syn_branch=0
49
-
50 48
 #!ifdef LOCAL_TEST_RUN
51 49
 debug=2
52 50
 mpath="modules"
... ...
@@ -535,31 +535,23 @@ int forward_request(struct sip_msg* msg, str* dst, unsigned short port,
535 535
 		}
536 536
 	}/* dst */
537 537
 	send_info->send_flags=msg->fwd_send_flags;
538
-	/* calculate branch for outbound request;  if syn_branch is turned off,
538
+	/* calculate branch for outbound request;
539 539
 	   calculate is from transaction key, i.e., as an md5 of From/To/CallID/
540 540
 	   CSeq exactly the same way as TM does; good for reboot -- than messages
541 541
 	   belonging to transaction lost due to reboot will still be forwarded
542 542
 	   with the same branch parameter and will be match-able downstream
543
-	
544
-	   if it is turned on, we don't care about reboot; we simply put a simple
545
-	   value in there; better for performance
546 543
 	*/
547
-	if (syn_branch ) {
548
-	        memcpy(msg->add_to_branch_s, "z9hG4bKcydzigwkX", 16);
549
-		msg->add_to_branch_len=16;
550
-	} else {
551
-		if (!char_msg_val( msg, md5 )) 	{ /* parses transaction key */
552
-			LOG(L_ERR, "ERROR: forward_request: char_msg_val failed\n");
553
-			ret=E_UNSPEC;
554
-			goto error;
555
-		}
556
-		msg->hash_index=hash( msg->callid->body, get_cseq(msg)->number);
557
-		if (!branch_builder( msg->hash_index, 0, md5, 0 /* 0-th branch */,
558
-					msg->add_to_branch_s, &msg->add_to_branch_len )) {
559
-			LOG(L_ERR, "ERROR: forward_request: branch_builder failed\n");
560
-			ret=E_UNSPEC;
561
-			goto error;
562
-		}
544
+	if (!char_msg_val( msg, md5 )) 	{ /* parses transaction key */
545
+		LOG(L_ERR, "ERROR: forward_request: char_msg_val failed\n");
546
+		ret=E_UNSPEC;
547
+		goto error;
548
+	}
549
+	msg->hash_index=hash( msg->callid->body, get_cseq(msg)->number);
550
+	if (!branch_builder( msg->hash_index, 0, md5, 0 /* 0-th branch */,
551
+				msg->add_to_branch_s, &msg->add_to_branch_len )) {
552
+		LOG(L_ERR, "ERROR: forward_request: branch_builder failed\n");
553
+		ret=E_UNSPEC;
554
+		goto error;
563 555
 	}
564 556
 	/* try to send the message until success or all the ips are exhausted
565 557
 	 *  (if dns lookup is performed && the dns cache used ) */
... ...
@@ -111,7 +111,6 @@ extern int dont_daemonize;
111 111
 extern int check_via;
112 112
 extern int phone2tel;
113 113
 extern int received_dns;
114
-extern int syn_branch;
115 114
 /* extern int process_no; */
116 115
 extern int child_rank;
117 116
 extern int sip_warning;
... ...
@@ -383,8 +383,6 @@ int config_check = 0;
383 383
 int check_via =  0;
384 384
 /* translate user=phone URIs to TEL URIs */
385 385
 int phone2tel = 1;
386
-/* shall use stateful synonym branches? faster but not reboot-safe */
387
-int syn_branch = 1;
388 386
 /* debugging level for timer debugging */
389 387
 int timerlog = L_WARN;
390 388
 /* should replies include extensive warnings? by default no,
... ...
@@ -256,27 +256,25 @@ static inline void init_synonym_id( struct cell *t )
256 256
 	char *c;
257 257
 	unsigned int myrand;
258 258
 
259
-	if (!syn_branch) {
260
-		p_msg=t->uas.request;
261
-		if (p_msg) {
262
-			/* char value of a proxied transaction is
263
-			   calculated out of header-fields forming
264
-			   transaction key
265
-			*/
266
-			char_msg_val( p_msg, t->md5 );
267
-		} else {
268
-			/* char value for a UAC transaction is created
269
-			   randomly -- UAC is an originating stateful element 
270
-			   which cannot be refreshed, so the value can be
271
-			   anything
272
-			*/
273
-			/* HACK : not long enough */
274
-			myrand=rand();
275
-			c=t->md5;
276
-			size=MD5_LEN;
277
-			memset(c, '0', size );
278
-			int2reverse_hex( &c, &size, myrand );
279
-		}
259
+	p_msg=t->uas.request;
260
+	if (p_msg) {
261
+		/* char value of a proxied transaction is
262
+		   calculated out of header-fields forming
263
+		   transaction key
264
+		*/
265
+		char_msg_val( p_msg, t->md5 );
266
+	} else {
267
+		/* char value for a UAC transaction is created
268
+		   randomly -- UAC is an originating stateful element
269
+		   which cannot be refreshed, so the value can be
270
+		   anything
271
+		*/
272
+		/* HACK : not long enough */
273
+		myrand=rand();
274
+		c=t->md5;
275
+		size=MD5_LEN;
276
+		memset(c, '0', size );
277
+		int2reverse_hex( &c, &size, myrand );
280 278
 	}
281 279
 }
282 280
 
... ...
@@ -309,10 +307,9 @@ struct cell*  build_cell( struct sip_msg* p_msg )
309 309
 	sr_xavp_t** xold;
310 310
 #endif
311 311
 
312
-	/* allocs a new cell */
313
-	/* if syn_branch==0 add space for md5 (MD5_LEN -sizeof(struct cell.md5)) */
312
+	/* allocs a new cell, add space for md5 (MD5_LEN - sizeof(struct cell.md5)) */
314 313
 	new_cell = (struct cell*)shm_malloc( sizeof( struct cell )+
315
-			((MD5_LEN-sizeof(((struct cell*)0)->md5))&((syn_branch!=0)-1)) );
314
+			MD5_LEN-sizeof(((struct cell*)0)->md5) );
316 315
 	if  ( !new_cell ) {
317 316
 		ser_error=E_OUT_OF_MEM;
318 317
 		return NULL;
... ...
@@ -455,8 +455,8 @@ typedef struct cell
455 455
 	 /* The route to take for each downstream branch separately */
456 456
 	unsigned short on_branch;
457 457
 
458
-	/* place holder for MD5checksum  (meaningful only if syn_branch=0) */
459
-	char md5[0]; /* if syn_branch==0 then MD5_LEN bytes are extra alloc'ed*/
458
+	/* place holder for MD5checksum, MD5_LEN bytes are extra alloc'ed */
459
+	char md5[0];
460 460
 
461 461
 } tm_cell_t;
462 462
 
... ...
@@ -13,15 +13,8 @@
13 13
  * reply and both  of them are constructed by different software.
14 14
  * 
15 15
  * As for reply matching, we match based on branch value -- that is
16
- * faster too. There are two versions .. with SYNONYMs #define
17
- * enabled, the branch includes ordinal number of a transaction
18
- * in a synonym list in hash table and is somewhat faster but
19
- * not reboot-resilient. SYNONYMs turned off are little slower
20
- * but work across reboots as well.
21
- *
22
- * The branch parameter is formed as follows:
23
- * SYNONYMS  on: hash.synonym.branch
24
- * SYNONYMS off: hash.md5.branch
16
+ * faster too.
17
+ * The branch parameter is formed as follows: hash.md5.branch
25 18
  *
26 19
  * -jiri
27 20
  *
... ...
@@ -892,16 +885,12 @@ int t_reply_matching( struct sip_msg *p_msg , int *p_branch )
892 892
 
893 893
 	char *loopi;
894 894
 	int loopl;
895
-	char *syni;
896
-	int synl;
897 895
 	
898 896
 	short is_cancel;
899 897
 
900 898
 	/* make compiler warnings happy */
901 899
 	loopi=0;
902 900
 	loopl=0;
903
-	syni=0;
904
-	synl=0;
905 901
 
906 902
 	/* split the branch into pieces: loop_detection_check(ignored),
907 903
 	 hash_table_id, synonym_id, branch_id */
... ...
@@ -928,25 +917,14 @@ int t_reply_matching( struct sip_msg *p_msg , int *p_branch )
928 928
 	hashi=p;
929 929
 	p=n+1;scan_space--;
930 930
 
931
-	if (!syn_branch) {
932
-		/* md5 value */
933
-		n=eat_token2_end( p, p+scan_space, BRANCH_SEPARATOR );
934
-		loopl = n-p;
935
-		scan_space-= loopl;
936
-		if (n==p || scan_space<2 || *n!=BRANCH_SEPARATOR) 
937
-			goto nomatch2;
938
-		loopi=p;
939
-		p=n+1; scan_space--;
940
-	} else {
941
-		/* synonym id */
942
-		n=eat_token2_end( p, p+scan_space, BRANCH_SEPARATOR);
943
-		synl=n-p;
944
-		scan_space-=synl;
945
-		if (!synl || scan_space<2 || *n!=BRANCH_SEPARATOR) 
946
-			goto nomatch2;
947
-		syni=p;
948
-		p=n+1;scan_space--;
949
-	}
931
+	/* md5 value */
932
+	n=eat_token2_end( p, p+scan_space, BRANCH_SEPARATOR );
933
+	loopl = n-p;
934
+	scan_space-= loopl;
935
+	if (n==p || scan_space<2 || *n!=BRANCH_SEPARATOR)
936
+		goto nomatch2;
937
+	loopi=p;
938
+	p=n+1; scan_space--;
950 939
 
951 940
 	/* branch id  -  should exceed the scan_space */
952 941
 	n=eat_token_end( p, p+scan_space );
... ...
@@ -959,8 +937,7 @@ int t_reply_matching( struct sip_msg *p_msg , int *p_branch )
959 959
 		||hash_index>=TABLE_ENTRIES
960 960
 		|| reverse_hex2int(branchi, branchl, &branch_id)<0
961 961
 		||branch_id>=MAX_BRANCHES
962
-		|| (syn_branch ? (reverse_hex2int(syni, synl, &entry_label))<0 
963
-			: loopl!=MD5_LEN ))
962
+		|| loopl!=MD5_LEN)
964 963
 	) {
965 964
 		DBG("DEBUG: t_reply_matching: poor reply labels %d label %d "
966 965
 			"branch %d\n", hash_index, entry_label, branch_id );
... ...
@@ -983,14 +960,8 @@ int t_reply_matching( struct sip_msg *p_msg , int *p_branch )
983 983
 	/* all the transactions from the entry are compared */
984 984
 	clist_foreach(hash_bucket, p_cell, next_c){
985 985
 		prefetch_loc_r(p_cell->next_c, 1);
986
-		/* first look if branch matches */
987
-		if (likely(syn_branch)) {
988
-			if (p_cell->label != entry_label) 
989
-				continue;
990
-		} else {
991
-			if ( memcmp(p_cell->md5, loopi,MD5_LEN)!=0)
986
+		if ( memcmp(p_cell->md5, loopi,MD5_LEN)!=0)
992 987
 					continue;
993
-		}
994 988
 
995 989
 		/* sanity check ... too high branch ? */
996 990
 		if (unlikely(branch_id>=p_cell->nr_of_outgoings))
... ...
@@ -1612,11 +1612,7 @@ char* build_uac_req(str* method, str* headers, str* body, dlg_t* dialog, int bra
1612 1612
 int t_calc_branch(struct cell *t, 
1613 1613
 	int b, char *branch, int *branch_len)
1614 1614
 {
1615
-	return syn_branch ?
1616
-		branch_builder( t->hash_index,
1617
-			t->label, 0,
1618
-			b, branch, branch_len )
1619
-		: branch_builder( t->hash_index,
1615
+	return branch_builder( t->hash_index,
1620 1616
 			0, t->md5,
1621 1617
 			b, branch, branch_len );
1622 1618
 }
... ...
@@ -18,7 +18,6 @@ rev_dns=no	# (cmd. line: -R)
18 18
 port=5060
19 19
 #port=8060
20 20
 
21
-syn_branch=1
22 21
 fifo="/tmp/ser_fifo"
23 22
 
24 23
 # advertise IP address in Via (as opposed to advertising DNS name
... ...
@@ -11,7 +11,6 @@ fork=1
11 11
 log_stderror=yes	# (cmd line: -E)
12 12
 check_via=no # (cmd. line: -v)
13 13
 dns=no # (cmd. line: -r)
14
-syn_branch=1
15 14
 reply_to_via=0
16 15
 fifo="/tmp/ser_fifo"
17 16
 
... ...
@@ -25,7 +25,6 @@ rev_dns=off      # (cmd. line: -R)
25 25
 # for more info: sip_router -h
26 26
 alias=iptel.org
27 27
 alias="foo.bar"
28
-syn_branch=0
29 28
 fifo="/tmp/ser_fifo"
30 29
 
31 30
 #modules