On Wed, Mar 04, 2015 at 02:34:12PM +0800, xuelin.shi at freescale.com wrote: > From: Xuelin Shi <xuelin.shi at 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 at freescale.com> > --- > lib/librte_lpm/rte_lpm.h | 19 +++++++++++++++++++ > 1 file changed, 19 insertions(+) > > diff --git a/lib/librte_lpm/rte_lpm.h b/lib/librte_lpm/rte_lpm.h > index 1af150c..08a2859 100644 > --- a/lib/librte_lpm/rte_lpm.h > +++ b/lib/librte_lpm/rte_lpm.h > @@ -96,6 +96,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 +118,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 >
Get an error compiling this up (using clang on FreeBSD). CC rte_lpm.o In file included from /usr/home/bruce/dpdk.org/lib/librte_lpm/rte_lpm.c:57: /usr/home/bruce/dpdk.org/lib/librte_lpm/rte_lpm.h:99:5: fatal error: 'RTE_BYTE_ORDER' is not defined, evaluates to 0 [-Wundef] #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN ^ 1 error generated. Adding "#include <rte_byteorder.h>" should fix the issue. Existing unit tests on IA (little endian) pass fine there-after, but I think for this patch it would be good to have an ack from someone who can validate on a big endian system, since this is what this patch is meant to enable. /Bruce