Added kernel_ipsec/net plugin feature loading callbacks
authorMartin Willi <martin@revosec.ch>
Thu, 13 Oct 2011 09:22:03 +0000 (11:22 +0200)
committerMartin Willi <martin@revosec.ch>
Fri, 14 Oct 2011 08:05:47 +0000 (10:05 +0200)
src/libhydra/Makefile.am
src/libhydra/kernel/kernel_ipsec.c
src/libhydra/kernel/kernel_ipsec.h
src/libhydra/kernel/kernel_net.c [new file with mode: 0644]
src/libhydra/kernel/kernel_net.h

index 032dada..1c7b3ba 100644 (file)
@@ -8,7 +8,7 @@ attributes/attribute_manager.c attributes/attribute_manager.h \
 attributes/mem_pool.c attributes/mem_pool.h \
 kernel/kernel_interface.c kernel/kernel_interface.h \
 kernel/kernel_ipsec.c kernel/kernel_ipsec.h \
-kernel/kernel_net.h \
+kernel/kernel_net.c kernel/kernel_net.h \
 kernel/kernel_listener.h
 
 libhydra_la_LIBADD =
index 9035196..9b38297 100644 (file)
@@ -15,6 +15,8 @@
 
 #include "kernel_ipsec.h"
 
+#include <hydra.h>
+
 ENUM(ipsec_mode_names, MODE_TRANSPORT, MODE_DROP,
        "TRANSPORT",
        "TUNNEL",
@@ -37,3 +39,21 @@ ENUM(ipcomp_transform_names, IPCOMP_NONE, IPCOMP_LZJH,
        "IPCOMP_LZJH"
 );
 
+/**
+ * See header
+ */
+bool kernel_ipsec_register(plugin_t *plugin, plugin_feature_t *feature,
+                                                  bool reg, void *data)
+{
+       if (reg)
+       {
+               hydra->kernel_interface->add_ipsec_interface(hydra->kernel_interface,
+                                                                                       (kernel_ipsec_constructor_t)data);
+       }
+       else
+       {
+               hydra->kernel_interface->remove_ipsec_interface(hydra->kernel_interface,
+                                                                                       (kernel_ipsec_constructor_t)data);
+       }
+       return TRUE;
+}
index 986e21f..eacf7c7 100644 (file)
@@ -37,6 +37,7 @@ typedef struct mark_t mark_t;
 #include <utils/host.h>
 #include <crypto/prf_plus.h>
 #include <selectors/traffic_selector.h>
+#include <plugins/plugin.h>
 
 /**
  * Mode of an IPsec SA.
@@ -386,4 +387,18 @@ struct kernel_ipsec_t {
        void (*destroy) (kernel_ipsec_t *this);
 };
 
+/**
+ * Helper function to (un-)register IPsec kernel interfaces from plugin features.
+ *
+ * This function is a plugin_feature_callback_t and can be used with the
+ * PLUGIN_CALLBACK macro to register an IPsec kernel interface constructor.
+ *
+ * @param plugin               plugin registering the kernel interface
+ * @param feature              associated plugin feature
+ * @param reg                  TRUE to register, FALSE to unregister
+ * @param data                 data passed to callback, an kernel_ipsec_constructor_t
+ */
+bool kernel_ipsec_register(plugin_t *plugin, plugin_feature_t *feature,
+                                                  bool reg, void *data);
+
 #endif /** KERNEL_IPSEC_H_ @}*/
diff --git a/src/libhydra/kernel/kernel_net.c b/src/libhydra/kernel/kernel_net.c
new file mode 100644 (file)
index 0000000..0841ed8
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2011 Martin Willi
+ * Copyright (C) 2011 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_net.h"
+
+#include <hydra.h>
+
+/**
+ * See header
+ */
+bool kernel_net_register(plugin_t *plugin, plugin_feature_t *feature,
+                                                bool reg, void *data)
+{
+       if (reg)
+       {
+               hydra->kernel_interface->add_net_interface(hydra->kernel_interface,
+                                                                                       (kernel_net_constructor_t)data);
+       }
+       else
+       {
+               hydra->kernel_interface->remove_net_interface(hydra->kernel_interface,
+                                                                                       (kernel_net_constructor_t)data);
+       }
+       return TRUE;
+}
index 69e01f4..a89e768 100644 (file)
@@ -26,6 +26,7 @@ typedef struct kernel_net_t kernel_net_t;
 
 #include <utils/enumerator.h>
 #include <utils/host.h>
+#include <plugins/plugin.h>
 
 /**
  * Interface to the network subsystem of the kernel.
@@ -142,4 +143,18 @@ struct kernel_net_t {
        void (*destroy) (kernel_net_t *this);
 };
 
+/**
+ * Helper function to (un-)register net kernel interfaces from plugin features.
+ *
+ * This function is a plugin_feature_callback_t and can be used with the
+ * PLUGIN_CALLBACK macro to register an net kernel interface constructor.
+ *
+ * @param plugin               plugin registering the kernel interface
+ * @param feature              associated plugin feature
+ * @param reg                  TRUE to register, FALSE to unregister
+ * @param data                 data passed to callback, an kernel_net_constructor_t
+ */
+bool kernel_net_register(plugin_t *plugin, plugin_feature_t *feature,
+                                                bool reg, void *data);
+
 #endif /** KERNEL_NET_H_ @}*/