nf_nat_h323.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * H.323 extension for NAT alteration.
  4. *
  5. * Copyright (c) 2006 Jing Min Zhao <zhaojingmin@users.sourceforge.net>
  6. * Copyright (c) 2006-2012 Patrick McHardy <kaber@trash.net>
  7. *
  8. * Based on the 'brute force' H.323 NAT module by
  9. * Jozsef Kadlecsik <kadlec@netfilter.org>
  10. */
  11. #include <linux/module.h>
  12. #include <linux/tcp.h>
  13. #include <net/tcp.h>
  14. #include <net/netfilter/nf_nat.h>
  15. #include <net/netfilter/nf_nat_helper.h>
  16. #include <net/netfilter/nf_conntrack_helper.h>
  17. #include <net/netfilter/nf_conntrack_expect.h>
  18. #include <linux/netfilter/nf_conntrack_h323.h>
  19. /****************************************************************************/
  20. static int set_addr(struct sk_buff *skb, unsigned int protoff,
  21. unsigned char **data, int dataoff,
  22. unsigned int addroff, __be32 ip, __be16 port)
  23. {
  24. enum ip_conntrack_info ctinfo;
  25. struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
  26. struct {
  27. __be32 ip;
  28. __be16 port;
  29. } __attribute__ ((__packed__)) buf;
  30. const struct tcphdr *th;
  31. struct tcphdr _tcph;
  32. buf.ip = ip;
  33. buf.port = port;
  34. addroff += dataoff;
  35. if (ip_hdr(skb)->protocol == IPPROTO_TCP) {
  36. if (!nf_nat_mangle_tcp_packet(skb, ct, ctinfo,
  37. protoff, addroff, sizeof(buf),
  38. (char *) &buf, sizeof(buf))) {
  39. net_notice_ratelimited("nf_nat_h323: nf_nat_mangle_tcp_packet error\n");
  40. return -1;
  41. }
  42. /* Relocate data pointer */
  43. th = skb_header_pointer(skb, ip_hdrlen(skb),
  44. sizeof(_tcph), &_tcph);
  45. if (th == NULL)
  46. return -1;
  47. *data = skb->data + ip_hdrlen(skb) + th->doff * 4 + dataoff;
  48. } else {
  49. if (!nf_nat_mangle_udp_packet(skb, ct, ctinfo,
  50. protoff, addroff, sizeof(buf),
  51. (char *) &buf, sizeof(buf))) {
  52. net_notice_ratelimited("nf_nat_h323: nf_nat_mangle_udp_packet error\n");
  53. return -1;
  54. }
  55. /* nf_nat_mangle_udp_packet uses skb_ensure_writable() to copy
  56. * or pull everything in a linear buffer, so we can safely
  57. * use the skb pointers now */
  58. *data = skb->data + ip_hdrlen(skb) + sizeof(struct udphdr);
  59. }
  60. return 0;
  61. }
  62. /****************************************************************************/
  63. static int set_h225_addr(struct sk_buff *skb, unsigned int protoff,
  64. unsigned char **data, int dataoff,
  65. TransportAddress *taddr,
  66. union nf_inet_addr *addr, __be16 port)
  67. {
  68. return set_addr(skb, protoff, data, dataoff, taddr->ipAddress.ip,
  69. addr->ip, port);
  70. }
  71. /****************************************************************************/
  72. static int set_h245_addr(struct sk_buff *skb, unsigned protoff,
  73. unsigned char **data, int dataoff,
  74. H245_TransportAddress *taddr,
  75. union nf_inet_addr *addr, __be16 port)
  76. {
  77. return set_addr(skb, protoff, data, dataoff,
  78. taddr->unicastAddress.iPAddress.network,
  79. addr->ip, port);
  80. }
  81. /****************************************************************************/
  82. static int set_sig_addr(struct sk_buff *skb, struct nf_conn *ct,
  83. enum ip_conntrack_info ctinfo,
  84. unsigned int protoff, unsigned char **data,
  85. TransportAddress *taddr, int count)
  86. {
  87. const struct nf_ct_h323_master *info = nfct_help_data(ct);
  88. int dir = CTINFO2DIR(ctinfo);
  89. int i;
  90. __be16 port;
  91. union nf_inet_addr addr;
  92. for (i = 0; i < count; i++) {
  93. if (get_h225_addr(ct, *data, &taddr[i], &addr, &port)) {
  94. if (addr.ip == ct->tuplehash[dir].tuple.src.u3.ip &&
  95. port == info->sig_port[dir]) {
  96. /* GW->GK */
  97. /* Fix for Gnomemeeting */
  98. if (i > 0 &&
  99. get_h225_addr(ct, *data, &taddr[0],
  100. &addr, &port) &&
  101. (ntohl(addr.ip) & 0xff000000) == 0x7f000000)
  102. i = 0;
  103. pr_debug("nf_nat_ras: set signal address %pI4:%hu->%pI4:%hu\n",
  104. &addr.ip, port,
  105. &ct->tuplehash[!dir].tuple.dst.u3.ip,
  106. info->sig_port[!dir]);
  107. return set_h225_addr(skb, protoff, data, 0,
  108. &taddr[i],
  109. &ct->tuplehash[!dir].
  110. tuple.dst.u3,
  111. info->sig_port[!dir]);
  112. } else if (addr.ip == ct->tuplehash[dir].tuple.dst.u3.ip &&
  113. port == info->sig_port[dir]) {
  114. /* GK->GW */
  115. pr_debug("nf_nat_ras: set signal address %pI4:%hu->%pI4:%hu\n",
  116. &addr.ip, port,
  117. &ct->tuplehash[!dir].tuple.src.u3.ip,
  118. info->sig_port[!dir]);
  119. return set_h225_addr(skb, protoff, data, 0,
  120. &taddr[i],
  121. &ct->tuplehash[!dir].
  122. tuple.src.u3,
  123. info->sig_port[!dir]);
  124. }
  125. }
  126. }
  127. return 0;
  128. }
  129. /****************************************************************************/
  130. static int set_ras_addr(struct sk_buff *skb, struct nf_conn *ct,
  131. enum ip_conntrack_info ctinfo,
  132. unsigned int protoff, unsigned char **data,
  133. TransportAddress *taddr, int count)
  134. {
  135. int dir = CTINFO2DIR(ctinfo);
  136. int i;
  137. __be16 port;
  138. union nf_inet_addr addr;
  139. for (i = 0; i < count; i++) {
  140. if (get_h225_addr(ct, *data, &taddr[i], &addr, &port) &&
  141. addr.ip == ct->tuplehash[dir].tuple.src.u3.ip &&
  142. port == ct->tuplehash[dir].tuple.src.u.udp.port) {
  143. pr_debug("nf_nat_ras: set rasAddress %pI4:%hu->%pI4:%hu\n",
  144. &addr.ip, ntohs(port),
  145. &ct->tuplehash[!dir].tuple.dst.u3.ip,
  146. ntohs(ct->tuplehash[!dir].tuple.dst.u.udp.port));
  147. return set_h225_addr(skb, protoff, data, 0, &taddr[i],
  148. &ct->tuplehash[!dir].tuple.dst.u3,
  149. ct->tuplehash[!dir].tuple.
  150. dst.u.udp.port);
  151. }
  152. }
  153. return 0;
  154. }
  155. /****************************************************************************/
  156. static int nat_rtp_rtcp(struct sk_buff *skb, struct nf_conn *ct,
  157. enum ip_conntrack_info ctinfo,
  158. unsigned int protoff, unsigned char **data, int dataoff,
  159. H245_TransportAddress *taddr,
  160. __be16 port, __be16 rtp_port,
  161. struct nf_conntrack_expect *rtp_exp,
  162. struct nf_conntrack_expect *rtcp_exp)
  163. {
  164. struct nf_ct_h323_master *info = nfct_help_data(ct);
  165. int dir = CTINFO2DIR(ctinfo);
  166. int i;
  167. u_int16_t nated_port;
  168. /* Set expectations for NAT */
  169. rtp_exp->saved_proto.udp.port = rtp_exp->tuple.dst.u.udp.port;
  170. rtp_exp->expectfn = nf_nat_follow_master;
  171. rtp_exp->dir = !dir;
  172. rtcp_exp->saved_proto.udp.port = rtcp_exp->tuple.dst.u.udp.port;
  173. rtcp_exp->expectfn = nf_nat_follow_master;
  174. rtcp_exp->dir = !dir;
  175. /* Lookup existing expects */
  176. for (i = 0; i < H323_RTP_CHANNEL_MAX; i++) {
  177. if (info->rtp_port[i][dir] == rtp_port) {
  178. /* Expected */
  179. /* Use allocated ports first. This will refresh
  180. * the expects */
  181. rtp_exp->tuple.dst.u.udp.port = info->rtp_port[i][dir];
  182. rtcp_exp->tuple.dst.u.udp.port =
  183. htons(ntohs(info->rtp_port[i][dir]) + 1);
  184. break;
  185. } else if (info->rtp_port[i][dir] == 0) {
  186. /* Not expected */
  187. break;
  188. }
  189. }
  190. /* Run out of expectations */
  191. if (i >= H323_RTP_CHANNEL_MAX) {
  192. net_notice_ratelimited("nf_nat_h323: out of expectations\n");
  193. return 0;
  194. }
  195. /* Try to get a pair of ports. */
  196. for (nated_port = ntohs(rtp_exp->tuple.dst.u.udp.port);
  197. nated_port != 0; nated_port += 2) {
  198. int ret;
  199. rtp_exp->tuple.dst.u.udp.port = htons(nated_port);
  200. ret = nf_ct_expect_related(rtp_exp, 0);
  201. if (ret == 0) {
  202. rtcp_exp->tuple.dst.u.udp.port =
  203. htons(nated_port + 1);
  204. ret = nf_ct_expect_related(rtcp_exp, 0);
  205. if (ret == 0)
  206. break;
  207. else if (ret == -EBUSY) {
  208. nf_ct_unexpect_related(rtp_exp);
  209. continue;
  210. } else if (ret < 0) {
  211. nf_ct_unexpect_related(rtp_exp);
  212. nated_port = 0;
  213. break;
  214. }
  215. } else if (ret != -EBUSY) {
  216. nated_port = 0;
  217. break;
  218. }
  219. }
  220. if (nated_port == 0) { /* No port available */
  221. net_notice_ratelimited("nf_nat_h323: out of RTP ports\n");
  222. return 0;
  223. }
  224. /* Modify signal */
  225. if (set_h245_addr(skb, protoff, data, dataoff, taddr,
  226. &ct->tuplehash[!dir].tuple.dst.u3,
  227. htons((port & htons(1)) ? nated_port + 1 :
  228. nated_port))) {
  229. nf_ct_unexpect_related(rtp_exp);
  230. nf_ct_unexpect_related(rtcp_exp);
  231. return -1;
  232. }
  233. /* Save ports */
  234. info->rtp_port[i][dir] = rtp_port;
  235. info->rtp_port[i][!dir] = htons(nated_port);
  236. /* Success */
  237. pr_debug("nf_nat_h323: expect RTP %pI4:%hu->%pI4:%hu\n",
  238. &rtp_exp->tuple.src.u3.ip,
  239. ntohs(rtp_exp->tuple.src.u.udp.port),
  240. &rtp_exp->tuple.dst.u3.ip,
  241. ntohs(rtp_exp->tuple.dst.u.udp.port));
  242. pr_debug("nf_nat_h323: expect RTCP %pI4:%hu->%pI4:%hu\n",
  243. &rtcp_exp->tuple.src.u3.ip,
  244. ntohs(rtcp_exp->tuple.src.u.udp.port),
  245. &rtcp_exp->tuple.dst.u3.ip,
  246. ntohs(rtcp_exp->tuple.dst.u.udp.port));
  247. return 0;
  248. }
  249. /****************************************************************************/
  250. static int nat_t120(struct sk_buff *skb, struct nf_conn *ct,
  251. enum ip_conntrack_info ctinfo,
  252. unsigned int protoff, unsigned char **data, int dataoff,
  253. H245_TransportAddress *taddr, __be16 port,
  254. struct nf_conntrack_expect *exp)
  255. {
  256. int dir = CTINFO2DIR(ctinfo);
  257. u_int16_t nated_port = ntohs(port);
  258. /* Set expectations for NAT */
  259. exp->saved_proto.tcp.port = exp->tuple.dst.u.tcp.port;
  260. exp->expectfn = nf_nat_follow_master;
  261. exp->dir = !dir;
  262. /* Try to get same port: if not, try to change it. */
  263. for (; nated_port != 0; nated_port++) {
  264. int ret;
  265. exp->tuple.dst.u.tcp.port = htons(nated_port);
  266. ret = nf_ct_expect_related(exp, 0);
  267. if (ret == 0)
  268. break;
  269. else if (ret != -EBUSY) {
  270. nated_port = 0;
  271. break;
  272. }
  273. }
  274. if (nated_port == 0) { /* No port available */
  275. net_notice_ratelimited("nf_nat_h323: out of TCP ports\n");
  276. return 0;
  277. }
  278. /* Modify signal */
  279. if (set_h245_addr(skb, protoff, data, dataoff, taddr,
  280. &ct->tuplehash[!dir].tuple.dst.u3,
  281. htons(nated_port)) < 0) {
  282. nf_ct_unexpect_related(exp);
  283. return -1;
  284. }
  285. pr_debug("nf_nat_h323: expect T.120 %pI4:%hu->%pI4:%hu\n",
  286. &exp->tuple.src.u3.ip,
  287. ntohs(exp->tuple.src.u.tcp.port),
  288. &exp->tuple.dst.u3.ip,
  289. ntohs(exp->tuple.dst.u.tcp.port));
  290. return 0;
  291. }
  292. /****************************************************************************/
  293. static int nat_h245(struct sk_buff *skb, struct nf_conn *ct,
  294. enum ip_conntrack_info ctinfo,
  295. unsigned int protoff, unsigned char **data, int dataoff,
  296. TransportAddress *taddr, __be16 port,
  297. struct nf_conntrack_expect *exp)
  298. {
  299. struct nf_ct_h323_master *info = nfct_help_data(ct);
  300. int dir = CTINFO2DIR(ctinfo);
  301. u_int16_t nated_port = ntohs(port);
  302. /* Set expectations for NAT */
  303. exp->saved_proto.tcp.port = exp->tuple.dst.u.tcp.port;
  304. exp->expectfn = nf_nat_follow_master;
  305. exp->dir = !dir;
  306. /* Check existing expects */
  307. if (info->sig_port[dir] == port)
  308. nated_port = ntohs(info->sig_port[!dir]);
  309. /* Try to get same port: if not, try to change it. */
  310. for (; nated_port != 0; nated_port++) {
  311. int ret;
  312. exp->tuple.dst.u.tcp.port = htons(nated_port);
  313. ret = nf_ct_expect_related(exp, 0);
  314. if (ret == 0)
  315. break;
  316. else if (ret != -EBUSY) {
  317. nated_port = 0;
  318. break;
  319. }
  320. }
  321. if (nated_port == 0) { /* No port available */
  322. net_notice_ratelimited("nf_nat_q931: out of TCP ports\n");
  323. return 0;
  324. }
  325. /* Modify signal */
  326. if (set_h225_addr(skb, protoff, data, dataoff, taddr,
  327. &ct->tuplehash[!dir].tuple.dst.u3,
  328. htons(nated_port))) {
  329. nf_ct_unexpect_related(exp);
  330. return -1;
  331. }
  332. /* Save ports */
  333. info->sig_port[dir] = port;
  334. info->sig_port[!dir] = htons(nated_port);
  335. pr_debug("nf_nat_q931: expect H.245 %pI4:%hu->%pI4:%hu\n",
  336. &exp->tuple.src.u3.ip,
  337. ntohs(exp->tuple.src.u.tcp.port),
  338. &exp->tuple.dst.u3.ip,
  339. ntohs(exp->tuple.dst.u.tcp.port));
  340. return 0;
  341. }
  342. /****************************************************************************
  343. * This conntrack expect function replaces nf_conntrack_q931_expect()
  344. * which was set by nf_conntrack_h323.c.
  345. ****************************************************************************/
  346. static void ip_nat_q931_expect(struct nf_conn *new,
  347. struct nf_conntrack_expect *this)
  348. {
  349. struct nf_nat_range2 range;
  350. if (this->tuple.src.u3.ip != 0) { /* Only accept calls from GK */
  351. nf_nat_follow_master(new, this);
  352. return;
  353. }
  354. /* This must be a fresh one. */
  355. BUG_ON(new->status & IPS_NAT_DONE_MASK);
  356. /* Change src to where master sends to */
  357. range.flags = NF_NAT_RANGE_MAP_IPS;
  358. range.min_addr = range.max_addr =
  359. new->tuplehash[!this->dir].tuple.src.u3;
  360. nf_nat_setup_info(new, &range, NF_NAT_MANIP_SRC);
  361. /* For DST manip, map port here to where it's expected. */
  362. range.flags = (NF_NAT_RANGE_MAP_IPS | NF_NAT_RANGE_PROTO_SPECIFIED);
  363. range.min_proto = range.max_proto = this->saved_proto;
  364. range.min_addr = range.max_addr =
  365. new->master->tuplehash[!this->dir].tuple.src.u3;
  366. nf_nat_setup_info(new, &range, NF_NAT_MANIP_DST);
  367. }
  368. /****************************************************************************/
  369. static int nat_q931(struct sk_buff *skb, struct nf_conn *ct,
  370. enum ip_conntrack_info ctinfo,
  371. unsigned int protoff, unsigned char **data,
  372. TransportAddress *taddr, int idx,
  373. __be16 port, struct nf_conntrack_expect *exp)
  374. {
  375. struct nf_ct_h323_master *info = nfct_help_data(ct);
  376. int dir = CTINFO2DIR(ctinfo);
  377. u_int16_t nated_port = ntohs(port);
  378. union nf_inet_addr addr;
  379. /* Set expectations for NAT */
  380. exp->saved_proto.tcp.port = exp->tuple.dst.u.tcp.port;
  381. exp->expectfn = ip_nat_q931_expect;
  382. exp->dir = !dir;
  383. /* Check existing expects */
  384. if (info->sig_port[dir] == port)
  385. nated_port = ntohs(info->sig_port[!dir]);
  386. /* Try to get same port: if not, try to change it. */
  387. for (; nated_port != 0; nated_port++) {
  388. int ret;
  389. exp->tuple.dst.u.tcp.port = htons(nated_port);
  390. ret = nf_ct_expect_related(exp, 0);
  391. if (ret == 0)
  392. break;
  393. else if (ret != -EBUSY) {
  394. nated_port = 0;
  395. break;
  396. }
  397. }
  398. if (nated_port == 0) { /* No port available */
  399. net_notice_ratelimited("nf_nat_ras: out of TCP ports\n");
  400. return 0;
  401. }
  402. /* Modify signal */
  403. if (set_h225_addr(skb, protoff, data, 0, &taddr[idx],
  404. &ct->tuplehash[!dir].tuple.dst.u3,
  405. htons(nated_port))) {
  406. nf_ct_unexpect_related(exp);
  407. return -1;
  408. }
  409. /* Save ports */
  410. info->sig_port[dir] = port;
  411. info->sig_port[!dir] = htons(nated_port);
  412. /* Fix for Gnomemeeting */
  413. if (idx > 0 &&
  414. get_h225_addr(ct, *data, &taddr[0], &addr, &port) &&
  415. (ntohl(addr.ip) & 0xff000000) == 0x7f000000) {
  416. if (set_h225_addr(skb, protoff, data, 0, &taddr[0],
  417. &ct->tuplehash[!dir].tuple.dst.u3,
  418. info->sig_port[!dir])) {
  419. nf_ct_unexpect_related(exp);
  420. return -1;
  421. }
  422. }
  423. /* Success */
  424. pr_debug("nf_nat_ras: expect Q.931 %pI4:%hu->%pI4:%hu\n",
  425. &exp->tuple.src.u3.ip,
  426. ntohs(exp->tuple.src.u.tcp.port),
  427. &exp->tuple.dst.u3.ip,
  428. ntohs(exp->tuple.dst.u.tcp.port));
  429. return 0;
  430. }
  431. /****************************************************************************/
  432. static void ip_nat_callforwarding_expect(struct nf_conn *new,
  433. struct nf_conntrack_expect *this)
  434. {
  435. struct nf_nat_range2 range;
  436. /* This must be a fresh one. */
  437. BUG_ON(new->status & IPS_NAT_DONE_MASK);
  438. /* Change src to where master sends to */
  439. range.flags = NF_NAT_RANGE_MAP_IPS;
  440. range.min_addr = range.max_addr =
  441. new->tuplehash[!this->dir].tuple.src.u3;
  442. nf_nat_setup_info(new, &range, NF_NAT_MANIP_SRC);
  443. /* For DST manip, map port here to where it's expected. */
  444. range.flags = (NF_NAT_RANGE_MAP_IPS | NF_NAT_RANGE_PROTO_SPECIFIED);
  445. range.min_proto = range.max_proto = this->saved_proto;
  446. range.min_addr = range.max_addr = this->saved_addr;
  447. nf_nat_setup_info(new, &range, NF_NAT_MANIP_DST);
  448. }
  449. /****************************************************************************/
  450. static int nat_callforwarding(struct sk_buff *skb, struct nf_conn *ct,
  451. enum ip_conntrack_info ctinfo,
  452. unsigned int protoff,
  453. unsigned char **data, int dataoff,
  454. TransportAddress *taddr, __be16 port,
  455. struct nf_conntrack_expect *exp)
  456. {
  457. int dir = CTINFO2DIR(ctinfo);
  458. u_int16_t nated_port;
  459. /* Set expectations for NAT */
  460. exp->saved_addr = exp->tuple.dst.u3;
  461. exp->tuple.dst.u3.ip = ct->tuplehash[!dir].tuple.dst.u3.ip;
  462. exp->saved_proto.tcp.port = exp->tuple.dst.u.tcp.port;
  463. exp->expectfn = ip_nat_callforwarding_expect;
  464. exp->dir = !dir;
  465. /* Try to get same port: if not, try to change it. */
  466. for (nated_port = ntohs(port); nated_port != 0; nated_port++) {
  467. int ret;
  468. exp->tuple.dst.u.tcp.port = htons(nated_port);
  469. ret = nf_ct_expect_related(exp, 0);
  470. if (ret == 0)
  471. break;
  472. else if (ret != -EBUSY) {
  473. nated_port = 0;
  474. break;
  475. }
  476. }
  477. if (nated_port == 0) { /* No port available */
  478. net_notice_ratelimited("nf_nat_q931: out of TCP ports\n");
  479. return 0;
  480. }
  481. /* Modify signal */
  482. if (set_h225_addr(skb, protoff, data, dataoff, taddr,
  483. &ct->tuplehash[!dir].tuple.dst.u3,
  484. htons(nated_port))) {
  485. nf_ct_unexpect_related(exp);
  486. return -1;
  487. }
  488. /* Success */
  489. pr_debug("nf_nat_q931: expect Call Forwarding %pI4:%hu->%pI4:%hu\n",
  490. &exp->tuple.src.u3.ip,
  491. ntohs(exp->tuple.src.u.tcp.port),
  492. &exp->tuple.dst.u3.ip,
  493. ntohs(exp->tuple.dst.u.tcp.port));
  494. return 0;
  495. }
  496. static struct nf_ct_helper_expectfn q931_nat = {
  497. .name = "Q.931",
  498. .expectfn = ip_nat_q931_expect,
  499. };
  500. static struct nf_ct_helper_expectfn callforwarding_nat = {
  501. .name = "callforwarding",
  502. .expectfn = ip_nat_callforwarding_expect,
  503. };
  504. /****************************************************************************/
  505. static int __init init(void)
  506. {
  507. BUG_ON(set_h245_addr_hook != NULL);
  508. BUG_ON(set_h225_addr_hook != NULL);
  509. BUG_ON(set_sig_addr_hook != NULL);
  510. BUG_ON(set_ras_addr_hook != NULL);
  511. BUG_ON(nat_rtp_rtcp_hook != NULL);
  512. BUG_ON(nat_t120_hook != NULL);
  513. BUG_ON(nat_h245_hook != NULL);
  514. BUG_ON(nat_callforwarding_hook != NULL);
  515. BUG_ON(nat_q931_hook != NULL);
  516. RCU_INIT_POINTER(set_h245_addr_hook, set_h245_addr);
  517. RCU_INIT_POINTER(set_h225_addr_hook, set_h225_addr);
  518. RCU_INIT_POINTER(set_sig_addr_hook, set_sig_addr);
  519. RCU_INIT_POINTER(set_ras_addr_hook, set_ras_addr);
  520. RCU_INIT_POINTER(nat_rtp_rtcp_hook, nat_rtp_rtcp);
  521. RCU_INIT_POINTER(nat_t120_hook, nat_t120);
  522. RCU_INIT_POINTER(nat_h245_hook, nat_h245);
  523. RCU_INIT_POINTER(nat_callforwarding_hook, nat_callforwarding);
  524. RCU_INIT_POINTER(nat_q931_hook, nat_q931);
  525. nf_ct_helper_expectfn_register(&q931_nat);
  526. nf_ct_helper_expectfn_register(&callforwarding_nat);
  527. return 0;
  528. }
  529. /****************************************************************************/
  530. static void __exit fini(void)
  531. {
  532. RCU_INIT_POINTER(set_h245_addr_hook, NULL);
  533. RCU_INIT_POINTER(set_h225_addr_hook, NULL);
  534. RCU_INIT_POINTER(set_sig_addr_hook, NULL);
  535. RCU_INIT_POINTER(set_ras_addr_hook, NULL);
  536. RCU_INIT_POINTER(nat_rtp_rtcp_hook, NULL);
  537. RCU_INIT_POINTER(nat_t120_hook, NULL);
  538. RCU_INIT_POINTER(nat_h245_hook, NULL);
  539. RCU_INIT_POINTER(nat_callforwarding_hook, NULL);
  540. RCU_INIT_POINTER(nat_q931_hook, NULL);
  541. nf_ct_helper_expectfn_unregister(&q931_nat);
  542. nf_ct_helper_expectfn_unregister(&callforwarding_nat);
  543. synchronize_rcu();
  544. }
  545. /****************************************************************************/
  546. module_init(init);
  547. module_exit(fini);
  548. MODULE_AUTHOR("Jing Min Zhao <zhaojingmin@users.sourceforge.net>");
  549. MODULE_DESCRIPTION("H.323 NAT helper");
  550. MODULE_LICENSE("GPL");
  551. MODULE_ALIAS_NF_NAT_HELPER("h323");