5 * Copyright(c) 2017 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of NXP nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <rte_malloc.h>
37 #include "rte_security.h"
38 #include "rte_security_driver.h"
40 struct rte_security_session *
41 rte_security_session_create(struct rte_security_ctx *instance,
42 struct rte_security_session_conf *conf,
43 struct rte_mempool *mp)
45 struct rte_security_session *sess = NULL;
50 RTE_FUNC_PTR_OR_ERR_RET(*instance->ops->session_create, NULL);
52 if (rte_mempool_get(mp, (void *)&sess))
55 if (instance->ops->session_create(instance->device, conf, sess, mp)) {
56 rte_mempool_put(mp, (void *)sess);
65 rte_security_session_update(struct rte_security_ctx *instance,
66 struct rte_security_session *sess,
67 struct rte_security_session_conf *conf)
69 RTE_FUNC_PTR_OR_ERR_RET(*instance->ops->session_update, -ENOTSUP);
70 return instance->ops->session_update(instance->device, sess, conf);
74 rte_security_session_stats_get(struct rte_security_ctx *instance,
75 struct rte_security_session *sess,
76 struct rte_security_stats *stats)
78 RTE_FUNC_PTR_OR_ERR_RET(*instance->ops->session_stats_get, -ENOTSUP);
79 return instance->ops->session_stats_get(instance->device, sess, stats);
83 rte_security_session_destroy(struct rte_security_ctx *instance,
84 struct rte_security_session *sess)
87 struct rte_mempool *mp = rte_mempool_from_obj(sess);
89 RTE_FUNC_PTR_OR_ERR_RET(*instance->ops->session_destroy, -ENOTSUP);
91 if (instance->sess_cnt)
94 ret = instance->ops->session_destroy(instance->device, sess);
96 rte_mempool_put(mp, (void *)sess);
102 rte_security_set_pkt_metadata(struct rte_security_ctx *instance,
103 struct rte_security_session *sess,
104 struct rte_mbuf *m, void *params)
106 RTE_FUNC_PTR_OR_ERR_RET(*instance->ops->set_pkt_metadata, -ENOTSUP);
107 return instance->ops->set_pkt_metadata(instance->device,
111 const struct rte_security_capability *
112 rte_security_capabilities_get(struct rte_security_ctx *instance)
114 RTE_FUNC_PTR_OR_ERR_RET(*instance->ops->capabilities_get, NULL);
115 return instance->ops->capabilities_get(instance->device);
118 const struct rte_security_capability *
119 rte_security_capability_get(struct rte_security_ctx *instance,
120 struct rte_security_capability_idx *idx)
122 const struct rte_security_capability *capabilities;
123 const struct rte_security_capability *capability;
126 RTE_FUNC_PTR_OR_ERR_RET(*instance->ops->capabilities_get, NULL);
127 capabilities = instance->ops->capabilities_get(instance->device);
129 if (capabilities == NULL)
132 while ((capability = &capabilities[i++])->action
133 != RTE_SECURITY_ACTION_TYPE_NONE) {
134 if (capability->action == idx->action &&
135 capability->protocol == idx->protocol) {
136 if (idx->protocol == RTE_SECURITY_PROTOCOL_IPSEC) {
137 if (capability->ipsec.proto ==
139 capability->ipsec.mode ==
141 capability->ipsec.direction ==
142 idx->ipsec.direction)