nft_chain_nat_ipv6.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Copyright (c) 2011 Patrick McHardy <kaber@trash.net>
  3. * Copyright (c) 2012 Intel Corporation
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. */
  10. #include <linux/module.h>
  11. #include <linux/init.h>
  12. #include <linux/list.h>
  13. #include <linux/skbuff.h>
  14. #include <linux/ip.h>
  15. #include <linux/netfilter.h>
  16. #include <linux/netfilter_ipv6.h>
  17. #include <linux/netfilter/nf_tables.h>
  18. #include <net/netfilter/nf_conntrack.h>
  19. #include <net/netfilter/nf_nat.h>
  20. #include <net/netfilter/nf_nat_core.h>
  21. #include <net/netfilter/nf_tables.h>
  22. #include <net/netfilter/nf_tables_ipv6.h>
  23. #include <net/netfilter/nf_nat_l3proto.h>
  24. #include <net/ipv6.h>
  25. static unsigned int nft_nat_do_chain(void *priv,
  26. struct sk_buff *skb,
  27. const struct nf_hook_state *state,
  28. struct nf_conn *ct)
  29. {
  30. struct nft_pktinfo pkt;
  31. nft_set_pktinfo_ipv6(&pkt, skb, state);
  32. return nft_do_chain(&pkt, priv);
  33. }
  34. static unsigned int nft_nat_ipv6_fn(void *priv,
  35. struct sk_buff *skb,
  36. const struct nf_hook_state *state)
  37. {
  38. return nf_nat_ipv6_fn(priv, skb, state, nft_nat_do_chain);
  39. }
  40. static unsigned int nft_nat_ipv6_in(void *priv,
  41. struct sk_buff *skb,
  42. const struct nf_hook_state *state)
  43. {
  44. return nf_nat_ipv6_in(priv, skb, state, nft_nat_do_chain);
  45. }
  46. static unsigned int nft_nat_ipv6_out(void *priv,
  47. struct sk_buff *skb,
  48. const struct nf_hook_state *state)
  49. {
  50. return nf_nat_ipv6_out(priv, skb, state, nft_nat_do_chain);
  51. }
  52. static unsigned int nft_nat_ipv6_local_fn(void *priv,
  53. struct sk_buff *skb,
  54. const struct nf_hook_state *state)
  55. {
  56. return nf_nat_ipv6_local_fn(priv, skb, state, nft_nat_do_chain);
  57. }
  58. static const struct nf_chain_type nft_chain_nat_ipv6 = {
  59. .name = "nat",
  60. .type = NFT_CHAIN_T_NAT,
  61. .family = NFPROTO_IPV6,
  62. .owner = THIS_MODULE,
  63. .hook_mask = (1 << NF_INET_PRE_ROUTING) |
  64. (1 << NF_INET_POST_ROUTING) |
  65. (1 << NF_INET_LOCAL_OUT) |
  66. (1 << NF_INET_LOCAL_IN),
  67. .hooks = {
  68. [NF_INET_PRE_ROUTING] = nft_nat_ipv6_in,
  69. [NF_INET_POST_ROUTING] = nft_nat_ipv6_out,
  70. [NF_INET_LOCAL_OUT] = nft_nat_ipv6_local_fn,
  71. [NF_INET_LOCAL_IN] = nft_nat_ipv6_fn,
  72. },
  73. };
  74. static int __init nft_chain_nat_ipv6_init(void)
  75. {
  76. int err;
  77. err = nft_register_chain_type(&nft_chain_nat_ipv6);
  78. if (err < 0)
  79. return err;
  80. return 0;
  81. }
  82. static void __exit nft_chain_nat_ipv6_exit(void)
  83. {
  84. nft_unregister_chain_type(&nft_chain_nat_ipv6);
  85. }
  86. module_init(nft_chain_nat_ipv6_init);
  87. module_exit(nft_chain_nat_ipv6_exit);
  88. MODULE_LICENSE("GPL");
  89. MODULE_AUTHOR("Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>");
  90. MODULE_ALIAS_NFT_CHAIN(AF_INET6, "nat");