nft_masq_ipv6.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright (c) 2014 Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
  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. #include <linux/kernel.h>
  9. #include <linux/init.h>
  10. #include <linux/module.h>
  11. #include <linux/netlink.h>
  12. #include <linux/netfilter.h>
  13. #include <linux/netfilter/nf_tables.h>
  14. #include <net/netfilter/nf_tables.h>
  15. #include <net/netfilter/nf_nat.h>
  16. #include <net/netfilter/nft_masq.h>
  17. #include <net/netfilter/ipv6/nf_nat_masquerade.h>
  18. static void nft_masq_ipv6_eval(const struct nft_expr *expr,
  19. struct nft_regs *regs,
  20. const struct nft_pktinfo *pkt)
  21. {
  22. struct nft_masq *priv = nft_expr_priv(expr);
  23. struct nf_nat_range range;
  24. memset(&range, 0, sizeof(range));
  25. range.flags = priv->flags;
  26. regs->verdict.code = nf_nat_masquerade_ipv6(pkt->skb, &range, pkt->out);
  27. }
  28. static struct nft_expr_type nft_masq_ipv6_type;
  29. static const struct nft_expr_ops nft_masq_ipv6_ops = {
  30. .type = &nft_masq_ipv6_type,
  31. .size = NFT_EXPR_SIZE(sizeof(struct nft_masq)),
  32. .eval = nft_masq_ipv6_eval,
  33. .init = nft_masq_init,
  34. .dump = nft_masq_dump,
  35. .validate = nft_masq_validate,
  36. };
  37. static struct nft_expr_type nft_masq_ipv6_type __read_mostly = {
  38. .family = NFPROTO_IPV6,
  39. .name = "masq",
  40. .ops = &nft_masq_ipv6_ops,
  41. .policy = nft_masq_policy,
  42. .maxattr = NFTA_MASQ_MAX,
  43. .owner = THIS_MODULE,
  44. };
  45. static int __init nft_masq_ipv6_module_init(void)
  46. {
  47. int ret;
  48. ret = nft_register_expr(&nft_masq_ipv6_type);
  49. if (ret < 0)
  50. return ret;
  51. nf_nat_masquerade_ipv6_register_notifier();
  52. return ret;
  53. }
  54. static void __exit nft_masq_ipv6_module_exit(void)
  55. {
  56. nft_unregister_expr(&nft_masq_ipv6_type);
  57. nf_nat_masquerade_ipv6_unregister_notifier();
  58. }
  59. module_init(nft_masq_ipv6_module_init);
  60. module_exit(nft_masq_ipv6_module_exit);
  61. MODULE_LICENSE("GPL");
  62. MODULE_AUTHOR("Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>");
  63. MODULE_ALIAS_NFT_AF_EXPR(AF_INET6, "masq");