]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
Integrate nm plugin directly in charon-nm.
authorTobias Brunner <tobias@strongswan.org>
Thu, 19 Apr 2012 14:40:21 +0000 (16:40 +0200)
committerTobias Brunner <tobias@strongswan.org>
Thu, 3 May 2012 11:57:03 +0000 (13:57 +0200)
13 files changed:
configure.in
src/charon-nm/Makefile.am
src/charon-nm/charon-nm.c
src/charon-nm/nm/nm_backend.c [moved from src/libcharon/plugins/nm/nm_plugin.c with 79% similarity]
src/charon-nm/nm/nm_backend.h [moved from src/libcharon/plugins/nm/nm_plugin.h with 61% similarity]
src/charon-nm/nm/nm_creds.c [moved from src/libcharon/plugins/nm/nm_creds.c with 100% similarity]
src/charon-nm/nm/nm_creds.h [moved from src/libcharon/plugins/nm/nm_creds.h with 100% similarity]
src/charon-nm/nm/nm_handler.c [moved from src/libcharon/plugins/nm/nm_handler.c with 100% similarity]
src/charon-nm/nm/nm_handler.h [moved from src/libcharon/plugins/nm/nm_handler.h with 100% similarity]
src/charon-nm/nm/nm_service.c [moved from src/libcharon/plugins/nm/nm_service.c with 99% similarity]
src/charon-nm/nm/nm_service.h [moved from src/libcharon/plugins/nm/nm_service.h with 100% similarity]
src/libcharon/Makefile.am
src/libcharon/plugins/nm/Makefile.am [deleted file]

