app/pktgen-pcap.c
static void
pktgen_pcap_mbuf_ctor(struct rte_mempool *mp,
		      void *opaque_arg,
		      void *_m,
		      unsigned i)
{
	struct rte_mbuf *m = _m;
	uint32_t mbuf_size, buf_len, priv_size = 0;
	pcaprec_hdr_t hdr;
	ssize_t len = -1;
	char buffer[DEFAULT_MBUF_SIZE];
	pcap_info_t *pcap = (pcap_info_t *)opaque_arg;

#if __RTE_VERSION >= RTE_VERSION_NUM(16, 7, 0, 0)
	priv_size = rte_pktmbuf_priv_size(mp);
	buf_len = rte_pktmbuf_data_room_size(mp);
#else
	buf_len = mp->elt_size - sizeof(struct rte_mbuf);
#endif
	mbuf_size = sizeof(struct rte_mbuf) + priv_size;
	memset(m, 0, mbuf_size);

#if __RTE_VERSION >= RTE_VERSION_NUM(17, 11, 0, 0)
	/* start of buffer is just after mbuf structure */
	m->priv_size    = priv_size;
	m->buf_addr     = (char *)m + mbuf_size;
	m->buf_iova     = rte_mempool_virt2iova(m) + mbuf_size;
	m->buf_len      = (uint16_t)buf_len;
#elif __RTE_VERSION >= RTE_VERSION_NUM(16, 7, 0, 0)
	/* start of buffer is after mbuf structure and priv data */
	m->priv_size = priv_size;
	m->buf_addr = (char *)m + mbuf_size;
	m->buf_physaddr = rte_mempool_virt2phy(mp, m) + mbuf_size;
	m->buf_len = (uint16_t)buf_len;
#else
	/* start of buffer is just after mbuf structure */
	m->buf_addr     = (char *)m + sizeof(struct rte_mbuf);
	m->buf_physaddr = rte_mempool_virt2phy(mp, m->buf_addr);
	m->buf_len      = (uint16_t)buf_len;
#endif

	/* keep some headroom between start of buffer and data */
	m->data_off = RTE_MIN(RTE_PKTMBUF_HEADROOM, m->buf_len);

	/* init some constant fields */
	m->pool         = mp;
	m->nb_segs      = 1;
	m->port         = MBUF_INVALID_PORT;
	rte_mbuf_refcnt_set(m, 1);
	m->next		= NULL;

	for (;; ) {
		union pktgen_data *d = pktgen_data_field(m);

		if ( (i & 0x3ff) == 0) {
			scrn_printf(1, 1, "%c\b", "-\\|/"[(i >> 10) & 3]);
			i++;
		}

		if (unlikely(_pcap_read(pcap, &hdr, buffer,
					sizeof(buffer)) <= 0) ) {
			_pcap_rewind(pcap);
			continue;
		}

		len = hdr.incl_len;

		/* Adjust the packet length if not a valid size. */
		if (len < MIN_PKT_SIZE)
			len = MIN_PKT_SIZE;
		else if (len > MAX_PKT_SIZE)
			len = MAX_PKT_SIZE;

		m->data_len = len;
		m->pkt_len  = len;

		d->pkt_len = len;
		d->data_len = len;
		d->buf_len = m->buf_len;

		rte_memcpy((uint8_t *)m->buf_addr + m->data_off, buffer, len);
		break;
	}
}
/**
 *
 * pktgen_pcap_mbuf_ctor - Callback routine to construct PCAP packets.
 *
 * DESCRIPTION
 * Callback routine to construct a set of PCAP packet buffers.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */
Callback routine to construct PCAP packets.
DESCRIPTION
Callback routine to construct a set of PCAP packet buffers.

N/A

