p4c icon indicating copy to clipboard operation
p4c copied to clipboard

p4-ebpf: get rid of dependency on bpf_endian.h

Open osinstom opened this issue 2 years ago • 2 comments

Currently, the ebpf_kernel.h imports <bpf/bpf_endian.h>, which comes from the libbpf library. This introduces the dependency on the libbpf files for the P4 compiler and requires an additional installation step.

The idea is to copy-paste bpf_X functions from bpf_endian.h to ebpf_kernel.h and remove a dependency on global <bpf/bpf_endian.h>. This will make p4c-ebpf self-contained and libbpf will no longer be needed for the P4 compiler (the dependency will only stay for the control plane API).

I'm wondering what do you think @mbudiu-vmw @kmateuszssak @tatry ?

osinstom avatar May 13 '22 11:05 osinstom

The reason libbpf was added is that the Ubuntu 16.04 bpf headers were mismatched with the what the kernel provided. libbpf is designed to be kernel-agnostic and makes the generated code less dependent on the kernel headers of a particular distribution. Originally, more headers were using the libbpf headers. But I believe this pull request already broke that:

https://github.com/p4lang/p4c/pull/2936

You can see that even here the ebpf_kernel file still has this line: #include "linux/bpf.h" // types, and general bpf definitions which is a libbpf header.

Personally, I'd prefer to use libbpf and remove all system dependencies until we nail down what distributions we want to support. Things have gotten much easier since we have dropped Ubuntu 16.04. So we may not need it anymore.

fruffy avatar May 13 '22 12:05 fruffy

This is a very difficult question because ebpf is such a fast moving target in various kernels. I have really no idea which kernels are supported by our compiler at this point. Ideally we should support as many as possible. If you can make a clear statement about what would work and what wouldn't then we can make a better decision.

mihaibudiu avatar May 13 '22 19:05 mihaibudiu