Commit 94b9bb54 authored by Jamal Hadi Salim's avatar Jamal Hadi Salim Committed by David S. Miller

[XFRM] Optimize SA dumping

Same comments as in "[XFRM] Optimize policy dumping"

The numbers are (20K SAs):
parent baf5d743
...@@ -1099,7 +1099,7 @@ int xfrm_state_walk(u8 proto, int (*func)(struct xfrm_state *, int, void*), ...@@ -1099,7 +1099,7 @@ int xfrm_state_walk(u8 proto, int (*func)(struct xfrm_state *, int, void*),
void *data) void *data)
{ {
int i; int i;
struct xfrm_state *x; struct xfrm_state *x, *last = NULL;
struct hlist_node *entry; struct hlist_node *entry;
int count = 0; int count = 0;
int err = 0; int err = 0;
...@@ -1107,24 +1107,22 @@ int xfrm_state_walk(u8 proto, int (*func)(struct xfrm_state *, int, void*), ...@@ -1107,24 +1107,22 @@ int xfrm_state_walk(u8 proto, int (*func)(struct xfrm_state *, int, void*),
spin_lock_bh(&xfrm_state_lock); spin_lock_bh(&xfrm_state_lock);
for (i = 0; i <= xfrm_state_hmask; i++) { for (i = 0; i <= xfrm_state_hmask; i++) {
hlist_for_each_entry(x, entry, xfrm_state_bydst+i, bydst) { hlist_for_each_entry(x, entry, xfrm_state_bydst+i, bydst) {
if (xfrm_id_proto_match(x->id.proto, proto)) if (!xfrm_id_proto_match(x->id.proto, proto))
count++; continue;
if (last) {
err = func(last, count, data);
if (err)
goto out;
}
last = x;
count++;
} }
} }
if (count == 0) { if (count == 0) {
err = -ENOENT; err = -ENOENT;
goto out; goto out;
} }
err = func(last, 0, data);
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;
}
}
out: out:
spin_unlock_bh(&xfrm_state_lock); spin_unlock_bh(&xfrm_state_lock);
return err; return err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment