Skip to contentSkip to conversation

rtsp-conntrack without needing NAT

PATCH Steven Van Acker 2 participants 5 messages Sep 14, 2006 – Sep 15, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi,

the rtsp-conntrack patch I found at
http://www.freenux.org/~mm/rtsp/2.6.15-rtsp.patch applies nicely to the kernels I compile with Full NAT support, but not without.

This is caused by calls to NAT functions from within ip_conntrack_rtsp.c

For the past couple days, I've tried to make sense of connectiontracking and NAT code and I believe my version of the patch should fix the problem.

I've compiled it without problems, and the modules load.
But since I've never really messed with kernel code before, I don't know if I broke anything or introduced bugs anywhere.

Maybe someone with more experience can look over the patch and see if it makes sense ?

kind regards,
-- Steven Van Acker

Signature · 2 lines
My amazon wishlist:
http://www.amazon.com/gp/registry/1DB4XNEIEQBPB
include/linux/netfilter_helpers.h +133 -0
diff -urN linux-2.6.15.orig/include/linux/netfilter_helpers.h linux-2.6.15/include/linux/netfilter_helpers.h
@@ -0,0 +1,133 @@
+/*
+ * Helpers for netfiler modules.  This file provides implementations for basic
+ * functions such as strncasecmp(), etc.
+ *
+ * gcc will warn for defined but unused functions, so we only include the
+ * functions requested.  The following macros are used:
+ *   NF_NEED_STRNCASECMP        nf_strncasecmp()
+ *   NF_NEED_STRTOU16           nf_strtou16()
+ *   NF_NEED_STRTOU32           nf_strtou32()
+ */
+#ifndef _NETFILTER_HELPERS_H
+#define _NETFILTER_HELPERS_H
+
+/* Only include these functions for kernel code. */
+#ifdef __KERNEL__
+
+#include <linux/ctype.h>
+#define iseol(c) ( (c) == '\r' || (c) == '\n' )
+
+/*
+ * The standard strncasecmp()
+ */
+#ifdef NF_NEED_STRNCASECMP
+static int
+nf_strncasecmp(const char* s1, const char* s2, u_int32_t len)
+{
+    if (s1 == NULL || s2 == NULL)
+    {
+        if (s1 == NULL && s2 == NULL)
+        {
+            return 0;
+        }
+        return (s1 == NULL) ? -1 : 1;
+    }
+    while (len > 0 && tolower(*s1) == tolower(*s2))
+    {
+        len--;
+        s1++;
+        s2++;
+    }
+    return ( (len == 0) ? 0 : (tolower(*s1) - tolower(*s2)) );
+}
+#endif /* NF_NEED_STRNCASECMP */
+
+/*
+ * Parse a string containing a 16-bit unsigned integer.
+ * Returns the number of chars used, or zero if no number is found.
+ */
+#ifdef NF_NEED_STRTOU16
+static int
+nf_strtou16(const char* pbuf, u_int16_t* pval)
+{
+    int n = 0;
+
+    *pval = 0;
+    while (isdigit(pbuf[n]))
+    {
+        *pval = (*pval * 10) + (pbuf[n] - '0');
+        n++;
+    }
+
+    return n;
+}
+#endif /* NF_NEED_STRTOU16 */
+
+/*
+ * Parse a string containing a 32-bit unsigned integer.
+ * Returns the number of chars used, or zero if no number is found.
+ */
+#ifdef NF_NEED_STRTOU32
+static int
+nf_strtou32(const char* pbuf, u_int32_t* pval)
+{
+    int n = 0;
+
+    *pval = 0;
+    while (pbuf[n] >= '0' && pbuf[n] <= '9')
+    {
+        *pval = (*pval * 10) + (pbuf[n] - '0');
+        n++;
+    }
+
+    return n;
+}
+#endif /* NF_NEED_STRTOU32 */
+
+/*
+ * Given a buffer and length, advance to the next line and mark the current
+ * line.
+ */
+#ifdef NF_NEED_NEXTLINE
+static int
+nf_nextline(char* p, uint len, uint* poff, uint* plineoff, uint* plinelen)
+{
+    uint    off = *poff;
+    uint    physlen = 0;
+
+    if (off >= len)
+    {
+        return 0;
+    }
+
+    while (p[off] != '\n')
+    {
+        if (len-off <= 1)
+        {
+            return 0;
+        }
+
+        physlen++;
+        off++;
+    }
+
+    /* if we saw a crlf, physlen needs adjusted */
+    if (physlen > 0 && p[off] == '\n' && p[off-1] == '\r')
+    {
+        physlen--;
+    }
+
+    /* advance past the newline */
+    off++;
+
+    *plineoff = *poff;
+    *plinelen = physlen;
+    *poff = off;
+
+    return 1;
+}
+#endif /* NF_NEED_NEXTLINE */
+
+#endif /* __KERNEL__ */
+
+#endif /* _NETFILTER_HELPERS_H */
include/linux/netfilter_ipv4/ip_conntrack_rtsp.h +63 -0

