src/dpdk/lib/librte_mbuf/rte_mbuf.h
static inline struct rte_mbuf_ext_shared_info *
rte_pktmbuf_ext_shinfo_init_helper(void *buf_addr, uint16_t *buf_len,
	rte_mbuf_extbuf_free_callback_t free_cb, void *fcb_opaque)
{
	struct rte_mbuf_ext_shared_info *shinfo;
	void *buf_end = RTE_PTR_ADD(buf_addr, *buf_len);
	void *addr;

	addr = RTE_PTR_ALIGN_FLOOR(RTE_PTR_SUB(buf_end, sizeof(*shinfo)),
				   sizeof(uintptr_t));
	if (addr <= buf_addr)
		return NULL;

	shinfo = (struct rte_mbuf_ext_shared_info *)addr;
	shinfo->free_cb = free_cb;
	shinfo->fcb_opaque = fcb_opaque;
	rte_mbuf_ext_refcnt_set(shinfo, 1);

	*buf_len = (uint16_t)RTE_PTR_DIFF(shinfo, buf_addr);
	return shinfo;
}
/**
 * Initialize shared data at the end of an external buffer before attaching
 * to a mbuf by ``rte_pktmbuf_attach_extbuf()``. This is not a mandatory
 * initialization but a helper function to simply spare a few bytes at the
 * end of the buffer for shared data. If shared data is allocated
 * separately, this should not be called but application has to properly
 * initialize the shared data according to its need.
 *
 * Free callback and its argument is saved and the refcnt is set to 1.
 *
 * @warning
 * The value of buf_len will be reduced to RTE_PTR_DIFF(shinfo, buf_addr)
 * after this initialization. This shall be used for
 * ``rte_pktmbuf_attach_extbuf()``
 *
 * @param buf_addr
 *   The pointer to the external buffer.
 * @param [in,out] buf_len
 *   The pointer to length of the external buffer. Input value must be
 *   larger than the size of ``struct rte_mbuf_ext_shared_info`` and
 *   padding for alignment. If not enough, this function will return NULL.
 *   Adjusted buffer length will be returned through this pointer.
 * @param free_cb
 *   Free callback function to call when the external buffer needs to be
 *   freed.
 * @param fcb_opaque
 *   Argument for the free callback function.
 *
 * @return
 *   A pointer to the initialized shared data on success, return NULL
 *   otherwise.
 */
Initialize shared data at the end of an external buffer before attaching
to a mbuf by ``rte_pktmbuf_attach_extbuf()``. This is not a mandatory
initialization but a helper function to simply spare a few bytes at the
end of the buffer for shared data. If shared data is allocated
separately, this should not be called but application has to properly
initialize the shared data according to its need.

Free callback and its argument is saved and the refcnt is set to 1.

@warning
The value of buf_len will be reduced to RTE_PTR_DIFF(shinfo, buf_addr)
after this initialization. This shall be used for
``rte_pktmbuf_attach_extbuf()``

@param buf_addr
The pointer to the external buffer.
@param [in,out] buf_len
The pointer to length of the external buffer. Input value must be
larger than the size of ``struct rte_mbuf_ext_shared_info`` and
padding for alignment. If not enough, this function will return NULL.
Adjusted buffer length will be returned through this pointer.
@param free_cb
Free callback function to call when the external buffer needs to be
freed.
@param fcb_opaque
Argument for the free callback function.

@return
A pointer to the initialized shared data on success, return NULL
otherwise.
Initialize shared data at the end of an external buffer before attaching to a mbuf by ` ` rte_pktmbuf_attach_extbuf () ` ` . This is not a mandatory initialization but a helper function to simply spare a few bytes at the end of the buffer for shared data . If shared data is allocated separately this should not be called but application has to properly initialize the shared data according to its need . Free callback and its argument is saved and the refcnt is set to 1 . @warning The value of buf_len will be reduced to RTE_PTR_DIFF ( shinfo buf_addr ) after this initialization . This shall be used for ` ` rte_pktmbuf_attach_extbuf () ` ` @param buf_addr The pointer to the external buffer . @param [ in out ] buf_len The pointer to length of the external buffer . Input value must be larger than the size of ` ` struct rte_mbuf_ext_shared_info ` ` and padding for alignment . If not enough this function will return NULL . Adjusted buffer length will be returned through this pointer . @param free_cb Free callback function to call when the external buffer needs to be freed . @param fcb_opaque Argument for the free callback function . @return A pointer to the initialized shared data on success return NULL otherwise .
static inline struct rte_mbuf_ext_shared_info *
rte_pktmbuf_ext_shinfo_init_helper(void *buf_addr, uint16_t *buf_len,
	rte_mbuf_extbuf_free_callback_t free_cb, void *fcb_opaque)
{
	struct rte_mbuf_ext_shared_info *shinfo;
	void *buf_end = RTE_PTR_ADD(buf_addr, *buf_len);
	void *addr;
	addr = RTE_PTR_ALIGN_FLOOR(RTE_PTR_SUB(buf_end, sizeof(*shinfo)),
				   sizeof(uintptr_t));
	if (addr <= buf_addr)
		return NULL;
	shinfo = (struct rte_mbuf_ext_shared_info *)addr;
	shinfo->free_cb = free_cb;
	shinfo->fcb_opaque = fcb_opaque;
	rte_mbuf_ext_refcnt_set(shinfo, 1);
	*buf_len = (uint16_t)RTE_PTR_DIFF(shinfo, buf_addr);
	return shinfo;
}
static inline struct rte_mbuf_ext_shared_info * rte_pktmbuf_ext_shinfo_init_helper ( void * buf_addr , uint16_t * buf_len , rte_mbuf_extbuf_free_callback_t free_cb , void * fcb_opaque ) { struct rte_mbuf_ext_shared_info * shinfo ; void * buf_end = RTE_PTR_ADD ( buf_addr , * buf_len ) ; void * addr ; addr = RTE_PTR_ALIGN_FLOOR ( RTE_PTR_SUB ( buf_end , sizeof ( * shinfo ) ) , sizeof ( uintptr_t ) ) ; if ( addr <= buf_addr ) return NULL ; shinfo = ( struct rte_mbuf_ext_shared_info * ) addr ; shinfo -> free_cb = free_cb ; shinfo -> fcb_opaque = fcb_opaque ; rte_mbuf_ext_refcnt_set ( shinfo , 1 ) ; * buf_len = ( uint16_t ) RTE_PTR_DIFF ( shinfo , buf_addr ) ; return shinfo ; }
Initialize shared data at the end of an external buffer before attaching
 to a mbuf by ``rte_pktmbuf_attach_extbuf()``.
Initialize shared data at the end of an external buffer before attaching to a mbuf by ` ` rte_pktmbuf_attach_extbuf () ` ` .