net: add bit fields to IPv6 header definition

Message ID 20240618051751.220610-1-getelson@nvidia.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series 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/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/github-robot: build success github build: passed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional 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, 5:17 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 patch also preserves existing `vtc_flow` structure member for
backward compatibility.

Signed-off-by: Gregory Etelson <getelson@nvidia.com>
---
 lib/net/rte_ip.h | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
  

Comments

Morten Brørup June 18, 2024, 6:42 a.m. UTC | #1
> From: Gregory Etelson [mailto:getelson@nvidia.com]
> Sent: Tuesday, 18 June 2024 07.18
> 
> 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 patch also preserves existing `vtc_flow` structure member for
> backward compatibility.

Good addition.
I had been wondering why we didn't have this already. :-)

> 
> Signed-off-by: Gregory Etelson <getelson@nvidia.com>
> ---
>  lib/net/rte_ip.h | 16 +++++++++++++++-
>  1 file changed, 15 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/net/rte_ip.h b/lib/net/rte_ip.h
> index 0d103d4127..26e78a6624 100644
> --- a/lib/net/rte_ip.h
> +++ b/lib/net/rte_ip.h
> @@ -524,7 +524,21 @@ 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.
> */
> +	__extension__
> +	union {
> +		rte_be32_t vtc_flow;        /**< IP version, traffic class & flow
> label. */

The mbuf structure [1] has __extension__ here,
i.e. preceding the structure following the integer field,
instead of preceding the union.

[1]: https://git.dpdk.org/dpdk/tree/lib/mbuf/rte_mbuf_core.h#n520

> +		struct {
> +#if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
> +			uint32_t flow_label:24; /**< flow label */

Flow Label is 20 bits, not 24.

> +			uint32_t tc:4;     /**< traffic class */

TC is 8 bits, not 4.

> +			uint32_t version:4; /**< version */
> +#elif RTE_BYTE_ORDER == RTE_BIG_ENDIAN
> +			uint8_t version:4; /**< version */
> +			uint8_t tc:4;     /**< traffic class */

:8, not :4.

> +			uint32_t flow_label:24; /**< flow label */

:20, not :24.

> +#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
  
Morten Brørup June 18, 2024, 7:02 a.m. UTC | #2
> From: Morten Brørup [mailto:mb@smartsharesystems.com]
> 
> > From: Gregory Etelson [mailto:getelson@nvidia.com]
> > Sent: Tuesday, 18 June 2024 07.18
> >
> > 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 patch also preserves existing `vtc_flow` structure member for
> > backward compatibility.
> 
> Good addition.
> I had been wondering why we didn't have this already. :-)
> 
> >
> > Signed-off-by: Gregory Etelson <getelson@nvidia.com>
> > ---
> >  lib/net/rte_ip.h | 16 +++++++++++++++-
> >  1 file changed, 15 insertions(+), 1 deletion(-)
> >
> > diff --git a/lib/net/rte_ip.h b/lib/net/rte_ip.h
> > index 0d103d4127..26e78a6624 100644
> > --- a/lib/net/rte_ip.h
> > +++ b/lib/net/rte_ip.h
> > @@ -524,7 +524,21 @@ 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.
> > */
> > +	__extension__
> > +	union {
> > +		rte_be32_t vtc_flow;        /**< IP version, traffic class & flow
> > label. */
> 
> The mbuf structure [1] has __extension__ here,
> i.e. preceding the structure following the integer field,
> instead of preceding the union.
> 
> [1]: https://git.dpdk.org/dpdk/tree/lib/mbuf/rte_mbuf_core.h#n520
> 
> > +		struct {
> > +#if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
> > +			uint32_t flow_label:24; /**< flow label */
> 
> Flow Label is 20 bits, not 24.

I forgot to mention that the flow_label field should be rte_be32_t instead of uint32_t.

> 
> > +			uint32_t tc:4;     /**< traffic class */
> 
> TC is 8 bits, not 4.

While you are at it, please also expand the "tc" field to another union with dedicated fields for "dscp:6" and "ecn:2", keeping the combined "tc" field too. The same goes for the IPv4 "type_of_service" field. This expansion could go into a separate patch, possibly in the same series.

> 
> > +			uint32_t version:4; /**< version */
> > +#elif RTE_BYTE_ORDER == RTE_BIG_ENDIAN
> > +			uint8_t version:4; /**< version */
> > +			uint8_t tc:4;     /**< traffic class */
> 
> :8, not :4.
> 
> > +			uint32_t flow_label:24; /**< flow label */
> 
> :20, not :24.
> 
> > +#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
  
Gregory Etelson June 18, 2024, 8:07 a.m. UTC | #3
Hello,

I've posted v2 patch with fixes.

Regards,
Gregory
  
Tyler Retzlaff June 19, 2024, 12:11 a.m. UTC | #4
On Tue, Jun 18, 2024 at 08:42:53AM +0200, Morten Brørup wrote:
> > From: Gregory Etelson [mailto:getelson@nvidia.com]
> > Sent: Tuesday, 18 June 2024 07.18
> > 
> > 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 patch also preserves existing `vtc_flow` structure member for
> > backward compatibility.
> 
> Good addition.
> I had been wondering why we didn't have this already. :-)
> 
> > 
> > Signed-off-by: Gregory Etelson <getelson@nvidia.com>
> > ---
> >  lib/net/rte_ip.h | 16 +++++++++++++++-
> >  1 file changed, 15 insertions(+), 1 deletion(-)
> > 
> > diff --git a/lib/net/rte_ip.h b/lib/net/rte_ip.h
> > index 0d103d4127..26e78a6624 100644
> > --- a/lib/net/rte_ip.h
> > +++ b/lib/net/rte_ip.h
> > @@ -524,7 +524,21 @@ 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.
> > */
> > +	__extension__
> > +	union {
> > +		rte_be32_t vtc_flow;        /**< IP version, traffic class & flow
> > label. */
> 
> The mbuf structure [1] has __extension__ here,
> i.e. preceding the structure following the integer field,
> instead of preceding the union.
> 
> [1]: https://git.dpdk.org/dpdk/tree/lib/mbuf/rte_mbuf_core.h#n520

+1 anonymous unions are standard C so __extension__ is not necessary, it
is necessary for an anonymous struct.

> 
> > +		struct {
> > +#if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
> > +			uint32_t flow_label:24; /**< flow label */
> 
> Flow Label is 20 bits, not 24.
> 
> > +			uint32_t tc:4;     /**< traffic class */
> 
> TC is 8 bits, not 4.
> 
> > +			uint32_t version:4; /**< version */
> > +#elif RTE_BYTE_ORDER == RTE_BIG_ENDIAN
> > +			uint8_t version:4; /**< version */
> > +			uint8_t tc:4;     /**< traffic class */
> 
> :8, not :4.
> 
> > +			uint32_t flow_label:24; /**< flow label */
> 
> :20, not :24.
> 
> > +#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
>
  
Gregory Etelson June 19, 2024, 4:31 a.m. UTC | #5
Hello,

>> The mbuf structure [1] has __extension__ here,
>> i.e. preceding the structure following the integer field,
>> instead of preceding the union.
>>
>> [1]: https://git.dpdk.org/dpdk/tree/lib/mbuf/rte_mbuf_core.h#n520
>
> +1 anonymous unions are standard C so __extension__ is not necessary, it
> is necessary for an anonymous struct.
>

That was fixed in the v4: 
https://mails.dpdk.org/archives/dev/2024-June/295803.html

Regards,
Gregory
  

Patch

diff --git a/lib/net/rte_ip.h b/lib/net/rte_ip.h
index 0d103d4127..26e78a6624 100644
--- a/lib/net/rte_ip.h
+++ b/lib/net/rte_ip.h
@@ -524,7 +524,21 @@  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. */
+	__extension__
+	union {
+		rte_be32_t vtc_flow;        /**< IP version, traffic class & flow label. */
+		struct {
+#if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
+			uint32_t flow_label:24; /**< flow label */
+			uint32_t tc:4;     /**< traffic class */
+			uint32_t version:4; /**< version */
+#elif RTE_BYTE_ORDER == RTE_BIG_ENDIAN
+			uint8_t version:4; /**< version */
+			uint8_t tc:4;     /**< traffic class */
+			uint32_t flow_label:24; /**< 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. */