From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from na01-by2-obe.outbound.protection.outlook.com (mail-by2on0139.outbound.protection.outlook.com [207.46.100.139]) by dpdk.org (Postfix) with ESMTP id CA4115949 for ; Wed, 11 Feb 2015 08:17:52 +0100 (CET) Received: from BY2PR03CA051.namprd03.prod.outlook.com (10.141.249.24) by BY2PR0301MB0677.namprd03.prod.outlook.com (25.160.63.144) with Microsoft SMTP Server (TLS) id 15.1.75.20; Wed, 11 Feb 2015 07:17:50 +0000 Received: from BN1AFFO11FD025.protection.gbl (2a01:111:f400:7c10::142) by BY2PR03CA051.outlook.office365.com (2a01:111:e400:2c5d::24) with Microsoft SMTP Server (TLS) id 15.1.87.13 via Frontend Transport; Wed, 11 Feb 2015 07:17:49 +0000 Received: from az84smr01.freescale.net (192.88.158.2) by BN1AFFO11FD025.mail.protection.outlook.com (10.58.52.85) with Microsoft SMTP Server (TLS) id 15.1.87.10 via Frontend Transport; Wed, 11 Feb 2015 07:17:49 +0000 Received: from localhost (rock.ap.freescale.net [10.193.20.106]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id t1B7HkkH002534; Wed, 11 Feb 2015 00:17:47 -0700 From: To: Date: Wed, 11 Feb 2015 14:12:59 +0800 Message-ID: <1423635179-24903-1-git-send-email-xuelin.shi@freescale.com> X-Mailer: git-send-email 1.8.4 X-EOPAttributedMessage: 0 Received-SPF: Fail (protection.outlook.com: domain of freescale.com does not designate 192.88.158.2 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.158.2; helo=az84smr01.freescale.net; Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=b29237@freescale.com; freescale.mail.onmicrosoft.com; dkim=none (message not signed) header.d=none; X-Forefront-Antispam-Report: CIP:192.88.158.2; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(339900001)(77156002)(36756003)(2351001)(110136001)(62966003)(104016003)(76506005)(46102003)(19580405001)(48376002)(50986999)(105606002)(229853001)(87936001)(86362001)(57986006)(33646002)(47776003)(50226001)(92566002)(86152002)(106466001)(85426001)(77096005)(19580395003)(50466002)(6806004); DIR:OUT; SFP:1102; SCL:1; SRVR:BY2PR0301MB0677; H:az84smr01.freescale.net; FPR:; SPF:Fail; MLV:sfv; LANG:en; MIME-Version: 1.0 Content-Type: text/plain X-Microsoft-Antispam: UriScan:; X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;SRVR:BY2PR0301MB0677; X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004); SRVR:BY2PR0301MB0677; X-Forefront-PRVS: 0484063412 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:; SRVR:BY2PR0301MB0677; X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Feb 2015 07:17:49.3479 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d; Ip=[192.88.158.2] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR0301MB0677 Cc: dev@dpdk.org Subject: [dpdk-dev] [PATCH] librte_lpm: use field access instead of type conversion. X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Feb 2015 07:17:53 -0000 From: Xuelin Shi struct tbl_entry{ uint8_t next_hop; uint8_t valid :1; uint8_t valid_group :1; uint8_t depth :6 } uint16_t tbl = (uint16_t)tbl_entry; next_hop = (uint8_t)tbl; next_hop cannot get the correct value of the field if the cpu arch is BIG_ENDIAN. change it to field access. Signed-off-by: Xuelin Shi --- lib/librte_lpm/rte_lpm.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/librte_lpm/rte_lpm.h b/lib/librte_lpm/rte_lpm.h index 586300b..1af150c 100644 --- a/lib/librte_lpm/rte_lpm.h +++ b/lib/librte_lpm/rte_lpm.h @@ -273,6 +273,7 @@ rte_lpm_lookup(struct rte_lpm *lpm, uint32_t ip, uint8_t *next_hop) { unsigned tbl24_index = (ip >> 8); uint16_t tbl_entry; + struct rte_lpm_tbl8_entry *entry; /* DEBUG: Check user input arguments. */ RTE_LPM_RETURN_IF_TRUE(((lpm == NULL) || (next_hop == NULL)), -EINVAL); @@ -290,8 +291,10 @@ rte_lpm_lookup(struct rte_lpm *lpm, uint32_t ip, uint8_t *next_hop) tbl_entry = *(const uint16_t *)&lpm->tbl8[tbl8_index]; } - *next_hop = (uint8_t)tbl_entry; - return (tbl_entry & RTE_LPM_LOOKUP_SUCCESS) ? 0 : -ENOENT; + entry = (struct rte_lpm_tbl8_entry *)&tbl_entry; + *next_hop = entry->next_hop; + + return (entry->valid) ? 0 : -ENOENT; } /** -- 1.9.1