4 * Copyright(c) 2016 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 Intel Corporation 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.
39 #include <rte_byteorder.h>
41 #include <rte_crypto.h>
43 #define RTE_LOGTYPE_IPSEC RTE_LOGTYPE_USER1
44 #define RTE_LOGTYPE_IPSEC_ESP RTE_LOGTYPE_USER2
45 #define RTE_LOGTYPE_IPSEC_IPIP RTE_LOGTYPE_USER3
47 #define MAX_PKT_BURST 32
48 #define MAX_QP_PER_LCORE 256
51 #define IPSEC_ASSERT(exp) \
53 rte_panic("line%d\tassert \"" #exp "\" failed\n", __LINE__); \
56 #define IPSEC_ASSERT(exp) do {} while (0)
57 #endif /* IPSEC_DEBUG */
59 #define MAX_DIGEST_SIZE 32 /* Bytes -- 256 bits */
61 #define uint32_t_to_char(ip, a, b, c, d) do {\
62 *a = (unsigned char)(ip >> 24 & 0xff);\
63 *b = (unsigned char)(ip >> 16 & 0xff);\
64 *c = (unsigned char)(ip >> 8 & 0xff);\
65 *d = (unsigned char)(ip & 0xff);\
68 #define DEFAULT_MAX_CATEGORIES 1
70 #define IPSEC_SA_MAX_ENTRIES (64) /* must be power of 2, max 2 power 30 */
71 #define SPI2IDX(spi) (spi & (IPSEC_SA_MAX_ENTRIES - 1))
72 #define INVALID_SPI (0)
74 #define DISCARD (0x80000000)
75 #define BYPASS (0x40000000)
76 #define PROTECT_MASK (0x3fffffff)
77 #define PROTECT(sa_idx) (SPI2IDX(sa_idx) & PROTECT_MASK) /* SA idx 30 bits */
79 #define IPSEC_XFORM_MAX 2
81 struct rte_crypto_xform;
83 struct rte_cryptodev_session;
88 typedef int (*ipsec_xform_fn)(struct rte_mbuf *m, struct ipsec_sa *sa,
89 struct rte_crypto_op *cop);
96 struct rte_cryptodev_sym_session *crypto_session;
97 struct rte_crypto_sym_xform *xforms;
98 ipsec_xform_fn pre_crypto;
99 ipsec_xform_fn post_crypto;
100 enum rte_crypto_cipher_algorithm cipher_algo;
101 enum rte_crypto_auth_algorithm auth_algo;
107 } __rte_cache_aligned;
109 struct ipsec_mbuf_metadata {
111 struct rte_crypto_op cop;
112 struct rte_crypto_sym_op sym_cop;
120 struct rte_crypto_op *buf[MAX_PKT_BURST] __rte_aligned(sizeof(void *));
124 struct rte_hash *cdev_map;
125 struct sp_ctx *sp_ctx;
126 struct sa_ctx *sa_ctx;
129 struct cdev_qp tbl[MAX_QP_PER_LCORE];
139 struct sa_ctx *sa_ipv4_in;
140 struct sa_ctx *sa_ipv4_out;
141 struct sp_ctx *sp_ipv4_in;
142 struct sp_ctx *sp_ipv4_out;
143 struct rt_ctx *rt_ipv4;
144 struct rte_mempool *mbuf_pool;
148 ipsec_inbound(struct ipsec_ctx *ctx, struct rte_mbuf *pkts[],
149 uint16_t nb_pkts, uint16_t len);
152 ipsec_outbound(struct ipsec_ctx *ctx, struct rte_mbuf *pkts[],
153 uint32_t sa_idx[], uint16_t nb_pkts, uint16_t len);
155 static inline uint16_t
156 ipsec_metadata_size(void)
158 return sizeof(struct ipsec_mbuf_metadata);
161 static inline struct ipsec_mbuf_metadata *
162 get_priv(struct rte_mbuf *m)
164 return RTE_PTR_ADD(m, sizeof(struct rte_mbuf));
168 inbound_sa_check(struct sa_ctx *sa_ctx, struct rte_mbuf *m, uint32_t sa_idx);
171 inbound_sa_lookup(struct sa_ctx *sa_ctx, struct rte_mbuf *pkts[],
172 struct ipsec_sa *sa[], uint16_t nb_pkts);
175 outbound_sa_lookup(struct sa_ctx *sa_ctx, uint32_t sa_idx[],
176 struct ipsec_sa *sa[], uint16_t nb_pkts);
179 sp_init(struct socket_ctx *ctx, int socket_id, unsigned ep);
182 sa_init(struct socket_ctx *ctx, int socket_id, unsigned ep);
185 rt_init(struct socket_ctx *ctx, int socket_id, unsigned ep);
187 #endif /* __IPSEC_H__ */