Merge branch 'upstream' of git://ftp.linux-mips.org/pub/scm/upstream-apm
[sfrench/cifs-2.6.git] / include / linux / netfilter_ipv4 / ip_nat.h
1 #ifndef _IP_NAT_H
2 #define _IP_NAT_H
3 #include <linux/netfilter_ipv4.h>
4 #include <linux/netfilter_ipv4/ip_conntrack_tuple.h>
5
6 #define IP_NAT_MAPPING_TYPE_MAX_NAMELEN 16
7
8 enum ip_nat_manip_type
9 {
10         IP_NAT_MANIP_SRC,
11         IP_NAT_MANIP_DST
12 };
13
14 /* SRC manip occurs POST_ROUTING or LOCAL_IN */
15 #define HOOK2MANIP(hooknum) ((hooknum) != NF_IP_POST_ROUTING && (hooknum) != NF_IP_LOCAL_IN)
16
17 #define IP_NAT_RANGE_MAP_IPS 1
18 #define IP_NAT_RANGE_PROTO_SPECIFIED 2
19 #define IP_NAT_RANGE_PROTO_RANDOM 4 /* add randomness to "port" selection */
20
21 /* NAT sequence number modifications */
22 struct ip_nat_seq {
23         /* position of the last TCP sequence number 
24          * modification (if any) */
25         u_int32_t correction_pos;
26         /* sequence number offset before and after last modification */
27         int16_t offset_before, offset_after;
28 };
29
30 /* Single range specification. */
31 struct ip_nat_range
32 {
33         /* Set to OR of flags above. */
34         unsigned int flags;
35
36         /* Inclusive: network order. */
37         __be32 min_ip, max_ip;
38
39         /* Inclusive: network order */
40         union ip_conntrack_manip_proto min, max;
41 };
42
43 /* For backwards compat: don't use in modern code. */
44 struct ip_nat_multi_range_compat
45 {
46         unsigned int rangesize; /* Must be 1. */
47
48         /* hangs off end. */
49         struct ip_nat_range range[1];
50 };
51
52 #ifdef __KERNEL__
53 #include <linux/list.h>
54
55 /* Protects NAT hash tables, and NAT-private part of conntracks. */
56 extern rwlock_t ip_nat_lock;
57
58 /* The structure embedded in the conntrack structure. */
59 struct ip_nat_info
60 {
61         struct list_head bysource;
62         struct ip_nat_seq seq[IP_CT_DIR_MAX];
63 };
64
65 struct ip_conntrack;
66
67 /* Set up the info structure to map into this range. */
68 extern unsigned int ip_nat_setup_info(struct ip_conntrack *conntrack,
69                                       const struct ip_nat_range *range,
70                                       unsigned int hooknum);
71
72 /* Is this tuple already taken? (not by us)*/
73 extern int ip_nat_used_tuple(const struct ip_conntrack_tuple *tuple,
74                              const struct ip_conntrack *ignored_conntrack);
75
76 #else  /* !__KERNEL__: iptables wants this to compile. */
77 #define ip_nat_multi_range ip_nat_multi_range_compat
78 #endif /*__KERNEL__*/
79 #endif