event/octeontx2: support xstats
[dpdk.git] / lib / librte_ipsec / ses.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Intel Corporation
3  */
4
5 #include <rte_ipsec.h>
6 #include "sa.h"
7
8 static int
9 session_check(struct rte_ipsec_session *ss)
10 {
11         if (ss == NULL || ss->sa == NULL)
12                 return -EINVAL;
13
14         if (ss->type == RTE_SECURITY_ACTION_TYPE_NONE) {
15                 if (ss->crypto.ses == NULL)
16                         return -EINVAL;
17         } else {
18                 if (ss->security.ses == NULL)
19                         return -EINVAL;
20                 if ((ss->type == RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO ||
21                                 ss->type ==
22                                 RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL) &&
23                                 ss->security.ctx == NULL)
24                         return -EINVAL;
25         }
26
27         return 0;
28 }
29
30 int
31 rte_ipsec_session_prepare(struct rte_ipsec_session *ss)
32 {
33         int32_t rc;
34         struct rte_ipsec_sa_pkt_func fp;
35
36         rc = session_check(ss);
37         if (rc != 0)
38                 return rc;
39
40         rc = ipsec_sa_pkt_func_select(ss, ss->sa, &fp);
41         if (rc != 0)
42                 return rc;
43
44         ss->pkt_func = fp;
45
46         if (ss->type == RTE_SECURITY_ACTION_TYPE_NONE)
47                 ss->crypto.ses->opaque_data = (uintptr_t)ss;
48         else
49                 ss->security.ses->opaque_data = (uintptr_t)ss;
50
51         return 0;
52 }