blob: 02515f7ed4cceceeaa9eb974531e2ec342346d07 [file] [log] [blame]
Jozsef Kadlecsik5b1158e2006-12-02 22:07:13 -08001#ifndef _NF_NAT_H
2#define _NF_NAT_H
3#include <linux/netfilter_ipv4.h>
Patrick McHardycbc9f2f2011-12-23 13:59:49 +01004#include <linux/netfilter/nf_nat.h>
Jozsef Kadlecsik5b1158e2006-12-02 22:07:13 -08005#include <net/netfilter/nf_conntrack_tuple.h>
6
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +00007enum nf_nat_manip_type {
Patrick McHardycbc9f2f2011-12-23 13:59:49 +01008 NF_NAT_MANIP_SRC,
9 NF_NAT_MANIP_DST
Jozsef Kadlecsik5b1158e2006-12-02 22:07:13 -080010};
11
12/* SRC manip occurs POST_ROUTING or LOCAL_IN */
Patrick McHardy6e23ae22007-11-19 18:53:30 -080013#define HOOK2MANIP(hooknum) ((hooknum) != NF_INET_POST_ROUTING && \
14 (hooknum) != NF_INET_LOCAL_IN)
Jozsef Kadlecsik5b1158e2006-12-02 22:07:13 -080015
Jozsef Kadlecsik5b1158e2006-12-02 22:07:13 -080016#include <linux/list.h>
Yasuyuki Kozakai4ba88772007-07-07 22:22:33 -070017#include <linux/netfilter/nf_conntrack_pptp.h>
Yasuyuki Kozakai2d59e5c2007-07-07 22:24:28 -070018#include <net/netfilter/nf_conntrack_extend.h>
Jozsef Kadlecsik5b1158e2006-12-02 22:07:13 -080019
Yasuyuki Kozakai4ba88772007-07-07 22:22:33 -070020/* per conntrack: nat application helper private data */
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +000021union nf_conntrack_nat_help {
Yasuyuki Kozakai4ba88772007-07-07 22:22:33 -070022 /* insert nat helper private data here */
Changli Gao03c0e5b2010-11-15 12:27:27 +010023#if defined(CONFIG_NF_NAT_PPTP) || defined(CONFIG_NF_NAT_PPTP_MODULE)
Yasuyuki Kozakai4ba88772007-07-07 22:22:33 -070024 struct nf_nat_pptp nat_pptp_info;
Changli Gao03c0e5b2010-11-15 12:27:27 +010025#endif
Yasuyuki Kozakai4ba88772007-07-07 22:22:33 -070026};
27
Yasuyuki Kozakaib6b84d42007-07-07 22:26:35 -070028struct nf_conn;
29
30/* The structure embedded in the conntrack structure. */
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +000031struct nf_conn_nat {
Yasuyuki Kozakai4ba88772007-07-07 22:22:33 -070032 union nf_conntrack_nat_help help;
Pablo Neira Ayuso67981fe2014-09-11 16:55:04 +020033#if IS_ENABLED(CONFIG_NF_NAT_MASQUERADE_IPV4) || \
34 IS_ENABLED(CONFIG_NF_NAT_MASQUERADE_IPV6)
Yasuyuki Kozakai4ba88772007-07-07 22:22:33 -070035 int masq_index;
36#endif
37};
38
Jozsef Kadlecsik5b1158e2006-12-02 22:07:13 -080039/* Set up the info structure to map into this range. */
Joe Perches4e77be42013-09-23 11:37:48 -070040unsigned int nf_nat_setup_info(struct nf_conn *ct,
41 const struct nf_nat_range *range,
42 enum nf_nat_manip_type maniptype);
Jozsef Kadlecsik5b1158e2006-12-02 22:07:13 -080043
Pablo Neira Ayusof59cb042013-10-14 10:57:04 +020044extern unsigned int nf_nat_alloc_null_binding(struct nf_conn *ct,
45 unsigned int hooknum);
46
Florian Westphalf768e5b2014-04-28 21:09:50 +020047struct nf_conn_nat *nf_ct_nat_ext_add(struct nf_conn *ct);
48
Jozsef Kadlecsik5b1158e2006-12-02 22:07:13 -080049/* Is this tuple already taken? (not by us)*/
Joe Perches4e77be42013-09-23 11:37:48 -070050int nf_nat_used_tuple(const struct nf_conntrack_tuple *tuple,
51 const struct nf_conn *ignored_conntrack);
Jozsef Kadlecsik5b1158e2006-12-02 22:07:13 -080052
Yasuyuki Kozakai2d59e5c2007-07-07 22:24:28 -070053static inline struct nf_conn_nat *nfct_nat(const struct nf_conn *ct)
54{
Changli Gaoe0e76c82010-11-15 12:23:24 +010055#if defined(CONFIG_NF_NAT) || defined(CONFIG_NF_NAT_MODULE)
Yasuyuki Kozakai2d59e5c2007-07-07 22:24:28 -070056 return nf_ct_ext_find(ct, NF_CT_EXT_NAT);
Changli Gaoe0e76c82010-11-15 12:23:24 +010057#else
58 return NULL;
59#endif
Yasuyuki Kozakai2d59e5c2007-07-07 22:24:28 -070060}
61
Jozsef Kadlecsika0ecb852012-11-30 12:37:26 +000062static inline bool nf_nat_oif_changed(unsigned int hooknum,
63 enum ip_conntrack_info ctinfo,
64 struct nf_conn_nat *nat,
65 const struct net_device *out)
66{
Pablo Neira Ayuso67981fe2014-09-11 16:55:04 +020067#if IS_ENABLED(CONFIG_NF_NAT_MASQUERADE_IPV4) || \
68 IS_ENABLED(CONFIG_NF_NAT_MASQUERADE_IPV6)
Jozsef Kadlecsika0ecb852012-11-30 12:37:26 +000069 return nat->masq_index && hooknum == NF_INET_POST_ROUTING &&
70 CTINFO2DIR(ctinfo) == IP_CT_DIR_ORIGINAL &&
71 nat->masq_index != out->ifindex;
72#else
73 return false;
74#endif
75}
76
Jozsef Kadlecsik5b1158e2006-12-02 22:07:13 -080077#endif