Skip to contentSkip to conversation

l2fwd-crypto: remove padding after decrypting

PATCH New Hemant Agrawal 2 participants 4 messages Feb 23, 2021 – Apr 13, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 l2fwd-crypto: remove padding after decrypting

From: Rohit Raj <[email protected]>

There were some padding left when a packet gets decrypted. This patch removes those padding.
This patch also removes the padding left after verifying auth of the packet.

---
 examples/l2fwd-crypto/main.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
examples/l2fwd-crypto/main.c +14 -0
index a96cb94cc..e7a1eea30 100644
@@ -616,12 +616,26 @@ l2fwd_simple_forward(struct rte_mbuf *m, uint16_t portid,
 		struct l2fwd_crypto_options *options)
 {
 	uint16_t dst_port;
+	uint32_t pad_len;
+	struct rte_ipv4_hdr *ip_hdr;
+	uint32_t ipdata_offset = sizeof(struct rte_ether_hdr);
 
+	ip_hdr = (struct rte_ipv4_hdr *)(rte_pktmbuf_mtod(m, char *) +
+					 ipdata_offset);
 	dst_port = l2fwd_dst_ports[portid];
 
 	if (options->mac_updating)
 		l2fwd_mac_updating(m, dst_port);
 
+	if (options->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY)
+		rte_pktmbuf_trim(m, options->auth_xform.auth.digest_length);
+
+	if (options->cipher_xform.cipher.op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
+		pad_len = m->pkt_len - rte_be_to_cpu_16(ip_hdr->total_length) -
+			  ipdata_offset;
+		rte_pktmbuf_trim(m, pad_len);
+	}
+
 	l2fwd_send_packet(m, dst_port);
 }
 
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/1 l2fwd-crypto: remove padding after decrypting

There were some padding left when a packet gets decrypted. This patch removes those padding.
This patch also removes the padding left after verifying auth of the packet.

---
 examples/l2fwd-crypto/main.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

this patch is a fix for a bug.
Could you please add a fixes tag and update the title of patch accordingly examples/l2fwd-crypto: fix packet length while decryption

#2 lore raw

PATCH v2 1/1 l2fwd-crypto: fix packet length while decryption

In reply to Hemant Agrawal

From: Rohit Raj <[email protected]>

There were some padding left when a packet gets decrypted. This patch removes those padding.
This patch also removes the padding left after verifying auth of the packet.

Fixes e2cdfbd07c8a ("examples/l2fwd-crypto: fix port id type")
---
 examples/l2fwd-crypto/main.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
examples/l2fwd-crypto/main.c +14 -0
index 1016ceb841..23a398043e 100644
@@ -616,12 +616,26 @@ l2fwd_simple_forward(struct rte_mbuf *m, uint16_t portid,
 		struct l2fwd_crypto_options *options)
 {
 	uint16_t dst_port;
+	uint32_t pad_len;
+	struct rte_ipv4_hdr *ip_hdr;
+	uint32_t ipdata_offset = sizeof(struct rte_ether_hdr);
 
+	ip_hdr = (struct rte_ipv4_hdr *)(rte_pktmbuf_mtod(m, char *) +
+					 ipdata_offset);
 	dst_port = l2fwd_dst_ports[portid];
 
 	if (options->mac_updating)
 		l2fwd_mac_updating(m, dst_port);
 
+	if (options->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY)
+		rte_pktmbuf_trim(m, options->auth_xform.auth.digest_length);
+
+	if (options->cipher_xform.cipher.op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
+		pad_len = m->pkt_len - rte_be_to_cpu_16(ip_hdr->total_length) -
+			  ipdata_offset;
+		rte_pktmbuf_trim(m, pad_len);
+	}
+
 	l2fwd_send_packet(m, dst_port);
 }
 
Signature · 1 line
2.17.1
Acked-by on v2 1/1 Applied
#3 lore raw

Re: [dpdk-dev] [EXT] [PATCH v2] l2fwd-crypto: fix packet length while decryption

Quoted 11 lines

From: Rohit Raj <[email protected]>

There were some padding left when a packet gets decrypted. This patch removes those padding.
This patch also removes the padding left after verifying auth of the packet.

Fixes e2cdfbd07c8a ("examples/l2fwd-crypto: fix port id type")

Applied to dpdk-next-crypto

Thanks.