From 1f4e21130751ca90292ef5c1b112f40d879661fa Mon Sep 17 00:00:00 2001 From: Nikolay Ivanuschak Date: Sun, 5 Feb 2023 12:01:21 +0300 Subject: [PATCH] No warning generated when UDP and no Content-Length header Added 'always_log_missed_content_length' mode for sanity module. If 'always_log_missed_content_length' is 1 then the SIP message with no 'Content-Length' header will cause warning message in the logs. Otherwise warning message is not generated for cases when SIP message with no 'Content-Length' header is sent over UDP. GH #3210 --- src/modules/sanity/doc/sanity_admin.xml | 21 +++++++++++++++++++++ src/modules/sanity/sanity.c | 4 +++- src/modules/sanity/sanity_mod.c | 12 +++++++----- src/modules/sanity/sanity_mod.h | 3 +++ 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/modules/sanity/doc/sanity_admin.xml b/src/modules/sanity/doc/sanity_admin.xml index cc3a78630f4..11136d94b94 100644 --- a/src/modules/sanity/doc/sanity_admin.xml +++ b/src/modules/sanity/doc/sanity_admin.xml @@ -248,6 +248,27 @@ modparam("sanity", "autodrop", 1) ... modparam("sanity", "noreply", 1) +... + + + + +
+ <varname>always_log_missed_content_length</varname> (integer) + + If the value is 1 then the SIP message with no 'Content-Length' header + will cause warning message in the logs. If the value is 0 then the warning + message is not generated for cases when SIP message with no 'Content-Length' + header is sent over UDP or SCTP. + + + Default value is 1. + + + Set <varname>always_log_missed_content_length</varname> parameter + +... +modparam("sanity", "always_log_missed_content_length", 0) ... diff --git a/src/modules/sanity/sanity.c b/src/modules/sanity/sanity.c index c6563e23c44..524d2af6678 100644 --- a/src/modules/sanity/sanity.c +++ b/src/modules/sanity/sanity.c @@ -39,6 +39,7 @@ #define UNSUPPORTED_HEADER_LEN (sizeof(UNSUPPORTED_HEADER)-1) extern int ksr_sanity_noreply; +extern int always_log_missed_content_length; #define KSR_SANITY_REASON_SIZE 128 typedef struct ksr_sanity_info { @@ -608,7 +609,8 @@ int check_cl(sip_msg_t* msg) { return SANITY_CHECK_FAILED; } LM_DBG("check_cl passed\n"); - } else { + } else if (SANITY_LOG_MISSED_CONTENT_LEN == always_log_missed_content_length || + (msg->rcv.proto != PROTO_UDP && msg->rcv.proto != PROTO_SCTP)) { LM_WARN("content length header missing in request\n"); } diff --git a/src/modules/sanity/sanity_mod.c b/src/modules/sanity/sanity_mod.c index 832a0c2308c..6afa8f3c682 100644 --- a/src/modules/sanity/sanity_mod.c +++ b/src/modules/sanity/sanity_mod.c @@ -40,6 +40,7 @@ int default_msg_checks = SANITY_DEFAULT_CHECKS; int default_uri_checks = SANITY_DEFAULT_URI_CHECKS; int _sanity_drop = 1; int ksr_sanity_noreply = 0; +int always_log_missed_content_length = SANITY_LOG_MISSED_CONTENT_LEN; str_list_t* proxyrequire_list = NULL; @@ -70,11 +71,12 @@ static cmd_export_t cmds[] = { * Exported parameters */ static param_export_t params[] = { - {"default_checks", PARAM_INT, &default_msg_checks }, - {"uri_checks", PARAM_INT, &default_uri_checks }, - {"proxy_require", PARAM_STR, &pr_str }, - {"autodrop", PARAM_INT, &_sanity_drop }, - {"noreply", PARAM_INT, &ksr_sanity_noreply }, + {"default_checks", PARAM_INT, &default_msg_checks }, + {"uri_checks", PARAM_INT, &default_uri_checks }, + {"proxy_require", PARAM_STR, &pr_str }, + {"autodrop", PARAM_INT, &_sanity_drop }, + {"noreply", PARAM_INT, &ksr_sanity_noreply }, + {"always_log_missed_content_length", PARAM_INT, &always_log_missed_content_length }, {0, 0, 0} }; diff --git a/src/modules/sanity/sanity_mod.h b/src/modules/sanity/sanity_mod.h index 2d9e12ff141..f3adcea849d 100644 --- a/src/modules/sanity/sanity_mod.h +++ b/src/modules/sanity/sanity_mod.h @@ -74,6 +74,9 @@ #define SANITY_CHECK_ERROR -1 #define SANITY_CHECK_NOT_APPLICABLE -2 +#define SANITY_DONT_LOG_MISSED_CONTENT_LEN 0 +#define SANITY_LOG_MISSED_CONTENT_LEN 1 + extern int default_checks; extern str_list_t* proxyrequire_list;