index 786d47cbc362ab26863dc163831a49963bf00ae9..43f664056b5bfbca054dc87780ff4eec8cdf5bb3 100755 (executable)
@@ -37,7 +37,7 @@ ARG_WITH_SUBST([ipsecdir],           [${libexecdir%/}/ipsec], [set installation
 ARG_WITH_SUBST([ipseclibdir],        [${libdir%/}/ipsec], [set installation path for ipsec libraries])
 ARG_WITH_SUBST([plugindir],          [${ipseclibdir%/}/plugins], [set the installation path of plugins])
 ARG_WITH_SUBST([imcvdir],            [${ipseclibdir%/}/imcvs], [set the installation path of IMC and IMV dynamic librariers])
-ARG_WITH_SUBST([nm-ca-dir],          [/usr/share/ca-certificates], [directory the NM plugin uses to look up trusted root certificates])
+ARG_WITH_SUBST([nm-ca-dir],          [/usr/share/ca-certificates], [directory the NM backend uses to look up trusted root certificates])
 ARG_WITH_SUBST([linux-headers],      [\${top_srcdir}/src/include], [set directory of linux header files to use])
 ARG_WITH_SUBST([routing-table],      [220], [set routing table to use for IPsec routes])
 ARG_WITH_SUBST([routing-table-prio], [220], [set priority for IPsec routing table])
@@ -890,7 +890,6 @@ ADD_PLUGIN([tnccs-11],             [c charon])
 ADD_PLUGIN([tnccs-dynamic],        [c charon])
 ADD_PLUGIN([medsrv],               [c charon])
 ADD_PLUGIN([medcli],               [c charon])
-ADD_PLUGIN([nm],                   [c charon])
 ADD_PLUGIN([dhcp],                 [c charon])
 ADD_PLUGIN([android],              [c charon])
 ADD_PLUGIN([ha],                   [c charon])
@@ -972,7 +971,6 @@ dnl ==============
 AM_CONDITIONAL(USE_STROKE, test x$stroke = xtrue)
 AM_CONDITIONAL(USE_MEDSRV, test x$medsrv = xtrue)
 AM_CONDITIONAL(USE_MEDCLI, test x$medcli = xtrue)
-AM_CONDITIONAL(USE_NM, test x$nm = xtrue)
 AM_CONDITIONAL(USE_UCI, test x$uci = xtrue)
 AM_CONDITIONAL(USE_ANDROID, test x$android = xtrue)
 AM_CONDITIONAL(USE_MAEMO, test x$maemo = xtrue)
@@ -1215,7 +1213,6 @@ AC_OUTPUT(
        src/libcharon/plugins/sql/Makefile
        src/libcharon/plugins/medsrv/Makefile
        src/libcharon/plugins/medcli/Makefile
-       src/libcharon/plugins/nm/Makefile
        src/libcharon/plugins/addrblock/Makefile
        src/libcharon/plugins/uci/Makefile
        src/libcharon/plugins/ha/Makefile
index 41c94b7eef8746764f144d4b5c12c684eeedaa68..80fc13ba11e6ffbb237032bb320fd71bbcbf51e8 100644 (file)
@@ -1,20 +1,26 @@
 ipsec_PROGRAMS = charon-nm
 
 charon_nm_SOURCES = \
-charon-nm.c
+charon-nm.c \
+nm/nm_backend.c nm/nm_backend.h \
+nm/nm_creds.c nm/nm_creds.h \
+nm/nm_handler.c nm/nm_handler.h \
+nm/nm_service.c nm/nm_service.h
 
 INCLUDES = \
        -I$(top_srcdir)/src/libstrongswan \
        -I$(top_srcdir)/src/libhydra \
-       -I$(top_srcdir)/src/libcharon
+       -I$(top_srcdir)/src/libcharon \
+       ${nm_CFLAGS}
 
 AM_CFLAGS = \
        -DIPSEC_DIR=\"${ipsecdir}\" \
        -DIPSEC_PIDDIR=\"${piddir}\" \
+       -DNM_CA_DIR=\"${nm_ca_dir}\" \
        -DPLUGINS=\""${nm_plugins}\""
 
 charon_nm_LDADD = \
        $(top_builddir)/src/libstrongswan/libstrongswan.la \
        $(top_builddir)/src/libhydra/libhydra.la \
        $(top_builddir)/src/libcharon/libcharon.la \
-       -lm $(PTHREADLIB) $(DLLIB)
+       -lm $(PTHREADLIB) $(DLLIB) ${nm_LIBS}
index 8b73f6a760c95b5f6a0fa4823799e15bd525b14b..16b0ed856137a4344da464517a51f18ff28a14b0 100644 (file)
@@ -31,6 +31,8 @@
 #include <utils/backtrace.h>
 #include <threading/thread.h>
 
+#include <nm/nm_backend.h>
+
 /**
  * Hook in library for debugging messages
  */
@@ -270,10 +272,17 @@ int main(int argc, char *argv[])
                goto deinit;
        }
 
+       /* load NM backend */
+       if (!nm_backend_init())
+       {
+               DBG1(DBG_DMN, "failed to initialize NetworkManager backend - aborting charon-nm");
+               goto deinit_nm;
+       }
+
        if (!drop_capabilities())
        {
                DBG1(DBG_DMN, "capability dropping failed - aborting charon-nm");
-               goto deinit;
+               goto deinit_nm;
        }
 
        /* add handler for SEGV and ILL,
@@ -299,6 +308,8 @@ int main(int argc, char *argv[])
 
        status = 0;
 
+deinit_nm:
+       nm_backend_deinit();
 deinit:
        libcharon_deinit();
        libhydra_deinit();
similarity index 79%
rename from src/libcharon/plugins/nm/nm_plugin.c
rename to src/charon-nm/nm/nm_backend.c
index 84b7c810a56c50da09d45ce7fa7f1e778b098e3a..19382a0280c48dbdb75094edad86c6fd535aa8b8 100644 (file)
@@ -1,4 +1,5 @@
 /*
+ * Copyright (C) 2012 Tobias Brunner
  * Copyright (C) 2008-2009 Martin Willi
  * Hochschule fuer Technik Rapperswil
  *
@@ -13,7 +14,6 @@
  * for more details.
  */
 
-#include "nm_plugin.h"
 #include "nm_service.h"
 #include "nm_creds.h"
 #include "nm_handler.h"
 
 #define CAP_DAC_OVERRIDE 1
 
-typedef struct private_nm_plugin_t private_nm_plugin_t;
+typedef struct nm_backend_t nm_backend_t;
 
 /**
- * private data of nm plugin
+ * Data for the NetworkManager backend.
  */
-struct private_nm_plugin_t {
-
-       /**
-        * implements plugin interface
-        */
-       nm_plugin_t public;
+struct nm_backend_t {
 
        /**
         * NetworkManager service (VPNPlugin)
@@ -57,25 +52,32 @@ struct private_nm_plugin_t {
        nm_handler_t *handler;
 };
 
+/**
+ * Global (but private) instance of the NM backend.
+ */
+static nm_backend_t *nm_backend = NULL;
+
 /**
  * NM plugin processing routine, creates and handles NMVPNPlugin
  */
-static job_requeue_t run(private_nm_plugin_t *this)
+static job_requeue_t run(nm_backend_t *this)
 {
        this->loop = g_main_loop_new(NULL, FALSE);
        g_main_loop_run(this->loop);
        return JOB_REQUEUE_NONE;
 }
 
-METHOD(plugin_t, get_name, char*,
-       private_nm_plugin_t *this)
+/*
+ * see header file
+ */
+void nm_backend_deinit()
 {
-       return "nm";
-}
+       nm_backend_t *this = nm_backend;
 
-METHOD(plugin_t, destroy, void,
-       private_nm_plugin_t *this)
-{
+       if (!this)
+       {
+               return;
+       }
        if (this->loop)
        {
                if (g_main_loop_is_running(this->loop))
@@ -93,14 +95,16 @@ METHOD(plugin_t, destroy, void,
        this->creds->destroy(this->creds);
        this->handler->destroy(this->handler);
        free(this);
+
+       nm_backend = NULL;
 }
 
 /*
  * see header file
  */
-plugin_t *nm_plugin_create()
+bool nm_backend_init()
 {
-       private_nm_plugin_t *this;
+       nm_backend_t *this;
 
        g_type_init ();
        if (!g_thread_supported())
@@ -109,25 +113,19 @@ plugin_t *nm_plugin_create()
        }
 
        INIT(this,
-               .public = {
-                       .plugin = {
-                               .get_name = _get_name,
-                               .reload = (void*)return_false,
-                               .destroy = _destroy,
-                       },
-               },
                .creds = nm_creds_create(),
                .handler = nm_handler_create(),
        );
        this->plugin = nm_strongswan_plugin_new(this->creds, this->handler);
+       nm_backend = this;
 
        hydra->attributes->add_handler(hydra->attributes, &this->handler->handler);
        lib->credmgr->add_set(lib->credmgr, &this->creds->set);
        if (!this->plugin)
        {
                DBG1(DBG_CFG, "DBUS binding failed");
-               destroy(this);
-               return NULL;
+               nm_backend_deinit();
+               return FALSE;
        }
 
        /* bypass file permissions to read from users ssh-agent */
@@ -136,7 +134,6 @@ plugin_t *nm_plugin_create()
        lib->processor->queue_job(lib->processor,
                                (job_t*)callback_job_create_with_prio((callback_job_cb_t)run,
                                                                                this, NULL, NULL, JOB_PRIO_CRITICAL));
-
-       return &this->public.plugin;
+       return TRUE;
 }
 
similarity index 61%
rename from src/libcharon/plugins/nm/nm_plugin.h
rename to src/charon-nm/nm/nm_backend.h
index b64b3edf662b3bce6f23dd6452dd02203bce750a..bff9d4d6f85ddac1a362dc3eb8c81062f217338c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 Martin Willi
+ * Copyright (C) 2012 Tobias Brunner
  * Hochschule fuer Technik Rapperswil
  *
  * This program is free software; you can redistribute it and/or modify it
  */
 
 /**
+ * @defgroup charon-nm charon-nm
+ *
  * @defgroup nm nm
- * @ingroup cplugins
+ * @ingroup charon-nm
  *
- * @defgroup nm_plugin nm_plugin
+ * @defgroup nm_backend nm_backend
  * @{ @ingroup nm
  */
 
-#ifndef NM_PLUGIN_H_
-#define NM_PLUGIN_H_
-
-#include <plugins/plugin.h>
-
-typedef struct nm_plugin_t nm_plugin_t;
+#ifndef NM_BACKEND_H_
+#define NM_BACKEND_H_
 
 /**
- * NetworkManager integration plugin.
+ * Initialize the NetworkManager backend.
+ *
+ * @return             TRUE, if initialization was successful
  */
-struct nm_plugin_t {
+bool nm_backend_init();
 
-       /**
-        * implements plugin interface
-        */
-       plugin_t plugin;
-};
+/**
+ * Deinitialize the NetworkManager backend.
+ */
+void nm_backend_deinit();
 
-#endif /** NM_PLUGIN_H_ @}*/
+#endif /** NM_BACKEND_H_ @}*/
similarity index 99%
rename from src/libcharon/plugins/nm/nm_service.c
rename to src/charon-nm/nm/nm_service.c
index d51b699ae6744968ff005eb7d7309f14577979cc..64da53f79524e5b5710a6f56bcab9829652ed2f2 100644 (file)
@@ -668,7 +668,7 @@ static void nm_strongswan_plugin_init(NMStrongswanPlugin *plugin)
 
        priv = NM_STRONGSWAN_PLUGIN_GET_PRIVATE(plugin);
        priv->plugin = NM_VPN_PLUGIN(plugin);
-       memset(&priv->listener.log, 0, sizeof(listener_t));
+       memset(&priv->listener, 0, sizeof(listener_t));
        priv->listener.child_updown = child_updown;
        priv->listener.ike_rekey = ike_rekey;
 }
index 8b16de1871039a1131892c5f6727e6c2ef65ae18..e31d532abb996c626971e1a136a3577cffdc200e 100755 (executable)
@@ -444,13 +444,6 @@ if MONOLITHIC
 endif
 endif
 
-if USE_NM
-  SUBDIRS += plugins/nm
-if MONOLITHIC
-  libcharon_la_LIBADD += plugins/nm/libstrongswan-nm.la
-endif
-endif
-
 if USE_DHCP
   SUBDIRS += plugins/dhcp
 if MONOLITHIC
diff --git a/src/libcharon/plugins/nm/Makefile.am b/src/libcharon/plugins/nm/Makefile.am
deleted file mode 100644 (file)
index 8e12a72..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-
-INCLUDES = -I$(top_srcdir)/src/libstrongswan -I$(top_srcdir)/src/libhydra \
-       -I$(top_srcdir)/src/libcharon ${nm_CFLAGS}
-
-AM_CFLAGS = -rdynamic \
-  -DNM_CA_DIR=\"${nm_ca_dir}\"
-
-if MONOLITHIC
-noinst_LTLIBRARIES = libstrongswan-nm.la
-else
-plugin_LTLIBRARIES = libstrongswan-nm.la
-endif
-
-libstrongswan_nm_la_SOURCES = \
-       nm_plugin.h nm_plugin.c \
-       nm_service.h nm_service.c \
-       nm_creds.h nm_creds.c \
-       nm_handler.h nm_handler.c
-
-libstrongswan_nm_la_LDFLAGS = -module -avoid-version
-libstrongswan_nm_la_LIBADD  = ${nm_LIBS}