DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH v2] librte_lpm: define tbl entry reversely for big endian
@ 2015-03-24  5:58 xuelin.shi
  2015-05-19 10:05 ` Bruce Richardson
  0 siblings, 1 reply; 3+ messages in thread
From: xuelin.shi @ 2015-03-24  5:58 UTC (permalink / raw)
  To: bruce.richardson; +Cc: dev, Xuelin Shi

From: Xuelin Shi <xuelin.shi@freescale.com>

This module uses type conversion between struct and int.
Also truncation and comparison is used with this int.
It is not safe for different endian arch.

Add ifdef for big endian struct to fix this issue.

Signed-off-by: Xuelin Shi <xuelin.shi@freescale.com>
---
changes for v2:
  add <rte_byteorder.h>

 lib/librte_lpm/rte_lpm.h | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/lib/librte_lpm/rte_lpm.h b/lib/librte_lpm/rte_lpm.h
index 1af150c..6cbcd4c 100644
--- a/lib/librte_lpm/rte_lpm.h
+++ b/lib/librte_lpm/rte_lpm.h
@@ -44,6 +44,7 @@
 #include <stdint.h>
 #include <stdlib.h>
 #include <rte_branch_prediction.h>
+#include <rte_byteorder.h>
 #include <rte_memory.h>
 #include <rte_common.h>
 #include <rte_common_vect.h>
@@ -96,6 +97,7 @@ extern "C" {
 /** Bitmask used to indicate successful lookup */
 #define RTE_LPM_LOOKUP_SUCCESS          0x0100
 
+#if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
 /** @internal Tbl24 entry structure. */
 struct rte_lpm_tbl24_entry {
 	/* Stores Next hop or group index (i.e. gindex)into tbl8. */
@@ -117,6 +119,24 @@ struct rte_lpm_tbl8_entry {
 	uint8_t valid_group :1; /**< Group validation flag. */
 	uint8_t depth       :6; /**< Rule depth. */
 };
+#else
+struct rte_lpm_tbl24_entry {
+	uint8_t depth 	    :6;
+	uint8_t ext_entry   :1;
+	uint8_t valid	    :1;
+	union {
+		uint8_t tbl8_gindex;
+		uint8_t next_hop;
+	};
+};
+
+struct rte_lpm_tbl8_entry {
+	uint8_t depth 	    :6;
+	uint8_t valid_group :1;
+	uint8_t valid	    :1;
+	uint8_t next_hop;
+};
+#endif
 
 /** @internal Rule structure. */
 struct rte_lpm_rule {
-- 
1.9.1

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [dpdk-dev] [PATCH v2] librte_lpm: define tbl entry reversely for big endian
  2015-03-24  5:58 [dpdk-dev] [PATCH v2] librte_lpm: define tbl entry reversely for big endian xuelin.shi
@ 2015-05-19 10:05 ` Bruce Richardson
  2015-07-10 21:23   ` Thomas Monjalon
  0 siblings, 1 reply; 3+ messages in thread
From: Bruce Richardson @ 2015-05-19 10:05 UTC (permalink / raw)
  To: xuelin.shi; +Cc: dev

On Tue, Mar 24, 2015 at 01:58:20PM +0800, xuelin.shi@freescale.com wrote:
> From: Xuelin Shi <xuelin.shi@freescale.com>
> 
> This module uses type conversion between struct and int.
> Also truncation and comparison is used with this int.
> It is not safe for different endian arch.
> 
> Add ifdef for big endian struct to fix this issue.
> 
> Signed-off-by: Xuelin Shi <xuelin.shi@freescale.com>

Since nobody objects to this patch, and it looks ok to me:

Acked-by: Bruce Richardson <bruce.richardson@intel.com>

> ---
> changes for v2:
>   add <rte_byteorder.h>
> 
>  lib/librte_lpm/rte_lpm.h | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/lib/librte_lpm/rte_lpm.h b/lib/librte_lpm/rte_lpm.h
> index 1af150c..6cbcd4c 100644
> --- a/lib/librte_lpm/rte_lpm.h
> +++ b/lib/librte_lpm/rte_lpm.h
> @@ -44,6 +44,7 @@
>  #include <stdint.h>
>  #include <stdlib.h>
>  #include <rte_branch_prediction.h>
> +#include <rte_byteorder.h>
>  #include <rte_memory.h>
>  #include <rte_common.h>
>  #include <rte_common_vect.h>
> @@ -96,6 +97,7 @@ extern "C" {
>  /** Bitmask used to indicate successful lookup */
>  #define RTE_LPM_LOOKUP_SUCCESS          0x0100
>  
> +#if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
>  /** @internal Tbl24 entry structure. */
>  struct rte_lpm_tbl24_entry {
>  	/* Stores Next hop or group index (i.e. gindex)into tbl8. */
> @@ -117,6 +119,24 @@ struct rte_lpm_tbl8_entry {
>  	uint8_t valid_group :1; /**< Group validation flag. */
>  	uint8_t depth       :6; /**< Rule depth. */
>  };
> +#else
> +struct rte_lpm_tbl24_entry {
> +	uint8_t depth 	    :6;
> +	uint8_t ext_entry   :1;
> +	uint8_t valid	    :1;
> +	union {
> +		uint8_t tbl8_gindex;
> +		uint8_t next_hop;
> +	};
> +};
> +
> +struct rte_lpm_tbl8_entry {
> +	uint8_t depth 	    :6;
> +	uint8_t valid_group :1;
> +	uint8_t valid	    :1;
> +	uint8_t next_hop;
> +};
> +#endif
>  
>  /** @internal Rule structure. */
>  struct rte_lpm_rule {
> -- 
> 1.9.1
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [dpdk-dev] [PATCH v2] librte_lpm: define tbl entry reversely for big endian
  2015-05-19 10:05 ` Bruce Richardson
@ 2015-07-10 21:23   ` Thomas Monjalon
  0 siblings, 0 replies; 3+ messages in thread
From: Thomas Monjalon @ 2015-07-10 21:23 UTC (permalink / raw)
  To: xuelin.shi; +Cc: dev

2015-05-19 11:05, Bruce Richardson:
> On Tue, Mar 24, 2015 at 01:58:20PM +0800, xuelin.shi@freescale.com wrote:
> > From: Xuelin Shi <xuelin.shi@freescale.com>
> > 
> > This module uses type conversion between struct and int.
> > Also truncation and comparison is used with this int.
> > It is not safe for different endian arch.
> > 
> > Add ifdef for big endian struct to fix this issue.
> > 
> > Signed-off-by: Xuelin Shi <xuelin.shi@freescale.com>
> 
> Since nobody objects to this patch, and it looks ok to me:
> 
> Acked-by: Bruce Richardson <bruce.richardson@intel.com>

Applied, thanks

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-07-10 21:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-24  5:58 [dpdk-dev] [PATCH v2] librte_lpm: define tbl entry reversely for big endian xuelin.shi
2015-05-19 10:05 ` Bruce Richardson
2015-07-10 21:23   ` Thomas Monjalon

DPDK patches and discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.dpdk.org/dev/0 dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dev dev/ https://inbox.dpdk.org/dev \
		dev@dpdk.org
	public-inbox-index dev

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git