app/test: add support to run multi-seg inline IPsec test
PATCH 1/1 app/test: add support to run multi-seg inline IPsec test
Add support to run multi-seg inline ipsec test using new test comman inline_ipsec_sg_autotest
Signed-off-by Nithin Dabilpuram <[email protected]>
--- app/test/test_cryptodev_security_ipsec.c | 97 ++++++++++++++++- app/test/test_cryptodev_security_ipsec.h | 6 +- app/test/test_security_inline_proto.c | 133 +++++++++++++++++++++-- 3 files changed, 218 insertions(+), 18 deletions(-)
app/test/test_cryptodev_security_ipsec.c +92 -5
@@ -445,6 +445,65 @@ test_ipsec_td_prepare(const struct crypto_param *param1, } } +/* Adjust the data to requested length */ +if (flags->plaintext_len && flags->ipv6) { +struct rte_ipv6_hdr *ip6 = (struct rte_ipv6_hdr *)td->input_text.data; +struct rte_tcp_hdr *tcp; +int64_t payload_len; +uint8_t *data; +int64_t i; + + payload_len =RTE_MIN (flags->plaintext_len,IPSEC_TEXT_MAX_LEN ); + payload_len -=sizeof (struct rte_ipv6_hdr ); + payload_len -=sizeof (struct rte_tcp_hdr ); +if (payload_len <=16 ) + payload_len =16 ; + +/* IPv6 */ + ip6->proto =IPPROTO_TCP ; + ip6->payload_len =sizeof (*tcp) + payload_len; + ip6->payload_len =rte_cpu_to_be_16 (ip6->payload_len); + +/* TCP */ + tcp = (struct rte_tcp_hdr *)(ip6 +1 ); + data = (uint8_t *)(tcp +1 ); +for (i =0 ; i < payload_len; i++) + data[i] = i; + tcp->cksum =0 ; + tcp->cksum =rte_ipv6_udptcp_cksum (ip6, tcp); + td->input_text.len = payload_len +sizeof (struct rte_ipv6_hdr ) + +sizeof (struct rte_tcp_hdr ); + }else if (flags->plaintext_len) { +struct rte_ipv4_hdr *ip = (struct rte_ipv4_hdr *)td->input_text.data; +struct rte_tcp_hdr *tcp; +int64_t payload_len; +uint8_t *data; +int64_t i; + + payload_len =RTE_MIN (flags->plaintext_len,IPSEC_TEXT_MAX_LEN ); + payload_len -=sizeof (struct rte_ipv4_hdr ); + payload_len -=sizeof (struct rte_tcp_hdr ); +if (payload_len <=8 ) + payload_len =8 ; + +/* IPv4 */ + ip->next_proto_id =IPPROTO_TCP ; + ip->total_length =sizeof (*ip) +sizeof (*tcp) + payload_len; + ip->total_length =rte_cpu_to_be_16 (ip->total_length); + ip->hdr_checksum =0 ; + ip->hdr_checksum =rte_ipv4_cksum (ip); + +/* TCP */ + tcp = (struct rte_tcp_hdr *)(ip +1 ); + data = (uint8_t *)(tcp +1 ); +for (i =0 ; i < payload_len; i++) + data[i] = i; + tcp->cksum =0 ; + tcp->cksum =rte_ipv4_udptcp_cksum (ip, tcp); + td->input_text.len = payload_len +sizeof (struct rte_ipv4_hdr ) + +sizeof (struct rte_tcp_hdr ); + } +if (flags->ah) { td->ipsec_xform.proto =RTE_SECURITY_IPSEC_SA_PROTO_AH ;
@@ -662,13 +721,23 @@ static int test_ipsec_l4_csum_verify(struct rte_mbuf *m) {uint16_t actual_cksum =0 , expected_cksum =0 ; +uint32_t len =rte_pktmbuf_pkt_len (m); +uint8_t data_arr[IPSEC_TEXT_MAX_LEN ];struct rte_ipv4_hdr *ipv4;struct rte_ipv6_hdr *ipv6; +uint8_t *data = data_arr;struct rte_tcp_hdr *tcp;struct rte_udp_hdr *udp; +const uint8_t *ptr;void *ip, *l4; - ip = rte_pktmbuf_mtod(m, void *); + ptr =rte_pktmbuf_read (m,0 , len, data_arr); +if (!ptr) +return -EINVAL ; +else if (ptr != data_arr) + data = rte_pktmbuf_mtod_offset(m, uint8_t *, 0); + + ip = (struct rte_ipv4_hdr *)data;if (is_ipv4 (ip)) { ipv4 = ip;
@@ -748,9 +817,11 @@ static int test_ipsec_td_verify(struct rte_mbuf *m, const struct ipsec_test_data *td, bool silent, const struct ipsec_test_flags *flags) { - uint8_t *output_text = rte_pktmbuf_mtod(m, uint8_t *); uint32_t skip, len = rte_pktmbuf_pkt_len(m); -uint8_t td_output_text[4096 ]; +uint8_t td_output_text[IPSEC_TEXT_MAX_LEN ]; +uint8_t data_arr[IPSEC_TEXT_MAX_LEN ]; +uint8_t *output_text = data_arr; +const uint8_t *ptr;int ret;/* For tests with status as error for test success, skip verification */
@@ -761,6 +832,12 @@ test_ipsec_td_verify(struct rte_mbuf *m, const struct ipsec_test_data *td, td->ar_packet))return TEST_SUCCESS ; + ptr =rte_pktmbuf_read (m,0 , len, data_arr); +if (!ptr) +return -EINVAL ; +else if (ptr != data_arr) + output_text = rte_pktmbuf_mtod_offset(m, uint8_t *, 0); +if (td->ipsec_xform.direction ==RTE_SECURITY_IPSEC_SA_DIR_EGRESS && flags->udp_encap) {const struct rte_ipv4_hdr *iph4;
@@ -868,10 +945,20 @@ test_ipsec_res_d_prepare(struct rte_mbuf *m, const struct ipsec_test_data *td, { uint8_t *output_text = rte_pktmbuf_mtod(m, uint8_t *);uint32_t len =rte_pktmbuf_pkt_len (m); +struct rte_mbuf *next = m; +uint32_t off =0 ;memcpy (res_d, td,sizeof (*res_d)); -memcpy (res_d->input_text.data, output_text, len); - res_d->input_text.len = len; + +while (next && off < len) { + output_text = rte_pktmbuf_mtod(next, uint8_t *); +if (off + next->data_len >sizeof (res_d->input_text.data)) +break ; +memcpy (&res_d->input_text.data[off], output_text, next->data_len); + off += next->data_len; + next = next->next; + } + res_d->input_text.len = off; res_d->ipsec_xform.direction =RTE_SECURITY_IPSEC_SA_DIR_INGRESS ;if (res_d->aead) {
app/test/test_cryptodev_security_ipsec.h +4 -2
@@ -9,6 +9,7 @@#include <rte_security.h> #define IPSEC_TEST_PACKETS_MAX 32 +#define IPSEC_TEXT_MAX_LEN 16384u struct ipsec_test_data { struct {
@@ -19,12 +20,12 @@ struct ipsec_test_data { } auth_key;struct { -uint8_t data[1024 ]; +uint8_t data[IPSEC_TEXT_MAX_LEN ];unsigned int len; } input_text;struct { -uint8_t data[1024 ]; +uint8_t data[IPSEC_TEXT_MAX_LEN ];unsigned int len; } output_text;
@@ -106,6 +107,7 @@ struct ipsec_test_flags {enum flabel_flags flabel;bool dec_ttl_or_hop_limit;bool ah; +uint32_t plaintext_len; };struct crypto_param {
app/test/test_security_inline_proto.c +122 -11
418 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 1/1 app/test: add support to run multi-seg inline IPsec test
Add support to run multi-seg inline ipsec test using new test command inline_ipsec_sg_autotest
Signed-off-by Nithin Dabilpuram <[email protected]>
---
v2:
- Fixed commit message and Windows compilation issue.
app/test/test_cryptodev_security_ipsec.c | 97 +++++++++++++++- app/test/test_cryptodev_security_ipsec.h | 6 +- app/test/test_security_inline_proto.c | 140 +++++++++++++++++++++-- 3 files changed, 225 insertions(+), 18 deletions(-)
app/test/test_cryptodev_security_ipsec.c +92 -5
@@ -445,6 +445,65 @@ test_ipsec_td_prepare(const struct crypto_param *param1, } } +/* Adjust the data to requested length */ +if (flags->plaintext_len && flags->ipv6) { +struct rte_ipv6_hdr *ip6 = (struct rte_ipv6_hdr *)td->input_text.data; +struct rte_tcp_hdr *tcp; +int64_t payload_len; +uint8_t *data; +int64_t i; + + payload_len =RTE_MIN (flags->plaintext_len,IPSEC_TEXT_MAX_LEN ); + payload_len -=sizeof (struct rte_ipv6_hdr ); + payload_len -=sizeof (struct rte_tcp_hdr ); +if (payload_len <=16 ) + payload_len =16 ; + +/* IPv6 */ + ip6->proto =IPPROTO_TCP ; + ip6->payload_len =sizeof (*tcp) + payload_len; + ip6->payload_len =rte_cpu_to_be_16 (ip6->payload_len); + +/* TCP */ + tcp = (struct rte_tcp_hdr *)(ip6 +1 ); + data = (uint8_t *)(tcp +1 ); +for (i =0 ; i < payload_len; i++) + data[i] = i; + tcp->cksum =0 ; + tcp->cksum =rte_ipv6_udptcp_cksum (ip6, tcp); + td->input_text.len = payload_len +sizeof (struct rte_ipv6_hdr ) + +sizeof (struct rte_tcp_hdr ); + }else if (flags->plaintext_len) { +struct rte_ipv4_hdr *ip = (struct rte_ipv4_hdr *)td->input_text.data; +struct rte_tcp_hdr *tcp; +int64_t payload_len; +uint8_t *data; +int64_t i; + + payload_len =RTE_MIN (flags->plaintext_len,IPSEC_TEXT_MAX_LEN ); + payload_len -=sizeof (struct rte_ipv4_hdr ); + payload_len -=sizeof (struct rte_tcp_hdr ); +if (payload_len <=8 ) + payload_len =8 ; + +/* IPv4 */ + ip->next_proto_id =IPPROTO_TCP ; + ip->total_length =sizeof (*ip) +sizeof (*tcp) + payload_len; + ip->total_length =rte_cpu_to_be_16 (ip->total_length); + ip->hdr_checksum =0 ; + ip->hdr_checksum =rte_ipv4_cksum (ip); + +/* TCP */ + tcp = (struct rte_tcp_hdr *)(ip +1 ); + data = (uint8_t *)(tcp +1 ); +for (i =0 ; i < payload_len; i++) + data[i] = i; + tcp->cksum =0 ; + tcp->cksum =rte_ipv4_udptcp_cksum (ip, tcp); + td->input_text.len = payload_len +sizeof (struct rte_ipv4_hdr ) + +sizeof (struct rte_tcp_hdr ); + } +if (flags->ah) { td->ipsec_xform.proto =RTE_SECURITY_IPSEC_SA_PROTO_AH ;
@@ -662,13 +721,23 @@ static int test_ipsec_l4_csum_verify(struct rte_mbuf *m) {uint16_t actual_cksum =0 , expected_cksum =0 ; +uint32_t len =rte_pktmbuf_pkt_len (m); +uint8_t data_arr[IPSEC_TEXT_MAX_LEN ];struct rte_ipv4_hdr *ipv4;struct rte_ipv6_hdr *ipv6; +uint8_t *data = data_arr;struct rte_tcp_hdr *tcp;struct rte_udp_hdr *udp; +const uint8_t *ptr;void *ip, *l4; - ip = rte_pktmbuf_mtod(m, void *); + ptr =rte_pktmbuf_read (m,0 , len, data_arr); +if (!ptr) +return -EINVAL ; +else if (ptr != data_arr) + data = rte_pktmbuf_mtod_offset(m, uint8_t *, 0); + + ip = (struct rte_ipv4_hdr *)data;if (is_ipv4 (ip)) { ipv4 = ip;
@@ -748,9 +817,11 @@ static int test_ipsec_td_verify(struct rte_mbuf *m, const struct ipsec_test_data *td, bool silent, const struct ipsec_test_flags *flags) { - uint8_t *output_text = rte_pktmbuf_mtod(m, uint8_t *); uint32_t skip, len = rte_pktmbuf_pkt_len(m); -uint8_t td_output_text[4096 ]; +uint8_t td_output_text[IPSEC_TEXT_MAX_LEN ]; +uint8_t data_arr[IPSEC_TEXT_MAX_LEN ]; +uint8_t *output_text = data_arr; +const uint8_t *ptr;int ret;/* For tests with status as error for test success, skip verification */
@@ -761,6 +832,12 @@ test_ipsec_td_verify(struct rte_mbuf *m, const struct ipsec_test_data *td, td->ar_packet))return TEST_SUCCESS ; + ptr =rte_pktmbuf_read (m,0 , len, data_arr); +if (!ptr) +return -EINVAL ; +else if (ptr != data_arr) + output_text = rte_pktmbuf_mtod_offset(m, uint8_t *, 0); +if (td->ipsec_xform.direction ==RTE_SECURITY_IPSEC_SA_DIR_EGRESS && flags->udp_encap) {const struct rte_ipv4_hdr *iph4;
@@ -868,10 +945,20 @@ test_ipsec_res_d_prepare(struct rte_mbuf *m, const struct ipsec_test_data *td, { uint8_t *output_text = rte_pktmbuf_mtod(m, uint8_t *);uint32_t len =rte_pktmbuf_pkt_len (m); +struct rte_mbuf *next = m; +uint32_t off =0 ;memcpy (res_d, td,sizeof (*res_d)); -memcpy (res_d->input_text.data, output_text, len); - res_d->input_text.len = len; + +while (next && off < len) { + output_text = rte_pktmbuf_mtod(next, uint8_t *); +if (off + next->data_len >sizeof (res_d->input_text.data)) +break ; +memcpy (&res_d->input_text.data[off], output_text, next->data_len); + off += next->data_len; + next = next->next; + } + res_d->input_text.len = off; res_d->ipsec_xform.direction =RTE_SECURITY_IPSEC_SA_DIR_INGRESS ;if (res_d->aead) {
app/test/test_cryptodev_security_ipsec.h +4 -2
@@ -9,6 +9,7 @@#include <rte_security.h> #define IPSEC_TEST_PACKETS_MAX 32 +#define IPSEC_TEXT_MAX_LEN 16384u struct ipsec_test_data { struct {
@@ -19,12 +20,12 @@ struct ipsec_test_data { } auth_key;struct { -uint8_t data[1024 ]; +uint8_t data[IPSEC_TEXT_MAX_LEN ];unsigned int len; } input_text;struct { -uint8_t data[1024 ]; +uint8_t data[IPSEC_TEXT_MAX_LEN ];unsigned int len; } output_text;
@@ -106,6 +107,7 @@ struct ipsec_test_flags {enum flabel_flags flabel;bool dec_ttl_or_hop_limit;bool ah; +uint32_t plaintext_len; };struct crypto_param {
app/test/test_security_inline_proto.c +129 -11
431 lines not on this page · raw message
Signature · 1 line
2.25.1
Quoted 7 lines
Subject: [PATCH v2] app/test: add support to run multi-seg inline IPsec test
Add support to run multi-seg inline ipsec test using new test command
inline_ipsec_sg_autotestSigned-off-by Nithin Dabilpuram <[email protected]>---
Acked-by Akhil Goyal <[email protected]>
Applied to dpdk-next-crypto
Thanks.