]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
kernel-utun: Add a stub for an OS X kernel backend using crypto-enabled utun
authorMartin Willi <martin@revosec.ch>
Fri, 12 Apr 2013 09:50:06 +0000 (11:50 +0200)
committerMartin Willi <martin@revosec.ch>
Thu, 18 Apr 2013 12:43:55 +0000 (14:43 +0200)
configure.in
src/libhydra/Makefile.am
src/libhydra/plugins/kernel_utun/Makefile.am [new file with mode: 0644]
src/libhydra/plugins/kernel_utun/kernel_utun_ipsec.c [new file with mode: 0644]
src/libhydra/plugins/kernel_utun/kernel_utun_ipsec.h [new file with mode: 0644]
src/libhydra/plugins/kernel_utun/kernel_utun_net.c [new file with mode: 0644]
src/libhydra/plugins/kernel_utun/kernel_utun_net.h [new file with mode: 0644]
src/libhydra/plugins/kernel_utun/kernel_utun_plugin.c [new file with mode: 0644]
src/libhydra/plugins/kernel_utun/kernel_utun_plugin.h [new file with mode: 0644]

index e409f4c437e9b42ee619238cfd8c0cef528413a0..b9d71213f2c340c072c463965d168cb18cdd190f 100644 (file)
@@ -187,6 +187,7 @@ ARG_DISBL_SET([kernel-netlink], [disable the netlink kernel interface.])
 ARG_ENABL_SET([kernel-pfkey],   [enable the PF_KEY kernel interface.])
 ARG_ENABL_SET([kernel-pfroute], [enable the PF_ROUTE kernel interface.])
 ARG_ENABL_SET([kernel-klips],   [enable the KLIPS kernel interface.])
+ARG_ENABL_SET([kernel-utun],    [enable the OS X kernel interface using crypto-enabled utun devices.])
 ARG_ENABL_SET([libipsec],       [enable user space IPsec implementation.])
 ARG_DISBL_SET([socket-default], [disable default socket implementation for charon.])
 ARG_ENABL_SET([socket-dynamic], [enable dynamic socket implementation for charon])
@@ -978,6 +979,7 @@ ADD_PLUGIN([kernel-pfkey],         [h charon starter nm cmd])
 ADD_PLUGIN([kernel-pfroute],       [h charon starter nm cmd])
 ADD_PLUGIN([kernel-klips],         [h charon starter])
 ADD_PLUGIN([kernel-netlink],       [h charon starter nm cmd])
+ADD_PLUGIN([kernel-utun],          [h charon starter nm cmd])
 ADD_PLUGIN([resolve],              [h charon cmd])
 ADD_PLUGIN([socket-default],       [c charon nm cmd])
 ADD_PLUGIN([socket-dynamic],       [c charon cmd])
@@ -1180,6 +1182,7 @@ AM_CONDITIONAL(USE_KERNEL_KLIPS, test x$kernel_klips = xtrue)
 AM_CONDITIONAL(USE_KERNEL_NETLINK, test x$kernel_netlink = xtrue)
 AM_CONDITIONAL(USE_KERNEL_PFKEY, test x$kernel_pfkey = xtrue)
 AM_CONDITIONAL(USE_KERNEL_PFROUTE, test x$kernel_pfroute = xtrue)
+AM_CONDITIONAL(USE_KERNEL_UTUN, test x$kernel_utun = xtrue)
 AM_CONDITIONAL(USE_RESOLVE, test x$resolve = xtrue)
 
 #  other options
