xdp-project / xdp-tutorial

XDP tutorial
2.49k stars 579 forks source link

Insert a timestamp into the packets in user-space #202

Closed Echo-chu331 closed 3 years ago

Echo-chu331 commented 3 years ago

https://github.com/xdp-project/xdp-tutorial/blob/master/experiment01-tailgrow/xdp_prog_kern.c#L21 introduced how to add timestamps in extended tailroom in kernel-space. But I want to insert a timestamp into the packets I receive in my XDP program (modify according to https://github.com/xdp-project/xdp-tutorial/blob/master/advanced03-AF_XDP/af_xdp_user.c ) in user-space.

I need to expand the tailroom of the packet or there is already a field as headroom I can use to insert a timestamp? What is the format of the data packet in XDP program?

tohojo commented 3 years ago

Echo-chu331 @.***> writes:

https://github.com/xdp-project/xdp-tutorial/blob/master/experiment01-tailgrow/xdp_prog_kern.c#L21 introduced how to add timestamps in extended tailroom in kernel-space. But I want to insert a timestamp into the packets I receive in my XDP program (modify according to https://github.com/xdp-project/xdp-tutorial/blob/master/advanced03-AF_XDP/af_xdp_user.c ) in user-space.

I need to expand the tailroom of the packet or there is already a field as headroom I can use to insert a timestamp? What is the format of the data packet in XDP program?

there is no "format of the data packet". It's just a buffer of bytes that come in (though generally it's assumed to be an Ethernet packet). So you can do whatever you want as long as your kernel and userspace programs agree.

For timestamps specifically there's also ongoing work to make hardware metadata available to XDP programs (and AF_XDP)