You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1683 lines
47 KiB

  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,732 @@
  239. +/*
  240. + * RTSP extension for IP connection tracking
  241. + * (C) 2003 by Tom Marshall <tmarshall at real.com>
  242. + *
  243. + * 2005-02-13: Harald Welte <laforge at netfilter.org>
  244. + * - port to 2.6
  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
  254. + * 2018-04-17: Alin Nastac <alin.nastac at gmail.com>
  255. + * Hans Dedecker <dedeckeh at gmail.com>
  256. + * - use IP address read from SETUP URI in expected connections
  257. + * 2018-04-18: Hans Dedecker <dedeckeh at gmail.com>
  258. + * - update RTP expected connection source IP based on SOURCE
  259. + * in the SETUP reply message
  260. + *
  261. + * based on ip_conntrack_irc.c
  262. + *
  263. + * This program is free software; you can redistribute it and/or
  264. + * modify it under the terms of the GNU General Public License
  265. + * as published by the Free Software Foundation; either version
  266. + * 2 of the License, or (at your option) any later version.
  267. + *
  268. + * Module load syntax:
  269. + * insmod nf_conntrack_rtsp.o ports=port1,port2,...port<MAX_PORTS>
  270. + * max_outstanding=n setup_timeout=secs
  271. + *
  272. + * If no ports are specified, the default will be port 554.
  273. + *
  274. + * With max_outstanding you can define the maximum number of not yet
  275. + * answered SETUP requests per RTSP session (default 8).
  276. + * With setup_timeout you can specify how long the system waits for
  277. + * an expected data channel (default 300 seconds).
  278. + *
  279. + */
  280. +
  281. +#include <linux/module.h>
  282. +#include <linux/netfilter.h>
  283. +#include <linux/ip.h>
  284. +#include <linux/inet.h>
  285. +#include <net/tcp.h>
  286. +
  287. +#include <net/netfilter/nf_conntrack.h>
  288. +#include <net/netfilter/nf_conntrack_expect.h>
  289. +#include <net/netfilter/nf_conntrack_helper.h>
  290. +#include "nf_conntrack_rtsp.h"
  291. +
  292. +#define NF_NEED_STRNCASECMP
  293. +#define NF_NEED_STRTOU16
  294. +#define NF_NEED_STRTOU32
  295. +#define NF_NEED_NEXTLINE
  296. +#include "netfilter_helpers.h"
  297. +#define NF_NEED_MIME_NEXTLINE
  298. +#include "netfilter_mime.h"
  299. +
  300. +#include <linux/ctype.h>
  301. +
  302. +#define MAX_PORTS 8
  303. +static int ports[MAX_PORTS];
  304. +static int num_ports = 0;
  305. +static int max_outstanding = 8;
  306. +static unsigned int setup_timeout = 300;
  307. +
  308. +MODULE_AUTHOR("Tom Marshall <tmarshall at real.com>");
  309. +MODULE_DESCRIPTION("RTSP connection tracking module");
  310. +MODULE_LICENSE("GPL");
  311. +module_param_array(ports, int, &num_ports, 0400);
  312. +MODULE_PARM_DESC(ports, "port numbers of RTSP servers");
  313. +module_param(max_outstanding, int, 0400);
  314. +MODULE_PARM_DESC(max_outstanding, "max number of outstanding SETUP requests per RTSP session");
  315. +module_param(setup_timeout, int, 0400);
  316. +MODULE_PARM_DESC(setup_timeout, "timeout on for unestablished data channels");
  317. +
  318. +static char *rtsp_buffer;
  319. +static DEFINE_SPINLOCK(rtsp_buffer_lock);
  320. +
  321. +static struct nf_conntrack_expect_policy rtsp_exp_policy;
  322. +
  323. +unsigned int (*nf_nat_rtsp_hook)(struct sk_buff *skb,
  324. + enum ip_conntrack_info ctinfo,
  325. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
  326. + unsigned int protoff,
  327. +#endif
  328. + unsigned int matchoff, unsigned int matchlen,
  329. + struct ip_ct_rtsp_expect* prtspexp,
  330. + struct nf_conntrack_expect *rtp_exp,
  331. + struct nf_conntrack_expect *rtcp_exp);
  332. +
  333. +EXPORT_SYMBOL_GPL(nf_nat_rtsp_hook);
  334. +
  335. +/*
  336. + * Max mappings we will allow for one RTSP connection (for RTP, the number
  337. + * of allocated ports is twice this value). Note that SMIL burns a lot of
  338. + * ports so keep this reasonably high. If this is too low, you will see a
  339. + * lot of "no free client map entries" messages.
  340. + */
  341. +#define MAX_PORT_MAPS 16
  342. +
  343. +/*** default port list was here in the masq code: 554, 3030, 4040 ***/
  344. +
  345. +#define SKIP_WSPACE(ptr,len,off) while(off < len && isspace(*(ptr+off))) { off++; }
  346. +
  347. +/*
  348. + * Parse an RTSP packet.
  349. + *
  350. + * Returns zero if parsing failed.
  351. + *
  352. + * Parameters:
  353. + * IN ptcp tcp data pointer
  354. + * IN tcplen tcp data len
  355. + * IN/OUT ptcpoff points to current tcp offset
  356. + * OUT phdrsoff set to offset of rtsp headers
  357. + * OUT phdrslen set to length of rtsp headers
  358. + * OUT pcseqoff set to offset of CSeq header
  359. + * OUT pcseqlen set to length of CSeq header
  360. + */
  361. +static int
  362. +rtsp_parse_message(char* ptcp, uint tcplen, uint* ptcpoff,
  363. + uint* phdrsoff, uint* phdrslen,
  364. + uint* pcseqoff, uint* pcseqlen,
  365. + uint* transoff, uint* translen)
  366. +{
  367. + uint entitylen = 0;
  368. + uint lineoff;
  369. + uint linelen;
  370. +
  371. + if (!nf_nextline(ptcp, tcplen, ptcpoff, &lineoff, &linelen))
  372. + return 0;
  373. +
  374. + *phdrsoff = *ptcpoff;
  375. + while (nf_mime_nextline(ptcp, tcplen, ptcpoff, &lineoff, &linelen)) {
  376. + if (linelen == 0) {
  377. + if (entitylen > 0)
  378. + *ptcpoff += min(entitylen, tcplen - *ptcpoff);
  379. + break;
  380. + }
  381. + if (lineoff+linelen > tcplen) {
  382. + pr_info("!! overrun !!\n");
  383. + break;
  384. + }
  385. +
  386. + if (nf_strncasecmp(ptcp+lineoff, "CSeq:", 5) == 0) {
  387. + *pcseqoff = lineoff;
  388. + *pcseqlen = linelen;
  389. + }
  390. +
  391. + if (nf_strncasecmp(ptcp+lineoff, "Transport:", 10) == 0) {
  392. + *transoff = lineoff;
  393. + *translen = linelen;
  394. + }
  395. +
  396. + if (nf_strncasecmp(ptcp+lineoff, "Content-Length:", 15) == 0) {
  397. + uint off = lineoff+15;
  398. + SKIP_WSPACE(ptcp+lineoff, linelen, off);
  399. + nf_strtou32(ptcp+off, &entitylen);
  400. + }
  401. + }
  402. + *phdrslen = (*ptcpoff) - (*phdrsoff);
  403. +
  404. + return 1;
  405. +}
  406. +
  407. +/*
  408. + * Find lo/hi client ports and/or source (if any) in transport header
  409. + * In:
  410. + * ptcp, tcplen = packet
  411. + * tranoff, tranlen = buffer to search
  412. + *
  413. + * Out:
  414. + * pport_lo, pport_hi = lo/hi ports (host endian)
  415. + * srvaddr
  416. + *
  417. + * Returns nonzero if any client ports found
  418. + *
  419. + * Note: it is valid (and expected) for the client to request multiple
  420. + * transports, so we need to parse the entire line.
  421. + */
  422. +static int
  423. +rtsp_parse_transport(char* ptran, uint tranlen,
  424. + struct ip_ct_rtsp_expect* prtspexp)
  425. +{
  426. + int rc = 0;
  427. + uint off = 0;
  428. +
  429. + if (tranlen < 10 || !iseol(ptran[tranlen-1]) ||
  430. + nf_strncasecmp(ptran, "Transport:", 10) != 0) {
  431. + pr_info("sanity check failed\n");
  432. + return 0;
  433. + }
  434. +
  435. + pr_debug("tran='%.*s'\n", (int)tranlen, ptran);
  436. + off += 10;
  437. + SKIP_WSPACE(ptran, tranlen, off);
  438. +
  439. + /* Transport: tran;field;field=val,tran;field;field=val,... */
  440. + while (off < tranlen) {
  441. + const char* pparamend;
  442. + uint nextparamoff;
  443. +
  444. + pparamend = memchr(ptran+off, ',', tranlen-off);
  445. + pparamend = (pparamend == NULL) ? ptran+tranlen : pparamend+1;
  446. + nextparamoff = pparamend-ptran;
  447. +
  448. + while (off < nextparamoff) {
  449. + const char* pfieldend;
  450. + uint nextfieldoff;
  451. +
  452. + pfieldend = memchr(ptran+off, ';', nextparamoff-off);
  453. + nextfieldoff = (pfieldend == NULL) ? nextparamoff : pfieldend-ptran+1;
  454. +
  455. + if (strncmp(ptran+off, "client_port=", 12) == 0) {
  456. + u_int16_t port;
  457. + uint numlen;
  458. +
  459. + off += 12;
  460. + numlen = nf_strtou16(ptran+off, &port);
  461. + off += numlen;
  462. + if (prtspexp->loport != 0 && prtspexp->loport != port)
  463. + pr_debug("multiple ports found, port %hu ignored\n", port);
  464. + else {
  465. + pr_debug("lo port found : %hu\n", port);
  466. + prtspexp->loport = prtspexp->hiport = port;
  467. + if (ptran[off] == '-') {
  468. + off++;
  469. + numlen = nf_strtou16(ptran+off, &port);
  470. + off += numlen;
  471. + prtspexp->pbtype = pb_range;
  472. + prtspexp->hiport = port;
  473. +
  474. + // If we have a range, assume rtp:
  475. + // loport must be even, hiport must be loport+1
  476. + if ((prtspexp->loport & 0x0001) != 0 ||
  477. + prtspexp->hiport != prtspexp->loport+1) {
  478. + pr_debug("incorrect range: %hu-%hu, correcting\n",
  479. + prtspexp->loport, prtspexp->hiport);
  480. + prtspexp->loport &= 0xfffe;
  481. + prtspexp->hiport = prtspexp->loport+1;
  482. + }
  483. + } else if (ptran[off] == '/') {
  484. + off++;
  485. + numlen = nf_strtou16(ptran+off, &port);
  486. + off += numlen;
  487. + prtspexp->pbtype = pb_discon;
  488. + prtspexp->hiport = port;
  489. + }
  490. + rc = 1;
  491. + }
  492. + } else if (strncmp(ptran+off, "source=", 7) == 0) {
  493. + uint srcaddrlen;
  494. +
  495. + off += 7;
  496. + srcaddrlen = nextfieldoff - off - 1;
  497. +
  498. + if (in4_pton(ptran + off, srcaddrlen,
  499. + (u8 *)&prtspexp->srvaddr.in,
  500. + -1, NULL))
  501. + pr_debug("source found : %pI4\n",
  502. + &prtspexp->srvaddr.ip);
  503. + }
  504. +
  505. + /*
  506. + * Note we don't look for the destination parameter here.
  507. + * If we are using NAT, the NAT module will handle it. If not,
  508. + * and the client is sending packets elsewhere, the expectation
  509. + * will quietly time out.
  510. + */
  511. +
  512. + off = nextfieldoff;
  513. + }
  514. +
  515. + off = nextparamoff;
  516. + }
  517. +
  518. + return rc;
  519. +}
  520. +
  521. +
  522. +/*** conntrack functions ***/
  523. +
  524. +/* outbound packet: client->server */
  525. +
  526. +static inline int
  527. +help_out(struct sk_buff *skb, unsigned char *rb_ptr, unsigned int datalen,
  528. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
  529. + struct nf_conn *ct, enum ip_conntrack_info ctinfo,
  530. + unsigned int protoff)
  531. +#else
  532. + struct nf_conn *ct, enum ip_conntrack_info ctinfo)
  533. +#endif
  534. +{
  535. + struct ip_ct_rtsp_expect expinfo;
  536. +
  537. + int dir = CTINFO2DIR(ctinfo); /* = IP_CT_DIR_ORIGINAL */
  538. + //struct tcphdr* tcph = (void*)iph + iph->ihl * 4;
  539. + //uint tcplen = pktlen - iph->ihl * 4;
  540. + char* pdata = rb_ptr;
  541. + //uint datalen = tcplen - tcph->doff * 4;
  542. + uint dataoff = 0;
  543. + int ret = NF_ACCEPT;
  544. +
  545. + struct nf_conntrack_expect *rtp_exp;
  546. + struct nf_conntrack_expect *rtcp_exp = NULL;
  547. +
  548. + __be16 be_loport;
  549. + __be16 be_hiport;
  550. +
  551. + typeof(nf_nat_rtsp_hook) nf_nat_rtsp;
  552. +
  553. + memset(&expinfo, 0, sizeof(expinfo));
  554. +
  555. + while (dataoff < datalen) {
  556. + uint cmdoff = dataoff;
  557. + uint hdrsoff = 0;
  558. + uint hdrslen = 0;
  559. + uint cseqoff = 0;
  560. + uint cseqlen = 0;
  561. + uint transoff = 0;
  562. + uint translen = 0;
  563. + uint off;
  564. + union nf_inet_addr srvaddr;
  565. +
  566. + if (!rtsp_parse_message(pdata, datalen, &dataoff,
  567. + &hdrsoff, &hdrslen,
  568. + &cseqoff, &cseqlen,
  569. + &transoff, &translen))
  570. + break; /* not a valid message */
  571. +
  572. + if (strncmp(pdata+cmdoff, "TEARDOWN ", 9) == 0) {
  573. + pr_debug("teardown handled\n");
  574. + nf_ct_remove_expectations(ct); /* FIXME must be session id aware */
  575. + break;
  576. + }
  577. +
  578. + if (strncmp(pdata+cmdoff, "SETUP ", 6) != 0)
  579. + continue; /* not a SETUP message */
  580. +
  581. + srvaddr = ct->tuplehash[!dir].tuple.src.u3;
  582. +
  583. + /* try to get RTP media source from SETUP URI */
  584. + off = cmdoff + 6;
  585. + while (off < datalen) {
  586. + if (strncmp(pdata+off, "://", 3) == 0) {
  587. + off += 3;
  588. + cmdoff = off;
  589. +
  590. + while (off < datalen) {
  591. + if (pdata[off] == ':' ||
  592. + pdata[off] == '/' ||
  593. + pdata[off] == ' ') {
  594. + in4_pton(pdata + cmdoff,
  595. + off - cmdoff,
  596. + (u8 *)&srvaddr.in,
  597. + -1, NULL);
  598. + break;
  599. + }
  600. + off++;
  601. + }
  602. + break;
  603. + }
  604. + off++;
  605. + }
  606. +
  607. + pr_debug("found a setup message\n");
  608. +
  609. + off = 0;
  610. + if(translen)
  611. + rtsp_parse_transport(pdata+transoff, translen, &expinfo);
  612. +
  613. + if (expinfo.loport == 0) {
  614. + pr_debug("no udp transports found\n");
  615. + continue; /* no udp transports found */
  616. + }
  617. +
  618. + pr_debug("udp transport found, ports=(%d,%hu,%hu)\n",
  619. + (int)expinfo.pbtype, expinfo.loport, expinfo.hiport);
  620. +
  621. +
  622. + be_loport = htons(expinfo.loport);
  623. +
  624. + rtp_exp = nf_ct_expect_alloc(ct);
  625. + if (rtp_exp == NULL) {
  626. + ret = NF_DROP;
  627. + goto out;
  628. + }
  629. +
  630. + nf_ct_expect_init(rtp_exp, NF_CT_EXPECT_CLASS_DEFAULT,
  631. + nf_ct_l3num(ct), &srvaddr,
  632. + &ct->tuplehash[!dir].tuple.dst.u3,
  633. + IPPROTO_UDP, NULL, &be_loport);
  634. +
  635. + rtp_exp->flags = 0;
  636. +
  637. + if (expinfo.pbtype == pb_range) {
  638. + pr_debug("setup expectation for rtcp\n");
  639. +
  640. + be_hiport = htons(expinfo.hiport);
  641. + rtcp_exp = nf_ct_expect_alloc(ct);
  642. + if (rtcp_exp == NULL) {
  643. + ret = NF_DROP;
  644. + goto out1;
  645. + }
  646. +
  647. + nf_ct_expect_init(rtcp_exp, NF_CT_EXPECT_CLASS_DEFAULT,
  648. + nf_ct_l3num(ct), &srvaddr,
  649. + &ct->tuplehash[!dir].tuple.dst.u3,
  650. + IPPROTO_UDP, NULL, &be_hiport);
  651. +
  652. + rtcp_exp->flags = 0;
  653. +
  654. + pr_debug("expect_related %pI4:%u-%u-%pI4:%u-%u\n",
  655. + &rtp_exp->tuple.src.u3.ip,
  656. + ntohs(rtp_exp->tuple.src.u.udp.port),
  657. + ntohs(rtcp_exp->tuple.src.u.udp.port),
  658. + &rtp_exp->tuple.dst.u3.ip,
  659. + ntohs(rtp_exp->tuple.dst.u.udp.port),
  660. + ntohs(rtcp_exp->tuple.dst.u.udp.port));
  661. + } else {
  662. + pr_debug("expect_related %pI4:%u-%pI4:%u\n",
  663. + &rtp_exp->tuple.src.u3.ip,
  664. + ntohs(rtp_exp->tuple.src.u.udp.port),
  665. + &rtp_exp->tuple.dst.u3.ip,
  666. + ntohs(rtp_exp->tuple.dst.u.udp.port));
  667. + }
  668. +
  669. + nf_nat_rtsp = rcu_dereference(nf_nat_rtsp_hook);
  670. + if (nf_nat_rtsp && ct->status & IPS_NAT_MASK)
  671. + /* pass the request off to the nat helper */
  672. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
  673. + ret = nf_nat_rtsp(skb, ctinfo, protoff, hdrsoff, hdrslen,
  674. + &expinfo, rtp_exp, rtcp_exp);
  675. +#else
  676. + ret = nf_nat_rtsp(skb, ctinfo, hdrsoff, hdrslen,
  677. + &expinfo, rtp_exp, rtcp_exp);
  678. +#endif
  679. + else {
  680. + if (nf_ct_expect_related(rtp_exp) == 0) {
  681. + if (rtcp_exp && nf_ct_expect_related(rtcp_exp) != 0) {
  682. + nf_ct_unexpect_related(rtp_exp);
  683. + pr_info("nf_conntrack_expect_related failed for rtcp\n");
  684. + ret = NF_DROP;
  685. + }
  686. + } else {
  687. + pr_info("nf_conntrack_expect_related failed for rtp\n");
  688. + ret = NF_DROP;
  689. + }
  690. + }
  691. + if (rtcp_exp) {
  692. + nf_ct_expect_put(rtcp_exp);
  693. + }
  694. +out1:
  695. + nf_ct_expect_put(rtp_exp);
  696. + goto out;
  697. + }
  698. +out:
  699. +
  700. + return ret;
  701. +}
  702. +
  703. +
  704. +static inline int
  705. +help_in(struct sk_buff *skb, unsigned char *rb_ptr, unsigned int datalen,
  706. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
  707. + struct nf_conn *ct, enum ip_conntrack_info ctinfo,
  708. + unsigned int protoff)
  709. +#else
  710. + struct nf_conn *ct, enum ip_conntrack_info ctinfo)
  711. +#endif
  712. + {
  713. + struct ip_ct_rtsp_expect expinfo;
  714. + union nf_inet_addr srvaddr;
  715. + int dir = CTINFO2DIR(ctinfo); /* = IP_CT_DIR_ORIGINAL */
  716. + int len;
  717. + char* pdata = rb_ptr;
  718. + uint dataoff = 0;
  719. + int ret = NF_ACCEPT;
  720. + u_int8_t family;
  721. + struct nf_conntrack_expect *exp_ct = NULL;
  722. + struct nf_conntrack_tuple t;
  723. + struct net *net = nf_ct_net(ct);
  724. +
  725. + memset(&expinfo, 0, sizeof(expinfo));
  726. +
  727. + while (dataoff < datalen) {
  728. + uint cmdoff = dataoff;
  729. + uint hdrsoff = 0;
  730. + uint hdrslen = 0;
  731. + uint cseqoff = 0;
  732. + uint cseqlen = 0;
  733. + uint transoff = 0;
  734. + uint translen = 0;
  735. +
  736. + if (!rtsp_parse_message(pdata, datalen, &dataoff,
  737. + &hdrsoff, &hdrslen,
  738. + &cseqoff, &cseqlen,
  739. + &transoff, &translen))
  740. + break; /* not a valid message */
  741. +
  742. + if (strncmp(pdata+cmdoff, "RTSP/", 5) == 0 && translen) {
  743. + union nf_inet_addr zeroaddr;
  744. +
  745. + memset(&zeroaddr, 0, sizeof(zeroaddr));
  746. +
  747. + if (!rtsp_parse_transport(pdata+transoff, translen, &expinfo))
  748. + continue;
  749. +
  750. + srvaddr = expinfo.srvaddr;
  751. +
  752. + if (nf_inet_addr_cmp(&srvaddr, &ct->tuplehash[dir].tuple.src.u3) ||
  753. + nf_inet_addr_cmp(&srvaddr, &zeroaddr))
  754. + continue;
  755. + } else
  756. + continue; /* not valid RTSP reply */
  757. +
  758. + if (expinfo.loport == 0) {
  759. + pr_debug("no udp transports found\n");
  760. + continue; /* no udp transports found */
  761. + }
  762. +
  763. + family = nf_ct_l3num(ct);
  764. + if (family == AF_INET)
  765. + len = 4;
  766. + else
  767. + len = 16;
  768. +
  769. + /* replace rtp expect src addr */
  770. + t.src.l3num = family;
  771. + t.dst.protonum = IPPROTO_UDP;
  772. +
  773. + memcpy(&t.src.u3, &ct->tuplehash[dir].tuple.src.u3, len);
  774. + if (sizeof(t.src.u3) > len)
  775. + /* address needs to be cleared for nf_ct_tuple_equal */
  776. + memset((void *)&t.src.u3 + len, 0, sizeof(t.src.u3) - len);
  777. +
  778. + t.src.u.all = 0;
  779. +
  780. + memcpy(&t.dst.u3, &ct->tuplehash[dir].tuple.dst.u3, len);
  781. + if (sizeof(t.dst.u3) > len)
  782. + /* address needs to be cleared for nf_ct_tuple_equal */
  783. + memset((void *)&t.dst.u3 + len, 0, sizeof(t.dst.u3) - len);
  784. +
  785. + t.dst.u.all = htons(expinfo.loport);
  786. +
  787. + /* get the rtp expect and replace the srcaddr with RTP server addr */
  788. + exp_ct = nf_ct_expect_find_get(net, nf_ct_zone(ct), &t);
  789. + if (exp_ct) {
  790. + memcpy(&exp_ct->tuple.src.u3, &srvaddr, len);
  791. + if (sizeof(exp_ct->tuple.src.u3) > len)
  792. + /* address needs to be cleared for nf_ct_tuple_equal */
  793. + memset((void *)&exp_ct->tuple.src.u3 + len, 0,
  794. + sizeof(exp_ct->tuple.src.u3) - len);
  795. + } else
  796. + goto out;
  797. +
  798. + /* replace rtcp expect src addr */
  799. + if (expinfo.pbtype == pb_range) {
  800. + t.dst.u.all = htons(expinfo.hiport);
  801. +
  802. + /* get the rtcp expect and replace the srcaddr with RTP server addr */
  803. + exp_ct = nf_ct_expect_find_get(net, nf_ct_zone(ct), &t);
  804. + if (exp_ct) {
  805. + memcpy(&exp_ct->tuple.src.u3, &srvaddr, len);
  806. + if (sizeof(exp_ct->tuple.src.u3) > len)
  807. + /* address needs to be cleared for nf_ct_tuple_equal */
  808. + memset((void *)&exp_ct->tuple.src.u3 + len, 0,
  809. + sizeof(exp_ct->tuple.src.u3) - len);
  810. + } else
  811. + goto out;
  812. + }
  813. +
  814. + goto out;
  815. + }
  816. +out:
  817. + return ret;
  818. + }
  819. +
  820. +static int help(struct sk_buff *skb, unsigned int protoff,
  821. + struct nf_conn *ct, enum ip_conntrack_info ctinfo)
  822. +{
  823. + struct tcphdr _tcph, *th;
  824. + unsigned int dataoff, datalen;
  825. + char *rb_ptr;
  826. + int ret = NF_DROP;
  827. +
  828. + /* Until there's been traffic both ways, don't look in packets. */
  829. + if (ctinfo != IP_CT_ESTABLISHED &&
  830. + ctinfo != IP_CT_ESTABLISHED + IP_CT_IS_REPLY) {
  831. + pr_debug("conntrackinfo = %u\n", ctinfo);
  832. + return NF_ACCEPT;
  833. + }
  834. +
  835. + /* Not whole TCP header? */
  836. + th = skb_header_pointer(skb, protoff, sizeof(_tcph), &_tcph);
  837. +
  838. + if (!th)
  839. + return NF_ACCEPT;
  840. +
  841. + /* No data ? */
  842. + dataoff = protoff + th->doff*4;
  843. + datalen = skb->len - dataoff;
  844. + if (dataoff >= skb->len)
  845. + return NF_ACCEPT;
  846. +
  847. + spin_lock_bh(&rtsp_buffer_lock);
  848. + rb_ptr = skb_header_pointer(skb, dataoff,
  849. + skb->len - dataoff, rtsp_buffer);
  850. + BUG_ON(rb_ptr == NULL);
  851. +
  852. +#if 0
  853. + /* Checksum invalid? Ignore. */
  854. + /* FIXME: Source route IP option packets --RR */
  855. + if (tcp_v4_check(tcph, tcplen, iph->saddr, iph->daddr,
  856. + csum_partial((char*)tcph, tcplen, 0)))
  857. + {
  858. + DEBUGP("bad csum: %p %u %u.%u.%u.%u %u.%u.%u.%u\n",
  859. + tcph, tcplen, NIPQUAD(iph->saddr), NIPQUAD(iph->daddr));
  860. + return NF_ACCEPT;
  861. + }
  862. +#endif
  863. +
  864. + switch (CTINFO2DIR(ctinfo)) {
  865. + case IP_CT_DIR_ORIGINAL:
  866. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
  867. + ret = help_out(skb, rb_ptr, datalen, ct, ctinfo, protoff);
  868. +#else
  869. + ret = help_out(skb, rb_ptr, datalen, ct, ctinfo);
  870. +#endif
  871. + break;
  872. + case IP_CT_DIR_REPLY:
  873. + pr_debug("IP_CT_DIR_REPLY\n");
  874. + /* inbound packet: server->client */
  875. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
  876. + ret = help_in(skb, rb_ptr, datalen, ct, ctinfo, protoff);
  877. +#else
  878. + ret = help_in(skb, rb_ptr, datalen, ct, ctinfo);
  879. +#endif
  880. + break;
  881. + }
  882. +
  883. + spin_unlock_bh(&rtsp_buffer_lock);
  884. +
  885. + return ret;
  886. +}
  887. +
  888. +static struct nf_conntrack_helper rtsp_helpers[MAX_PORTS];
  889. +static char rtsp_names[MAX_PORTS][10];
  890. +
  891. +/* This function is intentionally _NOT_ defined as __exit */
  892. +static void
  893. +fini(void)
  894. +{
  895. + int i;
  896. + for (i = 0; i < num_ports; i++) {
  897. + pr_debug("unregistering port %d\n", ports[i]);
  898. + nf_conntrack_helper_unregister(&rtsp_helpers[i]);
  899. + }
  900. + kfree(rtsp_buffer);
  901. +}
  902. +
  903. +static int __init
  904. +init(void)
  905. +{
  906. + int i, ret;
  907. + struct nf_conntrack_helper *hlpr;
  908. + char *tmpname;
  909. +
  910. + printk("nf_conntrack_rtsp v" IP_NF_RTSP_VERSION " loading\n");
  911. +
  912. + if (max_outstanding < 1) {
  913. + printk("nf_conntrack_rtsp: max_outstanding must be a positive integer\n");
  914. + return -EBUSY;
  915. + }
  916. + if (setup_timeout < 0) {
  917. + printk("nf_conntrack_rtsp: setup_timeout must be a positive integer\n");
  918. + return -EBUSY;
  919. + }
  920. +
  921. + rtsp_exp_policy.max_expected = max_outstanding;
  922. + rtsp_exp_policy.timeout = setup_timeout;
  923. +
  924. + rtsp_buffer = kmalloc(65536, GFP_KERNEL);
  925. + if (!rtsp_buffer)
  926. + return -ENOMEM;
  927. +
  928. + /* If no port given, default to standard rtsp port */
  929. + if (ports[0] == 0) {
  930. + ports[0] = RTSP_PORT;
  931. + num_ports = 1;
  932. + }
  933. +
  934. + for (i = 0; (i < MAX_PORTS) && ports[i]; i++) {
  935. + hlpr = &rtsp_helpers[i];
  936. + memset(hlpr, 0, sizeof(struct nf_conntrack_helper));
  937. + hlpr->tuple.src.l3num = AF_INET;
  938. + hlpr->tuple.src.u.tcp.port = htons(ports[i]);
  939. + hlpr->tuple.dst.protonum = IPPROTO_TCP;
  940. + hlpr->expect_policy = &rtsp_exp_policy;
  941. + hlpr->me = THIS_MODULE;
  942. + hlpr->help = help;
  943. +
  944. + tmpname = &rtsp_names[i][0];
  945. + if (ports[i] == RTSP_PORT) {
  946. + sprintf(tmpname, "rtsp");
  947. + } else {
  948. + sprintf(tmpname, "rtsp-%d", i);
  949. + }
  950. +
  951. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0)
  952. + strlcpy(hlpr->name, tmpname, sizeof(hlpr->name));
  953. +#else
  954. + hlpr->name = tmpname;
  955. +#endif
  956. + pr_debug("port #%d: %d\n", i, ports[i]);
  957. +
  958. + ret = nf_conntrack_helper_register(hlpr);
  959. +
  960. + if (ret) {
  961. + printk("nf_conntrack_rtsp: ERROR registering port %d\n", ports[i]);
  962. + fini();
  963. + return -EBUSY;
  964. + }
  965. + }
  966. + return 0;
  967. +}
  968. +
  969. +module_init(init);
  970. +module_exit(fini);
  971. --- /dev/null
  972. +++ b/extensions/rtsp/nf_conntrack_rtsp.h
  973. @@ -0,0 +1,73 @@
  974. +/*
  975. + * RTSP extension for IP connection tracking.
  976. + * (C) 2003 by Tom Marshall <tmarshall at real.com>
  977. + * based on ip_conntrack_irc.h
  978. + *
  979. + * This program is free software; you can redistribute it and/or
  980. + * modify it under the terms of the GNU General Public License
  981. + * as published by the Free Software Foundation; either version
  982. + * 2 of the License, or (at your option) any later version.
  983. + *
  984. + * 2013-03-04: Il'inykh Sergey <sergeyi at inango-sw.com>. Inango Systems Ltd
  985. + * - conditional compilation for kernel 3.7
  986. + * - port mapping improvements
  987. +*/
  988. +#ifndef _IP_CONNTRACK_RTSP_H
  989. +#define _IP_CONNTRACK_RTSP_H
  990. +
  991. +#include <linux/version.h>
  992. +
  993. +//#define IP_NF_RTSP_DEBUG 1
  994. +#define IP_NF_RTSP_VERSION "0.7"
  995. +
  996. +#ifdef __KERNEL__
  997. +/* port block types */
  998. +typedef enum {
  999. + pb_single, /* client_port=x */
  1000. + pb_range, /* client_port=x-y */
  1001. + pb_discon /* client_port=x/y (rtspbis) */
  1002. +} portblock_t;
  1003. +
  1004. +/* We record seq number and length of rtsp headers here, all in host order. */
  1005. +
  1006. +/*
  1007. + * This structure is per expected connection. It is a member of struct
  1008. + * ip_conntrack_expect. The TCP SEQ for the conntrack expect is stored
  1009. + * there and we are expected to only store the length of the data which
  1010. + * needs replaced. If a packet contains multiple RTSP messages, we create
  1011. + * one expected connection per message.
  1012. + *
  1013. + * We use these variables to mark the entire header block. This may seem
  1014. + * like overkill, but the nature of RTSP requires it. A header may appear
  1015. + * multiple times in a message. We must treat two Transport headers the
  1016. + * same as one Transport header with two entries.
  1017. + */
  1018. +struct ip_ct_rtsp_expect
  1019. +{
  1020. + u_int32_t len; /* length of header block */
  1021. + portblock_t pbtype; /* Type of port block that was requested */
  1022. + u_int16_t loport; /* Port that was requested, low or first */
  1023. + u_int16_t hiport; /* Port that was requested, high or second */
  1024. + union nf_inet_addr srvaddr; /* src address in SETUP reply */
  1025. +#if 0
  1026. + uint method; /* RTSP method */
  1027. + uint cseq; /* CSeq from request */
  1028. +#endif
  1029. +};
  1030. +
  1031. +extern unsigned int (*nf_nat_rtsp_hook)(struct sk_buff *skb,
  1032. + enum ip_conntrack_info ctinfo,
  1033. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
  1034. + unsigned int protoff,
  1035. +#endif
  1036. + unsigned int matchoff,
  1037. + unsigned int matchlen,
  1038. + struct ip_ct_rtsp_expect *prtspexp,
  1039. + struct nf_conntrack_expect *rtp_exp,
  1040. + struct nf_conntrack_expect *rtcp_exp);
  1041. +
  1042. +#define RTSP_PORT 554
  1043. +
  1044. +#endif /* __KERNEL__ */
  1045. +
  1046. +#endif /* _IP_CONNTRACK_RTSP_H */
  1047. --- /dev/null
  1048. +++ b/extensions/rtsp/nf_nat_rtsp.c
  1049. @@ -0,0 +1,617 @@
  1050. +/*
  1051. + * RTSP extension for TCP NAT alteration
  1052. + * (C) 2003 by Tom Marshall <tmarshall at real.com>
  1053. + *
  1054. + * 2013-03-04: Il'inykh Sergey <sergeyi at inango-sw.com>. Inango Systems Ltd
  1055. + * - fixed rtcp nat mapping and other port mapping fixes
  1056. + * - fixed system hard lock because of bug in the parser
  1057. + * - codestyle fixes and less significant fixes
  1058. + *
  1059. + * based on ip_nat_irc.c
  1060. + *
  1061. + * This program is free software; you can redistribute it and/or
  1062. + * modify it under the terms of the GNU General Public License
  1063. + * as published by the Free Software Foundation; either version
  1064. + * 2 of the License, or (at your option) any later version.
  1065. + *
  1066. + * Module load syntax:
  1067. + * insmod nf_nat_rtsp.o ports=port1,port2,...port<MAX_PORTS>
  1068. + * stunaddr=<address>
  1069. + * destaction=[auto|strip|none]
  1070. + *
  1071. + * If no ports are specified, the default will be port 554 only.
  1072. + *
  1073. + * stunaddr specifies the address used to detect that a client is using STUN.
  1074. + * If this address is seen in the destination parameter, it is assumed that
  1075. + * the client has already punched a UDP hole in the firewall, so we don't
  1076. + * mangle the client_port. If none is specified, it is autodetected. It
  1077. + * only needs to be set if you have multiple levels of NAT. It should be
  1078. + * set to the external address that the STUN clients detect. Note that in
  1079. + * this case, it will not be possible for clients to use UDP with servers
  1080. + * between the NATs.
  1081. + *
  1082. + * If no destaction is specified, auto is used.
  1083. + * destaction=auto: strip destination parameter if it is not stunaddr.
  1084. + * destaction=strip: always strip destination parameter (not recommended).
  1085. + * destaction=none: do not touch destination parameter (not recommended).
  1086. + */
  1087. +
  1088. +#include <linux/module.h>
  1089. +#include <linux/version.h>
  1090. +#include <net/tcp.h>
  1091. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
  1092. +# include <net/netfilter/nf_nat.h>
  1093. +#else
  1094. +# include <net/netfilter/nf_nat_rule.h>
  1095. +#endif
  1096. +#include <net/netfilter/nf_nat_helper.h>
  1097. +#include "nf_conntrack_rtsp.h"
  1098. +#include <net/netfilter/nf_conntrack_expect.h>
  1099. +
  1100. +#include <linux/inet.h>
  1101. +#include <linux/ctype.h>
  1102. +#define NF_NEED_STRNCASECMP
  1103. +#define NF_NEED_STRTOU16
  1104. +#include "netfilter_helpers.h"
  1105. +#define NF_NEED_MIME_NEXTLINE
  1106. +#include "netfilter_mime.h"
  1107. +
  1108. +#define MAX_PORTS 8
  1109. +#define DSTACT_AUTO 0
  1110. +#define DSTACT_STRIP 1
  1111. +#define DSTACT_NONE 2
  1112. +
  1113. +static char* stunaddr = NULL;
  1114. +static char* destaction = NULL;
  1115. +
  1116. +static u_int32_t extip = 0;
  1117. +static int dstact = 0;
  1118. +
  1119. +static void nf_nat_rtsp_expected(struct nf_conn* ct, struct nf_conntrack_expect *exp);
  1120. +
  1121. +MODULE_AUTHOR("Tom Marshall <tmarshall at real.com>");
  1122. +MODULE_DESCRIPTION("RTSP network address translation module");
  1123. +MODULE_LICENSE("GPL");
  1124. +module_param(stunaddr, charp, 0644);
  1125. +MODULE_PARM_DESC(stunaddr, "Address for detecting STUN");
  1126. +module_param(destaction, charp, 0644);
  1127. +MODULE_PARM_DESC(destaction, "Action for destination parameter (auto/strip/none)");
  1128. +
  1129. +#define SKIP_WSPACE(ptr,len,off) while(off < len && isspace(*(ptr+off))) { off++; }
  1130. +
  1131. +/*** helper functions ***/
  1132. +
  1133. +static void
  1134. +get_skb_tcpdata(struct sk_buff* skb, char** pptcpdata, uint* ptcpdatalen)
  1135. +{
  1136. + struct iphdr* iph = ip_hdr(skb);
  1137. + struct tcphdr* tcph = (void *)iph + ip_hdrlen(skb);
  1138. +
  1139. + *pptcpdata = (char*)tcph + tcph->doff*4;
  1140. + *ptcpdatalen = ((char*)skb_transport_header(skb) + skb->len) - *pptcpdata;
  1141. +}
  1142. +
  1143. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
  1144. +/* copy of sip_sprintf_addr */
  1145. +static int rtsp_sprintf_addr(const struct nf_conn *ct, char *buffer,
  1146. + const union nf_inet_addr *addr, bool delim)
  1147. +{
  1148. + if (nf_ct_l3num(ct) == NFPROTO_IPV4) {
  1149. + return sprintf(buffer, "%pI4", &addr->ip);
  1150. + } else {
  1151. + if (delim)
  1152. + return sprintf(buffer, "[%pI6c]", &addr->ip6);
  1153. + else
  1154. + return sprintf(buffer, "%pI6c", &addr->ip6);
  1155. + }
  1156. +}
  1157. +#endif
  1158. +
  1159. +/*** nat functions ***/
  1160. +
  1161. +/*
  1162. + * Mangle the "Transport:" header:
  1163. + * - Replace all occurences of "client_port=<spec>"
  1164. + * - Handle destination parameter
  1165. + *
  1166. + * In:
  1167. + * ct, ctinfo = conntrack context
  1168. + * skb = packet
  1169. + * tranoff = Transport header offset from TCP data
  1170. + * tranlen = Transport header length (incl. CRLF)
  1171. + * rport_lo = replacement low port (host endian)
  1172. + * rport_hi = replacement high port (host endian)
  1173. + *
  1174. + * Returns packet size difference.
  1175. + *
  1176. + * Assumes that a complete transport header is present, ending with CR or LF
  1177. + */
  1178. +static int
  1179. +rtsp_mangle_tran(enum ip_conntrack_info ctinfo,
  1180. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
  1181. + unsigned int protoff,
  1182. +#endif
  1183. + struct nf_conntrack_expect* rtp_exp,
  1184. + struct nf_conntrack_expect* rtcp_exp,
  1185. + struct ip_ct_rtsp_expect* prtspexp,
  1186. + struct sk_buff* skb, uint tranoff, uint tranlen)
  1187. +{
  1188. + char* ptcp;
  1189. + uint tcplen;
  1190. + char* ptran;
  1191. + char rbuf1[16]; /* Replacement buffer (one port) */
  1192. + uint rbuf1len; /* Replacement len (one port) */
  1193. + char rbufa[16]; /* Replacement buffer (all ports) */
  1194. + uint rbufalen; /* Replacement len (all ports) */
  1195. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
  1196. + union nf_inet_addr newip;
  1197. +#else
  1198. + u_int32_t newip;
  1199. +#endif
  1200. + u_int16_t loport, hiport;
  1201. + uint off = 0;
  1202. + uint diff; /* Number of bytes we removed */
  1203. +
  1204. + struct nf_conn *ct = rtp_exp->master;
  1205. + /* struct nf_conn *ct = nf_ct_get(skb, &ctinfo); */
  1206. + struct nf_conntrack_tuple *rtp_t;
  1207. +
  1208. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
  1209. + char szextaddr[INET6_ADDRSTRLEN];
  1210. +#else
  1211. + char szextaddr[INET_ADDRSTRLEN];
  1212. +#endif
  1213. + uint extaddrlen;
  1214. + int is_stun;
  1215. +
  1216. + get_skb_tcpdata(skb, &ptcp, &tcplen);
  1217. + ptran = ptcp+tranoff;
  1218. +
  1219. + if (tranoff+tranlen > tcplen || tcplen-tranoff < tranlen ||
  1220. + tranlen < 10 || !iseol(ptran[tranlen-1]) ||
  1221. + nf_strncasecmp(ptran, "Transport:", 10) != 0) {
  1222. + pr_info("sanity check failed\n");
  1223. + return 0;
  1224. + }
  1225. + off += 10;
  1226. + SKIP_WSPACE(ptcp+tranoff, tranlen, off);
  1227. +
  1228. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
  1229. + newip = ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.u3;
  1230. + rtp_t = &rtp_exp->tuple;
  1231. + rtp_t->dst.u3 = newip;
  1232. + if (rtcp_exp) {
  1233. + rtcp_exp->tuple.dst.u3 = newip;
  1234. + }
  1235. + extaddrlen = rtsp_sprintf_addr(ct, szextaddr, &newip, true); // FIXME handle extip
  1236. + pr_debug("stunaddr=%s (auto)\n", szextaddr);
  1237. +#else
  1238. + newip = ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.u3.ip;
  1239. + rtp_t = &rtp_exp->tuple;
  1240. + rtp_t->dst.u3.ip = newip;
  1241. + if (rtcp_exp) {
  1242. + rtcp_exp->tuple.dst.u3.ip = newip;
  1243. + }
  1244. + extaddrlen = extip ? sprintf(szextaddr, "%pI4", &extip)
  1245. + : sprintf(szextaddr, "%pI4", &newip);
  1246. + pr_debug("stunaddr=%s (%s)\n", szextaddr, (extip?"forced":"auto"));
  1247. +#endif
  1248. + hiport = 0;
  1249. + rbuf1len = rbufalen = 0;
  1250. + switch (prtspexp->pbtype) {
  1251. + case pb_single:
  1252. + for (loport = prtspexp->loport; loport != 0; loport++) { /* XXX: improper wrap? */
  1253. + rtp_t->dst.u.udp.port = htons(loport);
  1254. + if (nf_ct_expect_related(rtp_exp) == 0) {
  1255. + pr_debug("using port %hu\n", loport);
  1256. + break;
  1257. + }
  1258. + }
  1259. + if (loport != 0) {
  1260. + rbuf1len = sprintf(rbuf1, "%hu", loport);
  1261. + rbufalen = sprintf(rbufa, "%hu", loport);
  1262. + }
  1263. + break;
  1264. + case pb_range:
  1265. + for (loport = prtspexp->loport; loport != 0; loport += 2) { /* XXX: improper wrap? */
  1266. + rtp_t->dst.u.udp.port = htons(loport);
  1267. + if (nf_ct_expect_related(rtp_exp) != 0) {
  1268. + continue;
  1269. + }
  1270. + hiport = loport + 1;
  1271. + rtcp_exp->tuple.dst.u.udp.port = htons(hiport);
  1272. + if (nf_ct_expect_related(rtcp_exp) != 0) {
  1273. + nf_ct_unexpect_related(rtp_exp);
  1274. + continue;
  1275. + }
  1276. +
  1277. + /* FIXME: invalid print in case of ipv6 */
  1278. + pr_debug("nat expect_related %pI4:%u-%u-%pI4:%u-%u\n",
  1279. + &rtp_exp->tuple.src.u3.ip,
  1280. + ntohs(rtp_exp->tuple.src.u.udp.port),
  1281. + ntohs(rtcp_exp->tuple.src.u.udp.port),
  1282. + &rtp_exp->tuple.dst.u3.ip,
  1283. + ntohs(rtp_exp->tuple.dst.u.udp.port),
  1284. + ntohs(rtcp_exp->tuple.dst.u.udp.port));
  1285. + break;
  1286. + }
  1287. + if (loport != 0) {
  1288. + rbuf1len = sprintf(rbuf1, "%hu", loport);
  1289. + rbufalen = sprintf(rbufa, "%hu-%hu", loport, hiport);
  1290. + }
  1291. + break;
  1292. + case pb_discon:
  1293. + for (loport = prtspexp->loport; loport != 0; loport++) { /* XXX: improper wrap? */
  1294. + rtp_t->dst.u.udp.port = htons(loport);
  1295. + if (nf_ct_expect_related(rtp_exp) == 0) {
  1296. + pr_debug("using port %hu (1 of 2)\n", loport);
  1297. + break;
  1298. + }
  1299. + }
  1300. + for (hiport = prtspexp->hiport; hiport != 0; hiport++) { /* XXX: improper wrap? */
  1301. + rtp_t->dst.u.udp.port = htons(hiport);
  1302. + if (nf_ct_expect_related(rtp_exp) == 0) {
  1303. + pr_debug("using port %hu (2 of 2)\n", hiport);
  1304. + break;
  1305. + }
  1306. + }
  1307. + if (loport != 0 && hiport != 0) {
  1308. + rbuf1len = sprintf(rbuf1, "%hu", loport);
  1309. + rbufalen = sprintf(rbufa, hiport == loport+1 ?
  1310. + "%hu-%hu":"%hu/%hu", loport, hiport);
  1311. + }
  1312. + break;
  1313. + }
  1314. +
  1315. + if (rbuf1len == 0)
  1316. + return 0; /* cannot get replacement port(s) */
  1317. +
  1318. + /* Transport: tran;field;field=val,tran;field;field=val,...
  1319. + `off` is set to the start of Transport value from start of line
  1320. + */
  1321. + while (off < tranlen) {
  1322. + uint saveoff;
  1323. + const char* pparamend;
  1324. + uint nextparamoff;
  1325. +
  1326. + pparamend = memchr(ptran+off, ',', tranlen-off);
  1327. + pparamend = (pparamend == NULL) ? ptran+tranlen : pparamend+1;
  1328. + nextparamoff = pparamend-ptran;
  1329. +
  1330. + /*
  1331. + * We pass over each param twice. On the first pass, we look for a
  1332. + * destination= field. It is handled by the security policy. If it
  1333. + * is present, allowed, and equal to our external address, we assume
  1334. + * that STUN is being used and we leave the client_port= field alone.
  1335. + */
  1336. + is_stun = 0;
  1337. + saveoff = off;
  1338. + while (off < nextparamoff) {
  1339. + const char* pfieldend;
  1340. + uint nextfieldoff;
  1341. +
  1342. + pfieldend = memchr(ptran+off, ';', nextparamoff-off);
  1343. + nextfieldoff = (pfieldend == NULL) ? nextparamoff : pfieldend-ptran+1;
  1344. +
  1345. + if (dstact != DSTACT_NONE && strncmp(ptran+off, "destination=", 12) == 0) {
  1346. + if (strncmp(ptran+off+12, szextaddr, extaddrlen) == 0)
  1347. + is_stun = 1;
  1348. +
  1349. + if (dstact == DSTACT_STRIP || (dstact == DSTACT_AUTO && !is_stun)) {
  1350. + uint dstoff = (ptran-ptcp)+off;
  1351. + uint dstlen = nextfieldoff-off;
  1352. + char* pdstrep = NULL;
  1353. + uint dstreplen = 0;
  1354. + diff = dstlen;
  1355. + if (dstact == DSTACT_AUTO && !is_stun) {
  1356. + pr_debug("RTSP: replace dst addr\n");
  1357. + dstoff += 12;
  1358. + dstlen -= 13;
  1359. + pdstrep = szextaddr;
  1360. + dstreplen = extaddrlen;
  1361. + diff = nextfieldoff-off-13-extaddrlen;
  1362. + }
  1363. +
  1364. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
  1365. + if (!nf_nat_mangle_tcp_packet(skb, ct, ctinfo, protoff,
  1366. + dstoff, dstlen, pdstrep, dstreplen)) {
  1367. +#else
  1368. + if (!nf_nat_mangle_tcp_packet(skb, ct, ctinfo,
  1369. + dstoff, dstlen, pdstrep, dstreplen)) {
  1370. +#endif
  1371. + /* mangle failed, all we can do is bail */
  1372. + nf_ct_unexpect_related(rtp_exp);
  1373. + if (rtcp_exp)
  1374. + nf_ct_unexpect_related(rtcp_exp);
  1375. + return 0;
  1376. + }
  1377. + get_skb_tcpdata(skb, &ptcp, &tcplen);
  1378. + ptran = ptcp+tranoff;
  1379. + tranlen -= diff;
  1380. + nextparamoff -= diff;
  1381. + nextfieldoff -= diff;
  1382. + }
  1383. + }
  1384. +
  1385. + off = nextfieldoff;
  1386. + }
  1387. +
  1388. + if (is_stun)
  1389. + continue;
  1390. +
  1391. + off = saveoff;
  1392. + while (off < nextparamoff) {
  1393. + const char* pfieldend;
  1394. + uint nextfieldoff;
  1395. +
  1396. + pfieldend = memchr(ptran+off, ';', nextparamoff-off);
  1397. + nextfieldoff = (pfieldend == NULL) ? nextparamoff : pfieldend-ptran+1;
  1398. +
  1399. + if (strncmp(ptran+off, "client_port=", 12) == 0) {
  1400. + u_int16_t port;
  1401. + uint numlen;
  1402. + uint origoff;
  1403. + uint origlen;
  1404. + char* rbuf = rbuf1;
  1405. + uint rbuflen = rbuf1len;
  1406. +
  1407. + off += 12;
  1408. + origoff = (ptran-ptcp)+off;
  1409. + origlen = 0;
  1410. + numlen = nf_strtou16(ptran+off, &port);
  1411. + off += numlen;
  1412. + origlen += numlen;
  1413. + if (port != prtspexp->loport) {
  1414. + pr_debug("multiple ports found, port %hu ignored\n", port);
  1415. + } else {
  1416. + if (ptran[off] == '-' || ptran[off] == '/') {
  1417. + off++;
  1418. + origlen++;
  1419. + numlen = nf_strtou16(ptran+off, &port);
  1420. + off += numlen;
  1421. + origlen += numlen;
  1422. + rbuf = rbufa;
  1423. + rbuflen = rbufalen;
  1424. + }
  1425. +
  1426. + /*
  1427. + * note we cannot just memcpy() if the sizes are the same.
  1428. + * the mangle function does skb resizing, checks for a
  1429. + * cloned skb, and updates the checksums.
  1430. + *
  1431. + * parameter 4 below is offset from start of tcp data.
  1432. + */
  1433. + diff = origlen-rbuflen;
  1434. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
  1435. + if (!nf_nat_mangle_tcp_packet(skb, ct, ctinfo, protoff,
  1436. + origoff, origlen, rbuf, rbuflen)) {
  1437. +#else
  1438. + if (!nf_nat_mangle_tcp_packet(skb, ct, ctinfo,
  1439. + origoff, origlen, rbuf, rbuflen)) {
  1440. +#endif
  1441. + /* mangle failed, all we can do is bail */
  1442. + nf_ct_unexpect_related(rtp_exp);
  1443. + if (rtcp_exp)
  1444. + nf_ct_unexpect_related(rtcp_exp);
  1445. + return 0;
  1446. + }
  1447. + get_skb_tcpdata(skb, &ptcp, &tcplen);
  1448. + ptran = ptcp+tranoff;
  1449. + tranlen -= diff;
  1450. + nextparamoff -= diff;
  1451. + nextfieldoff -= diff;
  1452. + }
  1453. + }
  1454. +
  1455. + off = nextfieldoff;
  1456. + }
  1457. +
  1458. + off = nextparamoff;
  1459. + }
  1460. +
  1461. + return 1;
  1462. +}
  1463. +
  1464. +static uint
  1465. +help_out(struct sk_buff *skb, enum ip_conntrack_info ctinfo,
  1466. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
  1467. + unsigned int protoff,
  1468. +#endif
  1469. + unsigned int matchoff, unsigned int matchlen,
  1470. + struct ip_ct_rtsp_expect* prtspexp,
  1471. + struct nf_conntrack_expect* rtp_exp,
  1472. + struct nf_conntrack_expect* rtcp_exp)
  1473. +{
  1474. + char* ptcp;
  1475. + uint tcplen;
  1476. + uint hdrsoff;
  1477. + uint hdrslen;
  1478. + uint lineoff;
  1479. + uint linelen;
  1480. + uint off;
  1481. + int dir = CTINFO2DIR(ctinfo);
  1482. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
  1483. + union nf_inet_addr saddr = rtp_exp->master->tuplehash[dir].tuple.src.u3;
  1484. +#else
  1485. + __be32 saddr = rtp_exp->master->tuplehash[dir].tuple.src.u3.ip;
  1486. +#endif
  1487. +
  1488. + //struct iphdr* iph = (struct iphdr*)(*pskb)->nh.iph;
  1489. + //struct tcphdr* tcph = (struct tcphdr*)((void*)iph + iph->ihl*4);
  1490. +
  1491. + get_skb_tcpdata(skb, &ptcp, &tcplen);
  1492. + hdrsoff = matchoff;//exp->seq - ntohl(tcph->seq);
  1493. + hdrslen = matchlen;
  1494. + off = hdrsoff;
  1495. + pr_debug("NAT rtsp help_out\n");
  1496. +
  1497. + while (nf_mime_nextline(ptcp, hdrsoff+hdrslen, &off, &lineoff, &linelen)) {
  1498. + if (linelen == 0)
  1499. + break;
  1500. +
  1501. + if (off > hdrsoff+hdrslen) {
  1502. + pr_info("!! overrun !!");
  1503. + break;
  1504. + }
  1505. + pr_debug("hdr: len=%u, %.*s", linelen, (int)linelen, ptcp+lineoff);
  1506. +
  1507. + if (nf_strncasecmp(ptcp+lineoff, "Transport:", 10) == 0) {
  1508. + uint oldtcplen = tcplen;
  1509. + pr_debug("hdr: Transport\n");
  1510. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
  1511. + if (!rtsp_mangle_tran(ctinfo, protoff, rtp_exp, rtcp_exp,
  1512. + prtspexp, skb, lineoff, linelen)) {
  1513. +#else
  1514. + if (!rtsp_mangle_tran(ctinfo, rtp_exp, rtcp_exp, prtspexp,
  1515. + skb, lineoff, linelen)) {
  1516. +#endif
  1517. + pr_debug("hdr: Transport mangle failed");
  1518. + break;
  1519. + }
  1520. + rtp_exp->expectfn = nf_nat_rtsp_expected;
  1521. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
  1522. + rtp_exp->saved_addr = saddr;
  1523. +#else
  1524. + rtp_exp->saved_ip = saddr;
  1525. +#endif
  1526. + rtp_exp->saved_proto.udp.port = htons(prtspexp->loport);
  1527. + rtp_exp->dir = !dir;
  1528. + if (rtcp_exp) {
  1529. + rtcp_exp->expectfn = nf_nat_rtsp_expected;
  1530. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
  1531. + rtcp_exp->saved_addr = saddr;
  1532. +#else
  1533. + rtcp_exp->saved_ip = saddr;
  1534. +#endif
  1535. + rtcp_exp->saved_proto.udp.port = htons(prtspexp->hiport);
  1536. + rtcp_exp->dir = !dir;
  1537. + }
  1538. + get_skb_tcpdata(skb, &ptcp, &tcplen);
  1539. + hdrslen -= (oldtcplen-tcplen);
  1540. + off -= (oldtcplen-tcplen);
  1541. + lineoff -= (oldtcplen-tcplen);
  1542. + linelen -= (oldtcplen-tcplen);
  1543. + pr_debug("rep: len=%u, %.*s", linelen, (int)linelen, ptcp+lineoff);
  1544. + }
  1545. + }
  1546. +
  1547. + return NF_ACCEPT;
  1548. +}
  1549. +
  1550. +static unsigned int
  1551. +nf_nat_rtsp(struct sk_buff *skb, enum ip_conntrack_info ctinfo,
  1552. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
  1553. + unsigned int protoff,
  1554. +#endif
  1555. + unsigned int matchoff, unsigned int matchlen,
  1556. + struct ip_ct_rtsp_expect* prtspexp,
  1557. + struct nf_conntrack_expect* rtp_exp,
  1558. + struct nf_conntrack_expect* rtcp_exp)
  1559. +{
  1560. + int dir = CTINFO2DIR(ctinfo);
  1561. + int rc = NF_ACCEPT;
  1562. +
  1563. + switch (dir) {
  1564. + case IP_CT_DIR_ORIGINAL:
  1565. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
  1566. + rc = help_out(skb, ctinfo, protoff, matchoff, matchlen, prtspexp,
  1567. + rtp_exp, rtcp_exp);
  1568. +#else
  1569. + rc = help_out(skb, ctinfo, matchoff, matchlen, prtspexp,
  1570. + rtp_exp, rtcp_exp);
  1571. +#endif
  1572. + break;
  1573. + case IP_CT_DIR_REPLY:
  1574. + pr_debug("unmangle ! %u\n", ctinfo);
  1575. + /* XXX: unmangle */
  1576. + rc = NF_ACCEPT;
  1577. + break;
  1578. + }
  1579. + //UNLOCK_BH(&ip_rtsp_lock);
  1580. +
  1581. + return rc;
  1582. +}
  1583. +
  1584. +static void nf_nat_rtsp_expected(struct nf_conn* ct, struct nf_conntrack_expect *exp)
  1585. +{
  1586. +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,3,0) || LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
  1587. + struct nf_nat_range range;
  1588. +#else
  1589. + struct nf_nat_ipv4_range range;
  1590. +#endif
  1591. +
  1592. + /* This must be a fresh one. */
  1593. + BUG_ON(ct->status & IPS_NAT_DONE_MASK);
  1594. +
  1595. + /* For DST manip, map port here to where it's expected. */
  1596. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
  1597. + range.min_proto = range.max_proto = exp->saved_proto;
  1598. + range.min_addr = range.max_addr = exp->saved_addr;
  1599. +#else
  1600. + range.min = range.max = exp->saved_proto;
  1601. + range.min_ip = range.max_ip = exp->saved_ip;
  1602. +#endif
  1603. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,3,0)
  1604. + range.flags = (NF_NAT_RANGE_MAP_IPS | NF_NAT_RANGE_PROTO_SPECIFIED);
  1605. + nf_nat_setup_info(ct, &range, NF_NAT_MANIP_DST);
  1606. +#else
  1607. + range.flags = (IP_NAT_RANGE_MAP_IPS | IP_NAT_RANGE_PROTO_SPECIFIED);
  1608. + nf_nat_setup_info(ct, &range, IP_NAT_MANIP_DST);
  1609. +#endif
  1610. +
  1611. + /* Change src to where master sends to, but only if the connection
  1612. + * actually came from the same source. */
  1613. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0)
  1614. + if (nf_inet_addr_cmp(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.u3,
  1615. + &ct->master->tuplehash[exp->dir].tuple.src.u3)) {
  1616. + range.min_addr = range.max_addr
  1617. + = ct->master->tuplehash[!exp->dir].tuple.dst.u3;
  1618. +#else
  1619. + if (ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.u3.ip ==
  1620. + ct->master->tuplehash[exp->dir].tuple.src.u3.ip) {
  1621. + range.min_ip = range.max_ip
  1622. + = ct->master->tuplehash[!exp->dir].tuple.dst.u3.ip;
  1623. +#endif
  1624. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,3,0)
  1625. + range.flags = NF_NAT_RANGE_MAP_IPS;
  1626. + nf_nat_setup_info(ct, &range, NF_NAT_MANIP_SRC);
  1627. +#else
  1628. + range.flags = IP_NAT_RANGE_MAP_IPS;
  1629. + nf_nat_setup_info(ct, &range, IP_NAT_MANIP_SRC);
  1630. +#endif
  1631. + }
  1632. +}
  1633. +
  1634. +
  1635. +static void __exit fini(void)
  1636. +{
  1637. + rcu_assign_pointer(nf_nat_rtsp_hook, NULL);
  1638. + synchronize_net();
  1639. +}
  1640. +
  1641. +static int __init init(void)
  1642. +{
  1643. + printk("nf_nat_rtsp v" IP_NF_RTSP_VERSION " loading\n");
  1644. +
  1645. + BUG_ON(nf_nat_rtsp_hook);
  1646. + rcu_assign_pointer(nf_nat_rtsp_hook, nf_nat_rtsp);
  1647. +
  1648. + if (stunaddr != NULL)
  1649. + extip = in_aton(stunaddr);
  1650. +
  1651. + if (destaction != NULL) {
  1652. + if (strcmp(destaction, "auto") == 0)
  1653. + dstact = DSTACT_AUTO;
  1654. +
  1655. + if (strcmp(destaction, "strip") == 0)
  1656. + dstact = DSTACT_STRIP;
  1657. +
  1658. + if (strcmp(destaction, "none") == 0)
  1659. + dstact = DSTACT_NONE;
  1660. + }
  1661. +
  1662. + return 0;
  1663. +}
  1664. +
  1665. +module_init(init);
  1666. +module_exit(fini);
  1667. --- a/extensions/Kbuild
  1668. +++ b/extensions/Kbuild
  1669. @@ -26,6 +26,7 @@ obj-${build_lscan} += xt_lscan.o
  1670. obj-${build_pknock} += pknock/
  1671. obj-${build_psd} += xt_psd.o
  1672. obj-${build_quota2} += xt_quota2.o
  1673. +obj-${build_rtsp} += rtsp/
  1674. -include ${M}/*.Kbuild
  1675. -include ${M}/Kbuild.*
  1676. --- a/mconfig
  1677. +++ b/mconfig
  1678. @@ -22,3 +22,4 @@ build_lscan=m
  1679. build_pknock=m
  1680. build_psd=m
  1681. build_quota2=m
  1682. +build_rtsp=m