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