From: Dan Gora Subject: [PATCH 1/4] mbuf: add accessor function for private data area Date: Thu, 7 Jun 2018 20:54:54 -0300 Message-ID: <20180607235454.27832-1-dg@adax.com> Cc: Dan Gora , Olivier Matz To: dev@dpdk.org Return-path: Received: from mail-qt0-f196.google.com (mail-qt0-f196.google.com [209.85.216.196]) by dpdk.org (Postfix) with ESMTP id 9CBD169D4 for ; Fri, 8 Jun 2018 01:55:13 +0200 (CEST) Received: by mail-qt0-f196.google.com with SMTP id l10-v6so6584993qtj.0 for ; Thu, 07 Jun 2018 16:55:13 -0700 (PDT) List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Add an inline accessor function to return the starting address of the private data area in the supplied mbuf. If the user did not allocate space for a private data area in the mbuf's memory pool, then return NULL. This allows applications to easily access the private data area between the struct rte_mbuf and the data buffer in the specified mbuf without creating private macros or accessor functions. Signed-off-by: Dan Gora --- lib/librte_mbuf/rte_mbuf.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h index 8e6b4d292..0c4f8f698 100644 --- a/lib/librte_mbuf/rte_mbuf.h +++ b/lib/librte_mbuf/rte_mbuf.h @@ -728,6 +728,25 @@ rte_mbuf_to_baddr(struct rte_mbuf *md) return buffer_addr; } +/** + * Return the starting address of the private data area embedded in + * the given mbuf. + * + * @param md + * The pointer to the mbuf. + * @return + * The starting address of the private data area or NULL if there + * is no private data area. + */ +static inline void * +rte_mbuf_to_priv(struct rte_mbuf *md) +{ + if (md->priv_size == 0) + return NULL; + + return RTE_PTR_ADD(md, sizeof(struct rte_mbuf)); +} + /** * Returns TRUE if given mbuf is cloned by mbuf indirection, or FALSE * otherwise. -- 2.17.0.582.gccdcbd54c4