kernel-interface: Return bool for kernel interface registration
authorThomas Egerer <thomas.egerer@secunet.com>
Tue, 6 Oct 2015 09:02:45 +0000 (11:02 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 10 Nov 2015 14:40:14 +0000 (15:40 +0100)
If the (un)registering of a kernel interface (net or ipsec) fails, the
plugin loader will never know, since the appropriate functions always
returns TRUE.  By making the (un)register functions return a boolean
value, the loader can detect a failure during initializing the kernel
interface and abort charon startup if desired.

src/libhydra/kernel/kernel_interface.c
src/libhydra/kernel/kernel_interface.h
src/libhydra/kernel/kernel_ipsec.c
src/libhydra/kernel/kernel_net.c

index ce31bd4..e443545 100644 (file)
@@ -738,44 +738,52 @@ METHOD(kernel_interface_t, get_address_by_ts, status_t,
 }
 
 
-METHOD(kernel_interface_t, add_ipsec_interface, void,
+METHOD(kernel_interface_t, add_ipsec_interface, bool,
        private_kernel_interface_t *this, kernel_ipsec_constructor_t constructor)
 {
        if (!this->ipsec)
        {
                this->ipsec_constructor = constructor;
                this->ipsec = constructor();
+               return this->ipsec != NULL;
        }
+       return FALSE;
 }
 
-METHOD(kernel_interface_t, remove_ipsec_interface, void,
+METHOD(kernel_interface_t, remove_ipsec_interface, bool,
        private_kernel_interface_t *this, kernel_ipsec_constructor_t constructor)
 {
        if (constructor == this->ipsec_constructor && this->ipsec)
        {
                this->ipsec->destroy(this->ipsec);
                this->ipsec = NULL;
+               return TRUE;
        }
+       return FALSE;
 }
 
-METHOD(kernel_interface_t, add_net_interface, void,
+METHOD(kernel_interface_t, add_net_interface, bool,
        private_kernel_interface_t *this, kernel_net_constructor_t constructor)
 {
        if (!this->net)
        {
                this->net_constructor = constructor;
                this->net = constructor();
+               return this->net != NULL;
        }
+       return FALSE;
 }
 
-METHOD(kernel_interface_t, remove_net_interface, void,
+METHOD(kernel_interface_t, remove_net_interface, bool,
        private_kernel_interface_t *this, kernel_net_constructor_t constructor)
 {
        if (constructor == this->net_constructor && this->net)
        {
                this->net->destroy(this->net);
                this->net = NULL;
+               return TRUE;
        }
+       return FALSE;
 }
 
 METHOD(kernel_interface_t, add_listener, void,
index 96ce9e2..58113e5 100644 (file)
@@ -502,39 +502,49 @@ struct kernel_interface_t {
        /**
         * Register an ipsec kernel interface constructor on the manager.
         *
-        * @param create                        constructor to register
+        * @param create                constructor to register
+        * @return                              TRUE if the ipsec kernel interface was registered
+        *                                              successfully, FALSE if an interface was already
+        *                                              registered or the registration failed
         */
-       void (*add_ipsec_interface)(kernel_interface_t *this,
+       bool (*add_ipsec_interface)(kernel_interface_t *this,
                                                                kernel_ipsec_constructor_t create);
 
        /**
         * Unregister an ipsec kernel interface constructor.
         *
-        * @param create                        constructor to unregister
+        * @param create                constructor to unregister
+        * @return                              TRUE if the ipsec kernel interface was unregistered
+        *                                              successfully, FALSE otherwise
         */
-       void (*remove_ipsec_interface)(kernel_interface_t *this,
+       bool (*remove_ipsec_interface)(kernel_interface_t *this,
                                                                   kernel_ipsec_constructor_t create);
 
        /**
         * Register a network kernel interface constructor on the manager.
         *
-        * @param create                        constructor to register
+        * @param create                constructor to register
+        * @return                              TRUE if the kernel net interface was registered
+        *                                              successfully, FALSE if an interface was already
+        *                                              registered or the registration failed
         */
-       void (*add_net_interface)(kernel_interface_t *this,
+       bool (*add_net_interface)(kernel_interface_t *this,
                                                          kernel_net_constructor_t create);
 
        /**
         * Unregister a network kernel interface constructor.
         *
-        * @param create                        constructor to unregister
+        * @param create                constructor to unregister
+        * @return                              TRUE if the kernel net interface was unregistered
+        *                                              successfully, FALSE otherwise
         */
-       void (*remove_net_interface)(kernel_interface_t *this,
+       bool (*remove_net_interface)(kernel_interface_t *this,
                                                                 kernel_net_constructor_t create);
 
        /**
         * Add a listener to the kernel interface.
         *
-        * @param listener                      listener to add
+        * @param listener              listener to add
         */
        void (*add_listener)(kernel_interface_t *this,
                                                 kernel_listener_t *listener);
@@ -542,7 +552,7 @@ struct kernel_interface_t {
        /**
         * Remove a listener from the kernel interface.
         *
-        * @param listener                      listener to remove
+        * @param listener              listener to remove
         */
        void (*remove_listener)(kernel_interface_t *this,
                                                        kernel_listener_t *listener);
index 1a32ab4..697b1b3 100644 (file)
@@ -25,13 +25,14 @@ bool kernel_ipsec_register(plugin_t *plugin, plugin_feature_t *feature,
 {
        if (reg)
        {
-               hydra->kernel_interface->add_ipsec_interface(hydra->kernel_interface,
+               return hydra->kernel_interface->add_ipsec_interface(
+                                                                                       hydra->kernel_interface,
                                                                                        (kernel_ipsec_constructor_t)data);
        }
        else
        {
-               hydra->kernel_interface->remove_ipsec_interface(hydra->kernel_interface,
+               return hydra->kernel_interface->remove_ipsec_interface(
+                                                                                       hydra->kernel_interface,
                                                                                        (kernel_ipsec_constructor_t)data);
        }
-       return TRUE;
 }
index 0841ed8..07d8b29 100644 (file)
@@ -25,13 +25,14 @@ bool kernel_net_register(plugin_t *plugin, plugin_feature_t *feature,
 {
        if (reg)
        {
-               hydra->kernel_interface->add_net_interface(hydra->kernel_interface,
+               return hydra->kernel_interface->add_net_interface(
+                                                                                       hydra->kernel_interface,
                                                                                        (kernel_net_constructor_t)data);
        }
        else
        {
-               hydra->kernel_interface->remove_net_interface(hydra->kernel_interface,
+               return hydra->kernel_interface->remove_net_interface(
+                                                                                       hydra->kernel_interface,
                                                                                        (kernel_net_constructor_t)data);
        }
-       return TRUE;
 }