> -----Original Message----- > From: dev [mailto:dev-boun...@dpdk.org] On Behalf Of Stephen Hemminger > Sent: Saturday, September 28, 2019 2:38 AM > > This is a commonly used operation that surprisingly the > DPDK has not supported. The new rte_pktmbuf_copy does a > deep copy of packet. This is a complete copy including > meta-data. > > It handles the case where the source mbuf comes from a pool > with larger data area than the destination pool. The routine > also has options for skipping data, or truncating at a fixed > length.
Great initiative, and the offset/length params makes it even better! > > Signed-off-by: Stephen Hemminger <step...@networkplumber.org> > --- > lib/librte_mbuf/rte_mbuf.c | 70 ++++++++++++++++++++++++++++ > lib/librte_mbuf/rte_mbuf.h | 26 +++++++++++ > lib/librte_mbuf/rte_mbuf_version.map | 1 + > 3 files changed, 97 insertions(+) > > diff --git a/lib/librte_mbuf/rte_mbuf.c b/lib/librte_mbuf/rte_mbuf.c > index 12d0258a120d..6888d6bd5dfc 100644 > --- a/lib/librte_mbuf/rte_mbuf.c > +++ b/lib/librte_mbuf/rte_mbuf.c > @@ -324,6 +324,76 @@ rte_pktmbuf_linearize(struct rte_mbuf *mbuf) > return 0; > } > > +/* Create a deep copy of mbuf */ > +struct rte_mbuf * > +rte_pktmbuf_copy(const struct rte_mbuf *m, struct rte_mempool *mp, > + uint32_t off, uint32_t len) > +{ > + const struct rte_mbuf *seg = m; > + struct rte_mbuf *mc, *m_last, **prev; > + > + if (unlikely(off >= m->pkt_len)) > + return NULL; > + > + mc = rte_pktmbuf_alloc(mp); > + if (unlikely(mc == NULL)) > + return NULL; > + > + if (len > m->pkt_len - off) > + len = m->pkt_len - off; > + > + /* clone meta data from original */ > + mc->port = m->port; > + mc->vlan_tci = m->vlan_tci; > + mc->vlan_tci_outer = m->vlan_tci_outer; > + mc->tx_offload = m->tx_offload; > + mc->hash = m->hash; > + mc->packet_type = m->packet_type; > + mc->timestamp = m->timestamp; At the dynamic mbuf presentation at DPDK Userspace, it was mentioned that the last 8 bytes of the mbuf could be used by applications. Consider if their values should be copied too, and thus if they should be explicitly define in the mbuf, e.g. dynfield[1,2] like in the dynamic mbuf patch. I don't have an opinion on this, I'm just bringing it to your attention. Med venlig hilsen / kind regards - Morten Brørup