/*
- * Copyright (C) 2012 Tobias Brunner
+ * Copyright (C) 2012-2013 Tobias Brunner
*
* Copyright (C) secunet Security Networks AG
*
typedef struct ipsec_event_listener_t ipsec_event_listener_t;
#include <library.h>
+#include <selectors/traffic_selector.h>
/**
* Listener interface for IPsec events
* @param hard TRUE if this is a hard expire, FALSE otherwise
*/
void (*expire)(uint8_t protocol, uint32_t spi, host_t *dst, bool hard);
+
+ /**
+ * Called when no IPsec SA is found for an outbound policy
+ *
+ * @param reqid reqid of the policy for which to acquire an SA
+ */
+ void (*acquire)(uint32_t reqid);
};
#endif /** IPSEC_EVENT_LISTENER_H_ @}*/
/*
- * Copyright (C) 2012 Tobias Brunner
+ * Copyright (C) 2012-2013 Tobias Brunner
* Copyright (C) 2012 Giuliano Grassi
* Copyright (C) 2012 Ralf Sager
*
*/
enum {
IPSEC_EVENT_EXPIRE,
+ IPSEC_EVENT_ACQUIRE,
} type;
/**
- * Protocol of the SA
- */
- uint8_t protocol;
-
- /**
- * SPI of the SA, if any
- */
- uint32_t spi;
-
- /**
- * SA destination address
- */
- host_t *dst;
-
- /**
- * Additional data for specific event types
+ * Data for specific event types
*/
union {
struct {
+ /** Protocol of the SA */
+ uint8_t protocol;
+ /** SPI of the SA */
+ uint32_t spi;
+ /** SA destination address */
+ host_t *dst;
/** TRUE in case of a hard expire */
bool hard;
} expire;
+ struct {
+ /** Reqid of the SA */
+ uint32_t reqid;
+ } acquire;
+
} data;
} ipsec_event_t;
*/
static void ipsec_event_destroy(ipsec_event_t *event)
{
- event->dst->destroy(event->dst);
+ switch (event->type)
+ {
+ case IPSEC_EVENT_EXPIRE:
+ event->data.expire.dst->destroy(event->data.expire.dst);
+ break;
+ case IPSEC_EVENT_ACQUIRE:
+ break;
+ }
free(event);
}
case IPSEC_EVENT_EXPIRE:
if (current->expire)
{
- current->expire(event->protocol, event->spi, event->dst,
+ current->expire(event->data.expire.protocol,
+ event->data.expire.spi,
+ event->data.expire.dst,
event->data.expire.hard);
}
break;
+ case IPSEC_EVENT_ACQUIRE:
+ if (current->acquire)
+ {
+ current->acquire(event->data.acquire.reqid);
+ }
+ break;
}
}
enumerator->destroy(enumerator);
INIT(event,
.type = IPSEC_EVENT_EXPIRE,
- .protocol = protocol,
- .spi = spi,
- .dst = dst->clone(dst),
.data = {
.expire = {
+ .protocol = protocol,
+ .spi = spi,
+ .dst = dst->clone(dst),
.hard = hard,
},
},
this->queue->enqueue(this->queue, event);
}
+METHOD(ipsec_event_relay_t, acquire, void,
+ private_ipsec_event_relay_t *this, uint32_t reqid)
+{
+ ipsec_event_t *event;
+
+ INIT(event,
+ .type = IPSEC_EVENT_ACQUIRE,
+ .data = {
+ .acquire = {
+ .reqid = reqid,
+ },
+ },
+ );
+ this->queue->enqueue(this->queue, event);
+}
+
METHOD(ipsec_event_relay_t, register_listener, void,
private_ipsec_event_relay_t *this, ipsec_event_listener_t *listener)
{
INIT(this,
.public = {
.expire = _expire,
+ .acquire = _acquire,
.register_listener = _register_listener,
.unregister_listener = _unregister_listener,
.destroy = _destroy,
/*
+ * Copyright (C) 2013 Tobias Brunner
* Copyright (C) 2012 Giuliano Grassi
* Copyright (C) 2012 Ralf Sager
*
void (*expire)(ipsec_event_relay_t *this, uint8_t protocol, uint32_t spi,
host_t *dst, bool hard);
+ /**
+ * Raise an acquire event.
+ *
+ * @param reqid reqid of the policy for which to acquire an SA
+ */
+ void (*acquire)(ipsec_event_relay_t *this, uint32_t reqid);
+
/**
* Register a listener to events raised by this manager
*