Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is possible to encapsulate a new header in AF_XDP #415

Open
ZENOTME opened this issue Apr 11, 2024 · 1 comment
Open

Is possible to encapsulate a new header in AF_XDP #415

ZENOTME opened this issue Apr 11, 2024 · 1 comment

Comments

@ZENOTME
Copy link

ZENOTME commented Apr 11, 2024

I'm trying to capture the packet from veth and encapsulate a new eth header to send it out by a real eth nic. As far as I know, in xdp ebpf, we can use bpf_xdp_adjust_head to do something like this. Is possible we can do it in userspace using AF_XDP? E.g. using user head room and adjust the addr of frame desc forward when we want to encapsulate a new header.
image

@ZENOTME ZENOTME changed the title Is possible to encap a header in AF_XDP Is possible to encapsulate a new header in AF_XDP Apr 11, 2024
@ncshy
Copy link

ncshy commented Jul 11, 2024

It should be possible. The frame comes with a headroom by default (I can't be sure if it is 128B or 256B) so you can reference this by sending addr - (space for new headers) to process_packet() and fill in the new header there.
Another option is to push forward, so you use the same pkt pointer you get back from the example code as the start of your packet and push all the other data forward. Of course this will require a packet copy to hold the original data, which will reduce performance of your application.
Ultimately you cannot exceed your frame size and you have to keep track of you packet start offset, so that you fill in the tx descriptor correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants