Browse Source

xtables-addons: rtsp: support destination format address:port

RFC2326 specifies the attribute client_port as the RTP/RTCP port pair on
which the client has chosen to receive media data and control info;
however some clients (mostly STBs) embed the client_port value in the
destination attribute in the form of destination=<address:port> without
specifying the client_port attribute in the SETUP message.
To support such clients check if the destination attribute contains a
port value and use it as port value for the expected RTP connection.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
lilik-openwrt-22.03
Hans Dedecker 6 years ago
parent
commit
ab48f4df18
2 changed files with 55 additions and 11 deletions
  1. +1
    -1
      net/xtables-addons/Makefile
  2. +54
    -10
      net/xtables-addons/patches/100-add-rtsp-conntrack.patch

+ 1
- 1
net/xtables-addons/Makefile View File

@ -10,7 +10,7 @@ include $(INCLUDE_DIR)/kernel.mk
PKG_NAME:=xtables-addons PKG_NAME:=xtables-addons
PKG_VERSION:=2.14 PKG_VERSION:=2.14
PKG_RELEASE:=4
PKG_RELEASE:=5
PKG_HASH:=d215a9a8b8e66aae04b982fa2e1228e8a71e7dfe42320df99e34e5000cbdf152 PKG_HASH:=d215a9a8b8e66aae04b982fa2e1228e8a71e7dfe42320df99e34e5000cbdf152
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz


+ 54
- 10
net/xtables-addons/patches/100-add-rtsp-conntrack.patch View File

