From 7ed2a99eb55df82538bb03be171afe9dd556019e Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Wed, 13 Oct 2021 18:21:52 +0300 Subject: [PATCH] [mod_sofia] Implement maximum receiving requests per second max-recv-requests-per-second profile parameter. (Warning: Behaviour change. New default is 1000 requests per second) --- conf/vanilla/sip_profiles/internal-ipv6.xml | 2 ++ conf/vanilla/sip_profiles/internal.xml | 2 ++ src/mod/endpoints/mod_sofia/conf/sofia.conf.xml | 2 ++ src/mod/endpoints/mod_sofia/mod_sofia.c | 2 ++ src/mod/endpoints/mod_sofia/mod_sofia.h | 1 + src/mod/endpoints/mod_sofia/sofia.c | 12 ++++++++++++ 6 files changed, 21 insertions(+) diff --git a/conf/vanilla/sip_profiles/internal-ipv6.xml b/conf/vanilla/sip_profiles/internal-ipv6.xml index 21bb1f1e77..f067ae7482 100644 --- a/conf/vanilla/sip_profiles/internal-ipv6.xml +++ b/conf/vanilla/sip_profiles/internal-ipv6.xml @@ -36,6 +36,8 @@ + + diff --git a/conf/vanilla/sip_profiles/internal.xml b/conf/vanilla/sip_profiles/internal.xml index 85692fa631..749e4b0687 100644 --- a/conf/vanilla/sip_profiles/internal.xml +++ b/conf/vanilla/sip_profiles/internal.xml @@ -172,6 +172,8 @@ + + diff --git a/src/mod/endpoints/mod_sofia/conf/sofia.conf.xml b/src/mod/endpoints/mod_sofia/conf/sofia.conf.xml index 37e0937aeb..0f5db4468f 100644 --- a/src/mod/endpoints/mod_sofia/conf/sofia.conf.xml +++ b/src/mod/endpoints/mod_sofia/conf/sofia.conf.xml @@ -205,6 +205,8 @@ + + diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 1637cff924..a3a6cd8e91 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -3061,6 +3061,7 @@ static switch_status_t cmd_status(char **argv, int argc, switch_stream_handle_t stream->write_function(stream, "CNG \t%d\n", profile->cng_pt); stream->write_function(stream, "SESSION-TO \t%d\n", profile->session_timeout); stream->write_function(stream, "MAX-DIALOG \t%d\n", profile->max_proceeding); + stream->write_function(stream, "MAX-RECV-RPS \t%d\n", profile->max_recv_requests_per_second); stream->write_function(stream, "NOMEDIA \t%s\n", sofia_test_flag(profile, TFLAG_INB_NOMEDIA) ? "true" : "false"); stream->write_function(stream, "LATE-NEG \t%s\n", sofia_test_flag(profile, TFLAG_LATE_NEGOTIATION) ? "true" : "false"); stream->write_function(stream, "PROXY-MEDIA \t%s\n", sofia_test_flag(profile, TFLAG_PROXY_MEDIA) ? "true" : "false"); @@ -3363,6 +3364,7 @@ static switch_status_t cmd_xml_status(char **argv, int argc, switch_stream_handl stream->write_function(stream, " %d\n", profile->cng_pt); stream->write_function(stream, " %d\n", profile->session_timeout); stream->write_function(stream, " %d\n", profile->max_proceeding); + stream->write_function(stream, " %d\n", profile->max_recv_requests_per_second); stream->write_function(stream, " %s\n", sofia_test_flag(profile, TFLAG_INB_NOMEDIA) ? "true" : "false"); stream->write_function(stream, " %s\n", sofia_test_flag(profile, TFLAG_LATE_NEGOTIATION) ? "true" : "false"); stream->write_function(stream, " %s\n", sofia_test_flag(profile, TFLAG_PROXY_MEDIA) ? "true" : "false"); diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index 6e118e1fe3..3408b7ca0b 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -722,6 +722,7 @@ struct sofia_profile { uint32_t session_timeout; uint32_t minimum_session_expires; uint32_t max_proceeding; + uint32_t max_recv_requests_per_second; uint32_t rtp_timeout_sec; uint32_t rtp_hold_timeout_sec; char *odbc_dsn; diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 25e3278c97..36f3087db1 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -3345,6 +3345,7 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void TAG_IF(profile->session_timeout && profile->minimum_session_expires, NUTAG_MIN_SE(profile->minimum_session_expires)), NUTAG_SESSION_TIMER(profile->session_timeout), NTATAG_MAX_PROCEEDING(profile->max_proceeding), + NTATAG_MAX_RECV_REQUESTS_PER_SECOND(profile->max_recv_requests_per_second), TAG_IF(profile->pres_type, NUTAG_ALLOW("PUBLISH")), TAG_IF(profile->pres_type, NUTAG_ALLOW("SUBSCRIBE")), TAG_IF(profile->pres_type, NUTAG_ENABLEMESSAGE(1)), @@ -4571,6 +4572,7 @@ switch_status_t config_sofia(sofia_config_t reload, char *profile_name) char *auth_subscriptions_value = NULL; uint8_t disable_message_auth_flag = 0; uint8_t disable_subscription_auth_flag = 0; + uint8_t max_recv_requests_per_second_initialized = 0; if (!xprofilename) { xprofilename = "unnamed"; @@ -5307,6 +5309,12 @@ switch_status_t config_sofia(sofia_config_t reload, char *profile_name) if (v_max_proceeding >= 0) { profile->max_proceeding = v_max_proceeding; } + } else if (!strcasecmp(var, "max-recv-requests-per-second") && !zstr(val)) { + int v_max_recv_requests_per_second = atoi(val); + if (v_max_recv_requests_per_second >= 0) { + profile->max_recv_requests_per_second = v_max_recv_requests_per_second; + max_recv_requests_per_second_initialized = 1; + } } else if (!strcasecmp(var, "rtp-timeout-sec") && !zstr(val)) { int v = atoi(val); if (v >= 0) { @@ -6097,6 +6105,10 @@ switch_status_t config_sofia(sofia_config_t reload, char *profile_name) } } + if (!max_recv_requests_per_second_initialized) { + profile->max_recv_requests_per_second = 1000; + } + if (!disable_message_auth_flag) { if (!auth_messages_value || switch_true(auth_messages_value)) { sofia_set_pflag(profile, PFLAG_AUTH_MESSAGES);