xtables-addons: rstp: use specific source in expected RTP connection
authorHans Dedecker <dedeckeh@gmail.com>
Tue, 17 Apr 2018 15:27:42 +0000 (17:27 +0200)
committerHans Dedecker <dedeckeh@gmail.com>
Wed, 18 Apr 2018 12:32:32 +0000 (14:32 +0200)
Instead of passing a wildcard source to the expected RTP data connection;
use the server IP address of the RTSP SETUP packet or the RTP media source
from the SETUP URI contained in the SETUP packet.
This guarantees RTP data is only accepted from the expected source.

Signed-off-by: Alin Nastac <alin.nastac@gmail.com>
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
net/xtables-addons/patches/100-add-rtsp-conntrack.patch

index bd49d92de627a796709ac3a62cadf2fa9df0826a..917baf41a7408f496ce114614ba6794f2bf07f79 100644 (file)
 +#endif /* _NETFILTER_MIME_H */
 --- /dev/null
 +++ b/extensions/rtsp/nf_conntrack_rtsp.c
-@@ -0,0 +1,576 @@
+@@ -0,0 +1,604 @@
 +/*
 + * RTSP extension for IP connection tracking
 + * (C) 2003 by Tom Marshall <tmarshall at real.com>
 + * 2013-03-04: Il'inykh Sergey <sergeyi at inango-sw.com>. Inango Systems Ltd
 + *    - fixed rtcp nat mapping and other port mapping fixes
 + *    - simple TEARDOWN request handling
-+ *    - codestyle fixes and other less significant bug fixes 
++ *    - codestyle fixes and other less significant bug fixes
++ * 2018-04-17: Alin Nastac <alin.nastac at gmail.com>
++ *             Hans Dedecker <dedeckeh at gmail.com>
++ *       - use IP address read from SETUP URI in expected connections
 + *
 + * based on ip_conntrack_irc.c
 + *
 +              uint transoff = 0;
 +              uint translen = 0;
 +              uint off;
++              union nf_inet_addr srvaddr;
 +              
 +              if (!rtsp_parse_message(pdata, datalen, &dataoff,
 +                                      &hdrsoff, &hdrslen,
 +              if (strncmp(pdata+cmdoff, "SETUP ", 6) != 0)
 +                      continue;   /* not a SETUP message */
 +
++              srvaddr = ct->tuplehash[!dir].tuple.src.u3;
++
++              /* try to get RTP media source from SETUP URI */
++              off = cmdoff + 6;
++              while (off < datalen) {
++                      if (strncmp(pdata+off, "://", 3) == 0) {
++                              off += 3;
++                              cmdoff = off;
++
++                              while (off < datalen) {
++                                      if (pdata[off] == ':' ||
++                                          pdata[off] == '/' ||
++                                          pdata[off] == ' ') {
++                                              in4_pton(pdata + cmdoff,
++                                                       off - cmdoff,
++                                                       (u8 *)&srvaddr.in,
++                                                       -1, NULL);
++                                              break;
++                                      }
++                                      off++;
++                              }
++                              break;
++                      }
++                      off++;
++              }
++
 +              pr_debug("found a setup message\n");
 +
 +              off = 0;
 +              }
 +
 +              nf_ct_expect_init(rtp_exp, NF_CT_EXPECT_CLASS_DEFAULT,
-+                                nf_ct_l3num(ct),
-+                                NULL, /* &ct->tuplehash[!dir].tuple.src.u3, */
++                                nf_ct_l3num(ct), &srvaddr,
 +                                &ct->tuplehash[!dir].tuple.dst.u3,
 +                                IPPROTO_UDP, NULL, &be_loport);
 +
 +                      }
 +
 +                      nf_ct_expect_init(rtcp_exp, NF_CT_EXPECT_CLASS_DEFAULT,
-+                                        nf_ct_l3num(ct),
-+                                        NULL, /* &ct->tuplehash[!dir].tuple.src.u3, */
++                                        nf_ct_l3num(ct), &srvaddr,
 +                                        &ct->tuplehash[!dir].tuple.dst.u3,
 +                                        IPPROTO_UDP, NULL, &be_hiport);
 +