aboutsummaryrefslogtreecommitdiffstats
path: root/src/charon
diff options
context:
space:
mode:
authorMartin Willi <martin@strongswan.org>2010-02-03 11:04:18 +0100
committerMartin Willi <martin@strongswan.org>2010-02-03 11:07:53 +0100
commit7481f964ae82ad9e478aae00265415427b6613f3 (patch)
tree2c76fde8defaee42d04270a0e0d2752ed3e11363 /src/charon
parent0d8bdf24ffb3d3a1f2134628dc2e3db566d2d8d7 (diff)
downloadstrongswan-7481f964ae82ad9e478aae00265415427b6613f3.tar.bz2
strongswan-7481f964ae82ad9e478aae00265415427b6613f3.tar.xz
Use child_updown hook in updown plugin, fixes doubled invocation of down script
Diffstat (limited to 'src/charon')
-rw-r--r--src/charon/plugins/updown/updown_listener.c64
1 files changed, 17 insertions, 47 deletions
diff --git a/src/charon/plugins/updown/updown_listener.c b/src/charon/plugins/updown/updown_listener.c
index b4399c546..5a6746f92 100644
--- a/src/charon/plugins/updown/updown_listener.c
+++ b/src/charon/plugins/updown/updown_listener.c
@@ -89,11 +89,9 @@ static char* uncache_iface(private_updown_listener_t *this, u_int32_t reqid)
return iface;
}
-/**
- * Run the up/down script
- */
-static void updown(private_updown_listener_t *this, ike_sa_t *ike_sa,
- child_sa_t *child_sa, bool up)
+METHOD(listener_t, child_updown, bool,
+ private_updown_listener_t *this, ike_sa_t *ike_sa, child_sa_t *child_sa,
+ bool up)
{
traffic_selector_t *my_ts, *other_ts;
enumerator_t *enumerator;
@@ -109,7 +107,7 @@ static void updown(private_updown_listener_t *this, ike_sa_t *ike_sa,
if (script == NULL)
{
- return;
+ return TRUE;
}
enumerator = child_sa->create_policy_enumerator(child_sa);
@@ -238,7 +236,7 @@ static void updown(private_updown_listener_t *this, ike_sa_t *ike_sa,
if (shell == NULL)
{
DBG1(DBG_CHD, "could not execute updown script '%s'", script);
- return;
+ return TRUE;
}
while (TRUE)
@@ -250,12 +248,8 @@ static void updown(private_updown_listener_t *this, ike_sa_t *ike_sa,
if (ferror(shell))
{
DBG1(DBG_CHD, "error reading output from updown script");
- return;
- }
- else
- {
- break;
}
+ break;
}
else
{
@@ -270,37 +264,11 @@ static void updown(private_updown_listener_t *this, ike_sa_t *ike_sa,
pclose(shell);
}
enumerator->destroy(enumerator);
-}
-
-/**
- * Listener implementation
- */
-static bool child_state_change(private_updown_listener_t *this, ike_sa_t *ike_sa,
- child_sa_t *child_sa, child_sa_state_t state)
-{
- child_sa_state_t old;
-
- if (ike_sa)
- {
- old = child_sa->get_state(child_sa);
-
- if ((old == CHILD_INSTALLED && state != CHILD_REKEYING ) ||
- (old == CHILD_DELETING && state == CHILD_DESTROYING))
- {
- updown(this, ike_sa, child_sa, FALSE);
- }
- else if (state == CHILD_INSTALLED)
- {
- updown(this, ike_sa, child_sa, TRUE);
- }
- }
return TRUE;
}
-/**
- * Implementation of updown_listener_t.destroy.
- */
-static void destroy(private_updown_listener_t *this)
+METHOD(updown_listener_t, destroy, void,
+ private_updown_listener_t *this)
{
this->iface_cache->destroy(this->iface_cache);
free(this);
@@ -311,13 +279,15 @@ static void destroy(private_updown_listener_t *this)
*/
updown_listener_t *updown_listener_create()
{
- private_updown_listener_t *this = malloc_thing(private_updown_listener_t);
-
- memset(&this->public.listener, 0, sizeof(listener_t));
- this->public.listener.child_state_change = (void*)child_state_change;
- this->public.destroy = (void(*)(updown_listener_t*))destroy;
-
- this->iface_cache = linked_list_create();
+ private_updown_listener_t *this;
+
+ INIT(this,
+ .public = {
+ .listener.child_updown = _child_updown,
+ .destroy = _destroy,
+ },
+ .iface_cache = linked_list_create(),
+ );
return &this->public;
}