aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--net/ipv4/netfilter/nf_nat_proto_common.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/net/ipv4/netfilter/nf_nat_proto_common.c b/net/ipv4/netfilter/nf_nat_proto_common.c
index a124213fb9da..871ab0eb325d 100644
--- a/net/ipv4/netfilter/nf_nat_proto_common.c
+++ b/net/ipv4/netfilter/nf_nat_proto_common.c
@@ -42,6 +42,7 @@ int nf_nat_proto_unique_tuple(struct nf_conntrack_tuple *tuple,
42{ 42{
43 unsigned int range_size, min, i; 43 unsigned int range_size, min, i;
44 __be16 *portptr; 44 __be16 *portptr;
45 u_int16_t off;
45 46
46 if (maniptype == IP_NAT_MANIP_SRC) 47 if (maniptype == IP_NAT_MANIP_SRC)
47 portptr = &tuple->src.u.all; 48 portptr = &tuple->src.u.all;
@@ -72,13 +73,17 @@ int nf_nat_proto_unique_tuple(struct nf_conntrack_tuple *tuple,
72 range_size = ntohs(range->max.all) - min + 1; 73 range_size = ntohs(range->max.all) - min + 1;
73 } 74 }
74 75
76 off = *rover;
75 if (range->flags & IP_NAT_RANGE_PROTO_RANDOM) 77 if (range->flags & IP_NAT_RANGE_PROTO_RANDOM)
76 *rover = net_random(); 78 off = net_random();
77 79
78 for (i = 0; i < range_size; i++, (*rover)++) { 80 for (i = 0; i < range_size; i++, off++) {
79 *portptr = htons(min + *rover % range_size); 81 *portptr = htons(min + off % range_size);
80 if (!nf_nat_used_tuple(tuple, ct)) 82 if (nf_nat_used_tuple(tuple, ct))
81 return 1; 83 continue;
84 if (!(range->flags & IP_NAT_RANGE_PROTO_RANDOM))
85 *rover = off;
86 return 1;
82 } 87 }
83 return 0; 88 return 0;
84} 89}