Browse code

core: new parameter - max_branches

- the maximum number of uac branches can be set via config
- default value is 12 (old static value for MAX_BRNACHES)
- the upper limit is 31, it has to be at least 1
- example:
max_branches=16

Daniel-Constantin Mierla authored on 17/10/2014 09:04:23
Showing 8 changed files
... ...
@@ -489,6 +489,7 @@ VERSION_TABLE_CFG		"version_table"
489 489
 SERVER_ID     "server_id"
490 490
 
491 491
 MAX_RECURSIVE_LEVEL		"max_recursive_level"
492
+MAX_BRANCHES_PARAM		"max_branches"|"max_branches"
492 493
 
493 494
 LATENCY_LOG				latency_log
494 495
 LATENCY_LIMIT_DB		latency_limit_db
... ...
@@ -936,6 +937,7 @@ IMPORTFILE      "import_file"
936 936
 <INITIAL>{VERSION_TABLE_CFG}  { count(); yylval.strval=yytext; return VERSION_TABLE_CFG;}
937 937
 <INITIAL>{SERVER_ID}  { count(); yylval.strval=yytext; return SERVER_ID;}
938 938
 <INITIAL>{MAX_RECURSIVE_LEVEL}  { count(); yylval.strval=yytext; return MAX_RECURSIVE_LEVEL;}
939
+<INITIAL>{MAX_BRANCHES_PARAM}  { count(); yylval.strval=yytext; return MAX_BRANCHES_PARAM;}
939 940
 <INITIAL>{LATENCY_LOG}  { count(); yylval.strval=yytext; return LATENCY_LOG;}
940 941
 <INITIAL>{MSG_TIME}  { count(); yylval.strval=yytext; return MSG_TIME;}
941 942
 <INITIAL>{ONSEND_RT_REPLY}	{ count(); yylval.strval=yytext; return ONSEND_RT_REPLY; }
... ...
@@ -543,6 +543,7 @@ extern char *default_routename;
543 543
 %token CFG_DESCRIPTION
544 544
 %token SERVER_ID
545 545
 %token MAX_RECURSIVE_LEVEL
546
+%token MAX_BRANCHES_PARAM
546 547
 %token LATENCY_LOG
547 548
 %token LATENCY_LIMIT_DB
548 549
 %token LATENCY_LIMIT_ACTION
... ...
@@ -1572,6 +1573,7 @@ assign_stm:
1572 1572
 	| HTTP_REPLY_PARSE EQUAL error { yyerror("boolean value expected"); }
1573 1573
     | SERVER_ID EQUAL NUMBER { server_id=$3; }
1574 1574
     | MAX_RECURSIVE_LEVEL EQUAL NUMBER { set_max_recursive_level($3); }
1575
+    | MAX_BRANCHES_PARAM EQUAL NUMBER { sr_dst_max_branches = $3; }
1575 1576
     | LATENCY_LOG EQUAL NUMBER { default_core_cfg.latency_log=$3; }
1576 1577
 	| LATENCY_LOG EQUAL error  { yyerror("number  expected"); }
1577 1578
     | LATENCY_LIMIT_DB EQUAL NUMBER { default_core_cfg.latency_limit_db=$3; }
... ...
@@ -169,7 +169,8 @@
169 169
 #define MAX_RECEIVED_SIZE	59	/*!< forwarding  -- Via buffer dimensioning - Received header */
170 170
 #define MAX_RPORT_SIZE		13	/*!< forwarding  -- Via buffer dimensioning - Rport */
171 171
 
172
-#define MAX_BRANCHES    	12	/*!< maximum number of branches per transaction */
172
+#define MAX_BRANCHES_DEFAULT	12	/*!< default maximum number of branches per transaction */
173
+#define MAX_BRANCHES_LIMIT		32	/*!< limit of maximum number of branches per transaction */
173 174
 
174 175
 #define MAX_PRINT_TEXT 		256	/*!< max length of the text of fifo 'print' command */
175 176
 
... ...
@@ -166,10 +166,8 @@ struct dns_hash_entry{
166 166
 };
167 167
 
168 168
 
169
-#if MAX_BRANCHES < 16
170
-/* forking is limited by tm to 12 by default */
171
-typedef unsigned short srv_flags_t;
172
-#elif MAX_BRANCHES < 32
169
+/* to fit in the limit of MAX_BRANCHES */
170
+#if MAX_BRANCHES_LIMIT < 32
173 171
 typedef unsigned int srv_flags_t;
174 172
 #else
175 173
 typedef unsigned long long srv_flags_t;
