xref: /openbmc/linux/drivers/net/wireguard/main.c (revision f3d7c2cd)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
4  */
5 
6 #include "version.h"
7 #include "device.h"
8 #include "noise.h"
9 #include "queueing.h"
10 #include "ratelimiter.h"
11 #include "netlink.h"
12 
13 #include <uapi/linux/wireguard.h>
14 
15 #include <linux/init.h>
16 #include <linux/module.h>
17 #include <linux/genetlink.h>
18 #include <net/rtnetlink.h>
19 
20 static int __init mod_init(void)
21 {
22 	int ret;
23 
24 	ret = wg_allowedips_slab_init();
25 	if (ret < 0)
26 		goto err_allowedips;
27 
28 #ifdef DEBUG
29 	ret = -ENOTRECOVERABLE;
30 	if (!wg_allowedips_selftest() || !wg_packet_counter_selftest() ||
31 	    !wg_ratelimiter_selftest())
32 		goto err_peer;
33 #endif
34 	wg_noise_init();
35 
36 	ret = wg_peer_init();
37 	if (ret < 0)
38 		goto err_peer;
39 
40 	ret = wg_device_init();
41 	if (ret < 0)
42 		goto err_device;
43 
44 	ret = wg_genetlink_init();
45 	if (ret < 0)
46 		goto err_netlink;
47 
48 	pr_info("WireGuard " WIREGUARD_VERSION " loaded. See www.wireguard.com for information.\n");
49 	pr_info("Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.\n");
50 
51 	return 0;
52 
53 err_netlink:
54 	wg_device_uninit();
55 err_device:
56 	wg_peer_uninit();
57 err_peer:
58 	wg_allowedips_slab_uninit();
59 err_allowedips:
60 	return ret;
61 }
62 
63 static void __exit mod_exit(void)
64 {
65 	wg_genetlink_uninit();
66 	wg_device_uninit();
67 	wg_peer_uninit();
68 	wg_allowedips_slab_uninit();
69 }
70 
71 module_init(mod_init);
72 module_exit(mod_exit);
73 MODULE_LICENSE("GPL v2");
74 MODULE_DESCRIPTION("WireGuard secure network tunnel");
75 MODULE_AUTHOR("Jason A. Donenfeld <Jason@zx2c4.com>");
76 MODULE_VERSION(WIREGUARD_VERSION);
77 MODULE_ALIAS_RTNL_LINK(KBUILD_MODNAME);
78 MODULE_ALIAS_GENL_FAMILY(WG_GENL_NAME);
79