Skip to contentSkip to conversation

fixes for inline-crypto ipsec

PATCH In review Mariusz Drost 2 participants 5 messages Jun 26, 2019 – Jul 1, 2019 1 message not in the archive Network drivers

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): –[email protected]

#1 lore raw

v2 cover fixes for inline-crypto ipsec

Fixes for ipsec-secgw application to work with inline crypto IPv4 transport mode and IPv6 tunnel/transport modes.

v2:
* Added comment to WITHOUT_TRANSPORT_VERSION macro
* Added macros around all ipsec_sa flags checks

Mariusz Drost (2):
net/ixgbe: fix lack of ip type for crypto session examples/ipsec-secgw: fix not working inline ipsec modes

 drivers/net/ixgbe/ixgbe_ipsec.c |   6 +-
 examples/ipsec-secgw/esp.c      |  17 ++--
 examples/ipsec-secgw/ipsec.c    |  21 +++--
 examples/ipsec-secgw/ipsec.h    |  29 +++++-
 examples/ipsec-secgw/sa.c       | 160 +++++++++++++++++++++++---------
 examples/ipsec-secgw/sp4.c      |  24 ++++-
 examples/ipsec-secgw/sp6.c      |  42 ++++++++-
 7 files changed, 230 insertions(+), 69 deletions(-)
Signature · 1 line
2.17.1
#2 lore raw

PATCH v2 1/2 net/ixgbe: fix lack of ip type for crypto session

When ixgbe_crypto_add_sa() is called, it checks whether the ip type is IPv6 or IPv4 to write correct addresses to the registers. Type itself is never specified, and act as IPv4, which is the default value. It causes lack of support for IPv6.

To fix that, ip type needs to be stored in device private data, based on crypto session ip type field, before the checking is done.

Fixes ec17993a145a ("examples/ipsec-secgw: support security offload")
Fixes 9a0752f498d2 ("net/ixgbe: enable inline IPsec")
---
 drivers/net/ixgbe/ixgbe_ipsec.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/net/ixgbe/ixgbe_ipsec.c +5 -1
index 5a416885f..1eea70716 100644
@@ -154,8 +154,12 @@ ixgbe_crypto_add_sa(struct ixgbe_crypto_session *ic_session)
 		if (ic_session->op == IXGBE_OP_AUTHENTICATED_DECRYPTION)
 			priv->rx_sa_tbl[sa_index].mode |=
 					(IPSRXMOD_PROTO | IPSRXMOD_DECRYPT);
-		if (ic_session->dst_ip.type == IPv6)
+		if (ic_session->dst_ip.type == IPv6) {
 			priv->rx_sa_tbl[sa_index].mode |= IPSRXMOD_IPV6;
+			priv->rx_ip_tbl[ip_index].ip.type = IPv6;
+		} else if (ic_session->dst_ip.type == IPv4)
+			priv->rx_ip_tbl[ip_index].ip.type = IPv4;
+
 		priv->rx_sa_tbl[sa_index].used = 1;
 
 		/* write IP table entry*/
Signature · 1 line
2.17.1
#3 lore raw

PATCH v2 2/2 examples/ipsec-secgw: fix not working inline ipsec modes

In reply to Mariusz Drost

Application ipsec-secgw is not working for IPv4 transport mode and for IPv6 both transport and tunnel mode.

IPv6 tunnel mode is not working due to wrongly assigned fields of security association patterns, as it was IPv4, during creation of inline crypto session.

IPv6 and IPv4 transport mode is iterating through security capabilities until it reaches tunnel, which causes session to be created as tunnel, instead of transport. Another issue, is that config file does not provide source and destination ip addresses for transport mode, which are required by NIC to perform inline crypto. It uses default addresses stored in security association (all zeroes), which causes dropped packages.

To fix that, reorganization of code in create_session() is needed, to behave appropriately to given protocol (IPv6/IPv4). Change in iteration through security capabilities is also required, to check for expected mode (not only tunnel).

