1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018-2020 Intel Corporation
13 * librte_ipsec provides a framework for data-path IPsec protocol
14 * processing (ESP/AH).
17 #include <rte_ipsec_sa.h>
24 struct rte_ipsec_session;
27 * IPsec session specific functions that will be used to:
28 * - prepare - for input mbufs and given IPsec session prepare crypto ops
29 * that can be enqueued into the cryptodev associated with given session
30 * (see *rte_ipsec_pkt_crypto_prepare* below for more details).
31 * - process - finalize processing of packets after crypto-dev finished
32 * with them or process packets that are subjects to inline IPsec offload
33 * (see rte_ipsec_pkt_process for more details).
35 struct rte_ipsec_sa_pkt_func {
37 uint16_t (*async)(const struct rte_ipsec_session *ss,
38 struct rte_mbuf *mb[],
39 struct rte_crypto_op *cop[],
41 uint16_t (*sync)(const struct rte_ipsec_session *ss,
42 struct rte_mbuf *mb[],
45 uint16_t (*process)(const struct rte_ipsec_session *ss,
46 struct rte_mbuf *mb[],
51 * rte_ipsec_session is an aggregate structure that defines particular
52 * IPsec Security Association IPsec (SA) on given security/crypto device:
53 * - pointer to the SA object
54 * - security session action type
55 * - pointer to security/crypto session, plus other related data
56 * - session/device specific functions to prepare/process IPsec packets.
58 struct rte_ipsec_session {
60 * SA that session belongs to.
61 * Note that multiple sessions can belong to the same SA.
63 struct rte_ipsec_sa *sa;
64 /** session action type */
65 enum rte_security_session_action_type type;
66 /** session and related data */
69 struct rte_cryptodev_sym_session *ses;
73 struct rte_security_session *ses;
74 struct rte_security_ctx *ctx;
78 /** functions to prepare/process IPsec packets */
79 struct rte_ipsec_sa_pkt_func pkt_func;
80 } __rte_cache_aligned;
83 * Checks that inside given rte_ipsec_session crypto/security fields
84 * are filled correctly and setups function pointers based on these values.
85 * Expects that all fields except IPsec processing function pointers
86 * (*pkt_func*) will be filled correctly by caller.
88 * Pointer to the *rte_ipsec_session* object
90 * - Zero if operation completed successfully.
91 * - -EINVAL if the parameters are invalid.
94 rte_ipsec_session_prepare(struct rte_ipsec_session *ss);
97 * For input mbufs and given IPsec session prepare crypto ops that can be
98 * enqueued into the cryptodev associated with given session.
99 * expects that for each input packet:
100 * - l2_len, l3_len are setup correctly
101 * Note that erroneous mbufs are not freed by the function,
102 * but are placed beyond last valid mbuf in the *mb* array.
103 * It is a user responsibility to handle them further.
105 * Pointer to the *rte_ipsec_session* object the packets belong to.
107 * The address of an array of *num* pointers to *rte_mbuf* structures
108 * which contain the input packets.
110 * The address of an array of *num* pointers to the output *rte_crypto_op*
113 * The maximum number of packets to process.
115 * Number of successfully processed packets, with error code set in rte_errno.
117 static inline uint16_t
118 rte_ipsec_pkt_crypto_prepare(const struct rte_ipsec_session *ss,
119 struct rte_mbuf *mb[], struct rte_crypto_op *cop[], uint16_t num)
121 return ss->pkt_func.prepare.async(ss, mb, cop, num);
124 static inline uint16_t
125 rte_ipsec_pkt_cpu_prepare(const struct rte_ipsec_session *ss,
126 struct rte_mbuf *mb[], uint16_t num)
128 return ss->pkt_func.prepare.sync(ss, mb, num);
132 * Finalise processing of packets after crypto-dev finished with them or
133 * process packets that are subjects to inline IPsec offload.
134 * Expects that for each input packet:
135 * - l2_len, l3_len are setup correctly
136 * Output mbufs will be:
137 * inbound - decrypted & authenticated, ESP(AH) related headers removed,
138 * *l2_len* and *l3_len* fields are updated.
139 * outbound - appropriate mbuf fields (ol_flags, tx_offloads, etc.)
140 * properly setup, if necessary - IP headers updated, ESP(AH) fields added,
141 * Note that erroneous mbufs are not freed by the function,
142 * but are placed beyond last valid mbuf in the *mb* array.
143 * It is a user responsibility to handle them further.
145 * Pointer to the *rte_ipsec_session* object the packets belong to.
147 * The address of an array of *num* pointers to *rte_mbuf* structures
148 * which contain the input packets.
150 * The maximum number of packets to process.
152 * Number of successfully processed packets, with error code set in rte_errno.
154 static inline uint16_t
155 rte_ipsec_pkt_process(const struct rte_ipsec_session *ss, struct rte_mbuf *mb[],
158 return ss->pkt_func.process(ss, mb, num);
161 #include <rte_ipsec_group.h>
167 #endif /* _RTE_IPSEC_H_ */