summaryrefslogtreecommitdiffhomepage
path: root/src/main.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2016-11-25 21:14:50 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2016-11-29 13:18:33 +0100
commitfa449736cd339c8b81a757ce5f156625a05810e4 (patch)
tree735a0690b5348d52928dfeff4231e34521470000 /src/main.c
parent5442adf8d39675989193a7d29c6e5be59e3942e1 (diff)
ratelimiter: load hashlimit at modinsert time
This fixes a potential race with net_lock and rtnl_lock. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/src/main.c b/src/main.c
index 3102408..cd8c591 100644
--- a/src/main.c
+++ b/src/main.c
@@ -16,7 +16,7 @@
static int __init mod_init(void)
{
- int ret = 0;
+ int ret;
#ifdef DEBUG
if (!routing_table_selftest() ||
@@ -30,22 +30,31 @@ static int __init mod_init(void)
chacha20poly1305_init();
noise_init();
+ ret = ratelimiter_module_init();
+ if (ret < 0)
+ goto out;
+
#ifdef CONFIG_WIREGUARD_PARALLEL
ret = packet_init_data_caches();
if (ret < 0)
- return ret;
+ goto err_packet;
#endif
ret = device_init();
- if (ret < 0) {
-#ifdef CONFIG_WIREGUARD_PARALLEL
- packet_deinit_data_caches();
-#endif
- return ret;
- }
+ if (ret < 0)
+ goto err_device;
pr_info("WireGuard " WIREGUARD_VERSION " loaded. See www.wireguard.io for information.\n");
pr_info("Copyright (C) 2015-2016 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.\n");
+
+ goto out;
+err_device:
+#ifdef CONFIG_WIREGUARD_PARALLEL
+ packet_deinit_data_caches();
+#endif
+err_packet:
+ ratelimiter_module_deinit();
+out:
return ret;
}
@@ -55,6 +64,7 @@ static void __exit mod_exit(void)
#ifdef CONFIG_WIREGUARD_PARALLEL
packet_deinit_data_caches();
#endif
+ ratelimiter_module_deinit();
pr_debug("WireGuard has been unloaded\n");
}