[sr-dev] git:master: core: new global parameter max_recursive_level

Daniel-Constantin Mierla miconda at gmail.com
Sun Mar 30 00:24:37 CET 2014


Module: sip-router
Branch: master
Commit: d1c607183049fba9997bbb401da76d3277ab3426
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=d1c607183049fba9997bbb401da76d3277ab3426

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Sun Mar 30 00:22:17 2014 +0100

core: new global parameter max_recursive_level

- replace define ROUTE_MAX_REC_LEV with config paramter
- number of allowed recusive levels can be set in config now
- it affects calls of route blocks and chained if { ... } else if { ...
  } else ...

---

 action.c |   10 +++++++++-
 action.h |    2 ++
 cfg.lex  |    3 +++
 cfg.y    |    2 ++
 config.h |    3 ---
 5 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/action.c b/action.c
index 5fa50ee..f014b0f 100644
--- a/action.c
+++ b/action.c
@@ -114,6 +114,14 @@ struct onsend_info* p_onsend=0; /* onsend route send info */
 /* current action executed from config file */
 static cfg_action_t *_cfg_crt_action = 0;
 
+/*!< maximum number of recursive calls for blocks of actions */
+static unsigned int max_recursive_level = 256;
+
+void set_max_recursive_level(unsigned int lev)
+{
+	max_recursive_level = lev;
+}
+
 /* return current action executed from config file */
 cfg_action_t *get_cfg_crt_action(void)
 {
@@ -1567,7 +1575,7 @@ int run_actions(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
 
 	ret=E_UNSPEC;
 	h->rec_lev++;
-	if (unlikely(h->rec_lev>ROUTE_MAX_REC_LEV)){
+	if (unlikely(h->rec_lev>max_recursive_level)){
 		LOG(L_ERR, "WARNING: too many recursive routing table lookups (%d)"
 					" giving up!\n", h->rec_lev);
 		ret=E_UNSPEC;
diff --git a/action.h b/action.h
index 2ef00f7..fc789fb 100644
--- a/action.h
+++ b/action.h
@@ -72,6 +72,8 @@ cfg_action_t *get_cfg_crt_action(void);
 int get_cfg_crt_line(void);
 char *get_cfg_crt_name(void);
 
+void set_max_recursive_level(unsigned int lev);
+
 #ifdef USE_LONGJMP
 int run_actions_safe(struct run_act_ctx* c, struct action* a,
 						struct sip_msg* msg);
diff --git a/cfg.lex b/cfg.lex
index 50e7983..3d4b889 100644
--- a/cfg.lex
+++ b/cfg.lex
@@ -482,6 +482,8 @@ VERSION_TABLE_CFG		"version_table"
 
 SERVER_ID     "server_id"
 
+MAX_RECURSIVE_LEVEL		"max_recursive_level"
+
 LATENCY_LOG				latency_log
 LATENCY_LIMIT_DB		latency_limit_db
 LATENCY_LIMIT_ACTION	latency_limit_action
@@ -917,6 +919,7 @@ IMPORTFILE      "import_file"
 									return HTTP_REPLY_PARSE; }
 <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>{LATENCY_LOG}  { count(); yylval.strval=yytext; return LATENCY_LOG;}
 <INITIAL>{MSG_TIME}  { count(); yylval.strval=yytext; return MSG_TIME;}
 <INITIAL>{LATENCY_LIMIT_DB}  { count(); yylval.strval=yytext; return LATENCY_LIMIT_DB;}
diff --git a/cfg.y b/cfg.y
index 195593b..fd0fd2c 100644
--- a/cfg.y
+++ b/cfg.y
@@ -536,6 +536,7 @@ extern char *finame;
 %token VERSION_TABLE_CFG
 %token CFG_DESCRIPTION
 %token SERVER_ID
+%token MAX_RECURSIVE_LEVEL
 %token LATENCY_LOG
 %token LATENCY_LIMIT_DB
 %token LATENCY_LIMIT_ACTION
@@ -1559,6 +1560,7 @@ assign_stm:
 	| HTTP_REPLY_PARSE EQUAL NUMBER { http_reply_parse=$3; }
 	| 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); }
     | 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 32cd55c..48500ef 100644
--- a/config.h
+++ b/config.h
@@ -66,9 +66,6 @@
 #define EVENT_RT_NO RT_NO 		/*!< event_route routing tables number */
 #define DEFAULT_RT 0 			/*!< default routing table */
 
-#define MAX_REC_LEV 100 		/*!< maximum number of recursive calls */
-#define ROUTE_MAX_REC_LEV 100 		/*!< maximum number of recursive calls for route()*/
-
 #define MAX_URI_SIZE 1024		/*!< Max URI size used when rewriting URIs */
 
 #define MAX_PATH_SIZE 256 		/*!< Maximum length of path header buffer */




More information about the sr-dev mailing list