summaryrefslogtreecommitdiff
path: root/lib/librte_ipsec/ses.c
blob: 11580970eadefaf8dfa7660cb000e88d20f6823c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright(c) 2018 Intel Corporation
 */

#include <rte_ipsec.h>
#include "sa.h"

static int
session_check(struct rte_ipsec_session *ss)
{
	if (ss == NULL || ss->sa == NULL)
		return -EINVAL;

	if (ss->type == RTE_SECURITY_ACTION_TYPE_NONE) {
		if (ss->crypto.ses == NULL)
			return -EINVAL;
	} else {
		if (ss->security.ses == NULL)
			return -EINVAL;
		if ((ss->type == RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO ||
				ss->type ==
				RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL) &&
				ss->security.ctx == NULL)
			return -EINVAL;
	}

	return 0;
}

int __rte_experimental
rte_ipsec_session_prepare(struct rte_ipsec_session *ss)
{
	int32_t rc;
	struct rte_ipsec_sa_pkt_func fp;

	rc = session_check(ss);
	if (rc != 0)
		return rc;

	rc = ipsec_sa_pkt_func_select(ss, ss->sa, &fp);
	if (rc != 0)
		return rc;

	ss->pkt_func = fp;

	if (ss->type == RTE_SECURITY_ACTION_TYPE_NONE)
		ss->crypto.ses->opaque_data = (uintptr_t)ss;
	else
		ss->security.ses->opaque_data = (uintptr_t)ss;

	return 0;
}