[sr-dev] git:master: core: new parameter - max_branches
Daniel-Constantin Mierla
miconda at gmail.com
Fri Oct 17 11:23:23 CEST 2014
Module: sip-router
Branch: master
Commit: e008edb9772c08bb0a34dd719516f2a9b7b46115
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=e008edb9772c08bb0a34dd719516f2a9b7b46115
Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: Fri Oct 17 11:04:23 2014 +0200
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
---
cfg.lex | 2 ++
cfg.y | 2 ++
config.h | 3 ++-
dns_cache.h | 6 ++----
dset.c | 24 +++++++++++++++++++++---
dset.h | 2 ++
globals.h | 2 ++
main.c | 7 +++++++
8 files changed, 40 insertions(+), 8 deletions(-)
diff --git a/cfg.lex b/cfg.lex
index 1d5e40a..15cd19d 100644
--- a/cfg.lex
+++ b/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; }
diff --git a/cfg.y b/cfg.y
index 6a85292..7184191 100644
--- a/cfg.y
+++ b/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; }
diff --git a/config.h b/config.h
index 172ee7d..23880a0 100644
--- a/config.h
+++ b/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 */
diff --git a/dns_cache.h b/dns_cache.h
index e93b59b..b697b7c 100644
--- a/dns_cache.h
+++ b/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;
diff --git a/dset.c b/dset.c
index 8e7410e..43e28db 100644
--- a/dset.c
+++ b/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;
diff --git a/dset.h b/dset.h
index ff7e838..d90ce61 100644
--- a/dset.h
+++ b/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 */
diff --git a/globals.h b/globals.h
index 0a62d3e..1dc4194 100644
--- a/globals.h
+++ b/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;
diff --git a/main.c b/main.c
index 5aebc79..2e9d9fc 100644
--- a/main.c
+++ b/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) {
More information about the sr-dev
mailing list