diff options
author | David S. Miller <davem@sunset.davemloft.net> | 2006-08-24 04:50:50 -0700 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2006-09-22 15:08:49 -0700 |
commit | 44e36b42a8378be1dcf7e6f8a1cb2710a8903387 (patch) | |
tree | 2c057957a4e4dc7f679ac671a9f091f3fe366b92 /net/xfrm/xfrm_hash.c | |
parent | 2518c7c2b3d7f0a6b302b4efe17c911f8dd4049f (diff) | |
download | lwn-44e36b42a8378be1dcf7e6f8a1cb2710a8903387.tar.gz lwn-44e36b42a8378be1dcf7e6f8a1cb2710a8903387.zip |
[XFRM]: Extract common hashing code into xfrm_hash.[ch]
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/xfrm/xfrm_hash.c')
-rw-r--r-- | net/xfrm/xfrm_hash.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/net/xfrm/xfrm_hash.c b/net/xfrm/xfrm_hash.c new file mode 100644 index 000000000000..37643bb8768a --- /dev/null +++ b/net/xfrm/xfrm_hash.c @@ -0,0 +1,41 @@ +/* xfrm_hash.c: Common hash table code. + * + * Copyright (C) 2006 David S. Miller (davem@davemloft.net) + */ + +#include <linux/kernel.h> +#include <linux/mm.h> +#include <linux/bootmem.h> +#include <linux/vmalloc.h> +#include <linux/slab.h> +#include <linux/xfrm.h> + +#include "xfrm_hash.h" + +struct hlist_head *xfrm_hash_alloc(unsigned int sz) +{ + struct hlist_head *n; + + if (sz <= PAGE_SIZE) + n = kmalloc(sz, GFP_KERNEL); + else if (hashdist) + n = __vmalloc(sz, GFP_KERNEL, PAGE_KERNEL); + else + n = (struct hlist_head *) + __get_free_pages(GFP_KERNEL, get_order(sz)); + + if (n) + memset(n, 0, sz); + + return n; +} + +void xfrm_hash_free(struct hlist_head *n, unsigned int sz) +{ + if (sz <= PAGE_SIZE) + kfree(n); + else if (hashdist) + vfree(n); + else + free_pages((unsigned long)n, get_order(sz)); +} |