summaryrefslogtreecommitdiffhomepage
path: root/src/ratelimiter.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2017-07-11 04:25:32 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2017-07-20 03:37:39 +0200
commit52b3a7bc7cd8a74e273cb108042ea93f76d58468 (patch)
treeb4321eb4c43d070b7ed7abfd3636b1a7e3defc79 /src/ratelimiter.c
parentc5a6241a38db13a73c710fcfde86b5cf7796260f (diff)
ratelimiter: use KMEM_CACHE macro
Suggested-by: Samuel Holland <samuel@sholland.org> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/ratelimiter.c')
-rw-r--r--src/ratelimiter.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/ratelimiter.c b/src/ratelimiter.c
index 9c8a0c9..9ad451e 100644
--- a/src/ratelimiter.c
+++ b/src/ratelimiter.c
@@ -19,7 +19,7 @@ static struct hlist_head *table_v4;
static struct hlist_head *table_v6;
#endif
-struct entry {
+struct ratelimiter_entry {
u64 last_time_ns, tokens;
__be64 ip;
void *net;
@@ -37,11 +37,11 @@ enum {
static void entry_free(struct rcu_head *rcu)
{
- kmem_cache_free(entry_cache, container_of(rcu, struct entry, rcu));
+ kmem_cache_free(entry_cache, container_of(rcu, struct ratelimiter_entry, rcu));
atomic_dec(&total_entries);
}
-static void entry_uninit(struct entry *entry)
+static void entry_uninit(struct ratelimiter_entry *entry)
{
hlist_del_rcu(&entry->hash);
call_rcu(&entry->rcu, entry_free);
@@ -51,7 +51,7 @@ static void entry_uninit(struct entry *entry)
static void gc_entries(struct work_struct *work)
{
unsigned int i;
- struct entry *entry;
+ struct ratelimiter_entry *entry;
struct hlist_node *temp;
const u64 now = ktime_get_ns();
@@ -77,7 +77,7 @@ static void gc_entries(struct work_struct *work)
bool ratelimiter_allow(struct sk_buff *skb, struct net *net)
{
- struct entry *entry;
+ struct ratelimiter_entry *entry;
struct hlist_head *bucket;
struct { __be64 ip; u32 net; } data = { .net = (unsigned long)net & 0xffffffff };
@@ -142,7 +142,7 @@ int ratelimiter_init(void)
if (atomic64_inc_return(&refcnt) != 1)
return 0;
- entry_cache = kmem_cache_create("wireguard_ratelimiter", sizeof(struct entry), 0, 0, NULL);
+ entry_cache = KMEM_CACHE(ratelimiter_entry, 0);
if (!entry_cache)
goto err;