Skip to contentSkip to conversation

ipsec: fix NAT-T ports and length

PATCH In review Radu Nicolau 3 participants 7 messages May 25, 2022 – Jun 15, 2022 Network drivers

lore
Share & tools
lore
#0 lore raw

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")
---
 lib/ipsec/esp_outb.c | 2 +-
 lib/ipsec/sa.c       | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
lib/ipsec/esp_outb.c +1 -1
index 6925bb9945..5a5429a12b 100644
@@ -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);
 	}
lib/ipsec/sa.c +2 -2
index 1b673b6a18..59a547637d 100644
@@ -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;
 	}
 
Signature · 1 line
2.25.1
#1 lore raw

PATCH 2/3 examples/ipsec-secgw: fix NAT-T header fields

Use the proper IP protocol (UDP instead of ESP) and set the ports when UDP encapsulation is enabled.

Fixes 9ae86b4cfc77 ("examples/ipsec-secgw: support UDP encap for inline crypto")
---
 examples/ipsec-secgw/sa.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
examples/ipsec-secgw/sa.c +4 -2
index 1839ac71af..45509c5c68 100644
@@ -1458,6 +1458,8 @@ fill_ipsec_sa_prm(struct rte_ipsec_sa_prm *prm, const struct ipsec_sa *ss,
 		RTE_SECURITY_IPSEC_SA_MODE_TRANSPORT :
 		RTE_SECURITY_IPSEC_SA_MODE_TUNNEL;
 	prm->ipsec_xform.options.udp_encap = ss->udp_encap;
+	prm->ipsec_xform.udp.dport = ss->udp.dport;
+	prm->ipsec_xform.udp.sport = ss->udp.sport;
 	prm->ipsec_xform.options.ecn = 1;
 	prm->ipsec_xform.options.copy_dscp = 1;
 
@@ -1513,13 +1515,13 @@ ipsec_sa_init(struct ipsec_sa *lsa, struct rte_ipsec_sa *sa, uint32_t sa_size)
 		.version_ihl = IPVERSION << 4 |
 			sizeof(v4) / RTE_IPV4_IHL_MULTIPLIER,
 		.time_to_live = IPDEFTTL,
-		.next_proto_id = IPPROTO_ESP,
+		.next_proto_id = lsa->udp_encap ? IPPROTO_UDP : IPPROTO_ESP,
 		.src_addr = lsa->src.ip.ip4,
 		.dst_addr = lsa->dst.ip.ip4,
 	};
 	struct rte_ipv6_hdr v6 = {
 		.vtc_flow = htonl(IP6_VERSION << 28),
-		.proto = IPPROTO_ESP,
+		.proto = lsa->udp_encap ? IPPROTO_UDP : IPPROTO_ESP,
 	};
 
 	if (IS_IP6_TUNNEL(lsa->flags)) {
Signature · 1 line
2.25.1
Acked-by on v1 2/3
#2 lore raw

RE: [PATCH 2/3] examples/ipsec-secgw: fix NAT-T header fields

Quoted 11 lines

-----Original Message-----
From: Radu Nicolau <[email protected]>
Sent: Wednesday, May 25, 2022 2:59 PM
To: Nicolau, Radu <[email protected]>; Akhil Goyal <[email protected]>
Cc: [email protected]; Buckley, Daniel M <[email protected]>; Zhang, Qi Z <[email protected]>; [email protected]
Subject: [PATCH 2/3] examples/ipsec-secgw: fix NAT-T header fields

Use the proper IP protocol (UDP instead of ESP) and set the ports when UDP encapsulation is enabled.

Quoted 6 lines
Fixes 9ae86b4cfc77 ("examples/ipsec-secgw: support UDP encap for inline

crypto")
Cc: [email protected]

---

#3 lore raw

PATCH 3/3 net/iavf: fix NAT-T payload length

In reply to Radu Nicolau

Correct the length calculation used for NAT-T

Fixes 6bc987ecb860 ("net/iavf: support IPsec inline crypto")
---
 drivers/net/iavf/iavf_ipsec_crypto.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/net/iavf/iavf_ipsec_crypto.c +7 -4
index b1949cee91..b398819096 100644
@@ -1118,11 +1118,14 @@ iavf_ipsec_crypto_compute_l4_payload_length(struct rte_mbuf *m,
 		 * ipv4/6 hdr + ext hdrs
 		 */
 
-	if (s->udp_encap.enabled)
+	if (s->udp_encap.enabled) {
 		ol4_len = sizeof(struct rte_udp_hdr);
-
-	l3_len = m->l3_len;
-	l4_len = m->l4_len;
+		l3_len = m->l3_len - ol4_len;
+		l4_len = l3_len;
+	} else {
+		l3_len = m->l3_len;
+		l4_len = m->l4_len;
+	}
 
 	return rte_pktmbuf_pkt_len(m) - (ol2_len + ol3_len + ol4_len +
 			esp_hlen + l3_len + l4_len + esp_tlen);
Signature · 1 line
2.25.1
Acked-by on v1 3/3
#4 lore raw

RE: [PATCH 3/3] net/iavf: fix NAT-T payload length

Quoted 9 lines

-----Original Message-----
From: Radu Nicolau <[email protected]>
Sent: Wednesday, May 25, 2022 2:59 PM
To: Wu, Jingjing <[email protected]>; Xing, Beilei <[email protected]>
Cc: [email protected]; Buckley, Daniel M <[email protected]>; Zhang, Qi Z <[email protected]>; Nicolau, Radu <[email protected]>; [email protected]
Subject: [PATCH 3/3] net/iavf: fix NAT-T payload length

Quoted 7 lines

Correct the length calculation used for NAT-T

Fixes 6bc987ecb860 ("net/iavf: support IPsec inline crypto")

---

Acked-by on v1 1/3
#5 lore raw
In reply to Radu Nicolau
Quoted 11 lines

-----Original Message-----
From: Radu Nicolau <[email protected]>
Sent: Wednesday, May 25, 2022 2:59 PM
To: Konstantin Ananyev <[email protected]>; Iremonger, Bernard <[email protected]>; Medvedkin, Vladimir <[email protected]>
Cc: [email protected]; Buckley, Daniel M <[email protected]>; Zhang, Qi Z <[email protected]>; Nicolau, Radu <[email protected]>; [email protected]
Subject: [PATCH 1/3] ipsec: fix NAT-T ports and length

Quoted 8 lines

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")

---