11 #include <odp/helper/odph_api.h>
13 #include <odp_ipsec_cache.h>
16 ipsec_cache_t *ipsec_cache;
18 void init_ipsec_cache(
void)
24 sizeof(ipsec_cache_t),
29 ODPH_ERR(
"Error: shared mem reserve failed.\n");
35 if (ipsec_cache == NULL) {
36 ODPH_ERR(
"Error: shared mem alloc failed.\n");
39 memset(ipsec_cache, 0,
sizeof(*ipsec_cache));
41 for (i = 0; i < MAX_DB; i++)
45 int create_ipsec_cache_entry(sa_db_entry_t *cipher_sa,
46 sa_db_entry_t *auth_sa,
52 ipsec_cache_entry_t *entry;
54 uint32_t tun_src_ip, tun_dst_ip;
55 sa_mode_t mode = IPSEC_SA_MODE_TRANSPORT;
58 entry = &ipsec_cache->array[ipsec_cache->index];
59 if (MAX_DB <= ipsec_cache->index)
77 param.
spi = cipher_sa->spi;
87 param.
spi = auth_sa->spi;
96 param.
outbound.tunnel.ipv4.src_addr = &tun_src_ip;
97 param.
outbound.tunnel.ipv4.dst_addr = &tun_dst_ip;
102 ODPH_ERR(
"Error: SA creation failed\n");
108 entry->src_ip = cipher_sa->src_ip;
109 entry->dst_ip = cipher_sa->dst_ip;
110 entry->esp.alg = cipher_sa->alg.u.cipher;
111 entry->esp.spi = cipher_sa->spi;
112 entry->esp.block_len = cipher_sa->block_len;
113 entry->esp.iv_len = cipher_sa->iv_len;
114 memcpy(&entry->esp.key, &cipher_sa->key,
sizeof(ipsec_key_t));
117 entry->src_ip = auth_sa->src_ip;
118 entry->dst_ip = auth_sa->dst_ip;
119 entry->ah.alg = auth_sa->alg.u.auth;
120 entry->ah.spi = auth_sa->spi;
121 entry->ah.icv_len = auth_sa->icv_len;
122 memcpy(&entry->ah.key, &auth_sa->key,
sizeof(ipsec_key_t));
126 entry->tun_src_ip = tun->tun_src_ip;
127 entry->tun_dst_ip = tun->tun_dst_ip;
128 mode = IPSEC_SA_MODE_TUNNEL;
133 ipsec_cache->index++;
135 entry->next = ipsec_cache->in_list;
136 ipsec_cache->in_list = entry;
138 entry->next = ipsec_cache->out_list;
139 ipsec_cache->out_list = entry;
142 entry->ipsec_sa = ipsec_sa;
147 ipsec_cache_entry_t *find_ipsec_cache_entry_in(uint32_t src_ip,
152 ipsec_cache_entry_t *entry = ipsec_cache->in_list;
155 for (; NULL != entry; entry = entry->next) {
156 if ((entry->src_ip != src_ip) || (entry->dst_ip != dst_ip))
157 if ((entry->tun_src_ip != src_ip) ||
158 (entry->tun_dst_ip != dst_ip))
165 ((!entry->esp.alg) ||
174 ipsec_cache_entry_t *find_ipsec_cache_entry_out(uint32_t src_ip,
178 ipsec_cache_entry_t *entry = ipsec_cache->out_list;
181 for (; NULL != entry; entry = entry->next) {
182 if ((entry->src_ip == src_ip) && (entry->dst_ip == dst_ip))
188 int destroy_ipsec_cache(
void)
190 ipsec_cache_entry_t *entry;
194 for (i = 0; i < MAX_DB; i++) {
195 entry = &ipsec_cache->array[i];
#define ODP_UNUSED
Intentionally unused variables of functions.
odp_u32be_t odp_cpu_to_be_32(uint32_t cpu32)
Convert cpu native uint32_t to 32bit big endian.
uint32_t odp_be_to_cpu_32(odp_u32be_t be32)
Convert 32bit big endian to cpu native uint32_t.
@ ODP_CIPHER_ALG_NULL
No cipher algorithm specified.
@ ODP_AUTH_ALG_NULL
No authentication algorithm specified.
void odp_ipsec_sa_param_init(odp_ipsec_sa_param_t *param)
Initialize IPSEC SA parameters.
int odp_ipsec_sa_disable(odp_ipsec_sa_t sa)
Disable IPSEC SA.
#define ODP_IPSEC_SA_INVALID
Invalid IPSEC SA.
odp_ipsec_sa_t odp_ipsec_sa_create(const odp_ipsec_sa_param_t *param)
Create IPSEC SA.
int odp_ipsec_sa_destroy(odp_ipsec_sa_t sa)
Destroy IPSEC SA.
@ ODP_IPSEC_LOOKUP_SPI
Inbound SA lookup is enabled.
@ ODP_IPSEC_LOOKUP_DISABLED
Inbound SA lookup is disabled for the SA.
@ ODP_IPSEC_AH
AH protocol.
@ ODP_IPSEC_ESP
ESP protocol.
@ ODP_IPSEC_TUNNEL_IPV4
Outer header is IPv4.
@ ODP_IPSEC_MODE_TRANSPORT
IPSEC transport mode.
@ ODP_IPSEC_MODE_TUNNEL
IPSEC tunnel mode.
@ ODP_IPSEC_DIR_OUTBOUND
Outbound IPSEC SA.
@ ODP_IPSEC_DIR_INBOUND
Inbound IPSEC SA.
#define ODP_SHM_INVALID
Invalid shared memory block.
void * odp_shm_addr(odp_shm_t shm)
Shared memory block address.
odp_shm_t odp_shm_reserve(const char *name, uint64_t size, uint64_t align, uint32_t flags)
Reserve a contiguous block of shared memory.
bool odp_bool_t
Boolean type.
uint32_t length
Key length in bytes.
odp_crypto_key_t auth_key
Authentication key.
odp_auth_alg_t auth_alg
Authentication algorithm.
odp_cipher_alg_t cipher_alg
Cipher algorithm.
odp_crypto_key_t cipher_key
Cipher key.
IPSEC Security Association (SA) parameters.
odp_ipsec_crypto_param_t crypto
Parameters for crypto and authentication algorithms.
odp_queue_t dest_queue
Destination queue for IPSEC events.
odp_ipsec_mode_t mode
IPSEC protocol mode: transport or tunnel.
struct odp_ipsec_sa_param_t::@47::@49 inbound
Inbound specific parameters.
odp_ipsec_dir_t dir
IPSEC SA direction: inbound or outbound.
struct odp_ipsec_sa_param_t::@47::@50 outbound
Outbound specific parameters.
odp_ipsec_protocol_t proto
IPSEC protocol: ESP or AH.