For lack of addresses issue, some resolving mechanism is needed. Approach is to store addresses in security association, as it is for tunnel mode. Difference is that they are obtained from sp rules, instead of config file. To do that, sp[4/6]_spi_present() function is used to find addresses based on spi value, and then stored in corresponding sa rule. This approach assumes, that every sp rule for inline crypto have valid addresses, as well as range of addresses is not supported.

New flags for ipsec_sa structure are required to distinguish between IPv4 and IPv6 transport modes. Because of that, there is need to change all checks done on these flags, so they work as expected.

Fixes ec17993a145a ("examples/ipsec-secgw: support security offload")
Fixes 9a0752f498d2 ("net/ixgbe: enable inline IPsec")
---
 examples/ipsec-secgw/esp.c   |  17 ++--
 examples/ipsec-secgw/ipsec.c |  21 +++--
 examples/ipsec-secgw/ipsec.h |  29 ++++++-
 examples/ipsec-secgw/sa.c    | 160 +++++++++++++++++++++++++----------
 examples/ipsec-secgw/sp4.c   |  24 +++++-
 examples/ipsec-secgw/sp6.c   |  42 ++++++++-
 6 files changed, 225 insertions(+), 68 deletions(-)
examples/ipsec-secgw/esp.c +8 -9
index f11d095ba..d6d7b1256 100644
@@ -192,7 +192,7 @@ esp_inbound_post(struct rte_mbuf *m, struct ipsec_sa *sa,
 		}
 	}
 
