[dpdk-dev] [RFC] net: make eCPRI header host network order

Wang, Haiyue haiyue.wang at intel.com
Sat Nov 28 06:31:18 CET 2020


Hi Bing,

> -----Original Message-----
> From: Bing Zhao <bingz at nvidia.com>
> Sent: Saturday, November 28, 2020 11:18
> To: Yigit, Ferruh <ferruh.yigit at intel.com>; Olivier Matz <olivier.matz at 6wind.com>
> Cc: dev at dpdk.org; Wang, Haiyue <haiyue.wang at intel.com>; Stephen Hemminger <stephen at networkplumber.org>
> Subject: RE: [RFC] net: make eCPRI header host network order
> 
> Hi Ferruh & Haiyue,
> Have you checked other headers? Like:
> rte_ipv4_hdr
> rte_ipv6_hdr
> rte_tcp_hdr
> ...
> 
> Also
> 	[ITEM_UDP_SRC] = {
> 		.name = "src",
> 		.help = "UDP source port",
> 		.next = NEXT(item_udp, NEXT_ENTRY(UNSIGNED), item_param),
> 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_udp,
> 					     hdr.src_port)),
> 	},
> 	[ITEM_UDP_DST] = {
> 		.name = "dst",
> 		.help = "UDP destination port",
> 		.next = NEXT(item_udp, NEXT_ENTRY(UNSIGNED), item_param),
> 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_udp,
> 					     hdr.dst_port)),
> 	},
> 
> Or did I get sth. wrong?
> 

The original design is not wrong. ;-)

Since it is defined in librte_net, people will think it is just union
for network order quick access like 'struct rte_gre_hdr', but in fact
the bit field here is something like auxiliary data structure, we have
to translate the whole 4 byte from network order to host order for
accessing one bit field member, otherwise it will be wrong.

Like:

	struct rte_ecpri_common_hdr *eh;
	uint8_t pkt[4];

	pkt[0] = 0x10;
	pkt[1] = 0x03;
	pkt[2] = 0x00;
	pkt[3] = 0x18;

	eh = (struct rte_ecpri_common_hdr *)pkt;

	printf("eCPRI: 0x%08x, revision = %u, type = %u size = %u\n",
		eh->u32, eh->revision, eh->type, ntohs(eh->size));

eCPRI: 0x18000310, revision = 1, type = 0 size = 4099

But in fact it should be:

eCPRI: 0x18000310, revision = 1, type = 3 size = 24


After the enhancement (new revision from RFCv1):

struct rte_ecpri_common_hdr {
	union {
		rte_be32_t u32;			/**< 4B common header in BE */
		struct {
#if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
			uint16_t c:1;		/**< Concatenation Indicator */
			uint16_t res:3;		/**< Reserved */
			uint16_t revision:4;	/**< Protocol Revision */
			uint16_t type:8;	/**< Message Type */
#elif RTE_BYTE_ORDER == RTE_BIG_ENDIAN
			uint16_t revision:4;	/**< Protocol Revision */
			uint16_t res:3;		/**< Reserved */
			uint16_t c:1;		/**< Concatenation Indicator */
			uint16_t type:8;	/**< Message Type */
#endif
			rte_be16_t size;	/**< Payload Size */
		};
	};
};


The assignment in flow_dv_validate can also be simple:

			.common = {
				.u32 =
				RTE_BE32(((const struct rte_ecpri_common_hdr) {
					.type = 0xFF,
					}).u32),
			},

New:

struct rte_ecpri_common_hdr common = { .type = 0xff };


BR,
Haiyue

> BR. Bing
> 
> > -----Original Message-----
> > From: Ferruh Yigit <ferruh.yigit at intel.com>
> > Sent: Saturday, November 28, 2020 3:09 AM
> > To: Olivier Matz <olivier.matz at 6wind.com>
> > Cc: Ferruh Yigit <ferruh.yigit at intel.com>; dev at dpdk.org; Haiyue Wang
> > <haiyue.wang at intel.com>; Stephen Hemminger
> > <stephen at networkplumber.org>; Bing Zhao <bingz at nvidia.com>
> > Subject: [RFC] net: make eCPRI header host network order
> >
> > External email: Use caution opening links or attachments
> >
> >
> > Other protocol structs are in the host byte order, having eCPRI in
> > network byte order is insistent and error prone.
> >
> > Making eCPRI protocol header host byte order.
> >
> > Signed-off-by: Haiyue Wang <haiyue.wang at intel.com>
> > Signed-off-by: Ferruh Yigit <ferruh.yigit at intel.com>
> > ---
> > Cc: Stephen Hemminger <stephen at networkplumber.org>
> > Cc: Bing Zhao <bingz at nvidia.com>
> > Cc: Olivier Matz <olivier.matz at 6wind.com>
> > ---
> >  lib/librte_net/rte_ecpri.h | 7 +++----
> >  1 file changed, 3 insertions(+), 4 deletions(-)
> >
> > diff --git a/lib/librte_net/rte_ecpri.h b/lib/librte_net/rte_ecpri.h
> > index 1cbd6d813363..67bf9186ff6f 100644
> > --- a/lib/librte_net/rte_ecpri.h
> > +++ b/lib/librte_net/rte_ecpri.h
> > @@ -60,21 +60,20 @@ extern "C" {
> >  RTE_STD_C11
> >  struct rte_ecpri_common_hdr {
> >         union {
> > -               rte_be32_t u32;                 /**< 4B common
> > header in BE */
> > +               uint32_t u32;                   /**< 4B common
> > header in host byte order */
> >                 struct {
> >  #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
> > -                       uint32_t size:16;       /**< Payload Size */
> > -                       uint32_t type:8;        /**< Message Type */
> >                         uint32_t c:1;           /**< Concatenation
> > Indicator */
> >                         uint32_t res:3;         /**< Reserved */
> >                         uint32_t revision:4;    /**< Protocol
> > Revision */
> > +                       uint32_t type:8;        /**< Message Type */
> >  #elif RTE_BYTE_ORDER == RTE_BIG_ENDIAN
> >                         uint32_t revision:4;    /**< Protocol
> > Revision */
> >                         uint32_t res:3;         /**< Reserved */
> >                         uint32_t c:1;           /**< Concatenation
> > Indicator */
> >                         uint32_t type:8;        /**< Message Type */
> > -                       uint32_t size:16;       /**< Payload Size */
> >  #endif
> > +                       uint32_t size:16;       /**< Payload Size */
> >                 };
> >         };
> >  };
> > --
> > 2.26.2



More information about the dev mailing list