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;
if (script == NULL)
{
- return;
+ return TRUE;
}
enumerator = child_sa->create_policy_enumerator(child_sa);
if (shell == NULL)
{
DBG1(DBG_CHD, "could not execute updown script '%s'", script);
- return;
+ return TRUE;
}
while (TRUE)
if (ferror(shell))
{
DBG1(DBG_CHD, "error reading output from updown script");
- return;
- }
- else
- {
- break;
}
+ break;
}
else
{
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);
*/
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;
}