]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
[XFRM] Optimize SA dumping
authorJamal Hadi Salim <hadi@cyberus.ca>
Tue, 5 Dec 2006 04:03:35 +0000 (20:03 -0800)
committerDavid S. Miller <davem@sunset.davemloft.net>
Thu, 7 Dec 2006 02:38:45 +0000 (18:38 -0800)
Same comments as in "[XFRM] Optimize policy dumping"

The numbers are (20K SAs):

net/xfrm/xfrm_state.c

index da54a64ccfa3b9ffb4d4401ad3fac881591ce2dd..a14c88bf17f0c0bf6b7fb8ffcd71e0bdae017f54 100644 (file)
@@ -1099,7 +1099,7 @@ int xfrm_state_walk(u8 proto, int (*func)(struct xfrm_state *, int, void*),
                    void *data)
 {
        int i;
-       struct xfrm_state *x;
+       struct xfrm_state *x, *last = NULL;
        struct hlist_node *entry;
        int count = 0;
        int err = 0;
@@ -1107,24 +1107,22 @@ int xfrm_state_walk(u8 proto, int (*func)(struct xfrm_state *, int, void*),
        spin_lock_bh(&xfrm_state_lock);
        for (i = 0; i <= xfrm_state_hmask; i++) {
                hlist_for_each_entry(x, entry, xfrm_state_bydst+i, bydst) {
-                       if (xfrm_id_proto_match(x->id.proto, proto))
-                               count++;
+                       if (!xfrm_id_proto_match(x->id.proto, proto))
+                               continue;
+                       if (last) {
+                               err = func(last, count, data);
+                               if (err)
+                                       goto out;
+                       }
+                       last = x;
+                       count++;
                }
        }
        if (count == 0) {
                err = -ENOENT;
                goto out;
        }
-
-       for (i = 0; i <= xfrm_state_hmask; i++) {
-               hlist_for_each_entry(x, entry, xfrm_state_bydst+i, bydst) {
-                       if (!xfrm_id_proto_match(x->id.proto, proto))
-                               continue;
-                       err = func(x, --count, data);
-                       if (err)
-                               goto out;
-               }
-       }
+       err = func(last, 0, data);
 out:
        spin_unlock_bh(&xfrm_state_lock);
        return err;