SEE ALSO.
Callback routine to construct PCAP packets . DESCRIPTION Callback routine to construct a set of PCAP packet buffers . N / A SEE ALSO .
static void
pktgen_pcap_mbuf_ctor(struct rte_mempool *mp,
		      void *opaque_arg,
		      void *_m,
		      unsigned i)
{
	struct rte_mbuf *m = _m;
	uint32_t mbuf_size, buf_len, priv_size = 0;
	pcaprec_hdr_t hdr;
	ssize_t len = -1;
	char buffer[DEFAULT_MBUF_SIZE];
	pcap_info_t *pcap = (pcap_info_t *)opaque_arg;
#if __RTE_VERSION >= RTE_VERSION_NUM(16, 7, 0, 0)
	priv_size = rte_pktmbuf_priv_size(mp);
	buf_len = rte_pktmbuf_data_room_size(mp);
#else
	buf_len = mp->elt_size - sizeof(struct rte_mbuf);
#endif
	mbuf_size = sizeof(struct rte_mbuf) + priv_size;
	memset(m, 0, mbuf_size);
#if __RTE_VERSION >= RTE_VERSION_NUM(17, 11, 0, 0)
	m->priv_size    = priv_size;
	m->buf_addr     = (char *)m + mbuf_size;
	m->buf_iova     = rte_mempool_virt2iova(m) + mbuf_size;
	m->buf_len      = (uint16_t)buf_len;
#elif __RTE_VERSION >= RTE_VERSION_NUM(16, 7, 0, 0)
	m->priv_size = priv_size;
	m->buf_addr = (char *)m + mbuf_size;
	m->buf_physaddr = rte_mempool_virt2phy(mp, m) + mbuf_size;
	m->buf_len = (uint16_t)buf_len;
#else
	m->buf_addr     = (char *)m + sizeof(struct rte_mbuf);
	m->buf_physaddr = rte_mempool_virt2phy(mp, m->buf_addr);
	m->buf_len      = (uint16_t)buf_len;
#endif
	m->data_off = RTE_MIN(RTE_PKTMBUF_HEADROOM, m->buf_len);
	m->pool         = mp;
	m->nb_segs      = 1;
	m->port         = MBUF_INVALID_PORT;
	rte_mbuf_refcnt_set(m, 1);
	m->next		= NULL;
	for (;; ) {
		union pktgen_data *d = pktgen_data_field(m);
		if ( (i & 0x3ff) == 0) {
			scrn_printf(1, 1, "%c\b", "-\\|/"[(i >> 10) & 3]);
			i++;
		}
		if (unlikely(_pcap_read(pcap, &hdr, buffer,
					sizeof(buffer)) <= 0) ) {
			_pcap_rewind(pcap);
			continue;
		}
		len = hdr.incl_len;
		if (len < MIN_PKT_SIZE)
			len = MIN_PKT_SIZE;
		else if (len > MAX_PKT_SIZE)
			len = MAX_PKT_SIZE;
		m->data_len = len;
		m->pkt_len  = len;
		d->pkt_len = len;
		d->data_len = len;
		d->buf_len = m->buf_len;
		rte_memcpy((uint8_t *)m->buf_addr + m->data_off, buffer, len);
		break;
	}
}
static void pktgen_pcap_mbuf_ctor ( struct rte_mempool * mp , void * opaque_arg , void * _m , unsigned i ) { struct rte_mbuf * m = _m ; uint32_t mbuf_size , buf_len , priv_size = 0 ; pcaprec_hdr_t hdr ; ssize_t len = -1 ; char buffer [ DEFAULT_MBUF_SIZE ] ; pcap_info_t * pcap = ( pcap_info_t * ) opaque_arg ; #if __RTE_VERSION >= RTE_VERSION_NUM ( 16 , 7 , 0 , 0 ) priv_size = rte_pktmbuf_priv_size ( mp ) ; buf_len = rte_pktmbuf_data_room_size ( mp ) ; #else buf_len = mp -> elt_size - sizeof ( struct rte_mbuf ) ; #endif mbuf_size = sizeof ( struct rte_mbuf ) + priv_size ; memset ( m , 0 , mbuf_size ) ; #if __RTE_VERSION >= RTE_VERSION_NUM ( 17 , 11 , 0 , 0 ) m -> priv_size = priv_size ; m -> buf_addr = ( char * ) m + mbuf_size ; m -> buf_iova = rte_mempool_virt2iova ( m ) + mbuf_size ; m -> buf_len = ( uint16_t ) buf_len ; #elif __RTE_VERSION >= RTE_VERSION_NUM ( 16 , 7 , 0 , 0 ) m -> priv_size = priv_size ; m -> buf_addr = ( char * ) m + mbuf_size ; m -> buf_physaddr = rte_mempool_virt2phy ( mp , m ) + mbuf_size ; m -> buf_len = ( uint16_t ) buf_len ; #else m -> buf_addr = ( char * ) m + sizeof ( struct rte_mbuf ) ; m -> buf_physaddr = rte_mempool_virt2phy ( mp , m -> buf_addr ) ; m -> buf_len = ( uint16_t ) buf_len ; #endif m -> data_off = RTE_MIN ( RTE_PKTMBUF_HEADROOM , m -> buf_len ) ; m -> pool = mp ; m -> nb_segs = 1 ; m -> port = MBUF_INVALID_PORT ; rte_mbuf_refcnt_set ( m , 1 ) ; m -> next = NULL ; for ( ; ; ) { union pktgen_data * d = pktgen_data_field ( m ) ; if ( ( i & 0x3ff ) == 0 ) { scrn_printf ( 1 , 1 , " \b " , " \\ " [ ( i >> 10 ) & 3 ] ) ; i ++ ; } if ( unlikely ( _pcap_read ( pcap , & hdr , buffer , sizeof ( buffer ) ) <= 0 ) ) { _pcap_rewind ( pcap ) ; continue ; } len = hdr . incl_len ; if ( len < MIN_PKT_SIZE ) len = MIN_PKT_SIZE ; else if ( len > MAX_PKT_SIZE ) len = MAX_PKT_SIZE ; m -> data_len = len ; m -> pkt_len = len ; d -> pkt_len = len ; d -> data_len = len ; d -> buf_len = m -> buf_len ; rte_memcpy ( ( uint8_t * ) m -> buf_addr + m -> data_off , buffer , len ) ; break ; } }
pktgen_pcap_mbuf_ctor - Callback routine to construct PCAP packets.
pktgen_pcap_mbuf_ctor - Callback routine to construct PCAP packets .
/* start of buffer is just after mbuf structure */ /* start of buffer is after mbuf structure and priv data */ /* start of buffer is just after mbuf structure */ /* keep some headroom between start of buffer and data */ /* init some constant fields */ /* Adjust the packet length if not a valid size. */