#include <hydra.h>
#include <utils/debug.h>
+#include <threading/mutex.h>
typedef struct private_kernel_utun_ipsec_t private_kernel_utun_ipsec_t;
* Public part of the kernel_utun_t object
*/
kernel_utun_ipsec_t public;
+
+ /**
+ * Mutex to access shared objects
+ */
+ mutex_t *mutex;
+
+ /**
+ * Next SPI to allocate
+ */
+ u_int32_t spi;
};
METHOD(kernel_ipsec_t, get_features, kernel_feature_t,
private_kernel_utun_ipsec_t *this, host_t *src, host_t *dst,
u_int8_t protocol, u_int32_t reqid, u_int32_t *spi)
{
- return FAILED;
+ this->mutex->lock(this->mutex);
+ *spi = this->spi++;
+ this->mutex->unlock(this->mutex);
+
+ return SUCCESS;
}
METHOD(kernel_ipsec_t, get_cpi, status_t,
METHOD(kernel_ipsec_t, destroy, void,
private_kernel_utun_ipsec_t *this)
{
+ this->mutex->destroy(this->mutex);
free(this);
}
.destroy = _destroy,
},
},
+ .mutex = mutex_create(MUTEX_TYPE_DEFAULT),
+ /* initialize to "charon-style" SPIs with a leading "c" */
+ .spi = 0xc0000000,
);
return &this->public;
-}
\ No newline at end of file
+}