rtsp.patch 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316
  1. diff -Nur linux-2.6.33.orig/include/linux/netfilter/nf_conntrack_rtsp.h linux-2.6.33/include/linux/netfilter/nf_conntrack_rtsp.h
  2. --- linux-2.6.33.orig/include/linux/netfilter/nf_conntrack_rtsp.h 1970-01-01 01:00:00.000000000 +0100
  3. +++ linux-2.6.33/include/linux/netfilter/nf_conntrack_rtsp.h 2010-04-25 01:09:20.000000000 +0200
  4. @@ -0,0 +1,63 @@
  5. +/*
  6. + * RTSP extension for IP connection tracking.
  7. + * (C) 2003 by Tom Marshall <tmarshall at real.com>
  8. + * based on ip_conntrack_irc.h
  9. + *
  10. + * This program is free software; you can redistribute it and/or
  11. + * modify it under the terms of the GNU General Public License
  12. + * as published by the Free Software Foundation; either version
  13. + * 2 of the License, or (at your option) any later version.
  14. + */
  15. +#ifndef _IP_CONNTRACK_RTSP_H
  16. +#define _IP_CONNTRACK_RTSP_H
  17. +
  18. +//#define IP_NF_RTSP_DEBUG 1
  19. +#define IP_NF_RTSP_VERSION "0.6.21"
  20. +
  21. +#ifdef __KERNEL__
  22. +/* port block types */
  23. +typedef enum {
  24. + pb_single, /* client_port=x */
  25. + pb_range, /* client_port=x-y */
  26. + pb_discon /* client_port=x/y (rtspbis) */
  27. +} portblock_t;
  28. +
  29. +/* We record seq number and length of rtsp headers here, all in host order. */
  30. +
  31. +/*
  32. + * This structure is per expected connection. It is a member of struct
  33. + * ip_conntrack_expect. The TCP SEQ for the conntrack expect is stored
  34. + * there and we are expected to only store the length of the data which
  35. + * needs replaced. If a packet contains multiple RTSP messages, we create
  36. + * one expected connection per message.
  37. + *
  38. + * We use these variables to mark the entire header block. This may seem
  39. + * like overkill, but the nature of RTSP requires it. A header may appear
  40. + * multiple times in a message. We must treat two Transport headers the
  41. + * same as one Transport header with two entries.
  42. + */
  43. +struct ip_ct_rtsp_expect
  44. +{
  45. + u_int32_t len; /* length of header block */
  46. + portblock_t pbtype; /* Type of port block that was requested */
  47. + u_int16_t loport; /* Port that was requested, low or first */
  48. + u_int16_t hiport; /* Port that was requested, high or second */
  49. +#if 0
  50. + uint method; /* RTSP method */
  51. + uint cseq; /* CSeq from request */
  52. +#endif
  53. +};
  54. +
  55. +extern unsigned int (*nf_nat_rtsp_hook)(struct sk_buff *skb,
  56. + enum ip_conntrack_info ctinfo,
  57. + unsigned int matchoff, unsigned int matchlen,
  58. + struct ip_ct_rtsp_expect *prtspexp,
  59. + struct nf_conntrack_expect *exp);
  60. +
  61. +extern void (*nf_nat_rtsp_hook_expectfn)(struct nf_conn *ct, struct nf_conntrack_expect *exp);
  62. +
  63. +#define RTSP_PORT 554
  64. +
  65. +#endif /* __KERNEL__ */
  66. +
  67. +#endif /* _IP_CONNTRACK_RTSP_H */
  68. diff -Nur linux-2.6.33.orig/include/linux/netfilter_helpers.h linux-2.6.33/include/linux/netfilter_helpers.h
  69. --- linux-2.6.33.orig/include/linux/netfilter_helpers.h 1970-01-01 01:00:00.000000000 +0100
  70. +++ linux-2.6.33/include/linux/netfilter_helpers.h 2010-04-25 01:09:20.000000000 +0200
  71. @@ -0,0 +1,133 @@
  72. +/*
  73. + * Helpers for netfiler modules. This file provides implementations for basic
  74. + * functions such as strncasecmp(), etc.
  75. + *
  76. + * gcc will warn for defined but unused functions, so we only include the
  77. + * functions requested. The following macros are used:
  78. + * NF_NEED_STRNCASECMP nf_strncasecmp()
  79. + * NF_NEED_STRTOU16 nf_strtou16()
  80. + * NF_NEED_STRTOU32 nf_strtou32()
  81. + */
  82. +#ifndef _NETFILTER_HELPERS_H
  83. +#define _NETFILTER_HELPERS_H
  84. +
  85. +/* Only include these functions for kernel code. */
  86. +#ifdef __KERNEL__
  87. +
  88. +#include <linux/ctype.h>
  89. +#define iseol(c) ( (c) == '\r' || (c) == '\n' )
  90. +
  91. +/*
  92. + * The standard strncasecmp()
  93. + */
  94. +#ifdef NF_NEED_STRNCASECMP
  95. +static int
  96. +nf_strncasecmp(const char* s1, const char* s2, u_int32_t len)
  97. +{
  98. + if (s1 == NULL || s2 == NULL)
  99. + {
  100. + if (s1 == NULL && s2 == NULL)
  101. + {
  102. + return 0;
  103. + }
  104. + return (s1 == NULL) ? -1 : 1;
  105. + }
  106. + while (len > 0 && tolower(*s1) == tolower(*s2))
  107. + {
  108. + len--;
  109. + s1++;
  110. + s2++;
  111. + }
  112. + return ( (len == 0) ? 0 : (tolower(*s1) - tolower(*s2)) );
  113. +}
  114. +#endif /* NF_NEED_STRNCASECMP */
  115. +
  116. +/*
  117. + * Parse a string containing a 16-bit unsigned integer.
  118. + * Returns the number of chars used, or zero if no number is found.
  119. + */
  120. +#ifdef NF_NEED_STRTOU16
  121. +static int
  122. +nf_strtou16(const char* pbuf, u_int16_t* pval)
  123. +{
  124. + int n = 0;
  125. +
  126. + *pval = 0;
  127. + while (isdigit(pbuf[n]))
  128. + {
  129. + *pval = (*pval * 10) + (pbuf[n] - '0');
  130. + n++;
  131. + }
  132. +
  133. + return n;
  134. +}
  135. +#endif /* NF_NEED_STRTOU16 */
  136. +
  137. +/*
  138. + * Parse a string containing a 32-bit unsigned integer.
  139. + * Returns the number of chars used, or zero if no number is found.
  140. + */
  141. +#ifdef NF_NEED_STRTOU32
  142. +static int
  143. +nf_strtou32(const char* pbuf, u_int32_t* pval)
  144. +{
  145. + int n = 0;
  146. +
  147. + *pval = 0;
  148. + while (pbuf[n] >= '0' && pbuf[n] <= '9')
  149. + {
  150. + *pval = (*pval * 10) + (pbuf[n] - '0');
  151. + n++;
  152. + }
  153. +
  154. + return n;
  155. +}
  156. +#endif /* NF_NEED_STRTOU32 */
  157. +
  158. +/*
  159. + * Given a buffer and length, advance to the next line and mark the current
  160. + * line.
  161. + */
  162. +#ifdef NF_NEED_NEXTLINE
  163. +static int
  164. +nf_nextline(char* p, uint len, uint* poff, uint* plineoff, uint* plinelen)
  165. +{
  166. + uint off = *poff;
  167. + uint physlen = 0;
  168. +
  169. + if (off >= len)
  170. + {
  171. + return 0;
  172. + }
  173. +
  174. + while (p[off] != '\n')
  175. + {
  176. + if (len-off <= 1)
  177. + {
  178. + return 0;
  179. + }
  180. +
  181. + physlen++;
  182. + off++;
  183. + }
  184. +
  185. + /* if we saw a crlf, physlen needs adjusted */
  186. + if (physlen > 0 && p[off] == '\n' && p[off-1] == '\r')
  187. + {
  188. + physlen--;
  189. + }
  190. +
  191. + /* advance past the newline */
  192. + off++;
  193. +
  194. + *plineoff = *poff;
  195. + *plinelen = physlen;
  196. + *poff = off;
  197. +
  198. + return 1;
  199. +}
  200. +#endif /* NF_NEED_NEXTLINE */
  201. +
  202. +#endif /* __KERNEL__ */
  203. +
  204. +#endif /* _NETFILTER_HELPERS_H */
  205. diff -Nur linux-2.6.33.orig/include/linux/netfilter_mime.h linux-2.6.33/include/linux/netfilter_mime.h
  206. --- linux-2.6.33.orig/include/linux/netfilter_mime.h 1970-01-01 01:00:00.000000000 +0100
  207. +++ linux-2.6.33/include/linux/netfilter_mime.h 2010-04-25 01:09:20.000000000 +0200
  208. @@ -0,0 +1,89 @@
  209. +/*
  210. + * MIME functions for netfilter modules. This file provides implementations
  211. + * for basic MIME parsing. MIME headers are used in many protocols, such as
  212. + * HTTP, RTSP, SIP, etc.
  213. + *
  214. + * gcc will warn for defined but unused functions, so we only include the
  215. + * functions requested. The following macros are used:
  216. + * NF_NEED_MIME_NEXTLINE nf_mime_nextline()
  217. + */
  218. +#ifndef _NETFILTER_MIME_H
  219. +#define _NETFILTER_MIME_H
  220. +
  221. +/* Only include these functions for kernel code. */
  222. +#ifdef __KERNEL__
  223. +
  224. +#include <linux/ctype.h>
  225. +
  226. +/*
  227. + * Given a buffer and length, advance to the next line and mark the current
  228. + * line. If the current line is empty, *plinelen will be set to zero. If
  229. + * not, it will be set to the actual line length (including CRLF).
  230. + *
  231. + * 'line' in this context means logical line (includes LWS continuations).
  232. + * Returns 1 on success, 0 on failure.
  233. + */
  234. +#ifdef NF_NEED_MIME_NEXTLINE
  235. +static int
  236. +nf_mime_nextline(char* p, uint len, uint* poff, uint* plineoff, uint* plinelen)
  237. +{
  238. + uint off = *poff;
  239. + uint physlen = 0;
  240. + int is_first_line = 1;
  241. +
  242. + if (off >= len)
  243. + {
  244. + return 0;
  245. + }
  246. +
  247. + do
  248. + {
  249. + while (p[off] != '\n')
  250. + {
  251. + if (len-off <= 1)
  252. + {
  253. + return 0;
  254. + }
  255. +
  256. + physlen++;
  257. + off++;
  258. + }
  259. +
  260. + /* if we saw a crlf, physlen needs adjusted */
  261. + if (physlen > 0 && p[off] == '\n' && p[off-1] == '\r')
  262. + {
  263. + physlen--;
  264. + }
  265. +
  266. + /* advance past the newline */
  267. + off++;
  268. +
  269. + /* check for an empty line */
  270. + if (physlen == 0)
  271. + {
  272. + break;
  273. + }
  274. +
  275. + /* check for colon on the first physical line */
  276. + if (is_first_line)
  277. + {
  278. + is_first_line = 0;
  279. + if (memchr(p+(*poff), ':', physlen) == NULL)
  280. + {
  281. + return 0;
  282. + }
  283. + }
  284. + }
  285. + while (p[off] == ' ' || p[off] == '\t');
  286. +
  287. + *plineoff = *poff;
  288. + *plinelen = (physlen == 0) ? 0 : (off - *poff);
  289. + *poff = off;
  290. +
  291. + return 1;
  292. +}
  293. +#endif /* NF_NEED_MIME_NEXTLINE */
  294. +
  295. +#endif /* __KERNEL__ */
  296. +
  297. +#endif /* _NETFILTER_MIME_H */
  298. diff -Nur linux-2.6.33.orig/net/ipv4/netfilter/Kconfig linux-2.6.33/net/ipv4/netfilter/Kconfig
  299. --- linux-2.6.33.orig/net/ipv4/netfilter/Kconfig 2010-02-24 19:52:17.000000000 +0100
  300. +++ linux-2.6.33/net/ipv4/netfilter/Kconfig 2010-04-25 01:09:20.000000000 +0200
  301. @@ -257,6 +257,11 @@
  302. depends on NF_CONNTRACK && NF_NAT
  303. default NF_NAT && NF_CONNTRACK_IRC
  304. +config NF_NAT_RTSP
  305. + tristate
  306. + depends on IP_NF_IPTABLES && NF_CONNTRACK && NF_NAT
  307. + default NF_NAT && NF_CONNTRACK_RTSP
  308. +
  309. config NF_NAT_TFTP
  310. tristate
  311. depends on NF_CONNTRACK && NF_NAT
  312. diff -Nur linux-2.6.33.orig/net/ipv4/netfilter/Makefile linux-2.6.33/net/ipv4/netfilter/Makefile
  313. --- linux-2.6.33.orig/net/ipv4/netfilter/Makefile 2010-02-24 19:52:17.000000000 +0100
  314. +++ linux-2.6.33/net/ipv4/netfilter/Makefile 2010-04-25 01:09:20.000000000 +0200
  315. @@ -26,6 +26,7 @@
  316. obj-$(CONFIG_NF_NAT_FTP) += nf_nat_ftp.o
  317. obj-$(CONFIG_NF_NAT_H323) += nf_nat_h323.o
  318. obj-$(CONFIG_NF_NAT_IRC) += nf_nat_irc.o
  319. +obj-$(CONFIG_NF_NAT_RTSP) += nf_nat_rtsp.o
  320. obj-$(CONFIG_NF_NAT_PPTP) += nf_nat_pptp.o
  321. obj-$(CONFIG_NF_NAT_SIP) += nf_nat_sip.o
  322. obj-$(CONFIG_NF_NAT_SNMP_BASIC) += nf_nat_snmp_basic.o
  323. diff -Nur linux-2.6.33.orig/net/ipv4/netfilter/nf_nat_rtsp.c linux-2.6.33/net/ipv4/netfilter/nf_nat_rtsp.c
  324. --- linux-2.6.33.orig/net/ipv4/netfilter/nf_nat_rtsp.c 1970-01-01 01:00:00.000000000 +0100
  325. +++ linux-2.6.33/net/ipv4/netfilter/nf_nat_rtsp.c 2010-04-25 01:09:20.000000000 +0200
  326. @@ -0,0 +1,496 @@
  327. +/*
  328. + * RTSP extension for TCP NAT alteration
  329. + * (C) 2003 by Tom Marshall <tmarshall at real.com>
  330. + * based on ip_nat_irc.c
  331. + *
  332. + * This program is free software; you can redistribute it and/or
  333. + * modify it under the terms of the GNU General Public License
  334. + * as published by the Free Software Foundation; either version
  335. + * 2 of the License, or (at your option) any later version.
  336. + *
  337. + * Module load syntax:
  338. + * insmod nf_nat_rtsp.o ports=port1,port2,...port<MAX_PORTS>
  339. + * stunaddr=<address>
  340. + * destaction=[auto|strip|none]
  341. + *
  342. + * If no ports are specified, the default will be port 554 only.
  343. + *
  344. + * stunaddr specifies the address used to detect that a client is using STUN.
  345. + * If this address is seen in the destination parameter, it is assumed that
  346. + * the client has already punched a UDP hole in the firewall, so we don't
  347. + * mangle the client_port. If none is specified, it is autodetected. It
  348. + * only needs to be set if you have multiple levels of NAT. It should be
  349. + * set to the external address that the STUN clients detect. Note that in
  350. + * this case, it will not be possible for clients to use UDP with servers
  351. + * between the NATs.
  352. + *
  353. + * If no destaction is specified, auto is used.
  354. + * destaction=auto: strip destination parameter if it is not stunaddr.
  355. + * destaction=strip: always strip destination parameter (not recommended).
  356. + * destaction=none: do not touch destination parameter (not recommended).
  357. + */
  358. +
  359. +#include <linux/module.h>
  360. +#include <net/tcp.h>
  361. +#include <net/netfilter/nf_nat_helper.h>
  362. +#include <net/netfilter/nf_nat_rule.h>
  363. +#include <linux/netfilter/nf_conntrack_rtsp.h>
  364. +#include <net/netfilter/nf_conntrack_expect.h>
  365. +
  366. +#include <linux/inet.h>
  367. +#include <linux/ctype.h>
  368. +#define NF_NEED_STRNCASECMP
  369. +#define NF_NEED_STRTOU16
  370. +#include <linux/netfilter_helpers.h>
  371. +#define NF_NEED_MIME_NEXTLINE
  372. +#include <linux/netfilter_mime.h>
  373. +
  374. +#define INFOP(fmt, args...) printk(KERN_INFO "%s: %s: " fmt, __FILE__, __FUNCTION__ , ## args)
  375. +#if 0
  376. +#define DEBUGP(fmt, args...) printk(KERN_DEBUG "%s: %s: " fmt, __FILE__, __FUNCTION__ , ## args)
  377. +#else
  378. +#define DEBUGP(fmt, args...)
  379. +#endif
  380. +
  381. +#define MAX_PORTS 8
  382. +#define DSTACT_AUTO 0
  383. +#define DSTACT_STRIP 1
  384. +#define DSTACT_NONE 2
  385. +
  386. +static char* stunaddr = NULL;
  387. +static char* destaction = NULL;
  388. +
  389. +static u_int32_t extip = 0;
  390. +static int dstact = 0;
  391. +
  392. +MODULE_AUTHOR("Tom Marshall <tmarshall at real.com>");
  393. +MODULE_DESCRIPTION("RTSP network address translation module");
  394. +MODULE_LICENSE("GPL");
  395. +module_param(stunaddr, charp, 0644);
  396. +MODULE_PARM_DESC(stunaddr, "Address for detecting STUN");
  397. +module_param(destaction, charp, 0644);
  398. +MODULE_PARM_DESC(destaction, "Action for destination parameter (auto/strip/none)");
  399. +
  400. +#define SKIP_WSPACE(ptr,len,off) while(off < len && isspace(*(ptr+off))) { off++; }
  401. +
  402. +/*** helper functions ***/
  403. +
  404. +static void
  405. +get_skb_tcpdata(struct sk_buff* skb, char** pptcpdata, uint* ptcpdatalen)
  406. +{
  407. + struct iphdr* iph = ip_hdr(skb);
  408. + struct tcphdr* tcph = (void *)iph + ip_hdrlen(skb);
  409. +
  410. + *pptcpdata = (char*)tcph + tcph->doff*4;
  411. + *ptcpdatalen = ((char*)skb_transport_header(skb) + skb->len) - *pptcpdata;
  412. +}
  413. +
  414. +/*** nat functions ***/
  415. +
  416. +/*
  417. + * Mangle the "Transport:" header:
  418. + * - Replace all occurences of "client_port=<spec>"
  419. + * - Handle destination parameter
  420. + *
  421. + * In:
  422. + * ct, ctinfo = conntrack context
  423. + * skb = packet
  424. + * tranoff = Transport header offset from TCP data
  425. + * tranlen = Transport header length (incl. CRLF)
  426. + * rport_lo = replacement low port (host endian)
  427. + * rport_hi = replacement high port (host endian)
  428. + *
  429. + * Returns packet size difference.
  430. + *
  431. + * Assumes that a complete transport header is present, ending with CR or LF
  432. + */
  433. +static int
  434. +rtsp_mangle_tran(enum ip_conntrack_info ctinfo,
  435. + struct nf_conntrack_expect* exp,
  436. + struct ip_ct_rtsp_expect* prtspexp,
  437. + struct sk_buff* skb, uint tranoff, uint tranlen)
  438. +{
  439. + char* ptcp;
  440. + uint tcplen;
  441. + char* ptran;
  442. + char rbuf1[16]; /* Replacement buffer (one port) */
  443. + uint rbuf1len; /* Replacement len (one port) */
  444. + char rbufa[16]; /* Replacement buffer (all ports) */
  445. + uint rbufalen; /* Replacement len (all ports) */
  446. + u_int32_t newip;
  447. + u_int16_t loport, hiport;
  448. + uint off = 0;
  449. + uint diff; /* Number of bytes we removed */
  450. +
  451. + struct nf_conn *ct = exp->master;
  452. + struct nf_conntrack_tuple *t;
  453. +
  454. + char szextaddr[15+1];
  455. + uint extaddrlen;
  456. + int is_stun;
  457. +
  458. + get_skb_tcpdata(skb, &ptcp, &tcplen);
  459. + ptran = ptcp+tranoff;
  460. +
  461. + if (tranoff+tranlen > tcplen || tcplen-tranoff < tranlen ||
  462. + tranlen < 10 || !iseol(ptran[tranlen-1]) ||
  463. + nf_strncasecmp(ptran, "Transport:", 10) != 0)
  464. + {
  465. + INFOP("sanity check failed\n");
  466. + return 0;
  467. + }
  468. + off += 10;
  469. + SKIP_WSPACE(ptcp+tranoff, tranlen, off);
  470. +
  471. + newip = ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.u3.ip;
  472. + t = &exp->tuple;
  473. + t->dst.u3.ip = newip;
  474. +
  475. + extaddrlen = extip ? sprintf(szextaddr, "%u.%u.%u.%u", NIPQUAD(extip))
  476. + : sprintf(szextaddr, "%u.%u.%u.%u", NIPQUAD(newip));
  477. + DEBUGP("stunaddr=%s (%s)\n", szextaddr, (extip?"forced":"auto"));
  478. +
  479. + rbuf1len = rbufalen = 0;
  480. + switch (prtspexp->pbtype)
  481. + {
  482. + case pb_single:
  483. + for (loport = prtspexp->loport; loport != 0; loport++) /* XXX: improper wrap? */
  484. + {
  485. + t->dst.u.udp.port = htons(loport);
  486. + if (nf_ct_expect_related(exp) == 0)
  487. + {
  488. + DEBUGP("using port %hu\n", loport);
  489. + break;
  490. + }
  491. + }
  492. + if (loport != 0)
  493. + {
  494. + rbuf1len = sprintf(rbuf1, "%hu", loport);
  495. + rbufalen = sprintf(rbufa, "%hu", loport);
  496. + }
  497. + break;
  498. + case pb_range:
  499. + for (loport = prtspexp->loport; loport != 0; loport += 2) /* XXX: improper wrap? */
  500. + {
  501. + t->dst.u.udp.port = htons(loport);
  502. + if (nf_ct_expect_related(exp) == 0)
  503. + {
  504. + hiport = loport + ~exp->mask.src.u.udp.port;
  505. + DEBUGP("using ports %hu-%hu\n", loport, hiport);
  506. + break;
  507. + }
  508. + }
  509. + if (loport != 0)
  510. + {
  511. + rbuf1len = sprintf(rbuf1, "%hu", loport);
  512. + rbufalen = sprintf(rbufa, "%hu-%hu", loport, loport+1);
  513. + }
  514. + break;
  515. + case pb_discon:
  516. + for (loport = prtspexp->loport; loport != 0; loport++) /* XXX: improper wrap? */
  517. + {
  518. + t->dst.u.udp.port = htons(loport);
  519. + if (nf_ct_expect_related(exp) == 0)
  520. + {
  521. + DEBUGP("using port %hu (1 of 2)\n", loport);
  522. + break;
  523. + }
  524. + }
  525. + for (hiport = prtspexp->hiport; hiport != 0; hiport++) /* XXX: improper wrap? */
  526. + {
  527. + t->dst.u.udp.port = htons(hiport);
  528. + if (nf_ct_expect_related(exp) == 0)
  529. + {
  530. + DEBUGP("using port %hu (2 of 2)\n", hiport);
  531. + break;
  532. + }
  533. + }
  534. + if (loport != 0 && hiport != 0)
  535. + {
  536. + rbuf1len = sprintf(rbuf1, "%hu", loport);
  537. + if (hiport == loport+1)
  538. + {
  539. + rbufalen = sprintf(rbufa, "%hu-%hu", loport, hiport);
  540. + }
  541. + else
  542. + {
  543. + rbufalen = sprintf(rbufa, "%hu/%hu", loport, hiport);
  544. + }
  545. + }
  546. + break;
  547. + }
  548. +
  549. + if (rbuf1len == 0)
  550. + {
  551. + return 0; /* cannot get replacement port(s) */
  552. + }
  553. +
  554. + /* Transport: tran;field;field=val,tran;field;field=val,... */
  555. + while (off < tranlen)
  556. + {
  557. + uint saveoff;
  558. + const char* pparamend;
  559. + uint nextparamoff;
  560. +
  561. + pparamend = memchr(ptran+off, ',', tranlen-off);
  562. + pparamend = (pparamend == NULL) ? ptran+tranlen : pparamend+1;
  563. + nextparamoff = pparamend-ptcp;
  564. +
  565. + /*
  566. + * We pass over each param twice. On the first pass, we look for a
  567. + * destination= field. It is handled by the security policy. If it
  568. + * is present, allowed, and equal to our external address, we assume
  569. + * that STUN is being used and we leave the client_port= field alone.
  570. + */
  571. + is_stun = 0;
  572. + saveoff = off;
  573. + while (off < nextparamoff)
  574. + {
  575. + const char* pfieldend;
  576. + uint nextfieldoff;
  577. +
  578. + pfieldend = memchr(ptran+off, ';', nextparamoff-off);
  579. + nextfieldoff = (pfieldend == NULL) ? nextparamoff : pfieldend-ptran+1;
  580. +
  581. + if (dstact != DSTACT_NONE && strncmp(ptran+off, "destination=", 12) == 0)
  582. + {
  583. + if (strncmp(ptran+off+12, szextaddr, extaddrlen) == 0)
  584. + {
  585. + is_stun = 1;
  586. + }
  587. + if (dstact == DSTACT_STRIP || (dstact == DSTACT_AUTO && !is_stun))
  588. + {
  589. + diff = nextfieldoff-off;
  590. + if (!nf_nat_mangle_tcp_packet(skb, ct, ctinfo,
  591. + off, diff, NULL, 0))
  592. + {
  593. + /* mangle failed, all we can do is bail */
  594. + nf_ct_unexpect_related(exp);
  595. + return 0;
  596. + }
  597. + get_skb_tcpdata(skb, &ptcp, &tcplen);
  598. + ptran = ptcp+tranoff;
  599. + tranlen -= diff;
  600. + nextparamoff -= diff;
  601. + nextfieldoff -= diff;
  602. + }
  603. + }
  604. +
  605. + off = nextfieldoff;
  606. + }
  607. + if (is_stun)
  608. + {
  609. + continue;
  610. + }
  611. + off = saveoff;
  612. + while (off < nextparamoff)
  613. + {
  614. + const char* pfieldend;
  615. + uint nextfieldoff;
  616. +
  617. + pfieldend = memchr(ptran+off, ';', nextparamoff-off);
  618. + nextfieldoff = (pfieldend == NULL) ? nextparamoff : pfieldend-ptran+1;
  619. +
  620. + if (strncmp(ptran+off, "client_port=", 12) == 0)
  621. + {
  622. + u_int16_t port;
  623. + uint numlen;
  624. + uint origoff;
  625. + uint origlen;
  626. + char* rbuf = rbuf1;
  627. + uint rbuflen = rbuf1len;
  628. +
  629. + off += 12;
  630. + origoff = (ptran-ptcp)+off;
  631. + origlen = 0;
  632. + numlen = nf_strtou16(ptran+off, &port);
  633. + off += numlen;
  634. + origlen += numlen;
  635. + if (port != prtspexp->loport)
  636. + {
  637. + DEBUGP("multiple ports found, port %hu ignored\n", port);
  638. + }
  639. + else
  640. + {
  641. + if (ptran[off] == '-' || ptran[off] == '/')
  642. + {
  643. + off++;
  644. + origlen++;
  645. + numlen = nf_strtou16(ptran+off, &port);
  646. + off += numlen;
  647. + origlen += numlen;
  648. + rbuf = rbufa;
  649. + rbuflen = rbufalen;
  650. + }
  651. +
  652. + /*
  653. + * note we cannot just memcpy() if the sizes are the same.
  654. + * the mangle function does skb resizing, checks for a
  655. + * cloned skb, and updates the checksums.
  656. + *
  657. + * parameter 4 below is offset from start of tcp data.
  658. + */
  659. + diff = origlen-rbuflen;
  660. + if (!nf_nat_mangle_tcp_packet(skb, ct, ctinfo,
  661. + origoff, origlen, rbuf, rbuflen))
  662. + {
  663. + /* mangle failed, all we can do is bail */
  664. + nf_ct_unexpect_related(exp);
  665. + return 0;
  666. + }
  667. + get_skb_tcpdata(skb, &ptcp, &tcplen);
  668. + ptran = ptcp+tranoff;
  669. + tranlen -= diff;
  670. + nextparamoff -= diff;
  671. + nextfieldoff -= diff;
  672. + }
  673. + }
  674. +
  675. + off = nextfieldoff;
  676. + }
  677. +
  678. + off = nextparamoff;
  679. + }
  680. +
  681. + return 1;
  682. +}
  683. +
  684. +static uint
  685. +help_out(struct sk_buff *skb, enum ip_conntrack_info ctinfo,
  686. + unsigned int matchoff, unsigned int matchlen, struct ip_ct_rtsp_expect* prtspexp,
  687. + struct nf_conntrack_expect* exp)
  688. +{
  689. + char* ptcp;
  690. + uint tcplen;
  691. + uint hdrsoff;
  692. + uint hdrslen;
  693. + uint lineoff;
  694. + uint linelen;
  695. + uint off;
  696. +
  697. + //struct iphdr* iph = (struct iphdr*)skb->nh.iph;
  698. + //struct tcphdr* tcph = (struct tcphdr*)((void*)iph + iph->ihl*4);
  699. +
  700. + get_skb_tcpdata(skb, &ptcp, &tcplen);
  701. + hdrsoff = matchoff;//exp->seq - ntohl(tcph->seq);
  702. + hdrslen = matchlen;
  703. + off = hdrsoff;
  704. + DEBUGP("NAT rtsp help_out\n");
  705. +
  706. + while (nf_mime_nextline(ptcp, hdrsoff+hdrslen, &off, &lineoff, &linelen))
  707. + {
  708. + if (linelen == 0)
  709. + {
  710. + break;
  711. + }
  712. + if (off > hdrsoff+hdrslen)
  713. + {
  714. + INFOP("!! overrun !!");
  715. + break;
  716. + }
  717. + DEBUGP("hdr: len=%u, %.*s", linelen, (int)linelen, ptcp+lineoff);
  718. +
  719. + if (nf_strncasecmp(ptcp+lineoff, "Transport:", 10) == 0)
  720. + {
  721. + uint oldtcplen = tcplen;
  722. + DEBUGP("hdr: Transport\n");
  723. + if (!rtsp_mangle_tran(ctinfo, exp, prtspexp, skb, lineoff, linelen))
  724. + {
  725. + DEBUGP("hdr: Transport mangle failed");
  726. + break;
  727. + }
  728. + get_skb_tcpdata(skb, &ptcp, &tcplen);
  729. + hdrslen -= (oldtcplen-tcplen);
  730. + off -= (oldtcplen-tcplen);
  731. + lineoff -= (oldtcplen-tcplen);
  732. + linelen -= (oldtcplen-tcplen);
  733. + DEBUGP("rep: len=%u, %.*s", linelen, (int)linelen, ptcp+lineoff);
  734. + }
  735. + }
  736. +
  737. + return NF_ACCEPT;
  738. +}
  739. +
  740. +static unsigned int
  741. +help(struct sk_buff *skb, enum ip_conntrack_info ctinfo,
  742. + unsigned int matchoff, unsigned int matchlen, struct ip_ct_rtsp_expect* prtspexp,
  743. + struct nf_conntrack_expect* exp)
  744. +{
  745. + int dir = CTINFO2DIR(ctinfo);
  746. + int rc = NF_ACCEPT;
  747. +
  748. + switch (dir)
  749. + {
  750. + case IP_CT_DIR_ORIGINAL:
  751. + rc = help_out(skb, ctinfo, matchoff, matchlen, prtspexp, exp);
  752. + break;
  753. + case IP_CT_DIR_REPLY:
  754. + DEBUGP("unmangle ! %u\n", ctinfo);
  755. + /* XXX: unmangle */
  756. + rc = NF_ACCEPT;
  757. + break;
  758. + }
  759. + //UNLOCK_BH(&ip_rtsp_lock);
  760. +
  761. + return rc;
  762. +}
  763. +
  764. +static void expected(struct nf_conn* ct, struct nf_conntrack_expect *exp)
  765. +{
  766. + struct nf_nat_multi_range_compat mr;
  767. + u_int32_t newdstip, newsrcip, newip;
  768. +
  769. + struct nf_conn *master = ct->master;
  770. +
  771. + newdstip = master->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.u3.ip;
  772. + newsrcip = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.u3.ip;
  773. + //FIXME (how to port that ?)
  774. + //code from 2.4 : newip = (HOOK2MANIP(hooknum) == IP_NAT_MANIP_SRC) ? newsrcip : newdstip;
  775. + newip = newdstip;
  776. +
  777. + DEBUGP("newsrcip=%u.%u.%u.%u, newdstip=%u.%u.%u.%u, newip=%u.%u.%u.%u\n",
  778. + NIPQUAD(newsrcip), NIPQUAD(newdstip), NIPQUAD(newip));
  779. +
  780. + mr.rangesize = 1;
  781. + // We don't want to manip the per-protocol, just the IPs.
  782. + mr.range[0].flags = IP_NAT_RANGE_MAP_IPS;
  783. + mr.range[0].min_ip = mr.range[0].max_ip = newip;
  784. +
  785. + nf_nat_setup_info(ct, &mr.range[0], IP_NAT_MANIP_DST);
  786. +}
  787. +
  788. +
  789. +static void __exit fini(void)
  790. +{
  791. + nf_nat_rtsp_hook = NULL;
  792. + nf_nat_rtsp_hook_expectfn = NULL;
  793. + synchronize_net();
  794. +}
  795. +
  796. +static int __init init(void)
  797. +{
  798. + printk("nf_nat_rtsp v" IP_NF_RTSP_VERSION " loading\n");
  799. +
  800. + BUG_ON(nf_nat_rtsp_hook);
  801. + nf_nat_rtsp_hook = help;
  802. + nf_nat_rtsp_hook_expectfn = &expected;
  803. +
  804. + if (stunaddr != NULL)
  805. + extip = in_aton(stunaddr);
  806. +
  807. + if (destaction != NULL) {
  808. + if (strcmp(destaction, "auto") == 0)
  809. + dstact = DSTACT_AUTO;
  810. +
  811. + if (strcmp(destaction, "strip") == 0)
  812. + dstact = DSTACT_STRIP;
  813. +
  814. + if (strcmp(destaction, "none") == 0)
  815. + dstact = DSTACT_NONE;
  816. + }
  817. +
  818. + return 0;
  819. +}
  820. +
  821. +module_init(init);
  822. +module_exit(fini);
  823. diff -Nur linux-2.6.33.orig/net/netfilter/Kconfig linux-2.6.33/net/netfilter/Kconfig
  824. --- linux-2.6.33.orig/net/netfilter/Kconfig 2010-02-24 19:52:17.000000000 +0100
  825. +++ linux-2.6.33/net/netfilter/Kconfig 2010-04-25 01:09:20.000000000 +0200
  826. @@ -268,6 +268,16 @@
  827. To compile it as a module, choose M here. If unsure, say N.
  828. +config NF_CONNTRACK_RTSP
  829. + tristate "RTSP protocol support"
  830. + depends on NF_CONNTRACK
  831. + help
  832. + Support the RTSP protocol. This allows UDP transports to be setup
  833. + properly, including RTP and RDT.
  834. +
  835. + If you want to compile it as a module, say 'M' here and read
  836. + Documentation/modules.txt. If unsure, say 'Y'.
  837. +
  838. config NF_CT_NETLINK
  839. tristate 'Connection tracking netlink interface'
  840. select NETFILTER_NETLINK
  841. diff -Nur linux-2.6.33.orig/net/netfilter/Kconfig.orig linux-2.6.33/net/netfilter/Kconfig.orig
  842. --- linux-2.6.33.orig/net/netfilter/Kconfig.orig 1970-01-01 01:00:00.000000000 +0100
  843. +++ linux-2.6.33/net/netfilter/Kconfig.orig 2010-02-24 19:52:17.000000000 +0100
  844. @@ -0,0 +1,937 @@
  845. +menu "Core Netfilter Configuration"
  846. + depends on NET && INET && NETFILTER
  847. +
  848. +config NETFILTER_NETLINK
  849. + tristate
  850. +
  851. +config NETFILTER_NETLINK_QUEUE
  852. + tristate "Netfilter NFQUEUE over NFNETLINK interface"
  853. + depends on NETFILTER_ADVANCED
  854. + select NETFILTER_NETLINK
  855. + help
  856. + If this option is enabled, the kernel will include support
  857. + for queueing packets via NFNETLINK.
  858. +
  859. +config NETFILTER_NETLINK_LOG
  860. + tristate "Netfilter LOG over NFNETLINK interface"
  861. + default m if NETFILTER_ADVANCED=n
  862. + select NETFILTER_NETLINK
  863. + help
  864. + If this option is enabled, the kernel will include support
  865. + for logging packets via NFNETLINK.
  866. +
  867. + This obsoletes the existing ipt_ULOG and ebg_ulog mechanisms,
  868. + and is also scheduled to replace the old syslog-based ipt_LOG
  869. + and ip6t_LOG modules.
  870. +
  871. +config NF_CONNTRACK
  872. + tristate "Netfilter connection tracking support"
  873. + default m if NETFILTER_ADVANCED=n
  874. + help
  875. + Connection tracking keeps a record of what packets have passed
  876. + through your machine, in order to figure out how they are related
  877. + into connections.
  878. +
  879. + This is required to do Masquerading or other kinds of Network
  880. + Address Translation. It can also be used to enhance packet
  881. + filtering (see `Connection state match support' below).
  882. +
  883. + To compile it as a module, choose M here. If unsure, say N.
  884. +
  885. +if NF_CONNTRACK
  886. +
  887. +config NF_CT_ACCT
  888. + bool "Connection tracking flow accounting"
  889. + depends on NETFILTER_ADVANCED
  890. + help
  891. + If this option is enabled, the connection tracking code will
  892. + keep per-flow packet and byte counters.
  893. +
  894. + Those counters can be used for flow-based accounting or the
  895. + `connbytes' match.
  896. +
  897. + Please note that currently this option only sets a default state.
  898. + You may change it at boot time with nf_conntrack.acct=0/1 kernel
  899. + parameter or by loading the nf_conntrack module with acct=0/1.
  900. +
  901. + You may also disable/enable it on a running system with:
  902. + sysctl net.netfilter.nf_conntrack_acct=0/1
  903. +
  904. + This option will be removed in 2.6.29.
  905. +
  906. + If unsure, say `N'.
  907. +
  908. +config NF_CONNTRACK_MARK
  909. + bool 'Connection mark tracking support'
  910. + depends on NETFILTER_ADVANCED
  911. + help
  912. + This option enables support for connection marks, used by the
  913. + `CONNMARK' target and `connmark' match. Similar to the mark value
  914. + of packets, but this mark value is kept in the conntrack session
  915. + instead of the individual packets.
  916. +
  917. +config NF_CONNTRACK_SECMARK
  918. + bool 'Connection tracking security mark support'
  919. + depends on NETWORK_SECMARK
  920. + default m if NETFILTER_ADVANCED=n
  921. + help
  922. + This option enables security markings to be applied to
  923. + connections. Typically they are copied to connections from
  924. + packets using the CONNSECMARK target and copied back from
  925. + connections to packets with the same target, with the packets
  926. + being originally labeled via SECMARK.
  927. +
  928. + If unsure, say 'N'.
  929. +
  930. +config NF_CONNTRACK_EVENTS
  931. + bool "Connection tracking events"
  932. + depends on NETFILTER_ADVANCED
  933. + help
  934. + If this option is enabled, the connection tracking code will
  935. + provide a notifier chain that can be used by other kernel code
  936. + to get notified about changes in the connection tracking state.
  937. +
  938. + If unsure, say `N'.
  939. +
  940. +config NF_CT_PROTO_DCCP
  941. + tristate 'DCCP protocol connection tracking support (EXPERIMENTAL)'
  942. + depends on EXPERIMENTAL
  943. + depends on NETFILTER_ADVANCED
  944. + default IP_DCCP
  945. + help
  946. + With this option enabled, the layer 3 independent connection
  947. + tracking code will be able to do state tracking on DCCP connections.
  948. +
  949. + If unsure, say 'N'.
  950. +
  951. +config NF_CT_PROTO_GRE
  952. + tristate
  953. +
  954. +config NF_CT_PROTO_SCTP
  955. + tristate 'SCTP protocol connection tracking support (EXPERIMENTAL)'
  956. + depends on EXPERIMENTAL
  957. + depends on NETFILTER_ADVANCED
  958. + default IP_SCTP
  959. + help
  960. + With this option enabled, the layer 3 independent connection
  961. + tracking code will be able to do state tracking on SCTP connections.
  962. +
  963. + If you want to compile it as a module, say M here and read
  964. + <file:Documentation/kbuild/modules.txt>. If unsure, say `N'.
  965. +
  966. +config NF_CT_PROTO_UDPLITE
  967. + tristate 'UDP-Lite protocol connection tracking support'
  968. + depends on NETFILTER_ADVANCED
  969. + help
  970. + With this option enabled, the layer 3 independent connection
  971. + tracking code will be able to do state tracking on UDP-Lite
  972. + connections.
  973. +
  974. + To compile it as a module, choose M here. If unsure, say N.
  975. +
  976. +config NF_CONNTRACK_AMANDA
  977. + tristate "Amanda backup protocol support"
  978. + depends on NETFILTER_ADVANCED
  979. + select TEXTSEARCH
  980. + select TEXTSEARCH_KMP
  981. + help
  982. + If you are running the Amanda backup package <http://www.amanda.org/>
  983. + on this machine or machines that will be MASQUERADED through this
  984. + machine, then you may want to enable this feature. This allows the
  985. + connection tracking and natting code to allow the sub-channels that
  986. + Amanda requires for communication of the backup data, messages and
  987. + index.
  988. +
  989. + To compile it as a module, choose M here. If unsure, say N.
  990. +
  991. +config NF_CONNTRACK_FTP
  992. + tristate "FTP protocol support"
  993. + default m if NETFILTER_ADVANCED=n
  994. + help
  995. + Tracking FTP connections is problematic: special helpers are
  996. + required for tracking them, and doing masquerading and other forms
  997. + of Network Address Translation on them.
  998. +
  999. + This is FTP support on Layer 3 independent connection tracking.
  1000. + Layer 3 independent connection tracking is experimental scheme
  1001. + which generalize ip_conntrack to support other layer 3 protocols.
  1002. +
  1003. + To compile it as a module, choose M here. If unsure, say N.
  1004. +
  1005. +config NF_CONNTRACK_H323
  1006. + tristate "H.323 protocol support"
  1007. + depends on (IPV6 || IPV6=n)
  1008. + depends on NETFILTER_ADVANCED
  1009. + help
  1010. + H.323 is a VoIP signalling protocol from ITU-T. As one of the most
  1011. + important VoIP protocols, it is widely used by voice hardware and
  1012. + software including voice gateways, IP phones, Netmeeting, OpenPhone,
  1013. + Gnomemeeting, etc.
  1014. +
  1015. + With this module you can support H.323 on a connection tracking/NAT
  1016. + firewall.
  1017. +
  1018. + This module supports RAS, Fast Start, H.245 Tunnelling, Call
  1019. + Forwarding, RTP/RTCP and T.120 based audio, video, fax, chat,
  1020. + whiteboard, file transfer, etc. For more information, please
  1021. + visit http://nath323.sourceforge.net/.
  1022. +
  1023. + To compile it as a module, choose M here. If unsure, say N.
  1024. +
  1025. +config NF_CONNTRACK_IRC
  1026. + tristate "IRC protocol support"
  1027. + default m if NETFILTER_ADVANCED=n
  1028. + help
  1029. + There is a commonly-used extension to IRC called
  1030. + Direct Client-to-Client Protocol (DCC). This enables users to send
  1031. + files to each other, and also chat to each other without the need
  1032. + of a server. DCC Sending is used anywhere you send files over IRC,
  1033. + and DCC Chat is most commonly used by Eggdrop bots. If you are
  1034. + using NAT, this extension will enable you to send files and initiate
  1035. + chats. Note that you do NOT need this extension to get files or
  1036. + have others initiate chats, or everything else in IRC.
  1037. +
  1038. + To compile it as a module, choose M here. If unsure, say N.
  1039. +
  1040. +config NF_CONNTRACK_NETBIOS_NS
  1041. + tristate "NetBIOS name service protocol support"
  1042. + depends on NETFILTER_ADVANCED
  1043. + help
  1044. + NetBIOS name service requests are sent as broadcast messages from an
  1045. + unprivileged port and responded to with unicast messages to the
  1046. + same port. This make them hard to firewall properly because connection
  1047. + tracking doesn't deal with broadcasts. This helper tracks locally
  1048. + originating NetBIOS name service requests and the corresponding
  1049. + responses. It relies on correct IP address configuration, specifically
  1050. + netmask and broadcast address. When properly configured, the output
  1051. + of "ip address show" should look similar to this:
  1052. +
  1053. + $ ip -4 address show eth0
  1054. + 4: eth0: <BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast qlen 1000
  1055. + inet 172.16.2.252/24 brd 172.16.2.255 scope global eth0
  1056. +
  1057. + To compile it as a module, choose M here. If unsure, say N.
  1058. +
  1059. +config NF_CONNTRACK_PPTP
  1060. + tristate "PPtP protocol support"
  1061. + depends on NETFILTER_ADVANCED
  1062. + select NF_CT_PROTO_GRE
  1063. + help
  1064. + This module adds support for PPTP (Point to Point Tunnelling
  1065. + Protocol, RFC2637) connection tracking and NAT.
  1066. +
  1067. + If you are running PPTP sessions over a stateful firewall or NAT
  1068. + box, you may want to enable this feature.
  1069. +
  1070. + Please note that not all PPTP modes of operation are supported yet.
  1071. + Specifically these limitations exist:
  1072. + - Blindly assumes that control connections are always established
  1073. + in PNS->PAC direction. This is a violation of RFC2637.
  1074. + - Only supports a single call within each session
  1075. +
  1076. + To compile it as a module, choose M here. If unsure, say N.
  1077. +
  1078. +config NF_CONNTRACK_SANE
  1079. + tristate "SANE protocol support (EXPERIMENTAL)"
  1080. + depends on EXPERIMENTAL
  1081. + depends on NETFILTER_ADVANCED
  1082. + help
  1083. + SANE is a protocol for remote access to scanners as implemented
  1084. + by the 'saned' daemon. Like FTP, it uses separate control and
  1085. + data connections.
  1086. +
  1087. + With this module you can support SANE on a connection tracking
  1088. + firewall.
  1089. +
  1090. + To compile it as a module, choose M here. If unsure, say N.
  1091. +
  1092. +config NF_CONNTRACK_SIP
  1093. + tristate "SIP protocol support"
  1094. + default m if NETFILTER_ADVANCED=n
  1095. + help
  1096. + SIP is an application-layer control protocol that can establish,
  1097. + modify, and terminate multimedia sessions (conferences) such as
  1098. + Internet telephony calls. With the ip_conntrack_sip and
  1099. + the nf_nat_sip modules you can support the protocol on a connection
  1100. + tracking/NATing firewall.
  1101. +
  1102. + To compile it as a module, choose M here. If unsure, say N.
  1103. +
  1104. +config NF_CONNTRACK_TFTP
  1105. + tristate "TFTP protocol support"
  1106. + depends on NETFILTER_ADVANCED
  1107. + help
  1108. + TFTP connection tracking helper, this is required depending
  1109. + on how restrictive your ruleset is.
  1110. + If you are using a tftp client behind -j SNAT or -j MASQUERADING
  1111. + you will need this.
  1112. +
  1113. + To compile it as a module, choose M here. If unsure, say N.
  1114. +
  1115. +config NF_CT_NETLINK
  1116. + tristate 'Connection tracking netlink interface'
  1117. + select NETFILTER_NETLINK
  1118. + default m if NETFILTER_ADVANCED=n
  1119. + help
  1120. + This option enables support for a netlink-based userspace interface
  1121. +
  1122. +endif # NF_CONNTRACK
  1123. +
  1124. +# transparent proxy support
  1125. +config NETFILTER_TPROXY
  1126. + tristate "Transparent proxying support (EXPERIMENTAL)"
  1127. + depends on EXPERIMENTAL
  1128. + depends on IP_NF_MANGLE
  1129. + depends on NETFILTER_ADVANCED
  1130. + help
  1131. + This option enables transparent proxying support, that is,
  1132. + support for handling non-locally bound IPv4 TCP and UDP sockets.
  1133. + For it to work you will have to configure certain iptables rules
  1134. + and use policy routing. For more information on how to set it up
  1135. + see Documentation/networking/tproxy.txt.
  1136. +
  1137. + To compile it as a module, choose M here. If unsure, say N.
  1138. +
  1139. +config NETFILTER_XTABLES
  1140. + tristate "Netfilter Xtables support (required for ip_tables)"
  1141. + default m if NETFILTER_ADVANCED=n
  1142. + help
  1143. + This is required if you intend to use any of ip_tables,
  1144. + ip6_tables or arp_tables.
  1145. +
  1146. +if NETFILTER_XTABLES
  1147. +
  1148. +# alphabetically ordered list of targets
  1149. +
  1150. +config NETFILTER_XT_TARGET_CLASSIFY
  1151. + tristate '"CLASSIFY" target support'
  1152. + depends on NETFILTER_ADVANCED
  1153. + help
  1154. + This option adds a `CLASSIFY' target, which enables the user to set
  1155. + the priority of a packet. Some qdiscs can use this value for
  1156. + classification, among these are:
  1157. +
  1158. + atm, cbq, dsmark, pfifo_fast, htb, prio
  1159. +
  1160. + To compile it as a module, choose M here. If unsure, say N.
  1161. +
  1162. +config NETFILTER_XT_TARGET_CONNMARK
  1163. + tristate '"CONNMARK" target support'
  1164. + depends on NF_CONNTRACK
  1165. + depends on NETFILTER_ADVANCED
  1166. + select NF_CONNTRACK_MARK
  1167. + help
  1168. + This option adds a `CONNMARK' target, which allows one to manipulate
  1169. + the connection mark value. Similar to the MARK target, but
  1170. + affects the connection mark value rather than the packet mark value.
  1171. +
  1172. + If you want to compile it as a module, say M here and read
  1173. + <file:Documentation/kbuild/modules.txt>. The module will be called
  1174. + ipt_CONNMARK. If unsure, say `N'.
  1175. +
  1176. +config NETFILTER_XT_TARGET_CONNSECMARK
  1177. + tristate '"CONNSECMARK" target support'
  1178. + depends on NF_CONNTRACK && NF_CONNTRACK_SECMARK
  1179. + default m if NETFILTER_ADVANCED=n
  1180. + help
  1181. + The CONNSECMARK target copies security markings from packets
  1182. + to connections, and restores security markings from connections
  1183. + to packets (if the packets are not already marked). This would
  1184. + normally be used in conjunction with the SECMARK target.
  1185. +
  1186. + To compile it as a module, choose M here. If unsure, say N.
  1187. +
  1188. +config NETFILTER_XT_TARGET_DSCP
  1189. + tristate '"DSCP" and "TOS" target support'
  1190. + depends on IP_NF_MANGLE || IP6_NF_MANGLE
  1191. + depends on NETFILTER_ADVANCED
  1192. + help
  1193. + This option adds a `DSCP' target, which allows you to manipulate
  1194. + the IPv4/IPv6 header DSCP field (differentiated services codepoint).
  1195. +
  1196. + The DSCP field can have any value between 0x0 and 0x3f inclusive.
  1197. +
  1198. + It also adds the "TOS" target, which allows you to create rules in
  1199. + the "mangle" table which alter the Type Of Service field of an IPv4
  1200. + or the Priority field of an IPv6 packet, prior to routing.
  1201. +
  1202. + To compile it as a module, choose M here. If unsure, say N.
  1203. +
  1204. +config NETFILTER_XT_TARGET_HL
  1205. + tristate '"HL" hoplimit target support'
  1206. + depends on IP_NF_MANGLE || IP6_NF_MANGLE
  1207. + depends on NETFILTER_ADVANCED
  1208. + ---help---
  1209. + This option adds the "HL" (for IPv6) and "TTL" (for IPv4)
  1210. + targets, which enable the user to change the
  1211. + hoplimit/time-to-live value of the IP header.
  1212. +
  1213. + While it is safe to decrement the hoplimit/TTL value, the
  1214. + modules also allow to increment and set the hoplimit value of
  1215. + the header to arbitrary values. This is EXTREMELY DANGEROUS
  1216. + since you can easily create immortal packets that loop
  1217. + forever on the network.
  1218. +
  1219. +config NETFILTER_XT_TARGET_LED
  1220. + tristate '"LED" target support'
  1221. + depends on LEDS_CLASS && LEDS_TRIGGERS
  1222. + depends on NETFILTER_ADVANCED
  1223. + help
  1224. + This option adds a `LED' target, which allows you to blink LEDs in
  1225. + response to particular packets passing through your machine.
  1226. +
  1227. + This can be used to turn a spare LED into a network activity LED,
  1228. + which only flashes in response to FTP transfers, for example. Or
  1229. + you could have an LED which lights up for a minute or two every time
  1230. + somebody connects to your machine via SSH.
  1231. +
  1232. + You will need support for the "led" class to make this work.
  1233. +
  1234. + To create an LED trigger for incoming SSH traffic:
  1235. + iptables -A INPUT -p tcp --dport 22 -j LED --led-trigger-id ssh --led-delay 1000
  1236. +
  1237. + Then attach the new trigger to an LED on your system:
  1238. + echo netfilter-ssh > /sys/class/leds/<ledname>/trigger
  1239. +
  1240. + For more information on the LEDs available on your system, see
  1241. + Documentation/leds-class.txt
  1242. +
  1243. +config NETFILTER_XT_TARGET_MARK
  1244. + tristate '"MARK" target support'
  1245. + default m if NETFILTER_ADVANCED=n
  1246. + help
  1247. + This option adds a `MARK' target, which allows you to create rules
  1248. + in the `mangle' table which alter the netfilter mark (nfmark) field
  1249. + associated with the packet prior to routing. This can change
  1250. + the routing method (see `Use netfilter MARK value as routing
  1251. + key') and can also be used by other subsystems to change their
  1252. + behavior.
  1253. +
  1254. + To compile it as a module, choose M here. If unsure, say N.
  1255. +
  1256. +config NETFILTER_XT_TARGET_NFLOG
  1257. + tristate '"NFLOG" target support'
  1258. + default m if NETFILTER_ADVANCED=n
  1259. + select NETFILTER_NETLINK_LOG
  1260. + help
  1261. + This option enables the NFLOG target, which allows to LOG
  1262. + messages through nfnetlink_log.
  1263. +
  1264. + To compile it as a module, choose M here. If unsure, say N.
  1265. +
  1266. +config NETFILTER_XT_TARGET_NFQUEUE
  1267. + tristate '"NFQUEUE" target Support'
  1268. + depends on NETFILTER_ADVANCED
  1269. + help
  1270. + This target replaced the old obsolete QUEUE target.
  1271. +
  1272. + As opposed to QUEUE, it supports 65535 different queues,
  1273. + not just one.
  1274. +
  1275. + To compile it as a module, choose M here. If unsure, say N.
  1276. +
  1277. +config NETFILTER_XT_TARGET_NOTRACK
  1278. + tristate '"NOTRACK" target support'
  1279. + depends on IP_NF_RAW || IP6_NF_RAW
  1280. + depends on NF_CONNTRACK
  1281. + depends on NETFILTER_ADVANCED
  1282. + help
  1283. + The NOTRACK target allows a select rule to specify
  1284. + which packets *not* to enter the conntrack/NAT
  1285. + subsystem with all the consequences (no ICMP error tracking,
  1286. + no protocol helpers for the selected packets).
  1287. +
  1288. + If you want to compile it as a module, say M here and read
  1289. + <file:Documentation/kbuild/modules.txt>. If unsure, say `N'.
  1290. +
  1291. +config NETFILTER_XT_TARGET_RATEEST
  1292. + tristate '"RATEEST" target support'
  1293. + depends on NETFILTER_ADVANCED
  1294. + help
  1295. + This option adds a `RATEEST' target, which allows to measure
  1296. + rates similar to TC estimators. The `rateest' match can be
  1297. + used to match on the measured rates.
  1298. +
  1299. + To compile it as a module, choose M here. If unsure, say N.
  1300. +
  1301. +config NETFILTER_XT_TARGET_TPROXY
  1302. + tristate '"TPROXY" target support (EXPERIMENTAL)'
  1303. + depends on EXPERIMENTAL
  1304. + depends on NETFILTER_TPROXY
  1305. + depends on NETFILTER_XTABLES
  1306. + depends on NETFILTER_ADVANCED
  1307. + select NF_DEFRAG_IPV4
  1308. + help
  1309. + This option adds a `TPROXY' target, which is somewhat similar to
  1310. + REDIRECT. It can only be used in the mangle table and is useful
  1311. + to redirect traffic to a transparent proxy. It does _not_ depend
  1312. + on Netfilter connection tracking and NAT, unlike REDIRECT.
  1313. +
  1314. + To compile it as a module, choose M here. If unsure, say N.
  1315. +
  1316. +config NETFILTER_XT_TARGET_TRACE
  1317. + tristate '"TRACE" target support'
  1318. + depends on IP_NF_RAW || IP6_NF_RAW
  1319. + depends on NETFILTER_ADVANCED
  1320. + help
  1321. + The TRACE target allows you to mark packets so that the kernel
  1322. + will log every rule which match the packets as those traverse
  1323. + the tables, chains, rules.
  1324. +
  1325. + If you want to compile it as a module, say M here and read
  1326. + <file:Documentation/kbuild/modules.txt>. If unsure, say `N'.
  1327. +
  1328. +config NETFILTER_XT_TARGET_SECMARK
  1329. + tristate '"SECMARK" target support'
  1330. + depends on NETWORK_SECMARK
  1331. + default m if NETFILTER_ADVANCED=n
  1332. + help
  1333. + The SECMARK target allows security marking of network
  1334. + packets, for use with security subsystems.
  1335. +
  1336. + To compile it as a module, choose M here. If unsure, say N.
  1337. +
  1338. +config NETFILTER_XT_TARGET_TCPMSS
  1339. + tristate '"TCPMSS" target support'
  1340. + depends on (IPV6 || IPV6=n)
  1341. + default m if NETFILTER_ADVANCED=n
  1342. + ---help---
  1343. + This option adds a `TCPMSS' target, which allows you to alter the
  1344. + MSS value of TCP SYN packets, to control the maximum size for that
  1345. + connection (usually limiting it to your outgoing interface's MTU
  1346. + minus 40).
  1347. +
  1348. + This is used to overcome criminally braindead ISPs or servers which
  1349. + block ICMP Fragmentation Needed packets. The symptoms of this
  1350. + problem are that everything works fine from your Linux
  1351. + firewall/router, but machines behind it can never exchange large
  1352. + packets:
  1353. + 1) Web browsers connect, then hang with no data received.
  1354. + 2) Small mail works fine, but large emails hang.
  1355. + 3) ssh works fine, but scp hangs after initial handshaking.
  1356. +
  1357. + Workaround: activate this option and add a rule to your firewall
  1358. + configuration like:
  1359. +
  1360. + iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN \
  1361. + -j TCPMSS --clamp-mss-to-pmtu
  1362. +
  1363. + To compile it as a module, choose M here. If unsure, say N.
  1364. +
  1365. +config NETFILTER_XT_TARGET_TCPOPTSTRIP
  1366. + tristate '"TCPOPTSTRIP" target support (EXPERIMENTAL)'
  1367. + depends on EXPERIMENTAL
  1368. + depends on IP_NF_MANGLE || IP6_NF_MANGLE
  1369. + depends on NETFILTER_ADVANCED
  1370. + help
  1371. + This option adds a "TCPOPTSTRIP" target, which allows you to strip
  1372. + TCP options from TCP packets.
  1373. +
  1374. +config NETFILTER_XT_MATCH_CLUSTER
  1375. + tristate '"cluster" match support'
  1376. + depends on NF_CONNTRACK
  1377. + depends on NETFILTER_ADVANCED
  1378. + ---help---
  1379. + This option allows you to build work-load-sharing clusters of
  1380. + network servers/stateful firewalls without having a dedicated
  1381. + load-balancing router/server/switch. Basically, this match returns
  1382. + true when the packet must be handled by this cluster node. Thus,
  1383. + all nodes see all packets and this match decides which node handles
  1384. + what packets. The work-load sharing algorithm is based on source
  1385. + address hashing.
  1386. +
  1387. + If you say Y or M here, try `iptables -m cluster --help` for
  1388. + more information.
  1389. +
  1390. +config NETFILTER_XT_MATCH_COMMENT
  1391. + tristate '"comment" match support'
  1392. + depends on NETFILTER_ADVANCED
  1393. + help
  1394. + This option adds a `comment' dummy-match, which allows you to put
  1395. + comments in your iptables ruleset.
  1396. +
  1397. + If you want to compile it as a module, say M here and read
  1398. + <file:Documentation/kbuild/modules.txt>. If unsure, say `N'.
  1399. +
  1400. +config NETFILTER_XT_MATCH_CONNBYTES
  1401. + tristate '"connbytes" per-connection counter match support'
  1402. + depends on NF_CONNTRACK
  1403. + depends on NETFILTER_ADVANCED
  1404. + select NF_CT_ACCT
  1405. + help
  1406. + This option adds a `connbytes' match, which allows you to match the
  1407. + number of bytes and/or packets for each direction within a connection.
  1408. +
  1409. + If you want to compile it as a module, say M here and read
  1410. + <file:Documentation/kbuild/modules.txt>. If unsure, say `N'.
  1411. +
  1412. +config NETFILTER_XT_MATCH_CONNLIMIT
  1413. + tristate '"connlimit" match support"'
  1414. + depends on NF_CONNTRACK
  1415. + depends on NETFILTER_ADVANCED
  1416. + ---help---
  1417. + This match allows you to match against the number of parallel
  1418. + connections to a server per client IP address (or address block).
  1419. +
  1420. +config NETFILTER_XT_MATCH_CONNMARK
  1421. + tristate '"connmark" connection mark match support'
  1422. + depends on NF_CONNTRACK
  1423. + depends on NETFILTER_ADVANCED
  1424. + select NF_CONNTRACK_MARK
  1425. + help
  1426. + This option adds a `connmark' match, which allows you to match the
  1427. + connection mark value previously set for the session by `CONNMARK'.
  1428. +
  1429. + If you want to compile it as a module, say M here and read
  1430. + <file:Documentation/kbuild/modules.txt>. The module will be called
  1431. + ipt_connmark. If unsure, say `N'.
  1432. +
  1433. +config NETFILTER_XT_MATCH_CONNTRACK
  1434. + tristate '"conntrack" connection tracking match support'
  1435. + depends on NF_CONNTRACK
  1436. + default m if NETFILTER_ADVANCED=n
  1437. + help
  1438. + This is a general conntrack match module, a superset of the state match.
  1439. +
  1440. + It allows matching on additional conntrack information, which is
  1441. + useful in complex configurations, such as NAT gateways with multiple
  1442. + internet links or tunnels.
  1443. +
  1444. + To compile it as a module, choose M here. If unsure, say N.
  1445. +
  1446. +config NETFILTER_XT_MATCH_DCCP
  1447. + tristate '"dccp" protocol match support'
  1448. + depends on NETFILTER_ADVANCED
  1449. + default IP_DCCP
  1450. + help
  1451. + With this option enabled, you will be able to use the iptables
  1452. + `dccp' match in order to match on DCCP source/destination ports
  1453. + and DCCP flags.
  1454. +
  1455. + If you want to compile it as a module, say M here and read
  1456. + <file:Documentation/kbuild/modules.txt>. If unsure, say `N'.
  1457. +
  1458. +config NETFILTER_XT_MATCH_DSCP
  1459. + tristate '"dscp" and "tos" match support'
  1460. + depends on NETFILTER_ADVANCED
  1461. + help
  1462. + This option adds a `DSCP' match, which allows you to match against
  1463. + the IPv4/IPv6 header DSCP field (differentiated services codepoint).
  1464. +
  1465. + The DSCP field can have any value between 0x0 and 0x3f inclusive.
  1466. +
  1467. + It will also add a "tos" match, which allows you to match packets
  1468. + based on the Type Of Service fields of the IPv4 packet (which share
  1469. + the same bits as DSCP).
  1470. +
  1471. + To compile it as a module, choose M here. If unsure, say N.
  1472. +
  1473. +config NETFILTER_XT_MATCH_ESP
  1474. + tristate '"esp" match support'
  1475. + depends on NETFILTER_ADVANCED
  1476. + help
  1477. + This match extension allows you to match a range of SPIs
  1478. + inside ESP header of IPSec packets.
  1479. +
  1480. + To compile it as a module, choose M here. If unsure, say N.
  1481. +
  1482. +config NETFILTER_XT_MATCH_HASHLIMIT
  1483. + tristate '"hashlimit" match support'
  1484. + depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
  1485. + depends on NETFILTER_ADVANCED
  1486. + help
  1487. + This option adds a `hashlimit' match.
  1488. +
  1489. + As opposed to `limit', this match dynamically creates a hash table
  1490. + of limit buckets, based on your selection of source/destination
  1491. + addresses and/or ports.
  1492. +
  1493. + It enables you to express policies like `10kpps for any given
  1494. + destination address' or `500pps from any given source address'
  1495. + with a single rule.
  1496. +
  1497. +config NETFILTER_XT_MATCH_HELPER
  1498. + tristate '"helper" match support'
  1499. + depends on NF_CONNTRACK
  1500. + depends on NETFILTER_ADVANCED
  1501. + help
  1502. + Helper matching allows you to match packets in dynamic connections
  1503. + tracked by a conntrack-helper, ie. ip_conntrack_ftp
  1504. +
  1505. + To compile it as a module, choose M here. If unsure, say Y.
  1506. +
  1507. +config NETFILTER_XT_MATCH_HL
  1508. + tristate '"hl" hoplimit/TTL match support'
  1509. + depends on NETFILTER_ADVANCED
  1510. + ---help---
  1511. + HL matching allows you to match packets based on the hoplimit
  1512. + in the IPv6 header, or the time-to-live field in the IPv4
  1513. + header of the packet.
  1514. +
  1515. +config NETFILTER_XT_MATCH_IPRANGE
  1516. + tristate '"iprange" address range match support'
  1517. + depends on NETFILTER_ADVANCED
  1518. + ---help---
  1519. + This option adds a "iprange" match, which allows you to match based on
  1520. + an IP address range. (Normal iptables only matches on single addresses
  1521. + with an optional mask.)
  1522. +
  1523. + If unsure, say M.
  1524. +
  1525. +config NETFILTER_XT_MATCH_LENGTH
  1526. + tristate '"length" match support'
  1527. + depends on NETFILTER_ADVANCED
  1528. + help
  1529. + This option allows you to match the length of a packet against a
  1530. + specific value or range of values.
  1531. +
  1532. + To compile it as a module, choose M here. If unsure, say N.
  1533. +
  1534. +config NETFILTER_XT_MATCH_LIMIT
  1535. + tristate '"limit" match support'
  1536. + depends on NETFILTER_ADVANCED
  1537. + help
  1538. + limit matching allows you to control the rate at which a rule can be
  1539. + matched: mainly useful in combination with the LOG target ("LOG
  1540. + target support", below) and to avoid some Denial of Service attacks.
  1541. +
  1542. + To compile it as a module, choose M here. If unsure, say N.
  1543. +
  1544. +config NETFILTER_XT_MATCH_MAC
  1545. + tristate '"mac" address match support'
  1546. + depends on NETFILTER_ADVANCED
  1547. + help
  1548. + MAC matching allows you to match packets based on the source
  1549. + Ethernet address of the packet.
  1550. +
  1551. + To compile it as a module, choose M here. If unsure, say N.
  1552. +
  1553. +config NETFILTER_XT_MATCH_MARK
  1554. + tristate '"mark" match support'
  1555. + default m if NETFILTER_ADVANCED=n
  1556. + help
  1557. + Netfilter mark matching allows you to match packets based on the
  1558. + `nfmark' value in the packet. This can be set by the MARK target
  1559. + (see below).
  1560. +
  1561. + To compile it as a module, choose M here. If unsure, say N.
  1562. +
  1563. +config NETFILTER_XT_MATCH_MULTIPORT
  1564. + tristate '"multiport" Multiple port match support'
  1565. + depends on NETFILTER_ADVANCED
  1566. + help
  1567. + Multiport matching allows you to match TCP or UDP packets based on
  1568. + a series of source or destination ports: normally a rule can only
  1569. + match a single range of ports.
  1570. +
  1571. + To compile it as a module, choose M here. If unsure, say N.
  1572. +
  1573. +config NETFILTER_XT_MATCH_OWNER
  1574. + tristate '"owner" match support'
  1575. + depends on NETFILTER_ADVANCED
  1576. + ---help---
  1577. + Socket owner matching allows you to match locally-generated packets
  1578. + based on who created the socket: the user or group. It is also
  1579. + possible to check whether a socket actually exists.
  1580. +
  1581. +config NETFILTER_XT_MATCH_POLICY
  1582. + tristate 'IPsec "policy" match support'
  1583. + depends on XFRM
  1584. + default m if NETFILTER_ADVANCED=n
  1585. + help
  1586. + Policy matching allows you to match packets based on the
  1587. + IPsec policy that was used during decapsulation/will
  1588. + be used during encapsulation.
  1589. +
  1590. + To compile it as a module, choose M here. If unsure, say N.
  1591. +
  1592. +config NETFILTER_XT_MATCH_PHYSDEV
  1593. + tristate '"physdev" match support'
  1594. + depends on BRIDGE && BRIDGE_NETFILTER
  1595. + depends on NETFILTER_ADVANCED
  1596. + help
  1597. + Physdev packet matching matches against the physical bridge ports
  1598. + the IP packet arrived on or will leave by.
  1599. +
  1600. + To compile it as a module, choose M here. If unsure, say N.
  1601. +
  1602. +config NETFILTER_XT_MATCH_PKTTYPE
  1603. + tristate '"pkttype" packet type match support'
  1604. + depends on NETFILTER_ADVANCED
  1605. + help
  1606. + Packet type matching allows you to match a packet by
  1607. + its "class", eg. BROADCAST, MULTICAST, ...
  1608. +
  1609. + Typical usage:
  1610. + iptables -A INPUT -m pkttype --pkt-type broadcast -j LOG
  1611. +
  1612. + To compile it as a module, choose M here. If unsure, say N.
  1613. +
  1614. +config NETFILTER_XT_MATCH_QUOTA
  1615. + tristate '"quota" match support'
  1616. + depends on NETFILTER_ADVANCED
  1617. + help
  1618. + This option adds a `quota' match, which allows to match on a
  1619. + byte counter.
  1620. +
  1621. + If you want to compile it as a module, say M here and read
  1622. + <file:Documentation/kbuild/modules.txt>. If unsure, say `N'.
  1623. +
  1624. +config NETFILTER_XT_MATCH_RATEEST
  1625. + tristate '"rateest" match support'
  1626. + depends on NETFILTER_ADVANCED
  1627. + select NETFILTER_XT_TARGET_RATEEST
  1628. + help
  1629. + This option adds a `rateest' match, which allows to match on the
  1630. + rate estimated by the RATEEST target.
  1631. +
  1632. + To compile it as a module, choose M here. If unsure, say N.
  1633. +
  1634. +config NETFILTER_XT_MATCH_REALM
  1635. + tristate '"realm" match support'
  1636. + depends on NETFILTER_ADVANCED
  1637. + select NET_CLS_ROUTE
  1638. + help
  1639. + This option adds a `realm' match, which allows you to use the realm
  1640. + key from the routing subsystem inside iptables.
  1641. +
  1642. + This match pretty much resembles the CONFIG_NET_CLS_ROUTE4 option
  1643. + in tc world.
  1644. +
  1645. + If you want to compile it as a module, say M here and read
  1646. + <file:Documentation/kbuild/modules.txt>. If unsure, say `N'.
  1647. +
  1648. +config NETFILTER_XT_MATCH_RECENT
  1649. + tristate '"recent" match support'
  1650. + depends on NETFILTER_ADVANCED
  1651. + ---help---
  1652. + This match is used for creating one or many lists of recently
  1653. + used addresses and then matching against that/those list(s).
  1654. +
  1655. + Short options are available by using 'iptables -m recent -h'
  1656. + Official Website: <http://snowman.net/projects/ipt_recent/>
  1657. +
  1658. +config NETFILTER_XT_MATCH_RECENT_PROC_COMPAT
  1659. + bool 'Enable obsolete /proc/net/ipt_recent'
  1660. + depends on NETFILTER_XT_MATCH_RECENT && PROC_FS
  1661. + ---help---
  1662. + This option enables the old /proc/net/ipt_recent interface,
  1663. + which has been obsoleted by /proc/net/xt_recent.
  1664. +
  1665. +config NETFILTER_XT_MATCH_SCTP
  1666. + tristate '"sctp" protocol match support (EXPERIMENTAL)'
  1667. + depends on EXPERIMENTAL
  1668. + depends on NETFILTER_ADVANCED
  1669. + default IP_SCTP
  1670. + help
  1671. + With this option enabled, you will be able to use the
  1672. + `sctp' match in order to match on SCTP source/destination ports
  1673. + and SCTP chunk types.
  1674. +
  1675. + If you want to compile it as a module, say M here and read
  1676. + <file:Documentation/kbuild/modules.txt>. If unsure, say `N'.
  1677. +
  1678. +config NETFILTER_XT_MATCH_SOCKET
  1679. + tristate '"socket" match support (EXPERIMENTAL)'
  1680. + depends on EXPERIMENTAL
  1681. + depends on NETFILTER_TPROXY
  1682. + depends on NETFILTER_XTABLES
  1683. + depends on NETFILTER_ADVANCED
  1684. + depends on !NF_CONNTRACK || NF_CONNTRACK
  1685. + select NF_DEFRAG_IPV4
  1686. + help
  1687. + This option adds a `socket' match, which can be used to match
  1688. + packets for which a TCP or UDP socket lookup finds a valid socket.
  1689. + It can be used in combination with the MARK target and policy
  1690. + routing to implement full featured non-locally bound sockets.
  1691. +
  1692. + To compile it as a module, choose M here. If unsure, say N.
  1693. +
  1694. +config NETFILTER_XT_MATCH_STATE
  1695. + tristate '"state" match support'
  1696. + depends on NF_CONNTRACK
  1697. + default m if NETFILTER_ADVANCED=n
  1698. + help
  1699. + Connection state matching allows you to match packets based on their
  1700. + relationship to a tracked connection (ie. previous packets). This
  1701. + is a powerful tool for packet classification.
  1702. +
  1703. + To compile it as a module, choose M here. If unsure, say N.
  1704. +
  1705. +config NETFILTER_XT_MATCH_STATISTIC
  1706. + tristate '"statistic" match support'
  1707. + depends on NETFILTER_ADVANCED
  1708. + help
  1709. + This option adds a `statistic' match, which allows you to match
  1710. + on packets periodically or randomly with a given percentage.
  1711. +
  1712. + To compile it as a module, choose M here. If unsure, say N.
  1713. +
  1714. +config NETFILTER_XT_MATCH_STRING
  1715. + tristate '"string" match support'
  1716. + depends on NETFILTER_ADVANCED
  1717. + select TEXTSEARCH
  1718. + select TEXTSEARCH_KMP
  1719. + select TEXTSEARCH_BM
  1720. + select TEXTSEARCH_FSM
  1721. + help
  1722. + This option adds a `string' match, which allows you to look for
  1723. + pattern matchings in packets.
  1724. +
  1725. + To compile it as a module, choose M here. If unsure, say N.
  1726. +
  1727. +config NETFILTER_XT_MATCH_TCPMSS
  1728. + tristate '"tcpmss" match support'
  1729. + depends on NETFILTER_ADVANCED
  1730. + help
  1731. + This option adds a `tcpmss' match, which allows you to examine the
  1732. + MSS value of TCP SYN packets, which control the maximum packet size
  1733. + for that connection.
  1734. +
  1735. + To compile it as a module, choose M here. If unsure, say N.
  1736. +
  1737. +config NETFILTER_XT_MATCH_TIME
  1738. + tristate '"time" match support'
  1739. + depends on NETFILTER_ADVANCED
  1740. + ---help---
  1741. + This option adds a "time" match, which allows you to match based on
  1742. + the packet arrival time (at the machine which netfilter is running)
  1743. + on) or departure time/date (for locally generated packets).
  1744. +
  1745. + If you say Y here, try `iptables -m time --help` for
  1746. + more information.
  1747. +
  1748. + If you want to compile it as a module, say M here.
  1749. + If unsure, say N.
  1750. +
  1751. +config NETFILTER_XT_MATCH_U32
  1752. + tristate '"u32" match support'
  1753. + depends on NETFILTER_ADVANCED
  1754. + ---help---
  1755. + u32 allows you to extract quantities of up to 4 bytes from a packet,
  1756. + AND them with specified masks, shift them by specified amounts and
  1757. + test whether the results are in any of a set of specified ranges.
  1758. + The specification of what to extract is general enough to skip over
  1759. + headers with lengths stored in the packet, as in IP or TCP header
  1760. + lengths.
  1761. +
  1762. + Details and examples are in the kernel module source.
  1763. +
  1764. +config NETFILTER_XT_MATCH_OSF
  1765. + tristate '"osf" Passive OS fingerprint match'
  1766. + depends on NETFILTER_ADVANCED && NETFILTER_NETLINK
  1767. + help
  1768. + This option selects the Passive OS Fingerprinting match module
  1769. + that allows to passively match the remote operating system by
  1770. + analyzing incoming TCP SYN packets.
  1771. +
  1772. + Rules and loading software can be downloaded from
  1773. + http://www.ioremap.net/projects/osf
  1774. +
  1775. + To compile it as a module, choose M here. If unsure, say N.
  1776. +
  1777. +endif # NETFILTER_XTABLES
  1778. +
  1779. +endmenu
  1780. +
  1781. +source "net/netfilter/ipvs/Kconfig"
  1782. diff -Nur linux-2.6.33.orig/net/netfilter/Makefile linux-2.6.33/net/netfilter/Makefile
  1783. --- linux-2.6.33.orig/net/netfilter/Makefile 2010-02-24 19:52:17.000000000 +0100
  1784. +++ linux-2.6.33/net/netfilter/Makefile 2010-04-25 01:09:20.000000000 +0200
  1785. @@ -33,6 +33,7 @@
  1786. obj-$(CONFIG_NF_CONNTRACK_SANE) += nf_conntrack_sane.o
  1787. obj-$(CONFIG_NF_CONNTRACK_SIP) += nf_conntrack_sip.o
  1788. obj-$(CONFIG_NF_CONNTRACK_TFTP) += nf_conntrack_tftp.o
  1789. +obj-$(CONFIG_NF_CONNTRACK_RTSP) += nf_conntrack_rtsp.o
  1790. # transparent proxy support
  1791. obj-$(CONFIG_NETFILTER_TPROXY) += nf_tproxy_core.o
  1792. diff -Nur linux-2.6.33.orig/net/netfilter/nf_conntrack_rtsp.c linux-2.6.33/net/netfilter/nf_conntrack_rtsp.c
  1793. --- linux-2.6.33.orig/net/netfilter/nf_conntrack_rtsp.c 1970-01-01 01:00:00.000000000 +0100
  1794. +++ linux-2.6.33/net/netfilter/nf_conntrack_rtsp.c 2010-04-25 01:09:20.000000000 +0200
  1795. @@ -0,0 +1,517 @@
  1796. +/*
  1797. + * RTSP extension for IP connection tracking
  1798. + * (C) 2003 by Tom Marshall <tmarshall at real.com>
  1799. + * based on ip_conntrack_irc.c
  1800. + *
  1801. + * This program is free software; you can redistribute it and/or
  1802. + * modify it under the terms of the GNU General Public License
  1803. + * as published by the Free Software Foundation; either version
  1804. + * 2 of the License, or (at your option) any later version.
  1805. + *
  1806. + * Module load syntax:
  1807. + * insmod nf_conntrack_rtsp.o ports=port1,port2,...port<MAX_PORTS>
  1808. + * max_outstanding=n setup_timeout=secs
  1809. + *
  1810. + * If no ports are specified, the default will be port 554.
  1811. + *
  1812. + * With max_outstanding you can define the maximum number of not yet
  1813. + * answered SETUP requests per RTSP session (default 8).
  1814. + * With setup_timeout you can specify how long the system waits for
  1815. + * an expected data channel (default 300 seconds).
  1816. + *
  1817. + * 2005-02-13: Harald Welte <laforge at netfilter.org>
  1818. + * - port to 2.6
  1819. + * - update to recent post-2.6.11 api changes
  1820. + * 2006-09-14: Steven Van Acker <deepstar at singularity.be>
  1821. + * - removed calls to NAT code from conntrack helper: NAT no longer needed to use rtsp-conntrack
  1822. + * 2007-04-18: Michael Guntsche <mike at it-loops.com>
  1823. + * - Port to new NF API
  1824. + */
  1825. +
  1826. +#include <linux/module.h>
  1827. +#include <linux/netfilter.h>
  1828. +#include <linux/ip.h>
  1829. +#include <linux/inet.h>
  1830. +#include <net/tcp.h>
  1831. +
  1832. +#include <net/netfilter/nf_conntrack.h>
  1833. +#include <net/netfilter/nf_conntrack_expect.h>
  1834. +#include <net/netfilter/nf_conntrack_helper.h>
  1835. +#include <linux/netfilter/nf_conntrack_rtsp.h>
  1836. +
  1837. +#define NF_NEED_STRNCASECMP
  1838. +#define NF_NEED_STRTOU16
  1839. +#define NF_NEED_STRTOU32
  1840. +#define NF_NEED_NEXTLINE
  1841. +#include <linux/netfilter_helpers.h>
  1842. +#define NF_NEED_MIME_NEXTLINE
  1843. +#include <linux/netfilter_mime.h>
  1844. +
  1845. +#include <linux/ctype.h>
  1846. +#define MAX_SIMUL_SETUP 8 /* XXX: use max_outstanding */
  1847. +#define INFOP(fmt, args...) printk(KERN_INFO "%s: %s: " fmt, __FILE__, __FUNCTION__ , ## args)
  1848. +#if 0
  1849. +#define DEBUGP(fmt, args...) printk(KERN_DEBUG "%s: %s: " fmt, __FILE__, __FUNCTION__ , ## args)
  1850. +#else
  1851. +#define DEBUGP(fmt, args...)
  1852. +#endif
  1853. +
  1854. +#define MAX_PORTS 8
  1855. +static int ports[MAX_PORTS];
  1856. +static int num_ports = 0;
  1857. +static int max_outstanding = 8;
  1858. +static unsigned int setup_timeout = 300;
  1859. +
  1860. +MODULE_AUTHOR("Tom Marshall <tmarshall at real.com>");
  1861. +MODULE_DESCRIPTION("RTSP connection tracking module");
  1862. +MODULE_LICENSE("GPL");
  1863. +module_param_array(ports, int, &num_ports, 0400);
  1864. +MODULE_PARM_DESC(ports, "port numbers of RTSP servers");
  1865. +module_param(max_outstanding, int, 0400);
  1866. +MODULE_PARM_DESC(max_outstanding, "max number of outstanding SETUP requests per RTSP session");
  1867. +module_param(setup_timeout, int, 0400);
  1868. +MODULE_PARM_DESC(setup_timeout, "timeout on for unestablished data channels");
  1869. +
  1870. +static char *rtsp_buffer;
  1871. +static DEFINE_SPINLOCK(rtsp_buffer_lock);
  1872. +
  1873. +unsigned int (*nf_nat_rtsp_hook)(struct sk_buff *skb,
  1874. + enum ip_conntrack_info ctinfo,
  1875. + unsigned int matchoff, unsigned int matchlen,struct ip_ct_rtsp_expect* prtspexp,
  1876. + struct nf_conntrack_expect *exp);
  1877. +void (*nf_nat_rtsp_hook_expectfn)(struct nf_conn *ct, struct nf_conntrack_expect *exp);
  1878. +
  1879. +EXPORT_SYMBOL_GPL(nf_nat_rtsp_hook);
  1880. +
  1881. +/*
  1882. + * Max mappings we will allow for one RTSP connection (for RTP, the number
  1883. + * of allocated ports is twice this value). Note that SMIL burns a lot of
  1884. + * ports so keep this reasonably high. If this is too low, you will see a
  1885. + * lot of "no free client map entries" messages.
  1886. + */
  1887. +#define MAX_PORT_MAPS 16
  1888. +
  1889. +/*** default port list was here in the masq code: 554, 3030, 4040 ***/
  1890. +
  1891. +#define SKIP_WSPACE(ptr,len,off) while(off < len && isspace(*(ptr+off))) { off++; }
  1892. +
  1893. +/*
  1894. + * Parse an RTSP packet.
  1895. + *
  1896. + * Returns zero if parsing failed.
  1897. + *
  1898. + * Parameters:
  1899. + * IN ptcp tcp data pointer
  1900. + * IN tcplen tcp data len
  1901. + * IN/OUT ptcpoff points to current tcp offset
  1902. + * OUT phdrsoff set to offset of rtsp headers
  1903. + * OUT phdrslen set to length of rtsp headers
  1904. + * OUT pcseqoff set to offset of CSeq header
  1905. + * OUT pcseqlen set to length of CSeq header
  1906. + */
  1907. +static int
  1908. +rtsp_parse_message(char* ptcp, uint tcplen, uint* ptcpoff,
  1909. + uint* phdrsoff, uint* phdrslen,
  1910. + uint* pcseqoff, uint* pcseqlen,
  1911. + uint* transoff, uint* translen)
  1912. +{
  1913. + uint entitylen = 0;
  1914. + uint lineoff;
  1915. + uint linelen;
  1916. +
  1917. + if (!nf_nextline(ptcp, tcplen, ptcpoff, &lineoff, &linelen))
  1918. + return 0;
  1919. +
  1920. + *phdrsoff = *ptcpoff;
  1921. + while (nf_mime_nextline(ptcp, tcplen, ptcpoff, &lineoff, &linelen)) {
  1922. + if (linelen == 0) {
  1923. + if (entitylen > 0)
  1924. + *ptcpoff += min(entitylen, tcplen - *ptcpoff);
  1925. + break;
  1926. + }
  1927. + if (lineoff+linelen > tcplen) {
  1928. + INFOP("!! overrun !!\n");
  1929. + break;
  1930. + }
  1931. +
  1932. + if (nf_strncasecmp(ptcp+lineoff, "CSeq:", 5) == 0) {
  1933. + *pcseqoff = lineoff;
  1934. + *pcseqlen = linelen;
  1935. + }
  1936. +
  1937. + if (nf_strncasecmp(ptcp+lineoff, "Transport:", 10) == 0) {
  1938. + *transoff = lineoff;
  1939. + *translen = linelen;
  1940. + }
  1941. +
  1942. + if (nf_strncasecmp(ptcp+lineoff, "Content-Length:", 15) == 0) {
  1943. + uint off = lineoff+15;
  1944. + SKIP_WSPACE(ptcp+lineoff, linelen, off);
  1945. + nf_strtou32(ptcp+off, &entitylen);
  1946. + }
  1947. + }
  1948. + *phdrslen = (*ptcpoff) - (*phdrsoff);
  1949. +
  1950. + return 1;
  1951. +}
  1952. +
  1953. +/*
  1954. + * Find lo/hi client ports (if any) in transport header
  1955. + * In:
  1956. + * ptcp, tcplen = packet
  1957. + * tranoff, tranlen = buffer to search
  1958. + *
  1959. + * Out:
  1960. + * pport_lo, pport_hi = lo/hi ports (host endian)
  1961. + *
  1962. + * Returns nonzero if any client ports found
  1963. + *
  1964. + * Note: it is valid (and expected) for the client to request multiple
  1965. + * transports, so we need to parse the entire line.
  1966. + */
  1967. +static int
  1968. +rtsp_parse_transport(char* ptran, uint tranlen,
  1969. + struct ip_ct_rtsp_expect* prtspexp)
  1970. +{
  1971. + int rc = 0;
  1972. + uint off = 0;
  1973. +
  1974. + if (tranlen < 10 || !iseol(ptran[tranlen-1]) ||
  1975. + nf_strncasecmp(ptran, "Transport:", 10) != 0) {
  1976. + INFOP("sanity check failed\n");
  1977. + return 0;
  1978. + }
  1979. +
  1980. + DEBUGP("tran='%.*s'\n", (int)tranlen, ptran);
  1981. + off += 10;
  1982. + SKIP_WSPACE(ptran, tranlen, off);
  1983. +
  1984. + /* Transport: tran;field;field=val,tran;field;field=val,... */
  1985. + while (off < tranlen) {
  1986. + const char* pparamend;
  1987. + uint nextparamoff;
  1988. +
  1989. + pparamend = memchr(ptran+off, ',', tranlen-off);
  1990. + pparamend = (pparamend == NULL) ? ptran+tranlen : pparamend+1;
  1991. + nextparamoff = pparamend-ptran;
  1992. +
  1993. + while (off < nextparamoff) {
  1994. + const char* pfieldend;
  1995. + uint nextfieldoff;
  1996. +
  1997. + pfieldend = memchr(ptran+off, ';', nextparamoff-off);
  1998. + nextfieldoff = (pfieldend == NULL) ? nextparamoff : pfieldend-ptran+1;
  1999. +
  2000. + if (strncmp(ptran+off, "client_port=", 12) == 0) {
  2001. + u_int16_t port;
  2002. + uint numlen;
  2003. +
  2004. + off += 12;
  2005. + numlen = nf_strtou16(ptran+off, &port);
  2006. + off += numlen;
  2007. + if (prtspexp->loport != 0 && prtspexp->loport != port)
  2008. + DEBUGP("multiple ports found, port %hu ignored\n", port);
  2009. + else {
  2010. + DEBUGP("lo port found : %hu\n", port);
  2011. + prtspexp->loport = prtspexp->hiport = port;
  2012. + if (ptran[off] == '-') {
  2013. + off++;
  2014. + numlen = nf_strtou16(ptran+off, &port);
  2015. + off += numlen;
  2016. + prtspexp->pbtype = pb_range;
  2017. + prtspexp->hiport = port;
  2018. +
  2019. + // If we have a range, assume rtp:
  2020. + // loport must be even, hiport must be loport+1
  2021. + if ((prtspexp->loport & 0x0001) != 0 ||
  2022. + prtspexp->hiport != prtspexp->loport+1) {
  2023. + DEBUGP("incorrect range: %hu-%hu, correcting\n",
  2024. + prtspexp->loport, prtspexp->hiport);
  2025. + prtspexp->loport &= 0xfffe;
  2026. + prtspexp->hiport = prtspexp->loport+1;
  2027. + }
  2028. + } else if (ptran[off] == '/') {
  2029. + off++;
  2030. + numlen = nf_strtou16(ptran+off, &port);
  2031. + off += numlen;
  2032. + prtspexp->pbtype = pb_discon;
  2033. + prtspexp->hiport = port;
  2034. + }
  2035. + rc = 1;
  2036. + }
  2037. + }
  2038. +
  2039. + /*
  2040. + * Note we don't look for the destination parameter here.
  2041. + * If we are using NAT, the NAT module will handle it. If not,
  2042. + * and the client is sending packets elsewhere, the expectation
  2043. + * will quietly time out.
  2044. + */
  2045. +
  2046. + off = nextfieldoff;
  2047. + }
  2048. +
  2049. + off = nextparamoff;
  2050. + }
  2051. +
  2052. + return rc;
  2053. +}
  2054. +
  2055. +void expected(struct nf_conn *ct, struct nf_conntrack_expect *exp)
  2056. +{
  2057. + if(nf_nat_rtsp_hook_expectfn) {
  2058. + nf_nat_rtsp_hook_expectfn(ct,exp);
  2059. + }
  2060. +}
  2061. +
  2062. +/*** conntrack functions ***/
  2063. +
  2064. +/* outbound packet: client->server */
  2065. +
  2066. +static inline int
  2067. +help_out(struct sk_buff *skb, unsigned char *rb_ptr, unsigned int datalen,
  2068. + struct nf_conn *ct, enum ip_conntrack_info ctinfo)
  2069. +{
  2070. + struct ip_ct_rtsp_expect expinfo;
  2071. +
  2072. + int dir = CTINFO2DIR(ctinfo); /* = IP_CT_DIR_ORIGINAL */
  2073. + //struct tcphdr* tcph = (void*)iph + iph->ihl * 4;
  2074. + //uint tcplen = pktlen - iph->ihl * 4;
  2075. + char* pdata = rb_ptr;
  2076. + //uint datalen = tcplen - tcph->doff * 4;
  2077. + uint dataoff = 0;
  2078. + int ret = NF_ACCEPT;
  2079. +
  2080. + struct nf_conntrack_expect *exp;
  2081. +
  2082. + __be16 be_loport;
  2083. +
  2084. + memset(&expinfo, 0, sizeof(expinfo));
  2085. +
  2086. + while (dataoff < datalen) {
  2087. + uint cmdoff = dataoff;
  2088. + uint hdrsoff = 0;
  2089. + uint hdrslen = 0;
  2090. + uint cseqoff = 0;
  2091. + uint cseqlen = 0;
  2092. + uint transoff = 0;
  2093. + uint translen = 0;
  2094. + uint off;
  2095. +
  2096. + if (!rtsp_parse_message(pdata, datalen, &dataoff,
  2097. + &hdrsoff, &hdrslen,
  2098. + &cseqoff, &cseqlen,
  2099. + &transoff, &translen))
  2100. + break; /* not a valid message */
  2101. +
  2102. + if (strncmp(pdata+cmdoff, "SETUP ", 6) != 0)
  2103. + continue; /* not a SETUP message */
  2104. + DEBUGP("found a setup message\n");
  2105. +
  2106. + off = 0;
  2107. + if(translen) {
  2108. + rtsp_parse_transport(pdata+transoff, translen, &expinfo);
  2109. + }
  2110. +
  2111. + if (expinfo.loport == 0) {
  2112. + DEBUGP("no udp transports found\n");
  2113. + continue; /* no udp transports found */
  2114. + }
  2115. +
  2116. + DEBUGP("udp transport found, ports=(%d,%hu,%hu)\n",
  2117. + (int)expinfo.pbtype, expinfo.loport, expinfo.hiport);
  2118. +
  2119. + exp = nf_ct_expect_alloc(ct);
  2120. + if (!exp) {
  2121. + ret = NF_DROP;
  2122. + goto out;
  2123. + }
  2124. +
  2125. + be_loport = htons(expinfo.loport);
  2126. +
  2127. + nf_ct_expect_init(exp, NF_CT_EXPECT_CLASS_DEFAULT,
  2128. + ct->tuplehash[!dir].tuple.src.l3num,
  2129. + &ct->tuplehash[!dir].tuple.src.u3, &ct->tuplehash[!dir].tuple.dst.u3,
  2130. + IPPROTO_UDP, NULL, &be_loport);
  2131. +
  2132. + exp->master = ct;
  2133. +
  2134. + exp->expectfn = expected;
  2135. + exp->flags = 0;
  2136. +
  2137. + if (expinfo.pbtype == pb_range) {
  2138. + DEBUGP("Changing expectation mask to handle multiple ports\n");
  2139. + exp->mask.src.u.udp.port = 0xfffe;
  2140. + }
  2141. +
  2142. + DEBUGP("expect_related %u.%u.%u.%u:%u-%u.%u.%u.%u:%u\n",
  2143. + NIPQUAD(exp->tuple.src.u3.ip),
  2144. + ntohs(exp->tuple.src.u.udp.port),
  2145. + NIPQUAD(exp->tuple.dst.u3.ip),
  2146. + ntohs(exp->tuple.dst.u.udp.port));
  2147. +
  2148. + if (nf_nat_rtsp_hook)
  2149. + /* pass the request off to the nat helper */
  2150. + ret = nf_nat_rtsp_hook(skb, ctinfo, hdrsoff, hdrslen, &expinfo, exp);
  2151. + else if (nf_ct_expect_related(exp) != 0) {
  2152. + INFOP("nf_ct_expect_related failed\n");
  2153. + ret = NF_DROP;
  2154. + }
  2155. + nf_ct_expect_put(exp);
  2156. + goto out;
  2157. + }
  2158. +out:
  2159. +
  2160. + return ret;
  2161. +}
  2162. +
  2163. +
  2164. +static inline int
  2165. +help_in(struct sk_buff *skb, size_t pktlen,
  2166. + struct nf_conn* ct, enum ip_conntrack_info ctinfo)
  2167. +{
  2168. + return NF_ACCEPT;
  2169. +}
  2170. +
  2171. +static int help(struct sk_buff *skb, unsigned int protoff,
  2172. + struct nf_conn *ct, enum ip_conntrack_info ctinfo)
  2173. +{
  2174. + struct tcphdr _tcph, *th;
  2175. + unsigned int dataoff, datalen;
  2176. + char *rb_ptr;
  2177. + int ret = NF_DROP;
  2178. +
  2179. + /* Until there's been traffic both ways, don't look in packets. */
  2180. + if (ctinfo != IP_CT_ESTABLISHED &&
  2181. + ctinfo != IP_CT_ESTABLISHED + IP_CT_IS_REPLY) {
  2182. + DEBUGP("conntrackinfo = %u\n", ctinfo);
  2183. + return NF_ACCEPT;
  2184. + }
  2185. +
  2186. + /* Not whole TCP header? */
  2187. + th = skb_header_pointer(skb, protoff, sizeof(_tcph), &_tcph);
  2188. +
  2189. + if (!th)
  2190. + return NF_ACCEPT;
  2191. +
  2192. + /* No data ? */
  2193. + dataoff = protoff + th->doff*4;
  2194. + datalen = skb->len - dataoff;
  2195. + if (dataoff >= skb->len)
  2196. + return NF_ACCEPT;
  2197. +
  2198. + spin_lock_bh(&rtsp_buffer_lock);
  2199. + rb_ptr = skb_header_pointer(skb, dataoff,
  2200. + skb->len - dataoff, rtsp_buffer);
  2201. + BUG_ON(rb_ptr == NULL);
  2202. +
  2203. +#if 0
  2204. + /* Checksum invalid? Ignore. */
  2205. + /* FIXME: Source route IP option packets --RR */
  2206. + if (tcp_v4_check(tcph, tcplen, iph->saddr, iph->daddr,
  2207. + csum_partial((char*)tcph, tcplen, 0)))
  2208. + {
  2209. + DEBUGP("bad csum: %p %u %u.%u.%u.%u %u.%u.%u.%u\n",
  2210. + tcph, tcplen, NIPQUAD(iph->saddr), NIPQUAD(iph->daddr));
  2211. + return NF_ACCEPT;
  2212. + }
  2213. +#endif
  2214. +
  2215. + switch (CTINFO2DIR(ctinfo)) {
  2216. + case IP_CT_DIR_ORIGINAL:
  2217. + ret = help_out(skb, rb_ptr, datalen, ct, ctinfo);
  2218. + break;
  2219. + case IP_CT_DIR_REPLY:
  2220. + DEBUGP("IP_CT_DIR_REPLY\n");
  2221. + /* inbound packet: server->client */
  2222. + ret = NF_ACCEPT;
  2223. + break;
  2224. + }
  2225. +
  2226. + spin_unlock_bh(&rtsp_buffer_lock);
  2227. +
  2228. + return ret;
  2229. +}
  2230. +
  2231. +static struct nf_conntrack_helper rtsp_helpers[MAX_PORTS];
  2232. +static char rtsp_names[MAX_PORTS][10];
  2233. +static struct nf_conntrack_expect_policy rtsp_expect_policy;
  2234. +
  2235. +/* This function is intentionally _NOT_ defined as __exit */
  2236. +static void
  2237. +fini(void)
  2238. +{
  2239. + int i;
  2240. + for (i = 0; i < num_ports; i++) {
  2241. + DEBUGP("unregistering port %d\n", ports[i]);
  2242. + nf_conntrack_helper_unregister(&rtsp_helpers[i]);
  2243. + }
  2244. + kfree(rtsp_buffer);
  2245. +}
  2246. +
  2247. +static int __init
  2248. +init(void)
  2249. +{
  2250. + int i, ret;
  2251. + struct nf_conntrack_helper *hlpr;
  2252. + char *tmpname;
  2253. +
  2254. + printk("nf_conntrack_rtsp v" IP_NF_RTSP_VERSION " loading\n");
  2255. +
  2256. + if (max_outstanding < 1) {
  2257. + printk("nf_conntrack_rtsp: max_outstanding must be a positive integer\n");
  2258. + return -EBUSY;
  2259. + }
  2260. + if (setup_timeout < 0) {
  2261. + printk("nf_conntrack_rtsp: setup_timeout must be a positive integer\n");
  2262. + return -EBUSY;
  2263. + }
  2264. +
  2265. + rtsp_expect_policy.max_expected = max_outstanding;
  2266. + rtsp_expect_policy.timeout = setup_timeout;
  2267. +
  2268. + rtsp_buffer = kmalloc(65536, GFP_KERNEL);
  2269. + if (!rtsp_buffer)
  2270. + return -ENOMEM;
  2271. +
  2272. + /* If no port given, default to standard rtsp port */
  2273. + if (ports[0] == 0) {
  2274. + ports[0] = RTSP_PORT;
  2275. + }
  2276. +
  2277. + for (i = 0; (i < MAX_PORTS) && ports[i]; i++) {
  2278. + hlpr = &rtsp_helpers[i];
  2279. + memset(hlpr, 0, sizeof(struct nf_conntrack_helper));
  2280. + hlpr->tuple.src.u.tcp.port = htons(ports[i]);
  2281. + hlpr->tuple.dst.protonum = IPPROTO_TCP;
  2282. + hlpr->expect_policy = &rtsp_expect_policy;
  2283. + hlpr->me = THIS_MODULE;
  2284. + hlpr->help = help;
  2285. +
  2286. + tmpname = &rtsp_names[i][0];
  2287. + if (ports[i] == RTSP_PORT) {
  2288. + sprintf(tmpname, "rtsp");
  2289. + } else {
  2290. + sprintf(tmpname, "rtsp-%d", i);
  2291. + }
  2292. + hlpr->name = tmpname;
  2293. +
  2294. + DEBUGP("port #%d: %d\n", i, ports[i]);
  2295. +
  2296. + ret = nf_conntrack_helper_register(hlpr);
  2297. +
  2298. + if (ret) {
  2299. + printk("nf_conntrack_rtsp: ERROR registering port %d\n", ports[i]);
  2300. + fini();
  2301. + return -EBUSY;
  2302. + }
  2303. + num_ports++;
  2304. + }
  2305. + return 0;
  2306. +}
  2307. +
  2308. +module_init(init);
  2309. +module_exit(fini);
  2310. +
  2311. +EXPORT_SYMBOL(nf_nat_rtsp_hook_expectfn);
  2312. +