* [PATCH 2/2] nf_nat: don't check if the tuple is unique when there isn't any other choice
@ 2010-07-31 2:22 Changli Gao
2010-07-31 14:03 ` Jan Engelhardt
0 siblings, 1 reply; 3+ messages in thread
From: Changli Gao @ 2010-07-31 2:22 UTC (permalink / raw)
To: Patrick McHardy; +Cc: David S. Miller, netfilter-devel, netdev, Changli Gao
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>
----
net/ipv4/netfilter/nf_nat_proto_common.c | 4 ++--
net/ipv4/netfilter/nf_nat_proto_gre.c | 4 ++--
net/ipv4/netfilter/nf_nat_proto_icmp.c | 4 ++--
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/net/ipv4/netfilter/nf_nat_proto_common.c b/net/ipv4/netfilter/nf_nat_proto_common.c
index 2844a03..95aa286 100644
--- a/net/ipv4/netfilter/nf_nat_proto_common.c
+++ b/net/ipv4/netfilter/nf_nat_proto_common.c
@@ -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; 1; 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;
diff --git a/net/ipv4/netfilter/nf_nat_proto_gre.c b/net/ipv4/netfilter/nf_nat_proto_gre.c
index 89933ab..1669be6 100644
--- a/net/ipv4/netfilter/nf_nat_proto_gre.c
+++ b/net/ipv4/netfilter/nf_nat_proto_gre.c
@@ -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; 1; 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;
}
diff --git a/net/ipv4/netfilter/nf_nat_proto_icmp.c b/net/ipv4/netfilter/nf_nat_proto_icmp.c
index 97003fe..f6b07c9 100644
--- a/net/ipv4/netfilter/nf_nat_proto_icmp.c
+++ b/net/ipv4/netfilter/nf_nat_proto_icmp.c
@@ -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; 1; 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;
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 2/2] nf_nat: don't check if the tuple is unique when there isn't any other choice
2010-07-31 2:22 [PATCH 2/2] nf_nat: don't check if the tuple is unique when there isn't any other choice Changli Gao
@ 2010-07-31 14:03 ` Jan Engelhardt
2010-07-31 14:07 ` Changli Gao
0 siblings, 1 reply; 3+ messages in thread
From: Jan Engelhardt @ 2010-07-31 14:03 UTC (permalink / raw)
To: Changli Gao; +Cc: Patrick McHardy, David S. Miller, netfilter-devel, netdev
On Saturday 2010-07-31 04:22, Changli Gao wrote:
>+++ b/net/ipv4/netfilter/nf_nat_proto_common.c
>@@ -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; 1; off++) {
The 1 looks strange. It's more common to express this without
a condition, as in (i = 0; ; ++off).
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 2/2] nf_nat: don't check if the tuple is unique when there isn't any other choice
2010-07-31 14:03 ` Jan Engelhardt
@ 2010-07-31 14:07 ` Changli Gao
0 siblings, 0 replies; 3+ messages in thread
From: Changli Gao @ 2010-07-31 14:07 UTC (permalink / raw)
To: Jan Engelhardt; +Cc: Patrick McHardy, David S. Miller, netfilter-devel, netdev
On Sat, Jul 31, 2010 at 10:03 PM, Jan Engelhardt <jengelh@medozas.de> wrote:
>
> On Saturday 2010-07-31 04:22, Changli Gao wrote:
>>+++ b/net/ipv4/netfilter/nf_nat_proto_common.c
>>@@ -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; 1; off++) {
>
> The 1 looks strange. It's more common to express this without
> a condition, as in (i = 0; ; ++off).
>
>
OK, Thanks.
--
Regards,
Changli Gao(xiaosuo@gmail.com)
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-07-31 14:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-31 2:22 [PATCH 2/2] nf_nat: don't check if the tuple is unique when there isn't any other choice Changli Gao
2010-07-31 14:03 ` Jan Engelhardt
2010-07-31 14:07 ` Changli Gao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).