1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright(c) 2017 Intel Corporation.
6 #include <rte_malloc.h>
8 #include "rte_compat.h"
9 #include "rte_security.h"
10 #include "rte_security_driver.h"
12 struct rte_security_session *
13 rte_security_session_create(struct rte_security_ctx *instance,
14 struct rte_security_session_conf *conf,
15 struct rte_mempool *mp)
17 struct rte_security_session *sess = NULL;
22 RTE_FUNC_PTR_OR_ERR_RET(*instance->ops->session_create, NULL);
24 if (rte_mempool_get(mp, (void **)&sess))
27 if (instance->ops->session_create(instance->device, conf, sess, mp)) {
28 rte_mempool_put(mp, (void *)sess);
36 int __rte_experimental
37 rte_security_session_update(struct rte_security_ctx *instance,
38 struct rte_security_session *sess,
39 struct rte_security_session_conf *conf)
41 RTE_FUNC_PTR_OR_ERR_RET(*instance->ops->session_update, -ENOTSUP);
42 return instance->ops->session_update(instance->device, sess, conf);
46 rte_security_session_get_size(struct rte_security_ctx *instance)
48 RTE_FUNC_PTR_OR_ERR_RET(*instance->ops->session_get_size, 0);
49 return instance->ops->session_get_size(instance->device);
52 int __rte_experimental
53 rte_security_session_stats_get(struct rte_security_ctx *instance,
54 struct rte_security_session *sess,
55 struct rte_security_stats *stats)
57 RTE_FUNC_PTR_OR_ERR_RET(*instance->ops->session_stats_get, -ENOTSUP);
58 return instance->ops->session_stats_get(instance->device, sess, stats);
62 rte_security_session_destroy(struct rte_security_ctx *instance,
63 struct rte_security_session *sess)
67 RTE_FUNC_PTR_OR_ERR_RET(*instance->ops->session_destroy, -ENOTSUP);
69 if (instance->sess_cnt)
72 ret = instance->ops->session_destroy(instance->device, sess);
74 rte_mempool_put(rte_mempool_from_obj(sess), (void *)sess);
80 rte_security_set_pkt_metadata(struct rte_security_ctx *instance,
81 struct rte_security_session *sess,
82 struct rte_mbuf *m, void *params)
84 RTE_FUNC_PTR_OR_ERR_RET(*instance->ops->set_pkt_metadata, -ENOTSUP);
85 return instance->ops->set_pkt_metadata(instance->device,
89 void * __rte_experimental
90 rte_security_get_userdata(struct rte_security_ctx *instance, uint64_t md)
92 void *userdata = NULL;
94 RTE_FUNC_PTR_OR_ERR_RET(*instance->ops->get_userdata, NULL);
95 if (instance->ops->get_userdata(instance->device, md, &userdata))
101 const struct rte_security_capability *
102 rte_security_capabilities_get(struct rte_security_ctx *instance)
104 RTE_FUNC_PTR_OR_ERR_RET(*instance->ops->capabilities_get, NULL);
105 return instance->ops->capabilities_get(instance->device);
108 const struct rte_security_capability *
109 rte_security_capability_get(struct rte_security_ctx *instance,
110 struct rte_security_capability_idx *idx)
112 const struct rte_security_capability *capabilities;
113 const struct rte_security_capability *capability;
116 RTE_FUNC_PTR_OR_ERR_RET(*instance->ops->capabilities_get, NULL);
117 capabilities = instance->ops->capabilities_get(instance->device);
119 if (capabilities == NULL)
122 while ((capability = &capabilities[i++])->action
123 != RTE_SECURITY_ACTION_TYPE_NONE) {
124 if (capability->action == idx->action &&
125 capability->protocol == idx->protocol) {
126 if (idx->protocol == RTE_SECURITY_PROTOCOL_IPSEC) {
127 if (capability->ipsec.proto ==
129 capability->ipsec.mode ==
131 capability->ipsec.direction ==
132 idx->ipsec.direction)
134 } else if (idx->protocol == RTE_SECURITY_PROTOCOL_PDCP) {
135 if (capability->pdcp.domain ==