Use child_updown hook in updown plugin, fixes doubled invocation of down script
This commit is contained in:
parent
0d8bdf24ff
commit
7481f964ae
|
@ -89,11 +89,9 @@ static char* uncache_iface(private_updown_listener_t *this, u_int32_t reqid)
|
||||||
return iface;
|
return iface;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(listener_t, child_updown, bool,
|
||||||
* Run the up/down script
|
private_updown_listener_t *this, ike_sa_t *ike_sa, child_sa_t *child_sa,
|
||||||
*/
|
bool up)
|
||||||
static void updown(private_updown_listener_t *this, ike_sa_t *ike_sa,
|
|
||||||
child_sa_t *child_sa, bool up)
|
|
||||||
{
|
{
|
||||||
traffic_selector_t *my_ts, *other_ts;
|
traffic_selector_t *my_ts, *other_ts;
|
||||||
enumerator_t *enumerator;
|
enumerator_t *enumerator;
|
||||||
|
@ -109,7 +107,7 @@ static void updown(private_updown_listener_t *this, ike_sa_t *ike_sa,
|
||||||
|
|
||||||
if (script == NULL)
|
if (script == NULL)
|
||||||
{
|
{
|
||||||
return;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
enumerator = child_sa->create_policy_enumerator(child_sa);
|
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)
|
if (shell == NULL)
|
||||||
{
|
{
|
||||||
DBG1(DBG_CHD, "could not execute updown script '%s'", script);
|
DBG1(DBG_CHD, "could not execute updown script '%s'", script);
|
||||||
return;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (TRUE)
|
while (TRUE)
|
||||||
|
@ -250,12 +248,8 @@ static void updown(private_updown_listener_t *this, ike_sa_t *ike_sa,
|
||||||
if (ferror(shell))
|
if (ferror(shell))
|
||||||
{
|
{
|
||||||
DBG1(DBG_CHD, "error reading output from updown script");
|
DBG1(DBG_CHD, "error reading output from updown script");
|
||||||
return;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -270,37 +264,11 @@ static void updown(private_updown_listener_t *this, ike_sa_t *ike_sa,
|
||||||
pclose(shell);
|
pclose(shell);
|
||||||
}
|
}
|
||||||
enumerator->destroy(enumerator);
|
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;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(updown_listener_t, destroy, void,
|
||||||
* Implementation of updown_listener_t.destroy.
|
private_updown_listener_t *this)
|
||||||
*/
|
|
||||||
static void destroy(private_updown_listener_t *this)
|
|
||||||
{
|
{
|
||||||
this->iface_cache->destroy(this->iface_cache);
|
this->iface_cache->destroy(this->iface_cache);
|
||||||
free(this);
|
free(this);
|
||||||
|
@ -311,13 +279,15 @@ static void destroy(private_updown_listener_t *this)
|
||||||
*/
|
*/
|
||||||
updown_listener_t *updown_listener_create()
|
updown_listener_t *updown_listener_create()
|
||||||
{
|
{
|
||||||
private_updown_listener_t *this = malloc_thing(private_updown_listener_t);
|
private_updown_listener_t *this;
|
||||||
|
|
||||||
memset(&this->public.listener, 0, sizeof(listener_t));
|
INIT(this,
|
||||||
this->public.listener.child_state_change = (void*)child_state_change;
|
.public = {
|
||||||
this->public.destroy = (void(*)(updown_listener_t*))destroy;
|
.listener.child_updown = _child_updown,
|
||||||
|
.destroy = _destroy,
|
||||||
this->iface_cache = linked_list_create();
|
},
|
||||||
|
.iface_cache = linked_list_create(),
|
||||||
|
);
|
||||||
|
|
||||||
return &this->public;
|
return &this->public;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue