diff options
author | Tobias Brunner <tobias@strongswan.org> | 2013-06-11 18:47:55 +0200 |
---|---|---|
committer | Tobias Brunner <tobias@strongswan.org> | 2013-06-21 17:03:20 +0200 |
commit | 59be6ddd08f8b3eba53daf9f5fd69a2971bc4dee (patch) | |
tree | 3e780f66b3b6183d98d0c979cec190cdde9b69a0 /src/libcharon/plugins/kernel_libipsec/kernel_libipsec_plugin.c | |
parent | 279e0d42bd1e16095ae773191f408c258be1bb9b (diff) | |
download | strongswan-59be6ddd08f8b3eba53daf9f5fd69a2971bc4dee.tar.bz2 strongswan-59be6ddd08f8b3eba53daf9f5fd69a2971bc4dee.tar.xz |
kernel-libipsec: Create a TUN device and use it to install virtual IPs
Diffstat (limited to 'src/libcharon/plugins/kernel_libipsec/kernel_libipsec_plugin.c')
-rw-r--r-- | src/libcharon/plugins/kernel_libipsec/kernel_libipsec_plugin.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/libcharon/plugins/kernel_libipsec/kernel_libipsec_plugin.c b/src/libcharon/plugins/kernel_libipsec/kernel_libipsec_plugin.c index a20ee7b4b..9fa811d02 100644 --- a/src/libcharon/plugins/kernel_libipsec/kernel_libipsec_plugin.c +++ b/src/libcharon/plugins/kernel_libipsec/kernel_libipsec_plugin.c @@ -17,8 +17,11 @@ #include "kernel_libipsec_ipsec.h" #include <ipsec.h> +#include <networking/tun_device.h> #include <utils/debug.h> +#define TUN_DEFAULT_MTU 1400 + typedef struct private_kernel_libipsec_plugin_t private_kernel_libipsec_plugin_t; /** @@ -30,6 +33,12 @@ struct private_kernel_libipsec_plugin_t { * implements plugin interface */ kernel_libipsec_plugin_t public; + + /** + * TUN device created by this plugin + */ + tun_device_t *tun; + }; METHOD(plugin_t, get_name, char*, @@ -52,6 +61,11 @@ METHOD(plugin_t, get_features, int, METHOD(plugin_t, destroy, void, private_kernel_libipsec_plugin_t *this) { + if (this->tun) + { + lib->set(lib, "kernel-libipsec-tun", NULL); + this->tun->destroy(this->tun); + } libipsec_deinit(); free(this); } @@ -80,5 +94,24 @@ plugin_t *kernel_libipsec_plugin_create() return NULL; } + this->tun = tun_device_create("ipsec%d"); + if (!this->tun) + { + DBG1(DBG_KNL, "failed to create TUN device"); + destroy(this); + return NULL; + } + if (!this->tun->set_mtu(this->tun, TUN_DEFAULT_MTU) || + !this->tun->up(this->tun)) + { + DBG1(DBG_KNL, "failed to configure TUN device"); + destroy(this); + return NULL; + } + lib->set(lib, "kernel-libipsec-tun", this->tun); + + /* set TUN device as default to install VIPs */ + lib->settings->set_str(lib->settings, "%s.install_virtual_ip_on", + this->tun->get_name(this->tun), charon->name); return &this->public.plugin; } |