Added kernel event handler stub.
authorTobias Brunner <tobias@strongswan.org>
Tue, 6 Jul 2010 09:36:58 +0000 (11:36 +0200)
committerTobias Brunner <tobias@strongswan.org>
Thu, 2 Sep 2010 17:01:23 +0000 (19:01 +0200)
src/libcharon/Android.mk
src/libcharon/Makefile.am
src/libcharon/daemon.c
src/libcharon/kernel/kernel_handler.c [new file with mode: 0644]
src/libcharon/kernel/kernel_handler.h [new file with mode: 0644]

index f03d889..ed88a33 100644 (file)
@@ -40,6 +40,7 @@ encoding/payloads/transform_substructure.c encoding/payloads/transform_substruct
 encoding/payloads/ts_payload.c encoding/payloads/ts_payload.h \
 encoding/payloads/unknown_payload.c encoding/payloads/unknown_payload.h \
 encoding/payloads/vendor_id_payload.c encoding/payloads/vendor_id_payload.h \
+kernel/kernel_handler.c kernel/kernel_handler.h \
 kernel/kernel_interface.c kernel/kernel_interface.h \
 kernel/kernel_ipsec.c kernel/kernel_ipsec.h \
 kernel/kernel_net.h \
index 272d745..fd7fbd3 100644 (file)
@@ -38,6 +38,7 @@ encoding/payloads/transform_substructure.c encoding/payloads/transform_substruct
 encoding/payloads/ts_payload.c encoding/payloads/ts_payload.h \
 encoding/payloads/unknown_payload.c encoding/payloads/unknown_payload.h \
 encoding/payloads/vendor_id_payload.c encoding/payloads/vendor_id_payload.h \
+kernel/kernel_handler.c kernel/kernel_handler.h \
 kernel/kernel_interface.c kernel/kernel_interface.h \
 kernel/kernel_ipsec.c kernel/kernel_ipsec.h \
 kernel/kernel_net.h \
index f414db9..2267ac5 100644 (file)
@@ -34,6 +34,7 @@
 #include <library.h>
 #include <hydra.h>
 #include <config/proposal.h>
+#include <kernel/kernel_handler.h>
 
 #ifndef LOG_AUTHPRIV /* not defined on OpenSolaris */
 #define LOG_AUTHPRIV LOG_AUTH
@@ -51,6 +52,11 @@ struct private_daemon_t {
        daemon_t public;
 
        /**
+        * Handler for kernel events
+        */
+       kernel_handler_t *kernel_handler;
+
+       /**
         * capabilities to keep
         */
 #ifdef CAPABILITIES_LIBCAP
@@ -111,6 +117,7 @@ static void destroy(private_daemon_t *this)
 #endif /* CAPABILITIES_LIBCAP */
        DESTROY_IF(this->public.traps);
        DESTROY_IF(this->public.ike_sa_manager);
+       DESTROY_IF(this->kernel_handler);
        DESTROY_IF(this->public.kernel_interface);
        DESTROY_IF(this->public.scheduler);
        DESTROY_IF(this->public.controller);
@@ -364,6 +371,7 @@ METHOD(daemon_t, initialize, bool,
        this->public.sim = sim_manager_create();
        this->public.backends = backend_manager_create();
        this->public.kernel_interface = kernel_interface_create();
+       this->kernel_handler = kernel_handler_create();
        this->public.socket = socket_manager_create();
        this->public.traps = trap_manager_create();
 
diff --git a/src/libcharon/kernel/kernel_handler.c b/src/libcharon/kernel/kernel_handler.c
new file mode 100644 (file)
index 0000000..0e967fe
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2010 Tobias Brunner
+ * Hochschule fuer Technik Rapperswil
+ *
+ * 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_handler.h"
+
+#include <daemon.h>
+
+typedef struct private_kernel_handler_t private_kernel_handler_t;
+
+/**
+ * Private data of a kernel_handler_t object.
+ */
+struct private_kernel_handler_t {
+
+       /**
+        * Public part of kernel_handler_t object.
+        */
+       kernel_handler_t public;
+
+};
+
+METHOD(kernel_handler_t, destroy, void,
+          private_kernel_handler_t *this)
+{
+       charon->kernel_interface->remove_listener(charon->kernel_interface,
+                                                                                         &this->public.listener);
+       free(this);
+}
+
+kernel_handler_t *kernel_handler_create()
+{
+       private_kernel_handler_t *this;
+
+       INIT(this,
+               .public = {
+                       .listener = {
+                               .acquire = NULL,
+                       },
+                       .destroy = _destroy,
+               },
+       );
+
+       charon->kernel_interface->add_listener(charon->kernel_interface,
+                                                                                  &this->public.listener);
+
+       return &this->public;
+}
+
diff --git a/src/libcharon/kernel/kernel_handler.h b/src/libcharon/kernel/kernel_handler.h
new file mode 100644 (file)
index 0000000..f1fa0bd
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2010 Tobias Brunner
+ * Hochschule fuer Technik Rapperswil
+ *
+ * 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_handler kernel_handler
+ * @{ @ingroup kernel
+ */
+
+#ifndef KERNEL_HANDLER_H_
+#define KERNEL_HANDLER_H_
+
+typedef struct kernel_handler_t kernel_handler_t;
+
+#include <kernel/kernel_listener.h>
+
+/**
+ * Listens to and handles kernel events.
+ */
+struct kernel_handler_t {
+
+       /**
+        * Implements the kernel listener interface.
+        */
+       kernel_listener_t listener;
+
+       /**
+        * Destroy this instance.
+        */
+       void (*destroy)(kernel_handler_t *this);
+
+};
+
+/**
+ * Create an object of type kernel_handler_t.
+ */
+kernel_handler_t *kernel_handler_create();
+
+#endif /** KERNEL_HANDLER_H_ @}*/