From 86d8ccc9701101d55b46efff9f75e2d6685e9e29 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Wed, 29 Nov 2017 10:48:19 +0100 Subject: [PATCH] SAT>IP server: add configuration to limit maximal count of sessions and user connections, fixes #4735 From: Mono Polimorph --- src/satip/rtsp.c | 21 ++++++++++++++++++++- src/satip/server.c | 20 ++++++++++++++++++++ src/satip/server.h | 2 ++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/satip/rtsp.c b/src/satip/rtsp.c index 7cda53e1f..d9a651ccf 100644 --- a/src/satip/rtsp.c +++ b/src/satip/rtsp.c @@ -183,8 +183,25 @@ result: static struct session * rtsp_new_session(const char *ipstr, int delsys, uint32_t nsession, int session) { - struct session *rs = calloc(1, sizeof(*rs)); + struct session *rs = NULL; + int count_s = satip_server_conf.satip_max_sessions; + int count_u = satip_server_conf.satip_max_user_connections; + + if (count_s > 0 || count_u > 0) + TAILQ_FOREACH(rs, &rtsp_sessions, link) { + if (--count_s == 0) { + tvhnotice(LS_SATIPS, "Max number (%i) of active RTSP sessions reached.", + satip_server_conf.satip_max_sessions); + return NULL; + } + if (strcmp(rs->peer_ipstr, ipstr) == 0 && --count_i == 0) { + tvhnotice(LS_SATIPS, "Max number (%i) of active RTSP sessions per user (IP: %s).", + satip_server_conf.satip_max_user_connections, strdup(ipstr)); + return NULL; + } + } + rs = calloc(1, sizeof(*rs)); if (rs == NULL) return NULL; @@ -1024,12 +1041,14 @@ rtsp_parse_cmd if (cmd == RTSP_CMD_SETUP) { if (!rs) { rs = rtsp_new_session(hc->hc_peer_ipstr, msys, 0, -1); + if (rs == NULL) goto end; if (delsys == DVB_SYS_NONE) goto end; if (msys == DVB_SYS_NONE) goto end; if (!(*valid)) goto end; alloc_stream_id = 1; } else if (stream != rs->stream) { rs = rtsp_new_session(hc->hc_peer_ipstr, msys, rs->nsession, stream); + if (rs == NULL) goto end; if (delsys == DVB_SYS_NONE) goto end; if (msys == DVB_SYS_NONE) goto end; if (!(*valid)) goto end; diff --git a/src/satip/server.c b/src/satip/server.c index 57d8487cb..ba05491b9 100644 --- a/src/satip/server.c +++ b/src/satip/server.c @@ -872,6 +872,26 @@ const idclass_t satip_server_class = { .off = offsetof(struct satip_server_conf, satip_atsc_c), .group = 4, }, + { + .type = PT_INT, + .id = "satip_max_sessions", + .name = N_("Max Sessions"), + .desc = N_("The maximum number of active RTSP sessions " + "(if 0 no limit)."), + .off = offsetof(struct satip_server_conf, satip_max_sessions), + .opts = PO_ADVANCED, + .group = 4, + }, + { + .type = PT_INT, + .id = "satip_max_user_connections", + .name = N_("Max User connections"), + .desc = N_("The maximum concurrent RTSP connections from the " + "same IP address (if 0 no limit)."), + .off = offsetof(struct satip_server_conf, satip_max_user_connections), + .opts = PO_ADVANCED, + .group = 4, + }, { .type = PT_BOOL, .id = "satip_rewrite_pmt", diff --git a/src/satip/server.h b/src/satip/server.h index f72c01a8e..5b9ecbdb3 100644 --- a/src/satip/server.h +++ b/src/satip/server.h @@ -63,6 +63,8 @@ struct satip_server_conf { int satip_dvbc2; int satip_atsc_t; int satip_atsc_c; + int satip_max_sessions; + int satip_max_user_connections; char *satip_nat_ip; int satip_nat_rtsp; int satip_nat_name_force; -- 2.47.3