SOURCES (LINUX_2_6_22): kernel-nf_rtsp.patch - raw http://mike.it-...
zbyniu
zbyniu at pld-linux.org
Thu Mar 13 22:26:05 CET 2008
Author: zbyniu Date: Thu Mar 13 21:26:05 2008 GMT
Module: SOURCES Tag: LINUX_2_6_22
---- Log message:
- raw http://mike.it-loops.com/rtsp/rtsp-2.6.22.patch
---- Files affected:
SOURCES:
kernel-nf_rtsp.patch (1.1 -> 1.1.2.1)
---- Diffs:
================================================================
Index: SOURCES/kernel-nf_rtsp.patch
diff -u SOURCES/kernel-nf_rtsp.patch:1.1 SOURCES/kernel-nf_rtsp.patch:1.1.2.1
--- SOURCES/kernel-nf_rtsp.patch:1.1 Thu Mar 13 20:33:29 2008
+++ SOURCES/kernel-nf_rtsp.patch Thu Mar 13 22:26:00 2008
@@ -1,6 +1,73 @@
-diff -purN linux-2.6.23-rc2.orig/include/linux/netfilter_helpers.h linux-2.6.23-rc2/include/linux/netfilter_helpers.h
---- linux-2.6.23-rc2.orig/include/linux/netfilter_helpers.h 1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.23-rc2/include/linux/netfilter_helpers.h 2007-08-05 10:53:55.000000000 +0200
+diff -urN linux-2.6.21-rc7/include/linux/netfilter/nf_conntrack_rtsp.h linux-2.6.21-rc7.rtsp/include/linux/netfilter/nf_conntrack_rtsp.h
+--- linux-2.6.21-rc7/include/linux/netfilter/nf_conntrack_rtsp.h 1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.21-rc7.rtsp/include/linux/netfilter/nf_conntrack_rtsp.h 2007-04-16 14:07:06.000000000 +0200
+@@ -0,0 +1,63 @@
++/*
++ * RTSP extension for IP connection tracking.
++ * (C) 2003 by Tom Marshall <tmarshall at real.com>
++ * based on ip_conntrack_irc.h
++ *
++ * This program is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU General Public License
++ * as published by the Free Software Foundation; either version
++ * 2 of the License, or (at your option) any later version.
++ */
++#ifndef _IP_CONNTRACK_RTSP_H
++#define _IP_CONNTRACK_RTSP_H
++
++//#define IP_NF_RTSP_DEBUG 1
++#define IP_NF_RTSP_VERSION "0.6.21"
++
++#ifdef __KERNEL__
++/* port block types */
++typedef enum {
++ pb_single, /* client_port=x */
++ pb_range, /* client_port=x-y */
++ pb_discon /* client_port=x/y (rtspbis) */
++} portblock_t;
++
++/* We record seq number and length of rtsp headers here, all in host order. */
++
++/*
++ * This structure is per expected connection. It is a member of struct
++ * ip_conntrack_expect. The TCP SEQ for the conntrack expect is stored
++ * there and we are expected to only store the length of the data which
++ * needs replaced. If a packet contains multiple RTSP messages, we create
++ * one expected connection per message.
++ *
++ * We use these variables to mark the entire header block. This may seem
++ * like overkill, but the nature of RTSP requires it. A header may appear
++ * multiple times in a message. We must treat two Transport headers the
++ * same as one Transport header with two entries.
++ */
++struct ip_ct_rtsp_expect
++{
++ u_int32_t len; /* length of header block */
++ portblock_t pbtype; /* Type of port block that was requested */
++ u_int16_t loport; /* Port that was requested, low or first */
++ u_int16_t hiport; /* Port that was requested, high or second */
++#if 0
++ uint method; /* RTSP method */
++ uint cseq; /* CSeq from request */
++#endif
++};
++
++extern unsigned int (*nf_nat_rtsp_hook)(struct sk_buff **pskb,
++ enum ip_conntrack_info ctinfo,
++ unsigned int matchoff, unsigned int matchlen,
++ struct ip_ct_rtsp_expect *prtspexp,
++ struct nf_conntrack_expect *exp);
++
++extern void (*nf_nat_rtsp_hook_expectfn)(struct nf_conn *ct, struct nf_conntrack_expect *exp);
++
++#define RTSP_PORT 554
++
++#endif /* __KERNEL__ */
++
++#endif /* _IP_CONNTRACK_RTSP_H */
+diff -urN linux-2.6.21-rc7/include/linux/netfilter_helpers.h linux-2.6.21-rc7.rtsp/include/linux/netfilter_helpers.h
+--- linux-2.6.21-rc7/include/linux/netfilter_helpers.h 1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.21-rc7.rtsp/include/linux/netfilter_helpers.h 2007-04-15 00:34:57.000000000 +0200
@@ -0,0 +1,133 @@
+/*
+ * Helpers for netfiler modules. This file provides implementations for basic
@@ -135,9 +202,9 @@
+#endif /* __KERNEL__ */
+
+#endif /* _NETFILTER_HELPERS_H */
-diff -purN linux-2.6.23-rc2.orig/include/linux/netfilter_mime.h linux-2.6.23-rc2/include/linux/netfilter_mime.h
---- linux-2.6.23-rc2.orig/include/linux/netfilter_mime.h 1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.23-rc2/include/linux/netfilter_mime.h 2007-08-05 10:53:55.000000000 +0200
+diff -urN linux-2.6.21-rc7/include/linux/netfilter_mime.h linux-2.6.21-rc7.rtsp/include/linux/netfilter_mime.h
+--- linux-2.6.21-rc7/include/linux/netfilter_mime.h 1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.21-rc7.rtsp/include/linux/netfilter_mime.h 2007-04-15 00:34:57.000000000 +0200
@@ -0,0 +1,89 @@
+/*
+ * MIME functions for netfilter modules. This file provides implementations
@@ -228,25 +295,10 @@
+#endif /* __KERNEL__ */
+
+#endif /* _NETFILTER_MIME_H */
-diff -purN linux-2.6.23-rc2.orig/net/ipv4/netfilter/Kconfig linux-2.6.23-rc2/net/ipv4/netfilter/Kconfig
---- linux-2.6.23-rc2.orig/net/ipv4/netfilter/Kconfig 2007-08-05 21:17:01.000000000 +0200
-+++ linux-2.6.23-rc2/net/ipv4/netfilter/Kconfig 2007-08-05 11:04:59.000000000 +0200
-@@ -274,6 +274,11 @@ config NF_NAT_IRC
- depends on IP_NF_IPTABLES && NF_CONNTRACK && NF_NAT
- default NF_NAT && NF_CONNTRACK_IRC
-
-+config NF_NAT_RTSP
-+ tristate
-+ depends on IP_NF_IPTABLES && NF_CONNTRACK && NF_NAT
-+ default NF_NAT && NF_CONNTRACK_RTSP
-+
- config NF_NAT_TFTP
- tristate
- depends on IP_NF_IPTABLES && NF_CONNTRACK && NF_NAT
-diff -purN linux-2.6.23-rc2.orig/net/ipv4/netfilter/Makefile linux-2.6.23-rc2/net/ipv4/netfilter/Makefile
---- linux-2.6.23-rc2.orig/net/ipv4/netfilter/Makefile 2007-08-05 21:14:19.000000000 +0200
-+++ linux-2.6.23-rc2/net/ipv4/netfilter/Makefile 2007-08-05 10:53:55.000000000 +0200
-@@ -23,6 +23,7 @@ obj-$(CONFIG_NF_NAT_AMANDA) += nf_nat_am
+diff -urN linux-2.6.21-rc7/net/ipv4/netfilter/Makefile linux-2.6.21-rc7.rtsp/net/ipv4/netfilter/Makefile
+--- linux-2.6.21-rc7/net/ipv4/netfilter/Makefile 2007-04-18 23:26:10.000000000 +0200
++++ linux-2.6.21-rc7.rtsp/net/ipv4/netfilter/Makefile 2007-04-18 21:17:33.000000000 +0200
+@@ -64,6 +66,7 @@
obj-$(CONFIG_NF_NAT_FTP) += nf_nat_ftp.o
obj-$(CONFIG_NF_NAT_H323) += nf_nat_h323.o
obj-$(CONFIG_NF_NAT_IRC) += nf_nat_irc.o
@@ -254,10 +306,10 @@
obj-$(CONFIG_NF_NAT_PPTP) += nf_nat_pptp.o
obj-$(CONFIG_NF_NAT_SIP) += nf_nat_sip.o
obj-$(CONFIG_NF_NAT_SNMP_BASIC) += nf_nat_snmp_basic.o
-diff -purN linux-2.6.23-rc2.orig/net/netfilter/Kconfig linux-2.6.23-rc2/net/netfilter/Kconfig
---- linux-2.6.23-rc2.orig/net/netfilter/Kconfig 2007-08-05 21:17:02.000000000 +0200
-+++ linux-2.6.23-rc2/net/netfilter/Kconfig 2007-08-05 11:04:59.000000000 +0200
-@@ -249,6 +249,16 @@ config NF_CONNTRACK_TFTP
+diff -urN linux-2.6.21-rc7/net/netfilter/Kconfig linux-2.6.21-rc7.rtsp/net/netfilter/Kconfig
+--- linux-2.6.21-rc7/net/netfilter/Kconfig 2007-04-18 23:26:10.000000000 +0200
++++ linux-2.6.21-rc7.rtsp/net/netfilter/Kconfig 2007-04-18 22:25:13.000000000 +0200
+@@ -271,6 +272,16 @@
To compile it as a module, choose M here. If unsure, say N.
@@ -274,10 +326,10 @@
config NF_CT_NETLINK
tristate 'Connection tracking netlink interface (EXPERIMENTAL)'
depends on EXPERIMENTAL && NF_CONNTRACK && NETFILTER_NETLINK
-diff -purN linux-2.6.23-rc2.orig/net/netfilter/Makefile linux-2.6.23-rc2/net/netfilter/Makefile
---- linux-2.6.23-rc2.orig/net/netfilter/Makefile 2007-08-05 21:17:02.000000000 +0200
-+++ linux-2.6.23-rc2/net/netfilter/Makefile 2007-08-05 11:04:59.000000000 +0200
-@@ -33,6 +33,7 @@ obj-$(CONFIG_NF_CONNTRACK_PPTP) += nf_co
+diff -urN linux-2.6.21-rc7/net/netfilter/Makefile linux-2.6.21-rc7.rtsp/net/netfilter/Makefile
+--- linux-2.6.21-rc7/net/netfilter/Makefile 2007-04-18 23:26:10.000000000 +0200
++++ linux-2.6.21-rc7.rtsp/net/netfilter/Makefile 2007-04-18 21:17:33.000000000 +0200
+@@ -32,6 +32,7 @@
obj-$(CONFIG_NF_CONNTRACK_SANE) += nf_conntrack_sane.o
obj-$(CONFIG_NF_CONNTRACK_SIP) += nf_conntrack_sip.o
obj-$(CONFIG_NF_CONNTRACK_TFTP) += nf_conntrack_tftp.o
@@ -285,81 +337,27 @@
# generic X tables
obj-$(CONFIG_NETFILTER_XTABLES) += x_tables.o xt_tcpudp.o
-diff -purN linux-2.6.24-rc1.orig/include/linux/netfilter/nf_conntrack_rtsp.h linux-2.6.24-rc1/include/linux/netfilter/nf_conntrack_rtsp.h
---- linux-2.6.24-rc1.orig/include/linux/netfilter/nf_conntrack_rtsp.h 1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.24-rc1/include/linux/netfilter/nf_conntrack_rtsp.h 2007-11-10 17:16:36.000000000 +0100
-@@ -0,0 +1,63 @@
-+/*
-+ * RTSP extension for IP connection tracking.
-+ * (C) 2003 by Tom Marshall <tmarshall at real.com>
-+ * based on ip_conntrack_irc.h
-+ *
-+ * This program is free software; you can redistribute it and/or
-+ * modify it under the terms of the GNU General Public License
-+ * as published by the Free Software Foundation; either version
-+ * 2 of the License, or (at your option) any later version.
-+ */
-+#ifndef _IP_CONNTRACK_RTSP_H
-+#define _IP_CONNTRACK_RTSP_H
-+
-+//#define IP_NF_RTSP_DEBUG 1
-+#define IP_NF_RTSP_VERSION "0.6.21"
-+
-+#ifdef __KERNEL__
-+/* port block types */
-+typedef enum {
-+ pb_single, /* client_port=x */
-+ pb_range, /* client_port=x-y */
-+ pb_discon /* client_port=x/y (rtspbis) */
-+} portblock_t;
-+
-+/* We record seq number and length of rtsp headers here, all in host order. */
-+
-+/*
-+ * This structure is per expected connection. It is a member of struct
-+ * ip_conntrack_expect. The TCP SEQ for the conntrack expect is stored
-+ * there and we are expected to only store the length of the data which
-+ * needs replaced. If a packet contains multiple RTSP messages, we create
-+ * one expected connection per message.
-+ *
-+ * We use these variables to mark the entire header block. This may seem
-+ * like overkill, but the nature of RTSP requires it. A header may appear
-+ * multiple times in a message. We must treat two Transport headers the
-+ * same as one Transport header with two entries.
-+ */
-+struct ip_ct_rtsp_expect
-+{
-+ u_int32_t len; /* length of header block */
-+ portblock_t pbtype; /* Type of port block that was requested */
-+ u_int16_t loport; /* Port that was requested, low or first */
-+ u_int16_t hiport; /* Port that was requested, high or second */
-+#if 0
-+ uint method; /* RTSP method */
-+ uint cseq; /* CSeq from request */
-+#endif
-+};
-+
-+extern unsigned int (*nf_nat_rtsp_hook)(struct sk_buff *skb,
-+ enum ip_conntrack_info ctinfo,
-+ unsigned int matchoff, unsigned int matchlen,
-+ struct ip_ct_rtsp_expect *prtspexp,
-+ struct nf_conntrack_expect *exp);
-+
-+extern void (*nf_nat_rtsp_hook_expectfn)(struct nf_conn *ct, struct nf_conntrack_expect *exp);
-+
-+#define RTSP_PORT 554
-+
-+#endif /* __KERNEL__ */
+--- linux-2.6.22.1/net/ipv4/netfilter/Kconfig.orig 2007-07-29 23:57:51.000000000 +0200
++++ linux-2.6.22.1/net/ipv4/netfilter/Kconfig 2007-07-30 00:00:19.000000000 +0200
+@@ -274,6 +274,11 @@
+ depends on IP_NF_IPTABLES && NF_CONNTRACK && NF_NAT
+ default NF_NAT && NF_CONNTRACK_IRC
+
++config NF_NAT_RTSP
++ tristate
++ depends on IP_NF_IPTABLES && NF_CONNTRACK && NF_NAT
++ default NF_NAT && NF_CONNTRACK_RTSP
+
-+#endif /* _IP_CONNTRACK_RTSP_H */
-diff -purN linux-2.6.24-rc1.orig/net/ipv4/netfilter/nf_nat_rtsp.c linux-2.6.24-rc1/net/ipv4/netfilter/nf_nat_rtsp.c
---- linux-2.6.24-rc1.orig/net/ipv4/netfilter/nf_nat_rtsp.c 1970-01-01 01:00:00.000000000 +0100
-+++ linux-2.6.24-rc1/net/ipv4/netfilter/nf_nat_rtsp.c 2007-11-10 17:17:21.000000000 +0100
-@@ -0,0 +1,489 @@
+ config NF_NAT_TFTP
+ tristate
+ depends on IP_NF_IPTABLES && NF_CONNTRACK && NF_NAT
+--- linux-2.6.22.1/net/netfilter/nf_conntrack_rtsp.c.orig 2007-07-30 17:37:14.000000000 +0200
++++ linux-2.6.22.1/net/netfilter/nf_conntrack_rtsp.c 2007-07-30 00:03:07.000000000 +0200
+@@ -0,0 +1,515 @@
+/*
-+ * RTSP extension for TCP NAT alteration
++ * RTSP extension for IP connection tracking
+ * (C) 2003 by Tom Marshall <tmarshall at real.com>
-+ * based on ip_nat_irc.c
++ * based on ip_conntrack_irc.c
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
@@ -367,492 +365,517 @@
+ * 2 of the License, or (at your option) any later version.
+ *
+ * Module load syntax:
-+ * insmod nf_nat_rtsp.o ports=port1,port2,...port<MAX_PORTS>
-+ * stunaddr=<address>
-+ * destaction=[auto|strip|none]
++ * insmod nf_conntrack_rtsp.o ports=port1,port2,...port<MAX_PORTS>
++ * max_outstanding=n setup_timeout=secs
+ *
-+ * If no ports are specified, the default will be port 554 only.
++ * If no ports are specified, the default will be port 554.
+ *
-+ * stunaddr specifies the address used to detect that a client is using STUN.
-+ * If this address is seen in the destination parameter, it is assumed that
-+ * the client has already punched a UDP hole in the firewall, so we don't
-+ * mangle the client_port. If none is specified, it is autodetected. It
-+ * only needs to be set if you have multiple levels of NAT. It should be
-+ * set to the external address that the STUN clients detect. Note that in
-+ * this case, it will not be possible for clients to use UDP with servers
-+ * between the NATs.
++ * With max_outstanding you can define the maximum number of not yet
++ * answered SETUP requests per RTSP session (default 8).
++ * With setup_timeout you can specify how long the system waits for
++ * an expected data channel (default 300 seconds).
+ *
-+ * If no destaction is specified, auto is used.
-+ * destaction=auto: strip destination parameter if it is not stunaddr.
-+ * destaction=strip: always strip destination parameter (not recommended).
-+ * destaction=none: do not touch destination parameter (not recommended).
++ * 2005-02-13: Harald Welte <laforge at netfilter.org>
++ * - port to 2.6
++ * - update to recent post-2.6.11 api changes
++ * 2006-09-14: Steven Van Acker <deepstar at singularity.be>
++ * - removed calls to NAT code from conntrack helper: NAT no longer needed to use rtsp-conntrack
++ * 2007-04-18: Michael Guntsche <mike at it-loops.com>
++ * - Port to new NF API
+ */
+
+#include <linux/module.h>
++#include <linux/netfilter.h>
++#include <linux/ip.h>
++#include <linux/inet.h>
+#include <net/tcp.h>
-+#include <net/netfilter/nf_nat_helper.h>
-+#include <net/netfilter/nf_nat_rule.h>
-+#include <linux/netfilter/nf_conntrack_rtsp.h>
++
++#include <net/netfilter/nf_conntrack.h>
+#include <net/netfilter/nf_conntrack_expect.h>
++#include <net/netfilter/nf_conntrack_helper.h>
++#include <linux/netfilter/nf_conntrack_rtsp.h>
+
-+#include <linux/inet.h>
-+#include <linux/ctype.h>
+#define NF_NEED_STRNCASECMP
+#define NF_NEED_STRTOU16
++#define NF_NEED_STRTOU32
++#define NF_NEED_NEXTLINE
+#include <linux/netfilter_helpers.h>
+#define NF_NEED_MIME_NEXTLINE
+#include <linux/netfilter_mime.h>
+
-+#define MAX_PORTS 8
-+#define DSTACT_AUTO 0
-+#define DSTACT_STRIP 1
-+#define DSTACT_NONE 2
-+
-+static char* stunaddr = NULL;
-+static char* destaction = NULL;
++#include <linux/ctype.h>
++#define MAX_SIMUL_SETUP 8 /* XXX: use max_outstanding */
++#define INFOP(fmt, args...) printk(KERN_INFO "%s: %s: " fmt, __FILE__, __FUNCTION__ , ## args)
++#if 0
++#define DEBUGP(fmt, args...) printk(KERN_DEBUG "%s: %s: " fmt, __FILE__, __FUNCTION__ , ## args)
++#else
++#define DEBUGP(fmt, args...)
++#endif
+
-+static u_int32_t extip = 0;
-+static int dstact = 0;
++#define MAX_PORTS 8
++static int ports[MAX_PORTS];
++static int num_ports = 0;
++static int max_outstanding = 8;
++static unsigned int setup_timeout = 300;
+
+MODULE_AUTHOR("Tom Marshall <tmarshall at real.com>");
-+MODULE_DESCRIPTION("RTSP network address translation module");
++MODULE_DESCRIPTION("RTSP connection tracking module");
+MODULE_LICENSE("GPL");
-+module_param(stunaddr, charp, 0644);
-+MODULE_PARM_DESC(stunaddr, "Address for detecting STUN");
-+module_param(destaction, charp, 0644);
-+MODULE_PARM_DESC(destaction, "Action for destination parameter (auto/strip/none)");
++module_param_array(ports, int, &num_ports, 0400);
++MODULE_PARM_DESC(ports, "port numbers of RTSP servers");
++module_param(max_outstanding, int, 0400);
++MODULE_PARM_DESC(max_outstanding, "max number of outstanding SETUP requests per RTSP session");
++module_param(setup_timeout, int, 0400);
++MODULE_PARM_DESC(setup_timeout, "timeout on for unestablished data channels");
+
-+#define SKIP_WSPACE(ptr,len,off) while(off < len && isspace(*(ptr+off))) { off++; }
++static char *rtsp_buffer;
++static DEFINE_SPINLOCK(rtsp_buffer_lock);
+
-+/*** helper functions ***/
++unsigned int (*nf_nat_rtsp_hook)(struct sk_buff **pskb,
++ enum ip_conntrack_info ctinfo,
++ unsigned int matchoff, unsigned int matchlen,struct ip_ct_rtsp_expect* prtspexp,
++ struct nf_conntrack_expect *exp);
++void (*nf_nat_rtsp_hook_expectfn)(struct nf_conn *ct, struct nf_conntrack_expect *exp);
+
-+static void
-+get_skb_tcpdata(struct sk_buff* skb, char** pptcpdata, uint* ptcpdatalen)
-+{
-+ struct iphdr* iph = ip_hdr(skb);
-+ struct tcphdr* tcph = (void *)iph + ip_hdrlen(skb);
++EXPORT_SYMBOL_GPL(nf_nat_rtsp_hook);
+
-+ *pptcpdata = (char*)tcph + tcph->doff*4;
-+ *ptcpdatalen = ((char*)skb_transport_header(skb) + skb->len) - *pptcpdata;
-+}
++/*
++ * Max mappings we will allow for one RTSP connection (for RTP, the number
++ * of allocated ports is twice this value). Note that SMIL burns a lot of
++ * ports so keep this reasonably high. If this is too low, you will see a
++ * lot of "no free client map entries" messages.
++ */
++#define MAX_PORT_MAPS 16
+
-+/*** nat functions ***/
++/*** default port list was here in the masq code: 554, 3030, 4040 ***/
++
++#define SKIP_WSPACE(ptr,len,off) while(off < len && isspace(*(ptr+off))) { off++; }
+
+/*
-+ * Mangle the "Transport:" header:
-+ * - Replace all occurences of "client_port=<spec>"
-+ * - Handle destination parameter
++ * Parse an RTSP packet.
++ *
++ * Returns zero if parsing failed.
+ *
++ * Parameters:
++ * IN ptcp tcp data pointer
++ * IN tcplen tcp data len
++ * IN/OUT ptcpoff points to current tcp offset
++ * OUT phdrsoff set to offset of rtsp headers
++ * OUT phdrslen set to length of rtsp headers
++ * OUT pcseqoff set to offset of CSeq header
++ * OUT pcseqlen set to length of CSeq header
++ */
++static int
++rtsp_parse_message(char* ptcp, uint tcplen, uint* ptcpoff,
++ uint* phdrsoff, uint* phdrslen,
++ uint* pcseqoff, uint* pcseqlen,
++ uint* transoff, uint* translen)
++{
++ uint entitylen = 0;
++ uint lineoff;
++ uint linelen;
++
++ if (!nf_nextline(ptcp, tcplen, ptcpoff, &lineoff, &linelen))
++ return 0;
++
++ *phdrsoff = *ptcpoff;
++ while (nf_mime_nextline(ptcp, tcplen, ptcpoff, &lineoff, &linelen)) {
++ if (linelen == 0) {
++ if (entitylen > 0)
++ *ptcpoff += min(entitylen, tcplen - *ptcpoff);
++ break;
++ }
++ if (lineoff+linelen > tcplen) {
++ INFOP("!! overrun !!\n");
++ break;
++ }
++
++ if (nf_strncasecmp(ptcp+lineoff, "CSeq:", 5) == 0) {
++ *pcseqoff = lineoff;
++ *pcseqlen = linelen;
++ }
++
++ if (nf_strncasecmp(ptcp+lineoff, "Transport:", 10) == 0) {
++ *transoff = lineoff;
++ *translen = linelen;
++ }
++
++ if (nf_strncasecmp(ptcp+lineoff, "Content-Length:", 15) == 0) {
++ uint off = lineoff+15;
++ SKIP_WSPACE(ptcp+lineoff, linelen, off);
++ nf_strtou32(ptcp+off, &entitylen);
++ }
++ }
++ *phdrslen = (*ptcpoff) - (*phdrsoff);
++
++ return 1;
++}
++
++/*
++ * Find lo/hi client ports (if any) in transport header
+ * In:
-+ * ct, ctinfo = conntrack context
-+ * skb = packet
-+ * tranoff = Transport header offset from TCP data
-+ * tranlen = Transport header length (incl. CRLF)
-+ * rport_lo = replacement low port (host endian)
-+ * rport_hi = replacement high port (host endian)
++ * ptcp, tcplen = packet
++ * tranoff, tranlen = buffer to search
+ *
-+ * Returns packet size difference.
++ * Out:
++ * pport_lo, pport_hi = lo/hi ports (host endian)
+ *
-+ * Assumes that a complete transport header is present, ending with CR or LF
++ * Returns nonzero if any client ports found
++ *
++ * Note: it is valid (and expected) for the client to request multiple
++ * transports, so we need to parse the entire line.
+ */
+static int
-+rtsp_mangle_tran(enum ip_conntrack_info ctinfo,
-+ struct nf_conntrack_expect* exp,
-+ struct ip_ct_rtsp_expect* prtspexp,
-+ struct sk_buff* skb, uint tranoff, uint tranlen)
++rtsp_parse_transport(char* ptran, uint tranlen,
++ struct ip_ct_rtsp_expect* prtspexp)
+{
-+ char* ptcp;
-+ uint tcplen;
-+ char* ptran;
-+ char rbuf1[16]; /* Replacement buffer (one port) */
-+ uint rbuf1len; /* Replacement len (one port) */
-+ char rbufa[16]; /* Replacement buffer (all ports) */
-+ uint rbufalen; /* Replacement len (all ports) */
-+ u_int32_t newip;
-+ u_int16_t loport, hiport;
-+ uint off = 0;
-+ uint diff; /* Number of bytes we removed */
++ int rc = 0;
++ uint off = 0;
++
++ if (tranlen < 10 || !iseol(ptran[tranlen-1]) ||
++ nf_strncasecmp(ptran, "Transport:", 10) != 0) {
++ INFOP("sanity check failed\n");
++ return 0;
++ }
++
++ DEBUGP("tran='%.*s'\n", (int)tranlen, ptran);
++ off += 10;
++ SKIP_WSPACE(ptran, tranlen, off);
++
++ /* Transport: tran;field;field=val,tran;field;field=val,... */
++ while (off < tranlen) {
++ const char* pparamend;
++ uint nextparamoff;
++
++ pparamend = memchr(ptran+off, ',', tranlen-off);
++ pparamend = (pparamend == NULL) ? ptran+tranlen : pparamend+1;
++ nextparamoff = pparamend-ptran;
++
++ while (off < nextparamoff) {
++ const char* pfieldend;
++ uint nextfieldoff;
++
++ pfieldend = memchr(ptran+off, ';', nextparamoff-off);
++ nextfieldoff = (pfieldend == NULL) ? nextparamoff : pfieldend-ptran+1;
++
++ if (strncmp(ptran+off, "client_port=", 12) == 0) {
++ u_int16_t port;
++ uint numlen;
++
++ off += 12;
++ numlen = nf_strtou16(ptran+off, &port);
++ off += numlen;
++ if (prtspexp->loport != 0 && prtspexp->loport != port)
++ DEBUGP("multiple ports found, port %hu ignored\n", port);
++ else {
++ DEBUGP("lo port found : %hu\n", port);
++ prtspexp->loport = prtspexp->hiport = port;
++ if (ptran[off] == '-') {
++ off++;
++ numlen = nf_strtou16(ptran+off, &port);
++ off += numlen;
++ prtspexp->pbtype = pb_range;
++ prtspexp->hiport = port;
++
++ // If we have a range, assume rtp:
++ // loport must be even, hiport must be loport+1
++ if ((prtspexp->loport & 0x0001) != 0 ||
++ prtspexp->hiport != prtspexp->loport+1) {
++ DEBUGP("incorrect range: %hu-%hu, correcting\n",
++ prtspexp->loport, prtspexp->hiport);
++ prtspexp->loport &= 0xfffe;
++ prtspexp->hiport = prtspexp->loport+1;
++ }
++ } else if (ptran[off] == '/') {
++ off++;
++ numlen = nf_strtou16(ptran+off, &port);
++ off += numlen;
++ prtspexp->pbtype = pb_discon;
++ prtspexp->hiport = port;
++ }
++ rc = 1;
++ }
++ }
++
++ /*
++ * Note we don't look for the destination parameter here.
++ * If we are using NAT, the NAT module will handle it. If not,
++ * and the client is sending packets elsewhere, the expectation
++ * will quietly time out.
++ */
++
++ off = nextfieldoff;
++ }
++
++ off = nextparamoff;
++ }
++
++ return rc;
++}
+
-+ struct nf_conn *ct = exp->master;
-+ struct nf_conntrack_tuple *t;
++void expected(struct nf_conn *ct, struct nf_conntrack_expect *exp)
++{
++ if(nf_nat_rtsp_hook_expectfn) {
++ nf_nat_rtsp_hook_expectfn(ct,exp);
++ }
++}
+
-+ char szextaddr[15+1];
-+ uint extaddrlen;
-+ int is_stun;
++/*** conntrack functions ***/
+
-+ get_skb_tcpdata(skb, &ptcp, &tcplen);
-+ ptran = ptcp+tranoff;
++/* outbound packet: client->server */
+
<<Diff was trimmed, longer than 597 lines>>
---- CVS-web:
http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/SOURCES/kernel-nf_rtsp.patch?r1=1.1&r2=1.1.2.1&f=u
More information about the pld-cvs-commit
mailing list