[dpdk-dev] Packet crafting....

Richardson, Bruce bruce.richardson at intel.com
Fri Mar 14 12:08:57 CET 2014

> From: sabu kurian [mailto:sabu2kurian at gmail.com] 
> Sent: Friday, March 14, 2014 10:09 AM
> To: Richardson, Bruce
> Cc: dev at dpdk.org
> Subject: Re: [dpdk-dev] Packet crafting....
> Thank you very much Richardson for your valuable reply. But is there another way of doing it using the rte_pktmbuf_append / rte_pktmbuf_prepend ? Can you please tell me on how to do that ?

You could use pktmbuf_append and pktmbuf_prepend, but they are primarily designed to add headers/footers on to an existing packet that already has headers, so that you don't need to move the existing data. In the case of having to craft a packet from scratch, there is no existing data in the mbuf, so the whole packet can just be filled in sequentially. [Don't forget that when you get the mbuf from rte_pktmbuf_alloc, you also need to set the length value to the appropriate size.]

However, if you first write the data to the mbuf and then want to add the headers in order, like a packet moving down through layers of a stack,  you can use prepend to add udp, then ip, then your ethernet header, but this will be no faster than just writing the data directly to the mbuf space, and may be slightly slower as each prepend call has to just the length values and data pointer values in the mbuf. Each header prepended also uses up headroom in the mbuf, so you can only add 128-bytes of headers by default to each packet.

In short, if you are creating a single packet, I'd recommend just getting the data pointer from the returned mbuf and writing directly to that. 


More information about the dev mailing list