charon-tkm: Make CHILD/ESP SA database public

Make the CHILD/ESP SA database a public member of the global tkm_t
struct.
This commit is contained in:
Reto Buerki
2015-02-20 13:34:53 +01:00
committed by Martin Willi
parent e63cbb367c
commit fa4f66cba3
3 changed files with 15 additions and 22 deletions
+3 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2012 Reto Buerki * Copyright (C) 2012-2014 Reto Buerki
* Copyright (C) 2012 Adrian-Ken Rueegsegger * Copyright (C) 2012 Adrian-Ken Rueegsegger
* Hochschule fuer Technik Rapperswil * Hochschule fuer Technik Rapperswil
* *
@@ -95,6 +95,7 @@ bool tkm_init()
.public = { .public = {
.idmgr = tkm_id_manager_create(limits), .idmgr = tkm_id_manager_create(limits),
.chunk_map = tkm_chunk_map_create(), .chunk_map = tkm_chunk_map_create(),
.sad = tkm_kernel_sad_create(),
}, },
); );
tkm = &this->public; tkm = &this->public;
@@ -114,6 +115,7 @@ void tkm_deinit()
private_tkm_t *this = (private_tkm_t*)tkm; private_tkm_t *this = (private_tkm_t*)tkm;
this->public.idmgr->destroy(this->public.idmgr); this->public.idmgr->destroy(this->public.idmgr);
this->public.chunk_map->destroy(this->public.chunk_map); this->public.chunk_map->destroy(this->public.chunk_map);
this->public.sad->destroy(this->public.sad);
ees_server_finalize(); ees_server_finalize();
+7 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2012 Reto Buerki * Copyright (C) 2012-2014 Reto Buerki
* Copyright (C) 2012 Adrian-Ken Rueegsegger * Copyright (C) 2012 Adrian-Ken Rueegsegger
* Hochschule fuer Technik Rapperswil * Hochschule fuer Technik Rapperswil
* *
@@ -72,6 +72,7 @@
#include "tkm_id_manager.h" #include "tkm_id_manager.h"
#include "tkm_chunk_map.h" #include "tkm_chunk_map.h"
#include "tkm_kernel_sad.h"
typedef struct tkm_t tkm_t; typedef struct tkm_t tkm_t;
@@ -90,6 +91,11 @@ struct tkm_t {
*/ */
tkm_chunk_map_t *chunk_map; tkm_chunk_map_t *chunk_map;
/**
* CHILD/ESP SA database.
*/
tkm_kernel_sad_t *sad;
}; };
/** /**
+5 -20
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2012 Reto Buerki * Copyright (C) 2012-2014 Reto Buerki
* Copyright (C) 2012 Adrian-Ken Rueegsegger * Copyright (C) 2012 Adrian-Ken Rueegsegger
* Hochschule fuer Technik Rapperswil * Hochschule fuer Technik Rapperswil
* *
@@ -26,7 +26,6 @@
#include "tkm_utils.h" #include "tkm_utils.h"
#include "tkm_types.h" #include "tkm_types.h"
#include "tkm_keymat.h" #include "tkm_keymat.h"
#include "tkm_kernel_sad.h"
#include "tkm_kernel_ipsec.h" #include "tkm_kernel_ipsec.h"
/** From linux/in.h */ /** From linux/in.h */
@@ -51,11 +50,6 @@ struct private_tkm_kernel_ipsec_t {
*/ */
rng_t *rng; rng_t *rng;
/**
* CHILD/ESP SA database.
*/
tkm_kernel_sad_t *sad;
}; };
METHOD(kernel_ipsec_t, get_spi, status_t, METHOD(kernel_ipsec_t, get_spi, status_t,
@@ -142,7 +136,7 @@ METHOD(kernel_ipsec_t, add_sa, status_t,
} }
esa_id = tkm->idmgr->acquire_id(tkm->idmgr, TKM_CTX_ESA); esa_id = tkm->idmgr->acquire_id(tkm->idmgr, TKM_CTX_ESA);
if (!this->sad->insert(this->sad, esa_id, peer, local, spi_loc, protocol)) if (!tkm->sad->insert(tkm->sad, esa_id, peer, local, spi_loc, protocol))
{ {
DBG1(DBG_KNL, "unable to add entry (%llu) to SAD", esa_id); DBG1(DBG_KNL, "unable to add entry (%llu) to SAD", esa_id);
goto sad_failure; goto sad_failure;
@@ -206,7 +200,7 @@ METHOD(kernel_ipsec_t, add_sa, status_t,
return SUCCESS; return SUCCESS;
failure: failure:
this->sad->remove(this->sad, esa_id); tkm->sad->remove(tkm->sad, esa_id);
sad_failure: sad_failure:
tkm->idmgr->release_id(tkm->idmgr, TKM_CTX_ESA, esa_id); tkm->idmgr->release_id(tkm->idmgr, TKM_CTX_ESA, esa_id);
chunk_free(&esa.nonce_i); chunk_free(&esa.nonce_i);
@@ -228,7 +222,7 @@ METHOD(kernel_ipsec_t, del_sa, status_t,
{ {
esa_id_type esa_id; esa_id_type esa_id;
esa_id = this->sad->get_esa_id(this->sad, src, dst, spi, protocol); esa_id = tkm->sad->get_esa_id(tkm->sad, src, dst, spi, protocol);
if (esa_id) if (esa_id)
{ {
DBG1(DBG_KNL, "deleting child SA (esa: %llu, spi: %x)", esa_id, DBG1(DBG_KNL, "deleting child SA (esa: %llu, spi: %x)", esa_id,
@@ -238,7 +232,7 @@ METHOD(kernel_ipsec_t, del_sa, status_t,
DBG1(DBG_KNL, "child SA (%llu) deletion failed", esa_id); DBG1(DBG_KNL, "child SA (%llu) deletion failed", esa_id);
return FAILED; return FAILED;
} }
this->sad->remove(this->sad, esa_id); tkm->sad->remove(tkm->sad, esa_id);
tkm->idmgr->release_id(tkm->idmgr, TKM_CTX_ESA, esa_id); tkm->idmgr->release_id(tkm->idmgr, TKM_CTX_ESA, esa_id);
} }
return SUCCESS; return SUCCESS;
@@ -349,7 +343,6 @@ METHOD(kernel_ipsec_t, destroy, void,
private_tkm_kernel_ipsec_t *this) private_tkm_kernel_ipsec_t *this)
{ {
DESTROY_IF(this->rng); DESTROY_IF(this->rng);
DESTROY_IF(this->sad);
free(this); free(this);
} }
@@ -379,15 +372,7 @@ tkm_kernel_ipsec_t *tkm_kernel_ipsec_create()
.destroy = _destroy, .destroy = _destroy,
}, },
}, },
.sad = tkm_kernel_sad_create(),
); );
if (!this->sad)
{
DBG1(DBG_KNL, "unable to create SAD");
destroy(this);
return NULL;
}
return &this->public; return &this->public;
} }