]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
satip server: Support different PORT over NAT FORWARDING, fixes #4617
authorJaroslav Kysela <perex@perex.cz>
Mon, 9 Oct 2017 13:12:46 +0000 (15:12 +0200)
committerJaroslav Kysela <perex@perex.cz>
Mon, 9 Oct 2017 13:44:46 +0000 (15:44 +0200)
From: Mono Polimorph

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

index d36a1afa4b738c37b4263595af8170e38700c7bf..d2d5cb661a9337afab8014b6cff78cc6833175c4 100644 (file)
@@ -81,6 +81,7 @@ static uint16_t stream_id;
 static char *rtsp_ip = NULL;
 static char *rtsp_nat_ip = NULL;
 static int rtsp_port = -1;
+static int rtsp_nat_port = -1;
 static int rtsp_descramble = 1;
 static int rtsp_rewrite_pmt = 0;
 static int rtsp_muxcnf = MUXCNF_AUTO;
@@ -252,6 +253,7 @@ static char *
 rtsp_check_urlbase(char *u)
 {
   char *p, *s;
+  int t;
 
   if (*u == '/' || strncmp(u, "stream=", 7) == 0)
     return u;
@@ -264,8 +266,11 @@ rtsp_check_urlbase(char *u)
     *p = '\0';
   if ((s = strchr(u, ':')) != NULL) {
     *s = '\0';
-    if (atoi(s + 1) != rtsp_port)
-      return NULL;
+    t = atoi(s + 1);
+    if (t != rtsp_port) {
+      if (rtsp_nat_port <= 0 || t != rtsp_nat_port)
+        return NULL;
+    }
   } else {
 #if 0 /* VLC is broken */
     if (rtsp_port != 554)
@@ -1693,7 +1698,7 @@ rtsp_close_sessions(void)
  */
 void satip_server_rtsp_init
   (const char *bindaddr, int port, int descramble, int rewrite_pmt, int muxcnf,
-   const char *nat_ip)
+   const char *nat_ip, int nat_port)
 {
   static tcp_server_ops_t ops = {
     .start  = rtsp_serve,
@@ -1726,6 +1731,7 @@ void satip_server_rtsp_init
   s = rtsp_nat_ip;
   rtsp_nat_ip = nat_ip ? strdup(nat_ip) : NULL;
   free(s);
+  rtsp_nat_port = nat_port;
   if (!rtsp_server)
     rtsp_server = tcp_server_create(LS_SATIPS, "SAT>IP RTSP", bindaddr, port, &ops, NULL);
   if (reg)
@@ -1748,6 +1754,7 @@ void satip_server_rtsp_done(void)
   pthread_mutex_lock(&global_lock);
   rtsp_server = NULL;
   rtsp_port = -1;
+  rtsp_nat_port = -1;
   free(rtsp_ip);
   free(rtsp_nat_ip);
   rtsp_ip = rtsp_nat_ip = NULL;
index 9fba20ef524940167541a4da654988fe3a66bd22..fa958890fcd899a4b19fcf20e0a94b0ee21f294c 100644 (file)
@@ -763,6 +763,16 @@ const idclass_t satip_server_class = {
       .opts   = PO_EXPERT,
       .group  = 1,
     },
+    {
+      .type   = PT_INT,
+      .id     = "satip_nat_rtsp",
+      .name   = N_("External RTSP port (NAT)"),
+      .desc   = N_("Enter external PORT if behind Forwarding redirection."
+                   "(0 = use the same local port)."),
+      .off    = offsetof(struct satip_server_conf, satip_nat_rtsp),
+      .opts   = PO_EXPERT,
+      .group  = 1,
+    },
     {
       .type   = PT_BOOL,
       .id     = "satip_nom3u",
@@ -878,6 +888,7 @@ static void satip_server_init_common(const char *prefix, int announce)
   char http_ip[128];
   int descramble, rewrite_pmt, muxcnf;
   char *nat_ip;
+  int nat_port;
 
   if (satip_server_rtsp_port <= 0)
     return;
@@ -900,13 +911,14 @@ static void satip_server_init_common(const char *prefix, int announce)
   rewrite_pmt = satip_server_conf.satip_rewrite_pmt;
   muxcnf = satip_server_conf.satip_muxcnf;
   nat_ip = strdup(satip_server_conf.satip_nat_ip ?: "");
+  nat_port = satip_server_conf.satip_nat_rtsp ?: satip_server_rtsp_port;
 
   if (announce)
     pthread_mutex_unlock(&global_lock);
 
   pthread_mutex_lock(&satip_server_reinit);
 
-  satip_server_rtsp_init(http_server_ip, satip_server_rtsp_port, descramble, rewrite_pmt, muxcnf, nat_ip);
+  satip_server_rtsp_init(http_server_ip, satip_server_rtsp_port, descramble, rewrite_pmt, muxcnf, nat_ip, nat_port);
   satip_server_info(prefix, descramble, muxcnf);
 
   if (announce)
index 908d9291a48a60b86ae2b4acc7dfa10f1b01d07f..8c3c37ace01893bb809a0a7c7c76157a78cf06bd 100644 (file)
@@ -63,6 +63,7 @@ struct satip_server_conf {
   int satip_atsc_t;
   int satip_atsc_c;
   char *satip_nat_ip;
+  int satip_nat_rtsp;
 };
 
 extern struct satip_server_conf satip_server_conf;
@@ -93,7 +94,7 @@ int satip_rtsp_delsys(int fe, int *findex, const char **ftype);
 
 void satip_server_rtsp_init(const char *bindaddr, int port,
                             int descramble, int rewrite_pmt, int muxcnf,
-                            const char *nat_ip);
+                            const char *nat_ip, int nat_port);
 void satip_server_rtsp_register(void);
 void satip_server_rtsp_done(void);