dpdk mbuf 深拷贝

 

 

struct rte_mbuf *mbuf_copy(struct rte_mbuf *md, struct rte_mempool *mp)
{
    struct rte_mbuf *mc, *mi, **prev;
    uint32_t pktlen;
    uint8_t nseg;

    if (unlikely ((mc = rte_pktmbuf_alloc(mp)) == NULL))
        return NULL;

    mi = mc;
    pktlen = md->pkt_len;
    nseg = 0;
    prev = &mi->next;

    do {
        nseg++;
        mbuf_copy_metadata(mi, md);
        *prev = mi;
        prev = &mi->next;
        rte_memcpy(rte_pktmbuf_mtod(mi, void *), rte_pktmbuf_mtod(md, void *), md->data_len);
    } while ((md = md->next) != NULL && (mi = rte_pktmbuf_alloc(mp)) != NULL);

    *prev =  NULL;
    mc->nb_segs = nseg;
    mc->pkt_len = pktlen;

    if (unlikely (mi == NULL)) {
        rte_pktmbuf_free(mc);
        return NULL;
    }

    __rte_mbuf_sanity_check(mc, 1); //check packet header segment
    return mc;
}

 

posted on 2021-05-12 17:08  tycoon3  阅读(544)  评论(0编辑  收藏  举报

导航