-	if (unlikely(sa->flags == TRANSPORT)) {
+	if (unlikely(IS_TRANSPORT(sa->flags))) {
 		ip = rte_pktmbuf_mtod(m, struct ip *);
 		ip4 = (struct ip *)rte_pktmbuf_adj(m,
 				sizeof(struct rte_esp_hdr) + sa->iv_len);
@@ -233,13 +233,13 @@ esp_outbound(struct rte_mbuf *m, struct ipsec_sa *sa,
 
 	ip4 = rte_pktmbuf_mtod(m, struct ip *);
 	if (likely(ip4->ip_v == IPVERSION)) {
-		if (unlikely(sa->flags == TRANSPORT)) {
+		if (unlikely(IS_TRANSPORT(sa->flags))) {
 			ip_hdr_len = ip4->ip_hl * 4;
 			nlp = ip4->ip_p;
 		} else
 			nlp = IPPROTO_IPIP;
 	} else if (ip4->ip_v == IP6_VERSION) {
-		if (unlikely(sa->flags == TRANSPORT)) {
+		if (unlikely(IS_TRANSPORT(sa->flags))) {
 			/* XXX No option headers supported */
 			ip_hdr_len = sizeof(struct ip6_hdr);
 			ip6 = (struct ip6_hdr *)ip4;
@@ -257,14 +257,13 @@ esp_outbound(struct rte_mbuf *m, struct ipsec_sa *sa,
 			ip_hdr_len + 2, sa->block_size);
 	pad_len = pad_payload_len + ip_hdr_len - rte_pktmbuf_pkt_len(m);
 
-	RTE_ASSERT(sa->flags == IP4_TUNNEL || sa->flags == IP6_TUNNEL ||
-			sa->flags == TRANSPORT);
+	RTE_ASSERT(IS_TUNNEL(sa->flags) || IS_TRANSPORT(sa->flags));
 
-	if (likely(sa->flags == IP4_TUNNEL))
+	if (likely(IS_IP4_TUNNEL(sa->flags)))
 		ip_hdr_len = sizeof(struct ip);
-	else if (sa->flags == IP6_TUNNEL)
+	else if (IS_IP6_TUNNEL(sa->flags))
 		ip_hdr_len = sizeof(struct ip6_hdr);
-	else if (sa->flags != TRANSPORT) {
+	else if (!IS_TRANSPORT(sa->flags)) {
 		RTE_LOG(ERR, IPSEC_ESP, "Unsupported SA flags: 0x%x\n",
 				sa->flags);
 		return -EINVAL;
@@ -291,7 +290,7 @@ esp_outbound(struct rte_mbuf *m, struct ipsec_sa *sa,
 		rte_prefetch0(padding);
 	}
 
-	switch (sa->flags) {
+	switch (WITHOUT_TRANSPORT_VERSION(sa->flags)) {
 	case IP4_TUNNEL:
 		ip4 = ip4ip_outbound(m, sizeof(struct rte_esp_hdr) + sa->iv_len,
 				&sa->src, &sa->dst);
examples/ipsec-secgw/ipsec.c +12 -9
index 7b8533077..d1cbdc38d 100644
@@ -23,7 +23,7 @@ set_ipsec_conf(struct ipsec_sa *sa, struct rte_security_ipsec_xform *ipsec)
 	if (ipsec->mode == RTE_SECURITY_IPSEC_SA_MODE_TUNNEL) {
 		struct rte_security_ipsec_tunnel_param *tunnel =
 				&ipsec->tunnel;
-		if (sa->flags == IP4_TUNNEL) {
+		if (IS_IP4_TUNNEL(sa->flags)) {
 			tunnel->type =
 				RTE_SECURITY_IPSEC_TUNNEL_IPV4;
 			tunnel->ipv4.ttl = IPDEFTTL;
@@ -83,8 +83,7 @@ create_session(struct ipsec_ctx *ipsec_ctx, struct ipsec_sa *sa)
 				.options = { 0 },
 				.direction = sa->direction,
 				.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
-				.mode = (sa->flags == IP4_TUNNEL ||
-						sa->flags == IP6_TUNNEL) ?
+				.mode = (IS_TUNNEL(sa->flags)) ?
 					RTE_SECURITY_IPSEC_SA_MODE_TUNNEL :
 					RTE_SECURITY_IPSEC_SA_MODE_TRANSPORT,
 			} },
@@ -134,7 +133,7 @@ create_session(struct ipsec_ctx *ipsec_ctx, struct ipsec_sa *sa)
 				    sec_cap->protocol ==
 					RTE_SECURITY_PROTOCOL_IPSEC &&
 				    sec_cap->ipsec.mode ==
-					RTE_SECURITY_IPSEC_SA_MODE_TUNNEL &&
+					sess_conf.ipsec.mode &&
 				    sec_cap->ipsec.direction == sa->direction)
 					break;
 				sec_cap++;
@@ -150,16 +149,20 @@ create_session(struct ipsec_ctx *ipsec_ctx, struct ipsec_sa *sa)
 			sa->security_ctx = ctx;
 			sa->pattern[0].type = RTE_FLOW_ITEM_TYPE_ETH;
 
-			sa->pattern[1].type = RTE_FLOW_ITEM_TYPE_IPV4;
-			sa->pattern[1].mask = &rte_flow_item_ipv4_mask;
-			if (sa->flags & IP6_TUNNEL) {
+			if (IS_IP6(sa->flags)) {
+				sa->pattern[1].mask = &rte_flow_item_ipv6_mask;
+				sa->pattern[1].type = RTE_FLOW_ITEM_TYPE_IPV6;
 				sa->pattern[1].spec = &sa->ipv6_spec;
+
 				memcpy(sa->ipv6_spec.hdr.dst_addr,
 					sa->dst.ip.ip6.ip6_b, 16);
 				memcpy(sa->ipv6_spec.hdr.src_addr,
 				       sa->src.ip.ip6.ip6_b, 16);
-			} else {
+			} else if (IS_IP4(sa->flags)) {
+				sa->pattern[1].mask = &rte_flow_item_ipv4_mask;
+				sa->pattern[1].type = RTE_FLOW_ITEM_TYPE_IPV4;
 				sa->pattern[1].spec = &sa->ipv4_spec;
+
 				sa->ipv4_spec.hdr.dst_addr = sa->dst.ip.ip4;
 				sa->ipv4_spec.hdr.src_addr = sa->src.ip.ip4;
 			}
@@ -303,7 +306,7 @@ create_session(struct ipsec_ctx *ipsec_ctx, struct ipsec_sa *sa)
 				    sec_cap->protocol ==
 					RTE_SECURITY_PROTOCOL_IPSEC &&
 				    sec_cap->ipsec.mode ==
-					RTE_SECURITY_IPSEC_SA_MODE_TUNNEL &&
+					sess_conf.ipsec.mode &&
 				    sec_cap->ipsec.direction == sa->direction)
 					break;
 				sec_cap++;
examples/ipsec-secgw/ipsec.h +27 -2
index e9272d74b..88bd24dc1 100644
@@ -101,6 +101,8 @@ struct ipsec_sa {
 #define IP4_TUNNEL (1 << 0)
 #define IP6_TUNNEL (1 << 1)
 #define TRANSPORT  (1 << 2)
+#define IP4_TRANSPORT (1 << 3)
+#define IP6_TRANSPORT (1 << 4)
 	struct ip_addr src;
 	struct ip_addr dst;
 	uint8_t cipher_key[MAX_KEY_SIZE];
@@ -139,6 +141,27 @@ struct ipsec_mbuf_metadata {
 	uint8_t buf[32];
 } __rte_cache_aligned;
 
+#define IS_TRANSPORT(flags) ((flags) & TRANSPORT)
+
+#define IS_TUNNEL(flags) ((flags) & (IP4_TUNNEL | IP6_TUNNEL))
+
+#define IS_IP4(flags) ((flags) & (IP4_TUNNEL | IP4_TRANSPORT))
+
+#define IS_IP6(flags) ((flags) & (IP6_TUNNEL | IP6_TRANSPORT))
+
+#define IS_IP4_TUNNEL(flags) ((flags) & IP4_TUNNEL)
+
+#define IS_IP6_TUNNEL(flags) ((flags) & IP6_TUNNEL)
+
+/*
+ * Macro for getting ipsec_sa flags statuses without version of protocol
+ * used for transport (IP4_TRANSPORT and IP6_TRANSPORT flags).
+ */
+#define WITHOUT_TRANSPORT_VERSION(flags) \
+		((flags) & (IP4_TUNNEL | \
+			IP6_TUNNEL | \
+			TRANSPORT))
+
 struct cdev_qp {
 	uint16_t id;
 	uint16_t qp;
@@ -283,9 +306,11 @@ sp6_init(struct socket_ctx *ctx, int32_t socket_id);
  * or -ENOENT otherwise.
  */
 int
-sp4_spi_present(uint32_t spi, int inbound);
+sp4_spi_present(uint32_t spi, int inbound, struct ip_addr ip_addr[2],
+			uint32_t mask[2]);
 int
-sp6_spi_present(uint32_t spi, int inbound);
+sp6_spi_present(uint32_t spi, int inbound, struct ip_addr ip_addr[2],
+			uint32_t mask[2]);
 
 /*
  * Search through SA entries for given SPI.
examples/ipsec-secgw/sa.c +116 -44

266 lines not on this page · raw message

examples/ipsec-secgw/sp4.c +22 -2
index ca9ee7f24..3871c6cc1 100644
@@ -17,6 +17,18 @@
 
 #define MAX_ACL_RULE_NUM	1024
 
+#define IPV4_DST_FROM_SP(acr) \
+		(rte_cpu_to_be_32((acr).field[DST_FIELD_IPV4].value.u32))
+
+#define IPV4_SRC_FROM_SP(acr) \
+		(rte_cpu_to_be_32((acr).field[SRC_FIELD_IPV4].value.u32))
+
+#define IPV4_DST_MASK_FROM_SP(acr) \
+		((acr).field[DST_FIELD_IPV4].mask_range.u32)
+
+#define IPV4_SRC_MASK_FROM_SP(acr) \
+		((acr).field[SRC_FIELD_IPV4].mask_range.u32)
+
 /*
  * Rule and trace formats definitions.
  */
@@ -552,7 +564,8 @@ sp4_init(struct socket_ctx *ctx, int32_t socket_id)
  * Search though SP rules for given SPI.
  */
 int
-sp4_spi_present(uint32_t spi, int inbound)
+sp4_spi_present(uint32_t spi, int inbound, struct ip_addr ip_addr[2],
+			uint32_t mask[2])
 {
 	uint32_t i, num;
 	const struct acl4_rules *acr;
@@ -566,8 +579,15 @@ sp4_spi_present(uint32_t spi, int inbound)
 	}
 
 	for (i = 0; i != num; i++) {
-		if (acr[i].data.userdata == spi)
+		if (acr[i].data.userdata == spi) {
+			if (NULL != ip_addr && NULL != mask) {
+				ip_addr[0].ip.ip4 = IPV4_SRC_FROM_SP(acr[i]);
+				ip_addr[1].ip.ip4 = IPV4_DST_FROM_SP(acr[i]);
+				mask[0] = IPV4_SRC_MASK_FROM_SP(acr[i]);
+				mask[1] = IPV4_DST_MASK_FROM_SP(acr[i]);
+			}
 			return i;
+		}
 	}
 
 	return -ENOENT;
examples/ipsec-secgw/sp6.c +40 -2

61 lines not on this page · raw message

Signature · 1 line
2.17.1
Acked-by on v2 2/2
#4 lore raw

Re: [dpdk-dev] [PATCH v2 2/2] examples/ipsec-secgw: fix not working inline ipsec modes

Quoted 35 lines

Application ipsec-secgw is not working for IPv4 transport mode and for IPv6 both transport and tunnel mode.

IPv6 tunnel mode is not working due to wrongly assigned fields of security association patterns, as it was IPv4, during creation of inline crypto session.

IPv6 and IPv4 transport mode is iterating through security capabilities until it reaches tunnel, which causes session to be created as tunnel, instead of transport. Another issue, is that config file does not provide source and destination ip addresses for transport mode, which are required by NIC to perform inline crypto. It uses default addresses stored in security association (all zeroes), which causes dropped packages.

To fix that, reorganization of code in create_session() is needed, to behave appropriately to given protocol (IPv6/IPv4). Change in iteration through security capabilities is also required, to check for expected mode (not only tunnel).

For lack of addresses issue, some resolving mechanism is needed. Approach is to store addresses in security association, as it is for tunnel mode. Difference is that they are obtained from sp rules, instead of config file. To do that, sp[4/6]_spi_present() function is used to find addresses based on spi value, and then stored in corresponding sa rule. This approach assumes, that every sp rule for inline crypto have valid addresses, as well as range of addresses is not supported.

New flags for ipsec_sa structure are required to distinguish between IPv4 and IPv6 transport modes. Because of that, there is need to change all checks done on these flags, so they work as expected.

Quoted 7 lines
Fixes ec17993a145a ("examples/ipsec-secgw: support security offload")
Fixes 9a0752f498d2 ("net/ixgbe: enable inline IPsec")

---

#5 lore raw
In reply to Mariusz Drost
Quoted 13 lines

Fixes for ipsec-secgw application to work with inline crypto IPv4 transport mode and IPv6 tunnel/transport modes.

v2:
* Added comment to WITHOUT_TRANSPORT_VERSION macro
* Added macros around all ipsec_sa flags checks

Mariusz Drost (2):
net/ixgbe: fix lack of ip type for crypto session examples/ipsec-secgw: fix not working inline ipsec modes

Quoted 8 lines
 drivers/net/ixgbe/ixgbe_ipsec.c |   6 +-
 examples/ipsec-secgw/esp.c      |  17 ++--
 examples/ipsec-secgw/ipsec.c    |  21 +++--
 examples/ipsec-secgw/ipsec.h    |  29 +++++-
 examples/ipsec-secgw/sa.c       | 160 +++++++++++++++++++++++---------
 examples/ipsec-secgw/sp4.c      |  24 ++++-
 examples/ipsec-secgw/sp6.c      |  42 ++++++++-
 7 files changed, 230 insertions(+), 69 deletions(-)

Patchset Applied to dpdk-next-crypto

Thanks.