]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
SAT>IP server: add configuration to limit maximal count of sessions and user connecti...
authorJaroslav Kysela <perex@perex.cz>
Wed, 29 Nov 2017 09:48:19 +0000 (10:48 +0100)
committerJaroslav Kysela <perex@perex.cz>
Wed, 29 Nov 2017 09:49:59 +0000 (10:49 +0100)
From: Mono Polimorph

src/satip/rtsp.c
src/satip/server.c
src/satip/server.h

index 7cda53e1ffce49b9de374bcc0b8e8b761adc142f..d9a651ccf25124663143633e59e1aca879ca0343 100644 (file)
@@ -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;
index 57d8487cb8589858ff784517638945a966f5584e..ba05491b9f975d43eec4370d0bbb2a7ae1a2c4b5 100644 (file)
@@ -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",
index f72c01a8ea77951d2de7108b6eb8c633cb1b1596..5b9ecbdb352d5d61d88526d3f3ad9ca96e30c3f5 100644 (file)
@@ -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;