]> git.karo-electronics.de Git - linux-beck.git/commitdiff
netfilter: nf_nat: don't check if the tuple is unique when there isn't any other...
authorChangli Gao <xiaosuo@gmail.com>
Mon, 2 Aug 2010 15:35:49 +0000 (17:35 +0200)
committerPatrick McHardy <kaber@trash.net>
Mon, 2 Aug 2010 15:35:49 +0000 (17:35 +0200)
The tuple got from unique_tuple() doesn't need to be really unique, so the
check for the unique tuple isn't necessary, when there isn't any other
choice. Eliminating the unnecessary nf_nat_used_tuple() can save some CPU
cycles too.

Signed-off-by: Changli Gao <xiaosuo@gmail.com>
Signed-off-by: Patrick McHardy <kaber@trash.net>
net/ipv4/netfilter/nf_nat_proto_common.c
net/ipv4/netfilter/nf_nat_proto_gre.c
net/ipv4/netfilter/nf_nat_proto_icmp.c

index 2844a0383a11f05f640c6abcffbd63e45466f256..3e61faf23a9a0c8636433dd9a1805274dfce4691 100644 (file)
@@ -81,9 +81,9 @@ void nf_nat_proto_unique_tuple(struct nf_conntrack_tuple *tuple,
        else
                off = *rover;
 
-       for (i = 0; i < range_size; i++, off++) {
+       for (i = 0; ; ++off) {
                *portptr = htons(min + off % range_size);
-               if (nf_nat_used_tuple(tuple, ct))
+               if (++i != range_size && nf_nat_used_tuple(tuple, ct))
                        continue;
                if (!(range->flags & IP_NAT_RANGE_PROTO_RANDOM))
                        *rover = off;
index 89933ab6f63ee5170bd493af721fc20f091b2c5e..bc8d83a31c73ae4abe371e74c7b0df3e6068c03a 100644 (file)
@@ -68,9 +68,9 @@ gre_unique_tuple(struct nf_conntrack_tuple *tuple,
 
        pr_debug("min = %u, range_size = %u\n", min, range_size);
 
-       for (i = 0; i < range_size; i++, key++) {
+       for (i = 0; ; ++key) {
                *keyptr = htons(min + key % range_size);
-               if (!nf_nat_used_tuple(tuple, ct))
+               if (++i == range_size || !nf_nat_used_tuple(tuple, ct))
                        return;
        }
 
index 97003fe312e3fd67320ac392d837428450e44a90..5744c3ec847cc26440204b7584fdd60d857f7964 100644 (file)
@@ -42,10 +42,10 @@ icmp_unique_tuple(struct nf_conntrack_tuple *tuple,
        if (!(range->flags & IP_NAT_RANGE_PROTO_SPECIFIED))
                range_size = 0xFFFF;
 
-       for (i = 0; i < range_size; i++, id++) {
+       for (i = 0; ; ++id) {
                tuple->src.u.icmp.id = htons(ntohs(range->min.icmp.id) +
                                             (id % range_size));
-               if (!nf_nat_used_tuple(tuple, ct))
+               if (++i == range_size || !nf_nat_used_tuple(tuple, ct))
                        return;
        }
        return;