ip6t_MASQUERADE.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright (c) 2011 Patrick McHardy <kaber@trash.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * Based on Rusty Russell's IPv6 MASQUERADE target. Development of IPv6
  9. * NAT funded by Astaro.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/module.h>
  13. #include <linux/netdevice.h>
  14. #include <linux/ipv6.h>
  15. #include <linux/netfilter.h>
  16. #include <linux/netfilter_ipv6.h>
  17. #include <linux/netfilter/x_tables.h>
  18. #include <net/netfilter/nf_nat.h>
  19. #include <net/addrconf.h>
  20. #include <net/ipv6.h>
  21. #include <net/netfilter/ipv6/nf_nat_masquerade.h>
  22. static unsigned int
  23. masquerade_tg6(struct sk_buff *skb, const struct xt_action_param *par)
  24. {
  25. return nf_nat_masquerade_ipv6(skb, par->targinfo, par->out);
  26. }
  27. static int masquerade_tg6_checkentry(const struct xt_tgchk_param *par)
  28. {
  29. const struct nf_nat_range *range = par->targinfo;
  30. if (range->flags & NF_NAT_RANGE_MAP_IPS)
  31. return -EINVAL;
  32. return 0;
  33. }
  34. static struct xt_target masquerade_tg6_reg __read_mostly = {
  35. .name = "MASQUERADE",
  36. .family = NFPROTO_IPV6,
  37. .checkentry = masquerade_tg6_checkentry,
  38. .target = masquerade_tg6,
  39. .targetsize = sizeof(struct nf_nat_range),
  40. .table = "nat",
  41. .hooks = 1 << NF_INET_POST_ROUTING,
  42. .me = THIS_MODULE,
  43. };
  44. static int __init masquerade_tg6_init(void)
  45. {
  46. int err;
  47. err = xt_register_target(&masquerade_tg6_reg);
  48. if (err == 0)
  49. nf_nat_masquerade_ipv6_register_notifier();
  50. return err;
  51. }
  52. static void __exit masquerade_tg6_exit(void)
  53. {
  54. nf_nat_masquerade_ipv6_unregister_notifier();
  55. xt_unregister_target(&masquerade_tg6_reg);
  56. }
  57. module_init(masquerade_tg6_init);
  58. module_exit(masquerade_tg6_exit);
  59. MODULE_LICENSE("GPL");
  60. MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
  61. MODULE_DESCRIPTION("Xtables: automatic address SNAT");