2 +++ b/extensions/rtsp/Kbuild
6 +obj-m += nf_nat_rtsp.o
7 +obj-m += nf_conntrack_rtsp.o
9 +++ b/extensions/rtsp/netfilter_helpers.h
12 + * Helpers for netfiler modules. This file provides implementations for basic
13 + * functions such as strncasecmp(), etc.
15 + * gcc will warn for defined but unused functions, so we only include the
16 + * functions requested. The following macros are used:
17 + * NF_NEED_STRNCASECMP nf_strncasecmp()
18 + * NF_NEED_STRTOU16 nf_strtou16()
19 + * NF_NEED_STRTOU32 nf_strtou32()
21 +#ifndef _NETFILTER_HELPERS_H
22 +#define _NETFILTER_HELPERS_H
24 +/* Only include these functions for kernel code. */
27 +#include <linux/ctype.h>
28 +#define iseol(c) ( (c) == '\r' || (c) == '\n' )
31 + * The standard strncasecmp()
33 +#ifdef NF_NEED_STRNCASECMP
35 +nf_strncasecmp(const char* s1, const char* s2, u_int32_t len)
37 + if (s1 == NULL || s2 == NULL)
39 + if (s1 == NULL && s2 == NULL)
43 + return (s1 == NULL) ? -1 : 1;
45 + while (len > 0 && tolower(*s1) == tolower(*s2))
51 + return ( (len == 0) ? 0 : (tolower(*s1) - tolower(*s2)) );
53 +#endif /* NF_NEED_STRNCASECMP */
56 + * Parse a string containing a 16-bit unsigned integer.
57 + * Returns the number of chars used, or zero if no number is found.
59 +#ifdef NF_NEED_STRTOU16
61 +nf_strtou16(const char* pbuf, u_int16_t* pval)
66 + while (isdigit(pbuf[n]))
68 + *pval = (*pval * 10) + (pbuf[n] - '0');
74 +#endif /* NF_NEED_STRTOU16 */
77 + * Parse a string containing a 32-bit unsigned integer.
78 + * Returns the number of chars used, or zero if no number is found.
80 +#ifdef NF_NEED_STRTOU32
82 +nf_strtou32(const char* pbuf, u_int32_t* pval)
87 + while (pbuf[n] >= '0' && pbuf[n] <= '9')
89 + *pval = (*pval * 10) + (pbuf[n] - '0');
95 +#endif /* NF_NEED_STRTOU32 */
98 + * Given a buffer and length, advance to the next line and mark the current
101 +#ifdef NF_NEED_NEXTLINE
103 +nf_nextline(char* p, uint len, uint* poff, uint* plineoff, uint* plinelen)
113 + while (p[off] != '\n')
124 + /* if we saw a crlf, physlen needs adjusted */
125 + if (physlen > 0 && p[off] == '\n' && p[off-1] == '\r')
130 + /* advance past the newline */
134 + *plinelen = physlen;
139 +#endif /* NF_NEED_NEXTLINE */
141 +#endif /* __KERNEL__ */
143 +#endif /* _NETFILTER_HELPERS_H */
145 +++ b/extensions/rtsp/netfilter_mime.h
148 + * MIME functions for netfilter modules. This file provides implementations
149 + * for basic MIME parsing. MIME headers are used in many protocols, such as
150 + * HTTP, RTSP, SIP, etc.
152 + * gcc will warn for defined but unused functions, so we only include the
153 + * functions requested. The following macros are used:
154 + * NF_NEED_MIME_NEXTLINE nf_mime_nextline()
156 +#ifndef _NETFILTER_MIME_H
157 +#define _NETFILTER_MIME_H
159 +/* Only include these functions for kernel code. */
162 +#include <linux/ctype.h>
165 + * Given a buffer and length, advance to the next line and mark the current
166 + * line. If the current line is empty, *plinelen will be set to zero. If
167 + * not, it will be set to the actual line length (including CRLF).
169 + * 'line' in this context means logical line (includes LWS continuations).
170 + * Returns 1 on success, 0 on failure.
172 +#ifdef NF_NEED_MIME_NEXTLINE
174 +nf_mime_nextline(char* p, uint len, uint* poff, uint* plineoff, uint* plinelen)
178 + int is_first_line = 1;
187 + while (p[off] != '\n')
198 + /* if we saw a crlf, physlen needs adjusted */
199 + if (physlen > 0 && p[off] == '\n' && p[off-1] == '\r')
204 + /* advance past the newline */
207 + /* check for an empty line */
213 + /* check for colon on the first physical line */
217 + if (memchr(p+(*poff), ':', physlen) == NULL)
223 + while (p[off] == ' ' || p[off] == '\t');
226 + *plinelen = (physlen == 0) ? 0 : (off - *poff);
231 +#endif /* NF_NEED_MIME_NEXTLINE */
233 +#endif /* __KERNEL__ */
235 +#endif /* _NETFILTER_MIME_H */
237 +++ b/extensions/rtsp/nf_conntrack_rtsp.c
240 + * RTSP extension for IP connection tracking
241 + * (C) 2003 by Tom Marshall <tmarshall at real.com>
243 + * 2005-02-13: Harald Welte <laforge at netfilter.org>
245 + * - update to recent post-2.6.11 api changes
246 + * 2006-09-14: Steven Van Acker <deepstar at singularity.be>
247 + * - removed calls to NAT code from conntrack helper: NAT no longer needed to use rtsp-conntrack
248 + * 2007-04-18: Michael Guntsche <mike at it-loops.com>
249 + * - Port to new NF API
250 + * 2013-03-04: Il'inykh Sergey <sergeyi at inango-sw.com>. Inango Systems Ltd
251 + * - fixed rtcp nat mapping and other port mapping fixes
252 + * - simple TEARDOWN request handling
253 + * - codestyle fixes and other less significant bug fixes
255 + * based on ip_conntrack_irc.c
257 + * This program is free software; you can redistribute it and/or
258 + * modify it under the terms of the GNU General Public License
259 + * as published by the Free Software Foundation; either version
260 + * 2 of the License, or (at your option) any later version.
262 + * Module load syntax:
263 + * insmod nf_conntrack_rtsp.o ports=port1,port2,...port<MAX_PORTS>
264 + * max_outstanding=n setup_timeout=secs
266 + * If no ports are specified, the default will be port 554.
268 + * With max_outstanding you can define the maximum number of not yet
269 + * answered SETUP requests per RTSP session (default 8).
270 + * With setup_timeout you can specify how long the system waits for
271 + * an expected data channel (default 300 seconds).
275 +#include <linux/module.h>
276 +#include <linux/netfilter.h>
277 +#include <linux/ip.h>
278 +#include <linux/inet.h>
279 +#include <net/tcp.h>
281 +#include <net/netfilter/nf_conntrack.h>
282 +#include <net/netfilter/nf_conntrack_expect.h>
283 +#include <net/netfilter/nf_conntrack_helper.h>
284 +#include "nf_conntrack_rtsp.h"
286 +#define NF_NEED_STRNCASECMP
287 +#define NF_NEED_STRTOU16
288 +#define NF_NEED_STRTOU32
289 +#define NF_NEED_NEXTLINE
290 +#include "netfilter_helpers.h"
291 +#define NF_NEED_MIME_NEXTLINE
292 +#include "netfilter_mime.h"
294 +#include <linux/ctype.h>
297 +static int ports[MAX_PORTS];
298 +static int num_ports = 0;
299 +static int max_outstanding = 8;
300 +static unsigned int setup_timeout = 300;
302 +MODULE_AUTHOR("Tom Marshall <tmarshall at real.com>");
303 +MODULE_DESCRIPTION("RTSP connection tracking module");
304 +MODULE_LICENSE("GPL");
305 +module_param_array(ports, int, &num_ports, 0400);
306 +MODULE_PARM_DESC(ports, "port numbers of RTSP servers");
307 +module_param(max_outstanding, int, 0400);
308 +MODULE_PARM_DESC(max_outstanding, "max number of outstanding SETUP requests per RTSP session");
309 +module_param(setup_timeout, int, 0400);
310 +MODULE_PARM_DESC(setup_timeout, "timeout on for unestablished data channels");
312 +static char *rtsp_buffer;
313 +static DEFINE_SPINLOCK(rtsp_buffer_lock);
315 +static struct nf_conntrack_expect_policy rtsp_exp_policy;
317 +unsigned int (*nf_nat_rtsp_hook)(struct sk_buff *skb,
318 + enum ip_conntrack_info ctinfo,
319 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
320 + unsigned int protoff,
322 + unsigned int matchoff, unsigned int matchlen,
323 + struct ip_ct_rtsp_expect* prtspexp,
324 + struct nf_conntrack_expect *rtp_exp,
325 + struct nf_conntrack_expect *rtcp_exp);
327 +EXPORT_SYMBOL_GPL(nf_nat_rtsp_hook);
330 + * Max mappings we will allow for one RTSP connection (for RTP, the number
331 + * of allocated ports is twice this value). Note that SMIL burns a lot of
332 + * ports so keep this reasonably high. If this is too low, you will see a
333 + * lot of "no free client map entries" messages.
335 +#define MAX_PORT_MAPS 16
337 +/*** default port list was here in the masq code: 554, 3030, 4040 ***/
339 +#define SKIP_WSPACE(ptr,len,off) while(off < len && isspace(*(ptr+off))) { off++; }
342 + * Parse an RTSP packet.
344 + * Returns zero if parsing failed.
347 + * IN ptcp tcp data pointer
348 + * IN tcplen tcp data len
349 + * IN/OUT ptcpoff points to current tcp offset
350 + * OUT phdrsoff set to offset of rtsp headers
351 + * OUT phdrslen set to length of rtsp headers
352 + * OUT pcseqoff set to offset of CSeq header
353 + * OUT pcseqlen set to length of CSeq header
356 +rtsp_parse_message(char* ptcp, uint tcplen, uint* ptcpoff,
357 + uint* phdrsoff, uint* phdrslen,
358 + uint* pcseqoff, uint* pcseqlen,
359 + uint* transoff, uint* translen)
361 + uint entitylen = 0;
365 + if (!nf_nextline(ptcp, tcplen, ptcpoff, &lineoff, &linelen))
368 + *phdrsoff = *ptcpoff;
369 + while (nf_mime_nextline(ptcp, tcplen, ptcpoff, &lineoff, &linelen)) {
370 + if (linelen == 0) {
372 + *ptcpoff += min(entitylen, tcplen - *ptcpoff);
375 + if (lineoff+linelen > tcplen) {
376 + pr_info("!! overrun !!\n");
380 + if (nf_strncasecmp(ptcp+lineoff, "CSeq:", 5) == 0) {
381 + *pcseqoff = lineoff;
382 + *pcseqlen = linelen;
385 + if (nf_strncasecmp(ptcp+lineoff, "Transport:", 10) == 0) {
386 + *transoff = lineoff;
387 + *translen = linelen;
390 + if (nf_strncasecmp(ptcp+lineoff, "Content-Length:", 15) == 0) {
391 + uint off = lineoff+15;
392 + SKIP_WSPACE(ptcp+lineoff, linelen, off);
393 + nf_strtou32(ptcp+off, &entitylen);
396 + *phdrslen = (*ptcpoff) - (*phdrsoff);
402 + * Find lo/hi client ports (if any) in transport header
404 + * ptcp, tcplen = packet
405 + * tranoff, tranlen = buffer to search
408 + * pport_lo, pport_hi = lo/hi ports (host endian)
410 + * Returns nonzero if any client ports found
412 + * Note: it is valid (and expected) for the client to request multiple
413 + * transports, so we need to parse the entire line.
416 +rtsp_parse_transport(char* ptran, uint tranlen,
417 + struct ip_ct_rtsp_expect* prtspexp)
422 + if (tranlen < 10 || !iseol(ptran[tranlen-1]) ||
423 + nf_strncasecmp(ptran, "Transport:", 10) != 0) {
424 + pr_info("sanity check failed\n");
428 + pr_debug("tran='%.*s'\n", (int)tranlen, ptran);
430 + SKIP_WSPACE(ptran, tranlen, off);
432 + /* Transport: tran;field;field=val,tran;field;field=val,... */
433 + while (off < tranlen) {
434 + const char* pparamend;
437 + pparamend = memchr(ptran+off, ',', tranlen-off);
438 + pparamend = (pparamend == NULL) ? ptran+tranlen : pparamend+1;
439 + nextparamoff = pparamend-ptran;
441 + while (off < nextparamoff) {
442 + const char* pfieldend;
445 + pfieldend = memchr(ptran+off, ';', nextparamoff-off);
446 + nextfieldoff = (pfieldend == NULL) ? nextparamoff : pfieldend-ptran+1;
448 + if (strncmp(ptran+off, "client_port=", 12) == 0) {
453 + numlen = nf_strtou16(ptran+off, &port);
455 + if (prtspexp->loport != 0 && prtspexp->loport != port)
456 + pr_debug("multiple ports found, port %hu ignored\n", port);
458 + pr_debug("lo port found : %hu\n", port);
459 + prtspexp->loport = prtspexp->hiport = port;
460 + if (ptran[off] == '-') {
462 + numlen = nf_strtou16(ptran+off, &port);
464 + prtspexp->pbtype = pb_range;
465 + prtspexp->hiport = port;
467 + // If we have a range, assume rtp:
468 + // loport must be even, hiport must be loport+1
469 + if ((prtspexp->loport & 0x0001) != 0 ||
470 + prtspexp->hiport != prtspexp->loport+1) {
471 + pr_debug("incorrect range: %hu-%hu, correcting\n",
472 + prtspexp->loport, prtspexp->hiport);
473 + prtspexp->loport &= 0xfffe;
474 + prtspexp->hiport = prtspexp->loport+1;
476 + } else if (ptran[off] == '/') {
478 + numlen = nf_strtou16(ptran+off, &port);
480 + prtspexp->pbtype = pb_discon;
481 + prtspexp->hiport = port;
488 + * Note we don't look for the destination parameter here.
489 + * If we are using NAT, the NAT module will handle it. If not,
490 + * and the client is sending packets elsewhere, the expectation
491 + * will quietly time out.
494 + off = nextfieldoff;
497 + off = nextparamoff;
504 +/*** conntrack functions ***/
506 +/* outbound packet: client->server */
509 +help_out(struct sk_buff *skb, unsigned char *rb_ptr, unsigned int datalen,
510 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
511 + struct nf_conn *ct, enum ip_conntrack_info ctinfo,
512 + unsigned int protoff)
514 + struct nf_conn *ct, enum ip_conntrack_info ctinfo)
517 + struct ip_ct_rtsp_expect expinfo;
519 + int dir = CTINFO2DIR(ctinfo); /* = IP_CT_DIR_ORIGINAL */
520 + //struct tcphdr* tcph = (void*)iph + iph->ihl * 4;
521 + //uint tcplen = pktlen - iph->ihl * 4;
522 + char* pdata = rb_ptr;
523 + //uint datalen = tcplen - tcph->doff * 4;
525 + int ret = NF_ACCEPT;
527 + struct nf_conntrack_expect *rtp_exp;
528 + struct nf_conntrack_expect *rtcp_exp = NULL;
533 + typeof(nf_nat_rtsp_hook) nf_nat_rtsp;
535 + memset(&expinfo, 0, sizeof(expinfo));
537 + while (dataoff < datalen) {
538 + uint cmdoff = dataoff;
547 + if (!rtsp_parse_message(pdata, datalen, &dataoff,
548 + &hdrsoff, &hdrslen,
549 + &cseqoff, &cseqlen,
550 + &transoff, &translen))
551 + break; /* not a valid message */
553 + if (strncmp(pdata+cmdoff, "TEARDOWN ", 9) == 0) {
554 + pr_debug("teardown handled\n");
555 + nf_ct_remove_expectations(ct); /* FIXME must be session id aware */
559 + if (strncmp(pdata+cmdoff, "SETUP ", 6) != 0)
560 + continue; /* not a SETUP message */
562 + pr_debug("found a setup message\n");
566 + rtsp_parse_transport(pdata+transoff, translen, &expinfo);
568 + if (expinfo.loport == 0) {
569 + pr_debug("no udp transports found\n");
570 + continue; /* no udp transports found */
573 + pr_debug("udp transport found, ports=(%d,%hu,%hu)\n",
574 + (int)expinfo.pbtype, expinfo.loport, expinfo.hiport);
577 + be_loport = htons(expinfo.loport);
579 + rtp_exp = nf_ct_expect_alloc(ct);
580 + if (rtp_exp == NULL) {
585 + nf_ct_expect_init(rtp_exp, NF_CT_EXPECT_CLASS_DEFAULT,
587 + NULL, /* &ct->tuplehash[!dir].tuple.src.u3, */
588 + &ct->tuplehash[!dir].tuple.dst.u3,
589 + IPPROTO_UDP, NULL, &be_loport);
591 + rtp_exp->flags = 0;
593 + if (expinfo.pbtype == pb_range) {
594 + pr_debug("setup expectation for rtcp\n");
596 + be_hiport = htons(expinfo.hiport);
597 + rtcp_exp = nf_ct_expect_alloc(ct);
598 + if (rtcp_exp == NULL) {
603 + nf_ct_expect_init(rtcp_exp, NF_CT_EXPECT_CLASS_DEFAULT,
605 + NULL, /* &ct->tuplehash[!dir].tuple.src.u3, */
606 + &ct->tuplehash[!dir].tuple.dst.u3,
607 + IPPROTO_UDP, NULL, &be_hiport);
609 + rtcp_exp->flags = 0;
611 + pr_debug("expect_related %pI4:%u-%u-%pI4:%u-%u\n",
612 + &rtp_exp->tuple.src.u3.ip,
613 + ntohs(rtp_exp->tuple.src.u.udp.port),
614 + ntohs(rtcp_exp->tuple.src.u.udp.port),
615 + &rtp_exp->tuple.dst.u3.ip,
616 + ntohs(rtp_exp->tuple.dst.u.udp.port),
617 + ntohs(rtcp_exp->tuple.dst.u.udp.port));
619 + pr_debug("expect_related %pI4:%u-%pI4:%u\n",
620 + &rtp_exp->tuple.src.u3.ip,
621 + ntohs(rtp_exp->tuple.src.u.udp.port),
622 + &rtp_exp->tuple.dst.u3.ip,
623 + ntohs(rtp_exp->tuple.dst.u.udp.port));
626 + nf_nat_rtsp = rcu_dereference(nf_nat_rtsp_hook);
627 + if (nf_nat_rtsp && ct->status & IPS_NAT_MASK)
628 + /* pass the request off to the nat helper */
629 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
630 + ret = nf_nat_rtsp(skb, ctinfo, protoff, hdrsoff, hdrslen,
631 + &expinfo, rtp_exp, rtcp_exp);
633 + ret = nf_nat_rtsp(skb, ctinfo, hdrsoff, hdrslen,
634 + &expinfo, rtp_exp, rtcp_exp);
637 + if (nf_ct_expect_related(rtp_exp) == 0) {
638 + if (rtcp_exp && nf_ct_expect_related(rtcp_exp) != 0) {
639 + nf_ct_unexpect_related(rtp_exp);
640 + pr_info("nf_conntrack_expect_related failed for rtcp\n");
644 + pr_info("nf_conntrack_expect_related failed for rtp\n");
649 + nf_ct_expect_put(rtcp_exp);
652 + nf_ct_expect_put(rtp_exp);
662 +help_in(struct sk_buff *skb, size_t pktlen,
663 + struct nf_conn* ct, enum ip_conntrack_info ctinfo)
668 +static int help(struct sk_buff *skb, unsigned int protoff,
669 + struct nf_conn *ct, enum ip_conntrack_info ctinfo)
671 + struct tcphdr _tcph, *th;
672 + unsigned int dataoff, datalen;
676 + /* Until there's been traffic both ways, don't look in packets. */
677 + if (ctinfo != IP_CT_ESTABLISHED &&
678 + ctinfo != IP_CT_ESTABLISHED + IP_CT_IS_REPLY) {
679 + pr_debug("conntrackinfo = %u\n", ctinfo);
683 + /* Not whole TCP header? */
684 + th = skb_header_pointer(skb, protoff, sizeof(_tcph), &_tcph);
690 + dataoff = protoff + th->doff*4;
691 + datalen = skb->len - dataoff;
692 + if (dataoff >= skb->len)
695 + spin_lock_bh(&rtsp_buffer_lock);
696 + rb_ptr = skb_header_pointer(skb, dataoff,
697 + skb->len - dataoff, rtsp_buffer);
698 + BUG_ON(rb_ptr == NULL);
701 + /* Checksum invalid? Ignore. */
702 + /* FIXME: Source route IP option packets --RR */
703 + if (tcp_v4_check(tcph, tcplen, iph->saddr, iph->daddr,
704 + csum_partial((char*)tcph, tcplen, 0)))
706 + DEBUGP("bad csum: %p %u %u.%u.%u.%u %u.%u.%u.%u\n",
707 + tcph, tcplen, NIPQUAD(iph->saddr), NIPQUAD(iph->daddr));
712 + switch (CTINFO2DIR(ctinfo)) {
713 + case IP_CT_DIR_ORIGINAL:
714 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
715 + ret = help_out(skb, rb_ptr, datalen, ct, ctinfo, protoff);
717 + ret = help_out(skb, rb_ptr, datalen, ct, ctinfo);
720 + case IP_CT_DIR_REPLY:
721 + pr_debug("IP_CT_DIR_REPLY\n");
722 + /* inbound packet: server->client */
727 + spin_unlock_bh(&rtsp_buffer_lock);
732 +static struct nf_conntrack_helper rtsp_helpers[MAX_PORTS];
733 +static char rtsp_names[MAX_PORTS][10];
735 +/* This function is intentionally _NOT_ defined as __exit */
740 + for (i = 0; i < num_ports; i++) {
741 + pr_debug("unregistering port %d\n", ports[i]);
742 + nf_conntrack_helper_unregister(&rtsp_helpers[i]);
744 + kfree(rtsp_buffer);
751 + struct nf_conntrack_helper *hlpr;
754 + printk("nf_conntrack_rtsp v" IP_NF_RTSP_VERSION " loading\n");
756 + if (max_outstanding < 1) {
757 + printk("nf_conntrack_rtsp: max_outstanding must be a positive integer\n");
760 + if (setup_timeout < 0) {
761 + printk("nf_conntrack_rtsp: setup_timeout must be a positive integer\n");
765 + rtsp_exp_policy.max_expected = max_outstanding;
766 + rtsp_exp_policy.timeout = setup_timeout;
768 + rtsp_buffer = kmalloc(65536, GFP_KERNEL);
772 + /* If no port given, default to standard rtsp port */
773 + if (ports[0] == 0) {
774 + ports[0] = RTSP_PORT;
778 + for (i = 0; (i < MAX_PORTS) && ports[i]; i++) {
779 + hlpr = &rtsp_helpers[i];
780 + memset(hlpr, 0, sizeof(struct nf_conntrack_helper));
781 + hlpr->tuple.src.l3num = AF_INET;
782 + hlpr->tuple.src.u.tcp.port = htons(ports[i]);
783 + hlpr->tuple.dst.protonum = IPPROTO_TCP;
784 + hlpr->expect_policy = &rtsp_exp_policy;
785 + hlpr->me = THIS_MODULE;
788 + tmpname = &rtsp_names[i][0];
789 + if (ports[i] == RTSP_PORT) {
790 + sprintf(tmpname, "rtsp");
792 + sprintf(tmpname, "rtsp-%d", i);
795 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0)
796 + strlcpy(hlpr->name, tmpname, sizeof(hlpr->name));
798 + hlpr->name = tmpname;
800 + pr_debug("port #%d: %d\n", i, ports[i]);
802 + ret = nf_conntrack_helper_register(hlpr);
805 + printk("nf_conntrack_rtsp: ERROR registering port %d\n", ports[i]);
816 +++ b/extensions/rtsp/nf_conntrack_rtsp.h
819 + * RTSP extension for IP connection tracking.
820 + * (C) 2003 by Tom Marshall <tmarshall at real.com>
821 + * based on ip_conntrack_irc.h
823 + * This program is free software; you can redistribute it and/or
824 + * modify it under the terms of the GNU General Public License
825 + * as published by the Free Software Foundation; either version
826 + * 2 of the License, or (at your option) any later version.
828 + * 2013-03-04: Il'inykh Sergey <sergeyi at inango-sw.com>. Inango Systems Ltd
829 + * - conditional compilation for kernel 3.7
830 + * - port mapping improvements
832 +#ifndef _IP_CONNTRACK_RTSP_H
833 +#define _IP_CONNTRACK_RTSP_H
835 +#include <linux/version.h>
837 +//#define IP_NF_RTSP_DEBUG 1
838 +#define IP_NF_RTSP_VERSION "0.7"
841 +/* port block types */
843 + pb_single, /* client_port=x */
844 + pb_range, /* client_port=x-y */
845 + pb_discon /* client_port=x/y (rtspbis) */
848 +/* We record seq number and length of rtsp headers here, all in host order. */
851 + * This structure is per expected connection. It is a member of struct
852 + * ip_conntrack_expect. The TCP SEQ for the conntrack expect is stored
853 + * there and we are expected to only store the length of the data which
854 + * needs replaced. If a packet contains multiple RTSP messages, we create
855 + * one expected connection per message.
857 + * We use these variables to mark the entire header block. This may seem
858 + * like overkill, but the nature of RTSP requires it. A header may appear
859 + * multiple times in a message. We must treat two Transport headers the
860 + * same as one Transport header with two entries.
862 +struct ip_ct_rtsp_expect
864 + u_int32_t len; /* length of header block */
865 + portblock_t pbtype; /* Type of port block that was requested */
866 + u_int16_t loport; /* Port that was requested, low or first */
867 + u_int16_t hiport; /* Port that was requested, high or second */
869 + uint method; /* RTSP method */
870 + uint cseq; /* CSeq from request */
874 +extern unsigned int (*nf_nat_rtsp_hook)(struct sk_buff *skb,
875 + enum ip_conntrack_info ctinfo,
876 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
877 + unsigned int protoff,
879 + unsigned int matchoff,
880 + unsigned int matchlen,
881 + struct ip_ct_rtsp_expect *prtspexp,
882 + struct nf_conntrack_expect *rtp_exp,
883 + struct nf_conntrack_expect *rtcp_exp);
885 +#define RTSP_PORT 554
887 +#endif /* __KERNEL__ */
889 +#endif /* _IP_CONNTRACK_RTSP_H */
891 +++ b/extensions/rtsp/nf_nat_rtsp.c
894 + * RTSP extension for TCP NAT alteration
895 + * (C) 2003 by Tom Marshall <tmarshall at real.com>
897 + * 2013-03-04: Il'inykh Sergey <sergeyi at inango-sw.com>. Inango Systems Ltd
898 + * - fixed rtcp nat mapping and other port mapping fixes
899 + * - fixed system hard lock because of bug in the parser
900 + * - codestyle fixes and less significant fixes
902 + * based on ip_nat_irc.c
904 + * This program is free software; you can redistribute it and/or
905 + * modify it under the terms of the GNU General Public License
906 + * as published by the Free Software Foundation; either version
907 + * 2 of the License, or (at your option) any later version.
909 + * Module load syntax:
910 + * insmod nf_nat_rtsp.o ports=port1,port2,...port<MAX_PORTS>
911 + * stunaddr=<address>
912 + * destaction=[auto|strip|none]
914 + * If no ports are specified, the default will be port 554 only.
916 + * stunaddr specifies the address used to detect that a client is using STUN.
917 + * If this address is seen in the destination parameter, it is assumed that
918 + * the client has already punched a UDP hole in the firewall, so we don't
919 + * mangle the client_port. If none is specified, it is autodetected. It
920 + * only needs to be set if you have multiple levels of NAT. It should be
921 + * set to the external address that the STUN clients detect. Note that in
922 + * this case, it will not be possible for clients to use UDP with servers
923 + * between the NATs.
925 + * If no destaction is specified, auto is used.
926 + * destaction=auto: strip destination parameter if it is not stunaddr.
927 + * destaction=strip: always strip destination parameter (not recommended).
928 + * destaction=none: do not touch destination parameter (not recommended).
931 +#include <linux/module.h>
932 +#include <linux/version.h>
933 +#include <net/tcp.h>
934 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
935 +# include <net/netfilter/nf_nat.h>
937 +# include <net/netfilter/nf_nat_rule.h>
939 +#include <net/netfilter/nf_nat_helper.h>
940 +#include "nf_conntrack_rtsp.h"
941 +#include <net/netfilter/nf_conntrack_expect.h>
943 +#include <linux/inet.h>
944 +#include <linux/ctype.h>
945 +#define NF_NEED_STRNCASECMP
946 +#define NF_NEED_STRTOU16
947 +#include "netfilter_helpers.h"
948 +#define NF_NEED_MIME_NEXTLINE
949 +#include "netfilter_mime.h"
952 +#define DSTACT_AUTO 0
953 +#define DSTACT_STRIP 1
954 +#define DSTACT_NONE 2
956 +static char* stunaddr = NULL;
957 +static char* destaction = NULL;
959 +static u_int32_t extip = 0;
960 +static int dstact = 0;
962 +static void nf_nat_rtsp_expected(struct nf_conn* ct, struct nf_conntrack_expect *exp);
964 +MODULE_AUTHOR("Tom Marshall <tmarshall at real.com>");
965 +MODULE_DESCRIPTION("RTSP network address translation module");
966 +MODULE_LICENSE("GPL");
967 +module_param(stunaddr, charp, 0644);
968 +MODULE_PARM_DESC(stunaddr, "Address for detecting STUN");
969 +module_param(destaction, charp, 0644);
970 +MODULE_PARM_DESC(destaction, "Action for destination parameter (auto/strip/none)");
972 +#define SKIP_WSPACE(ptr,len,off) while(off < len && isspace(*(ptr+off))) { off++; }
974 +/*** helper functions ***/
977 +get_skb_tcpdata(struct sk_buff* skb, char** pptcpdata, uint* ptcpdatalen)
979 + struct iphdr* iph = ip_hdr(skb);
980 + struct tcphdr* tcph = (void *)iph + ip_hdrlen(skb);
982 + *pptcpdata = (char*)tcph + tcph->doff*4;
983 + *ptcpdatalen = ((char*)skb_transport_header(skb) + skb->len) - *pptcpdata;
986 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
987 +/* copy of sip_sprintf_addr */
988 +static int rtsp_sprintf_addr(const struct nf_conn *ct, char *buffer,
989 + const union nf_inet_addr *addr, bool delim)
991 + if (nf_ct_l3num(ct) == NFPROTO_IPV4) {
992 + return sprintf(buffer, "%pI4", &addr->ip);
995 + return sprintf(buffer, "[%pI6c]", &addr->ip6);
997 + return sprintf(buffer, "%pI6c", &addr->ip6);
1002 +/*** nat functions ***/
1005 + * Mangle the "Transport:" header:
1006 + * - Replace all occurences of "client_port=<spec>"
1007 + * - Handle destination parameter
1010 + * ct, ctinfo = conntrack context
1012 + * tranoff = Transport header offset from TCP data
1013 + * tranlen = Transport header length (incl. CRLF)
1014 + * rport_lo = replacement low port (host endian)
1015 + * rport_hi = replacement high port (host endian)
1017 + * Returns packet size difference.
1019 + * Assumes that a complete transport header is present, ending with CR or LF
1022 +rtsp_mangle_tran(enum ip_conntrack_info ctinfo,
1023 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
1024 + unsigned int protoff,
1026 + struct nf_conntrack_expect* rtp_exp,
1027 + struct nf_conntrack_expect* rtcp_exp,
1028 + struct ip_ct_rtsp_expect* prtspexp,
1029 + struct sk_buff* skb, uint tranoff, uint tranlen)
1034 + char rbuf1[16]; /* Replacement buffer (one port) */
1035 + uint rbuf1len; /* Replacement len (one port) */
1036 + char rbufa[16]; /* Replacement buffer (all ports) */
1037 + uint rbufalen; /* Replacement len (all ports) */
1038 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
1039 + union nf_inet_addr newip;
1043 + u_int16_t loport, hiport;
1045 + uint diff; /* Number of bytes we removed */
1047 + struct nf_conn *ct = rtp_exp->master;
1048 + /* struct nf_conn *ct = nf_ct_get(skb, &ctinfo); */
1049 + struct nf_conntrack_tuple *rtp_t;
1051 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
1052 + char szextaddr[INET6_ADDRSTRLEN];
1054 + char szextaddr[INET_ADDRSTRLEN];
1059 + get_skb_tcpdata(skb, &ptcp, &tcplen);
1060 + ptran = ptcp+tranoff;
1062 + if (tranoff+tranlen > tcplen || tcplen-tranoff < tranlen ||
1063 + tranlen < 10 || !iseol(ptran[tranlen-1]) ||
1064 + nf_strncasecmp(ptran, "Transport:", 10) != 0) {
1065 + pr_info("sanity check failed\n");
1069 + SKIP_WSPACE(ptcp+tranoff, tranlen, off);
1071 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
1072 + newip = ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.u3;
1073 + rtp_t = &rtp_exp->tuple;
1074 + rtp_t->dst.u3 = newip;
1076 + rtcp_exp->tuple.dst.u3 = newip;
1078 + extaddrlen = rtsp_sprintf_addr(ct, szextaddr, &newip, true); // FIXME handle extip
1079 + pr_debug("stunaddr=%s (auto)\n", szextaddr);
1081 + newip = ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.u3.ip;
1082 + rtp_t = &rtp_exp->tuple;
1083 + rtp_t->dst.u3.ip = newip;
1085 + rtcp_exp->tuple.dst.u3.ip = newip;
1087 + extaddrlen = extip ? sprintf(szextaddr, "%pI4", &extip)
1088 + : sprintf(szextaddr, "%pI4", &newip);
1089 + pr_debug("stunaddr=%s (%s)\n", szextaddr, (extip?"forced":"auto"));
1092 + rbuf1len = rbufalen = 0;
1093 + switch (prtspexp->pbtype) {
1095 + for (loport = prtspexp->loport; loport != 0; loport++) { /* XXX: improper wrap? */
1096 + rtp_t->dst.u.udp.port = htons(loport);
1097 + if (nf_ct_expect_related(rtp_exp) == 0) {
1098 + pr_debug("using port %hu\n", loport);
1102 + if (loport != 0) {
1103 + rbuf1len = sprintf(rbuf1, "%hu", loport);
1104 + rbufalen = sprintf(rbufa, "%hu", loport);
1108 + for (loport = prtspexp->loport; loport != 0; loport += 2) { /* XXX: improper wrap? */
1109 + rtp_t->dst.u.udp.port = htons(loport);
1110 + if (nf_ct_expect_related(rtp_exp) != 0) {
1113 + hiport = loport + 1;
1114 + rtcp_exp->tuple.dst.u.udp.port = htons(hiport);
1115 + if (nf_ct_expect_related(rtcp_exp) != 0) {
1116 + nf_ct_unexpect_related(rtp_exp);
1120 + /* FIXME: invalid print in case of ipv6 */
1121 + pr_debug("nat expect_related %pI4:%u-%u-%pI4:%u-%u\n",
1122 + &rtp_exp->tuple.src.u3.ip,
1123 + ntohs(rtp_exp->tuple.src.u.udp.port),
1124 + ntohs(rtcp_exp->tuple.src.u.udp.port),
1125 + &rtp_exp->tuple.dst.u3.ip,
1126 + ntohs(rtp_exp->tuple.dst.u.udp.port),
1127 + ntohs(rtcp_exp->tuple.dst.u.udp.port));
1130 + if (loport != 0) {
1131 + rbuf1len = sprintf(rbuf1, "%hu", loport);
1132 + rbufalen = sprintf(rbufa, "%hu-%hu", loport, hiport);
1136 + for (loport = prtspexp->loport; loport != 0; loport++) { /* XXX: improper wrap? */
1137 + rtp_t->dst.u.udp.port = htons(loport);
1138 + if (nf_ct_expect_related(rtp_exp) == 0) {
1139 + pr_debug("using port %hu (1 of 2)\n", loport);
1143 + for (hiport = prtspexp->hiport; hiport != 0; hiport++) { /* XXX: improper wrap? */
1144 + rtp_t->dst.u.udp.port = htons(hiport);
1145 + if (nf_ct_expect_related(rtp_exp) == 0) {
1146 + pr_debug("using port %hu (2 of 2)\n", hiport);
1150 + if (loport != 0 && hiport != 0) {
1151 + rbuf1len = sprintf(rbuf1, "%hu", loport);
1152 + rbufalen = sprintf(rbufa, hiport == loport+1 ?
1153 + "%hu-%hu":"%hu/%hu", loport, hiport);
1158 + if (rbuf1len == 0)
1159 + return 0; /* cannot get replacement port(s) */
1161 + /* Transport: tran;field;field=val,tran;field;field=val,...
1162 + `off` is set to the start of Transport value from start of line
1164 + while (off < tranlen) {
1166 + const char* pparamend;
1167 + uint nextparamoff;
1169 + pparamend = memchr(ptran+off, ',', tranlen-off);
1170 + pparamend = (pparamend == NULL) ? ptran+tranlen : pparamend+1;
1171 + nextparamoff = pparamend-ptran;
1174 + * We pass over each param twice. On the first pass, we look for a
1175 + * destination= field. It is handled by the security policy. If it
1176 + * is present, allowed, and equal to our external address, we assume
1177 + * that STUN is being used and we leave the client_port= field alone.
1181 + while (off < nextparamoff) {
1182 + const char* pfieldend;
1183 + uint nextfieldoff;
1185 + pfieldend = memchr(ptran+off, ';', nextparamoff-off);
1186 + nextfieldoff = (pfieldend == NULL) ? nextparamoff : pfieldend-ptran+1;
1188 + if (dstact != DSTACT_NONE && strncmp(ptran+off, "destination=", 12) == 0) {
1189 + if (strncmp(ptran+off+12, szextaddr, extaddrlen) == 0)
1192 + if (dstact == DSTACT_STRIP || (dstact == DSTACT_AUTO && !is_stun)) {
1193 + uint dstoff = (ptran-ptcp)+off;
1194 + uint dstlen = nextfieldoff-off;
1195 + char* pdstrep = NULL;
1196 + uint dstreplen = 0;
1198 + if (dstact == DSTACT_AUTO && !is_stun) {
1199 + pr_debug("RTSP: replace dst addr\n");
1202 + pdstrep = szextaddr;
1203 + dstreplen = extaddrlen;
1204 + diff = nextfieldoff-off-13-extaddrlen;
1207 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
1208 + if (!nf_nat_mangle_tcp_packet(skb, ct, ctinfo, protoff,
1209 + dstoff, dstlen, pdstrep, dstreplen)) {
1211 + if (!nf_nat_mangle_tcp_packet(skb, ct, ctinfo,
1212 + dstoff, dstlen, pdstrep, dstreplen)) {
1214 + /* mangle failed, all we can do is bail */
1215 + nf_ct_unexpect_related(rtp_exp);
1217 + nf_ct_unexpect_related(rtcp_exp);
1220 + get_skb_tcpdata(skb, &ptcp, &tcplen);
1221 + ptran = ptcp+tranoff;
1223 + nextparamoff -= diff;
1224 + nextfieldoff -= diff;
1228 + off = nextfieldoff;
1235 + while (off < nextparamoff) {
1236 + const char* pfieldend;
1237 + uint nextfieldoff;
1239 + pfieldend = memchr(ptran+off, ';', nextparamoff-off);
1240 + nextfieldoff = (pfieldend == NULL) ? nextparamoff : pfieldend-ptran+1;
1242 + if (strncmp(ptran+off, "client_port=", 12) == 0) {
1247 + char* rbuf = rbuf1;
1248 + uint rbuflen = rbuf1len;
1251 + origoff = (ptran-ptcp)+off;
1253 + numlen = nf_strtou16(ptran+off, &port);
1255 + origlen += numlen;
1256 + if (port != prtspexp->loport) {
1257 + pr_debug("multiple ports found, port %hu ignored\n", port);
1259 + if (ptran[off] == '-' || ptran[off] == '/') {
1262 + numlen = nf_strtou16(ptran+off, &port);
1264 + origlen += numlen;
1266 + rbuflen = rbufalen;
1270 + * note we cannot just memcpy() if the sizes are the same.
1271 + * the mangle function does skb resizing, checks for a
1272 + * cloned skb, and updates the checksums.
1274 + * parameter 4 below is offset from start of tcp data.
1276 + diff = origlen-rbuflen;
1277 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
1278 + if (!nf_nat_mangle_tcp_packet(skb, ct, ctinfo, protoff,
1279 + origoff, origlen, rbuf, rbuflen)) {
1281 + if (!nf_nat_mangle_tcp_packet(skb, ct, ctinfo,
1282 + origoff, origlen, rbuf, rbuflen)) {
1284 + /* mangle failed, all we can do is bail */
1285 + nf_ct_unexpect_related(rtp_exp);
1287 + nf_ct_unexpect_related(rtcp_exp);
1290 + get_skb_tcpdata(skb, &ptcp, &tcplen);
1291 + ptran = ptcp+tranoff;
1293 + nextparamoff -= diff;
1294 + nextfieldoff -= diff;
1298 + off = nextfieldoff;
1301 + off = nextparamoff;
1308 +help_out(struct sk_buff *skb, enum ip_conntrack_info ctinfo,
1309 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
1310 + unsigned int protoff,
1312 + unsigned int matchoff, unsigned int matchlen,
1313 + struct ip_ct_rtsp_expect* prtspexp,
1314 + struct nf_conntrack_expect* rtp_exp,
1315 + struct nf_conntrack_expect* rtcp_exp)
1324 + int dir = CTINFO2DIR(ctinfo);
1325 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
1326 + union nf_inet_addr saddr = rtp_exp->master->tuplehash[dir].tuple.src.u3;
1328 + __be32 saddr = rtp_exp->master->tuplehash[dir].tuple.src.u3.ip;
1331 + //struct iphdr* iph = (struct iphdr*)(*pskb)->nh.iph;
1332 + //struct tcphdr* tcph = (struct tcphdr*)((void*)iph + iph->ihl*4);
1334 + get_skb_tcpdata(skb, &ptcp, &tcplen);
1335 + hdrsoff = matchoff;//exp->seq - ntohl(tcph->seq);
1336 + hdrslen = matchlen;
1338 + pr_debug("NAT rtsp help_out\n");
1340 + while (nf_mime_nextline(ptcp, hdrsoff+hdrslen, &off, &lineoff, &linelen)) {
1344 + if (off > hdrsoff+hdrslen) {
1345 + pr_info("!! overrun !!");
1348 + pr_debug("hdr: len=%u, %.*s", linelen, (int)linelen, ptcp+lineoff);
1350 + if (nf_strncasecmp(ptcp+lineoff, "Transport:", 10) == 0) {
1351 + uint oldtcplen = tcplen;
1352 + pr_debug("hdr: Transport\n");
1353 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
1354 + if (!rtsp_mangle_tran(ctinfo, protoff, rtp_exp, rtcp_exp,
1355 + prtspexp, skb, lineoff, linelen)) {
1357 + if (!rtsp_mangle_tran(ctinfo, rtp_exp, rtcp_exp, prtspexp,
1358 + skb, lineoff, linelen)) {
1360 + pr_debug("hdr: Transport mangle failed");
1363 + rtp_exp->expectfn = nf_nat_rtsp_expected;
1364 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
1365 + rtp_exp->saved_addr = saddr;
1367 + rtp_exp->saved_ip = saddr;
1369 + rtp_exp->saved_proto.udp.port = htons(prtspexp->loport);
1370 + rtp_exp->dir = !dir;
1372 + rtcp_exp->expectfn = nf_nat_rtsp_expected;
1373 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
1374 + rtcp_exp->saved_addr = saddr;
1376 + rtcp_exp->saved_ip = saddr;
1378 + rtcp_exp->saved_proto.udp.port = htons(prtspexp->hiport);
1379 + rtcp_exp->dir = !dir;
1381 + get_skb_tcpdata(skb, &ptcp, &tcplen);
1382 + hdrslen -= (oldtcplen-tcplen);
1383 + off -= (oldtcplen-tcplen);
1384 + lineoff -= (oldtcplen-tcplen);
1385 + linelen -= (oldtcplen-tcplen);
1386 + pr_debug("rep: len=%u, %.*s", linelen, (int)linelen, ptcp+lineoff);
1393 +static unsigned int
1394 +nf_nat_rtsp(struct sk_buff *skb, enum ip_conntrack_info ctinfo,
1395 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
1396 + unsigned int protoff,
1398 + unsigned int matchoff, unsigned int matchlen,
1399 + struct ip_ct_rtsp_expect* prtspexp,
1400 + struct nf_conntrack_expect* rtp_exp,
1401 + struct nf_conntrack_expect* rtcp_exp)
1403 + int dir = CTINFO2DIR(ctinfo);
1404 + int rc = NF_ACCEPT;
1407 + case IP_CT_DIR_ORIGINAL:
1408 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
1409 + rc = help_out(skb, ctinfo, protoff, matchoff, matchlen, prtspexp,
1410 + rtp_exp, rtcp_exp);
1412 + rc = help_out(skb, ctinfo, matchoff, matchlen, prtspexp,
1413 + rtp_exp, rtcp_exp);
1416 + case IP_CT_DIR_REPLY:
1417 + pr_debug("unmangle ! %u\n", ctinfo);
1418 + /* XXX: unmangle */
1422 + //UNLOCK_BH(&ip_rtsp_lock);
1427 +static void nf_nat_rtsp_expected(struct nf_conn* ct, struct nf_conntrack_expect *exp)
1429 +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,3,0) || LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
1430 + struct nf_nat_range range;
1432 + struct nf_nat_ipv4_range range;
1435 + /* This must be a fresh one. */
1436 + BUG_ON(ct->status & IPS_NAT_DONE_MASK);
1438 + /* For DST manip, map port here to where it's expected. */
1439 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
1440 + range.min_proto = range.max_proto = exp->saved_proto;
1441 + range.min_addr = range.max_addr = exp->saved_addr;
1443 + range.min = range.max = exp->saved_proto;
1444 + range.min_ip = range.max_ip = exp->saved_ip;
1446 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,3,0)
1447 + range.flags = (NF_NAT_RANGE_MAP_IPS | NF_NAT_RANGE_PROTO_SPECIFIED);
1448 + nf_nat_setup_info(ct, &range, NF_NAT_MANIP_DST);
1450 + range.flags = (IP_NAT_RANGE_MAP_IPS | IP_NAT_RANGE_PROTO_SPECIFIED);
1451 + nf_nat_setup_info(ct, &range, IP_NAT_MANIP_DST);
1454 + /* Change src to where master sends to, but only if the connection
1455 + * actually came from the same source. */
1456 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
1457 + if (nf_inet_addr_cmp(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.u3,
1458 + &ct->master->tuplehash[exp->dir].tuple.src.u3)) {
1459 + range.min_addr = range.max_addr
1460 + = ct->master->tuplehash[!exp->dir].tuple.dst.u3;
1462 + if (ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.u3.ip ==
1463 + ct->master->tuplehash[exp->dir].tuple.src.u3.ip) {
1464 + range.min_ip = range.max_ip
1465 + = ct->master->tuplehash[!exp->dir].tuple.dst.u3.ip;
1467 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,3,0)
1468 + range.flags = NF_NAT_RANGE_MAP_IPS;
1469 + nf_nat_setup_info(ct, &range, NF_NAT_MANIP_SRC);
1471 + range.flags = IP_NAT_RANGE_MAP_IPS;
1472 + nf_nat_setup_info(ct, &range, IP_NAT_MANIP_SRC);
1478 +static void __exit fini(void)
1480 + rcu_assign_pointer(nf_nat_rtsp_hook, NULL);
1481 + synchronize_net();
1484 +static int __init init(void)
1486 + printk("nf_nat_rtsp v" IP_NF_RTSP_VERSION " loading\n");
1488 + BUG_ON(nf_nat_rtsp_hook);
1489 + rcu_assign_pointer(nf_nat_rtsp_hook, nf_nat_rtsp);
1491 + if (stunaddr != NULL)
1492 + extip = in_aton(stunaddr);
1494 + if (destaction != NULL) {
1495 + if (strcmp(destaction, "auto") == 0)
1496 + dstact = DSTACT_AUTO;
1498 + if (strcmp(destaction, "strip") == 0)
1499 + dstact = DSTACT_STRIP;
1501 + if (strcmp(destaction, "none") == 0)
1502 + dstact = DSTACT_NONE;
1510 --- a/extensions/Kbuild
1511 +++ b/extensions/Kbuild
1512 @@ -28,6 +28,7 @@ obj-${build_lscan} += xt_lscan.o
1513 obj-${build_pknock} += pknock/
1514 obj-${build_psd} += xt_psd.o
1515 obj-${build_quota2} += xt_quota2.o
1516 +obj-${build_rtsp} += rtsp/
1518 -include ${M}/*.Kbuild
1519 -include ${M}/Kbuild.*
1522 @@ -22,3 +22,4 @@ build_lscan=m