aboutsummaryrefslogtreecommitdiffstatshomepage
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
commitf91c72c70b26eb0b0b3b729e4e4f2a7ae96248dd (patch)
treef3a65c3905c513e37f19292f3d9008840a1d1655
parentglobal: use pointer to net_device (diff)
downloadwireguard-monolithic-historical-f91c72c70b26eb0b0b3b729e4e4f2a7ae96248dd.tar.xz
wireguard-monolithic-historical-f91c72c70b26eb0b0b3b729e4e4f2a7ae96248dd.zip
ratelimiter: use KMEM_CACHE macro
Suggested-by: Samuel Holland <samuel@sholland.org>
-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;