@ -235,7 +235,7 @@
+#endif /* _NETFILTER_MIME_H */ +#endif /* _NETFILTER_MIME_H */
--- /dev/null --- /dev/null
+++ b/extensions/rtsp/nf_conntrack_rtsp.c +++ b/extensions/rtsp/nf_conntrack_rtsp.c
@@ -0,0 +1,735 @@
@@ -0,0 +1,761 @@
+/* +/*
+ * RTSP extension for IP connection tracking + * RTSP extension for IP connection tracking
+ * (C) 2003 by Tom Marshall <tmarshall at real.com> + * (C) 2003 by Tom Marshall <tmarshall at real.com>
@ -257,6 +257,9 @@
+ * 2018-04-18: Hans Dedecker <dedeckeh at gmail.com> + * 2018-04-18: Hans Dedecker <dedeckeh at gmail.com>
+ * - update RTP expected connection source IP based on SOURCE + * - update RTP expected connection source IP based on SOURCE
+ * in the SETUP reply message + * in the SETUP reply message
+ * 2018-08-03: Alin Nastac <alin.nastac at gmail.com>
+ * Hans Dedecker <dedeckeh at gmail.com>
+ * - parse non-standard destination=address:port format
+ * + *
+ * based on ip_conntrack_irc.c + * based on ip_conntrack_irc.c
+ * + *
@ -501,6 +504,29 @@
+ -1, NULL)) + -1, NULL))
+ pr_debug("source found : %pI4\n", + pr_debug("source found : %pI4\n",
+ &prtspexp->srvaddr.ip); + &prtspexp->srvaddr.ip);
+ } else if (nextfieldoff - off > 12 && strncmp(ptran+off, "destination=", 12) == 0) {
+ const char *psep;
+ u_int16_t port;
+
+ off += 12;
+
+ if (in4_pton(ptran+off, nextfieldoff - off - 1, (u8 *)&prtspexp->cltaddr.in, -1, NULL)) {
+ pr_debug("destination found : %pI4\n", &prtspexp->cltaddr.ip);
+
+ /*
+ * Some RTSP clients(mostly STBs) use non-standard destination parameters:
+ * destination=address:port
+ */
+ psep = memchr(ptran+off, ':', nextfieldoff-off);
+ if (psep != NULL && nf_strtou16(psep + 1, &port)) {
+ if (prtspexp->loport != 0 && prtspexp->loport != port)
+ pr_debug("multiple ports found, port %hu ignored\n", port);
+ else {
+ pr_debug("lo port found : %hu\n", port);
+ prtspexp->loport = prtspexp->hiport = port;
+ }
+ }
+ }
+ } + }
+ +
+ /* + /*
@ -973,7 +999,7 @@
+module_exit(fini); +module_exit(fini);
--- /dev/null --- /dev/null
+++ b/extensions/rtsp/nf_conntrack_rtsp.h +++ b/extensions/rtsp/nf_conntrack_rtsp.h
@@ -0,0 +1,73 @@
@@ -0,0 +1,74 @@
+/* +/*
+ * RTSP extension for IP connection tracking. + * RTSP extension for IP connection tracking.
+ * (C) 2003 by Tom Marshall <tmarshall at real.com> + * (C) 2003 by Tom Marshall <tmarshall at real.com>
@ -1025,6 +1051,7 @@
+ u_int16_t loport; /* Port that was requested, low or first */ + u_int16_t loport; /* Port that was requested, low or first */
+ u_int16_t hiport; /* Port that was requested, high or second */ + u_int16_t hiport; /* Port that was requested, high or second */
+ union nf_inet_addr srvaddr; /* src address in SETUP reply */ + union nf_inet_addr srvaddr; /* src address in SETUP reply */
+ union nf_inet_addr cltaddr; /* destination address */
+#if 0 +#if 0
+ uint method; /* RTSP method */ + uint method; /* RTSP method */
+ uint cseq; /* CSeq from request */ + uint cseq; /* CSeq from request */
@ -1049,7 +1076,7 @@
+#endif /* _IP_CONNTRACK_RTSP_H */ +#endif /* _IP_CONNTRACK_RTSP_H */
--- /dev/null --- /dev/null
+++ b/extensions/rtsp/nf_nat_rtsp.c +++ b/extensions/rtsp/nf_nat_rtsp.c
@@ -0,0 +1,617 @@
@@ -0,0 +1,634 @@
+/* +/*
+ * RTSP extension for TCP NAT alteration + * RTSP extension for TCP NAT alteration
+ * (C) 2003 by Tom Marshall <tmarshall at real.com> + * (C) 2003 by Tom Marshall <tmarshall at real.com>
@ -1209,9 +1236,9 @@
+ struct nf_conntrack_tuple *rtp_t; + struct nf_conntrack_tuple *rtp_t;
+ +
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
+ char szextaddr[INET6_ADDRSTRLEN];
+ char szextaddr[INET6_ADDRSTRLEN + 16];
+#else +#else
+ char szextaddr[INET_ADDRSTRLEN];
+ char szextaddr[INET_ADDRSTRLEN + 16];
+#endif +#endif
+ uint extaddrlen; + uint extaddrlen;
+ int is_stun; + int is_stun;
@ -1344,8 +1371,9 @@
+ +
+ pfieldend = memchr(ptran+off, ';', nextparamoff-off); + pfieldend = memchr(ptran+off, ';', nextparamoff-off);
+ nextfieldoff = (pfieldend == NULL) ? nextparamoff : pfieldend-ptran+1; + nextfieldoff = (pfieldend == NULL) ? nextparamoff : pfieldend-ptran+1;
+ SKIP_WSPACE(ptran, nextfieldoff, off);
+ +
+ if (dstact != DSTACT_NONE && strncmp(ptran+off, "destination=", 12) == 0) {
+ if (dstact != DSTACT_NONE && nextfieldoff - off > 12 && strncmp(ptran+off, "destination=", 12) == 0) {
+ if (strncmp(ptran+off+12, szextaddr, extaddrlen) == 0) + if (strncmp(ptran+off+12, szextaddr, extaddrlen) == 0)
+ is_stun = 1; + is_stun = 1;
+ +
@ -1356,12 +1384,28 @@
+ uint dstreplen = 0; + uint dstreplen = 0;
+ diff = dstlen; + diff = dstlen;
+ if (dstact == DSTACT_AUTO && !is_stun) { + if (dstact == DSTACT_AUTO && !is_stun) {
+ pr_debug("RTSP: replace dst addr\n");
+ const char* psep = memchr(ptran+off, ':', dstlen);
+ u_int16_t port;
+
+ dstoff += 12; + dstoff += 12;
+ dstlen -= 13; + dstlen -= 13;
+ pdstrep = szextaddr; + pdstrep = szextaddr;
+ dstreplen = extaddrlen;
+ diff = nextfieldoff-off-13-extaddrlen;
+
+ if (psep != NULL && nf_strtou16(psep + 1, &port)) {
+ pr_debug("RTSP: replace dst addr&port\n");
+
+ if (port != prtspexp->loport) {
+ pr_debug("multiple ports found, port %hu ignored\n", port);
+ dstreplen = extaddrlen;
+ } else {
+ sprintf(szextaddr+extaddrlen, ":%s", rbuf1);
+ dstreplen = extaddrlen+1+rbuf1len;
+ }
+ } else {
+ pr_debug("RTSP: replace dst addr\n");
+ dstreplen = extaddrlen;
+ }
+ diff = nextfieldoff-off-13-dstreplen;
+ } + }
+ +
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
@ -1399,7 +1443,7 @@
+ pfieldend = memchr(ptran+off, ';', nextparamoff-off); + pfieldend = memchr(ptran+off, ';', nextparamoff-off);
+ nextfieldoff = (pfieldend == NULL) ? nextparamoff : pfieldend-ptran+1; + nextfieldoff = (pfieldend == NULL) ? nextparamoff : pfieldend-ptran+1;
+ +
+ if (strncmp(ptran+off, "client_port=", 12) == 0) {
+ if (nextfieldoff - off > 12 && strncmp(ptran+off, "client_port=", 12) == 0) {
+ u_int16_t port; + u_int16_t port;
+ uint numlen; + uint numlen;
+ uint origoff; + uint origoff;


Loading…
Cancel
Save