Skip to contentSkip to conversation

RFC: ethdev: add reassembly offload

PATCH In review Akhil Goyal 12 participants 184 messages Aug 23, 2021 – Sep 27, 2022 Arm/Amlogic Meson SoC support Page 1 of 2

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 RFC: ethdev: add reassembly offload

Reassembly is a costly operation if it is done in software, however, if it is offloaded to HW, it can considerably save application cycles.
The operation becomes even more costlier if IP fragmants are encrypted.

To resolve above two issues, a new offload DEV_RX_OFFLOAD_REASSEMBLY is introduced in ethdev for devices which can attempt reassembly of packets in hardware. rte_eth_dev_info is added with the reassembly capabilities which a device can support.
Now, if IP fragments are encrypted, reassembly can also be attempted while doing inline IPsec processing.
This is controlled by a flag in rte_security_ipsec_sa_options to enable reassembly of encrypted IP fragments in the inline path.

The resulting reassembled packet would be a typical segmented mbuf in case of success.

And if reassembly of fragments is failed or is incomplete (if fragments do not come before the reass_timeout), the mbuf is updated with an ol_flag PKT_RX_REASSEMBLY_INCOMPLETE and mbuf is returned as is. Now application may decide the fate of the packet to wait more for fragments to come or drop.

---
 lib/ethdev/rte_ethdev.c     |  1 +
 lib/ethdev/rte_ethdev.h     | 18 +++++++++++++++++-
 lib/mbuf/rte_mbuf_core.h    |  3 ++-
 lib/security/rte_security.h | 10 ++++++++++
 4 files changed, 30 insertions(+), 2 deletions(-)
lib/ethdev/rte_ethdev.c +1 -0
index 9d95cd11e1..1ab3a093cf 100644
@@ -119,6 +119,7 @@ static const struct {
 	RTE_RX_OFFLOAD_BIT2STR(VLAN_FILTER),
 	RTE_RX_OFFLOAD_BIT2STR(VLAN_EXTEND),
 	RTE_RX_OFFLOAD_BIT2STR(JUMBO_FRAME),
+	RTE_RX_OFFLOAD_BIT2STR(REASSEMBLY),
 	RTE_RX_OFFLOAD_BIT2STR(SCATTER),
 	RTE_RX_OFFLOAD_BIT2STR(TIMESTAMP),
 	RTE_RX_OFFLOAD_BIT2STR(SECURITY),
lib/ethdev/rte_ethdev.h +17 -1
index d2b27c351f..e89a4dc1eb 100644
@@ -1360,6 +1360,7 @@ struct rte_eth_conf {
 #define DEV_RX_OFFLOAD_VLAN_FILTER	0x00000200
 #define DEV_RX_OFFLOAD_VLAN_EXTEND	0x00000400
 #define DEV_RX_OFFLOAD_JUMBO_FRAME	0x00000800
+#define DEV_RX_OFFLOAD_REASSEMBLY	0x00001000
 #define DEV_RX_OFFLOAD_SCATTER		0x00002000
 /**
  * Timestamp is set by the driver in RTE_MBUF_DYNFIELD_TIMESTAMP_NAME
@@ -1477,6 +1478,20 @@ struct rte_eth_dev_portconf {
  */
 #define RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID	(UINT16_MAX)
 
+/**
+ * Reassembly capabilities that a device can support.
+ * The device which can support reassembly offload should set
+ * DEV_RX_OFFLOAD_REASSEMBLY
+ */
+struct rte_eth_reass_capa {
+	/** Maximum time in ns that a fragment can wait for further fragments */
+	uint64_t reass_timeout;
+	/** Maximum number of fragments that device can reassemble */
+	uint16_t max_frags;
+	/** Reserved for future capabilities */
+	uint16_t reserved[3];
+};
+
 /**
  * Ethernet device associated switch information
  */
@@ -1582,8 +1597,9 @@ struct rte_eth_dev_info {
 	 * embedded managed interconnect/switch.
 	 */
 	struct rte_eth_switch_info switch_info;
+	/* Reassembly capabilities of a device for reassembly offload */
+	struct rte_eth_reass_capa reass_capa;
 
-	uint64_t reserved_64s[2]; /**< Reserved for future fields */
 	void *reserved_ptrs[2];   /**< Reserved for future fields */
 };
 
lib/mbuf/rte_mbuf_core.h +2 -1
index bb38d7f581..cea25c87f7 100644
@@ -200,10 +200,11 @@ extern "C" {
 #define PKT_RX_OUTER_L4_CKSUM_BAD	(1ULL << 21)
 #define PKT_RX_OUTER_L4_CKSUM_GOOD	(1ULL << 22)
 #define PKT_RX_OUTER_L4_CKSUM_INVALID	((1ULL << 21) | (1ULL << 22))
+#define PKT_RX_REASSEMBLY_INCOMPLETE	(1ULL << 23)
 
 /* add new RX flags here, don't forget to update PKT_FIRST_FREE */
 
-#define PKT_FIRST_FREE (1ULL << 23)
+#define PKT_FIRST_FREE (1ULL << 24)
 #define PKT_LAST_FREE (1ULL << 40)
 
 /* add new TX flags here, don't forget to update PKT_LAST_FREE  */
lib/security/rte_security.h +10 -0
index 88d31de0a6..364eeb5cd4 100644
@@ -181,6 +181,16 @@ struct rte_security_ipsec_sa_options {
 	 * * 0: Disable per session security statistics collection for this SA.
 	 */
 	uint32_t stats : 1;
+
+	/** Enable reassembly on incoming packets.
+	 *
+	 * * 1: Enable driver to try reassembly of encrypted IP packets for
+	 *      this SA, if supported by the driver. This feature will work
+	 *      only if rx_offload DEV_RX_OFFLOAD_REASSEMBLY is set in
+	 *      inline ethernet device.
+	 * * 0: Disable reassembly of packets (default).
+	 */
+	uint32_t reass_en : 1;
 };
 
 /** IPSec security association direction */
Signature · 1 line
2.25.1
#1 lore raw
Quoted 20 lines · Akhil Goyal

Reassembly is a costly operation if it is done in software, however, if it is offloaded to HW, it can considerably save application cycles.
The operation becomes even more costlier if IP fragmants are encrypted.

To resolve above two issues, a new offload DEV_RX_OFFLOAD_REASSEMBLY is introduced in ethdev for devices which can attempt reassembly of packets in hardware. rte_eth_dev_info is added with the reassembly capabilities which a device can support.
Now, if IP fragments are encrypted, reassembly can also be attempted while doing inline IPsec processing.
This is controlled by a flag in rte_security_ipsec_sa_options to enable reassembly of encrypted IP fragments in the inline path.

The resulting reassembled packet would be a typical segmented mbuf in case of success.

Quoted 7 lines

And if reassembly of fragments is failed or is incomplete (if fragments do not come before the reass_timeout), the mbuf is updated with an ol_flag PKT_RX_REASSEMBLY_INCOMPLETE and mbuf is returned as is. Now application may decide the fate of the packet to wait more for fragments to come or drop.

Is it IPv4 only or IPv6 as well? I guess IPv4 only to start with. If so, I think offload name should say so. See below.

I'd say that the feature should be added to
doc/guides/nics/features.rst

Do we really need RX_REASSEMBLY_INCOMPLETE if we provide buffered packets for incomplete reassembly anyway? I guess it is sufficient to cover simply reassembly case only in HW when there is no overlapping fragments etc. Everything else should be handled in SW anyway as without the offload support at all.

Quoted 24 lines
---
 lib/ethdev/rte_ethdev.c     |  1 +
 lib/ethdev/rte_ethdev.h     | 18 +++++++++++++++++-
 lib/mbuf/rte_mbuf_core.h    |  3 ++-
 lib/security/rte_security.h | 10 ++++++++++
 4 files changed, 30 insertions(+), 2 deletions(-)
lib/ethdev/rte_ethdev.c +1 -0
index 9d95cd11e1..1ab3a093cf 100644
@@ -119,6 +119,7 @@ static const struct {
 	RTE_RX_OFFLOAD_BIT2STR(VLAN_FILTER),
 	RTE_RX_OFFLOAD_BIT2STR(VLAN_EXTEND),
 	RTE_RX_OFFLOAD_BIT2STR(JUMBO_FRAME),
+	RTE_RX_OFFLOAD_BIT2STR(REASSEMBLY),
 	RTE_RX_OFFLOAD_BIT2STR(SCATTER),
 	RTE_RX_OFFLOAD_BIT2STR(TIMESTAMP),
 	RTE_RX_OFFLOAD_BIT2STR(SECURITY),
lib/ethdev/rte_ethdev.h +0 -0
index d2b27c351f..e89a4dc1eb 100644

lib/ethdev/rte_ethdev.h struct rte_eth_conf { · line 1363

Quoted 4 lines
lib/ethdev/rte_ethdev.h +1 -0
@@ -1360,6 +1360,7 @@ struct rte_eth_conf {
 #define DEV_RX_OFFLOAD_VLAN_FILTER	0x00000200
 #define DEV_RX_OFFLOAD_VLAN_EXTEND	0x00000400
 #define DEV_RX_OFFLOAD_JUMBO_FRAME	0x00000800
+#define DEV_RX_OFFLOAD_REASSEMBLY	0x00001000

I think it should be:
RTE_ETH_RX_OFFLOAD_IPV4_REASSEMBLY

i.e. have correct prefix similar to RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT and mention IPv4.

If we'd like to cover IPv6 as well, it could be RTE_ETH_RX_OFFLOAD_IP_REASSEMBLY and have IPv4/6 support bits in the offload capabilities below.

Quoted 40 lines
lib/ethdev/rte_ethdev.h +16 -1
 #define DEV_RX_OFFLOAD_SCATTER		0x00002000
 /**
  * Timestamp is set by the driver in RTE_MBUF_DYNFIELD_TIMESTAMP_NAME
@@ -1477,6 +1478,20 @@ struct rte_eth_dev_portconf {
  */
 #define RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID	(UINT16_MAX)
 
+/**
+ * Reassembly capabilities that a device can support.
+ * The device which can support reassembly offload should set
+ * DEV_RX_OFFLOAD_REASSEMBLY
+ */
+struct rte_eth_reass_capa {
+	/** Maximum time in ns that a fragment can wait for further fragments */
+	uint64_t reass_timeout;
+	/** Maximum number of fragments that device can reassemble */
+	uint16_t max_frags;
+	/** Reserved for future capabilities */
+	uint16_t reserved[3];
+};
+
 /**
  * Ethernet device associated switch information
  */
@@ -1582,8 +1597,9 @@ struct rte_eth_dev_info {
 	 * embedded managed interconnect/switch.
 	 */
 	struct rte_eth_switch_info switch_info;
+	/* Reassembly capabilities of a device for reassembly offload */
+	struct rte_eth_reass_capa reass_capa;
 
-	uint64_t reserved_64s[2]; /**< Reserved for future fields */
 	void *reserved_ptrs[2];   /**< Reserved for future fields */
 };
 
lib/mbuf/rte_mbuf_core.h +0 -0
index bb38d7f581..cea25c87f7 100644

lib/mbuf/rte_mbuf_core.h extern "C" { · line 203

Quoted 4 lines
lib/mbuf/rte_mbuf_core.h +1 -0
@@ -200,10 +200,11 @@ extern "C" {
 #define PKT_RX_OUTER_L4_CKSUM_BAD	(1ULL << 21)
 #define PKT_RX_OUTER_L4_CKSUM_GOOD	(1ULL << 22)
 #define PKT_RX_OUTER_L4_CKSUM_INVALID	((1ULL << 21) | (1ULL << 22))
+#define PKT_RX_REASSEMBLY_INCOMPLETE	(1ULL << 23)

In accordance with deprecation notice it should be RTE_MBUF_F_RX_REASSEMBLY_INCOMPLETE

Quoted 13 lines
lib/mbuf/rte_mbuf_core.h +1 -1
 /* add new RX flags here, don't forget to update PKT_FIRST_FREE */
 
-#define PKT_FIRST_FREE (1ULL << 23)
+#define PKT_FIRST_FREE (1ULL << 24)
 #define PKT_LAST_FREE (1ULL << 40)
 
 /* add new TX flags here, don't forget to update PKT_LAST_FREE  */
lib/security/rte_security.h +0 -0
index 88d31de0a6..364eeb5cd4 100644

lib/security/rte_security.h struct rte_security_ipsec_sa_options { · line 190

Quoted 10 lines
lib/security/rte_security.h +7 -0
@@ -181,6 +181,16 @@ struct rte_security_ipsec_sa_options {
 	 * * 0: Disable per session security statistics collection for this SA.
 	 */
 	uint32_t stats : 1;
+
+	/** Enable reassembly on incoming packets.
+	 *
+	 * * 1: Enable driver to try reassembly of encrypted IP packets for
+	 *      this SA, if supported by the driver. This feature will work
+	 *      only if rx_offload DEV_RX_OFFLOAD_REASSEMBLY is set in
+	 *      inline ethernet device.

ethernet -> Ethernet

Quoted 7 lines
lib/security/rte_security.h +3 -0
+	 * * 0: Disable reassembly of packets (default).
+	 */
+	uint32_t reass_en : 1;
 };
 
 /** IPSec security association direction */
#2 lore raw
Quoted 27 lines · Akhil Goyal
Quoted 26 lines

Reassembly is a costly operation if it is done in software, however, if it is offloaded to HW, it can considerably save application cycles.
The operation becomes even more costlier if IP fragmants are encrypted.

To resolve above two issues, a new offload DEV_RX_OFFLOAD_REASSEMBLY is introduced in ethdev for devices which can attempt reassembly of packets in hardware. rte_eth_dev_info is added with the reassembly capabilities which a device can support.
Now, if IP fragments are encrypted, reassembly can also be attempted while doing inline IPsec processing.
This is controlled by a flag in rte_security_ipsec_sa_options to enable reassembly of encrypted IP fragments in the inline path.

The resulting reassembled packet would be a typical segmented mbuf in case of success.

And if reassembly of fragments is failed or is incomplete (if fragments do not come before the reass_timeout), the mbuf is updated with an ol_flag PKT_RX_REASSEMBLY_INCOMPLETE and mbuf is returned as is. Now application may decide the fate of the packet to wait more for fragments to come or drop.

Quoted 5 lines
Quoted 1 line

Is it IPv4 only or IPv6 as well? I guess IPv4 only to start with. If so, I think offload name should say so. See below.

We can update spec for both and update capabilities for both. See below.

Quoted 2 lines

I'd say that the feature should be added to
doc/guides/nics/features.rst

OK will update in next version

Quoted 8 lines

Do we really need RX_REASSEMBLY_INCOMPLETE if we provide buffered packets for incomplete reassembly anyway? I guess it is sufficient to cover simply reassembly case only in HW when there is no overlapping fragments etc. Everything else should be handled in SW anyway as without the offload support at all.

In that case, application would need to again parse the packet to check whether it is a fragment or not even when the reassembly is not required. However, we would consider your suggestion in implementation.

Quoted 32 lines
Quoted 24 lines
---
 lib/ethdev/rte_ethdev.c     |  1 +
 lib/ethdev/rte_ethdev.h     | 18 +++++++++++++++++-
 lib/mbuf/rte_mbuf_core.h    |  3 ++-
 lib/security/rte_security.h | 10 ++++++++++
 4 files changed, 30 insertions(+), 2 deletions(-)
lib/ethdev/rte_ethdev.c +1 -0
index 9d95cd11e1..1ab3a093cf 100644
@@ -119,6 +119,7 @@ static const struct {
 	RTE_RX_OFFLOAD_BIT2STR(VLAN_FILTER),
 	RTE_RX_OFFLOAD_BIT2STR(VLAN_EXTEND),
 	RTE_RX_OFFLOAD_BIT2STR(JUMBO_FRAME),
+	RTE_RX_OFFLOAD_BIT2STR(REASSEMBLY),
 	RTE_RX_OFFLOAD_BIT2STR(SCATTER),
 	RTE_RX_OFFLOAD_BIT2STR(TIMESTAMP),
 	RTE_RX_OFFLOAD_BIT2STR(SECURITY),
lib/ethdev/rte_ethdev.h +0 -0
index d2b27c351f..e89a4dc1eb 100644

lib/ethdev/rte_ethdev.h struct rte_eth_conf { · line 1363

Quoted 4 lines
lib/ethdev/rte_ethdev.h +1 -0
@@ -1360,6 +1360,7 @@ struct rte_eth_conf {
 #define DEV_RX_OFFLOAD_VLAN_FILTER	0x00000200
 #define DEV_RX_OFFLOAD_VLAN_EXTEND	0x00000400
 #define DEV_RX_OFFLOAD_JUMBO_FRAME	0x00000800
+#define DEV_RX_OFFLOAD_REASSEMBLY	0x00001000

I think it should be:
RTE_ETH_RX_OFFLOAD_IPV4_REASSEMBLY

Quoted 6 lines

i.e. have correct prefix similar to RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT and mention IPv4.

If we'd like to cover IPv6 as well, it could be RTE_ETH_RX_OFFLOAD_IP_REASSEMBLY and have IPv4/6 support bits in the offload capabilities below.

Intention is to update spec for both.
Will update the capabilities accordingly to have both IPv4 and IPv6.

Quoted 39 lines

lib/ethdev/rte_ethdev.h struct rte_eth_conf {

Quoted 4 lines
lib/ethdev/rte_ethdev.h +0 -0
 #define DEV_RX_OFFLOAD_SCATTER		0x00002000
 /**
  * Timestamp is set by the driver in

RTE_MBUF_DYNFIELD_TIMESTAMP_NAME

lib/ethdev/rte_ethdev.h struct rte_eth_dev_portconf { · line 1479

Quoted 3 lines
lib/ethdev/rte_ethdev.h +0 -0
@@ -1477,6 +1478,20 @@ struct rte_eth_dev_portconf {
  */
 #define RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID
	(UINT16_MAX)

lib/ethdev/rte_ethdev.h struct rte_eth_dev_portconf {

Quoted 8 lines
lib/ethdev/rte_ethdev.h +7 -0
+/**
+ * Reassembly capabilities that a device can support.
+ * The device which can support reassembly offload should set
+ * DEV_RX_OFFLOAD_REASSEMBLY
+ */
+struct rte_eth_reass_capa {
+	/** Maximum time in ns that a fragment can wait for further

fragments */

Quoted 21 lines
lib/ethdev/rte_ethdev.h +9 -1
+	uint64_t reass_timeout;
+	/** Maximum number of fragments that device can reassemble */
+	uint16_t max_frags;
+	/** Reserved for future capabilities */
+	uint16_t reserved[3];
+};
+
 /**
  * Ethernet device associated switch information
  */
@@ -1582,8 +1597,9 @@ struct rte_eth_dev_info {
 	 * embedded managed interconnect/switch.
 	 */
 	struct rte_eth_switch_info switch_info;
+	/* Reassembly capabilities of a device for reassembly offload */
+	struct rte_eth_reass_capa reass_capa;
 
-	uint64_t reserved_64s[2]; /**< Reserved for future fields */
 	void *reserved_ptrs[2];   /**< Reserved for future fields */
 };
 
Quoted 13 lines

lib/mbuf/rte_mbuf_core.h extern "C" { · line 203

Quoted 9 lines
lib/mbuf/rte_mbuf_core.h +1 -0
index bb38d7f581..cea25c87f7 100644
@@ -200,10 +200,11 @@ extern "C" {
 #define PKT_RX_OUTER_L4_CKSUM_BAD	(1ULL << 21)
 #define PKT_RX_OUTER_L4_CKSUM_GOOD	(1ULL << 22)
 #define PKT_RX_OUTER_L4_CKSUM_INVALID	((1ULL << 21) | (1ULL << 22))
+#define PKT_RX_REASSEMBLY_INCOMPLETE	(1ULL << 23)

In accordance with deprecation notice it should be RTE_MBUF_F_RX_REASSEMBLY_INCOMPLETE

Ok will correct in next version.

Quoted 33 lines
Quoted 13 lines
lib/mbuf/rte_mbuf_core.h +1 -1
 /* add new RX flags here, don't forget to update PKT_FIRST_FREE */
 
-#define PKT_FIRST_FREE (1ULL << 23)
+#define PKT_FIRST_FREE (1ULL << 24)
 #define PKT_LAST_FREE (1ULL << 40)
 
 /* add new TX flags here, don't forget to update PKT_LAST_FREE  */
lib/security/rte_security.h +0 -0
index 88d31de0a6..364eeb5cd4 100644

lib/security/rte_security.h struct rte_security_ipsec_sa_options { · line 190

Quoted 10 lines
lib/security/rte_security.h +7 -0
@@ -181,6 +181,16 @@ struct rte_security_ipsec_sa_options {
 	 * * 0: Disable per session security statistics collection for this SA.
 	 */
 	uint32_t stats : 1;
+
+	/** Enable reassembly on incoming packets.
+	 *
+	 * * 1: Enable driver to try reassembly of encrypted IP packets for
+	 *      this SA, if supported by the driver. This feature will work
+	 *      only if rx_offload DEV_RX_OFFLOAD_REASSEMBLY is set in
+	 *      inline ethernet device.

ethernet -> Ethernet

Quoted 7 lines
lib/security/rte_security.h +3 -0
+	 * * 0: Disable reassembly of packets (default).
+	 */
+	uint32_t reass_en : 1;
 };
 
 /** IPSec security association direction */
#3 lore raw

29/08/2021 15:14, Akhil Goyal:

Quoted 26 lines
Quoted 6 lines · Akhil Goyal
Quoted 1 line

+#define DEV_RX_OFFLOAD_REASSEMBLY 0x00001000

I think it should be:
RTE_ETH_RX_OFFLOAD_IPV4_REASSEMBLY

Quoted 6 lines

i.e. have correct prefix similar to RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT and mention IPv4.

If we'd like to cover IPv6 as well, it could be RTE_ETH_RX_OFFLOAD_IP_REASSEMBLY and have IPv4/6 support bits in the offload capabilities below.

Intention is to update spec for both.
Will update the capabilities accordingly to have both IPv4 and IPv6.

Quoted 10 lines
Quoted 4 lines

#define DEV_RX_OFFLOAD_SCATTER 0x00002000
/**
* Timestamp is set by the driver in

RTE_MBUF_DYNFIELD_TIMESTAMP_NAME

Review struct rte_eth_dev_portconf { · line 1479

Quoted 3 lines
(quoted diff) +0 -0
@@ -1477,6 +1478,20 @@ struct rte_eth_dev_portconf {
  */
 #define RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID
	(UINT16_MAX)
Quoted 1 line
Quoted 6 lines
Quoted 6 lines

lib/ethdev/rte_ethdev.h struct rte_eth_dev_portconf { · line 1486

Quoted 6 lines
lib/ethdev/rte_ethdev.h +6 -0
+/**
+ * Reassembly capabilities that a device can support.
+ * The device which can support reassembly offload should set
+ * DEV_RX_OFFLOAD_REASSEMBLY
+ */
+struct rte_eth_reass_capa {

Please add "IP" in flags, struct and comments.

#4 lore raw
In reply to Akhil Goyal
Quoted 51 lines · Akhil Goyal

Reassembly is a costly operation if it is done in software, however, if it is offloaded to HW, it can considerably save application cycles.
The operation becomes even more costlier if IP fragmants are encrypted.

To resolve above two issues, a new offload DEV_RX_OFFLOAD_REASSEMBLY is introduced in ethdev for devices which can attempt reassembly of packets in hardware. rte_eth_dev_info is added with the reassembly capabilities which a device can support.
Now, if IP fragments are encrypted, reassembly can also be attempted while doing inline IPsec processing.
This is controlled by a flag in rte_security_ipsec_sa_options to enable reassembly of encrypted IP fragments in the inline path.

The resulting reassembled packet would be a typical segmented mbuf in case of success.

And if reassembly of fragments is failed or is incomplete (if fragments do not come before the reass_timeout), the mbuf is updated with an ol_flag PKT_RX_REASSEMBLY_INCOMPLETE and mbuf is returned as is. Now application may decide the fate of the packet to wait more for fragments to come or drop.

---
 lib/ethdev/rte_ethdev.c     |  1 +
 lib/ethdev/rte_ethdev.h     | 18 +++++++++++++++++-
 lib/mbuf/rte_mbuf_core.h    |  3 ++-
 lib/security/rte_security.h | 10 ++++++++++
 4 files changed, 30 insertions(+), 2 deletions(-)
lib/ethdev/rte_ethdev.c +1 -0
index 9d95cd11e1..1ab3a093cf 100644
@@ -119,6 +119,7 @@ static const struct {
 	RTE_RX_OFFLOAD_BIT2STR(VLAN_FILTER),
 	RTE_RX_OFFLOAD_BIT2STR(VLAN_EXTEND),
 	RTE_RX_OFFLOAD_BIT2STR(JUMBO_FRAME),
+	RTE_RX_OFFLOAD_BIT2STR(REASSEMBLY),
 	RTE_RX_OFFLOAD_BIT2STR(SCATTER),
 	RTE_RX_OFFLOAD_BIT2STR(TIMESTAMP),
 	RTE_RX_OFFLOAD_BIT2STR(SECURITY),
lib/ethdev/rte_ethdev.h +0 -0
index d2b27c351f..e89a4dc1eb 100644

lib/ethdev/rte_ethdev.h struct rte_eth_conf { · line 1363

Quoted 4 lines
lib/ethdev/rte_ethdev.h +1 -0
@@ -1360,6 +1360,7 @@ struct rte_eth_conf {
 #define DEV_RX_OFFLOAD_VLAN_FILTER	0x00000200
 #define DEV_RX_OFFLOAD_VLAN_EXTEND	0x00000400
 #define DEV_RX_OFFLOAD_JUMBO_FRAME	0x00000800
+#define DEV_RX_OFFLOAD_REASSEMBLY	0x00001000

previous '0x00001000' was 'DEV_RX_OFFLOAD_CRC_STRIP', it has been long that offload has been removed, but not sure if it cause any problem to re-use it.

Quoted 11 lines
lib/ethdev/rte_ethdev.h +4 -0
 #define DEV_RX_OFFLOAD_SCATTER		0x00002000
 /**
  * Timestamp is set by the driver in RTE_MBUF_DYNFIELD_TIMESTAMP_NAME
@@ -1477,6 +1478,20 @@ struct rte_eth_dev_portconf {
  */
 #define RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID	(UINT16_MAX)
 
+/**
+ * Reassembly capabilities that a device can support.
+ * The device which can support reassembly offload should set
+ * DEV_RX_OFFLOAD_REASSEMBLY

lib/ethdev/rte_ethdev.h struct rte_eth_dev_portconf { · line 1494

Quoted 10 lines
lib/ethdev/rte_ethdev.h +10 -0
+ */
+struct rte_eth_reass_capa {
+	/** Maximum time in ns that a fragment can wait for further fragments */
+	uint64_t reass_timeout;
+	/** Maximum number of fragments that device can reassemble */
+	uint16_t max_frags;
+	/** Reserved for future capabilities */
+	uint16_t reserved[3];
+};
+

I wonder if there is any other hardware around supports reassembly offload, it would be good to get more feedback on the capabilities list.

lib/ethdev/rte_ethdev.h struct rte_eth_dev_info { · line 1586

Quoted 11 lines
lib/ethdev/rte_ethdev.h +2 -1
 /**
  * Ethernet device associated switch information
  */
@@ -1582,8 +1597,9 @@ struct rte_eth_dev_info {
 	 * embedded managed interconnect/switch.
 	 */
 	struct rte_eth_switch_info switch_info;
+	/* Reassembly capabilities of a device for reassembly offload */
+	struct rte_eth_reass_capa reass_capa;
 
-	uint64_t reserved_64s[2]; /**< Reserved for future fields */

Reserved fields were added to be able to update the struct without breaking the ABI, so that a critical change doesn't have to wait until next ABI break release. Since this is ABI break release, we can keep the reserved field and add the new struct. Or this can be an opportunity to get rid of the reserved field.

Personally I have no objection to get rid of the reserved field, but better to agree on this explicitly.

lib/mbuf/rte_mbuf_core.h extern "C" { · line 204

Quoted 13 lines
lib/ethdev/rte_ethdev.h +0 -0
 	void *reserved_ptrs[2];   /**< Reserved for future fields */
 };
 
lib/mbuf/rte_mbuf_core.h +1 -0
index bb38d7f581..cea25c87f7 100644
@@ -200,10 +200,11 @@ extern "C" {
 #define PKT_RX_OUTER_L4_CKSUM_BAD	(1ULL << 21)
 #define PKT_RX_OUTER_L4_CKSUM_GOOD	(1ULL << 22)
 #define PKT_RX_OUTER_L4_CKSUM_INVALID	((1ULL << 21) | (1ULL << 22))
+#define PKT_RX_REASSEMBLY_INCOMPLETE	(1ULL << 23)
 

Similar comment with Andrew's, what is the expectation from application if this flag exists? Can we drop it to simplify the logic in the application?

Quoted 29 lines
lib/mbuf/rte_mbuf_core.h +1 -1
 /* add new RX flags here, don't forget to update PKT_FIRST_FREE */
 
-#define PKT_FIRST_FREE (1ULL << 23)
+#define PKT_FIRST_FREE (1ULL << 24)
 #define PKT_LAST_FREE (1ULL << 40)
 
 /* add new TX flags here, don't forget to update PKT_LAST_FREE  */
lib/security/rte_security.h +10 -0
index 88d31de0a6..364eeb5cd4 100644
@@ -181,6 +181,16 @@ struct rte_security_ipsec_sa_options {
 	 * * 0: Disable per session security statistics collection for this SA.
 	 */
 	uint32_t stats : 1;
+
+	/** Enable reassembly on incoming packets.
+	 *
+	 * * 1: Enable driver to try reassembly of encrypted IP packets for
+	 *      this SA, if supported by the driver. This feature will work
+	 *      only if rx_offload DEV_RX_OFFLOAD_REASSEMBLY is set in
+	 *      inline ethernet device.
+	 * * 0: Disable reassembly of packets (default).
+	 */
+	uint32_t reass_en : 1;
 };
 
 /** IPSec security association direction */
#5 lore raw

Hi Ferruh, Rosen, Andrew,

Please see inline.

Thanks,
Anoob

Quoted 127 lines

Subject: [EXT] Re: [PATCH] RFC: ethdev: add reassembly offload

External Email

----------------------------------------------------------------------

Quoted 6 lines · Akhil Goyal

Reassembly is a costly operation if it is done in software, however, if it is offloaded to HW, it can considerably save application cycles. The operation becomes even more costlier if IP fragmants are encrypted.

To resolve above two issues, a new offload

DEV_RX_OFFLOAD_REASSEMBLY

Quoted 9 lines

is introduced in ethdev for devices which can attempt reassembly of packets in hardware.
rte_eth_dev_info is added with the reassembly capabilities which a device can support.
Now, if IP fragments are encrypted, reassembly can also be attempted while doing inline IPsec processing.
This is controlled by a flag in rte_security_ipsec_sa_options to enable reassembly of encrypted IP fragments in the inline path.

Quoted 6 lines

The resulting reassembled packet would be a typical segmented mbuf in case of success.

And if reassembly of fragments is failed or is incomplete (if fragments do not come before the reass_timeout), the mbuf is updated with an ol_flag PKT_RX_REASSEMBLY_INCOMPLETE and mbuf is returned

as

Quoted 28 lines

is. Now application may decide the fate of the packet to wait more for fragments to come or drop.

---
 lib/ethdev/rte_ethdev.c     |  1 +
 lib/ethdev/rte_ethdev.h     | 18 +++++++++++++++++-
 lib/mbuf/rte_mbuf_core.h    |  3 ++-
 lib/security/rte_security.h | 10 ++++++++++
 4 files changed, 30 insertions(+), 2 deletions(-)
lib/ethdev/rte_ethdev.c index renamed from lib/ethdev/rte_ethdev.c +0 -0

9d95cd11e1..1ab3a093cf 100644

lib/ethdev/rte_ethdev.c +1 -0
@@ -119,6 +119,7 @@ static const struct {
 	RTE_RX_OFFLOAD_BIT2STR(VLAN_FILTER),
 	RTE_RX_OFFLOAD_BIT2STR(VLAN_EXTEND),
 	RTE_RX_OFFLOAD_BIT2STR(JUMBO_FRAME),
+	RTE_RX_OFFLOAD_BIT2STR(REASSEMBLY),
 	RTE_RX_OFFLOAD_BIT2STR(SCATTER),
 	RTE_RX_OFFLOAD_BIT2STR(TIMESTAMP),
 	RTE_RX_OFFLOAD_BIT2STR(SECURITY),
lib/ethdev/rte_ethdev.h index renamed from lib/ethdev/rte_ethdev.h +0 -0

d2b27c351f..e89a4dc1eb 100644

lib/ethdev/rte_ethdev.h struct rte_eth_conf { · line 1363

Quoted 4 lines
lib/ethdev/rte_ethdev.h +1 -0
@@ -1360,6 +1360,7 @@ struct rte_eth_conf {
 #define DEV_RX_OFFLOAD_VLAN_FILTER	0x00000200
 #define DEV_RX_OFFLOAD_VLAN_EXTEND	0x00000400
 #define DEV_RX_OFFLOAD_JUMBO_FRAME	0x00000800
+#define DEV_RX_OFFLOAD_REASSEMBLY	0x00001000

previous '0x00001000' was 'DEV_RX_OFFLOAD_CRC_STRIP', it has been long that offload has been removed, but not sure if it cause any problem to re- use it.

lib/ethdev/rte_ethdev.h struct rte_eth_conf {

Quoted 3 lines
lib/ethdev/rte_ethdev.h +0 -0
 #define DEV_RX_OFFLOAD_SCATTER		0x00002000
 /**
  * Timestamp is set by the driver in

RTE_MBUF_DYNFIELD_TIMESTAMP_NAME

lib/ethdev/rte_ethdev.h struct rte_eth_dev_portconf { · line 1479

Quoted 3 lines
lib/ethdev/rte_ethdev.h +0 -0
@@ -1477,6 +1478,20 @@ struct rte_eth_dev_portconf {
  */
 #define RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID
	(UINT16_MAX)

lib/ethdev/rte_ethdev.h struct rte_eth_dev_portconf {

Quoted 8 lines
lib/ethdev/rte_ethdev.h +7 -0
+/**
+ * Reassembly capabilities that a device can support.
+ * The device which can support reassembly offload should set
+ * DEV_RX_OFFLOAD_REASSEMBLY
+ */
+struct rte_eth_reass_capa {
+	/** Maximum time in ns that a fragment can wait for further

fragments */

lib/ethdev/rte_ethdev.h struct rte_eth_dev_portconf { · line 1494

Quoted 7 lines
lib/ethdev/rte_ethdev.h +7 -0
+	uint64_t reass_timeout;
+	/** Maximum number of fragments that device can reassemble */
+	uint16_t max_frags;
+	/** Reserved for future capabilities */
+	uint16_t reserved[3];
+};
+

I wonder if there is any other hardware around supports reassembly offload, it would be good to get more feedback on the capabilities list.

lib/ethdev/rte_ethdev.h struct rte_eth_dev_info { · line 1586

Quoted 11 lines
lib/ethdev/rte_ethdev.h +2 -1
 /**
  * Ethernet device associated switch information
  */
@@ -1582,8 +1597,9 @@ struct rte_eth_dev_info {
 	 * embedded managed interconnect/switch.
 	 */
 	struct rte_eth_switch_info switch_info;
+	/* Reassembly capabilities of a device for reassembly offload */
+	struct rte_eth_reass_capa reass_capa;
 
-	uint64_t reserved_64s[2]; /**< Reserved for future fields */

Reserved fields were added to be able to update the struct without breaking the ABI, so that a critical change doesn't have to wait until next ABI break release.
Since this is ABI break release, we can keep the reserved field and add the new struct. Or this can be an opportunity to get rid of the reserved field.

Personally I have no objection to get rid of the reserved field, but better to agree on this explicitly.

lib/mbuf/rte_mbuf_core.h extern "C" { · line 202

Quoted 11 lines
lib/ethdev/rte_ethdev.h +0 -0
 	void *reserved_ptrs[2];   /**< Reserved for future fields */
 };
 
lib/mbuf/rte_mbuf_core.h index renamed from lib/mbuf/rte_mbuf_core.h +0 -0

bb38d7f581..cea25c87f7 100644

lib/mbuf/rte_mbuf_core.h +0 -0
@@ -200,10 +200,11 @@ extern "C" {
 #define PKT_RX_OUTER_L4_CKSUM_BAD	(1ULL << 21)
 #define PKT_RX_OUTER_L4_CKSUM_GOOD	(1ULL << 22)
 #define PKT_RX_OUTER_L4_CKSUM_INVALID	((1ULL << 21) | (1ULL

<< 22))

Quoted 5 lines

lib/mbuf/rte_mbuf_core.h extern "C" { · line 204

Quoted 2 lines
lib/mbuf/rte_mbuf_core.h +1 -0
+#define PKT_RX_REASSEMBLY_INCOMPLETE	(1ULL << 23)
 

Similar comment with Andrew's, what is the expectation from application if this flag exists? Can we drop it to simplify the logic in the application?

[Anoob] There can be few cases where hardware/NIC attempts inline reassembly but it fails to complete it

1. Number of fragments is larger than what is supported by the hardware
2. Hardware reassembly resources are exhausted (due to limited reassembly contexts etc)
3. Reassembly errors such as overlapping fragments
4. Wait time exhausted (or reassembly timeout)

In such cases, application would be required to retrieve the original fragments so that it can attempt reassembly in software. The incomplete flag is useful for 2 purposes basically,
1. Application would need to retrieve the time the fragment has already spend in hardware reassembly so that software reassembly attempt can compensate for it. Otherwise, reassembly timeout across hardware + software will not be accurate
2. Retrieve original fragments. With this proposal, an incomplete reassembly would result in a chained mbuf but the segments need not be consecutive. To explain bit more,

Suppose we have a packet that is fragmented into 3 fragments, and fragment 3 & fragment 1 arrives in that order. Fragment 2 didn't arrive and hardware ultimately pushes it. In that case, application would be receiving a chained/segmented mbuf with fragment 1 & fragment 3 chained.

Now, this chained mbuf can't be treated like a regular chained mbuf. Each fragment would have its IP hdr and there are fragments missing in between. The only thing application is expected to do is, retrieve fragments, push it to s/w reassembly.

Quoted 30 lines
Quoted 30 lines
lib/mbuf/rte_mbuf_core.h +1 -1
 /* add new RX flags here, don't forget to update PKT_FIRST_FREE */
 
-#define PKT_FIRST_FREE (1ULL << 23)
+#define PKT_FIRST_FREE (1ULL << 24)
 #define PKT_LAST_FREE (1ULL << 40)
 
 /* add new TX flags here, don't forget to update PKT_LAST_FREE  */
lib/security/rte_security.h +10 -0
index 88d31de0a6..364eeb5cd4 100644
@@ -181,6 +181,16 @@ struct rte_security_ipsec_sa_options {
 	 * * 0: Disable per session security statistics collection for this SA.
 	 */
 	uint32_t stats : 1;
+
+	/** Enable reassembly on incoming packets.
+	 *
+	 * * 1: Enable driver to try reassembly of encrypted IP packets for
+	 *      this SA, if supported by the driver. This feature will work
+	 *      only if rx_offload DEV_RX_OFFLOAD_REASSEMBLY is set in
+	 *      inline ethernet device.
+	 * * 0: Disable reassembly of packets (default).
+	 */
+	uint32_t reass_en : 1;
 };
 
 /** IPSec security association direction */
#6 lore raw

Hi,

Quoted 179 lines

-----Original Message-----
From: Anoob Joseph <[email protected]>
Sent: Wednesday, September 08, 2021 18:30
To: Yigit, Ferruh <[email protected]>; Xu, Rosen <[email protected]>; Andrew Rybchenko <[email protected]>
Cc: Nicolau, Radu <[email protected]>; Doherty, Declan <[email protected]>; [email protected]; [email protected]; Ananyev, Konstantin <[email protected]>; [email protected]; Ankur Dwivedi <[email protected]>; [email protected]; Akhil Goyal <[email protected]>; [email protected]
Subject: RE: [EXT] Re: [PATCH] RFC: ethdev: add reassembly offload

Hi Ferruh, Rosen, Andrew,

Please see inline.

Thanks,
Anoob

Quoted 55 lines

Subject: [EXT] Re: [PATCH] RFC: ethdev: add reassembly offload

External Email

----------------------------------------------------------------------

Quoted 6 lines · Akhil Goyal

Reassembly is a costly operation if it is done in software, however, if it is offloaded to HW, it can considerably save application cycles. The operation becomes even more costlier if IP fragmants are encrypted.

To resolve above two issues, a new offload

DEV_RX_OFFLOAD_REASSEMBLY

Quoted 9 lines

is introduced in ethdev for devices which can attempt reassembly of packets in hardware.
rte_eth_dev_info is added with the reassembly capabilities which a device can support.
Now, if IP fragments are encrypted, reassembly can also be attempted while doing inline IPsec processing.
This is controlled by a flag in rte_security_ipsec_sa_options to enable reassembly of encrypted IP fragments in the inline path.

Quoted 6 lines

The resulting reassembled packet would be a typical segmented mbuf in case of success.

And if reassembly of fragments is failed or is incomplete (if fragments do not come before the reass_timeout), the mbuf is updated with an ol_flag PKT_RX_REASSEMBLY_INCOMPLETE and mbuf is returned

as

Quoted 26 lines

is. Now application may decide the fate of the packet to wait more for fragments to come or drop.

---
 lib/ethdev/rte_ethdev.c     |  1 +
 lib/ethdev/rte_ethdev.h     | 18 +++++++++++++++++-
 lib/mbuf/rte_mbuf_core.h    |  3 ++-
 lib/security/rte_security.h | 10 ++++++++++
 4 files changed, 30 insertions(+), 2 deletions(-)
lib/ethdev/rte_ethdev.c index renamed from lib/ethdev/rte_ethdev.c +0 -0

9d95cd11e1..1ab3a093cf 100644

lib/ethdev/rte_ethdev.c +1 -0
@@ -119,6 +119,7 @@ static const struct {
 	RTE_RX_OFFLOAD_BIT2STR(VLAN_FILTER),
 	RTE_RX_OFFLOAD_BIT2STR(VLAN_EXTEND),
 	RTE_RX_OFFLOAD_BIT2STR(JUMBO_FRAME),
+	RTE_RX_OFFLOAD_BIT2STR(REASSEMBLY),
 	RTE_RX_OFFLOAD_BIT2STR(SCATTER),
 	RTE_RX_OFFLOAD_BIT2STR(TIMESTAMP),
 	RTE_RX_OFFLOAD_BIT2STR(SECURITY),
lib/ethdev/rte_ethdev.h index renamed from lib/ethdev/rte_ethdev.h +0 -0

d2b27c351f..e89a4dc1eb 100644
--- a/lib/ethdev/rte_ethdev.h

Quoted 8 lines

lib/ethdev/rte_ethdev.h index struct rte_eth_conf { · line 1363

Quoted 6 lines

+++ b/lib/ethdev/rte_ethdev.h

lib/ethdev/rte_ethdev.h index renamed from lib/ethdev/rte_ethdev.h +1 -0
@@ -1360,6 +1360,7 @@ struct rte_eth_conf {
 #define DEV_RX_OFFLOAD_VLAN_FILTER	0x00000200
 #define DEV_RX_OFFLOAD_VLAN_EXTEND	0x00000400
 #define DEV_RX_OFFLOAD_JUMBO_FRAME	0x00000800
+#define DEV_RX_OFFLOAD_REASSEMBLY	0x00001000

previous '0x00001000' was 'DEV_RX_OFFLOAD_CRC_STRIP', it has been

long

Quoted 41 lines

that offload has been removed, but not sure if it cause any problem to re- use it.

lib/ethdev/rte_ethdev.h index struct rte_eth_conf { · line 1366

Quoted 3 lines
lib/ethdev/rte_ethdev.h index renamed from lib/ethdev/rte_ethdev.h +0 -0
 #define DEV_RX_OFFLOAD_SCATTER		0x00002000
 /**
  * Timestamp is set by the driver in

RTE_MBUF_DYNFIELD_TIMESTAMP_NAME

lib/ethdev/rte_ethdev.h index struct rte_eth_dev_portconf { · line 1479

Quoted 3 lines
lib/ethdev/rte_ethdev.h index renamed from lib/ethdev/rte_ethdev.h +0 -0
@@ -1477,6 +1478,20 @@ struct rte_eth_dev_portconf {
  */
 #define RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID
	(UINT16_MAX)

lib/ethdev/rte_ethdev.h index struct rte_eth_dev_portconf { · line 1486

Quoted 8 lines
lib/ethdev/rte_ethdev.h index renamed from lib/ethdev/rte_ethdev.h +7 -0
+/**
+ * Reassembly capabilities that a device can support.
+ * The device which can support reassembly offload should set
+ * DEV_RX_OFFLOAD_REASSEMBLY
+ */
+struct rte_eth_reass_capa {
+	/** Maximum time in ns that a fragment can wait for further

fragments */

lib/ethdev/rte_ethdev.h index struct rte_eth_dev_portconf { · line 1493

Quoted 7 lines
lib/ethdev/rte_ethdev.h index renamed from lib/ethdev/rte_ethdev.h +7 -0
+	uint64_t reass_timeout;
+	/** Maximum number of fragments that device can reassemble */
+	uint16_t max_frags;
+	/** Reserved for future capabilities */
+	uint16_t reserved[3];
+};
+

I wonder if there is any other hardware around supports reassembly offload, it would be good to get more feedback on the capabilities list.

Quoted 10 lines
lib/ethdev/rte_ethdev.h index renamed from lib/ethdev/rte_ethdev.h +2 -0
 /**
  * Ethernet device associated switch information
  */
@@ -1582,8 +1597,9 @@ struct rte_eth_dev_info {
 	 * embedded managed interconnect/switch.
 	 */
 	struct rte_eth_switch_info switch_info;
+	/* Reassembly capabilities of a device for reassembly offload */
+	struct rte_eth_reass_capa reass_capa;
 
Quoted 7 lines

lib/ethdev/rte_ethdev.h index struct rte_eth_dev_info { · line 1586

Quoted 1 line
lib/ethdev/rte_ethdev.h index renamed from lib/ethdev/rte_ethdev.h +0 -1
-	uint64_t reserved_64s[2]; /**< Reserved for future fields */

Reserved fields were added to be able to update the struct without breaking the ABI, so that a critical change doesn't have to wait until next ABI break release.
Since this is ABI break release, we can keep the reserved field and add the new struct. Or this can be an opportunity to get rid of the reserved

field.

Quoted 17 lines

Personally I have no objection to get rid of the reserved field, but better to agree on this explicitly.

lib/mbuf/rte_mbuf_core.h extern "C" { · line 202

Quoted 12 lines
lib/ethdev/rte_ethdev.h index renamed from lib/ethdev/rte_ethdev.h +0 -0
 	void *reserved_ptrs[2];   /**< Reserved for future fields */
 };
 
lib/mbuf/rte_mbuf_core.h +0 -0

index
bb38d7f581..cea25c87f7 100644

lib/mbuf/rte_mbuf_core.h +0 -0
@@ -200,10 +200,11 @@ extern "C" {
 #define PKT_RX_OUTER_L4_CKSUM_BAD	(1ULL << 21)
 #define PKT_RX_OUTER_L4_CKSUM_GOOD	(1ULL << 22)
 #define PKT_RX_OUTER_L4_CKSUM_INVALID	((1ULL << 21) | (1ULL

<< 22))

Quoted 5 lines

lib/mbuf/rte_mbuf_core.h extern "C" { · line 204

Quoted 2 lines
lib/mbuf/rte_mbuf_core.h +1 -0
+#define PKT_RX_REASSEMBLY_INCOMPLETE	(1ULL << 23)
 

Similar comment with Andrew's, what is the expectation from application if this flag exists? Can we drop it to simplify the logic in the

application?

[Anoob] There can be few cases where hardware/NIC attempts inline reassembly but it fails to complete it

1. Number of fragments is larger than what is supported by the hardware 2. Hardware reassembly resources are exhausted (due to limited reassembly contexts etc) 3. Reassembly errors such as overlapping fragments 4. Wait time exhausted (or reassembly timeout)

In such cases, application would be required to retrieve the original fragments so that it can attempt reassembly in software. The incomplete flag is useful for 2 purposes basically, 1. Application would need to retrieve the time the fragment has already spend in hardware reassembly so that software reassembly attempt can compensate for it. Otherwise, reassembly timeout across hardware + software will not be accurate 2. Retrieve original fragments. With this proposal, an incomplete reassembly would result in a chained mbuf but the segments need not be consecutive. To explain bit more,

Suppose we have a packet that is fragmented into 3 fragments, and fragment 3 & fragment 1 arrives in that order. Fragment 2 didn't arrive and hardware ultimately pushes it. In that case, application would be receiving a chained/segmented mbuf with fragment 1 & fragment 3 chained.

Quoted 4 lines

Now, this chained mbuf can't be treated like a regular chained mbuf. Each fragment would have its IP hdr and there are fragments missing in between. The only thing application is expected to do is, retrieve fragments, push it to s/w reassembly.

What you mentioned is error identification. But actually a negotiation about max frame size is needed before datagrams tx/rx.

Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
lib/mbuf/rte_mbuf_core.h +1 -1
 /* add new RX flags here, don't forget to update PKT_FIRST_FREE */
 
-#define PKT_FIRST_FREE (1ULL << 23)
+#define PKT_FIRST_FREE (1ULL << 24)
 #define PKT_LAST_FREE (1ULL << 40)
 
 /* add new TX flags here, don't forget to update PKT_LAST_FREE  */
(quoted diff) +0 -0

b/lib/security/rte_security.h index 88d31de0a6..364eeb5cd4 100644

lib/security/rte_security.h +10 -0
@@ -181,6 +181,16 @@ struct rte_security_ipsec_sa_options {
 	 * * 0: Disable per session security statistics collection for this SA.
 	 */
 	uint32_t stats : 1;
+
+	/** Enable reassembly on incoming packets.
+	 *
+	 * * 1: Enable driver to try reassembly of encrypted IP packets for
+	 *      this SA, if supported by the driver. This feature will work
+	 *      only if rx_offload DEV_RX_OFFLOAD_REASSEMBLY is set in
+	 *      inline ethernet device.
+	 * * 0: Disable reassembly of packets (default).
+	 */
+	uint32_t reass_en : 1;
 };
 
 /** IPSec security association direction */
#7 lore raw
Quoted 173 lines · Rosen

Hi,

Quoted 171 lines

-----Original Message-----
From: Anoob Joseph <[email protected]>
Sent: Wednesday, September 08, 2021 18:30
To: Yigit, Ferruh <[email protected]>; Xu, Rosen <[email protected]>; Andrew Rybchenko <[email protected]>
Cc: Nicolau, Radu <[email protected]>; Doherty, Declan <[email protected]>; [email protected]; [email protected]; Ananyev, Konstantin <[email protected]>; [email protected]; Ankur Dwivedi <[email protected]>; [email protected]; Akhil Goyal <[email protected]>; [email protected]
Subject: RE: [EXT] Re: [PATCH] RFC: ethdev: add reassembly offload

Hi Ferruh, Rosen, Andrew,

Please see inline.

Thanks,
Anoob

Quoted 55 lines

Subject: [EXT] Re: [PATCH] RFC: ethdev: add reassembly offload

External Email

----------------------------------------------------------------------

Quoted 6 lines · Akhil Goyal

Reassembly is a costly operation if it is done in software, however, if it is offloaded to HW, it can considerably save application cycles. The operation becomes even more costlier if IP fragmants are encrypted.

To resolve above two issues, a new offload

DEV_RX_OFFLOAD_REASSEMBLY

Quoted 9 lines

is introduced in ethdev for devices which can attempt reassembly of packets in hardware.
rte_eth_dev_info is added with the reassembly capabilities which a device can support.
Now, if IP fragments are encrypted, reassembly can also be attempted while doing inline IPsec processing.
This is controlled by a flag in rte_security_ipsec_sa_options to enable reassembly of encrypted IP fragments in the inline path.

Quoted 6 lines

The resulting reassembled packet would be a typical segmented mbuf in case of success.

And if reassembly of fragments is failed or is incomplete (if fragments do not come before the reass_timeout), the mbuf is updated with an ol_flag PKT_RX_REASSEMBLY_INCOMPLETE and mbuf is returned

as

Quoted 26 lines

is. Now application may decide the fate of the packet to wait more for fragments to come or drop.

---
 lib/ethdev/rte_ethdev.c     |  1 +
 lib/ethdev/rte_ethdev.h     | 18 +++++++++++++++++-
 lib/mbuf/rte_mbuf_core.h    |  3 ++-
 lib/security/rte_security.h | 10 ++++++++++
 4 files changed, 30 insertions(+), 2 deletions(-)
lib/ethdev/rte_ethdev.c index renamed from lib/ethdev/rte_ethdev.c +0 -0

9d95cd11e1..1ab3a093cf 100644

lib/ethdev/rte_ethdev.c +1 -0
@@ -119,6 +119,7 @@ static const struct {
 	RTE_RX_OFFLOAD_BIT2STR(VLAN_FILTER),
 	RTE_RX_OFFLOAD_BIT2STR(VLAN_EXTEND),
 	RTE_RX_OFFLOAD_BIT2STR(JUMBO_FRAME),
+	RTE_RX_OFFLOAD_BIT2STR(REASSEMBLY),
 	RTE_RX_OFFLOAD_BIT2STR(SCATTER),
 	RTE_RX_OFFLOAD_BIT2STR(TIMESTAMP),
 	RTE_RX_OFFLOAD_BIT2STR(SECURITY),
lib/ethdev/rte_ethdev.h index renamed from lib/ethdev/rte_ethdev.h +0 -0

d2b27c351f..e89a4dc1eb 100644
--- a/lib/ethdev/rte_ethdev.h

Quoted 8 lines

lib/ethdev/rte_ethdev.h index struct rte_eth_conf { · line 1363

Quoted 6 lines

+++ b/lib/ethdev/rte_ethdev.h

lib/ethdev/rte_ethdev.h index renamed from lib/ethdev/rte_ethdev.h +1 -0
@@ -1360,6 +1360,7 @@ struct rte_eth_conf {
 #define DEV_RX_OFFLOAD_VLAN_FILTER	0x00000200
 #define DEV_RX_OFFLOAD_VLAN_EXTEND	0x00000400
 #define DEV_RX_OFFLOAD_JUMBO_FRAME	0x00000800
+#define DEV_RX_OFFLOAD_REASSEMBLY	0x00001000

previous '0x00001000' was 'DEV_RX_OFFLOAD_CRC_STRIP', it has been

long

Quoted 41 lines

that offload has been removed, but not sure if it cause any problem to re- use it.

lib/ethdev/rte_ethdev.h index struct rte_eth_conf { · line 1366

Quoted 3 lines
lib/ethdev/rte_ethdev.h index renamed from lib/ethdev/rte_ethdev.h +0 -0
 #define DEV_RX_OFFLOAD_SCATTER		0x00002000
 /**
  * Timestamp is set by the driver in

RTE_MBUF_DYNFIELD_TIMESTAMP_NAME

lib/ethdev/rte_ethdev.h index struct rte_eth_dev_portconf { · line 1479

Quoted 3 lines
lib/ethdev/rte_ethdev.h index renamed from lib/ethdev/rte_ethdev.h +0 -0
@@ -1477,6 +1478,20 @@ struct rte_eth_dev_portconf {
  */
 #define RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID
	(UINT16_MAX)

lib/ethdev/rte_ethdev.h index struct rte_eth_dev_portconf { · line 1486

Quoted 8 lines
lib/ethdev/rte_ethdev.h index renamed from lib/ethdev/rte_ethdev.h +7 -0
+/**
+ * Reassembly capabilities that a device can support.
+ * The device which can support reassembly offload should set
+ * DEV_RX_OFFLOAD_REASSEMBLY
+ */
+struct rte_eth_reass_capa {
+	/** Maximum time in ns that a fragment can wait for further

fragments */

lib/ethdev/rte_ethdev.h index struct rte_eth_dev_portconf { · line 1493

Quoted 7 lines
lib/ethdev/rte_ethdev.h index renamed from lib/ethdev/rte_ethdev.h +7 -0
+	uint64_t reass_timeout;
+	/** Maximum number of fragments that device can reassemble */
+	uint16_t max_frags;
+	/** Reserved for future capabilities */
+	uint16_t reserved[3];
+};
+

I wonder if there is any other hardware around supports reassembly offload, it would be good to get more feedback on the capabilities list.

Quoted 10 lines
lib/ethdev/rte_ethdev.h index renamed from lib/ethdev/rte_ethdev.h +2 -0
 /**
  * Ethernet device associated switch information
  */
@@ -1582,8 +1597,9 @@ struct rte_eth_dev_info {
 	 * embedded managed interconnect/switch.
 	 */
 	struct rte_eth_switch_info switch_info;
+	/* Reassembly capabilities of a device for reassembly offload */
+	struct rte_eth_reass_capa reass_capa;
 
Quoted 7 lines

lib/ethdev/rte_ethdev.h index struct rte_eth_dev_info { · line 1586

Quoted 1 line
lib/ethdev/rte_ethdev.h index renamed from lib/ethdev/rte_ethdev.h +0 -1
-	uint64_t reserved_64s[2]; /**< Reserved for future fields */

Reserved fields were added to be able to update the struct without breaking the ABI, so that a critical change doesn't have to wait until next ABI break release.
Since this is ABI break release, we can keep the reserved field and add the new struct. Or this can be an opportunity to get rid of the reserved

field.

Quoted 17 lines

Personally I have no objection to get rid of the reserved field, but better to agree on this explicitly.

lib/mbuf/rte_mbuf_core.h extern "C" { · line 202

Quoted 12 lines
lib/ethdev/rte_ethdev.h index renamed from lib/ethdev/rte_ethdev.h +0 -0
 	void *reserved_ptrs[2];   /**< Reserved for future fields */
 };
 
lib/mbuf/rte_mbuf_core.h +0 -0

index
bb38d7f581..cea25c87f7 100644

lib/mbuf/rte_mbuf_core.h +0 -0
@@ -200,10 +200,11 @@ extern "C" {
 #define PKT_RX_OUTER_L4_CKSUM_BAD	(1ULL << 21)
 #define PKT_RX_OUTER_L4_CKSUM_GOOD	(1ULL << 22)
 #define PKT_RX_OUTER_L4_CKSUM_INVALID	((1ULL << 21) | (1ULL

<< 22))

Quoted 5 lines

lib/mbuf/rte_mbuf_core.h extern "C" { · line 204

Quoted 2 lines
lib/mbuf/rte_mbuf_core.h +1 -0
+#define PKT_RX_REASSEMBLY_INCOMPLETE	(1ULL << 23)
 

Similar comment with Andrew's, what is the expectation from application if this flag exists? Can we drop it to simplify the logic in the

application?

[Anoob] There can be few cases where hardware/NIC attempts inline reassembly but it fails to complete it

1. Number of fragments is larger than what is supported by the hardware 2. Hardware reassembly resources are exhausted (due to limited reassembly contexts etc) 3. Reassembly errors such as overlapping fragments 4. Wait time exhausted (or reassembly timeout)

In such cases, application would be required to retrieve the original fragments so that it can attempt reassembly in software. The incomplete flag is useful for 2 purposes basically, 1. Application would need to retrieve the time the fragment has already spend in hardware reassembly so that software reassembly attempt can compensate for it. Otherwise, reassembly timeout across hardware + software will not be accurate

Could you clarify how application will find out the time spent in HW.

Quoted 9 lines
Quoted 9 lines

2. Retrieve original
fragments. With this proposal, an incomplete reassembly would result in a chained mbuf but the segments need not be consecutive. To explain bit more,

Suppose we have a packet that is fragmented into 3 fragments, and fragment 3 & fragment 1 arrives in that order. Fragment 2 didn't arrive and hardware ultimately pushes it. In that case, application would be receiving a chained/segmented mbuf with fragment 1 & fragment 3 chained.

Quoted 4 lines
Quoted 4 lines

Now, this chained mbuf can't be treated like a regular chained mbuf. Each fragment would have its IP hdr and there are fragments missing in between. The only thing application is expected to do is, retrieve fragments, push it to s/w reassembly.

It sounds like it conflicts with SCATTER and BUFFER_SPLIT offloads which allow to return chained mbuf's. Don't know if it is good or bad, but anyway it must be documented.

Quoted 2 lines

What you mentioned is error identification. But actually a negotiation about max frame size is needed before datagrams tx/rx.

It sounds like it is OK for informational purposes, but right now I don't understand how it could be used by the application. Application still has to support reassembly in SW regardless of the information.

Quoted 31 lines
Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
lib/mbuf/rte_mbuf_core.h +1 -1
 /* add new RX flags here, don't forget to update PKT_FIRST_FREE */
 
-#define PKT_FIRST_FREE (1ULL << 23)
+#define PKT_FIRST_FREE (1ULL << 24)
 #define PKT_LAST_FREE (1ULL << 40)
 
 /* add new TX flags here, don't forget to update PKT_LAST_FREE  */
(quoted diff) +0 -0

b/lib/security/rte_security.h index 88d31de0a6..364eeb5cd4 100644

lib/security/rte_security.h +10 -0
@@ -181,6 +181,16 @@ struct rte_security_ipsec_sa_options {
 	 * * 0: Disable per session security statistics collection for this SA.
 	 */
 	uint32_t stats : 1;
+
+	/** Enable reassembly on incoming packets.
+	 *
+	 * * 1: Enable driver to try reassembly of encrypted IP packets for
+	 *      this SA, if supported by the driver. This feature will work
+	 *      only if rx_offload DEV_RX_OFFLOAD_REASSEMBLY is set in
+	 *      inline ethernet device.
+	 * * 0: Disable reassembly of packets (default).
+	 */
+	uint32_t reass_en : 1;
 };
 
 /** IPSec security association direction */
#8 lore raw

Hi Andrew, Rosen,

Please see inline.

Thanks,
Anoob

Quoted 198 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Monday, September 13, 2021 12:52 PM
To: Xu, Rosen <[email protected]>; Anoob Joseph <[email protected]>; Yigit, Ferruh <[email protected]>; Andrew Rybchenko <[email protected]>
Cc: Nicolau, Radu <[email protected]>; Doherty, Declan <[email protected]>; [email protected]; [email protected]; Ananyev, Konstantin <[email protected]>; [email protected]; Ankur Dwivedi <[email protected]>; Akhil Goyal <[email protected]>; [email protected]
Subject: Re: [EXT] Re: [PATCH] RFC: ethdev: add reassembly offload

Quoted 7 lines · Rosen

Hi,

Quoted 5 lines

-----Original Message-----
From: Anoob Joseph <[email protected]>
Sent: Wednesday, September 08, 2021 18:30
To: Yigit, Ferruh <[email protected]>; Xu, Rosen <[email protected]>; Andrew Rybchenko

<[email protected]>

Quoted 2 lines
Quoted 2 lines

Cc: Nicolau, Radu <[email protected]>; Doherty, Declan <[email protected]>; [email protected];

[email protected];

Quoted 13 lines
Quoted 13 lines

Ananyev, Konstantin <[email protected]>; [email protected]; Ankur Dwivedi <[email protected]>; [email protected]; Akhil Goyal <[email protected]>; [email protected]
Subject: RE: [EXT] Re: [PATCH] RFC: ethdev: add reassembly offload

Hi Ferruh, Rosen, Andrew,

Please see inline.

Thanks,
Anoob

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Subject: [EXT] Re: [PATCH] RFC: ethdev: add reassembly offload

External Email

--------------------------------------------------------------------

Quoted 2 lines · Akhil Goyal

Reassembly is a costly operation if it is done in software, however, if it is offloaded to HW, it can considerably save application

cycles.

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 4 lines

The operation becomes even more costlier if IP fragmants are encrypted.

To resolve above two issues, a new offload

DEV_RX_OFFLOAD_REASSEMBLY

Quoted 9 lines

is introduced in ethdev for devices which can attempt reassembly of packets in hardware.
rte_eth_dev_info is added with the reassembly capabilities which a device can support.
Now, if IP fragments are encrypted, reassembly can also be attempted while doing inline IPsec processing.
This is controlled by a flag in rte_security_ipsec_sa_options to enable reassembly of encrypted IP fragments in the inline path.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

The resulting reassembled packet would be a typical segmented mbuf in case of success.

And if reassembly of fragments is failed or is incomplete (if fragments do not come before the reass_timeout), the mbuf is updated with an ol_flag PKT_RX_REASSEMBLY_INCOMPLETE and mbuf

is

Quoted 111 lines
Quoted 111 lines
Quoted 28 lines
Quoted 1 line

returned

as

Quoted 26 lines

is. Now application may decide the fate of the packet to wait more for fragments to come or drop.

---
 lib/ethdev/rte_ethdev.c     |  1 +
 lib/ethdev/rte_ethdev.h     | 18 +++++++++++++++++-
 lib/mbuf/rte_mbuf_core.h    |  3 ++-
 lib/security/rte_security.h | 10 ++++++++++
 4 files changed, 30 insertions(+), 2 deletions(-)
lib/ethdev/rte_ethdev.c +1 -0
index 9d95cd11e1..1ab3a093cf 100644
@@ -119,6 +119,7 @@ static const struct {
 	RTE_RX_OFFLOAD_BIT2STR(VLAN_FILTER),
 	RTE_RX_OFFLOAD_BIT2STR(VLAN_EXTEND),
 	RTE_RX_OFFLOAD_BIT2STR(JUMBO_FRAME),
+	RTE_RX_OFFLOAD_BIT2STR(REASSEMBLY),
 	RTE_RX_OFFLOAD_BIT2STR(SCATTER),
 	RTE_RX_OFFLOAD_BIT2STR(TIMESTAMP),
 	RTE_RX_OFFLOAD_BIT2STR(SECURITY), diff --git

a/lib/ethdev/rte_ethdev.h b/lib/ethdev/rte_ethdev.h index d2b27c351f..e89a4dc1eb 100644
--- a/lib/ethdev/rte_ethdev.h

Quoted 8 lines

lib/ethdev/rte_ethdev.c struct rte_eth_conf { · line 1363

Quoted 6 lines

+++ b/lib/ethdev/rte_ethdev.h

lib/ethdev/rte_ethdev.c +1 -0
@@ -1360,6 +1360,7 @@ struct rte_eth_conf {
 #define DEV_RX_OFFLOAD_VLAN_FILTER	0x00000200
 #define DEV_RX_OFFLOAD_VLAN_EXTEND	0x00000400
 #define DEV_RX_OFFLOAD_JUMBO_FRAME	0x00000800
+#define DEV_RX_OFFLOAD_REASSEMBLY	0x00001000

previous '0x00001000' was 'DEV_RX_OFFLOAD_CRC_STRIP', it has been

long

Quoted 42 lines

that offload has been removed, but not sure if it cause any problem to
re- use it.

lib/ethdev/rte_ethdev.c struct rte_eth_conf { · line 1366

Quoted 3 lines
lib/ethdev/rte_ethdev.c +0 -0
 #define DEV_RX_OFFLOAD_SCATTER		0x00002000
 /**
  * Timestamp is set by the driver in

RTE_MBUF_DYNFIELD_TIMESTAMP_NAME

lib/ethdev/rte_ethdev.c struct rte_eth_dev_portconf { · line 1479

Quoted 3 lines
lib/ethdev/rte_ethdev.c +0 -0
@@ -1477,6 +1478,20 @@ struct rte_eth_dev_portconf {
  */
 #define RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID
	(UINT16_MAX)

lib/ethdev/rte_ethdev.c struct rte_eth_dev_portconf { · line 1486

Quoted 8 lines
lib/ethdev/rte_ethdev.c +7 -0
+/**
+ * Reassembly capabilities that a device can support.
+ * The device which can support reassembly offload should set
+ * DEV_RX_OFFLOAD_REASSEMBLY
+ */
+struct rte_eth_reass_capa {
+	/** Maximum time in ns that a fragment can wait for further

fragments */

lib/ethdev/rte_ethdev.c struct rte_eth_dev_portconf { · line 1493

Quoted 7 lines
lib/ethdev/rte_ethdev.c +7 -0
+	uint64_t reass_timeout;
+	/** Maximum number of fragments that device can reassemble */
+	uint16_t max_frags;
+	/** Reserved for future capabilities */
+	uint16_t reserved[3];
+};
+

I wonder if there is any other hardware around supports reassembly offload, it would be good to get more feedback on the capabilities list.

Quoted 10 lines
lib/ethdev/rte_ethdev.c +2 -0
 /**
  * Ethernet device associated switch information
  */
@@ -1582,8 +1597,9 @@ struct rte_eth_dev_info {
 	 * embedded managed interconnect/switch.
 	 */
 	struct rte_eth_switch_info switch_info;
+	/* Reassembly capabilities of a device for reassembly offload */
+	struct rte_eth_reass_capa reass_capa;
 
Quoted 8 lines

lib/ethdev/rte_ethdev.c struct rte_eth_dev_info { · line 1586

Quoted 1 line
lib/ethdev/rte_ethdev.c +0 -1
-	uint64_t reserved_64s[2]; /**< Reserved for future fields */

Reserved fields were added to be able to update the struct without breaking the ABI, so that a critical change doesn't have to wait until next ABI break release.
Since this is ABI break release, we can keep the reserved field and add the new struct. Or this can be an opportunity to get rid of the reserved

field.

Quoted 23 lines

Personally I have no objection to get rid of the reserved field, but better to agree on this explicitly.

lib/mbuf/rte_mbuf_core.h extern "C" { · line 202

Quoted 12 lines
lib/ethdev/rte_ethdev.c +0 -0
 	void *reserved_ptrs[2];   /**< Reserved for future fields */
 };
 
lib/mbuf/rte_mbuf_core.h +0 -0

index
bb38d7f581..cea25c87f7 100644

lib/mbuf/rte_mbuf_core.h +0 -0
@@ -200,10 +200,11 @@ extern "C" {
 #define PKT_RX_OUTER_L4_CKSUM_BAD	(1ULL << 21)
 #define PKT_RX_OUTER_L4_CKSUM_GOOD	(1ULL << 22)
 #define PKT_RX_OUTER_L4_CKSUM_INVALID	((1ULL << 21) | (1ULL

<< 22))

lib/mbuf/rte_mbuf_core.h extern "C" { · line 204

Quoted 2 lines
lib/mbuf/rte_mbuf_core.h +1 -0
+#define PKT_RX_REASSEMBLY_INCOMPLETE	(1ULL << 23)
 

Similar comment with Andrew's, what is the expectation from application if this flag exists? Can we drop it to simplify the logic in the

Quoted 6 lines
Quoted 6 lines

application?

[Anoob] There can be few cases where hardware/NIC attempts inline reassembly but it fails to complete it

1. Number of fragments is larger than what is supported by the hardware

2.

Quoted 11 lines
Quoted 11 lines

Hardware reassembly resources are exhausted (due to limited reassembly contexts etc) 3. Reassembly errors such as overlapping fragments 4. Wait time exhausted (or reassembly timeout)

In such cases, application would be required to retrieve the original fragments so that it can attempt reassembly in software. The incomplete flag is useful for 2 purposes basically, 1. Application would need to retrieve the time the fragment has already spend in hardware reassembly so that software reassembly attempt can compensate for it. Otherwise, reassembly timeout across hardware + software will not be accurate

Quoted 1 line

Could you clarify how application will find out the time spent in HW.

[Anoob] We could use rte_mbuf dynamic fields for the same. Looks like RFC hasn't touched on this aspect yet.

Quoted 15 lines
Quoted 11 lines
Quoted 11 lines

2. Retrieve original
fragments. With this proposal, an incomplete reassembly would result in a chained mbuf but the segments need not be consecutive. To explain bit more,

Suppose we have a packet that is fragmented into 3 fragments, and fragment
3 & fragment 1 arrives in that order. Fragment 2 didn't arrive and hardware ultimately pushes it. In that case, application would be receiving a chained/segmented mbuf with fragment 1 & fragment 3

chained.

Quoted 3 lines
Quoted 3 lines

Now, this chained mbuf can't be treated like a regular chained mbuf. Each fragment would have its IP hdr and there are fragments missing in

Quoted 7 lines

between.

Quoted 2 lines
Quoted 2 lines

The only thing application is expected to do is, retrieve fragments, push it to s/w reassembly.

It sounds like it conflicts with SCATTER and BUFFER_SPLIT offloads which allow to return chained mbuf's. Don't know if it is good or bad, but anyway it must be documented.

[Anoob] Agreed.

Quoted 4 lines
Quoted 3 lines

What you mentioned is error identification. But actually a negotiation about

max frame size is needed before datagrams tx/rx.

[Anoob] The actually reassembly settings would be negotiated by the s/w. The offload can be thought of like how checksum is being done now. S/w negotiates with peer and then enables the hardware to accelerate. If hardware is able to reassemble, then well and good. If not, we would have software compensate for it.

Quoted 4 lines

It sounds like it is OK for informational purposes, but right now I don't understand how it could be used by the application. Application still has to support reassembly in SW regardless of the information.

[Anoob] The additional information from "incomplete reassembly" attempt would be useful for software to properly compensate for the hardware reassembly attempt (basically, the reassembly timeout is honored across s/w + h/w reassembly attempt).

Benefit of such an offload is in accelerating reassembly in hardware for performance use cases. If application expects heavy fragmentation, then every packet would have a cost of ~1000 cycles (typically) to get it reassembled. By offloading this (atleast some portion of it) to hardware, application would be able to save significant cycles.

Since IP reassembly presents varying challenges depending on hardware implementation, we cannot expect complete reassembly offload in hardware. For some vendors, maximum number of fragments supported could be limited. Some vendors could have limited reassembly timeout (or wait_time). Some vendors could have limitations depending on datagram sizes. So s/w reassembly is not going away even with the proposed hardware assisted inline reassembly.

Quoted 32 lines
Quoted 32 lines
Quoted 31 lines
Quoted 31 lines
Quoted 31 lines
lib/mbuf/rte_mbuf_core.h +1 -1
 /* add new RX flags here, don't forget to update PKT_FIRST_FREE */
 
-#define PKT_FIRST_FREE (1ULL << 23)
+#define PKT_FIRST_FREE (1ULL << 24)
 #define PKT_LAST_FREE (1ULL << 40)
 
 /* add new TX flags here, don't forget to update PKT_LAST_FREE  */
(quoted diff) +0 -0

b/lib/security/rte_security.h index 88d31de0a6..364eeb5cd4 100644

lib/security/rte_security.h +10 -0
@@ -181,6 +181,16 @@ struct rte_security_ipsec_sa_options {
 	 * * 0: Disable per session security statistics collection for this SA.
 	 */
 	uint32_t stats : 1;
+
+	/** Enable reassembly on incoming packets.
+	 *
+	 * * 1: Enable driver to try reassembly of encrypted IP packets for
+	 *      this SA, if supported by the driver. This feature will work
+	 *      only if rx_offload DEV_RX_OFFLOAD_REASSEMBLY is set in
+	 *      inline ethernet device.
+	 * * 0: Disable reassembly of packets (default).
+	 */
+	uint32_t reass_en : 1;
 };
 
 /** IPSec security association direction */
#9 lore raw
In reply to Akhil Goyal

Hi,

Quoted 81 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Akhil Goyal
Sent: Monday, August 23, 2021 18:03
To: [email protected]
Cc: [email protected]; Nicolau, Radu <[email protected]>; Doherty, Declan <[email protected]>; [email protected]; [email protected]; Ananyev, Konstantin <[email protected]>; [email protected]; [email protected]; Yigit, Ferruh <[email protected]>; [email protected]; Akhil Goyal <[email protected]>
Subject: [dpdk-dev] [PATCH] RFC: ethdev: add reassembly offload

Reassembly is a costly operation if it is done in software, however, if it is offloaded to HW, it can considerably save application cycles.
The operation becomes even more costlier if IP fragmants are encrypted.

To resolve above two issues, a new offload DEV_RX_OFFLOAD_REASSEMBLY is introduced in ethdev for devices which can attempt reassembly of packets in hardware.
rte_eth_dev_info is added with the reassembly capabilities which a device can support.
Now, if IP fragments are encrypted, reassembly can also be attempted while doing inline IPsec processing.
This is controlled by a flag in rte_security_ipsec_sa_options to enable reassembly of encrypted IP fragments in the inline path.

The resulting reassembled packet would be a typical segmented mbuf in case of success.

And if reassembly of fragments is failed or is incomplete (if fragments do not come before the reass_timeout), the mbuf is updated with an ol_flag PKT_RX_REASSEMBLY_INCOMPLETE and mbuf is returned as is. Now application may decide the fate of the packet to wait more for fragments to come or drop.

---
 lib/ethdev/rte_ethdev.c     |  1 +
 lib/ethdev/rte_ethdev.h     | 18 +++++++++++++++++-
 lib/mbuf/rte_mbuf_core.h    |  3 ++-
 lib/security/rte_security.h | 10 ++++++++++
 4 files changed, 30 insertions(+), 2 deletions(-)
lib/ethdev/rte_ethdev.c index renamed from lib/ethdev/rte_ethdev.c +0 -0

9d95cd11e1..1ab3a093cf 100644

lib/ethdev/rte_ethdev.c +1 -0
@@ -119,6 +119,7 @@ static const struct {
 	RTE_RX_OFFLOAD_BIT2STR(VLAN_FILTER),
 	RTE_RX_OFFLOAD_BIT2STR(VLAN_EXTEND),
 	RTE_RX_OFFLOAD_BIT2STR(JUMBO_FRAME),
+	RTE_RX_OFFLOAD_BIT2STR(REASSEMBLY),
 	RTE_RX_OFFLOAD_BIT2STR(SCATTER),
 	RTE_RX_OFFLOAD_BIT2STR(TIMESTAMP),
 	RTE_RX_OFFLOAD_BIT2STR(SECURITY),
lib/ethdev/rte_ethdev.h index renamed from lib/ethdev/rte_ethdev.h +0 -0

d2b27c351f..e89a4dc1eb 100644

lib/ethdev/rte_ethdev.h +1 -0
@@ -1360,6 +1360,7 @@ struct rte_eth_conf {
 #define DEV_RX_OFFLOAD_VLAN_FILTER	0x00000200
 #define DEV_RX_OFFLOAD_VLAN_EXTEND	0x00000400
 #define DEV_RX_OFFLOAD_JUMBO_FRAME	0x00000800
+#define DEV_RX_OFFLOAD_REASSEMBLY	0x00001000
 #define DEV_RX_OFFLOAD_SCATTER		0x00002000
 /**
  * Timestamp is set by the driver in

RTE_MBUF_DYNFIELD_TIMESTAMP_NAME @@ -1477,6 +1478,20 @@ struct rte_eth_dev_portconf {
*/

 #define RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID
	(UINT16_MAX)
lib/ethdev/rte_ethdev.h +7 -0
+/**
+ * Reassembly capabilities that a device can support.
+ * The device which can support reassembly offload should set
+ * DEV_RX_OFFLOAD_REASSEMBLY
+ */
+struct rte_eth_reass_capa {
+	/** Maximum time in ns that a fragment can wait for further

fragments */

lib/ethdev/rte_ethdev.h struct rte_eth_dev_portconf { · line 1493

Quoted 6 lines
lib/ethdev/rte_ethdev.h +6 -0
+	uint64_t reass_timeout;
+	/** Maximum number of fragments that device can reassemble */
+	uint16_t max_frags;
+	/** Reserved for future capabilities */
+	uint16_t reserved[3];
+};

IP reassembly occurs at the final recipient of the message, NIC attempts to do it has a fer challenges. The reason is that having NICs need to worry about reassembling fragments would increase their complexity, so most likely it only can handle range length of datagrams. Seems rte_eth_reass_capa miss the max original datagrams length which NIC can support, this features is better to be negotiated between NIC and SW as well.

Quoted 54 lines

/**
* Ethernet device associated switch information
*/

lib/ethdev/rte_ethdev.h +2 -1
@@ -1582,8 +1597,9 @@ struct rte_eth_dev_info {
 	 * embedded managed interconnect/switch.
 	 */
 	struct rte_eth_switch_info switch_info;
+	/* Reassembly capabilities of a device for reassembly offload */
+	struct rte_eth_reass_capa reass_capa;
 
-	uint64_t reserved_64s[2]; /**< Reserved for future fields */
 	void *reserved_ptrs[2];   /**< Reserved for future fields */
 };
 
lib/mbuf/rte_mbuf_core.h index renamed from lib/mbuf/rte_mbuf_core.h +0 -0

bb38d7f581..cea25c87f7 100644

lib/mbuf/rte_mbuf_core.h +2 -1
@@ -200,10 +200,11 @@ extern "C" {
 #define PKT_RX_OUTER_L4_CKSUM_BAD	(1ULL << 21)
 #define PKT_RX_OUTER_L4_CKSUM_GOOD	(1ULL << 22)
 #define PKT_RX_OUTER_L4_CKSUM_INVALID	((1ULL << 21) | (1ULL << 22))
+#define PKT_RX_REASSEMBLY_INCOMPLETE	(1ULL << 23)
 
 /* add new RX flags here, don't forget to update PKT_FIRST_FREE */
 
-#define PKT_FIRST_FREE (1ULL << 23)
+#define PKT_FIRST_FREE (1ULL << 24)
 #define PKT_LAST_FREE (1ULL << 40)
 
 /* add new TX flags here, don't forget to update PKT_LAST_FREE  */ diff --git

a/lib/security/rte_security.h b/lib/security/rte_security.h index 88d31de0a6..364eeb5cd4 100644

lib/security/rte_security.h +10 -1
@@ -181,6 +181,16 @@ struct rte_security_ipsec_sa_options {
 	 * * 0: Disable per session security statistics collection for this SA.
 	 */
 	uint32_t stats : 1;
+
+	/** Enable reassembly on incoming packets.
+	 *
+	 * * 1: Enable driver to try reassembly of encrypted IP packets for
+	 *      this SA, if supported by the driver. This feature will work
+	 *      only if rx_offload DEV_RX_OFFLOAD_REASSEMBLY is set in
+	 *      inline ethernet device.
+	 * * 0: Disable reassembly of packets (default).
+	 */
+	uint32_t reass_en : 1;
 };
 
 /** IPSec security association direction */
--

2.25.1

#10 lore raw

Cc myself

Quoted 168 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Xu, Rosen
Sent: Wednesday, September 08, 2021 14:34
To: Akhil Goyal <[email protected]>; [email protected]
Cc: [email protected]; Nicolau, Radu <[email protected]>; Doherty, Declan <[email protected]>; [email protected]; [email protected]; Ananyev, Konstantin <[email protected]>; [email protected]; [email protected]; Yigit, Ferruh <[email protected]>; [email protected]
Subject: Re: [dpdk-dev] [PATCH] RFC: ethdev: add reassembly offload

Hi,

Quoted 7 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Akhil Goyal
Sent: Monday, August 23, 2021 18:03
To: [email protected]
Cc: [email protected]; Nicolau, Radu <[email protected]>; Doherty, Declan <[email protected]>; [email protected]; [email protected]; Ananyev, Konstantin

<[email protected]>;

Quoted 10 lines

[email protected]; [email protected]; Yigit, Ferruh <[email protected]>; [email protected]; Akhil Goyal <[email protected]>
Subject: [dpdk-dev] [PATCH] RFC: ethdev: add reassembly offload

Reassembly is a costly operation if it is done in software, however, if it is offloaded to HW, it can considerably save application cycles. The operation becomes even more costlier if IP fragmants are encrypted.

To resolve above two issues, a new offload

DEV_RX_OFFLOAD_REASSEMBLY

Quoted 9 lines

is introduced in ethdev for devices which can attempt reassembly of packets in hardware.
rte_eth_dev_info is added with the reassembly capabilities which a device can support.
Now, if IP fragments are encrypted, reassembly can also be attempted while doing inline IPsec processing.
This is controlled by a flag in rte_security_ipsec_sa_options to enable reassembly of encrypted IP fragments in the inline path.

Quoted 6 lines

The resulting reassembled packet would be a typical segmented mbuf in case of success.

And if reassembly of fragments is failed or is incomplete (if fragments do not come before the reass_timeout), the mbuf is updated with an ol_flag PKT_RX_REASSEMBLY_INCOMPLETE and mbuf is returned

as

Quoted 35 lines

is. Now application may decide the fate of the packet to wait more for fragments to come or drop.

---
 lib/ethdev/rte_ethdev.c     |  1 +
 lib/ethdev/rte_ethdev.h     | 18 +++++++++++++++++-
 lib/mbuf/rte_mbuf_core.h    |  3 ++-
 lib/security/rte_security.h | 10 ++++++++++
 4 files changed, 30 insertions(+), 2 deletions(-)
lib/ethdev/rte_ethdev.c index renamed from lib/ethdev/rte_ethdev.c +0 -0

9d95cd11e1..1ab3a093cf 100644

lib/ethdev/rte_ethdev.c +1 -0
@@ -119,6 +119,7 @@ static const struct {
 	RTE_RX_OFFLOAD_BIT2STR(VLAN_FILTER),
 	RTE_RX_OFFLOAD_BIT2STR(VLAN_EXTEND),
 	RTE_RX_OFFLOAD_BIT2STR(JUMBO_FRAME),
+	RTE_RX_OFFLOAD_BIT2STR(REASSEMBLY),
 	RTE_RX_OFFLOAD_BIT2STR(SCATTER),
 	RTE_RX_OFFLOAD_BIT2STR(TIMESTAMP),
 	RTE_RX_OFFLOAD_BIT2STR(SECURITY),
lib/ethdev/rte_ethdev.h index renamed from lib/ethdev/rte_ethdev.h +0 -0

d2b27c351f..e89a4dc1eb 100644

lib/ethdev/rte_ethdev.h +1 -0
@@ -1360,6 +1360,7 @@ struct rte_eth_conf {
 #define DEV_RX_OFFLOAD_VLAN_FILTER	0x00000200
 #define DEV_RX_OFFLOAD_VLAN_EXTEND	0x00000400
 #define DEV_RX_OFFLOAD_JUMBO_FRAME	0x00000800
+#define DEV_RX_OFFLOAD_REASSEMBLY	0x00001000
 #define DEV_RX_OFFLOAD_SCATTER		0x00002000
 /**
  * Timestamp is set by the driver in
Quoted 1 line

RTE_MBUF_DYNFIELD_TIMESTAMP_NAME @@ -1477,6 +1478,20 @@

struct

Quoted 13 lines

rte_eth_dev_portconf {
*/

 #define RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID
	(UINT16_MAX)
lib/ethdev/rte_ethdev.h +7 -0
+/**
+ * Reassembly capabilities that a device can support.
+ * The device which can support reassembly offload should set
+ * DEV_RX_OFFLOAD_REASSEMBLY
+ */
+struct rte_eth_reass_capa {
+	/** Maximum time in ns that a fragment can wait for further

fragments */

lib/ethdev/rte_ethdev.h struct rte_eth_dev_portconf { · line 1493

Quoted 6 lines
lib/ethdev/rte_ethdev.h +6 -0
+	uint64_t reass_timeout;
+	/** Maximum number of fragments that device can reassemble */
+	uint16_t max_frags;
+	/** Reserved for future capabilities */
+	uint16_t reserved[3];
+};

IP reassembly occurs at the final recipient of the message, NIC attempts to do it has a fer challenges. The reason is that having NICs need to worry about reassembling fragments would increase their complexity, so most likely it only can handle range length of datagrams. Seems rte_eth_reass_capa miss the max original datagrams length which NIC can support, this features is better to be negotiated between NIC and SW as well.

Quoted 19 lines

/**
* Ethernet device associated switch information
*/

lib/ethdev/rte_ethdev.h +2 -1
@@ -1582,8 +1597,9 @@ struct rte_eth_dev_info {
 	 * embedded managed interconnect/switch.
 	 */
 	struct rte_eth_switch_info switch_info;
+	/* Reassembly capabilities of a device for reassembly offload */
+	struct rte_eth_reass_capa reass_capa;
 
-	uint64_t reserved_64s[2]; /**< Reserved for future fields */
 	void *reserved_ptrs[2];   /**< Reserved for future fields */
 };
 
lib/mbuf/rte_mbuf_core.h index renamed from lib/mbuf/rte_mbuf_core.h +0 -0

bb38d7f581..cea25c87f7 100644

lib/mbuf/rte_mbuf_core.h extern "C" { · line 202

Quoted 3 lines
lib/mbuf/rte_mbuf_core.h +0 -0
@@ -200,10 +200,11 @@ extern "C" {
 #define PKT_RX_OUTER_L4_CKSUM_BAD	(1ULL << 21)
 #define PKT_RX_OUTER_L4_CKSUM_GOOD	(1ULL << 22)
 #define PKT_RX_OUTER_L4_CKSUM_INVALID	((1ULL << 21) | (1ULL

<< 22))

Quoted 33 lines
lib/mbuf/rte_mbuf_core.h +2 -1
+#define PKT_RX_REASSEMBLY_INCOMPLETE	(1ULL << 23)
 
 /* add new RX flags here, don't forget to update PKT_FIRST_FREE */
 
-#define PKT_FIRST_FREE (1ULL << 23)
+#define PKT_FIRST_FREE (1ULL << 24)
 #define PKT_LAST_FREE (1ULL << 40)
 
 /* add new TX flags here, don't forget to update PKT_LAST_FREE  */
lib/security/rte_security.h +0 -0

index
88d31de0a6..364eeb5cd4 100644

lib/security/rte_security.h +10 -1
@@ -181,6 +181,16 @@ struct rte_security_ipsec_sa_options {
 	 * * 0: Disable per session security statistics collection for this SA.
 	 */
 	uint32_t stats : 1;
+
+	/** Enable reassembly on incoming packets.
+	 *
+	 * * 1: Enable driver to try reassembly of encrypted IP packets for
+	 *      this SA, if supported by the driver. This feature will work
+	 *      only if rx_offload DEV_RX_OFFLOAD_REASSEMBLY is set in
+	 *      inline ethernet device.
+	 * * 0: Disable reassembly of packets (default).
+	 */
+	uint32_t reass_en : 1;
 };
 
 /** IPSec security association direction */
--

2.25.1

#11 lore raw

cover ethdev: introduce IP reassembly offload

In reply to Akhil Goyal

As discussed in the RFC[1] sent in 21.11, a new offload is introduced in ethdev for IP reassembly.

This patchset add the RX offload and an application to test it. Currently, the offload is tested along with inline IPsec processing. It can also be updated as a standalone offload without IPsec, if there are some hardware available to test it.
The patchset is tested on cnxk platform. The driver implementation is added as a separate patchset.

[1]: http://patches.dpdk.org/project/dpdk/patch/[email protected]/

Akhil Goyal (8):
ethdev: introduce IP reassembly offload
ethdev: add dev op for IP reassembly configuration
ethdev: add mbuf dynfield for incomplete IP reassembly
security: add IPsec option for IP reassembly app/test: add unit cases for inline IPsec offload app/test: add IP reassembly case with no frags app/test: add IP reassembly cases with multiple fragments app/test: add IP reassembly negative cases

 app/test/meson.build                          |    1 +
 app/test/test_inline_ipsec.c                  | 1036 +++++++++++++++++
 .../test_inline_ipsec_reassembly_vectors.h    |  790 +++++++++++++
 doc/guides/nics/features.rst                  |   12 +
 lib/ethdev/ethdev_driver.h                    |   27 +
 lib/ethdev/rte_ethdev.c                       |   47 +
 lib/ethdev/rte_ethdev.h                       |  117 +-
 lib/ethdev/version.map                        |    5 +
 lib/mbuf/rte_mbuf_core.h                      |    3 +-
 lib/security/rte_security.h                   |   12 +-
 10 files changed, 2047 insertions(+), 3 deletions(-)
 create mode 100644 app/test/test_inline_ipsec.c
 create mode 100644 app/test/test_inline_ipsec_reassembly_vectors.h
Signature · 1 line
2.25.1
#12 lore raw

PATCH 1/8 ethdev: introduce IP reassembly offload

IP Reassembly is a costly operation if it is done in software.
The operation becomes even more costlier if IP fragmants are encrypted. However, if it is offloaded to HW, it can considerably save application cycles.

Hence, a new offload RTE_ETH_RX_OFFLOAD_IP_REASSEMBLY is introduced in ethdev for devices which can attempt reassembly of packets in hardware. rte_eth_dev_info is updated with the reassembly capabilities which a device can support.

The resulting reassembled packet would be a typical segmented mbuf in case of success.

And if reassembly of fragments is failed or is incomplete (if fragments do not come before the reass_timeout), the mbuf ol_flags can be updated. This is updated in a subsequent patch.

---
 doc/guides/nics/features.rst | 12 ++++++++++++
 lib/ethdev/rte_ethdev.c      |  1 +
 lib/ethdev/rte_ethdev.h      | 32 +++++++++++++++++++++++++++++++-
 3 files changed, 44 insertions(+), 1 deletion(-)
doc/guides/nics/features.rst +12 -0
index 27be2d2576..1dfdee9602 100644
@@ -602,6 +602,18 @@ Supports inner packet L4 checksum.
   ``tx_offload_capa,tx_queue_offload_capa:RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM``.
 
 
+.. _nic_features_ip_reassembly:
+
+IP reassembly
+-------------
+
+Supports IP reassembly in hardware.
+
+* **[uses]     rte_eth_rxconf,rte_eth_rxmode**: ``offloads:RTE_ETH_RX_OFFLOAD_IP_REASSEMBLY``.
+* **[provides] mbuf**: ``mbuf.ol_flags:RTE_MBUF_F_RX_IP_REASSEMBLY_INCOMPLETE``.
+* **[provides] rte_eth_dev_info**: ``reass_capa``.
+
+
 .. _nic_features_shared_rx_queue:
 
 Shared Rx queue
lib/ethdev/rte_ethdev.c +1 -0
index a1d475a292..d9a03f12f9 100644
@@ -126,6 +126,7 @@ static const struct {
 	RTE_RX_OFFLOAD_BIT2STR(OUTER_UDP_CKSUM),
 	RTE_RX_OFFLOAD_BIT2STR(RSS_HASH),
 	RTE_RX_OFFLOAD_BIT2STR(BUFFER_SPLIT),
+	RTE_RX_OFFLOAD_BIT2STR(IP_REASSEMBLY),
 };
 
 #undef RTE_RX_OFFLOAD_BIT2STR
lib/ethdev/rte_ethdev.h +31 -1
index fa299c8ad7..11427b2e4d 100644
@@ -1586,6 +1586,7 @@ struct rte_eth_conf {
 #define RTE_ETH_RX_OFFLOAD_RSS_HASH         RTE_BIT64(19)
 #define DEV_RX_OFFLOAD_RSS_HASH             RTE_ETH_RX_OFFLOAD_RSS_HASH
 #define RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT     RTE_BIT64(20)
+#define RTE_ETH_RX_OFFLOAD_IP_REASSEMBLY    RTE_BIT64(21)
 
 #define RTE_ETH_RX_OFFLOAD_CHECKSUM (RTE_ETH_RX_OFFLOAD_IPV4_CKSUM | \
 				 RTE_ETH_RX_OFFLOAD_UDP_CKSUM | \
@@ -1781,6 +1782,33 @@ enum rte_eth_representor_type {
 	RTE_ETH_REPRESENTOR_PF,   /**< representor of Physical Function. */
 };
 
+/* Flag to offload IP reassembly for IPv4 packets. */
+#define RTE_ETH_DEV_REASSEMBLY_F_IPV4 (RTE_BIT32(0))
+/* Flag to offload IP reassembly for IPv6 packets. */
+#define RTE_ETH_DEV_REASSEMBLY_F_IPV6 (RTE_BIT32(1))
+/**
+ * @warning
+ * @b EXPERIMENTAL: this structure may change without prior notice.
+ *
+ * A structure used to set IP reassembly configuration.
+ *
+ * If RTE_ETH_RX_OFFLOAD_IP_REASSEMBLY flag is set in offloads field,
+ * the PMD will attempt IP reassembly for the received packets as per
+ * properties defined in this structure:
+ *
+ */
+struct rte_eth_ip_reass_params {
+	/** Maximum time in ms which PMD can wait for other fragments. */
+	uint32_t reass_timeout;
+	/** Maximum number of fragments that can be reassembled. */
+	uint16_t max_frags;
+	/**
+	 * Flags to enable reassembly of packet types -
+	 * RTE_ETH_DEV_REASSEMBLY_F_xxx.
+	 */
+	uint16_t flags;
+};
+
 /**
  * A structure used to retrieve the contextual information of
  * an Ethernet device, such as the controlling driver of the
@@ -1841,8 +1869,10 @@ struct rte_eth_dev_info {
 	 * embedded managed interconnect/switch.
 	 */
 	struct rte_eth_switch_info switch_info;
+	/** IP reassembly offload capabilities that a device can support. */
+	struct rte_eth_ip_reass_params reass_capa;
 
-	uint64_t reserved_64s[2]; /**< Reserved for future fields */
+	uint64_t reserved_64s[1]; /**< Reserved for future fields */
 	void *reserved_ptrs[2];   /**< Reserved for future fields */
 };
 
Signature · 1 line
2.25.1
Acked-by on v1 1/8
#13 lore raw

RE: [PATCH 1/8] ethdev: introduce IP reassembly offload

Quoted 108 lines

IP Reassembly is a costly operation if it is done in software.
The operation becomes even more costlier if IP fragmants are encrypted. However, if it is offloaded to HW, it can considerably save application cycles.

Hence, a new offload RTE_ETH_RX_OFFLOAD_IP_REASSEMBLY is introduced in ethdev for devices which can attempt reassembly of packets in hardware. rte_eth_dev_info is updated with the reassembly capabilities which a device can support.

The resulting reassembled packet would be a typical segmented mbuf in case of success.

And if reassembly of fragments is failed or is incomplete (if fragments do not come before the reass_timeout), the mbuf ol_flags can be updated. This is updated in a subsequent patch.

---
 doc/guides/nics/features.rst | 12 ++++++++++++
 lib/ethdev/rte_ethdev.c      |  1 +
 lib/ethdev/rte_ethdev.h      | 32 +++++++++++++++++++++++++++++++-
 3 files changed, 44 insertions(+), 1 deletion(-)
doc/guides/nics/features.rst +12 -0
index 27be2d2576..1dfdee9602 100644
@@ -602,6 +602,18 @@ Supports inner packet L4 checksum.
   ``tx_offload_capa,tx_queue_offload_capa:RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM``.
 
 
+.. _nic_features_ip_reassembly:
+
+IP reassembly
+-------------
+
+Supports IP reassembly in hardware.
+
+* **[uses]     rte_eth_rxconf,rte_eth_rxmode**: ``offloads:RTE_ETH_RX_OFFLOAD_IP_REASSEMBLY``.
+* **[provides] mbuf**: ``mbuf.ol_flags:RTE_MBUF_F_RX_IP_REASSEMBLY_INCOMPLETE``.
+* **[provides] rte_eth_dev_info**: ``reass_capa``.
+
+
 .. _nic_features_shared_rx_queue:
 
 Shared Rx queue
lib/ethdev/rte_ethdev.c +1 -0
index a1d475a292..d9a03f12f9 100644
@@ -126,6 +126,7 @@ static const struct {
 	RTE_RX_OFFLOAD_BIT2STR(OUTER_UDP_CKSUM),
 	RTE_RX_OFFLOAD_BIT2STR(RSS_HASH),
 	RTE_RX_OFFLOAD_BIT2STR(BUFFER_SPLIT),
+	RTE_RX_OFFLOAD_BIT2STR(IP_REASSEMBLY),
 };
 
 #undef RTE_RX_OFFLOAD_BIT2STR
lib/ethdev/rte_ethdev.h +28 -0
index fa299c8ad7..11427b2e4d 100644
@@ -1586,6 +1586,7 @@ struct rte_eth_conf {
 #define RTE_ETH_RX_OFFLOAD_RSS_HASH         RTE_BIT64(19)
 #define DEV_RX_OFFLOAD_RSS_HASH             RTE_ETH_RX_OFFLOAD_RSS_HASH
 #define RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT     RTE_BIT64(20)
+#define RTE_ETH_RX_OFFLOAD_IP_REASSEMBLY    RTE_BIT64(21)
 
 #define RTE_ETH_RX_OFFLOAD_CHECKSUM (RTE_ETH_RX_OFFLOAD_IPV4_CKSUM | \
 				 RTE_ETH_RX_OFFLOAD_UDP_CKSUM | \
@@ -1781,6 +1782,33 @@ enum rte_eth_representor_type {
 	RTE_ETH_REPRESENTOR_PF,   /**< representor of Physical Function. */
 };
 
+/* Flag to offload IP reassembly for IPv4 packets. */
+#define RTE_ETH_DEV_REASSEMBLY_F_IPV4 (RTE_BIT32(0))
+/* Flag to offload IP reassembly for IPv6 packets. */
+#define RTE_ETH_DEV_REASSEMBLY_F_IPV6 (RTE_BIT32(1))
+/**
+ * @warning
+ * @b EXPERIMENTAL: this structure may change without prior notice.
+ *
+ * A structure used to set IP reassembly configuration.
+ *
+ * If RTE_ETH_RX_OFFLOAD_IP_REASSEMBLY flag is set in offloads field,
+ * the PMD will attempt IP reassembly for the received packets as per
+ * properties defined in this structure:
+ *
+ */
+struct rte_eth_ip_reass_params {
+	/** Maximum time in ms which PMD can wait for other fragments. */
+	uint32_t reass_timeout;
+	/** Maximum number of fragments that can be reassembled. */
+	uint16_t max_frags;
+	/**
+	 * Flags to enable reassembly of packet types -
+	 * RTE_ETH_DEV_REASSEMBLY_F_xxx.
+	 */
+	uint16_t flags;
+};
+
 /**
  * A structure used to retrieve the contextual information of
  * an Ethernet device, such as the controlling driver of the
@@ -1841,8 +1869,10 @@ struct rte_eth_dev_info {
 	 * embedded managed interconnect/switch.
 	 */

lib/ethdev/rte_ethdev.h struct rte_eth_dev_info {

Quoted 10 lines
lib/ethdev/rte_ethdev.h +3 -2
 	struct rte_eth_switch_info switch_info;
+	/** IP reassembly offload capabilities that a device can support. */
+	struct rte_eth_ip_reass_params reass_capa;
 
-	uint64_t reserved_64s[2]; /**< Reserved for future fields */
+	uint64_t reserved_64s[1]; /**< Reserved for future fields */
 	void *reserved_ptrs[2];   /**< Reserved for future fields */
 };
 
--
Quoted 1 line

2.25.1

#14 lore raw

Re: [PATCH 1/8] ethdev: introduce IP reassembly offload

In reply to Akhil Goyal
Quoted 8 lines · Akhil Goyal

IP Reassembly is a costly operation if it is done in software.
The operation becomes even more costlier if IP fragmants are encrypted. However, if it is offloaded to HW, it can considerably save application cycles.

Hence, a new offload RTE_ETH_RX_OFFLOAD_IP_REASSEMBLY is introduced in ethdev for devices which can attempt reassembly of packets in hardware. rte_eth_dev_info is updated with the reassembly capabilities which a device can support.

Yes, reassembly is really complicated process taking possibility to have overlapping fragments, out-of-order etc.
There are network attacks based on IP reassembly.
Will it simply result in IP reassembly failure if no buffers are left for IP fragments? What will be reported in mbuf if some packets overlap? Just raw packets as is or reassembly result with holes?
I think behavour should be specified/

Quoted 20 lines

The resulting reassembled packet would be a typical segmented mbuf in case of success.

And if reassembly of fragments is failed or is incomplete (if fragments do not come before the reass_timeout), the mbuf ol_flags can be updated. This is updated in a subsequent patch.

---
  doc/guides/nics/features.rst | 12 ++++++++++++
  lib/ethdev/rte_ethdev.c      |  1 +
  lib/ethdev/rte_ethdev.h      | 32 +++++++++++++++++++++++++++++++-
  3 files changed, 44 insertions(+), 1 deletion(-)
doc/guides/nics/features.rst +0 -0
index 27be2d2576..1dfdee9602 100644
@@ -602,6 +602,18 @@ Supports inner packet L4 checksum.
    ``tx_offload_capa,tx_queue_offload_capa:RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM``.

doc/guides/nics/features.rst Supports inner packet L4 checksum. · line 612

Quoted 10 lines
doc/guides/nics/features.rst +8 -0
 
 
+.. _nic_features_ip_reassembly:
+
+IP reassembly
+-------------
+
+Supports IP reassembly in hardware.
+
+* **[uses]     rte_eth_rxconf,rte_eth_rxmode**: ``offloads:RTE_ETH_RX_OFFLOAD_IP_REASSEMBLY``.

Looking at the patch I see no changes and usage of rte_eth_rxconf and rte_eth_rxmode. It should be added here later if corresponding changes come in subsequent patches.

doc/guides/nics/features.rst Supports inner packet L4 checksum. · line 613

Quoted 1 line
doc/guides/nics/features.rst +1 -0
+* **[provides] mbuf**: ``mbuf.ol_flags:RTE_MBUF_F_RX_IP_REASSEMBLY_INCOMPLETE``

Same here. The flag is not defined yet. So, it must not be mentioned in the patch.
.

Quoted 12 lines
doc/guides/nics/features.rst +3 -0
+* **[provides] rte_eth_dev_info**: ``reass_capa``.
+
+
  .. _nic_features_shared_rx_queue:
 
  Shared Rx queue
lib/ethdev/rte_ethdev.h +0 -0
index fa299c8ad7..11427b2e4d 100644

[snip]

lib/ethdev/rte_ethdev.h enum rte_eth_representor_type { · line 1793

Quoted 13 lines
lib/ethdev/rte_ethdev.h +9 -0
@@ -1781,6 +1782,33 @@ enum rte_eth_representor_type {
  	RTE_ETH_REPRESENTOR_PF,   /**< representor of Physical Function. */
  };
 
+/* Flag to offload IP reassembly for IPv4 packets. */
+#define RTE_ETH_DEV_REASSEMBLY_F_IPV4 (RTE_BIT32(0))
+/* Flag to offload IP reassembly for IPv6 packets. */
+#define RTE_ETH_DEV_REASSEMBLY_F_IPV6 (RTE_BIT32(1))
+/**
+ * @warning
+ * @b EXPERIMENTAL: this structure may change without prior notice.
+ *
+ * A structure used to set IP reassembly configuration.

In the patch the structure is used to provide capabilities, not to set configuration.

If you are going to use the same structure in capabilities and configuration, it could be handy, but really confusing since interpretation of fields should be different.
As a bare minimum the difference must be specified in comments. Right now all fields makes sense in capabilities and configuration:
maximum possible vs actual value, however, not everything could be really configurable and it will become confusing. It is really hard to discuss right now since the patch does not provide usage of the structure for the configuration.

lib/ethdev/rte_ethdev.h enum rte_eth_representor_type { · line 1802

Quoted 9 lines
lib/ethdev/rte_ethdev.h +9 -0
+ *
+ * If RTE_ETH_RX_OFFLOAD_IP_REASSEMBLY flag is set in offloads field,
+ * the PMD will attempt IP reassembly for the received packets as per
+ * properties defined in this structure:
+ *
+ */
+struct rte_eth_ip_reass_params {
+	/** Maximum time in ms which PMD can wait for other fragments. */
+	uint32_t reass_timeout;

Please, specify units. May be even in field name. E.g. reass_timeout_ms.

lib/ethdev/rte_ethdev.h enum rte_eth_representor_type { · line 1809

Quoted 7 lines
lib/ethdev/rte_ethdev.h +7 -0
+	/** Maximum number of fragments that can be reassembled. */
+	uint16_t max_frags;
+	/**
+	 * Flags to enable reassembly of packet types -
+	 * RTE_ETH_DEV_REASSEMBLY_F_xxx.
+	 */
+	uint16_t flags;

If it is just for packet types, I'd suggest to name the field more precise. Also it will avoid flags vs frags misreading. Just an idea. Up to you.

Quoted 17 lines
lib/ethdev/rte_ethdev.h +5 -1
+};
+
  /**
   * A structure used to retrieve the contextual information of
   * an Ethernet device, such as the controlling driver of the
@@ -1841,8 +1869,10 @@ struct rte_eth_dev_info {
  	 * embedded managed interconnect/switch.
  	 */
  	struct rte_eth_switch_info switch_info;
+	/** IP reassembly offload capabilities that a device can support. */
+	struct rte_eth_ip_reass_params reass_capa;
 
-	uint64_t reserved_64s[2]; /**< Reserved for future fields */
+	uint64_t reserved_64s[1]; /**< Reserved for future fields */
  	void *reserved_ptrs[2];   /**< Reserved for future fields */
  };
 
#15 lore raw

RE: [EXT] Re: [PATCH 1/8] ethdev: introduce IP reassembly offload

Hi Andrew,
Thanks for the review.

Quoted 11 lines · Akhil Goyal
Quoted 5 lines

IP Reassembly is a costly operation if it is done in software.
The operation becomes even more costlier if IP fragmants are encrypted. However, if it is offloaded to HW, it can considerably save application cycles.

Hence, a new offload RTE_ETH_RX_OFFLOAD_IP_REASSEMBLY is introduced

in

Quoted 3 lines

ethdev for devices which can attempt reassembly of packets in hardware. rte_eth_dev_info is updated with the reassembly capabilities which a device can support.

Quoted 7 lines

Yes, reassembly is really complicated process taking possibility to have overlapping fragments, out-of-order etc.
There are network attacks based on IP reassembly.
Will it simply result in IP reassembly failure if no buffers are left for IP fragments? What will be reported in mbuf if some packets overlap? Just raw packets as is or reassembly result with holes?
I think behavour should be specified/

The PMD will set the reassembly incomplete dynflag and the user can retrieve the Mbufs using dynfields. This is shown in v2 of the patchset and a test app is also added To cover this negative case.

Quoted 39 lines
Quoted 20 lines

The resulting reassembled packet would be a typical segmented mbuf in case of success.

And if reassembly of fragments is failed or is incomplete (if fragments do not come before the reass_timeout), the mbuf ol_flags can be updated. This is updated in a subsequent patch.

---
  doc/guides/nics/features.rst | 12 ++++++++++++
  lib/ethdev/rte_ethdev.c      |  1 +
  lib/ethdev/rte_ethdev.h      | 32 +++++++++++++++++++++++++++++++-
  3 files changed, 44 insertions(+), 1 deletion(-)
doc/guides/nics/features.rst +0 -0
index 27be2d2576..1dfdee9602 100644

doc/guides/nics/features.rst Supports inner packet L4 checksum. · line 602

Quoted 1 line
doc/guides/nics/features.rst +0 -0
@@ -602,6 +602,18 @@ Supports inner packet L4 checksum.
 

``tx_offload_capa,tx_queue_offload_capa:RTE_ETH_TX_OFFLOAD_OUTER_UD P_CKSUM``.

doc/guides/nics/features.rst Supports inner packet L4 checksum.

Quoted 10 lines
doc/guides/nics/features.rst +8 -0
+.. _nic_features_ip_reassembly:
+
+IP reassembly
+-------------
+
+Supports IP reassembly in hardware.
+
+* **[uses]     rte_eth_rxconf,rte_eth_rxmode**:

``offloads:RTE_ETH_RX_OFFLOAD_IP_REASSEMBLY``.

Looking at the patch I see no changes and usage of rte_eth_rxconf and rte_eth_rxmode. It should be added here later if corresponding changes come in subsequent patches.

Quoted 6 lines

doc/guides/nics/features.rst Supports inner packet L4 checksum. · line 611

Quoted 1 line
doc/guides/nics/features.rst +1 -0
+* **[provides] mbuf**:

``mbuf.ol_flags:RTE_MBUF_F_RX_IP_REASSEMBLY_INCOMPLETE``

Same here. The flag is not defined yet. So, it must not be mentioned in the patch.
.

Ok

Quoted 32 lines
Quoted 12 lines
doc/guides/nics/features.rst +3 -0
+* **[provides] rte_eth_dev_info**: ``reass_capa``.
+
+
  .. _nic_features_shared_rx_queue:
 
  Shared Rx queue
 
 
lib/ethdev/rte_ethdev.h +0 -0
index fa299c8ad7..11427b2e4d 100644

[snip]

lib/ethdev/rte_ethdev.h enum rte_eth_representor_type { · line 1793

Quoted 13 lines
lib/ethdev/rte_ethdev.h +9 -0
@@ -1781,6 +1782,33 @@ enum rte_eth_representor_type {
  	RTE_ETH_REPRESENTOR_PF,   /**< representor of Physical Function. */
  };
 
+/* Flag to offload IP reassembly for IPv4 packets. */
+#define RTE_ETH_DEV_REASSEMBLY_F_IPV4 (RTE_BIT32(0))
+/* Flag to offload IP reassembly for IPv6 packets. */
+#define RTE_ETH_DEV_REASSEMBLY_F_IPV6 (RTE_BIT32(1))
+/**
+ * @warning
+ * @b EXPERIMENTAL: this structure may change without prior notice.
+ *
+ * A structure used to set IP reassembly configuration.

In the patch the structure is used to provide capabilities, not to set configuration.

Quoted 9 lines

If you are going to use the same structure in capabilities and configuration, it could be handy, but really confusing since interpretation of fields should be different.
As a bare minimum the difference must be specified in comments. Right now all fields makes sense in capabilities and configuration:
maximum possible vs actual value, however, not everything could be really configurable and it will become confusing. It is really hard to discuss right now since the patch does not provide usage of the structure for the configuration.

The idea is to use it both for capabilities as well as configuration of those values. And from library perspective not creating any limitation about which param can Be configured which cannot be configured.
However will add a comment to specify both usage.
Could you please check v2 and test app for the usage?

Quoted 12 lines

lib/ethdev/rte_ethdev.h enum rte_eth_representor_type { · line 1802

Quoted 10 lines
lib/ethdev/rte_ethdev.h +9 -0
+ *
+ * If RTE_ETH_RX_OFFLOAD_IP_REASSEMBLY flag is set in offloads field,
+ * the PMD will attempt IP reassembly for the received packets as per
+ * properties defined in this structure:
+ *
+ */
+struct rte_eth_ip_reass_params {
+	/** Maximum time in ms which PMD can wait for other fragments. */
+	uint32_t reass_timeout;

Please, specify units. May be even in field name. E.g. reass_timeout_ms.

Ok

Quoted 12 lines

lib/ethdev/rte_ethdev.h enum rte_eth_representor_type { · line 1809

Quoted 8 lines
lib/ethdev/rte_ethdev.h +7 -0
+	/** Maximum number of fragments that can be reassembled. */
+	uint16_t max_frags;
+	/**
+	 * Flags to enable reassembly of packet types -
+	 * RTE_ETH_DEV_REASSEMBLY_F_xxx.
+	 */
+	uint16_t flags;

If it is just for packet types, I'd suggest to name the field more precise. Also it will avoid flags vs frags misreading. Just an idea. Up to you.

Currently it is for packet type, but it can be extended for further usage in future. Hence thought of making it generic - flags.
What do you suggest? How about renaming it to 'options'?

Regards,
Akhil

#16 lore raw

PATCH 2/8 ethdev: add dev op for IP reassembly configuration

In reply to Akhil Goyal

A new ethernet device op is added to give application control over the IP reassembly configuration. This operation is an optional call from the application, default values are set by PMD and exposed via rte_eth_dev_info.
Application should always first retreive the capabilities from rte_eth_dev_info and then set the fields accordingly.

---
 lib/ethdev/ethdev_driver.h | 19 +++++++++++++++++++
 lib/ethdev/rte_ethdev.c    | 30 ++++++++++++++++++++++++++++++
 lib/ethdev/rte_ethdev.h    | 28 ++++++++++++++++++++++++++++
 lib/ethdev/version.map     |  3 +++
 4 files changed, 80 insertions(+)
lib/ethdev/ethdev_driver.h +19 -0
index d95605a355..0ed53c14f3 100644
@@ -990,6 +990,22 @@ typedef int (*eth_representor_info_get_t)(struct rte_eth_dev *dev,
 typedef int (*eth_rx_metadata_negotiate_t)(struct rte_eth_dev *dev,
 				       uint64_t *features);
 
+/**
+ * @internal
+ * Set configuration parameters for enabling IP reassembly offload in hardware.
+ *
+ * @param dev
+ *   Port (ethdev) handle
+ *
+ * @param[in] conf
+ *   Configuration parameters for IP reassembly.
+ *
+ * @return
+ *   Negative errno value on error, zero otherwise
+ */
+typedef int (*eth_ip_reassembly_conf_set_t)(struct rte_eth_dev *dev,
+				       struct rte_eth_ip_reass_params *conf);
+
 /**
  * @internal A structure containing the functions exported by an Ethernet driver.
  */
@@ -1186,6 +1202,9 @@ struct eth_dev_ops {
 	 * kinds of metadata to the PMD
 	 */
 	eth_rx_metadata_negotiate_t rx_metadata_negotiate;
+
+	/** Set IP reassembly configuration */
+	eth_ip_reassembly_conf_set_t ip_reassembly_conf_set;
 };
 
 /**
lib/ethdev/rte_ethdev.c +30 -0
index d9a03f12f9..ecc6c1fe37 100644
@@ -6473,6 +6473,36 @@ rte_eth_rx_metadata_negotiate(uint16_t port_id, uint64_t *features)
 		       (*dev->dev_ops->rx_metadata_negotiate)(dev, features));
 }
 
+int
+rte_eth_ip_reassembly_conf_set(uint16_t port_id,
+			       struct rte_eth_ip_reass_params *conf)
+{
+	struct rte_eth_dev *dev;
+
+	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+	dev = &rte_eth_devices[port_id];
+
+	if ((dev->data->dev_conf.rxmode.offloads &
+			RTE_ETH_RX_OFFLOAD_IP_REASSEMBLY) == 0) {
+		RTE_ETHDEV_LOG(ERR,
+			"The port (ID=%"PRIu16") is not configured for IP reassembly\n",
+			port_id);
+		return -EINVAL;
+	}
+
+
+	if (conf == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+				"Invalid IP reassembly configuration (NULL)\n");
+		return -EINVAL;
+	}
+
+	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->ip_reassembly_conf_set,
+				-ENOTSUP);
+	return eth_err(port_id,
+		       (*dev->dev_ops->ip_reassembly_conf_set)(dev, conf));
+}
+
 RTE_LOG_REGISTER_DEFAULT(rte_eth_dev_logtype, INFO);
 
 RTE_INIT(ethdev_init_telemetry)
lib/ethdev/rte_ethdev.h +28 -0
index 11427b2e4d..891f9a6e06 100644
@@ -5218,6 +5218,34 @@ int rte_eth_representor_info_get(uint16_t port_id,
 __rte_experimental
 int rte_eth_rx_metadata_negotiate(uint16_t port_id, uint64_t *features);
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice
+ *
+ * Set IP reassembly configuration parameters if device rx offload
+ * flag (RTE_ETH_RX_OFFLOAD_IP_REASSEMBLY) is enabled and the PMD
+ * supports IP reassembly offload. User should first check the
+ * reass_capa in rte_eth_dev_info before setting the configuration.
+ * The values of configuration parameters must not exceed the device
+ * capabilities. The use of this API is optional and if called, it
+ * should be called before rte_eth_dev_start().
+ *
+ * @param port_id
+ *   The port identifier of the device.
+ * @param conf
+ *   A pointer to rte_eth_ip_reass_params structure.
+ * @return
+ *   - (-ENOTSUP) if offload configuration is not supported by device.
+ *   - (-EINVAL) if offload is not enabled in rte_eth_conf.
+ *   - (-ENODEV) if *port_id* invalid.
+ *   - (-EIO) if device is removed.
+ *   - (0) on success.
+ */
+__rte_experimental
+int rte_eth_ip_reassembly_conf_set(uint16_t port_id,
+				   struct rte_eth_ip_reass_params *conf);
+
+
 #include <rte_ethdev_core.h>
 
 /**
lib/ethdev/version.map +3 -0
index c2fb0669a4..f08fe72044 100644
@@ -256,6 +256,9 @@ EXPERIMENTAL {
 	rte_flow_flex_item_create;
 	rte_flow_flex_item_release;
 	rte_flow_pick_transfer_proxy;
+
+	#added in 22.03
+	rte_eth_ip_reassembly_conf_set;
 };
 
 INTERNAL {
Signature · 1 line
2.25.1
#17 lore raw

RE: [PATCH 2/8] ethdev: add dev op for IP reassembly configuration

Quoted 60 lines

A new ethernet device op is added to give application control over the IP reassembly configuration. This operation is an optional call from the application, default values are set by PMD and exposed via rte_eth_dev_info.
Application should always first retreive the capabilities from rte_eth_dev_info and then set the fields accordingly.

---
 lib/ethdev/ethdev_driver.h | 19 +++++++++++++++++++
 lib/ethdev/rte_ethdev.c    | 30 ++++++++++++++++++++++++++++++
 lib/ethdev/rte_ethdev.h    | 28 ++++++++++++++++++++++++++++
 lib/ethdev/version.map     |  3 +++
 4 files changed, 80 insertions(+)
lib/ethdev/ethdev_driver.h +19 -0
index d95605a355..0ed53c14f3 100644
@@ -990,6 +990,22 @@ typedef int (*eth_representor_info_get_t)(struct rte_eth_dev *dev,
 typedef int (*eth_rx_metadata_negotiate_t)(struct rte_eth_dev *dev,
 				       uint64_t *features);
 
+/**
+ * @internal
+ * Set configuration parameters for enabling IP reassembly offload in hardware.
+ *
+ * @param dev
+ *   Port (ethdev) handle
+ *
+ * @param[in] conf
+ *   Configuration parameters for IP reassembly.
+ *
+ * @return
+ *   Negative errno value on error, zero otherwise
+ */
+typedef int (*eth_ip_reassembly_conf_set_t)(struct rte_eth_dev *dev,
+				       struct rte_eth_ip_reass_params *conf);
+
 /**
  * @internal A structure containing the functions exported by an Ethernet driver.
  */
@@ -1186,6 +1202,9 @@ struct eth_dev_ops {
 	 * kinds of metadata to the PMD
 	 */
 	eth_rx_metadata_negotiate_t rx_metadata_negotiate;
+
+	/** Set IP reassembly configuration */
+	eth_ip_reassembly_conf_set_t ip_reassembly_conf_set;
 };
 
 /**
lib/ethdev/rte_ethdev.c +0 -0
index d9a03f12f9..ecc6c1fe37 100644
@@ -6473,6 +6473,36 @@ rte_eth_rx_metadata_negotiate(uint16_t port_id, uint64_t *features)
 		       (*dev->dev_ops->rx_metadata_negotiate)(dev, features));

lib/ethdev/rte_ethdev.c rte_eth_rx_metadata_negotiate(uint16_t port_id, uint64_t *features) · line 6483

Quoted 10 lines
lib/ethdev/rte_ethdev.c +8 -0
 }
 
+int
+rte_eth_ip_reassembly_conf_set(uint16_t port_id,
+			       struct rte_eth_ip_reass_params *conf)
+{
+	struct rte_eth_dev *dev;
+
+	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+	dev = &rte_eth_devices[port_id];

Should we check here that device is properly configured, but not started yet? Another question - if we have reassembly_conf_set() would it make sense to have also reassembly_conf_get?
So user can retrieve current ip_reassembly config values?

Quoted 25 lines
lib/ethdev/rte_ethdev.c +22 -0
+
+	if ((dev->data->dev_conf.rxmode.offloads &
+			RTE_ETH_RX_OFFLOAD_IP_REASSEMBLY) == 0) {
+		RTE_ETHDEV_LOG(ERR,
+			"The port (ID=%"PRIu16") is not configured for IP reassembly\n",
+			port_id);
+		return -EINVAL;
+	}
+
+
+	if (conf == NULL) {
+		RTE_ETHDEV_LOG(ERR,
+				"Invalid IP reassembly configuration (NULL)\n");
+		return -EINVAL;
+	}
+
+	RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->ip_reassembly_conf_set,
+				-ENOTSUP);
+	return eth_err(port_id,
+		       (*dev->dev_ops->ip_reassembly_conf_set)(dev, conf));
+}
+
 RTE_LOG_REGISTER_DEFAULT(rte_eth_dev_logtype, INFO);
 
 RTE_INIT(ethdev_init_telemetry)
#18 lore raw

RE: [PATCH 2/8] ethdev: add dev op for IP reassembly configuration

Quoted 9 lines

lib/ethdev/rte_ethdev.c rte_eth_rx_metadata_negotiate(uint16_t port_id,

Quoted 5 lines
lib/ethdev/rte_ethdev.c +0 -0
index d9a03f12f9..ecc6c1fe37 100644
@@ -6473,6 +6473,36 @@ rte_eth_rx_metadata_negotiate(uint16_t port_id,

uint64_t *features)

Quoted 3 lines
lib/ethdev/rte_ethdev.c +0 -0
 		       (*dev->dev_ops->rx_metadata_negotiate)(dev, features));
 }
 
Quoted 10 lines

lib/ethdev/rte_ethdev.c rte_eth_rx_metadata_negotiate(uint16_t port_id, uint64_t *features) · line 6483

Quoted 8 lines
lib/ethdev/rte_ethdev.c +8 -0
+int
+rte_eth_ip_reassembly_conf_set(uint16_t port_id,
+			       struct rte_eth_ip_reass_params *conf)
+{
+	struct rte_eth_dev *dev;
+
+	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+	dev = &rte_eth_devices[port_id];

Should we check here that device is properly configured, but not started yet?

Ok will add checks for dev->data->dev_configured and dev->data->dev_started

Quoted 4 lines

Another question - if we have reassembly_conf_set() would it make sense to have also reassembly_conf_get?
So user can retrieve current ip_reassembly config values?

The set/supported values can be retrieved using rte_eth_dev_info :: reass_capa

#19 lore raw

RE: [PATCH 2/8] ethdev: add dev op for IP reassembly configuration

Quoted 21 lines
Quoted 11 lines

lib/ethdev/rte_ethdev.c rte_eth_rx_metadata_negotiate(uint16_t port_id,

Quoted 7 lines
lib/ethdev/rte_ethdev.c +0 -0
index d9a03f12f9..ecc6c1fe37 100644
@@ -6473,6 +6473,36 @@ rte_eth_rx_metadata_negotiate(uint16_t port_id,

uint64_t *features)

Quoted 3 lines
lib/ethdev/rte_ethdev.c +0 -0
 		       (*dev->dev_ops->rx_metadata_negotiate)(dev, features));
 }
 
Quoted 10 lines

lib/ethdev/rte_ethdev.c rte_eth_rx_metadata_negotiate(uint16_t port_id, uint64_t *features) · line 6483

Quoted 8 lines
lib/ethdev/rte_ethdev.c +8 -0
+int
+rte_eth_ip_reassembly_conf_set(uint16_t port_id,
+			       struct rte_eth_ip_reass_params *conf)
+{
+	struct rte_eth_dev *dev;
+
+	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+	dev = &rte_eth_devices[port_id];

Should we check here that device is properly configured, but not started yet?

Quoted 7 lines

Ok will add checks for dev->data->dev_configured and dev->data->dev_started

Quoted 4 lines

Another question - if we have reassembly_conf_set() would it make sense to have also reassembly_conf_get?
So user can retrieve current ip_reassembly config values?

The set/supported values can be retrieved using rte_eth_dev_info :: reass_capa

Hmm, I thought rte_eth_dev_info :: reass_capa reports max supported values, not currently set values. Did I misunderstand something?

#20 lore raw

RE: [PATCH 2/8] ethdev: add dev op for IP reassembly configuration

Quoted 11 lines
Quoted 5 lines
Quoted 4 lines

Another question - if we have reassembly_conf_set() would it make sense to have also reassembly_conf_get?
So user can retrieve current ip_reassembly config values?

The set/supported values can be retrieved using rte_eth_dev_info ::

reass_capa

Hmm, I thought rte_eth_dev_info :: reass_capa reports max supported values, not currently set values. Did I misunderstand something?

Reassembly configuration is expected to be a one-time setting and is not expected to change multiple times in the application.
You are correct that rte_eth_dev_info :: reass_capa reports max supported values by the PMD.
But if somebody uses the _set API, dev_info values will be overwritten. However, a get API can be added, if we have some use case.
IMO, we can add it later if it will be required.

#21 lore raw

RE: [PATCH 2/8] ethdev: add dev op for IP reassembly configuration

Quoted 13 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Another question - if we have reassembly_conf_set() would it make sense to have also reassembly_conf_get?
So user can retrieve current ip_reassembly config values?

Quoted 7 lines
Quoted 1 line

The set/supported values can be retrieved using rte_eth_dev_info ::

reass_capa

Hmm, I thought rte_eth_dev_info :: reass_capa reports max supported values, not currently set values. Did I misunderstand something?

Quoted 7 lines

Reassembly configuration is expected to be a one-time setting and is not expected to change multiple times in the application.
You are correct that rte_eth_dev_info :: reass_capa reports max supported values by the PMD.
But if somebody uses the _set API, dev_info values will be overwritten. However, a get API can be added, if we have some use case.
IMO, we can add it later if it will be required.

Basically you forbid user to reconfigure this feature during application life-time?
That sounds like a really strange approach to me and Probably will affect its usability in a negative way. Wonder why it has to be that restrictive?
Also with the model you suggest, what would happen after user will do:
dev_stop(); dev_configure();?
Would rte_eth_dev_info :: reass_capa be reset to initial values, or user values will be preserved, or ...?

#22 lore raw

RE: [PATCH 2/8] ethdev: add dev op for IP reassembly configuration

Quoted 22 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Another question - if we have reassembly_conf_set() would it make sense

to

Quoted 11 lines
Quoted 10 lines
Quoted 4 lines
Quoted 3 lines

have also reassembly_conf_get?
So user can retrieve current ip_reassembly config values?

The set/supported values can be retrieved using rte_eth_dev_info ::

reass_capa

Hmm, I thought rte_eth_dev_info :: reass_capa reports max supported values, not currently set values. Did I misunderstand something?

Reassembly configuration is expected to be a one-time setting and is not

expected

Quoted 2 lines

to change multiple times in the application.
You are correct that rte_eth_dev_info :: reass_capa reports max supported

values

Quoted 4 lines

by the PMD.
But if somebody uses the _set API, dev_info values will be overwritten. However, a get API can be added, if we have some use case. IMO, we can add it later if it will be required.

Quoted 10 lines

Basically you forbid user to reconfigure this feature during application life-time?
That sounds like a really strange approach to me and Probably will affect its usability in a negative way. Wonder why it has to be that restrictive?
Also with the model you suggest, what would happen after user will do:
dev_stop(); dev_configure();?
Would rte_eth_dev_info :: reass_capa be reset to initial values, or user values will be preserved, or ...?

I am not restricting the user to not reconfigure the feature.
When dev_configure() is called again after dev_stop(), it will reset the previously set values to max ones.
However, if you insist the get API can be added. No strong opinion on that.

#23 lore raw

RE: [PATCH 2/8] ethdev: add dev op for IP reassembly configuration

Hi Konstantin,

Quoted 33 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Another question - if we have reassembly_conf_set() would it make

sense

Quoted 21 lines

to

Quoted 11 lines
Quoted 10 lines
Quoted 4 lines
Quoted 3 lines

have also reassembly_conf_get?
So user can retrieve current ip_reassembly config values?

The set/supported values can be retrieved using rte_eth_dev_info ::

reass_capa

Hmm, I thought rte_eth_dev_info :: reass_capa reports max supported values, not currently set values. Did I misunderstand something?

Reassembly configuration is expected to be a one-time setting and is not

expected

Quoted 2 lines

to change multiple times in the application.
You are correct that rte_eth_dev_info :: reass_capa reports max supported

values

Quoted 4 lines

by the PMD.
But if somebody uses the _set API, dev_info values will be overwritten. However, a get API can be added, if we have some use case. IMO, we can add it later if it will be required.

Quoted 10 lines

Basically you forbid user to reconfigure this feature during application life-time?
That sounds like a really strange approach to me and Probably will affect its usability in a negative way. Wonder why it has to be that restrictive?
Also with the model you suggest, what would happen after user will do:
dev_stop(); dev_configure();?
Would rte_eth_dev_info :: reass_capa be reset to initial values, or user values will be preserved, or ...?

Quoted 4 lines

I am not restricting the user to not reconfigure the feature.
When dev_configure() is called again after dev_stop(), it will reset the previously set values to max ones.
However, if you insist the get API can be added. No strong opinion on that.

On another thought, setting dev_info :: reass_capa to a max value and not changing it in reassembly_conf_set() will make more sense.
The most common case, would be to get the max values and if they are not good Enough for the application, set lesser values using the new API.
I do not see a use case to get the current values set. However, it may be used for debugging some driver issue related to these values. But, I believe that can be managed internally in the PMD. Do you suspect any other use case for get API?

#24 lore raw

RE: [PATCH 2/8] ethdev: add dev op for IP reassembly configuration

Quoted 35 lines
Quoted 35 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Another question - if we have reassembly_conf_set() would it make

sense

Quoted 31 lines

to

Quoted 11 lines
Quoted 10 lines
Quoted 4 lines
Quoted 3 lines

have also reassembly_conf_get?
So user can retrieve current ip_reassembly config values?

The set/supported values can be retrieved using rte_eth_dev_info ::

reass_capa

Hmm, I thought rte_eth_dev_info :: reass_capa reports max supported values, not currently set values. Did I misunderstand something?

Reassembly configuration is expected to be a one-time setting and is not

expected

Quoted 2 lines

to change multiple times in the application.
You are correct that rte_eth_dev_info :: reass_capa reports max supported

values

Quoted 4 lines

by the PMD.
But if somebody uses the _set API, dev_info values will be overwritten. However, a get API can be added, if we have some use case. IMO, we can add it later if it will be required.

Basically you forbid user to reconfigure this feature during application life-time?
That sounds like a really strange approach to me and Probably will affect its usability in a negative way. Wonder why it has to be that restrictive?
Also with the model you suggest, what would happen after user will do:
dev_stop(); dev_configure();?
Would rte_eth_dev_info :: reass_capa be reset to initial values, or user values will be preserved, or ...?

Quoted 7 lines
Quoted 4 lines

I am not restricting the user to not reconfigure the feature.
When dev_configure() is called again after dev_stop(), it will reset the previously set values to max ones.
However, if you insist the get API can be added. No strong opinion on that.

On another thought, setting dev_info :: reass_capa to a max value and not changing it in reassembly_conf_set() will make more sense.

Yes, agree.

Quoted 5 lines

The most common case, would be to get the max values and if they are not good Enough for the application, set lesser values using the new API.
I do not see a use case to get the current values set. However, it may be used for debugging some driver issue related to these values. But, I believe that can be managed internally in the PMD. Do you suspect any other use case for get API?

I think it would be really plausible for both user and ethdev layer to have an ability to get values that are currently in place.

#25 lore raw

PATCH 3/8 ethdev: add mbuf dynfield for incomplete IP reassembly

In reply to Akhil Goyal

Hardware IP reassembly may be incomplete for multiple reasons like reassembly timeout reached, duplicate fragments, etc. To save application cycles to process these packets again, a new mbuf ol_flag (RTE_MBUF_F_RX_IPREASSEMBLY_INCOMPLETE) is added to show that the mbuf received is not reassembled properly.

Now if this flag is set, application can retreive corresponding chain of mbufs using mbuf dynfield set by the PMD. Now, it will be upto application to either drop those fragments or wait for more time.

---
 lib/ethdev/ethdev_driver.h |  8 ++++++
 lib/ethdev/rte_ethdev.c    | 16 +++++++++++
 lib/ethdev/rte_ethdev.h    | 57 ++++++++++++++++++++++++++++++++++++++
 lib/ethdev/version.map     |  2 ++
 lib/mbuf/rte_mbuf_core.h   |  3 +-
 5 files changed, 85 insertions(+), 1 deletion(-)
lib/ethdev/ethdev_driver.h +8 -0
index 0ed53c14f3..9a0bab9a61 100644
@@ -1671,6 +1671,14 @@ int
 rte_eth_hairpin_queue_peer_unbind(uint16_t cur_port, uint16_t cur_queue,
 				  uint32_t direction);
 
+/**
+ * @internal
+ * Register mbuf dynamic field for IP reassembly incomplete case.
+ */
+__rte_internal
+int
+rte_eth_ip_reass_dynfield_register(void);
+
 
 /*
  * Legacy ethdev API used internally by drivers.
lib/ethdev/rte_ethdev.c +16 -0
index ecc6c1fe37..d53ce4eaca 100644
@@ -6503,6 +6503,22 @@ rte_eth_ip_reassembly_conf_set(uint16_t port_id,
 		       (*dev->dev_ops->ip_reassembly_conf_set)(dev, conf));
 }
 
+#define RTE_ETH_IP_REASS_DYNFIELD_NAME "rte_eth_ip_reass_dynfield"
+int rte_eth_ip_reass_dynfield_offset = -1;
+
+int
+rte_eth_ip_reass_dynfield_register(void)
+{
+	static const struct rte_mbuf_dynfield dynfield_desc = {
+		.name = RTE_ETH_IP_REASS_DYNFIELD_NAME,
+		.size = sizeof(rte_eth_ip_reass_dynfield_t),
+		.align = __alignof__(rte_eth_ip_reass_dynfield_t),
+	};
+	rte_eth_ip_reass_dynfield_offset =
+		rte_mbuf_dynfield_register(&dynfield_desc);
+	return rte_eth_ip_reass_dynfield_offset;
+}
+
 RTE_LOG_REGISTER_DEFAULT(rte_eth_dev_logtype, INFO);
 
 RTE_INIT(ethdev_init_telemetry)
lib/ethdev/rte_ethdev.h +57 -0

63 lines not on this page · raw message

lib/ethdev/version.map +2 -0
index f08fe72044..e824b776b1 100644
@@ -259,6 +259,7 @@ EXPERIMENTAL {
 
 	#added in 22.03
 	rte_eth_ip_reassembly_conf_set;
+	rte_eth_ip_reass_dynfield_offset;
 };
 
 INTERNAL {
@@ -282,6 +283,7 @@ INTERNAL {
 	rte_eth_hairpin_queue_peer_bind;
 	rte_eth_hairpin_queue_peer_unbind;
 	rte_eth_hairpin_queue_peer_update;
+	rte_eth_ip_reass_dynfield_register;
 	rte_eth_representor_id_get;
 	rte_eth_switch_domain_alloc;
 	rte_eth_switch_domain_free;
lib/mbuf/rte_mbuf_core.h +2 -1
index 321a419c71..2cd1f95ae4 100644
@@ -233,10 +233,11 @@ extern "C" {
 #define PKT_RX_OUTER_L4_CKSUM_INVALID \
 	RTE_DEPRECATED(PKT_RX_OUTER_L4_CKSUM_INVALID) \
 	RTE_MBUF_F_RX_OUTER_L4_CKSUM_INVALID
+#define RTE_MBUF_F_RX_IPREASSEMBLY_INCOMPLETE   (1ULL << 23)
 
 /* add new RX flags here, don't forget to update RTE_MBUF_F_FIRST_FREE */
 
-#define RTE_MBUF_F_FIRST_FREE (1ULL << 23)
+#define RTE_MBUF_F_FIRST_FREE (1ULL << 24)
 #define PKT_FIRST_FREE RTE_DEPRECATED(PKT_FIRST_FREE) RTE_MBUF_F_FIRST_FREE
 #define RTE_MBUF_F_LAST_FREE (1ULL << 40)
 #define PKT_LAST_FREE RTE_DEPRECATED(PKT_LAST_FREE) RTE_MBUF_F_LAST_FREE
Signature · 1 line
2.25.1
#26 lore raw

RE: [PATCH 3/8] ethdev: add mbuf dynfield for incomplete IP reassembly

Quoted 6 lines

Hardware IP reassembly may be incomplete for multiple reasons like reassembly timeout reached, duplicate fragments, etc. To save application cycles to process these packets again, a new mbuf ol_flag (RTE_MBUF_F_RX_IPREASSEMBLY_INCOMPLETE) is added to show that the mbuf received is not reassembled properly.

If we use dynfiled for data, why not use dynflag for RTE_MBUF_F_RX_IPREASSEMBLY_INCOMPLETE? That way we can avoid introduced hardcoded (always defined) flags for that case.

Quoted 75 lines

Now if this flag is set, application can retreive corresponding chain of mbufs using mbuf dynfield set by the PMD. Now, it will be upto application to either drop those fragments or wait for more time.

---
 lib/ethdev/ethdev_driver.h |  8 ++++++
 lib/ethdev/rte_ethdev.c    | 16 +++++++++++
 lib/ethdev/rte_ethdev.h    | 57 ++++++++++++++++++++++++++++++++++++++
 lib/ethdev/version.map     |  2 ++
 lib/mbuf/rte_mbuf_core.h   |  3 +-
 5 files changed, 85 insertions(+), 1 deletion(-)
lib/ethdev/ethdev_driver.h +8 -0
index 0ed53c14f3..9a0bab9a61 100644
@@ -1671,6 +1671,14 @@ int
 rte_eth_hairpin_queue_peer_unbind(uint16_t cur_port, uint16_t cur_queue,
 				  uint32_t direction);
 
+/**
+ * @internal
+ * Register mbuf dynamic field for IP reassembly incomplete case.
+ */
+__rte_internal
+int
+rte_eth_ip_reass_dynfield_register(void);
+
 
 /*
  * Legacy ethdev API used internally by drivers.
lib/ethdev/rte_ethdev.c +16 -0
index ecc6c1fe37..d53ce4eaca 100644
@@ -6503,6 +6503,22 @@ rte_eth_ip_reassembly_conf_set(uint16_t port_id,
 		       (*dev->dev_ops->ip_reassembly_conf_set)(dev, conf));
 }
 
+#define RTE_ETH_IP_REASS_DYNFIELD_NAME "rte_eth_ip_reass_dynfield"
+int rte_eth_ip_reass_dynfield_offset = -1;
+
+int
+rte_eth_ip_reass_dynfield_register(void)
+{
+	static const struct rte_mbuf_dynfield dynfield_desc = {
+		.name = RTE_ETH_IP_REASS_DYNFIELD_NAME,
+		.size = sizeof(rte_eth_ip_reass_dynfield_t),
+		.align = __alignof__(rte_eth_ip_reass_dynfield_t),
+	};
+	rte_eth_ip_reass_dynfield_offset =
+		rte_mbuf_dynfield_register(&dynfield_desc);
+	return rte_eth_ip_reass_dynfield_offset;
+}
+
 RTE_LOG_REGISTER_DEFAULT(rte_eth_dev_logtype, INFO);
 
 RTE_INIT(ethdev_init_telemetry)
lib/ethdev/rte_ethdev.h +7 -0
index 891f9a6e06..c4024d2265 100644
@@ -5245,6 +5245,63 @@ __rte_experimental
 int rte_eth_ip_reassembly_conf_set(uint16_t port_id,
 				   struct rte_eth_ip_reass_params *conf);
 
+/**
+ * In case of IP reassembly offload failure, ol_flags in mbuf will be set
+ * with RTE_MBUF_F_RX_IPREASSEMBLY_INCOMPLETE and packets will be returned
+ * without alteration. The application can retrieve the attached fragments
+ * using mbuf dynamic field.
+ */	
+typedef struct {

lib/ethdev/rte_ethdev.h __rte_experimental · line 5264

Quoted 10 lines
lib/ethdev/rte_ethdev.h +10 -0
+	/**
+	 * Next fragment packet. Application should fetch dynamic field of
+	 * each fragment until a NULL is received and nb_frags is 0.
+	 */
+	struct rte_mbuf *next_frag;
+	/** Time spent(in ms) by HW in waiting for further fragments. */
+	uint16_t time_spent;
+	/** Number of more fragments attached in mbuf dynamic fields. */
+	uint16_t nb_frags;
+} rte_eth_ip_reass_dynfield_t;

Looks like a bit of overkill to me:
We do already have 'next' and 'nb_frags' fields inside mbuf, why can't they be used here? Why a separate ones are necessary?

Quoted 3 lines
lib/ethdev/rte_ethdev.h +3 -0
+
+extern int rte_eth_ip_reass_dynfield_offset;
+
#27 lore raw

RE: [PATCH 3/8] ethdev: add mbuf dynfield for incomplete IP reassembly

Quoted 11 lines
Quoted 6 lines

Hardware IP reassembly may be incomplete for multiple reasons like reassembly timeout reached, duplicate fragments, etc. To save application cycles to process these packets again, a new mbuf ol_flag (RTE_MBUF_F_RX_IPREASSEMBLY_INCOMPLETE) is added to show that the mbuf received is not reassembled properly.

If we use dynfiled for data, why not use dynflag for RTE_MBUF_F_RX_IPREASSEMBLY_INCOMPLETE?
That way we can avoid introduced hardcoded (always defined) flags for that case.

I have not looked into using dynflag. Will explore if it can be used.

Quoted 16 lines
Quoted 4 lines

+/**
+ * In case of IP reassembly offload failure, ol_flags in mbuf will be set
+ * with RTE_MBUF_F_RX_IPREASSEMBLY_INCOMPLETE and packets will be

returned

Quoted 11 lines

+ * without alteration. The application can retrieve the attached fragments
+ * using mbuf dynamic field.
+ */

lib/ethdev/rte_ethdev.h +8 -0
+typedef struct {
+	/**
+	 * Next fragment packet. Application should fetch dynamic field of
+	 * each fragment until a NULL is received and nb_frags is 0.
+	 */
+	struct rte_mbuf *next_frag;
+	/** Time spent(in ms) by HW in waiting for further fragments. */
+	uint16_t time_spent;
Quoted 9 lines

lib/ethdev/rte_ethdev.h __rte_experimental · line 5264

Quoted 3 lines
lib/ethdev/rte_ethdev.h +3 -0
+	/** Number of more fragments attached in mbuf dynamic fields. */
+	uint16_t nb_frags;
+} rte_eth_ip_reass_dynfield_t;

Looks like a bit of overkill to me:
We do already have 'next' and 'nb_frags' fields inside mbuf, why can't they be used here? Why a separate ones are necessary?

The next and nb_frags in mbuf is for segmented buffers and not IP fragments. But here we will have separate mbufs in each dynfield denoting each of the fragments which may have further segmented buffers.

#28 lore raw

RE: [PATCH 3/8] ethdev: add mbuf dynfield for incomplete IP reassembly

Quoted 41 lines
Quoted 8 lines
Quoted 7 lines

Hardware IP reassembly may be incomplete for multiple reasons like reassembly timeout reached, duplicate fragments, etc. To save application cycles to process these packets again, a new mbuf ol_flag (RTE_MBUF_F_RX_IPREASSEMBLY_INCOMPLETE) is added to show that the mbuf received is not reassembled properly.

Quoted 4 lines

If we use dynfiled for data, why not use dynflag for RTE_MBUF_F_RX_IPREASSEMBLY_INCOMPLETE?
That way we can avoid introduced hardcoded (always defined) flags for that case.

I have not looked into using dynflag. Will explore if it can be used.

Quoted 16 lines
Quoted 4 lines

+/**
+ * In case of IP reassembly offload failure, ol_flags in mbuf will be set
+ * with RTE_MBUF_F_RX_IPREASSEMBLY_INCOMPLETE and packets will be

returned

Quoted 11 lines

+ * without alteration. The application can retrieve the attached fragments
+ * using mbuf dynamic field.
+ */

lib/ethdev/rte_ethdev.h +8 -0
+typedef struct {
+	/**
+	 * Next fragment packet. Application should fetch dynamic field of
+	 * each fragment until a NULL is received and nb_frags is 0.
+	 */
+	struct rte_mbuf *next_frag;
+	/** Time spent(in ms) by HW in waiting for further fragments. */
+	uint16_t time_spent;
Quoted 9 lines

lib/ethdev/rte_ethdev.h __rte_experimental · line 5264

Quoted 3 lines
lib/ethdev/rte_ethdev.h +3 -0
+	/** Number of more fragments attached in mbuf dynamic fields. */
+	uint16_t nb_frags;
+} rte_eth_ip_reass_dynfield_t;

Looks like a bit of overkill to me:
We do already have 'next' and 'nb_frags' fields inside mbuf, why can't they be used here? Why a separate ones are necessary?

Quoted 3 lines

The next and nb_frags in mbuf is for segmented buffers and not IP fragments. But here we will have separate mbufs in each dynfield denoting each of the fragments which may have further segmented buffers.

Makes sense, thanks for explanation.
Though in that case just 'struct rte_mbuf *next_frag' might be enough (user will walk though the list till mbuf->next_frag != NULL)?
The reason I am asking: current sizeof(rte_eth_ip_reass_dynfield_t) is 16B, which is quite a lot for mbuf, especially considering that it has to be continuous 16B. Making it smaller (8B) or even splitting into 2 fileds (8+4) will give it more chances to coexist with other dynfields.

#29 lore raw

RE: [PATCH 3/8] ethdev: add mbuf dynfield for incomplete IP reassembly

Quoted 30 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

+/**
+ * In case of IP reassembly offload failure, ol_flags in mbuf will be set
+ * with RTE_MBUF_F_RX_IPREASSEMBLY_INCOMPLETE and packets will

be

Quoted 21 lines
Quoted 12 lines

returned

Quoted 11 lines

+ * without alteration. The application can retrieve the attached fragments
+ * using mbuf dynamic field.
+ */

lib/ethdev/rte_ethdev.h +8 -0
+typedef struct {
+	/**
+	 * Next fragment packet. Application should fetch dynamic field of
+	 * each fragment until a NULL is received and nb_frags is 0.
+	 */
+	struct rte_mbuf *next_frag;
+	/** Time spent(in ms) by HW in waiting for further fragments. */
+	uint16_t time_spent;
Quoted 9 lines

lib/ethdev/rte_ethdev.h __rte_experimental · line 5264

Quoted 3 lines
lib/ethdev/rte_ethdev.h +3 -0
+	/** Number of more fragments attached in mbuf dynamic fields. */
+	uint16_t nb_frags;
+} rte_eth_ip_reass_dynfield_t;

Looks like a bit of overkill to me:
We do already have 'next' and 'nb_frags' fields inside mbuf, why can't they be used here? Why a separate ones are necessary?

Quoted 3 lines

The next and nb_frags in mbuf is for segmented buffers and not IP fragments. But here we will have separate mbufs in each dynfield denoting each of the fragments which may have further segmented buffers.

Quoted 9 lines

Makes sense, thanks for explanation.
Though in that case just 'struct rte_mbuf *next_frag' might be enough (user will walk though the list till mbuf->next_frag != NULL)?
The reason I am asking: current sizeof(rte_eth_ip_reass_dynfield_t) is 16B, which is quite a lot for mbuf, especially considering that it has to be continuous 16B.
Making it smaller (8B) or even splitting into 2 fileds (8+4) will give it more chances
to coexist with other dynfields.

Even if we drop nb_frags, we will be left with uint16_t time_spent. Are you suggesting to use separate dynfield altogether for 2 bytes of time_spent?

#30 lore raw

RE: [PATCH 3/8] ethdev: add mbuf dynfield for incomplete IP reassembly

Quoted 42 lines
Quoted 32 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

+/**
+ * In case of IP reassembly offload failure, ol_flags in mbuf will be set
+ * with RTE_MBUF_F_RX_IPREASSEMBLY_INCOMPLETE and packets will

be

Quoted 21 lines
Quoted 12 lines

returned

Quoted 11 lines

+ * without alteration. The application can retrieve the attached fragments
+ * using mbuf dynamic field.
+ */

lib/ethdev/rte_ethdev.h +8 -0
+typedef struct {
+	/**
+	 * Next fragment packet. Application should fetch dynamic field of
+	 * each fragment until a NULL is received and nb_frags is 0.
+	 */
+	struct rte_mbuf *next_frag;
+	/** Time spent(in ms) by HW in waiting for further fragments. */
+	uint16_t time_spent;
Quoted 9 lines

lib/ethdev/rte_ethdev.h __rte_experimental · line 5264

Quoted 3 lines
lib/ethdev/rte_ethdev.h +3 -0
+	/** Number of more fragments attached in mbuf dynamic fields. */
+	uint16_t nb_frags;
+} rte_eth_ip_reass_dynfield_t;

Looks like a bit of overkill to me:
We do already have 'next' and 'nb_frags' fields inside mbuf, why can't they be used here? Why a separate ones are necessary?

Quoted 3 lines

The next and nb_frags in mbuf is for segmented buffers and not IP fragments. But here we will have separate mbufs in each dynfield denoting each of the fragments which may have further segmented buffers.

Quoted 9 lines

Makes sense, thanks for explanation.
Though in that case just 'struct rte_mbuf *next_frag' might be enough (user will walk though the list till mbuf->next_frag != NULL)?
The reason I am asking: current sizeof(rte_eth_ip_reass_dynfield_t) is 16B, which is quite a lot for mbuf, especially considering that it has to be continuous 16B.
Making it smaller (8B) or even splitting into 2 fileds (8+4) will give it more chances
to coexist with other dynfields.

Quoted 2 lines

Even if we drop nb_frags, we will be left with uint16_t time_spent. Are you suggesting to use separate dynfield altogether for 2 bytes of time_spent?

Yes, that's was my thought - split it into two separate fields, if possible.

#31 lore raw

RE: [PATCH 3/8] ethdev: add mbuf dynfield for incomplete IP reassembly

In reply to Akhil Goyal

Hi Konstantin,

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

Hardware IP reassembly may be incomplete for multiple reasons like reassembly timeout reached, duplicate fragments, etc. To save application cycles to process these packets again, a new mbuf ol_flag (RTE_MBUF_F_RX_IPREASSEMBLY_INCOMPLETE) is added to show that the mbuf received is not reassembled properly.

Quoted 6 lines
Quoted 4 lines

If we use dynfiled for data, why not use dynflag for RTE_MBUF_F_RX_IPREASSEMBLY_INCOMPLETE?
That way we can avoid introduced hardcoded (always defined) flags for that case.

I have not looked into using dynflag. Will explore if it can be used.

The intent of adding this feature is to reduce application cycles for IP reassembly. But if we use dynflag, it will take a lot of cycles to check if dyn flag is set or not. As I understand, it first need to be looked up in a linked list and then checked. And this will be checked for each packet even if there is no reassembly involved.

#32 lore raw

RE: [PATCH 3/8] ethdev: add mbuf dynfield for incomplete IP reassembly

Hi Akhil,

Quoted 12 lines

Hi Konstantin,

Quoted 11 lines
Quoted 10 lines
Quoted 5 lines

Hardware IP reassembly may be incomplete for multiple reasons like reassembly timeout reached, duplicate fragments, etc. To save application cycles to process these packets again, a new mbuf ol_flag (RTE_MBUF_F_RX_IPREASSEMBLY_INCOMPLETE) is added to show that the mbuf received is not reassembled properly.

If we use dynfiled for data, why not use dynflag for RTE_MBUF_F_RX_IPREASSEMBLY_INCOMPLETE?
That way we can avoid introduced hardcoded (always defined) flags for that case.

Quoted 5 lines
Quoted 1 line

I have not looked into using dynflag. Will explore if it can be used.

The intent of adding this feature is to reduce application cycles for IP reassembly. But if we use dynflag, it will take a lot of cycles to check if dyn flag is set or not. As I understand, it first need to be looked up in a linked list and then checked. And this will be checked for each packet even if there is no reassembly involved.

No, I don't think it is correct understanding.
For dyn-flag it is the same approach as for dyn-field.
At init time it selects the bit which will be used and return it'e value to the user. Then user will set/check the at runtime.
So no linking list walks at runtime.
All you missing comparing to hard-coded values: complier optimizations.

#33 lore raw

RE: [PATCH 3/8] ethdev: add mbuf dynfield for incomplete IP reassembly

Quoted 23 lines

Hi Akhil,

Quoted 5 lines

Hi Konstantin,

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Hardware IP reassembly may be incomplete for multiple reasons like reassembly timeout reached, duplicate fragments, etc. To save application cycles to process these packets again, a new mbuf ol_flag (RTE_MBUF_F_RX_IPREASSEMBLY_INCOMPLETE) is added

to

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line

show that the mbuf received is not reassembled properly.

If we use dynfiled for data, why not use dynflag for RTE_MBUF_F_RX_IPREASSEMBLY_INCOMPLETE?
That way we can avoid introduced hardcoded (always defined) flags for

that

Quoted 4 lines
Quoted 3 lines
Quoted 1 line

case.

I have not looked into using dynflag. Will explore if it can be used.

The intent of adding this feature is to reduce application cycles for IP

reassembly.

Quoted 1 line

But if we use dynflag, it will take a lot of cycles to check if dyn flag is set or

not.

Quoted 2 lines

As I understand, it first need to be looked up in a linked list and then checked. And this will be checked for each packet even if there is no reassembly

Quoted 9 lines

involved.

No, I don't think it is correct understanding.
For dyn-flag it is the same approach as for dyn-field.
At init time it selects the bit which will be used and return it'e value to the user. Then user will set/check the at runtime.
So no linking list walks at runtime.
All you missing comparing to hard-coded values: complier optimizations.

Ok, got it. rte_mbuf_dynflag_lookup() need to happen only for the first mbuf. I was checking is_timestamp_enabled() in test-pmd. Didn't see that dynflag was a static variable.
I thought it was happening for each packet.

#34 lore raw

PATCH 4/8 security: add IPsec option for IP reassembly

In reply to Akhil Goyal

A new option is added in IPsec to enable and attempt reassembly of inbound packets.

---
 lib/security/rte_security.h | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
lib/security/rte_security.h +11 -1
index 1228b6c8b1..168b837a82 100644
@@ -264,6 +264,16 @@ struct rte_security_ipsec_sa_options {
 	 */
 	uint32_t l4_csum_enable : 1;
 
+	/** Enable reassembly on incoming packets.
+	 *
+	 * * 1: Enable driver to try reassembly of encrypted IP packets for
+	 *      this SA, if supported by the driver. This feature will work
+	 *      only if rx_offload RTE_ETH_RX_OFFLOAD_IP_REASSEMBLY is set in
+	 *      inline Ethernet device.
+	 * * 0: Disable reassembly of packets (default).
+	 */
+	uint32_t reass_en : 1;
+
 	/** Reserved bit fields for future extension
 	 *
 	 * User should ensure reserved_opts is cleared as it may change in
@@ -271,7 +281,7 @@ struct rte_security_ipsec_sa_options {
 	 *
 	 * Note: Reduce number of bits in reserved_opts for every new option.
 	 */
-	uint32_t reserved_opts : 18;
+	uint32_t reserved_opts : 17;
 };
 
 /** IPSec security association direction */
Signature · 1 line
2.25.1
#35 lore raw

PATCH 5/8 app/test: add unit cases for inline IPsec offload

In reply to Akhil Goyal

A new test suite is added in test app to test inline IPsec protocol offload. In this patch, a couple of predefined plain and cipher test vectors are used to verify the IPsec functionality without the need of external traffic generators. The sent packet is loopbacked onto the same interface which is received and matched with the expected output. The test suite can be updated further with other functional test cases. The testsuite can be run using:
RTE> inline_ipsec_autotest

---
 app/test/meson.build                          |   1 +
 app/test/test_inline_ipsec.c                  | 728 ++++++++++++++++++
 .../test_inline_ipsec_reassembly_vectors.h    | 198 +++++
 3 files changed, 927 insertions(+)
 create mode 100644 app/test/test_inline_ipsec.c
 create mode 100644 app/test/test_inline_ipsec_reassembly_vectors.h
app/test/meson.build +1 -0
index 2b480adfba..9c88240e3f 100644
@@ -74,6 +74,7 @@ test_sources = files(
         'test_hash_readwrite.c',
         'test_hash_perf.c',
         'test_hash_readwrite_lf_perf.c',
+	'test_inline_ipsec.c',
         'test_interrupts.c',
         'test_ipfrag.c',
         'test_ipsec.c',
app/test/test_inline_ipsec.c new file +728 -0

728 lines not on this page · raw message

app/test/test_inline_ipsec_reassembly_vectors.h new file +198 -0

198 lines not on this page · raw message

Signature · 1 line
2.25.1
#36 lore raw

v2 cover app/test: add inline IPsec and reassembly cases

IP reassembly RX offload is introduced in [1].
This patchset is added to test the IP reassembly RX offload and to test other inline IPsec test cases which need to be verified before testing IP reassembly in inline inbound cases.
In this app, plain IP packets(with/without IP fragments) are sent on one interface for outbound processing and then the packets are received back on the same interface using loopback mode. While receiving the packets, the packets are processed for inline inbound IPsec processing and if the packets are fragmented, they will be reassembled before getting received in the driver/app.

v1 of this patchset was sent along with the ethdev changes in [2]. v2 is split so that it can be reviewed separately.

changes in v2:
- added IPsec burst mode case
- updated as per the latest ethdev changes in [1].

[1] http://patches.dpdk.org/project/dpdk/list/?series=21283
[2] http://patches.dpdk.org/project/dpdk/list/?series=21052

Akhil Goyal (4):
app/test: add unit cases for inline IPsec offload app/test: add IP reassembly case with no frags app/test: add IP reassembly cases with multiple fragments app/test: add IP reassembly negative cases

 MAINTAINERS                                   |    2 +-
 app/test/meson.build                          |    1 +
 app/test/test_security_inline_proto.c         | 1299 +++++++++++++++++
 app/test/test_security_inline_proto_vectors.h |  778 ++++++++++
 4 files changed, 2079 insertions(+), 1 deletion(-)
 create mode 100644 app/test/test_security_inline_proto.c
 create mode 100644 app/test/test_security_inline_proto_vectors.h
Signature · 1 line
2.25.1
#37 lore raw

PATCH v2 1/4 app/test: add unit cases for inline IPsec offload

A new test suite is added in test app to test inline IPsec protocol offload. In this patch, a couple of predefined plain and cipher test vectors are used to verify the IPsec functionality without the need of external traffic generators. The sent packet is loopbacked onto the same interface which is received and matched with the expected output. The test suite can be updated further with other functional test cases. The testsuite can be run using:
RTE> inline_ipsec_autotest

---
 MAINTAINERS                                   |   2 +-
 app/test/meson.build                          |   1 +
 app/test/test_security_inline_proto.c         | 758 ++++++++++++++++++
 app/test/test_security_inline_proto_vectors.h | 185 +++++
 4 files changed, 945 insertions(+), 1 deletion(-)
 create mode 100644 app/test/test_security_inline_proto.c
 create mode 100644 app/test/test_security_inline_proto_vectors.h
MAINTAINERS +1 -1
index f46cec0c55..832bff3609 100644
@@ -439,7 +439,7 @@ M: Declan Doherty <[email protected]>
 T: git://dpdk.org/next/dpdk-next-crypto
 F: lib/security/
 F: doc/guides/prog_guide/rte_security.rst
-F: app/test/test_security.c
+F: app/test/test_security*
 
 Compression API - EXPERIMENTAL
 M: Fan Zhang <[email protected]>
app/test/meson.build +1 -0
index 344a609a4d..2161afa7be 100644
@@ -131,6 +131,7 @@ test_sources = files(
         'test_rwlock.c',
         'test_sched.c',
         'test_security.c',
+        'test_security_inline_proto.c',
         'test_service_cores.c',
         'test_spinlock.c',
         'test_stack.c',
app/test/test_security_inline_proto.c new file +758 -0

758 lines not on this page · raw message

app/test/test_security_inline_proto_vectors.h new file +185 -0

185 lines not on this page · raw message

Signature · 1 line
2.25.1
#38 lore raw

PATCH v2 2/4 app/test: add IP reassembly case with no frags

In reply to Akhil Goyal

test_inline_ipsec testsuite is extended to test IP reassembly of inbound fragmented packets. The fragmented packet is sent on an interface which encrypts the packet and then it is loopbacked on the same interface which decrypts the packet and then attempts IP reassembly of the decrypted packets.
In this patch, a case is added for packets without fragmentation to verify the complete path. Other cases are added in subsequent patches.

---
 app/test/test_security_inline_proto.c         | 325 ++++++++++++++++++
 app/test/test_security_inline_proto_vectors.h |   1 +
 2 files changed, 326 insertions(+)
app/test/test_security_inline_proto.c +325 -0
index 4738792cb8..9dc083369a 100644
@@ -25,6 +25,8 @@
 #define RTE_TEST_TX_DESC_DEFAULT        (1024)
 #define RTE_PORT_ALL            (~(uint16_t)0x0)
 
+#define ENCAP_DECAP_BURST_SZ 33
+
 /*
  * RX and TX Prefetch, Host, and Write-back threshold values should be
  * carefully set for optimal performance. Consult the network
@@ -103,6 +105,8 @@ struct lcore_cfg lcore_cfg;
 
 static uint64_t link_mbps;
 
+static int ip_reass_dynfield_offset = -1;
+
 static struct rte_flow *default_flow[RTE_MAX_ETHPORTS];
 
 /* Create Inline IPsec session */
@@ -477,6 +481,293 @@ destroy_default_flow(uint16_t port_id)
 struct rte_mbuf **tx_pkts_burst;
 struct rte_mbuf **rx_pkts_burst;
 
+static int
+compare_pkt_data(struct rte_mbuf *m, uint8_t *ref, unsigned int tot_len)
+{
+	unsigned int len;
+	unsigned int nb_segs = m->nb_segs;
+	unsigned int matched = 0;
+	struct rte_mbuf *save = m;
+
+	while (m && nb_segs != 0) {
+		len = tot_len;
+		if (len > m->data_len)
+			len = m->data_len;
+		if (len != 0) {
+			if (memcmp(rte_pktmbuf_mtod(m, char *),
+					ref + matched, len)) {
+				printf("\n====Reassembly case failed: Data Mismatch");
+				rte_hexdump(stdout, "Reassembled",
+					rte_pktmbuf_mtod(m, char *),
+					len);
+				rte_hexdump(stdout, "reference",
+					ref + matched,
+					len);
+				return TEST_FAILED;
+			}
+		}
+		tot_len -= len;
+		matched += len;
+		m = m->next;
+		nb_segs--;
+	}
+
+	if (tot_len) {
+		printf("\n====Reassembly case failed: Data Missing %u",
+		       tot_len);
+		printf("\n====nb_segs %u, tot_len %u", nb_segs, tot_len);
+		rte_pktmbuf_dump(stderr, save, -1);
+		return TEST_FAILED;
+	}
+	return TEST_SUCCESS;
+}
+
+static inline bool
+is_ip_reassembly_incomplete(struct rte_mbuf *mbuf)
+{
+	static uint64_t ip_reass_dynflag;
+	int ip_reass_dynflag_offset;
+
+	if (ip_reass_dynflag == 0) {
+		ip_reass_dynflag_offset = rte_mbuf_dynflag_lookup(
+				RTE_ETH_IP_REASS_INCOMPLETE_DYNFLAG_NAME, NULL);
+		if (ip_reass_dynflag_offset < 0)
+			return false;
+		ip_reass_dynflag = RTE_BIT64(ip_reass_dynflag_offset);
+	}
+
+	return (mbuf->ol_flags & ip_reass_dynflag) != 0;
+}
+
+static void
+free_mbuf(struct rte_mbuf *mbuf)
+{
+	rte_eth_ip_reass_dynfield_t dynfield;
+
+	if (!mbuf)
+		return;
+
+	if (!is_ip_reassembly_incomplete(mbuf)) {
+		rte_pktmbuf_free(mbuf);
+	} else {
+		if (ip_reass_dynfield_offset < 0)
+			return;
+
+		while (mbuf) {
+			dynfield = *RTE_MBUF_DYNFIELD(mbuf, ip_reass_dynfield_offset,
+						      rte_eth_ip_reass_dynfield_t *);
+			rte_pktmbuf_free(mbuf);
+			mbuf = dynfield.next_frag;
+		}
+	}
+}
+
+
+static int
+get_and_verify_incomplete_frags(struct rte_mbuf *mbuf,
+				struct reassembly_vector *vector)
+{
+	rte_eth_ip_reass_dynfield_t *dynfield[MAX_PKT_BURST];
+	int j = 0, ret;
+	/**
+	 * IP reassembly offload is incomplete, and fragments are listed in
+	 * dynfield which can be reassembled in SW.
+	 */
+	printf("\nHW IP Reassembly is not complete; attempt SW IP Reassembly,"
+		"\nMatching with original frags.");
+
+	if (ip_reass_dynfield_offset < 0)
+		return -1;
+
+	printf("\ncomparing frag: %d", j);
+	ret = compare_pkt_data(mbuf, vector->frags[j]->data,
+				vector->frags[j]->len);
+	if (ret)
+		return ret;
+	j++;
+	dynfield[j] = RTE_MBUF_DYNFIELD(mbuf, ip_reass_dynfield_offset,
+					rte_eth_ip_reass_dynfield_t *);
+	printf("\ncomparing frag: %d", j);
+	ret = compare_pkt_data(dynfield[j]->next_frag, vector->frags[j]->data,
+			vector->frags[j]->len);
+	if (ret)
+		return ret;
+
+	while ((dynfield[j]->nb_frags > 1) &&
+			is_ip_reassembly_incomplete(dynfield[j]->next_frag)) {
+		j++;
+		dynfield[j] = RTE_MBUF_DYNFIELD(dynfield[j-1]->next_frag,
+						ip_reass_dynfield_offset,
+						rte_eth_ip_reass_dynfield_t *);
+		printf("\ncomparing frag: %d", j);
+		ret = compare_pkt_data(dynfield[j]->next_frag,
+				vector->frags[j]->data, vector->frags[j]->len);
+		if (ret)
+			return ret;
+	}
+	return ret;
+}
+
+static int
+test_ipsec_encap_decap(struct reassembly_vector *vector,
+		       enum rte_security_ipsec_tunnel_type tun_type)
+{
+	struct rte_ipsec_session out_ips[ENCAP_DECAP_BURST_SZ] = {0};
+	struct rte_ipsec_session in_ips[ENCAP_DECAP_BURST_SZ] = {0};
+	unsigned int nb_tx, burst_sz, nb_sent = 0;
+	struct rte_eth_dev_info dev_info = {0};
+	unsigned int i, portid, nb_rx = 0, j;
+	struct ipsec_session_data sa_data;
+	int ret = 0;
+
+	burst_sz = vector->burst ? ENCAP_DECAP_BURST_SZ : 1;
+
+	portid = lcore_cfg.port;
+	rte_eth_dev_info_get(portid, &dev_info);
+	if (dev_info.reass_capa.max_frags < vector->nb_frags)
+		return TEST_SKIPPED;
+
+	nb_tx = vector->nb_frags * burst_sz;
+	memset(tx_pkts_burst, 0, sizeof(tx_pkts_burst[0]) * nb_tx);
+	memset(rx_pkts_burst, 0, sizeof(rx_pkts_burst[0]) * nb_tx);
+
+	for (i = 0; i < nb_tx; i += vector->nb_frags) {
+		ret = init_traffic(mbufpool[lcore_cfg.socketid],
+				   &tx_pkts_burst[i], vector->frags,
+				   vector->nb_frags);
+		if (ret != vector->nb_frags) {
+			ret = -1;
+			goto out;
+		}
+	}
+
+	for (i = 0; i < burst_sz; i++) {
+		memcpy(&sa_data, vector->sa_data, sizeof(sa_data));
+		/* Update SPI for every new SA */
+		sa_data.ipsec_xform.spi += i;
+
+		/* Create Inline IPsec outbound session. */
+		ret = create_inline_ipsec_session(&sa_data, portid, &out_ips[i],
+						  RTE_SECURITY_IPSEC_SA_DIR_EGRESS,
+						  tun_type);
+		if (ret)
+			goto out;
+	}
+
+	j = 0;
+	for (i = 0; i < nb_tx; i++) {
+		if (out_ips[j].security.ol_flags &
+				RTE_SECURITY_TX_OLOAD_NEED_MDATA)
+			rte_security_set_pkt_metadata(out_ips[j].security.ctx,
+				out_ips[j].security.ses, tx_pkts_burst[i], NULL);
+		tx_pkts_burst[i]->ol_flags |= RTE_MBUF_F_TX_SEC_OFFLOAD;
+		tx_pkts_burst[i]->l2_len = RTE_ETHER_HDR_LEN;
+
+		/* Move to next SA after nb_frags */
+		if ((i + 1) % vector->nb_frags == 0)
+			j++;
+	}
+
+	for (i = 0; i < burst_sz; i++) {
+		memcpy(&sa_data, vector->sa_data, sizeof(sa_data));
+		/* Update SPI for every new SA */
+		sa_data.ipsec_xform.spi += i;
+
+		/* Create Inline IPsec inbound session. */
+		ret = create_inline_ipsec_session(&sa_data, portid, &in_ips[i],
+						  RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
+						  tun_type);
+		if (ret)
+			goto out;
+	}
+
+	/* Retrieve reassembly dynfield offset if available */
+	if (ip_reass_dynfield_offset < 0 && vector->nb_frags > 1)
+		ip_reass_dynfield_offset = rte_mbuf_dynfield_lookup(
+				RTE_ETH_IP_REASS_DYNFIELD_NAME, NULL);
+
+
+	create_default_flow(portid);
+
+	nb_sent = rte_eth_tx_burst(portid, 0, tx_pkts_burst, nb_tx);
+	if (nb_sent != nb_tx) {
+		ret = -1;
+		printf("\nFailed to tx %u pkts", nb_tx);
+		goto out;
+	}
+
+	rte_delay_ms(100);
+
+	/* Retry few times before giving up */
+	nb_rx = 0;
+	j = 0;
+	do {
+		nb_rx += rte_eth_rx_burst(portid, 0, &rx_pkts_burst[nb_rx],
+					  nb_tx - nb_rx);
+		j++;
+		if (nb_rx >= nb_tx)
+			break;
+		rte_delay_ms(100);
+	} while (j < 5 || !nb_rx);
+
+	/* Check for minimum number of Rx packets expected */
+	if ((vector->nb_frags == 1 && nb_rx != nb_tx) ||
+	    (vector->nb_frags > 1 && nb_rx < burst_sz)) {
+		printf("\nreceived less Rx pkts(%u) pkts\n", nb_rx);
+		ret = TEST_FAILED;
+		goto out;
+	}
+
+	for (i = 0; i < nb_rx; i++) {
+		if (vector->nb_frags > 1 &&
+		    is_ip_reassembly_incomplete(rx_pkts_burst[i])) {
+			ret = get_and_verify_incomplete_frags(rx_pkts_burst[i],
+							      vector);
+			if (ret != TEST_SUCCESS)
+				break;
+			continue;
+		}
+
+		if (rx_pkts_burst[i]->ol_flags &
+		    RTE_MBUF_F_RX_SEC_OFFLOAD_FAILED ||
+		    !(rx_pkts_burst[i]->ol_flags & RTE_MBUF_F_RX_SEC_OFFLOAD)) {
+			printf("\nsecurity offload failed\n");
+			ret = TEST_FAILED;
+			break;
+		}
+
+		if (vector->full_pkt->len != rx_pkts_burst[i]->pkt_len) {
+			printf("\nreassembled/decrypted packet length mismatch\n");
+			ret = TEST_FAILED;
+			break;
+		}
+		ret = compare_pkt_data(rx_pkts_burst[i],
+				       vector->full_pkt->data,
+				       vector->full_pkt->len);
+		if (ret != TEST_SUCCESS)
+			break;
+	}
+
+out:
+	destroy_default_flow(portid);
+
+	/* Clear session data. */
+	for (i = 0; i < burst_sz; i++) {
+		if (out_ips[i].security.ses)
+			rte_security_session_destroy(out_ips[i].security.ctx,
+						     out_ips[i].security.ses);
+		if (in_ips[i].security.ses)
+			rte_security_session_destroy(in_ips[i].security.ctx,
+						     in_ips[i].security.ses);
+	}
+
+	for (i = nb_sent; i < nb_tx; i++)
+		free_mbuf(tx_pkts_burst[i]);
+	for (i = 0; i < nb_rx; i++)
+		free_mbuf(rx_pkts_burst[i]);
+	return ret;
+}
+
 static int
 test_ipsec(struct reassembly_vector *vector,
 	   enum rte_security_ipsec_sa_direction dir,
@@ -733,6 +1024,34 @@ test_ipsec_ipv4_decap_nofrag(void)
 			RTE_SECURITY_IPSEC_TUNNEL_IPV4);
 }
 
+static int
+test_reassembly_ipv4_nofrag(void)
+{
+	struct reassembly_vector ipv4_nofrag_case = {
+				.sa_data = &conf_aes_128_gcm,
+				.full_pkt = &pkt_ipv4_plain,
+				.frags[0] = &pkt_ipv4_plain,
+				.nb_frags = 1,
+	};
+	return test_ipsec_encap_decap(&ipv4_nofrag_case,
+				      RTE_SECURITY_IPSEC_TUNNEL_IPV4);
+}
+
+
+static int
+test_ipsec_ipv4_burst_encap_decap(void)
+{
+	struct reassembly_vector ipv4_nofrag_case = {
+				.sa_data = &conf_aes_128_gcm,
+				.full_pkt = &pkt_ipv4_plain,
+				.frags[0] = &pkt_ipv4_plain,
+				.nb_frags = 1,
+				.burst = true,
+	};
+	return test_ipsec_encap_decap(&ipv4_nofrag_case,
+				      RTE_SECURITY_IPSEC_TUNNEL_IPV4);
+}
+
 static struct unit_test_suite inline_ipsec_testsuite  = {
 	.suite_name = "Inline IPsec Ethernet Device Unit Test Suite",
 	.setup = testsuite_setup,
@@ -744,6 +1063,12 @@ static struct unit_test_suite inline_ipsec_testsuite  = {
 		TEST_CASE_ST(ut_setup_inline_ipsec,
 				ut_teardown_inline_ipsec,
 				test_ipsec_ipv4_decap_nofrag),
+		TEST_CASE_ST(ut_setup_inline_ipsec,
+				ut_teardown_inline_ipsec,
+				test_reassembly_ipv4_nofrag),
+		TEST_CASE_ST(ut_setup_inline_ipsec,
+				ut_teardown_inline_ipsec,
+				test_ipsec_ipv4_burst_encap_decap),
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	}
app/test/test_security_inline_proto_vectors.h +1 -0
index 08e6868b0d..861c4fad48 100644
@@ -42,6 +42,7 @@ struct reassembly_vector {
 	struct ipsec_test_packet *full_pkt;
 	struct ipsec_test_packet *frags[MAX_FRAGS];
 	uint16_t nb_frags;
+	bool burst;
 };
 
 struct ipsec_test_packet pkt_ipv4_plain = {
Signature · 1 line
2.25.1
#39 lore raw

PATCH v2 3/4 app/test: add IP reassembly cases with multiple fragments

In reply to Akhil Goyal

More cases are added in test_inline_ipsec test suite to verify packets having multiple IP(v4/v6) fragments. These fragments are encrypted and then decrypted as per inline IPsec processing and then an attempt is made to reassemble the fragments. The reassembled packet content is matched with the known test vectors.

---
 app/test/test_security_inline_proto.c         | 147 ++++-
 app/test/test_security_inline_proto_vectors.h | 592 ++++++++++++++++++
 2 files changed, 738 insertions(+), 1 deletion(-)
app/test/test_security_inline_proto.c +146 -1
index 9dc083369a..d05325b205 100644
@@ -1037,7 +1037,6 @@ test_reassembly_ipv4_nofrag(void)
 				      RTE_SECURITY_IPSEC_TUNNEL_IPV4);
 }
 
-
 static int
 test_ipsec_ipv4_burst_encap_decap(void)
 {
@@ -1052,6 +1051,134 @@ test_ipsec_ipv4_burst_encap_decap(void)
 				      RTE_SECURITY_IPSEC_TUNNEL_IPV4);
 }
 
+static int
+test_reassembly_ipv4_2frag(void)
+{
+	struct reassembly_vector ipv4_2frag_case = {
+				.sa_data = &conf_aes_128_gcm,
+				.full_pkt = &pkt_ipv4_udp_p1,
+				.frags[0] = &pkt_ipv4_udp_p1_f1,
+				.frags[1] = &pkt_ipv4_udp_p1_f2,
+				.nb_frags = 2,
+	};
+	test_vector_payload_populate(&pkt_ipv4_udp_p1, true);
+	test_vector_payload_populate(&pkt_ipv4_udp_p1_f1, true);
+	test_vector_payload_populate(&pkt_ipv4_udp_p1_f2, false);
+
+	return test_ipsec_encap_decap(&ipv4_2frag_case,
+				      RTE_SECURITY_IPSEC_TUNNEL_IPV4);
+}
+
+static int
+test_reassembly_ipv6_2frag(void)
+{
+	struct reassembly_vector ipv6_2frag_case = {
+				.sa_data = &conf_aes_128_gcm,
+				.full_pkt = &pkt_ipv6_udp_p1,
+				.frags[0] = &pkt_ipv6_udp_p1_f1,
+				.frags[1] = &pkt_ipv6_udp_p1_f2,
+				.nb_frags = 2,
+	};
+	test_vector_payload_populate(&pkt_ipv6_udp_p1, true);
+	test_vector_payload_populate(&pkt_ipv6_udp_p1_f1, true);
+	test_vector_payload_populate(&pkt_ipv6_udp_p1_f2, false);
+
+	return test_ipsec_encap_decap(&ipv6_2frag_case,
+				      RTE_SECURITY_IPSEC_TUNNEL_IPV6);
+}
+
+static int
+test_reassembly_ipv4_4frag(void)
+{
+	struct reassembly_vector ipv4_4frag_case = {
+				.sa_data = &conf_aes_128_gcm,
+				.full_pkt = &pkt_ipv4_udp_p2,
+				.frags[0] = &pkt_ipv4_udp_p2_f1,
+				.frags[1] = &pkt_ipv4_udp_p2_f2,
+				.frags[2] = &pkt_ipv4_udp_p2_f3,
+				.frags[3] = &pkt_ipv4_udp_p2_f4,
+				.nb_frags = 4,
+	};
+	test_vector_payload_populate(&pkt_ipv4_udp_p2, true);
+	test_vector_payload_populate(&pkt_ipv4_udp_p2_f1, true);
+	test_vector_payload_populate(&pkt_ipv4_udp_p2_f2, false);
+	test_vector_payload_populate(&pkt_ipv4_udp_p2_f3, false);
+	test_vector_payload_populate(&pkt_ipv4_udp_p2_f4, false);
+
+	return test_ipsec_encap_decap(&ipv4_4frag_case,
+				      RTE_SECURITY_IPSEC_TUNNEL_IPV4);
+}
+
+static int
+test_reassembly_ipv6_4frag(void)
+{
+	struct reassembly_vector ipv6_4frag_case = {
+				.sa_data = &conf_aes_128_gcm,
+				.full_pkt = &pkt_ipv6_udp_p2,
+				.frags[0] = &pkt_ipv6_udp_p2_f1,
+				.frags[1] = &pkt_ipv6_udp_p2_f2,
+				.frags[2] = &pkt_ipv6_udp_p2_f3,
+				.frags[3] = &pkt_ipv6_udp_p2_f4,
+				.nb_frags = 4,
+	};
+	test_vector_payload_populate(&pkt_ipv6_udp_p2, true);
+	test_vector_payload_populate(&pkt_ipv6_udp_p2_f1, true);
+	test_vector_payload_populate(&pkt_ipv6_udp_p2_f2, false);
+	test_vector_payload_populate(&pkt_ipv6_udp_p2_f3, false);
+	test_vector_payload_populate(&pkt_ipv6_udp_p2_f4, false);
+
+	return test_ipsec_encap_decap(&ipv6_4frag_case,
+				      RTE_SECURITY_IPSEC_TUNNEL_IPV6);
+}
+
+static int
+test_reassembly_ipv4_5frag(void)
+{
+	struct reassembly_vector ipv4_5frag_case = {
+				.sa_data = &conf_aes_128_gcm,
+				.full_pkt = &pkt_ipv4_udp_p3,
+				.frags[0] = &pkt_ipv4_udp_p3_f1,
+				.frags[1] = &pkt_ipv4_udp_p3_f2,
+				.frags[2] = &pkt_ipv4_udp_p3_f3,
+				.frags[3] = &pkt_ipv4_udp_p3_f4,
+				.frags[4] = &pkt_ipv4_udp_p3_f5,
+				.nb_frags = 5,
+	};
+	test_vector_payload_populate(&pkt_ipv4_udp_p3, true);
+	test_vector_payload_populate(&pkt_ipv4_udp_p3_f1, true);
+	test_vector_payload_populate(&pkt_ipv4_udp_p3_f2, false);
+	test_vector_payload_populate(&pkt_ipv4_udp_p3_f3, false);
+	test_vector_payload_populate(&pkt_ipv4_udp_p3_f4, false);
+	test_vector_payload_populate(&pkt_ipv4_udp_p3_f5, false);
+
+	return test_ipsec_encap_decap(&ipv4_5frag_case,
+				      RTE_SECURITY_IPSEC_TUNNEL_IPV4);
+}
+
+static int
+test_reassembly_ipv6_5frag(void)
+{
+	struct reassembly_vector ipv6_5frag_case = {
+				.sa_data = &conf_aes_128_gcm,
+				.full_pkt = &pkt_ipv6_udp_p3,
+				.frags[0] = &pkt_ipv6_udp_p3_f1,
+				.frags[1] = &pkt_ipv6_udp_p3_f2,
+				.frags[2] = &pkt_ipv6_udp_p3_f3,
+				.frags[3] = &pkt_ipv6_udp_p3_f4,
+				.frags[4] = &pkt_ipv6_udp_p3_f5,
+				.nb_frags = 5,
+	};
+	test_vector_payload_populate(&pkt_ipv6_udp_p3, true);
+	test_vector_payload_populate(&pkt_ipv6_udp_p3_f1, true);
+	test_vector_payload_populate(&pkt_ipv6_udp_p3_f2, false);
+	test_vector_payload_populate(&pkt_ipv6_udp_p3_f3, false);
+	test_vector_payload_populate(&pkt_ipv6_udp_p3_f4, false);
+	test_vector_payload_populate(&pkt_ipv6_udp_p3_f5, false);
+
+	return test_ipsec_encap_decap(&ipv6_5frag_case,
+				      RTE_SECURITY_IPSEC_TUNNEL_IPV6);
+}
+
 static struct unit_test_suite inline_ipsec_testsuite  = {
 	.suite_name = "Inline IPsec Ethernet Device Unit Test Suite",
 	.setup = testsuite_setup,
@@ -1069,6 +1196,24 @@ static struct unit_test_suite inline_ipsec_testsuite  = {
 		TEST_CASE_ST(ut_setup_inline_ipsec,
 				ut_teardown_inline_ipsec,
 				test_ipsec_ipv4_burst_encap_decap),
+		TEST_CASE_ST(ut_setup_inline_ipsec,
+				ut_teardown_inline_ipsec,
+				test_reassembly_ipv4_2frag),
+		TEST_CASE_ST(ut_setup_inline_ipsec,
+				ut_teardown_inline_ipsec,
+				test_reassembly_ipv6_2frag),
+		TEST_CASE_ST(ut_setup_inline_ipsec,
+				ut_teardown_inline_ipsec,
+				test_reassembly_ipv4_4frag),
+		TEST_CASE_ST(ut_setup_inline_ipsec,
+				ut_teardown_inline_ipsec,
+				test_reassembly_ipv6_4frag),
+		TEST_CASE_ST(ut_setup_inline_ipsec,
+				ut_teardown_inline_ipsec,
+				test_reassembly_ipv4_5frag),
+		TEST_CASE_ST(ut_setup_inline_ipsec,
+				ut_teardown_inline_ipsec,
+				test_reassembly_ipv6_5frag),
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	}
app/test/test_security_inline_proto_vectors.h +592 -0

604 lines not on this page · raw message

Signature · 1 line
2.25.1
#40 lore raw

PATCH v2 4/4 app/test: add IP reassembly negative cases

In reply to Akhil Goyal

test_inline_ipsec testsuite is added with cases where the IP reassembly is incomplete and software will need to reassemble them later. The failure cases added are:
- all fragments are not received.
- same fragment is received more than once.
- out of order fragments.

---
 app/test/test_security_inline_proto.c | 71 +++++++++++++++++++++++++++
 1 file changed, 71 insertions(+)
app/test/test_security_inline_proto.c +71 -0
index d05325b205..b1794c1bc7 100644
@@ -1179,6 +1179,68 @@ test_reassembly_ipv6_5frag(void)
 				      RTE_SECURITY_IPSEC_TUNNEL_IPV6);
 }
 
+static int
+test_reassembly_incomplete(void)
+{
+	/* Negative test case, not sending all fragments. */
+	struct reassembly_vector ipv4_incomplete_case = {
+				.sa_data = &conf_aes_128_gcm,
+				.full_pkt = &pkt_ipv4_udp_p2,
+				.frags[0] = &pkt_ipv4_udp_p2_f1,
+				.frags[1] = &pkt_ipv4_udp_p2_f2,
+				.nb_frags = 2,
+	};
+	test_vector_payload_populate(&pkt_ipv4_udp_p2, true);
+	test_vector_payload_populate(&pkt_ipv4_udp_p2_f1, true);
+	test_vector_payload_populate(&pkt_ipv4_udp_p2_f2, false);
+
+	return test_ipsec_encap_decap(&ipv4_incomplete_case,
+				      RTE_SECURITY_IPSEC_TUNNEL_IPV4);
+}
+
+static int
+test_reassembly_overlap(void)
+{
+	/* Negative test case, sending 1 fragment twice. */
+	struct reassembly_vector ipv4_overlap_case = {
+				.sa_data = &conf_aes_128_gcm,
+				.full_pkt = &pkt_ipv4_udp_p1,
+				.frags[0] = &pkt_ipv4_udp_p1_f1,
+				.frags[1] = &pkt_ipv4_udp_p1_f1, /* Overlap */
+				.frags[2] = &pkt_ipv4_udp_p1_f2,
+				.nb_frags = 3,
+	};
+	test_vector_payload_populate(&pkt_ipv4_udp_p2, true);
+	test_vector_payload_populate(&pkt_ipv4_udp_p2_f1, true);
+	test_vector_payload_populate(&pkt_ipv4_udp_p2_f2, false);
+
+	return test_ipsec_encap_decap(&ipv4_overlap_case,
+				      RTE_SECURITY_IPSEC_TUNNEL_IPV4);
+}
+
+static int
+test_reassembly_out_of_order(void)
+{
+	/* Negative test case, out of order fragments. */
+	struct reassembly_vector ipv4_ooo_case = {
+				.sa_data = &conf_aes_128_gcm,
+				.full_pkt = &pkt_ipv4_udp_p2,
+				.frags[0] = &pkt_ipv4_udp_p2_f1,
+				.frags[1] = &pkt_ipv4_udp_p2_f3,
+				.frags[2] = &pkt_ipv4_udp_p2_f4,
+				.frags[3] = &pkt_ipv4_udp_p2_f2,
+				.nb_frags = 4,
+	};
+	test_vector_payload_populate(&pkt_ipv4_udp_p2, true);
+	test_vector_payload_populate(&pkt_ipv4_udp_p2_f1, true);
+	test_vector_payload_populate(&pkt_ipv4_udp_p2_f2, false);
+	test_vector_payload_populate(&pkt_ipv4_udp_p2_f3, false);
+	test_vector_payload_populate(&pkt_ipv4_udp_p2_f4, false);
+
+	return test_ipsec_encap_decap(&ipv4_ooo_case,
+				      RTE_SECURITY_IPSEC_TUNNEL_IPV4);
+}
+
 static struct unit_test_suite inline_ipsec_testsuite  = {
 	.suite_name = "Inline IPsec Ethernet Device Unit Test Suite",
 	.setup = testsuite_setup,
@@ -1214,6 +1276,15 @@ static struct unit_test_suite inline_ipsec_testsuite  = {
 		TEST_CASE_ST(ut_setup_inline_ipsec,
 				ut_teardown_inline_ipsec,
 				test_reassembly_ipv6_5frag),
+		TEST_CASE_ST(ut_setup_inline_ipsec,
+				ut_teardown_inline_ipsec,
+				test_reassembly_incomplete),
+		TEST_CASE_ST(ut_setup_inline_ipsec,
+				ut_teardown_inline_ipsec,
+				test_reassembly_overlap),
+		TEST_CASE_ST(ut_setup_inline_ipsec,
+				ut_teardown_inline_ipsec,
+				test_reassembly_out_of_order),
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	}
Signature · 1 line
2.25.1
#41 lore raw

v3 cover app/test: add inline IPsec and reassembly cases

In reply to Akhil Goyal

IP reassembly RX offload is introduced in [1].
This patchset is added to test the IP reassembly RX offload and to test other inline IPsec test cases which need to be verified before testing IP reassembly in inline inbound cases.
In this app, plain IP packets(with/without IP fragments) are sent on one interface for outbound processing and then the packets are received back on the same interface using loopback mode. While receiving the packets, the packets are processed for inline inbound IPsec processing and if the packets are fragmented, they will be reassembled before getting received in the driver/app.

v1 of this patchset was sent along with the ethdev changes in [2]. v2 is split so that it can be reviewed separately.

Changes in v3:
- incorporated latest ethdev changes for reassembly.
- skipped build on windows as it needs rte_ipsec lib which is not compiled on windows.
changes in v2:
- added IPsec burst mode case
- updated as per the latest ethdev changes in [1].

[1] http://patches.dpdk.org/project/dpdk/list/?series=21283
[2] http://patches.dpdk.org/project/dpdk/list/?series=21052

Akhil Goyal (4):
app/test: add unit cases for inline IPsec offload app/test: add IP reassembly case with no frags app/test: add IP reassembly cases with multiple fragments app/test: add IP reassembly negative cases

 MAINTAINERS                                   |    2 +-
 app/test/meson.build                          |    4 +
 app/test/test_security_inline_proto.c         | 1299 +++++++++++++++++
 app/test/test_security_inline_proto_vectors.h |  778 ++++++++++
 4 files changed, 2082 insertions(+), 1 deletion(-)
 create mode 100644 app/test/test_security_inline_proto.c
 create mode 100644 app/test/test_security_inline_proto_vectors.h
Signature · 1 line
2.25.1
#42 lore raw

PATCH v3 1/4 app/test: add unit cases for inline IPsec offload

A new test suite is added in test app to test inline IPsec protocol offload. In this patch, a couple of predefined plain and cipher test vectors are used to verify the IPsec functionality without the need of external traffic generators. The sent packet is loopbacked onto the same interface which is received and matched with the expected output. The test suite can be updated further with other functional test cases. The testsuite can be run using:
RTE> inline_ipsec_autotest

---
 MAINTAINERS                                   |   2 +-
 app/test/meson.build                          |   4 +
 app/test/test_security_inline_proto.c         | 757 ++++++++++++++++++
 app/test/test_security_inline_proto_vectors.h | 185 +++++
 4 files changed, 947 insertions(+), 1 deletion(-)
 create mode 100644 app/test/test_security_inline_proto.c
 create mode 100644 app/test/test_security_inline_proto_vectors.h
MAINTAINERS +1 -1
index d5cd0a6c2f..52eee9b2b3 100644
@@ -439,7 +439,7 @@ M: Akhil Goyal <[email protected]>
 T: git://dpdk.org/next/dpdk-next-crypto
 F: lib/security/
 F: doc/guides/prog_guide/rte_security.rst
-F: app/test/test_security.c
+F: app/test/test_security*
 
 Compression API - EXPERIMENTAL
 M: Fan Zhang <[email protected]>
app/test/meson.build +4 -0
index 5fc1dd1b7b..5804b888c9 100644
@@ -355,6 +355,10 @@ if not is_windows and dpdk_conf.has('RTE_LIB_TELEMETRY')
     test_sources += ['test_telemetry_json.c', 'test_telemetry_data.c']
     fast_tests += [['telemetry_json_autotest', true], ['telemetry_data_autotest', true]]
 endif
+if not is_windows
+    test_sources += ['test_security_inline_proto.c']
+    fast_tests += [['inline_ipsec_autotest', false]]
+endif
 if dpdk_conf.has('RTE_LIB_PIPELINE')
 # pipeline lib depends on port and table libs, so those must be present
 # if pipeline library is.
app/test/test_security_inline_proto.c new file +757 -0

757 lines not on this page · raw message

app/test/test_security_inline_proto_vectors.h new file +185 -0

185 lines not on this page · raw message

Signature · 1 line
2.25.1
#43 lore raw

PATCH v3 2/4 app/test: add IP reassembly case with no frags

In reply to Akhil Goyal

test_inline_ipsec testsuite is extended to test IP reassembly of inbound fragmented packets. The fragmented packet is sent on an interface which encrypts the packet and then it is loopbacked on the same interface which decrypts the packet and then attempts IP reassembly of the decrypted packets.
In this patch, a case is added for packets without fragmentation to verify the complete path. Other cases are added in subsequent patches.

---
 app/test/test_security_inline_proto.c         | 326 ++++++++++++++++++
 app/test/test_security_inline_proto_vectors.h |   1 +
 2 files changed, 327 insertions(+)
app/test/test_security_inline_proto.c +326 -0
index e2b95de68e..3fbf8105e1 100644
@@ -25,6 +25,8 @@
 #define RTE_TEST_TX_DESC_DEFAULT        (1024)
 #define RTE_PORT_ALL            (~(uint16_t)0x0)
 
+#define ENCAP_DECAP_BURST_SZ 33
+
 /*
  * RX and TX Prefetch, Host, and Write-back threshold values should be
  * carefully set for optimal performance. Consult the network
@@ -102,6 +104,8 @@ struct lcore_cfg lcore_cfg;
 
 static uint64_t link_mbps;
 
+static int ip_reassembly_dynfield_offset = -1;
+
 static struct rte_flow *default_flow[RTE_MAX_ETHPORTS];
 
 /* Create Inline IPsec session */
@@ -476,6 +480,294 @@ destroy_default_flow(uint16_t port_id)
 struct rte_mbuf **tx_pkts_burst;
 struct rte_mbuf **rx_pkts_burst;
 
+static int
+compare_pkt_data(struct rte_mbuf *m, uint8_t *ref, unsigned int tot_len)
+{
+	unsigned int len;
+	unsigned int nb_segs = m->nb_segs;
+	unsigned int matched = 0;
+	struct rte_mbuf *save = m;
+
+	while (m && nb_segs != 0) {
+		len = tot_len;
+		if (len > m->data_len)
+			len = m->data_len;
+		if (len != 0) {
+			if (memcmp(rte_pktmbuf_mtod(m, char *),
+					ref + matched, len)) {
+				printf("\n====Reassembly case failed: Data Mismatch");
+				rte_hexdump(stdout, "Reassembled",
+					rte_pktmbuf_mtod(m, char *),
+					len);
+				rte_hexdump(stdout, "reference",
+					ref + matched,
+					len);
+				return TEST_FAILED;
+			}
+		}
+		tot_len -= len;
+		matched += len;
+		m = m->next;
+		nb_segs--;
+	}
+
+	if (tot_len) {
+		printf("\n====Reassembly case failed: Data Missing %u",
+		       tot_len);
+		printf("\n====nb_segs %u, tot_len %u", nb_segs, tot_len);
+		rte_pktmbuf_dump(stderr, save, -1);
+		return TEST_FAILED;
+	}
+	return TEST_SUCCESS;
+}
+
+static inline bool
+is_ip_reassembly_incomplete(struct rte_mbuf *mbuf)
+{
+	static uint64_t ip_reassembly_dynflag;
+	int ip_reassembly_dynflag_offset;
+
+	if (ip_reassembly_dynflag == 0) {
+		ip_reassembly_dynflag_offset = rte_mbuf_dynflag_lookup(
+			RTE_MBUF_DYNFLAG_IP_REASSEMBLY_INCOMPLETE_NAME, NULL);
+		if (ip_reassembly_dynflag_offset < 0)
+			return false;
+		ip_reassembly_dynflag = RTE_BIT64(ip_reassembly_dynflag_offset);
+	}
+
+	return (mbuf->ol_flags & ip_reassembly_dynflag) != 0;
+}
+
+static void
+free_mbuf(struct rte_mbuf *mbuf)
+{
+	rte_eth_ip_reassembly_dynfield_t dynfield;
+
+	if (!mbuf)
+		return;
+
+	if (!is_ip_reassembly_incomplete(mbuf)) {
+		rte_pktmbuf_free(mbuf);
+	} else {
+		if (ip_reassembly_dynfield_offset < 0)
+			return;
+
+		while (mbuf) {
+			dynfield = *RTE_MBUF_DYNFIELD(mbuf,
+					ip_reassembly_dynfield_offset,
+					rte_eth_ip_reassembly_dynfield_t *);
+			rte_pktmbuf_free(mbuf);
+			mbuf = dynfield.next_frag;
+		}
+	}
+}
+
+
+static int
+get_and_verify_incomplete_frags(struct rte_mbuf *mbuf,
+				struct reassembly_vector *vector)
+{
+	rte_eth_ip_reassembly_dynfield_t *dynfield[MAX_PKT_BURST];
+	int j = 0, ret;
+	/**
+	 * IP reassembly offload is incomplete, and fragments are listed in
+	 * dynfield which can be reassembled in SW.
+	 */
+	printf("\nHW IP Reassembly is not complete; attempt SW IP Reassembly,"
+		"\nMatching with original frags.");
+
+	if (ip_reassembly_dynfield_offset < 0)
+		return -1;
+
+	printf("\ncomparing frag: %d", j);
+	ret = compare_pkt_data(mbuf, vector->frags[j]->data,
+				vector->frags[j]->len);
+	if (ret)
+		return ret;
+	j++;
+	dynfield[j] = RTE_MBUF_DYNFIELD(mbuf, ip_reassembly_dynfield_offset,
+					rte_eth_ip_reassembly_dynfield_t *);
+	printf("\ncomparing frag: %d", j);
+	ret = compare_pkt_data(dynfield[j]->next_frag, vector->frags[j]->data,
+			vector->frags[j]->len);
+	if (ret)
+		return ret;
+
+	while ((dynfield[j]->nb_frags > 1) &&
+			is_ip_reassembly_incomplete(dynfield[j]->next_frag)) {
+		j++;
+		dynfield[j] = RTE_MBUF_DYNFIELD(dynfield[j-1]->next_frag,
+					ip_reassembly_dynfield_offset,
+					rte_eth_ip_reassembly_dynfield_t *);
+		printf("\ncomparing frag: %d", j);
+		ret = compare_pkt_data(dynfield[j]->next_frag,
+				vector->frags[j]->data, vector->frags[j]->len);
+		if (ret)
+			return ret;
+	}
+	return ret;
+}
+
+static int
+test_ipsec_encap_decap(struct reassembly_vector *vector,
+		       enum rte_security_ipsec_tunnel_type tun_type)
+{
+	struct rte_ipsec_session out_ips[ENCAP_DECAP_BURST_SZ] = {0};
+	struct rte_ipsec_session in_ips[ENCAP_DECAP_BURST_SZ] = {0};
+	struct rte_eth_ip_reassembly_params reass_capa = {0};
+	unsigned int nb_tx, burst_sz, nb_sent = 0;
+	unsigned int i, portid, nb_rx = 0, j;
+	struct ipsec_session_data sa_data;
+	int ret = 0;
+
+	burst_sz = vector->burst ? ENCAP_DECAP_BURST_SZ : 1;
+
+	portid = lcore_cfg.port;
+	rte_eth_ip_reassembly_capability_get(portid, &reass_capa);
+	if (reass_capa.max_frags < vector->nb_frags)
+		return TEST_SKIPPED;
+
+	nb_tx = vector->nb_frags * burst_sz;
+	memset(tx_pkts_burst, 0, sizeof(tx_pkts_burst[0]) * nb_tx);
+	memset(rx_pkts_burst, 0, sizeof(rx_pkts_burst[0]) * nb_tx);
+
+	for (i = 0; i < nb_tx; i += vector->nb_frags) {
+		ret = init_traffic(mbufpool[lcore_cfg.socketid],
+				   &tx_pkts_burst[i], vector->frags,
+				   vector->nb_frags);
+		if (ret != vector->nb_frags) {
+			ret = -1;
+			goto out;
+		}
+	}
+
+	for (i = 0; i < burst_sz; i++) {
+		memcpy(&sa_data, vector->sa_data, sizeof(sa_data));
+		/* Update SPI for every new SA */
+		sa_data.ipsec_xform.spi += i;
+
+		/* Create Inline IPsec outbound session. */
+		ret = create_inline_ipsec_session(&sa_data, portid, &out_ips[i],
+						  RTE_SECURITY_IPSEC_SA_DIR_EGRESS,
+						  tun_type);
+		if (ret)
+			goto out;
+	}
+
+	j = 0;
+	for (i = 0; i < nb_tx; i++) {
+		if (out_ips[j].security.ol_flags &
+				RTE_SECURITY_TX_OLOAD_NEED_MDATA)
+			rte_security_set_pkt_metadata(out_ips[j].security.ctx,
+				out_ips[j].security.ses, tx_pkts_burst[i], NULL);
+		tx_pkts_burst[i]->ol_flags |= RTE_MBUF_F_TX_SEC_OFFLOAD;
+		tx_pkts_burst[i]->l2_len = RTE_ETHER_HDR_LEN;
+
+		/* Move to next SA after nb_frags */
+		if ((i + 1) % vector->nb_frags == 0)
+			j++;
+	}
+
+	for (i = 0; i < burst_sz; i++) {
+		memcpy(&sa_data, vector->sa_data, sizeof(sa_data));
+		/* Update SPI for every new SA */
+		sa_data.ipsec_xform.spi += i;
+
+		/* Create Inline IPsec inbound session. */
+		ret = create_inline_ipsec_session(&sa_data, portid, &in_ips[i],
+						  RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
+						  tun_type);
+		if (ret)
+			goto out;
+	}
+
+	/* Retrieve reassembly dynfield offset if available */
+	if (ip_reassembly_dynfield_offset < 0 && vector->nb_frags > 1)
+		ip_reassembly_dynfield_offset = rte_mbuf_dynfield_lookup(
+				RTE_MBUF_DYNFIELD_IP_REASSEMBLY_NAME, NULL);
+
+
+	create_default_flow(portid);
+
+	nb_sent = rte_eth_tx_burst(portid, 0, tx_pkts_burst, nb_tx);
+	if (nb_sent != nb_tx) {
+		ret = -1;
+		printf("\nFailed to tx %u pkts", nb_tx);
+		goto out;
+	}
+
+	rte_delay_ms(100);
+
+	/* Retry few times before giving up */
+	nb_rx = 0;
+	j = 0;
+	do {
+		nb_rx += rte_eth_rx_burst(portid, 0, &rx_pkts_burst[nb_rx],
+					  nb_tx - nb_rx);
+		j++;
+		if (nb_rx >= nb_tx)
+			break;
+		rte_delay_ms(100);
+	} while (j < 5 || !nb_rx);
+
+	/* Check for minimum number of Rx packets expected */
+	if ((vector->nb_frags == 1 && nb_rx != nb_tx) ||
+	    (vector->nb_frags > 1 && nb_rx < burst_sz)) {
+		printf("\nreceived less Rx pkts(%u) pkts\n", nb_rx);
+		ret = TEST_FAILED;
+		goto out;
+	}
+
+	for (i = 0; i < nb_rx; i++) {
+		if (vector->nb_frags > 1 &&
+		    is_ip_reassembly_incomplete(rx_pkts_burst[i])) {
+			ret = get_and_verify_incomplete_frags(rx_pkts_burst[i],
+							      vector);
+			if (ret != TEST_SUCCESS)
+				break;
+			continue;
+		}
+
+		if (rx_pkts_burst[i]->ol_flags &
+		    RTE_MBUF_F_RX_SEC_OFFLOAD_FAILED ||
+		    !(rx_pkts_burst[i]->ol_flags & RTE_MBUF_F_RX_SEC_OFFLOAD)) {
+			printf("\nsecurity offload failed\n");
+			ret = TEST_FAILED;
+			break;
+		}
+
+		if (vector->full_pkt->len != rx_pkts_burst[i]->pkt_len) {
+			printf("\nreassembled/decrypted packet length mismatch\n");
+			ret = TEST_FAILED;
+			break;
+		}
+		ret = compare_pkt_data(rx_pkts_burst[i],
+				       vector->full_pkt->data,
+				       vector->full_pkt->len);
+		if (ret != TEST_SUCCESS)
+			break;
+	}
+
+out:
+	destroy_default_flow(portid);
+
+	/* Clear session data. */
+	for (i = 0; i < burst_sz; i++) {
+		if (out_ips[i].security.ses)
+			rte_security_session_destroy(out_ips[i].security.ctx,
+						     out_ips[i].security.ses);
+		if (in_ips[i].security.ses)
+			rte_security_session_destroy(in_ips[i].security.ctx,
+						     in_ips[i].security.ses);
+	}
+
+	for (i = nb_sent; i < nb_tx; i++)
+		free_mbuf(tx_pkts_burst[i]);
+	for (i = 0; i < nb_rx; i++)
+		free_mbuf(rx_pkts_burst[i]);
+	return ret;
+}
+
 static int
 test_ipsec(struct reassembly_vector *vector,
 	   enum rte_security_ipsec_sa_direction dir,
@@ -732,6 +1024,34 @@ test_ipsec_ipv4_decap_nofrag(void)
 			RTE_SECURITY_IPSEC_TUNNEL_IPV4);
 }
 
+static int
+test_reassembly_ipv4_nofrag(void)
+{
+	struct reassembly_vector ipv4_nofrag_case = {
+				.sa_data = &conf_aes_128_gcm,
+				.full_pkt = &pkt_ipv4_plain,
+				.frags[0] = &pkt_ipv4_plain,
+				.nb_frags = 1,
+	};
+	return test_ipsec_encap_decap(&ipv4_nofrag_case,
+				      RTE_SECURITY_IPSEC_TUNNEL_IPV4);
+}
+
+
+static int
+test_ipsec_ipv4_burst_encap_decap(void)
+{
+	struct reassembly_vector ipv4_nofrag_case = {
+				.sa_data = &conf_aes_128_gcm,
+				.full_pkt = &pkt_ipv4_plain,
+				.frags[0] = &pkt_ipv4_plain,
+				.nb_frags = 1,
+				.burst = true,
+	};
+	return test_ipsec_encap_decap(&ipv4_nofrag_case,
+				      RTE_SECURITY_IPSEC_TUNNEL_IPV4);
+}
+
 static struct unit_test_suite inline_ipsec_testsuite  = {
 	.suite_name = "Inline IPsec Ethernet Device Unit Test Suite",
 	.setup = testsuite_setup,
@@ -743,6 +1063,12 @@ static struct unit_test_suite inline_ipsec_testsuite  = {
 		TEST_CASE_ST(ut_setup_inline_ipsec,
 				ut_teardown_inline_ipsec,
 				test_ipsec_ipv4_decap_nofrag),
+		TEST_CASE_ST(ut_setup_inline_ipsec,
+				ut_teardown_inline_ipsec,
+				test_reassembly_ipv4_nofrag),
+		TEST_CASE_ST(ut_setup_inline_ipsec,
+				ut_teardown_inline_ipsec,
+				test_ipsec_ipv4_burst_encap_decap),
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	}
app/test/test_security_inline_proto_vectors.h +1 -0
index 94d2f0145c..2ee1b3fc41 100644
@@ -42,6 +42,7 @@ struct reassembly_vector {
 	struct ipsec_test_packet *full_pkt;
 	struct ipsec_test_packet *frags[MAX_FRAGS];
 	uint16_t nb_frags;
+	bool burst;
 };
 
 struct ipsec_test_packet pkt_ipv4_plain = {
Signature · 1 line
2.25.1
#44 lore raw

PATCH v3 3/4 app/test: add IP reassembly cases with multiple fragments

In reply to Akhil Goyal

More cases are added in test_inline_ipsec test suite to verify packets having multiple IP(v4/v6) fragments. These fragments are encrypted and then decrypted as per inline IPsec processing and then an attempt is made to reassemble the fragments. The reassembled packet content is matched with the known test vectors.

---
 app/test/test_security_inline_proto.c         | 147 ++++-
 app/test/test_security_inline_proto_vectors.h | 592 ++++++++++++++++++
 2 files changed, 738 insertions(+), 1 deletion(-)
app/test/test_security_inline_proto.c +146 -1
index 3fbf8105e1..9c9e34ca0d 100644
@@ -1037,7 +1037,6 @@ test_reassembly_ipv4_nofrag(void)
 				      RTE_SECURITY_IPSEC_TUNNEL_IPV4);
 }
 
-
 static int
 test_ipsec_ipv4_burst_encap_decap(void)
 {
@@ -1052,6 +1051,134 @@ test_ipsec_ipv4_burst_encap_decap(void)
 				      RTE_SECURITY_IPSEC_TUNNEL_IPV4);
 }
 
+static int
+test_reassembly_ipv4_2frag(void)
+{
+	struct reassembly_vector ipv4_2frag_case = {
+				.sa_data = &conf_aes_128_gcm,
+				.full_pkt = &pkt_ipv4_udp_p1,
+				.frags[0] = &pkt_ipv4_udp_p1_f1,
+				.frags[1] = &pkt_ipv4_udp_p1_f2,
+				.nb_frags = 2,
+	};
+	test_vector_payload_populate(&pkt_ipv4_udp_p1, true);
+	test_vector_payload_populate(&pkt_ipv4_udp_p1_f1, true);
+	test_vector_payload_populate(&pkt_ipv4_udp_p1_f2, false);
+
+	return test_ipsec_encap_decap(&ipv4_2frag_case,
+				      RTE_SECURITY_IPSEC_TUNNEL_IPV4);
+}
+
+static int
+test_reassembly_ipv6_2frag(void)
+{
+	struct reassembly_vector ipv6_2frag_case = {
+				.sa_data = &conf_aes_128_gcm,
+				.full_pkt = &pkt_ipv6_udp_p1,
+				.frags[0] = &pkt_ipv6_udp_p1_f1,
+				.frags[1] = &pkt_ipv6_udp_p1_f2,
+				.nb_frags = 2,
+	};
+	test_vector_payload_populate(&pkt_ipv6_udp_p1, true);
+	test_vector_payload_populate(&pkt_ipv6_udp_p1_f1, true);
+	test_vector_payload_populate(&pkt_ipv6_udp_p1_f2, false);
+
+	return test_ipsec_encap_decap(&ipv6_2frag_case,
+				      RTE_SECURITY_IPSEC_TUNNEL_IPV6);
+}
+
+static int
+test_reassembly_ipv4_4frag(void)
+{
+	struct reassembly_vector ipv4_4frag_case = {
+				.sa_data = &conf_aes_128_gcm,
+				.full_pkt = &pkt_ipv4_udp_p2,
+				.frags[0] = &pkt_ipv4_udp_p2_f1,
+				.frags[1] = &pkt_ipv4_udp_p2_f2,
+				.frags[2] = &pkt_ipv4_udp_p2_f3,
+				.frags[3] = &pkt_ipv4_udp_p2_f4,
+				.nb_frags = 4,
+	};
+	test_vector_payload_populate(&pkt_ipv4_udp_p2, true);
+	test_vector_payload_populate(&pkt_ipv4_udp_p2_f1, true);
+	test_vector_payload_populate(&pkt_ipv4_udp_p2_f2, false);
+	test_vector_payload_populate(&pkt_ipv4_udp_p2_f3, false);
+	test_vector_payload_populate(&pkt_ipv4_udp_p2_f4, false);
+
+	return test_ipsec_encap_decap(&ipv4_4frag_case,
+				      RTE_SECURITY_IPSEC_TUNNEL_IPV4);
+}
+
+static int
+test_reassembly_ipv6_4frag(void)
+{
+	struct reassembly_vector ipv6_4frag_case = {
+				.sa_data = &conf_aes_128_gcm,
+				.full_pkt = &pkt_ipv6_udp_p2,
+				.frags[0] = &pkt_ipv6_udp_p2_f1,
+				.frags[1] = &pkt_ipv6_udp_p2_f2,
+				.frags[2] = &pkt_ipv6_udp_p2_f3,
+				.frags[3] = &pkt_ipv6_udp_p2_f4,
+				.nb_frags = 4,
+	};
+	test_vector_payload_populate(&pkt_ipv6_udp_p2, true);
+	test_vector_payload_populate(&pkt_ipv6_udp_p2_f1, true);
+	test_vector_payload_populate(&pkt_ipv6_udp_p2_f2, false);
+	test_vector_payload_populate(&pkt_ipv6_udp_p2_f3, false);
+	test_vector_payload_populate(&pkt_ipv6_udp_p2_f4, false);
+
+	return test_ipsec_encap_decap(&ipv6_4frag_case,
+				      RTE_SECURITY_IPSEC_TUNNEL_IPV6);
+}
+
+static int
+test_reassembly_ipv4_5frag(void)
+{
+	struct reassembly_vector ipv4_5frag_case = {
+				.sa_data = &conf_aes_128_gcm,
+				.full_pkt = &pkt_ipv4_udp_p3,
+				.frags[0] = &pkt_ipv4_udp_p3_f1,
+				.frags[1] = &pkt_ipv4_udp_p3_f2,
+				.frags[2] = &pkt_ipv4_udp_p3_f3,
+				.frags[3] = &pkt_ipv4_udp_p3_f4,
+				.frags[4] = &pkt_ipv4_udp_p3_f5,
+				.nb_frags = 5,
+	};
+	test_vector_payload_populate(&pkt_ipv4_udp_p3, true);
+	test_vector_payload_populate(&pkt_ipv4_udp_p3_f1, true);
+	test_vector_payload_populate(&pkt_ipv4_udp_p3_f2, false);
+	test_vector_payload_populate(&pkt_ipv4_udp_p3_f3, false);
+	test_vector_payload_populate(&pkt_ipv4_udp_p3_f4, false);
+	test_vector_payload_populate(&pkt_ipv4_udp_p3_f5, false);
+
+	return test_ipsec_encap_decap(&ipv4_5frag_case,
+				      RTE_SECURITY_IPSEC_TUNNEL_IPV4);
+}
+
+static int
+test_reassembly_ipv6_5frag(void)
+{
+	struct reassembly_vector ipv6_5frag_case = {
+				.sa_data = &conf_aes_128_gcm,
+				.full_pkt = &pkt_ipv6_udp_p3,
+				.frags[0] = &pkt_ipv6_udp_p3_f1,
+				.frags[1] = &pkt_ipv6_udp_p3_f2,
+				.frags[2] = &pkt_ipv6_udp_p3_f3,
+				.frags[3] = &pkt_ipv6_udp_p3_f4,
+				.frags[4] = &pkt_ipv6_udp_p3_f5,
+				.nb_frags = 5,
+	};
+	test_vector_payload_populate(&pkt_ipv6_udp_p3, true);
+	test_vector_payload_populate(&pkt_ipv6_udp_p3_f1, true);
+	test_vector_payload_populate(&pkt_ipv6_udp_p3_f2, false);
+	test_vector_payload_populate(&pkt_ipv6_udp_p3_f3, false);
+	test_vector_payload_populate(&pkt_ipv6_udp_p3_f4, false);
+	test_vector_payload_populate(&pkt_ipv6_udp_p3_f5, false);
+
+	return test_ipsec_encap_decap(&ipv6_5frag_case,
+				      RTE_SECURITY_IPSEC_TUNNEL_IPV6);
+}
+
 static struct unit_test_suite inline_ipsec_testsuite  = {
 	.suite_name = "Inline IPsec Ethernet Device Unit Test Suite",
 	.setup = testsuite_setup,
@@ -1069,6 +1196,24 @@ static struct unit_test_suite inline_ipsec_testsuite  = {
 		TEST_CASE_ST(ut_setup_inline_ipsec,
 				ut_teardown_inline_ipsec,
 				test_ipsec_ipv4_burst_encap_decap),
+		TEST_CASE_ST(ut_setup_inline_ipsec,
+				ut_teardown_inline_ipsec,
+				test_reassembly_ipv4_2frag),
+		TEST_CASE_ST(ut_setup_inline_ipsec,
+				ut_teardown_inline_ipsec,
+				test_reassembly_ipv6_2frag),
+		TEST_CASE_ST(ut_setup_inline_ipsec,
+				ut_teardown_inline_ipsec,
+				test_reassembly_ipv4_4frag),
+		TEST_CASE_ST(ut_setup_inline_ipsec,
+				ut_teardown_inline_ipsec,
+				test_reassembly_ipv6_4frag),
+		TEST_CASE_ST(ut_setup_inline_ipsec,
+				ut_teardown_inline_ipsec,
+				test_reassembly_ipv4_5frag),
+		TEST_CASE_ST(ut_setup_inline_ipsec,
+				ut_teardown_inline_ipsec,
+				test_reassembly_ipv6_5frag),
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	}
app/test/test_security_inline_proto_vectors.h +592 -0

604 lines not on this page · raw message

Signature · 1 line
2.25.1
#45 lore raw

PATCH v3 4/4 app/test: add IP reassembly negative cases

In reply to Akhil Goyal

test_inline_ipsec testsuite is added with cases where the IP reassembly is incomplete and software will need to reassemble them later. The failure cases added are:
- all fragments are not received.
- same fragment is received more than once.
- out of order fragments.

---
 app/test/test_security_inline_proto.c | 71 +++++++++++++++++++++++++++
 1 file changed, 71 insertions(+)
app/test/test_security_inline_proto.c +71 -0
index 9c9e34ca0d..cae8b083bc 100644
@@ -1179,6 +1179,68 @@ test_reassembly_ipv6_5frag(void)
 				      RTE_SECURITY_IPSEC_TUNNEL_IPV6);
 }
 
+static int
+test_reassembly_incomplete(void)
+{
+	/* Negative test case, not sending all fragments. */
+	struct reassembly_vector ipv4_incomplete_case = {
+				.sa_data = &conf_aes_128_gcm,
+				.full_pkt = &pkt_ipv4_udp_p2,
+				.frags[0] = &pkt_ipv4_udp_p2_f1,
+				.frags[1] = &pkt_ipv4_udp_p2_f2,
+				.nb_frags = 2,
+	};
+	test_vector_payload_populate(&pkt_ipv4_udp_p2, true);
+	test_vector_payload_populate(&pkt_ipv4_udp_p2_f1, true);
+	test_vector_payload_populate(&pkt_ipv4_udp_p2_f2, false);
+
+	return test_ipsec_encap_decap(&ipv4_incomplete_case,
+				      RTE_SECURITY_IPSEC_TUNNEL_IPV4);
+}
+
+static int
+test_reassembly_overlap(void)
+{
+	/* Negative test case, sending 1 fragment twice. */
+	struct reassembly_vector ipv4_overlap_case = {
+				.sa_data = &conf_aes_128_gcm,
+				.full_pkt = &pkt_ipv4_udp_p1,
+				.frags[0] = &pkt_ipv4_udp_p1_f1,
+				.frags[1] = &pkt_ipv4_udp_p1_f1, /* Overlap */
+				.frags[2] = &pkt_ipv4_udp_p1_f2,
+				.nb_frags = 3,
+	};
+	test_vector_payload_populate(&pkt_ipv4_udp_p2, true);
+	test_vector_payload_populate(&pkt_ipv4_udp_p2_f1, true);
+	test_vector_payload_populate(&pkt_ipv4_udp_p2_f2, false);
+
+	return test_ipsec_encap_decap(&ipv4_overlap_case,
+				      RTE_SECURITY_IPSEC_TUNNEL_IPV4);
+}
+
+static int
+test_reassembly_out_of_order(void)
+{
+	/* Negative test case, out of order fragments. */
+	struct reassembly_vector ipv4_ooo_case = {
+				.sa_data = &conf_aes_128_gcm,
+				.full_pkt = &pkt_ipv4_udp_p2,
+				.frags[0] = &pkt_ipv4_udp_p2_f1,
+				.frags[1] = &pkt_ipv4_udp_p2_f3,
+				.frags[2] = &pkt_ipv4_udp_p2_f4,
+				.frags[3] = &pkt_ipv4_udp_p2_f2,
+				.nb_frags = 4,
+	};
+	test_vector_payload_populate(&pkt_ipv4_udp_p2, true);
+	test_vector_payload_populate(&pkt_ipv4_udp_p2_f1, true);
+	test_vector_payload_populate(&pkt_ipv4_udp_p2_f2, false);
+	test_vector_payload_populate(&pkt_ipv4_udp_p2_f3, false);
+	test_vector_payload_populate(&pkt_ipv4_udp_p2_f4, false);
+
+	return test_ipsec_encap_decap(&ipv4_ooo_case,
+				      RTE_SECURITY_IPSEC_TUNNEL_IPV4);
+}
+
 static struct unit_test_suite inline_ipsec_testsuite  = {
 	.suite_name = "Inline IPsec Ethernet Device Unit Test Suite",
 	.setup = testsuite_setup,
@@ -1214,6 +1276,15 @@ static struct unit_test_suite inline_ipsec_testsuite  = {
 		TEST_CASE_ST(ut_setup_inline_ipsec,
 				ut_teardown_inline_ipsec,
 				test_reassembly_ipv6_5frag),
+		TEST_CASE_ST(ut_setup_inline_ipsec,
+				ut_teardown_inline_ipsec,
+				test_reassembly_incomplete),
+		TEST_CASE_ST(ut_setup_inline_ipsec,
+				ut_teardown_inline_ipsec,
+				test_reassembly_overlap),
+		TEST_CASE_ST(ut_setup_inline_ipsec,
+				ut_teardown_inline_ipsec,
+				test_reassembly_out_of_order),
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	}
Signature · 1 line
2.25.1
#46 lore raw

v4 cover app/test: add inline IPsec and reassembly cases

In reply to Akhil Goyal

IP reassembly offload was added in last release. The test app for unit testing IP reassembly of inline inbound IPsec flows is added in this patchset.
For testing IP reassembly, base inline IPsec is also added. The app is enhanced in v4 to handle more functional unit test cases for inline IPsec similar to Lookaside IPsec. The functions from Lookaside more are reused to verify functional cases.

Changes in v4:
- rebased over next-crypto
- updated app to take benefit from Lookaside protocol test functions.
- Added more functional cases
- Added soft and hard expiry event subtypes in ethdev for testing SA soft and hard pkt/byte expiry events.
- reassembly cases are squashed in a single patch

Changes in v3:
- incorporated latest ethdev changes for reassembly.
- skipped build on windows as it needs rte_ipsec lib which is not compiled on windows.
changes in v2:
- added IPsec burst mode case
- updated as per the latest ethdev changes.

Akhil Goyal (6):
app/test: add unit cases for inline IPsec offload test/security: add inline inbound IPsec cases test/security: add combined mode inline IPsec cases test/security: add inline IPsec reassembly cases test/security: add more inline IPsec functional cases test/security: add ESN and anti-replay cases for inline

Vamsi Attunuru (4):
ethdev: add IPsec SA expiry event subtypes test/security: add inline IPsec SA soft expiry cases test/security: add inline IPsec SA hard expiry cases test/security: add inline IPsec IPv6 flow label cases

 MAINTAINERS                                   |    2 +-
 app/test/meson.build                          |    1 +
 app/test/test_cryptodev_security_ipsec.c      |   35 +-
 app/test/test_cryptodev_security_ipsec.h      |   12 +
 app/test/test_security_inline_proto.c         | 2525 +++++++++++++++++
 app/test/test_security_inline_proto_vectors.h |  710 +++++
 lib/ethdev/rte_ethdev.h                       |    9 +
 7 files changed, 3292 insertions(+), 2 deletions(-)
 create mode 100644 app/test/test_security_inline_proto.c
 create mode 100644 app/test/test_security_inline_proto_vectors.h
Signature · 1 line
2.25.1
#47 lore raw

PATCH v4 1/10 app/test: add unit cases for inline IPsec offload

A new test suite is added in test app to test inline IPsec protocol offload. In this patch, predefined vectors from Lookaside IPsec test are used to verify the IPsec functionality without the need of external traffic generators. The sent packet is loopbacked onto the same interface which is received and matched with the expected output. The test suite can be updated further with other functional test cases. In this patch encap only cases are added.
The testsuite can be run using:
RTE> inline_ipsec_autotest

---
 MAINTAINERS                                   |   2 +-
 app/test/meson.build                          |   1 +
 app/test/test_security_inline_proto.c         | 881 ++++++++++++++++++
 app/test/test_security_inline_proto_vectors.h |  20 +
 4 files changed, 903 insertions(+), 1 deletion(-)
 create mode 100644 app/test/test_security_inline_proto.c
 create mode 100644 app/test/test_security_inline_proto_vectors.h
MAINTAINERS +1 -1
index 15008c03bc..89affa08ff 100644
@@ -440,7 +440,7 @@ M: Akhil Goyal <[email protected]>
 T: git://dpdk.org/next/dpdk-next-crypto
 F: lib/security/
 F: doc/guides/prog_guide/rte_security.rst
-F: app/test/test_security.c
+F: app/test/test_security*
 
 Compression API - EXPERIMENTAL
 M: Fan Zhang <[email protected]>
app/test/meson.build +1 -0
index 5fc1dd1b7b..39952c6c4f 100644
@@ -125,6 +125,7 @@ test_sources = files(
         'test_rwlock.c',
         'test_sched.c',
         'test_security.c',
+        'test_security_inline_proto.c',
         'test_service_cores.c',
         'test_spinlock.c',
         'test_stack.c',
app/test/test_security_inline_proto.c new file +881 -0

881 lines not on this page · raw message

app/test/test_security_inline_proto_vectors.h new file +20 -0
new file mode 100644
index 0000000000..d1074da36a
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2022 Marvell.
+ */
+#ifndef _TEST_INLINE_IPSEC_REASSEMBLY_VECTORS_H_
+#define _TEST_INLINE_IPSEC_REASSEMBLY_VECTORS_H_
+
+#include "test_cryptodev_security_ipsec.h"
+
+uint8_t dummy_ipv4_eth_hdr[] = {
+		/* ETH */
+		0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1,
+		0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0x08, 0x00,
+};
+uint8_t dummy_ipv6_eth_hdr[] = {
+		/* ETH */
+		0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1,
+		0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0x86, 0xdd,
+};
+
+#endif
Signature · 1 line
2.25.1
#48 lore raw

PATCH v4 2/10 test/security: add inline inbound IPsec cases

In reply to Akhil Goyal

Added test cases for inline Inbound protocol offload verification with known test vectors from Lookaside mode.

---
 app/test/test_security_inline_proto.c | 65 +++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)
app/test/test_security_inline_proto.c +65 -0
index aeb5a57aca..fc0525479c 100644
@@ -818,6 +818,24 @@ test_ipsec_inline_proto_known_vec(const void *test_data)
 				false, &flags);
 }
 
+static int
+test_ipsec_inline_proto_known_vec_inb(const void *test_data)
+{
+	const struct ipsec_test_data *td = test_data;
+	struct ipsec_test_flags flags;
+	struct ipsec_test_data td_inb;
+
+	memset(&flags, 0, sizeof(flags));
+
+	if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS)
+		test_ipsec_td_in_from_out(td, &td_inb);
+	else
+		memcpy(&td_inb, td, sizeof(td_inb));
+
+	return test_ipsec_inline_proto_process(&td_inb, NULL, 1, false, &flags);
+}
+
+
 static struct unit_test_suite inline_ipsec_testsuite  = {
 	.suite_name = "Inline IPsec Ethernet Device Unit Test Suite",
 	.setup = inline_ipsec_testsuite_setup,
@@ -864,6 +882,53 @@ static struct unit_test_suite inline_ipsec_testsuite  = {
 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
 			test_ipsec_inline_proto_known_vec,
 			&pkt_null_aes_xcbc),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 128)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_inb, &pkt_aes_128_gcm),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 192)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_inb, &pkt_aes_192_gcm),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 256)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_inb, &pkt_aes_256_gcm),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_inb, &pkt_aes_128_cbc_null),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA256 [16B ICV])",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_inb,
+			&pkt_aes_128_cbc_hmac_sha256),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA384 [24B ICV])",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_inb,
+			&pkt_aes_128_cbc_hmac_sha384),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA512 [32B ICV])",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_inb,
+			&pkt_aes_128_cbc_hmac_sha512),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Inbound known vector (ESP tunnel mode IPv6 AES-GCM 128)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_inb, &pkt_aes_256_gcm_v6),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Inbound known vector (ESP tunnel mode IPv6 AES-CBC 128 HMAC-SHA256 [16B ICV])",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_inb,
+			&pkt_aes_128_cbc_hmac_sha256_v6),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Inbound known vector (ESP tunnel mode IPv4 NULL AES-XCBC-MAC [12B ICV])",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_inb,
+			&pkt_null_aes_xcbc),
+
+
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	},
Signature · 1 line
2.25.1
#49 lore raw

PATCH v4 3/10 test/security: add combined mode inline IPsec cases

In reply to Akhil Goyal

Added combined encap and decap test cases for various algorithm combinations

---
 app/test/test_security_inline_proto.c | 102 ++++++++++++++++++++++++++
 1 file changed, 102 insertions(+)
app/test/test_security_inline_proto.c +102 -0
index fc0525479c..890bc10115 100644
@@ -661,6 +661,92 @@ test_ipsec_inline_proto_process(struct ipsec_test_data *td,
 	return ret;
 }
 
+static int
+test_ipsec_inline_proto_all(const struct ipsec_test_flags *flags)
+{
+	struct ipsec_test_data td_outb;
+	struct ipsec_test_data td_inb;
+	unsigned int i, nb_pkts = 1, pass_cnt = 0, fail_cnt = 0;
+	int ret;
+
+	if (flags->iv_gen || flags->sa_expiry_pkts_soft ||
+			flags->sa_expiry_pkts_hard)
+		nb_pkts = IPSEC_TEST_PACKETS_MAX;
+
+	for (i = 0; i < RTE_DIM(alg_list); i++) {
+		test_ipsec_td_prepare(alg_list[i].param1,
+				      alg_list[i].param2,
+				      flags, &td_outb, 1);
+
+		if (!td_outb.aead) {
+			enum rte_crypto_cipher_algorithm cipher_alg;
+			enum rte_crypto_auth_algorithm auth_alg;
+
+			cipher_alg = td_outb.xform.chain.cipher.cipher.algo;
+			auth_alg = td_outb.xform.chain.auth.auth.algo;
+
+			if (td_outb.aes_gmac && cipher_alg != RTE_CRYPTO_CIPHER_NULL)
+				continue;
+
+			/* ICV is not applicable for NULL auth */
+			if (flags->icv_corrupt &&
+			    auth_alg == RTE_CRYPTO_AUTH_NULL)
+				continue;
+
+			/* IV is not applicable for NULL cipher */
+			if (flags->iv_gen &&
+			    cipher_alg == RTE_CRYPTO_CIPHER_NULL)
+				continue;
+		}
+
+		if (flags->udp_encap)
+			td_outb.ipsec_xform.options.udp_encap = 1;
+
+		ret = test_ipsec_inline_proto_process(&td_outb, &td_inb, nb_pkts,
+						false, flags);
+		if (ret == TEST_SKIPPED)
+			continue;
+
+		if (ret == TEST_FAILED) {
+			printf("\n TEST FAILED");
+			test_ipsec_display_alg(alg_list[i].param1,
+					       alg_list[i].param2);
+			fail_cnt++;
+			continue;
+		}
+
+		test_ipsec_td_update(&td_inb, &td_outb, 1, flags);
+
+		ret = test_ipsec_inline_proto_process(&td_inb, NULL, nb_pkts,
+						false, flags);
+		if (ret == TEST_SKIPPED)
+			continue;
+
+		if (ret == TEST_FAILED) {
+			printf("\n TEST FAILED");
+			test_ipsec_display_alg(alg_list[i].param1,
+					       alg_list[i].param2);
+			fail_cnt++;
+			continue;
+		}
+
+		if (flags->display_alg)
+			test_ipsec_display_alg(alg_list[i].param1,
+					       alg_list[i].param2);
+
+		pass_cnt++;
+	}
+
+	printf("Tests passed: %d, failed: %d", pass_cnt, fail_cnt);
+	if (fail_cnt > 0)
+		return TEST_FAILED;
+	if (pass_cnt > 0)
+		return TEST_SUCCESS;
+	else
+		return TEST_SKIPPED;
+}
+
+
 static int
 ut_setup_inline_ipsec(void)
 {
@@ -835,6 +921,17 @@ test_ipsec_inline_proto_known_vec_inb(const void *test_data)
 	return test_ipsec_inline_proto_process(&td_inb, NULL, 1, false, &flags);
 }
 
+static int
+test_ipsec_inline_proto_display_list(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.display_alg = true;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
 
 static struct unit_test_suite inline_ipsec_testsuite  = {
 	.suite_name = "Inline IPsec Ethernet Device Unit Test Suite",
@@ -928,6 +1025,11 @@ static struct unit_test_suite inline_ipsec_testsuite  = {
 			test_ipsec_inline_proto_known_vec_inb,
 			&pkt_null_aes_xcbc),
 
+		TEST_CASE_NAMED_ST(
+			"Combined test alg list",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_display_list),
+
 
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
Signature · 1 line
2.25.1
#50 lore raw

PATCH v4 4/10 test/security: add inline IPsec reassembly cases

In reply to Akhil Goyal

Added unit test cases for IP reassembly of inline IPsec inbound scenarios.
In these cases, known test vectors of fragments are first processed for inline outbound processing and then received back on loopback interface for inbound processing along with IP reassembly of the corresponding decrypted packets. The resultant plain text reassembled packet is compared with original unfragmented packet.

In this patch, cases are added for 2/4/5 fragments for both IPv4 and IPv6 packets. A few negative test cases are also added like incomplete fragments, out of place fragments, duplicate fragments.

---
 app/test/test_security_inline_proto.c         | 421 ++++++++++-
 app/test/test_security_inline_proto_vectors.h | 684 ++++++++++++++++++
 2 files changed, 1104 insertions(+), 1 deletion(-)
app/test/test_security_inline_proto.c +420 -1
index 890bc10115..9ddc3f7dd4 100644
@@ -41,6 +41,9 @@ test_inline_ipsec(void)
 #define MAX_TRAFFIC_BURST		2048
 #define NB_MBUF				10240
 
+#define ENCAP_DECAP_BURST_SZ		33
+#define APP_REASS_TIMEOUT		10
+
 extern struct ipsec_test_data pkt_aes_128_gcm;
 extern struct ipsec_test_data pkt_aes_192_gcm;
 extern struct ipsec_test_data pkt_aes_256_gcm;
@@ -94,6 +97,8 @@ uint16_t port_id;
 
 static uint64_t link_mbps;
 
+static int ip_reassembly_dynfield_offset = -1;
+
 static struct rte_flow *default_flow[RTE_MAX_ETHPORTS];
 
 /* Create Inline IPsec session */
@@ -528,6 +533,347 @@ destroy_default_flow(uint16_t portid)
 struct rte_mbuf **tx_pkts_burst;
 struct rte_mbuf **rx_pkts_burst;
 
+static int
+compare_pkt_data(struct rte_mbuf *m, uint8_t *ref, unsigned int tot_len)
+{
+	unsigned int len;
+	unsigned int nb_segs = m->nb_segs;
+	unsigned int matched = 0;
+	struct rte_mbuf *save = m;
+
+	while (m) {
+		len = tot_len;
+		if (len > m->data_len)
+			len = m->data_len;
+		if (len != 0) {
+			if (memcmp(rte_pktmbuf_mtod(m, char *),
+					ref + matched, len)) {
+				printf("\n====Reassembly case failed: Data Mismatch");
+				rte_hexdump(stdout, "Reassembled",
+					rte_pktmbuf_mtod(m, char *),
+					len);
+				rte_hexdump(stdout, "reference",
+					ref + matched,
+					len);
+				return TEST_FAILED;
+			}
+		}
+		tot_len -= len;
+		matched += len;
+		m = m->next;
+	}
+
+	if (tot_len) {
+		printf("\n====Reassembly case failed: Data Missing %u",
+		       tot_len);
+		printf("\n====nb_segs %u, tot_len %u", nb_segs, tot_len);
+		rte_pktmbuf_dump(stderr, save, -1);
+		return TEST_FAILED;
+	}
+	return TEST_SUCCESS;
+}
+
+static inline bool
+is_ip_reassembly_incomplete(struct rte_mbuf *mbuf)
+{
+	static uint64_t ip_reassembly_dynflag;
+	int ip_reassembly_dynflag_offset;
+
+	if (ip_reassembly_dynflag == 0) {
+		ip_reassembly_dynflag_offset = rte_mbuf_dynflag_lookup(
+			RTE_MBUF_DYNFLAG_IP_REASSEMBLY_INCOMPLETE_NAME, NULL);
+		if (ip_reassembly_dynflag_offset < 0)
+			return false;
+		ip_reassembly_dynflag = RTE_BIT64(ip_reassembly_dynflag_offset);
+	}
+
+	return (mbuf->ol_flags & ip_reassembly_dynflag) != 0;
+}
+
+static void
+free_mbuf(struct rte_mbuf *mbuf)
+{
+	rte_eth_ip_reassembly_dynfield_t dynfield;
+
+	if (!mbuf)
+		return;
+
+	if (!is_ip_reassembly_incomplete(mbuf)) {
+		rte_pktmbuf_free(mbuf);
+	} else {
+		if (ip_reassembly_dynfield_offset < 0)
+			return;
+
+		while (mbuf) {
+			dynfield = *RTE_MBUF_DYNFIELD(mbuf,
+					ip_reassembly_dynfield_offset,
+					rte_eth_ip_reassembly_dynfield_t *);
+			rte_pktmbuf_free(mbuf);
+			mbuf = dynfield.next_frag;
+		}
+	}
+}
+
+
+static int
+get_and_verify_incomplete_frags(struct rte_mbuf *mbuf,
+				struct reassembly_vector *vector)
+{
+	rte_eth_ip_reassembly_dynfield_t *dynfield[MAX_PKT_BURST];
+	int j = 0, ret;
+	/**
+	 * IP reassembly offload is incomplete, and fragments are listed in
+	 * dynfield which can be reassembled in SW.
+	 */
+	printf("\nHW IP Reassembly is not complete; attempt SW IP Reassembly,"
+		"\nMatching with original frags.");
+
+	if (ip_reassembly_dynfield_offset < 0)
+		return -1;
+
+	printf("\ncomparing frag: %d", j);
+	/* Skip Ethernet header comparison */
+	rte_pktmbuf_adj(mbuf, RTE_ETHER_HDR_LEN);
+	ret = compare_pkt_data(mbuf, vector->frags[j]->data,
+				vector->frags[j]->len);
+	if (ret)
+		return ret;
+	j++;
+	dynfield[j] = RTE_MBUF_DYNFIELD(mbuf, ip_reassembly_dynfield_offset,
+					rte_eth_ip_reassembly_dynfield_t *);
+	printf("\ncomparing frag: %d", j);
+	/* Skip Ethernet header comparison */
+	rte_pktmbuf_adj(dynfield[j]->next_frag, RTE_ETHER_HDR_LEN);
+	ret = compare_pkt_data(dynfield[j]->next_frag, vector->frags[j]->data,
+			vector->frags[j]->len);
+	if (ret)
+		return ret;
+
+	while ((dynfield[j]->nb_frags > 1) &&
+			is_ip_reassembly_incomplete(dynfield[j]->next_frag)) {
+		j++;
+		dynfield[j] = RTE_MBUF_DYNFIELD(dynfield[j-1]->next_frag,
+					ip_reassembly_dynfield_offset,
+					rte_eth_ip_reassembly_dynfield_t *);
+		printf("\ncomparing frag: %d", j);
+		/* Skip Ethernet header comparison */
+		rte_pktmbuf_adj(dynfield[j]->next_frag, RTE_ETHER_HDR_LEN);
+		ret = compare_pkt_data(dynfield[j]->next_frag,
+				vector->frags[j]->data, vector->frags[j]->len);
+		if (ret)
+			return ret;
+	}
+	return ret;
+}
+
+static int
+test_ipsec_with_reassembly(struct reassembly_vector *vector,
+		const struct ipsec_test_flags *flags)
+{
+	struct rte_security_session *out_ses[ENCAP_DECAP_BURST_SZ] = {0};
+	struct rte_security_session *in_ses[ENCAP_DECAP_BURST_SZ] = {0};
+	struct rte_eth_ip_reassembly_params reass_capa = {0};
+	struct rte_security_session_conf sess_conf_out = {0};
+	struct rte_security_session_conf sess_conf_in = {0};
+	unsigned int nb_tx, burst_sz, nb_sent = 0;
+	struct rte_crypto_sym_xform cipher_out = {0};
+	struct rte_crypto_sym_xform auth_out = {0};
+	struct rte_crypto_sym_xform aead_out = {0};
+	struct rte_crypto_sym_xform cipher_in = {0};
+	struct rte_crypto_sym_xform auth_in = {0};
+	struct rte_crypto_sym_xform aead_in = {0};
+	struct ipsec_test_data sa_data = {0};
+	struct rte_security_ctx *ctx;
+	unsigned int i, nb_rx = 0, j;
+	uint32_t ol_flags;
+	int ret = 0;
+
+	burst_sz = vector->burst ? ENCAP_DECAP_BURST_SZ : 1;
+	nb_tx = vector->nb_frags * burst_sz;
+
+	rte_eth_dev_stop(port_id);
+	if (ret != 0) {
+		printf("rte_eth_dev_stop: err=%s, port=%u\n",
+			       rte_strerror(-ret), port_id);
+		return ret;
+	}
+	rte_eth_ip_reassembly_capability_get(port_id, &reass_capa);
+	if (reass_capa.max_frags < vector->nb_frags)
+		return TEST_SKIPPED;
+	if (reass_capa.timeout_ms > APP_REASS_TIMEOUT) {
+		reass_capa.timeout_ms = APP_REASS_TIMEOUT;
+		rte_eth_ip_reassembly_conf_set(port_id, &reass_capa);
+	}
+
+	ret = rte_eth_dev_start(port_id);
+	if (ret < 0) {
+		printf("rte_eth_dev_start: err=%d, port=%d\n",
+			ret, port_id);
+		return ret;
+	}
+
+	memset(tx_pkts_burst, 0, sizeof(tx_pkts_burst[0]) * nb_tx);
+	memset(rx_pkts_burst, 0, sizeof(rx_pkts_burst[0]) * nb_tx);
+
+	for (i = 0; i < nb_tx; i += vector->nb_frags) {
+		for (j = 0; j < vector->nb_frags; j++) {
+			tx_pkts_burst[i+j] = init_packet(mbufpool,
+						vector->frags[j]->data,
+						vector->frags[j]->len);
+			if (tx_pkts_burst[i+j] == NULL) {
+				ret = -1;
+				printf("\n packed init failed\n");
+				goto out;
+			}
+		}
+	}
+
+	for (i = 0; i < burst_sz; i++) {
+		memcpy(&sa_data, vector->sa_data,
+				sizeof(struct ipsec_test_data));
+		/* Update SPI for every new SA */
+		sa_data.ipsec_xform.spi += i;
+		sa_data.ipsec_xform.direction =
+					RTE_SECURITY_IPSEC_SA_DIR_EGRESS;
+		if (sa_data.aead) {
+			sess_conf_out.crypto_xform = &aead_out;
+		} else {
+			sess_conf_out.crypto_xform = &cipher_out;
+			sess_conf_out.crypto_xform->next = &auth_out;
+		}
+
+		/* Create Inline IPsec outbound session. */
+		ret = create_inline_ipsec_session(&sa_data, port_id,
+				&out_ses[i], &ctx, &ol_flags, flags,
+				&sess_conf_out);
+		if (ret) {
+			printf("\nInline outbound session create failed\n");
+			goto out;
+		}
+	}
+
+	j = 0;
+	for (i = 0; i < nb_tx; i++) {
+		if (ol_flags & RTE_SECURITY_TX_OLOAD_NEED_MDATA)
+			rte_security_set_pkt_metadata(ctx,
+				out_ses[j], tx_pkts_burst[i], NULL);
+		tx_pkts_burst[i]->ol_flags |= RTE_MBUF_F_TX_SEC_OFFLOAD;
+
+		/* Move to next SA after nb_frags */
+		if ((i + 1) % vector->nb_frags == 0)
+			j++;
+	}
+
+	for (i = 0; i < burst_sz; i++) {
+		memcpy(&sa_data, vector->sa_data,
+				sizeof(struct ipsec_test_data));
+		/* Update SPI for every new SA */
+		sa_data.ipsec_xform.spi += i;
+		sa_data.ipsec_xform.direction =
+					RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
+
+		if (sa_data.aead) {
+			sess_conf_in.crypto_xform = &aead_in;
+		} else {
+			sess_conf_in.crypto_xform = &auth_in;
+			sess_conf_in.crypto_xform->next = &cipher_in;
+		}
+		/* Create Inline IPsec inbound session. */
+		ret = create_inline_ipsec_session(&sa_data, port_id, &in_ses[i],
+				&ctx, &ol_flags, flags, &sess_conf_in);
+		if (ret) {
+			printf("\nInline inbound session create failed\n");
+			goto out;
+		}
+	}
+
+	/* Retrieve reassembly dynfield offset if available */
+	if (ip_reassembly_dynfield_offset < 0 && vector->nb_frags > 1)
+		ip_reassembly_dynfield_offset = rte_mbuf_dynfield_lookup(
+				RTE_MBUF_DYNFIELD_IP_REASSEMBLY_NAME, NULL);
+
+
+	create_default_flow(port_id);
+
+	nb_sent = rte_eth_tx_burst(port_id, 0, tx_pkts_burst, nb_tx);
+	if (nb_sent != nb_tx) {
+		ret = -1;
+		printf("\nFailed to tx %u pkts", nb_tx);
+		goto out;
+	}
+
+	rte_delay_ms(1);
+
+	/* Retry few times before giving up */
+	nb_rx = 0;
+	j = 0;
+	do {
+		nb_rx += rte_eth_rx_burst(port_id, 0, &rx_pkts_burst[nb_rx],
+					  nb_tx - nb_rx);
+		j++;
+		if (nb_rx >= nb_tx)
+			break;
+		rte_delay_ms(1);
+	} while (j < 5 || !nb_rx);
+
+	/* Check for minimum number of Rx packets expected */
+	if ((vector->nb_frags == 1 && nb_rx != nb_tx) ||
+	    (vector->nb_frags > 1 && nb_rx < burst_sz)) {
+		printf("\nreceived less Rx pkts(%u) pkts\n", nb_rx);
+		ret = TEST_FAILED;
+		goto out;
+	}
+
+	for (i = 0; i < nb_rx; i++) {
+		if (vector->nb_frags > 1 &&
+		    is_ip_reassembly_incomplete(rx_pkts_burst[i])) {
+			ret = get_and_verify_incomplete_frags(rx_pkts_burst[i],
+							      vector);
+			if (ret != TEST_SUCCESS)
+				break;
+			continue;
+		}
+
+		if (rx_pkts_burst[i]->ol_flags &
+		    RTE_MBUF_F_RX_SEC_OFFLOAD_FAILED ||
+		    !(rx_pkts_burst[i]->ol_flags & RTE_MBUF_F_RX_SEC_OFFLOAD)) {
+			printf("\nsecurity offload failed\n");
+			ret = TEST_FAILED;
+			break;
+		}
+
+		if (vector->full_pkt->len + RTE_ETHER_HDR_LEN !=
+				rx_pkts_burst[i]->pkt_len) {
+			printf("\nreassembled/decrypted packet length mismatch\n");
+			ret = TEST_FAILED;
+			break;
+		}
+		rte_pktmbuf_adj(rx_pkts_burst[i], RTE_ETHER_HDR_LEN);
+		ret = compare_pkt_data(rx_pkts_burst[i],
+				       vector->full_pkt->data,
+				       vector->full_pkt->len);
+		if (ret != TEST_SUCCESS)
+			break;
+	}
+
+out:
+	destroy_default_flow(port_id);
+
+	/* Clear session data. */
+	for (i = 0; i < burst_sz; i++) {
+		if (out_ses[i])
+			rte_security_session_destroy(ctx, out_ses[i]);
+		if (in_ses[i])
+			rte_security_session_destroy(ctx, in_ses[i]);
+	}
+
+	for (i = nb_sent; i < nb_tx; i++)
+		free_mbuf(tx_pkts_burst[i]);
+	for (i = 0; i < nb_rx; i++)
+		free_mbuf(rx_pkts_burst[i]);
+	return ret;
+}
+
 static int
 test_ipsec_inline_proto_process(struct ipsec_test_data *td,
 		struct ipsec_test_data *res_d,
@@ -775,6 +1121,7 @@ ut_setup_inline_ipsec(void)
 static void
 ut_teardown_inline_ipsec(void)
 {
+	struct rte_eth_ip_reassembly_params reass_conf = {0};
 	uint16_t portid;
 	int ret;
 
@@ -784,6 +1131,9 @@ ut_teardown_inline_ipsec(void)
 		if (ret != 0)
 			printf("rte_eth_dev_stop: err=%s, port=%u\n",
 			       rte_strerror(-ret), portid);
+
+		/* Clear reassembly configuration */
+		rte_eth_ip_reassembly_conf_set(portid, &reass_conf);
 	}
 }
 
@@ -884,6 +1234,36 @@ inline_ipsec_testsuite_teardown(void)
 	}
 }
 
+static int
+test_inline_ip_reassembly(const void *testdata)
+{
+	struct reassembly_vector reassembly_td = {0};
+	const struct reassembly_vector *td = testdata;
+	struct ip_reassembly_test_packet full_pkt;
+	struct ip_reassembly_test_packet frags[MAX_FRAGS];
+	struct ipsec_test_flags flags = {0};
+	int i = 0;
+
+	reassembly_td.sa_data = td->sa_data;
+	reassembly_td.nb_frags = td->nb_frags;
+	reassembly_td.burst = td->burst;
+
+	memcpy(&full_pkt, td->full_pkt,
+			sizeof(struct ip_reassembly_test_packet));
+	reassembly_td.full_pkt = &full_pkt;
+
+	test_vector_payload_populate(reassembly_td.full_pkt, true);
+	for (; i < reassembly_td.nb_frags; i++) {
+		memcpy(&frags[i], td->frags[i],
+			sizeof(struct ip_reassembly_test_packet));
+		reassembly_td.frags[i] = &frags[i];
+		test_vector_payload_populate(reassembly_td.frags[i],
+				(i == 0) ? true : false);
+	}
+
+	return test_ipsec_with_reassembly(&reassembly_td, &flags);
+}
+
 static int
 test_ipsec_inline_proto_known_vec(const void *test_data)
 {
@@ -1030,7 +1410,46 @@ static struct unit_test_suite inline_ipsec_testsuite  = {
 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
 			test_ipsec_inline_proto_display_list),
 
-
+		TEST_CASE_NAMED_WITH_DATA(
+			"IPv4 Reassembly with 2 fragments",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_inline_ip_reassembly, &ipv4_2frag_vector),
+		TEST_CASE_NAMED_WITH_DATA(
+			"IPv6 Reassembly with 2 fragments",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_inline_ip_reassembly, &ipv6_2frag_vector),
+		TEST_CASE_NAMED_WITH_DATA(
+			"IPv4 Reassembly with 4 fragments",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_inline_ip_reassembly, &ipv4_4frag_vector),
+		TEST_CASE_NAMED_WITH_DATA(
+			"IPv6 Reassembly with 4 fragments",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_inline_ip_reassembly, &ipv6_4frag_vector),
+		TEST_CASE_NAMED_WITH_DATA(
+			"IPv4 Reassembly with 5 fragments",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_inline_ip_reassembly, &ipv4_5frag_vector),
+		TEST_CASE_NAMED_WITH_DATA(
+			"IPv6 Reassembly with 5 fragments",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_inline_ip_reassembly, &ipv6_5frag_vector),
+		TEST_CASE_NAMED_WITH_DATA(
+			"IPv4 Reassembly with incomplete fragments",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_inline_ip_reassembly, &ipv4_incomplete_vector),
+		TEST_CASE_NAMED_WITH_DATA(
+			"IPv4 Reassembly with overlapping fragments",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_inline_ip_reassembly, &ipv4_overlap_vector),
+		TEST_CASE_NAMED_WITH_DATA(
+			"IPv4 Reassembly with out of order fragments",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_inline_ip_reassembly, &ipv4_out_of_order_vector),
+		TEST_CASE_NAMED_WITH_DATA(
+			"IPv4 Reassembly with burst of 4 fragments",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_inline_ip_reassembly, &ipv4_4frag_burst_vector),
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	},
app/test/test_security_inline_proto_vectors.h +684 -0

688 lines not on this page · raw message

Signature · 1 line
2.25.1
#51 lore raw

PATCH v4 5/10 test/security: add more inline IPsec functional cases

In reply to Akhil Goyal

Added more inline IPsec functional verification cases. These cases do not have known vectors but are verified using encap + decap test for all the algo combinations.

---
 app/test/test_security_inline_proto.c | 517 ++++++++++++++++++++++++++
 1 file changed, 517 insertions(+)
app/test/test_security_inline_proto.c +517 -0
index 9ddc3f7dd4..209999d02c 100644
@@ -1313,6 +1313,394 @@ test_ipsec_inline_proto_display_list(const void *data __rte_unused)
 	return test_ipsec_inline_proto_all(&flags);
 }
 
+static int
+test_ipsec_inline_proto_udp_encap(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.udp_encap = true;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_udp_ports_verify(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.udp_encap = true;
+	flags.udp_ports_verify = true;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_err_icv_corrupt(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.icv_corrupt = true;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_tunnel_dst_addr_verify(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_tunnel_src_dst_addr_verify(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_inner_ip_csum(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.ip_csum = true;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_inner_l4_csum(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.l4_csum = true;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_tunnel_v4_in_v4(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.ipv6 = false;
+	flags.tunnel_ipv6 = false;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_tunnel_v6_in_v6(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.ipv6 = true;
+	flags.tunnel_ipv6 = true;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_tunnel_v4_in_v6(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.ipv6 = false;
+	flags.tunnel_ipv6 = true;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_tunnel_v6_in_v4(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.ipv6 = true;
+	flags.tunnel_ipv6 = false;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_transport_v4(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.ipv6 = false;
+	flags.transport = true;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_transport_l4_csum(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags = {
+		.l4_csum = true,
+		.transport = true,
+	};
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_stats(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.stats_success = true;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_pkt_fragment(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.fragment = true;
+
+	return test_ipsec_inline_proto_all(&flags);
+
+}
+
+static int
+test_ipsec_inline_proto_copy_df_inner_0(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.df = TEST_IPSEC_COPY_DF_INNER_0;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_copy_df_inner_1(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.df = TEST_IPSEC_COPY_DF_INNER_1;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_set_df_0_inner_1(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.df = TEST_IPSEC_SET_DF_0_INNER_1;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_set_df_1_inner_0(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.df = TEST_IPSEC_SET_DF_1_INNER_0;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_ipv4_copy_dscp_inner_0(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_0;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_ipv4_copy_dscp_inner_1(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_1;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_ipv4_set_dscp_0_inner_1(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.dscp = TEST_IPSEC_SET_DSCP_0_INNER_1;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_ipv4_set_dscp_1_inner_0(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.dscp = TEST_IPSEC_SET_DSCP_1_INNER_0;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_ipv6_copy_dscp_inner_0(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.ipv6 = true;
+	flags.tunnel_ipv6 = true;
+	flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_0;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_ipv6_copy_dscp_inner_1(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.ipv6 = true;
+	flags.tunnel_ipv6 = true;
+	flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_1;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_ipv6_set_dscp_0_inner_1(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.ipv6 = true;
+	flags.tunnel_ipv6 = true;
+	flags.dscp = TEST_IPSEC_SET_DSCP_0_INNER_1;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_ipv6_set_dscp_1_inner_0(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.ipv6 = true;
+	flags.tunnel_ipv6 = true;
+	flags.dscp = TEST_IPSEC_SET_DSCP_1_INNER_0;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_ipv4_ttl_decrement(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags = {
+		.dec_ttl_or_hop_limit = true
+	};
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_ipv6_hop_limit_decrement(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags = {
+		.ipv6 = true,
+		.dec_ttl_or_hop_limit = true
+	};
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_iv_gen(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.iv_gen = true;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_known_vec_fragmented(const void *test_data)
+{
+	struct ipsec_test_data td_outb;
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+	flags.fragment = true;
+
+	memcpy(&td_outb, test_data, sizeof(td_outb));
+
+	/* Disable IV gen to be able to test with known vectors */
+	td_outb.ipsec_xform.options.iv_gen_disable = 1;
+
+	return test_ipsec_inline_proto_process(&td_outb, NULL, 1, false,
+						&flags);
+}
 static struct unit_test_suite inline_ipsec_testsuite  = {
 	.suite_name = "Inline IPsec Ethernet Device Unit Test Suite",
 	.setup = inline_ipsec_testsuite_setup,
@@ -1359,6 +1747,13 @@ static struct unit_test_suite inline_ipsec_testsuite  = {
 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
 			test_ipsec_inline_proto_known_vec,
 			&pkt_null_aes_xcbc),
+
+		TEST_CASE_NAMED_WITH_DATA(
+			"Outbound fragmented packet",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_fragmented,
+			&pkt_aes_128_gcm_frag),
+
 		TEST_CASE_NAMED_WITH_DATA(
 			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 128)",
 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
@@ -1410,6 +1805,128 @@ static struct unit_test_suite inline_ipsec_testsuite  = {
 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
 			test_ipsec_inline_proto_display_list),
 
+		TEST_CASE_NAMED_ST(
+			"UDP encapsulation",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_udp_encap),
+		TEST_CASE_NAMED_ST(
+			"UDP encapsulation ports verification test",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_udp_ports_verify),
+		TEST_CASE_NAMED_ST(
+			"Negative test: ICV corruption",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_err_icv_corrupt),
+		TEST_CASE_NAMED_ST(
+			"Tunnel dst addr verification",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_tunnel_dst_addr_verify),
+		TEST_CASE_NAMED_ST(
+			"Tunnel src and dst addr verification",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_tunnel_src_dst_addr_verify),
+		TEST_CASE_NAMED_ST(
+			"Inner IP checksum",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_inner_ip_csum),
+		TEST_CASE_NAMED_ST(
+			"Inner L4 checksum",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_inner_l4_csum),
+		TEST_CASE_NAMED_ST(
+			"Tunnel IPv4 in IPv4",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_tunnel_v4_in_v4),
+		TEST_CASE_NAMED_ST(
+			"Tunnel IPv6 in IPv6",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_tunnel_v6_in_v6),
+		TEST_CASE_NAMED_ST(
+			"Tunnel IPv4 in IPv6",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_tunnel_v4_in_v6),
+		TEST_CASE_NAMED_ST(
+			"Tunnel IPv6 in IPv4",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_tunnel_v6_in_v4),
+		TEST_CASE_NAMED_ST(
+			"Transport IPv4",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_transport_v4),
+		TEST_CASE_NAMED_ST(
+			"Transport l4 checksum",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_transport_l4_csum),
+		TEST_CASE_NAMED_ST(
+			"Statistics: success",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_stats),
+		TEST_CASE_NAMED_ST(
+			"Fragmented packet",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_pkt_fragment),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header copy DF (inner 0)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_copy_df_inner_0),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header copy DF (inner 1)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_copy_df_inner_1),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header set DF 0 (inner 1)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_set_df_0_inner_1),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header set DF 1 (inner 0)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_set_df_1_inner_0),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header IPv4 copy DSCP (inner 0)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_ipv4_copy_dscp_inner_0),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header IPv4 copy DSCP (inner 1)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_ipv4_copy_dscp_inner_1),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header IPv4 set DSCP 0 (inner 1)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_ipv4_set_dscp_0_inner_1),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header IPv4 set DSCP 1 (inner 0)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_ipv4_set_dscp_1_inner_0),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header IPv6 copy DSCP (inner 0)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_ipv6_copy_dscp_inner_0),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header IPv6 copy DSCP (inner 1)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_ipv6_copy_dscp_inner_1),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header IPv6 set DSCP 0 (inner 1)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_ipv6_set_dscp_0_inner_1),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header IPv6 set DSCP 1 (inner 0)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_ipv6_set_dscp_1_inner_0),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header IPv4 decrement inner TTL",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_ipv4_ttl_decrement),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header IPv6 decrement inner hop limit",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_ipv6_hop_limit_decrement),
+		TEST_CASE_NAMED_ST(
+			"IV generation",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_iv_gen),
+
+
 		TEST_CASE_NAMED_WITH_DATA(
 			"IPv4 Reassembly with 2 fragments",
 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
Signature · 1 line
2.25.1
#52 lore raw

PATCH v4 6/10 test/security: add ESN and anti-replay cases for inline

In reply to Akhil Goyal

Added cases to test anti replay for inline IPsec processing with and without extended sequence number support.

---
 app/test/test_security_inline_proto.c | 308 ++++++++++++++++++++++++++
 1 file changed, 308 insertions(+)
app/test/test_security_inline_proto.c +308 -0
index 209999d02c..f8d6adc88f 100644
@@ -1092,6 +1092,136 @@ test_ipsec_inline_proto_all(const struct ipsec_test_flags *flags)
 		return TEST_SKIPPED;
 }
 
+static int
+test_ipsec_inline_proto_process_with_esn(struct ipsec_test_data td[],
+		struct ipsec_test_data res_d[],
+		int nb_pkts,
+		bool silent,
+		const struct ipsec_test_flags *flags)
+{
+	struct rte_security_session_conf sess_conf = {0};
+	struct ipsec_test_data *res_d_tmp = NULL;
+	struct rte_crypto_sym_xform cipher = {0};
+	struct rte_crypto_sym_xform auth = {0};
+	struct rte_crypto_sym_xform aead = {0};
+	struct rte_mbuf *rx_pkt = NULL;
+	struct rte_mbuf *tx_pkt = NULL;
+	int nb_rx, nb_sent;
+	struct rte_security_session *ses;
+	struct rte_security_ctx *ctx;
+	uint32_t ol_flags;
+	int i, ret;
+
+	if (td[0].aead) {
+		sess_conf.crypto_xform = &aead;
+	} else {
+		if (td[0].ipsec_xform.direction ==
+				RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
+			sess_conf.crypto_xform = &cipher;
+			sess_conf.crypto_xform->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
+			sess_conf.crypto_xform->next = &auth;
+			sess_conf.crypto_xform->next->type = RTE_CRYPTO_SYM_XFORM_AUTH;
+		} else {
+			sess_conf.crypto_xform = &auth;
+			sess_conf.crypto_xform->type = RTE_CRYPTO_SYM_XFORM_AUTH;
+			sess_conf.crypto_xform->next = &cipher;
+			sess_conf.crypto_xform->next->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
+		}
+	}
+
+	/* Create Inline IPsec session. */
+	ret = create_inline_ipsec_session(&td[0], port_id, &ses, &ctx,
+					  &ol_flags, flags, &sess_conf);
+	if (ret)
+		return ret;
+
+	if (td[0].ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS)
+		create_default_flow(port_id);
+
+	for (i = 0; i < nb_pkts; i++) {
+		tx_pkt = init_packet(mbufpool, td[i].input_text.data,
+					td[i].input_text.len);
+		if (tx_pkt == NULL) {
+			ret = TEST_FAILED;
+			goto out;
+		}
+
+		if (test_ipsec_pkt_update(rte_pktmbuf_mtod_offset(tx_pkt,
+					uint8_t *, RTE_ETHER_HDR_LEN), flags)) {
+			ret = TEST_FAILED;
+			goto out;
+		}
+
+		if (td[i].ipsec_xform.direction ==
+				RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
+			if (flags->antireplay) {
+				sess_conf.ipsec.esn.value =
+						td[i].ipsec_xform.esn.value;
+				ret = rte_security_session_update(ctx, ses,
+						&sess_conf);
+				if (ret) {
+					printf("Could not update ESN in session\n");
+					rte_pktmbuf_free(tx_pkt);
+					goto out;
+				}
+			}
+			if (ol_flags & RTE_SECURITY_TX_OLOAD_NEED_MDATA)
+				rte_security_set_pkt_metadata(ctx, ses,
+						tx_pkt, NULL);
+			tx_pkt->ol_flags |= RTE_MBUF_F_TX_SEC_OFFLOAD;
+		}
+		/* Send packet to ethdev for inline IPsec processing. */
+		nb_sent = rte_eth_tx_burst(port_id, 0, &tx_pkt, 1);
+		if (nb_sent != 1) {
+			printf("\nUnable to TX packets");
+			rte_pktmbuf_free(tx_pkt);
+			ret = TEST_FAILED;
+			goto out;
+		}
+
+		rte_pause();
+
+		/* Receive back packet on loopback interface. */
+		do {
+			rte_delay_ms(1);
+			nb_rx = rte_eth_rx_burst(port_id, 0, &rx_pkt, 1);
+		} while (nb_rx == 0);
+
+		rte_pktmbuf_adj(rx_pkt, RTE_ETHER_HDR_LEN);
+
+		if (res_d != NULL)
+			res_d_tmp = &res_d[i];
+
+		ret = test_ipsec_post_process(rx_pkt, &td[i],
+					      res_d_tmp, silent, flags);
+		if (ret != TEST_SUCCESS) {
+			rte_pktmbuf_free(rx_pkt);
+			goto out;
+		}
+
+		ret = test_ipsec_stats_verify(ctx, ses, flags,
+					td->ipsec_xform.direction);
+		if (ret != TEST_SUCCESS) {
+			rte_pktmbuf_free(rx_pkt);
+			goto out;
+		}
+
+		rte_pktmbuf_free(rx_pkt);
+		rx_pkt = NULL;
+		tx_pkt = NULL;
+		res_d_tmp = NULL;
+	}
+
+out:
+	if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS)
+		destroy_default_flow(port_id);
+
+	/* Destroy session so that other cases can create the session again */
+	rte_security_session_destroy(ctx, ses);
+	ses = NULL;
+
+	return ret;
+}
 
 static int
 ut_setup_inline_ipsec(void)
@@ -1701,6 +1831,153 @@ test_ipsec_inline_proto_known_vec_fragmented(const void *test_data)
 	return test_ipsec_inline_proto_process(&td_outb, NULL, 1, false,
 						&flags);
 }
+
+static int
+test_ipsec_inline_pkt_replay(const void *test_data, const uint64_t esn[],
+		      bool replayed_pkt[], uint32_t nb_pkts, bool esn_en,
+		      uint64_t winsz)
+{
+	struct ipsec_test_data td_outb[IPSEC_TEST_PACKETS_MAX];
+	struct ipsec_test_data td_inb[IPSEC_TEST_PACKETS_MAX];
+	struct ipsec_test_flags flags;
+	uint32_t i, ret = 0;
+
+	memset(&flags, 0, sizeof(flags));
+	flags.antireplay = true;
+
+	for (i = 0; i < nb_pkts; i++) {
+		memcpy(&td_outb[i], test_data, sizeof(td_outb));
+		td_outb[i].ipsec_xform.options.iv_gen_disable = 1;
+		td_outb[i].ipsec_xform.replay_win_sz = winsz;
+		td_outb[i].ipsec_xform.options.esn = esn_en;
+	}
+
+	for (i = 0; i < nb_pkts; i++)
+		td_outb[i].ipsec_xform.esn.value = esn[i];
+
+	ret = test_ipsec_inline_proto_process_with_esn(td_outb, td_inb,
+				nb_pkts, true, &flags);
+	if (ret != TEST_SUCCESS)
+		return ret;
+
+	test_ipsec_td_update(td_inb, td_outb, nb_pkts, &flags);
+
+	for (i = 0; i < nb_pkts; i++) {
+		td_inb[i].ipsec_xform.options.esn = esn_en;
+		/* Set antireplay flag for packets to be dropped */
+		td_inb[i].ar_packet = replayed_pkt[i];
+	}
+
+	ret = test_ipsec_inline_proto_process_with_esn(td_inb, NULL, nb_pkts,
+				true, &flags);
+
+	return ret;
+}
+
+static int
+test_ipsec_inline_proto_pkt_antireplay(const void *test_data, uint64_t winsz)
+{
+
+	uint32_t nb_pkts = 5;
+	bool replayed_pkt[5];
+	uint64_t esn[5];
+
+	/* 1. Advance the TOP of the window to WS * 2 */
+	esn[0] = winsz * 2;
+	/* 2. Test sequence number within the new window(WS + 1) */
+	esn[1] = winsz + 1;
+	/* 3. Test sequence number less than the window BOTTOM */
+	esn[2] = winsz;
+	/* 4. Test sequence number in the middle of the window */
+	esn[3] = winsz + (winsz / 2);
+	/* 5. Test replay of the packet in the middle of the window */
+	esn[4] = winsz + (winsz / 2);
+
+	replayed_pkt[0] = false;
+	replayed_pkt[1] = false;
+	replayed_pkt[2] = true;
+	replayed_pkt[3] = false;
+	replayed_pkt[4] = true;
+
+	return test_ipsec_inline_pkt_replay(test_data, esn, replayed_pkt,
+			nb_pkts, false, winsz);
+}
+
+static int
+test_ipsec_inline_proto_pkt_antireplay1024(const void *test_data)
+{
+	return test_ipsec_inline_proto_pkt_antireplay(test_data, 1024);
+}
+
+static int
+test_ipsec_inline_proto_pkt_antireplay2048(const void *test_data)
+{
+	return test_ipsec_inline_proto_pkt_antireplay(test_data, 2048);
+}
+
+static int
+test_ipsec_inline_proto_pkt_antireplay4096(const void *test_data)
+{
+	return test_ipsec_inline_proto_pkt_antireplay(test_data, 4096);
+}
+
+static int
+test_ipsec_inline_proto_pkt_esn_antireplay(const void *test_data, uint64_t winsz)
+{
+
+	uint32_t nb_pkts = 7;
+	bool replayed_pkt[7];
+	uint64_t esn[7];
+
+	/* Set the initial sequence number */
+	esn[0] = (uint64_t)(0xFFFFFFFF - winsz);
+	/* 1. Advance the TOP of the window to (1<<32 + WS/2) */
+	esn[1] = (uint64_t)((1ULL << 32) + (winsz / 2));
+	/* 2. Test sequence number within new window (1<<32 + WS/2 + 1) */
+	esn[2] = (uint64_t)((1ULL << 32) - (winsz / 2) + 1);
+	/* 3. Test with sequence number within window (1<<32 - 1) */
+	esn[3] = (uint64_t)((1ULL << 32) - 1);
+	/* 4. Test with sequence number within window (1<<32 - 1) */
+	esn[4] = (uint64_t)(1ULL << 32);
+	/* 5. Test with duplicate sequence number within
+	 * new window (1<<32 - 1)
+	 */
+	esn[5] = (uint64_t)((1ULL << 32) - 1);
+	/* 6. Test with duplicate sequence number within new window (1<<32) */
+	esn[6] = (uint64_t)(1ULL << 32);
+
+	replayed_pkt[0] = false;
+	replayed_pkt[1] = false;
+	replayed_pkt[2] = false;
+	replayed_pkt[3] = false;
+	replayed_pkt[4] = false;
+	replayed_pkt[5] = true;
+	replayed_pkt[6] = true;
+
+	return test_ipsec_inline_pkt_replay(test_data, esn, replayed_pkt, nb_pkts,
+				     true, winsz);
+}
+
+static int
+test_ipsec_inline_proto_pkt_esn_antireplay1024(const void *test_data)
+{
+	return test_ipsec_inline_proto_pkt_esn_antireplay(test_data, 1024);
+}
+
+static int
+test_ipsec_inline_proto_pkt_esn_antireplay2048(const void *test_data)
+{
+	return test_ipsec_inline_proto_pkt_esn_antireplay(test_data, 2048);
+}
+
+static int
+test_ipsec_inline_proto_pkt_esn_antireplay4096(const void *test_data)
+{
+	return test_ipsec_inline_proto_pkt_esn_antireplay(test_data, 4096);
+}
+
+
+
 static struct unit_test_suite inline_ipsec_testsuite  = {
 	.suite_name = "Inline IPsec Ethernet Device Unit Test Suite",
 	.setup = inline_ipsec_testsuite_setup,
@@ -1927,6 +2204,37 @@ static struct unit_test_suite inline_ipsec_testsuite  = {
 			test_ipsec_inline_proto_iv_gen),
 
 
+		TEST_CASE_NAMED_WITH_DATA(
+			"Antireplay with window size 1024",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_pkt_antireplay1024,
+			&pkt_aes_128_gcm),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Antireplay with window size 2048",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_pkt_antireplay2048,
+			&pkt_aes_128_gcm),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Antireplay with window size 4096",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_pkt_antireplay4096,
+			&pkt_aes_128_gcm),
+		TEST_CASE_NAMED_WITH_DATA(
+			"ESN and Antireplay with window size 1024",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_pkt_esn_antireplay1024,
+			&pkt_aes_128_gcm),
+		TEST_CASE_NAMED_WITH_DATA(
+			"ESN and Antireplay with window size 2048",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_pkt_esn_antireplay2048,
+			&pkt_aes_128_gcm),
+		TEST_CASE_NAMED_WITH_DATA(
+			"ESN and Antireplay with window size 4096",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_pkt_esn_antireplay4096,
+			&pkt_aes_128_gcm),
+
 		TEST_CASE_NAMED_WITH_DATA(
 			"IPv4 Reassembly with 2 fragments",
 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
Signature · 1 line
2.25.1
#53 lore raw

PATCH v4 7/10 ethdev: add IPsec SA expiry event subtypes

In reply to Akhil Goyal

From: Vamsi Attunuru <[email protected]>

Patch adds new event subtypes for notifying expiry events upon reaching IPsec SA soft packet expiry and hard packet/byte expiry limits.

---
 lib/ethdev/rte_ethdev.h | 9 +++++++++
 1 file changed, 9 insertions(+)
lib/ethdev/rte_ethdev.h +9 -0
index 04cff8ee10..08819fe4ba 100644
@@ -3828,6 +3828,12 @@ enum rte_eth_event_ipsec_subtype {
 	RTE_ETH_EVENT_IPSEC_SA_TIME_EXPIRY,
 	/** Soft byte expiry of SA */
 	RTE_ETH_EVENT_IPSEC_SA_BYTE_EXPIRY,
+	/** Soft packet expiry of SA */
+	RTE_ETH_EVENT_IPSEC_SA_PKT_EXPIRY,
+	/** Hard byte expiry of SA */
+	RTE_ETH_EVENT_IPSEC_SA_BYTE_HARD_EXPIRY,
+	/** Hard packet expiry of SA */
+	RTE_ETH_EVENT_IPSEC_SA_PKT_HARD_EXPIRY,
 	/** Max value of this enum */
 	RTE_ETH_EVENT_IPSEC_MAX
 };
@@ -3849,6 +3855,9 @@ struct rte_eth_event_ipsec_desc {
 	 * - @ref RTE_ETH_EVENT_IPSEC_ESN_OVERFLOW
 	 * - @ref RTE_ETH_EVENT_IPSEC_SA_TIME_EXPIRY
 	 * - @ref RTE_ETH_EVENT_IPSEC_SA_BYTE_EXPIRY
+	 * - @ref RTE_ETH_EVENT_IPSEC_SA_PKT_EXPIRY
+	 * - @ref RTE_ETH_EVENT_IPSEC_SA_BYTE_HARD_EXPIRY
+	 * - @ref RTE_ETH_EVENT_IPSEC_SA_PKT_HARD_EXPIRY
 	 *
 	 * @see struct rte_security_session_conf
 	 *
Signature · 1 line
2.25.1
#54 lore raw

Re: [PATCH v4 07/10] ethdev: add IPsec SA expiry event subtypes

16/04/2022 21:25, Akhil Goyal:

lib/ethdev/rte_ethdev.h enum rte_eth_event_ipsec_subtype { · line 3831

Quoted 7 lines
lib/ethdev/rte_ethdev.h +1 -0
@@ -3828,6 +3828,12 @@ enum rte_eth_event_ipsec_subtype {
 	RTE_ETH_EVENT_IPSEC_SA_TIME_EXPIRY,
 	/** Soft byte expiry of SA */
 	RTE_ETH_EVENT_IPSEC_SA_BYTE_EXPIRY,
+	/** Soft packet expiry of SA */

Is there a reference explaining what exactly is a "soft packet expiry"? I think you should also mention what should be done
in the event handler.

lib/ethdev/rte_ethdev.h enum rte_eth_event_ipsec_subtype { · line 3836

Quoted 5 lines
lib/ethdev/rte_ethdev.h +5 -0
+	RTE_ETH_EVENT_IPSEC_SA_PKT_EXPIRY,
+	/** Hard byte expiry of SA */
+	RTE_ETH_EVENT_IPSEC_SA_BYTE_HARD_EXPIRY,
+	/** Hard packet expiry of SA */
+	RTE_ETH_EVENT_IPSEC_SA_PKT_HARD_EXPIRY,

Same comment for the 3 events.

lib/ethdev/rte_ethdev.h enum rte_eth_event_ipsec_subtype { · line 3839

Quoted 3 lines
lib/ethdev/rte_ethdev.h +0 -0
 	/** Max value of this enum */
 	RTE_ETH_EVENT_IPSEC_MAX
 };

What is the impact of this "MAX" value on ABI compatibility?

#55 lore raw

RE: [EXT] Re: [PATCH v4 07/10] ethdev: add IPsec SA expiry event subtypes

Hi Thomas,

Quoted 10 lines

16/04/2022 21:25, Akhil Goyal:

lib/ethdev/rte_ethdev.h enum rte_eth_event_ipsec_subtype { · line 3831

Quoted 7 lines
lib/ethdev/rte_ethdev.h +1 -0
@@ -3828,6 +3828,12 @@ enum rte_eth_event_ipsec_subtype {
 	RTE_ETH_EVENT_IPSEC_SA_TIME_EXPIRY,
 	/** Soft byte expiry of SA */
 	RTE_ETH_EVENT_IPSEC_SA_BYTE_EXPIRY,
+	/** Soft packet expiry of SA */

Is there a reference explaining what exactly is a "soft packet expiry"?

SA expiry is a very common procedure in case of IPsec.
And all stacks must support this feature.
You can refer https://docs.strongswan.org/strongswan-docs/5.9/config/rekeying.html
For details.
Time expiry means after x seconds SA will expire.
Packet expiry means after x packets processing SA will expire.
Byte expiry means after x bytes of packet processing SA will expire.

Quoted 2 lines

I think you should also mention what should be done in the event handler.

I believe this is quite obvious as per IPsec specifications. Application need to start rekeying or SA need to be created again.

Quoted 9 lines

lib/ethdev/rte_ethdev.h enum rte_eth_event_ipsec_subtype { · line 3836

Quoted 6 lines
lib/ethdev/rte_ethdev.h +5 -0
+	RTE_ETH_EVENT_IPSEC_SA_PKT_EXPIRY,
+	/** Hard byte expiry of SA */
+	RTE_ETH_EVENT_IPSEC_SA_BYTE_HARD_EXPIRY,
+	/** Hard packet expiry of SA */
+	RTE_ETH_EVENT_IPSEC_SA_PKT_HARD_EXPIRY,

Same comment for the 3 events.

Quoted 5 lines

lib/ethdev/rte_ethdev.h enum rte_eth_event_ipsec_subtype { · line 3839

Quoted 3 lines
lib/ethdev/rte_ethdev.h +0 -0
 	/** Max value of this enum */
 	RTE_ETH_EVENT_IPSEC_MAX
 };

What is the impact of this "MAX" value on ABI compatibility?

I see no issues reported while running ABI check. There is no array being used inside library based on MAX.

#56 lore raw

RE: [EXT] Re: [PATCH v4 07/10] ethdev: add IPsec SA expiry event subtypes

Hi Thomas, Akhil,

Quoted 1 line

Is there a reference explaining what exactly is a "soft packet expiry"?

The SA lifetime/expiry is described in security library.
https://elixir.bootlin.com/dpdk/latest/source/lib/security/rte_security.h#L295

Thanks,
Anoob

Quoted 57 lines

-----Original Message-----
From: Akhil Goyal <[email protected]>
Sent: Tuesday, April 19, 2022 3:44 PM
To: Thomas Monjalon <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Anoob Joseph <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Nithin Kumar Dabilpuram <[email protected]>; Vamsi Krishna Attunuru <[email protected]>
Subject: RE: [EXT] Re: [PATCH v4 07/10] ethdev: add IPsec SA expiry event subtypes

Hi Thomas,

Quoted 10 lines

16/04/2022 21:25, Akhil Goyal:

lib/ethdev/rte_ethdev.h enum rte_eth_event_ipsec_subtype { · line 3831

Quoted 7 lines
lib/ethdev/rte_ethdev.h +1 -0
@@ -3828,6 +3828,12 @@ enum rte_eth_event_ipsec_subtype {
 	RTE_ETH_EVENT_IPSEC_SA_TIME_EXPIRY,
 	/** Soft byte expiry of SA */
 	RTE_ETH_EVENT_IPSEC_SA_BYTE_EXPIRY,
+	/** Soft packet expiry of SA */

Is there a reference explaining what exactly is a "soft packet expiry"?

SA expiry is a very common procedure in case of IPsec. And all stacks must support this feature.
You can refer https://docs.strongswan.org/strongswan-
docs/5.9/config/rekeying.html
For details.
Time expiry means after x seconds SA will expire.
Packet expiry means after x packets processing SA will expire. Byte expiry means after x bytes of packet processing SA will expire.

Quoted 2 lines

I think you should also mention what should be done in the event handler.

I believe this is quite obvious as per IPsec specifications. Application need to start rekeying or SA need to be created again.

Quoted 9 lines

lib/ethdev/rte_ethdev.h enum rte_eth_event_ipsec_subtype { · line 3836

Quoted 6 lines
lib/ethdev/rte_ethdev.h +5 -0
+	RTE_ETH_EVENT_IPSEC_SA_PKT_EXPIRY,
+	/** Hard byte expiry of SA */
+	RTE_ETH_EVENT_IPSEC_SA_BYTE_HARD_EXPIRY,
+	/** Hard packet expiry of SA */
+	RTE_ETH_EVENT_IPSEC_SA_PKT_HARD_EXPIRY,

Same comment for the 3 events.

Quoted 5 lines

lib/ethdev/rte_ethdev.h enum rte_eth_event_ipsec_subtype { · line 3839

Quoted 3 lines
lib/ethdev/rte_ethdev.h +0 -0
 	/** Max value of this enum */
 	RTE_ETH_EVENT_IPSEC_MAX
 };

What is the impact of this "MAX" value on ABI compatibility?

I see no issues reported while running ABI check. There is no array being used inside library based on MAX.

#57 lore raw

Re: [EXT] Re: [PATCH v4 07/10] ethdev: add IPsec SA expiry event subtypes

19/04/2022 12:19, Anoob Joseph:

Quoted 6 lines

Hi Thomas, Akhil,

Quoted 1 line

Is there a reference explaining what exactly is a "soft packet expiry"?

The SA lifetime/expiry is described in security library.
https://elixir.bootlin.com/dpdk/latest/source/lib/security/rte_security.h#L295

The comment you are referencing is using "soft" for all limits, even for packets_hard_limit and bytes_hard_limit.
It seems these comments need to be fixed.

#58 lore raw

RE: [EXT] Re: [PATCH v4 07/10] ethdev: add IPsec SA expiry event subtypes

Hi Thomas,

Yes. The comments need to be fixed. I'll push a patch for that. Thanks for pointing out.

Thanks,
Anoob

Quoted 33 lines

-----Original Message-----
From: Thomas Monjalon <[email protected]>
Sent: Tuesday, April 19, 2022 4:08 PM
To: Anoob Joseph <[email protected]>
Cc: Akhil Goyal <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Nithin Kumar Dabilpuram <[email protected]>; Vamsi Krishna Attunuru <[email protected]>
Subject: Re: [EXT] Re: [PATCH v4 07/10] ethdev: add IPsec SA expiry event subtypes

19/04/2022 12:19, Anoob Joseph:

Quoted 7 lines

Hi Thomas, Akhil,

Quoted 1 line

Is there a reference explaining what exactly is a "soft packet expiry"?

The SA lifetime/expiry is described in security library.
https://urldefense.proofpoint.com/v2/url?u=https-3A__elixir.bootlin.co
m_dpdk_latest_source_lib_security_rte-5Fsecurity.h-

23L295&d=DwICAg&c=n

Quoted 1 line

KjWec2b6R0mOyPaz7xtfQ&r=jPfB8rwwviRSxyLWs2n6B-

WYLn1v9SyTMrT5EQqh2TU&m=

Quoted 1 line

d9ONaYIdobFMxqt05JVZ3nT7rJib1rL35ax9X56teaPlvEGKpDNKMSCv1bYxhN8 1&s=jqz

Quoted 1 line

cuIk0XOpIidta-KGZ4zmUvmkhsnbe_VzT3QXAWe4&e=

The comment you are referencing is using "soft" for all limits, even for packets_hard_limit and bytes_hard_limit.
It seems these comments need to be fixed.

#59 lore raw

Re: [EXT] Re: [PATCH v4 07/10] ethdev: add IPsec SA expiry event subtypes

In reply to Akhil Goyal

19/04/2022 12:14, Akhil Goyal:

Quoted 13 lines

Hi Thomas,

Quoted 10 lines

16/04/2022 21:25, Akhil Goyal:

lib/ethdev/rte_ethdev.h enum rte_eth_event_ipsec_subtype { · line 3831

Quoted 7 lines
lib/ethdev/rte_ethdev.h +1 -0
@@ -3828,6 +3828,12 @@ enum rte_eth_event_ipsec_subtype {
 	RTE_ETH_EVENT_IPSEC_SA_TIME_EXPIRY,
 	/** Soft byte expiry of SA */
 	RTE_ETH_EVENT_IPSEC_SA_BYTE_EXPIRY,
+	/** Soft packet expiry of SA */

Is there a reference explaining what exactly is a "soft packet expiry"?

Quoted 7 lines

SA expiry is a very common procedure in case of IPsec.
And all stacks must support this feature.
You can refer https://docs.strongswan.org/strongswan-docs/5.9/config/rekeying.html
For details.
Time expiry means after x seconds SA will expire.
Packet expiry means after x packets processing SA will expire.
Byte expiry means after x bytes of packet processing SA will expire.

I think you should use the syntax @ref packets_soft_limit so it is clear where the event come from.

Quoted 5 lines
Quoted 2 lines

I think you should also mention what should be done in the event handler.

I believe this is quite obvious as per IPsec specifications. Application need to start rekeying or SA need to be created again.

Yes indeed.

Quoted 8 lines
Quoted 8 lines

lib/ethdev/rte_ethdev.h enum rte_eth_event_ipsec_subtype { · line 3836

Quoted 5 lines
lib/ethdev/rte_ethdev.h +5 -0
+	RTE_ETH_EVENT_IPSEC_SA_PKT_EXPIRY,
+	/** Hard byte expiry of SA */
+	RTE_ETH_EVENT_IPSEC_SA_BYTE_HARD_EXPIRY,
+	/** Hard packet expiry of SA */
+	RTE_ETH_EVENT_IPSEC_SA_PKT_HARD_EXPIRY,

Same comment for the 3 events.

Quoted 8 lines
Quoted 5 lines

lib/ethdev/rte_ethdev.h enum rte_eth_event_ipsec_subtype { · line 3839

Quoted 3 lines
lib/ethdev/rte_ethdev.h +0 -0
 	/** Max value of this enum */
 	RTE_ETH_EVENT_IPSEC_MAX
 };

What is the impact of this "MAX" value on ABI compatibility?

I see no issues reported while running ABI check. There is no array being used inside library based on MAX.

No need of array inside the library, the events are exposed to the app. I'm surprised libabigail is OK with changing an enum value.

#60 lore raw

RE: [EXT] Re: [PATCH v4 07/10] ethdev: add IPsec SA expiry event subtypes

Quoted 6 lines
Quoted 3 lines

Time expiry means after x seconds SA will expire.
Packet expiry means after x packets processing SA will expire. Byte expiry means after x bytes of packet processing SA will expire.

I think you should use the syntax @ref packets_soft_limit so it is clear where the event come from.

OK will update the comments.

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines

lib/ethdev/rte_ethdev.h enum rte_eth_event_ipsec_subtype { · line 3836

Quoted 7 lines
lib/ethdev/rte_ethdev.h +5 -0
+	RTE_ETH_EVENT_IPSEC_SA_PKT_EXPIRY,
+	/** Hard byte expiry of SA */
+	RTE_ETH_EVENT_IPSEC_SA_BYTE_HARD_EXPIRY,
+	/** Hard packet expiry of SA */
+	RTE_ETH_EVENT_IPSEC_SA_PKT_HARD_EXPIRY,

Same comment for the 3 events.

Quoted 3 lines
lib/ethdev/rte_ethdev.h +0 -0
 	/** Max value of this enum */
 	RTE_ETH_EVENT_IPSEC_MAX
 };
Quoted 8 lines
Quoted 4 lines
Quoted 1 line

What is the impact of this "MAX" value on ABI compatibility?

I see no issues reported while running ABI check. There is no array being used inside library based on MAX.

No need of array inside the library, the events are exposed to the app. I'm surprised libabigail is OK with changing an enum value.

@Ray Can you please check if it is an issue to add more values in this enum?

#61 lore raw

Re: [EXT] Re: [PATCH v4 07/10] ethdev: add IPsec SA expiry event subtypes

Quoted 25 lines · Akhil Goyal
Quoted 6 lines
Quoted 3 lines

Time expiry means after x seconds SA will expire.
Packet expiry means after x packets processing SA will expire. Byte expiry means after x bytes of packet processing SA will expire.

I think you should use the syntax @ref packets_soft_limit so it is clear where the event come from.

OK will update the comments.

Quoted 16 lines
Quoted 16 lines
Quoted 15 lines

lib/ethdev/rte_ethdev.h enum rte_eth_event_ipsec_subtype { · line 3836

Quoted 7 lines
lib/ethdev/rte_ethdev.h +5 -0
+	RTE_ETH_EVENT_IPSEC_SA_PKT_EXPIRY,
+	/** Hard byte expiry of SA */
+	RTE_ETH_EVENT_IPSEC_SA_BYTE_HARD_EXPIRY,
+	/** Hard packet expiry of SA */
+	RTE_ETH_EVENT_IPSEC_SA_PKT_HARD_EXPIRY,

Same comment for the 3 events.

lib/ethdev/rte_ethdev.h enum rte_eth_event_ipsec_subtype { · line 3839

Quoted 3 lines
lib/ethdev/rte_ethdev.h +0 -0
 	/** Max value of this enum */
 	RTE_ETH_EVENT_IPSEC_MAX
 };

What is the impact of this "MAX" value on ABI compatibility?

Quoted 7 lines
Quoted 6 lines
Quoted 2 lines

I see no issues reported while running ABI check. There is no array being used inside library based on MAX.

No need of array inside the library, the events are exposed to the app. I'm surprised libabigail is OK with changing an enum value.

@Ray Can you please check if it is an issue to add more values in this enum?

Well look there is two seperate things going on here.

Why isn't libabigail complaining about the _MAX value changing. I'll need to look at libabigail to see what the issue is, so lets put this one aside for a moment.

This second issue is it safe for the _MAX value to change? We have a lot of back and forth argument on these, and previously concluded that we should probably look to remove _MAX values in the 22.11 release.

The core issue is that we need look at how a user is likely to use rte_eth_event_ipsec_subtype. Take a look at the example below:-

/root/src/dpdk/examples/ipsec-secgw/ipsec-secgw.c:2592:0

For instance, can we guarantee that an application built against DPDK 21.11, but running against 22.xx will never recieve one of the new values in event_desc->subtype (or by any other means)?

Signature · 1 line
Regards, Ray K
#62 lore raw

RE: [EXT] Re: [PATCH v4 07/10] ethdev: add IPsec SA expiry event subtypes

Hi Ray,

Quoted 24 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines

lib/ethdev/rte_ethdev.h enum rte_eth_event_ipsec_subtype { · line 3836

Quoted 5 lines
lib/ethdev/rte_ethdev.h +5 -0
+	RTE_ETH_EVENT_IPSEC_SA_PKT_EXPIRY,
+	/** Hard byte expiry of SA */
+	RTE_ETH_EVENT_IPSEC_SA_BYTE_HARD_EXPIRY,
+	/** Hard packet expiry of SA */
+	RTE_ETH_EVENT_IPSEC_SA_PKT_HARD_EXPIRY,

Same comment for the 3 events.

lib/ethdev/rte_ethdev.h enum rte_eth_event_ipsec_subtype { · line 3839

Quoted 3 lines
lib/ethdev/rte_ethdev.h +0 -0
 	/** Max value of this enum */
 	RTE_ETH_EVENT_IPSEC_MAX
 };

What is the impact of this "MAX" value on ABI compatibility?

Quoted 7 lines
Quoted 6 lines
Quoted 2 lines

I see no issues reported while running ABI check. There is no array being used inside library based on MAX.

No need of array inside the library, the events are exposed to the app. I'm surprised libabigail is OK with changing an enum value.

@Ray Can you please check if it is an issue to add more values in this enum?

Well look there is two seperate things going on here.

Quoted 8 lines

Why isn't libabigail complaining about the _MAX value changing. I'll need to look at libabigail to see what the issue is, so lets put this one aside for a moment.

This second issue is it safe for the _MAX value to change? We have a lot of back and forth argument on these, and previously concluded that we should probably look to remove _MAX values in the 22.11 release.

Agreed.

Quoted 9 lines

The core issue is that we need look at how a user is likely to use rte_eth_event_ipsec_subtype. Take a look at the example below:-

/root/src/dpdk/examples/ipsec-secgw/ipsec-secgw.c:2592:0

For instance, can we guarantee that an application built against DPDK 21.11, but running against 22.xx will never recieve one of the new values in event_desc->subtype (or by any other means)?

ok we can defer the 7/10, 8/10, 9/10 patch to next release then.

#63 lore raw

v5 cover Add and test IPsec SA expiry events

In reply to Akhil Goyal

This patchset is carried forward from last release patches [1] which added test application changes to test inline IPsec. These patches were not merged due to the ABI compatibility issues due to the extension of enum.

Changes in this version:
added reference to struct which raised these interrupts.

[1] https://patches.dpdk.org/project/dpdk/patch/[email protected]/

Vamsi Attunuru (3):
ethdev: add IPsec SA expiry event subtypes test/security: add inline IPsec SA soft expiry cases test/security: add inline IPsec SA hard expiry cases

 app/test/test_cryptodev_security_ipsec.h      |   2 +
 app/test/test_security_inline_proto.c         | 158 +++++++++++++++++-
 app/test/test_security_inline_proto_vectors.h |   6 +
 lib/ethdev/rte_ethdev.h                       |  23 ++-
 4 files changed, 186 insertions(+), 3 deletions(-)
Signature · 1 line
2.25.1
#64 lore raw

PATCH v5 1/3 ethdev: add IPsec SA expiry event subtypes

From: Vamsi Attunuru <[email protected]>

Patch adds new event subtypes for notifying expiry events upon reaching IPsec SA soft packet expiry and hard packet/byte expiry limits.

---
 lib/ethdev/rte_ethdev.h | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)
lib/ethdev/rte_ethdev.h +22 -1
index 2e783536c1..d730676a0e 100644
@@ -3875,8 +3875,26 @@ enum rte_eth_event_ipsec_subtype {
 	RTE_ETH_EVENT_IPSEC_ESN_OVERFLOW,
 	/** Soft time expiry of SA */
 	RTE_ETH_EVENT_IPSEC_SA_TIME_EXPIRY,
-	/** Soft byte expiry of SA */
+	/**
+	 * Soft byte expiry of SA determined by @ref bytes_soft_limit
+	 * defined in @ref rte_security_ipsec_lifetime
+	 */
 	RTE_ETH_EVENT_IPSEC_SA_BYTE_EXPIRY,
+	/**
+	 * Soft packet expiry of SA determined by @ref packets_soft_limit
+	 * defined in @ref rte_security_ipsec_lifetime
+	 */
+	RTE_ETH_EVENT_IPSEC_SA_PKT_EXPIRY,
+	/**
+	 * Hard byte expiry of SA determined by @ref bytes_hard_limit
+	 * defined in @ref rte_security_ipsec_lifetime
+	 */
+	RTE_ETH_EVENT_IPSEC_SA_BYTE_HARD_EXPIRY,
+	/**
+	 * Hard packet expiry of SA determined by @ref packets_hard_limit
+	 * defined in @ref rte_security_ipsec_lifetime
+	 */
+	RTE_ETH_EVENT_IPSEC_SA_PKT_HARD_EXPIRY,
 	/** Max value of this enum */
 	RTE_ETH_EVENT_IPSEC_MAX
 };
@@ -3898,6 +3916,9 @@ struct rte_eth_event_ipsec_desc {
 	 * - @ref RTE_ETH_EVENT_IPSEC_ESN_OVERFLOW
 	 * - @ref RTE_ETH_EVENT_IPSEC_SA_TIME_EXPIRY
 	 * - @ref RTE_ETH_EVENT_IPSEC_SA_BYTE_EXPIRY
+	 * - @ref RTE_ETH_EVENT_IPSEC_SA_PKT_EXPIRY
+	 * - @ref RTE_ETH_EVENT_IPSEC_SA_BYTE_HARD_EXPIRY
+	 * - @ref RTE_ETH_EVENT_IPSEC_SA_PKT_HARD_EXPIRY
 	 *
 	 * @see struct rte_security_session_conf
 	 *
Signature · 1 line
2.25.1
#65 lore raw

RE: [PATCH v5 1/3] ethdev: add IPsec SA expiry event subtypes

Hi Thomas,

Quoted 11 lines

Subject: [PATCH v5 1/3] ethdev: add IPsec SA expiry event subtypes

From: Vamsi Attunuru <[email protected]>

Patch adds new event subtypes for notifying expiry events upon reaching IPsec SA soft packet expiry and hard packet/byte expiry limits.

---

Can you ack this patch if no further comments? This patch is from last release deferred to 22.11.
https://patches.dpdk.org/project/dpdk/patch/[email protected]/

Regards,
Akhil

Acked-by on v5 1/3
#66 lore raw

Re: [PATCH v5 1/3] ethdev: add IPsec SA expiry event subtypes

In reply to Akhil Goyal

24/09/2022 15:57, Akhil Goyal:

Quoted 28 lines

From: Vamsi Attunuru <[email protected]>

Patch adds new event subtypes for notifying expiry events upon reaching IPsec SA soft packet expiry and hard packet/byte expiry limits.

---

lib/ethdev/rte_ethdev.h +11 -1
@@ -3875,8 +3875,26 @@ enum rte_eth_event_ipsec_subtype {
 	RTE_ETH_EVENT_IPSEC_ESN_OVERFLOW,
 	/** Soft time expiry of SA */
 	RTE_ETH_EVENT_IPSEC_SA_TIME_EXPIRY,
-	/** Soft byte expiry of SA */
+	/**
+	 * Soft byte expiry of SA determined by @ref bytes_soft_limit
+	 * defined in @ref rte_security_ipsec_lifetime
+	 */
 	RTE_ETH_EVENT_IPSEC_SA_BYTE_EXPIRY,
+	/**
+	 * Soft packet expiry of SA determined by @ref packets_soft_limit
+	 * defined in @ref rte_security_ipsec_lifetime
+	 */
+	RTE_ETH_EVENT_IPSEC_SA_PKT_EXPIRY,
+	/**
+	 * Hard byte expiry of SA determined by @ref bytes_hard_limit

lib/ethdev/rte_ethdev.h enum rte_eth_event_ipsec_subtype { · line 3899

Quoted 10 lines
lib/ethdev/rte_ethdev.h +8 -0
+	 * defined in @ref rte_security_ipsec_lifetime
+	 */
+	RTE_ETH_EVENT_IPSEC_SA_BYTE_HARD_EXPIRY,
+	/**
+	 * Hard packet expiry of SA determined by @ref packets_hard_limit
+	 * defined in @ref rte_security_ipsec_lifetime
+	 */
+	RTE_ETH_EVENT_IPSEC_SA_PKT_HARD_EXPIRY,
 	/** Max value of this enum */
 	RTE_ETH_EVENT_IPSEC_MAX

I would prefer we remove this MAX value, but it would be another patch.

You can merge this patch in the crypto tree.

#67 lore raw

RE: [EXT] Re: [PATCH v5 1/3] ethdev: add IPsec SA expiry event subtypes

Quoted 42 lines

24/09/2022 15:57, Akhil Goyal:

Quoted 28 lines

From: Vamsi Attunuru <[email protected]>

Patch adds new event subtypes for notifying expiry events upon reaching IPsec SA soft packet expiry and hard packet/byte expiry limits.

---

lib/ethdev/rte_ethdev.h +11 -1
@@ -3875,8 +3875,26 @@ enum rte_eth_event_ipsec_subtype {
 	RTE_ETH_EVENT_IPSEC_ESN_OVERFLOW,
 	/** Soft time expiry of SA */
 	RTE_ETH_EVENT_IPSEC_SA_TIME_EXPIRY,
-	/** Soft byte expiry of SA */
+	/**
+	 * Soft byte expiry of SA determined by @ref bytes_soft_limit
+	 * defined in @ref rte_security_ipsec_lifetime
+	 */
 	RTE_ETH_EVENT_IPSEC_SA_BYTE_EXPIRY,
+	/**
+	 * Soft packet expiry of SA determined by @ref packets_soft_limit
+	 * defined in @ref rte_security_ipsec_lifetime
+	 */
+	RTE_ETH_EVENT_IPSEC_SA_PKT_EXPIRY,
+	/**
+	 * Hard byte expiry of SA determined by @ref bytes_hard_limit

lib/ethdev/rte_ethdev.h enum rte_eth_event_ipsec_subtype { · line 3899

Quoted 10 lines
lib/ethdev/rte_ethdev.h +8 -0
+	 * defined in @ref rte_security_ipsec_lifetime
+	 */
+	RTE_ETH_EVENT_IPSEC_SA_BYTE_HARD_EXPIRY,
+	/**
+	 * Hard packet expiry of SA determined by @ref packets_hard_limit
+	 * defined in @ref rte_security_ipsec_lifetime
+	 */
+	RTE_ETH_EVENT_IPSEC_SA_PKT_HARD_EXPIRY,
 	/** Max value of this enum */
 	RTE_ETH_EVENT_IPSEC_MAX

I would prefer we remove this MAX value, but it would be another patch.

Quoted 4 lines

You can merge this patch in the crypto tree.

Series Applied to dpdk-next-crypto

#68 lore raw

PATCH v5 2/3 test/security: add inline IPsec SA soft expiry cases

In reply to Akhil Goyal

From: Vamsi Attunuru <[email protected]>

Patch adds unit tests for packet & byte soft expiry events.

---
 app/test/test_cryptodev_security_ipsec.h      |   2 +
 app/test/test_security_inline_proto.c         | 105 +++++++++++++++++-
 app/test/test_security_inline_proto_vectors.h |   6 +
 3 files changed, 112 insertions(+), 1 deletion(-)
app/test/test_cryptodev_security_ipsec.h +2 -0
index 744dd64a9e..9a3c021dd8 100644
@@ -86,6 +86,8 @@ struct ipsec_test_flags {
 	bool display_alg;
 	bool sa_expiry_pkts_soft;
 	bool sa_expiry_pkts_hard;
+	bool sa_expiry_bytes_soft;
+	bool sa_expiry_bytes_hard;
 	bool icv_corrupt;
 	bool iv_gen;
 	uint32_t tunnel_hdr_verify;
app/test/test_security_inline_proto.c +104 -1

157 lines not on this page · raw message

app/test/test_security_inline_proto_vectors.h +6 -0
index c18965d80f..003537e200 100644
@@ -36,6 +36,12 @@ struct reassembly_vector {
 	bool burst;
 };
 
+struct sa_expiry_vector {
+	struct ipsec_session_data *sa_data;
+	enum rte_eth_event_ipsec_subtype event;
+	bool notify_event;
+};
+
 /* The source file includes below test vectors */
 /* IPv6:
  *
Signature · 1 line
2.25.1
#69 lore raw

PATCH v5 3/3 test/security: add inline IPsec SA hard expiry cases

In reply to Akhil Goyal

From: Vamsi Attunuru <[email protected]>

Patch adds hard expiry unit tests for both packet
and byte limits.

---
 app/test/test_security_inline_proto.c | 71 +++++++++++++++++++++++----
 1 file changed, 61 insertions(+), 10 deletions(-)
app/test/test_security_inline_proto.c +61 -10
index 5747ee0990..8d0dd7765c 100644
@@ -969,18 +969,25 @@ test_ipsec_inline_sa_exp_event_callback(uint16_t port_id,
 		printf("Mismatch in event specific metadata\n");
 		return -1;
 	}
-	if (event_desc->subtype == RTE_ETH_EVENT_IPSEC_SA_PKT_EXPIRY) {
+	switch (event_desc->subtype) {
+	case RTE_ETH_EVENT_IPSEC_SA_PKT_EXPIRY:
 		vector->event = RTE_ETH_EVENT_IPSEC_SA_PKT_EXPIRY;
-		return 0;
-	} else if (event_desc->subtype == RTE_ETH_EVENT_IPSEC_SA_BYTE_EXPIRY) {
+		break;
+	case RTE_ETH_EVENT_IPSEC_SA_BYTE_EXPIRY:
 		vector->event = RTE_ETH_EVENT_IPSEC_SA_BYTE_EXPIRY;
-		return 0;
-	} else if (event_desc->subtype >= RTE_ETH_EVENT_IPSEC_MAX) {
+		break;
+	case RTE_ETH_EVENT_IPSEC_SA_PKT_HARD_EXPIRY:
+		vector->event = RTE_ETH_EVENT_IPSEC_SA_PKT_HARD_EXPIRY;
+		break;
+	case RTE_ETH_EVENT_IPSEC_SA_BYTE_HARD_EXPIRY:
+		vector->event = RTE_ETH_EVENT_IPSEC_SA_BYTE_HARD_EXPIRY;
+		break;
+	default:
 		printf("Invalid IPsec event reported\n");
 		return -1;
 	}
 
-	return -1;
+	return 0;
 }
 
 static enum rte_eth_event_ipsec_subtype
@@ -995,8 +1002,12 @@ test_ipsec_inline_setup_expiry_vector(struct sa_expiry_vector *vector,
 	vector->sa_data = (void *)tdata;
 	if (flags->sa_expiry_pkts_soft)
 		event = RTE_ETH_EVENT_IPSEC_SA_PKT_EXPIRY;
-	else
+	else if (flags->sa_expiry_bytes_soft)
 		event = RTE_ETH_EVENT_IPSEC_SA_BYTE_EXPIRY;
+	else if (flags->sa_expiry_pkts_hard)
+		event = RTE_ETH_EVENT_IPSEC_SA_PKT_HARD_EXPIRY;
+	else
+		event = RTE_ETH_EVENT_IPSEC_SA_BYTE_HARD_EXPIRY;
 	rte_eth_dev_callback_register(port_id, RTE_ETH_EVENT_IPSEC,
 		       test_ipsec_inline_sa_exp_event_callback, vector);
 
@@ -1024,7 +1035,8 @@ test_ipsec_inline_proto_process(struct ipsec_test_data *td,
 
 	memset(rx_pkts_burst, 0, sizeof(rx_pkts_burst[0]) * nb_pkts);
 
-	if (flags->sa_expiry_pkts_soft || flags->sa_expiry_bytes_soft) {
+	if (flags->sa_expiry_pkts_soft || flags->sa_expiry_bytes_soft ||
+		flags->sa_expiry_pkts_hard || flags->sa_expiry_bytes_hard) {
 		if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS)
 			return TEST_SUCCESS;
 		event = test_ipsec_inline_setup_expiry_vector(&vector, flags, td);
@@ -1112,7 +1124,9 @@ test_ipsec_inline_proto_process(struct ipsec_test_data *td,
 				break;
 		} while (j++ < 5 || nb_rx == 0);
 
-	if (nb_rx != nb_sent) {
+	if (!flags->sa_expiry_pkts_hard &&
+			!flags->sa_expiry_bytes_hard &&
+			(nb_rx != nb_sent)) {
 		printf("\nUnable to RX all %d packets, received(%i)",
 				nb_sent, nb_rx);
 		while (--nb_rx >= 0)
@@ -1147,7 +1161,8 @@ test_ipsec_inline_proto_process(struct ipsec_test_data *td,
 out:
 	if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS)
 		destroy_default_flow(port_id);
-	if (flags->sa_expiry_pkts_soft || flags->sa_expiry_bytes_soft) {
+	if (flags->sa_expiry_pkts_soft || flags->sa_expiry_bytes_soft ||
+		flags->sa_expiry_pkts_hard || flags->sa_expiry_bytes_hard) {
 		if (vector.notify_event && (vector.event == event))
 			ret = TEST_SUCCESS;
 		else
@@ -1174,6 +1189,7 @@ test_ipsec_inline_proto_all(const struct ipsec_test_flags *flags)
 
 	if (flags->iv_gen || flags->sa_expiry_pkts_soft ||
 			flags->sa_expiry_bytes_soft ||
+			flags->sa_expiry_bytes_hard ||
 			flags->sa_expiry_pkts_hard)
 		nb_pkts = IPSEC_TEST_PACKETS_MAX;
 
@@ -1210,6 +1226,13 @@ test_ipsec_inline_proto_all(const struct ipsec_test_flags *flags)
 			td_outb.ipsec_xform.life.bytes_soft_limit =
 				(((td_outb.output_text.len + RTE_ETHER_HDR_LEN)
 				  * nb_pkts) >> 3) - 1;
+		if (flags->sa_expiry_pkts_hard)
+			td_outb.ipsec_xform.life.packets_hard_limit =
+					IPSEC_TEST_PACKETS_MAX - 1;
+		if (flags->sa_expiry_bytes_hard)
+			td_outb.ipsec_xform.life.bytes_hard_limit =
+				(((td_outb.output_text.len + RTE_ETHER_HDR_LEN)
+				  * nb_pkts) >> 3) - 1;
 
 		ret = test_ipsec_inline_proto_process(&td_outb, &td_inb, nb_pkts,
 						false, flags);
@@ -2338,6 +2361,26 @@ test_ipsec_inline_proto_sa_byte_soft_expiry(const void *data __rte_unused)
 	return test_ipsec_inline_proto_all(&flags);
 }
 
+static int
+test_ipsec_inline_proto_sa_pkt_hard_expiry(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags = {
+		.sa_expiry_pkts_hard = true
+	};
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_sa_byte_hard_expiry(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags = {
+		.sa_expiry_bytes_hard = true
+	};
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
 static int
 test_ipsec_inline_proto_known_vec_fragmented(const void *test_data)
 {
@@ -2748,6 +2791,14 @@ static struct unit_test_suite inline_ipsec_testsuite  = {
 			"SA soft expiry with byte limit",
 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
 			test_ipsec_inline_proto_sa_byte_soft_expiry),
+		TEST_CASE_NAMED_ST(
+			"SA hard expiry with packet limit",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_sa_pkt_hard_expiry),
+		TEST_CASE_NAMED_ST(
+			"SA hard expiry with byte limit",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_sa_byte_hard_expiry),
 
 		TEST_CASE_NAMED_WITH_DATA(
 			"Antireplay with window size 1024",
Signature · 1 line
2.25.1
#70 lore raw

v6 cover Add and test IPsec SA expiry events

In reply to Akhil Goyal

This patchset is carried forward from last release patches [1] which added test application changes to test inline IPsec. These patches were not merged due to the ABI compatibility issues due to the extension of enum.

Changes in v6:
fix doc build in 1/3

Changes in v5:
added reference to struct which raised these interrupts.

[1] https://patches.dpdk.org/project/dpdk/patch/[email protected]/

Vamsi Attunuru (3):
ethdev: add IPsec SA expiry event subtypes test/security: add inline IPsec SA soft expiry cases test/security: add inline IPsec SA hard expiry cases

 app/test/test_cryptodev_security_ipsec.h      |   2 +
 app/test/test_security_inline_proto.c         | 158 +++++++++++++++++-
 app/test/test_security_inline_proto_vectors.h |   6 +
 lib/ethdev/rte_ethdev.h                       |  23 ++-
 4 files changed, 186 insertions(+), 3 deletions(-)
Signature · 1 line
2.25.1
#71 lore raw

PATCH v6 1/3 ethdev: add IPsec SA expiry event subtypes

From: Vamsi Attunuru <[email protected]>

Patch adds new event subtypes for notifying expiry events upon reaching IPsec SA soft packet expiry and hard packet/byte expiry limits.

---
 lib/ethdev/rte_ethdev.h | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)
lib/ethdev/rte_ethdev.h +22 -1
index 2e783536c1..3ee6786a79 100644
@@ -3875,8 +3875,26 @@ enum rte_eth_event_ipsec_subtype {
 	RTE_ETH_EVENT_IPSEC_ESN_OVERFLOW,
 	/** Soft time expiry of SA */
 	RTE_ETH_EVENT_IPSEC_SA_TIME_EXPIRY,
-	/** Soft byte expiry of SA */
+	/**
+	 * Soft byte expiry of SA determined by
+	 * @ref rte_security_ipsec_lifetime::bytes_soft_limit
+	 */
 	RTE_ETH_EVENT_IPSEC_SA_BYTE_EXPIRY,
+	/**
+	 * Soft packet expiry of SA determined by
+	 * @ref rte_security_ipsec_lifetime::packets_soft_limit
+	 */
+	RTE_ETH_EVENT_IPSEC_SA_PKT_EXPIRY,
+	/**
+	 * Hard byte expiry of SA determined by
+	 * @ref rte_security_ipsec_lifetime::bytes_hard_limit
+	 */
+	RTE_ETH_EVENT_IPSEC_SA_BYTE_HARD_EXPIRY,
+	/**
+	 * Hard packet expiry of SA determined by
+	 * @ref rte_security_ipsec_lifetime::packets_hard_limit
+	 */
+	RTE_ETH_EVENT_IPSEC_SA_PKT_HARD_EXPIRY,
 	/** Max value of this enum */
 	RTE_ETH_EVENT_IPSEC_MAX
 };
@@ -3898,6 +3916,9 @@ struct rte_eth_event_ipsec_desc {
 	 * - @ref RTE_ETH_EVENT_IPSEC_ESN_OVERFLOW
 	 * - @ref RTE_ETH_EVENT_IPSEC_SA_TIME_EXPIRY
 	 * - @ref RTE_ETH_EVENT_IPSEC_SA_BYTE_EXPIRY
+	 * - @ref RTE_ETH_EVENT_IPSEC_SA_PKT_EXPIRY
+	 * - @ref RTE_ETH_EVENT_IPSEC_SA_BYTE_HARD_EXPIRY
+	 * - @ref RTE_ETH_EVENT_IPSEC_SA_PKT_HARD_EXPIRY
 	 *
 	 * @see struct rte_security_session_conf
 	 *
Signature · 1 line
2.25.1
#72 lore raw

PATCH v6 2/3 test/security: add inline IPsec SA soft expiry cases

In reply to Akhil Goyal

From: Vamsi Attunuru <[email protected]>

Patch adds unit tests for packet & byte soft expiry events.

---
 app/test/test_cryptodev_security_ipsec.h      |   2 +
 app/test/test_security_inline_proto.c         | 105 +++++++++++++++++-
 app/test/test_security_inline_proto_vectors.h |   6 +
 3 files changed, 112 insertions(+), 1 deletion(-)
app/test/test_cryptodev_security_ipsec.h +2 -0
index 744dd64a9e..9a3c021dd8 100644
@@ -86,6 +86,8 @@ struct ipsec_test_flags {
 	bool display_alg;
 	bool sa_expiry_pkts_soft;
 	bool sa_expiry_pkts_hard;
+	bool sa_expiry_bytes_soft;
+	bool sa_expiry_bytes_hard;
 	bool icv_corrupt;
 	bool iv_gen;
 	uint32_t tunnel_hdr_verify;
app/test/test_security_inline_proto.c +104 -1

157 lines not on this page · raw message

app/test/test_security_inline_proto_vectors.h +6 -0
index c18965d80f..003537e200 100644
@@ -36,6 +36,12 @@ struct reassembly_vector {
 	bool burst;
 };
 
+struct sa_expiry_vector {
+	struct ipsec_session_data *sa_data;
+	enum rte_eth_event_ipsec_subtype event;
+	bool notify_event;
+};
+
 /* The source file includes below test vectors */
 /* IPv6:
  *
Signature · 1 line
2.25.1
#73 lore raw

PATCH v6 3/3 test/security: add inline IPsec SA hard expiry cases

In reply to Akhil Goyal

From: Vamsi Attunuru <[email protected]>

Patch adds hard expiry unit tests for both packet
and byte limits.

---
 app/test/test_security_inline_proto.c | 71 +++++++++++++++++++++++----
 1 file changed, 61 insertions(+), 10 deletions(-)
app/test/test_security_inline_proto.c +61 -10
index 5747ee0990..8d0dd7765c 100644
@@ -969,18 +969,25 @@ test_ipsec_inline_sa_exp_event_callback(uint16_t port_id,
 		printf("Mismatch in event specific metadata\n");
 		return -1;
 	}
-	if (event_desc->subtype == RTE_ETH_EVENT_IPSEC_SA_PKT_EXPIRY) {
+	switch (event_desc->subtype) {
+	case RTE_ETH_EVENT_IPSEC_SA_PKT_EXPIRY:
 		vector->event = RTE_ETH_EVENT_IPSEC_SA_PKT_EXPIRY;
-		return 0;
-	} else if (event_desc->subtype == RTE_ETH_EVENT_IPSEC_SA_BYTE_EXPIRY) {
+		break;
+	case RTE_ETH_EVENT_IPSEC_SA_BYTE_EXPIRY:
 		vector->event = RTE_ETH_EVENT_IPSEC_SA_BYTE_EXPIRY;
-		return 0;
-	} else if (event_desc->subtype >= RTE_ETH_EVENT_IPSEC_MAX) {
+		break;
+	case RTE_ETH_EVENT_IPSEC_SA_PKT_HARD_EXPIRY:
+		vector->event = RTE_ETH_EVENT_IPSEC_SA_PKT_HARD_EXPIRY;
+		break;
+	case RTE_ETH_EVENT_IPSEC_SA_BYTE_HARD_EXPIRY:
+		vector->event = RTE_ETH_EVENT_IPSEC_SA_BYTE_HARD_EXPIRY;
+		break;
+	default:
 		printf("Invalid IPsec event reported\n");
 		return -1;
 	}
 
-	return -1;
+	return 0;
 }
 
 static enum rte_eth_event_ipsec_subtype
@@ -995,8 +1002,12 @@ test_ipsec_inline_setup_expiry_vector(struct sa_expiry_vector *vector,
 	vector->sa_data = (void *)tdata;
 	if (flags->sa_expiry_pkts_soft)
 		event = RTE_ETH_EVENT_IPSEC_SA_PKT_EXPIRY;
-	else
+	else if (flags->sa_expiry_bytes_soft)
 		event = RTE_ETH_EVENT_IPSEC_SA_BYTE_EXPIRY;
+	else if (flags->sa_expiry_pkts_hard)
+		event = RTE_ETH_EVENT_IPSEC_SA_PKT_HARD_EXPIRY;
+	else
+		event = RTE_ETH_EVENT_IPSEC_SA_BYTE_HARD_EXPIRY;
 	rte_eth_dev_callback_register(port_id, RTE_ETH_EVENT_IPSEC,
 		       test_ipsec_inline_sa_exp_event_callback, vector);
 
@@ -1024,7 +1035,8 @@ test_ipsec_inline_proto_process(struct ipsec_test_data *td,
 
 	memset(rx_pkts_burst, 0, sizeof(rx_pkts_burst[0]) * nb_pkts);
 
-	if (flags->sa_expiry_pkts_soft || flags->sa_expiry_bytes_soft) {
+	if (flags->sa_expiry_pkts_soft || flags->sa_expiry_bytes_soft ||
+		flags->sa_expiry_pkts_hard || flags->sa_expiry_bytes_hard) {
 		if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS)
 			return TEST_SUCCESS;
 		event = test_ipsec_inline_setup_expiry_vector(&vector, flags, td);
@@ -1112,7 +1124,9 @@ test_ipsec_inline_proto_process(struct ipsec_test_data *td,
 				break;
 		} while (j++ < 5 || nb_rx == 0);
 
-	if (nb_rx != nb_sent) {
+	if (!flags->sa_expiry_pkts_hard &&
+			!flags->sa_expiry_bytes_hard &&
+			(nb_rx != nb_sent)) {
 		printf("\nUnable to RX all %d packets, received(%i)",
 				nb_sent, nb_rx);
 		while (--nb_rx >= 0)
@@ -1147,7 +1161,8 @@ test_ipsec_inline_proto_process(struct ipsec_test_data *td,
 out:
 	if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS)
 		destroy_default_flow(port_id);
-	if (flags->sa_expiry_pkts_soft || flags->sa_expiry_bytes_soft) {
+	if (flags->sa_expiry_pkts_soft || flags->sa_expiry_bytes_soft ||
+		flags->sa_expiry_pkts_hard || flags->sa_expiry_bytes_hard) {
 		if (vector.notify_event && (vector.event == event))
 			ret = TEST_SUCCESS;
 		else
@@ -1174,6 +1189,7 @@ test_ipsec_inline_proto_all(const struct ipsec_test_flags *flags)
 
 	if (flags->iv_gen || flags->sa_expiry_pkts_soft ||
 			flags->sa_expiry_bytes_soft ||
+			flags->sa_expiry_bytes_hard ||
 			flags->sa_expiry_pkts_hard)
 		nb_pkts = IPSEC_TEST_PACKETS_MAX;
 
@@ -1210,6 +1226,13 @@ test_ipsec_inline_proto_all(const struct ipsec_test_flags *flags)
 			td_outb.ipsec_xform.life.bytes_soft_limit =
 				(((td_outb.output_text.len + RTE_ETHER_HDR_LEN)
 				  * nb_pkts) >> 3) - 1;
+		if (flags->sa_expiry_pkts_hard)
+			td_outb.ipsec_xform.life.packets_hard_limit =
+					IPSEC_TEST_PACKETS_MAX - 1;
+		if (flags->sa_expiry_bytes_hard)
+			td_outb.ipsec_xform.life.bytes_hard_limit =
+				(((td_outb.output_text.len + RTE_ETHER_HDR_LEN)
+				  * nb_pkts) >> 3) - 1;
 
 		ret = test_ipsec_inline_proto_process(&td_outb, &td_inb, nb_pkts,
 						false, flags);
@@ -2338,6 +2361,26 @@ test_ipsec_inline_proto_sa_byte_soft_expiry(const void *data __rte_unused)
 	return test_ipsec_inline_proto_all(&flags);
 }
 
+static int
+test_ipsec_inline_proto_sa_pkt_hard_expiry(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags = {
+		.sa_expiry_pkts_hard = true
+	};
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_sa_byte_hard_expiry(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags = {
+		.sa_expiry_bytes_hard = true
+	};
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
 static int
 test_ipsec_inline_proto_known_vec_fragmented(const void *test_data)
 {
@@ -2748,6 +2791,14 @@ static struct unit_test_suite inline_ipsec_testsuite  = {
 			"SA soft expiry with byte limit",
 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
 			test_ipsec_inline_proto_sa_byte_soft_expiry),
+		TEST_CASE_NAMED_ST(
+			"SA hard expiry with packet limit",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_sa_pkt_hard_expiry),
+		TEST_CASE_NAMED_ST(
+			"SA hard expiry with byte limit",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_sa_byte_hard_expiry),
 
 		TEST_CASE_NAMED_WITH_DATA(
 			"Antireplay with window size 1024",
Signature · 1 line
2.25.1
#74 lore raw

PATCH v4 8/10 test/security: add inline IPsec SA soft expiry cases

In reply to Akhil Goyal

From: Vamsi Attunuru <[email protected]>

Patch adds unit tests for packet & byte soft expiry events.

---
 app/test/test_cryptodev_security_ipsec.h      |   2 +
 app/test/test_security_inline_proto.c         | 105 +++++++++++++++++-
 app/test/test_security_inline_proto_vectors.h |   6 +
 3 files changed, 112 insertions(+), 1 deletion(-)
app/test/test_cryptodev_security_ipsec.h +2 -0
index 0d9b5b6e2e..418ab16ba6 100644
@@ -77,6 +77,8 @@ struct ipsec_test_flags {
 	bool display_alg;
 	bool sa_expiry_pkts_soft;
 	bool sa_expiry_pkts_hard;
+	bool sa_expiry_bytes_soft;
+	bool sa_expiry_bytes_hard;
 	bool icv_corrupt;
 	bool iv_gen;
 	uint32_t tunnel_hdr_verify;
app/test/test_security_inline_proto.c +104 -1

157 lines not on this page · raw message

app/test/test_security_inline_proto_vectors.h +6 -0
index c18965d80f..003537e200 100644
@@ -36,6 +36,12 @@ struct reassembly_vector {
 	bool burst;
 };
 
+struct sa_expiry_vector {
+	struct ipsec_session_data *sa_data;
+	enum rte_eth_event_ipsec_subtype event;
+	bool notify_event;
+};
+
 /* The source file includes below test vectors */
 /* IPv6:
  *
Signature · 1 line
2.25.1
#75 lore raw

PATCH v4 9/10 test/security: add inline IPsec SA hard expiry cases

In reply to Akhil Goyal

From: Vamsi Attunuru <[email protected]>

Patch adds hard expiry unit tests for both packet
and byte limits.

---
 app/test/test_security_inline_proto.c | 71 +++++++++++++++++++++++----
 1 file changed, 61 insertions(+), 10 deletions(-)
app/test/test_security_inline_proto.c +61 -10
index 5b111af53e..15f08a2d6c 100644
@@ -896,18 +896,25 @@ test_ipsec_inline_sa_exp_event_callback(uint16_t port_id,
 		printf("Mismatch in event specific metadata\n");
 		return -1;
 	}
-	if (event_desc->subtype == RTE_ETH_EVENT_IPSEC_SA_PKT_EXPIRY) {
+	switch (event_desc->subtype) {
+	case RTE_ETH_EVENT_IPSEC_SA_PKT_EXPIRY:
 		vector->event = RTE_ETH_EVENT_IPSEC_SA_PKT_EXPIRY;
-		return 0;
-	} else if (event_desc->subtype == RTE_ETH_EVENT_IPSEC_SA_BYTE_EXPIRY) {
+		break;
+	case RTE_ETH_EVENT_IPSEC_SA_BYTE_EXPIRY:
 		vector->event = RTE_ETH_EVENT_IPSEC_SA_BYTE_EXPIRY;
-		return 0;
-	} else if (event_desc->subtype >= RTE_ETH_EVENT_IPSEC_MAX) {
+		break;
+	case RTE_ETH_EVENT_IPSEC_SA_PKT_HARD_EXPIRY:
+		vector->event = RTE_ETH_EVENT_IPSEC_SA_PKT_HARD_EXPIRY;
+		break;
+	case RTE_ETH_EVENT_IPSEC_SA_BYTE_HARD_EXPIRY:
+		vector->event = RTE_ETH_EVENT_IPSEC_SA_BYTE_HARD_EXPIRY;
+		break;
+	default:
 		printf("Invalid IPsec event reported\n");
 		return -1;
 	}
 
-	return -1;
+	return 0;
 }
 
 static enum rte_eth_event_ipsec_subtype
@@ -922,8 +929,12 @@ test_ipsec_inline_setup_expiry_vector(struct sa_expiry_vector *vector,
 	vector->sa_data = (void *)tdata;
 	if (flags->sa_expiry_pkts_soft)
 		event = RTE_ETH_EVENT_IPSEC_SA_PKT_EXPIRY;
-	else
+	else if (flags->sa_expiry_bytes_soft)
 		event = RTE_ETH_EVENT_IPSEC_SA_BYTE_EXPIRY;
+	else if (flags->sa_expiry_pkts_hard)
+		event = RTE_ETH_EVENT_IPSEC_SA_PKT_HARD_EXPIRY;
+	else
+		event = RTE_ETH_EVENT_IPSEC_SA_BYTE_HARD_EXPIRY;
 	rte_eth_dev_callback_register(port_id, RTE_ETH_EVENT_IPSEC,
 		       test_ipsec_inline_sa_exp_event_callback, vector);
 
@@ -951,7 +962,8 @@ test_ipsec_inline_proto_process(struct ipsec_test_data *td,
 
 	memset(rx_pkts_burst, 0, sizeof(rx_pkts_burst[0]) * nb_pkts);
 
-	if (flags->sa_expiry_pkts_soft || flags->sa_expiry_bytes_soft) {
+	if (flags->sa_expiry_pkts_soft || flags->sa_expiry_bytes_soft ||
+		flags->sa_expiry_pkts_hard || flags->sa_expiry_bytes_hard) {
 		if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS)
 			return TEST_SUCCESS;
 		event = test_ipsec_inline_setup_expiry_vector(&vector, flags, td);
@@ -1029,7 +1041,9 @@ test_ipsec_inline_proto_process(struct ipsec_test_data *td,
 			break;
 	} while (j++ < 5 || nb_rx == 0);
 
-	if (nb_rx != nb_sent) {
+	if (!flags->sa_expiry_pkts_hard &&
+		!flags->sa_expiry_bytes_hard &&
+		(nb_rx != nb_sent)) {
 		printf("\nUnable to RX all %d packets", nb_sent);
 		while(--nb_rx)
 			rte_pktmbuf_free(rx_pkts_burst[nb_rx]);
@@ -1063,7 +1077,8 @@ test_ipsec_inline_proto_process(struct ipsec_test_data *td,
 out:
 	if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS)
 		destroy_default_flow(port_id);
-	if (flags->sa_expiry_pkts_soft || flags->sa_expiry_bytes_soft) {
+	if (flags->sa_expiry_pkts_soft || flags->sa_expiry_bytes_soft ||
+		flags->sa_expiry_pkts_hard || flags->sa_expiry_bytes_hard) {
 		if (vector.notify_event && (vector.event == event))
 			ret = TEST_SUCCESS;
 		else
@@ -1090,6 +1105,7 @@ test_ipsec_inline_proto_all(const struct ipsec_test_flags *flags)
 
 	if (flags->iv_gen || flags->sa_expiry_pkts_soft ||
 			flags->sa_expiry_bytes_soft ||
+			flags->sa_expiry_bytes_hard ||
 			flags->sa_expiry_pkts_hard)
 		nb_pkts = IPSEC_TEST_PACKETS_MAX;
 
@@ -1126,6 +1142,13 @@ test_ipsec_inline_proto_all(const struct ipsec_test_flags *flags)
 			td_outb.ipsec_xform.life.bytes_soft_limit =
 				(((td_outb.output_text.len + RTE_ETHER_HDR_LEN)
 				  * nb_pkts) >> 3) - 1;
+		if (flags->sa_expiry_pkts_hard)
+			td_outb.ipsec_xform.life.packets_hard_limit =
+					IPSEC_TEST_PACKETS_MAX - 1;
+		if (flags->sa_expiry_bytes_hard)
+			td_outb.ipsec_xform.life.bytes_hard_limit =
+				(((td_outb.output_text.len + RTE_ETHER_HDR_LEN)
+				  * nb_pkts) >> 3) - 1;
 
 		ret = test_ipsec_inline_proto_process(&td_outb, &td_inb, nb_pkts,
 						false, flags);
@@ -1910,6 +1933,26 @@ test_ipsec_inline_proto_sa_byte_soft_expiry(const void *data __rte_unused)
 	return test_ipsec_inline_proto_all(&flags);
 }
 
+static int
+test_ipsec_inline_proto_sa_pkt_hard_expiry(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags = {
+		.sa_expiry_pkts_hard = true
+	};
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_sa_byte_hard_expiry(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags = {
+		.sa_expiry_bytes_hard = true
+	};
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
 static int
 test_ipsec_inline_proto_known_vec_fragmented(const void *test_data)
 {
@@ -2306,6 +2349,14 @@ static struct unit_test_suite inline_ipsec_testsuite  = {
 			"SA soft expiry with byte limit",
 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
 			test_ipsec_inline_proto_sa_byte_soft_expiry),
+		TEST_CASE_NAMED_ST(
+			"SA hard expiry with packet limit",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_sa_pkt_hard_expiry),
+		TEST_CASE_NAMED_ST(
+			"SA hard expiry with byte limit",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_sa_byte_hard_expiry),
 
 		TEST_CASE_NAMED_WITH_DATA(
 			"Antireplay with window size 1024",
Signature · 1 line
2.25.1
#76 lore raw

PATCH v4 10/10 test/security: add inline IPsec IPv6 flow label cases

In reply to Akhil Goyal

From: Vamsi Attunuru <[email protected]>

Patch adds unit tests for IPv6 flow label set & copy operations.

---
 app/test/test_cryptodev_security_ipsec.c | 35 ++++++++++-
 app/test/test_cryptodev_security_ipsec.h | 10 +++
 app/test/test_security_inline_proto.c    | 79 ++++++++++++++++++++++++
 3 files changed, 123 insertions(+), 1 deletion(-)
app/test/test_cryptodev_security_ipsec.c +34 -1
index 14c6ba681f..408bd0bc82 100644
@@ -495,6 +495,10 @@ test_ipsec_td_prepare(const struct crypto_param *param1,
 		    flags->dscp == TEST_IPSEC_COPY_DSCP_INNER_1)
 			td->ipsec_xform.options.copy_dscp = 1;
 
+		if (flags->flabel == TEST_IPSEC_COPY_FLABEL_INNER_0 ||
+		    flags->flabel == TEST_IPSEC_COPY_FLABEL_INNER_1)
+			td->ipsec_xform.options.copy_flabel = 1;
+
 		if (flags->dec_ttl_or_hop_limit)
 			td->ipsec_xform.options.dec_ttl = 1;
 	}
@@ -933,6 +937,7 @@ test_ipsec_iph6_hdr_validate(const struct rte_ipv6_hdr *iph6,
 			     const struct ipsec_test_flags *flags)
 {
 	uint32_t vtc_flow;
+	uint32_t flabel;
 	uint8_t dscp;
 
 	if (!is_valid_ipv6_pkt(iph6)) {
@@ -959,6 +964,23 @@ test_ipsec_iph6_hdr_validate(const struct rte_ipv6_hdr *iph6,
 		}
 	}
 
+	flabel = vtc_flow & RTE_IPV6_HDR_FL_MASK;
+
+	if (flags->flabel == TEST_IPSEC_COPY_FLABEL_INNER_1 ||
+	    flags->flabel == TEST_IPSEC_SET_FLABEL_1_INNER_0) {
+		if (flabel != TEST_IPSEC_FLABEL_VAL) {
+			printf("FLABEL value is not matching [exp: %x, actual: %x]\n",
+			       TEST_IPSEC_FLABEL_VAL, flabel);
+			return -1;
+		}
+	} else {
+		if (flabel != 0) {
+			printf("FLABEL value is set [exp: 0, actual: %x]\n",
+			       flabel);
+			return -1;
+		}
+	}
+
 	return 0;
 }
 
@@ -1159,7 +1181,11 @@ test_ipsec_pkt_update(uint8_t *pkt, const struct ipsec_test_flags *flags)
 	if (flags->dscp == TEST_IPSEC_COPY_DSCP_INNER_1 ||
 	    flags->dscp == TEST_IPSEC_SET_DSCP_0_INNER_1 ||
 	    flags->dscp == TEST_IPSEC_COPY_DSCP_INNER_0 ||
-	    flags->dscp == TEST_IPSEC_SET_DSCP_1_INNER_0) {
+	    flags->dscp == TEST_IPSEC_SET_DSCP_1_INNER_0 ||
+	    flags->flabel == TEST_IPSEC_COPY_FLABEL_INNER_1 ||
+	    flags->flabel == TEST_IPSEC_SET_FLABEL_0_INNER_1 ||
+	    flags->flabel == TEST_IPSEC_COPY_FLABEL_INNER_0 ||
+	    flags->flabel == TEST_IPSEC_SET_FLABEL_1_INNER_0) {
 
 		if (is_ipv4(iph4)) {
 			uint8_t tos;
@@ -1187,6 +1213,13 @@ test_ipsec_pkt_update(uint8_t *pkt, const struct ipsec_test_flags *flags)
 			else
 				vtc_flow &= ~RTE_IPV6_HDR_DSCP_MASK;
 
+			if (flags->flabel == TEST_IPSEC_COPY_FLABEL_INNER_1 ||
+			    flags->flabel == TEST_IPSEC_SET_FLABEL_0_INNER_1)
+				vtc_flow |= (RTE_IPV6_HDR_FL_MASK &
+					     (TEST_IPSEC_FLABEL_VAL << RTE_IPV6_HDR_FL_SHIFT));
+			else
+				vtc_flow &= ~RTE_IPV6_HDR_FL_MASK;
+
 			iph6->vtc_flow = rte_cpu_to_be_32(vtc_flow);
 		}
 	}
app/test/test_cryptodev_security_ipsec.h +10 -0
index 418ab16ba6..9a3c021dd8 100644
@@ -73,6 +73,15 @@ enum dscp_flags {
 	TEST_IPSEC_SET_DSCP_1_INNER_0,
 };
 
+#define TEST_IPSEC_FLABEL_VAL 0x1234
+
+enum flabel_flags {
+	TEST_IPSEC_COPY_FLABEL_INNER_0 = 1,
+	TEST_IPSEC_COPY_FLABEL_INNER_1,
+	TEST_IPSEC_SET_FLABEL_0_INNER_1,
+	TEST_IPSEC_SET_FLABEL_1_INNER_0,
+};
+
 struct ipsec_test_flags {
 	bool display_alg;
 	bool sa_expiry_pkts_soft;
@@ -94,6 +103,7 @@ struct ipsec_test_flags {
 	bool antireplay;
 	enum df_flags df;
 	enum dscp_flags dscp;
+	enum flabel_flags flabel;
 	bool dec_ttl_or_hop_limit;
 	bool ah;
 };
app/test/test_security_inline_proto.c +79 -0

97 lines not on this page · raw message

Signature · 1 line
2.25.1
#77 lore raw

RE: [PATCH v4 10/10] test/security: add inline IPsec IPv6 flow label cases

Hi Akhil, Vamsi,

Please add the same test cases in lookaside IPsec tests also. And please do update release notes.

Thanks,
Anoob

Quoted 250 lines

-----Original Message-----
From: Akhil Goyal <[email protected]>
Sent: Sunday, April 17, 2022 12:56 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Anoob Joseph <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Nithin Kumar Dabilpuram <[email protected]>; Vamsi Krishna Attunuru <[email protected]>
Subject: [PATCH v4 10/10] test/security: add inline IPsec IPv6 flow label cases

From: Vamsi Attunuru <[email protected]>

Patch adds unit tests for IPv6 flow label set & copy operations.

---
 app/test/test_cryptodev_security_ipsec.c | 35 ++++++++++-
app/test/test_cryptodev_security_ipsec.h | 10 +++
 app/test/test_security_inline_proto.c    | 79 ++++++++++++++++++++++++
 3 files changed, 123 insertions(+), 1 deletion(-)
app/test/test_cryptodev_security_ipsec.c +4 -0
index 14c6ba681f..408bd0bc82 100644
@@ -495,6 +495,10 @@ test_ipsec_td_prepare(const struct crypto_param
 *param1,
 		    flags->dscp == TEST_IPSEC_COPY_DSCP_INNER_1)
 			td->ipsec_xform.options.copy_dscp = 1;
 
+		if (flags->flabel == TEST_IPSEC_COPY_FLABEL_INNER_0 ||
+		    flags->flabel == TEST_IPSEC_COPY_FLABEL_INNER_1)
+			td->ipsec_xform.options.copy_flabel = 1;
+
 		if (flags->dec_ttl_or_hop_limit)
 			td->ipsec_xform.options.dec_ttl = 1;
app/test/test_cryptodev_security_ipsec.c +18 -0
 	}
@@ -933,6 +937,7 @@ test_ipsec_iph6_hdr_validate(const struct
 rte_ipv6_hdr *iph6,
 			     const struct ipsec_test_flags *flags)  {
 	uint32_t vtc_flow;
+	uint32_t flabel;
 	uint8_t dscp;
 
 	if (!is_valid_ipv6_pkt(iph6)) {
@@ -959,6 +964,23 @@ test_ipsec_iph6_hdr_validate(const struct
 rte_ipv6_hdr *iph6,
 		}
 	}
 
+	flabel = vtc_flow & RTE_IPV6_HDR_FL_MASK;
+
+	if (flags->flabel == TEST_IPSEC_COPY_FLABEL_INNER_1 ||
+	    flags->flabel == TEST_IPSEC_SET_FLABEL_1_INNER_0) {
+		if (flabel != TEST_IPSEC_FLABEL_VAL) {
+			printf("FLABEL value is not matching [exp: %x, actual:
 %x]\n",
+			       TEST_IPSEC_FLABEL_VAL, flabel);
+			return -1;
+		}
+	} else {
+		if (flabel != 0) {
+			printf("FLABEL value is set [exp: 0, actual: %x]\n",
+			       flabel);
+			return -1;
+		}
+	}
+
 	return 0;

}

app/test/test_cryptodev_security_ipsec.c +5 -1
@@ -1159,7 +1181,11 @@ test_ipsec_pkt_update(uint8_t *pkt, const struct
 ipsec_test_flags *flags)
 	if (flags->dscp == TEST_IPSEC_COPY_DSCP_INNER_1 ||
 	    flags->dscp == TEST_IPSEC_SET_DSCP_0_INNER_1 ||
 	    flags->dscp == TEST_IPSEC_COPY_DSCP_INNER_0 ||
-	    flags->dscp == TEST_IPSEC_SET_DSCP_1_INNER_0) {
+	    flags->dscp == TEST_IPSEC_SET_DSCP_1_INNER_0 ||
+	    flags->flabel == TEST_IPSEC_COPY_FLABEL_INNER_1 ||
+	    flags->flabel == TEST_IPSEC_SET_FLABEL_0_INNER_1 ||
+	    flags->flabel == TEST_IPSEC_COPY_FLABEL_INNER_0 ||
+	    flags->flabel == TEST_IPSEC_SET_FLABEL_1_INNER_0) {
 
 		if (is_ipv4(iph4)) {
app/test/test_cryptodev_security_ipsec.c +1 -0
 			uint8_t tos;
@@ -1187,6 +1213,13 @@ test_ipsec_pkt_update(uint8_t *pkt, const struct
 ipsec_test_flags *flags)
 			else
 				vtc_flow &= ~RTE_IPV6_HDR_DSCP_MASK;
 
+			if (flags->flabel ==

TEST_IPSEC_COPY_FLABEL_INNER_1 ||

app/test/test_cryptodev_security_ipsec.c +1 -0
+			    flags->flabel ==

TEST_IPSEC_SET_FLABEL_0_INNER_1)

app/test/test_cryptodev_security_ipsec.c +2 -0
+				vtc_flow |= (RTE_IPV6_HDR_FL_MASK &
+					     (TEST_IPSEC_FLABEL_VAL <<

RTE_IPV6_HDR_FL_SHIFT));

app/test/test_cryptodev_security_ipsec.c +3 -0
+			else
+				vtc_flow &= ~RTE_IPV6_HDR_FL_MASK;
+
 			iph6->vtc_flow = rte_cpu_to_be_32(vtc_flow);
 		}
 	}
app/test/test_cryptodev_security_ipsec.h +10 -0
index 418ab16ba6..9a3c021dd8 100644
@@ -73,6 +73,15 @@ enum dscp_flags {
 	TEST_IPSEC_SET_DSCP_1_INNER_0,
 };
 
+#define TEST_IPSEC_FLABEL_VAL 0x1234
+
+enum flabel_flags {
+	TEST_IPSEC_COPY_FLABEL_INNER_0 = 1,
+	TEST_IPSEC_COPY_FLABEL_INNER_1,
+	TEST_IPSEC_SET_FLABEL_0_INNER_1,
+	TEST_IPSEC_SET_FLABEL_1_INNER_0,
+};
+
 struct ipsec_test_flags {
 	bool display_alg;
 	bool sa_expiry_pkts_soft;
@@ -94,6 +103,7 @@ struct ipsec_test_flags {
 	bool antireplay;
 	enum df_flags df;
 	enum dscp_flags dscp;
+	enum flabel_flags flabel;
 	bool dec_ttl_or_hop_limit;
 	bool ah;
 };
app/test/test_security_inline_proto.c +7 -0
index 15f08a2d6c..16fe164f77 100644
@@ -163,6 +163,13 @@ create_inline_ipsec_session(struct ipsec_test_data
 *sa, uint16_t portid,
 				sess_conf->ipsec.tunnel.ipv6.dscp =
 						TEST_IPSEC_DSCP_VAL;
 
+			if (flags->flabel ==
 TEST_IPSEC_SET_FLABEL_0_INNER_1)
+				sess_conf->ipsec.tunnel.ipv6.flabel = 0;
+
+			if (flags->flabel ==
 TEST_IPSEC_SET_FLABEL_1_INNER_0)
+				sess_conf->ipsec.tunnel.ipv6.flabel =
+						TEST_IPSEC_FLABEL_VAL;
+

memcpy(&sess_conf->ipsec.tunnel.ipv6.src_addr,
&src_v6,

app/test/test_security_inline_proto.c +0 -0
 					sizeof(src_v6));
 			memcpy(&sess_conf->ipsec.tunnel.ipv6.dst_addr,

&dst_v6, @@ -1883,6 +1890,62 @@ test_ipsec_inline_proto_ipv6_set_dscp_1_inner_0(const void *data __rte_unused)

app/test/test_security_inline_proto.c +56 -0
 	return test_ipsec_inline_proto_all(&flags);
 }
 
+static int
+test_ipsec_inline_proto_ipv6_copy_flabel_inner_0(const void *data
+__rte_unused) {
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.ipv6 = true;
+	flags.tunnel_ipv6 = true;
+	flags.flabel = TEST_IPSEC_COPY_FLABEL_INNER_0;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_ipv6_copy_flabel_inner_1(const void *data
+__rte_unused) {
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.ipv6 = true;
+	flags.tunnel_ipv6 = true;
+	flags.flabel = TEST_IPSEC_COPY_FLABEL_INNER_1;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_ipv6_set_flabel_0_inner_1(const void *data
+__rte_unused) {
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.ipv6 = true;
+	flags.tunnel_ipv6 = true;
+	flags.flabel = TEST_IPSEC_SET_FLABEL_0_INNER_1;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_ipv6_set_flabel_1_inner_0(const void *data
+__rte_unused) {
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.ipv6 = true;
+	flags.tunnel_ipv6 = true;
+	flags.flabel = TEST_IPSEC_SET_FLABEL_1_INNER_0;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
 static int
 test_ipsec_inline_proto_ipv4_ttl_decrement(const void *data

__rte_unused) { @@ -2329,6 +2392,22 @@ static struct unit_test_suite inline_ipsec_testsuite = {

app/test/test_security_inline_proto.c +12 -0
 			"Tunnel header IPv6 set DSCP 1 (inner 0)",
 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
 			test_ipsec_inline_proto_ipv6_set_dscp_1_inner_0),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header IPv6 copy FLABEL (inner 0)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_ipv6_copy_flabel_inner_0),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header IPv6 copy FLABEL (inner 1)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_ipv6_copy_flabel_inner_1),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header IPv6 set FLABEL 0 (inner 1)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+
	test_ipsec_inline_proto_ipv6_set_flabel_0_inner_1),
app/test/test_security_inline_proto.c +4 -0
+		TEST_CASE_NAMED_ST(
+			"Tunnel header IPv6 set FLABEL 1 (inner 0)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+
	test_ipsec_inline_proto_ipv6_set_flabel_1_inner_0),
app/test/test_security_inline_proto.c +0 -1
 		TEST_CASE_NAMED_ST(
 			"Tunnel header IPv4 decrement inner TTL",
 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
--

2.25.1

#78 lore raw

RE: [PATCH v4 10/10] test/security: add inline IPsec IPv6 flow label cases

Hi Anoob,

Quoted 5 lines

Hi Akhil, Vamsi,

Please add the same test cases in lookaside IPsec tests also. And please do update release notes.

I was planning to send it as a separate patchset.

#79 lore raw

RE: [PATCH v4 00/10] app/test: add inline IPsec and reassembly cases

In reply to Akhil Goyal

Hi everyone,

When running inline_ipsec_autotest, tests should be marked as "skipped" rather than "failed".

Kind Regards,
Jakub Poczatek

-----Original Message-----
From: Akhil Goyal <[email protected]>
Sent: Saturday 16 April 2022 20:25
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Ananyev, Konstantin <[email protected]>; Power, Ciara <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]; [email protected]; [email protected]; Akhil Goyal <[email protected]>
Subject: [PATCH v4 00/10] app/test: add inline IPsec and reassembly cases

IP reassembly offload was added in last release.
The test app for unit testing IP reassembly of inline inbound IPsec flows is added in this patchset.
For testing IP reassembly, base inline IPsec is also added. The app is enhanced in v4 to handle more functional unit test cases for inline IPsec similar to Lookaside IPsec. The functions from Lookaside more are reused to verify functional cases.

Changes in v4:
- rebased over next-crypto
- updated app to take benefit from Lookaside protocol test functions.
- Added more functional cases
- Added soft and hard expiry event subtypes in ethdev for testing SA soft and hard pkt/byte expiry events.
- reassembly cases are squashed in a single patch

Changes in v3:
- incorporated latest ethdev changes for reassembly.
- skipped build on windows as it needs rte_ipsec lib which is not compiled on windows.
changes in v2:
- added IPsec burst mode case
- updated as per the latest ethdev changes.

Akhil Goyal (6):
app/test: add unit cases for inline IPsec offload test/security: add inline inbound IPsec cases test/security: add combined mode inline IPsec cases test/security: add inline IPsec reassembly cases test/security: add more inline IPsec functional cases test/security: add ESN and anti-replay cases for inline

Vamsi Attunuru (4):
ethdev: add IPsec SA expiry event subtypes test/security: add inline IPsec SA soft expiry cases test/security: add inline IPsec SA hard expiry cases test/security: add inline IPsec IPv6 flow label cases

 MAINTAINERS                                   |    2 +-
 app/test/meson.build                          |    1 +
 app/test/test_cryptodev_security_ipsec.c      |   35 +-
 app/test/test_cryptodev_security_ipsec.h      |   12 +
 app/test/test_security_inline_proto.c         | 2525 +++++++++++++++++
 app/test/test_security_inline_proto_vectors.h |  710 +++++
 lib/ethdev/rte_ethdev.h                       |    9 +
 7 files changed, 3292 insertions(+), 2 deletions(-)  create mode 100644 app/test/test_security_inline_proto.c
 create mode 100644 app/test/test_security_inline_proto_vectors.h

--
2.25.1

#80 lore raw

v5 cover app/test: add inline IPsec and reassembly cases

In reply to Akhil Goyal

IP reassembly offload was added in last release. The test app for unit testing IP reassembly of inline inbound IPsec flows is added in this patchset.
For testing IP reassembly, base inline IPsec is also added. The app is enhanced in v4 to handle more functional unit test cases for inline IPsec similar to Lookaside IPsec. The functions from Lookaside more are reused to verify functional cases.

changed in v5:
- removed soft/hard expiry patches which are deferred for next release
- skipped tests if no port is added.
- added release notes.
Changes in v4:
- rebased over next-crypto
- updated app to take benefit from Lookaside protocol
test functions.
- Added more functional cases
- Added soft and hard expiry event subtypes in ethdev
for testing SA soft and hard pkt/byte expiry events.
- reassembly cases are squashed in a single patch

Changes in v3:
- incorporated latest ethdev changes for reassembly.
- skipped build on windows as it needs rte_ipsec lib which is not compiled on windows.
changes in v2:
- added IPsec burst mode case
- updated as per the latest ethdev changes.

Akhil Goyal (6):
app/test: add unit cases for inline IPsec offload test/security: add inline inbound IPsec cases test/security: add combined mode inline IPsec cases test/security: add inline IPsec reassembly cases test/security: add more inline IPsec functional cases test/security: add ESN and anti-replay cases for inline

Vamsi Attunuru (1):
test/security: add inline IPsec IPv6 flow label cases

 MAINTAINERS                                   |    2 +-
 app/test/meson.build                          |    1 +
 app/test/test_cryptodev_security_ipsec.c      |   35 +-
 app/test/test_cryptodev_security_ipsec.h      |   10 +
 app/test/test_security_inline_proto.c         | 2372 +++++++++++++++++
 app/test/test_security_inline_proto_vectors.h |  704 +++++
 doc/guides/rel_notes/release_22_07.rst        |    5 +
 7 files changed, 3127 insertions(+), 2 deletions(-)
 create mode 100644 app/test/test_security_inline_proto.c
 create mode 100644 app/test/test_security_inline_proto_vectors.h
Signature · 1 line
2.25.1
#81 lore raw

PATCH v5 1/7 app/test: add unit cases for inline IPsec offload

A new test suite is added in test app to test inline IPsec protocol offload. In this patch, predefined vectors from Lookaside IPsec test are used to verify the IPsec functionality without the need of external traffic generators. The sent packet is loopbacked onto the same interface which is received and matched with the expected output. The test suite can be updated further with other functional test cases. In this patch encap only cases are added.
The testsuite can be run using:
RTE> inline_ipsec_autotest

---
 MAINTAINERS                                   |   2 +-
 app/test/meson.build                          |   1 +
 app/test/test_security_inline_proto.c         | 882 ++++++++++++++++++
 app/test/test_security_inline_proto_vectors.h |  20 +
 doc/guides/rel_notes/release_22_07.rst        |   5 +
 5 files changed, 909 insertions(+), 1 deletion(-)
 create mode 100644 app/test/test_security_inline_proto.c
 create mode 100644 app/test/test_security_inline_proto_vectors.h
MAINTAINERS +1 -1
index 15008c03bc..89affa08ff 100644
@@ -440,7 +440,7 @@ M: Akhil Goyal <[email protected]>
 T: git://dpdk.org/next/dpdk-next-crypto
 F: lib/security/
 F: doc/guides/prog_guide/rte_security.rst
-F: app/test/test_security.c
+F: app/test/test_security*
 
 Compression API - EXPERIMENTAL
 M: Fan Zhang <[email protected]>
app/test/meson.build +1 -0
index 5fc1dd1b7b..39952c6c4f 100644
@@ -125,6 +125,7 @@ test_sources = files(
         'test_rwlock.c',
         'test_sched.c',
         'test_security.c',
+        'test_security_inline_proto.c',
         'test_service_cores.c',
         'test_spinlock.c',
         'test_stack.c',
app/test/test_security_inline_proto.c new file +882 -0

882 lines not on this page · raw message

app/test/test_security_inline_proto_vectors.h new file +20 -0
new file mode 100644
index 0000000000..d1074da36a
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2022 Marvell.
+ */
+#ifndef _TEST_INLINE_IPSEC_REASSEMBLY_VECTORS_H_
+#define _TEST_INLINE_IPSEC_REASSEMBLY_VECTORS_H_
+
+#include "test_cryptodev_security_ipsec.h"
+
+uint8_t dummy_ipv4_eth_hdr[] = {
+		/* ETH */
+		0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1,
+		0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0x08, 0x00,
+};
+uint8_t dummy_ipv6_eth_hdr[] = {
+		/* ETH */
+		0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1,
+		0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0x86, 0xdd,
+};
+
+#endif
doc/guides/rel_notes/release_22_07.rst +5 -0
index 42a5f2d990..212116f166 100644
@@ -55,6 +55,11 @@ New Features
      Also, make sure to start the actual text at the margin.
      =======================================================
 
+* **Added security inline protocol (IPsec) tests in dpdk-test.**
+
+  Added various functional test cases in dpdk-test to verify
+  inline IPsec protocol offload using loopback interface.
+
 
 Removed Items
 -------------
Signature · 1 line
2.25.1
Acked-by on v5 1/7
#82 lore raw

RE: [PATCH v5 1/7] app/test: add unit cases for inline IPsec offload

Quoted 22 lines

-----Original Message-----
From: Akhil Goyal <[email protected]>
Sent: Wednesday, April 27, 2022 4:11 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Ananyev, Konstantin <[email protected]>; Power, Ciara <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Akhil Goyal <[email protected]>
Subject: [PATCH v5 1/7] app/test: add unit cases for inline IPsec offload

A new test suite is added in test app to test inline IPsec protocol offload. In this patch, predefined vectors from Lookaside IPsec test are used to verify the IPsec functionality without the need of external traffic generators. The sent packet is loopbacked onto the same interface which is received and matched with the expected output. The test suite can be updated further with other functional test cases. In this patch encap only cases are added.
The testsuite can be run using:
RTE> inline_ipsec_autotest

Quoted 3 lines

---

#83 lore raw

PATCH v5 2/7 test/security: add inline inbound IPsec cases

In reply to Akhil Goyal

Added test cases for inline Inbound protocol offload verification with known test vectors from Lookaside mode.

---
 app/test/test_security_inline_proto.c | 65 +++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)
app/test/test_security_inline_proto.c +65 -0
index 249474be91..7dd9ba7aff 100644
@@ -819,6 +819,24 @@ test_ipsec_inline_proto_known_vec(const void *test_data)
 				false, &flags);
 }
 
+static int
+test_ipsec_inline_proto_known_vec_inb(const void *test_data)
+{
+	const struct ipsec_test_data *td = test_data;
+	struct ipsec_test_flags flags;
+	struct ipsec_test_data td_inb;
+
+	memset(&flags, 0, sizeof(flags));
+
+	if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS)
+		test_ipsec_td_in_from_out(td, &td_inb);
+	else
+		memcpy(&td_inb, td, sizeof(td_inb));
+
+	return test_ipsec_inline_proto_process(&td_inb, NULL, 1, false, &flags);
+}
+
+
 static struct unit_test_suite inline_ipsec_testsuite  = {
 	.suite_name = "Inline IPsec Ethernet Device Unit Test Suite",
 	.setup = inline_ipsec_testsuite_setup,
@@ -865,6 +883,53 @@ static struct unit_test_suite inline_ipsec_testsuite  = {
 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
 			test_ipsec_inline_proto_known_vec,
 			&pkt_null_aes_xcbc),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 128)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_inb, &pkt_aes_128_gcm),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 192)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_inb, &pkt_aes_192_gcm),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 256)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_inb, &pkt_aes_256_gcm),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_inb, &pkt_aes_128_cbc_null),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA256 [16B ICV])",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_inb,
+			&pkt_aes_128_cbc_hmac_sha256),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA384 [24B ICV])",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_inb,
+			&pkt_aes_128_cbc_hmac_sha384),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA512 [32B ICV])",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_inb,
+			&pkt_aes_128_cbc_hmac_sha512),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Inbound known vector (ESP tunnel mode IPv6 AES-GCM 128)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_inb, &pkt_aes_256_gcm_v6),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Inbound known vector (ESP tunnel mode IPv6 AES-CBC 128 HMAC-SHA256 [16B ICV])",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_inb,
+			&pkt_aes_128_cbc_hmac_sha256_v6),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Inbound known vector (ESP tunnel mode IPv4 NULL AES-XCBC-MAC [12B ICV])",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_inb,
+			&pkt_null_aes_xcbc),
+
+
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	},
Signature · 1 line
2.25.1
Acked-by on v5 2/7
#84 lore raw

RE: [PATCH v5 2/7] test/security: add inline inbound IPsec cases

Quoted 12 lines

-----Original Message-----
From: Akhil Goyal <[email protected]>
Sent: Wednesday, April 27, 2022 4:11 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Ananyev, Konstantin <[email protected]>; Power, Ciara <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Akhil Goyal <[email protected]>
Subject: [PATCH v5 2/7] test/security: add inline inbound IPsec cases

Quoted 5 lines

Added test cases for inline Inbound protocol offload verification with known test vectors from Lookaside mode.

---

#85 lore raw

PATCH v5 3/7 test/security: add combined mode inline IPsec cases

In reply to Akhil Goyal

Added combined encap and decap test cases for various algorithm combinations

---
 app/test/test_security_inline_proto.c | 102 ++++++++++++++++++++++++++
 1 file changed, 102 insertions(+)
app/test/test_security_inline_proto.c +102 -0
index 7dd9ba7aff..ea36d1188c 100644
@@ -660,6 +660,92 @@ test_ipsec_inline_proto_process(struct ipsec_test_data *td,
 	return ret;
 }
 
+static int
+test_ipsec_inline_proto_all(const struct ipsec_test_flags *flags)
+{
+	struct ipsec_test_data td_outb;
+	struct ipsec_test_data td_inb;
+	unsigned int i, nb_pkts = 1, pass_cnt = 0, fail_cnt = 0;
+	int ret;
+
+	if (flags->iv_gen || flags->sa_expiry_pkts_soft ||
+			flags->sa_expiry_pkts_hard)
+		nb_pkts = IPSEC_TEST_PACKETS_MAX;
+
+	for (i = 0; i < RTE_DIM(alg_list); i++) {
+		test_ipsec_td_prepare(alg_list[i].param1,
+				      alg_list[i].param2,
+				      flags, &td_outb, 1);
+
+		if (!td_outb.aead) {
+			enum rte_crypto_cipher_algorithm cipher_alg;
+			enum rte_crypto_auth_algorithm auth_alg;
+
+			cipher_alg = td_outb.xform.chain.cipher.cipher.algo;
+			auth_alg = td_outb.xform.chain.auth.auth.algo;
+
+			if (td_outb.aes_gmac && cipher_alg != RTE_CRYPTO_CIPHER_NULL)
+				continue;
+
+			/* ICV is not applicable for NULL auth */
+			if (flags->icv_corrupt &&
+			    auth_alg == RTE_CRYPTO_AUTH_NULL)
+				continue;
+
+			/* IV is not applicable for NULL cipher */
+			if (flags->iv_gen &&
+			    cipher_alg == RTE_CRYPTO_CIPHER_NULL)
+				continue;
+		}
+
+		if (flags->udp_encap)
+			td_outb.ipsec_xform.options.udp_encap = 1;
+
+		ret = test_ipsec_inline_proto_process(&td_outb, &td_inb, nb_pkts,
+						false, flags);
+		if (ret == TEST_SKIPPED)
+			continue;
+
+		if (ret == TEST_FAILED) {
+			printf("\n TEST FAILED");
+			test_ipsec_display_alg(alg_list[i].param1,
+					       alg_list[i].param2);
+			fail_cnt++;
+			continue;
+		}
+
+		test_ipsec_td_update(&td_inb, &td_outb, 1, flags);
+
+		ret = test_ipsec_inline_proto_process(&td_inb, NULL, nb_pkts,
+						false, flags);
+		if (ret == TEST_SKIPPED)
+			continue;
+
+		if (ret == TEST_FAILED) {
+			printf("\n TEST FAILED");
+			test_ipsec_display_alg(alg_list[i].param1,
+					       alg_list[i].param2);
+			fail_cnt++;
+			continue;
+		}
+
+		if (flags->display_alg)
+			test_ipsec_display_alg(alg_list[i].param1,
+					       alg_list[i].param2);
+
+		pass_cnt++;
+	}
+
+	printf("Tests passed: %d, failed: %d", pass_cnt, fail_cnt);
+	if (fail_cnt > 0)
+		return TEST_FAILED;
+	if (pass_cnt > 0)
+		return TEST_SUCCESS;
+	else
+		return TEST_SKIPPED;
+}
+
+
 static int
 ut_setup_inline_ipsec(void)
 {
@@ -836,6 +922,17 @@ test_ipsec_inline_proto_known_vec_inb(const void *test_data)
 	return test_ipsec_inline_proto_process(&td_inb, NULL, 1, false, &flags);
 }
 
+static int
+test_ipsec_inline_proto_display_list(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.display_alg = true;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
 
 static struct unit_test_suite inline_ipsec_testsuite  = {
 	.suite_name = "Inline IPsec Ethernet Device Unit Test Suite",
@@ -929,6 +1026,11 @@ static struct unit_test_suite inline_ipsec_testsuite  = {
 			test_ipsec_inline_proto_known_vec_inb,
 			&pkt_null_aes_xcbc),
 
+		TEST_CASE_NAMED_ST(
+			"Combined test alg list",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_display_list),
+
 
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
Signature · 1 line
2.25.1
Acked-by on v5 3/7
#86 lore raw

RE: [PATCH v5 3/7] test/security: add combined mode inline IPsec cases

Quoted 12 lines

-----Original Message-----
From: Akhil Goyal <[email protected]>
Sent: Wednesday, April 27, 2022 4:11 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Ananyev, Konstantin <[email protected]>; Power, Ciara <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Akhil Goyal <[email protected]>
Subject: [PATCH v5 3/7] test/security: add combined mode inline IPsec cases

Quoted 5 lines

Added combined encap and decap test cases for various algorithm combinations

---

#87 lore raw

PATCH v5 4/7 test/security: add inline IPsec reassembly cases

In reply to Akhil Goyal

Added unit test cases for IP reassembly of inline IPsec inbound scenarios.
In these cases, known test vectors of fragments are first processed for inline outbound processing and then received back on loopback interface for inbound processing along with IP reassembly of the corresponding decrypted packets. The resultant plain text reassembled packet is compared with original unfragmented packet.

In this patch, cases are added for 2/4/5 fragments for both IPv4 and IPv6 packets. A few negative test cases are also added like incomplete fragments, out of place fragments, duplicate fragments.

---
 app/test/test_security_inline_proto.c         | 421 ++++++++++-
 app/test/test_security_inline_proto_vectors.h | 684 ++++++++++++++++++
 2 files changed, 1104 insertions(+), 1 deletion(-)
app/test/test_security_inline_proto.c +420 -1
index ea36d1188c..46636af072 100644
@@ -41,6 +41,9 @@ test_inline_ipsec(void)
 #define MAX_TRAFFIC_BURST		2048
 #define NB_MBUF				10240
 
+#define ENCAP_DECAP_BURST_SZ		33
+#define APP_REASS_TIMEOUT		10
+
 extern struct ipsec_test_data pkt_aes_128_gcm;
 extern struct ipsec_test_data pkt_aes_192_gcm;
 extern struct ipsec_test_data pkt_aes_256_gcm;
@@ -94,6 +97,8 @@ uint16_t port_id;
 
 static uint64_t link_mbps;
 
+static int ip_reassembly_dynfield_offset = -1;
+
 static struct rte_flow *default_flow[RTE_MAX_ETHPORTS];
 
 /* Create Inline IPsec session */
@@ -527,6 +532,347 @@ destroy_default_flow(uint16_t portid)
 struct rte_mbuf **tx_pkts_burst;
 struct rte_mbuf **rx_pkts_burst;
 
+static int
+compare_pkt_data(struct rte_mbuf *m, uint8_t *ref, unsigned int tot_len)
+{
+	unsigned int len;
+	unsigned int nb_segs = m->nb_segs;
+	unsigned int matched = 0;
+	struct rte_mbuf *save = m;
+
+	while (m) {
+		len = tot_len;
+		if (len > m->data_len)
+			len = m->data_len;
+		if (len != 0) {
+			if (memcmp(rte_pktmbuf_mtod(m, char *),
+					ref + matched, len)) {
+				printf("\n====Reassembly case failed: Data Mismatch");
+				rte_hexdump(stdout, "Reassembled",
+					rte_pktmbuf_mtod(m, char *),
+					len);
+				rte_hexdump(stdout, "reference",
+					ref + matched,
+					len);
+				return TEST_FAILED;
+			}
+		}
+		tot_len -= len;
+		matched += len;
+		m = m->next;
+	}
+
+	if (tot_len) {
+		printf("\n====Reassembly case failed: Data Missing %u",
+		       tot_len);
+		printf("\n====nb_segs %u, tot_len %u", nb_segs, tot_len);
+		rte_pktmbuf_dump(stderr, save, -1);
+		return TEST_FAILED;
+	}
+	return TEST_SUCCESS;
+}
+
+static inline bool
+is_ip_reassembly_incomplete(struct rte_mbuf *mbuf)
+{
+	static uint64_t ip_reassembly_dynflag;
+	int ip_reassembly_dynflag_offset;
+
+	if (ip_reassembly_dynflag == 0) {
+		ip_reassembly_dynflag_offset = rte_mbuf_dynflag_lookup(
+			RTE_MBUF_DYNFLAG_IP_REASSEMBLY_INCOMPLETE_NAME, NULL);
+		if (ip_reassembly_dynflag_offset < 0)
+			return false;
+		ip_reassembly_dynflag = RTE_BIT64(ip_reassembly_dynflag_offset);
+	}
+
+	return (mbuf->ol_flags & ip_reassembly_dynflag) != 0;
+}
+
+static void
+free_mbuf(struct rte_mbuf *mbuf)
+{
+	rte_eth_ip_reassembly_dynfield_t dynfield;
+
+	if (!mbuf)
+		return;
+
+	if (!is_ip_reassembly_incomplete(mbuf)) {
+		rte_pktmbuf_free(mbuf);
+	} else {
+		if (ip_reassembly_dynfield_offset < 0)
+			return;
+
+		while (mbuf) {
+			dynfield = *RTE_MBUF_DYNFIELD(mbuf,
+					ip_reassembly_dynfield_offset,
+					rte_eth_ip_reassembly_dynfield_t *);
+			rte_pktmbuf_free(mbuf);
+			mbuf = dynfield.next_frag;
+		}
+	}
+}
+
+
+static int
+get_and_verify_incomplete_frags(struct rte_mbuf *mbuf,
+				struct reassembly_vector *vector)
+{
+	rte_eth_ip_reassembly_dynfield_t *dynfield[MAX_PKT_BURST];
+	int j = 0, ret;
+	/**
+	 * IP reassembly offload is incomplete, and fragments are listed in
+	 * dynfield which can be reassembled in SW.
+	 */
+	printf("\nHW IP Reassembly is not complete; attempt SW IP Reassembly,"
+		"\nMatching with original frags.");
+
+	if (ip_reassembly_dynfield_offset < 0)
+		return -1;
+
+	printf("\ncomparing frag: %d", j);
+	/* Skip Ethernet header comparison */
+	rte_pktmbuf_adj(mbuf, RTE_ETHER_HDR_LEN);
+	ret = compare_pkt_data(mbuf, vector->frags[j]->data,
+				vector->frags[j]->len);
+	if (ret)
+		return ret;
+	j++;
+	dynfield[j] = RTE_MBUF_DYNFIELD(mbuf, ip_reassembly_dynfield_offset,
+					rte_eth_ip_reassembly_dynfield_t *);
+	printf("\ncomparing frag: %d", j);
+	/* Skip Ethernet header comparison */
+	rte_pktmbuf_adj(dynfield[j]->next_frag, RTE_ETHER_HDR_LEN);
+	ret = compare_pkt_data(dynfield[j]->next_frag, vector->frags[j]->data,
+			vector->frags[j]->len);
+	if (ret)
+		return ret;
+
+	while ((dynfield[j]->nb_frags > 1) &&
+			is_ip_reassembly_incomplete(dynfield[j]->next_frag)) {
+		j++;
+		dynfield[j] = RTE_MBUF_DYNFIELD(dynfield[j-1]->next_frag,
+					ip_reassembly_dynfield_offset,
+					rte_eth_ip_reassembly_dynfield_t *);
+		printf("\ncomparing frag: %d", j);
+		/* Skip Ethernet header comparison */
+		rte_pktmbuf_adj(dynfield[j]->next_frag, RTE_ETHER_HDR_LEN);
+		ret = compare_pkt_data(dynfield[j]->next_frag,
+				vector->frags[j]->data, vector->frags[j]->len);
+		if (ret)
+			return ret;
+	}
+	return ret;
+}
+
+static int
+test_ipsec_with_reassembly(struct reassembly_vector *vector,
+		const struct ipsec_test_flags *flags)
+{
+	struct rte_security_session *out_ses[ENCAP_DECAP_BURST_SZ] = {0};
+	struct rte_security_session *in_ses[ENCAP_DECAP_BURST_SZ] = {0};
+	struct rte_eth_ip_reassembly_params reass_capa = {0};
+	struct rte_security_session_conf sess_conf_out = {0};
+	struct rte_security_session_conf sess_conf_in = {0};
+	unsigned int nb_tx, burst_sz, nb_sent = 0;
+	struct rte_crypto_sym_xform cipher_out = {0};
+	struct rte_crypto_sym_xform auth_out = {0};
+	struct rte_crypto_sym_xform aead_out = {0};
+	struct rte_crypto_sym_xform cipher_in = {0};
+	struct rte_crypto_sym_xform auth_in = {0};
+	struct rte_crypto_sym_xform aead_in = {0};
+	struct ipsec_test_data sa_data = {0};
+	struct rte_security_ctx *ctx;
+	unsigned int i, nb_rx = 0, j;
+	uint32_t ol_flags;
+	int ret = 0;
+
+	burst_sz = vector->burst ? ENCAP_DECAP_BURST_SZ : 1;
+	nb_tx = vector->nb_frags * burst_sz;
+
+	rte_eth_dev_stop(port_id);
+	if (ret != 0) {
+		printf("rte_eth_dev_stop: err=%s, port=%u\n",
+			       rte_strerror(-ret), port_id);
+		return ret;
+	}
+	rte_eth_ip_reassembly_capability_get(port_id, &reass_capa);
+	if (reass_capa.max_frags < vector->nb_frags)
+		return TEST_SKIPPED;
+	if (reass_capa.timeout_ms > APP_REASS_TIMEOUT) {
+		reass_capa.timeout_ms = APP_REASS_TIMEOUT;
+		rte_eth_ip_reassembly_conf_set(port_id, &reass_capa);
+	}
+
+	ret = rte_eth_dev_start(port_id);
+	if (ret < 0) {
+		printf("rte_eth_dev_start: err=%d, port=%d\n",
+			ret, port_id);
+		return ret;
+	}
+
+	memset(tx_pkts_burst, 0, sizeof(tx_pkts_burst[0]) * nb_tx);
+	memset(rx_pkts_burst, 0, sizeof(rx_pkts_burst[0]) * nb_tx);
+
+	for (i = 0; i < nb_tx; i += vector->nb_frags) {
+		for (j = 0; j < vector->nb_frags; j++) {
+			tx_pkts_burst[i+j] = init_packet(mbufpool,
+						vector->frags[j]->data,
+						vector->frags[j]->len);
+			if (tx_pkts_burst[i+j] == NULL) {
+				ret = -1;
+				printf("\n packed init failed\n");
+				goto out;
+			}
+		}
+	}
+
+	for (i = 0; i < burst_sz; i++) {
+		memcpy(&sa_data, vector->sa_data,
+				sizeof(struct ipsec_test_data));
+		/* Update SPI for every new SA */
+		sa_data.ipsec_xform.spi += i;
+		sa_data.ipsec_xform.direction =
+					RTE_SECURITY_IPSEC_SA_DIR_EGRESS;
+		if (sa_data.aead) {
+			sess_conf_out.crypto_xform = &aead_out;
+		} else {
+			sess_conf_out.crypto_xform = &cipher_out;
+			sess_conf_out.crypto_xform->next = &auth_out;
+		}
+
+		/* Create Inline IPsec outbound session. */
+		ret = create_inline_ipsec_session(&sa_data, port_id,
+				&out_ses[i], &ctx, &ol_flags, flags,
+				&sess_conf_out);
+		if (ret) {
+			printf("\nInline outbound session create failed\n");
+			goto out;
+		}
+	}
+
+	j = 0;
+	for (i = 0; i < nb_tx; i++) {
+		if (ol_flags & RTE_SECURITY_TX_OLOAD_NEED_MDATA)
+			rte_security_set_pkt_metadata(ctx,
+				out_ses[j], tx_pkts_burst[i], NULL);
+		tx_pkts_burst[i]->ol_flags |= RTE_MBUF_F_TX_SEC_OFFLOAD;
+
+		/* Move to next SA after nb_frags */
+		if ((i + 1) % vector->nb_frags == 0)
+			j++;
+	}
+
+	for (i = 0; i < burst_sz; i++) {
+		memcpy(&sa_data, vector->sa_data,
+				sizeof(struct ipsec_test_data));
+		/* Update SPI for every new SA */
+		sa_data.ipsec_xform.spi += i;
+		sa_data.ipsec_xform.direction =
+					RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
+
+		if (sa_data.aead) {
+			sess_conf_in.crypto_xform = &aead_in;
+		} else {
+			sess_conf_in.crypto_xform = &auth_in;
+			sess_conf_in.crypto_xform->next = &cipher_in;
+		}
+		/* Create Inline IPsec inbound session. */
+		ret = create_inline_ipsec_session(&sa_data, port_id, &in_ses[i],
+				&ctx, &ol_flags, flags, &sess_conf_in);
+		if (ret) {
+			printf("\nInline inbound session create failed\n");
+			goto out;
+		}
+	}
+
+	/* Retrieve reassembly dynfield offset if available */
+	if (ip_reassembly_dynfield_offset < 0 && vector->nb_frags > 1)
+		ip_reassembly_dynfield_offset = rte_mbuf_dynfield_lookup(
+				RTE_MBUF_DYNFIELD_IP_REASSEMBLY_NAME, NULL);
+
+
+	create_default_flow(port_id);
+
+	nb_sent = rte_eth_tx_burst(port_id, 0, tx_pkts_burst, nb_tx);
+	if (nb_sent != nb_tx) {
+		ret = -1;
+		printf("\nFailed to tx %u pkts", nb_tx);
+		goto out;
+	}
+
+	rte_delay_ms(1);
+
+	/* Retry few times before giving up */
+	nb_rx = 0;
+	j = 0;
+	do {
+		nb_rx += rte_eth_rx_burst(port_id, 0, &rx_pkts_burst[nb_rx],
+					  nb_tx - nb_rx);
+		j++;
+		if (nb_rx >= nb_tx)
+			break;
+		rte_delay_ms(1);
+	} while (j < 5 || !nb_rx);
+
+	/* Check for minimum number of Rx packets expected */
+	if ((vector->nb_frags == 1 && nb_rx != nb_tx) ||
+	    (vector->nb_frags > 1 && nb_rx < burst_sz)) {
+		printf("\nreceived less Rx pkts(%u) pkts\n", nb_rx);
+		ret = TEST_FAILED;
+		goto out;
+	}
+
+	for (i = 0; i < nb_rx; i++) {
+		if (vector->nb_frags > 1 &&
+		    is_ip_reassembly_incomplete(rx_pkts_burst[i])) {
+			ret = get_and_verify_incomplete_frags(rx_pkts_burst[i],
+							      vector);
+			if (ret != TEST_SUCCESS)
+				break;
+			continue;
+		}
+
+		if (rx_pkts_burst[i]->ol_flags &
+		    RTE_MBUF_F_RX_SEC_OFFLOAD_FAILED ||
+		    !(rx_pkts_burst[i]->ol_flags & RTE_MBUF_F_RX_SEC_OFFLOAD)) {
+			printf("\nsecurity offload failed\n");
+			ret = TEST_FAILED;
+			break;
+		}
+
+		if (vector->full_pkt->len + RTE_ETHER_HDR_LEN !=
+				rx_pkts_burst[i]->pkt_len) {
+			printf("\nreassembled/decrypted packet length mismatch\n");
+			ret = TEST_FAILED;
+			break;
+		}
+		rte_pktmbuf_adj(rx_pkts_burst[i], RTE_ETHER_HDR_LEN);
+		ret = compare_pkt_data(rx_pkts_burst[i],
+				       vector->full_pkt->data,
+				       vector->full_pkt->len);
+		if (ret != TEST_SUCCESS)
+			break;
+	}
+
+out:
+	destroy_default_flow(port_id);
+
+	/* Clear session data. */
+	for (i = 0; i < burst_sz; i++) {
+		if (out_ses[i])
+			rte_security_session_destroy(ctx, out_ses[i]);
+		if (in_ses[i])
+			rte_security_session_destroy(ctx, in_ses[i]);
+	}
+
+	for (i = nb_sent; i < nb_tx; i++)
+		free_mbuf(tx_pkts_burst[i]);
+	for (i = 0; i < nb_rx; i++)
+		free_mbuf(rx_pkts_burst[i]);
+	return ret;
+}
+
 static int
 test_ipsec_inline_proto_process(struct ipsec_test_data *td,
 		struct ipsec_test_data *res_d,
@@ -774,6 +1120,7 @@ ut_setup_inline_ipsec(void)
 static void
 ut_teardown_inline_ipsec(void)
 {
+	struct rte_eth_ip_reassembly_params reass_conf = {0};
 	uint16_t portid;
 	int ret;
 
@@ -783,6 +1130,9 @@ ut_teardown_inline_ipsec(void)
 		if (ret != 0)
 			printf("rte_eth_dev_stop: err=%s, port=%u\n",
 			       rte_strerror(-ret), portid);
+
+		/* Clear reassembly configuration */
+		rte_eth_ip_reassembly_conf_set(portid, &reass_conf);
 	}
 }
 
@@ -885,6 +1235,36 @@ inline_ipsec_testsuite_teardown(void)
 	}
 }
 
+static int
+test_inline_ip_reassembly(const void *testdata)
+{
+	struct reassembly_vector reassembly_td = {0};
+	const struct reassembly_vector *td = testdata;
+	struct ip_reassembly_test_packet full_pkt;
+	struct ip_reassembly_test_packet frags[MAX_FRAGS];
+	struct ipsec_test_flags flags = {0};
+	int i = 0;
+
+	reassembly_td.sa_data = td->sa_data;
+	reassembly_td.nb_frags = td->nb_frags;
+	reassembly_td.burst = td->burst;
+
+	memcpy(&full_pkt, td->full_pkt,
+			sizeof(struct ip_reassembly_test_packet));
+	reassembly_td.full_pkt = &full_pkt;
+
+	test_vector_payload_populate(reassembly_td.full_pkt, true);
+	for (; i < reassembly_td.nb_frags; i++) {
+		memcpy(&frags[i], td->frags[i],
+			sizeof(struct ip_reassembly_test_packet));
+		reassembly_td.frags[i] = &frags[i];
+		test_vector_payload_populate(reassembly_td.frags[i],
+				(i == 0) ? true : false);
+	}
+
+	return test_ipsec_with_reassembly(&reassembly_td, &flags);
+}
+
 static int
 test_ipsec_inline_proto_known_vec(const void *test_data)
 {
@@ -1031,7 +1411,46 @@ static struct unit_test_suite inline_ipsec_testsuite  = {
 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
 			test_ipsec_inline_proto_display_list),
 
-
+		TEST_CASE_NAMED_WITH_DATA(
+			"IPv4 Reassembly with 2 fragments",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_inline_ip_reassembly, &ipv4_2frag_vector),
+		TEST_CASE_NAMED_WITH_DATA(
+			"IPv6 Reassembly with 2 fragments",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_inline_ip_reassembly, &ipv6_2frag_vector),
+		TEST_CASE_NAMED_WITH_DATA(
+			"IPv4 Reassembly with 4 fragments",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_inline_ip_reassembly, &ipv4_4frag_vector),
+		TEST_CASE_NAMED_WITH_DATA(
+			"IPv6 Reassembly with 4 fragments",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_inline_ip_reassembly, &ipv6_4frag_vector),
+		TEST_CASE_NAMED_WITH_DATA(
+			"IPv4 Reassembly with 5 fragments",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_inline_ip_reassembly, &ipv4_5frag_vector),
+		TEST_CASE_NAMED_WITH_DATA(
+			"IPv6 Reassembly with 5 fragments",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_inline_ip_reassembly, &ipv6_5frag_vector),
+		TEST_CASE_NAMED_WITH_DATA(
+			"IPv4 Reassembly with incomplete fragments",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_inline_ip_reassembly, &ipv4_incomplete_vector),
+		TEST_CASE_NAMED_WITH_DATA(
+			"IPv4 Reassembly with overlapping fragments",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_inline_ip_reassembly, &ipv4_overlap_vector),
+		TEST_CASE_NAMED_WITH_DATA(
+			"IPv4 Reassembly with out of order fragments",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_inline_ip_reassembly, &ipv4_out_of_order_vector),
+		TEST_CASE_NAMED_WITH_DATA(
+			"IPv4 Reassembly with burst of 4 fragments",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_inline_ip_reassembly, &ipv4_4frag_burst_vector),
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	},
app/test/test_security_inline_proto_vectors.h +684 -0

688 lines not on this page · raw message

Signature · 1 line
2.25.1
Acked-by on v5 4/7
#88 lore raw

RE: [PATCH v5 4/7] test/security: add inline IPsec reassembly cases

Quoted 21 lines

-----Original Message-----
From: Akhil Goyal <[email protected]>
Sent: Wednesday, April 27, 2022 4:11 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Ananyev, Konstantin <[email protected]>; Power, Ciara <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Akhil Goyal <[email protected]>
Subject: [PATCH v5 4/7] test/security: add inline IPsec reassembly cases

Added unit test cases for IP reassembly of inline IPsec inbound scenarios.
In these cases, known test vectors of fragments are first processed for inline outbound processing and then received back on loopback interface for inbound processing along with IP reassembly of the corresponding decrypted packets. The resultant plain text reassembled packet is compared with original unfragmented packet.

Quoted 7 lines

In this patch, cases are added for 2/4/5 fragments for both IPv4 and IPv6 packets. A few negative test cases are also added like incomplete fragments, out of place fragments, duplicate fragments.

---

#89 lore raw

PATCH v5 5/7 test/security: add more inline IPsec functional cases

In reply to Akhil Goyal

Added more inline IPsec functional verification cases. These cases do not have known vectors but are verified using encap + decap test for all the algo combinations.

---
 app/test/test_security_inline_proto.c | 517 ++++++++++++++++++++++++++
 1 file changed, 517 insertions(+)
app/test/test_security_inline_proto.c +517 -0
index 46636af072..055b753634 100644
@@ -1314,6 +1314,394 @@ test_ipsec_inline_proto_display_list(const void *data __rte_unused)
 	return test_ipsec_inline_proto_all(&flags);
 }
 
+static int
+test_ipsec_inline_proto_udp_encap(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.udp_encap = true;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_udp_ports_verify(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.udp_encap = true;
+	flags.udp_ports_verify = true;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_err_icv_corrupt(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.icv_corrupt = true;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_tunnel_dst_addr_verify(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_tunnel_src_dst_addr_verify(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_inner_ip_csum(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.ip_csum = true;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_inner_l4_csum(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.l4_csum = true;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_tunnel_v4_in_v4(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.ipv6 = false;
+	flags.tunnel_ipv6 = false;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_tunnel_v6_in_v6(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.ipv6 = true;
+	flags.tunnel_ipv6 = true;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_tunnel_v4_in_v6(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.ipv6 = false;
+	flags.tunnel_ipv6 = true;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_tunnel_v6_in_v4(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.ipv6 = true;
+	flags.tunnel_ipv6 = false;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_transport_v4(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.ipv6 = false;
+	flags.transport = true;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_transport_l4_csum(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags = {
+		.l4_csum = true,
+		.transport = true,
+	};
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_stats(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.stats_success = true;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_pkt_fragment(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.fragment = true;
+
+	return test_ipsec_inline_proto_all(&flags);
+
+}
+
+static int
+test_ipsec_inline_proto_copy_df_inner_0(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.df = TEST_IPSEC_COPY_DF_INNER_0;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_copy_df_inner_1(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.df = TEST_IPSEC_COPY_DF_INNER_1;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_set_df_0_inner_1(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.df = TEST_IPSEC_SET_DF_0_INNER_1;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_set_df_1_inner_0(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.df = TEST_IPSEC_SET_DF_1_INNER_0;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_ipv4_copy_dscp_inner_0(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_0;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_ipv4_copy_dscp_inner_1(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_1;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_ipv4_set_dscp_0_inner_1(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.dscp = TEST_IPSEC_SET_DSCP_0_INNER_1;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_ipv4_set_dscp_1_inner_0(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.dscp = TEST_IPSEC_SET_DSCP_1_INNER_0;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_ipv6_copy_dscp_inner_0(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.ipv6 = true;
+	flags.tunnel_ipv6 = true;
+	flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_0;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_ipv6_copy_dscp_inner_1(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.ipv6 = true;
+	flags.tunnel_ipv6 = true;
+	flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_1;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_ipv6_set_dscp_0_inner_1(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.ipv6 = true;
+	flags.tunnel_ipv6 = true;
+	flags.dscp = TEST_IPSEC_SET_DSCP_0_INNER_1;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_ipv6_set_dscp_1_inner_0(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.ipv6 = true;
+	flags.tunnel_ipv6 = true;
+	flags.dscp = TEST_IPSEC_SET_DSCP_1_INNER_0;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_ipv4_ttl_decrement(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags = {
+		.dec_ttl_or_hop_limit = true
+	};
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_ipv6_hop_limit_decrement(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags = {
+		.ipv6 = true,
+		.dec_ttl_or_hop_limit = true
+	};
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_iv_gen(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.iv_gen = true;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_known_vec_fragmented(const void *test_data)
+{
+	struct ipsec_test_data td_outb;
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+	flags.fragment = true;
+
+	memcpy(&td_outb, test_data, sizeof(td_outb));
+
+	/* Disable IV gen to be able to test with known vectors */
+	td_outb.ipsec_xform.options.iv_gen_disable = 1;
+
+	return test_ipsec_inline_proto_process(&td_outb, NULL, 1, false,
+						&flags);
+}
 static struct unit_test_suite inline_ipsec_testsuite  = {
 	.suite_name = "Inline IPsec Ethernet Device Unit Test Suite",
 	.setup = inline_ipsec_testsuite_setup,
@@ -1360,6 +1748,13 @@ static struct unit_test_suite inline_ipsec_testsuite  = {
 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
 			test_ipsec_inline_proto_known_vec,
 			&pkt_null_aes_xcbc),
+
+		TEST_CASE_NAMED_WITH_DATA(
+			"Outbound fragmented packet",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_fragmented,
+			&pkt_aes_128_gcm_frag),
+
 		TEST_CASE_NAMED_WITH_DATA(
 			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 128)",
 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
@@ -1411,6 +1806,128 @@ static struct unit_test_suite inline_ipsec_testsuite  = {
 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
 			test_ipsec_inline_proto_display_list),
 
+		TEST_CASE_NAMED_ST(
+			"UDP encapsulation",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_udp_encap),
+		TEST_CASE_NAMED_ST(
+			"UDP encapsulation ports verification test",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_udp_ports_verify),
+		TEST_CASE_NAMED_ST(
+			"Negative test: ICV corruption",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_err_icv_corrupt),
+		TEST_CASE_NAMED_ST(
+			"Tunnel dst addr verification",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_tunnel_dst_addr_verify),
+		TEST_CASE_NAMED_ST(
+			"Tunnel src and dst addr verification",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_tunnel_src_dst_addr_verify),
+		TEST_CASE_NAMED_ST(
+			"Inner IP checksum",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_inner_ip_csum),
+		TEST_CASE_NAMED_ST(
+			"Inner L4 checksum",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_inner_l4_csum),
+		TEST_CASE_NAMED_ST(
+			"Tunnel IPv4 in IPv4",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_tunnel_v4_in_v4),
+		TEST_CASE_NAMED_ST(
+			"Tunnel IPv6 in IPv6",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_tunnel_v6_in_v6),
+		TEST_CASE_NAMED_ST(
+			"Tunnel IPv4 in IPv6",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_tunnel_v4_in_v6),
+		TEST_CASE_NAMED_ST(
+			"Tunnel IPv6 in IPv4",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_tunnel_v6_in_v4),
+		TEST_CASE_NAMED_ST(
+			"Transport IPv4",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_transport_v4),
+		TEST_CASE_NAMED_ST(
+			"Transport l4 checksum",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_transport_l4_csum),
+		TEST_CASE_NAMED_ST(
+			"Statistics: success",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_stats),
+		TEST_CASE_NAMED_ST(
+			"Fragmented packet",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_pkt_fragment),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header copy DF (inner 0)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_copy_df_inner_0),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header copy DF (inner 1)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_copy_df_inner_1),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header set DF 0 (inner 1)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_set_df_0_inner_1),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header set DF 1 (inner 0)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_set_df_1_inner_0),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header IPv4 copy DSCP (inner 0)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_ipv4_copy_dscp_inner_0),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header IPv4 copy DSCP (inner 1)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_ipv4_copy_dscp_inner_1),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header IPv4 set DSCP 0 (inner 1)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_ipv4_set_dscp_0_inner_1),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header IPv4 set DSCP 1 (inner 0)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_ipv4_set_dscp_1_inner_0),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header IPv6 copy DSCP (inner 0)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_ipv6_copy_dscp_inner_0),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header IPv6 copy DSCP (inner 1)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_ipv6_copy_dscp_inner_1),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header IPv6 set DSCP 0 (inner 1)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_ipv6_set_dscp_0_inner_1),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header IPv6 set DSCP 1 (inner 0)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_ipv6_set_dscp_1_inner_0),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header IPv4 decrement inner TTL",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_ipv4_ttl_decrement),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header IPv6 decrement inner hop limit",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_ipv6_hop_limit_decrement),
+		TEST_CASE_NAMED_ST(
+			"IV generation",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_iv_gen),
+
+
 		TEST_CASE_NAMED_WITH_DATA(
 			"IPv4 Reassembly with 2 fragments",
 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
Signature · 1 line
2.25.1
Acked-by on v5 5/7
#90 lore raw

RE: [PATCH v5 5/7] test/security: add more inline IPsec functional cases

Quoted 12 lines

-----Original Message-----
From: Akhil Goyal <[email protected]>
Sent: Wednesday, April 27, 2022 4:11 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Ananyev, Konstantin <[email protected]>; Power, Ciara <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Akhil Goyal <[email protected]>
Subject: [PATCH v5 5/7] test/security: add more inline IPsec functional cases

Quoted 6 lines

Added more inline IPsec functional verification cases. These cases do not have known vectors but are verified using encap + decap test for all the algo combinations.

---

#91 lore raw

PATCH v5 6/7 test/security: add ESN and anti-replay cases for inline

In reply to Akhil Goyal

Added cases to test anti replay for inline IPsec processing with and without extended sequence number support.

---
 app/test/test_security_inline_proto.c | 308 ++++++++++++++++++++++++++
 1 file changed, 308 insertions(+)
app/test/test_security_inline_proto.c +308 -0
index 055b753634..009405f403 100644
@@ -1091,6 +1091,136 @@ test_ipsec_inline_proto_all(const struct ipsec_test_flags *flags)
 		return TEST_SKIPPED;
 }
 
+static int
+test_ipsec_inline_proto_process_with_esn(struct ipsec_test_data td[],
+		struct ipsec_test_data res_d[],
+		int nb_pkts,
+		bool silent,
+		const struct ipsec_test_flags *flags)
+{
+	struct rte_security_session_conf sess_conf = {0};
+	struct ipsec_test_data *res_d_tmp = NULL;
+	struct rte_crypto_sym_xform cipher = {0};
+	struct rte_crypto_sym_xform auth = {0};
+	struct rte_crypto_sym_xform aead = {0};
+	struct rte_mbuf *rx_pkt = NULL;
+	struct rte_mbuf *tx_pkt = NULL;
+	int nb_rx, nb_sent;
+	struct rte_security_session *ses;
+	struct rte_security_ctx *ctx;
+	uint32_t ol_flags;
+	int i, ret;
+
+	if (td[0].aead) {
+		sess_conf.crypto_xform = &aead;
+	} else {
+		if (td[0].ipsec_xform.direction ==
+				RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
+			sess_conf.crypto_xform = &cipher;
+			sess_conf.crypto_xform->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
+			sess_conf.crypto_xform->next = &auth;
+			sess_conf.crypto_xform->next->type = RTE_CRYPTO_SYM_XFORM_AUTH;
+		} else {
+			sess_conf.crypto_xform = &auth;
+			sess_conf.crypto_xform->type = RTE_CRYPTO_SYM_XFORM_AUTH;
+			sess_conf.crypto_xform->next = &cipher;
+			sess_conf.crypto_xform->next->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
+		}
+	}
+
+	/* Create Inline IPsec session. */
+	ret = create_inline_ipsec_session(&td[0], port_id, &ses, &ctx,
+					  &ol_flags, flags, &sess_conf);
+	if (ret)
+		return ret;
+
+	if (td[0].ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS)
+		create_default_flow(port_id);
+
+	for (i = 0; i < nb_pkts; i++) {
+		tx_pkt = init_packet(mbufpool, td[i].input_text.data,
+					td[i].input_text.len);
+		if (tx_pkt == NULL) {
+			ret = TEST_FAILED;
+			goto out;
+		}
+
+		if (test_ipsec_pkt_update(rte_pktmbuf_mtod_offset(tx_pkt,
+					uint8_t *, RTE_ETHER_HDR_LEN), flags)) {
+			ret = TEST_FAILED;
+			goto out;
+		}
+
+		if (td[i].ipsec_xform.direction ==
+				RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
+			if (flags->antireplay) {
+				sess_conf.ipsec.esn.value =
+						td[i].ipsec_xform.esn.value;
+				ret = rte_security_session_update(ctx, ses,
+						&sess_conf);
+				if (ret) {
+					printf("Could not update ESN in session\n");
+					rte_pktmbuf_free(tx_pkt);
+					goto out;
+				}
+			}
+			if (ol_flags & RTE_SECURITY_TX_OLOAD_NEED_MDATA)
+				rte_security_set_pkt_metadata(ctx, ses,
+						tx_pkt, NULL);
+			tx_pkt->ol_flags |= RTE_MBUF_F_TX_SEC_OFFLOAD;
+		}
+		/* Send packet to ethdev for inline IPsec processing. */
+		nb_sent = rte_eth_tx_burst(port_id, 0, &tx_pkt, 1);
+		if (nb_sent != 1) {
+			printf("\nUnable to TX packets");
+			rte_pktmbuf_free(tx_pkt);
+			ret = TEST_FAILED;
+			goto out;
+		}
+
+		rte_pause();
+
+		/* Receive back packet on loopback interface. */
+		do {
+			rte_delay_ms(1);
+			nb_rx = rte_eth_rx_burst(port_id, 0, &rx_pkt, 1);
+		} while (nb_rx == 0);
+
+		rte_pktmbuf_adj(rx_pkt, RTE_ETHER_HDR_LEN);
+
+		if (res_d != NULL)
+			res_d_tmp = &res_d[i];
+
+		ret = test_ipsec_post_process(rx_pkt, &td[i],
+					      res_d_tmp, silent, flags);
+		if (ret != TEST_SUCCESS) {
+			rte_pktmbuf_free(rx_pkt);
+			goto out;
+		}
+
+		ret = test_ipsec_stats_verify(ctx, ses, flags,
+					td->ipsec_xform.direction);
+		if (ret != TEST_SUCCESS) {
+			rte_pktmbuf_free(rx_pkt);
+			goto out;
+		}
+
+		rte_pktmbuf_free(rx_pkt);
+		rx_pkt = NULL;
+		tx_pkt = NULL;
+		res_d_tmp = NULL;
+	}
+
+out:
+	if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS)
+		destroy_default_flow(port_id);
+
+	/* Destroy session so that other cases can create the session again */
+	rte_security_session_destroy(ctx, ses);
+	ses = NULL;
+
+	return ret;
+}
 
 static int
 ut_setup_inline_ipsec(void)
@@ -1702,6 +1832,153 @@ test_ipsec_inline_proto_known_vec_fragmented(const void *test_data)
 	return test_ipsec_inline_proto_process(&td_outb, NULL, 1, false,
 						&flags);
 }
+
+static int
+test_ipsec_inline_pkt_replay(const void *test_data, const uint64_t esn[],
+		      bool replayed_pkt[], uint32_t nb_pkts, bool esn_en,
+		      uint64_t winsz)
+{
+	struct ipsec_test_data td_outb[IPSEC_TEST_PACKETS_MAX];
+	struct ipsec_test_data td_inb[IPSEC_TEST_PACKETS_MAX];
+	struct ipsec_test_flags flags;
+	uint32_t i, ret = 0;
+
+	memset(&flags, 0, sizeof(flags));
+	flags.antireplay = true;
+
+	for (i = 0; i < nb_pkts; i++) {
+		memcpy(&td_outb[i], test_data, sizeof(td_outb));
+		td_outb[i].ipsec_xform.options.iv_gen_disable = 1;
+		td_outb[i].ipsec_xform.replay_win_sz = winsz;
+		td_outb[i].ipsec_xform.options.esn = esn_en;
+	}
+
+	for (i = 0; i < nb_pkts; i++)
+		td_outb[i].ipsec_xform.esn.value = esn[i];
+
+	ret = test_ipsec_inline_proto_process_with_esn(td_outb, td_inb,
+				nb_pkts, true, &flags);
+	if (ret != TEST_SUCCESS)
+		return ret;
+
+	test_ipsec_td_update(td_inb, td_outb, nb_pkts, &flags);
+
+	for (i = 0; i < nb_pkts; i++) {
+		td_inb[i].ipsec_xform.options.esn = esn_en;
+		/* Set antireplay flag for packets to be dropped */
+		td_inb[i].ar_packet = replayed_pkt[i];
+	}
+
+	ret = test_ipsec_inline_proto_process_with_esn(td_inb, NULL, nb_pkts,
+				true, &flags);
+
+	return ret;
+}
+
+static int
+test_ipsec_inline_proto_pkt_antireplay(const void *test_data, uint64_t winsz)
+{
+
+	uint32_t nb_pkts = 5;
+	bool replayed_pkt[5];
+	uint64_t esn[5];
+
+	/* 1. Advance the TOP of the window to WS * 2 */
+	esn[0] = winsz * 2;
+	/* 2. Test sequence number within the new window(WS + 1) */
+	esn[1] = winsz + 1;
+	/* 3. Test sequence number less than the window BOTTOM */
+	esn[2] = winsz;
+	/* 4. Test sequence number in the middle of the window */
+	esn[3] = winsz + (winsz / 2);
+	/* 5. Test replay of the packet in the middle of the window */
+	esn[4] = winsz + (winsz / 2);
+
+	replayed_pkt[0] = false;
+	replayed_pkt[1] = false;
+	replayed_pkt[2] = true;
+	replayed_pkt[3] = false;
+	replayed_pkt[4] = true;
+
+	return test_ipsec_inline_pkt_replay(test_data, esn, replayed_pkt,
+			nb_pkts, false, winsz);
+}
+
+static int
+test_ipsec_inline_proto_pkt_antireplay1024(const void *test_data)
+{
+	return test_ipsec_inline_proto_pkt_antireplay(test_data, 1024);
+}
+
+static int
+test_ipsec_inline_proto_pkt_antireplay2048(const void *test_data)
+{
+	return test_ipsec_inline_proto_pkt_antireplay(test_data, 2048);
+}
+
+static int
+test_ipsec_inline_proto_pkt_antireplay4096(const void *test_data)
+{
+	return test_ipsec_inline_proto_pkt_antireplay(test_data, 4096);
+}
+
+static int
+test_ipsec_inline_proto_pkt_esn_antireplay(const void *test_data, uint64_t winsz)
+{
+
+	uint32_t nb_pkts = 7;
+	bool replayed_pkt[7];
+	uint64_t esn[7];
+
+	/* Set the initial sequence number */
+	esn[0] = (uint64_t)(0xFFFFFFFF - winsz);
+	/* 1. Advance the TOP of the window to (1<<32 + WS/2) */
+	esn[1] = (uint64_t)((1ULL << 32) + (winsz / 2));
+	/* 2. Test sequence number within new window (1<<32 + WS/2 + 1) */
+	esn[2] = (uint64_t)((1ULL << 32) - (winsz / 2) + 1);
+	/* 3. Test with sequence number within window (1<<32 - 1) */
+	esn[3] = (uint64_t)((1ULL << 32) - 1);
+	/* 4. Test with sequence number within window (1<<32 - 1) */
+	esn[4] = (uint64_t)(1ULL << 32);
+	/* 5. Test with duplicate sequence number within
+	 * new window (1<<32 - 1)
+	 */
+	esn[5] = (uint64_t)((1ULL << 32) - 1);
+	/* 6. Test with duplicate sequence number within new window (1<<32) */
+	esn[6] = (uint64_t)(1ULL << 32);
+
+	replayed_pkt[0] = false;
+	replayed_pkt[1] = false;
+	replayed_pkt[2] = false;
+	replayed_pkt[3] = false;
+	replayed_pkt[4] = false;
+	replayed_pkt[5] = true;
+	replayed_pkt[6] = true;
+
+	return test_ipsec_inline_pkt_replay(test_data, esn, replayed_pkt, nb_pkts,
+				     true, winsz);
+}
+
+static int
+test_ipsec_inline_proto_pkt_esn_antireplay1024(const void *test_data)
+{
+	return test_ipsec_inline_proto_pkt_esn_antireplay(test_data, 1024);
+}
+
+static int
+test_ipsec_inline_proto_pkt_esn_antireplay2048(const void *test_data)
+{
+	return test_ipsec_inline_proto_pkt_esn_antireplay(test_data, 2048);
+}
+
+static int
+test_ipsec_inline_proto_pkt_esn_antireplay4096(const void *test_data)
+{
+	return test_ipsec_inline_proto_pkt_esn_antireplay(test_data, 4096);
+}
+
+
+
 static struct unit_test_suite inline_ipsec_testsuite  = {
 	.suite_name = "Inline IPsec Ethernet Device Unit Test Suite",
 	.setup = inline_ipsec_testsuite_setup,
@@ -1928,6 +2205,37 @@ static struct unit_test_suite inline_ipsec_testsuite  = {
 			test_ipsec_inline_proto_iv_gen),
 
 
+		TEST_CASE_NAMED_WITH_DATA(
+			"Antireplay with window size 1024",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_pkt_antireplay1024,
+			&pkt_aes_128_gcm),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Antireplay with window size 2048",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_pkt_antireplay2048,
+			&pkt_aes_128_gcm),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Antireplay with window size 4096",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_pkt_antireplay4096,
+			&pkt_aes_128_gcm),
+		TEST_CASE_NAMED_WITH_DATA(
+			"ESN and Antireplay with window size 1024",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_pkt_esn_antireplay1024,
+			&pkt_aes_128_gcm),
+		TEST_CASE_NAMED_WITH_DATA(
+			"ESN and Antireplay with window size 2048",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_pkt_esn_antireplay2048,
+			&pkt_aes_128_gcm),
+		TEST_CASE_NAMED_WITH_DATA(
+			"ESN and Antireplay with window size 4096",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_pkt_esn_antireplay4096,
+			&pkt_aes_128_gcm),
+
 		TEST_CASE_NAMED_WITH_DATA(
 			"IPv4 Reassembly with 2 fragments",
 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
Signature · 1 line
2.25.1
Acked-by on v5 6/7
#92 lore raw

RE: [PATCH v5 6/7] test/security: add ESN and anti-replay cases for inline

Quoted 12 lines

-----Original Message-----
From: Akhil Goyal <[email protected]>
Sent: Wednesday, April 27, 2022 4:11 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Ananyev, Konstantin <[email protected]>; Power, Ciara <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Akhil Goyal <[email protected]>
Subject: [PATCH v5 6/7] test/security: add ESN and anti-replay cases for inline

Quoted 5 lines

Added cases to test anti replay for inline IPsec processing with and without extended sequence number support.

---

#93 lore raw

RE: [PATCH v5 6/7] test/security: add ESN and anti-replay cases for inline

In reply to Akhil Goyal

Hi Akhil,

Please see inline.

Thanks,
Anoob

Quoted 69 lines

Subject: [PATCH v5 6/7] test/security: add ESN and anti-replay cases for inline

Added cases to test anti replay for inline IPsec processing with and without extended sequence number support.

---
 app/test/test_security_inline_proto.c | 308
++++++++++++++++++++++++++
 1 file changed, 308 insertions(+)
app/test/test_security_inline_proto.c +31 -0
index 055b753634..009405f403 100644
@@ -1091,6 +1091,136 @@ test_ipsec_inline_proto_all(const struct
 ipsec_test_flags *flags)
 		return TEST_SKIPPED;
 }
 
+static int
+test_ipsec_inline_proto_process_with_esn(struct ipsec_test_data td[],
+		struct ipsec_test_data res_d[],
+		int nb_pkts,
+		bool silent,
+		const struct ipsec_test_flags *flags) {
+	struct rte_security_session_conf sess_conf = {0};
+	struct ipsec_test_data *res_d_tmp = NULL;
+	struct rte_crypto_sym_xform cipher = {0};
+	struct rte_crypto_sym_xform auth = {0};
+	struct rte_crypto_sym_xform aead = {0};
+	struct rte_mbuf *rx_pkt = NULL;
+	struct rte_mbuf *tx_pkt = NULL;
+	int nb_rx, nb_sent;
+	struct rte_security_session *ses;
+	struct rte_security_ctx *ctx;
+	uint32_t ol_flags;
+	int i, ret;
+
+	if (td[0].aead) {
+		sess_conf.crypto_xform = &aead;
+	} else {
+		if (td[0].ipsec_xform.direction ==
+				RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
+			sess_conf.crypto_xform = &cipher;
+			sess_conf.crypto_xform->type =
 RTE_CRYPTO_SYM_XFORM_CIPHER;
+			sess_conf.crypto_xform->next = &auth;
+			sess_conf.crypto_xform->next->type =
 RTE_CRYPTO_SYM_XFORM_AUTH;
+		} else {
+			sess_conf.crypto_xform = &auth;
+			sess_conf.crypto_xform->type =

RTE_CRYPTO_SYM_XFORM_AUTH;

app/test/test_security_inline_proto.c +2 -0
+			sess_conf.crypto_xform->next = &cipher;
+			sess_conf.crypto_xform->next->type =

RTE_CRYPTO_SYM_XFORM_CIPHER;

app/test/test_security_inline_proto.c +10 -0
+		}
+	}
+
+	/* Create Inline IPsec session. */
+	ret = create_inline_ipsec_session(&td[0], port_id, &ses, &ctx,
+					  &ol_flags, flags, &sess_conf);
+	if (ret)
+		return ret;
+
+	if (td[0].ipsec_xform.direction ==

RTE_SECURITY_IPSEC_SA_DIR_INGRESS)

app/test/test_security_inline_proto.c test_ipsec_inline_proto_all(const struct ipsec_test_flags *flags) · line 1138

Quoted 1 line
app/test/test_security_inline_proto.c +1 -0
+		create_default_flow(port_id);

[Anoob] If rte_flow creation fails, then the test should be skipped. I see that create_default_flow() is not returning error in case flow_validate() or flow_create() fails. IMO, it should be fixed.

Quoted 15 lines
app/test/test_security_inline_proto.c +10 -0
+
+	for (i = 0; i < nb_pkts; i++) {
+		tx_pkt = init_packet(mbufpool, td[i].input_text.data,
+					td[i].input_text.len);
+		if (tx_pkt == NULL) {
+			ret = TEST_FAILED;
+			goto out;
+		}
+
+		if

(test_ipsec_pkt_update(rte_pktmbuf_mtod_offset(tx_pkt,

app/test/test_security_inline_proto.c +1 -0
+					uint8_t *, RTE_ETHER_HDR_LEN),

flags)) {

app/test/test_security_inline_proto.c +2 -0
+			ret = TEST_FAILED;
+			goto out;

app/test/test_security_inline_proto.c test_ipsec_inline_proto_all(const struct ipsec_test_flags *flags) · line 1161

Quoted 10 lines
app/test/test_security_inline_proto.c +10 -0
+		}
+
+		if (td[i].ipsec_xform.direction ==
+				RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
+			if (flags->antireplay) {
+				sess_conf.ipsec.esn.value =
+						td[i].ipsec_xform.esn.value;
+				ret = rte_security_session_update(ctx, ses,
+						&sess_conf);
+				if (ret) {

[Anoob] ret should be set as TEST_SKIPPED.

Quoted 43 lines
app/test/test_security_inline_proto.c +1 -0
+					printf("Could not update ESN in

session\n");

app/test/test_security_inline_proto.c +5 -0
+					rte_pktmbuf_free(tx_pkt);
+					goto out;
+				}
+			}
+			if (ol_flags &

RTE_SECURITY_TX_OLOAD_NEED_MDATA)

app/test/test_security_inline_proto.c +3 -0
+				rte_security_set_pkt_metadata(ctx, ses,
+						tx_pkt, NULL);
+			tx_pkt->ol_flags |=

RTE_MBUF_F_TX_SEC_OFFLOAD;

app/test/test_security_inline_proto.c +31 -0
+		}
+		/* Send packet to ethdev for inline IPsec processing. */
+		nb_sent = rte_eth_tx_burst(port_id, 0, &tx_pkt, 1);
+		if (nb_sent != 1) {
+			printf("\nUnable to TX packets");
+			rte_pktmbuf_free(tx_pkt);
+			ret = TEST_FAILED;
+			goto out;
+		}
+
+		rte_pause();
+
+		/* Receive back packet on loopback interface. */
+		do {
+			rte_delay_ms(1);
+			nb_rx = rte_eth_rx_burst(port_id, 0, &rx_pkt, 1);
+		} while (nb_rx == 0);
+
+		rte_pktmbuf_adj(rx_pkt, RTE_ETHER_HDR_LEN);
+
+		if (res_d != NULL)
+			res_d_tmp = &res_d[i];
+
+		ret = test_ipsec_post_process(rx_pkt, &td[i],
+					      res_d_tmp, silent, flags);
+		if (ret != TEST_SUCCESS) {
+			rte_pktmbuf_free(rx_pkt);
+			goto out;
+		}
+
+		ret = test_ipsec_stats_verify(ctx, ses, flags,

app/test/test_security_inline_proto.c test_ipsec_inline_proto_all(const struct ipsec_test_flags *flags) · line 1211

Quoted 10 lines
app/test/test_security_inline_proto.c +10 -0
+					td->ipsec_xform.direction);
+		if (ret != TEST_SUCCESS) {
+			rte_pktmbuf_free(rx_pkt);
+			goto out;
+		}
+
+		rte_pktmbuf_free(rx_pkt);
+		rx_pkt = NULL;
+		tx_pkt = NULL;
+		res_d_tmp = NULL; 

[Anoob] Why do we need to set res_d_tmp to NULL?

Quoted 14 lines
app/test/test_security_inline_proto.c +4 -0
+	}
+
+out:
+	if (td->ipsec_xform.direction ==

RTE_SECURITY_IPSEC_SA_DIR_INGRESS)

app/test/test_security_inline_proto.c +8 -0
+		destroy_default_flow(port_id);
+
+	/* Destroy session so that other cases can create the session again */
+	rte_security_session_destroy(ctx, ses);
+	ses = NULL;
+
+	return ret;
+}

<snip>

#94 lore raw

PATCH v5 7/7 test/security: add inline IPsec IPv6 flow label cases

In reply to Akhil Goyal

From: Vamsi Attunuru <[email protected]>

Patch adds unit tests for IPv6 flow label set & copy operations.

---
 app/test/test_cryptodev_security_ipsec.c | 35 ++++++++++-
 app/test/test_cryptodev_security_ipsec.h | 10 +++
 app/test/test_security_inline_proto.c    | 79 ++++++++++++++++++++++++
 3 files changed, 123 insertions(+), 1 deletion(-)
app/test/test_cryptodev_security_ipsec.c +34 -1
index 14c6ba681f..408bd0bc82 100644
@@ -495,6 +495,10 @@ test_ipsec_td_prepare(const struct crypto_param *param1,
 		    flags->dscp == TEST_IPSEC_COPY_DSCP_INNER_1)
 			td->ipsec_xform.options.copy_dscp = 1;
 
+		if (flags->flabel == TEST_IPSEC_COPY_FLABEL_INNER_0 ||
+		    flags->flabel == TEST_IPSEC_COPY_FLABEL_INNER_1)
+			td->ipsec_xform.options.copy_flabel = 1;
+
 		if (flags->dec_ttl_or_hop_limit)
 			td->ipsec_xform.options.dec_ttl = 1;
 	}
@@ -933,6 +937,7 @@ test_ipsec_iph6_hdr_validate(const struct rte_ipv6_hdr *iph6,
 			     const struct ipsec_test_flags *flags)
 {
 	uint32_t vtc_flow;
+	uint32_t flabel;
 	uint8_t dscp;
 
 	if (!is_valid_ipv6_pkt(iph6)) {
@@ -959,6 +964,23 @@ test_ipsec_iph6_hdr_validate(const struct rte_ipv6_hdr *iph6,
 		}
 	}
 
+	flabel = vtc_flow & RTE_IPV6_HDR_FL_MASK;
+
+	if (flags->flabel == TEST_IPSEC_COPY_FLABEL_INNER_1 ||
+	    flags->flabel == TEST_IPSEC_SET_FLABEL_1_INNER_0) {
+		if (flabel != TEST_IPSEC_FLABEL_VAL) {
+			printf("FLABEL value is not matching [exp: %x, actual: %x]\n",
+			       TEST_IPSEC_FLABEL_VAL, flabel);
+			return -1;
+		}
+	} else {
+		if (flabel != 0) {
+			printf("FLABEL value is set [exp: 0, actual: %x]\n",
+			       flabel);
+			return -1;
+		}
+	}
+
 	return 0;
 }
 
@@ -1159,7 +1181,11 @@ test_ipsec_pkt_update(uint8_t *pkt, const struct ipsec_test_flags *flags)
 	if (flags->dscp == TEST_IPSEC_COPY_DSCP_INNER_1 ||
 	    flags->dscp == TEST_IPSEC_SET_DSCP_0_INNER_1 ||
 	    flags->dscp == TEST_IPSEC_COPY_DSCP_INNER_0 ||
-	    flags->dscp == TEST_IPSEC_SET_DSCP_1_INNER_0) {
+	    flags->dscp == TEST_IPSEC_SET_DSCP_1_INNER_0 ||
+	    flags->flabel == TEST_IPSEC_COPY_FLABEL_INNER_1 ||
+	    flags->flabel == TEST_IPSEC_SET_FLABEL_0_INNER_1 ||
+	    flags->flabel == TEST_IPSEC_COPY_FLABEL_INNER_0 ||
+	    flags->flabel == TEST_IPSEC_SET_FLABEL_1_INNER_0) {
 
 		if (is_ipv4(iph4)) {
 			uint8_t tos;
@@ -1187,6 +1213,13 @@ test_ipsec_pkt_update(uint8_t *pkt, const struct ipsec_test_flags *flags)
 			else
 				vtc_flow &= ~RTE_IPV6_HDR_DSCP_MASK;
 
+			if (flags->flabel == TEST_IPSEC_COPY_FLABEL_INNER_1 ||
+			    flags->flabel == TEST_IPSEC_SET_FLABEL_0_INNER_1)
+				vtc_flow |= (RTE_IPV6_HDR_FL_MASK &
+					     (TEST_IPSEC_FLABEL_VAL << RTE_IPV6_HDR_FL_SHIFT));
+			else
+				vtc_flow &= ~RTE_IPV6_HDR_FL_MASK;
+
 			iph6->vtc_flow = rte_cpu_to_be_32(vtc_flow);
 		}
 	}
app/test/test_cryptodev_security_ipsec.h +10 -0
index 0d9b5b6e2e..744dd64a9e 100644
@@ -73,6 +73,15 @@ enum dscp_flags {
 	TEST_IPSEC_SET_DSCP_1_INNER_0,
 };
 
+#define TEST_IPSEC_FLABEL_VAL 0x1234
+
+enum flabel_flags {
+	TEST_IPSEC_COPY_FLABEL_INNER_0 = 1,
+	TEST_IPSEC_COPY_FLABEL_INNER_1,
+	TEST_IPSEC_SET_FLABEL_0_INNER_1,
+	TEST_IPSEC_SET_FLABEL_1_INNER_0,
+};
+
 struct ipsec_test_flags {
 	bool display_alg;
 	bool sa_expiry_pkts_soft;
@@ -92,6 +101,7 @@ struct ipsec_test_flags {
 	bool antireplay;
 	enum df_flags df;
 	enum dscp_flags dscp;
+	enum flabel_flags flabel;
 	bool dec_ttl_or_hop_limit;
 	bool ah;
 };
app/test/test_security_inline_proto.c +79 -0

97 lines not on this page · raw message

Signature · 1 line
2.25.1
Acked-by on v5 7/7
#95 lore raw

RE: [PATCH v5 7/7] test/security: add inline IPsec IPv6 flow label cases

Quoted 11 lines

-----Original Message-----
From: Akhil Goyal <[email protected]>
Sent: Wednesday, April 27, 2022 4:11 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Ananyev, Konstantin <[email protected]>; Power, Ciara <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [PATCH v5 7/7] test/security: add inline IPsec IPv6 flow label cases

Quoted 7 lines

From: Vamsi Attunuru <[email protected]>

Patch adds unit tests for IPv6 flow label set & copy operations.

---

#96 lore raw

RE: [PATCH v5 0/7] app/test: add inline IPsec and reassembly cases

In reply to Akhil Goyal
Quoted 65 lines

-----Original Message-----
From: Akhil Goyal <[email protected]>
Sent: Wednesday, April 27, 2022 4:11 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Ananyev, Konstantin <[email protected]>; Power, Ciara <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Akhil Goyal <[email protected]>
Subject: [PATCH v5 0/7] app/test: add inline IPsec and reassembly cases

IP reassembly offload was added in last release. The test app for unit testing IP reassembly of inline inbound IPsec flows is added in this patchset.
For testing IP reassembly, base inline IPsec is also added. The app is enhanced in v4 to handle more functional unit test cases for inline IPsec similar to Lookaside IPsec. The functions from Lookaside more are reused to verify functional cases.

changed in v5:
- removed soft/hard expiry patches which are deferred for next release
- skipped tests if no port is added.
- added release notes.
Changes in v4:
- rebased over next-crypto
- updated app to take benefit from Lookaside protocol
test functions.
- Added more functional cases
- Added soft and hard expiry event subtypes in ethdev
for testing SA soft and hard pkt/byte expiry events.
- reassembly cases are squashed in a single patch

Changes in v3:
- incorporated latest ethdev changes for reassembly.
- skipped build on windows as it needs rte_ipsec lib which is not compiled on windows.
changes in v2:
- added IPsec burst mode case
- updated as per the latest ethdev changes.

Akhil Goyal (6):
app/test: add unit cases for inline IPsec offload test/security: add inline inbound IPsec cases test/security: add combined mode inline IPsec cases test/security: add inline IPsec reassembly cases test/security: add more inline IPsec functional cases test/security: add ESN and anti-replay cases for inline

Vamsi Attunuru (1):
test/security: add inline IPsec IPv6 flow label cases

 MAINTAINERS                                   |    2 +-
 app/test/meson.build                          |    1 +
 app/test/test_cryptodev_security_ipsec.c      |   35 +-
 app/test/test_cryptodev_security_ipsec.h      |   10 +
 app/test/test_security_inline_proto.c         | 2372 +++++++++++++++++
 app/test/test_security_inline_proto_vectors.h |  704 +++++
 doc/guides/rel_notes/release_22_07.rst        |    5 +
 7 files changed, 3127 insertions(+), 2 deletions(-)
 create mode 100644 app/test/test_security_inline_proto.c
 create mode 100644 app/test/test_security_inline_proto_vectors.h
Quoted 2 lines

--
2.25.1

#97 lore raw

v6 cover app/test: add inline IPsec and reassembly cases

In reply to Akhil Goyal

IP reassembly offload was added in last release. The test app for unit testing IP reassembly of inline inbound IPsec flows is added in this patchset.
For testing IP reassembly, base inline IPsec is also added. The app is enhanced in v4 to handle more functional unit test cases for inline IPsec similar to Lookaside IPsec. The functions from Lookaside more are reused to verify functional cases.

Changes in v6:
- Addressed comments from Anoob.

changes in v5:
- removed soft/hard expiry patches which are deferred for next release
- skipped tests if no port is added.
- added release notes.
Changes in v4:
- rebased over next-crypto
- updated app to take benefit from Lookaside protocol
test functions.
- Added more functional cases
- Added soft and hard expiry event subtypes in ethdev
for testing SA soft and hard pkt/byte expiry events.
- reassembly cases are squashed in a single patch

Changes in v3:
- incorporated latest ethdev changes for reassembly.
- skipped build on windows as it needs rte_ipsec lib which is not compiled on windows.
changes in v2:
- added IPsec burst mode case
- updated as per the latest ethdev changes.

Akhil Goyal (6):
app/test: add unit cases for inline IPsec offload test/security: add inline inbound IPsec cases test/security: add combined mode inline IPsec cases test/security: add inline IPsec reassembly cases test/security: add more inline IPsec functional cases test/security: add ESN and anti-replay cases for inline

Vamsi Attunuru (1):
test/security: add inline IPsec IPv6 flow label cases

 MAINTAINERS                                   |    2 +-
 app/test/meson.build                          |    1 +
 app/test/test_cryptodev_security_ipsec.c      |   35 +-
 app/test/test_cryptodev_security_ipsec.h      |   10 +
 app/test/test_security_inline_proto.c         | 2382 +++++++++++++++++
 app/test/test_security_inline_proto_vectors.h |  704 +++++
 doc/guides/rel_notes/release_22_07.rst        |    5 +
 7 files changed, 3137 insertions(+), 2 deletions(-)
 create mode 100644 app/test/test_security_inline_proto.c
 create mode 100644 app/test/test_security_inline_proto_vectors.h
Signature · 1 line
2.25.1
#98 lore raw

PATCH v6 1/7 app/test: add unit cases for inline IPsec offload

A new test suite is added in test app to test inline IPsec protocol offload. In this patch, predefined vectors from Lookaside IPsec test are used to verify the IPsec functionality without the need of external traffic generators. The sent packet is loopbacked onto the same interface which is received and matched with the expected output. The test suite can be updated further with other functional test cases. In this patch encap only cases are added.
The testsuite can be run using:
RTE> inline_ipsec_autotest

---
 MAINTAINERS                                   |   2 +-
 app/test/meson.build                          |   1 +
 app/test/test_security_inline_proto.c         | 887 ++++++++++++++++++
 app/test/test_security_inline_proto_vectors.h |  20 +
 doc/guides/rel_notes/release_22_07.rst        |   5 +
 5 files changed, 914 insertions(+), 1 deletion(-)
 create mode 100644 app/test/test_security_inline_proto.c
 create mode 100644 app/test/test_security_inline_proto_vectors.h
MAINTAINERS +1 -1
index 8f4e9c3479..8031fed09f 100644
@@ -440,7 +440,7 @@ M: Akhil Goyal <[email protected]>
 T: git://dpdk.org/next/dpdk-next-crypto
 F: lib/security/
 F: doc/guides/prog_guide/rte_security.rst
-F: app/test/test_security.c
+F: app/test/test_security*
 
 Compression API - EXPERIMENTAL
 M: Fan Zhang <[email protected]>
app/test/meson.build +1 -0
index bb4621ed2a..df01257142 100644
@@ -125,6 +125,7 @@ test_sources = files(
         'test_rwlock.c',
         'test_sched.c',
         'test_security.c',
+        'test_security_inline_proto.c',
         'test_service_cores.c',
         'test_spinlock.c',
         'test_stack.c',
app/test/test_security_inline_proto.c new file +887 -0

887 lines not on this page · raw message

app/test/test_security_inline_proto_vectors.h new file +20 -0
new file mode 100644
index 0000000000..d1074da36a
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2022 Marvell.
+ */
+#ifndef _TEST_INLINE_IPSEC_REASSEMBLY_VECTORS_H_
+#define _TEST_INLINE_IPSEC_REASSEMBLY_VECTORS_H_
+
+#include "test_cryptodev_security_ipsec.h"
+
+uint8_t dummy_ipv4_eth_hdr[] = {
+		/* ETH */
+		0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1,
+		0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0x08, 0x00,
+};
+uint8_t dummy_ipv6_eth_hdr[] = {
+		/* ETH */
+		0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1,
+		0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0x86, 0xdd,
+};
+
+#endif
doc/guides/rel_notes/release_22_07.rst +5 -0
index 4ae91dd94d..b5ffbd8bca 100644
@@ -70,6 +70,11 @@ New Features
   * Added AH mode support in lookaside protocol (IPsec) for CN9K & CN10K.
   * Added AES-GMAC support in lookaside protocol (IPsec) for CN9K & CN10K.
 
+* **Added security inline protocol (IPsec) tests in dpdk-test.**
+
+  Added various functional test cases in dpdk-test to verify
+  inline IPsec protocol offload using loopback interface.
+
 
 Removed Items
 -------------
Signature · 1 line
2.25.1
#99 lore raw

PATCH v6 2/7 test/security: add inline inbound IPsec cases

In reply to Akhil Goyal

Added test cases for inline Inbound protocol offload verification with known test vectors from Lookaside mode.

---
 app/test/test_security_inline_proto.c | 65 +++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)
app/test/test_security_inline_proto.c +65 -0
index 4b960ddfe0..4a95b25a0b 100644
@@ -824,6 +824,24 @@ test_ipsec_inline_proto_known_vec(const void *test_data)
 				false, &flags);
 }
 
+static int
+test_ipsec_inline_proto_known_vec_inb(const void *test_data)
+{
+	const struct ipsec_test_data *td = test_data;
+	struct ipsec_test_flags flags;
+	struct ipsec_test_data td_inb;
+
+	memset(&flags, 0, sizeof(flags));
+
+	if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS)
+		test_ipsec_td_in_from_out(td, &td_inb);
+	else
+		memcpy(&td_inb, td, sizeof(td_inb));
+
+	return test_ipsec_inline_proto_process(&td_inb, NULL, 1, false, &flags);
+}
+
+
 static struct unit_test_suite inline_ipsec_testsuite  = {
 	.suite_name = "Inline IPsec Ethernet Device Unit Test Suite",
 	.setup = inline_ipsec_testsuite_setup,
@@ -870,6 +888,53 @@ static struct unit_test_suite inline_ipsec_testsuite  = {
 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
 			test_ipsec_inline_proto_known_vec,
 			&pkt_null_aes_xcbc),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 128)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_inb, &pkt_aes_128_gcm),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 192)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_inb, &pkt_aes_192_gcm),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 256)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_inb, &pkt_aes_256_gcm),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_inb, &pkt_aes_128_cbc_null),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA256 [16B ICV])",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_inb,
+			&pkt_aes_128_cbc_hmac_sha256),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA384 [24B ICV])",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_inb,
+			&pkt_aes_128_cbc_hmac_sha384),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA512 [32B ICV])",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_inb,
+			&pkt_aes_128_cbc_hmac_sha512),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Inbound known vector (ESP tunnel mode IPv6 AES-GCM 128)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_inb, &pkt_aes_256_gcm_v6),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Inbound known vector (ESP tunnel mode IPv6 AES-CBC 128 HMAC-SHA256 [16B ICV])",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_inb,
+			&pkt_aes_128_cbc_hmac_sha256_v6),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Inbound known vector (ESP tunnel mode IPv4 NULL AES-XCBC-MAC [12B ICV])",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_inb,
+			&pkt_null_aes_xcbc),
+
+
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	},
Signature · 1 line
2.25.1
#100 lore raw

PATCH v6 3/7 test/security: add combined mode inline IPsec cases

In reply to Akhil Goyal

Added combined encap and decap test cases for various algorithm combinations

---
 app/test/test_security_inline_proto.c | 102 ++++++++++++++++++++++++++
 1 file changed, 102 insertions(+)
app/test/test_security_inline_proto.c +102 -0
index 4a95b25a0b..a44a4f9b04 100644
@@ -665,6 +665,92 @@ test_ipsec_inline_proto_process(struct ipsec_test_data *td,
 	return ret;
 }
 
+static int
+test_ipsec_inline_proto_all(const struct ipsec_test_flags *flags)
+{
+	struct ipsec_test_data td_outb;
+	struct ipsec_test_data td_inb;
+	unsigned int i, nb_pkts = 1, pass_cnt = 0, fail_cnt = 0;
+	int ret;
+
+	if (flags->iv_gen || flags->sa_expiry_pkts_soft ||
+			flags->sa_expiry_pkts_hard)
+		nb_pkts = IPSEC_TEST_PACKETS_MAX;
+
+	for (i = 0; i < RTE_DIM(alg_list); i++) {
+		test_ipsec_td_prepare(alg_list[i].param1,
+				      alg_list[i].param2,
+				      flags, &td_outb, 1);
+
+		if (!td_outb.aead) {
+			enum rte_crypto_cipher_algorithm cipher_alg;
+			enum rte_crypto_auth_algorithm auth_alg;
+
+			cipher_alg = td_outb.xform.chain.cipher.cipher.algo;
+			auth_alg = td_outb.xform.chain.auth.auth.algo;
+
+			if (td_outb.aes_gmac && cipher_alg != RTE_CRYPTO_CIPHER_NULL)
+				continue;
+
+			/* ICV is not applicable for NULL auth */
+			if (flags->icv_corrupt &&
+			    auth_alg == RTE_CRYPTO_AUTH_NULL)
+				continue;
+
+			/* IV is not applicable for NULL cipher */
+			if (flags->iv_gen &&
+			    cipher_alg == RTE_CRYPTO_CIPHER_NULL)
+				continue;
+		}
+
+		if (flags->udp_encap)
+			td_outb.ipsec_xform.options.udp_encap = 1;
+
+		ret = test_ipsec_inline_proto_process(&td_outb, &td_inb, nb_pkts,
+						false, flags);
+		if (ret == TEST_SKIPPED)
+			continue;
+
+		if (ret == TEST_FAILED) {
+			printf("\n TEST FAILED");
+			test_ipsec_display_alg(alg_list[i].param1,
+					       alg_list[i].param2);
+			fail_cnt++;
+			continue;
+		}
+
+		test_ipsec_td_update(&td_inb, &td_outb, 1, flags);
+
+		ret = test_ipsec_inline_proto_process(&td_inb, NULL, nb_pkts,
+						false, flags);
+		if (ret == TEST_SKIPPED)
+			continue;
+
+		if (ret == TEST_FAILED) {
+			printf("\n TEST FAILED");
+			test_ipsec_display_alg(alg_list[i].param1,
+					       alg_list[i].param2);
+			fail_cnt++;
+			continue;
+		}
+
+		if (flags->display_alg)
+			test_ipsec_display_alg(alg_list[i].param1,
+					       alg_list[i].param2);
+
+		pass_cnt++;
+	}
+
+	printf("Tests passed: %d, failed: %d", pass_cnt, fail_cnt);
+	if (fail_cnt > 0)
+		return TEST_FAILED;
+	if (pass_cnt > 0)
+		return TEST_SUCCESS;
+	else
+		return TEST_SKIPPED;
+}
+
+
 static int
 ut_setup_inline_ipsec(void)
 {
@@ -841,6 +927,17 @@ test_ipsec_inline_proto_known_vec_inb(const void *test_data)
 	return test_ipsec_inline_proto_process(&td_inb, NULL, 1, false, &flags);
 }
 
+static int
+test_ipsec_inline_proto_display_list(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.display_alg = true;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
 
 static struct unit_test_suite inline_ipsec_testsuite  = {
 	.suite_name = "Inline IPsec Ethernet Device Unit Test Suite",
@@ -934,6 +1031,11 @@ static struct unit_test_suite inline_ipsec_testsuite  = {
 			test_ipsec_inline_proto_known_vec_inb,
 			&pkt_null_aes_xcbc),
 
+		TEST_CASE_NAMED_ST(
+			"Combined test alg list",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_display_list),
+
 
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
Signature · 1 line
2.25.1
#101 lore raw

PATCH v6 4/7 test/security: add inline IPsec reassembly cases

In reply to Akhil Goyal

Added unit test cases for IP reassembly of inline IPsec inbound scenarios.
In these cases, known test vectors of fragments are first processed for inline outbound processing and then received back on loopback interface for inbound processing along with IP reassembly of the corresponding decrypted packets. The resultant plain text reassembled packet is compared with original unfragmented packet.

In this patch, cases are added for 2/4/5 fragments for both IPv4 and IPv6 packets. A few negative test cases are also added like incomplete fragments, out of place fragments, duplicate fragments.

---
 app/test/test_security_inline_proto.c         | 423 ++++++++++-
 app/test/test_security_inline_proto_vectors.h | 684 ++++++++++++++++++
 2 files changed, 1106 insertions(+), 1 deletion(-)
app/test/test_security_inline_proto.c +422 -1
index a44a4f9b04..2aa7072512 100644
@@ -41,6 +41,9 @@ test_inline_ipsec(void)
 #define MAX_TRAFFIC_BURST		2048
 #define NB_MBUF				10240
 
+#define ENCAP_DECAP_BURST_SZ		33
+#define APP_REASS_TIMEOUT		10
+
 extern struct ipsec_test_data pkt_aes_128_gcm;
 extern struct ipsec_test_data pkt_aes_192_gcm;
 extern struct ipsec_test_data pkt_aes_256_gcm;
@@ -94,6 +97,8 @@ uint16_t port_id;
 
 static uint64_t link_mbps;
 
+static int ip_reassembly_dynfield_offset = -1;
+
 static struct rte_flow *default_flow[RTE_MAX_ETHPORTS];
 
 /* Create Inline IPsec session */
@@ -530,6 +535,349 @@ destroy_default_flow(uint16_t portid)
 struct rte_mbuf **tx_pkts_burst;
 struct rte_mbuf **rx_pkts_burst;
 
+static int
+compare_pkt_data(struct rte_mbuf *m, uint8_t *ref, unsigned int tot_len)
+{
+	unsigned int len;
+	unsigned int nb_segs = m->nb_segs;
+	unsigned int matched = 0;
+	struct rte_mbuf *save = m;
+
+	while (m) {
+		len = tot_len;
+		if (len > m->data_len)
+			len = m->data_len;
+		if (len != 0) {
+			if (memcmp(rte_pktmbuf_mtod(m, char *),
+					ref + matched, len)) {
+				printf("\n====Reassembly case failed: Data Mismatch");
+				rte_hexdump(stdout, "Reassembled",
+					rte_pktmbuf_mtod(m, char *),
+					len);
+				rte_hexdump(stdout, "reference",
+					ref + matched,
+					len);
+				return TEST_FAILED;
+			}
+		}
+		tot_len -= len;
+		matched += len;
+		m = m->next;
+	}
+
+	if (tot_len) {
+		printf("\n====Reassembly case failed: Data Missing %u",
+		       tot_len);
+		printf("\n====nb_segs %u, tot_len %u", nb_segs, tot_len);
+		rte_pktmbuf_dump(stderr, save, -1);
+		return TEST_FAILED;
+	}
+	return TEST_SUCCESS;
+}
+
+static inline bool
+is_ip_reassembly_incomplete(struct rte_mbuf *mbuf)
+{
+	static uint64_t ip_reassembly_dynflag;
+	int ip_reassembly_dynflag_offset;
+
+	if (ip_reassembly_dynflag == 0) {
+		ip_reassembly_dynflag_offset = rte_mbuf_dynflag_lookup(
+			RTE_MBUF_DYNFLAG_IP_REASSEMBLY_INCOMPLETE_NAME, NULL);
+		if (ip_reassembly_dynflag_offset < 0)
+			return false;
+		ip_reassembly_dynflag = RTE_BIT64(ip_reassembly_dynflag_offset);
+	}
+
+	return (mbuf->ol_flags & ip_reassembly_dynflag) != 0;
+}
+
+static void
+free_mbuf(struct rte_mbuf *mbuf)
+{
+	rte_eth_ip_reassembly_dynfield_t dynfield;
+
+	if (!mbuf)
+		return;
+
+	if (!is_ip_reassembly_incomplete(mbuf)) {
+		rte_pktmbuf_free(mbuf);
+	} else {
+		if (ip_reassembly_dynfield_offset < 0)
+			return;
+
+		while (mbuf) {
+			dynfield = *RTE_MBUF_DYNFIELD(mbuf,
+					ip_reassembly_dynfield_offset,
+					rte_eth_ip_reassembly_dynfield_t *);
+			rte_pktmbuf_free(mbuf);
+			mbuf = dynfield.next_frag;
+		}
+	}
+}
+
+
+static int
+get_and_verify_incomplete_frags(struct rte_mbuf *mbuf,
+				struct reassembly_vector *vector)
+{
+	rte_eth_ip_reassembly_dynfield_t *dynfield[MAX_PKT_BURST];
+	int j = 0, ret;
+	/**
+	 * IP reassembly offload is incomplete, and fragments are listed in
+	 * dynfield which can be reassembled in SW.
+	 */
+	printf("\nHW IP Reassembly is not complete; attempt SW IP Reassembly,"
+		"\nMatching with original frags.");
+
+	if (ip_reassembly_dynfield_offset < 0)
+		return -1;
+
+	printf("\ncomparing frag: %d", j);
+	/* Skip Ethernet header comparison */
+	rte_pktmbuf_adj(mbuf, RTE_ETHER_HDR_LEN);
+	ret = compare_pkt_data(mbuf, vector->frags[j]->data,
+				vector->frags[j]->len);
+	if (ret)
+		return ret;
+	j++;
+	dynfield[j] = RTE_MBUF_DYNFIELD(mbuf, ip_reassembly_dynfield_offset,
+					rte_eth_ip_reassembly_dynfield_t *);
+	printf("\ncomparing frag: %d", j);
+	/* Skip Ethernet header comparison */
+	rte_pktmbuf_adj(dynfield[j]->next_frag, RTE_ETHER_HDR_LEN);
+	ret = compare_pkt_data(dynfield[j]->next_frag, vector->frags[j]->data,
+			vector->frags[j]->len);
+	if (ret)
+		return ret;
+
+	while ((dynfield[j]->nb_frags > 1) &&
+			is_ip_reassembly_incomplete(dynfield[j]->next_frag)) {
+		j++;
+		dynfield[j] = RTE_MBUF_DYNFIELD(dynfield[j-1]->next_frag,
+					ip_reassembly_dynfield_offset,
+					rte_eth_ip_reassembly_dynfield_t *);
+		printf("\ncomparing frag: %d", j);
+		/* Skip Ethernet header comparison */
+		rte_pktmbuf_adj(dynfield[j]->next_frag, RTE_ETHER_HDR_LEN);
+		ret = compare_pkt_data(dynfield[j]->next_frag,
+				vector->frags[j]->data, vector->frags[j]->len);
+		if (ret)
+			return ret;
+	}
+	return ret;
+}
+
+static int
+test_ipsec_with_reassembly(struct reassembly_vector *vector,
+		const struct ipsec_test_flags *flags)
+{
+	struct rte_security_session *out_ses[ENCAP_DECAP_BURST_SZ] = {0};
+	struct rte_security_session *in_ses[ENCAP_DECAP_BURST_SZ] = {0};
+	struct rte_eth_ip_reassembly_params reass_capa = {0};
+	struct rte_security_session_conf sess_conf_out = {0};
+	struct rte_security_session_conf sess_conf_in = {0};
+	unsigned int nb_tx, burst_sz, nb_sent = 0;
+	struct rte_crypto_sym_xform cipher_out = {0};
+	struct rte_crypto_sym_xform auth_out = {0};
+	struct rte_crypto_sym_xform aead_out = {0};
+	struct rte_crypto_sym_xform cipher_in = {0};
+	struct rte_crypto_sym_xform auth_in = {0};
+	struct rte_crypto_sym_xform aead_in = {0};
+	struct ipsec_test_data sa_data = {0};
+	struct rte_security_ctx *ctx;
+	unsigned int i, nb_rx = 0, j;
+	uint32_t ol_flags;
+	int ret = 0;
+
+	burst_sz = vector->burst ? ENCAP_DECAP_BURST_SZ : 1;
+	nb_tx = vector->nb_frags * burst_sz;
+
+	rte_eth_dev_stop(port_id);
+	if (ret != 0) {
+		printf("rte_eth_dev_stop: err=%s, port=%u\n",
+			       rte_strerror(-ret), port_id);
+		return ret;
+	}
+	rte_eth_ip_reassembly_capability_get(port_id, &reass_capa);
+	if (reass_capa.max_frags < vector->nb_frags)
+		return TEST_SKIPPED;
+	if (reass_capa.timeout_ms > APP_REASS_TIMEOUT) {
+		reass_capa.timeout_ms = APP_REASS_TIMEOUT;
+		rte_eth_ip_reassembly_conf_set(port_id, &reass_capa);
+	}
+
+	ret = rte_eth_dev_start(port_id);
+	if (ret < 0) {
+		printf("rte_eth_dev_start: err=%d, port=%d\n",
+			ret, port_id);
+		return ret;
+	}
+
+	memset(tx_pkts_burst, 0, sizeof(tx_pkts_burst[0]) * nb_tx);
+	memset(rx_pkts_burst, 0, sizeof(rx_pkts_burst[0]) * nb_tx);
+
+	for (i = 0; i < nb_tx; i += vector->nb_frags) {
+		for (j = 0; j < vector->nb_frags; j++) {
+			tx_pkts_burst[i+j] = init_packet(mbufpool,
+						vector->frags[j]->data,
+						vector->frags[j]->len);
+			if (tx_pkts_burst[i+j] == NULL) {
+				ret = -1;
+				printf("\n packed init failed\n");
+				goto out;
+			}
+		}
+	}
+
+	for (i = 0; i < burst_sz; i++) {
+		memcpy(&sa_data, vector->sa_data,
+				sizeof(struct ipsec_test_data));
+		/* Update SPI for every new SA */
+		sa_data.ipsec_xform.spi += i;
+		sa_data.ipsec_xform.direction =
+					RTE_SECURITY_IPSEC_SA_DIR_EGRESS;
+		if (sa_data.aead) {
+			sess_conf_out.crypto_xform = &aead_out;
+		} else {
+			sess_conf_out.crypto_xform = &cipher_out;
+			sess_conf_out.crypto_xform->next = &auth_out;
+		}
+
+		/* Create Inline IPsec outbound session. */
+		ret = create_inline_ipsec_session(&sa_data, port_id,
+				&out_ses[i], &ctx, &ol_flags, flags,
+				&sess_conf_out);
+		if (ret) {
+			printf("\nInline outbound session create failed\n");
+			goto out;
+		}
+	}
+
+	j = 0;
+	for (i = 0; i < nb_tx; i++) {
+		if (ol_flags & RTE_SECURITY_TX_OLOAD_NEED_MDATA)
+			rte_security_set_pkt_metadata(ctx,
+				out_ses[j], tx_pkts_burst[i], NULL);
+		tx_pkts_burst[i]->ol_flags |= RTE_MBUF_F_TX_SEC_OFFLOAD;
+
+		/* Move to next SA after nb_frags */
+		if ((i + 1) % vector->nb_frags == 0)
+			j++;
+	}
+
+	for (i = 0; i < burst_sz; i++) {
+		memcpy(&sa_data, vector->sa_data,
+				sizeof(struct ipsec_test_data));
+		/* Update SPI for every new SA */
+		sa_data.ipsec_xform.spi += i;
+		sa_data.ipsec_xform.direction =
+					RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
+
+		if (sa_data.aead) {
+			sess_conf_in.crypto_xform = &aead_in;
+		} else {
+			sess_conf_in.crypto_xform = &auth_in;
+			sess_conf_in.crypto_xform->next = &cipher_in;
+		}
+		/* Create Inline IPsec inbound session. */
+		ret = create_inline_ipsec_session(&sa_data, port_id, &in_ses[i],
+				&ctx, &ol_flags, flags, &sess_conf_in);
+		if (ret) {
+			printf("\nInline inbound session create failed\n");
+			goto out;
+		}
+	}
+
+	/* Retrieve reassembly dynfield offset if available */
+	if (ip_reassembly_dynfield_offset < 0 && vector->nb_frags > 1)
+		ip_reassembly_dynfield_offset = rte_mbuf_dynfield_lookup(
+				RTE_MBUF_DYNFIELD_IP_REASSEMBLY_NAME, NULL);
+
+
+	ret = create_default_flow(port_id);
+	if (ret)
+		goto out;
+
+	nb_sent = rte_eth_tx_burst(port_id, 0, tx_pkts_burst, nb_tx);
+	if (nb_sent != nb_tx) {
+		ret = -1;
+		printf("\nFailed to tx %u pkts", nb_tx);
+		goto out;
+	}
+
+	rte_delay_ms(1);
+
+	/* Retry few times before giving up */
+	nb_rx = 0;
+	j = 0;
+	do {
+		nb_rx += rte_eth_rx_burst(port_id, 0, &rx_pkts_burst[nb_rx],
+					  nb_tx - nb_rx);
+		j++;
+		if (nb_rx >= nb_tx)
+			break;
+		rte_delay_ms(1);
+	} while (j < 5 || !nb_rx);
+
+	/* Check for minimum number of Rx packets expected */
+	if ((vector->nb_frags == 1 && nb_rx != nb_tx) ||
+	    (vector->nb_frags > 1 && nb_rx < burst_sz)) {
+		printf("\nreceived less Rx pkts(%u) pkts\n", nb_rx);
+		ret = TEST_FAILED;
+		goto out;
+	}
+
+	for (i = 0; i < nb_rx; i++) {
+		if (vector->nb_frags > 1 &&
+		    is_ip_reassembly_incomplete(rx_pkts_burst[i])) {
+			ret = get_and_verify_incomplete_frags(rx_pkts_burst[i],
+							      vector);
+			if (ret != TEST_SUCCESS)
+				break;
+			continue;
+		}
+
+		if (rx_pkts_burst[i]->ol_flags &
+		    RTE_MBUF_F_RX_SEC_OFFLOAD_FAILED ||
+		    !(rx_pkts_burst[i]->ol_flags & RTE_MBUF_F_RX_SEC_OFFLOAD)) {
+			printf("\nsecurity offload failed\n");
+			ret = TEST_FAILED;
+			break;
+		}
+
+		if (vector->full_pkt->len + RTE_ETHER_HDR_LEN !=
+				rx_pkts_burst[i]->pkt_len) {
+			printf("\nreassembled/decrypted packet length mismatch\n");
+			ret = TEST_FAILED;
+			break;
+		}
+		rte_pktmbuf_adj(rx_pkts_burst[i], RTE_ETHER_HDR_LEN);
+		ret = compare_pkt_data(rx_pkts_burst[i],
+				       vector->full_pkt->data,
+				       vector->full_pkt->len);
+		if (ret != TEST_SUCCESS)
+			break;
+	}
+
+out:
+	destroy_default_flow(port_id);
+
+	/* Clear session data. */
+	for (i = 0; i < burst_sz; i++) {
+		if (out_ses[i])
+			rte_security_session_destroy(ctx, out_ses[i]);
+		if (in_ses[i])
+			rte_security_session_destroy(ctx, in_ses[i]);
+	}
+
+	for (i = nb_sent; i < nb_tx; i++)
+		free_mbuf(tx_pkts_burst[i]);
+	for (i = 0; i < nb_rx; i++)
+		free_mbuf(rx_pkts_burst[i]);
+	return ret;
+}
+
 static int
 test_ipsec_inline_proto_process(struct ipsec_test_data *td,
 		struct ipsec_test_data *res_d,
@@ -779,6 +1127,7 @@ ut_setup_inline_ipsec(void)
 static void
 ut_teardown_inline_ipsec(void)
 {
+	struct rte_eth_ip_reassembly_params reass_conf = {0};
 	uint16_t portid;
 	int ret;
 
@@ -788,6 +1137,9 @@ ut_teardown_inline_ipsec(void)
 		if (ret != 0)
 			printf("rte_eth_dev_stop: err=%s, port=%u\n",
 			       rte_strerror(-ret), portid);
+
+		/* Clear reassembly configuration */
+		rte_eth_ip_reassembly_conf_set(portid, &reass_conf);
 	}
 }
 
@@ -890,6 +1242,36 @@ inline_ipsec_testsuite_teardown(void)
 	}
 }
 
+static int
+test_inline_ip_reassembly(const void *testdata)
+{
+	struct reassembly_vector reassembly_td = {0};
+	const struct reassembly_vector *td = testdata;
+	struct ip_reassembly_test_packet full_pkt;
+	struct ip_reassembly_test_packet frags[MAX_FRAGS];
+	struct ipsec_test_flags flags = {0};
+	int i = 0;
+
+	reassembly_td.sa_data = td->sa_data;
+	reassembly_td.nb_frags = td->nb_frags;
+	reassembly_td.burst = td->burst;
+
+	memcpy(&full_pkt, td->full_pkt,
+			sizeof(struct ip_reassembly_test_packet));
+	reassembly_td.full_pkt = &full_pkt;
+
+	test_vector_payload_populate(reassembly_td.full_pkt, true);
+	for (; i < reassembly_td.nb_frags; i++) {
+		memcpy(&frags[i], td->frags[i],
+			sizeof(struct ip_reassembly_test_packet));
+		reassembly_td.frags[i] = &frags[i];
+		test_vector_payload_populate(reassembly_td.frags[i],
+				(i == 0) ? true : false);
+	}
+
+	return test_ipsec_with_reassembly(&reassembly_td, &flags);
+}
+
 static int
 test_ipsec_inline_proto_known_vec(const void *test_data)
 {
@@ -1036,7 +1418,46 @@ static struct unit_test_suite inline_ipsec_testsuite  = {
 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
 			test_ipsec_inline_proto_display_list),
 
-
+		TEST_CASE_NAMED_WITH_DATA(
+			"IPv4 Reassembly with 2 fragments",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_inline_ip_reassembly, &ipv4_2frag_vector),
+		TEST_CASE_NAMED_WITH_DATA(
+			"IPv6 Reassembly with 2 fragments",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_inline_ip_reassembly, &ipv6_2frag_vector),
+		TEST_CASE_NAMED_WITH_DATA(
+			"IPv4 Reassembly with 4 fragments",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_inline_ip_reassembly, &ipv4_4frag_vector),
+		TEST_CASE_NAMED_WITH_DATA(
+			"IPv6 Reassembly with 4 fragments",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_inline_ip_reassembly, &ipv6_4frag_vector),
+		TEST_CASE_NAMED_WITH_DATA(
+			"IPv4 Reassembly with 5 fragments",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_inline_ip_reassembly, &ipv4_5frag_vector),
+		TEST_CASE_NAMED_WITH_DATA(
+			"IPv6 Reassembly with 5 fragments",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_inline_ip_reassembly, &ipv6_5frag_vector),
+		TEST_CASE_NAMED_WITH_DATA(
+			"IPv4 Reassembly with incomplete fragments",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_inline_ip_reassembly, &ipv4_incomplete_vector),
+		TEST_CASE_NAMED_WITH_DATA(
+			"IPv4 Reassembly with overlapping fragments",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_inline_ip_reassembly, &ipv4_overlap_vector),
+		TEST_CASE_NAMED_WITH_DATA(
+			"IPv4 Reassembly with out of order fragments",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_inline_ip_reassembly, &ipv4_out_of_order_vector),
+		TEST_CASE_NAMED_WITH_DATA(
+			"IPv4 Reassembly with burst of 4 fragments",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_inline_ip_reassembly, &ipv4_4frag_burst_vector),
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	},
app/test/test_security_inline_proto_vectors.h +684 -0

688 lines not on this page · raw message

Signature · 1 line
2.25.1
#102 lore raw

PATCH v6 5/7 test/security: add more inline IPsec functional cases

In reply to Akhil Goyal

Added more inline IPsec functional verification cases. These cases do not have known vectors but are verified using encap + decap test for all the algo combinations.

---
 app/test/test_security_inline_proto.c | 517 ++++++++++++++++++++++++++
 1 file changed, 517 insertions(+)
app/test/test_security_inline_proto.c +517 -0
index 2aa7072512..ce68da7605 100644
@@ -1321,6 +1321,394 @@ test_ipsec_inline_proto_display_list(const void *data __rte_unused)
 	return test_ipsec_inline_proto_all(&flags);
 }
 
+static int
+test_ipsec_inline_proto_udp_encap(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.udp_encap = true;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_udp_ports_verify(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.udp_encap = true;
+	flags.udp_ports_verify = true;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_err_icv_corrupt(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.icv_corrupt = true;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_tunnel_dst_addr_verify(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_tunnel_src_dst_addr_verify(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_inner_ip_csum(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.ip_csum = true;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_inner_l4_csum(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.l4_csum = true;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_tunnel_v4_in_v4(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.ipv6 = false;
+	flags.tunnel_ipv6 = false;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_tunnel_v6_in_v6(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.ipv6 = true;
+	flags.tunnel_ipv6 = true;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_tunnel_v4_in_v6(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.ipv6 = false;
+	flags.tunnel_ipv6 = true;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_tunnel_v6_in_v4(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.ipv6 = true;
+	flags.tunnel_ipv6 = false;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_transport_v4(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.ipv6 = false;
+	flags.transport = true;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_transport_l4_csum(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags = {
+		.l4_csum = true,
+		.transport = true,
+	};
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_stats(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.stats_success = true;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_pkt_fragment(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.fragment = true;
+
+	return test_ipsec_inline_proto_all(&flags);
+
+}
+
+static int
+test_ipsec_inline_proto_copy_df_inner_0(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.df = TEST_IPSEC_COPY_DF_INNER_0;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_copy_df_inner_1(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.df = TEST_IPSEC_COPY_DF_INNER_1;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_set_df_0_inner_1(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.df = TEST_IPSEC_SET_DF_0_INNER_1;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_set_df_1_inner_0(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.df = TEST_IPSEC_SET_DF_1_INNER_0;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_ipv4_copy_dscp_inner_0(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_0;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_ipv4_copy_dscp_inner_1(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_1;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_ipv4_set_dscp_0_inner_1(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.dscp = TEST_IPSEC_SET_DSCP_0_INNER_1;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_ipv4_set_dscp_1_inner_0(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.dscp = TEST_IPSEC_SET_DSCP_1_INNER_0;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_ipv6_copy_dscp_inner_0(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.ipv6 = true;
+	flags.tunnel_ipv6 = true;
+	flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_0;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_ipv6_copy_dscp_inner_1(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.ipv6 = true;
+	flags.tunnel_ipv6 = true;
+	flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_1;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_ipv6_set_dscp_0_inner_1(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.ipv6 = true;
+	flags.tunnel_ipv6 = true;
+	flags.dscp = TEST_IPSEC_SET_DSCP_0_INNER_1;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_ipv6_set_dscp_1_inner_0(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.ipv6 = true;
+	flags.tunnel_ipv6 = true;
+	flags.dscp = TEST_IPSEC_SET_DSCP_1_INNER_0;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_ipv4_ttl_decrement(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags = {
+		.dec_ttl_or_hop_limit = true
+	};
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_ipv6_hop_limit_decrement(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags = {
+		.ipv6 = true,
+		.dec_ttl_or_hop_limit = true
+	};
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_iv_gen(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.iv_gen = true;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
+
+static int
+test_ipsec_inline_proto_known_vec_fragmented(const void *test_data)
+{
+	struct ipsec_test_data td_outb;
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+	flags.fragment = true;
+
+	memcpy(&td_outb, test_data, sizeof(td_outb));
+
+	/* Disable IV gen to be able to test with known vectors */
+	td_outb.ipsec_xform.options.iv_gen_disable = 1;
+
+	return test_ipsec_inline_proto_process(&td_outb, NULL, 1, false,
+						&flags);
+}
 static struct unit_test_suite inline_ipsec_testsuite  = {
 	.suite_name = "Inline IPsec Ethernet Device Unit Test Suite",
 	.setup = inline_ipsec_testsuite_setup,
@@ -1367,6 +1755,13 @@ static struct unit_test_suite inline_ipsec_testsuite  = {
 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
 			test_ipsec_inline_proto_known_vec,
 			&pkt_null_aes_xcbc),
+
+		TEST_CASE_NAMED_WITH_DATA(
+			"Outbound fragmented packet",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_fragmented,
+			&pkt_aes_128_gcm_frag),
+
 		TEST_CASE_NAMED_WITH_DATA(
 			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 128)",
 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
@@ -1418,6 +1813,128 @@ static struct unit_test_suite inline_ipsec_testsuite  = {
 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
 			test_ipsec_inline_proto_display_list),
 
+		TEST_CASE_NAMED_ST(
+			"UDP encapsulation",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_udp_encap),
+		TEST_CASE_NAMED_ST(
+			"UDP encapsulation ports verification test",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_udp_ports_verify),
+		TEST_CASE_NAMED_ST(
+			"Negative test: ICV corruption",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_err_icv_corrupt),
+		TEST_CASE_NAMED_ST(
+			"Tunnel dst addr verification",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_tunnel_dst_addr_verify),
+		TEST_CASE_NAMED_ST(
+			"Tunnel src and dst addr verification",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_tunnel_src_dst_addr_verify),
+		TEST_CASE_NAMED_ST(
+			"Inner IP checksum",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_inner_ip_csum),
+		TEST_CASE_NAMED_ST(
+			"Inner L4 checksum",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_inner_l4_csum),
+		TEST_CASE_NAMED_ST(
+			"Tunnel IPv4 in IPv4",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_tunnel_v4_in_v4),
+		TEST_CASE_NAMED_ST(
+			"Tunnel IPv6 in IPv6",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_tunnel_v6_in_v6),
+		TEST_CASE_NAMED_ST(
+			"Tunnel IPv4 in IPv6",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_tunnel_v4_in_v6),
+		TEST_CASE_NAMED_ST(
+			"Tunnel IPv6 in IPv4",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_tunnel_v6_in_v4),
+		TEST_CASE_NAMED_ST(
+			"Transport IPv4",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_transport_v4),
+		TEST_CASE_NAMED_ST(
+			"Transport l4 checksum",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_transport_l4_csum),
+		TEST_CASE_NAMED_ST(
+			"Statistics: success",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_stats),
+		TEST_CASE_NAMED_ST(
+			"Fragmented packet",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_pkt_fragment),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header copy DF (inner 0)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_copy_df_inner_0),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header copy DF (inner 1)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_copy_df_inner_1),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header set DF 0 (inner 1)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_set_df_0_inner_1),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header set DF 1 (inner 0)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_set_df_1_inner_0),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header IPv4 copy DSCP (inner 0)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_ipv4_copy_dscp_inner_0),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header IPv4 copy DSCP (inner 1)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_ipv4_copy_dscp_inner_1),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header IPv4 set DSCP 0 (inner 1)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_ipv4_set_dscp_0_inner_1),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header IPv4 set DSCP 1 (inner 0)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_ipv4_set_dscp_1_inner_0),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header IPv6 copy DSCP (inner 0)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_ipv6_copy_dscp_inner_0),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header IPv6 copy DSCP (inner 1)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_ipv6_copy_dscp_inner_1),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header IPv6 set DSCP 0 (inner 1)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_ipv6_set_dscp_0_inner_1),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header IPv6 set DSCP 1 (inner 0)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_ipv6_set_dscp_1_inner_0),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header IPv4 decrement inner TTL",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_ipv4_ttl_decrement),
+		TEST_CASE_NAMED_ST(
+			"Tunnel header IPv6 decrement inner hop limit",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_ipv6_hop_limit_decrement),
+		TEST_CASE_NAMED_ST(
+			"IV generation",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_iv_gen),
+
+
 		TEST_CASE_NAMED_WITH_DATA(
 			"IPv4 Reassembly with 2 fragments",
 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
Signature · 1 line
2.25.1
#103 lore raw

PATCH v6 6/7 test/security: add ESN and anti-replay cases for inline

In reply to Akhil Goyal

Added cases to test anti replay for inline IPsec processing with and without extended sequence number support.

---
 app/test/test_security_inline_proto.c | 311 ++++++++++++++++++++++++++
 1 file changed, 311 insertions(+)
app/test/test_security_inline_proto.c +311 -0
index ce68da7605..1c32141cd1 100644
@@ -1098,6 +1098,139 @@ test_ipsec_inline_proto_all(const struct ipsec_test_flags *flags)
 		return TEST_SKIPPED;
 }
 
+static int
+test_ipsec_inline_proto_process_with_esn(struct ipsec_test_data td[],
+		struct ipsec_test_data res_d[],
+		int nb_pkts,
+		bool silent,
+		const struct ipsec_test_flags *flags)
+{
+	struct rte_security_session_conf sess_conf = {0};
+	struct ipsec_test_data *res_d_tmp = NULL;
+	struct rte_crypto_sym_xform cipher = {0};
+	struct rte_crypto_sym_xform auth = {0};
+	struct rte_crypto_sym_xform aead = {0};
+	struct rte_mbuf *rx_pkt = NULL;
+	struct rte_mbuf *tx_pkt = NULL;
+	int nb_rx, nb_sent;
+	struct rte_security_session *ses;
+	struct rte_security_ctx *ctx;
+	uint32_t ol_flags;
+	int i, ret;
+
+	if (td[0].aead) {
+		sess_conf.crypto_xform = &aead;
+	} else {
+		if (td[0].ipsec_xform.direction ==
+				RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
+			sess_conf.crypto_xform = &cipher;
+			sess_conf.crypto_xform->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
+			sess_conf.crypto_xform->next = &auth;
+			sess_conf.crypto_xform->next->type = RTE_CRYPTO_SYM_XFORM_AUTH;
+		} else {
+			sess_conf.crypto_xform = &auth;
+			sess_conf.crypto_xform->type = RTE_CRYPTO_SYM_XFORM_AUTH;
+			sess_conf.crypto_xform->next = &cipher;
+			sess_conf.crypto_xform->next->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
+		}
+	}
+
+	/* Create Inline IPsec session. */
+	ret = create_inline_ipsec_session(&td[0], port_id, &ses, &ctx,
+					  &ol_flags, flags, &sess_conf);
+	if (ret)
+		return ret;
+
+	if (td[0].ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS) {
+		ret = create_default_flow(port_id);
+		if (ret)
+			goto out;
+	}
+
+	for (i = 0; i < nb_pkts; i++) {
+		tx_pkt = init_packet(mbufpool, td[i].input_text.data,
+					td[i].input_text.len);
+		if (tx_pkt == NULL) {
+			ret = TEST_FAILED;
+			goto out;
+		}
+
+		if (test_ipsec_pkt_update(rte_pktmbuf_mtod_offset(tx_pkt,
+					uint8_t *, RTE_ETHER_HDR_LEN), flags)) {
+			ret = TEST_FAILED;
+			goto out;
+		}
+
+		if (td[i].ipsec_xform.direction ==
+				RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
+			if (flags->antireplay) {
+				sess_conf.ipsec.esn.value =
+						td[i].ipsec_xform.esn.value;
+				ret = rte_security_session_update(ctx, ses,
+						&sess_conf);
+				if (ret) {
+					printf("Could not update ESN in session\n");
+					rte_pktmbuf_free(tx_pkt);
+					ret = TEST_SKIPPED;
+					goto out;
+				}
+			}
+			if (ol_flags & RTE_SECURITY_TX_OLOAD_NEED_MDATA)
+				rte_security_set_pkt_metadata(ctx, ses,
+						tx_pkt, NULL);
+			tx_pkt->ol_flags |= RTE_MBUF_F_TX_SEC_OFFLOAD;
+		}
+		/* Send packet to ethdev for inline IPsec processing. */
+		nb_sent = rte_eth_tx_burst(port_id, 0, &tx_pkt, 1);
+		if (nb_sent != 1) {
+			printf("\nUnable to TX packets");
+			rte_pktmbuf_free(tx_pkt);
+			ret = TEST_FAILED;
+			goto out;
+		}
+
+		rte_pause();
+
+		/* Receive back packet on loopback interface. */
+		do {
+			rte_delay_ms(1);
+			nb_rx = rte_eth_rx_burst(port_id, 0, &rx_pkt, 1);
+		} while (nb_rx == 0);
+
+		rte_pktmbuf_adj(rx_pkt, RTE_ETHER_HDR_LEN);
+
+		if (res_d != NULL)
+			res_d_tmp = &res_d[i];
+
+		ret = test_ipsec_post_process(rx_pkt, &td[i],
+					      res_d_tmp, silent, flags);
+		if (ret != TEST_SUCCESS) {
+			rte_pktmbuf_free(rx_pkt);
+			goto out;
+		}
+
+		ret = test_ipsec_stats_verify(ctx, ses, flags,
+					td->ipsec_xform.direction);
+		if (ret != TEST_SUCCESS) {
+			rte_pktmbuf_free(rx_pkt);
+			goto out;
+		}
+
+		rte_pktmbuf_free(rx_pkt);
+		rx_pkt = NULL;
+		tx_pkt = NULL;
+	}
+
+out:
+	if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS)
+		destroy_default_flow(port_id);
+
+	/* Destroy session so that other cases can create the session again */
+	rte_security_session_destroy(ctx, ses);
+	ses = NULL;
+
+	return ret;
+}
 
 static int
 ut_setup_inline_ipsec(void)
@@ -1709,6 +1842,153 @@ test_ipsec_inline_proto_known_vec_fragmented(const void *test_data)
 	return test_ipsec_inline_proto_process(&td_outb, NULL, 1, false,
 						&flags);
 }
+
+static int
+test_ipsec_inline_pkt_replay(const void *test_data, const uint64_t esn[],
+		      bool replayed_pkt[], uint32_t nb_pkts, bool esn_en,
+		      uint64_t winsz)
+{
+	struct ipsec_test_data td_outb[IPSEC_TEST_PACKETS_MAX];
+	struct ipsec_test_data td_inb[IPSEC_TEST_PACKETS_MAX];
+	struct ipsec_test_flags flags;
+	uint32_t i, ret = 0;
+
+	memset(&flags, 0, sizeof(flags));
+	flags.antireplay = true;
+
+	for (i = 0; i < nb_pkts; i++) {
+		memcpy(&td_outb[i], test_data, sizeof(td_outb));
+		td_outb[i].ipsec_xform.options.iv_gen_disable = 1;
+		td_outb[i].ipsec_xform.replay_win_sz = winsz;
+		td_outb[i].ipsec_xform.options.esn = esn_en;
+	}
+
+	for (i = 0; i < nb_pkts; i++)
+		td_outb[i].ipsec_xform.esn.value = esn[i];
+
+	ret = test_ipsec_inline_proto_process_with_esn(td_outb, td_inb,
+				nb_pkts, true, &flags);
+	if (ret != TEST_SUCCESS)
+		return ret;
+
+	test_ipsec_td_update(td_inb, td_outb, nb_pkts, &flags);
+
+	for (i = 0; i < nb_pkts; i++) {
+		td_inb[i].ipsec_xform.options.esn = esn_en;
+		/* Set antireplay flag for packets to be dropped */
+		td_inb[i].ar_packet = replayed_pkt[i];
+	}
+
+	ret = test_ipsec_inline_proto_process_with_esn(td_inb, NULL, nb_pkts,
+				true, &flags);
+
+	return ret;
+}
+
+static int
+test_ipsec_inline_proto_pkt_antireplay(const void *test_data, uint64_t winsz)
+{
+
+	uint32_t nb_pkts = 5;
+	bool replayed_pkt[5];
+	uint64_t esn[5];
+
+	/* 1. Advance the TOP of the window to WS * 2 */
+	esn[0] = winsz * 2;
+	/* 2. Test sequence number within the new window(WS + 1) */
+	esn[1] = winsz + 1;
+	/* 3. Test sequence number less than the window BOTTOM */
+	esn[2] = winsz;
+	/* 4. Test sequence number in the middle of the window */
+	esn[3] = winsz + (winsz / 2);
+	/* 5. Test replay of the packet in the middle of the window */
+	esn[4] = winsz + (winsz / 2);
+
+	replayed_pkt[0] = false;
+	replayed_pkt[1] = false;
+	replayed_pkt[2] = true;
+	replayed_pkt[3] = false;
+	replayed_pkt[4] = true;
+
+	return test_ipsec_inline_pkt_replay(test_data, esn, replayed_pkt,
+			nb_pkts, false, winsz);
+}
+
+static int
+test_ipsec_inline_proto_pkt_antireplay1024(const void *test_data)
+{
+	return test_ipsec_inline_proto_pkt_antireplay(test_data, 1024);
+}
+
+static int
+test_ipsec_inline_proto_pkt_antireplay2048(const void *test_data)
+{
+	return test_ipsec_inline_proto_pkt_antireplay(test_data, 2048);
+}
+
+static int
+test_ipsec_inline_proto_pkt_antireplay4096(const void *test_data)
+{
+	return test_ipsec_inline_proto_pkt_antireplay(test_data, 4096);
+}
+
+static int
+test_ipsec_inline_proto_pkt_esn_antireplay(const void *test_data, uint64_t winsz)
+{
+
+	uint32_t nb_pkts = 7;
+	bool replayed_pkt[7];
+	uint64_t esn[7];
+
+	/* Set the initial sequence number */
+	esn[0] = (uint64_t)(0xFFFFFFFF - winsz);
+	/* 1. Advance the TOP of the window to (1<<32 + WS/2) */
+	esn[1] = (uint64_t)((1ULL << 32) + (winsz / 2));
+	/* 2. Test sequence number within new window (1<<32 + WS/2 + 1) */
+	esn[2] = (uint64_t)((1ULL << 32) - (winsz / 2) + 1);
+	/* 3. Test with sequence number within window (1<<32 - 1) */
+	esn[3] = (uint64_t)((1ULL << 32) - 1);
+	/* 4. Test with sequence number within window (1<<32 - 1) */
+	esn[4] = (uint64_t)(1ULL << 32);
+	/* 5. Test with duplicate sequence number within
+	 * new window (1<<32 - 1)
+	 */
+	esn[5] = (uint64_t)((1ULL << 32) - 1);
+	/* 6. Test with duplicate sequence number within new window (1<<32) */
+	esn[6] = (uint64_t)(1ULL << 32);
+
+	replayed_pkt[0] = false;
+	replayed_pkt[1] = false;
+	replayed_pkt[2] = false;
+	replayed_pkt[3] = false;
+	replayed_pkt[4] = false;
+	replayed_pkt[5] = true;
+	replayed_pkt[6] = true;
+
+	return test_ipsec_inline_pkt_replay(test_data, esn, replayed_pkt, nb_pkts,
+				     true, winsz);
+}
+
+static int
+test_ipsec_inline_proto_pkt_esn_antireplay1024(const void *test_data)
+{
+	return test_ipsec_inline_proto_pkt_esn_antireplay(test_data, 1024);
+}
+
+static int
+test_ipsec_inline_proto_pkt_esn_antireplay2048(const void *test_data)
+{
+	return test_ipsec_inline_proto_pkt_esn_antireplay(test_data, 2048);
+}
+
+static int
+test_ipsec_inline_proto_pkt_esn_antireplay4096(const void *test_data)
+{
+	return test_ipsec_inline_proto_pkt_esn_antireplay(test_data, 4096);
+}
+
+
+
 static struct unit_test_suite inline_ipsec_testsuite  = {
 	.suite_name = "Inline IPsec Ethernet Device Unit Test Suite",
 	.setup = inline_ipsec_testsuite_setup,
@@ -1935,6 +2215,37 @@ static struct unit_test_suite inline_ipsec_testsuite  = {
 			test_ipsec_inline_proto_iv_gen),
 
 
+		TEST_CASE_NAMED_WITH_DATA(
+			"Antireplay with window size 1024",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_pkt_antireplay1024,
+			&pkt_aes_128_gcm),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Antireplay with window size 2048",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_pkt_antireplay2048,
+			&pkt_aes_128_gcm),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Antireplay with window size 4096",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_pkt_antireplay4096,
+			&pkt_aes_128_gcm),
+		TEST_CASE_NAMED_WITH_DATA(
+			"ESN and Antireplay with window size 1024",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_pkt_esn_antireplay1024,
+			&pkt_aes_128_gcm),
+		TEST_CASE_NAMED_WITH_DATA(
+			"ESN and Antireplay with window size 2048",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_pkt_esn_antireplay2048,
+			&pkt_aes_128_gcm),
+		TEST_CASE_NAMED_WITH_DATA(
+			"ESN and Antireplay with window size 4096",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_pkt_esn_antireplay4096,
+			&pkt_aes_128_gcm),
+
 		TEST_CASE_NAMED_WITH_DATA(
 			"IPv4 Reassembly with 2 fragments",
 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
Signature · 1 line
2.25.1
#104 lore raw

PATCH v6 7/7 test/security: add inline IPsec IPv6 flow label cases

In reply to Akhil Goyal

From: Vamsi Attunuru <[email protected]>

Patch adds unit tests for IPv6 flow label set & copy operations.

---
 app/test/test_cryptodev_security_ipsec.c | 35 ++++++++++-
 app/test/test_cryptodev_security_ipsec.h | 10 +++
 app/test/test_security_inline_proto.c    | 79 ++++++++++++++++++++++++
 3 files changed, 123 insertions(+), 1 deletion(-)
app/test/test_cryptodev_security_ipsec.c +34 -1
index 14c6ba681f..408bd0bc82 100644
@@ -495,6 +495,10 @@ test_ipsec_td_prepare(const struct crypto_param *param1,
 		    flags->dscp == TEST_IPSEC_COPY_DSCP_INNER_1)
 			td->ipsec_xform.options.copy_dscp = 1;
 
+		if (flags->flabel == TEST_IPSEC_COPY_FLABEL_INNER_0 ||
+		    flags->flabel == TEST_IPSEC_COPY_FLABEL_INNER_1)
+			td->ipsec_xform.options.copy_flabel = 1;
+
 		if (flags->dec_ttl_or_hop_limit)
 			td->ipsec_xform.options.dec_ttl = 1;
 	}
@@ -933,6 +937,7 @@ test_ipsec_iph6_hdr_validate(const struct rte_ipv6_hdr *iph6,
 			     const struct ipsec_test_flags *flags)
 {
 	uint32_t vtc_flow;
+	uint32_t flabel;
 	uint8_t dscp;
 
 	if (!is_valid_ipv6_pkt(iph6)) {
@@ -959,6 +964,23 @@ test_ipsec_iph6_hdr_validate(const struct rte_ipv6_hdr *iph6,
 		}
 	}
 
+	flabel = vtc_flow & RTE_IPV6_HDR_FL_MASK;
+
+	if (flags->flabel == TEST_IPSEC_COPY_FLABEL_INNER_1 ||
+	    flags->flabel == TEST_IPSEC_SET_FLABEL_1_INNER_0) {
+		if (flabel != TEST_IPSEC_FLABEL_VAL) {
+			printf("FLABEL value is not matching [exp: %x, actual: %x]\n",
+			       TEST_IPSEC_FLABEL_VAL, flabel);
+			return -1;
+		}
+	} else {
+		if (flabel != 0) {
+			printf("FLABEL value is set [exp: 0, actual: %x]\n",
+			       flabel);
+			return -1;
+		}
+	}
+
 	return 0;
 }
 
@@ -1159,7 +1181,11 @@ test_ipsec_pkt_update(uint8_t *pkt, const struct ipsec_test_flags *flags)
 	if (flags->dscp == TEST_IPSEC_COPY_DSCP_INNER_1 ||
 	    flags->dscp == TEST_IPSEC_SET_DSCP_0_INNER_1 ||
 	    flags->dscp == TEST_IPSEC_COPY_DSCP_INNER_0 ||
-	    flags->dscp == TEST_IPSEC_SET_DSCP_1_INNER_0) {
+	    flags->dscp == TEST_IPSEC_SET_DSCP_1_INNER_0 ||
+	    flags->flabel == TEST_IPSEC_COPY_FLABEL_INNER_1 ||
+	    flags->flabel == TEST_IPSEC_SET_FLABEL_0_INNER_1 ||
+	    flags->flabel == TEST_IPSEC_COPY_FLABEL_INNER_0 ||
+	    flags->flabel == TEST_IPSEC_SET_FLABEL_1_INNER_0) {
 
 		if (is_ipv4(iph4)) {
 			uint8_t tos;
@@ -1187,6 +1213,13 @@ test_ipsec_pkt_update(uint8_t *pkt, const struct ipsec_test_flags *flags)
 			else
 				vtc_flow &= ~RTE_IPV6_HDR_DSCP_MASK;
 
+			if (flags->flabel == TEST_IPSEC_COPY_FLABEL_INNER_1 ||
+			    flags->flabel == TEST_IPSEC_SET_FLABEL_0_INNER_1)
+				vtc_flow |= (RTE_IPV6_HDR_FL_MASK &
+					     (TEST_IPSEC_FLABEL_VAL << RTE_IPV6_HDR_FL_SHIFT));
+			else
+				vtc_flow &= ~RTE_IPV6_HDR_FL_MASK;
+
 			iph6->vtc_flow = rte_cpu_to_be_32(vtc_flow);
 		}
 	}
app/test/test_cryptodev_security_ipsec.h +10 -0
index 0d9b5b6e2e..744dd64a9e 100644
@@ -73,6 +73,15 @@ enum dscp_flags {
 	TEST_IPSEC_SET_DSCP_1_INNER_0,
 };
 
+#define TEST_IPSEC_FLABEL_VAL 0x1234
+
+enum flabel_flags {
+	TEST_IPSEC_COPY_FLABEL_INNER_0 = 1,
+	TEST_IPSEC_COPY_FLABEL_INNER_1,
+	TEST_IPSEC_SET_FLABEL_0_INNER_1,
+	TEST_IPSEC_SET_FLABEL_1_INNER_0,
+};
+
 struct ipsec_test_flags {
 	bool display_alg;
 	bool sa_expiry_pkts_soft;
@@ -92,6 +101,7 @@ struct ipsec_test_flags {
 	bool antireplay;
 	enum df_flags df;
 	enum dscp_flags dscp;
+	enum flabel_flags flabel;
 	bool dec_ttl_or_hop_limit;
 	bool ah;
 };
app/test/test_security_inline_proto.c +79 -0

97 lines not on this page · raw message

Signature · 1 line
2.25.1
#105 lore raw

v7 cover app/test: add inline IPsec and reassembly cases

In reply to Akhil Goyal

IP reassembly offload was added in last release. The test app for unit testing IP reassembly of inline inbound IPsec flows is added in this patchset.
For testing IP reassembly, base inline IPsec is also added. The app is enhanced in v4 to handle more functional unit test cases for inline IPsec similar to Lookaside IPsec. The functions from Lookaside more are reused to verify functional cases.

Changes in v7:
- fixed compilation

Changes in v6:
- Addressed comments from Anoob.

changes in v5:
- removed soft/hard expiry patches which are deferred for next release
- skipped tests if no port is added.
- added release notes.
Changes in v4:
- rebased over next-crypto
- updated app to take benefit from Lookaside protocol
test functions.
- Added more functional cases
- Added soft and hard expiry event subtypes in ethdev
for testing SA soft and hard pkt/byte expiry events.
- reassembly cases are squashed in a single patch

Changes in v3:
- incorporated latest ethdev changes for reassembly.
- skipped build on windows as it needs rte_ipsec lib which is not compiled on windows.
changes in v2:
- added IPsec burst mode case
- updated as per the latest ethdev changes.

Akhil Goyal (6):
app/test: add unit cases for inline IPsec offload test/security: add inline inbound IPsec cases test/security: add combined mode inline IPsec cases test/security: add inline IPsec reassembly cases test/security: add more inline IPsec functional cases test/security: add ESN and anti-replay cases for inline

Vamsi Attunuru (1):
test/security: add inline IPsec IPv6 flow label cases

 MAINTAINERS                                   |    2 +-
 app/test/meson.build                          |    1 +
 app/test/test_cryptodev_security_ipsec.c      |   35 +-
 app/test/test_cryptodev_security_ipsec.h      |   10 +
 app/test/test_security_inline_proto.c         | 2382 +++++++++++++++++
 app/test/test_security_inline_proto_vectors.h |  704 +++++
 doc/guides/rel_notes/release_22_07.rst        |    5 +
 7 files changed, 3137 insertions(+), 2 deletions(-)
 create mode 100644 app/test/test_security_inline_proto.c
 create mode 100644 app/test/test_security_inline_proto_vectors.h
Signature · 1 line
2.25.1
#106 lore raw

PATCH v7 1/7 app/test: add unit cases for inline IPsec offload

A new test suite is added in test app to test inline IPsec protocol offload. In this patch, predefined vectors from Lookaside IPsec test are used to verify the IPsec functionality without the need of external traffic generators. The sent packet is loopbacked onto the same interface which is received and matched with the expected output. The test suite can be updated further with other functional test cases. In this patch encap only cases are added.
The testsuite can be run using:
RTE> inline_ipsec_autotest

---
 MAINTAINERS                                   |   2 +-
 app/test/meson.build                          |   1 +
 app/test/test_security_inline_proto.c         | 887 ++++++++++++++++++
 app/test/test_security_inline_proto_vectors.h |  20 +
 doc/guides/rel_notes/release_22_07.rst        |   5 +
 5 files changed, 914 insertions(+), 1 deletion(-)
 create mode 100644 app/test/test_security_inline_proto.c
 create mode 100644 app/test/test_security_inline_proto_vectors.h
MAINTAINERS +1 -1
index 17a0559ee7..841279814b 100644
@@ -441,7 +441,7 @@ M: Akhil Goyal <[email protected]>
 T: git://dpdk.org/next/dpdk-next-crypto
 F: lib/security/
 F: doc/guides/prog_guide/rte_security.rst
-F: app/test/test_security.c
+F: app/test/test_security*
 
 Compression API - EXPERIMENTAL
 M: Fan Zhang <[email protected]>
app/test/meson.build +1 -0
index 15591ce5cf..0f712680de 100644
@@ -125,6 +125,7 @@ test_sources = files(
         'test_rwlock.c',
         'test_sched.c',
         'test_security.c',
+        'test_security_inline_proto.c',
         'test_service_cores.c',
         'test_spinlock.c',
         'test_stack.c',
app/test/test_security_inline_proto.c new file +887 -0

887 lines not on this page · raw message

app/test/test_security_inline_proto_vectors.h new file +20 -0
new file mode 100644
index 0000000000..d1074da36a
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2022 Marvell.
+ */
+#ifndef _TEST_INLINE_IPSEC_REASSEMBLY_VECTORS_H_
+#define _TEST_INLINE_IPSEC_REASSEMBLY_VECTORS_H_
+
+#include "test_cryptodev_security_ipsec.h"
+
+uint8_t dummy_ipv4_eth_hdr[] = {
+		/* ETH */
+		0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1,
+		0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0x08, 0x00,
+};
+uint8_t dummy_ipv6_eth_hdr[] = {
+		/* ETH */
+		0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1,
+		0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0xf2, 0x86, 0xdd,
+};
+
+#endif
doc/guides/rel_notes/release_22_07.rst +5 -0
index e49cacecef..46d60f7369 100644
@@ -104,6 +104,11 @@ New Features
   * ``RTE_EVENT_QUEUE_ATTR_WEIGHT``
   * ``RTE_EVENT_QUEUE_ATTR_AFFINITY``
 
+* **Added security inline protocol (IPsec) tests in dpdk-test.**
+
+  Added various functional test cases in dpdk-test to verify
+  inline IPsec protocol offload using loopback interface.
+
 
 Removed Items
 -------------
Signature · 1 line
2.25.1
#107 lore raw

PATCH v7 2/7 test/security: add inline inbound IPsec cases

In reply to Akhil Goyal

Added test cases for inline Inbound protocol offload verification with known test vectors from Lookaside mode.

---
 app/test/test_security_inline_proto.c | 65 +++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)
app/test/test_security_inline_proto.c +65 -0
index 4b960ddfe0..4a95b25a0b 100644
@@ -824,6 +824,24 @@ test_ipsec_inline_proto_known_vec(const void *test_data)
 				false, &flags);
 }
 
+static int
+test_ipsec_inline_proto_known_vec_inb(const void *test_data)
+{
+	const struct ipsec_test_data *td = test_data;
+	struct ipsec_test_flags flags;
+	struct ipsec_test_data td_inb;
+
+	memset(&flags, 0, sizeof(flags));
+
+	if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS)
+		test_ipsec_td_in_from_out(td, &td_inb);
+	else
+		memcpy(&td_inb, td, sizeof(td_inb));
+
+	return test_ipsec_inline_proto_process(&td_inb, NULL, 1, false, &flags);
+}
+
+
 static struct unit_test_suite inline_ipsec_testsuite  = {
 	.suite_name = "Inline IPsec Ethernet Device Unit Test Suite",
 	.setup = inline_ipsec_testsuite_setup,
@@ -870,6 +888,53 @@ static struct unit_test_suite inline_ipsec_testsuite  = {
 			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
 			test_ipsec_inline_proto_known_vec,
 			&pkt_null_aes_xcbc),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 128)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_inb, &pkt_aes_128_gcm),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 192)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_inb, &pkt_aes_192_gcm),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 256)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_inb, &pkt_aes_256_gcm),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_inb, &pkt_aes_128_cbc_null),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA256 [16B ICV])",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_inb,
+			&pkt_aes_128_cbc_hmac_sha256),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA384 [24B ICV])",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_inb,
+			&pkt_aes_128_cbc_hmac_sha384),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA512 [32B ICV])",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_inb,
+			&pkt_aes_128_cbc_hmac_sha512),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Inbound known vector (ESP tunnel mode IPv6 AES-GCM 128)",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_inb, &pkt_aes_256_gcm_v6),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Inbound known vector (ESP tunnel mode IPv6 AES-CBC 128 HMAC-SHA256 [16B ICV])",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_inb,
+			&pkt_aes_128_cbc_hmac_sha256_v6),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Inbound known vector (ESP tunnel mode IPv4 NULL AES-XCBC-MAC [12B ICV])",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_known_vec_inb,
+			&pkt_null_aes_xcbc),
+
+
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	},
Signature · 1 line
2.25.1
#108 lore raw

PATCH v7 3/7 test/security: add combined mode inline IPsec cases

In reply to Akhil Goyal

Added combined encap and decap test cases for various algorithm combinations

---
 app/test/test_security_inline_proto.c | 102 ++++++++++++++++++++++++++
 1 file changed, 102 insertions(+)
app/test/test_security_inline_proto.c +102 -0
index 4a95b25a0b..a44a4f9b04 100644
@@ -665,6 +665,92 @@ test_ipsec_inline_proto_process(struct ipsec_test_data *td,
 	return ret;
 }
 
+static int
+test_ipsec_inline_proto_all(const struct ipsec_test_flags *flags)
+{
+	struct ipsec_test_data td_outb;
+	struct ipsec_test_data td_inb;
+	unsigned int i, nb_pkts = 1, pass_cnt = 0, fail_cnt = 0;
+	int ret;
+
+	if (flags->iv_gen || flags->sa_expiry_pkts_soft ||
+			flags->sa_expiry_pkts_hard)
+		nb_pkts = IPSEC_TEST_PACKETS_MAX;
+
+	for (i = 0; i < RTE_DIM(alg_list); i++) {
+		test_ipsec_td_prepare(alg_list[i].param1,
+				      alg_list[i].param2,
+				      flags, &td_outb, 1);
+
+		if (!td_outb.aead) {
+			enum rte_crypto_cipher_algorithm cipher_alg;
+			enum rte_crypto_auth_algorithm auth_alg;
+
+			cipher_alg = td_outb.xform.chain.cipher.cipher.algo;
+			auth_alg = td_outb.xform.chain.auth.auth.algo;
+
+			if (td_outb.aes_gmac && cipher_alg != RTE_CRYPTO_CIPHER_NULL)
+				continue;
+
+			/* ICV is not applicable for NULL auth */
+			if (flags->icv_corrupt &&
+			    auth_alg == RTE_CRYPTO_AUTH_NULL)
+				continue;
+
+			/* IV is not applicable for NULL cipher */
+			if (flags->iv_gen &&
+			    cipher_alg == RTE_CRYPTO_CIPHER_NULL)
+				continue;
+		}
+
+		if (flags->udp_encap)
+			td_outb.ipsec_xform.options.udp_encap = 1;
+
+		ret = test_ipsec_inline_proto_process(&td_outb, &td_inb, nb_pkts,
+						false, flags);
+		if (ret == TEST_SKIPPED)
+			continue;
+
+		if (ret == TEST_FAILED) {
+			printf("\n TEST FAILED");
+			test_ipsec_display_alg(alg_list[i].param1,
+					       alg_list[i].param2);
+			fail_cnt++;
+			continue;
+		}
+
+		test_ipsec_td_update(&td_inb, &td_outb, 1, flags);
+
+		ret = test_ipsec_inline_proto_process(&td_inb, NULL, nb_pkts,
+						false, flags);
+		if (ret == TEST_SKIPPED)
+			continue;
+
+		if (ret == TEST_FAILED) {
+			printf("\n TEST FAILED");
+			test_ipsec_display_alg(alg_list[i].param1,
+					       alg_list[i].param2);
+			fail_cnt++;
+			continue;
+		}
+
+		if (flags->display_alg)
+			test_ipsec_display_alg(alg_list[i].param1,
+					       alg_list[i].param2);
+
+		pass_cnt++;
+	}
+
+	printf("Tests passed: %d, failed: %d", pass_cnt, fail_cnt);
+	if (fail_cnt > 0)
+		return TEST_FAILED;
+	if (pass_cnt > 0)
+		return TEST_SUCCESS;
+	else
+		return TEST_SKIPPED;
+}
+
+
 static int
 ut_setup_inline_ipsec(void)
 {
@@ -841,6 +927,17 @@ test_ipsec_inline_proto_known_vec_inb(const void *test_data)
 	return test_ipsec_inline_proto_process(&td_inb, NULL, 1, false, &flags);
 }
 
+static int
+test_ipsec_inline_proto_display_list(const void *data __rte_unused)
+{
+	struct ipsec_test_flags flags;
+
+	memset(&flags, 0, sizeof(flags));
+
+	flags.display_alg = true;
+
+	return test_ipsec_inline_proto_all(&flags);
+}
 
 static struct unit_test_suite inline_ipsec_testsuite  = {
 	.suite_name = "Inline IPsec Ethernet Device Unit Test Suite",
@@ -934,6 +1031,11 @@ static struct unit_test_suite inline_ipsec_testsuite  = {
 			test_ipsec_inline_proto_known_vec_inb,
 			&pkt_null_aes_xcbc),
 
+		TEST_CASE_NAMED_ST(
+			"Combined test alg list",
+			ut_setup_inline_ipsec, ut_teardown_inline_ipsec,
+			test_ipsec_inline_proto_display_list),
+
 
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
Signature · 1 line
2.25.1