nf_nat: don't check if the tuple is unique when there isn't any other choice
Subsystems (3)
PATCH 2/2 nf_nat: don't check if the tuple is unique when there isn't any other choice
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.
----
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(-)
net/ipv4/netfilter/nf_nat_proto_common.c +2 -2
@@ -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;
net/ipv4/netfilter/nf_nat_proto_gre.c +2 -2
@@ -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 ; }
net/ipv4/netfilter/nf_nat_proto_icmp.c +2 -2
@@ -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 ;
net/ipv4/netfilter/nf_nat_proto_common.c void nf_nat_proto_unique_tuple(struct nf_conntrack_tuple *tuple, · line 84
Quoted 7 lines · Changli Gao
+++
b/net/ipv4/netfilter/nf_nat_proto_common.cnet/ipv4/netfilter/nf_nat_proto_common.c +1
-1@@ -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).
Quoted 7 lines · Jan Engelhardt
Quoted 5 lines · Changli Gao
+++
b/net/ipv4/netfilter/nf_nat_proto_common.c(quoted diff) +0
-0@@ -81,9 +81,9 @@ void nf_nat_proto_unique_tuple(struct nf_conntrack_tuple *tuple,else
off = *rover;
Quoted 7 lines
Quoted 2 lines
- 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.
Signature · 6 lines
Regards, Changli Gao([email protected]) -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html