Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2018 Intel Corporation
3 : : */
4 : :
5 : : #include "test.h"
6 : :
7 : : #include <time.h>
8 : :
9 : : #include <rte_common.h>
10 : : #include <rte_hexdump.h>
11 : : #include <rte_mbuf.h>
12 : : #include <rte_malloc.h>
13 : : #include <rte_memcpy.h>
14 : : #include <rte_cycles.h>
15 : : #include <rte_bus_vdev.h>
16 : : #include <rte_ip.h>
17 : : #include <rte_crypto.h>
18 : : #include <rte_cryptodev.h>
19 : : #include <rte_lcore.h>
20 : :
21 : : #ifdef RTE_EXEC_ENV_WINDOWS
22 : : static int
23 : : test_ipsec(void)
24 : : {
25 : : printf("ipsec not supported on Windows, skipping test\n");
26 : : return TEST_SKIPPED;
27 : : }
28 : :
29 : : #else
30 : :
31 : : #include <rte_ipsec.h>
32 : : #include <rte_random.h>
33 : : #include <rte_esp.h>
34 : : #include <rte_security_driver.h>
35 : :
36 : : #include "test_cryptodev.h"
37 : :
38 : : #define VDEV_ARGS_SIZE 100
39 : : #define MAX_NB_SESSIONS 200
40 : : #define MAX_NB_SAS 2
41 : : #define REPLAY_WIN_0 0
42 : : #define REPLAY_WIN_32 32
43 : : #define REPLAY_WIN_64 64
44 : : #define REPLAY_WIN_128 128
45 : : #define REPLAY_WIN_256 256
46 : : #define DATA_64_BYTES 64
47 : : #define DATA_80_BYTES 80
48 : : #define DATA_100_BYTES 100
49 : : #define ESN_ENABLED 1
50 : : #define ESN_DISABLED 0
51 : : #define INBOUND_SPI 7
52 : : #define OUTBOUND_SPI 17
53 : : #define BURST_SIZE 32
54 : : #define REORDER_PKTS 1
55 : : #define DEQUEUE_COUNT 1000
56 : :
57 : : struct user_params {
58 : : enum rte_crypto_sym_xform_type auth;
59 : : enum rte_crypto_sym_xform_type cipher;
60 : : enum rte_crypto_sym_xform_type aead;
61 : :
62 : : char auth_algo[128];
63 : : char cipher_algo[128];
64 : : char aead_algo[128];
65 : : };
66 : :
67 : : struct ipsec_testsuite_params {
68 : : struct rte_mempool *mbuf_pool;
69 : : struct rte_mempool *cop_mpool;
70 : : struct rte_cryptodev_config conf;
71 : : struct rte_cryptodev_qp_conf qp_conf;
72 : :
73 : : uint8_t valid_dev;
74 : : uint8_t valid_dev_found;
75 : : };
76 : :
77 : : struct ipsec_unitest_params {
78 : : struct rte_crypto_sym_xform cipher_xform;
79 : : struct rte_crypto_sym_xform auth_xform;
80 : : struct rte_crypto_sym_xform aead_xform;
81 : : struct rte_crypto_sym_xform *crypto_xforms;
82 : :
83 : : struct rte_security_ipsec_xform ipsec_xform;
84 : :
85 : : struct rte_ipsec_sa_prm sa_prm;
86 : : struct rte_ipsec_session ss[MAX_NB_SAS];
87 : :
88 : : struct rte_crypto_op *cop[BURST_SIZE];
89 : :
90 : : struct rte_mbuf *obuf[BURST_SIZE], *ibuf[BURST_SIZE],
91 : : *testbuf[BURST_SIZE];
92 : :
93 : : uint16_t pkt_index;
94 : : };
95 : :
96 : : struct ipsec_test_cfg {
97 : : uint32_t replay_win_sz;
98 : : uint32_t esn;
99 : : uint64_t flags;
100 : : size_t pkt_sz;
101 : : uint16_t num_pkts;
102 : : uint32_t reorder_pkts;
103 : : };
104 : :
105 : : static const struct ipsec_test_cfg test_cfg[] = {
106 : : {REPLAY_WIN_0, ESN_DISABLED, 0, DATA_64_BYTES, 1, 0},
107 : : {REPLAY_WIN_0, ESN_DISABLED, 0, DATA_64_BYTES, BURST_SIZE, 0},
108 : : {REPLAY_WIN_0, ESN_DISABLED, 0, DATA_80_BYTES, BURST_SIZE,
109 : : REORDER_PKTS},
110 : : {REPLAY_WIN_32, ESN_ENABLED, 0, DATA_100_BYTES, 1, 0},
111 : : {REPLAY_WIN_32, ESN_ENABLED, 0, DATA_100_BYTES, BURST_SIZE,
112 : : REORDER_PKTS},
113 : : {REPLAY_WIN_64, ESN_ENABLED, 0, DATA_64_BYTES, 1, 0},
114 : : {REPLAY_WIN_128, ESN_ENABLED, RTE_IPSEC_SAFLAG_SQN_ATOM,
115 : : DATA_80_BYTES, 1, 0},
116 : : {REPLAY_WIN_256, ESN_DISABLED, 0, DATA_100_BYTES, 1, 0},
117 : : };
118 : :
119 : : static const int num_cfg = RTE_DIM(test_cfg);
120 : : static struct ipsec_testsuite_params testsuite_params = { NULL };
121 : : static struct ipsec_unitest_params unittest_params;
122 : : static struct user_params uparams;
123 : :
124 : : struct supported_cipher_algo {
125 : : const char *keyword;
126 : : enum rte_crypto_cipher_algorithm algo;
127 : : uint16_t iv_len;
128 : : uint16_t block_size;
129 : : uint16_t key_len;
130 : : };
131 : :
132 : : struct supported_auth_algo {
133 : : const char *keyword;
134 : : enum rte_crypto_auth_algorithm algo;
135 : : uint16_t digest_len;
136 : : uint16_t key_len;
137 : : uint8_t key_not_req;
138 : : };
139 : :
140 : : const struct supported_cipher_algo cipher_algos[] = {
141 : : {
142 : : .keyword = "null",
143 : : .algo = RTE_CRYPTO_CIPHER_NULL,
144 : : .iv_len = 0,
145 : : .block_size = 4,
146 : : .key_len = 0
147 : : },
148 : : };
149 : :
150 : : const struct supported_auth_algo auth_algos[] = {
151 : : {
152 : : .keyword = "null",
153 : : .algo = RTE_CRYPTO_AUTH_NULL,
154 : : .digest_len = 0,
155 : : .key_len = 0,
156 : : .key_not_req = 1
157 : : },
158 : : };
159 : :
160 : : static int
161 : 0 : dummy_sec_create(void *device, struct rte_security_session_conf *conf,
162 : : struct rte_security_session *sess)
163 : : {
164 : : RTE_SET_USED(device);
165 : : RTE_SET_USED(conf);
166 : : RTE_SET_USED(sess);
167 : :
168 : 0 : return 0;
169 : : }
170 : :
171 : : static int
172 : 0 : dummy_sec_destroy(void *device, struct rte_security_session *sess)
173 : : {
174 : : RTE_SET_USED(device);
175 : : RTE_SET_USED(sess);
176 : 0 : return 0;
177 : : }
178 : :
179 : : static const struct rte_security_ops dummy_sec_ops = {
180 : : .session_create = dummy_sec_create,
181 : : .session_destroy = dummy_sec_destroy,
182 : : };
183 : :
184 : : static struct rte_security_ctx dummy_sec_ctx = {
185 : : .ops = &dummy_sec_ops,
186 : : };
187 : :
188 : : static const struct supported_cipher_algo *
189 : : find_match_cipher_algo(const char *cipher_keyword)
190 : : {
191 : : size_t i;
192 : :
193 : : for (i = 0; i < RTE_DIM(cipher_algos); i++) {
194 : : const struct supported_cipher_algo *algo =
195 : : &cipher_algos[i];
196 : :
197 [ - - - + ]: 1 : if (strcmp(cipher_keyword, algo->keyword) == 0)
198 : : return algo;
199 : : }
200 : :
201 : : return NULL;
202 : : }
203 : :
204 : : static const struct supported_auth_algo *
205 : : find_match_auth_algo(const char *auth_keyword)
206 : : {
207 : : size_t i;
208 : :
209 : : for (i = 0; i < RTE_DIM(auth_algos); i++) {
210 : : const struct supported_auth_algo *algo =
211 : : &auth_algos[i];
212 : :
213 [ - - - + ]: 1 : if (strcmp(auth_keyword, algo->keyword) == 0)
214 : : return algo;
215 : : }
216 : :
217 : : return NULL;
218 : : }
219 : :
220 : : static void
221 : : fill_crypto_xform(struct ipsec_unitest_params *ut_params,
222 : : const struct supported_auth_algo *auth_algo,
223 : : const struct supported_cipher_algo *cipher_algo)
224 : : {
225 : 1 : ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
226 : 1 : ut_params->cipher_xform.cipher.algo = cipher_algo->algo;
227 : 1 : ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
228 : 1 : ut_params->auth_xform.auth.algo = auth_algo->algo;
229 : :
230 [ # # ]: 0 : if (ut_params->ipsec_xform.direction ==
231 : : RTE_SECURITY_IPSEC_SA_DIR_INGRESS) {
232 : 0 : ut_params->cipher_xform.cipher.op =
233 : : RTE_CRYPTO_CIPHER_OP_DECRYPT;
234 : 0 : ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
235 : 0 : ut_params->cipher_xform.next = NULL;
236 : 0 : ut_params->auth_xform.next = &ut_params->cipher_xform;
237 : 0 : ut_params->crypto_xforms = &ut_params->auth_xform;
238 : : } else {
239 : 0 : ut_params->cipher_xform.cipher.op =
240 : : RTE_CRYPTO_CIPHER_OP_ENCRYPT;
241 : 1 : ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
242 : 0 : ut_params->auth_xform.next = NULL;
243 : 1 : ut_params->cipher_xform.next = &ut_params->auth_xform;
244 : 0 : ut_params->crypto_xforms = &ut_params->cipher_xform;
245 : : }
246 : : }
247 : :
248 : : static int
249 : 0 : check_cryptodev_capability(const struct ipsec_unitest_params *ut,
250 : : uint8_t dev_id)
251 : : {
252 : : struct rte_cryptodev_sym_capability_idx cap_idx;
253 : : const struct rte_cryptodev_symmetric_capability *cap;
254 : : int rc = -1;
255 : :
256 : 0 : cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
257 : 0 : cap_idx.algo.auth = ut->auth_xform.auth.algo;
258 : 0 : cap = rte_cryptodev_sym_capability_get(dev_id, &cap_idx);
259 : :
260 [ # # ]: 0 : if (cap != NULL) {
261 : 0 : rc = rte_cryptodev_sym_capability_check_auth(cap,
262 : 0 : ut->auth_xform.auth.key.length,
263 : 0 : ut->auth_xform.auth.digest_length, 0);
264 [ # # ]: 0 : if (rc == 0) {
265 : 0 : cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
266 : 0 : cap_idx.algo.cipher = ut->cipher_xform.cipher.algo;
267 : 0 : cap = rte_cryptodev_sym_capability_get(
268 : : dev_id, &cap_idx);
269 [ # # ]: 0 : if (cap != NULL)
270 : 0 : rc = rte_cryptodev_sym_capability_check_cipher(
271 : : cap,
272 : 0 : ut->cipher_xform.cipher.key.length,
273 : 0 : ut->cipher_xform.cipher.iv.length);
274 : : }
275 : : }
276 : :
277 : 0 : return rc;
278 : : }
279 : :
280 : : static int
281 [ - + ]: 1 : testsuite_setup(void)
282 : : {
283 : : struct ipsec_testsuite_params *ts_params = &testsuite_params;
284 : : struct ipsec_unitest_params *ut_params = &unittest_params;
285 : : const struct supported_auth_algo *auth_algo;
286 : : const struct supported_cipher_algo *cipher_algo;
287 : : struct rte_cryptodev_info info;
288 : : uint32_t i, nb_devs, dev_id;
289 : : size_t sess_sz;
290 : : int rc;
291 : :
292 : : memset(ts_params, 0, sizeof(*ts_params));
293 : : memset(ut_params, 0, sizeof(*ut_params));
294 : : memset(&uparams, 0, sizeof(struct user_params));
295 : :
296 : 1 : uparams.auth = RTE_CRYPTO_SYM_XFORM_AUTH;
297 [ - + ]: 1 : uparams.cipher = RTE_CRYPTO_SYM_XFORM_CIPHER;
298 : : uparams.aead = RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED;
299 : : strcpy(uparams.auth_algo, "null");
300 : : strcpy(uparams.cipher_algo, "null");
301 : :
302 : : auth_algo = find_match_auth_algo(uparams.auth_algo);
303 : : cipher_algo = find_match_cipher_algo(uparams.cipher_algo);
304 : : fill_crypto_xform(ut_params, auth_algo, cipher_algo);
305 : :
306 : 1 : nb_devs = rte_cryptodev_count();
307 [ + - ]: 1 : if (nb_devs < 1) {
308 : 1 : RTE_LOG(WARNING, USER1, "No crypto devices found?\n");
309 : 1 : return TEST_SKIPPED;
310 : : }
311 : :
312 : : /* Find first valid crypto device */
313 [ # # ]: 0 : for (i = 0; i < nb_devs; i++) {
314 : 0 : rc = check_cryptodev_capability(ut_params, i);
315 [ # # ]: 0 : if (rc == 0) {
316 : 0 : ts_params->valid_dev = i;
317 : 0 : ts_params->valid_dev_found = 1;
318 : 0 : break;
319 : : }
320 : : }
321 : :
322 [ # # ]: 0 : if (ts_params->valid_dev_found == 0) {
323 : 0 : RTE_LOG(WARNING, USER1, "No compatible crypto device found.\n");
324 : 0 : return TEST_SKIPPED;
325 : : }
326 : :
327 : 0 : ts_params->mbuf_pool = rte_pktmbuf_pool_create(
328 : : "CRYPTO_MBUFPOOL",
329 : : NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
330 : 0 : rte_socket_id());
331 [ # # ]: 0 : if (ts_params->mbuf_pool == NULL) {
332 : 0 : RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
333 : 0 : return TEST_FAILED;
334 : : }
335 : :
336 : 0 : ts_params->cop_mpool = rte_crypto_op_pool_create(
337 : : "MBUF_CRYPTO_SYM_OP_POOL",
338 : : RTE_CRYPTO_OP_TYPE_SYMMETRIC,
339 : : NUM_MBUFS, MBUF_CACHE_SIZE,
340 : : DEFAULT_NUM_XFORMS *
341 : : sizeof(struct rte_crypto_sym_xform) +
342 : : MAXIMUM_IV_LENGTH,
343 : 0 : rte_socket_id());
344 [ # # ]: 0 : if (ts_params->cop_mpool == NULL) {
345 : 0 : RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
346 : 0 : return TEST_FAILED;
347 : : }
348 : :
349 : : /* Set up all the qps on the first of the valid devices found */
350 : 0 : dev_id = ts_params->valid_dev;
351 : :
352 : 0 : rte_cryptodev_info_get(dev_id, &info);
353 : :
354 : 0 : ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
355 : 0 : ts_params->conf.socket_id = SOCKET_ID_ANY;
356 : 0 : ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO;
357 : :
358 : 0 : sess_sz = rte_cryptodev_sym_get_private_session_size(dev_id);
359 : : sess_sz = RTE_MAX(sess_sz, sizeof(struct rte_security_session));
360 : :
361 : : /*
362 : : * Create mempools for sessions
363 : : */
364 [ # # ]: 0 : if (info.sym.max_nb_sessions != 0 &&
365 : : info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
366 : 0 : RTE_LOG(ERR, USER1, "Device does not support "
367 : : "at least %u sessions\n",
368 : : MAX_NB_SESSIONS);
369 : 0 : return TEST_FAILED;
370 : : }
371 : :
372 : 0 : ts_params->qp_conf.mp_session =
373 : 0 : rte_cryptodev_sym_session_pool_create("test_sess_mp",
374 : : MAX_NB_SESSIONS, sess_sz, 0, 0, SOCKET_ID_ANY);
375 : :
376 [ # # ]: 0 : TEST_ASSERT_NOT_NULL(ts_params->qp_conf.mp_session,
377 : : "session mempool allocation failed");
378 : :
379 [ # # ]: 0 : TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
380 : : &ts_params->conf),
381 : : "Failed to configure cryptodev %u with %u qps",
382 : : dev_id, ts_params->conf.nb_queue_pairs);
383 : :
384 : 0 : ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
385 : :
386 [ # # ]: 0 : TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
387 : : dev_id, 0, &ts_params->qp_conf,
388 : : rte_cryptodev_socket_id(dev_id)),
389 : : "Failed to setup queue pair %u on cryptodev %u",
390 : : 0, dev_id);
391 : :
392 : : return TEST_SUCCESS;
393 : : }
394 : :
395 : : static void
396 : 0 : testsuite_teardown(void)
397 : : {
398 : : struct ipsec_testsuite_params *ts_params = &testsuite_params;
399 : :
400 [ # # ]: 0 : if (ts_params->mbuf_pool != NULL) {
401 : 0 : RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
402 : : rte_mempool_avail_count(ts_params->mbuf_pool));
403 : 0 : rte_mempool_free(ts_params->mbuf_pool);
404 : 0 : ts_params->mbuf_pool = NULL;
405 : : }
406 : :
407 [ # # ]: 0 : if (ts_params->cop_mpool != NULL) {
408 : 0 : RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
409 : : rte_mempool_avail_count(ts_params->cop_mpool));
410 : 0 : rte_mempool_free(ts_params->cop_mpool);
411 : 0 : ts_params->cop_mpool = NULL;
412 : : }
413 : :
414 : : /* Free session mempools */
415 [ # # ]: 0 : if (ts_params->qp_conf.mp_session != NULL) {
416 : 0 : rte_mempool_free(ts_params->qp_conf.mp_session);
417 : 0 : ts_params->qp_conf.mp_session = NULL;
418 : : }
419 : 0 : }
420 : :
421 : : static int
422 : 0 : ut_setup_ipsec(void)
423 : : {
424 : : struct ipsec_testsuite_params *ts_params = &testsuite_params;
425 : : struct ipsec_unitest_params *ut_params = &unittest_params;
426 : :
427 : : /* Clear unit test parameters before running test */
428 : : memset(ut_params, 0, sizeof(*ut_params));
429 : :
430 : : /* Reconfigure device to default parameters */
431 : 0 : ts_params->conf.socket_id = SOCKET_ID_ANY;
432 : :
433 : : /* Start the device */
434 [ # # ]: 0 : TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_dev),
435 : : "Failed to start cryptodev %u",
436 : : ts_params->valid_dev);
437 : :
438 : : return TEST_SUCCESS;
439 : : }
440 : :
441 : : static void
442 : 0 : ut_teardown_ipsec(void)
443 : : {
444 : : struct ipsec_testsuite_params *ts_params = &testsuite_params;
445 : : struct ipsec_unitest_params *ut_params = &unittest_params;
446 : : int i;
447 : :
448 [ # # ]: 0 : for (i = 0; i < BURST_SIZE; i++) {
449 : : /* free crypto operation structure */
450 [ # # ]: 0 : if (ut_params->cop[i]) {
451 : 0 : rte_crypto_op_free(ut_params->cop[i]);
452 : 0 : ut_params->cop[i] = NULL;
453 : : }
454 : :
455 : : /*
456 : : * free mbuf - both obuf and ibuf are usually the same,
457 : : * so check if they point at the same address is necessary,
458 : : * to avoid freeing the mbuf twice.
459 : : */
460 [ # # ]: 0 : if (ut_params->obuf[i]) {
461 : 0 : rte_pktmbuf_free(ut_params->obuf[i]);
462 [ # # ]: 0 : if (ut_params->ibuf[i] == ut_params->obuf[i])
463 : 0 : ut_params->ibuf[i] = NULL;
464 : 0 : ut_params->obuf[i] = NULL;
465 : : }
466 [ # # ]: 0 : if (ut_params->ibuf[i]) {
467 : 0 : rte_pktmbuf_free(ut_params->ibuf[i]);
468 : 0 : ut_params->ibuf[i] = NULL;
469 : : }
470 : :
471 [ # # ]: 0 : if (ut_params->testbuf[i]) {
472 : 0 : rte_pktmbuf_free(ut_params->testbuf[i]);
473 : 0 : ut_params->testbuf[i] = NULL;
474 : : }
475 : : }
476 : :
477 [ # # ]: 0 : if (ts_params->mbuf_pool != NULL)
478 : 0 : RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
479 : : rte_mempool_avail_count(ts_params->mbuf_pool));
480 : :
481 : : /* Stop the device */
482 : 0 : rte_cryptodev_stop(ts_params->valid_dev);
483 : 0 : }
484 : :
485 : : #define IPSEC_MAX_PAD_SIZE UINT8_MAX
486 : :
487 : : static const uint8_t esp_pad_bytes[IPSEC_MAX_PAD_SIZE] = {
488 : : 1, 2, 3, 4, 5, 6, 7, 8,
489 : : 9, 10, 11, 12, 13, 14, 15, 16,
490 : : 17, 18, 19, 20, 21, 22, 23, 24,
491 : : 25, 26, 27, 28, 29, 30, 31, 32,
492 : : 33, 34, 35, 36, 37, 38, 39, 40,
493 : : 41, 42, 43, 44, 45, 46, 47, 48,
494 : : 49, 50, 51, 52, 53, 54, 55, 56,
495 : : 57, 58, 59, 60, 61, 62, 63, 64,
496 : : 65, 66, 67, 68, 69, 70, 71, 72,
497 : : 73, 74, 75, 76, 77, 78, 79, 80,
498 : : 81, 82, 83, 84, 85, 86, 87, 88,
499 : : 89, 90, 91, 92, 93, 94, 95, 96,
500 : : 97, 98, 99, 100, 101, 102, 103, 104,
501 : : 105, 106, 107, 108, 109, 110, 111, 112,
502 : : 113, 114, 115, 116, 117, 118, 119, 120,
503 : : 121, 122, 123, 124, 125, 126, 127, 128,
504 : : 129, 130, 131, 132, 133, 134, 135, 136,
505 : : 137, 138, 139, 140, 141, 142, 143, 144,
506 : : 145, 146, 147, 148, 149, 150, 151, 152,
507 : : 153, 154, 155, 156, 157, 158, 159, 160,
508 : : 161, 162, 163, 164, 165, 166, 167, 168,
509 : : 169, 170, 171, 172, 173, 174, 175, 176,
510 : : 177, 178, 179, 180, 181, 182, 183, 184,
511 : : 185, 186, 187, 188, 189, 190, 191, 192,
512 : : 193, 194, 195, 196, 197, 198, 199, 200,
513 : : 201, 202, 203, 204, 205, 206, 207, 208,
514 : : 209, 210, 211, 212, 213, 214, 215, 216,
515 : : 217, 218, 219, 220, 221, 222, 223, 224,
516 : : 225, 226, 227, 228, 229, 230, 231, 232,
517 : : 233, 234, 235, 236, 237, 238, 239, 240,
518 : : 241, 242, 243, 244, 245, 246, 247, 248,
519 : : 249, 250, 251, 252, 253, 254, 255,
520 : : };
521 : :
522 : : /* ***** data for tests ***** */
523 : :
524 : : const char null_plain_data[] =
525 : : "Network Security People Have A Strange Sense Of Humor unlike Other "
526 : : "People who have a normal sense of humour";
527 : :
528 : : const char null_encrypted_data[] =
529 : : "Network Security People Have A Strange Sense Of Humor unlike Other "
530 : : "People who have a normal sense of humour";
531 : :
532 : : struct rte_ipv4_hdr ipv4_outer = {
533 : : .version_ihl = IPVERSION << 4 |
534 : : sizeof(ipv4_outer) / RTE_IPV4_IHL_MULTIPLIER,
535 : : .time_to_live = IPDEFTTL,
536 : : .next_proto_id = IPPROTO_ESP,
537 : : .src_addr = RTE_IPV4(192, 168, 1, 100),
538 : : .dst_addr = RTE_IPV4(192, 168, 2, 100),
539 : : };
540 : :
541 : : static struct rte_mbuf *
542 : 0 : setup_test_string(struct rte_mempool *mpool, const char *string,
543 : : size_t string_len, size_t len, uint8_t blocksize)
544 : : {
545 : 0 : struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
546 [ # # ]: 0 : size_t t_len = len - (blocksize ? (len % blocksize) : 0);
547 : :
548 [ # # ]: 0 : RTE_VERIFY(len <= string_len);
549 : :
550 [ # # ]: 0 : if (m) {
551 : 0 : memset(m->buf_addr, 0, m->buf_len);
552 : 0 : char *dst = rte_pktmbuf_append(m, t_len);
553 : :
554 [ # # ]: 0 : if (!dst) {
555 : 0 : rte_pktmbuf_free(m);
556 : 0 : return NULL;
557 : : }
558 [ # # ]: 0 : if (string != NULL)
559 : : rte_memcpy(dst, string, t_len);
560 : : else
561 : : memset(dst, 0, t_len);
562 : : }
563 : :
564 : : return m;
565 : : }
566 : :
567 : : static struct rte_mbuf *
568 : 0 : setup_test_string_tunneled(struct rte_mempool *mpool, const char *string,
569 : : size_t len, uint32_t spi, uint32_t seq)
570 : : {
571 : 0 : struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
572 : : uint32_t hdrlen = sizeof(struct rte_ipv4_hdr) +
573 : : sizeof(struct rte_esp_hdr);
574 : : uint32_t taillen = sizeof(struct rte_esp_tail);
575 : 0 : uint32_t t_len = len + hdrlen + taillen;
576 : : uint32_t padlen;
577 : :
578 : 0 : struct rte_esp_hdr esph = {
579 [ # # ]: 0 : .spi = rte_cpu_to_be_32(spi),
580 [ # # ]: 0 : .seq = rte_cpu_to_be_32(seq)
581 : : };
582 : :
583 : 0 : padlen = RTE_ALIGN(t_len, 4) - t_len;
584 : : t_len += padlen;
585 : :
586 : 0 : struct rte_esp_tail espt = {
587 : : .pad_len = padlen,
588 : : .next_proto = IPPROTO_IPIP,
589 : : };
590 : :
591 [ # # ]: 0 : if (m == NULL)
592 : : return NULL;
593 : :
594 : 0 : memset(m->buf_addr, 0, m->buf_len);
595 : : char *dst = rte_pktmbuf_append(m, t_len);
596 : :
597 [ # # ]: 0 : if (!dst) {
598 : 0 : rte_pktmbuf_free(m);
599 : 0 : return NULL;
600 : : }
601 : : /* copy outer IP and ESP header */
602 [ # # ]: 0 : ipv4_outer.total_length = rte_cpu_to_be_16(t_len);
603 [ # # # # ]: 0 : ipv4_outer.packet_id = rte_cpu_to_be_16(seq);
604 : : rte_memcpy(dst, &ipv4_outer, sizeof(ipv4_outer));
605 : 0 : dst += sizeof(ipv4_outer);
606 [ # # ]: 0 : m->l3_len = sizeof(ipv4_outer);
607 : : rte_memcpy(dst, &esph, sizeof(esph));
608 : 0 : dst += sizeof(esph);
609 : :
610 [ # # ]: 0 : if (string != NULL) {
611 : : /* copy payload */
612 : : rte_memcpy(dst, string, len);
613 : 0 : dst += len;
614 : : /* copy pad bytes */
615 [ # # ]: 0 : rte_memcpy(dst, esp_pad_bytes, RTE_MIN(padlen,
616 : : sizeof(esp_pad_bytes)));
617 [ # # ]: 0 : dst += padlen;
618 : : /* copy ESP tail header */
619 : : rte_memcpy(dst, &espt, sizeof(espt));
620 : : } else
621 : 0 : memset(dst, 0, t_len);
622 : :
623 : : return m;
624 : : }
625 : :
626 : : static int
627 : : create_dummy_sec_session(struct ipsec_unitest_params *ut,
628 : : struct rte_cryptodev_qp_conf *qp, uint32_t j)
629 : : {
630 : : static struct rte_security_session_conf conf;
631 : :
632 : 0 : ut->ss[j].security.ses = rte_security_session_create(&dummy_sec_ctx,
633 : : &conf, qp->mp_session);
634 : :
635 [ # # ]: 0 : if (ut->ss[j].security.ses == NULL)
636 : : return -ENOMEM;
637 : :
638 : 0 : ut->ss[j].security.ctx = &dummy_sec_ctx;
639 : 0 : ut->ss[j].security.ol_flags = 0;
640 : 0 : return 0;
641 : : }
642 : :
643 : : static int
644 : : create_crypto_session(struct ipsec_unitest_params *ut,
645 : : struct rte_cryptodev_qp_conf *qp, uint8_t dev_id, uint32_t j)
646 : : {
647 : : void *s;
648 : :
649 : 0 : s = rte_cryptodev_sym_session_create(dev_id, ut->crypto_xforms,
650 : : qp->mp_session);
651 [ # # ]: 0 : if (s == NULL)
652 : : return -ENOMEM;
653 : :
654 : 0 : ut->ss[j].crypto.ses = s;
655 : 0 : return 0;
656 : : }
657 : :
658 : : static int
659 : 0 : create_session(struct ipsec_unitest_params *ut,
660 : : struct rte_cryptodev_qp_conf *qp, uint8_t crypto_dev, uint32_t j)
661 : : {
662 [ # # ]: 0 : if (ut->ss[j].type == RTE_SECURITY_ACTION_TYPE_NONE)
663 : 0 : return create_crypto_session(ut, qp, crypto_dev, j);
664 : : else
665 : 0 : return create_dummy_sec_session(ut, qp, j);
666 : : }
667 : :
668 : : static int
669 : 0 : fill_ipsec_param(uint32_t replay_win_sz, uint64_t flags)
670 : : {
671 : : struct ipsec_unitest_params *ut_params = &unittest_params;
672 : : struct rte_ipsec_sa_prm *prm = &ut_params->sa_prm;
673 : : const struct supported_auth_algo *auth_algo;
674 : : const struct supported_cipher_algo *cipher_algo;
675 : :
676 : : memset(prm, 0, sizeof(*prm));
677 : :
678 : 0 : prm->userdata = 1;
679 : 0 : prm->flags = flags;
680 : :
681 : : /* setup ipsec xform */
682 : 0 : prm->ipsec_xform = ut_params->ipsec_xform;
683 : 0 : prm->ipsec_xform.salt = (uint32_t)rte_rand();
684 : 0 : prm->ipsec_xform.replay_win_sz = replay_win_sz;
685 : :
686 : : /* setup tunnel related fields */
687 : 0 : prm->tun.hdr_len = sizeof(ipv4_outer);
688 : 0 : prm->tun.next_proto = IPPROTO_IPIP;
689 : 0 : prm->tun.hdr = &ipv4_outer;
690 : :
691 : : /* setup crypto section */
692 [ # # ]: 0 : if (uparams.aead != 0) {
693 : : /* TODO: will need to fill out with other test cases */
694 : : } else {
695 [ # # # # ]: 0 : if (uparams.auth == 0 && uparams.cipher == 0)
696 : : return TEST_FAILED;
697 : :
698 : : auth_algo = find_match_auth_algo(uparams.auth_algo);
699 : : cipher_algo = find_match_cipher_algo(uparams.cipher_algo);
700 : :
701 : : fill_crypto_xform(ut_params, auth_algo, cipher_algo);
702 : : }
703 : :
704 : 0 : prm->crypto_xform = ut_params->crypto_xforms;
705 : 0 : return TEST_SUCCESS;
706 : : }
707 : :
708 : : static int
709 : 0 : create_sa(enum rte_security_session_action_type action_type,
710 : : uint32_t replay_win_sz, uint64_t flags, uint32_t j)
711 : : {
712 : : struct ipsec_testsuite_params *ts = &testsuite_params;
713 : : struct ipsec_unitest_params *ut = &unittest_params;
714 : : size_t sz;
715 : : int rc;
716 : :
717 : 0 : memset(&ut->ss[j], 0, sizeof(ut->ss[j]));
718 : :
719 : 0 : rc = fill_ipsec_param(replay_win_sz, flags);
720 [ # # ]: 0 : if (rc != 0)
721 : : return TEST_FAILED;
722 : :
723 : : /* create rte_ipsec_sa*/
724 : 0 : sz = rte_ipsec_sa_size(&ut->sa_prm);
725 [ # # ]: 0 : TEST_ASSERT(sz > 0, "rte_ipsec_sa_size() failed\n");
726 : :
727 : 0 : ut->ss[j].sa = rte_zmalloc(NULL, sz, RTE_CACHE_LINE_SIZE);
728 [ # # ]: 0 : TEST_ASSERT_NOT_NULL(ut->ss[j].sa,
729 : : "failed to allocate memory for rte_ipsec_sa\n");
730 : :
731 : 0 : ut->ss[j].type = action_type;
732 : 0 : rc = create_session(ut, &ts->qp_conf, ts->valid_dev, j);
733 [ # # ]: 0 : if (rc != 0)
734 : : return rc;
735 : :
736 : 0 : rc = rte_ipsec_sa_init(ut->ss[j].sa, &ut->sa_prm, sz);
737 [ # # # # ]: 0 : rc = (rc > 0 && (uint32_t)rc <= sz) ? 0 : -EINVAL;
738 : : if (rc == 0)
739 : 0 : rc = rte_ipsec_session_prepare(&ut->ss[j]);
740 : :
741 : : return rc;
742 : : }
743 : :
744 : : static int
745 : 0 : crypto_dequeue_burst(uint16_t num_pkts)
746 : : {
747 : : struct ipsec_testsuite_params *ts_params = &testsuite_params;
748 : : struct ipsec_unitest_params *ut_params = &unittest_params;
749 : : uint32_t pkt_cnt, k;
750 : : int i;
751 : :
752 : 0 : for (i = 0, pkt_cnt = 0;
753 [ # # # # ]: 0 : i < DEQUEUE_COUNT && pkt_cnt != num_pkts; i++) {
754 : 0 : k = rte_cryptodev_dequeue_burst(ts_params->valid_dev, 0,
755 : 0 : &ut_params->cop[pkt_cnt], num_pkts - pkt_cnt);
756 : 0 : pkt_cnt += k;
757 : 0 : rte_delay_us(1);
758 : : }
759 : :
760 [ # # ]: 0 : if (pkt_cnt != num_pkts) {
761 : 0 : RTE_LOG(ERR, USER1, "rte_cryptodev_dequeue_burst fail\n");
762 : 0 : return TEST_FAILED;
763 : : }
764 : : return TEST_SUCCESS;
765 : : }
766 : :
767 : : static int
768 : 0 : crypto_ipsec(uint16_t num_pkts)
769 : : {
770 : : struct ipsec_testsuite_params *ts_params = &testsuite_params;
771 : : struct ipsec_unitest_params *ut_params = &unittest_params;
772 : : uint32_t k, ng;
773 : : struct rte_ipsec_group grp[1];
774 : :
775 : : /* call crypto prepare */
776 : 0 : k = rte_ipsec_pkt_crypto_prepare(&ut_params->ss[0], ut_params->ibuf,
777 : : ut_params->cop, num_pkts);
778 [ # # ]: 0 : if (k != num_pkts) {
779 : 0 : RTE_LOG(ERR, USER1, "rte_ipsec_pkt_crypto_prepare fail\n");
780 : 0 : return TEST_FAILED;
781 : : }
782 : :
783 : 0 : k = rte_cryptodev_enqueue_burst(ts_params->valid_dev, 0,
784 : : ut_params->cop, num_pkts);
785 [ # # ]: 0 : if (k != num_pkts) {
786 : 0 : RTE_LOG(ERR, USER1, "rte_cryptodev_enqueue_burst fail\n");
787 : 0 : return TEST_FAILED;
788 : : }
789 : :
790 [ # # ]: 0 : if (crypto_dequeue_burst(num_pkts) == TEST_FAILED)
791 : : return TEST_FAILED;
792 : :
793 : 0 : ng = rte_ipsec_pkt_crypto_group(
794 : : (const struct rte_crypto_op **)(uintptr_t)ut_params->cop,
795 : : ut_params->obuf, grp, num_pkts);
796 [ # # ]: 0 : if (ng != 1 ||
797 [ # # ]: 0 : grp[0].m[0] != ut_params->obuf[0] ||
798 [ # # ]: 0 : grp[0].cnt != num_pkts ||
799 [ # # ]: 0 : grp[0].id.ptr != &ut_params->ss[0]) {
800 : 0 : RTE_LOG(ERR, USER1, "rte_ipsec_pkt_crypto_group fail\n");
801 : 0 : return TEST_FAILED;
802 : : }
803 : :
804 : : /* call crypto process */
805 : 0 : k = rte_ipsec_pkt_process(grp[0].id.ptr, grp[0].m, grp[0].cnt);
806 [ # # ]: 0 : if (k != num_pkts) {
807 : 0 : RTE_LOG(ERR, USER1, "rte_ipsec_pkt_process fail\n");
808 : 0 : return TEST_FAILED;
809 : : }
810 : :
811 : : return TEST_SUCCESS;
812 : : }
813 : :
814 : : static int
815 : 0 : lksd_proto_ipsec(uint16_t num_pkts)
816 : : {
817 : : struct ipsec_unitest_params *ut_params = &unittest_params;
818 : : uint32_t i, k, ng;
819 : : struct rte_ipsec_group grp[1];
820 : :
821 : : /* call crypto prepare */
822 : 0 : k = rte_ipsec_pkt_crypto_prepare(&ut_params->ss[0], ut_params->ibuf,
823 : : ut_params->cop, num_pkts);
824 [ # # ]: 0 : if (k != num_pkts) {
825 : 0 : RTE_LOG(ERR, USER1, "rte_ipsec_pkt_crypto_prepare fail\n");
826 : 0 : return TEST_FAILED;
827 : : }
828 : :
829 : : /* check crypto ops */
830 [ # # ]: 0 : for (i = 0; i != num_pkts; i++) {
831 [ # # ]: 0 : TEST_ASSERT_EQUAL(ut_params->cop[i]->type,
832 : : RTE_CRYPTO_OP_TYPE_SYMMETRIC,
833 : : "%s: invalid crypto op type for %u-th packet\n",
834 : : __func__, i);
835 [ # # ]: 0 : TEST_ASSERT_EQUAL(ut_params->cop[i]->status,
836 : : RTE_CRYPTO_OP_STATUS_NOT_PROCESSED,
837 : : "%s: invalid crypto op status for %u-th packet\n",
838 : : __func__, i);
839 [ # # ]: 0 : TEST_ASSERT_EQUAL(ut_params->cop[i]->sess_type,
840 : : RTE_CRYPTO_OP_SECURITY_SESSION,
841 : : "%s: invalid crypto op sess_type for %u-th packet\n",
842 : : __func__, i);
843 [ # # ]: 0 : TEST_ASSERT_EQUAL(ut_params->cop[i]->sym->m_src,
844 : : ut_params->ibuf[i],
845 : : "%s: invalid crypto op m_src for %u-th packet\n",
846 : : __func__, i);
847 : : }
848 : :
849 : : /* update crypto ops, pretend all finished ok */
850 [ # # ]: 0 : for (i = 0; i != num_pkts; i++)
851 : 0 : ut_params->cop[i]->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
852 : :
853 : 0 : ng = rte_ipsec_pkt_crypto_group(
854 : : (const struct rte_crypto_op **)(uintptr_t)ut_params->cop,
855 : : ut_params->obuf, grp, num_pkts);
856 [ # # ]: 0 : if (ng != 1 ||
857 [ # # ]: 0 : grp[0].m[0] != ut_params->obuf[0] ||
858 [ # # ]: 0 : grp[0].cnt != num_pkts ||
859 [ # # ]: 0 : grp[0].id.ptr != &ut_params->ss[0]) {
860 : 0 : RTE_LOG(ERR, USER1, "rte_ipsec_pkt_crypto_group fail\n");
861 : 0 : return TEST_FAILED;
862 : : }
863 : :
864 : : /* call crypto process */
865 : 0 : k = rte_ipsec_pkt_process(grp[0].id.ptr, grp[0].m, grp[0].cnt);
866 [ # # ]: 0 : if (k != num_pkts) {
867 : 0 : RTE_LOG(ERR, USER1, "rte_ipsec_pkt_process fail\n");
868 : 0 : return TEST_FAILED;
869 : : }
870 : :
871 : : return TEST_SUCCESS;
872 : : }
873 : :
874 : : static void
875 : 0 : dump_grp_pkt(uint32_t i, struct rte_ipsec_group *grp, uint32_t k)
876 : : {
877 : 0 : RTE_LOG(ERR, USER1,
878 : : "After rte_ipsec_pkt_process grp[%d].cnt=%d k=%d fail\n",
879 : : i, grp[i].cnt, k);
880 : 0 : RTE_LOG(ERR, USER1,
881 : : "After rte_ipsec_pkt_process grp[%d].m=%p grp[%d].m[%d]=%p\n",
882 : : i, grp[i].m, i, k, grp[i].m[k]);
883 : :
884 : 0 : rte_pktmbuf_dump(stdout, grp[i].m[k], grp[i].m[k]->data_len);
885 : 0 : }
886 : :
887 : : static int
888 : 0 : crypto_ipsec_2sa(void)
889 : : {
890 : : struct ipsec_testsuite_params *ts_params = &testsuite_params;
891 : : struct ipsec_unitest_params *ut_params = &unittest_params;
892 : : struct rte_ipsec_group grp[BURST_SIZE];
893 : : uint32_t k, ng, i, r;
894 : :
895 [ # # ]: 0 : for (i = 0; i < BURST_SIZE; i++) {
896 : 0 : r = i % 2;
897 : : /* call crypto prepare */
898 : 0 : k = rte_ipsec_pkt_crypto_prepare(&ut_params->ss[r],
899 : 0 : ut_params->ibuf + i, ut_params->cop + i, 1);
900 [ # # ]: 0 : if (k != 1) {
901 : 0 : RTE_LOG(ERR, USER1,
902 : : "rte_ipsec_pkt_crypto_prepare fail\n");
903 : 0 : return TEST_FAILED;
904 : : }
905 : 0 : k = rte_cryptodev_enqueue_burst(ts_params->valid_dev, 0,
906 : : ut_params->cop + i, 1);
907 [ # # ]: 0 : if (k != 1) {
908 : 0 : RTE_LOG(ERR, USER1,
909 : : "rte_cryptodev_enqueue_burst fail\n");
910 : 0 : return TEST_FAILED;
911 : : }
912 : : }
913 : :
914 [ # # ]: 0 : if (crypto_dequeue_burst(BURST_SIZE) == TEST_FAILED)
915 : : return TEST_FAILED;
916 : :
917 : 0 : ng = rte_ipsec_pkt_crypto_group(
918 : : (const struct rte_crypto_op **)(uintptr_t)ut_params->cop,
919 : : ut_params->obuf, grp, BURST_SIZE);
920 [ # # ]: 0 : if (ng != BURST_SIZE) {
921 : 0 : RTE_LOG(ERR, USER1, "rte_ipsec_pkt_crypto_group fail ng=%d\n",
922 : : ng);
923 : 0 : return TEST_FAILED;
924 : : }
925 : :
926 : : /* call crypto process */
927 [ # # ]: 0 : for (i = 0; i < ng; i++) {
928 : 0 : k = rte_ipsec_pkt_process(grp[i].id.ptr, grp[i].m, grp[i].cnt);
929 [ # # ]: 0 : if (k != grp[i].cnt) {
930 : 0 : dump_grp_pkt(i, grp, k);
931 : 0 : return TEST_FAILED;
932 : : }
933 : : }
934 : : return TEST_SUCCESS;
935 : : }
936 : :
937 : : #define PKT_4 4
938 : : #define PKT_12 12
939 : : #define PKT_21 21
940 : :
941 : : static uint32_t
942 : : crypto_ipsec_4grp(uint32_t pkt_num)
943 : : {
944 : : uint32_t sa_ind;
945 : :
946 : : /* group packets in 4 different size groups, 2 per SA */
947 [ # # ]: 0 : if (pkt_num < PKT_4)
948 : : sa_ind = 0;
949 [ # # # # ]: 0 : else if (pkt_num < PKT_12)
950 : : sa_ind = 1;
951 [ # # # # ]: 0 : else if (pkt_num < PKT_21)
952 : : sa_ind = 0;
953 : : else
954 : : sa_ind = 1;
955 : :
956 : : return sa_ind;
957 : : }
958 : :
959 : : static uint32_t
960 : 0 : crypto_ipsec_4grp_check_mbufs(uint32_t grp_ind, struct rte_ipsec_group *grp)
961 : : {
962 : : struct ipsec_unitest_params *ut_params = &unittest_params;
963 : : uint32_t i, j;
964 : : uint32_t rc = 0;
965 : :
966 [ # # ]: 0 : if (grp_ind == 0) {
967 [ # # ]: 0 : for (i = 0, j = 0; i < PKT_4; i++, j++)
968 [ # # ]: 0 : if (grp[grp_ind].m[i] != ut_params->obuf[j]) {
969 : : rc = TEST_FAILED;
970 : : break;
971 : : }
972 [ # # ]: 0 : } else if (grp_ind == 1) {
973 [ # # ]: 0 : for (i = 0, j = PKT_4; i < (PKT_12 - PKT_4); i++, j++) {
974 [ # # ]: 0 : if (grp[grp_ind].m[i] != ut_params->obuf[j]) {
975 : : rc = TEST_FAILED;
976 : : break;
977 : : }
978 : : }
979 [ # # ]: 0 : } else if (grp_ind == 2) {
980 [ # # ]: 0 : for (i = 0, j = PKT_12; i < (PKT_21 - PKT_12); i++, j++)
981 [ # # ]: 0 : if (grp[grp_ind].m[i] != ut_params->obuf[j]) {
982 : : rc = TEST_FAILED;
983 : : break;
984 : : }
985 [ # # ]: 0 : } else if (grp_ind == 3) {
986 [ # # ]: 0 : for (i = 0, j = PKT_21; i < (BURST_SIZE - PKT_21); i++, j++)
987 [ # # ]: 0 : if (grp[grp_ind].m[i] != ut_params->obuf[j]) {
988 : : rc = TEST_FAILED;
989 : : break;
990 : : }
991 : : } else
992 : : rc = TEST_FAILED;
993 : :
994 : 0 : return rc;
995 : : }
996 : :
997 : : static uint32_t
998 : 0 : crypto_ipsec_4grp_check_cnt(uint32_t grp_ind, struct rte_ipsec_group *grp)
999 : : {
1000 : : uint32_t rc = 0;
1001 : :
1002 [ # # ]: 0 : if (grp_ind == 0) {
1003 [ # # ]: 0 : if (grp[grp_ind].cnt != PKT_4)
1004 : : rc = TEST_FAILED;
1005 [ # # ]: 0 : } else if (grp_ind == 1) {
1006 [ # # ]: 0 : if (grp[grp_ind].cnt != PKT_12 - PKT_4)
1007 : : rc = TEST_FAILED;
1008 [ # # ]: 0 : } else if (grp_ind == 2) {
1009 [ # # ]: 0 : if (grp[grp_ind].cnt != PKT_21 - PKT_12)
1010 : : rc = TEST_FAILED;
1011 [ # # ]: 0 : } else if (grp_ind == 3) {
1012 [ # # ]: 0 : if (grp[grp_ind].cnt != BURST_SIZE - PKT_21)
1013 : : rc = TEST_FAILED;
1014 : : } else
1015 : : rc = TEST_FAILED;
1016 : :
1017 : 0 : return rc;
1018 : : }
1019 : :
1020 : : static int
1021 : 0 : crypto_ipsec_2sa_4grp(void)
1022 : : {
1023 : : struct ipsec_testsuite_params *ts_params = &testsuite_params;
1024 : : struct ipsec_unitest_params *ut_params = &unittest_params;
1025 : : struct rte_ipsec_group grp[BURST_SIZE];
1026 : : uint32_t k, ng, i, j;
1027 : : uint32_t rc = 0;
1028 : :
1029 [ # # ]: 0 : for (i = 0; i < BURST_SIZE; i++) {
1030 : : j = crypto_ipsec_4grp(i);
1031 : :
1032 : : /* call crypto prepare */
1033 : 0 : k = rte_ipsec_pkt_crypto_prepare(&ut_params->ss[j],
1034 : 0 : ut_params->ibuf + i, ut_params->cop + i, 1);
1035 [ # # ]: 0 : if (k != 1) {
1036 : 0 : RTE_LOG(ERR, USER1,
1037 : : "rte_ipsec_pkt_crypto_prepare fail\n");
1038 : 0 : return TEST_FAILED;
1039 : : }
1040 : 0 : k = rte_cryptodev_enqueue_burst(ts_params->valid_dev, 0,
1041 : : ut_params->cop + i, 1);
1042 [ # # ]: 0 : if (k != 1) {
1043 : 0 : RTE_LOG(ERR, USER1,
1044 : : "rte_cryptodev_enqueue_burst fail\n");
1045 : 0 : return TEST_FAILED;
1046 : : }
1047 : : }
1048 : :
1049 [ # # ]: 0 : if (crypto_dequeue_burst(BURST_SIZE) == TEST_FAILED)
1050 : : return TEST_FAILED;
1051 : :
1052 : 0 : ng = rte_ipsec_pkt_crypto_group(
1053 : : (const struct rte_crypto_op **)(uintptr_t)ut_params->cop,
1054 : : ut_params->obuf, grp, BURST_SIZE);
1055 [ # # ]: 0 : if (ng != 4) {
1056 : 0 : RTE_LOG(ERR, USER1, "rte_ipsec_pkt_crypto_group fail ng=%d\n",
1057 : : ng);
1058 : 0 : return TEST_FAILED;
1059 : : }
1060 : :
1061 : : /* call crypto process */
1062 [ # # ]: 0 : for (i = 0; i < ng; i++) {
1063 : 0 : k = rte_ipsec_pkt_process(grp[i].id.ptr, grp[i].m, grp[i].cnt);
1064 [ # # ]: 0 : if (k != grp[i].cnt) {
1065 : 0 : dump_grp_pkt(i, grp, k);
1066 : 0 : return TEST_FAILED;
1067 : : }
1068 : 0 : rc = crypto_ipsec_4grp_check_cnt(i, grp);
1069 [ # # ]: 0 : if (rc != 0) {
1070 : 0 : RTE_LOG(ERR, USER1,
1071 : : "crypto_ipsec_4grp_check_cnt fail\n");
1072 : 0 : return TEST_FAILED;
1073 : : }
1074 : 0 : rc = crypto_ipsec_4grp_check_mbufs(i, grp);
1075 [ # # ]: 0 : if (rc != 0) {
1076 : 0 : RTE_LOG(ERR, USER1,
1077 : : "crypto_ipsec_4grp_check_mbufs fail\n");
1078 : 0 : return TEST_FAILED;
1079 : : }
1080 : : }
1081 : : return TEST_SUCCESS;
1082 : : }
1083 : :
1084 : : static void
1085 : 0 : test_ipsec_reorder_inb_pkt_burst(uint16_t num_pkts)
1086 : : {
1087 : : struct ipsec_unitest_params *ut_params = &unittest_params;
1088 : : struct rte_mbuf *ibuf_tmp[BURST_SIZE];
1089 : : uint16_t j;
1090 : :
1091 : : /* reorder packets and create gaps in sequence numbers */
1092 : : static const uint32_t reorder[BURST_SIZE] = {
1093 : : 24, 25, 26, 27, 28, 29, 30, 31,
1094 : : 16, 17, 18, 19, 20, 21, 22, 23,
1095 : : 8, 9, 10, 11, 12, 13, 14, 15,
1096 : : 0, 1, 2, 3, 4, 5, 6, 7,
1097 : : };
1098 : :
1099 [ # # ]: 0 : if (num_pkts != BURST_SIZE)
1100 : 0 : return;
1101 : :
1102 [ # # ]: 0 : for (j = 0; j != BURST_SIZE; j++)
1103 : 0 : ibuf_tmp[j] = ut_params->ibuf[reorder[j]];
1104 : :
1105 : : memcpy(ut_params->ibuf, ibuf_tmp, sizeof(ut_params->ibuf));
1106 : : }
1107 : :
1108 : : static int
1109 : 0 : test_ipsec_crypto_op_alloc(uint16_t num_pkts)
1110 : : {
1111 : : struct ipsec_testsuite_params *ts_params = &testsuite_params;
1112 : : struct ipsec_unitest_params *ut_params = &unittest_params;
1113 : : int rc = 0;
1114 : : uint16_t j;
1115 : :
1116 [ # # ]: 0 : for (j = 0; j < num_pkts && rc == 0; j++) {
1117 : 0 : ut_params->cop[j] = rte_crypto_op_alloc(ts_params->cop_mpool,
1118 : : RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1119 [ # # ]: 0 : if (ut_params->cop[j] == NULL) {
1120 : 0 : RTE_LOG(ERR, USER1,
1121 : : "Failed to allocate symmetric crypto op\n");
1122 : : rc = TEST_FAILED;
1123 : : }
1124 : : }
1125 : :
1126 : 0 : return rc;
1127 : : }
1128 : :
1129 : : static void
1130 : 0 : test_ipsec_dump_buffers(struct ipsec_unitest_params *ut_params, int i)
1131 : : {
1132 : 0 : uint16_t j = ut_params->pkt_index;
1133 : :
1134 : : printf("\ntest config: num %d\n", i);
1135 : 0 : printf(" replay_win_sz %u\n", test_cfg[i].replay_win_sz);
1136 : 0 : printf(" esn %u\n", test_cfg[i].esn);
1137 : 0 : printf(" flags 0x%" PRIx64 "\n", test_cfg[i].flags);
1138 : 0 : printf(" pkt_sz %zu\n", test_cfg[i].pkt_sz);
1139 : 0 : printf(" num_pkts %u\n\n", test_cfg[i].num_pkts);
1140 : :
1141 [ # # ]: 0 : if (ut_params->ibuf[j]) {
1142 : : printf("ibuf[%u] data:\n", j);
1143 : 0 : rte_pktmbuf_dump(stdout, ut_params->ibuf[j],
1144 : 0 : ut_params->ibuf[j]->data_len);
1145 : : }
1146 [ # # ]: 0 : if (ut_params->obuf[j]) {
1147 : : printf("obuf[%u] data:\n", j);
1148 : 0 : rte_pktmbuf_dump(stdout, ut_params->obuf[j],
1149 : 0 : ut_params->obuf[j]->data_len);
1150 : : }
1151 [ # # ]: 0 : if (ut_params->testbuf[j]) {
1152 : : printf("testbuf[%u] data:\n", j);
1153 : 0 : rte_pktmbuf_dump(stdout, ut_params->testbuf[j],
1154 : 0 : ut_params->testbuf[j]->data_len);
1155 : : }
1156 : 0 : }
1157 : :
1158 : : static void
1159 : : destroy_dummy_sec_session(struct ipsec_unitest_params *ut,
1160 : : uint32_t j)
1161 : : {
1162 : 0 : rte_security_session_destroy(&dummy_sec_ctx,
1163 : 0 : ut->ss[j].security.ses);
1164 : 0 : ut->ss[j].security.ctx = NULL;
1165 : : }
1166 : :
1167 : : static void
1168 : 0 : destroy_crypto_session(struct ipsec_unitest_params *ut,
1169 : : uint8_t crypto_dev, uint32_t j)
1170 : : {
1171 : 0 : rte_cryptodev_sym_session_free(crypto_dev, ut->ss[j].crypto.ses);
1172 : 0 : memset(&ut->ss[j], 0, sizeof(ut->ss[j]));
1173 : 0 : }
1174 : :
1175 : : static void
1176 : 0 : destroy_session(struct ipsec_unitest_params *ut,
1177 : : uint8_t crypto_dev, uint32_t j)
1178 : : {
1179 [ # # ]: 0 : if (ut->ss[j].type == RTE_SECURITY_ACTION_TYPE_NONE)
1180 : 0 : return destroy_crypto_session(ut, crypto_dev, j);
1181 : : else
1182 : 0 : return destroy_dummy_sec_session(ut, j);
1183 : : }
1184 : :
1185 : : static void
1186 : 0 : destroy_sa(uint32_t j)
1187 : : {
1188 : : struct ipsec_unitest_params *ut = &unittest_params;
1189 : : struct ipsec_testsuite_params *ts = &testsuite_params;
1190 : :
1191 : 0 : rte_ipsec_sa_fini(ut->ss[j].sa);
1192 : 0 : rte_free(ut->ss[j].sa);
1193 : :
1194 : 0 : destroy_session(ut, ts->valid_dev, j);
1195 : 0 : }
1196 : :
1197 : : static int
1198 : 0 : crypto_inb_burst_null_null_check(struct ipsec_unitest_params *ut_params, int i,
1199 : : uint16_t num_pkts)
1200 : : {
1201 : : uint16_t j;
1202 : :
1203 [ # # ]: 0 : for (j = 0; j < num_pkts && num_pkts <= BURST_SIZE; j++) {
1204 : 0 : ut_params->pkt_index = j;
1205 : :
1206 : : /* compare the data buffers */
1207 [ # # ]: 0 : TEST_ASSERT_BUFFERS_ARE_EQUAL(null_plain_data,
1208 : : rte_pktmbuf_mtod(ut_params->obuf[j], void *),
1209 : : test_cfg[i].pkt_sz,
1210 : : "input and output data does not match\n");
1211 [ # # ]: 0 : TEST_ASSERT_EQUAL(ut_params->obuf[j]->data_len,
1212 : : ut_params->obuf[j]->pkt_len,
1213 : : "data_len is not equal to pkt_len");
1214 [ # # ]: 0 : TEST_ASSERT_EQUAL(ut_params->obuf[j]->data_len,
1215 : : test_cfg[i].pkt_sz,
1216 : : "data_len is not equal to input data");
1217 : : }
1218 : :
1219 : : return 0;
1220 : : }
1221 : :
1222 : : static int
1223 : 0 : test_ipsec_crypto_inb_burst_null_null(int i)
1224 : : {
1225 : : struct ipsec_testsuite_params *ts_params = &testsuite_params;
1226 : : struct ipsec_unitest_params *ut_params = &unittest_params;
1227 : 0 : uint16_t num_pkts = test_cfg[i].num_pkts;
1228 : : uint16_t j;
1229 : : int rc;
1230 : :
1231 : : /* create rte_ipsec_sa */
1232 : 0 : rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
1233 : 0 : test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1234 [ # # ]: 0 : if (rc != 0) {
1235 : 0 : RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
1236 : 0 : return rc;
1237 : : }
1238 : :
1239 : : /* Generate test mbuf data */
1240 [ # # ]: 0 : for (j = 0; j < num_pkts && rc == 0; j++) {
1241 : : /* packet with sequence number 0 is invalid */
1242 : 0 : ut_params->ibuf[j] = setup_test_string_tunneled(
1243 : : ts_params->mbuf_pool, null_encrypted_data,
1244 : 0 : test_cfg[i].pkt_sz, INBOUND_SPI, j + 1);
1245 [ # # ]: 0 : if (ut_params->ibuf[j] == NULL)
1246 : : rc = TEST_FAILED;
1247 : : }
1248 : :
1249 [ # # ]: 0 : if (rc == 0) {
1250 [ # # ]: 0 : if (test_cfg[i].reorder_pkts)
1251 : 0 : test_ipsec_reorder_inb_pkt_burst(num_pkts);
1252 : 0 : rc = test_ipsec_crypto_op_alloc(num_pkts);
1253 : : }
1254 : :
1255 [ # # ]: 0 : if (rc == 0) {
1256 : : /* call ipsec library api */
1257 : 0 : rc = crypto_ipsec(num_pkts);
1258 [ # # ]: 0 : if (rc == 0)
1259 : 0 : rc = crypto_inb_burst_null_null_check(
1260 : : ut_params, i, num_pkts);
1261 : : else {
1262 : 0 : RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
1263 : : i);
1264 : : rc = TEST_FAILED;
1265 : : }
1266 : : }
1267 : :
1268 [ # # ]: 0 : if (rc == TEST_FAILED)
1269 : 0 : test_ipsec_dump_buffers(ut_params, i);
1270 : :
1271 : 0 : destroy_sa(0);
1272 : 0 : return rc;
1273 : : }
1274 : :
1275 : : static int
1276 : 0 : test_ipsec_crypto_inb_burst_null_null_wrapper(void)
1277 : : {
1278 : : int i;
1279 : : int rc = 0;
1280 : : struct ipsec_unitest_params *ut_params = &unittest_params;
1281 : :
1282 : 0 : ut_params->ipsec_xform.spi = INBOUND_SPI;
1283 : 0 : ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
1284 : 0 : ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1285 : 0 : ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1286 : 0 : ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1287 : :
1288 [ # # ]: 0 : for (i = 0; i < num_cfg && rc == 0; i++) {
1289 : 0 : ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1290 : 0 : rc = test_ipsec_crypto_inb_burst_null_null(i);
1291 : : }
1292 : :
1293 : 0 : return rc;
1294 : : }
1295 : :
1296 : : static int
1297 : 0 : crypto_outb_burst_null_null_check(struct ipsec_unitest_params *ut_params,
1298 : : uint16_t num_pkts)
1299 : : {
1300 : : void *obuf_data;
1301 : : void *testbuf_data;
1302 : : uint16_t j;
1303 : :
1304 [ # # ]: 0 : for (j = 0; j < num_pkts && num_pkts <= BURST_SIZE; j++) {
1305 : 0 : ut_params->pkt_index = j;
1306 : :
1307 : 0 : testbuf_data = rte_pktmbuf_mtod(ut_params->testbuf[j], void *);
1308 : 0 : obuf_data = rte_pktmbuf_mtod(ut_params->obuf[j], void *);
1309 : : /* compare the buffer data */
1310 [ # # ]: 0 : TEST_ASSERT_BUFFERS_ARE_EQUAL(testbuf_data, obuf_data,
1311 : : ut_params->obuf[j]->pkt_len,
1312 : : "test and output data does not match\n");
1313 [ # # ]: 0 : TEST_ASSERT_EQUAL(ut_params->obuf[j]->data_len,
1314 : : ut_params->testbuf[j]->data_len,
1315 : : "obuf data_len is not equal to testbuf data_len");
1316 [ # # ]: 0 : TEST_ASSERT_EQUAL(ut_params->obuf[j]->pkt_len,
1317 : : ut_params->testbuf[j]->pkt_len,
1318 : : "obuf pkt_len is not equal to testbuf pkt_len");
1319 : : }
1320 : :
1321 : : return 0;
1322 : : }
1323 : :
1324 : : static int
1325 : 0 : test_ipsec_crypto_outb_burst_null_null(int i)
1326 : : {
1327 : : struct ipsec_testsuite_params *ts_params = &testsuite_params;
1328 : : struct ipsec_unitest_params *ut_params = &unittest_params;
1329 : 0 : uint16_t num_pkts = test_cfg[i].num_pkts;
1330 : : uint16_t j;
1331 : : int32_t rc;
1332 : :
1333 : : /* create rte_ipsec_sa*/
1334 : 0 : rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
1335 : 0 : test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1336 [ # # ]: 0 : if (rc != 0) {
1337 : 0 : RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
1338 : 0 : return rc;
1339 : : }
1340 : :
1341 : : /* Generate input mbuf data */
1342 [ # # ]: 0 : for (j = 0; j < num_pkts && rc == 0; j++) {
1343 : 0 : ut_params->ibuf[j] = setup_test_string(ts_params->mbuf_pool,
1344 : : null_plain_data, sizeof(null_plain_data),
1345 : 0 : test_cfg[i].pkt_sz, 0);
1346 [ # # ]: 0 : if (ut_params->ibuf[j] == NULL)
1347 : : rc = TEST_FAILED;
1348 : : else {
1349 : : /* Generate test mbuf data */
1350 : : /* packet with sequence number 0 is invalid */
1351 : 0 : ut_params->testbuf[j] = setup_test_string_tunneled(
1352 : : ts_params->mbuf_pool,
1353 : : null_plain_data, test_cfg[i].pkt_sz,
1354 : 0 : OUTBOUND_SPI, j + 1);
1355 [ # # ]: 0 : if (ut_params->testbuf[j] == NULL)
1356 : : rc = TEST_FAILED;
1357 : : }
1358 : : }
1359 : :
1360 [ # # ]: 0 : if (rc == 0)
1361 : 0 : rc = test_ipsec_crypto_op_alloc(num_pkts);
1362 : :
1363 [ # # ]: 0 : if (rc == 0) {
1364 : : /* call ipsec library api */
1365 : 0 : rc = crypto_ipsec(num_pkts);
1366 [ # # ]: 0 : if (rc == 0)
1367 : 0 : rc = crypto_outb_burst_null_null_check(ut_params,
1368 : : num_pkts);
1369 : : else
1370 : 0 : RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
1371 : : i);
1372 : : }
1373 : :
1374 [ # # ]: 0 : if (rc == TEST_FAILED)
1375 : 0 : test_ipsec_dump_buffers(ut_params, i);
1376 : :
1377 : 0 : destroy_sa(0);
1378 : 0 : return rc;
1379 : : }
1380 : :
1381 : : static int
1382 : 0 : test_ipsec_crypto_outb_burst_null_null_wrapper(void)
1383 : : {
1384 : : int i;
1385 : : int rc = 0;
1386 : : struct ipsec_unitest_params *ut_params = &unittest_params;
1387 : :
1388 : 0 : ut_params->ipsec_xform.spi = OUTBOUND_SPI;
1389 : 0 : ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS;
1390 : 0 : ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1391 : 0 : ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1392 : 0 : ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1393 : :
1394 [ # # ]: 0 : for (i = 0; i < num_cfg && rc == 0; i++) {
1395 : 0 : ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1396 : 0 : rc = test_ipsec_crypto_outb_burst_null_null(i);
1397 : : }
1398 : :
1399 : 0 : return rc;
1400 : : }
1401 : :
1402 : : static int
1403 : 0 : inline_inb_burst_null_null_check(struct ipsec_unitest_params *ut_params, int i,
1404 : : uint16_t num_pkts)
1405 : : {
1406 : : void *ibuf_data;
1407 : : void *obuf_data;
1408 : : uint16_t j;
1409 : :
1410 [ # # ]: 0 : for (j = 0; j < num_pkts && num_pkts <= BURST_SIZE; j++) {
1411 : 0 : ut_params->pkt_index = j;
1412 : :
1413 : : /* compare the buffer data */
1414 : 0 : ibuf_data = rte_pktmbuf_mtod(ut_params->ibuf[j], void *);
1415 : 0 : obuf_data = rte_pktmbuf_mtod(ut_params->obuf[j], void *);
1416 : :
1417 [ # # ]: 0 : TEST_ASSERT_BUFFERS_ARE_EQUAL(ibuf_data, obuf_data,
1418 : : ut_params->ibuf[j]->data_len,
1419 : : "input and output data does not match\n");
1420 [ # # ]: 0 : TEST_ASSERT_EQUAL(ut_params->ibuf[j]->data_len,
1421 : : ut_params->obuf[j]->data_len,
1422 : : "ibuf data_len is not equal to obuf data_len");
1423 [ # # ]: 0 : TEST_ASSERT_EQUAL(ut_params->ibuf[j]->pkt_len,
1424 : : ut_params->obuf[j]->pkt_len,
1425 : : "ibuf pkt_len is not equal to obuf pkt_len");
1426 [ # # ]: 0 : TEST_ASSERT_EQUAL(ut_params->ibuf[j]->data_len,
1427 : : test_cfg[i].pkt_sz,
1428 : : "data_len is not equal input data");
1429 : : }
1430 : : return 0;
1431 : : }
1432 : :
1433 : : static int
1434 : 0 : test_ipsec_inline_crypto_inb_burst_null_null(int i)
1435 : : {
1436 : : struct ipsec_testsuite_params *ts_params = &testsuite_params;
1437 : : struct ipsec_unitest_params *ut_params = &unittest_params;
1438 : 0 : uint16_t num_pkts = test_cfg[i].num_pkts;
1439 : : uint16_t j;
1440 : : int32_t rc;
1441 : : uint32_t n;
1442 : :
1443 : : /* create rte_ipsec_sa*/
1444 : 0 : rc = create_sa(RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO,
1445 : 0 : test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1446 [ # # ]: 0 : if (rc != 0) {
1447 : 0 : RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
1448 : 0 : return rc;
1449 : : }
1450 : :
1451 : : /* Generate inbound mbuf data */
1452 [ # # ]: 0 : for (j = 0; j < num_pkts && rc == 0; j++) {
1453 : 0 : ut_params->ibuf[j] = setup_test_string_tunneled(
1454 : : ts_params->mbuf_pool,
1455 : 0 : null_plain_data, test_cfg[i].pkt_sz,
1456 : 0 : INBOUND_SPI, j + 1);
1457 [ # # ]: 0 : if (ut_params->ibuf[j] == NULL)
1458 : : rc = TEST_FAILED;
1459 : : else {
1460 : : /* Generate test mbuf data */
1461 : 0 : ut_params->obuf[j] = setup_test_string(
1462 : : ts_params->mbuf_pool,
1463 : : null_plain_data, sizeof(null_plain_data),
1464 : : test_cfg[i].pkt_sz, 0);
1465 [ # # ]: 0 : if (ut_params->obuf[j] == NULL)
1466 : : rc = TEST_FAILED;
1467 : : }
1468 : : }
1469 : :
1470 [ # # ]: 0 : if (rc == 0) {
1471 : 0 : n = rte_ipsec_pkt_process(&ut_params->ss[0], ut_params->ibuf,
1472 : : num_pkts);
1473 [ # # ]: 0 : if (n == num_pkts)
1474 : 0 : rc = inline_inb_burst_null_null_check(ut_params, i,
1475 : : num_pkts);
1476 : : else {
1477 : 0 : RTE_LOG(ERR, USER1,
1478 : : "rte_ipsec_pkt_process failed, cfg %d\n",
1479 : : i);
1480 : : rc = TEST_FAILED;
1481 : : }
1482 : : }
1483 : :
1484 [ # # ]: 0 : if (rc == TEST_FAILED)
1485 : 0 : test_ipsec_dump_buffers(ut_params, i);
1486 : :
1487 : 0 : destroy_sa(0);
1488 : 0 : return rc;
1489 : : }
1490 : :
1491 : : static int
1492 : 0 : test_ipsec_inline_crypto_inb_burst_null_null_wrapper(void)
1493 : : {
1494 : : int i;
1495 : : int rc = 0;
1496 : : struct ipsec_unitest_params *ut_params = &unittest_params;
1497 : :
1498 : 0 : ut_params->ipsec_xform.spi = INBOUND_SPI;
1499 : 0 : ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
1500 : 0 : ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1501 : 0 : ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1502 : 0 : ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1503 : :
1504 [ # # ]: 0 : for (i = 0; i < num_cfg && rc == 0; i++) {
1505 : 0 : ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1506 : 0 : rc = test_ipsec_inline_crypto_inb_burst_null_null(i);
1507 : : }
1508 : :
1509 : 0 : return rc;
1510 : : }
1511 : :
1512 : : static int
1513 : 0 : test_ipsec_inline_proto_inb_burst_null_null(int i)
1514 : : {
1515 : : struct ipsec_testsuite_params *ts_params = &testsuite_params;
1516 : : struct ipsec_unitest_params *ut_params = &unittest_params;
1517 : 0 : uint16_t num_pkts = test_cfg[i].num_pkts;
1518 : : uint16_t j;
1519 : : int32_t rc;
1520 : : uint32_t n;
1521 : :
1522 : : /* create rte_ipsec_sa*/
1523 : 0 : rc = create_sa(RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL,
1524 : 0 : test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1525 [ # # ]: 0 : if (rc != 0) {
1526 : 0 : RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
1527 : 0 : return rc;
1528 : : }
1529 : :
1530 : : /* Generate inbound mbuf data */
1531 [ # # ]: 0 : for (j = 0; j < num_pkts && rc == 0; j++) {
1532 : 0 : ut_params->ibuf[j] = setup_test_string(ts_params->mbuf_pool,
1533 : : null_plain_data, sizeof(null_plain_data),
1534 : 0 : test_cfg[i].pkt_sz, 0);
1535 [ # # ]: 0 : if (ut_params->ibuf[j] == NULL)
1536 : : rc = TEST_FAILED;
1537 : : else {
1538 : : /* Generate test mbuf data */
1539 : 0 : ut_params->obuf[j] = setup_test_string(
1540 : : ts_params->mbuf_pool,
1541 : : null_plain_data, sizeof(null_plain_data),
1542 : : test_cfg[i].pkt_sz, 0);
1543 [ # # ]: 0 : if (ut_params->obuf[j] == NULL)
1544 : : rc = TEST_FAILED;
1545 : : }
1546 : : }
1547 : :
1548 [ # # ]: 0 : if (rc == 0) {
1549 : 0 : n = rte_ipsec_pkt_process(&ut_params->ss[0], ut_params->ibuf,
1550 : : num_pkts);
1551 [ # # ]: 0 : if (n == num_pkts)
1552 : 0 : rc = inline_inb_burst_null_null_check(ut_params, i,
1553 : : num_pkts);
1554 : : else {
1555 : 0 : RTE_LOG(ERR, USER1,
1556 : : "rte_ipsec_pkt_process failed, cfg %d\n",
1557 : : i);
1558 : : rc = TEST_FAILED;
1559 : : }
1560 : : }
1561 : :
1562 [ # # ]: 0 : if (rc == TEST_FAILED)
1563 : 0 : test_ipsec_dump_buffers(ut_params, i);
1564 : :
1565 : 0 : destroy_sa(0);
1566 : 0 : return rc;
1567 : : }
1568 : :
1569 : : static int
1570 : 0 : test_ipsec_inline_proto_inb_burst_null_null_wrapper(void)
1571 : : {
1572 : : int i;
1573 : : int rc = 0;
1574 : : struct ipsec_unitest_params *ut_params = &unittest_params;
1575 : :
1576 : 0 : ut_params->ipsec_xform.spi = INBOUND_SPI;
1577 : 0 : ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
1578 : 0 : ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1579 : 0 : ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1580 : 0 : ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1581 : :
1582 [ # # ]: 0 : for (i = 0; i < num_cfg && rc == 0; i++) {
1583 : 0 : ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1584 : 0 : rc = test_ipsec_inline_proto_inb_burst_null_null(i);
1585 : : }
1586 : :
1587 : 0 : return rc;
1588 : : }
1589 : :
1590 : : static int
1591 : 0 : inline_outb_burst_null_null_check(struct ipsec_unitest_params *ut_params,
1592 : : uint16_t num_pkts)
1593 : : {
1594 : : void *obuf_data;
1595 : : void *ibuf_data;
1596 : : uint16_t j;
1597 : :
1598 [ # # ]: 0 : for (j = 0; j < num_pkts && num_pkts <= BURST_SIZE; j++) {
1599 : 0 : ut_params->pkt_index = j;
1600 : :
1601 : : /* compare the buffer data */
1602 : 0 : ibuf_data = rte_pktmbuf_mtod(ut_params->ibuf[j], void *);
1603 : 0 : obuf_data = rte_pktmbuf_mtod(ut_params->obuf[j], void *);
1604 [ # # ]: 0 : TEST_ASSERT_BUFFERS_ARE_EQUAL(ibuf_data, obuf_data,
1605 : : ut_params->ibuf[j]->data_len,
1606 : : "input and output data does not match\n");
1607 [ # # ]: 0 : TEST_ASSERT_EQUAL(ut_params->ibuf[j]->data_len,
1608 : : ut_params->obuf[j]->data_len,
1609 : : "ibuf data_len is not equal to obuf data_len");
1610 [ # # ]: 0 : TEST_ASSERT_EQUAL(ut_params->ibuf[j]->pkt_len,
1611 : : ut_params->obuf[j]->pkt_len,
1612 : : "ibuf pkt_len is not equal to obuf pkt_len");
1613 : :
1614 : : /* check mbuf ol_flags */
1615 [ # # ]: 0 : TEST_ASSERT(ut_params->ibuf[j]->ol_flags & RTE_MBUF_F_TX_SEC_OFFLOAD,
1616 : : "ibuf RTE_MBUF_F_TX_SEC_OFFLOAD is not set");
1617 : : }
1618 : : return 0;
1619 : : }
1620 : :
1621 : : static int
1622 : 0 : test_ipsec_inline_crypto_outb_burst_null_null(int i)
1623 : : {
1624 : : struct ipsec_testsuite_params *ts_params = &testsuite_params;
1625 : : struct ipsec_unitest_params *ut_params = &unittest_params;
1626 : 0 : uint16_t num_pkts = test_cfg[i].num_pkts;
1627 : : uint16_t j;
1628 : : int32_t rc;
1629 : : uint32_t n;
1630 : :
1631 : : /* create rte_ipsec_sa */
1632 : 0 : rc = create_sa(RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO,
1633 : 0 : test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1634 [ # # ]: 0 : if (rc != 0) {
1635 : 0 : RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
1636 : 0 : return rc;
1637 : : }
1638 : :
1639 : : /* Generate test mbuf data */
1640 [ # # ]: 0 : for (j = 0; j < num_pkts && rc == 0; j++) {
1641 : 0 : ut_params->ibuf[j] = setup_test_string(ts_params->mbuf_pool,
1642 : : null_plain_data, sizeof(null_plain_data),
1643 : 0 : test_cfg[i].pkt_sz, 0);
1644 [ # # ]: 0 : if (ut_params->ibuf[0] == NULL)
1645 : : rc = TEST_FAILED;
1646 : :
1647 : : if (rc == 0) {
1648 : : /* Generate test tunneled mbuf data for comparison */
1649 : 0 : ut_params->obuf[j] = setup_test_string_tunneled(
1650 : : ts_params->mbuf_pool,
1651 : : null_plain_data, test_cfg[i].pkt_sz,
1652 : 0 : OUTBOUND_SPI, j + 1);
1653 [ # # ]: 0 : if (ut_params->obuf[j] == NULL)
1654 : : rc = TEST_FAILED;
1655 : : }
1656 : : }
1657 : :
1658 [ # # ]: 0 : if (rc == 0) {
1659 : 0 : n = rte_ipsec_pkt_process(&ut_params->ss[0], ut_params->ibuf,
1660 : : num_pkts);
1661 [ # # ]: 0 : if (n == num_pkts)
1662 : 0 : rc = inline_outb_burst_null_null_check(ut_params,
1663 : : num_pkts);
1664 : : else {
1665 : 0 : RTE_LOG(ERR, USER1,
1666 : : "rte_ipsec_pkt_process failed, cfg %d\n",
1667 : : i);
1668 : : rc = TEST_FAILED;
1669 : : }
1670 : : }
1671 : :
1672 [ # # ]: 0 : if (rc == TEST_FAILED)
1673 : 0 : test_ipsec_dump_buffers(ut_params, i);
1674 : :
1675 : 0 : destroy_sa(0);
1676 : 0 : return rc;
1677 : : }
1678 : :
1679 : : static int
1680 : 0 : test_ipsec_inline_crypto_outb_burst_null_null_wrapper(void)
1681 : : {
1682 : : int i;
1683 : : int rc = 0;
1684 : : struct ipsec_unitest_params *ut_params = &unittest_params;
1685 : :
1686 : 0 : ut_params->ipsec_xform.spi = OUTBOUND_SPI;
1687 : 0 : ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS;
1688 : 0 : ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1689 : 0 : ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1690 : 0 : ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1691 : :
1692 [ # # ]: 0 : for (i = 0; i < num_cfg && rc == 0; i++) {
1693 : 0 : ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1694 : 0 : rc = test_ipsec_inline_crypto_outb_burst_null_null(i);
1695 : : }
1696 : :
1697 : 0 : return rc;
1698 : : }
1699 : :
1700 : : static int
1701 : 0 : test_ipsec_inline_proto_outb_burst_null_null(int i)
1702 : : {
1703 : : struct ipsec_testsuite_params *ts_params = &testsuite_params;
1704 : : struct ipsec_unitest_params *ut_params = &unittest_params;
1705 : 0 : uint16_t num_pkts = test_cfg[i].num_pkts;
1706 : : uint16_t j;
1707 : : int32_t rc;
1708 : : uint32_t n;
1709 : :
1710 : : /* create rte_ipsec_sa */
1711 : 0 : rc = create_sa(RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL,
1712 : 0 : test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1713 [ # # ]: 0 : if (rc != 0) {
1714 : 0 : RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
1715 : 0 : return rc;
1716 : : }
1717 : :
1718 : : /* Generate test mbuf data */
1719 [ # # ]: 0 : for (j = 0; j < num_pkts && rc == 0; j++) {
1720 : 0 : ut_params->ibuf[j] = setup_test_string(ts_params->mbuf_pool,
1721 : : null_plain_data, sizeof(null_plain_data),
1722 : 0 : test_cfg[i].pkt_sz, 0);
1723 [ # # ]: 0 : if (ut_params->ibuf[0] == NULL)
1724 : : rc = TEST_FAILED;
1725 : :
1726 : : if (rc == 0) {
1727 : : /* Generate test tunneled mbuf data for comparison */
1728 : 0 : ut_params->obuf[j] = setup_test_string(
1729 : : ts_params->mbuf_pool, null_plain_data,
1730 : : sizeof(null_plain_data), test_cfg[i].pkt_sz,
1731 : : 0);
1732 [ # # ]: 0 : if (ut_params->obuf[j] == NULL)
1733 : : rc = TEST_FAILED;
1734 : : }
1735 : : }
1736 : :
1737 [ # # ]: 0 : if (rc == 0) {
1738 : 0 : n = rte_ipsec_pkt_process(&ut_params->ss[0], ut_params->ibuf,
1739 : : num_pkts);
1740 [ # # ]: 0 : if (n == num_pkts)
1741 : 0 : rc = inline_outb_burst_null_null_check(ut_params,
1742 : : num_pkts);
1743 : : else {
1744 : 0 : RTE_LOG(ERR, USER1,
1745 : : "rte_ipsec_pkt_process failed, cfg %d\n",
1746 : : i);
1747 : : rc = TEST_FAILED;
1748 : : }
1749 : : }
1750 : :
1751 [ # # ]: 0 : if (rc == TEST_FAILED)
1752 : 0 : test_ipsec_dump_buffers(ut_params, i);
1753 : :
1754 : 0 : destroy_sa(0);
1755 : 0 : return rc;
1756 : : }
1757 : :
1758 : : static int
1759 : 0 : test_ipsec_inline_proto_outb_burst_null_null_wrapper(void)
1760 : : {
1761 : : int i;
1762 : : int rc = 0;
1763 : : struct ipsec_unitest_params *ut_params = &unittest_params;
1764 : :
1765 : 0 : ut_params->ipsec_xform.spi = OUTBOUND_SPI;
1766 : 0 : ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS;
1767 : 0 : ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1768 : 0 : ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1769 : 0 : ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1770 : :
1771 [ # # ]: 0 : for (i = 0; i < num_cfg && rc == 0; i++) {
1772 : 0 : ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1773 : 0 : rc = test_ipsec_inline_proto_outb_burst_null_null(i);
1774 : : }
1775 : :
1776 : 0 : return rc;
1777 : : }
1778 : :
1779 : : static int
1780 : 0 : test_ipsec_lksd_proto_inb_burst_null_null(int i)
1781 : : {
1782 : : struct ipsec_testsuite_params *ts_params = &testsuite_params;
1783 : : struct ipsec_unitest_params *ut_params = &unittest_params;
1784 : 0 : uint16_t num_pkts = test_cfg[i].num_pkts;
1785 : : uint16_t j;
1786 : : int rc;
1787 : :
1788 : : /* create rte_ipsec_sa */
1789 : 0 : rc = create_sa(RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
1790 : 0 : test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1791 [ # # ]: 0 : if (rc != 0) {
1792 : 0 : RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
1793 : 0 : return rc;
1794 : : }
1795 : :
1796 : : /* Generate test mbuf data */
1797 [ # # ]: 0 : for (j = 0; j < num_pkts && rc == 0; j++) {
1798 : : /* packet with sequence number 0 is invalid */
1799 : 0 : ut_params->ibuf[j] = setup_test_string(ts_params->mbuf_pool,
1800 : : null_encrypted_data, sizeof(null_encrypted_data),
1801 : 0 : test_cfg[i].pkt_sz, 0);
1802 [ # # ]: 0 : if (ut_params->ibuf[j] == NULL)
1803 : : rc = TEST_FAILED;
1804 : : }
1805 : :
1806 [ # # ]: 0 : if (rc == 0) {
1807 [ # # ]: 0 : if (test_cfg[i].reorder_pkts)
1808 : 0 : test_ipsec_reorder_inb_pkt_burst(num_pkts);
1809 : 0 : rc = test_ipsec_crypto_op_alloc(num_pkts);
1810 : : }
1811 : :
1812 [ # # ]: 0 : if (rc == 0) {
1813 : : /* call ipsec library api */
1814 : 0 : rc = lksd_proto_ipsec(num_pkts);
1815 [ # # ]: 0 : if (rc == 0)
1816 : 0 : rc = crypto_inb_burst_null_null_check(ut_params, i,
1817 : : num_pkts);
1818 : : else {
1819 : 0 : RTE_LOG(ERR, USER1, "%s failed, cfg %d\n",
1820 : : __func__, i);
1821 : : rc = TEST_FAILED;
1822 : : }
1823 : : }
1824 : :
1825 [ # # ]: 0 : if (rc == TEST_FAILED)
1826 : 0 : test_ipsec_dump_buffers(ut_params, i);
1827 : :
1828 : 0 : destroy_sa(0);
1829 : 0 : return rc;
1830 : : }
1831 : :
1832 : : static int
1833 : 0 : test_ipsec_lksd_proto_inb_burst_null_null_wrapper(void)
1834 : : {
1835 : : int i;
1836 : : int rc = 0;
1837 : : struct ipsec_unitest_params *ut_params = &unittest_params;
1838 : :
1839 : 0 : ut_params->ipsec_xform.spi = INBOUND_SPI;
1840 : 0 : ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
1841 : 0 : ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1842 : 0 : ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1843 : 0 : ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1844 : :
1845 [ # # ]: 0 : for (i = 0; i < num_cfg && rc == 0; i++) {
1846 : 0 : ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1847 : 0 : rc = test_ipsec_lksd_proto_inb_burst_null_null(i);
1848 : : }
1849 : :
1850 : 0 : return rc;
1851 : : }
1852 : :
1853 : : static int
1854 : 0 : test_ipsec_lksd_proto_outb_burst_null_null_wrapper(void)
1855 : : {
1856 : : int i;
1857 : : int rc = 0;
1858 : : struct ipsec_unitest_params *ut_params = &unittest_params;
1859 : :
1860 : 0 : ut_params->ipsec_xform.spi = INBOUND_SPI;
1861 : 0 : ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS;
1862 : 0 : ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1863 : 0 : ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1864 : 0 : ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1865 : :
1866 [ # # ]: 0 : for (i = 0; i < num_cfg && rc == 0; i++) {
1867 : 0 : ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1868 : 0 : rc = test_ipsec_lksd_proto_inb_burst_null_null(i);
1869 : : }
1870 : :
1871 : 0 : return rc;
1872 : : }
1873 : :
1874 : : static int
1875 : 0 : replay_inb_null_null_check(struct ipsec_unitest_params *ut_params, int i,
1876 : : int num_pkts)
1877 : : {
1878 : : uint16_t j;
1879 : :
1880 [ # # ]: 0 : for (j = 0; j < num_pkts; j++) {
1881 : : /* compare the buffer data */
1882 [ # # ]: 0 : TEST_ASSERT_BUFFERS_ARE_EQUAL(null_plain_data,
1883 : : rte_pktmbuf_mtod(ut_params->obuf[j], void *),
1884 : : test_cfg[i].pkt_sz,
1885 : : "input and output data does not match\n");
1886 : :
1887 [ # # ]: 0 : TEST_ASSERT_EQUAL(ut_params->obuf[j]->data_len,
1888 : : ut_params->obuf[j]->pkt_len,
1889 : : "data_len is not equal to pkt_len");
1890 : : }
1891 : :
1892 : : return 0;
1893 : : }
1894 : :
1895 : : static int
1896 : 0 : test_ipsec_replay_inb_inside_null_null(int i)
1897 : : {
1898 : : struct ipsec_testsuite_params *ts_params = &testsuite_params;
1899 : : struct ipsec_unitest_params *ut_params = &unittest_params;
1900 : : int rc;
1901 : :
1902 : : /* create rte_ipsec_sa*/
1903 : 0 : rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
1904 : 0 : test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1905 [ # # ]: 0 : if (rc != 0) {
1906 : 0 : RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
1907 : 0 : return rc;
1908 : : }
1909 : :
1910 : : /* Generate inbound mbuf data */
1911 : 0 : ut_params->ibuf[0] = setup_test_string_tunneled(ts_params->mbuf_pool,
1912 : 0 : null_encrypted_data, test_cfg[i].pkt_sz, INBOUND_SPI, 1);
1913 [ # # ]: 0 : if (ut_params->ibuf[0] == NULL)
1914 : : rc = TEST_FAILED;
1915 : : else
1916 : 0 : rc = test_ipsec_crypto_op_alloc(1);
1917 : :
1918 [ # # ]: 0 : if (rc == 0) {
1919 : : /* call ipsec library api */
1920 : 0 : rc = crypto_ipsec(1);
1921 [ # # ]: 0 : if (rc == 0)
1922 : 0 : rc = replay_inb_null_null_check(ut_params, i, 1);
1923 : : else {
1924 : 0 : RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
1925 : : i);
1926 : : rc = TEST_FAILED;
1927 : : }
1928 : : }
1929 : :
1930 [ # # # # ]: 0 : if ((rc == 0) && (test_cfg[i].replay_win_sz != 0)) {
1931 : : /* generate packet with seq number inside the replay window */
1932 [ # # ]: 0 : if (ut_params->ibuf[0]) {
1933 : 0 : rte_pktmbuf_free(ut_params->ibuf[0]);
1934 : 0 : ut_params->ibuf[0] = 0;
1935 : : }
1936 : :
1937 : 0 : ut_params->ibuf[0] = setup_test_string_tunneled(
1938 : : ts_params->mbuf_pool, null_encrypted_data,
1939 : : test_cfg[i].pkt_sz, INBOUND_SPI,
1940 : : test_cfg[i].replay_win_sz);
1941 [ # # ]: 0 : if (ut_params->ibuf[0] == NULL)
1942 : : rc = TEST_FAILED;
1943 : : else
1944 : 0 : rc = test_ipsec_crypto_op_alloc(1);
1945 : :
1946 [ # # ]: 0 : if (rc == 0) {
1947 : : /* call ipsec library api */
1948 : 0 : rc = crypto_ipsec(1);
1949 [ # # ]: 0 : if (rc == 0)
1950 : 0 : rc = replay_inb_null_null_check(
1951 : : ut_params, i, 1);
1952 : : else {
1953 : 0 : RTE_LOG(ERR, USER1, "crypto_ipsec failed\n");
1954 : : rc = TEST_FAILED;
1955 : : }
1956 : : }
1957 : : }
1958 : :
1959 [ # # ]: 0 : if (rc == TEST_FAILED)
1960 : 0 : test_ipsec_dump_buffers(ut_params, i);
1961 : :
1962 : 0 : destroy_sa(0);
1963 : :
1964 : 0 : return rc;
1965 : : }
1966 : :
1967 : : static int
1968 : 0 : test_ipsec_replay_inb_inside_null_null_wrapper(void)
1969 : : {
1970 : : int i;
1971 : : int rc = 0;
1972 : : struct ipsec_unitest_params *ut_params = &unittest_params;
1973 : :
1974 : 0 : ut_params->ipsec_xform.spi = INBOUND_SPI;
1975 : 0 : ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
1976 : 0 : ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
1977 : 0 : ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
1978 : 0 : ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
1979 : :
1980 [ # # ]: 0 : for (i = 0; i < num_cfg && rc == 0; i++) {
1981 : 0 : ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
1982 : 0 : rc = test_ipsec_replay_inb_inside_null_null(i);
1983 : : }
1984 : :
1985 : 0 : return rc;
1986 : : }
1987 : :
1988 : : static int
1989 : 0 : test_ipsec_replay_inb_outside_null_null(int i)
1990 : : {
1991 : : struct ipsec_testsuite_params *ts_params = &testsuite_params;
1992 : : struct ipsec_unitest_params *ut_params = &unittest_params;
1993 : : int rc;
1994 : :
1995 : : /* create rte_ipsec_sa */
1996 : 0 : rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
1997 : 0 : test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
1998 [ # # ]: 0 : if (rc != 0) {
1999 : 0 : RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
2000 : 0 : return rc;
2001 : : }
2002 : :
2003 : : /* Generate test mbuf data */
2004 : 0 : ut_params->ibuf[0] = setup_test_string_tunneled(ts_params->mbuf_pool,
2005 : 0 : null_encrypted_data, test_cfg[i].pkt_sz, INBOUND_SPI,
2006 : : test_cfg[i].replay_win_sz + 2);
2007 [ # # ]: 0 : if (ut_params->ibuf[0] == NULL)
2008 : : rc = TEST_FAILED;
2009 : : else
2010 : 0 : rc = test_ipsec_crypto_op_alloc(1);
2011 : :
2012 [ # # ]: 0 : if (rc == 0) {
2013 : : /* call ipsec library api */
2014 : 0 : rc = crypto_ipsec(1);
2015 [ # # ]: 0 : if (rc == 0)
2016 : 0 : rc = replay_inb_null_null_check(ut_params, i, 1);
2017 : : else {
2018 : 0 : RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
2019 : : i);
2020 : : rc = TEST_FAILED;
2021 : : }
2022 : : }
2023 : :
2024 [ # # # # ]: 0 : if ((rc == 0) && (test_cfg[i].replay_win_sz != 0)) {
2025 : : /* generate packet with seq number outside the replay window */
2026 [ # # ]: 0 : if (ut_params->ibuf[0]) {
2027 : 0 : rte_pktmbuf_free(ut_params->ibuf[0]);
2028 : 0 : ut_params->ibuf[0] = 0;
2029 : : }
2030 : 0 : ut_params->ibuf[0] = setup_test_string_tunneled(
2031 : : ts_params->mbuf_pool, null_encrypted_data,
2032 : : test_cfg[i].pkt_sz, INBOUND_SPI, 1);
2033 [ # # ]: 0 : if (ut_params->ibuf[0] == NULL)
2034 : : rc = TEST_FAILED;
2035 : : else
2036 : 0 : rc = test_ipsec_crypto_op_alloc(1);
2037 : :
2038 [ # # ]: 0 : if (rc == 0) {
2039 : : /* call ipsec library api */
2040 : 0 : rc = crypto_ipsec(1);
2041 [ # # ]: 0 : if (rc == 0) {
2042 [ # # ]: 0 : if (test_cfg[i].esn == 0) {
2043 : 0 : RTE_LOG(ERR, USER1,
2044 : : "packet is not outside the replay window, cfg %d pkt0_seq %u pkt1_seq %u\n",
2045 : : i,
2046 : : test_cfg[i].replay_win_sz + 2,
2047 : : 1);
2048 : : rc = TEST_FAILED;
2049 : : }
2050 : : } else {
2051 : 0 : RTE_LOG(ERR, USER1,
2052 : : "packet is outside the replay window, cfg %d pkt0_seq %u pkt1_seq %u\n",
2053 : : i, test_cfg[i].replay_win_sz + 2, 1);
2054 : : rc = 0;
2055 : : }
2056 : : }
2057 : : }
2058 : :
2059 [ # # ]: 0 : if (rc == TEST_FAILED)
2060 : 0 : test_ipsec_dump_buffers(ut_params, i);
2061 : :
2062 : 0 : destroy_sa(0);
2063 : :
2064 : 0 : return rc;
2065 : : }
2066 : :
2067 : : static int
2068 : 0 : test_ipsec_replay_inb_outside_null_null_wrapper(void)
2069 : : {
2070 : : int i;
2071 : : int rc = 0;
2072 : : struct ipsec_unitest_params *ut_params = &unittest_params;
2073 : :
2074 : 0 : ut_params->ipsec_xform.spi = INBOUND_SPI;
2075 : 0 : ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
2076 : 0 : ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
2077 : 0 : ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
2078 : 0 : ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
2079 : :
2080 [ # # ]: 0 : for (i = 0; i < num_cfg && rc == 0; i++) {
2081 : 0 : ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
2082 : 0 : rc = test_ipsec_replay_inb_outside_null_null(i);
2083 : : }
2084 : :
2085 : 0 : return rc;
2086 : : }
2087 : :
2088 : : static int
2089 : 0 : test_ipsec_replay_inb_repeat_null_null(int i)
2090 : : {
2091 : : struct ipsec_testsuite_params *ts_params = &testsuite_params;
2092 : : struct ipsec_unitest_params *ut_params = &unittest_params;
2093 : : int rc;
2094 : :
2095 : : /* create rte_ipsec_sa */
2096 : 0 : rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
2097 : 0 : test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
2098 [ # # ]: 0 : if (rc != 0) {
2099 : 0 : RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
2100 : 0 : return rc;
2101 : : }
2102 : :
2103 : : /* Generate test mbuf data */
2104 : 0 : ut_params->ibuf[0] = setup_test_string_tunneled(ts_params->mbuf_pool,
2105 : 0 : null_encrypted_data, test_cfg[i].pkt_sz, INBOUND_SPI, 1);
2106 [ # # ]: 0 : if (ut_params->ibuf[0] == NULL)
2107 : : rc = TEST_FAILED;
2108 : : else
2109 : 0 : rc = test_ipsec_crypto_op_alloc(1);
2110 : :
2111 [ # # ]: 0 : if (rc == 0) {
2112 : : /* call ipsec library api */
2113 : 0 : rc = crypto_ipsec(1);
2114 [ # # ]: 0 : if (rc == 0)
2115 : 0 : rc = replay_inb_null_null_check(ut_params, i, 1);
2116 : : else {
2117 : 0 : RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
2118 : : i);
2119 : : rc = TEST_FAILED;
2120 : : }
2121 : : }
2122 : :
2123 [ # # # # ]: 0 : if ((rc == 0) && (test_cfg[i].replay_win_sz != 0)) {
2124 : : /*
2125 : : * generate packet with repeat seq number in the replay
2126 : : * window
2127 : : */
2128 [ # # ]: 0 : if (ut_params->ibuf[0]) {
2129 : 0 : rte_pktmbuf_free(ut_params->ibuf[0]);
2130 : 0 : ut_params->ibuf[0] = 0;
2131 : : }
2132 : :
2133 : 0 : ut_params->ibuf[0] = setup_test_string_tunneled(
2134 : : ts_params->mbuf_pool, null_encrypted_data,
2135 : : test_cfg[i].pkt_sz, INBOUND_SPI, 1);
2136 [ # # ]: 0 : if (ut_params->ibuf[0] == NULL)
2137 : : rc = TEST_FAILED;
2138 : : else
2139 : 0 : rc = test_ipsec_crypto_op_alloc(1);
2140 : :
2141 [ # # ]: 0 : if (rc == 0) {
2142 : : /* call ipsec library api */
2143 : 0 : rc = crypto_ipsec(1);
2144 [ # # ]: 0 : if (rc == 0) {
2145 : 0 : RTE_LOG(ERR, USER1,
2146 : : "packet is not repeated in the replay window, cfg %d seq %u\n",
2147 : : i, 1);
2148 : : rc = TEST_FAILED;
2149 : : } else {
2150 : 0 : RTE_LOG(ERR, USER1,
2151 : : "packet is repeated in the replay window, cfg %d seq %u\n",
2152 : : i, 1);
2153 : : rc = 0;
2154 : : }
2155 : : }
2156 : : }
2157 : :
2158 [ # # ]: 0 : if (rc == TEST_FAILED)
2159 : 0 : test_ipsec_dump_buffers(ut_params, i);
2160 : :
2161 : 0 : destroy_sa(0);
2162 : :
2163 : 0 : return rc;
2164 : : }
2165 : :
2166 : : static int
2167 : 0 : test_ipsec_replay_inb_repeat_null_null_wrapper(void)
2168 : : {
2169 : : int i;
2170 : : int rc = 0;
2171 : : struct ipsec_unitest_params *ut_params = &unittest_params;
2172 : :
2173 : 0 : ut_params->ipsec_xform.spi = INBOUND_SPI;
2174 : 0 : ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
2175 : 0 : ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
2176 : 0 : ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
2177 : 0 : ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
2178 : :
2179 [ # # ]: 0 : for (i = 0; i < num_cfg && rc == 0; i++) {
2180 : 0 : ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
2181 : 0 : rc = test_ipsec_replay_inb_repeat_null_null(i);
2182 : : }
2183 : :
2184 : 0 : return rc;
2185 : : }
2186 : :
2187 : : static int
2188 : 0 : test_ipsec_replay_inb_inside_burst_null_null(int i)
2189 : : {
2190 : : struct ipsec_testsuite_params *ts_params = &testsuite_params;
2191 : : struct ipsec_unitest_params *ut_params = &unittest_params;
2192 : 0 : uint16_t num_pkts = test_cfg[i].num_pkts;
2193 : : int rc;
2194 : : int j;
2195 : :
2196 : : /* create rte_ipsec_sa*/
2197 : 0 : rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
2198 : 0 : test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
2199 [ # # ]: 0 : if (rc != 0) {
2200 : 0 : RTE_LOG(ERR, USER1, "create_sa failed, cfg %d\n", i);
2201 : 0 : return rc;
2202 : : }
2203 : :
2204 : : /* Generate inbound mbuf data */
2205 : 0 : ut_params->ibuf[0] = setup_test_string_tunneled(ts_params->mbuf_pool,
2206 : 0 : null_encrypted_data, test_cfg[i].pkt_sz, INBOUND_SPI, 1);
2207 [ # # ]: 0 : if (ut_params->ibuf[0] == NULL)
2208 : : rc = TEST_FAILED;
2209 : : else
2210 : 0 : rc = test_ipsec_crypto_op_alloc(1);
2211 : :
2212 [ # # ]: 0 : if (rc == 0) {
2213 : : /* call ipsec library api */
2214 : 0 : rc = crypto_ipsec(1);
2215 [ # # ]: 0 : if (rc == 0)
2216 : 0 : rc = replay_inb_null_null_check(ut_params, i, 1);
2217 : : else {
2218 : 0 : RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
2219 : : i);
2220 : : rc = TEST_FAILED;
2221 : : }
2222 : : }
2223 : :
2224 [ # # # # ]: 0 : if ((rc == 0) && (test_cfg[i].replay_win_sz != 0)) {
2225 : : /*
2226 : : * generate packet(s) with seq number(s) inside the
2227 : : * replay window
2228 : : */
2229 [ # # ]: 0 : if (ut_params->ibuf[0]) {
2230 : 0 : rte_pktmbuf_free(ut_params->ibuf[0]);
2231 : 0 : ut_params->ibuf[0] = 0;
2232 : : }
2233 : :
2234 [ # # # # ]: 0 : for (j = 0; j < num_pkts && rc == 0; j++) {
2235 : : /* packet with sequence number 1 already processed */
2236 : 0 : ut_params->ibuf[j] = setup_test_string_tunneled(
2237 : : ts_params->mbuf_pool, null_encrypted_data,
2238 : 0 : test_cfg[i].pkt_sz, INBOUND_SPI, j + 2);
2239 [ # # ]: 0 : if (ut_params->ibuf[j] == NULL)
2240 : : rc = TEST_FAILED;
2241 : : }
2242 : :
2243 [ # # ]: 0 : if (rc == 0) {
2244 [ # # ]: 0 : if (test_cfg[i].reorder_pkts)
2245 : 0 : test_ipsec_reorder_inb_pkt_burst(num_pkts);
2246 : 0 : rc = test_ipsec_crypto_op_alloc(num_pkts);
2247 : : }
2248 : :
2249 [ # # ]: 0 : if (rc == 0) {
2250 : : /* call ipsec library api */
2251 : 0 : rc = crypto_ipsec(num_pkts);
2252 [ # # ]: 0 : if (rc == 0)
2253 : 0 : rc = replay_inb_null_null_check(
2254 : : ut_params, i, num_pkts);
2255 : : else {
2256 : 0 : RTE_LOG(ERR, USER1, "crypto_ipsec failed\n");
2257 : : rc = TEST_FAILED;
2258 : : }
2259 : : }
2260 : : }
2261 : :
2262 [ # # ]: 0 : if (rc == TEST_FAILED)
2263 : 0 : test_ipsec_dump_buffers(ut_params, i);
2264 : :
2265 : 0 : destroy_sa(0);
2266 : :
2267 : 0 : return rc;
2268 : : }
2269 : :
2270 : : static int
2271 : 0 : test_ipsec_replay_inb_inside_burst_null_null_wrapper(void)
2272 : : {
2273 : : int i;
2274 : : int rc = 0;
2275 : : struct ipsec_unitest_params *ut_params = &unittest_params;
2276 : :
2277 : 0 : ut_params->ipsec_xform.spi = INBOUND_SPI;
2278 : 0 : ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
2279 : 0 : ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
2280 : 0 : ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
2281 : 0 : ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
2282 : :
2283 [ # # ]: 0 : for (i = 0; i < num_cfg && rc == 0; i++) {
2284 : 0 : ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
2285 : 0 : rc = test_ipsec_replay_inb_inside_burst_null_null(i);
2286 : : }
2287 : :
2288 : 0 : return rc;
2289 : : }
2290 : :
2291 : :
2292 : : static int
2293 : 0 : crypto_inb_burst_2sa_null_null_check(struct ipsec_unitest_params *ut_params,
2294 : : int i)
2295 : : {
2296 : : uint16_t j;
2297 : :
2298 [ # # ]: 0 : for (j = 0; j < BURST_SIZE; j++) {
2299 : 0 : ut_params->pkt_index = j;
2300 : :
2301 : : /* compare the data buffers */
2302 [ # # ]: 0 : TEST_ASSERT_BUFFERS_ARE_EQUAL(null_plain_data,
2303 : : rte_pktmbuf_mtod(ut_params->obuf[j], void *),
2304 : : test_cfg[i].pkt_sz,
2305 : : "input and output data does not match\n");
2306 [ # # ]: 0 : TEST_ASSERT_EQUAL(ut_params->obuf[j]->data_len,
2307 : : ut_params->obuf[j]->pkt_len,
2308 : : "data_len is not equal to pkt_len");
2309 [ # # ]: 0 : TEST_ASSERT_EQUAL(ut_params->obuf[j]->data_len,
2310 : : test_cfg[i].pkt_sz,
2311 : : "data_len is not equal to input data");
2312 : : }
2313 : :
2314 : : return 0;
2315 : : }
2316 : :
2317 : : static int
2318 : 0 : test_ipsec_crypto_inb_burst_2sa_null_null(int i)
2319 : : {
2320 : : struct ipsec_testsuite_params *ts_params = &testsuite_params;
2321 : : struct ipsec_unitest_params *ut_params = &unittest_params;
2322 : 0 : uint16_t num_pkts = test_cfg[i].num_pkts;
2323 : : uint16_t j, r;
2324 : : int rc = 0;
2325 : :
2326 [ # # ]: 0 : if (num_pkts != BURST_SIZE)
2327 : : return rc;
2328 : :
2329 : : /* create rte_ipsec_sa */
2330 : 0 : rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
2331 : 0 : test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
2332 [ # # ]: 0 : if (rc != 0) {
2333 : 0 : RTE_LOG(ERR, USER1, "create_sa 0 failed, cfg %d\n", i);
2334 : 0 : return rc;
2335 : : }
2336 : :
2337 : : /* create second rte_ipsec_sa */
2338 : 0 : ut_params->ipsec_xform.spi = INBOUND_SPI + 1;
2339 : 0 : rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
2340 : : test_cfg[i].replay_win_sz, test_cfg[i].flags, 1);
2341 [ # # ]: 0 : if (rc != 0) {
2342 : 0 : RTE_LOG(ERR, USER1, "create_sa 1 failed, cfg %d\n", i);
2343 : 0 : destroy_sa(0);
2344 : 0 : return rc;
2345 : : }
2346 : :
2347 : : /* Generate test mbuf data */
2348 [ # # ]: 0 : for (j = 0; j < num_pkts && rc == 0; j++) {
2349 : 0 : r = j % 2;
2350 : : /* packet with sequence number 0 is invalid */
2351 : 0 : ut_params->ibuf[j] = setup_test_string_tunneled(
2352 : : ts_params->mbuf_pool, null_encrypted_data,
2353 : 0 : test_cfg[i].pkt_sz, INBOUND_SPI + r, j + 1);
2354 [ # # ]: 0 : if (ut_params->ibuf[j] == NULL)
2355 : : rc = TEST_FAILED;
2356 : : }
2357 : :
2358 [ # # ]: 0 : if (rc == 0)
2359 : 0 : rc = test_ipsec_crypto_op_alloc(num_pkts);
2360 : :
2361 [ # # ]: 0 : if (rc == 0) {
2362 : : /* call ipsec library api */
2363 : 0 : rc = crypto_ipsec_2sa();
2364 [ # # ]: 0 : if (rc == 0)
2365 : 0 : rc = crypto_inb_burst_2sa_null_null_check(
2366 : : ut_params, i);
2367 : : else {
2368 : 0 : RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
2369 : : i);
2370 : : rc = TEST_FAILED;
2371 : : }
2372 : : }
2373 : :
2374 [ # # ]: 0 : if (rc == TEST_FAILED)
2375 : 0 : test_ipsec_dump_buffers(ut_params, i);
2376 : :
2377 : 0 : destroy_sa(0);
2378 : 0 : destroy_sa(1);
2379 : 0 : return rc;
2380 : : }
2381 : :
2382 : : static int
2383 : 0 : test_ipsec_crypto_inb_burst_2sa_null_null_wrapper(void)
2384 : : {
2385 : : int i;
2386 : : int rc = 0;
2387 : : struct ipsec_unitest_params *ut_params = &unittest_params;
2388 : :
2389 : 0 : ut_params->ipsec_xform.spi = INBOUND_SPI;
2390 : 0 : ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
2391 : 0 : ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
2392 : 0 : ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
2393 : 0 : ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
2394 : :
2395 [ # # ]: 0 : for (i = 0; i < num_cfg && rc == 0; i++) {
2396 : 0 : ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
2397 : 0 : rc = test_ipsec_crypto_inb_burst_2sa_null_null(i);
2398 : : }
2399 : :
2400 : 0 : return rc;
2401 : : }
2402 : :
2403 : : static int
2404 : 0 : test_ipsec_crypto_inb_burst_2sa_4grp_null_null(int i)
2405 : : {
2406 : : struct ipsec_testsuite_params *ts_params = &testsuite_params;
2407 : : struct ipsec_unitest_params *ut_params = &unittest_params;
2408 : 0 : uint16_t num_pkts = test_cfg[i].num_pkts;
2409 : : uint16_t j, k;
2410 : : int rc = 0;
2411 : :
2412 [ # # ]: 0 : if (num_pkts != BURST_SIZE)
2413 : : return rc;
2414 : :
2415 : : /* create rte_ipsec_sa */
2416 : 0 : rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
2417 : 0 : test_cfg[i].replay_win_sz, test_cfg[i].flags, 0);
2418 [ # # ]: 0 : if (rc != 0) {
2419 : 0 : RTE_LOG(ERR, USER1, "create_sa 0 failed, cfg %d\n", i);
2420 : 0 : return rc;
2421 : : }
2422 : :
2423 : : /* create second rte_ipsec_sa */
2424 : 0 : ut_params->ipsec_xform.spi = INBOUND_SPI + 1;
2425 : 0 : rc = create_sa(RTE_SECURITY_ACTION_TYPE_NONE,
2426 : : test_cfg[i].replay_win_sz, test_cfg[i].flags, 1);
2427 [ # # ]: 0 : if (rc != 0) {
2428 : 0 : RTE_LOG(ERR, USER1, "create_sa 1 failed, cfg %d\n", i);
2429 : 0 : destroy_sa(0);
2430 : 0 : return rc;
2431 : : }
2432 : :
2433 : : /* Generate test mbuf data */
2434 [ # # ]: 0 : for (j = 0; j < num_pkts && rc == 0; j++) {
2435 [ # # ]: 0 : k = crypto_ipsec_4grp(j);
2436 : :
2437 : : /* packet with sequence number 0 is invalid */
2438 : 0 : ut_params->ibuf[j] = setup_test_string_tunneled(
2439 : : ts_params->mbuf_pool, null_encrypted_data,
2440 : 0 : test_cfg[i].pkt_sz, INBOUND_SPI + k, j + 1);
2441 [ # # ]: 0 : if (ut_params->ibuf[j] == NULL)
2442 : : rc = TEST_FAILED;
2443 : : }
2444 : :
2445 [ # # ]: 0 : if (rc == 0)
2446 : 0 : rc = test_ipsec_crypto_op_alloc(num_pkts);
2447 : :
2448 [ # # ]: 0 : if (rc == 0) {
2449 : : /* call ipsec library api */
2450 : 0 : rc = crypto_ipsec_2sa_4grp();
2451 [ # # ]: 0 : if (rc == 0)
2452 : 0 : rc = crypto_inb_burst_2sa_null_null_check(
2453 : : ut_params, i);
2454 : : else {
2455 : 0 : RTE_LOG(ERR, USER1, "crypto_ipsec failed, cfg %d\n",
2456 : : i);
2457 : : rc = TEST_FAILED;
2458 : : }
2459 : : }
2460 : :
2461 [ # # ]: 0 : if (rc == TEST_FAILED)
2462 : 0 : test_ipsec_dump_buffers(ut_params, i);
2463 : :
2464 : 0 : destroy_sa(0);
2465 : 0 : destroy_sa(1);
2466 : 0 : return rc;
2467 : : }
2468 : :
2469 : : static int
2470 : 0 : test_ipsec_crypto_inb_burst_2sa_4grp_null_null_wrapper(void)
2471 : : {
2472 : : int i;
2473 : : int rc = 0;
2474 : : struct ipsec_unitest_params *ut_params = &unittest_params;
2475 : :
2476 : 0 : ut_params->ipsec_xform.spi = INBOUND_SPI;
2477 : 0 : ut_params->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
2478 : 0 : ut_params->ipsec_xform.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP;
2479 : 0 : ut_params->ipsec_xform.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
2480 : 0 : ut_params->ipsec_xform.tunnel.type = RTE_SECURITY_IPSEC_TUNNEL_IPV4;
2481 : :
2482 [ # # ]: 0 : for (i = 0; i < num_cfg && rc == 0; i++) {
2483 : 0 : ut_params->ipsec_xform.options.esn = test_cfg[i].esn;
2484 : 0 : rc = test_ipsec_crypto_inb_burst_2sa_4grp_null_null(i);
2485 : : }
2486 : :
2487 : 0 : return rc;
2488 : : }
2489 : :
2490 : : static struct unit_test_suite ipsec_testsuite = {
2491 : : .suite_name = "IPsec NULL Unit Test Suite",
2492 : : .setup = testsuite_setup,
2493 : : .teardown = testsuite_teardown,
2494 : : .unit_test_cases = {
2495 : : TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec,
2496 : : test_ipsec_crypto_inb_burst_null_null_wrapper),
2497 : : TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec,
2498 : : test_ipsec_crypto_outb_burst_null_null_wrapper),
2499 : : TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec,
2500 : : test_ipsec_inline_crypto_inb_burst_null_null_wrapper),
2501 : : TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec,
2502 : : test_ipsec_inline_crypto_outb_burst_null_null_wrapper),
2503 : : TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec,
2504 : : test_ipsec_inline_proto_inb_burst_null_null_wrapper),
2505 : : TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec,
2506 : : test_ipsec_inline_proto_outb_burst_null_null_wrapper),
2507 : : TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec,
2508 : : test_ipsec_lksd_proto_inb_burst_null_null_wrapper),
2509 : : TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec,
2510 : : test_ipsec_lksd_proto_outb_burst_null_null_wrapper),
2511 : : TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec,
2512 : : test_ipsec_replay_inb_inside_null_null_wrapper),
2513 : : TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec,
2514 : : test_ipsec_replay_inb_outside_null_null_wrapper),
2515 : : TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec,
2516 : : test_ipsec_replay_inb_repeat_null_null_wrapper),
2517 : : TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec,
2518 : : test_ipsec_replay_inb_inside_burst_null_null_wrapper),
2519 : : TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec,
2520 : : test_ipsec_crypto_inb_burst_2sa_null_null_wrapper),
2521 : : TEST_CASE_ST(ut_setup_ipsec, ut_teardown_ipsec,
2522 : : test_ipsec_crypto_inb_burst_2sa_4grp_null_null_wrapper),
2523 : : TEST_CASES_END() /**< NULL terminate unit test array */
2524 : : }
2525 : : };
2526 : :
2527 : : static int
2528 : 1 : test_ipsec(void)
2529 : : {
2530 : 1 : return unit_test_suite_runner(&ipsec_testsuite);
2531 : : }
2532 : :
2533 : : #endif /* !RTE_EXEC_ENV_WINDOWS */
2534 : :
2535 : 235 : REGISTER_FAST_TEST(ipsec_autotest, true, true, test_ipsec);
|