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

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

Checks

Context Check Description
ci/loongarch-compilation success Compilation OK
ci/checkpatch success coding style OK
ci/loongarch-unit-testing fail Unit Testing FAIL
ci/Intel-compilation fail Compilation issues
ci/github-robot: build fail github build: failed

Commit Message

Gregory Etelson June 18, 2024, 9:51 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.
v3:
Define both traffic_class and DS + ECN fields.
---
 lib/net/rte_ip.h | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)
  

Comments

Morten Brørup June 18, 2024, 10:47 a.m. UTC | #1
>  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 played around with this in Godbolt, and __attribute__((__packed__)) only packs bytes, not bits, so the packed structure grows from 4 to 5 bytes, because the compiler adds 4 bits of padding here, to byte align the union holding "tc".

Please revert to v2.

Sorry about the noise. ;-)

> +			union {
> +				rte_be32_t tc:8;
> +				struct {
> +					rte_be32_t ecn:2; /**< ECN */
> +					rte_be32_t ds:6;  /**< differentiated
> services */
> +				};
> +			};
  

Patch

diff --git a/lib/net/rte_ip.h b/lib/net/rte_ip.h
index 0d103d4127..3adfcbc431 100644
--- a/lib/net/rte_ip.h
+++ b/lib/net/rte_ip.h
@@ -524,7 +524,33 @@  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 */
+			union {
+				rte_be32_t tc:8;
+				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 */
+			union {
+				rte_be32_t tc:8;
+				struct {
+					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. */