diff --git a/src/satip/rtsp.c b/src/satip/rtsp.c index 7cda53e..de1ebbe 100644 --- a/src/satip/rtsp.c +++ b/src/satip/rtsp.c @@ -183,8 +183,28 @@ 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) { + count_s--; + 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, strdup(ipstr)) == 0) + count_u--; + if (count_u == 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 +1044,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 57d8487..ba05491 100644 --- a/src/satip/server.c +++ b/src/satip/server.c @@ -873,6 +873,26 @@ const idclass_t satip_server_class = { .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", .name = N_("Rewrite PMT"), diff --git a/src/satip/server.h b/src/satip/server.h index f72c01a..5b9ecbd 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;