]> err.no Git - linux-2.6/commitdiff
[NETFILTER]: nf_conntrack: optimize __nf_conntrack_find()
authorPatrick McHardy <kaber@trash.net>
Thu, 31 Jan 2008 12:39:23 +0000 (04:39 -0800)
committerDavid S. Miller <davem@davemloft.net>
Fri, 1 Feb 2008 03:27:55 +0000 (19:27 -0800)
Ignoring specific entries in __nf_conntrack_find() is only needed by NAT
for nf_conntrack_tuple_taken(). Remove it from __nf_conntrack_find()
and make nf_conntrack_tuple_taken() search the hash itself.

Saves 54 bytes of text in the hotpath on x86_64:

  __nf_conntrack_find      |  -54 # 321 -> 267, # inlines: 3 -> 2, size inlines: 181 -> 127
  nf_conntrack_tuple_taken | +305 # 15 -> 320, lexblocks: 0 -> 3, # inlines: 0 -> 3, size inlines: 0 -> 181
  nf_conntrack_find_get    |   -2 # 90 -> 88
 3 functions changed, 305 bytes added, 56 bytes removed, diff: +249

Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/netfilter/nf_conntrack.h
net/netfilter/nf_conntrack_core.c
net/netfilter/nf_conntrack_netlink.c
net/netfilter/xt_connlimit.c

index 561ae7658f55ffb8870c4ff407d537c846fbe5dc..14e0cc8364f2f7e5fe22320c12f3f7763c41a7a4 100644 (file)
@@ -178,8 +178,7 @@ extern void nf_ct_free_hashtable(struct hlist_head *hash, int vmalloced,
                                 unsigned int size);
 
 extern struct nf_conntrack_tuple_hash *
-__nf_conntrack_find(const struct nf_conntrack_tuple *tuple,
-                   const struct nf_conn *ignored_conntrack);
+__nf_conntrack_find(const struct nf_conntrack_tuple *tuple);
 
 extern void nf_conntrack_hash_insert(struct nf_conn *ct);
 
index f284dddfc8999cf7ac56c6e435a6ed856429b541..ce4c4ba31cb170c94bd9dbc8548acadabf22b1ee 100644 (file)
@@ -246,16 +246,14 @@ static void death_by_timeout(unsigned long ul_conntrack)
 }
 
 struct nf_conntrack_tuple_hash *
-__nf_conntrack_find(const struct nf_conntrack_tuple *tuple,
-                   const struct nf_conn *ignored_conntrack)
+__nf_conntrack_find(const struct nf_conntrack_tuple *tuple)
 {
        struct nf_conntrack_tuple_hash *h;
        struct hlist_node *n;
        unsigned int hash = hash_conntrack(tuple);
 
        hlist_for_each_entry_rcu(h, n, &nf_conntrack_hash[hash], hnode) {
-               if (nf_ct_tuplehash_to_ctrack(h) != ignored_conntrack &&
-                   nf_ct_tuple_equal(tuple, &h->tuple)) {
+               if (nf_ct_tuple_equal(tuple, &h->tuple)) {
                        NF_CT_STAT_INC(found);
                        return h;
                }
@@ -274,7 +272,7 @@ nf_conntrack_find_get(const struct nf_conntrack_tuple *tuple)
        struct nf_conn *ct;
 
        rcu_read_lock();
-       h = __nf_conntrack_find(tuple, NULL);
+       h = __nf_conntrack_find(tuple);
        if (h) {
                ct = nf_ct_tuplehash_to_ctrack(h);
                if (unlikely(!atomic_inc_not_zero(&ct->ct_general.use)))
@@ -395,12 +393,22 @@ nf_conntrack_tuple_taken(const struct nf_conntrack_tuple *tuple,
                         const struct nf_conn *ignored_conntrack)
 {
        struct nf_conntrack_tuple_hash *h;
+       struct hlist_node *n;
+       unsigned int hash = hash_conntrack(tuple);
 
        rcu_read_lock();
-       h = __nf_conntrack_find(tuple, ignored_conntrack);
+       hlist_for_each_entry_rcu(h, n, &nf_conntrack_hash[hash], hnode) {
+               if (nf_ct_tuplehash_to_ctrack(h) != ignored_conntrack &&
+                   nf_ct_tuple_equal(tuple, &h->tuple)) {
+                       NF_CT_STAT_INC(found);
+                       rcu_read_unlock();
+                       return 1;
+               }
+               NF_CT_STAT_INC(searched);
+       }
        rcu_read_unlock();
 
-       return h != NULL;
+       return 0;
 }
 EXPORT_SYMBOL_GPL(nf_conntrack_tuple_taken);
 
index b6a8c089a075837de862561cbef6a986621e5936..bf86fdd89fd0595d822b954174bac9edb3a657e9 100644 (file)
@@ -1222,9 +1222,9 @@ ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb,
 
        spin_lock_bh(&nf_conntrack_lock);
        if (cda[CTA_TUPLE_ORIG])
-               h = __nf_conntrack_find(&otuple, NULL);
+               h = __nf_conntrack_find(&otuple);
        else if (cda[CTA_TUPLE_REPLY])
-               h = __nf_conntrack_find(&rtuple, NULL);
+               h = __nf_conntrack_find(&rtuple);
 
        if (h == NULL) {
                struct nf_conntrack_tuple master;
@@ -1239,7 +1239,7 @@ ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb,
                        if (err < 0)
                                goto out_unlock;
 
-                       master_h = __nf_conntrack_find(&master, NULL);
+                       master_h = __nf_conntrack_find(&master);
                        if (master_h == NULL) {
                                err = -ENOENT;
                                goto out_unlock;
index f9b59a6753ee26a4c2cf5dac18831db2f2c952e5..3b0111933f601782887e4edc8f7500aff4a2116f 100644 (file)
@@ -124,7 +124,7 @@ static int count_them(struct xt_connlimit_data *data,
 
        /* check the saved connections */
        list_for_each_entry_safe(conn, tmp, hash, list) {
-               found    = __nf_conntrack_find(&conn->tuple, NULL);
+               found    = __nf_conntrack_find(&conn->tuple);
                found_ct = NULL;
 
                if (found != NULL)