[v2] net: add bit fields to IPv6 header definition

Message ID 20240618075810.265960-1-getelson@nvidia.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series [v2] net: add bit fields to IPv6 header definition |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/github-robot: build success github build: passed
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS

Commit Message

Gregory Etelson June 18, 2024, 7:58 a.m. UTC
DPDK IPv6 header definition combined the `version`, `traffic class`
and `flow label` header fields into a single 32 bits structure member
`vtc_flow`.

The patch expands IPv6 header definition with dedicated structure
members for the `version`, `traffic class` and `flow label` fields.
The `traffic class` is also separated into DS and ECN fields.

The patch also preserves existing `vtc_flow` structure member for
backward compatibility.

Signed-off-by: Gregory Etelson <getelson@nvidia.com>
---
v2: 
Replace uint32_t with rte_be32_t.
Split traffic_class into DS and ECN bits.
---
 lib/net/rte_ip.h | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

--
2.43.0
  

Comments

Morten Brørup June 18, 2024, 8:11 a.m. UTC | #1
> From: Gregory Etelson [mailto:getelson@nvidia.com]
> Sent: Tuesday, 18 June 2024 09.58
> 
> DPDK IPv6 header definition combined the `version`, `traffic class`
> and `flow label` header fields into a single 32 bits structure member
> `vtc_flow`.
> 
> The patch expands IPv6 header definition with dedicated structure
> members for the `version`, `traffic class` and `flow label` fields.
> The `traffic class` is also separated into DS and ECN fields.
> 
> The patch also preserves existing `vtc_flow` structure member for
> backward compatibility.
> 
> Signed-off-by: Gregory Etelson <getelson@nvidia.com>
> ---
> v2:
> Replace uint32_t with rte_be32_t.
> Split traffic_class into DS and ECN bits.
> ---
>  lib/net/rte_ip.h | 18 +++++++++++++++++-
>  1 file changed, 17 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/net/rte_ip.h b/lib/net/rte_ip.h
> index 0d103d4127..fe1d596054 100644
> --- a/lib/net/rte_ip.h
> +++ b/lib/net/rte_ip.h
> @@ -524,7 +524,23 @@ rte_ipv4_udptcp_cksum_mbuf_verify(const struct rte_mbuf
> *m,
>   * IPv6 Header
>   */
>  struct rte_ipv6_hdr {
> -	rte_be32_t vtc_flow;	/**< IP version, traffic class & flow label.
> */
> +	union {
> +		rte_be32_t vtc_flow;        /**< IP version, traffic class & flow
> label. */
> +		__extension__
> +		struct {
> +#if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
> +			rte_be32_t flow_label:20; /**< flow label */

I don't know if sub-unions of bitfields are possible and/or require special magic for packing the bits.
If possible, expanding the 8 bit "tc" field like this would be nice:

+ union {
+ 	rte_be32_t tc:8;
+ 	__extension__
+ 	struct {

> +			rte_be32_t ecn:2; /**< ECN */
> +			rte_be32_t ds:6;     /**< differentiated services */

+ 	};
+ };

> +			rte_be32_t version:4; /**< version */
> +#elif RTE_BYTE_ORDER == RTE_BIG_ENDIAN
> +			rte_be32_t version:4; /**< version */
> +			rte_be32_t ds:6;     /**< differentiated services */
> +			rte_be32_t ecn:2; /**< ECN */
> +			rte_be32_t flow_label:20; /**< flow label */
> +#endif
> +		};
> +	};
>  	rte_be16_t payload_len;	/**< IP payload size, including ext. headers
> */
>  	uint8_t  proto;		/**< Protocol, next header. */
>  	uint8_t  hop_limits;	/**< Hop limits. */
> --
> 2.43.0

Without the suggested addition,
Reviewed-by: Morten Brørup <mb@smartsharesystems.com>

With the suggested addition,
Acked-by: Morten Brørup <mb@smartsharesystems.com>
  

Patch

diff --git a/lib/net/rte_ip.h b/lib/net/rte_ip.h
index 0d103d4127..fe1d596054 100644
--- a/lib/net/rte_ip.h
+++ b/lib/net/rte_ip.h
@@ -524,7 +524,23 @@  rte_ipv4_udptcp_cksum_mbuf_verify(const struct rte_mbuf *m,
  * IPv6 Header
  */
 struct rte_ipv6_hdr {
-	rte_be32_t vtc_flow;	/**< IP version, traffic class & flow label. */
+	union {
+		rte_be32_t vtc_flow;        /**< IP version, traffic class & flow label. */
+		__extension__
+		struct {
+#if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
+			rte_be32_t flow_label:20; /**< flow label */
+			rte_be32_t ecn:2; /**< ECN */
+			rte_be32_t ds:6;     /**< differentiated services */
+			rte_be32_t version:4; /**< version */
+#elif RTE_BYTE_ORDER == RTE_BIG_ENDIAN
+			rte_be32_t version:4; /**< version */
+			rte_be32_t ds:6;     /**< differentiated services */
+			rte_be32_t ecn:2; /**< ECN */
+			rte_be32_t flow_label:20; /**< flow label */
+#endif
+		};
+	};
 	rte_be16_t payload_len;	/**< IP payload size, including ext. headers */
 	uint8_t  proto;		/**< Protocol, next header. */
 	uint8_t  hop_limits;	/**< Hop limits. */