1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Intel Corporation
5 #ifndef _RTE_IPSEC_GROUP_H_
6 #define _RTE_IPSEC_GROUP_H_
9 * @file rte_ipsec_group.h
10 * @b EXPERIMENTAL: this API may change without prior notice
13 * It is not recommended to include this file directly,
14 * include <rte_ipsec.h> instead.
15 * Contains helper functions to process completed crypto-ops
16 * and group related packets by sessions they belong to.
25 * Used to group mbufs by some id.
26 * See below for particular usage.
28 struct rte_ipsec_group {
32 } id; /**< grouped by value */
33 struct rte_mbuf **m; /**< start of the group */
34 uint32_t cnt; /**< number of entries in the group */
35 int32_t rc; /**< status code associated with the group */
39 * Take crypto-op as an input and extract pointer to related ipsec session.
41 * The address of an input *rte_crypto_op* structure.
43 * The pointer to the related *rte_ipsec_session* structure.
46 static inline struct rte_ipsec_session *
47 rte_ipsec_ses_from_crypto(const struct rte_crypto_op *cop)
49 const struct rte_security_session *ss;
50 const struct rte_cryptodev_sym_session *cs;
52 if (cop->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
53 ss = cop->sym[0].sec_session;
54 return (void *)(uintptr_t)ss->opaque_data;
55 } else if (cop->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
56 cs = cop->sym[0].session;
57 return (void *)(uintptr_t)cs->opaque_data;
63 * Take as input completed crypto ops, extract related mbufs
64 * and group them by rte_ipsec_session they belong to.
65 * For mbuf which crypto-op wasn't completed successfully
66 * PKT_RX_SEC_OFFLOAD_FAILED will be raised in ol_flags.
67 * Note that mbufs with undetermined SA (session-less) are not freed
68 * by the function, but are placed beyond mbufs for the last valid group.
69 * It is a user responsibility to handle them further.
71 * The address of an array of *num* pointers to the input *rte_crypto_op*
74 * The address of an array of *num* pointers to output *rte_mbuf* structures.
76 * The address of an array of *num* to output *rte_ipsec_group* structures.
78 * The maximum number of crypto-ops to process.
80 * Number of filled elements in *grp* array.
83 static inline uint16_t
84 rte_ipsec_pkt_crypto_group(const struct rte_crypto_op *cop[],
85 struct rte_mbuf *mb[], struct rte_ipsec_group grp[], uint16_t num)
89 struct rte_mbuf *m, *dr[num];
96 for (i = 0; i != num; i++) {
98 m = cop[i]->sym[0].m_src;
99 ns = cop[i]->sym[0].session;
101 m->ol_flags |= PKT_RX_SEC_OFFLOAD;
102 if (cop[i]->status != RTE_CRYPTO_OP_STATUS_SUCCESS)
103 m->ol_flags |= PKT_RX_SEC_OFFLOAD_FAILED;
105 /* no valid session found */
115 * we already have an open group - finalize it,
116 * then open a new one.
120 rte_ipsec_ses_from_crypto(cop[i - 1]);
121 grp[n].cnt = mb + j - grp[n].m;
125 /* start new group */
133 /* finalise last group */
135 grp[n].id.ptr = rte_ipsec_ses_from_crypto(cop[i - 1]);
136 grp[n].cnt = mb + j - grp[n].m;
140 /* copy mbufs with unknown session beyond recognised ones */
141 if (k != 0 && k != num) {
142 for (i = 0; i != k; i++)
153 #endif /* _RTE_IPSEC_GROUP_H_ */