Integrate nm plugin directly in charon-nm.

This commit is contained in:
Tobias Brunner 2012-04-19 16:40:21 +02:00
parent 1c7a733e36
commit b64f333612
13 changed files with 67 additions and 85 deletions

View File

@ -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([ipseclibdir], [${libdir%/}/ipsec], [set installation path for ipsec libraries])
ARG_WITH_SUBST([plugindir], [${ipseclibdir%/}/plugins], [set the installation path of plugins]) 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([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([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], [220], [set routing table to use for IPsec routes])
ARG_WITH_SUBST([routing-table-prio], [220], [set priority for IPsec routing table]) 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([tnccs-dynamic], [c charon])
ADD_PLUGIN([medsrv], [c charon]) ADD_PLUGIN([medsrv], [c charon])
ADD_PLUGIN([medcli], [c charon]) ADD_PLUGIN([medcli], [c charon])
ADD_PLUGIN([nm], [c charon])
ADD_PLUGIN([dhcp], [c charon]) ADD_PLUGIN([dhcp], [c charon])
ADD_PLUGIN([android], [c charon]) ADD_PLUGIN([android], [c charon])
ADD_PLUGIN([ha], [c charon]) ADD_PLUGIN([ha], [c charon])
@ -972,7 +971,6 @@ dnl ==============
AM_CONDITIONAL(USE_STROKE, test x$stroke = xtrue) AM_CONDITIONAL(USE_STROKE, test x$stroke = xtrue)
AM_CONDITIONAL(USE_MEDSRV, test x$medsrv = xtrue) AM_CONDITIONAL(USE_MEDSRV, test x$medsrv = xtrue)
AM_CONDITIONAL(USE_MEDCLI, test x$medcli = 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_UCI, test x$uci = xtrue)
AM_CONDITIONAL(USE_ANDROID, test x$android = xtrue) AM_CONDITIONAL(USE_ANDROID, test x$android = xtrue)
AM_CONDITIONAL(USE_MAEMO, test x$maemo = xtrue) AM_CONDITIONAL(USE_MAEMO, test x$maemo = xtrue)
@ -1215,7 +1213,6 @@ AC_OUTPUT(
src/libcharon/plugins/sql/Makefile src/libcharon/plugins/sql/Makefile
src/libcharon/plugins/medsrv/Makefile src/libcharon/plugins/medsrv/Makefile
src/libcharon/plugins/medcli/Makefile src/libcharon/plugins/medcli/Makefile
src/libcharon/plugins/nm/Makefile
src/libcharon/plugins/addrblock/Makefile src/libcharon/plugins/addrblock/Makefile
src/libcharon/plugins/uci/Makefile src/libcharon/plugins/uci/Makefile
src/libcharon/plugins/ha/Makefile src/libcharon/plugins/ha/Makefile

View File

@ -1,20 +1,26 @@
ipsec_PROGRAMS = charon-nm ipsec_PROGRAMS = charon-nm
charon_nm_SOURCES = \ 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 = \ INCLUDES = \
-I$(top_srcdir)/src/libstrongswan \ -I$(top_srcdir)/src/libstrongswan \
-I$(top_srcdir)/src/libhydra \ -I$(top_srcdir)/src/libhydra \
-I$(top_srcdir)/src/libcharon -I$(top_srcdir)/src/libcharon \
${nm_CFLAGS}
AM_CFLAGS = \ AM_CFLAGS = \
-DIPSEC_DIR=\"${ipsecdir}\" \ -DIPSEC_DIR=\"${ipsecdir}\" \
-DIPSEC_PIDDIR=\"${piddir}\" \ -DIPSEC_PIDDIR=\"${piddir}\" \
-DNM_CA_DIR=\"${nm_ca_dir}\" \
-DPLUGINS=\""${nm_plugins}\"" -DPLUGINS=\""${nm_plugins}\""
charon_nm_LDADD = \ charon_nm_LDADD = \
$(top_builddir)/src/libstrongswan/libstrongswan.la \ $(top_builddir)/src/libstrongswan/libstrongswan.la \
$(top_builddir)/src/libhydra/libhydra.la \ $(top_builddir)/src/libhydra/libhydra.la \
$(top_builddir)/src/libcharon/libcharon.la \ $(top_builddir)/src/libcharon/libcharon.la \
-lm $(PTHREADLIB) $(DLLIB) -lm $(PTHREADLIB) $(DLLIB) ${nm_LIBS}

View File

@ -31,6 +31,8 @@
#include <utils/backtrace.h> #include <utils/backtrace.h>
#include <threading/thread.h> #include <threading/thread.h>
#include <nm/nm_backend.h>
/** /**
* Hook in library for debugging messages * Hook in library for debugging messages
*/ */
@ -270,10 +272,17 @@ int main(int argc, char *argv[])
goto deinit; 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()) if (!drop_capabilities())
{ {
DBG1(DBG_DMN, "capability dropping failed - aborting charon-nm"); DBG1(DBG_DMN, "capability dropping failed - aborting charon-nm");
goto deinit; goto deinit_nm;
} }
/* add handler for SEGV and ILL, /* add handler for SEGV and ILL,
@ -299,6 +308,8 @@ int main(int argc, char *argv[])
status = 0; status = 0;
deinit_nm:
nm_backend_deinit();
deinit: deinit:
libcharon_deinit(); libcharon_deinit();
libhydra_deinit(); libhydra_deinit();

View File

@ -1,4 +1,5 @@
/* /*
* Copyright (C) 2012 Tobias Brunner
* Copyright (C) 2008-2009 Martin Willi * Copyright (C) 2008-2009 Martin Willi
* Hochschule fuer Technik Rapperswil * Hochschule fuer Technik Rapperswil
* *
@ -13,7 +14,6 @@
* for more details. * for more details.
*/ */
#include "nm_plugin.h"
#include "nm_service.h" #include "nm_service.h"
#include "nm_creds.h" #include "nm_creds.h"
#include "nm_handler.h" #include "nm_handler.h"
@ -24,17 +24,12 @@
#define CAP_DAC_OVERRIDE 1 #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 { struct nm_backend_t {
/**
* implements plugin interface
*/
nm_plugin_t public;
/** /**
* NetworkManager service (VPNPlugin) * NetworkManager service (VPNPlugin)
@ -57,25 +52,32 @@ struct private_nm_plugin_t {
nm_handler_t *handler; 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 * 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); this->loop = g_main_loop_new(NULL, FALSE);
g_main_loop_run(this->loop); g_main_loop_run(this->loop);
return JOB_REQUEUE_NONE; 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, if (!this)
private_nm_plugin_t *this) {
{ return;
}
if (this->loop) if (this->loop)
{ {
if (g_main_loop_is_running(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->creds->destroy(this->creds);
this->handler->destroy(this->handler); this->handler->destroy(this->handler);
free(this); free(this);
nm_backend = NULL;
} }
/* /*
* see header file * see header file
*/ */
plugin_t *nm_plugin_create() bool nm_backend_init()
{ {
private_nm_plugin_t *this; nm_backend_t *this;
g_type_init (); g_type_init ();
if (!g_thread_supported()) if (!g_thread_supported())
@ -109,25 +113,19 @@ plugin_t *nm_plugin_create()
} }
INIT(this, INIT(this,
.public = {
.plugin = {
.get_name = _get_name,
.reload = (void*)return_false,
.destroy = _destroy,
},
},
.creds = nm_creds_create(), .creds = nm_creds_create(),
.handler = nm_handler_create(), .handler = nm_handler_create(),
); );
this->plugin = nm_strongswan_plugin_new(this->creds, this->handler); this->plugin = nm_strongswan_plugin_new(this->creds, this->handler);
nm_backend = this;
hydra->attributes->add_handler(hydra->attributes, &this->handler->handler); hydra->attributes->add_handler(hydra->attributes, &this->handler->handler);
lib->credmgr->add_set(lib->credmgr, &this->creds->set); lib->credmgr->add_set(lib->credmgr, &this->creds->set);
if (!this->plugin) if (!this->plugin)
{ {
DBG1(DBG_CFG, "DBUS binding failed"); DBG1(DBG_CFG, "DBUS binding failed");
destroy(this); nm_backend_deinit();
return NULL; return FALSE;
} }
/* bypass file permissions to read from users ssh-agent */ /* bypass file permissions to read from users ssh-agent */
@ -136,7 +134,6 @@ plugin_t *nm_plugin_create()
lib->processor->queue_job(lib->processor, lib->processor->queue_job(lib->processor,
(job_t*)callback_job_create_with_prio((callback_job_cb_t)run, (job_t*)callback_job_create_with_prio((callback_job_cb_t)run,
this, NULL, NULL, JOB_PRIO_CRITICAL)); this, NULL, NULL, JOB_PRIO_CRITICAL));
return TRUE;
return &this->public.plugin;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2008 Martin Willi * Copyright (C) 2012 Tobias Brunner
* Hochschule fuer Technik Rapperswil * Hochschule fuer Technik Rapperswil
* *
* This program is free software; you can redistribute it and/or modify it * This program is free software; you can redistribute it and/or modify it
@ -14,29 +14,28 @@
*/ */
/** /**
* @defgroup nm nm * @defgroup charon-nm charon-nm
* @ingroup cplugins
* *
* @defgroup nm_plugin nm_plugin * @defgroup nm nm
* @ingroup charon-nm
*
* @defgroup nm_backend nm_backend
* @{ @ingroup nm * @{ @ingroup nm
*/ */
#ifndef NM_PLUGIN_H_ #ifndef NM_BACKEND_H_
#define NM_PLUGIN_H_ #define NM_BACKEND_H_
#include <plugins/plugin.h>
typedef struct nm_plugin_t nm_plugin_t;
/** /**
* NetworkManager integration plugin. * Initialize the NetworkManager backend.
*
* @return TRUE, if initialization was successful
*/ */
struct nm_plugin_t { bool nm_backend_init();
/** /**
* implements plugin interface * Deinitialize the NetworkManager backend.
*/ */
plugin_t plugin; void nm_backend_deinit();
};
#endif /** NM_PLUGIN_H_ @}*/ #endif /** NM_BACKEND_H_ @}*/

View File

@ -668,7 +668,7 @@ static void nm_strongswan_plugin_init(NMStrongswanPlugin *plugin)
priv = NM_STRONGSWAN_PLUGIN_GET_PRIVATE(plugin); priv = NM_STRONGSWAN_PLUGIN_GET_PRIVATE(plugin);
priv->plugin = NM_VPN_PLUGIN(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.child_updown = child_updown;
priv->listener.ike_rekey = ike_rekey; priv->listener.ike_rekey = ike_rekey;
} }

View File

@ -444,13 +444,6 @@ if MONOLITHIC
endif endif
endif endif
if USE_NM
SUBDIRS += plugins/nm
if MONOLITHIC
libcharon_la_LIBADD += plugins/nm/libstrongswan-nm.la
endif
endif
if USE_DHCP if USE_DHCP
SUBDIRS += plugins/dhcp SUBDIRS += plugins/dhcp
if MONOLITHIC if MONOLITHIC

View File

@ -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}