18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#include "version.h" 78c2ecf20Sopenharmony_ci#include "device.h" 88c2ecf20Sopenharmony_ci#include "noise.h" 98c2ecf20Sopenharmony_ci#include "queueing.h" 108c2ecf20Sopenharmony_ci#include "ratelimiter.h" 118c2ecf20Sopenharmony_ci#include "netlink.h" 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include <uapi/linux/wireguard.h> 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#include <linux/init.h> 168c2ecf20Sopenharmony_ci#include <linux/module.h> 178c2ecf20Sopenharmony_ci#include <linux/genetlink.h> 188c2ecf20Sopenharmony_ci#include <net/rtnetlink.h> 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_cistatic int __init mod_init(void) 218c2ecf20Sopenharmony_ci{ 228c2ecf20Sopenharmony_ci int ret; 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci ret = wg_allowedips_slab_init(); 258c2ecf20Sopenharmony_ci if (ret < 0) 268c2ecf20Sopenharmony_ci goto err_allowedips; 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci#ifdef DEBUG 298c2ecf20Sopenharmony_ci ret = -ENOTRECOVERABLE; 308c2ecf20Sopenharmony_ci if (!wg_allowedips_selftest() || !wg_packet_counter_selftest() || 318c2ecf20Sopenharmony_ci !wg_ratelimiter_selftest()) 328c2ecf20Sopenharmony_ci goto err_peer; 338c2ecf20Sopenharmony_ci#endif 348c2ecf20Sopenharmony_ci wg_noise_init(); 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci ret = wg_peer_init(); 378c2ecf20Sopenharmony_ci if (ret < 0) 388c2ecf20Sopenharmony_ci goto err_peer; 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci ret = wg_device_init(); 418c2ecf20Sopenharmony_ci if (ret < 0) 428c2ecf20Sopenharmony_ci goto err_device; 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci ret = wg_genetlink_init(); 458c2ecf20Sopenharmony_ci if (ret < 0) 468c2ecf20Sopenharmony_ci goto err_netlink; 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci pr_info("WireGuard " WIREGUARD_VERSION " loaded. See www.wireguard.com for information.\n"); 498c2ecf20Sopenharmony_ci pr_info("Copyright (C) 2015-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.\n"); 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci return 0; 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_cierr_netlink: 548c2ecf20Sopenharmony_ci wg_device_uninit(); 558c2ecf20Sopenharmony_cierr_device: 568c2ecf20Sopenharmony_ci wg_peer_uninit(); 578c2ecf20Sopenharmony_cierr_peer: 588c2ecf20Sopenharmony_ci wg_allowedips_slab_uninit(); 598c2ecf20Sopenharmony_cierr_allowedips: 608c2ecf20Sopenharmony_ci return ret; 618c2ecf20Sopenharmony_ci} 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_cistatic void __exit mod_exit(void) 648c2ecf20Sopenharmony_ci{ 658c2ecf20Sopenharmony_ci wg_genetlink_uninit(); 668c2ecf20Sopenharmony_ci wg_device_uninit(); 678c2ecf20Sopenharmony_ci wg_peer_uninit(); 688c2ecf20Sopenharmony_ci wg_allowedips_slab_uninit(); 698c2ecf20Sopenharmony_ci} 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_cimodule_init(mod_init); 728c2ecf20Sopenharmony_cimodule_exit(mod_exit); 738c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2"); 748c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("WireGuard secure network tunnel"); 758c2ecf20Sopenharmony_ciMODULE_AUTHOR("Jason A. Donenfeld <Jason@zx2c4.com>"); 768c2ecf20Sopenharmony_ciMODULE_VERSION(WIREGUARD_VERSION); 778c2ecf20Sopenharmony_ciMODULE_ALIAS_RTNL_LINK(KBUILD_MODNAME); 788c2ecf20Sopenharmony_ciMODULE_ALIAS_GENL_FAMILY(WG_GENL_NAME); 79