nf_nat.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #ifndef _NF_NAT_H
  2. #define _NF_NAT_H
  3. #include <linux/netfilter_ipv4.h>
  4. #include <linux/netfilter/nf_nat.h>
  5. #include <net/netfilter/nf_conntrack_tuple.h>
  6. enum nf_nat_manip_type {
  7. NF_NAT_MANIP_SRC,
  8. NF_NAT_MANIP_DST
  9. };
  10. /* SRC manip occurs POST_ROUTING or LOCAL_IN */
  11. #define HOOK2MANIP(hooknum) ((hooknum) != NF_INET_POST_ROUTING && \
  12. (hooknum) != NF_INET_LOCAL_IN)
  13. #include <linux/list.h>
  14. #include <linux/netfilter/nf_conntrack_pptp.h>
  15. #include <net/netfilter/nf_conntrack_extend.h>
  16. /* per conntrack: nat application helper private data */
  17. union nf_conntrack_nat_help {
  18. /* insert nat helper private data here */
  19. #if defined(CONFIG_NF_NAT_PPTP) || defined(CONFIG_NF_NAT_PPTP_MODULE)
  20. struct nf_nat_pptp nat_pptp_info;
  21. #endif
  22. };
  23. struct nf_conn;
  24. /* The structure embedded in the conntrack structure. */
  25. struct nf_conn_nat {
  26. struct hlist_node bysource;
  27. struct nf_conn *ct;
  28. union nf_conntrack_nat_help help;
  29. #if IS_ENABLED(CONFIG_NF_NAT_MASQUERADE_IPV4) || \
  30. IS_ENABLED(CONFIG_NF_NAT_MASQUERADE_IPV6)
  31. int masq_index;
  32. #endif
  33. };
  34. /* Set up the info structure to map into this range. */
  35. unsigned int nf_nat_setup_info(struct nf_conn *ct,
  36. const struct nf_nat_range *range,
  37. enum nf_nat_manip_type maniptype);
  38. extern unsigned int nf_nat_alloc_null_binding(struct nf_conn *ct,
  39. unsigned int hooknum);
  40. struct nf_conn_nat *nf_ct_nat_ext_add(struct nf_conn *ct);
  41. /* Is this tuple already taken? (not by us)*/
  42. int nf_nat_used_tuple(const struct nf_conntrack_tuple *tuple,
  43. const struct nf_conn *ignored_conntrack);
  44. static inline struct nf_conn_nat *nfct_nat(const struct nf_conn *ct)
  45. {
  46. #if defined(CONFIG_NF_NAT) || defined(CONFIG_NF_NAT_MODULE)
  47. return nf_ct_ext_find(ct, NF_CT_EXT_NAT);
  48. #else
  49. return NULL;
  50. #endif
  51. }
  52. static inline bool nf_nat_oif_changed(unsigned int hooknum,
  53. enum ip_conntrack_info ctinfo,
  54. struct nf_conn_nat *nat,
  55. const struct net_device *out)
  56. {
  57. #if IS_ENABLED(CONFIG_NF_NAT_MASQUERADE_IPV4) || \
  58. IS_ENABLED(CONFIG_NF_NAT_MASQUERADE_IPV6)
  59. return nat->masq_index && hooknum == NF_INET_POST_ROUTING &&
  60. CTINFO2DIR(ctinfo) == IP_CT_DIR_ORIGINAL &&
  61. nat->masq_index != out->ifindex;
  62. #else
  63. return false;
  64. #endif
  65. }
  66. #endif