File: ses.c

package info (click to toggle)
dpdk 25.11-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 127,892 kB
  • sloc: ansic: 2,358,479; python: 16,426; sh: 4,474; makefile: 1,713; awk: 70
file content (56 lines) | stat: -rw-r--r-- 1,197 bytes parent folder | download
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
53
54
55
56
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright(c) 2018-2020 Intel Corporation
 */

#include <eal_export.h>
#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 ||
		ss->type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
		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;
}

RTE_EXPORT_SYMBOL(rte_ipsec_session_prepare)
int
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)
		rte_cryptodev_sym_session_opaque_data_set(ss->crypto.ses,
			(uintptr_t)ss);
	else
		rte_security_session_opaque_data_set(ss->security.ses, (uintptr_t)ss);

	return 0;
}