DevinLeamy commented on code in PR #501:
URL: https://github.com/apache/mesos/pull/501#discussion_r1517858068


##########
src/linux/ebpf.hpp:
##########
@@ -17,4 +17,136 @@
 #ifndef __EBPF_HPP__
 #define __EBPF_HPP__
 
+#include <linux/bpf.h>
+
+#include <cstddef>
+#include <vector>
+
+#include "stout/nothing.hpp"
+#include "stout/try.hpp"
+
+namespace ebpf {
+
+// Loadable eBPF program. Constructed using an ebpf::ProgramBuilder.
+struct Program
+{
+  // eBPF attribute containing an eBPF program.
+  union bpf_attr attribute;
+};
+
+
+// Builder for eBPF programs.
+class ProgramBuilder
+{
+public:
+  explicit ProgramBuilder(enum bpf_prog_type type);
+
+  // Append instructions to the end of the eBPF program.
+  void append(std::vector<struct bpf_insn> instructions);
+
+  // Number of instructions in the eBPF program.
+  size_t instructions() const;
+
+  // Build a loadable eBPF program.
+  Program build();

Review Comment:
   I opted to copy the program instructions from ProgramBuilder into Program on 
build, and then free the instructions in the Program's destructor. 
   
   I saw having the `Builder` as useful for implementing the DeviceController 
where there's instructions we want to add to the program instructions before it 
becomes a `Program`. By having this separation we can do those additions in the 
`build()` step, so the caller doesn't have to remember to do some `finalize()` 
step before "building" (AKA creating the bpf_attr). The idea is make sure 
`Program`s are _truly_ loadable eBPF programs.
   
   If that's not clear, here's the DeviceProgram I'm preparing for the device 
controller (note - the API is slightly different but it should make what I'm 
going for more evident): 
https://github.com/DevinLeamy/mesos/commit/50e4c0ff7cf806ae02e8dc03488b70d00412583f
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to