Skip to content

Commit

Permalink
core: add sip_parser_log core variable
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
lazedo committed Jul 17, 2020
1 parent 1691478 commit f39f88a
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/core/cfg.lex
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ MEMSAFETY "mem_safety"
MEMJOIN "mem_join"
MEMSTATUSMODE "mem_status_mode"
CORELOG "corelog"|"core_log"
SIP_PARSER_LOG "sip_parser_log"
SIP_WARNING sip_warning
SERVER_SIGNATURE server_signature
SERVER_HEADER server_header
Expand Down Expand Up @@ -810,6 +811,7 @@ IMPORTFILE "import_file"
<INITIAL>{MEMSAFETY} { count(); yylval.strval=yytext; return MEMSAFETY; }
<INITIAL>{MEMJOIN} { count(); yylval.strval=yytext; return MEMJOIN; }
<INITIAL>{MEMSTATUSMODE} { count(); yylval.strval=yytext; return MEMSTATUSMODE; }
<INITIAL>{SIP_PARSER_LOG} { count(); yylval.strval=yytext; return SIP_PARSER_LOG; }
<INITIAL>{CORELOG} { count(); yylval.strval=yytext; return CORELOG; }
<INITIAL>{SIP_WARNING} { count(); yylval.strval=yytext; return SIP_WARNING; }
<INITIAL>{USER} { count(); yylval.strval=yytext; return USER; }
Expand Down
3 changes: 3 additions & 0 deletions src/core/cfg.y
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ extern char *default_routename;
%token MEMSAFETY
%token MEMJOIN
%token MEMSTATUSMODE
%token SIP_PARSER_LOG
%token CORELOG
%token SIP_WARNING
%token SERVER_SIGNATURE
Expand Down Expand Up @@ -943,6 +944,8 @@ assign_stm:
| MEMJOIN EQUAL error { yyerror("int value expected"); }
| MEMSTATUSMODE EQUAL intno { default_core_cfg.mem_status_mode=$3; }
| MEMSTATUSMODE EQUAL error { yyerror("int value expected"); }
| SIP_PARSER_LOG EQUAL intno { default_core_cfg.sip_parser_log=$3; }
| SIP_PARSER_LOG EQUAL error { yyerror("int value expected"); }
| CORELOG EQUAL intno { default_core_cfg.corelog=$3; }
| CORELOG EQUAL error { yyerror("int value expected"); }
| SIP_WARNING EQUAL NUMBER { sip_warning=$3; }
Expand Down
3 changes: 3 additions & 0 deletions src/core/cfg_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ struct cfg_group_core default_core_cfg = {
1, /*!< mem_safety - 0 disabled; 1 enabled */
1, /*!< mem_join - 1 enabled */
0, /*!< mem_status_mode - 0 only free fragments, 1 all fragements */
L_ERR, /*!< sip msg parser error log level*/
L_ERR, /*!< corelog */
L_DBG, /*!< latency cfg log */
L_ERR, /*!< latency log */
Expand Down Expand Up @@ -318,6 +319,8 @@ cfg_def_t core_cfg_def[] = {
"join free memory fragments"},
{"mem_status_mode", CFG_VAR_INT|CFG_ATOMIC, 0, 0, 0, 0,
"print status for free or all memory fragments"},
{"sip_parser_log", CFG_VAR_INT|CFG_ATOMIC, 0, 0, 0, 0,
"log level for sip msg parser error messages"},
{"corelog", CFG_VAR_INT|CFG_ATOMIC, 0, 0, 0, 0,
"log level for non-critical core error messages"},
{"latency_cfg_log", CFG_VAR_INT|CFG_ATOMIC, 0, 0, 0, 0,
Expand Down
1 change: 1 addition & 0 deletions src/core/cfg_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ struct cfg_group_core {
int mem_safety; /*!< memory safety control option */
int mem_join; /*!< memory free fragments join option */
int mem_status_mode; /*!< memory status printed for free/all fragments */
int sip_parser_log; /*!< sip msg parser error log level*/
int corelog; /*!< log level for non-critcal core error messages */
int latency_cfg_log; /*!< log level for printing latency of routing blocks */
int latency_log; /*!< log level for latency limits messages */
Expand Down
2 changes: 1 addition & 1 deletion src/core/parser/msg_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ int parse_msg(char* const buf, const unsigned int len, struct sip_msg* const msg

error:
/* more debugging, msg->orig is/should be null terminated*/
LOG(cfg_get(core, core_cfg, corelog), "ERROR: parse_msg: message=<%.*s>\n",
LOG(cfg_get(core, core_cfg, sip_parser_log), "ERROR: parse_msg: message=<%.*s>\n",
(int)msg->len, ZSW(msg->buf));
return -1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/parser/parse_fline.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ char* parse_first_line(char* buffer, unsigned int len, struct msg_start* fl)
}
error1:
fl->type=SIP_INVALID;
LOG(cfg_get(core, core_cfg, corelog), "parse_first_line: bad message (offset: %d)\n", offset);
LOG(cfg_get(core, core_cfg, sip_parser_log), "parse_first_line: bad message (offset: %d)\n", offset);
/* skip line */
nl=eat_line(buffer,len);
return nl;
Expand Down
2 changes: 1 addition & 1 deletion src/core/receive.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ int receive_msg(char *buf, unsigned int len, receive_info_t *rcv_info)
}
}
if(errsipmsg==1) {
LOG(cfg_get(core, core_cfg, corelog),
LOG(cfg_get(core, core_cfg, sip_parser_log),
"core parsing of SIP message failed (%s:%d/%d)\n",
ip_addr2a(&msg->rcv.src_ip), (int)msg->rcv.src_port,
(int)msg->rcv.proto);
Expand Down

0 comments on commit f39f88a

Please sign in to comment.