[v2,1/2] ethdev: introduce NAT64 action

Message ID 20240131093804.357465-2-bingz@nvidia.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series support NAT64 action |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Bing Zhao Jan. 31, 2024, 9:38 a.m. UTC
  In order to support the communication between IPv4 and IPv6 nodes in
the network, different technologies are used, like dual-stacks,
tunneling and NAT64. In some IPv4-only clients, it is hard to deploy
new software and(or) hardware to support IPv6 protocol.

NAT64 is a choice and it will also reduce the unnecessary overhead of
the traffic in the network. The NAT64 gateways take the
responsibility of the packet headers translation between the IPv6
clouds and IPv4-only clouds.

The commit introduce the NAT64 flow action to offload the software
involvement to the hardware.

This action should support the offloading of the IP headers'
translation. The following fields should be reset correctly in the
translation.
  - Version
  - Traffic Class / TOS
  - Flow Label (0 in v4)
  - Payload Length / Total length
  - Next Header
  - Hop Limit / TTL

The PMD needs to support the basic conversion of the fields above,
and the well-known prefix will be used when translating IPv4 address
to IPv6 address. Another modify fields can be used after the NAT64 to
support other modes with different prefix and offset.

The ICMP* and transport layers protocol is out of the scope of NAT64
rte_flow action.

Reference links:
  - https://datatracker.ietf.org/doc/html/rfc6146
  - https://datatracker.ietf.org/doc/html/rfc6052
  - https://datatracker.ietf.org/doc/html/rfc6145

Signed-off-by: Bing Zhao <bingz@nvidia.com>
---
 doc/guides/nics/features/default.ini |  1 +
 doc/guides/prog_guide/rte_flow.rst   |  8 ++++++++
 lib/ethdev/rte_flow.c                |  1 +
 lib/ethdev/rte_flow.h                | 27 +++++++++++++++++++++++++++
 4 files changed, 37 insertions(+)
  

Comments

Ori Kam Feb. 1, 2024, 8:38 a.m. UTC | #1
Hi Bing

> -----Original Message-----
> From: Bing Zhao <bingz@nvidia.com>
> Sent: Wednesday, January 31, 2024 11:38 AM
> 
> In order to support the communication between IPv4 and IPv6 nodes in
> the network, different technologies are used, like dual-stacks,
> tunneling and NAT64. In some IPv4-only clients, it is hard to deploy
> new software and(or) hardware to support IPv6 protocol.
> 
> NAT64 is a choice and it will also reduce the unnecessary overhead of
> the traffic in the network. The NAT64 gateways take the
> responsibility of the packet headers translation between the IPv6
> clouds and IPv4-only clouds.
> 
> The commit introduce the NAT64 flow action to offload the software
> involvement to the hardware.
> 
> This action should support the offloading of the IP headers'
> translation. The following fields should be reset correctly in the
> translation.
>   - Version
>   - Traffic Class / TOS
>   - Flow Label (0 in v4)
>   - Payload Length / Total length
>   - Next Header
>   - Hop Limit / TTL
> 
> The PMD needs to support the basic conversion of the fields above,
> and the well-known prefix will be used when translating IPv4 address
> to IPv6 address. Another modify fields can be used after the NAT64 to
> support other modes with different prefix and offset.
> 
> The ICMP* and transport layers protocol is out of the scope of NAT64
> rte_flow action.
> 
> Reference links:
>   - https://datatracker.ietf.org/doc/html/rfc6146
>   - https://datatracker.ietf.org/doc/html/rfc6052
>   - https://datatracker.ietf.org/doc/html/rfc6145
> 
> Signed-off-by: Bing Zhao <bingz@nvidia.com>
> ---

Acked-by: Ori Kam <orika@nvidia.com>
Best,
Ori
  

Patch

diff --git a/doc/guides/nics/features/default.ini b/doc/guides/nics/features/default.ini
index 6d50236292..4db7e41193 100644
--- a/doc/guides/nics/features/default.ini
+++ b/doc/guides/nics/features/default.ini
@@ -171,6 +171,7 @@  mark                 =
 meter                =
 meter_mark           =
 modify_field         =
+nat64                =
 nvgre_decap          =
 nvgre_encap          =
 of_copy_ttl_in       =
diff --git a/doc/guides/prog_guide/rte_flow.rst b/doc/guides/prog_guide/rte_flow.rst
index 900fdaefb6..7af329bd93 100644
--- a/doc/guides/prog_guide/rte_flow.rst
+++ b/doc/guides/prog_guide/rte_flow.rst
@@ -3520,6 +3520,14 @@  The packets will be received by the kernel driver sharing the same device
 as the DPDK port on which this action is configured.
 
 
+Action: ``NAT64``
+^^^^^^^^^^^^^^^^^
+
+This action does the header translation between IPv4 and IPv6. Besides
+converting the IP addresses, other fields in the IP header are handled as
+well. The ``type`` field should be provided as defined in the
+``rte_flow_action_nat64`` when creating the action.
+
 Negative types
 ~~~~~~~~~~~~~~
 
diff --git a/lib/ethdev/rte_flow.c b/lib/ethdev/rte_flow.c
index 3f58d792f9..156545454c 100644
--- a/lib/ethdev/rte_flow.c
+++ b/lib/ethdev/rte_flow.c
@@ -271,6 +271,7 @@  static const struct rte_flow_desc_data rte_flow_desc_action[] = {
 		       sizeof(struct rte_flow_action_indirect_list)),
 	MK_FLOW_ACTION(PROG,
 		       sizeof(struct rte_flow_action_prog)),
+	MK_FLOW_ACTION(NAT64, sizeof(struct rte_flow_action_nat64)),
 };
 
 int
diff --git a/lib/ethdev/rte_flow.h b/lib/ethdev/rte_flow.h
index 1267c146e5..1dded812ec 100644
--- a/lib/ethdev/rte_flow.h
+++ b/lib/ethdev/rte_flow.h
@@ -3051,6 +3051,13 @@  enum rte_flow_action_type {
 	 * @see struct rte_flow_action_prog.
 	 */
 	RTE_FLOW_ACTION_TYPE_PROG,
+
+	/**
+	 * Support the NAT64 translation.
+	 *
+	 * @see struct rte_flow_action_nat64
+	 */
+	RTE_FLOW_ACTION_TYPE_NAT64,
 };
 
 /**
@@ -4180,6 +4187,26 @@  rte_flow_dynf_metadata_set(struct rte_mbuf *m, uint32_t v)
 	*RTE_FLOW_DYNF_METADATA(m) = v;
 }
 
+/**
+ * NAT64 translation type for IP headers.
+ */
+enum rte_flow_nat64_type {
+	RTE_FLOW_NAT64_6TO4 = 0, /**< IPv6 to IPv4 headers translation. */
+	RTE_FLOW_NAT64_4TO6 = 1, /**< IPv4 to IPv6 headers translation. */
+};
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this structure may change without prior notice
+ *
+ * RTE_FLOW_ACTION_TYPE_NAT64
+ *
+ * Specify the NAT64 translation type.
+ */
+struct rte_flow_action_nat64 {
+	enum rte_flow_nat64_type type;
+};
+
 /**
  * Definition of a single action.
  *