Skip to contentSkip to conversation

Fwd: [Fwd: Re: trying to revive rtsp]

Fwd: Re: trying to revive rtsp Punky 2 participants 2 messages Feb 27, 2006 – Mar 11, 2006 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Punky

author
#1 lore raw

Hi all,

I am helping Mickael to resend his rtsp patch as he found his mail can't get to the list promptly. As far, I am able to use his patch on my own 2.6.15 kernel. He already has another cleaner version of the patch and will post to the list later.

- Punky

---------- Forwarded message ----------
From: Mickael Marchand <[email protected]>
Date: Feb 21, 2006 2:56 PM
Subject: [Fwd: Re: trying to revive rtsp]
To: [email protected]

resent to you as my mail to netfilter-devel seems to take ages to get in ...

Cheers,
Mik

-------- Original Message --------
Subject: Re: trying to revive rtsp
Date: Mon, 20 Feb 2006 21:16:49 +0100
From: Mickael Marchand <[email protected]>
To: Patrick McHardy <[email protected]>
CC: [email protected]
References: <[email protected]> <[email protected]>

Hi,

thanks for the tip Patrick, there were 2 bugs in my expectation paquet as you thought, and I was missing the expectfn function mainly.

after fighting some hours with the code, importing old code back, merging code from ip_conntrack_irc, I have been able to watch 3 RTSP streams simultaneously behind my iptables firewall :)

it's probably bad code that definitely needs review and help from others, my knowledge of netfilter being so low.

full patch against 2.6.15 attached

I will try to improve it if experienced netfilter people can give me the good directions.

all comments are welcome :)

and well, of course, testers are welcome too.

Cheers,
Mik

Quoted 35 lines · Patrick McHardy
Quoted 33 lines · Mickael Marchand

Hi,

I am really a newbie to the netfilter coding world, so please forgive any stupid questions :)

I have mostly ported the old rtsp conntrack+nat code to recent 2.6 kernels, compiles and loads fine into the kernel,
but I have some problems to make it work now :)

the initial TCP connexion to the RTSP server:554 is correctly detected and the expectation packet seems to be properly setup :
cat /proc/net/ip_conntrack_expect
255 proto=17 src=212.27.38.253 dst=10.0.0.2 sport=0 dport=33302

212.27.38.253 is the RTSP server, 10.0.0.2 is the client, 10.0.0.1 is the netfilter box.

so once the TCP connexion has been established, we expect a UDP stream from the server going to the client port 33302.

my problem is that the expected packet does not get through the netfilter box, I can see the UDP stream coming from the RTSP server and going to my netfilter box,
the expectation packet seems to get removed of /proc/net/ip_conntrack_expect as well (so basically it looks all good) but the netfilter box does not forward packets to 10.0.0.2. so it looks like a NAT problem to me, maybe the UDP packets are not getting NAT-ed back to the client.

my first question would be :
is it expected to see 10.0.0.2 in the expected paquet ? should not it be my external IP instead ?

Quoted 6 lines
Quoted 1 line

any tips in what direction I could look ? :)

Probably something related to the expect API changes and/or missing initializations. Compare your helper with other helpers and make sure you initialize all fields of struct ip_conntrack_expect properly.

--
--
Regards,
Punky
P U N K N ! X . c o m
Technology + Lifestyle
(http://www.punknix.com)

Voyage Linux
(http://www.voyage.hk/software/voyage.html)

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 +60 -0

60 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 +5 -0
diff -urN linux-2.6.15.orig/net/ipv4/netfilter/Makefile linux-2.6.15/net/ipv4/netfilter/Makefile
@@ -22,6 +22,11 @@
 obj-$(CONFIG_IP_NF_CT_PROTO_SCTP) += ip_conntrack_proto_sctp.o
 
 # connection tracking helpers
+
+# rtsp protocol support
+obj-$(CONFIG_IP_NF_RTSP) += ip_conntrack_rtsp.o
+obj-$(CONFIG_IP_NF_NAT_RTSP) += ip_nat_rtsp.o
+
 obj-$(CONFIG_IP_NF_PPTP) += ip_conntrack_pptp.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 +536 -0

536 lines not on this page · raw message

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

475 lines not on this page · raw message

#2 lore raw

Hi Guys,

Quoted 4 lines · Punky

I am helping Mickael to resend his rtsp patch as he found his mail can't get to the list promptly. As far, I am able to use his patch on my own 2.6.15 kernel. He already has another cleaner version of the patch and will post to the list later.

I'm looking forward to see this cleaner version of the patch. If it could apply to 2.6.16 it would be even better.
Also I think It would be nice to send a proper message to netfilter-devel with a proper subjet: '[PATCH] message' if you want it to be integrated.

Thanks in advance.