diff mbox series

[1/3] ipsec: fix NAT-T ports and length

Message ID 20220525135912.181765-1-radu.nicolau@intel.com (mailing list archive)
State Accepted
Delegated to: akhil goyal
Headers show
Series [1/3] ipsec: fix NAT-T ports and length | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Radu Nicolau May 25, 2022, 1:59 p.m. UTC
Fix the UDP header fields, wrong byte order used for src and dst port
and wrong offset used when updating UDP datagram length.

Fixes: 01eef5907fc3 ("ipsec: support NAT-T")
Cc: stable@dpdk.org

Signed-off-by: Radu Nicolau <radu.nicolau@intel.com>
---
 lib/ipsec/esp_outb.c | 2 +-
 lib/ipsec/sa.c       | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

Comments

Zhang, Roy Fan June 14, 2022, 3:49 p.m. UTC | #1
> -----Original Message-----
> From: Radu Nicolau <radu.nicolau@intel.com>
> Sent: Wednesday, May 25, 2022 2:59 PM
> To: Konstantin Ananyev <konstantin.v.ananyev@yandex.ru>; Iremonger,
> Bernard <bernard.iremonger@intel.com>; Medvedkin, Vladimir
> <vladimir.medvedkin@intel.com>
> Cc: dev@dpdk.org; Buckley, Daniel M <daniel.m.buckley@intel.com>; Zhang, Qi
> Z <qi.z.zhang@intel.com>; Nicolau, Radu <radu.nicolau@intel.com>;
> stable@dpdk.org
> Subject: [PATCH 1/3] ipsec: fix NAT-T ports and length
> 
> Fix the UDP header fields, wrong byte order used for src and dst port
> and wrong offset used when updating UDP datagram length.
> 
> Fixes: 01eef5907fc3 ("ipsec: support NAT-T")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Radu Nicolau <radu.nicolau@intel.com>
> ---
Acked-by: Fan Zhang <roy.fan.zhang@intel.com>
Akhil Goyal June 15, 2022, 3:07 p.m. UTC | #2
> ----------------------------------------------------------------------
> Fix the UDP header fields, wrong byte order used for src and dst port
> and wrong offset used when updating UDP datagram length.
> 
> Fixes: 01eef5907fc3 ("ipsec: support NAT-T")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Radu Nicolau <radu.nicolau@intel.com>
Series applied to dpdk-next-crypto

Thanks.
diff mbox series

Patch

diff --git a/lib/ipsec/esp_outb.c b/lib/ipsec/esp_outb.c
index 6925bb9945..5a5429a12b 100644
--- a/lib/ipsec/esp_outb.c
+++ b/lib/ipsec/esp_outb.c
@@ -196,7 +196,7 @@  outb_tun_pkt_prepare(struct rte_ipsec_sa *sa, rte_be64_t sqc,
 	/* if UDP encap is enabled update the dgram_len */
 	if (sa->type & RTE_IPSEC_SATP_NATT_ENABLE) {
 		struct rte_udp_hdr *udph = (struct rte_udp_hdr *)
-				(ph - sizeof(struct rte_udp_hdr));
+			(ph + sa->hdr_len - sizeof(struct rte_udp_hdr));
 		udph->dgram_len = rte_cpu_to_be_16(mb->pkt_len - sqh_len -
 				sa->hdr_l3_off - sa->hdr_len);
 	}
diff --git a/lib/ipsec/sa.c b/lib/ipsec/sa.c
index 1b673b6a18..59a547637d 100644
--- a/lib/ipsec/sa.c
+++ b/lib/ipsec/sa.c
@@ -364,8 +364,8 @@  esp_outb_tun_init(struct rte_ipsec_sa *sa, const struct rte_ipsec_sa_prm *prm)
 		struct rte_udp_hdr *udph = (struct rte_udp_hdr *)
 				&sa->hdr[prm->tun.hdr_len];
 		sa->hdr_len += sizeof(struct rte_udp_hdr);
-		udph->src_port = prm->ipsec_xform.udp.sport;
-		udph->dst_port = prm->ipsec_xform.udp.dport;
+		udph->src_port = rte_cpu_to_be_16(prm->ipsec_xform.udp.sport);
+		udph->dst_port = rte_cpu_to_be_16(prm->ipsec_xform.udp.dport);
 		udph->dgram_cksum = 0;
 	}