Commit 98d500d6 authored by Patrick McHardy's avatar Patrick McHardy

netfilter: nf_nat: add support for persistent mappings

The removal of the SAME target accidentally removed one feature that is
not available from the normal NAT targets so far, having multi-range
mappings that use the same mapping for each connection from a single
client. The current behaviour is to choose the address from the range
based on source and destination IP, which breaks when communicating
with sites having multiple addresses that require all connections to
originate from the same IP address.

Introduce a IP_NAT_RANGE_PERSISTENT option that controls whether the
destination address is taken into account for selecting addresses.

http://bugzilla.kernel.org/show_bug.cgi?id=12954Signed-off-by: default avatarPatrick McHardy <kaber@trash.net>
parent 38fb0afc
...@@ -18,6 +18,7 @@ enum nf_nat_manip_type ...@@ -18,6 +18,7 @@ enum nf_nat_manip_type
#define IP_NAT_RANGE_MAP_IPS 1 #define IP_NAT_RANGE_MAP_IPS 1
#define IP_NAT_RANGE_PROTO_SPECIFIED 2 #define IP_NAT_RANGE_PROTO_SPECIFIED 2
#define IP_NAT_RANGE_PROTO_RANDOM 4 #define IP_NAT_RANGE_PROTO_RANDOM 4
#define IP_NAT_RANGE_PERSISTENT 8
/* NAT sequence number modifications */ /* NAT sequence number modifications */
struct nf_nat_seq { struct nf_nat_seq {
......
...@@ -211,7 +211,8 @@ find_best_ips_proto(struct nf_conntrack_tuple *tuple, ...@@ -211,7 +211,8 @@ find_best_ips_proto(struct nf_conntrack_tuple *tuple,
minip = ntohl(range->min_ip); minip = ntohl(range->min_ip);
maxip = ntohl(range->max_ip); maxip = ntohl(range->max_ip);
j = jhash_2words((__force u32)tuple->src.u3.ip, j = jhash_2words((__force u32)tuple->src.u3.ip,
(__force u32)tuple->dst.u3.ip, 0); range->flags & IP_NAT_RANGE_PERSISTENT ?
(__force u32)tuple->dst.u3.ip : 0, 0);
j = ((u64)j * (maxip - minip + 1)) >> 32; j = ((u64)j * (maxip - minip + 1)) >> 32;
*var_ipp = htonl(minip + j); *var_ipp = htonl(minip + j);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment