Browse code

core: use the prev. via branch id if it's 3261

When computing the via branch value in syn_branch==0 mode, use the
previous via branch id and not the to_tag, from_tag, callid, ruri,
cseq number, via port and host, if the previous via branch id is
in rfc3261 format (begins with the magic cookie).
See rfc3261/16.11 P116 for more informations.
To revert to the old behaviour, define BRANCH_IGNORE_3261_VIA.

Andrei Pelinescu-Onciul authored on 10/02/2010 20:48:00
Showing 1 changed files
... ...
@@ -22,7 +22,7 @@
22 22
  * History:
23 23
  * --------
24 24
  *  2010-02-10  moved from parser/msg_parser.h and added tag only mode
25
- *              by default (andrei)
25
+ *               by default (andrei)
26 26
 */
27 27
 /** compute the characteristic value of a message.
28 28
  * @file
... ...
@@ -32,6 +32,9 @@
32 32
  *  BRANCH_INCLUDE_FROMTO_BODY - if defined the old (pre 3.1) mode of
33 33
  *   including the full from & to bodies will be used (instead of only the
34 34
  *   tags).
35
+ * BRANCH_IGNORE_3261_VIA - if defined, no check and special/simpler handling
36
+ *   of messages with 3261 cookies in the via branch will be made (same
37
+ *   behaviour as in pre 3.1 versions).
35 38
 */
36 39
 
37 40
 #ifndef __char_msg_val_h
... ...
@@ -59,7 +62,15 @@ inline static int char_msg_val( struct sip_msg *msg, char *cv )
59 59
 		memset( cv, '0', MD5_LEN );
60 60
 		return 0;
61 61
 	}
62
-
62
+#ifndef BRANCH_IGNORE_3261_VIA
63
+	if (likely(msg->via1->branch && msg->via1->branch->value.len>MCOOKIE_LEN &&
64
+				memcmp(msg->via1->branch->value.s, MCOOKIE, MCOOKIE_LEN)==0)){
65
+		/* 3261 branch cookie present => hash only the received branch ID */
66
+		src[0]=msg->via1->branch->value;
67
+		MD5StringArray ( cv, src, 1 );
68
+		return 1; /* success */
69
+	}
70
+#endif /* BRANCH_IGNORE_3261_VIA */
63 71
 #ifdef BRANCH_INCLUDE_FROMTO_BODY
64 72
 	/* use the from & to full bodies */
65 73
 	src[0]= msg->from->body;
... ...
@@ -77,7 +88,7 @@ inline static int char_msg_val( struct sip_msg *msg, char *cv )
77 77
 	/* use only the from & to tags */
78 78
 	src[0]=get_from(msg)->tag_value;
79 79
 	src[1]=get_to(msg)->tag_value;
80
-#endif
80
+#endif /* BRANCH_INCLUDE_FROMTO_BODY */
81 81
 	src[2]= msg->callid->body;
82 82
 	src[3]= msg->first_line.u.request.uri;
83 83
 	src[4]= get_cseq( msg )->number;
... ...
@@ -85,7 +96,7 @@ inline static int char_msg_val( struct sip_msg *msg, char *cv )
85 85
 	/* topmost Via is part of transaction key as well ! */
86 86
 	src[5]= msg->via1->host;
87 87
 	src[6]= msg->via1->port_str;
88
-	if (msg->via1->branch) {
88
+	if (likely(msg->via1->branch)) {
89 89
 		src[7]= msg->via1->branch->value;
90 90
 		MD5StringArray ( cv, src, 8 );
91 91
 	} else {