Skip to content

Commit

Permalink
backends/ebpf: Change packet length calc to pass kernel verifier (p4l…
Browse files Browse the repository at this point in the history
  • Loading branch information
thomascalvert-xlnx committed Sep 18, 2023
1 parent 6e7cc24 commit 40611be
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions backends/ebpf/ebpfProgram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ void EBPFProgram::emitLocalVariables(CodeBuilder *builder) {
builder->newline();

builder->emitIndent();
builder->appendFormat("u32 %s = %s - %s", lengthVar.c_str(), packetEndVar.c_str(),
packetStartVar.c_str());
builder->appendFormat("u32 %s = %s", lengthVar.c_str(),
builder->target->dataLength(model.CPacketName.str()).c_str());
builder->endOfStatement(true);
}

Expand Down
6 changes: 6 additions & 0 deletions backends/ebpf/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class Target {
cstring argName) const = 0;
virtual cstring dataOffset(cstring base) const = 0;
virtual cstring dataEnd(cstring base) const = 0;
virtual cstring dataLength(cstring base) const = 0;
virtual cstring forwardReturnCode() const = 0;
virtual cstring dropReturnCode() const = 0;
virtual cstring abortReturnCode() const = 0;
Expand Down Expand Up @@ -183,6 +184,7 @@ class KernelSamplesTarget : public Target {
cstring dataEnd(cstring base) const override {
return cstring("((void*)(long)") + base + "->data_end)";
}
cstring dataLength(cstring base) const override { return cstring(base) + "->len"; }
cstring forwardReturnCode() const override { return "TC_ACT_OK"; }
cstring dropReturnCode() const override { return "TC_ACT_SHOT"; }
cstring abortReturnCode() const override { return "TC_ACT_SHOT"; }
Expand All @@ -206,6 +208,9 @@ class XdpTarget : public KernelSamplesTarget {
cstring sysMapPath() const override { return "/sys/fs/bpf/xdp/globals"; }
cstring packetDescriptorType() const override { return "struct xdp_md"; }

cstring dataLength(cstring base) const override {
return cstring("(") + base + "->data_end - " + base + "->data)";
}
void emitResizeBuffer(Util::SourceCodeBuilder *builder, cstring buffer,
cstring offsetVar) const override;
void emitMain(Util::SourceCodeBuilder *builder, cstring functionName,
Expand Down Expand Up @@ -237,6 +242,7 @@ class BccTarget : public Target {
cstring dataEnd(cstring base) const override {
return cstring("(") + base + " + " + base + "->len)";
}
cstring dataLength(cstring base) const override { return cstring(base) + "->len"; }
cstring forwardReturnCode() const override { return "0"; }
cstring dropReturnCode() const override { return "1"; }
cstring abortReturnCode() const override { return "1"; }
Expand Down
1 change: 1 addition & 0 deletions backends/ubpf/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class UbpfTarget : public EBPF::Target {

cstring dataOffset(UNUSED cstring base) const override { return cstring(""); }
cstring dataEnd(UNUSED cstring base) const override { return cstring(""); }
cstring dataLength(UNUSED cstring base) const override { return cstring(""); }
cstring dropReturnCode() const override { return "0"; }
cstring abortReturnCode() const override { return "1"; }
cstring forwardReturnCode() const override { return "1"; }
Expand Down

0 comments on commit 40611be

Please sign in to comment.