summaryrefslogtreecommitdiffhomepage
path: root/src/main.c
blob: 67ce6a6be7128e2a5fa1d0f4038f1a45136e1813 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* Copyright 2015-2016 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. */

#include "wireguard.h"
#include "device.h"
#include "crypto/chacha20poly1305.h"
#include "crypto/blake2s.h"
#include "crypto/siphash24.h"
#include "crypto/curve25519.h"
#include "noise.h"
#include "packets.h"
#include <linux/init.h>
#include <linux/module.h>
#include <net/rtnetlink.h>

static int __init mod_init(void)
{
	int ret = 0;

#ifdef DEBUG
	if (!routing_table_selftest() ||
	    !packet_counter_selftest() ||
	    !curve25519_selftest() ||
	    !chacha20poly1305_selftest() ||
	    !blake2s_selftest() ||
	    !siphash24_selftest())
		return -ENOTRECOVERABLE;
#endif
	chacha20poly1305_init();
	noise_init();

	ret = device_init();
	if (ret < 0)
		return ret;

	pr_info("WireGuard loaded. See www.wireguard.io for information.\n");
	pr_info("(C) Copyright 2015-2016 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.\n");
	return ret;
}

static void __exit mod_exit(void)
{
	device_uninit();
	pr_debug("WireGuard has been unloaded\n");
}

module_init(mod_init);
module_exit(mod_exit);
MODULE_LICENSE("GPL v2");
MODULE_DESCRIPTION("Simple, secure, and speedy VPN tunnel");
MODULE_AUTHOR("Jason A. Donenfeld <Jason@zx2c4.com>");
MODULE_ALIAS_RTNL_LINK(KBUILD_MODNAME);