ba646219240e3fea9562805edf2efda52645667e
[strongswan.git] / src / charon-tkm / src / tkm / tkm_kernel_sad.h
1 /*
2 * Copyright (C) 2012-2014 Reto Buerki
3 * Copyright (C) 2012 Adrian-Ken Rueegsegger
4 * Hochschule fuer Technik Rapperswil
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 */
16
17 /**
18 * @defgroup tkm-kernel-sad kernel sad
19 * @{ @ingroup tkm
20 */
21
22 #ifndef TKM_KERNEL_SAD_H_
23 #define TKM_KERNEL_SAD_H_
24
25 #include <networking/host.h>
26 #include <tkm/types.h>
27
28 typedef struct tkm_kernel_sad_t tkm_kernel_sad_t;
29
30 /**
31 * The TKM kernel SAD (security association database) stores information about
32 * CHILD SAs.
33 */
34 struct tkm_kernel_sad_t {
35
36 /**
37 * Insert new SAD entry with specified parameters.
38 *
39 * @param esa_id ESP SA context identifier
40 * @param reqid reqid of the SA
41 * @param src source address of CHILD SA
42 * @param dst destination address of CHILD SA
43 * @param spi_loc Local SPI of CHILD SA
44 * @param spi_rem Remote SPI of CHILD SA
45 * @param proto protocol of CHILD SA (ESP/AH)
46 * @return TRUE if entry was inserted, FALSE otherwise
47 */
48 bool (*insert)(tkm_kernel_sad_t * const this, const esa_id_type esa_id,
49 const uint32_t reqid, const host_t * const src,
50 const host_t * const dst, const uint32_t spi_loc,
51 const uint32_t spi_rem, const uint8_t proto);
52
53 /**
54 * Get ESA id for entry with given parameters.
55 *
56 * @param src source address of CHILD SA
57 * @param dst destination address of CHILD SA
58 * @param spi Remote SPI of CHILD SA
59 * @param proto protocol of CHILD SA (ESP/AH)
60 * @return ESA id of entry if found, 0 otherwise
61 */
62 esa_id_type (*get_esa_id)(tkm_kernel_sad_t * const this,
63 const host_t * const src, const host_t * const dst,
64 const uint32_t spi, const uint8_t proto);
65
66 /**
67 * Get ESA id for entry associated with same security policy as the
68 * specified ESA.
69 *
70 * @param esa_id id of ESA identifying the security policy
71 * @return ESA id of entry if found, 0 otherwise
72 */
73 esa_id_type (*get_other_esa_id)(tkm_kernel_sad_t * const this,
74 const esa_id_type esa_id);
75
76 /**
77 * Get destination host for entry with given parameters.
78 *
79 * @param reqid reqid of CHILD SA
80 * @param spi Remote SPI of CHILD SA
81 * @param proto protocol of CHILD SA (ESP/AH)
82 * @return destination host of entry if found, NULL otherwise
83 */
84 host_t * (*get_dst_host)(tkm_kernel_sad_t * const this,
85 const uint32_t reqid, const uint32_t spi, const uint8_t proto);
86
87 /**
88 * Remove entry with given ESA id from SAD.
89 *
90 * @param esa_id ESA identifier of entry to remove
91 * @return TRUE if entry was removed, FALSE otherwise
92 */
93 bool (*remove)(tkm_kernel_sad_t * const this, const esa_id_type esa_id);
94
95 /**
96 * Destroy a tkm_kernel_sad instance.
97 */
98 void (*destroy)(tkm_kernel_sad_t *this);
99
100 };
101
102 /**
103 * Create a TKM kernel SAD instance.
104 */
105 tkm_kernel_sad_t *tkm_kernel_sad_create();
106
107 #endif /** TKM_KERNEL_SAD_H_ @}*/