summaryrefslogtreecommitdiff
path: root/src/libcharon/plugins/unity
diff options
context:
space:
mode:
Diffstat (limited to 'src/libcharon/plugins/unity')
-rw-r--r--src/libcharon/plugins/unity/Makefile.am8
-rw-r--r--src/libcharon/plugins/unity/Makefile.in78
-rw-r--r--src/libcharon/plugins/unity/unity_handler.c147
-rw-r--r--src/libcharon/plugins/unity/unity_narrow.c43
-rw-r--r--src/libcharon/plugins/unity/unity_plugin.c49
-rw-r--r--src/libcharon/plugins/unity/unity_provider.c1
6 files changed, 227 insertions, 99 deletions
diff --git a/src/libcharon/plugins/unity/Makefile.am b/src/libcharon/plugins/unity/Makefile.am
index b23143fd6..b50dc9a03 100644
--- a/src/libcharon/plugins/unity/Makefile.am
+++ b/src/libcharon/plugins/unity/Makefile.am
@@ -1,8 +1,10 @@
-
-INCLUDES = -I$(top_srcdir)/src/libstrongswan -I$(top_srcdir)/src/libhydra \
+AM_CPPFLAGS = \
+ -I$(top_srcdir)/src/libstrongswan \
+ -I$(top_srcdir)/src/libhydra \
-I$(top_srcdir)/src/libcharon
-AM_CFLAGS = -rdynamic
+AM_CFLAGS = \
+ -rdynamic
if MONOLITHIC
noinst_LTLIBRARIES = libstrongswan-unity.la
diff --git a/src/libcharon/plugins/unity/Makefile.in b/src/libcharon/plugins/unity/Makefile.in
index 85c5fc97e..09ea080bf 100644
--- a/src/libcharon/plugins/unity/Makefile.in
+++ b/src/libcharon/plugins/unity/Makefile.in
@@ -62,7 +62,7 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/config/libtool.m4 \
$(top_srcdir)/m4/macros/with.m4 \
$(top_srcdir)/m4/macros/enable-disable.m4 \
$(top_srcdir)/m4/macros/add-plugin.m4 \
- $(top_srcdir)/configure.in
+ $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(install_sh) -d
@@ -102,9 +102,13 @@ libstrongswan_unity_la_LIBADD =
am_libstrongswan_unity_la_OBJECTS = unity_plugin.lo unity_handler.lo \
unity_narrow.lo unity_provider.lo
libstrongswan_unity_la_OBJECTS = $(am_libstrongswan_unity_la_OBJECTS)
-libstrongswan_unity_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
- $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
- $(libstrongswan_unity_la_LDFLAGS) $(LDFLAGS) -o $@
+AM_V_lt = $(am__v_lt_@AM_V@)
+am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
+am__v_lt_0 = --silent
+libstrongswan_unity_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
+ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
+ $(AM_CFLAGS) $(CFLAGS) $(libstrongswan_unity_la_LDFLAGS) \
+ $(LDFLAGS) -o $@
@MONOLITHIC_FALSE@am_libstrongswan_unity_la_rpath = -rpath \
@MONOLITHIC_FALSE@ $(plugindir)
@MONOLITHIC_TRUE@am_libstrongswan_unity_la_rpath =
@@ -114,13 +118,26 @@ am__depfiles_maybe = depfiles
am__mv = mv -f
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
-LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
- --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
- $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
+ $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
+ $(AM_CFLAGS) $(CFLAGS)
+AM_V_CC = $(am__v_CC_@AM_V@)
+am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
+am__v_CC_0 = @echo " CC " $@;
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
+am__v_at_0 = @
CCLD = $(CC)
-LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
- --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
- $(LDFLAGS) -o $@
+LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+ $(AM_LDFLAGS) $(LDFLAGS) -o $@
+AM_V_CCLD = $(am__v_CCLD_@AM_V@)
+am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
+am__v_CCLD_0 = @echo " CCLD " $@;
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
+am__v_GEN_0 = @echo " GEN " $@;
SOURCES = $(libstrongswan_unity_la_SOURCES)
DIST_SOURCES = $(libstrongswan_unity_la_SOURCES)
am__can_run_installinfo = \
@@ -134,6 +151,7 @@ DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
ALLOCA = @ALLOCA@
AMTAR = @AMTAR@
+AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
AR = @AR@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
@@ -146,6 +164,8 @@ CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
CHECK_CFLAGS = @CHECK_CFLAGS@
CHECK_LIBS = @CHECK_LIBS@
+COVERAGE_CFLAGS = @COVERAGE_CFLAGS@
+COVERAGE_LDFLAGS = @COVERAGE_LDFLAGS@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CYGPATH_W = @CYGPATH_W@
@@ -161,6 +181,7 @@ ECHO_T = @ECHO_T@
EGREP = @EGREP@
EXEEXT = @EXEEXT@
FGREP = @FGREP@
+GENHTML = @GENHTML@
GPERF = @GPERF@
GPRBUILD = @GPRBUILD@
GREP = @GREP@
@@ -169,6 +190,7 @@ INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LCOV = @LCOV@
LD = @LD@
LDFLAGS = @LDFLAGS@
LEX = @LEX@
@@ -215,6 +237,7 @@ SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
SOCKLIB = @SOCKLIB@
STRIP = @STRIP@
+UNWINDLIB = @UNWINDLIB@
VERSION = @VERSION@
YACC = @YACC@
YFLAGS = @YFLAGS@
@@ -243,6 +266,7 @@ charon_natt_port = @charon_natt_port@
charon_plugins = @charon_plugins@
charon_udp_port = @charon_udp_port@
clearsilver_LIBS = @clearsilver_LIBS@
+cmd_plugins = @cmd_plugins@
datadir = @datadir@
datarootdir = @datarootdir@
dbusservicedir = @dbusservicedir@
@@ -320,10 +344,14 @@ top_srcdir = @top_srcdir@
urandom_device = @urandom_device@
xml_CFLAGS = @xml_CFLAGS@
xml_LIBS = @xml_LIBS@
-INCLUDES = -I$(top_srcdir)/src/libstrongswan -I$(top_srcdir)/src/libhydra \
+AM_CPPFLAGS = \
+ -I$(top_srcdir)/src/libstrongswan \
+ -I$(top_srcdir)/src/libhydra \
-I$(top_srcdir)/src/libcharon
-AM_CFLAGS = -rdynamic
+AM_CFLAGS = \
+ -rdynamic
+
@MONOLITHIC_TRUE@noinst_LTLIBRARIES = libstrongswan-unity.la
@MONOLITHIC_FALSE@plugin_LTLIBRARIES = libstrongswan-unity.la
libstrongswan_unity_la_SOURCES = \
@@ -409,7 +437,7 @@ clean-pluginLTLIBRARIES:
rm -f "$${dir}/so_locations"; \
done
libstrongswan-unity.la: $(libstrongswan_unity_la_OBJECTS) $(libstrongswan_unity_la_DEPENDENCIES) $(EXTRA_libstrongswan_unity_la_DEPENDENCIES)
- $(libstrongswan_unity_la_LINK) $(am_libstrongswan_unity_la_rpath) $(libstrongswan_unity_la_OBJECTS) $(libstrongswan_unity_la_LIBADD) $(LIBS)
+ $(AM_V_CCLD)$(libstrongswan_unity_la_LINK) $(am_libstrongswan_unity_la_rpath) $(libstrongswan_unity_la_OBJECTS) $(libstrongswan_unity_la_LIBADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT)
@@ -423,25 +451,25 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/unity_provider.Plo@am__quote@
.c.o:
-@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
-@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@ $(COMPILE) -c $<
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c $<
.c.obj:
-@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
-@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'`
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c `$(CYGPATH_W) '$<'`
.c.lo:
-@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
-@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $<
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
mostlyclean-libtool:
-rm -f *.lo
diff --git a/src/libcharon/plugins/unity/unity_handler.c b/src/libcharon/plugins/unity/unity_handler.c
index 3dec7a3b6..bcef0dc25 100644
--- a/src/libcharon/plugins/unity/unity_handler.c
+++ b/src/libcharon/plugins/unity/unity_handler.c
@@ -1,4 +1,7 @@
/*
+ * Copyright (C) 2013 Tobias Brunner
+ * Hochschule fuer Technik Rapperswil
+ *
* Copyright (C) 2012 Martin Willi
* Copyright (C) 2012 revosec AG
*
@@ -70,12 +73,8 @@ static traffic_selector_t *create_ts(chunk_t subnet)
chunk_t net, mask;
int i;
- if (subnet.len != 8)
- {
- return NULL;
- }
net = chunk_create(subnet.ptr, 4);
- mask = chunk_clonea(chunk_skip(subnet, 4));
+ mask = chunk_clonea(chunk_create(subnet.ptr + 4, 4));
for (i = 0; i < net.len; i++)
{
mask.ptr[i] = (mask.ptr[i] ^ 0xFF) | net.ptr[i];
@@ -85,11 +84,37 @@ static traffic_selector_t *create_ts(chunk_t subnet)
}
/**
- * Store a subnet to include in tunnels under this IKE_SA
+ * Parse a unity attribute and extract all subnets as traffic selectors
+ */
+static linked_list_t *parse_subnets(chunk_t data)
+{
+ linked_list_t *list = NULL;
+ traffic_selector_t *ts;
+
+ while (data.len >= 8)
+ { /* the padding is optional */
+ ts = create_ts(data);
+ if (ts)
+ {
+ if (!list)
+ {
+ list = linked_list_create();
+ }
+ list->insert_last(list, ts);
+ }
+ /* skip address, mask and 6 bytes of padding */
+ data = chunk_skip(data, 14);
+ }
+ return list;
+}
+
+/**
+ * Store a list of subnets to include in tunnels under this IKE_SA
*/
-static bool add_include(private_unity_handler_t *this, chunk_t subnet)
+static bool add_include(private_unity_handler_t *this, chunk_t data)
{
traffic_selector_t *ts;
+ linked_list_t *list;
ike_sa_t *ike_sa;
entry_t *entry;
@@ -98,29 +123,34 @@ static bool add_include(private_unity_handler_t *this, chunk_t subnet)
{
return FALSE;
}
- ts = create_ts(subnet);
- if (!ts)
+ list = parse_subnets(data);
+ if (!list)
{
return FALSE;
}
- INIT(entry,
- .sa = ike_sa->get_unique_id(ike_sa),
- .ts = ts,
- );
-
- this->mutex->lock(this->mutex);
- this->include->insert_last(this->include, entry);
- this->mutex->unlock(this->mutex);
+ while (list->remove_first(list, (void**)&ts) == SUCCESS)
+ {
+ INIT(entry,
+ .sa = ike_sa->get_unique_id(ike_sa),
+ .ts = ts,
+ );
+
+ this->mutex->lock(this->mutex);
+ this->include->insert_last(this->include, entry);
+ this->mutex->unlock(this->mutex);
+ }
+ list->destroy(list);
return TRUE;
}
/**
- * Remove a subnet from the inclusion list for this IKE_SA
+ * Remove a list of subnets from the inclusion list for this IKE_SA
*/
-static bool remove_include(private_unity_handler_t *this, chunk_t subnet)
+static bool remove_include(private_unity_handler_t *this, chunk_t data)
{
enumerator_t *enumerator;
traffic_selector_t *ts;
+ linked_list_t *list;
ike_sa_t *ike_sa;
entry_t *entry;
@@ -129,27 +159,31 @@ static bool remove_include(private_unity_handler_t *this, chunk_t subnet)
{
return FALSE;
}
- ts = create_ts(subnet);
- if (!ts)
+ list = parse_subnets(data);
+ if (!list)
{
return FALSE;
}
this->mutex->lock(this->mutex);
- enumerator = this->include->create_enumerator(this->include);
- while (enumerator->enumerate(enumerator, &entry))
+ while (list->remove_first(list, (void**)&ts) == SUCCESS)
{
- if (entry->sa == ike_sa->get_unique_id(ike_sa) &&
- ts->equals(ts, entry->ts))
+ enumerator = this->include->create_enumerator(this->include);
+ while (enumerator->enumerate(enumerator, &entry))
{
- this->include->remove_at(this->include, enumerator);
- entry_destroy(entry);
- break;
+ if (entry->sa == ike_sa->get_unique_id(ike_sa) &&
+ ts->equals(ts, entry->ts))
+ {
+ this->include->remove_at(this->include, enumerator);
+ entry_destroy(entry);
+ break;
+ }
}
+ enumerator->destroy(enumerator);
+ ts->destroy(ts);
}
- enumerator->destroy(enumerator);
this->mutex->unlock(this->mutex);
- ts->destroy(ts);
+ list->destroy(list);
return TRUE;
}
@@ -212,9 +246,10 @@ static job_requeue_t add_exclude_async(entry_t *entry)
/**
* Add a bypass policy for a given subnet
*/
-static bool add_exclude(private_unity_handler_t *this, chunk_t subnet)
+static bool add_exclude(private_unity_handler_t *this, chunk_t data)
{
traffic_selector_t *ts;
+ linked_list_t *list;
ike_sa_t *ike_sa;
entry_t *entry;
@@ -223,48 +258,60 @@ static bool add_exclude(private_unity_handler_t *this, chunk_t subnet)
{
return FALSE;
}
- ts = create_ts(subnet);
- if (!ts)
+ list = parse_subnets(data);
+ if (!list)
{
return FALSE;
}
- INIT(entry,
- .sa = ike_sa->get_unique_id(ike_sa),
- .ts = ts,
- );
- /* we can't install the shunt policy yet, as we don't know the virtual IP.
- * Defer installation using an async callback. */
- lib->processor->queue_job(lib->processor, (job_t*)
- callback_job_create((void*)add_exclude_async, entry,
- (void*)entry_destroy, NULL));
+ while (list->remove_first(list, (void**)&ts) == SUCCESS)
+ {
+ INIT(entry,
+ .sa = ike_sa->get_unique_id(ike_sa),
+ .ts = ts,
+ );
+
+ /* we can't install the shunt policy yet, as we don't know the virtual IP.
+ * Defer installation using an async callback. */
+ lib->processor->queue_job(lib->processor, (job_t*)
+ callback_job_create((void*)add_exclude_async, entry,
+ (void*)entry_destroy, NULL));
+ }
+ list->destroy(list);
return TRUE;
}
/**
* Remove a bypass policy for a given subnet
*/
-static bool remove_exclude(private_unity_handler_t *this, chunk_t subnet)
+static bool remove_exclude(private_unity_handler_t *this, chunk_t data)
{
traffic_selector_t *ts;
+ linked_list_t *list;
ike_sa_t *ike_sa;
char name[128];
+ bool success = TRUE;
ike_sa = charon->bus->get_sa(charon->bus);
if (!ike_sa)
{
return FALSE;
}
- ts = create_ts(subnet);
- if (!ts)
+ list = parse_subnets(data);
+ if (!list)
{
return FALSE;
}
- create_shunt_name(ike_sa, ts, name, sizeof(name));
- DBG1(DBG_IKE, "uninstalling %N bypass policy for %R",
- configuration_attribute_type_names, UNITY_LOCAL_LAN, ts);
- ts->destroy(ts);
- return charon->shunts->uninstall(charon->shunts, name);
+ while (list->remove_first(list, (void**)&ts) == SUCCESS)
+ {
+ create_shunt_name(ike_sa, ts, name, sizeof(name));
+ DBG1(DBG_IKE, "uninstalling %N bypass policy for %R",
+ configuration_attribute_type_names, UNITY_LOCAL_LAN, ts);
+ ts->destroy(ts);
+ success = charon->shunts->uninstall(charon->shunts, name) && success;
+ }
+ list->destroy(list);
+ return success;
}
METHOD(attribute_handler_t, handle, bool,
diff --git a/src/libcharon/plugins/unity/unity_narrow.c b/src/libcharon/plugins/unity/unity_narrow.c
index 56de0028f..edff51a08 100644
--- a/src/libcharon/plugins/unity/unity_narrow.c
+++ b/src/libcharon/plugins/unity/unity_narrow.c
@@ -36,13 +36,32 @@ struct private_unity_narrow_t {
};
/**
+ * Narrow the given received traffic selector with the child configuration and
+ * put them into the given list of TS
+ */
+static void narrow_ts(child_cfg_t *cfg, traffic_selector_t *ts,
+ linked_list_t *list)
+{
+ linked_list_t *received, *selected;
+
+ received = linked_list_create();
+ received->insert_last(received, ts);
+ selected = cfg->get_traffic_selectors(cfg, FALSE, received, NULL);
+ while (selected->remove_first(selected, (void**)&ts) == SUCCESS)
+ {
+ list->insert_last(list, ts);
+ }
+ selected->destroy(selected);
+ received->destroy(received);
+}
+
+/**
* Narrow TS as initiator to Unity Split-Include/Local-LAN
*/
static void narrow_initiator(private_unity_narrow_t *this, ike_sa_t *ike_sa,
child_cfg_t *cfg, linked_list_t *remote)
{
traffic_selector_t *current, *orig = NULL;
- linked_list_t *received, *selected;
enumerator_t *enumerator;
enumerator = this->handler->create_include_enumerator(this->handler,
@@ -56,16 +75,7 @@ static void narrow_initiator(private_unity_narrow_t *this, ike_sa_t *ike_sa,
break;
}
}
- /* narrow received Unity TS with the child configuration */
- received = linked_list_create();
- received->insert_last(received, current);
- selected = cfg->get_traffic_selectors(cfg, FALSE, received, NULL);
- while (selected->remove_first(selected, (void**)&current) == SUCCESS)
- {
- remote->insert_last(remote, current);
- }
- selected->destroy(selected);
- received->destroy(received);
+ narrow_ts(cfg, current, remote);
}
enumerator->destroy(enumerator);
if (orig)
@@ -75,6 +85,15 @@ static void narrow_initiator(private_unity_narrow_t *this, ike_sa_t *ike_sa,
UNITY_SPLIT_INCLUDE, remote);
orig->destroy(orig);
}
+ else
+ { /* since we originally changed the traffic selector to 0.0.0.0/0 local
+ * narrowing is not applied if no Split-Include attrs are received */
+ if (remote->remove_first(remote, (void**)&orig) == SUCCESS)
+ {
+ narrow_ts(cfg, orig, remote);
+ orig->destroy(orig);
+ }
+ }
}
/**
@@ -93,6 +112,8 @@ static void narrow_initiator_pre(linked_list_t *list)
"255.255.255.255", 65535);
if (ts)
{
+ DBG2(DBG_CFG, "changing proposed traffic selectors for other:");
+ DBG2(DBG_CFG, " %R", ts);
list->insert_last(list, ts);
}
}
diff --git a/src/libcharon/plugins/unity/unity_plugin.c b/src/libcharon/plugins/unity/unity_plugin.c
index 9e21bd9ed..9e4571d34 100644
--- a/src/libcharon/plugins/unity/unity_plugin.c
+++ b/src/libcharon/plugins/unity/unity_plugin.c
@@ -55,14 +55,47 @@ METHOD(plugin_t, get_name, char*,
return "unity";
}
+/**
+ * Register listener
+ */
+static bool plugin_cb(private_unity_plugin_t *this,
+ plugin_feature_t *feature, bool reg, void *cb_data)
+{
+ if (reg)
+ {
+ hydra->attributes->add_handler(hydra->attributes,
+ &this->handler->handler);
+ hydra->attributes->add_provider(hydra->attributes,
+ &this->provider->provider);
+ charon->bus->add_listener(charon->bus, &this->narrower->listener);
+ }
+ else
+ {
+ charon->bus->remove_listener(charon->bus, &this->narrower->listener);
+ hydra->attributes->remove_handler(hydra->attributes,
+ &this->handler->handler);
+ hydra->attributes->remove_provider(hydra->attributes,
+ &this->provider->provider);
+
+ }
+ return TRUE;
+}
+
+METHOD(plugin_t, get_features, int,
+ private_unity_plugin_t *this, plugin_feature_t *features[])
+{
+ static plugin_feature_t f[] = {
+ PLUGIN_CALLBACK((plugin_feature_callback_t)plugin_cb, NULL),
+ PLUGIN_PROVIDE(CUSTOM, "unity"),
+ };
+ *features = f;
+ return countof(f);
+}
+
METHOD(plugin_t, destroy, void,
private_unity_plugin_t *this)
{
- charon->bus->remove_listener(charon->bus, &this->narrower->listener);
this->narrower->destroy(this->narrower);
- hydra->attributes->remove_handler(hydra->attributes, &this->handler->handler);
- hydra->attributes->remove_provider(hydra->attributes,
- &this->provider->provider);
this->handler->destroy(this->handler);
this->provider->destroy(this->provider);
free(this);
@@ -79,18 +112,14 @@ plugin_t *unity_plugin_create()
.public = {
.plugin = {
.get_name = _get_name,
- .reload = (void*)return_false,
+ .get_features = _get_features,
.destroy = _destroy,
},
},
.handler = unity_handler_create(),
.provider = unity_provider_create(),
);
- hydra->attributes->add_handler(hydra->attributes, &this->handler->handler);
- hydra->attributes->add_provider(hydra->attributes, &this->provider->provider);
-
- this->narrower = unity_narrow_create(this->handler),
- charon->bus->add_listener(charon->bus, &this->narrower->listener);
+ this->narrower = unity_narrow_create(this->handler);
return &this->public.plugin;
}
diff --git a/src/libcharon/plugins/unity/unity_provider.c b/src/libcharon/plugins/unity/unity_provider.c
index 655b8724a..ac6f93d69 100644
--- a/src/libcharon/plugins/unity/unity_provider.c
+++ b/src/libcharon/plugins/unity/unity_provider.c
@@ -60,6 +60,7 @@ METHOD(enumerator_t, attribute_enumerate, bool,
}
if (ts->to_subnet(ts, &net, &mask))
{
+ ts->destroy(ts);
break;
}
ts->destroy(ts);