net/ixgbe/base: fix infinite recursion on PCIe link down
[dpdk.git] / lib / librte_ipsec / ses.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018-2020 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                 ss->type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
16                 if (ss->crypto.ses == NULL)
17                         return -EINVAL;
18         } else {
19                 if (ss->security.ses == NULL)
20                         return -EINVAL;
21                 if ((ss->type == RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO ||
22                                 ss->type ==
23                                 RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL) &&
24                                 ss->security.ctx == NULL)
25                         return -EINVAL;
26         }
27
28         return 0;
29 }
30
31 int
32 rte_ipsec_session_prepare(struct rte_ipsec_session *ss)
33 {
34         int32_t rc;
35         struct rte_ipsec_sa_pkt_func fp;
36
37         rc = session_check(ss);
38         if (rc != 0)
39                 return rc;
40
41         rc = ipsec_sa_pkt_func_select(ss, ss->sa, &fp);
42         if (rc != 0)
43                 return rc;
44
45         ss->pkt_func = fp;
46
47         if (ss->type == RTE_SECURITY_ACTION_TYPE_NONE)
48                 ss->crypto.ses->opaque_data = (uintptr_t)ss;
49         else
50                 ss->security.ses->opaque_data = (uintptr_t)ss;
51
52         return 0;
53 }