63 lines not on this page · raw message

include/linux/netfilter_mime.h +89 -0

89 lines not on this page · raw message

net/ipv4/netfilter/Kconfig +16 -0
diff -urN linux-2.6.15.orig/net/ipv4/netfilter/Kconfig linux-2.6.15/net/ipv4/netfilter/Kconfig
@@ -842,5 +842,21 @@
 	  Allows altering the ARP packet payload: source and destination
 	  hardware and network addresses.
 
+config IP_NF_NAT_RTSP
+	tristate
+	depends on IP_NF_CONNTRACK!=n && IP_NF_NAT!=n
+	default IP_NF_NAT if IP_NF_RTSP=y
+	default m if IP_NF_RTSP=m
+
+config IP_NF_RTSP
+	tristate  ' RTSP protocol support'
+	depends on IP_NF_CONNTRACK
+	help
+	  Support the RTSP protocol.  This allows UDP transports to be setup
+	  properly, including RTP and RDT.
+	
+	  If you want to compile it as a module, say 'M' here and read
+	  Documentation/modules.txt.  If unsure, say 'Y'.
+
 endmenu
 
net/ipv4/netfilter/Makefile +2 -0
diff -urN linux-2.6.15.orig/net/ipv4/netfilter/Makefile linux-2.6.15/net/ipv4/netfilter/Makefile
@@ -22,3 +22,5 @@
 obj-$(CONFIG_IP_NF_PPTP) += ip_conntrack_pptp.o
+obj-$(CONFIG_IP_NF_RTSP) += ip_conntrack_rtsp.o
+obj-$(CONFIG_IP_NF_NAT_RTSP) += ip_nat_rtsp.o
 obj-$(CONFIG_IP_NF_AMANDA) += ip_conntrack_amanda.o
 obj-$(CONFIG_IP_NF_TFTP) += ip_conntrack_tftp.o
net/ipv4/netfilter/ip_conntrack_rtsp.c +526 -0

526 lines not on this page · raw message

net/ipv4/netfilter/ip_nat_rtsp.c +502 -0

502 lines not on this page · raw message

#1 lore raw
Quoted 12 lines · Steven Van Acker

Hi,

the rtsp-conntrack patch I found at
http://www.freenux.org/~mm/rtsp/2.6.15-rtsp.patch applies nicely to the kernels I compile with Full NAT support, but not without.

This is caused by calls to NAT functions from within ip_conntrack_rtsp.c

For the past couple days, I've tried to make sense of connectiontracking and NAT code and I believe my version of the patch should fix the problem.

Quoted 6 lines

I've compiled it without problems, and the modules load.
But since I've never really messed with kernel code before, I don't know if I broke anything or introduced bugs anywhere.

Maybe someone with more experience can look over the patch and see if it makes sense ?

You're more likely to find someone if you post your changes as a patch to the original version.

#2 lore raw
Quoted 4 lines · Patrick McHardy

You're more likely to find someone if you post your changes as a patch to the original version.

Sorry about that. I recreated the patch based on the latest pom-ng snapshot (patch-o-matic-ng-20060914)

kind regards,
-- Steven

