-
Notifications
You must be signed in to change notification settings - Fork 444
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
Should we support headers which aren't byte-aligned? #4176
Comments
I have half a recollection of some change being made to the language spec explicitly saying that implementations are allowed to restrict themselves to header definitions whose total size must be a multiple of 8 bits long. I definitely recall that the BMv2 software switch is such an implementation, and at least somewhere in the p4c-bm2-ss back end code there is a check that rejects programs at compile time that attempt to define headers whose total length is not a multiple of 8 bits long. |
The error message from the BMv2 back end looks like this, if you want to grep through the source code for the error message and see how it is implemented, and do something similar for the EBPF back end:
|
AFAIK, this line
has been in the P4_16 spec since version 1.0.0, from 2017. |
…g#4176). Although P4 allows headers to be an arbitrary number of bits, the eBPF backend does not support it properly. Specifically, the code in compileExtractField() assumes that the header starts at a byte boundary. In any case, there is no realistic use case for headers which aren't a whole number of bytes. Output an error rather than fail silently. The BMv2 backend has a similar limitation already.
…g#4176). Although P4 allows headers to be an arbitrary number of bits, the eBPF backend does not support it properly. Specifically, the code in compileExtractField() assumes that the header starts at a byte boundary. In any case, there is no realistic use case for headers which aren't a whole number of bytes. Output an error rather than fail silently. The BMv2 backend has a similar limitation already.
…g#4176). Although P4 allows headers to be an arbitrary number of bits, the eBPF backend does not support it properly. Specifically, the code in compileExtractField() assumes that the header starts at a byte boundary. In any case, there is no realistic use case for headers which aren't a whole number of bytes. Output an error rather than fail silently. The BMv2 backend has a similar limitation already.
…g#4176). Although P4 allows headers to be an arbitrary number of bits, the eBPF backend does not support it properly. Specifically, the code in compileExtractField() assumes that the header starts at a byte boundary. In any case, there is no realistic use case for headers which aren't a whole number of bytes. Output an error rather than fail silently. The BMv2 backend has a similar limitation already.
Although P4 allows headers to be an arbitrary number of bits, the eBPF backend does not support it properly. Specifically, the code in compileExtractField() assumes that the header starts at a byte boundary. In any case, there is no realistic use case for headers which aren't a whole number of bytes. Output an error rather than fail silently. The BMv2 backend has a similar limitation already.
This question arose whilst working on the eBPF backend, however it applies more generally to the rest of the compiler.
Consider a
header
which has a size in bits which isn't a multiple of 8. I have never encountered any protocol which would define something like this, but it seems that the P4 language permits it - please correct me if I'm wrong.Currently I believe that the eBPF backend won't deal with this case properly: although it tracks the packet offset in bits there is an assumption that headers start on a byte boundary:
p4c/backends/ebpf/ebpfParser.cpp
Lines 462 to 475 in aefe41f
No errors or warnings will be generated, but the emitted code won't work properly. I could not find any tests which define non-byte-sized headers either. I have not checked other backends but wouldn't be surprised if there exists similar conditions.
The compiler should either handle such headers correctly, or print an error message when they are encountered. I am in favour of the latter approach since there are no real-world scenarios for such headers, and doing so will allow for future performance optimisations.
The text was updated successfully, but these errors were encountered: