forked from p4lang/p4c
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
backends/ebpf: Output an error if a header is not byte-aligned (p4lan…
…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.
- Loading branch information
1 parent
43a00bf
commit 115dd15
Showing
4 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include <ebpf_model.p4> | ||
#include <core.p4> | ||
|
||
header ThreeBit_h { | ||
bit<3> x; | ||
} | ||
|
||
struct Headers_t { | ||
ThreeBit_h foo; | ||
ThreeBit_h bar; | ||
} | ||
|
||
parser prs(packet_in p, out Headers_t headers) { | ||
state start { | ||
p.extract(headers.foo); | ||
p.extract(headers.bar); | ||
transition accept; | ||
} | ||
} | ||
|
||
control pipe(inout Headers_t headers, out bool pass) { | ||
|
||
apply { | ||
pass = true; | ||
} | ||
} | ||
|
||
ebpfFilter(prs(), pipe()) main; |
Empty file.
6 changes: 6 additions & 0 deletions
6
testdata/p4_16_ebpf_errors_outputs/header_unaligned.p4-stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
header_unaligned.p4(15): [--Werror=target-error] error: Header headers.foo size 3 is not a multiple of 8 bits. | ||
p.extract(headers.foo); | ||
^^^^^^^^^^^ | ||
header_unaligned.p4(16): [--Werror=target-error] error: Header headers.bar size 3 is not a multiple of 8 bits. | ||
p.extract(headers.bar); | ||
^^^^^^^^^^^ |