patchlets/rtsp-conntrack/linux-2.6.11/include/linux/netfilter_ipv4/ip_conntrack_rtsp.h +9 -2
diff -Naur patch-o-matic-ng-20060913/patchlets/rtsp-conntrack/linux-2.6.11/include/linux/netfilter_ipv4/ip_conntrack_rtsp.h patch-o-matic-ng-20060913-patched-rtsp/patchlets/rtsp-conntrack/linux-2.6.11/include/linux/netfilter_ipv4/ip_conntrack_rtsp.h
@@ -11,9 +11,10 @@
 #ifndef _IP_CONNTRACK_RTSP_H
 #define _IP_CONNTRACK_RTSP_H
 
-/* #define IP_NF_RTSP_DEBUG */
+//#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 */
@@ -47,7 +48,13 @@
 #endif
 };
 
-#ifdef __KERNEL__
+extern unsigned int (*ip_nat_rtsp_hook)(struct sk_buff **pskb,
+				 enum ip_conntrack_info ctinfo,
+				 unsigned int matchoff, unsigned int matchlen,
+				 struct ip_ct_rtsp_expect *expinfo,
+				 struct ip_conntrack_expect *exp);
+
+extern void (*ip_nat_rtsp_hook_expectfn)(struct ip_conntrack *ct, struct ip_conntrack_expect *exp);
 
 #define RTSP_PORT   554
 
patchlets/rtsp-conntrack/linux-2.6.11/net/ipv4/netfilter/ip_conntrack_rtsp.c +346 -351

784 lines not on this page · raw message

patchlets/rtsp-conntrack/linux-2.6.11/net/ipv4/netfilter/ip_nat_rtsp.c +46 -47

193 lines not on this page · raw message

#3 lore raw
Quoted 2 lines · Steven Van Acker

Sorry about that. I recreated the patch based on the latest pom-ng snapshot (patch-o-matic-ng-20060914)

Umph, this is getting really embarassing...
Someone complained that I didn't use the --ignore-space-change and --ignore-tab-expansion options of diff, resulting in a large patchfile.

I recreated the patchfile again.

kinds regards,
-- Steven

#4 lore raw
In reply to Steven Van Acker
Quoted 2 lines · Steven Van Acker

Sorry about that. I recreated the patch based on the latest pom-ng snapshot (patch-o-matic-ng-20060914)

Umph, this is getting really embarassing...
Someone complained that I didn't use the --ignore-space-change and --ignore-tab-expansion options of diff, resulting in a large patchfile.

I recreated the patchfile again.

kinds regards,
-- Steven
PS: This time with patch attached... I need some coffee

patchlets/rtsp-conntrack/linux-2.6.11/include/linux/netfilter_ipv4/ip_conntrack_rtsp.h +9 -2
diff -NEbaur patch-o-matic-ng-20060913/patchlets/rtsp-conntrack/linux-2.6.11/include/linux/netfilter_ipv4/ip_conntrack_rtsp.h patch-o-matic-ng-20060999/patchlets/rtsp-conntrack/linux-2.6.11/include/linux/netfilter_ipv4/ip_conntrack_rtsp.h
@@ -11,9 +11,10 @@
 #ifndef _IP_CONNTRACK_RTSP_H
 #define _IP_CONNTRACK_RTSP_H
 
-/* #define IP_NF_RTSP_DEBUG */
+//#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 */
@@ -47,7 +48,13 @@
 #endif
 };
 
-#ifdef __KERNEL__
+extern unsigned int (*ip_nat_rtsp_hook)(struct sk_buff **pskb,
+				 enum ip_conntrack_info ctinfo,
+				 unsigned int matchoff, unsigned int matchlen,
+				 struct ip_ct_rtsp_expect *expinfo,
+				 struct ip_conntrack_expect *exp);
+
+extern void (*ip_nat_rtsp_hook_expectfn)(struct ip_conntrack *ct, struct ip_conntrack_expect *exp);
 
 #define RTSP_PORT   554
 
patchlets/rtsp-conntrack/linux-2.6.11/net/ipv4/netfilter/ip_conntrack_rtsp.c +100 -105

423 lines not on this page · raw message

patchlets/rtsp-conntrack/linux-2.6.11/net/ipv4/netfilter/ip_nat_rtsp.c +46 -47

193 lines not on this page · raw message