Browse code

core: add sip_parser_log core variable

* when handling non sip messages, parser errors are logged at core level
which defaults to ERR. since this may induce in error sysops or log
scanners, sometimes the core level is set to debug just to omit these
messages from log, which is not good since other messages are omitted
too. this commit adds a new core variable to set the log level for
message parsing errors. this way, we can explicitly set the log level
for message parsing while leaving the core level at ERR.

lazedo authored on 17/07/2020 10:08:43
Showing 7 changed files
... ...
@@ -363,6 +363,7 @@ MEMSAFETY	"mem_safety"
363 363
 MEMJOIN		"mem_join"
364 364
 MEMSTATUSMODE		"mem_status_mode"
365 365
 CORELOG		"corelog"|"core_log"
366
+SIP_PARSER_LOG "sip_parser_log"
366 367
 SIP_WARNING sip_warning
367 368
 SERVER_SIGNATURE server_signature
368 369
 SERVER_HEADER server_header
... ...
@@ -810,6 +811,7 @@ IMPORTFILE      "import_file"
810 811
 <INITIAL>{MEMSAFETY}	{ count(); yylval.strval=yytext; return MEMSAFETY; }
811 812
 <INITIAL>{MEMJOIN}	{ count(); yylval.strval=yytext; return MEMJOIN; }
812 813
 <INITIAL>{MEMSTATUSMODE}	{ count(); yylval.strval=yytext; return MEMSTATUSMODE; }
814
+<INITIAL>{SIP_PARSER_LOG}  { count(); yylval.strval=yytext; return SIP_PARSER_LOG; }
813 815
 <INITIAL>{CORELOG}	{ count(); yylval.strval=yytext; return CORELOG; }
814 816
 <INITIAL>{SIP_WARNING}	{ count(); yylval.strval=yytext; return SIP_WARNING; }
815 817
 <INITIAL>{USER}		{ count(); yylval.strval=yytext; return USER; }
... ...
@@ -388,6 +388,7 @@ extern char *default_routename;
388 388
 %token MEMSAFETY
389 389
 %token MEMJOIN
390 390
 %token MEMSTATUSMODE
391
+%token SIP_PARSER_LOG
391 392
 %token CORELOG
392 393
 %token SIP_WARNING
393 394
 %token SERVER_SIGNATURE
... ...
@@ -943,6 +944,8 @@ assign_stm:
943 944
 	| MEMJOIN EQUAL error { yyerror("int value expected"); }
944 945
 	| MEMSTATUSMODE EQUAL intno { default_core_cfg.mem_status_mode=$3; }
945 946
 	| MEMSTATUSMODE EQUAL error { yyerror("int value expected"); }
947
+	| SIP_PARSER_LOG EQUAL intno { default_core_cfg.sip_parser_log=$3; }
948
+	| SIP_PARSER_LOG EQUAL error { yyerror("int value expected"); }
946 949
 	| CORELOG EQUAL intno { default_core_cfg.corelog=$3; }
947 950
 	| CORELOG EQUAL error { yyerror("int value expected"); }
948 951
 	| SIP_WARNING EQUAL NUMBER { sip_warning=$3; }
... ...
@@ -115,6 +115,7 @@ struct cfg_group_core default_core_cfg = {
115 115
 	1, /*!< mem_safety - 0 disabled; 1 enabled */
116 116
 	1, /*!< mem_join - 1 enabled */
117 117
 	0, /*!< mem_status_mode - 0 only free fragments, 1 all fragements */
118
+	L_ERR, /*!< sip msg parser error log level*/
118 119
 	L_ERR, /*!< corelog */
119 120
 	L_DBG, /*!< latency cfg log */
120 121
 	L_ERR, /*!< latency log */
... ...
@@ -318,6 +319,8 @@ cfg_def_t core_cfg_def[] = {
318 319
 		"join free memory fragments"},
319 320
 	{"mem_status_mode",		CFG_VAR_INT|CFG_ATOMIC,	0, 0, 0, 0,
320 321
 		"print status for free or all memory fragments"},
322
+	{"sip_parser_log",		CFG_VAR_INT|CFG_ATOMIC,	0, 0, 0, 0,
323
+		"log level for sip msg parser error messages"},
321 324
 	{"corelog",		CFG_VAR_INT|CFG_ATOMIC,	0, 0, 0, 0,
322 325
 		"log level for non-critical core error messages"},
323 326
 	{"latency_cfg_log",		CFG_VAR_INT|CFG_ATOMIC,	0, 0, 0, 0,
... ...
@@ -103,6 +103,7 @@ struct cfg_group_core {
103 103
 	int mem_safety; /*!< memory safety control option */
104 104
 	int mem_join; /*!< memory free fragments join option */
105 105
 	int mem_status_mode; /*!< memory status printed for free/all fragments */
106
+	int sip_parser_log; /*!< sip msg parser error log level*/
106 107
 	int corelog; /*!< log level for non-critcal core error messages */
107 108
 	int latency_cfg_log; /*!< log level for printing latency of routing blocks */
108 109
 	int latency_log; /*!< log level for latency limits messages */
... ...
@@ -677,7 +677,7 @@ int parse_msg(char* const buf, const unsigned int len, struct sip_msg* const msg
677 677
 
678 678
 error:
679 679
 	/* more debugging, msg->orig is/should be null terminated*/
680
-	LOG(cfg_get(core, core_cfg, corelog), "ERROR: parse_msg: message=<%.*s>\n",
680
+	LOG(cfg_get(core, core_cfg, sip_parser_log), "ERROR: parse_msg: message=<%.*s>\n",
681 681
 			(int)msg->len, ZSW(msg->buf));
682 682
 	return -1;
683 683
 }
... ...
@@ -268,7 +268,7 @@ error:
268 268
 	}
269 269
 error1:
270 270
 	fl->type=SIP_INVALID;
271
-	LOG(cfg_get(core, core_cfg, corelog), "parse_first_line: bad message (offset: %d)\n", offset);
271
+	LOG(cfg_get(core, core_cfg, sip_parser_log), "parse_first_line: bad message (offset: %d)\n", offset);
272 272
 	/* skip  line */
273 273
 	nl=eat_line(buffer,len);
274 274
 	return nl;
... ...
@@ -304,7 +304,7 @@ int receive_msg(char *buf, unsigned int len, receive_info_t *rcv_info)
304 304
 		}
305 305
 	}
306 306
 	if(errsipmsg==1) {
307
-		LOG(cfg_get(core, core_cfg, corelog),
307
+		LOG(cfg_get(core, core_cfg, sip_parser_log),
308 308
 				"core parsing of SIP message failed (%s:%d/%d)\n",
309 309
 				ip_addr2a(&msg->rcv.src_ip), (int)msg->rcv.src_port,
310 310
 				(int)msg->rcv.proto);