ip_nat_tftp.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* (C) 2001-2002 Magnus Boden <mb@ozaba.mine.nu>
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 as
  5. * published by the Free Software Foundation.
  6. *
  7. * Version: 0.0.7
  8. *
  9. * Thu 21 Mar 2002 Harald Welte <laforge@gnumonks.org>
  10. * - Port to newnat API
  11. *
  12. * This module currently supports DNAT:
  13. * iptables -t nat -A PREROUTING -d x.x.x.x -j DNAT --to-dest x.x.x.y
  14. *
  15. * and SNAT:
  16. * iptables -t nat -A POSTROUTING { -j MASQUERADE , -j SNAT --to-source x.x.x.x }
  17. *
  18. * It has not been tested with
  19. * -j SNAT --to-source x.x.x.x-x.x.x.y since I only have one external ip
  20. * If you do test this please let me know if it works or not.
  21. *
  22. */
  23. #include <linux/module.h>
  24. #include <linux/netfilter_ipv4.h>
  25. #include <linux/ip.h>
  26. #include <linux/udp.h>
  27. #include <linux/netfilter.h>
  28. #include <linux/netfilter_ipv4/ip_tables.h>
  29. #include <linux/netfilter_ipv4/ip_conntrack_helper.h>
  30. #include <linux/netfilter_ipv4/ip_conntrack_tftp.h>
  31. #include <linux/netfilter_ipv4/ip_nat_helper.h>
  32. #include <linux/netfilter_ipv4/ip_nat_rule.h>
  33. #include <linux/moduleparam.h>
  34. MODULE_AUTHOR("Magnus Boden <mb@ozaba.mine.nu>");
  35. MODULE_DESCRIPTION("tftp NAT helper");
  36. MODULE_LICENSE("GPL");
  37. static unsigned int help(struct sk_buff **pskb,
  38. enum ip_conntrack_info ctinfo,
  39. struct ip_conntrack_expect *exp)
  40. {
  41. struct ip_conntrack *ct = exp->master;
  42. exp->saved_proto.udp.port
  43. = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.u.udp.port;
  44. exp->dir = IP_CT_DIR_REPLY;
  45. exp->expectfn = ip_nat_follow_master;
  46. if (ip_conntrack_expect_related(exp) != 0)
  47. return NF_DROP;
  48. return NF_ACCEPT;
  49. }
  50. static void __exit ip_nat_tftp_fini(void)
  51. {
  52. rcu_assign_pointer(ip_nat_tftp_hook, NULL);
  53. synchronize_rcu();
  54. }
  55. static int __init ip_nat_tftp_init(void)
  56. {
  57. BUG_ON(rcu_dereference(ip_nat_tftp_hook));
  58. rcu_assign_pointer(ip_nat_tftp_hook, help);
  59. return 0;
  60. }
  61. module_init(ip_nat_tftp_init);
  62. module_exit(ip_nat_tftp_fini);