[packages] xtables-addons: add rtsp-module-2.6.36 to xtables-addons and make it avail...
[openwrt/svn-archive/archive.git] / net / xtables-addons / patches / 100-add-rtsp-conntrack.patch
1 --- /dev/null
2 +++ b/extensions/rtsp/Kbuild
3 @@ -0,0 +1,4 @@
4 +# -*- Makefile -*-
5 +
6 +obj-m += nf_nat_rtsp.o
7 +obj-m += nf_conntrack_rtsp.o
8 --- /dev/null
9 +++ b/extensions/rtsp/netfilter_helpers.h
10 @@ -0,0 +1,133 @@
11 +/*
12 + * Helpers for netfiler modules. This file provides implementations for basic
13 + * functions such as strncasecmp(), etc.
14 + *
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()
20 + */
21 +#ifndef _NETFILTER_HELPERS_H
22 +#define _NETFILTER_HELPERS_H
23 +
24 +/* Only include these functions for kernel code. */
25 +#ifdef __KERNEL__
26 +
27 +#include <linux/ctype.h>
28 +#define iseol(c) ( (c) == '\r' || (c) == '\n' )
29 +
30 +/*
31 + * The standard strncasecmp()
32 + */
33 +#ifdef NF_NEED_STRNCASECMP
34 +static int
35 +nf_strncasecmp(const char* s1, const char* s2, u_int32_t len)
36 +{
37 + if (s1 == NULL || s2 == NULL)
38 + {
39 + if (s1 == NULL && s2 == NULL)
40 + {
41 + return 0;
42 + }
43 + return (s1 == NULL) ? -1 : 1;
44 + }
45 + while (len > 0 && tolower(*s1) == tolower(*s2))
46 + {
47 + len--;
48 + s1++;
49 + s2++;
50 + }
51 + return ( (len == 0) ? 0 : (tolower(*s1) - tolower(*s2)) );
52 +}
53 +#endif /* NF_NEED_STRNCASECMP */
54 +
55 +/*
56 + * Parse a string containing a 16-bit unsigned integer.
57 + * Returns the number of chars used, or zero if no number is found.
58 + */
59 +#ifdef NF_NEED_STRTOU16
60 +static int
61 +nf_strtou16(const char* pbuf, u_int16_t* pval)
62 +{
63 + int n = 0;
64 +
65 + *pval = 0;
66 + while (isdigit(pbuf[n]))
67 + {
68 + *pval = (*pval * 10) + (pbuf[n] - '0');
69 + n++;
70 + }
71 +
72 + return n;
73 +}
74 +#endif /* NF_NEED_STRTOU16 */
75 +
76 +/*
77 + * Parse a string containing a 32-bit unsigned integer.
78 + * Returns the number of chars used, or zero if no number is found.
79 + */
80 +#ifdef NF_NEED_STRTOU32
81 +static int
82 +nf_strtou32(const char* pbuf, u_int32_t* pval)
83 +{
84 + int n = 0;
85 +
86 + *pval = 0;
87 + while (pbuf[n] >= '0' && pbuf[n] <= '9')
88 + {
89 + *pval = (*pval * 10) + (pbuf[n] - '0');
90 + n++;
91 + }
92 +
93 + return n;
94 +}
95 +#endif /* NF_NEED_STRTOU32 */
96 +
97 +/*
98 + * Given a buffer and length, advance to the next line and mark the current
99 + * line.
100 + */
101 +#ifdef NF_NEED_NEXTLINE
102 +static int
103 +nf_nextline(char* p, uint len, uint* poff, uint* plineoff, uint* plinelen)
104 +{
105 + uint off = *poff;
106 + uint physlen = 0;
107 +
108 + if (off >= len)
109 + {
110 + return 0;
111 + }
112 +
113 + while (p[off] != '\n')
114 + {
115 + if (len-off <= 1)
116 + {
117 + return 0;
118 + }
119 +
120 + physlen++;
121 + off++;
122 + }
123 +
124 + /* if we saw a crlf, physlen needs adjusted */
125 + if (physlen > 0 && p[off] == '\n' && p[off-1] == '\r')
126 + {
127 + physlen--;
128 + }
129 +
130 + /* advance past the newline */
131 + off++;
132 +
133 + *plineoff = *poff;
134 + *plinelen = physlen;
135 + *poff = off;
136 +
137 + return 1;
138 +}
139 +#endif /* NF_NEED_NEXTLINE */
140 +
141 +#endif /* __KERNEL__ */
142 +
143 +#endif /* _NETFILTER_HELPERS_H */
144 --- /dev/null
145 +++ b/extensions/rtsp/netfilter_mime.h
146 @@ -0,0 +1,89 @@
147 +/*
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.
151 + *
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()
155 + */
156 +#ifndef _NETFILTER_MIME_H
157 +#define _NETFILTER_MIME_H
158 +
159 +/* Only include these functions for kernel code. */
160 +#ifdef __KERNEL__
161 +
162 +#include <linux/ctype.h>
163 +
164 +/*
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).
168 + *
169 + * 'line' in this context means logical line (includes LWS continuations).
170 + * Returns 1 on success, 0 on failure.
171 + */
172 +#ifdef NF_NEED_MIME_NEXTLINE
173 +static int
174 +nf_mime_nextline(char* p, uint len, uint* poff, uint* plineoff, uint* plinelen)
175 +{
176 + uint off = *poff;
177 + uint physlen = 0;
178 + int is_first_line = 1;
179 +
180 + if (off >= len)
181 + {
182 + return 0;
183 + }
184 +
185 + do
186 + {
187 + while (p[off] != '\n')
188 + {
189 + if (len-off <= 1)
190 + {
191 + return 0;
192 + }
193 +
194 + physlen++;
195 + off++;
196 + }
197 +
198 + /* if we saw a crlf, physlen needs adjusted */
199 + if (physlen > 0 && p[off] == '\n' && p[off-1] == '\r')
200 + {
201 + physlen--;
202 + }
203 +
204 + /* advance past the newline */
205 + off++;
206 +
207 + /* check for an empty line */
208 + if (physlen == 0)
209 + {
210 + break;
211 + }
212 +
213 + /* check for colon on the first physical line */
214 + if (is_first_line)
215 + {
216 + is_first_line = 0;
217 + if (memchr(p+(*poff), ':', physlen) == NULL)
218 + {
219 + return 0;
220 + }
221 + }
222 + }
223 + while (p[off] == ' ' || p[off] == '\t');
224 +
225 + *plineoff = *poff;
226 + *plinelen = (physlen == 0) ? 0 : (off - *poff);
227 + *poff = off;
228 +
229 + return 1;
230 +}
231 +#endif /* NF_NEED_MIME_NEXTLINE */
232 +
233 +#endif /* __KERNEL__ */
234 +
235 +#endif /* _NETFILTER_MIME_H */
236 --- /dev/null
237 +++ b/extensions/rtsp/nf_conntrack_rtsp.c
238 @@ -0,0 +1,519 @@
239 +/*
240 + * RTSP extension for IP connection tracking
241 + * (C) 2003 by Tom Marshall <tmarshall at real.com>
242 + * based on ip_conntrack_irc.c
243 + *
244 + * This program is free software; you can redistribute it and/or
245 + * modify it under the terms of the GNU General Public License
246 + * as published by the Free Software Foundation; either version
247 + * 2 of the License, or (at your option) any later version.
248 + *
249 + * Module load syntax:
250 + * insmod nf_conntrack_rtsp.o ports=port1,port2,...port<MAX_PORTS>
251 + * max_outstanding=n setup_timeout=secs
252 + *
253 + * If no ports are specified, the default will be port 554.
254 + *
255 + * With max_outstanding you can define the maximum number of not yet
256 + * answered SETUP requests per RTSP session (default 8).
257 + * With setup_timeout you can specify how long the system waits for
258 + * an expected data channel (default 300 seconds).
259 + *
260 + * 2005-02-13: Harald Welte <laforge at netfilter.org>
261 + * - port to 2.6
262 + * - update to recent post-2.6.11 api changes
263 + * 2006-09-14: Steven Van Acker <deepstar at singularity.be>
264 + * - removed calls to NAT code from conntrack helper: NAT no longer needed to use rtsp-conntrack
265 + * 2007-04-18: Michael Guntsche <mike at it-loops.com>
266 + * - Port to new NF API
267 + */
268 +
269 +#include <linux/module.h>
270 +#include <linux/netfilter.h>
271 +#include <linux/ip.h>
272 +#include <linux/inet.h>
273 +#include <net/tcp.h>
274 +
275 +#include <net/netfilter/nf_conntrack.h>
276 +#include <net/netfilter/nf_conntrack_expect.h>
277 +#include <net/netfilter/nf_conntrack_helper.h>
278 +#include "nf_conntrack_rtsp.h"
279 +
280 +#define NF_NEED_STRNCASECMP
281 +#define NF_NEED_STRTOU16
282 +#define NF_NEED_STRTOU32
283 +#define NF_NEED_NEXTLINE
284 +#include "netfilter_helpers.h"
285 +#define NF_NEED_MIME_NEXTLINE
286 +#include "netfilter_mime.h"
287 +
288 +#include <linux/ctype.h>
289 +#define MAX_SIMUL_SETUP 8 /* XXX: use max_outstanding */
290 +
291 +#define MAX_PORTS 8
292 +static int ports[MAX_PORTS];
293 +static int num_ports = 0;
294 +static int max_outstanding = 8;
295 +static unsigned int setup_timeout = 300;
296 +
297 +MODULE_AUTHOR("Tom Marshall <tmarshall at real.com>");
298 +MODULE_DESCRIPTION("RTSP connection tracking module");
299 +MODULE_LICENSE("GPL");
300 +module_param_array(ports, int, &num_ports, 0400);
301 +MODULE_PARM_DESC(ports, "port numbers of RTSP servers");
302 +module_param(max_outstanding, int, 0400);
303 +MODULE_PARM_DESC(max_outstanding, "max number of outstanding SETUP requests per RTSP session");
304 +module_param(setup_timeout, int, 0400);
305 +MODULE_PARM_DESC(setup_timeout, "timeout on for unestablished data channels");
306 +
307 +static char *rtsp_buffer;
308 +static DEFINE_SPINLOCK(rtsp_buffer_lock);
309 +
310 +static struct nf_conntrack_expect_policy rtsp_exp_policy;
311 +
312 +unsigned int (*nf_nat_rtsp_hook)(struct sk_buff *skb,
313 + enum ip_conntrack_info ctinfo,
314 + unsigned int matchoff, unsigned int matchlen,struct ip_ct_rtsp_expect* prtspexp,
315 + struct nf_conntrack_expect *exp);
316 +void (*nf_nat_rtsp_hook_expectfn)(struct nf_conn *ct, struct nf_conntrack_expect *exp);
317 +
318 +EXPORT_SYMBOL_GPL(nf_nat_rtsp_hook);
319 +
320 +/*
321 + * Max mappings we will allow for one RTSP connection (for RTP, the number
322 + * of allocated ports is twice this value). Note that SMIL burns a lot of
323 + * ports so keep this reasonably high. If this is too low, you will see a
324 + * lot of "no free client map entries" messages.
325 + */
326 +#define MAX_PORT_MAPS 16
327 +
328 +/*** default port list was here in the masq code: 554, 3030, 4040 ***/
329 +
330 +#define SKIP_WSPACE(ptr,len,off) while(off < len && isspace(*(ptr+off))) { off++; }
331 +
332 +/*
333 + * Parse an RTSP packet.
334 + *
335 + * Returns zero if parsing failed.
336 + *
337 + * Parameters:
338 + * IN ptcp tcp data pointer
339 + * IN tcplen tcp data len
340 + * IN/OUT ptcpoff points to current tcp offset
341 + * OUT phdrsoff set to offset of rtsp headers
342 + * OUT phdrslen set to length of rtsp headers
343 + * OUT pcseqoff set to offset of CSeq header
344 + * OUT pcseqlen set to length of CSeq header
345 + */
346 +static int
347 +rtsp_parse_message(char* ptcp, uint tcplen, uint* ptcpoff,
348 + uint* phdrsoff, uint* phdrslen,
349 + uint* pcseqoff, uint* pcseqlen,
350 + uint* transoff, uint* translen)
351 +{
352 + uint entitylen = 0;
353 + uint lineoff;
354 + uint linelen;
355 +
356 + if (!nf_nextline(ptcp, tcplen, ptcpoff, &lineoff, &linelen))
357 + return 0;
358 +
359 + *phdrsoff = *ptcpoff;
360 + while (nf_mime_nextline(ptcp, tcplen, ptcpoff, &lineoff, &linelen)) {
361 + if (linelen == 0) {
362 + if (entitylen > 0)
363 + *ptcpoff += min(entitylen, tcplen - *ptcpoff);
364 + break;
365 + }
366 + if (lineoff+linelen > tcplen) {
367 + pr_info("!! overrun !!\n");
368 + break;
369 + }
370 +
371 + if (nf_strncasecmp(ptcp+lineoff, "CSeq:", 5) == 0) {
372 + *pcseqoff = lineoff;
373 + *pcseqlen = linelen;
374 + }
375 +
376 + if (nf_strncasecmp(ptcp+lineoff, "Transport:", 10) == 0) {
377 + *transoff = lineoff;
378 + *translen = linelen;
379 + }
380 +
381 + if (nf_strncasecmp(ptcp+lineoff, "Content-Length:", 15) == 0) {
382 + uint off = lineoff+15;
383 + SKIP_WSPACE(ptcp+lineoff, linelen, off);
384 + nf_strtou32(ptcp+off, &entitylen);
385 + }
386 + }
387 + *phdrslen = (*ptcpoff) - (*phdrsoff);
388 +
389 + return 1;
390 +}
391 +
392 +/*
393 + * Find lo/hi client ports (if any) in transport header
394 + * In:
395 + * ptcp, tcplen = packet
396 + * tranoff, tranlen = buffer to search
397 + *
398 + * Out:
399 + * pport_lo, pport_hi = lo/hi ports (host endian)
400 + *
401 + * Returns nonzero if any client ports found
402 + *
403 + * Note: it is valid (and expected) for the client to request multiple
404 + * transports, so we need to parse the entire line.
405 + */
406 +static int
407 +rtsp_parse_transport(char* ptran, uint tranlen,
408 + struct ip_ct_rtsp_expect* prtspexp)
409 +{
410 + int rc = 0;
411 + uint off = 0;
412 +
413 + if (tranlen < 10 || !iseol(ptran[tranlen-1]) ||
414 + nf_strncasecmp(ptran, "Transport:", 10) != 0) {
415 + pr_info("sanity check failed\n");
416 + return 0;
417 + }
418 +
419 + pr_debug("tran='%.*s'\n", (int)tranlen, ptran);
420 + off += 10;
421 + SKIP_WSPACE(ptran, tranlen, off);
422 +
423 + /* Transport: tran;field;field=val,tran;field;field=val,... */
424 + while (off < tranlen) {
425 + const char* pparamend;
426 + uint nextparamoff;
427 +
428 + pparamend = memchr(ptran+off, ',', tranlen-off);
429 + pparamend = (pparamend == NULL) ? ptran+tranlen : pparamend+1;
430 + nextparamoff = pparamend-ptran;
431 +
432 + while (off < nextparamoff) {
433 + const char* pfieldend;
434 + uint nextfieldoff;
435 +
436 + pfieldend = memchr(ptran+off, ';', nextparamoff-off);
437 + nextfieldoff = (pfieldend == NULL) ? nextparamoff : pfieldend-ptran+1;
438 +
439 + if (strncmp(ptran+off, "client_port=", 12) == 0) {
440 + u_int16_t port;
441 + uint numlen;
442 +
443 + off += 12;
444 + numlen = nf_strtou16(ptran+off, &port);
445 + off += numlen;
446 + if (prtspexp->loport != 0 && prtspexp->loport != port)
447 + pr_debug("multiple ports found, port %hu ignored\n", port);
448 + else {
449 + pr_debug("lo port found : %hu\n", port);
450 + prtspexp->loport = prtspexp->hiport = port;
451 + if (ptran[off] == '-') {
452 + off++;
453 + numlen = nf_strtou16(ptran+off, &port);
454 + off += numlen;
455 + prtspexp->pbtype = pb_range;
456 + prtspexp->hiport = port;
457 +
458 + // If we have a range, assume rtp:
459 + // loport must be even, hiport must be loport+1
460 + if ((prtspexp->loport & 0x0001) != 0 ||
461 + prtspexp->hiport != prtspexp->loport+1) {
462 + pr_debug("incorrect range: %hu-%hu, correcting\n",
463 + prtspexp->loport, prtspexp->hiport);
464 + prtspexp->loport &= 0xfffe;
465 + prtspexp->hiport = prtspexp->loport+1;
466 + }
467 + } else if (ptran[off] == '/') {
468 + off++;
469 + numlen = nf_strtou16(ptran+off, &port);
470 + off += numlen;
471 + prtspexp->pbtype = pb_discon;
472 + prtspexp->hiport = port;
473 + }
474 + rc = 1;
475 + }
476 + }
477 +
478 + /*
479 + * Note we don't look for the destination parameter here.
480 + * If we are using NAT, the NAT module will handle it. If not,
481 + * and the client is sending packets elsewhere, the expectation
482 + * will quietly time out.
483 + */
484 +
485 + off = nextfieldoff;
486 + }
487 +
488 + off = nextparamoff;
489 + }
490 +
491 + return rc;
492 +}
493 +
494 +void expected(struct nf_conn *ct, struct nf_conntrack_expect *exp)
495 +{
496 + typeof(nf_nat_rtsp_hook_expectfn) nf_nat_rtsp_expectfn;
497 + nf_nat_rtsp_expectfn = rcu_dereference(nf_nat_rtsp_hook_expectfn);
498 + if(nf_nat_rtsp_expectfn && ct->master->status & IPS_NAT_MASK) {
499 + nf_nat_rtsp_expectfn(ct,exp);
500 + }
501 +}
502 +
503 +/*** conntrack functions ***/
504 +
505 +/* outbound packet: client->server */
506 +
507 +static inline int
508 +help_out(struct sk_buff *skb, unsigned char *rb_ptr, unsigned int datalen,
509 + struct nf_conn *ct, enum ip_conntrack_info ctinfo)
510 +{
511 + struct ip_ct_rtsp_expect expinfo;
512 +
513 + int dir = CTINFO2DIR(ctinfo); /* = IP_CT_DIR_ORIGINAL */
514 + //struct tcphdr* tcph = (void*)iph + iph->ihl * 4;
515 + //uint tcplen = pktlen - iph->ihl * 4;
516 + char* pdata = rb_ptr;
517 + //uint datalen = tcplen - tcph->doff * 4;
518 + uint dataoff = 0;
519 + int ret = NF_ACCEPT;
520 +
521 + struct nf_conntrack_expect *exp;
522 +
523 + __be16 be_loport;
524 +
525 + typeof(nf_nat_rtsp_hook) nf_nat_rtsp;
526 +
527 + memset(&expinfo, 0, sizeof(expinfo));
528 +
529 + while (dataoff < datalen) {
530 + uint cmdoff = dataoff;
531 + uint hdrsoff = 0;
532 + uint hdrslen = 0;
533 + uint cseqoff = 0;
534 + uint cseqlen = 0;
535 + uint transoff = 0;
536 + uint translen = 0;
537 + uint off;
538 +
539 + if (!rtsp_parse_message(pdata, datalen, &dataoff,
540 + &hdrsoff, &hdrslen,
541 + &cseqoff, &cseqlen,
542 + &transoff, &translen))
543 + break; /* not a valid message */
544 +
545 + if (strncmp(pdata+cmdoff, "SETUP ", 6) != 0)
546 + continue; /* not a SETUP message */
547 + pr_debug("found a setup message\n");
548 +
549 + off = 0;
550 + if(translen) {
551 + rtsp_parse_transport(pdata+transoff, translen, &expinfo);
552 + }
553 +
554 + if (expinfo.loport == 0) {
555 + pr_debug("no udp transports found\n");
556 + continue; /* no udp transports found */
557 + }
558 +
559 + pr_debug("udp transport found, ports=(%d,%hu,%hu)\n",
560 + (int)expinfo.pbtype, expinfo.loport, expinfo.hiport);
561 +
562 + exp = nf_ct_expect_alloc(ct);
563 + if (!exp) {
564 + ret = NF_DROP;
565 + goto out;
566 + }
567 +
568 + be_loport = htons(expinfo.loport);
569 +
570 + nf_ct_expect_init(exp, NF_CT_EXPECT_CLASS_DEFAULT, nf_ct_l3num(ct),
571 + &ct->tuplehash[!dir].tuple.src.u3, &ct->tuplehash[!dir].tuple.dst.u3,
572 + IPPROTO_UDP, NULL, &be_loport);
573 +
574 + exp->master = ct;
575 +
576 + exp->expectfn = expected;
577 + exp->flags = 0;
578 +
579 + if (expinfo.pbtype == pb_range) {
580 + pr_debug("Changing expectation mask to handle multiple ports\n");
581 + //exp->mask.dst.u.udp.port = 0xfffe;
582 + }
583 +
584 + pr_debug("expect_related %pI4:%u-%pI4:%u\n",
585 + &exp->tuple.src.u3.ip,
586 + ntohs(exp->tuple.src.u.udp.port),
587 + &exp->tuple.dst.u3.ip,
588 + ntohs(exp->tuple.dst.u.udp.port));
589 +
590 + nf_nat_rtsp = rcu_dereference(nf_nat_rtsp_hook);
591 + if (nf_nat_rtsp && ct->status & IPS_NAT_MASK)
592 + /* pass the request off to the nat helper */
593 + ret = nf_nat_rtsp(skb, ctinfo, hdrsoff, hdrslen, &expinfo, exp);
594 + else if (nf_ct_expect_related(exp) != 0) {
595 + pr_info("nf_conntrack_expect_related failed\n");
596 + ret = NF_DROP;
597 + }
598 + nf_ct_expect_put(exp);
599 + goto out;
600 + }
601 +out:
602 +
603 + return ret;
604 +}
605 +
606 +
607 +static inline int
608 +help_in(struct sk_buff *skb, size_t pktlen,
609 + struct nf_conn* ct, enum ip_conntrack_info ctinfo)
610 +{
611 + return NF_ACCEPT;
612 +}
613 +
614 +static int help(struct sk_buff *skb, unsigned int protoff,
615 + struct nf_conn *ct, enum ip_conntrack_info ctinfo)
616 +{
617 + struct tcphdr _tcph, *th;
618 + unsigned int dataoff, datalen;
619 + char *rb_ptr;
620 + int ret = NF_DROP;
621 +
622 + /* Until there's been traffic both ways, don't look in packets. */
623 + if (ctinfo != IP_CT_ESTABLISHED &&
624 + ctinfo != IP_CT_ESTABLISHED + IP_CT_IS_REPLY) {
625 + pr_debug("conntrackinfo = %u\n", ctinfo);
626 + return NF_ACCEPT;
627 + }
628 +
629 + /* Not whole TCP header? */
630 + th = skb_header_pointer(skb,protoff, sizeof(_tcph), &_tcph);
631 +
632 + if (!th)
633 + return NF_ACCEPT;
634 +
635 + /* No data ? */
636 + dataoff = protoff + th->doff*4;
637 + datalen = skb->len - dataoff;
638 + if (dataoff >= skb->len)
639 + return NF_ACCEPT;
640 +
641 + spin_lock_bh(&rtsp_buffer_lock);
642 + rb_ptr = skb_header_pointer(skb, dataoff,
643 + skb->len - dataoff, rtsp_buffer);
644 + BUG_ON(rb_ptr == NULL);
645 +
646 +#if 0
647 + /* Checksum invalid? Ignore. */
648 + /* FIXME: Source route IP option packets --RR */
649 + if (tcp_v4_check(tcph, tcplen, iph->saddr, iph->daddr,
650 + csum_partial((char*)tcph, tcplen, 0)))
651 + {
652 + DEBUGP("bad csum: %p %u %u.%u.%u.%u %u.%u.%u.%u\n",
653 + tcph, tcplen, NIPQUAD(iph->saddr), NIPQUAD(iph->daddr));
654 + return NF_ACCEPT;
655 + }
656 +#endif
657 +
658 + switch (CTINFO2DIR(ctinfo)) {
659 + case IP_CT_DIR_ORIGINAL:
660 + ret = help_out(skb, rb_ptr, datalen, ct, ctinfo);
661 + break;
662 + case IP_CT_DIR_REPLY:
663 + pr_debug("IP_CT_DIR_REPLY\n");
664 + /* inbound packet: server->client */
665 + ret = NF_ACCEPT;
666 + break;
667 + }
668 +
669 + spin_unlock_bh(&rtsp_buffer_lock);
670 +
671 + return ret;
672 +}
673 +
674 +static struct nf_conntrack_helper rtsp_helpers[MAX_PORTS];
675 +static char rtsp_names[MAX_PORTS][10];
676 +
677 +/* This function is intentionally _NOT_ defined as __exit */
678 +static void
679 +fini(void)
680 +{
681 + int i;
682 + for (i = 0; i < num_ports; i++) {
683 + pr_debug("unregistering port %d\n", ports[i]);
684 + nf_conntrack_helper_unregister(&rtsp_helpers[i]);
685 + }
686 + kfree(rtsp_buffer);
687 +}
688 +
689 +static int __init
690 +init(void)
691 +{
692 + int i, ret;
693 + struct nf_conntrack_helper *hlpr;
694 + char *tmpname;
695 +
696 + printk("nf_conntrack_rtsp v" IP_NF_RTSP_VERSION " loading\n");
697 +
698 + if (max_outstanding < 1) {
699 + printk("nf_conntrack_rtsp: max_outstanding must be a positive integer\n");
700 + return -EBUSY;
701 + }
702 + if (setup_timeout < 0) {
703 + printk("nf_conntrack_rtsp: setup_timeout must be a positive integer\n");
704 + return -EBUSY;
705 + }
706 +
707 + rtsp_exp_policy.max_expected = max_outstanding;
708 + rtsp_exp_policy.timeout = setup_timeout;
709 +
710 + rtsp_buffer = kmalloc(65536, GFP_KERNEL);
711 + if (!rtsp_buffer)
712 + return -ENOMEM;
713 +
714 + /* If no port given, default to standard rtsp port */
715 + if (ports[0] == 0) {
716 + ports[0] = RTSP_PORT;
717 + }
718 +
719 + for (i = 0; (i < MAX_PORTS) && ports[i]; i++) {
720 + hlpr = &rtsp_helpers[i];
721 + memset(hlpr, 0, sizeof(struct nf_conntrack_helper));
722 + hlpr->tuple.src.l3num = AF_INET;
723 + hlpr->tuple.src.u.tcp.port = htons(ports[i]);
724 + hlpr->tuple.dst.protonum = IPPROTO_TCP;
725 + //hlpr->mask.src.u.tcp.port = 0xFFFF;
726 + //hlpr->mask.dst.protonum = 0xFF;
727 + hlpr->expect_policy = &rtsp_exp_policy;
728 + hlpr->me = THIS_MODULE;
729 + hlpr->help = help;
730 +
731 + tmpname = &rtsp_names[i][0];
732 + if (ports[i] == RTSP_PORT) {
733 + sprintf(tmpname, "rtsp");
734 + } else {
735 + sprintf(tmpname, "rtsp-%d", i);
736 + }
737 + hlpr->name = tmpname;
738 +
739 + pr_debug("port #%d: %d\n", i, ports[i]);
740 +
741 + ret = nf_conntrack_helper_register(hlpr);
742 +
743 + if (ret) {
744 + printk("nf_conntrack_rtsp: ERROR registering port %d\n", ports[i]);
745 + fini();
746 + return -EBUSY;
747 + }
748 + num_ports++;
749 + }
750 + return 0;
751 +}
752 +
753 +module_init(init);
754 +module_exit(fini);
755 +
756 +EXPORT_SYMBOL(nf_nat_rtsp_hook_expectfn);
757 +
758 --- /dev/null
759 +++ b/extensions/rtsp/nf_conntrack_rtsp.h
760 @@ -0,0 +1,63 @@
761 +/*
762 + * RTSP extension for IP connection tracking.
763 + * (C) 2003 by Tom Marshall <tmarshall at real.com>
764 + * based on ip_conntrack_irc.h
765 + *
766 + * This program is free software; you can redistribute it and/or
767 + * modify it under the terms of the GNU General Public License
768 + * as published by the Free Software Foundation; either version
769 + * 2 of the License, or (at your option) any later version.
770 + */
771 +#ifndef _IP_CONNTRACK_RTSP_H
772 +#define _IP_CONNTRACK_RTSP_H
773 +
774 +//#define IP_NF_RTSP_DEBUG 1
775 +#define IP_NF_RTSP_VERSION "0.6.21"
776 +
777 +#ifdef __KERNEL__
778 +/* port block types */
779 +typedef enum {
780 + pb_single, /* client_port=x */
781 + pb_range, /* client_port=x-y */
782 + pb_discon /* client_port=x/y (rtspbis) */
783 +} portblock_t;
784 +
785 +/* We record seq number and length of rtsp headers here, all in host order. */
786 +
787 +/*
788 + * This structure is per expected connection. It is a member of struct
789 + * ip_conntrack_expect. The TCP SEQ for the conntrack expect is stored
790 + * there and we are expected to only store the length of the data which
791 + * needs replaced. If a packet contains multiple RTSP messages, we create
792 + * one expected connection per message.
793 + *
794 + * We use these variables to mark the entire header block. This may seem
795 + * like overkill, but the nature of RTSP requires it. A header may appear
796 + * multiple times in a message. We must treat two Transport headers the
797 + * same as one Transport header with two entries.
798 + */
799 +struct ip_ct_rtsp_expect
800 +{
801 + u_int32_t len; /* length of header block */
802 + portblock_t pbtype; /* Type of port block that was requested */
803 + u_int16_t loport; /* Port that was requested, low or first */
804 + u_int16_t hiport; /* Port that was requested, high or second */
805 +#if 0
806 + uint method; /* RTSP method */
807 + uint cseq; /* CSeq from request */
808 +#endif
809 +};
810 +
811 +extern unsigned int (*nf_nat_rtsp_hook)(struct sk_buff *skb,
812 + enum ip_conntrack_info ctinfo,
813 + unsigned int matchoff, unsigned int matchlen,
814 + struct ip_ct_rtsp_expect *prtspexp,
815 + struct nf_conntrack_expect *exp);
816 +
817 +extern void (*nf_nat_rtsp_hook_expectfn)(struct nf_conn *ct, struct nf_conntrack_expect *exp);
818 +
819 +#define RTSP_PORT 554
820 +
821 +#endif /* __KERNEL__ */
822 +
823 +#endif /* _IP_CONNTRACK_RTSP_H */
824 --- /dev/null
825 +++ b/extensions/rtsp/nf_nat_rtsp.c
826 @@ -0,0 +1,489 @@
827 +/*
828 + * RTSP extension for TCP NAT alteration
829 + * (C) 2003 by Tom Marshall <tmarshall at real.com>
830 + * based on ip_nat_irc.c
831 + *
832 + * This program is free software; you can redistribute it and/or
833 + * modify it under the terms of the GNU General Public License
834 + * as published by the Free Software Foundation; either version
835 + * 2 of the License, or (at your option) any later version.
836 + *
837 + * Module load syntax:
838 + * insmod nf_nat_rtsp.o ports=port1,port2,...port<MAX_PORTS>
839 + * stunaddr=<address>
840 + * destaction=[auto|strip|none]
841 + *
842 + * If no ports are specified, the default will be port 554 only.
843 + *
844 + * stunaddr specifies the address used to detect that a client is using STUN.
845 + * If this address is seen in the destination parameter, it is assumed that
846 + * the client has already punched a UDP hole in the firewall, so we don't
847 + * mangle the client_port. If none is specified, it is autodetected. It
848 + * only needs to be set if you have multiple levels of NAT. It should be
849 + * set to the external address that the STUN clients detect. Note that in
850 + * this case, it will not be possible for clients to use UDP with servers
851 + * between the NATs.
852 + *
853 + * If no destaction is specified, auto is used.
854 + * destaction=auto: strip destination parameter if it is not stunaddr.
855 + * destaction=strip: always strip destination parameter (not recommended).
856 + * destaction=none: do not touch destination parameter (not recommended).
857 + */
858 +
859 +#include <linux/module.h>
860 +#include <net/tcp.h>
861 +#include <net/netfilter/nf_nat_helper.h>
862 +#include <net/netfilter/nf_nat_rule.h>
863 +#include "nf_conntrack_rtsp.h"
864 +#include <net/netfilter/nf_conntrack_expect.h>
865 +
866 +#include <linux/inet.h>
867 +#include <linux/ctype.h>
868 +#define NF_NEED_STRNCASECMP
869 +#define NF_NEED_STRTOU16
870 +#include "netfilter_helpers.h"
871 +#define NF_NEED_MIME_NEXTLINE
872 +#include "netfilter_mime.h"
873 +
874 +#define MAX_PORTS 8
875 +#define DSTACT_AUTO 0
876 +#define DSTACT_STRIP 1
877 +#define DSTACT_NONE 2
878 +
879 +static char* stunaddr = NULL;
880 +static char* destaction = NULL;
881 +
882 +static u_int32_t extip = 0;
883 +static int dstact = 0;
884 +
885 +MODULE_AUTHOR("Tom Marshall <tmarshall at real.com>");
886 +MODULE_DESCRIPTION("RTSP network address translation module");
887 +MODULE_LICENSE("GPL");
888 +module_param(stunaddr, charp, 0644);
889 +MODULE_PARM_DESC(stunaddr, "Address for detecting STUN");
890 +module_param(destaction, charp, 0644);
891 +MODULE_PARM_DESC(destaction, "Action for destination parameter (auto/strip/none)");
892 +
893 +#define SKIP_WSPACE(ptr,len,off) while(off < len && isspace(*(ptr+off))) { off++; }
894 +
895 +/*** helper functions ***/
896 +
897 +static void
898 +get_skb_tcpdata(struct sk_buff* skb, char** pptcpdata, uint* ptcpdatalen)
899 +{
900 + struct iphdr* iph = ip_hdr(skb);
901 + struct tcphdr* tcph = (void *)iph + ip_hdrlen(skb);
902 +
903 + *pptcpdata = (char*)tcph + tcph->doff*4;
904 + *ptcpdatalen = ((char*)skb_transport_header(skb) + skb->len) - *pptcpdata;
905 +}
906 +
907 +/*** nat functions ***/
908 +
909 +/*
910 + * Mangle the "Transport:" header:
911 + * - Replace all occurences of "client_port=<spec>"
912 + * - Handle destination parameter
913 + *
914 + * In:
915 + * ct, ctinfo = conntrack context
916 + * skb = packet
917 + * tranoff = Transport header offset from TCP data
918 + * tranlen = Transport header length (incl. CRLF)
919 + * rport_lo = replacement low port (host endian)
920 + * rport_hi = replacement high port (host endian)
921 + *
922 + * Returns packet size difference.
923 + *
924 + * Assumes that a complete transport header is present, ending with CR or LF
925 + */
926 +static int
927 +rtsp_mangle_tran(enum ip_conntrack_info ctinfo,
928 + struct nf_conntrack_expect* exp,
929 + struct ip_ct_rtsp_expect* prtspexp,
930 + struct sk_buff* skb, uint tranoff, uint tranlen)
931 +{
932 + char* ptcp;
933 + uint tcplen;
934 + char* ptran;
935 + char rbuf1[16]; /* Replacement buffer (one port) */
936 + uint rbuf1len; /* Replacement len (one port) */
937 + char rbufa[16]; /* Replacement buffer (all ports) */
938 + uint rbufalen; /* Replacement len (all ports) */
939 + u_int32_t newip;
940 + u_int16_t loport, hiport;
941 + uint off = 0;
942 + uint diff; /* Number of bytes we removed */
943 +
944 + struct nf_conn *ct = exp->master;
945 + struct nf_conntrack_tuple *t;
946 +
947 + char szextaddr[15+1];
948 + uint extaddrlen;
949 + int is_stun;
950 +
951 + get_skb_tcpdata(skb, &ptcp, &tcplen);
952 + ptran = ptcp+tranoff;
953 +
954 + if (tranoff+tranlen > tcplen || tcplen-tranoff < tranlen ||
955 + tranlen < 10 || !iseol(ptran[tranlen-1]) ||
956 + nf_strncasecmp(ptran, "Transport:", 10) != 0)
957 + {
958 + pr_info("sanity check failed\n");
959 + return 0;
960 + }
961 + off += 10;
962 + SKIP_WSPACE(ptcp+tranoff, tranlen, off);
963 +
964 + newip = ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.u3.ip;
965 + t = &exp->tuple;
966 + t->dst.u3.ip = newip;
967 +
968 + extaddrlen = extip ? sprintf(szextaddr, "%pI4", &extip)
969 + : sprintf(szextaddr, "%pI4", &newip);
970 + pr_debug("stunaddr=%s (%s)\n", szextaddr, (extip?"forced":"auto"));
971 +
972 + rbuf1len = rbufalen = 0;
973 + switch (prtspexp->pbtype)
974 + {
975 + case pb_single:
976 + for (loport = prtspexp->loport; loport != 0; loport++) /* XXX: improper wrap? */
977 + {
978 + t->dst.u.udp.port = htons(loport);
979 + if (nf_ct_expect_related(exp) == 0)
980 + {
981 + pr_debug("using port %hu\n", loport);
982 + break;
983 + }
984 + }
985 + if (loport != 0)
986 + {
987 + rbuf1len = sprintf(rbuf1, "%hu", loport);
988 + rbufalen = sprintf(rbufa, "%hu", loport);
989 + }
990 + break;
991 + case pb_range:
992 + for (loport = prtspexp->loport; loport != 0; loport += 2) /* XXX: improper wrap? */
993 + {
994 + t->dst.u.udp.port = htons(loport);
995 + if (nf_ct_expect_related(exp) == 0)
996 + {
997 + hiport = loport + 1; //~exp->mask.dst.u.udp.port;
998 + pr_debug("using ports %hu-%hu\n", loport, hiport);
999 + break;
1000 + }
1001 + }
1002 + if (loport != 0)
1003 + {
1004 + rbuf1len = sprintf(rbuf1, "%hu", loport);
1005 + rbufalen = sprintf(rbufa, "%hu-%hu", loport, loport+1);
1006 + }
1007 + break;
1008 + case pb_discon:
1009 + for (loport = prtspexp->loport; loport != 0; loport++) /* XXX: improper wrap? */
1010 + {
1011 + t->dst.u.udp.port = htons(loport);
1012 + if (nf_ct_expect_related(exp) == 0)
1013 + {
1014 + pr_debug("using port %hu (1 of 2)\n", loport);
1015 + break;
1016 + }
1017 + }
1018 + for (hiport = prtspexp->hiport; hiport != 0; hiport++) /* XXX: improper wrap? */
1019 + {
1020 + t->dst.u.udp.port = htons(hiport);
1021 + if (nf_ct_expect_related(exp) == 0)
1022 + {
1023 + pr_debug("using port %hu (2 of 2)\n", hiport);
1024 + break;
1025 + }
1026 + }
1027 + if (loport != 0 && hiport != 0)
1028 + {
1029 + rbuf1len = sprintf(rbuf1, "%hu", loport);
1030 + if (hiport == loport+1)
1031 + {
1032 + rbufalen = sprintf(rbufa, "%hu-%hu", loport, hiport);
1033 + }
1034 + else
1035 + {
1036 + rbufalen = sprintf(rbufa, "%hu/%hu", loport, hiport);
1037 + }
1038 + }
1039 + break;
1040 + }
1041 +
1042 + if (rbuf1len == 0)
1043 + {
1044 + return 0; /* cannot get replacement port(s) */
1045 + }
1046 +
1047 + /* Transport: tran;field;field=val,tran;field;field=val,... */
1048 + while (off < tranlen)
1049 + {
1050 + uint saveoff;
1051 + const char* pparamend;
1052 + uint nextparamoff;
1053 +
1054 + pparamend = memchr(ptran+off, ',', tranlen-off);
1055 + pparamend = (pparamend == NULL) ? ptran+tranlen : pparamend+1;
1056 + nextparamoff = pparamend-ptcp;
1057 +
1058 + /*
1059 + * We pass over each param twice. On the first pass, we look for a
1060 + * destination= field. It is handled by the security policy. If it
1061 + * is present, allowed, and equal to our external address, we assume
1062 + * that STUN is being used and we leave the client_port= field alone.
1063 + */
1064 + is_stun = 0;
1065 + saveoff = off;
1066 + while (off < nextparamoff)
1067 + {
1068 + const char* pfieldend;
1069 + uint nextfieldoff;
1070 +
1071 + pfieldend = memchr(ptran+off, ';', nextparamoff-off);
1072 + nextfieldoff = (pfieldend == NULL) ? nextparamoff : pfieldend-ptran+1;
1073 +
1074 + if (dstact != DSTACT_NONE && strncmp(ptran+off, "destination=", 12) == 0)
1075 + {
1076 + if (strncmp(ptran+off+12, szextaddr, extaddrlen) == 0)
1077 + {
1078 + is_stun = 1;
1079 + }
1080 + if (dstact == DSTACT_STRIP || (dstact == DSTACT_AUTO && !is_stun))
1081 + {
1082 + diff = nextfieldoff-off;
1083 + if (!nf_nat_mangle_tcp_packet(skb, ct, ctinfo,
1084 + off, diff, NULL, 0))
1085 + {
1086 + /* mangle failed, all we can do is bail */
1087 + nf_ct_unexpect_related(exp);
1088 + return 0;
1089 + }
1090 + get_skb_tcpdata(skb, &ptcp, &tcplen);
1091 + ptran = ptcp+tranoff;
1092 + tranlen -= diff;
1093 + nextparamoff -= diff;
1094 + nextfieldoff -= diff;
1095 + }
1096 + }
1097 +
1098 + off = nextfieldoff;
1099 + }
1100 + if (is_stun)
1101 + {
1102 + continue;
1103 + }
1104 + off = saveoff;
1105 + while (off < nextparamoff)
1106 + {
1107 + const char* pfieldend;
1108 + uint nextfieldoff;
1109 +
1110 + pfieldend = memchr(ptran+off, ';', nextparamoff-off);
1111 + nextfieldoff = (pfieldend == NULL) ? nextparamoff : pfieldend-ptran+1;
1112 +
1113 + if (strncmp(ptran+off, "client_port=", 12) == 0)
1114 + {
1115 + u_int16_t port;
1116 + uint numlen;
1117 + uint origoff;
1118 + uint origlen;
1119 + char* rbuf = rbuf1;
1120 + uint rbuflen = rbuf1len;
1121 +
1122 + off += 12;
1123 + origoff = (ptran-ptcp)+off;
1124 + origlen = 0;
1125 + numlen = nf_strtou16(ptran+off, &port);
1126 + off += numlen;
1127 + origlen += numlen;
1128 + if (port != prtspexp->loport)
1129 + {
1130 + pr_debug("multiple ports found, port %hu ignored\n", port);
1131 + }
1132 + else
1133 + {
1134 + if (ptran[off] == '-' || ptran[off] == '/')
1135 + {
1136 + off++;
1137 + origlen++;
1138 + numlen = nf_strtou16(ptran+off, &port);
1139 + off += numlen;
1140 + origlen += numlen;
1141 + rbuf = rbufa;
1142 + rbuflen = rbufalen;
1143 + }
1144 +
1145 + /*
1146 + * note we cannot just memcpy() if the sizes are the same.
1147 + * the mangle function does skb resizing, checks for a
1148 + * cloned skb, and updates the checksums.
1149 + *
1150 + * parameter 4 below is offset from start of tcp data.
1151 + */
1152 + diff = origlen-rbuflen;
1153 + if (!nf_nat_mangle_tcp_packet(skb, ct, ctinfo,
1154 + origoff, origlen, rbuf, rbuflen))
1155 + {
1156 + /* mangle failed, all we can do is bail */
1157 + nf_ct_unexpect_related(exp);
1158 + return 0;
1159 + }
1160 + get_skb_tcpdata(skb, &ptcp, &tcplen);
1161 + ptran = ptcp+tranoff;
1162 + tranlen -= diff;
1163 + nextparamoff -= diff;
1164 + nextfieldoff -= diff;
1165 + }
1166 + }
1167 +
1168 + off = nextfieldoff;
1169 + }
1170 +
1171 + off = nextparamoff;
1172 + }
1173 +
1174 + return 1;
1175 +}
1176 +
1177 +static uint
1178 +help_out(struct sk_buff *skb, enum ip_conntrack_info ctinfo,
1179 + unsigned int matchoff, unsigned int matchlen, struct ip_ct_rtsp_expect* prtspexp,
1180 + struct nf_conntrack_expect* exp)
1181 +{
1182 + char* ptcp;
1183 + uint tcplen;
1184 + uint hdrsoff;
1185 + uint hdrslen;
1186 + uint lineoff;
1187 + uint linelen;
1188 + uint off;
1189 +
1190 + //struct iphdr* iph = (struct iphdr*)(*pskb)->nh.iph;
1191 + //struct tcphdr* tcph = (struct tcphdr*)((void*)iph + iph->ihl*4);
1192 +
1193 + get_skb_tcpdata(skb, &ptcp, &tcplen);
1194 + hdrsoff = matchoff;//exp->seq - ntohl(tcph->seq);
1195 + hdrslen = matchlen;
1196 + off = hdrsoff;
1197 + pr_debug("NAT rtsp help_out\n");
1198 +
1199 + while (nf_mime_nextline(ptcp, hdrsoff+hdrslen, &off, &lineoff, &linelen))
1200 + {
1201 + if (linelen == 0)
1202 + {
1203 + break;
1204 + }
1205 + if (off > hdrsoff+hdrslen)
1206 + {
1207 + pr_info("!! overrun !!");
1208 + break;
1209 + }
1210 + pr_debug("hdr: len=%u, %.*s", linelen, (int)linelen, ptcp+lineoff);
1211 +
1212 + if (nf_strncasecmp(ptcp+lineoff, "Transport:", 10) == 0)
1213 + {
1214 + uint oldtcplen = tcplen;
1215 + pr_debug("hdr: Transport\n");
1216 + if (!rtsp_mangle_tran(ctinfo, exp, prtspexp, skb, lineoff, linelen))
1217 + {
1218 + pr_debug("hdr: Transport mangle failed");
1219 + break;
1220 + }
1221 + get_skb_tcpdata(skb, &ptcp, &tcplen);
1222 + hdrslen -= (oldtcplen-tcplen);
1223 + off -= (oldtcplen-tcplen);
1224 + lineoff -= (oldtcplen-tcplen);
1225 + linelen -= (oldtcplen-tcplen);
1226 + pr_debug("rep: len=%u, %.*s", linelen, (int)linelen, ptcp+lineoff);
1227 + }
1228 + }
1229 +
1230 + return NF_ACCEPT;
1231 +}
1232 +
1233 +static unsigned int
1234 +help(struct sk_buff *skb, enum ip_conntrack_info ctinfo,
1235 + unsigned int matchoff, unsigned int matchlen, struct ip_ct_rtsp_expect* prtspexp,
1236 + struct nf_conntrack_expect* exp)
1237 +{
1238 + int dir = CTINFO2DIR(ctinfo);
1239 + int rc = NF_ACCEPT;
1240 +
1241 + switch (dir)
1242 + {
1243 + case IP_CT_DIR_ORIGINAL:
1244 + rc = help_out(skb, ctinfo, matchoff, matchlen, prtspexp, exp);
1245 + break;
1246 + case IP_CT_DIR_REPLY:
1247 + pr_debug("unmangle ! %u\n", ctinfo);
1248 + /* XXX: unmangle */
1249 + rc = NF_ACCEPT;
1250 + break;
1251 + }
1252 + //UNLOCK_BH(&ip_rtsp_lock);
1253 +
1254 + return rc;
1255 +}
1256 +
1257 +static void expected(struct nf_conn* ct, struct nf_conntrack_expect *exp)
1258 +{
1259 + struct nf_nat_multi_range_compat mr;
1260 + u_int32_t newdstip, newsrcip, newip;
1261 +
1262 + struct nf_conn *master = ct->master;
1263 +
1264 + newdstip = master->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.u3.ip;
1265 + newsrcip = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.u3.ip;
1266 + //FIXME (how to port that ?)
1267 + //code from 2.4 : newip = (HOOK2MANIP(hooknum) == IP_NAT_MANIP_SRC) ? newsrcip : newdstip;
1268 + newip = newdstip;
1269 +
1270 + pr_debug("newsrcip=%pI4, newdstip=%pI4, newip=%pI4\n",
1271 + &newsrcip, &newdstip, &newip);
1272 +
1273 + mr.rangesize = 1;
1274 + // We don't want to manip the per-protocol, just the IPs.
1275 + mr.range[0].flags = IP_NAT_RANGE_MAP_IPS;
1276 + mr.range[0].min_ip = mr.range[0].max_ip = newip;
1277 +
1278 + nf_nat_setup_info(ct, &mr.range[0], IP_NAT_MANIP_DST);
1279 +}
1280 +
1281 +
1282 +static void __exit fini(void)
1283 +{
1284 + nf_nat_rtsp_hook = NULL;
1285 + nf_nat_rtsp_hook_expectfn = NULL;
1286 + synchronize_net();
1287 +}
1288 +
1289 +static int __init init(void)
1290 +{
1291 + printk("nf_nat_rtsp v" IP_NF_RTSP_VERSION " loading\n");
1292 +
1293 + BUG_ON(nf_nat_rtsp_hook);
1294 + nf_nat_rtsp_hook = help;
1295 + nf_nat_rtsp_hook_expectfn = &expected;
1296 +
1297 + if (stunaddr != NULL)
1298 + extip = in_aton(stunaddr);
1299 +
1300 + if (destaction != NULL) {
1301 + if (strcmp(destaction, "auto") == 0)
1302 + dstact = DSTACT_AUTO;
1303 +
1304 + if (strcmp(destaction, "strip") == 0)
1305 + dstact = DSTACT_STRIP;
1306 +
1307 + if (strcmp(destaction, "none") == 0)
1308 + dstact = DSTACT_NONE;
1309 + }
1310 +
1311 + return 0;
1312 +}
1313 +
1314 +module_init(init);
1315 +module_exit(fini);
1316 --- a/extensions/Kbuild
1317 +++ b/extensions/Kbuild
1318 @@ -33,6 +33,7 @@ obj-${build_lscan} += xt_lscan.o
1319 obj-${build_pknock} += pknock/
1320 obj-${build_psd} += xt_psd.o
1321 obj-${build_quota2} += xt_quota2.o
1322 +obj-${build_rtsp} += rtsp/
1323
1324 -include ${M}/*.Kbuild
1325 -include ${M}/Kbuild.*
1326 --- a/mconfig
1327 +++ b/mconfig
1328 @@ -26,3 +26,4 @@ build_lscan=m
1329 build_pknock=m
1330 build_psd=m
1331 build_quota2=m
1332 +build_rtsp=m