... ...
@@ -39,6 +39,7 @@
39 39
 #include "parser/parser_f.h"
40 40
 #include "parser/parse_uri.h"
41 41
 #include "parser/msg_parser.h"
42
+#include "globals.h"
42 43
 #include "ut.h"
43 44
 #include "hash_func.h"
44 45
 #include "error.h"
... ...
@@ -58,9 +59,9 @@
58 58
 
59 59
 /* 
60 60
  * Where we store URIs of additional transaction branches
61
- * (-1 because of the default branch, #0)
61
+ * (sr_dst_max_branches - 1 : because of the default branch for r-uri, #0 in tm)
62 62
  */
63
-static struct branch branches[MAX_BRANCHES - 1];
63
+static struct branch *branches = NULL;
64 64
 
65 65
 /* how many of them we have */
66 66
 unsigned int nr_branches = 0;
... ...
@@ -78,6 +79,23 @@ static qvalue_t ruri_q = Q_UNSPECIFIED;
78 78
 static flag_t ruri_bflags;
79 79
 
80 80
 
81
+int init_dst_set(void)
82
+{
83
+	if(sr_dst_max_branches<=0 || sr_dst_max_branches>=MAX_BRANCHES_LIMIT) {
84
+		LM_ERR("invalid value for max branches parameter: %u\n",
85
+				sr_dst_max_branches);
86
+		return -1;
87
+	}
88
+	/* sr_dst_max_branches - 1 : because of the default branch for r-uri, #0 in tm */
89
+	branches = (branch_t*)pkg_malloc((sr_dst_max_branches-1)*sizeof(branch_t));
90
+	if(branches==NULL) {
91
+		LM_ERR("not enough memory to initialize destination branches\n");
92
+		return -1;
93
+	}
94
+	memset(branches, 0, (sr_dst_max_branches-1)*sizeof(branch_t));
95
+	return 0;
96
+}
97
+
81 98
 /*! \brief
82 99
  * Return pointer to branch[idx] structure
83 100
  * @param idx - branch index
... ...
@@ -333,7 +351,7 @@ int append_branch(struct sip_msg* msg, str* uri, str* dst_uri, str* path,
333 333
 	/* if we have already set up the maximum number
334 334
 	 * of branches, don't try new ones 
335 335
 	 */
336
-	if (unlikely(nr_branches == MAX_BRANCHES - 1)) {
336
+	if (unlikely(nr_branches == sr_dst_max_branches - 1)) {
337 337
 		LM_ERR("max nr of branches exceeded\n");
338 338
 		ser_error = E_TOO_MANY_BRANCHES;
339 339
 		return -1;
... ...
@@ -258,4 +258,6 @@ int setbflagsval(unsigned int branch, flag_t val);
258 258
 int uri_add_rcv_alias(sip_msg_t *msg, str *uri, str *nuri);
259 259
 int uri_restore_rcv_alias(str *uri, str *nuri, str *suri);
260 260
 
261
+int init_dst_set(void);
262
+
261 263
 #endif /* _DSET_H */
... ...
@@ -50,6 +50,8 @@ extern int config_check;
50 50
 extern char* stat_file;
51 51
 extern unsigned short port_no;
52 52
 
53
+extern unsigned int sr_dst_max_branches; /* max number of branches per transaction */
54
+
53 55
 extern time_t up_since;
54 56
 extern pid_t creator_pid;  /* pid of first process before daemonization */
55 57
 extern int uid;
... ...
@@ -424,6 +424,9 @@ int sock_mode= S_IRUSR| S_IWUSR| S_IRGRP| S_IWGRP; /* rw-rw---- */
424 424
 
425 425
 int server_id = 0; /* Configurable unique ID of the server */
426 426
 
427
+/* maximum number of branches for transaction */
428
+unsigned int sr_dst_max_branches = MAX_BRANCHES_DEFAULT;
429
+
427 430
 /* set timeval for each received sip message */
428 431
 int sr_msg_time = 1;
429 432
 
... ...
@@ -2119,6 +2122,10 @@ try_again:
2119 2119
 	pp_ifdef_level_check();
2120 2120
 	print_rls();
2121 2121
 
2122
+	if(init_dst_set()<0) {
2123
+		LM_ERR("failed to initialize destination set structure\n");
2124
+		goto error;
2125
+	}
2122 2126
 	/* options with higher priority than cfg file */
2123 2127
 	optind = 1;  /* reset getopt */
2124 2128
 	while((c=getopt(argc,argv,options))!=-1) {