فهرست منبع

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 11 سال پیش
والد
کامیت
e008edb977
8فایلهای تغییر یافته به همراه40 افزوده شده و 8 حذف شده
  1. 2 0
      cfg.lex
  2. 2 0
      cfg.y
  3. 2 1
      config.h
  4. 2 4
      dns_cache.h
  5. 21 3
      dset.c
  6. 2 0
      dset.h
  7. 2 0
      globals.h
  8. 7 0
      main.c

+ 2 - 0
cfg.lex

@@ -489,6 +489,7 @@ VERSION_TABLE_CFG		"version_table"
 SERVER_ID     "server_id"
 
 MAX_RECURSIVE_LEVEL		"max_recursive_level"
+MAX_BRANCHES_PARAM		"max_branches"|"max_branches"
 
 LATENCY_LOG				latency_log
 LATENCY_LIMIT_DB		latency_limit_db
@@ -936,6 +937,7 @@ IMPORTFILE      "import_file"
 <INITIAL>{VERSION_TABLE_CFG}  { count(); yylval.strval=yytext; return VERSION_TABLE_CFG;}
 <INITIAL>{SERVER_ID}  { count(); yylval.strval=yytext; return SERVER_ID;}
 <INITIAL>{MAX_RECURSIVE_LEVEL}  { count(); yylval.strval=yytext; return MAX_RECURSIVE_LEVEL;}
+<INITIAL>{MAX_BRANCHES_PARAM}  { count(); yylval.strval=yytext; return MAX_BRANCHES_PARAM;}
 <INITIAL>{LATENCY_LOG}  { count(); yylval.strval=yytext; return LATENCY_LOG;}
 <INITIAL>{MSG_TIME}  { count(); yylval.strval=yytext; return MSG_TIME;}
 <INITIAL>{ONSEND_RT_REPLY}	{ count(); yylval.strval=yytext; return ONSEND_RT_REPLY; }

+ 2 - 0
cfg.y

@@ -543,6 +543,7 @@ extern char *default_routename;
 %token CFG_DESCRIPTION
 %token SERVER_ID
 %token MAX_RECURSIVE_LEVEL
+%token MAX_BRANCHES_PARAM
 %token LATENCY_LOG
 %token LATENCY_LIMIT_DB
 %token LATENCY_LIMIT_ACTION
@@ -1572,6 +1573,7 @@ assign_stm:
 	| HTTP_REPLY_PARSE EQUAL error { yyerror("boolean value expected"); }
     | SERVER_ID EQUAL NUMBER { server_id=$3; }
     | MAX_RECURSIVE_LEVEL EQUAL NUMBER { set_max_recursive_level($3); }
+    | MAX_BRANCHES_PARAM EQUAL NUMBER { sr_dst_max_branches = $3; }
     | LATENCY_LOG EQUAL NUMBER { default_core_cfg.latency_log=$3; }
 	| LATENCY_LOG EQUAL error  { yyerror("number  expected"); }
     | LATENCY_LIMIT_DB EQUAL NUMBER { default_core_cfg.latency_limit_db=$3; }

+ 2 - 1
config.h

@@ -169,7 +169,8 @@
 #define MAX_RECEIVED_SIZE	59	/*!< forwarding  -- Via buffer dimensioning - Received header */
 #define MAX_RPORT_SIZE		13	/*!< forwarding  -- Via buffer dimensioning - Rport */
 
-#define MAX_BRANCHES    	12	/*!< maximum number of branches per transaction */
+#define MAX_BRANCHES_DEFAULT	12	/*!< default maximum number of branches per transaction */
+#define MAX_BRANCHES_LIMIT		32	/*!< limit of maximum number of branches per transaction */
 
 #define MAX_PRINT_TEXT 		256	/*!< max length of the text of fifo 'print' command */
 

+ 2 - 4
dns_cache.h

@@ -166,10 +166,8 @@ struct dns_hash_entry{
 };
 
 
