From patchwork Fri Jun 19 18:57:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Chemparathy X-Patchwork-Id: 5640 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id D120BC974; Fri, 19 Jun 2015 20:57:45 +0200 (CEST) Received: from sclab-apps-2.localdomain (sc-fw1.tilera.com [12.218.212.162]) by dpdk.org (Postfix) with ESMTP id A9ED0C8FC for ; Fri, 19 Jun 2015 20:57:29 +0200 (CEST) X-CheckPoint: {55846619-2-A3D4DA0C-C0000002} Received: by sclab-apps-2.localdomain (Postfix, from userid 1318) id 3CDF02204AA; Fri, 19 Jun 2015 11:57:18 -0700 (PDT) From: Cyril Chemparathy To: dev@dpdk.org Date: Fri, 19 Jun 2015 11:57:10 -0700 Message-Id: <1434740232-10954-9-git-send-email-cchemparathy@ezchip.com> X-Mailer: git-send-email 2.1.2 In-Reply-To: <1434740232-10954-1-git-send-email-cchemparathy@ezchip.com> References: <1434740232-10954-1-git-send-email-cchemparathy@ezchip.com> Subject: [dpdk-dev] [PATCH v3 08/10] librte_mbuf: Add rte_pktmbuf_mtod_offset() 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" There are a number of instances in the code where rte_pktmbuf_mtod() is used to get the mbuf data pointer, only to add an offset before casting the result to some other header type. This patch adds a new rte_pktmbuf_mtod_offset() macro to eliminate these awful double cast situations. Signed-off-by: Cyril Chemparathy --- lib/librte_mbuf/rte_mbuf.h | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h index 6efd2b5..396963c 100644 --- a/lib/librte_mbuf/rte_mbuf.h +++ b/lib/librte_mbuf/rte_mbuf.h @@ -54,6 +54,7 @@ */ #include +#include #include #include #include @@ -1080,18 +1081,35 @@ static inline struct rte_mbuf *rte_pktmbuf_lastseg(struct rte_mbuf *m) } /** + * A macro that points to an offset into the data in the mbuf. + * + * The returned pointer is cast to type t. Before using this + * function, the user must ensure that the first segment is large + * enough to accomodate its data. + * + * @param m + * The packet mbuf. + * @param o + * The offset into the mbuf data. + * @param t + * The type to cast the result into. + */ +#define rte_pktmbuf_mtod_offset(m, t, o) \ + ((t)((char *)(m)->buf_addr + (m)->data_off + (o))) + +/** * A macro that points to the start of the data in the mbuf. * * The returned pointer is cast to type t. Before using this - * function, the user must ensure that m_headlen(m) is large enough to - * read its data. + * function, the user must ensure that the first segment is large + * enough to accomodate its data. * * @param m * The packet mbuf. * @param t * The type to cast the result into. */ -#define rte_pktmbuf_mtod(m, t) ((t)((char *)(m)->buf_addr + (m)->data_off)) +#define rte_pktmbuf_mtod(m, t) rte_pktmbuf_mtod_offset(m, t, 0) /** * A macro that returns the length of the packet.