xref: /dpdk/examples/ipsec-secgw/ipsec.h (revision 7f2a987ca852a45bdb4520edc7ad7e02c4efd269)
13998e2a0SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
23998e2a0SBruce Richardson  * Copyright(c) 2016-2017 Intel Corporation
3d299106eSSergio Gonzalez Monroy  */
4d299106eSSergio Gonzalez Monroy 
5d299106eSSergio Gonzalez Monroy #ifndef __IPSEC_H__
6d299106eSSergio Gonzalez Monroy #define __IPSEC_H__
7d299106eSSergio Gonzalez Monroy 
8d299106eSSergio Gonzalez Monroy #include <stdint.h>
9d299106eSSergio Gonzalez Monroy 
10d299106eSSergio Gonzalez Monroy #include <rte_byteorder.h>
11d299106eSSergio Gonzalez Monroy #include <rte_crypto.h>
12dcbf9ad5SNithin Dabilpuram #include <rte_ip_frag.h>
13ec17993aSAkhil Goyal #include <rte_security.h>
14ec17993aSAkhil Goyal #include <rte_flow.h>
155a032a71SKonstantin Ananyev #include <rte_ipsec.h>
16d299106eSSergio Gonzalez Monroy 
176938fc92SVolodymyr Fialko #include "event_helper.h"
184965dda0SLukasz Bartosik #include "ipsec-secgw.h"
194965dda0SLukasz Bartosik 
20d299106eSSergio Gonzalez Monroy #define RTE_LOGTYPE_IPSEC_ESP   RTE_LOGTYPE_USER2
21d299106eSSergio Gonzalez Monroy #define RTE_LOGTYPE_IPSEC_IPIP  RTE_LOGTYPE_USER3
22d299106eSSergio Gonzalez Monroy 
23833e36b8SRadu Nicolau #define MAX_INFLIGHT 128
24d299106eSSergio Gonzalez Monroy #define MAX_QP_PER_LCORE 256
25d299106eSSergio Gonzalez Monroy 
26d299106eSSergio Gonzalez Monroy #define MAX_DIGEST_SIZE 32 /* Bytes -- 256 bits */
27d299106eSSergio Gonzalez Monroy 
280fbd75a9SPablo de Lara #define IV_OFFSET		(sizeof(struct rte_crypto_op) + \
290fbd75a9SPablo de Lara 				sizeof(struct rte_crypto_sym_op))
300fbd75a9SPablo de Lara 
31d299106eSSergio Gonzalez Monroy #define DEFAULT_MAX_CATEGORIES	1
32d299106eSSergio Gonzalez Monroy 
33d299106eSSergio Gonzalez Monroy #define INVALID_SPI (0)
34d299106eSSergio Gonzalez Monroy 
3549757b68SKonstantin Ananyev #define DISCARD	INVALID_SPI
3649757b68SKonstantin Ananyev #define BYPASS	UINT32_MAX
37d299106eSSergio Gonzalez Monroy 
38d299106eSSergio Gonzalez Monroy #define IPSEC_XFORM_MAX 2
39d299106eSSergio Gonzalez Monroy 
40906257e9SSergio Gonzalez Monroy #define IP6_VERSION (6)
41906257e9SSergio Gonzalez Monroy 
42dcbf9ad5SNithin Dabilpuram #define SATP_OUT_IPV4(t)	\
43dcbf9ad5SNithin Dabilpuram 	((((t) & RTE_IPSEC_SATP_MODE_MASK) == RTE_IPSEC_SATP_MODE_TRANS && \
44dcbf9ad5SNithin Dabilpuram 	(((t) & RTE_IPSEC_SATP_IPV_MASK) == RTE_IPSEC_SATP_IPV4)) || \
45dcbf9ad5SNithin Dabilpuram 	((t) & RTE_IPSEC_SATP_MODE_MASK) == RTE_IPSEC_SATP_MODE_TUNLV4)
46dcbf9ad5SNithin Dabilpuram 
47dae3a7afSAmit Prakash Shukla #define BAD_PORT	((uint16_t)-1)
48dae3a7afSAmit Prakash Shukla 
49d299106eSSergio Gonzalez Monroy struct rte_crypto_xform;
50d299106eSSergio Gonzalez Monroy struct ipsec_xform;
51d299106eSSergio Gonzalez Monroy struct rte_mbuf;
52d299106eSSergio Gonzalez Monroy 
53d299106eSSergio Gonzalez Monroy struct ipsec_sa;
548e499dffSVladimir Medvedkin /*
558e499dffSVladimir Medvedkin  * Keeps number of configured SA's for each address family:
568e499dffSVladimir Medvedkin  */
578e499dffSVladimir Medvedkin struct ipsec_sa_cnt {
588e499dffSVladimir Medvedkin 	uint32_t	nb_v4;
598e499dffSVladimir Medvedkin 	uint32_t	nb_v6;
608e499dffSVladimir Medvedkin };
61d299106eSSergio Gonzalez Monroy 
62906257e9SSergio Gonzalez Monroy typedef int32_t (*ipsec_xform_fn)(struct rte_mbuf *m, struct ipsec_sa *sa,
63d299106eSSergio Gonzalez Monroy 		struct rte_crypto_op *cop);
64d299106eSSergio Gonzalez Monroy 
65906257e9SSergio Gonzalez Monroy struct ip_addr {
66906257e9SSergio Gonzalez Monroy 	union {
67906257e9SSergio Gonzalez Monroy 		uint32_t ip4;
689ac91e2fSRobin Jarry 		struct rte_ipv6_addr ip6;
6996362fadSSergio Gonzalez Monroy 	} ip;
70906257e9SSergio Gonzalez Monroy };
71906257e9SSergio Gonzalez Monroy 
729413c390SRadu Nicolau #define MAX_KEY_SIZE		64
735a032a71SKonstantin Ananyev /*
745a032a71SKonstantin Ananyev  * application wide SA parameters
755a032a71SKonstantin Ananyev  */
765a032a71SKonstantin Ananyev struct app_sa_prm {
775a032a71SKonstantin Ananyev 	uint32_t enable; /* use librte_ipsec API for ipsec pkt processing */
785a032a71SKonstantin Ananyev 	uint32_t window_size; /* replay window size */
795a032a71SKonstantin Ananyev 	uint32_t enable_esn;  /* enable/disable ESN support */
802cf67788SVladimir Medvedkin 	uint32_t cache_sz;	/* per lcore SA cache size */
819a1cc8f1STejasree Kondoj 	uint32_t udp_encap;   /* enable/disable UDP Encapsulation */
825a032a71SKonstantin Ananyev 	uint64_t flags;       /* rte_ipsec_sa_prm.flags */
835a032a71SKonstantin Ananyev };
845a032a71SKonstantin Ananyev 
855a032a71SKonstantin Ananyev extern struct app_sa_prm app_sa_prm;
865a032a71SKonstantin Ananyev 
87513f192bSAnkur Dwivedi struct flow_info {
88513f192bSAnkur Dwivedi 	struct rte_flow *rx_def_flow;
89513f192bSAnkur Dwivedi };
90513f192bSAnkur Dwivedi 
91513f192bSAnkur Dwivedi extern struct flow_info flow_info_tbl[RTE_MAX_ETHPORTS];
92513f192bSAnkur Dwivedi 
93ba66534fSMarcin Smoczynski enum {
94ba66534fSMarcin Smoczynski 	IPSEC_SESSION_PRIMARY = 0,
95ba66534fSMarcin Smoczynski 	IPSEC_SESSION_FALLBACK = 1,
96ba66534fSMarcin Smoczynski 	IPSEC_SESSION_MAX
97ba66534fSMarcin Smoczynski };
98ba66534fSMarcin Smoczynski 
99ba66534fSMarcin Smoczynski #define IPSEC_SA_OFFLOAD_FALLBACK_FLAG (1)
100ba66534fSMarcin Smoczynski 
101ba66534fSMarcin Smoczynski static inline struct ipsec_sa *
102ba66534fSMarcin Smoczynski ipsec_mask_saptr(void *ptr)
103ba66534fSMarcin Smoczynski {
104ba66534fSMarcin Smoczynski 	uintptr_t i = (uintptr_t)ptr;
105ba66534fSMarcin Smoczynski 	static const uintptr_t mask = IPSEC_SA_OFFLOAD_FALLBACK_FLAG;
106ba66534fSMarcin Smoczynski 
107ba66534fSMarcin Smoczynski 	i &= ~mask;
108ba66534fSMarcin Smoczynski 
109ba66534fSMarcin Smoczynski 	return (struct ipsec_sa *)i;
110ba66534fSMarcin Smoczynski }
111ba66534fSMarcin Smoczynski 
1127e06c0deSTyler Retzlaff struct __rte_cache_aligned ipsec_sa {
113ba66534fSMarcin Smoczynski 	struct rte_ipsec_session sessions[IPSEC_SESSION_MAX];
114d299106eSSergio Gonzalez Monroy 	uint32_t spi;
115a8ade121SVolodymyr Fialko 	struct cdev_qp *cqp[RTE_MAX_LCORE];
116cef50fc6SSergio Gonzalez Monroy 	uint64_t seq;
1177f9b2c92SVladimir Medvedkin 	rte_be32_t salt;
118ba66534fSMarcin Smoczynski 	uint32_t fallback_sessions;
119d299106eSSergio Gonzalez Monroy 	enum rte_crypto_cipher_algorithm cipher_algo;
120d299106eSSergio Gonzalez Monroy 	enum rte_crypto_auth_algorithm auth_algo;
121501e9c22SPablo de Lara 	enum rte_crypto_aead_algorithm aead_algo;
122d299106eSSergio Gonzalez Monroy 	uint16_t digest_len;
123d299106eSSergio Gonzalez Monroy 	uint16_t iv_len;
124d299106eSSergio Gonzalez Monroy 	uint16_t block_size;
125d299106eSSergio Gonzalez Monroy 	uint16_t flags;
126906257e9SSergio Gonzalez Monroy #define IP4_TUNNEL (1 << 0)
127906257e9SSergio Gonzalez Monroy #define IP6_TUNNEL (1 << 1)
128f159e70bSSergio Gonzalez Monroy #define TRANSPORT  (1 << 2)
129b1a3ac78SMariusz Drost #define IP4_TRANSPORT (1 << 3)
130b1a3ac78SMariusz Drost #define IP6_TRANSPORT (1 << 4)
1313e7b7dd8SRadu Nicolau #define SA_TELEMETRY_ENABLE (1 << 5)
132d8d51d4fSRahul Bhansali #define SA_REASSEMBLY_ENABLE (1 << 6)
1333e7b7dd8SRadu Nicolau 
134906257e9SSergio Gonzalez Monroy 	struct ip_addr src;
135906257e9SSergio Gonzalez Monroy 	struct ip_addr dst;
1369ae86b4cSRadu Nicolau 	struct {
1379ae86b4cSRadu Nicolau 		uint16_t sport;
1389ae86b4cSRadu Nicolau 		uint16_t dport;
1399ae86b4cSRadu Nicolau 	} udp;
1400d547ed0SFan Zhang 	uint8_t cipher_key[MAX_KEY_SIZE];
1410d547ed0SFan Zhang 	uint16_t cipher_key_len;
1420d547ed0SFan Zhang 	uint8_t auth_key[MAX_KEY_SIZE];
1430d547ed0SFan Zhang 	uint16_t auth_key_len;
144a9121c40SSergio Gonzalez Monroy 	uint16_t aad_len;
145ec17993aSAkhil Goyal 	union {
146906257e9SSergio Gonzalez Monroy 		struct rte_crypto_sym_xform *xforms;
147ec17993aSAkhil Goyal 		struct rte_security_ipsec_xform *sec_xform;
148ec17993aSAkhil Goyal 	};
149ec17993aSAkhil Goyal 	enum rte_security_ipsec_sa_direction direction;
1509a1cc8f1STejasree Kondoj 	uint8_t udp_encap;
151ec17993aSAkhil Goyal 	uint16_t portid;
152560029d5SRadu Nicolau 	uint64_t esn;
153a7f32947SRadu Nicolau 	uint16_t mss;
1546738c0a9SPraveen Shetty 	uint8_t fdir_qid;
1556738c0a9SPraveen Shetty 	uint8_t fdir_flag;
156ec17993aSAkhil Goyal 
1579ae86b4cSRadu Nicolau #define MAX_RTE_FLOW_PATTERN (5)
158a4677f78SNélio Laranjeiro #define MAX_RTE_FLOW_ACTIONS (3)
159ec17993aSAkhil Goyal 	struct rte_flow_item pattern[MAX_RTE_FLOW_PATTERN];
160ec17993aSAkhil Goyal 	struct rte_flow_action action[MAX_RTE_FLOW_ACTIONS];
161ec17993aSAkhil Goyal 	struct rte_flow_attr attr;
162ec17993aSAkhil Goyal 	union {
163ec17993aSAkhil Goyal 		struct rte_flow_item_ipv4 ipv4_spec;
164ec17993aSAkhil Goyal 		struct rte_flow_item_ipv6 ipv6_spec;
165ec17993aSAkhil Goyal 	};
1669ae86b4cSRadu Nicolau 	struct rte_flow_item_udp udp_spec;
167ec17993aSAkhil Goyal 	struct rte_flow_item_esp esp_spec;
168ec17993aSAkhil Goyal 	struct rte_flow *flow;
169ec17993aSAkhil Goyal 	struct rte_security_session_conf sess_conf;
1707e06c0deSTyler Retzlaff };
171d299106eSSergio Gonzalez Monroy 
17265e3a202SLukasz Bartosik struct ipsec_xf {
17365e3a202SLukasz Bartosik 	struct rte_crypto_sym_xform a;
17465e3a202SLukasz Bartosik 	struct rte_crypto_sym_xform b;
17565e3a202SLukasz Bartosik };
17665e3a202SLukasz Bartosik 
17765e3a202SLukasz Bartosik struct ipsec_sad {
17865e3a202SLukasz Bartosik 	struct rte_ipsec_sad *sad_v4;
17965e3a202SLukasz Bartosik 	struct rte_ipsec_sad *sad_v6;
18065e3a202SLukasz Bartosik };
18165e3a202SLukasz Bartosik 
18265e3a202SLukasz Bartosik struct sa_ctx {
18365e3a202SLukasz Bartosik 	void *satbl; /* pointer to array of rte_ipsec_sa objects*/
18465e3a202SLukasz Bartosik 	struct ipsec_sad sad;
18565e3a202SLukasz Bartosik 	struct ipsec_xf *xf;
18665e3a202SLukasz Bartosik 	uint32_t nb_sa;
18765e3a202SLukasz Bartosik 	struct ipsec_sa sa[];
18865e3a202SLukasz Bartosik };
18965e3a202SLukasz Bartosik 
1907e06c0deSTyler Retzlaff struct __rte_cache_aligned ipsec_mbuf_metadata {
191d299106eSSergio Gonzalez Monroy 	struct ipsec_sa *sa;
192d299106eSSergio Gonzalez Monroy 	struct rte_crypto_op cop;
193d299106eSSergio Gonzalez Monroy 	struct rte_crypto_sym_op sym_cop;
194dad71e99SPablo de Lara 	uint8_t buf[32];
1957e06c0deSTyler Retzlaff };
196d299106eSSergio Gonzalez Monroy 
197b1a3ac78SMariusz Drost #define IS_TRANSPORT(flags) ((flags) & TRANSPORT)
198b1a3ac78SMariusz Drost 
199b1a3ac78SMariusz Drost #define IS_TUNNEL(flags) ((flags) & (IP4_TUNNEL | IP6_TUNNEL))
200b1a3ac78SMariusz Drost 
201b1a3ac78SMariusz Drost #define IS_IP4(flags) ((flags) & (IP4_TUNNEL | IP4_TRANSPORT))
202b1a3ac78SMariusz Drost 
203b1a3ac78SMariusz Drost #define IS_IP6(flags) ((flags) & (IP6_TUNNEL | IP6_TRANSPORT))
204b1a3ac78SMariusz Drost 
205b1a3ac78SMariusz Drost #define IS_IP4_TUNNEL(flags) ((flags) & IP4_TUNNEL)
206b1a3ac78SMariusz Drost 
207b1a3ac78SMariusz Drost #define IS_IP6_TUNNEL(flags) ((flags) & IP6_TUNNEL)
208b1a3ac78SMariusz Drost 
209d8d51d4fSRahul Bhansali #define IS_HW_REASSEMBLY_EN(flags) ((flags) & SA_REASSEMBLY_ENABLE)
210b1a3ac78SMariusz Drost /*
211b1a3ac78SMariusz Drost  * Macro for getting ipsec_sa flags statuses without version of protocol
212b1a3ac78SMariusz Drost  * used for transport (IP4_TRANSPORT and IP6_TRANSPORT flags).
213b1a3ac78SMariusz Drost  */
214b1a3ac78SMariusz Drost #define WITHOUT_TRANSPORT_VERSION(flags) \
215b1a3ac78SMariusz Drost 		((flags) & (IP4_TUNNEL | \
216b1a3ac78SMariusz Drost 			IP6_TUNNEL | \
217b1a3ac78SMariusz Drost 			TRANSPORT))
218b1a3ac78SMariusz Drost 
219d299106eSSergio Gonzalez Monroy struct cdev_qp {
220d299106eSSergio Gonzalez Monroy 	uint16_t id;
221d299106eSSergio Gonzalez Monroy 	uint16_t qp;
222d299106eSSergio Gonzalez Monroy 	uint16_t in_flight;
223d299106eSSergio Gonzalez Monroy 	uint16_t len;
2247e06c0deSTyler Retzlaff 	struct rte_crypto_op *buf[MAX_PKT_BURST];
225d299106eSSergio Gonzalez Monroy };
226d299106eSSergio Gonzalez Monroy 
227d299106eSSergio Gonzalez Monroy struct ipsec_ctx {
228d299106eSSergio Gonzalez Monroy 	struct rte_hash *cdev_map;
229906257e9SSergio Gonzalez Monroy 	struct sp_ctx *sp4_ctx;
230906257e9SSergio Gonzalez Monroy 	struct sp_ctx *sp6_ctx;
231d299106eSSergio Gonzalez Monroy 	struct sa_ctx *sa_ctx;
232d299106eSSergio Gonzalez Monroy 	uint16_t nb_qps;
233d299106eSSergio Gonzalez Monroy 	uint16_t last_qp;
234d299106eSSergio Gonzalez Monroy 	struct cdev_qp tbl[MAX_QP_PER_LCORE];
2357e06c0deSTyler Retzlaff 	struct rte_mbuf *ol_pkts[MAX_PKT_BURST];
2363da37f68SRadu Nicolau 	uint16_t ol_pkts_cnt;
23703128be4SKonstantin Ananyev 	uint64_t ipv4_offloads;
23803128be4SKonstantin Ananyev 	uint64_t ipv6_offloads;
239a8ade121SVolodymyr Fialko 	uint32_t lcore_id;
240d299106eSSergio Gonzalez Monroy };
241d299106eSSergio Gonzalez Monroy 
242b1a6b1e9SVolodymyr Fialko struct offloads {
243b1a6b1e9SVolodymyr Fialko 	uint64_t ipv4_offloads;
244b1a6b1e9SVolodymyr Fialko 	uint64_t ipv6_offloads;
245b1a6b1e9SVolodymyr Fialko };
246b1a6b1e9SVolodymyr Fialko 
247b1a6b1e9SVolodymyr Fialko extern struct offloads tx_offloads;
248b1a6b1e9SVolodymyr Fialko 
249ae9267a6SBrian Dooley /*
250ae9267a6SBrian Dooley  * This structure is used for the key in hash table.
251ae9267a6SBrian Dooley  * Padding is to force the struct to use 8 bytes,
252ae9267a6SBrian Dooley  * to ensure memory is not read past this structs boundary
253ae9267a6SBrian Dooley  * (hash key calculation reads 8 bytes if this struct is size 5 bytes).
254ae9267a6SBrian Dooley  */
255d299106eSSergio Gonzalez Monroy struct cdev_key {
2564b978938SSivaprasad Tummala 	uint32_t lcore_id;
257d299106eSSergio Gonzalez Monroy 	uint8_t cipher_algo;
258d299106eSSergio Gonzalez Monroy 	uint8_t auth_algo;
25915f81cbfSAviad Yehezkel 	uint8_t aead_algo;
2604b978938SSivaprasad Tummala 	uint8_t padding; /* padding to 8-byte size should be zeroed */
261d299106eSSergio Gonzalez Monroy };
262d299106eSSergio Gonzalez Monroy 
263d299106eSSergio Gonzalez Monroy struct socket_ctx {
264906257e9SSergio Gonzalez Monroy 	struct sa_ctx *sa_in;
265906257e9SSergio Gonzalez Monroy 	struct sa_ctx *sa_out;
266906257e9SSergio Gonzalez Monroy 	struct sp_ctx *sp_ip4_in;
267906257e9SSergio Gonzalez Monroy 	struct sp_ctx *sp_ip4_out;
268906257e9SSergio Gonzalez Monroy 	struct sp_ctx *sp_ip6_in;
269906257e9SSergio Gonzalez Monroy 	struct sp_ctx *sp_ip6_out;
270906257e9SSergio Gonzalez Monroy 	struct rt_ctx *rt_ip4;
271906257e9SSergio Gonzalez Monroy 	struct rt_ctx *rt_ip6;
27248a39871SNithin Dabilpuram 	struct rte_mempool *mbuf_pool[RTE_MAX_ETHPORTS];
273b01d1cd2SKonstantin Ananyev 	struct rte_mempool *mbuf_pool_indir;
2742c59bd32SSlawomir Mrozowicz 	struct rte_mempool *session_pool;
275d299106eSSergio Gonzalez Monroy };
276d299106eSSergio Gonzalez Monroy 
277*7f2a987cSAndre Muezerie struct __rte_packed_begin cnt_blk {
278cef50fc6SSergio Gonzalez Monroy 	uint32_t salt;
279cef50fc6SSergio Gonzalez Monroy 	uint64_t iv;
280cef50fc6SSergio Gonzalez Monroy 	uint32_t cnt;
281*7f2a987cSAndre Muezerie } __rte_packed_end;
282cef50fc6SSergio Gonzalez Monroy 
2837e06c0deSTyler Retzlaff struct __rte_cache_aligned lcore_rx_queue {
284dcbf9ad5SNithin Dabilpuram 	uint16_t port_id;
285b23c5bd7SSivaprasad Tummala 	uint16_t queue_id;
28679bdb787SAkhil Goyal 	void *sec_ctx;
2877e06c0deSTyler Retzlaff };
288dcbf9ad5SNithin Dabilpuram 
289dcbf9ad5SNithin Dabilpuram struct buffer {
290dcbf9ad5SNithin Dabilpuram 	uint16_t len;
2917e06c0deSTyler Retzlaff 	struct rte_mbuf *m_table[MAX_PKT_BURST];
292dcbf9ad5SNithin Dabilpuram };
293dcbf9ad5SNithin Dabilpuram 
2947e06c0deSTyler Retzlaff struct __rte_cache_aligned lcore_conf {
295dcbf9ad5SNithin Dabilpuram 	uint16_t nb_rx_queue;
296dcbf9ad5SNithin Dabilpuram 	struct lcore_rx_queue rx_queue_list[MAX_RX_QUEUE_PER_LCORE];
297dcbf9ad5SNithin Dabilpuram 	uint16_t tx_queue_id[RTE_MAX_ETHPORTS];
298dcbf9ad5SNithin Dabilpuram 	struct buffer tx_mbufs[RTE_MAX_ETHPORTS];
299dcbf9ad5SNithin Dabilpuram 	struct ipsec_ctx inbound;
300dcbf9ad5SNithin Dabilpuram 	struct ipsec_ctx outbound;
301dcbf9ad5SNithin Dabilpuram 	struct rt_ctx *rt4_ctx;
302dcbf9ad5SNithin Dabilpuram 	struct rt_ctx *rt6_ctx;
303dcbf9ad5SNithin Dabilpuram 	struct {
304dcbf9ad5SNithin Dabilpuram 		struct rte_ip_frag_tbl *tbl;
305dcbf9ad5SNithin Dabilpuram 		struct rte_mempool *pool_indir;
306dcbf9ad5SNithin Dabilpuram 		struct rte_ip_frag_death_row dr;
307dcbf9ad5SNithin Dabilpuram 	} frag;
3087e06c0deSTyler Retzlaff };
309dcbf9ad5SNithin Dabilpuram 
310dcbf9ad5SNithin Dabilpuram extern struct lcore_conf lcore_conf[RTE_MAX_LCORE];
311dcbf9ad5SNithin Dabilpuram 
3124965dda0SLukasz Bartosik /* Socket ctx */
3134965dda0SLukasz Bartosik extern struct socket_ctx socket_ctx[NB_SOCKETS];
3144965dda0SLukasz Bartosik 
3154965dda0SLukasz Bartosik void
3164965dda0SLukasz Bartosik ipsec_poll_mode_worker(void);
3174965dda0SLukasz Bartosik 
3184965dda0SLukasz Bartosik int
3194965dda0SLukasz Bartosik ipsec_launch_one_lcore(void *args);
3204965dda0SLukasz Bartosik 
32165e3a202SLukasz Bartosik extern struct ipsec_sa *sa_out;
32265e3a202SLukasz Bartosik extern uint32_t nb_sa_out;
32365e3a202SLukasz Bartosik 
32465e3a202SLukasz Bartosik extern struct ipsec_sa *sa_in;
32565e3a202SLukasz Bartosik extern uint32_t nb_sa_in;
32665e3a202SLukasz Bartosik 
327d299106eSSergio Gonzalez Monroy uint16_t
328d299106eSSergio Gonzalez Monroy ipsec_inbound(struct ipsec_ctx *ctx, struct rte_mbuf *pkts[],
329d299106eSSergio Gonzalez Monroy 		uint16_t nb_pkts, uint16_t len);
330d299106eSSergio Gonzalez Monroy 
331d299106eSSergio Gonzalez Monroy uint16_t
332d299106eSSergio Gonzalez Monroy ipsec_outbound(struct ipsec_ctx *ctx, struct rte_mbuf *pkts[],
333d299106eSSergio Gonzalez Monroy 		uint32_t sa_idx[], uint16_t nb_pkts, uint16_t len);
334d299106eSSergio Gonzalez Monroy 
335d87152e7SKonstantin Ananyev uint16_t
336d87152e7SKonstantin Ananyev ipsec_inbound_cqp_dequeue(struct ipsec_ctx *ctx, struct rte_mbuf *pkts[],
337d87152e7SKonstantin Ananyev 		uint16_t len);
338d87152e7SKonstantin Ananyev 
339d87152e7SKonstantin Ananyev uint16_t
340d87152e7SKonstantin Ananyev ipsec_outbound_cqp_dequeue(struct ipsec_ctx *ctx, struct rte_mbuf *pkts[],
341d87152e7SKonstantin Ananyev 		uint16_t len);
342d87152e7SKonstantin Ananyev 
3433e5f4625SKonstantin Ananyev void
3443e5f4625SKonstantin Ananyev ipsec_process(struct ipsec_ctx *ctx, struct ipsec_traffic *trf);
3453e5f4625SKonstantin Ananyev 
3463e5f4625SKonstantin Ananyev void
3473e5f4625SKonstantin Ananyev ipsec_cqp_process(struct ipsec_ctx *ctx, struct ipsec_traffic *trf);
3483e5f4625SKonstantin Ananyev 
349d299106eSSergio Gonzalez Monroy static inline uint16_t
350d299106eSSergio Gonzalez Monroy ipsec_metadata_size(void)
351d299106eSSergio Gonzalez Monroy {
352d299106eSSergio Gonzalez Monroy 	return sizeof(struct ipsec_mbuf_metadata);
353d299106eSSergio Gonzalez Monroy }
354d299106eSSergio Gonzalez Monroy 
355d299106eSSergio Gonzalez Monroy static inline struct ipsec_mbuf_metadata *
356d299106eSSergio Gonzalez Monroy get_priv(struct rte_mbuf *m)
357d299106eSSergio Gonzalez Monroy {
358b1d295e6SDan Gora 	return rte_mbuf_to_priv(m);
359d299106eSSergio Gonzalez Monroy }
360d299106eSSergio Gonzalez Monroy 
361cef50fc6SSergio Gonzalez Monroy static inline void *
362cef50fc6SSergio Gonzalez Monroy get_cnt_blk(struct rte_mbuf *m)
363cef50fc6SSergio Gonzalez Monroy {
364cef50fc6SSergio Gonzalez Monroy 	struct ipsec_mbuf_metadata *priv = get_priv(m);
365cef50fc6SSergio Gonzalez Monroy 
366cef50fc6SSergio Gonzalez Monroy 	return &priv->buf[0];
367cef50fc6SSergio Gonzalez Monroy }
368cef50fc6SSergio Gonzalez Monroy 
369cef50fc6SSergio Gonzalez Monroy static inline void *
370a9121c40SSergio Gonzalez Monroy get_aad(struct rte_mbuf *m)
371a9121c40SSergio Gonzalez Monroy {
372a9121c40SSergio Gonzalez Monroy 	struct ipsec_mbuf_metadata *priv = get_priv(m);
373a9121c40SSergio Gonzalez Monroy 
374a9121c40SSergio Gonzalez Monroy 	return &priv->buf[16];
375a9121c40SSergio Gonzalez Monroy }
376a9121c40SSergio Gonzalez Monroy 
377a9121c40SSergio Gonzalez Monroy static inline void *
378cef50fc6SSergio Gonzalez Monroy get_sym_cop(struct rte_crypto_op *cop)
379cef50fc6SSergio Gonzalez Monroy {
380cef50fc6SSergio Gonzalez Monroy 	return (cop + 1);
381cef50fc6SSergio Gonzalez Monroy }
382cef50fc6SSergio Gonzalez Monroy 
3834a67af84SMarcin Smoczynski static inline struct rte_ipsec_session *
384ba66534fSMarcin Smoczynski ipsec_get_primary_session(struct ipsec_sa *sa)
3854a67af84SMarcin Smoczynski {
386ba66534fSMarcin Smoczynski 	return &sa->sessions[IPSEC_SESSION_PRIMARY];
387ba66534fSMarcin Smoczynski }
388ba66534fSMarcin Smoczynski 
389ba66534fSMarcin Smoczynski static inline struct rte_ipsec_session *
390ba66534fSMarcin Smoczynski ipsec_get_fallback_session(struct ipsec_sa *sa)
391ba66534fSMarcin Smoczynski {
392ba66534fSMarcin Smoczynski 	return &sa->sessions[IPSEC_SESSION_FALLBACK];
3934a67af84SMarcin Smoczynski }
3944a67af84SMarcin Smoczynski 
3954a67af84SMarcin Smoczynski static inline enum rte_security_session_action_type
3964a67af84SMarcin Smoczynski ipsec_get_action_type(struct ipsec_sa *sa)
3974a67af84SMarcin Smoczynski {
3984a67af84SMarcin Smoczynski 	struct rte_ipsec_session *ips;
399ba66534fSMarcin Smoczynski 	ips = ipsec_get_primary_session(sa);
4004a67af84SMarcin Smoczynski 	return ips->type;
4014a67af84SMarcin Smoczynski }
4024a67af84SMarcin Smoczynski 
403d299106eSSergio Gonzalez Monroy int
404d299106eSSergio Gonzalez Monroy inbound_sa_check(struct sa_ctx *sa_ctx, struct rte_mbuf *m, uint32_t sa_idx);
405d299106eSSergio Gonzalez Monroy 
406d299106eSSergio Gonzalez Monroy void
407d299106eSSergio Gonzalez Monroy inbound_sa_lookup(struct sa_ctx *sa_ctx, struct rte_mbuf *pkts[],
408ba66534fSMarcin Smoczynski 		void *sa[], uint16_t nb_pkts);
409d299106eSSergio Gonzalez Monroy 
410d299106eSSergio Gonzalez Monroy void
411d299106eSSergio Gonzalez Monroy outbound_sa_lookup(struct sa_ctx *sa_ctx, uint32_t sa_idx[],
412ba66534fSMarcin Smoczynski 		void *sa[], uint16_t nb_pkts);
413d299106eSSergio Gonzalez Monroy 
414d299106eSSergio Gonzalez Monroy void
4150d547ed0SFan Zhang sp4_init(struct socket_ctx *ctx, int32_t socket_id);
416d299106eSSergio Gonzalez Monroy 
417d299106eSSergio Gonzalez Monroy void
4180d547ed0SFan Zhang sp6_init(struct socket_ctx *ctx, int32_t socket_id);
419d299106eSSergio Gonzalez Monroy 
4205a032a71SKonstantin Ananyev /*
4215a032a71SKonstantin Ananyev  * Search through SP rules for given SPI.
4225a032a71SKonstantin Ananyev  * Returns first rule index if found(greater or equal then zero),
4235a032a71SKonstantin Ananyev  * or -ENOENT otherwise.
4245a032a71SKonstantin Ananyev  */
4255a032a71SKonstantin Ananyev int
426b1a3ac78SMariusz Drost sp4_spi_present(uint32_t spi, int inbound, struct ip_addr ip_addr[2],
427b1a3ac78SMariusz Drost 			uint32_t mask[2]);
4285a032a71SKonstantin Ananyev int
429b1a3ac78SMariusz Drost sp6_spi_present(uint32_t spi, int inbound, struct ip_addr ip_addr[2],
430b1a3ac78SMariusz Drost 			uint32_t mask[2]);
4315a032a71SKonstantin Ananyev 
43249757b68SKonstantin Ananyev /*
43349757b68SKonstantin Ananyev  * Search through SA entries for given SPI.
43449757b68SKonstantin Ananyev  * Returns first entry index if found(greater or equal then zero),
43549757b68SKonstantin Ananyev  * or -ENOENT otherwise.
43649757b68SKonstantin Ananyev  */
43749757b68SKonstantin Ananyev int
438df3e1d94SVladimir Medvedkin sa_spi_present(struct sa_ctx *sa_ctx, uint32_t spi, int inbound);
43949757b68SKonstantin Ananyev 
440d299106eSSergio Gonzalez Monroy void
441a8ade121SVolodymyr Fialko sa_init(struct socket_ctx *ctx, int32_t socket_id,
4426938fc92SVolodymyr Fialko 	struct lcore_conf *lcore_conf,
4436938fc92SVolodymyr Fialko 	const struct eventmode_conf *em_conf);
444906257e9SSergio Gonzalez Monroy 
445906257e9SSergio Gonzalez Monroy void
4460d547ed0SFan Zhang rt_init(struct socket_ctx *ctx, int32_t socket_id);
447d299106eSSergio Gonzalez Monroy 
44803128be4SKonstantin Ananyev int
44903128be4SKonstantin Ananyev sa_check_offloads(uint16_t port_id, uint64_t *rx_offloads,
450d8d51d4fSRahul Bhansali 		uint64_t *tx_offloads, uint8_t *hw_reassembly);
45103128be4SKonstantin Ananyev 
4527622291bSKonstantin Ananyev int
4536d13ea8eSOlivier Matz add_dst_ethaddr(uint16_t port, const struct rte_ether_addr *addr);
4547622291bSKonstantin Ananyev 
455d87152e7SKonstantin Ananyev void
456d87152e7SKonstantin Ananyev enqueue_cop_burst(struct cdev_qp *cqp);
457d87152e7SKonstantin Ananyev 
4583e5f4625SKonstantin Ananyev int
459a8ade121SVolodymyr Fialko create_lookaside_session(struct ipsec_ctx *ipsec_ctx[],
4606938fc92SVolodymyr Fialko 	struct socket_ctx *skt_ctx, const struct eventmode_conf *em_conf,
4616938fc92SVolodymyr Fialko 	struct ipsec_sa *sa, struct rte_ipsec_session *ips);
4623a690d5aSBernard Iremonger 
4633a690d5aSBernard Iremonger int
4644a67af84SMarcin Smoczynski create_inline_session(struct socket_ctx *skt_ctx, struct ipsec_sa *sa,
4654a67af84SMarcin Smoczynski 		struct rte_ipsec_session *ips);
4666738c0a9SPraveen Shetty int
4676738c0a9SPraveen Shetty check_flow_params(uint16_t fdir_portid, uint8_t fdir_qid);
4686738c0a9SPraveen Shetty 
4696738c0a9SPraveen Shetty int
4706738c0a9SPraveen Shetty create_ipsec_esp_flow(struct ipsec_sa *sa);
4713e5f4625SKonstantin Ananyev 
47204fa1906SVladimir Medvedkin uint32_t
47304fa1906SVladimir Medvedkin get_nb_crypto_sessions(void);
47404fa1906SVladimir Medvedkin 
475d299106eSSergio Gonzalez Monroy #endif /* __IPSEC_H__ */
476