diff options
| -rw-r--r-- | include/uapi/linux/netfilter/nf_nat.h | 12 | ||||
| -rw-r--r-- | net/netfilter/nf_nat_core.c | 4 | ||||
| -rw-r--r-- | net/netfilter/nf_nat_proto_common.c | 10 |
3 files changed, 16 insertions, 10 deletions
diff --git a/include/uapi/linux/netfilter/nf_nat.h b/include/uapi/linux/netfilter/nf_nat.h index bf0cc373ffb6..1ad3659102b6 100644 --- a/include/uapi/linux/netfilter/nf_nat.h +++ b/include/uapi/linux/netfilter/nf_nat.h | |||
| @@ -4,10 +4,14 @@ | |||
| 4 | #include <linux/netfilter.h> | 4 | #include <linux/netfilter.h> |
| 5 | #include <linux/netfilter/nf_conntrack_tuple_common.h> | 5 | #include <linux/netfilter/nf_conntrack_tuple_common.h> |
| 6 | 6 | ||
| 7 | #define NF_NAT_RANGE_MAP_IPS 1 | 7 | #define NF_NAT_RANGE_MAP_IPS (1 << 0) |
| 8 | #define NF_NAT_RANGE_PROTO_SPECIFIED 2 | 8 | #define NF_NAT_RANGE_PROTO_SPECIFIED (1 << 1) |
| 9 | #define NF_NAT_RANGE_PROTO_RANDOM 4 | 9 | #define NF_NAT_RANGE_PROTO_RANDOM (1 << 2) |
| 10 | #define NF_NAT_RANGE_PERSISTENT 8 | 10 | #define NF_NAT_RANGE_PERSISTENT (1 << 3) |
| 11 | #define NF_NAT_RANGE_PROTO_RANDOM_FULLY (1 << 4) | ||
| 12 | |||
| 13 | #define NF_NAT_RANGE_PROTO_RANDOM_ALL \ | ||
| 14 | (NF_NAT_RANGE_PROTO_RANDOM | NF_NAT_RANGE_PROTO_RANDOM_FULLY) | ||
| 11 | 15 | ||
| 12 | struct nf_nat_ipv4_range { | 16 | struct nf_nat_ipv4_range { |
| 13 | unsigned int flags; | 17 | unsigned int flags; |
diff --git a/net/netfilter/nf_nat_core.c b/net/netfilter/nf_nat_core.c index 63a815402211..d3f5cd6dd962 100644 --- a/net/netfilter/nf_nat_core.c +++ b/net/netfilter/nf_nat_core.c | |||
| @@ -315,7 +315,7 @@ get_unique_tuple(struct nf_conntrack_tuple *tuple, | |||
| 315 | * manips not an issue. | 315 | * manips not an issue. |
| 316 | */ | 316 | */ |
| 317 | if (maniptype == NF_NAT_MANIP_SRC && | 317 | if (maniptype == NF_NAT_MANIP_SRC && |
| 318 | !(range->flags & NF_NAT_RANGE_PROTO_RANDOM)) { | 318 | !(range->flags & NF_NAT_RANGE_PROTO_RANDOM_ALL)) { |
| 319 | /* try the original tuple first */ | 319 | /* try the original tuple first */ |
| 320 | if (in_range(l3proto, l4proto, orig_tuple, range)) { | 320 | if (in_range(l3proto, l4proto, orig_tuple, range)) { |
| 321 | if (!nf_nat_used_tuple(orig_tuple, ct)) { | 321 | if (!nf_nat_used_tuple(orig_tuple, ct)) { |
| @@ -339,7 +339,7 @@ get_unique_tuple(struct nf_conntrack_tuple *tuple, | |||
| 339 | */ | 339 | */ |
| 340 | 340 | ||
| 341 | /* Only bother mapping if it's not already in range and unique */ | 341 | /* Only bother mapping if it's not already in range and unique */ |
| 342 | if (!(range->flags & NF_NAT_RANGE_PROTO_RANDOM)) { | 342 | if (!(range->flags & NF_NAT_RANGE_PROTO_RANDOM_ALL)) { |
| 343 | if (range->flags & NF_NAT_RANGE_PROTO_SPECIFIED) { | 343 | if (range->flags & NF_NAT_RANGE_PROTO_SPECIFIED) { |
| 344 | if (l4proto->in_range(tuple, maniptype, | 344 | if (l4proto->in_range(tuple, maniptype, |
| 345 | &range->min_proto, | 345 | &range->min_proto, |
diff --git a/net/netfilter/nf_nat_proto_common.c b/net/netfilter/nf_nat_proto_common.c index 9baaf734c142..83a72a235cae 100644 --- a/net/netfilter/nf_nat_proto_common.c +++ b/net/netfilter/nf_nat_proto_common.c | |||
| @@ -74,22 +74,24 @@ void nf_nat_l4proto_unique_tuple(const struct nf_nat_l3proto *l3proto, | |||
| 74 | range_size = ntohs(range->max_proto.all) - min + 1; | 74 | range_size = ntohs(range->max_proto.all) - min + 1; |
| 75 | } | 75 | } |
| 76 | 76 | ||
| 77 | if (range->flags & NF_NAT_RANGE_PROTO_RANDOM) | 77 | if (range->flags & NF_NAT_RANGE_PROTO_RANDOM) { |
| 78 | off = l3proto->secure_port(tuple, maniptype == NF_NAT_MANIP_SRC | 78 | off = l3proto->secure_port(tuple, maniptype == NF_NAT_MANIP_SRC |
| 79 | ? tuple->dst.u.all | 79 | ? tuple->dst.u.all |
| 80 | : tuple->src.u.all); | 80 | : tuple->src.u.all); |
| 81 | else | 81 | } else if (range->flags & NF_NAT_RANGE_PROTO_RANDOM_FULLY) { |
| 82 | off = prandom_u32(); | ||
| 83 | } else { | ||
| 82 | off = *rover; | 84 | off = *rover; |
| 85 | } | ||
| 83 | 86 | ||
| 84 | for (i = 0; ; ++off) { | 87 | for (i = 0; ; ++off) { |
| 85 | *portptr = htons(min + off % range_size); | 88 | *portptr = htons(min + off % range_size); |
| 86 | if (++i != range_size && nf_nat_used_tuple(tuple, ct)) | 89 | if (++i != range_size && nf_nat_used_tuple(tuple, ct)) |
| 87 | continue; | 90 | continue; |
| 88 | if (!(range->flags & NF_NAT_RANGE_PROTO_RANDOM)) | 91 | if (!(range->flags & NF_NAT_RANGE_PROTO_RANDOM_ALL)) |
| 89 | *rover = off; | 92 | *rover = off; |
| 90 | return; | 93 | return; |
| 91 | } | 94 | } |
| 92 | return; | ||
| 93 | } | 95 | } |
| 94 | EXPORT_SYMBOL_GPL(nf_nat_l4proto_unique_tuple); | 96 | EXPORT_SYMBOL_GPL(nf_nat_l4proto_unique_tuple); |
| 95 | 97 | ||