-#if MAX_BRANCHES < 16
-/* forking is limited by tm to 12 by default */
-typedef unsigned short srv_flags_t;
-#elif MAX_BRANCHES < 32
+/* to fit in the limit of MAX_BRANCHES */
+#if MAX_BRANCHES_LIMIT < 32
 typedef unsigned int srv_flags_t;
 #else
 typedef unsigned long long srv_flags_t;

+ 21 - 3
dset.c

@@ -39,6 +39,7 @@
 #include "parser/parser_f.h"
 #include "parser/parse_uri.h"
 #include "parser/msg_parser.h"
+#include "globals.h"
 #include "ut.h"
 #include "hash_func.h"
 #include "error.h"
@@ -58,9 +59,9 @@
 
 /* 
  * Where we store URIs of additional transaction branches
- * (-1 because of the default branch, #0)
+ * (sr_dst_max_branches - 1 : because of the default branch for r-uri, #0 in tm)
  */
-static struct branch branches[MAX_BRANCHES - 1];
+static struct branch *branches = NULL;
 
 /* how many of them we have */
 unsigned int nr_branches = 0;
@@ -78,6 +79,23 @@ static qvalue_t ruri_q = Q_UNSPECIFIED;
 static flag_t ruri_bflags;
 
 
+int init_dst_set(void)
+{
+	if(sr_dst_max_branches<=0 || sr_dst_max_branches>=MAX_BRANCHES_LIMIT) {
+		LM_ERR("invalid value for max branches parameter: %u\n",
+				sr_dst_max_branches);
+		return -1;
+	}
+	/* sr_dst_max_branches - 1 : because of the default branch for r-uri, #0 in tm */
+	branches = (branch_t*)pkg_malloc((sr_dst_max_branches-1)*sizeof(branch_t));
+	if(branches==NULL) {
+		LM_ERR("not enough memory to initialize destination branches\n");
+		return -1;
+	}
+	memset(branches, 0, (sr_dst_max_branches-1)*sizeof(branch_t));
+	return 0;
+}
+
 /*! \brief
  * Return pointer to branch[idx] structure
  * @param idx - branch index
@@ -333,7 +351,7 @@ int append_branch(struct sip_msg* msg, str* uri, str* dst_uri, str* path,
 	/* if we have already set up the maximum number
 	 * of branches, don't try new ones 
 	 */
-	if (unlikely(nr_branches == MAX_BRANCHES - 1)) {
+	if (unlikely(nr_branches == sr_dst_max_branches - 1)) {
 		LM_ERR("max nr of branches exceeded\n");
 		ser_error = E_TOO_MANY_BRANCHES;
 		return -1;

+ 2 - 0
dset.h

@@ -258,4 +258,6 @@ int setbflagsval(unsigned int branch, flag_t val);
 int uri_add_rcv_alias(sip_msg_t *msg, str *uri, str *nuri);
 int uri_restore_rcv_alias(str *uri, str *nuri, str *suri);
 
+int init_dst_set(void);
+
 #endif /* _DSET_H */

+ 2 - 0
globals.h

@@ -50,6 +50,8 @@ extern int config_check;
 extern char* stat_file;
 extern unsigned short port_no;
 
+extern unsigned int sr_dst_max_branches; /* max number of branches per transaction */
+
 extern time_t up_since;
 extern pid_t creator_pid;  /* pid of first process before daemonization */
 extern int uid;

+ 7 - 0
main.c

@@ -424,6 +424,9 @@ int sock_mode= S_IRUSR| S_IWUSR| S_IRGRP| S_IWGRP; /* rw-rw---- */
 
 int server_id = 0; /* Configurable unique ID of the server */
 
+/* maximum number of branches for transaction */
+unsigned int sr_dst_max_branches = MAX_BRANCHES_DEFAULT;
+
 /* set timeval for each received sip message */
 int sr_msg_time = 1;
 
@@ -2119,6 +2122,10 @@ try_again:
 	pp_ifdef_level_check();
 	print_rls();
 
+	if(init_dst_set()<0) {
+		LM_ERR("failed to initialize destination set structure\n");
+		goto error;
+	}
 	/* options with higher priority than cfg file */
 	optind = 1;  /* reset getopt */
 	while((c=getopt(argc,argv,options))!=-1) {