1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2021 Marvell.
5 #ifndef RTE_EXEC_ENV_WINDOWS
7 #include <rte_common.h>
8 #include <rte_cryptodev.h>
11 #include <rte_security.h>
16 #include "test_cryptodev_security_ipsec.h"
20 struct crypto_param_comb alg_list[RTE_DIM(aead_list) +
21 (RTE_DIM(cipher_list) *
25 is_valid_ipv4_pkt(const struct rte_ipv4_hdr *pkt)
27 /* The IP version number must be 4 */
28 if (((pkt->version_ihl) >> 4) != 4)
31 * The IP header length field must be large enough to hold the
32 * minimum length legal IP datagram (20 bytes = 5 words).
34 if ((pkt->version_ihl & 0xf) < 5)
38 * The IP total length field must be large enough to hold the IP
39 * datagram header, whose length is specified in the IP header length
42 if (rte_cpu_to_be_16(pkt->total_length) < sizeof(struct rte_ipv4_hdr))
49 is_valid_ipv6_pkt(const struct rte_ipv6_hdr *pkt)
51 /* The IP version number must be 6 */
52 if ((rte_be_to_cpu_32((pkt->vtc_flow)) >> 28) != 6)
59 test_ipsec_alg_list_populate(void)
61 unsigned long i, j, index = 0;
63 for (i = 0; i < RTE_DIM(aead_list); i++) {
64 alg_list[index].param1 = &aead_list[i];
65 alg_list[index].param2 = NULL;
69 for (i = 0; i < RTE_DIM(cipher_list); i++) {
70 for (j = 0; j < RTE_DIM(auth_list); j++) {
71 alg_list[index].param1 = &cipher_list[i];
72 alg_list[index].param2 = &auth_list[j];
79 test_ipsec_sec_caps_verify(struct rte_security_ipsec_xform *ipsec_xform,
80 const struct rte_security_capability *sec_cap,
83 /* Verify security capabilities */
85 if (ipsec_xform->options.esn == 1 && sec_cap->ipsec.options.esn == 0) {
87 RTE_LOG(INFO, USER1, "ESN is not supported\n");
91 if (ipsec_xform->options.udp_encap == 1 &&
92 sec_cap->ipsec.options.udp_encap == 0) {
94 RTE_LOG(INFO, USER1, "UDP encapsulation is not supported\n");
98 if (ipsec_xform->options.udp_ports_verify == 1 &&
99 sec_cap->ipsec.options.udp_ports_verify == 0) {
101 RTE_LOG(INFO, USER1, "UDP encapsulation ports "
102 "verification is not supported\n");
106 if (ipsec_xform->options.copy_dscp == 1 &&
107 sec_cap->ipsec.options.copy_dscp == 0) {
109 RTE_LOG(INFO, USER1, "Copy DSCP is not supported\n");
113 if (ipsec_xform->options.copy_flabel == 1 &&
114 sec_cap->ipsec.options.copy_flabel == 0) {
116 RTE_LOG(INFO, USER1, "Copy Flow Label is not supported\n");
120 if (ipsec_xform->options.copy_df == 1 &&
121 sec_cap->ipsec.options.copy_df == 0) {
123 RTE_LOG(INFO, USER1, "Copy DP bit is not supported\n");
127 if (ipsec_xform->options.dec_ttl == 1 &&
128 sec_cap->ipsec.options.dec_ttl == 0) {
130 RTE_LOG(INFO, USER1, "Decrement TTL is not supported\n");
134 if (ipsec_xform->options.ecn == 1 && sec_cap->ipsec.options.ecn == 0) {
136 RTE_LOG(INFO, USER1, "ECN is not supported\n");
140 if (ipsec_xform->options.stats == 1 &&
141 sec_cap->ipsec.options.stats == 0) {
143 RTE_LOG(INFO, USER1, "Stats is not supported\n");
147 if ((ipsec_xform->direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) &&
148 (ipsec_xform->options.iv_gen_disable == 1) &&
149 (sec_cap->ipsec.options.iv_gen_disable != 1)) {
152 "Application provided IV is not supported\n");
156 if ((ipsec_xform->direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS) &&
157 (ipsec_xform->options.tunnel_hdr_verify >
158 sec_cap->ipsec.options.tunnel_hdr_verify)) {
161 "Tunnel header verify is not supported\n");
165 if (ipsec_xform->options.ip_csum_enable == 1 &&
166 sec_cap->ipsec.options.ip_csum_enable == 0) {
169 "Inner IP checksum is not supported\n");
173 if (ipsec_xform->options.l4_csum_enable == 1 &&
174 sec_cap->ipsec.options.l4_csum_enable == 0) {
177 "Inner L4 checksum is not supported\n");
185 test_ipsec_crypto_caps_aead_verify(
186 const struct rte_security_capability *sec_cap,
187 struct rte_crypto_sym_xform *aead)
189 const struct rte_cryptodev_symmetric_capability *sym_cap;
190 const struct rte_cryptodev_capabilities *crypto_cap;
193 while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
194 RTE_CRYPTO_OP_TYPE_UNDEFINED) {
195 if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
196 crypto_cap->sym.xform_type == aead->type &&
197 crypto_cap->sym.aead.algo == aead->aead.algo) {
198 sym_cap = &crypto_cap->sym;
199 if (rte_cryptodev_sym_capability_check_aead(sym_cap,
200 aead->aead.key.length,
201 aead->aead.digest_length,
202 aead->aead.aad_length,
203 aead->aead.iv.length) == 0)
212 test_ipsec_crypto_caps_cipher_verify(
213 const struct rte_security_capability *sec_cap,
214 struct rte_crypto_sym_xform *cipher)
216 const struct rte_cryptodev_symmetric_capability *sym_cap;
217 const struct rte_cryptodev_capabilities *cap;
220 while ((cap = &sec_cap->crypto_capabilities[j++])->op !=
221 RTE_CRYPTO_OP_TYPE_UNDEFINED) {
222 if (cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
223 cap->sym.xform_type == cipher->type &&
224 cap->sym.cipher.algo == cipher->cipher.algo) {
226 if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
227 cipher->cipher.key.length,
228 cipher->cipher.iv.length) == 0)
237 test_ipsec_crypto_caps_auth_verify(
238 const struct rte_security_capability *sec_cap,
239 struct rte_crypto_sym_xform *auth)
241 const struct rte_cryptodev_symmetric_capability *sym_cap;
242 const struct rte_cryptodev_capabilities *cap;
245 while ((cap = &sec_cap->crypto_capabilities[j++])->op !=
246 RTE_CRYPTO_OP_TYPE_UNDEFINED) {
247 if (cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
248 cap->sym.xform_type == auth->type &&
249 cap->sym.auth.algo == auth->auth.algo) {
251 if (rte_cryptodev_sym_capability_check_auth(sym_cap,
252 auth->auth.key.length,
253 auth->auth.digest_length,
254 auth->auth.iv.length) == 0)
263 test_ipsec_td_in_from_out(const struct ipsec_test_data *td_out,
264 struct ipsec_test_data *td_in)
266 memcpy(td_in, td_out, sizeof(*td_in));
268 /* Populate output text of td_in with input text of td_out */
269 memcpy(td_in->output_text.data, td_out->input_text.data,
270 td_out->input_text.len);
271 td_in->output_text.len = td_out->input_text.len;
273 /* Populate input text of td_in with output text of td_out */
274 memcpy(td_in->input_text.data, td_out->output_text.data,
275 td_out->output_text.len);
276 td_in->input_text.len = td_out->output_text.len;
278 td_in->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
281 td_in->xform.aead.aead.op = RTE_CRYPTO_AEAD_OP_DECRYPT;
283 td_in->xform.chain.auth.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
284 td_in->xform.chain.cipher.cipher.op =
285 RTE_CRYPTO_CIPHER_OP_DECRYPT;
292 struct rte_ipv4_hdr *ipv4 = ip;
295 ip_ver = (ipv4->version_ihl & 0xf0) >> RTE_IPV4_IHL_MULTIPLIER;
296 if (ip_ver == IPVERSION)
303 test_ipsec_csum_init(void *ip, bool l3, bool l4)
305 struct rte_ipv4_hdr *ipv4;
306 struct rte_tcp_hdr *tcp;
307 struct rte_udp_hdr *udp;
313 size = sizeof(struct rte_ipv4_hdr);
314 next_proto = ipv4->next_proto_id;
317 ipv4->hdr_checksum = 0;
319 size = sizeof(struct rte_ipv6_hdr);
320 next_proto = ((struct rte_ipv6_hdr *)ip)->proto;
324 switch (next_proto) {
326 tcp = (struct rte_tcp_hdr *)RTE_PTR_ADD(ip, size);
330 udp = (struct rte_udp_hdr *)RTE_PTR_ADD(ip, size);
331 udp->dgram_cksum = 0;
340 test_ipsec_td_prepare(const struct crypto_param *param1,
341 const struct crypto_param *param2,
342 const struct ipsec_test_flags *flags,
343 struct ipsec_test_data *td_array,
347 struct ipsec_test_data *td;
350 memset(td_array, 0, nb_td * sizeof(*td));
352 for (i = 0; i < nb_td; i++) {
355 /* Prepare fields based on param */
357 if (param1->type == RTE_CRYPTO_SYM_XFORM_AEAD) {
358 /* Copy template for packet & key fields */
360 memcpy(td, &pkt_aes_256_gcm_v6, sizeof(*td));
362 memcpy(td, &pkt_aes_256_gcm, sizeof(*td));
365 td->xform.aead.aead.algo = param1->alg.aead;
366 td->xform.aead.aead.key.length = param1->key_length;
368 /* Copy template for packet & key fields */
370 memcpy(td, &pkt_aes_128_cbc_hmac_sha256_v6,
373 memcpy(td, &pkt_aes_128_cbc_hmac_sha256,
377 td->xform.chain.cipher.cipher.algo = param1->alg.cipher;
378 td->xform.chain.cipher.cipher.key.length =
380 td->xform.chain.cipher.cipher.iv.length =
382 td->xform.chain.auth.auth.algo = param2->alg.auth;
383 td->xform.chain.auth.auth.key.length =
385 td->xform.chain.auth.auth.digest_length =
386 param2->digest_length;
391 td->ipsec_xform.options.iv_gen_disable = 0;
393 if (flags->sa_expiry_pkts_soft)
394 td->ipsec_xform.life.packets_soft_limit =
395 IPSEC_TEST_PACKETS_MAX - 1;
397 if (flags->ip_csum) {
398 td->ipsec_xform.options.ip_csum_enable = 1;
399 test_ipsec_csum_init(&td->input_text.data, true, false);
402 if (flags->l4_csum) {
403 td->ipsec_xform.options.l4_csum_enable = 1;
404 test_ipsec_csum_init(&td->input_text.data, false, true);
407 if (flags->transport) {
408 td->ipsec_xform.mode =
409 RTE_SECURITY_IPSEC_SA_MODE_TRANSPORT;
411 td->ipsec_xform.mode =
412 RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
414 if (flags->tunnel_ipv6)
415 td->ipsec_xform.tunnel.type =
416 RTE_SECURITY_IPSEC_TUNNEL_IPV6;
418 td->ipsec_xform.tunnel.type =
419 RTE_SECURITY_IPSEC_TUNNEL_IPV4;
422 if (flags->stats_success)
423 td->ipsec_xform.options.stats = 1;
425 if (flags->fragment) {
426 struct rte_ipv4_hdr *ip;
427 ip = (struct rte_ipv4_hdr *)&td->input_text.data;
428 ip->fragment_offset = 4;
429 ip->hdr_checksum = rte_ipv4_cksum(ip);
432 if (flags->df == TEST_IPSEC_COPY_DF_INNER_0 ||
433 flags->df == TEST_IPSEC_COPY_DF_INNER_1)
434 td->ipsec_xform.options.copy_df = 1;
439 test_ipsec_td_update(struct ipsec_test_data td_inb[],
440 const struct ipsec_test_data td_outb[],
442 const struct ipsec_test_flags *flags)
446 for (i = 0; i < nb_td; i++) {
447 memcpy(td_inb[i].output_text.data, td_outb[i].input_text.data,
448 td_outb[i].input_text.len);
449 td_inb[i].output_text.len = td_outb->input_text.len;
451 if (flags->icv_corrupt) {
452 int icv_pos = td_inb[i].input_text.len - 4;
453 td_inb[i].input_text.data[icv_pos] += 1;
456 if (flags->sa_expiry_pkts_hard)
457 td_inb[i].ipsec_xform.life.packets_hard_limit =
458 IPSEC_TEST_PACKETS_MAX - 1;
460 if (flags->udp_encap)
461 td_inb[i].ipsec_xform.options.udp_encap = 1;
463 if (flags->udp_ports_verify)
464 td_inb[i].ipsec_xform.options.udp_ports_verify = 1;
466 td_inb[i].ipsec_xform.options.tunnel_hdr_verify =
467 flags->tunnel_hdr_verify;
470 td_inb[i].ipsec_xform.options.ip_csum_enable = 1;
473 td_inb[i].ipsec_xform.options.l4_csum_enable = 1;
475 /* Clear outbound specific flags */
476 td_inb[i].ipsec_xform.options.iv_gen_disable = 0;
481 test_ipsec_display_alg(const struct crypto_param *param1,
482 const struct crypto_param *param2)
484 if (param1->type == RTE_CRYPTO_SYM_XFORM_AEAD) {
486 rte_crypto_aead_algorithm_strings[param1->alg.aead],
487 param1->key_length * 8);
490 rte_crypto_cipher_algorithm_strings[param1->alg.cipher]);
491 if (param1->alg.cipher != RTE_CRYPTO_CIPHER_NULL)
492 printf(" [%d]", param1->key_length * 8);
494 rte_crypto_auth_algorithm_strings[param2->alg.auth]);
495 if (param2->alg.auth != RTE_CRYPTO_AUTH_NULL)
496 printf(" [%dB ICV]", param2->digest_length);
502 test_ipsec_tunnel_hdr_len_get(const struct ipsec_test_data *td)
506 if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
507 if (td->ipsec_xform.mode == RTE_SECURITY_IPSEC_SA_MODE_TUNNEL) {
508 if (td->ipsec_xform.tunnel.type ==
509 RTE_SECURITY_IPSEC_TUNNEL_IPV4)
510 len += sizeof(struct rte_ipv4_hdr);
512 len += sizeof(struct rte_ipv6_hdr);
520 test_ipsec_iv_verify_push(struct rte_mbuf *m, const struct ipsec_test_data *td)
522 static uint8_t iv_queue[IV_LEN_MAX * IPSEC_TEST_PACKETS_MAX];
523 uint8_t *iv_tmp, *output_text = rte_pktmbuf_mtod(m, uint8_t *);
524 int i, iv_pos, iv_len;
528 iv_len = td->xform.aead.aead.iv.length - td->salt.len;
530 iv_len = td->xform.chain.cipher.cipher.iv.length;
532 iv_pos = test_ipsec_tunnel_hdr_len_get(td) + sizeof(struct rte_esp_hdr);
533 output_text += iv_pos;
535 TEST_ASSERT(iv_len <= IV_LEN_MAX, "IV length greater than supported");
537 /* Compare against previous values */
538 for (i = 0; i < index; i++) {
539 iv_tmp = &iv_queue[i * IV_LEN_MAX];
541 if (memcmp(output_text, iv_tmp, iv_len) == 0) {
542 printf("IV repeated");
547 /* Save IV for future comparisons */
549 iv_tmp = &iv_queue[index * IV_LEN_MAX];
550 memcpy(iv_tmp, output_text, iv_len);
553 if (index == IPSEC_TEST_PACKETS_MAX)
560 test_ipsec_l3_csum_verify(struct rte_mbuf *m)
562 uint16_t actual_cksum, expected_cksum;
563 struct rte_ipv4_hdr *ip;
565 ip = rte_pktmbuf_mtod(m, struct rte_ipv4_hdr *);
567 if (!is_ipv4((void *)ip))
570 actual_cksum = ip->hdr_checksum;
572 ip->hdr_checksum = 0;
574 expected_cksum = rte_ipv4_cksum(ip);
576 if (actual_cksum != expected_cksum)
583 test_ipsec_l4_csum_verify(struct rte_mbuf *m)
585 uint16_t actual_cksum = 0, expected_cksum = 0;
586 struct rte_ipv4_hdr *ipv4;
587 struct rte_ipv6_hdr *ipv6;
588 struct rte_tcp_hdr *tcp;
589 struct rte_udp_hdr *udp;
592 ip = rte_pktmbuf_mtod(m, void *);
596 l4 = RTE_PTR_ADD(ipv4, sizeof(struct rte_ipv4_hdr));
598 switch (ipv4->next_proto_id) {
600 tcp = (struct rte_tcp_hdr *)l4;
601 actual_cksum = tcp->cksum;
603 expected_cksum = rte_ipv4_udptcp_cksum(ipv4, l4);
606 udp = (struct rte_udp_hdr *)l4;
607 actual_cksum = udp->dgram_cksum;
608 udp->dgram_cksum = 0;
609 expected_cksum = rte_ipv4_udptcp_cksum(ipv4, l4);
616 l4 = RTE_PTR_ADD(ipv6, sizeof(struct rte_ipv6_hdr));
618 switch (ipv6->proto) {
620 tcp = (struct rte_tcp_hdr *)l4;
621 actual_cksum = tcp->cksum;
623 expected_cksum = rte_ipv6_udptcp_cksum(ipv6, l4);
626 udp = (struct rte_udp_hdr *)l4;
627 actual_cksum = udp->dgram_cksum;
628 udp->dgram_cksum = 0;
629 expected_cksum = rte_ipv6_udptcp_cksum(ipv6, l4);
636 if (actual_cksum != expected_cksum)
643 test_ipsec_td_verify(struct rte_mbuf *m, const struct ipsec_test_data *td,
644 bool silent, const struct ipsec_test_flags *flags)
646 uint8_t *output_text = rte_pktmbuf_mtod(m, uint8_t *);
647 uint32_t skip, len = rte_pktmbuf_pkt_len(m);
648 uint8_t td_output_text[4096];
651 /* For tests with status as error for test success, skip verification */
652 if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS &&
653 (flags->icv_corrupt ||
654 flags->sa_expiry_pkts_hard ||
655 flags->tunnel_hdr_verify))
658 if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS &&
660 const struct rte_ipv4_hdr *iph4;
661 const struct rte_ipv6_hdr *iph6;
663 if (td->ipsec_xform.tunnel.type ==
664 RTE_SECURITY_IPSEC_TUNNEL_IPV4) {
665 iph4 = (const struct rte_ipv4_hdr *)output_text;
666 if (iph4->next_proto_id != IPPROTO_UDP) {
667 printf("UDP header is not found\n");
671 iph6 = (const struct rte_ipv6_hdr *)output_text;
672 if (iph6->proto != IPPROTO_UDP) {
673 printf("UDP header is not found\n");
678 len -= sizeof(struct rte_udp_hdr);
679 output_text += sizeof(struct rte_udp_hdr);
682 if (len != td->output_text.len) {
683 printf("Output length (%d) not matching with expected (%d)\n",
684 len, td->output_text.len);
688 if ((td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) &&
690 const struct rte_ipv4_hdr *iph4;
691 iph4 = (const struct rte_ipv4_hdr *)output_text;
692 if (iph4->fragment_offset) {
693 printf("Output packet is fragmented");
698 skip = test_ipsec_tunnel_hdr_len_get(td);
703 if ((td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS) &&
705 if (m->ol_flags & RTE_MBUF_F_RX_IP_CKSUM_GOOD)
706 ret = test_ipsec_l3_csum_verify(m);
710 if (ret == TEST_FAILED)
711 printf("Inner IP checksum test failed\n");
716 if ((td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS) &&
718 if (m->ol_flags & RTE_MBUF_F_RX_L4_CKSUM_GOOD)
719 ret = test_ipsec_l4_csum_verify(m);
723 if (ret == TEST_FAILED)
724 printf("Inner L4 checksum test failed\n");
729 memcpy(td_output_text, td->output_text.data + skip, len);
731 if (test_ipsec_pkt_update(td_output_text, flags)) {
732 printf("Could not update expected vector");
736 if (memcmp(output_text, td_output_text, len)) {
740 printf("TestCase %s line %d: %s\n", __func__, __LINE__,
741 "output text not as expected\n");
743 rte_hexdump(stdout, "expected", td_output_text, len);
744 rte_hexdump(stdout, "actual", output_text, len);
752 test_ipsec_res_d_prepare(struct rte_mbuf *m, const struct ipsec_test_data *td,
753 struct ipsec_test_data *res_d)
755 uint8_t *output_text = rte_pktmbuf_mtod(m, uint8_t *);
756 uint32_t len = rte_pktmbuf_pkt_len(m);
758 memcpy(res_d, td, sizeof(*res_d));
759 memcpy(res_d->input_text.data, output_text, len);
760 res_d->input_text.len = len;
762 res_d->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
764 res_d->xform.aead.aead.op = RTE_CRYPTO_AEAD_OP_DECRYPT;
766 res_d->xform.chain.cipher.cipher.op =
767 RTE_CRYPTO_CIPHER_OP_DECRYPT;
768 res_d->xform.chain.auth.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
775 test_ipsec_post_process(struct rte_mbuf *m, const struct ipsec_test_data *td,
776 struct ipsec_test_data *res_d, bool silent,
777 const struct ipsec_test_flags *flags)
779 uint8_t *output_text = rte_pktmbuf_mtod(m, uint8_t *);
782 if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
783 const struct rte_ipv4_hdr *iph4;
784 const struct rte_ipv6_hdr *iph6;
787 ret = test_ipsec_iv_verify_push(m, td);
788 if (ret != TEST_SUCCESS)
792 iph4 = (const struct rte_ipv4_hdr *)output_text;
794 if (td->ipsec_xform.mode ==
795 RTE_SECURITY_IPSEC_SA_MODE_TRANSPORT) {
797 iph6 = (const struct rte_ipv6_hdr *)output_text;
798 if (is_valid_ipv6_pkt(iph6) == false) {
799 printf("Transport packet is not IPv6\n");
803 if (is_valid_ipv4_pkt(iph4) == false) {
804 printf("Transport packet is not IPv4\n");
809 if (td->ipsec_xform.tunnel.type ==
810 RTE_SECURITY_IPSEC_TUNNEL_IPV4) {
813 if (is_valid_ipv4_pkt(iph4) == false) {
814 printf("Tunnel outer header is not IPv4\n");
818 f_off = rte_be_to_cpu_16(iph4->fragment_offset);
820 if (flags->df == TEST_IPSEC_COPY_DF_INNER_1 ||
821 flags->df == TEST_IPSEC_SET_DF_1_INNER_0) {
822 if (!(f_off & RTE_IPV4_HDR_DF_FLAG)) {
823 printf("DF bit is not set\n");
827 if ((f_off & RTE_IPV4_HDR_DF_FLAG)) {
828 printf("DF bit is set\n");
833 iph6 = (const struct rte_ipv6_hdr *)output_text;
834 if (is_valid_ipv6_pkt(iph6) == false) {
835 printf("Tunnel outer header is not IPv6\n");
843 * In case of known vector tests & all inbound tests, res_d provided
844 * would be NULL and output data need to be validated against expected.
845 * For inbound, output_text would be plain packet and for outbound
846 * output_text would IPsec packet. Validate by comparing against
849 * In case of combined mode tests, the output_text from outbound
850 * operation (ie, IPsec packet) would need to be inbound processed to
851 * obtain the plain text. Copy output_text to result data, 'res_d', so
852 * that inbound processing can be done.
856 return test_ipsec_td_verify(m, td, silent, flags);
858 return test_ipsec_res_d_prepare(m, td, res_d);
862 test_ipsec_status_check(struct rte_crypto_op *op,
863 const struct ipsec_test_flags *flags,
864 enum rte_security_ipsec_sa_direction dir,
867 int ret = TEST_SUCCESS;
869 if (dir == RTE_SECURITY_IPSEC_SA_DIR_INGRESS &&
870 flags->sa_expiry_pkts_hard &&
871 pkt_num == IPSEC_TEST_PACKETS_MAX) {
872 if (op->status != RTE_CRYPTO_OP_STATUS_ERROR) {
873 printf("SA hard expiry (pkts) test failed\n");
880 if ((dir == RTE_SECURITY_IPSEC_SA_DIR_INGRESS) &&
881 flags->tunnel_hdr_verify) {
882 if (op->status != RTE_CRYPTO_OP_STATUS_ERROR) {
883 printf("Tunnel header verify test case failed\n");
890 if (dir == RTE_SECURITY_IPSEC_SA_DIR_INGRESS && flags->icv_corrupt) {
891 if (op->status != RTE_CRYPTO_OP_STATUS_ERROR) {
892 printf("ICV corruption test case failed\n");
896 if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
897 printf("Security op processing failed [pkt_num: %d]\n",
903 if (flags->sa_expiry_pkts_soft && pkt_num == IPSEC_TEST_PACKETS_MAX) {
904 if (!(op->aux_flags &
905 RTE_CRYPTO_OP_AUX_FLAGS_IPSEC_SOFT_EXPIRY)) {
906 printf("SA soft expiry (pkts) test failed\n");
915 test_ipsec_stats_verify(struct rte_security_ctx *ctx,
916 struct rte_security_session *sess,
917 const struct ipsec_test_flags *flags,
918 enum rte_security_ipsec_sa_direction dir)
920 struct rte_security_stats stats = {0};
921 int ret = TEST_SUCCESS;
923 if (flags->stats_success) {
924 if (rte_security_session_stats_get(ctx, sess, &stats) < 0)
927 if (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
928 if (stats.ipsec.opackets != 1 ||
929 stats.ipsec.oerrors != 0)
932 if (stats.ipsec.ipackets != 1 ||
933 stats.ipsec.ierrors != 0)
942 test_ipsec_pkt_update(uint8_t *pkt, const struct ipsec_test_flags *flags)
944 struct rte_ipv4_hdr *iph4;
945 bool cksum_dirty = false;
948 iph4 = (struct rte_ipv4_hdr *)pkt;
950 if (flags->df == TEST_IPSEC_COPY_DF_INNER_1 ||
951 flags->df == TEST_IPSEC_SET_DF_0_INNER_1 ||
952 flags->df == TEST_IPSEC_COPY_DF_INNER_0 ||
953 flags->df == TEST_IPSEC_SET_DF_1_INNER_0) {
955 if (!is_ipv4(iph4)) {
956 printf("Invalid packet type");
960 frag_off = rte_be_to_cpu_16(iph4->fragment_offset);
962 if (flags->df == TEST_IPSEC_COPY_DF_INNER_1 ||
963 flags->df == TEST_IPSEC_SET_DF_0_INNER_1)
964 frag_off |= RTE_IPV4_HDR_DF_FLAG;
966 frag_off &= ~RTE_IPV4_HDR_DF_FLAG;
968 iph4->fragment_offset = rte_cpu_to_be_16(frag_off);
972 if (cksum_dirty && is_ipv4(iph4)) {
973 iph4->hdr_checksum = 0;
974 iph4->hdr_checksum = rte_ipv4_cksum(iph4);
980 #endif /* !RTE_EXEC_ENV_WINDOWS */