charon-nm: Set local address to %any so IPv6 may be used as outer address
[strongswan.git] / src / libipsec / ipsec_event_relay.c
index 3422225..4d33fb7 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (C) 2012 Tobias Brunner
  * Copyright (C) 2012 Giuliano Grassi
  * Copyright (C) 2012 Ralf Sager
- * Hochschule fuer Technik Rapperswil
+ * HSR Hochschule fuer Technik Rapperswil
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
 #include "ipsec_event_relay.h"
 
 #include <library.h>
-#include <debug.h>
+#include <utils/debug.h>
 #include <threading/rwlock.h>
-#include <utils/linked_list.h>
-#include <utils/blocking_queue.h>
+#include <collections/linked_list.h>
+#include <collections/blocking_queue.h>
 #include <processing/jobs/callback_job.h>
 
 typedef struct private_ipsec_event_relay_t private_ipsec_event_relay_t;
@@ -65,14 +65,19 @@ typedef struct {
        } type;
 
        /**
-        * Reqid of the SA, if any
+        * Protocol of the SA
         */
-       u_int32_t reqid;
+       uint8_t protocol;
 
        /**
         * SPI of the SA, if any
         */
-       u_int32_t spi;
+       uint32_t spi;
+
+       /**
+        * SA destination address
+        */
+       host_t *dst;
 
        /**
         * Additional data for specific event types
@@ -80,8 +85,6 @@ typedef struct {
        union {
 
                struct {
-                       /** Protocol of the SA */
-                       u_int8_t protocol;
                        /** TRUE in case of a hard expire */
                        bool hard;
                } expire;
@@ -91,6 +94,15 @@ typedef struct {
 } ipsec_event_t;
 
 /**
+ * Destroy IPsec event data
+ */
+static void ipsec_event_destroy(ipsec_event_t *event)
+{
+       event->dst->destroy(event->dst);
+       free(event);
+}
+
+/**
  * Dequeue events and relay them to listeners
  */
 static job_requeue_t handle_events(private_ipsec_event_relay_t *this)
@@ -110,30 +122,31 @@ static job_requeue_t handle_events(private_ipsec_event_relay_t *this)
                        case IPSEC_EVENT_EXPIRE:
                                if (current->expire)
                                {
-                                       current->expire(event->reqid, event->data.expire.protocol,
-                                                                       event->spi, event->data.expire.hard);
+                                       current->expire(event->protocol, event->spi, event->dst,
+                                                                       event->data.expire.hard);
                                }
                                break;
                }
        }
        enumerator->destroy(enumerator);
        this->lock->unlock(this->lock);
+       ipsec_event_destroy(event);
        return JOB_REQUEUE_DIRECT;
 }
 
 METHOD(ipsec_event_relay_t, expire, void,
-       private_ipsec_event_relay_t *this, u_int32_t reqid, u_int8_t protocol,
-       u_int32_t spi, bool hard)
+       private_ipsec_event_relay_t *this, uint8_t protocol, uint32_t spi,
+       host_t *dst, bool hard)
 {
        ipsec_event_t *event;
 
        INIT(event,
                .type = IPSEC_EVENT_EXPIRE,
-               .reqid = reqid,
+               .protocol = protocol,
                .spi = spi,
+               .dst = dst->clone(dst),
                .data = {
                        .expire = {
-                               .protocol = protocol,
                                .hard = hard,
                        },
                },