@@ -1303,6 +1306,7 @@ AC_CONFIG_FILES([
        src/libhydra/plugins/kernel_netlink/Makefile
        src/libhydra/plugins/kernel_pfkey/Makefile
        src/libhydra/plugins/kernel_pfroute/Makefile
+       src/libhydra/plugins/kernel_utun/Makefile
        src/libhydra/plugins/resolve/Makefile
        src/libipsec/Makefile
        src/libsimaka/Makefile
index 1c7b3ba438935f192ba869022e4ea631975b1b58..5282d0a0b3e2e1eeda1456690b42c097eb3d5145 100644 (file)
@@ -72,6 +72,13 @@ if MONOLITHIC
 endif
 endif
 
+if USE_KERNEL_UTUN
+  SUBDIRS += plugins/kernel_utun
+if MONOLITHIC
+  libhydra_la_LIBADD += plugins/kernel_utun/libstrongswan-kernel-utun.la
+endif
+endif
+
 if USE_RESOLVE
   SUBDIRS += plugins/resolve
 if MONOLITHIC
diff --git a/src/libhydra/plugins/kernel_utun/Makefile.am b/src/libhydra/plugins/kernel_utun/Makefile.am
new file mode 100644 (file)
index 0000000..308d842
--- /dev/null
@@ -0,0 +1,18 @@
+
+INCLUDES = -I${linux_headers} -I$(top_srcdir)/src/libstrongswan \
+       -I$(top_srcdir)/src/libhydra
+
+AM_CFLAGS = -rdynamic
+
+if MONOLITHIC
+noinst_LTLIBRARIES = libstrongswan-kernel-utun.la
+else
+plugin_LTLIBRARIES = libstrongswan-kernel-utun.la
+endif
+
+libstrongswan_kernel_utun_la_SOURCES = \
+       kernel_utun_plugin.h kernel_utun_plugin.c \
+       kernel_utun_ipsec.h kernel_utun_ipsec.c \
+       kernel_utun_net.h kernel_utun_net.c
+
+libstrongswan_kernel_utun_la_LDFLAGS = -module -avoid-version
diff --git a/src/libhydra/plugins/kernel_utun/kernel_utun_ipsec.c b/src/libhydra/plugins/kernel_utun/kernel_utun_ipsec.c
new file mode 100644 (file)
index 0000000..3a71527
--- /dev/null
@@ -0,0 +1,173 @@
+/*
+ * Copyright (C) 2013 Martin Willi
+ * Copyright (C) 2013 revosec AG
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+#include "kernel_utun_ipsec.h"
+
+#include <hydra.h>
+#include <utils/debug.h>
+
+typedef struct private_kernel_utun_ipsec_t private_kernel_utun_ipsec_t;
+
+/**
+ * Private variables and functions of kernel_utun class.
+ */
+struct private_kernel_utun_ipsec_t {
+
+       /**
+        * Public part of the kernel_utun_t object
+        */
+       kernel_utun_ipsec_t public;
+};
+
+METHOD(kernel_ipsec_t, get_features, kernel_feature_t,
+       private_kernel_utun_ipsec_t *this)
+{
+       return 0;
+}
+
+METHOD(kernel_ipsec_t, get_spi, status_t,
+       private_kernel_utun_ipsec_t *this, host_t *src, host_t *dst,
+       u_int8_t protocol, u_int32_t reqid, u_int32_t *spi)
+{
+       return FAILED;
+}
+
+METHOD(kernel_ipsec_t, get_cpi, status_t,
+       private_kernel_utun_ipsec_t *this, host_t *src, host_t *dst,
+       u_int32_t reqid, u_int16_t *cpi)
+{
+       return FAILED;
+}
+
+METHOD(kernel_ipsec_t, add_sa, status_t,
+       private_kernel_utun_ipsec_t *this, host_t *src, host_t *dst,
+       u_int32_t spi, u_int8_t protocol, u_int32_t reqid, mark_t mark,
+       u_int32_t tfc, lifetime_cfg_t *lifetime, u_int16_t enc_alg, chunk_t enc_key,
+       u_int16_t int_alg, chunk_t int_key, ipsec_mode_t mode, u_int16_t ipcomp,
+       u_int16_t cpi, bool encap, bool esn, bool inbound,
+       traffic_selector_t* src_ts, traffic_selector_t* dst_ts)
+{
+       return FAILED;
+}
+
+METHOD(kernel_ipsec_t, query_sa, status_t,
+       private_kernel_utun_ipsec_t *this, host_t *src, host_t *dst,
+       u_int32_t spi, u_int8_t protocol, mark_t mark,
+       u_int64_t *bytes, u_int64_t *packets)
+{
+       return FAILED;
+}
+
+METHOD(kernel_ipsec_t, del_sa, status_t,
+       private_kernel_utun_ipsec_t *this, host_t *src, host_t *dst,
+       u_int32_t spi, u_int8_t protocol, u_int16_t cpi, mark_t mark)
+{
+       return FAILED;
+}
+
+METHOD(kernel_ipsec_t, update_sa, status_t,
+       private_kernel_utun_ipsec_t *this, u_int32_t spi, u_int8_t protocol,
+       u_int16_t cpi, host_t *src, host_t *dst, host_t *new_src, host_t *new_dst,
+       bool old_encap, bool new_encap, mark_t mark)
+{
+       return FAILED;
+}
+
+METHOD(kernel_ipsec_t, flush_sas, status_t,
+       private_kernel_utun_ipsec_t *this)
+{
+       return FAILED;
+}
+
+METHOD(kernel_ipsec_t, add_policy, status_t,
+       private_kernel_utun_ipsec_t *this, host_t *src, host_t *dst,
+       traffic_selector_t *src_ts, traffic_selector_t *dst_ts,
+       policy_dir_t direction, policy_type_t type, ipsec_sa_cfg_t *sa,
+       mark_t mark, policy_priority_t priority)
+{
+       return FAILED;
+}
+
+METHOD(kernel_ipsec_t, query_policy, status_t,
+       private_kernel_utun_ipsec_t *this, traffic_selector_t *src_ts,
+       traffic_selector_t *dst_ts, policy_dir_t direction, mark_t mark,
+       u_int32_t *use_time)
+{
+       return FAILED;
+}
+
+METHOD(kernel_ipsec_t, del_policy, status_t,
+       private_kernel_utun_ipsec_t *this, traffic_selector_t *src_ts,
+       traffic_selector_t *dst_ts, policy_dir_t direction, u_int32_t reqid,
+       mark_t mark, policy_priority_t prio)
+{
+       return FAILED;
+}
+
+METHOD(kernel_ipsec_t, flush_policies, status_t,
+       private_kernel_utun_ipsec_t *this)
+{
+       return FAILED;
+}
+
+
+METHOD(kernel_ipsec_t, bypass_socket, bool,
+       private_kernel_utun_ipsec_t *this, int fd, int family)
+{
+       return FALSE;
+}
+
+METHOD(kernel_ipsec_t, enable_udp_decap, bool,
+       private_kernel_utun_ipsec_t *this, int fd, int family, u_int16_t port)
+{
+       return FALSE;
+}
+
+METHOD(kernel_ipsec_t, destroy, void,
+       private_kernel_utun_ipsec_t *this)
+{
+       free(this);
+}
+
+/*
+ * Described in header.
+ */
+kernel_utun_ipsec_t *kernel_utun_ipsec_create()
+{
+       private_kernel_utun_ipsec_t *this;
+
+       INIT(this,
+               .public = {
+                       .interface = {
+                               .get_features = _get_features,
+                               .get_spi = _get_spi,
+                               .get_cpi = _get_cpi,
+                               .add_sa  = _add_sa,
+                               .update_sa = _update_sa,
+                               .query_sa = _query_sa,
+                               .del_sa = _del_sa,
+                               .flush_sas = _flush_sas,
+                               .add_policy = _add_policy,
+                               .query_policy = _query_policy,
+                               .del_policy = _del_policy,
+                               .flush_policies = _flush_policies,
+                               .bypass_socket = _bypass_socket,
+                               .enable_udp_decap = _enable_udp_decap,
+                               .destroy = _destroy,
+                       },
+               },
+       );
+       return &this->public;
+}
\ No newline at end of file
diff --git a/src/libhydra/plugins/kernel_utun/kernel_utun_ipsec.h b/src/libhydra/plugins/kernel_utun/kernel_utun_ipsec.h
new file mode 100644 (file)
index 0000000..7c52cf3
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2013 Martin Willi
+ * Copyright (C) 2013 revosec AG
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+/**
+ * @defgroup kernel_utun_ipsec_i kernel_utun_ipsec
+ * @{ @ingroup kernel_utun
+ */
+
+#ifndef KERNEL_UTUN_IPSEC_H_
+#define KERNEL_UTUN_IPSEC_H_
+
+#include <kernel/kernel_ipsec.h>
+
+typedef struct kernel_utun_ipsec_t kernel_utun_ipsec_t;
+
+/**
+ * Implementation of the kernel ipsec interface using OS X utun devices.
+ */
+struct kernel_utun_ipsec_t {
+
+       /**
+        * Implements kernel_ipsec_t interface
+        */
+       kernel_ipsec_t interface;
+};
+
+/**
+ * Create a utun kernel ipsec interface instance.
+ *
+ * @return                     kernel_utun_ipsec_t instance
+ */
+kernel_utun_ipsec_t *kernel_utun_ipsec_create();
+
+#endif /** KERNEL_UTUN_IPSEC_H_ @}*/
diff --git a/src/libhydra/plugins/kernel_utun/kernel_utun_net.c b/src/libhydra/plugins/kernel_utun/kernel_utun_net.c
new file mode 100644 (file)
index 0000000..22ead0a
--- /dev/null
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2013 Martin Willi
+ * Copyright (C) 2013 revosec AG
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+
+#include "kernel_utun_net.h"
+
+#include <hydra.h>
+#include <utils/debug.h>
+
+typedef struct private_kernel_utun_net_t private_kernel_utun_net_t;
+
+/**
+ * Private variables and functions of kernel_utun_net class.
+ */
+struct private_kernel_utun_net_t {
+
+       /**
+        * Public part of the kernel_utun_net_t object.
+        */
+       kernel_utun_net_t public;
+};
+
+METHOD(kernel_net_t, create_address_enumerator, enumerator_t*,
+       private_kernel_utun_net_t *this, kernel_address_type_t which)
+{
+       return enumerator_create_empty();
+}
+
+METHOD(kernel_net_t, get_interface_name, bool,
+       private_kernel_utun_net_t *this, host_t* ip, char **name)
+{
+       return FALSE;
+}
+
+METHOD(kernel_net_t, get_source_addr, host_t*,
+       private_kernel_utun_net_t *this, host_t *dest, host_t *src)
+{
+       return NULL;
+}
+
+METHOD(kernel_net_t, get_nexthop, host_t*,
+       private_kernel_utun_net_t *this, host_t *dest, host_t *src)
+{
+       return NULL;
+}
+
+METHOD(kernel_net_t, add_ip, status_t,
+       private_kernel_utun_net_t *this, host_t *virtual_ip, int prefix,
+       char *iface_name)
+{
+       return FAILED;
+}
+
+METHOD(kernel_net_t, del_ip, status_t,
+       private_kernel_utun_net_t *this, host_t *virtual_ip, int prefix,
+       bool wait)
+{
+       return FAILED;
+}
+
+METHOD(kernel_net_t, add_route, status_t,
+       private_kernel_utun_net_t *this, chunk_t dst_net, u_int8_t prefixlen,
+       host_t *gateway, host_t *src_ip, char *if_name)
+{
+       return FAILED;
+}
+
+METHOD(kernel_net_t, del_route, status_t,
+       private_kernel_utun_net_t *this, chunk_t dst_net, u_int8_t prefixlen,
+       host_t *gateway, host_t *src_ip, char *if_name)
+{
+       return FAILED;
+}
+
+METHOD(kernel_net_t, destroy, void,
+       private_kernel_utun_net_t *this)
+{
+       free(this);
+}
+
+/*
+ * Described in header.
+ */
+kernel_utun_net_t *kernel_utun_net_create()
+{
+       private_kernel_utun_net_t *this;
+
+       INIT(this,
+               .public = {
+                       .interface = {
+                               .get_interface = _get_interface_name,
+                               .create_address_enumerator = _create_address_enumerator,
+                               .get_source_addr = _get_source_addr,
+                               .get_nexthop = _get_nexthop,
+                               .add_ip = _add_ip,
+                               .del_ip = _del_ip,
+                               .add_route = _add_route,
+                               .del_route = _del_route,
+                               .destroy = _destroy,
+                       },
+               },
+       );
+
+       return &this->public;
+}
\ No newline at end of file
diff --git a/src/libhydra/plugins/kernel_utun/kernel_utun_net.h b/src/libhydra/plugins/kernel_utun/kernel_utun_net.h
new file mode 100644 (file)
index 0000000..2bc2f9b
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2013 Martin Willi
+ * Copyright (C) 2013 revosec AG
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+/**
+ * @defgroup kernel_utun_net_i kernel_utun_net
+ * @{ @ingroup kernel_utun
+ */
+
+#ifndef KERNEL_UTUN_NET_H_
+#define KERNEL_UTUN_NET_H_
+
+#include <kernel/kernel_net.h>
+
+typedef struct kernel_utun_net_t kernel_utun_net_t;
+
+/**
+ * Implementation of the kernel network interface using OS X utun devices.
+ */
+struct kernel_utun_net_t {
+
+       /**
+        * Implements kernel_net_t interface
+        */
+       kernel_net_t interface;
+};
+
+/**
+ * Create a utun kernel network interface instance.
+ *
+ * @return                     kernel_utun_net_t instance
+ */
+kernel_utun_net_t *kernel_utun_net_create();
+
+#endif /** KERNEL_UTUN_NET_H_ @}*/
diff --git a/src/libhydra/plugins/kernel_utun/kernel_utun_plugin.c b/src/libhydra/plugins/kernel_utun/kernel_utun_plugin.c
new file mode 100644 (file)
index 0000000..793e572
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2013 Martin Willi
+ * Copyright (C) 2013 revosec AG
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+
+#include "kernel_utun_plugin.h"
+
+#include "kernel_utun_ipsec.h"
+#include "kernel_utun_net.h"
+
+#include <hydra.h>
+
+typedef struct private_kernel_utun_plugin_t private_kernel_utun_plugin_t;
+
+/**
+ * private data of kernel utun plugin
+ */
+struct private_kernel_utun_plugin_t {
+
+       /**
+        * implements plugin interface
+        */
+       kernel_utun_plugin_t public;
+};
+
+METHOD(plugin_t, get_name, char*,
+       private_kernel_utun_plugin_t *this)
+{
+       return "kernel-utun";
+}
+
+METHOD(plugin_t, get_features, int,
+       private_kernel_utun_plugin_t *this, plugin_feature_t *features[])
+{
+       static plugin_feature_t f[] = {
+               PLUGIN_CALLBACK(kernel_ipsec_register, kernel_utun_ipsec_create),
+                       PLUGIN_PROVIDE(CUSTOM, "kernel-ipsec"),
+               PLUGIN_CALLBACK(kernel_net_register, kernel_utun_net_create),
+                       PLUGIN_PROVIDE(CUSTOM, "kernel-net"),
+       };
+       *features = f;
+       return countof(f);
+}
+
+METHOD(plugin_t, destroy, void,
+       private_kernel_utun_plugin_t *this)
+{
+       free(this);
+}
+
+/*
+ * see header file
+ */
+plugin_t *kernel_utun_plugin_create()
+{
+       private_kernel_utun_plugin_t *this;
+
+       INIT(this,
+               .public = {
+                       .plugin = {
+                               .get_name = _get_name,
+                               .get_features = _get_features,
+                               .destroy = _destroy,
+                       },
+               },
+       );
+
+       return &this->public.plugin;
+}
diff --git a/src/libhydra/plugins/kernel_utun/kernel_utun_plugin.h b/src/libhydra/plugins/kernel_utun/kernel_utun_plugin.h
new file mode 100644 (file)
index 0000000..1304063
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2013 Martin Willi
+ * Copyright (C) 2013 revosec AG
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+/**
+ * @defgroup kernel_utun kernel_utun
+ * @ingroup hplugins
+ *
+ * @defgroup kernel_utun_plugin kernel_utun_plugin
+ * @{ @ingroup kernel_utun
+ */
+
+#ifndef KERNEL_UTUN_PLUGIN_H_
+#define KERNEL_UTUN_PLUGIN_H_
+
+#include <plugins/plugin.h>
+
+typedef struct kernel_utun_plugin_t kernel_utun_plugin_t;
+
+/**
+ * OS X kernel interface plugin using crypto-enabled utun devices
+ */
+struct kernel_utun_plugin_t {
+
+       /**
+        * implements plugin interface
+        */
+       plugin_t plugin;
+};
+
+#endif /** KERNEL_UTUN_PLUGIN_H_ @}*/