diff --git a/backends/ebpf/codeGen.cpp b/backends/ebpf/codeGen.cpp index 91b7a4aa6c1..ebdb8a718c5 100644 --- a/backends/ebpf/codeGen.cpp +++ b/backends/ebpf/codeGen.cpp @@ -404,7 +404,7 @@ bool CodeGenInspector::preorder(const IR::BlockStatement *s) { return false; } -// This is correct only after inlining +/// This is correct only after inlining. bool CodeGenInspector::preorder(const IR::ExitStatement *) { builder->append("return"); builder->endOfStatement(); @@ -590,25 +590,24 @@ void CodeGenInspector::emitTCAssignmentEndianessConversion(const IR::Expression return; } if (rByteOrder == "NETWORK") { - /* - If left side of assignment is not annotated field i.e host endian and right expression - is annotated field i.e network endian, we need to convert rexp to host order. - Example - - select_0 = hdr.ipv4.diffserv - select_0 = bntoh(hdr.ipv4.diffserv) - */ + // If left side of assignment is not annotated field i.e host endian and right expression + // is annotated field i.e network endian, we need to convert rexp to host order. + // Example - + // select_0 = hdr.ipv4.diffserv + // select_0 = bntoh(hdr.ipv4.diffserv) + // emitAndConvertByteOrder(rexpr, "HOST"); } if (lByteOrder == "NETWORK") { - /* - If left side of assignment is annotated field i.e network endian, we need to convert - right expression to network order. - Example - - hdr.opv4.diffserv = 0x1; - hdr.opv4.diffserv = bhton(0x1) - */ + // If left side of assignment is annotated field i.e network endian, we need to convert + // right expression to network order. + // Example - + // hdr.opv4.diffserv = 0x1; + // hdr.opv4.diffserv = bhton(0x1) + // emitAndConvertByteOrder(rexpr, "NETWORK"); } + return; } diff --git a/backends/ebpf/codeGen.h b/backends/ebpf/codeGen.h index 76c358c928d..e015b66f37c 100644 --- a/backends/ebpf/codeGen.h +++ b/backends/ebpf/codeGen.h @@ -36,20 +36,20 @@ class CodeBuilder : public Util::SourceCodeBuilder { explicit CodeBuilder(const Target *target) : target(target) {} }; -// Visitor for generating C for EBPF -// This visitor is invoked on various subtrees +/// Visitor for generating C for EBPF. +/// This visitor is invoked on various subtrees. class CodeGenInspector : public Inspector { protected: CodeBuilder *builder; P4::ReferenceMap *refMap; P4::TypeMap *typeMap; std::map substitution; - // asPointerVariables stores the list of string expressions that - // should be emitted as pointer variables. + /// asPointerVariables stores the list of string expressions that + /// should be emitted as pointer variables. std::set asPointerVariables; - // Since CodeGenInspector also generates C comments, - // this variable keeps track of the current comment depth. + /// Since CodeGenInspector also generates C comments, + /// this variable keeps track of the current comment depth. int commentDescriptionDepth = 0; public: @@ -134,10 +134,10 @@ class CodeGenInspector : public Inspector { class EBPFInitializerUtils { public: - // return *real* number of bits required by type + /// return *real* number of bits required by type static unsigned ebpfTypeWidth(P4::TypeMap *typeMap, const IR::Expression *expr); - // Generate hex string and prepend it with zeroes when shorter than required width + /// Generate hex string and prepend it with zeroes when shorter than required width. static cstring genHexStr(const big_int &value, unsigned width, const IR::Expression *expr); }; diff --git a/backends/ebpf/ebpfControl.h b/backends/ebpf/ebpfControl.h index 7ddb6cc2b0a..9e0702287bd 100644 --- a/backends/ebpf/ebpfControl.h +++ b/backends/ebpf/ebpfControl.h @@ -35,7 +35,7 @@ class ControlBodyTranslator : public virtual CodeGenInspector { public: explicit ControlBodyTranslator(const EBPFControl *control); - // handle the packet_out.emit method + /// Handle the packet_out.emit method. virtual void compileEmitField(const IR::Expression *expr, cstring field, unsigned alignment, EBPFType *type); virtual void compileEmit(const IR::Vector *args); @@ -63,7 +63,7 @@ class EBPFControl : public EBPFObject { const IR::Parameter *xdpInputMeta; // only for xdp progs const IR::Parameter *xdpOutputMeta; // only for xdp progs const IR::Parameter *parserHeaders; - // replace references to headers with references to parserHeaders + /// Replace references to headers with references to parserHeaders cstring hitVariable; ControlBodyTranslator *codeGen; const bool emitExterns; diff --git a/backends/ebpf/ebpfDeparser.h b/backends/ebpf/ebpfDeparser.h index 1153afb6539..d1a2a3b69e3 100644 --- a/backends/ebpf/ebpfDeparser.h +++ b/backends/ebpf/ebpfDeparser.h @@ -23,7 +23,7 @@ namespace EBPF { class EBPFDeparser; -// this translator emits deparser externs +/// This translator emits deparser externs. class DeparserBodyTranslator : public ControlBodyTranslator { protected: const EBPFDeparser *deparser; @@ -34,7 +34,7 @@ class DeparserBodyTranslator : public ControlBodyTranslator { bool preorder(const IR::MethodCallExpression *expression) override; }; -// this translator emits buffer preparation (eg. which headers will be emitted) +/// This translator emits buffer preparation (eg. which headers will be emitted) class DeparserPrepareBufferTranslator : public ControlBodyTranslator { protected: const EBPFDeparser *deparser; @@ -47,7 +47,7 @@ class DeparserPrepareBufferTranslator : public ControlBodyTranslator { bool preorder(const IR::MethodCallExpression *expression) override; }; -// this translator emits headers +/// This translator emits headers class DeparserHdrEmitTranslator : public DeparserPrepareBufferTranslator { protected: const EBPFDeparser *deparser; @@ -79,9 +79,9 @@ class EBPFDeparser : public EBPFControl { bool build() override; void emit(CodeBuilder *builder) override; - // A "PreDeparser" is emitted just before a sequence of hdr.emit() functions. - // It is useful in the case of resubmit or clone operation, as these operations - // require to have an original packet. + /// A "PreDeparser" is emitted just before a sequence of hdr.emit() functions. + /// It is useful in the case of resubmit or clone operation, as these operations + /// require to have an original packet. virtual void emitPreDeparser(CodeBuilder *builder) { (void)builder; } virtual void emitDeparserExternCalls(CodeBuilder *builder) { (void)builder; } diff --git a/backends/ebpf/ebpfModel.h b/backends/ebpf/ebpfModel.h index cb0b8ceb3af..07570277038 100644 --- a/backends/ebpf/ebpfModel.h +++ b/backends/ebpf/ebpfModel.h @@ -60,7 +60,7 @@ struct Filter_Model : public ::Model::Elem { ::Model::Elem filter; }; -// Keep this in sync with ebpf_model.p4 and xdp_model.p4 +/// Keep this in sync with ebpf_model.p4 and xdp_model.p4 class EBPFModel : public ::Model::Model { protected: EBPFModel() @@ -87,7 +87,7 @@ class EBPFModel : public ::Model::Model { ::Model::Elem CPacketName; ::Model::Param_Model packet; ModelArchitecture arch; - // Only one of these should be used, depending on arch value. + /// Only one of these should be used, depending on arch value. Filter_Model filter; Xdp_Model xdp; diff --git a/backends/ebpf/ebpfObject.h b/backends/ebpf/ebpfObject.h index 8039badd6d8..32d8960a989 100644 --- a/backends/ebpf/ebpfObject.h +++ b/backends/ebpf/ebpfObject.h @@ -27,7 +27,7 @@ limitations under the License. namespace EBPF { -// Base class for EBPF objects +/// Base class for EBPF objects. class EBPFObject : public ICastable { public: virtual ~EBPFObject() {} diff --git a/backends/ebpf/ebpfOptions.h b/backends/ebpf/ebpfOptions.h index f6358dd9e71..f642f172093 100644 --- a/backends/ebpf/ebpfOptions.h +++ b/backends/ebpf/ebpfOptions.h @@ -25,21 +25,21 @@ enum XDP2TC { XDP2TC_NONE, XDP2TC_META, XDP2TC_HEAD, XDP2TC_CPUMAP }; class EbpfOptions : public CompilerOptions { public: - // file to output to + /// file to output to cstring outputFile = nullptr; - // read from json + /// read from json bool loadIRFromJson = false; - // Externs generation + /// Externs generation bool emitExterns = false; - // tracing eBPF code execution + /// tracing eBPF code execution bool emitTraceMessages = false; - // generate program to XDP layer + /// generate program to XDP layer bool generateToXDP = false; - // XDP2TC mode for PSA-eBPF + //// XDP2TC mode for PSA-eBPF enum XDP2TC xdp2tcMode = XDP2TC_NONE; - // maximum number of unique ternary masks + /// maximum number of unique ternary masks unsigned int maxTernaryMasks = 128; - // Enable table cache for LPM and ternary tables + /// Enable table cache for LPM and ternary tables bool enableTableCache = false; EbpfOptions(); diff --git a/backends/ebpf/ebpfParser.h b/backends/ebpf/ebpfParser.h index 4ca45d5deb6..5e9e1a982fa 100644 --- a/backends/ebpf/ebpfParser.h +++ b/backends/ebpf/ebpfParser.h @@ -30,7 +30,7 @@ class EBPFParserState; class StateTranslationVisitor : public CodeGenInspector { protected: - // stores the result of evaluating the select argument + /// Stores the result of evaluating the select argument. cstring selectValue; P4::P4CoreLibrary &p4lib; diff --git a/backends/ebpf/ebpfProgram.h b/backends/ebpf/ebpfProgram.h index b4a6ea0aaa1..ff029976ac8 100644 --- a/backends/ebpf/ebpfProgram.h +++ b/backends/ebpf/ebpfProgram.h @@ -50,17 +50,17 @@ class EBPFProgram : public EBPFObject { EBPFParser *parser; EBPFControl *control; EBPFModel &model; - // Deparser may be NULL if not supported (e.g. ebpfFilter package) + /// Deparser may be NULL if not supported (e.g. ebpfFilter package). EBPFDeparser *deparser; cstring endLabel, offsetVar, lengthVar, headerStartVar; cstring zeroKey, functionName, errorVar; cstring packetStartVar, packetEndVar, byteVar; cstring errorEnum; - cstring license = "GPL"; // TODO: this should be a compiler option probably + cstring license = "GPL"; /// TODO: this should be a compiler option probably cstring arrayIndexType = "u32"; - virtual bool build(); // return 'true' on success + virtual bool build(); /// return 'true' on success EBPFProgram(const EbpfOptions &options, const IR::P4Program *program, P4::ReferenceMap *refMap, P4::TypeMap *typeMap, const IR::ToplevelBlock *toplevel) diff --git a/backends/ebpf/ebpfTable.cpp b/backends/ebpf/ebpfTable.cpp index c53ed50f1e4..fb4ed36adb7 100644 --- a/backends/ebpf/ebpfTable.cpp +++ b/backends/ebpf/ebpfTable.cpp @@ -104,10 +104,11 @@ void EBPFTable::initKey() { } } -// Performs the following validations: -// - Validates if LPM key is the last one from match keys in an LPM table (ignores selector fields). -// - Validates if match fields in ternary tables are sorted by size -// in descending order (ignores selector fields). +/// Performs the following validations: +/// - Validates if LPM key is the last one from match keys in an LPM table (ignores selector +/// fields). +/// - Validates if match fields in ternary tables are sorted by size +/// in descending order (ignores selector fields). void EBPFTable::validateKeys() const { if (keyGenerator == nullptr) return; @@ -862,8 +863,8 @@ cstring EBPFTable::p4ActionToActionIDName(const IR::P4Action *action) const { return Util::printf_format("%s_ACT_%s", tableInstance.toUpper(), actionName.toUpper()); } -// As ternary has precedence over lpm, this function checks if any -// field is key field is lpm and none of key fields is of type ternary. +/// As ternary has precedence over lpm, this function checks if any +/// field is key field is lpm and none of key fields is of type ternary. bool EBPFTable::isLPMTable() const { bool isLPM = false; if (keyGenerator != nullptr) { diff --git a/backends/ebpf/ebpfTable.h b/backends/ebpf/ebpfTable.h index 9cf2499cb9f..8dd31082727 100644 --- a/backends/ebpf/ebpfTable.h +++ b/backends/ebpf/ebpfTable.h @@ -45,7 +45,7 @@ class ActionTranslationVisitor : public virtual CodeGenInspector { bool isActionParameter(const IR::PathExpression *expression) const; }; // ActionTranslationVisitor -// Also used to represent counters +/// Also used to represent counters class EBPFTableBase : public EBPFObject { public: const EBPFProgram *program; @@ -94,8 +94,8 @@ class EBPFTable : public EBPFTableBase { cstring defaultActionMapName; std::map keyFieldNames; std::map keyTypes; - // Use 1024 by default. - // TODO: make it configurable using compiler options. + /// Use 1024 by default. + /// TODO: make it configurable using compiler options. size_t size = 1024; const cstring prefixFieldName = "prefixlen"; @@ -112,7 +112,7 @@ class EBPFTable : public EBPFTableBase { virtual void emitValueType(CodeBuilder *builder); virtual void emitValueActionIDNames(CodeBuilder *builder); virtual void emitValueStructStructure(CodeBuilder *builder); - // Emits value types used by direct externs. + /// Emits value types used by direct externs. virtual void emitDirectValueTypes(CodeBuilder *builder) { (void)builder; } virtual void emitAction(CodeBuilder *builder, cstring valueName, cstring actionRunVariable); virtual void emitInitializer(CodeBuilder *builder); @@ -128,8 +128,8 @@ class EBPFTable : public EBPFTableBase { matchType->name.name == P4::P4CoreLibrary::instance().ternaryMatch.name || matchType->name.name == P4::P4CoreLibrary::instance().lpmMatch.name; } - // Whether to drop packet if no match entry found. - // Some table implementations may want to continue processing. + /// Whether to drop packet if no match entry found. + /// Some table implementations may want to continue processing. virtual bool dropOnNoMatchingEntryFound() const { return true; } virtual bool cacheEnabled() { return false; } diff --git a/backends/ebpf/ebpfType.h b/backends/ebpf/ebpfType.h index ce591389de4..6af9a9cdbc5 100644 --- a/backends/ebpf/ebpfType.h +++ b/backends/ebpf/ebpfType.h @@ -25,7 +25,7 @@ limitations under the License. namespace EBPF { -// Base class for EBPF types +/// Base class for EBPF types class EBPFType : public EBPFObject { protected: explicit EBPFType(const IR::Type *type) : type(type) {} @@ -46,10 +46,10 @@ class EBPFType : public EBPFObject { class IHasWidth : public ICastable { public: virtual ~IHasWidth() {} - // P4 width + /// P4 width virtual unsigned widthInBits() const = 0; - // Width in the target implementation. - // Currently a multiple of 8. + /// Width in the target implementation. + /// Currently a multiple of 8. virtual unsigned implementationWidthInBits() const = 0; DECLARE_TYPEINFO(IHasWidth); @@ -125,7 +125,7 @@ class EBPFScalarType : public EBPFType, public IHasWidth { DECLARE_TYPEINFO(EBPFScalarType, EBPFType, IHasWidth); }; -// This should not always implement IHasWidth, but it may... +/// This should not always implement IHasWidth, but it may... class EBPFTypeName : public EBPFType, public IHasWidth { const IR::Type_Name *type; EBPFType *canonical; @@ -149,7 +149,7 @@ class EBPFTypeName : public EBPFType, public IHasWidth { DECLARE_TYPEINFO(EBPFTypeName, EBPFType, IHasWidth); }; -// Also represents headers and unions +/// Also represents headers and unions class EBPFStructType : public EBPFType, public IHasWidth { class EBPFField { public: diff --git a/backends/ebpf/lower.h b/backends/ebpf/lower.h index 43253ffee5b..2f498cca125 100644 --- a/backends/ebpf/lower.h +++ b/backends/ebpf/lower.h @@ -23,12 +23,10 @@ limitations under the License. namespace EBPF { -/** - This pass rewrites expressions which are not supported natively on EBPF. -*/ +/// This pass rewrites expressions which are not supported natively on EBPF. class LowerExpressions : public Transform { P4::TypeMap *typeMap; - // Cannot shift with a value larger than 5 bits + /// Cannot shift with a value larger than 5 bits. const int maxShiftWidth = 5; const IR::Expression *shift(const IR::Operation_Binary *expression) const; diff --git a/backends/ebpf/midend.h b/backends/ebpf/midend.h index 316dab1d974..c1a639a5cbb 100644 --- a/backends/ebpf/midend.h +++ b/backends/ebpf/midend.h @@ -31,7 +31,7 @@ class MidEnd { P4::TypeMap typeMap; void addDebugHook(DebugHook hook) { hooks.push_back(hook); } - // If p4c is run with option '--listMidendPasses', outStream is used for printing passes names + /// If p4c is run with option '--listMidendPasses', outStream is used for printing passes names. const IR::ToplevelBlock *run(EbpfOptions &options, const IR::P4Program *program, std::ostream *outStream = nullptr); }; diff --git a/backends/ebpf/psa/backend.h b/backends/ebpf/psa/backend.h index 84e40bb8c9f..c9a1660ce0b 100644 --- a/backends/ebpf/psa/backend.h +++ b/backends/ebpf/psa/backend.h @@ -45,7 +45,7 @@ class PSASwitchBackend { void convert(const IR::ToplevelBlock *tlb); void codegen(std::ostream &cstream) const { CodeBuilder c(target); - // instead of generating two files, put all the code in a single file + // Instead of generating two files, put all the code in a single file. ebpf_program->emit(&c); cstream << c.toString(); } diff --git a/backends/ebpf/psa/ebpfPipeline.cpp b/backends/ebpf/psa/ebpfPipeline.cpp index a025e0ae3bb..ce12f25553f 100644 --- a/backends/ebpf/psa/ebpfPipeline.cpp +++ b/backends/ebpf/psa/ebpfPipeline.cpp @@ -21,7 +21,7 @@ limitations under the License. namespace EBPF { bool EBPFPipeline::isEmpty() const { - // check if parser doesn't have any state + // Check if parser doesn't have any state // Why 3? Parser will always have at least start, accept and reject states. if (parser->parserBlock->container->states.size() > 3) { return false; @@ -34,12 +34,12 @@ bool EBPFPipeline::isEmpty() const { return false; } - // check if control is empty + // Check if control is empty if (!control->controlBlock->container->body->components.empty()) { return false; } - // check if deparser doesn't emit anything + // Check if deparser doesn't emit anything if (!deparser->controlBlock->container->body->components.empty()) { return false; } @@ -176,7 +176,7 @@ void EBPFPipeline::emitInputPortMapping(CodeBuilder *builder) { builder->appendFormat("if (%s == PSA_PORT_RECIRCULATE) ", inputPortVar.c_str()); builder->blockStart(); builder->emitIndent(); - // To be conformant with psa.p4, where PSA_PORT_RECIRCULATE is constant + // To be conformant with psa.p4, where PSA_PORT_RECIRCULATE is constant. builder->appendFormat("%s = P4C_PSA_PORT_RECIRCULATE", inputPortVar.c_str()); builder->endOfStatement(true); builder->blockEnd(true); @@ -223,7 +223,7 @@ void EBPFIngressPipeline::emitPSAControlOutputMetadata(CodeBuilder *builder) { void EBPFIngressPipeline::emit(CodeBuilder *builder) { cstring msgStr, varStr; - // firstly emit process() in-lined function and then the actual BPF section. + // Firstly emit process() in-lined function and then the actual BPF section. builder->append("static __always_inline"); builder->spc(); // FIXME: use Target to generate metadata type @@ -552,11 +552,9 @@ void TCIngressPipeline::emitTCWorkaroundUsingCPUMAP(CodeBuilder *builder) { " eth->h_proto = *orig_ethtype;\n"); } -/* - * The Traffic Manager for Ingress pipeline implements: - * - Multicast handling - * - send to port - */ +/// The Traffic Manager for Ingress pipeline implements: +/// - Multicast handling +/// - send to port void TCIngressPipeline::emitTrafficManager(CodeBuilder *builder) { cstring mcast_grp = Util::printf_format("%s.multicast_group", control->outputStandardMetadata->name.name); diff --git a/backends/ebpf/psa/ebpfPipeline.h b/backends/ebpf/psa/ebpfPipeline.h index 44d6546e430..85b38de2346 100644 --- a/backends/ebpf/psa/ebpfPipeline.h +++ b/backends/ebpf/psa/ebpfPipeline.h @@ -24,32 +24,30 @@ limitations under the License. namespace EBPF { -/* - * EBPFPipeline represents a single eBPF program in the TC/XDP hook. - */ +/// EBPFPipeline represents a single eBPF program in the TC/XDP hook. class EBPFPipeline : public EBPFProgram { public: - // a custom name of eBPF program + /// A custom name of eBPF program. cstring name; - // eBPF section name, which should a concatenation of `classifier/` + a custom name. + /// eBPF section name, which should a concatenation of `classifier/` + a custom name. cstring sectionName; - // Variable name storing pointer to eBPF packet descriptor (e.g., __sk_buff). + /// Variable name storing pointer to eBPF packet descriptor (e.g., __sk_buff). cstring contextVar; - // Variable name storing current timestamp retrieved from bpf_ktime_get_ns(). + /// Variable name storing current timestamp retrieved from bpf_ktime_get_ns(). cstring timestampVar; - // Variable storing ingress interface index. + /// Variable storing ingress interface index. cstring ifindexVar; - // Variable storing skb->priority value (TC only). + /// Variable storing skb->priority value (TC only). cstring priorityVar; - // Variables storing global metadata (packet_path & instance). + /// Variables storing global metadata (packet_path & instance). cstring packetPathVar, pktInstanceVar; - // A name of an internal variable storing global metadata. + /// A name of an internal variable storing global metadata. cstring compilerGlobalMetadata; - // A variable name storing "1" value. Used to access BPF array map index. + /// A variable name storing "1" value. Used to access BPF array map index. cstring oneKey; - // A unique mark used to differentiate packets processed by P4/eBPF from others. + /// A unique mark used to differentiate packets processed by P4/eBPF from others. unsigned packetMark; - // A variable to store ifindex after mapping (e.g. due to recirculation) + /// A variable to store ifindex after mapping (e.g. due to recirculation). cstring inputPortVar; EBPFControlPSA *control; @@ -81,8 +79,8 @@ class EBPFPipeline : public EBPFProgram { progTarget = new KernelSamplesTarget(options.emitTraceMessages); } - /* Check if pipeline does any processing. - * Return false if not. */ + /// Check if pipeline does any processing. + /// Return false if not. bool isEmpty() const; virtual cstring dropReturnCode() { @@ -107,25 +105,26 @@ class EBPFPipeline : public EBPFProgram { virtual void emitPSAControlInputMetadata(CodeBuilder *builder) = 0; virtual void emitPSAControlOutputMetadata(CodeBuilder *builder) = 0; - /* Generates a pointer to struct Headers_t and puts it on the BPF program's stack. */ + /// Generates a pointer to struct Headers_t and puts it on the BPF program's stack. void emitLocalHeaderInstancesAsPointers(CodeBuilder *builder); - /* Generates a pointer to struct hdr_md. The pointer is used to access data from per-CPU map. */ + /// Generates a pointer to struct hdr_md. The pointer is used to access data from per-CPU map. void emitCPUMAPHeadersInitializers(CodeBuilder *builder); - /* Generates an instance of struct Headers_t, - * allocated in the per-CPU map. */ + /// Generates an instance of struct Headers_t, + /// allocated in the per-CPU map. void emitHeaderInstances(CodeBuilder *builder) override; - /* Generates a set of helper variables that are used during packet processing. */ + /// Generates a set of helper variables that are used during packet processing. void emitLocalVariables(CodeBuilder *builder) override; - /* Generates and instance of user metadata for a pipeline, - * allocated in the per-CPU map. */ + /// Generates and instance of user metadata for a pipeline, + /// allocated in the per-CPU map. void emitUserMetadataInstance(CodeBuilder *builder); virtual void emitCPUMAPInitializers(CodeBuilder *builder); virtual void emitCPUMAPLookup(CodeBuilder *builder); - /* Generates a pointer to skb->cb and maps it to - * psa_global_metadata to access global metadata shared between pipelines. */ + /// Generates a pointer to skb->cb and maps it to + /// psa_global_metadata to access global metadata shared between pipelines. virtual void emitGlobalMetadataInitializer(CodeBuilder *builder); + virtual void emitPacketLength(CodeBuilder *builder); virtual void emitTimestamp(CodeBuilder *builder); void emitInputPortMapping(CodeBuilder *builder); @@ -141,27 +140,23 @@ class EBPFPipeline : public EBPFProgram { bool anyDirectMeter = directMeter != control->tables.end(); return anyDirectMeter || (!control->meters.empty()); } - /* - * Returns whether the compiler should generate - * timestamp retrieved by bpf_ktime_get_ns(). - * - * This allows to avoid overhead introduced by bpf_ktime_get_ns(), - * if the timestamp field is not used within a pipeline. - */ + /// Returns whether the compiler should generate + /// timestamp retrieved by bpf_ktime_get_ns(). + /// + /// This allows to avoid overhead introduced by bpf_ktime_get_ns(), + /// if the timestamp field is not used within a pipeline. bool shouldEmitTimestamp() const { return hasAnyMeter() || control->timestampIsUsed; } DECLARE_TYPEINFO(EBPFPipeline, EBPFProgram); }; -/* - * EBPFIngressPipeline represents a hook-independent EBPF-based ingress pipeline. - * It includes common definitions for TC and XDP. - */ +/// EBPFIngressPipeline represents a hook-independent EBPF-based ingress pipeline. +/// It includes common definitions for TC and XDP. class EBPFIngressPipeline : public EBPFPipeline { public: unsigned int maxResubmitDepth; - // actUnspecCode stores the "undefined action" value. - // It's returned from eBPF program is PSA-eBPF doesn't make any forwarding/drop decision. + //// actUnspecCode stores the "undefined action" value. + /// It's returned from eBPF program is PSA-eBPF doesn't make any forwarding/drop decision. int actUnspecCode; EBPFIngressPipeline(cstring name, const EbpfOptions &options, P4::ReferenceMap *refMap, @@ -183,10 +178,8 @@ class EBPFIngressPipeline : public EBPFPipeline { DECLARE_TYPEINFO(EBPFIngressPipeline, EBPFPipeline); }; -/* - * EBPFEgressPipeline represents a hook-independent EBPF-based egress pipeline. - * It includes common definitions for TC and XDP. - */ +/// EBPFEgressPipeline represents a hook-independent EBPF-based egress pipeline. +/// It includes common definitions for TC and XDP. class EBPFEgressPipeline : public EBPFPipeline { public: EBPFEgressPipeline(cstring name, const EbpfOptions &options, P4::ReferenceMap *refMap, diff --git a/backends/ebpf/psa/ebpfPsaControl.cpp b/backends/ebpf/psa/ebpfPsaControl.cpp index 756e37ff61e..79411b12bc1 100644 --- a/backends/ebpf/psa/ebpfPsaControl.cpp +++ b/backends/ebpf/psa/ebpfPsaControl.cpp @@ -106,7 +106,7 @@ void EBPFControlPSA::emitTableTypes(CodeBuilder *builder) { for (auto it : registers) it.second->emitTypes(builder); for (auto it : meters) it.second->emitKeyType(builder); - // Value type for any indirect meter is the same + // Value type for any indirect meter is the same. if (!meters.empty()) { meters.begin()->second->emitValueType(builder); } diff --git a/backends/ebpf/psa/ebpfPsaControl.h b/backends/ebpf/psa/ebpfPsaControl.h index 337cbc36417..a5ad690a332 100644 --- a/backends/ebpf/psa/ebpfPsaControl.h +++ b/backends/ebpf/psa/ebpfPsaControl.h @@ -57,7 +57,7 @@ class ActionTranslationVisitorPSA : public ActionTranslationVisitor, class EBPFControlPSA : public EBPFControl { public: - // Keeps track if ingress_timestamp or egress_timestamp is used within a control block. + /// Keeps track if ingress_timestamp or egress_timestamp is used within a control block. bool timestampIsUsed = false; const IR::Parameter *user_metadata; diff --git a/backends/ebpf/psa/ebpfPsaDeparser.cpp b/backends/ebpf/psa/ebpfPsaDeparser.cpp index de66314b089..4f41f9a6db2 100644 --- a/backends/ebpf/psa/ebpfPsaDeparser.cpp +++ b/backends/ebpf/psa/ebpfPsaDeparser.cpp @@ -129,12 +129,10 @@ bool EgressDeparserPSA::build() { } // =====================TCIngressDeparserPSA============================= -/* - * PreDeparser for Ingress pipeline implements: - * - packet cloning (using clone sessions) - * - early packet drop - * - resubmission - */ +/// PreDeparser for Ingress pipeline implements: +/// - packet cloning (using clone sessions) +/// - early packet drop +/// - resubmission void TCIngressDeparserPSA::emitPreDeparser(CodeBuilder *builder) { builder->emitIndent(); diff --git a/backends/ebpf/psa/ebpfPsaGen.cpp b/backends/ebpf/psa/ebpfPsaGen.cpp index f8d3ef60594..2d9b0fe2c4e 100644 --- a/backends/ebpf/psa/ebpfPsaGen.cpp +++ b/backends/ebpf/psa/ebpfPsaGen.cpp @@ -41,7 +41,7 @@ class PSAErrorCodesGen : public Inspector { ++id; if (decl->srcInfo.isValid()) { auto sourceFile = decl->srcInfo.getSourceFile(); - // all the error codes are located in core.p4 file, they are defined in psa.h + // All the error codes are located in core.p4 file, they are defined in psa.h if (sourceFile.endsWith("p4include/core.p4")) continue; } @@ -49,7 +49,7 @@ class PSAErrorCodesGen : public Inspector { builder->appendFormat("static const ParserError_t %s = %d", decl->name.name, id); builder->endOfStatement(true); - // type ParserError_t is u8, which can have values from 0 to 255 + // Type ParserError_t is u8, which can have values from 0 to 255. if (id > 255) { ::error(ErrorType::ERR_OVERLIMIT, "%1%: Reached maximum number of possible errors", decl); @@ -113,7 +113,7 @@ void PSAEbpfGenerator::emitInternalStructures(CodeBuilder *builder) const { builder->newline(); } -/* Generate headers and structs in p4 prog */ +/// Generate headers and structs in p4 prog. void PSAEbpfGenerator::emitTypes(CodeBuilder *builder) const { PSAErrorCodesGen errorGen(builder); ingress->program->apply(errorGen); @@ -149,7 +149,7 @@ void PSAEbpfGenerator::emitGlobalHeadersMetadata(CodeBuilder *builder) const { userMetadataType->declare(builder, "cpumap_usermeta", false); builder->endOfStatement(true); - // additional field to avoid compiler errors when both headers and user_metadata are empty. + // Additional field to avoid compiler errors when both headers and user_metadata are empty. builder->emitIndent(); builder->append("__u8 __hook"); builder->endOfStatement(true); @@ -239,7 +239,7 @@ void PSAEbpfGenerator::emitHelperFunctions(CodeBuilder *builder) const { builder->appendLine(forEachFunc); builder->newline(); - // Function to perform cloning, common for ingress and egress + // Function to perform cloning, common for ingress and egress. cstring cloneFunction = "static __always_inline\n" "void do_clone(SK_BUFF *skb, void *data)\n" @@ -417,19 +417,17 @@ void PSAEbpfGenerator::emitCRC32LookupTableInitializer(CodeBuilder *builder) con // =====================PSAArchTC============================= void PSAArchTC::emit(CodeBuilder *builder) const { - /** - * How the structure of a single C program for PSA should look like? - * 1. Automatically generated comment - * 2. Includes - * 3. Macro definitions (it's called "preamble") - * 4. Headers, structs, types, PSA-specific data types. - * 5. BPF map definitions. - * 6. BPF map initialization - * 7. XDP helper program. - * 8. Helper functions - * 9. TC Ingress program. - * 10. TC Egress program. - */ + // How the structure of a single C program for PSA should look like? + // 1. Automatically generated comment + // 2. Includes + // 3. Macro definitions (it's called "preamble") + // 4. Headers, structs, types, PSA-specific data types. + // 5. BPF map definitions. + // 6. BPF map initialization + // 7. XDP helper program. + // 8. Helper functions + // 9. TC Ingress program. + // 10. TC Egress program. // 1. Automatically generated comment. // Note we use inherited function from EBPFProgram. @@ -441,47 +439,31 @@ void PSAArchTC::emit(CodeBuilder *builder) const { builder->target->emitIncludes(builder); emitPSAIncludes(builder); - /* - * 3. Macro definitions (it's called "preamble") - */ + // 3. Macro definitions (it's called "preamble") emitPreamble(builder); - /* - * 4. Headers, structs, types, PSA-specific data types. - */ + // 4. Headers, structs, types, PSA-specific data types. emitInternalStructures(builder); emitTypes(builder); emitGlobalHeadersMetadata(builder); - /* - * 5. BPF map definitions. - */ + // 5. BPF map definitions. emitInstances(builder); - /* - * 6. Helper functions for ingress and egress program. - */ + // 6. Helper functions for ingress and egress program. emitHelperFunctions(builder); - /* - * 7. BPF map initialization. - */ + // 7. BPF map initialization. emitInitializer(builder); builder->newline(); - /* - * 8. XDP helper program. - */ + // 8. XDP helper program. xdp->emit(builder); - /* - * 9. TC Ingress program. - */ + // 9. TC Ingress program. ingress->emit(builder); - /* - * 10. TC Egress program. - */ + // 10. TC Egress program. if (!egress->isEmpty()) { // Do not generate TC Egress program if PSA egress pipeline is not used (empty). egress->emit(builder); diff --git a/backends/ebpf/psa/ebpfPsaGen.h b/backends/ebpf/psa/ebpfPsaGen.h index d2bd3c1df80..e3159000fe8 100644 --- a/backends/ebpf/psa/ebpfPsaGen.h +++ b/backends/ebpf/psa/ebpfPsaGen.h @@ -72,7 +72,7 @@ class PSAEbpfGenerator : public EbpfCodeGenerator { virtual void emitInitializerSection(CodeBuilder *builder) const = 0; void emitHelperFunctions(CodeBuilder *builder) const; - // TODO: move them to the externs/ebpfPsaHashAlgorithm.cpp file + /// TODO: move them to the externs/ebpfPsaHashAlgorithm.cpp file void emitCRC32LookupTableTypes(CodeBuilder *builder) const; void emitCRC32LookupTableInitializer(CodeBuilder *builder) const; void emitCRC32LookupTableInstance(CodeBuilder *builder) const; @@ -94,9 +94,9 @@ class PSAArchTC : public PSAEbpfGenerator { class PSAArchXDP : public PSAEbpfGenerator { public: - // TC Ingress program used to support packet cloning in the XDP mode. + /// TC Ingress program used to support packet cloning in the XDP mode. EBPFPipeline *tcIngressForXDP; - // If the XDP mode is used, we need to have TC Egress pipeline to handle cloned packets. + /// If the XDP mode is used, we need to have TC Egress pipeline to handle cloned packets. EBPFPipeline *tcEgressForXDP; static const unsigned egressDevmapSize = 256; diff --git a/backends/ebpf/psa/ebpfPsaTable.cpp b/backends/ebpf/psa/ebpfPsaTable.cpp index 6b941b3c582..e77101579fc 100644 --- a/backends/ebpf/psa/ebpfPsaTable.cpp +++ b/backends/ebpf/psa/ebpfPsaTable.cpp @@ -31,9 +31,9 @@ class EBPFTablePsaPropertyVisitor : public Inspector { public: explicit EBPFTablePsaPropertyVisitor(EBPFTablePSA *table) : table(table) {} - // Use these two preorders to print error when property contains something other than name of - // extern instance. ListExpression is required because without it Expression will take - // precedence over it and throw error for whole list. + /// Use these two preorders to print error when property contains something other than name of + /// extern instance. ListExpression is required because without it Expression will take + /// precedence over it and throw error for whole list. bool preorder(const IR::ListExpression *) override { return true; } bool preorder(const IR::Expression *expr) override { ::error(ErrorType::ERR_UNSUPPORTED, @@ -105,8 +105,8 @@ class EBPFTablePSAImplementationPropertyVisitor : public EBPFTablePsaPropertyVis explicit EBPFTablePSAImplementationPropertyVisitor(EBPFTablePSA *table) : EBPFTablePsaPropertyVisitor(table) {} - // PSA table is allowed to have up to one table implementation. This visitor - // will iterate over all entries in property, so lets use this and print errors. + /// PSA table is allowed to have up to one table implementation. This visitor + /// will iterate over all entries in property, so lets use this and print errors. bool preorder(const IR::PathExpression *pe) override { auto decl = table->program->refMap->getDeclaration(pe->path, true); auto di = decl->to(); @@ -137,8 +137,8 @@ class EBPFTablePSAImplementationPropertyVisitor : public EBPFTablePsaPropertyVis } }; -// Generator for table key/value initializer value (const entries). Can't be used during table -// lookup because this inspector expects only constant values as initializer. +/// Generator for table key/value initializer value (const entries). Can't be used during table +/// lookup because this inspector expects only constant values as initializer. class EBPFTablePSAInitializerCodeGen : public CodeGenInspector { protected: unsigned currentKeyEntryIndex = 0; @@ -189,7 +189,7 @@ class EBPFTablePSAInitializerCodeGen : public CodeGenInspector { return false; } - // {pre,post}orders for table key initializer + /// {pre,post}orders for table key initializer bool preorder(const IR::Key *) override { BUG_CHECK(table->keyGenerator->keyElements.size() == currentEntry->keys->size(), "Entry key size does not match table key size"); @@ -252,7 +252,7 @@ class EBPFTablePSAInitializerCodeGen : public CodeGenInspector { } void postorder(const IR::Key *) override { builder->blockEnd(false); } - // preorder for value table value initializer + /// preorder for value table value initializer bool preorder(const IR::MethodCallExpression *mce) override { auto mi = P4::MethodInstance::resolve(mce, refMap, typeMap); auto ac = mi->to(); @@ -280,13 +280,13 @@ class EBPFTablePSAInitializerCodeGen : public CodeGenInspector { bool preorder(const IR::PathExpression *p) override { return notSupported(p); } }; -// Generate mask for whole table key +/// Generate mask for whole table key class EBPFTablePSATernaryTableMaskGenerator : public Inspector { protected: P4::ReferenceMap *refMap; P4::TypeMap *typeMap; - // Mask generation is done using string concatenation, - // so use std::string as it behave better in this case than cstring. + /// Mask generation is done using string concatenation, + /// so use std::string as it behave better in this case than cstring. std::string mask; public: @@ -315,7 +315,7 @@ class EBPFTablePSATernaryTableMaskGenerator : public Inspector { } }; -// Build mask initializer for a single table key entry +/// Build mask initializer for a single table key entry. class EBPFTablePSATernaryKeyMaskGenerator : public EBPFTablePSAInitializerCodeGen { public: EBPFTablePSATernaryKeyMaskGenerator(P4::ReferenceMap *refMap, P4::TypeMap *typeMap) @@ -542,10 +542,8 @@ void EBPFTablePSA::emitTypes(CodeBuilder *builder) { emitCacheTypes(builder); } -/** - * Order of emitting counters and meters affects generated layout of BPF map value. - * Do not change this order! - */ +/// Order of emitting counters and meters affects generated layout of BPF map value. +/// Do not change this order! void EBPFTablePSA::emitDirectValueTypes(CodeBuilder *builder) { for (auto ctr : counters) { ctr.second->emitValueType(builder); @@ -861,12 +859,10 @@ void EBPFTablePSA::emitValueMask(CodeBuilder *builder, const cstring valueMask, } } -/** - * This method groups entries with the same prefix into separate lists. - * For example four entries which have two different masks - * will give as a result a list of two list (each with two entries). - * @return a vector of vectors with const entries that have the same prefix - */ +/// This method groups entries with the same prefix into separate lists. +/// For example four entries which have two different masks +/// will give as a result a list of two list (each with two entries). +/// @return a vector of vectors with const entries that have the same prefix. EBPFTablePSA::EntriesGroupedByMask_t EBPFTablePSA::getConstEntriesGroupedByMask() { EntriesGroupedByMask_t result; const IR::EntriesList *entries = table->container->getEntries(); diff --git a/backends/ebpf/psa/ebpfPsaTable.h b/backends/ebpf/psa/ebpfPsaTable.h index 46939807a86..5161e361922 100644 --- a/backends/ebpf/psa/ebpfPsaTable.h +++ b/backends/ebpf/psa/ebpfPsaTable.h @@ -68,8 +68,8 @@ class EBPFTablePSA : public EBPFTable { std::vector &keyNames, std::vector &valueNames); public: - // We use vectors to keep an order of Direct Meters or Counters from a P4 program. - // This order is important from CLI tool point of view. + /// We use vectors to keep an order of Direct Meters or Counters from a P4 program. + /// This order is important from CLI tool point of view. std::vector> counters; std::vector> meters; EBPFTableImplementationPSA *implementation; diff --git a/backends/ebpf/psa/externs/ebpfPsaChecksum.cpp b/backends/ebpf/psa/externs/ebpfPsaChecksum.cpp index ff1187b8874..c90a9eecd53 100644 --- a/backends/ebpf/psa/externs/ebpfPsaChecksum.cpp +++ b/backends/ebpf/psa/externs/ebpfPsaChecksum.cpp @@ -96,9 +96,7 @@ void EBPFHashPSA::processMethod(CodeBuilder *builder, cstring method, } } -/** - * This method calculates a hash value and saves it to the registerVar. - */ +/// This method calculates a hash value and saves it to the registerVar. void EBPFHashPSA::calculateHash(CodeBuilder *builder, const IR::MethodCallExpression *expr, Visitor *visitor) { engine->setVisitor(visitor); diff --git a/backends/ebpf/psa/externs/ebpfPsaDigest.cpp b/backends/ebpf/psa/externs/ebpfPsaDigest.cpp index 643a6f5c775..aa14abc1686 100644 --- a/backends/ebpf/psa/externs/ebpfPsaDigest.cpp +++ b/backends/ebpf/psa/externs/ebpfPsaDigest.cpp @@ -35,21 +35,21 @@ class EBPFDigestPSAValueVisitor : public CodeGenInspector { codegen(codegen), valueType(valueType) {} - // handle expression like: "digest.pack(msg)", where "msg" is an existing variable + /// Handle expression like: "digest.pack(msg)", where "msg" is an existing variable. bool preorder(const IR::PathExpression *pe) override { digest->emitPushElement(builder, pe, codegen); return false; } - // handle expression like: "digest.pack(metadata.msg)", where "metadata.msg" is a member from an - // instance of struct or header + /// Handle expression like: "digest.pack(metadata.msg)", where "metadata.msg" is a member from + /// an instance of struct or header. bool preorder(const IR::Member *member) override { digest->emitPushElement(builder, member, codegen); return false; } - // handle expression like: "digest.pack(value)", where "value" is compile time known constant - // value + /// handle expression like: "digest.pack(value)", where "value" is compile time known constant + /// value. bool preorder(const IR::Constant *c) override { cstring tmpVar = refMap->newName("digest_entry"); @@ -68,8 +68,8 @@ class EBPFDigestPSAValueVisitor : public CodeGenInspector { return false; } - // handle expression like: "digest.pack({ expr1, expr2, ... })", where "exprN" is an any valid - // expression at this context + /// Handle expression like: "digest.pack({ expr1, expr2, ... })", where "exprN" is an any valid + /// expression at this context. bool preorder(const IR::StructExpression *se) override { cstring tmpVar = refMap->newName("digest_entry"); diff --git a/backends/ebpf/psa/externs/ebpfPsaDigest.h b/backends/ebpf/psa/externs/ebpfPsaDigest.h index 5e9823036e2..a7cdc22475f 100644 --- a/backends/ebpf/psa/externs/ebpfPsaDigest.h +++ b/backends/ebpf/psa/externs/ebpfPsaDigest.h @@ -31,8 +31,8 @@ class EBPFDigestPSA : public EBPFObject { EBPFType *valueType; cstring valueTypeName; const IR::Declaration_Instance *declaration; - // arbitrary value for max queue size - // TODO: make it configurable + /// arbitrary value for max queue size + /// TODO: make it configurable int maxDigestQueueSize = 128; public: diff --git a/backends/ebpf/psa/externs/ebpfPsaHashAlgorithm.cpp b/backends/ebpf/psa/externs/ebpfPsaHashAlgorithm.cpp index 16ee7d8b48e..5375a0dd74a 100644 --- a/backends/ebpf/psa/externs/ebpfPsaHashAlgorithm.cpp +++ b/backends/ebpf/psa/externs/ebpfPsaHashAlgorithm.cpp @@ -215,21 +215,19 @@ void CRCChecksumAlgorithm::emitClear(CodeBuilder *builder) { builder->endOfStatement(true); } -/* - * This method generates a C code that is responsible for updating - * a CRC check value from a given data. - * - * From following P4 code: - * Checksum>(PSA_HashAlgorithm_t.CRC32) checksum; - * checksum.update(parsed_hdr.crc.f1); - * There will be generated a C code: - * crc32_update(&c_0_reg, (u8 *) &(parsed_hdr->crc.f1), 5, 0xEDB88320); - * Where: - * c_0_reg - a checksum internal state (CRC register) - * parsed_hdr->field1 - a data on which CRC is calculated - * 5 - a field size in bytes - * 0xEDB88320 - a polynomial in a reflected bit order. - */ +/// This method generates a C code that is responsible for updating +/// a CRC check value from a given data. +/// +/// From following P4 code: +/// Checksum>(PSA_HashAlgorithm_t.CRC32) checksum; +/// checksum.update(parsed_hdr.crc.f1); +/// There will be generated a C code: +/// crc32_update(&c_0_reg, (u8 *) &(parsed_hdr->crc.f1), 5, 0xEDB88320); +/// Where: +/// c_0_reg - a checksum internal state (CRC register) +/// parsed_hdr->field1 - a data on which CRC is calculated +/// 5 - a field size in bytes +/// 0xEDB88320 - a polynomial in a reflected bit order. void CRCChecksumAlgorithm::emitAddData(CodeBuilder *builder, const ArgumentsList &arguments) { cstring tmpVar = program->refMap->newName(baseName + "_tmp"); @@ -250,7 +248,7 @@ void CRCChecksumAlgorithm::emitAddData(CodeBuilder *builder, const ArgumentsList } const int width = fieldType->width_bits(); - // We concatenate less than 8-bit fields into one byte + // We concatenate less than 8-bit fields into one byte. if (width < 8 || concatenateBits) { concatenateBits = true; if (width > remainingBits) { @@ -395,7 +393,7 @@ void InternetChecksumAlgorithm::updateChecksum(CodeBuilder *builder, const Argum // Let's convert internal array into an array of u16 and calc csum for such entries. // Byte order conversion is required, because csum is calculated in host byte order - // but data is preserved in network byte order + // but data is preserved in network byte order. const unsigned arrayEntries = width / 16; for (unsigned i = 0; i < arrayEntries; ++i) { builder->emitIndent(); @@ -426,7 +424,7 @@ void InternetChecksumAlgorithm::updateChecksum(CodeBuilder *builder, const Argum builder->append(" | "); } - // TODO: add masks for fields, however they should not exceed declared width + // TODO: add masks for fields, however they should not exceed declared width. if (bitsToRead < remainingBits) { remainingBits -= bitsToRead; builder->append("("); diff --git a/backends/ebpf/psa/externs/ebpfPsaHashAlgorithm.h b/backends/ebpf/psa/externs/ebpfPsaHashAlgorithm.h index e3005f59cc0..ed37042fe3e 100644 --- a/backends/ebpf/psa/externs/ebpfPsaHashAlgorithm.h +++ b/backends/ebpf/psa/externs/ebpfPsaHashAlgorithm.h @@ -35,7 +35,7 @@ class EBPFHashAlgorithmPSA : public EBPFObject { ArgumentsList unpackArguments(const IR::MethodCallExpression *expr, int dataPos); public: - // keep this enum in sync with psa.p4 file + /// Keep this enum in sync with psa.p4 file. enum HashAlgorithm { IDENTITY, CRC32, @@ -53,7 +53,7 @@ class EBPFHashAlgorithmPSA : public EBPFObject { virtual unsigned getOutputWidth() const { return 0; } - // decl might be a null pointer + /// decl might be a null pointer virtual void emitVariables(CodeBuilder *builder, const IR::Declaration_Instance *decl) = 0; virtual void emitClear(CodeBuilder *builder) = 0; @@ -100,14 +100,12 @@ class CRCChecksumAlgorithm : public EBPFHashAlgorithmPSA { void emitSetInternalState(CodeBuilder *builder, const IR::MethodCallExpression *expr) override; }; -/** - * For CRC16 calculation we use a polynomial 0x8005. - * - updateMethod adds a data to the checksum - * and performs a CRC16 calculation - * - finalizeMethod returns the CRC16 result - * - * Above C functions are emitted via emitGlobals. - */ +/// For CRC16 calculation we use a polynomial 0x8005. +/// - updateMethod adds a data to the checksum +/// and performs a CRC16 calculation +/// - finalizeMethod returns the CRC16 result +/// +/// Above C functions are emitted via emitGlobals. class CRC16ChecksumAlgorithm : public CRCChecksumAlgorithm { public: CRC16ChecksumAlgorithm(const EBPFProgram *program, cstring name) @@ -123,15 +121,13 @@ class CRC16ChecksumAlgorithm : public CRCChecksumAlgorithm { static void emitGlobals(CodeBuilder *builder); }; -/** - * For CRC32 calculation we use a polynomial 0x04C11DB7. - * - updateMethod adds a data to the checksum - * and performs a CRC32 calculation - * - finalizeMethod finalizes a CRC32 calculation - * and returns the CRC32 result - * - * Above C functions are emitted via emitGlobals. - */ +/// For CRC32 calculation we use a polynomial 0x04C11DB7. +/// - updateMethod adds a data to the checksum +/// and performs a CRC32 calculation +/// - finalizeMethod finalizes a CRC32 calculation +/// and returns the CRC32 result +/// +/// Above C functions are emitted via emitGlobals. class CRC32ChecksumAlgorithm : public CRCChecksumAlgorithm { public: CRC32ChecksumAlgorithm(const EBPFProgram *program, cstring name) diff --git a/backends/ebpf/psa/externs/ebpfPsaRegister.cpp b/backends/ebpf/psa/externs/ebpfPsaRegister.cpp index ef89a0a9540..e065e05e276 100644 --- a/backends/ebpf/psa/externs/ebpfPsaRegister.cpp +++ b/backends/ebpf/psa/externs/ebpfPsaRegister.cpp @@ -67,7 +67,7 @@ bool EBPFRegisterPSA::shouldUseArrayMap() { if (auto wt = this->keyType->to()) { unsigned keyWidth = wt->widthInBits(); // For keys <= 32 bit register is based on array map, - // otherwise we use hash map + // otherwise we use hash map. return (keyWidth > 0 && keyWidth <= 32); } @@ -97,13 +97,13 @@ void EBPFRegisterPSA::emitValueType(CodeBuilder *builder) { void EBPFRegisterPSA::emitInitializer(CodeBuilder *builder) { if (!shouldUseArrayMap()) { - // initialize array-based Registers only, + // Initialize array-based Registers only, // hash-based Registers are "lazy-initialized", upon a first lookup to the map. return; } if (this->initialValue == nullptr || this->initialValue->value.is_zero()) { - // for array maps, initialize only if an initial value is provided by a developer, + // For array maps, initialize only if an initial value is provided by a developer, // or if an initial value doesn't equal 0. Otherwise, array map is already zero-initialized. return; } @@ -190,7 +190,7 @@ void EBPFRegisterPSA::emitRegisterRead(CodeBuilder *builder, const P4::ExternMet if (leftExpression != nullptr) { if (initialValue != nullptr || leftExpression->type->is()) { - // let's create fake assigment statement and use it to generate valid code + // Let's create fake assigment statement and use it to generate valid code. const IR::Expression *right = initialValue != nullptr ? initialValue : new IR::Constant(leftExpression->type, 0); const auto *assigment = new IR::AssignmentStatement(leftExpression, right); diff --git a/backends/ebpf/psa/externs/ebpfPsaRegister.h b/backends/ebpf/psa/externs/ebpfPsaRegister.h index ace20d15a02..048f79182ee 100644 --- a/backends/ebpf/psa/externs/ebpfPsaRegister.h +++ b/backends/ebpf/psa/externs/ebpfPsaRegister.h @@ -27,8 +27,8 @@ class ControlBodyTranslatorPSA; class EBPFRegisterPSA : public EBPFTableBase { protected: size_t size; - // initial value for Register cells. - // It can be nullptr if an initial value is not provided or not IR::Constant. + /// Initial value for Register cells. + /// It can be nullptr if an initial value is not provided or not IR::Constant. const IR::Constant *initialValue = nullptr; const IR::Type *keyArg; const IR::Type *valueArg; diff --git a/backends/ebpf/psa/externs/ebpfPsaTableImplementation.cpp b/backends/ebpf/psa/externs/ebpfPsaTableImplementation.cpp index a173f3ed390..0d265576a6e 100644 --- a/backends/ebpf/psa/externs/ebpfPsaTableImplementation.cpp +++ b/backends/ebpf/psa/externs/ebpfPsaTableImplementation.cpp @@ -45,17 +45,17 @@ void EBPFTableImplementationPSA::emitReferenceEntry(CodeBuilder *builder) { } void EBPFTableImplementationPSA::registerTable(const EBPFTablePSA *instance) { - // verify table instance + // Verify table instance. verifyTableNoEntries(instance); verifyTableNoDefaultAction(instance); verifyTableNoDirectObjects(instance); if (table == nullptr) { - // no other tables at the moment, take it as a reference + // No other tables at the moment, take it as a reference. table = instance->table; actionList = instance->actionList; } else { - // another table, check that new instance has the same action list + // Another table, check that new instance has the same action list. verifyTableActionList(instance); } } diff --git a/backends/ebpf/psa/externs/ebpfPsaTableImplementation.h b/backends/ebpf/psa/externs/ebpfPsaTableImplementation.h index 42aa9856e57..b546630ad6f 100644 --- a/backends/ebpf/psa/externs/ebpfPsaTableImplementation.h +++ b/backends/ebpf/psa/externs/ebpfPsaTableImplementation.h @@ -24,7 +24,7 @@ limitations under the License. namespace EBPF { -// Base class for ActionProfile and ActionSelector +/// Base class for ActionProfile and ActionSelector. class EBPFTableImplementationPSA : public EBPFTablePSA { public: EBPFTableImplementationPSA(const EBPFProgram *program, CodeGenInspector *codeGen, diff --git a/backends/ebpf/psa/xdpHelpProgram.h b/backends/ebpf/psa/xdpHelpProgram.h index e55a4b8dd1b..760e2156a6b 100644 --- a/backends/ebpf/psa/xdpHelpProgram.h +++ b/backends/ebpf/psa/xdpHelpProgram.h @@ -108,7 +108,7 @@ class XDPHelpProgram : public EBPFProgram { builder->spc(); builder->blockStart(); builder->emitIndent(); - // this is static program, so we can just paste a piece of code. + // This is static program, so we can just paste a piece of code. if (options.xdp2tcMode == XDP2TC_META) { builder->appendLine(XDPProgUsingMetaForXDP2TC); } else if (options.xdp2tcMode == XDP2TC_HEAD) { diff --git a/backends/ebpf/runtime/ebpf_common.h b/backends/ebpf/runtime/ebpf_common.h index c5406b9aa10..a22f21c0998 100644 --- a/backends/ebpf/runtime/ebpf_common.h +++ b/backends/ebpf/runtime/ebpf_common.h @@ -33,10 +33,8 @@ typedef signed long long s64; typedef unsigned long long u64; -/* - * Helper function. - * Print a byte buffer according to the specified length. - */ +/// Helper function. +/// Print a byte buffer according to the specified length. static inline void print_n_bytes(void *receiveBuffer, int num) { for (int i = 0; i < num; i++) printf("%02x", ((unsigned char *)receiveBuffer)[i]); diff --git a/backends/ebpf/runtime/ebpf_kernel.h b/backends/ebpf/runtime/ebpf_kernel.h index 1fd64806eea..f50cd05c2ad 100644 --- a/backends/ebpf/runtime/ebpf_kernel.h +++ b/backends/ebpf/runtime/ebpf_kernel.h @@ -14,12 +14,10 @@ See the License for the specific language governing permissions and limitations under the License. */ -/* - * This file contains all functions and definitions necessary for the kernel target C - * code to compile. It must be included with any file generated by the p4c-ebpf kernel - * compiler. - */ +/// This file contains all functions and definitions necessary for the kernel target C +/// code to compile. It must be included with any file generated by the p4c-ebpf kernel +/// compiler. #ifndef BACKENDS_EBPF_RUNTIME_EBPF_KERNEL_H_ #define BACKENDS_EBPF_RUNTIME_EBPF_KERNEL_H_ @@ -42,12 +40,10 @@ limitations under the License. #define load_word(data, b) bpf_ntohl(*(u32 *)((u8*)(data) + (b))) #define load_dword(data, b) bpf_be64_to_cpu(*(u64 *)((u8*)(data) + (b))) - -/* If we operate in user space we only need to include bpf.h and - * define the userspace API macros. - * For kernel programs we need to specify a list of kernel helpers. These are - * taken from here: https://github.com/torvalds/linux/blob/master/tools/testing/selftests/bpf/bpf_helpers.h - */ +/// If we operate in user space we only need to include bpf.h and +/// define the userspace API macros. +/// For kernel programs we need to specify a list of kernel helpers. These are +/// taken from here: https://github.com/torvalds/linux/blob/master/tools/testing/selftests/bpf/bpf_helpers.h #ifdef CONTROL_PLANE // BEGIN EBPF USER SPACE DEFINITIONS #include // bpf_obj_get/pin, bpf_map_update_elem @@ -64,10 +60,9 @@ limitations under the License. // This file contains the definitions of all the kernel bpf essentials #include -/* a helper structure used by an eBPF C program - * to describe map attributes for the elf_bpf loader - * FIXME: We only need this because we are loading with iproute2 - */ +/// A helper structure used by an eBPF C program +/// to describe map attributes for the elf_bpf loader +/// FIXME: We only need this because we are loading with iproute2 struct bpf_elf_map { __u32 type; __u32 size_key; @@ -80,10 +75,10 @@ struct bpf_elf_map { __u32 inner_idx; }; -/* simple descriptor which replaces the kernel sk_buff structure */ +/// Simple descriptor which replaces the kernel sk_buff structure. #define SK_BUFF struct __sk_buff -/* from iproute2, annotate table with BTF which allows to read types at runtime */ +/// From iproute2, annotate table with BTF which allows to read types at runtime. #define BPF_ANNOTATE_KV_PAIR(name, type_key, type_val) \ struct ____btf_map_##name { \ type_key key; \ @@ -95,7 +90,7 @@ struct bpf_elf_map { #define REGISTER_START() #ifndef BTF -/* Note: pinning exports the table name globally, do not remove */ +/// Note: pinning exports the table name globally, do not remove. #define REGISTER_TABLE(NAME, TYPE, KEY_TYPE, VALUE_TYPE, MAX_ENTRIES) \ struct bpf_elf_map SEC("maps") NAME = { \ .type = TYPE, \ diff --git a/backends/ebpf/runtime/ebpf_map.c b/backends/ebpf/runtime/ebpf_map.c index 53b3044783c..19fdcd0b6bf 100644 --- a/backends/ebpf/runtime/ebpf_map.c +++ b/backends/ebpf/runtime/ebpf_map.c @@ -14,10 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -/* -Implementation of userlevel eBPF map structure. Emulates the linux kernel bpf maps. -*/ - +/// Implementation of userlevel eBPF map structure. Emulates the linux kernel bpf maps. #include #include #include "ebpf_map.h" @@ -30,13 +27,13 @@ enum bpf_flags { static int check_flags(void *elem, unsigned long long map_flags) { if (map_flags > USER_BPF_EXIST) - /* unknown flags */ + // unknown flags return EXIT_FAILURE; if (elem && map_flags == USER_BPF_NOEXIST) - /* elem already exists */ + // elem already exists return EXIT_FAILURE; if (!elem && map_flags == USER_BPF_EXIST) - /* elem doesn't exist, cannot update it */ + // elem doesn't exist, cannot update it return EXIT_FAILURE; return EXIT_SUCCESS; } diff --git a/backends/ebpf/runtime/ebpf_map.h b/backends/ebpf/runtime/ebpf_map.h index 635534b1421..3c1cc46ccc8 100644 --- a/backends/ebpf/runtime/ebpf_map.h +++ b/backends/ebpf/runtime/ebpf_map.h @@ -14,11 +14,9 @@ See the License for the specific language governing permissions and limitations under the License. */ -/* - * This file defines a library of simple hashmap operations which emulate the behavior - * of the kernel ebpf map API. This library is currently not thread-safe. - */ +/// This file defines a library of simple hashmap operations which emulate the behavior +/// of the kernel ebpf map API. This library is currently not thread-safe. #ifndef BACKENDS_EBPF_RUNTIME_EBPF_MAP_H_ #define BACKENDS_EBPF_RUNTIME_EBPF_MAP_H_ @@ -30,41 +28,33 @@ struct bpf_map { UT_hash_handle hh; // makes this structure hashable }; -/** - * @brief Add/Update a value in the map - * @details Updates a value in the map based on the provided key. - * If the key does not exist, it depends the provided flags if the - * element is added or the operation is rejected. - * - * @return EXIT_FAILURE if update operation fails - */ +/// @brief Add/Update a value in the map +/// @details Updates a value in the map based on the provided key. +/// If the key does not exist, it depends on the provided flags if the +/// element is added or the operation is rejected. +/// +/// @return EXIT_FAILURE if update operation fails int bpf_map_update_elem(struct bpf_map **map, void *key, unsigned int key_size, void *value,unsigned int value_size, unsigned long long flags); -/** - * @brief Find a value based on a key. - * @details Provides a pointer to a value in the map based on the provided key. - * If the key does not exist, NULL is returned. - * - * @return NULL if key does not exist - */ +/// @brief Find a value based on a key. +/// @details Provides a pointer to a value in the map based on the provided key. +/// If the key does not exist, NULL is returned. +/// +/// @return NULL if key does not exist void *bpf_map_lookup_elem(struct bpf_map *map, void *key, unsigned int key_size); -/** - * @brief Delete key and value from the map. - * @details Deletes the key and the corresponding value from the map. - * If the key does not exist, no operation is performed. - * - * @return EXIT_FAILURE if operation fails. - */ +/// @brief Delete key and value from the map. +/// @details Deletes the key and the corresponding value from the map. +/// If the key does not exist, no operation is performed. +/// +/// @return EXIT_FAILURE if operation fails. int bpf_map_delete_elem(struct bpf_map *map, void *key, unsigned int key_size); -/** - * @brief Delete the entire map at once. - * @details Deletes all the keys and values in the map. - * Also frees all the values allocated with the map. - * - * @return EXIT_FAILURE if operation fails. - */ +/// @brief Delete the entire map at once. +/// @details Deletes all the keys and values in the map. +/// Also frees all the values allocated with the map. +/// +/// @return EXIT_FAILURE if operation fails. int bpf_map_delete_map(struct bpf_map *map); diff --git a/backends/ebpf/runtime/ebpf_registry.c b/backends/ebpf/runtime/ebpf_registry.c index d89f255ae12..8afbfc7fb5c 100644 --- a/backends/ebpf/runtime/ebpf_registry.c +++ b/backends/ebpf/runtime/ebpf_registry.c @@ -14,18 +14,13 @@ See the License for the specific language governing permissions and limitations under the License. */ -/* -Implementation of ebpf registry. Intended to provide a common access interface between control and data plane. Emulates the linux userspace API which can access the kernel eBPF map using string and integer identifiers. -*/ - +/// Implementation of ebpf registry. Intended to provide a common access interface between control and data plane. Emulates the linux userspace API which can access the kernel eBPF map using string and integer identifiers. #include #include "ebpf_registry.h" -/** - * @brief Defines the structure of the central registry. - * @details Defines a registry type, which maps names to tables - * as well as integer identifiers. - */ +/// @brief Defines the structure of the central registry. +/// @details Defines a registry type, which maps names to tables +/// as well as integer identifiers. typedef struct { char name[MAX_TABLE_NAME_LENGTH]; // name of the map struct bpf_table *tbl; // ptr to the map @@ -36,7 +31,7 @@ typedef struct { static int table_indexer = 0; -/* Instantiation of the central registry by id and name */ +// Instantiation of the central registry by id and name static registry_entry *reg_tables_name = NULL; static registry_entry *reg_tables_id = NULL; @@ -51,28 +46,28 @@ static registry_entry *find_register(const char *name) { } int registry_add(struct bpf_table *tbl) { - /* Check if the register exists already */ + // Check if the register exists already registry_entry *tmp_reg = find_register(tbl->name); if (tmp_reg != NULL) { fprintf(stderr, "Error: Table %s already exists!\n", tbl->name); return EXIT_FAILURE; } - /* Check key maximum length */ + // Check key maximum length if (strlen(tbl->name) > MAX_TABLE_NAME_LENGTH) { fprintf(stderr, "Error: Key name %s exceeds maximum size %d", tbl->name, MAX_TABLE_NAME_LENGTH); return EXIT_FAILURE; } - /* Add the table */ + // Add the table tmp_reg = malloc(sizeof(registry_entry)); if (!tmp_reg) { perror("Fatal: Could not allocate memory\n"); exit(EXIT_FAILURE); } - /* Do not forget to actually copy the values to the entry... */ + // Do not forget to actually copy the values to the entry... memcpy(tmp_reg->name, tbl->name, strlen(tbl->name)); tmp_reg->handle = table_indexer; tmp_reg->tbl = tbl; - /* Add the id and name to the registry. */ + // Add the id and name to the registry. HASH_ADD(h_name, reg_tables_name, name, strlen(tbl->name), tmp_reg); HASH_ADD(h_id, reg_tables_id, handle, sizeof(int), tmp_reg); table_indexer++; @@ -123,7 +118,7 @@ struct bpf_table *registry_lookup_table_id(int tbl_id) { int registry_update_table(const char *name, void *key, void *value, unsigned long long flags) { struct bpf_table *tmp_tbl = registry_lookup_table(name); if (tmp_tbl == NULL) - /* not found, return */ + // not found, return return EXIT_FAILURE; return bpf_map_update_elem(&tmp_tbl->bpf_map, key, tmp_tbl->key_size, value, tmp_tbl->value_size, flags); } @@ -131,7 +126,7 @@ int registry_update_table(const char *name, void *key, void *value, unsigned lon int registry_update_table_id(int tbl_id, void *key, void *value, unsigned long long flags) { struct bpf_table *tmp_tbl = registry_lookup_table_id(tbl_id); if (tmp_tbl == NULL) - /* not found, return */ + // not found, return return EXIT_FAILURE; return bpf_map_update_elem(&tmp_tbl->bpf_map, key, tmp_tbl->key_size, value, tmp_tbl->value_size, flags); } @@ -139,7 +134,7 @@ int registry_update_table_id(int tbl_id, void *key, void *value, unsigned long l int registry_delete_table_elem(const char *name, void *key) { struct bpf_table *tmp_tbl = registry_lookup_table(name); if (tmp_tbl == NULL) - /* not found, return */ + // not found, return return EXIT_FAILURE; return bpf_map_delete_elem(tmp_tbl->bpf_map, key, tmp_tbl->key_size);; } @@ -147,7 +142,7 @@ int registry_delete_table_elem(const char *name, void *key) { int registry_delete_table_elem_id(int tbl_id, void *key) { struct bpf_table *tmp_tbl = registry_lookup_table_id(tbl_id); if (tmp_tbl == NULL) - /* not found, return */ + // not found, return return EXIT_FAILURE; return bpf_map_delete_elem(tmp_tbl->bpf_map, key, tmp_tbl->key_size);; } @@ -155,7 +150,7 @@ int registry_delete_table_elem_id(int tbl_id, void *key) { void *registry_lookup_table_elem(const char *name, void *key) { struct bpf_table *tmp_tbl = registry_lookup_table(name); if (tmp_tbl == NULL) - /* not found, return */ + // not found, return return NULL; return bpf_map_lookup_elem(tmp_tbl->bpf_map, key, tmp_tbl->key_size); } @@ -163,7 +158,7 @@ void *registry_lookup_table_elem(const char *name, void *key) { void *registry_lookup_table_elem_id(int tbl_id, void *key) { struct bpf_table *tmp_tbl = registry_lookup_table_id(tbl_id); if (tmp_tbl == NULL) - /* not found, return */ + // not found, return return NULL; return bpf_map_lookup_elem(tmp_tbl->bpf_map, key, tmp_tbl->key_size); } diff --git a/backends/ebpf/runtime/ebpf_registry.h b/backends/ebpf/runtime/ebpf_registry.h index 4ccb80df6b6..34ee8eaca02 100644 --- a/backends/ebpf/runtime/ebpf_registry.h +++ b/backends/ebpf/runtime/ebpf_registry.h @@ -14,13 +14,10 @@ See the License for the specific language governing permissions and limitations under the License. */ -/* - * This file defines a shared registry. It is required by the p4c-ebpf test framework - * and acts as an interface between the emulated control and data plane. It provides - * a mechanism to access shared tables by name or id and is intended to approximate the - * kernel ebpf object API as closely as possible. This library is currently not thread-safe. - */ - +/// This file defines a shared registry. It is required by the p4c-ebpf test framework +/// and acts as an interface between the emulated control and data plane. It provides +/// a mechanism to access shared tables by name or id and is intended to approximate the +/// kernel ebpf object API as closely as possible. This library is currently not thread-safe. #ifndef BACKENDS_EBPF_RUNTIME_EBPF_REGISTRY_H_ #define BACKENDS_EBPF_RUNTIME_EBPF_REGISTRY_H_ @@ -28,16 +25,14 @@ limitations under the License. #define MAX_TABLE_NAME_LENGTH 256 // maximum length of the table name -/** - * @brief A helper structure used to describe attributes. - * @details This structure describes various properties of the ebpf table - * such as key and value size and the maximum amount of entries possible. - * In userspace, this space is theoretically unlimited. - * This table definition points to an actual hashmap managed by uthash, - * the relation is many-to-one. - * "name" should not exceed VAR_SIZE. Functions using bpf_table also assume - * that "name" is a conventional null-terminated string. - */ +/// @brief A helper structure used to describe attributes. +/// @details This structure describes various properties of the ebpf table +/// such as key and value size and the maximum amount of entries possible. +/// In userspace, this space is theoretically unlimited. +/// This table definition points to an actual hashmap managed by uthash, +/// the relation is many-to-one. +/// "name" should not exceed VAR_SIZE. Functions using bpf_table also assume +/// that "name" is a conventional null-terminated string. struct bpf_table { char *name; // table name longer than VAR_SIZE is not accessed unsigned int type; // currently only hashmap is supported @@ -47,116 +42,92 @@ struct bpf_table { struct bpf_map *bpf_map; // Pointer to the actual hash map }; -/** - * @brief Adds a new table to the registry. - * @details Adds a new table to the shared registry and assigns - * an id to it. This operation uses a char name stored in "table" as a key. - * @return EXIT_FAILURE if map already exists or cannot be added. - */ +/// @brief Adds a new table to the registry. +/// @details Adds a new table to the shared registry and assigns +/// an id to it. This operation uses a char name stored in "table" as a key. +/// @return EXIT_FAILURE if map already exists or cannot be added. int registry_add(struct bpf_table *tbl); -/** - * @brief Removes a new table from the registry. - * @details Removes a table from the shared registry. - * This operation uses a char name as the key. - * @return EXIT_FAILURE if map cannot be found. - */ +/// @brief Removes a new table from the registry. +/// @details Removes a table from the shared registry. +/// This operation uses a char name as the key. +/// @return EXIT_FAILURE if map cannot be found. int registry_delete_tbl(const char *name); -/** - * @brief Clears the entire registry. - * @details Removes all the tables from the registry. - * Also cleans up all the entries of the tables. - * Cleans the id as well as name identifier. - */ +/// @brief Clears the entire registry. +/// @details Removes all the tables from the registry. +/// Also cleans up all the entries of the tables. +/// Cleans the id as well as name identifier. void registry_delete(); -/** - * @brief Retrieve a table from the registry. - * @details Retrieves a table from the shared registry. - * This operation uses a char name as the key. - * @return NULL if map cannot be found. - */ +/// @brief Retrieve a table from the registry. +/// @details Retrieves a table from the shared registry. +/// This operation uses a char name as the key. +/// @return NULL if map cannot be found. struct bpf_table *registry_lookup_table(const char *name); -/** - * @brief Retrieve a table from the registry. - * @details Retrieves a table from the shared registry. - * This operation uses an integer as the key. - * @return NULL if map cannot be found. - */ +/// @brief Retrieve a table from the registry. +/// @details Retrieves a table from the shared registry. +/// This operation uses an integer as the key. +/// @return NULL if map cannot be found. struct bpf_table *registry_lookup_table_id(int tbl_id); -/** - * @brief Retrieve id of a table in the registry - * @details Retrieves a one-to-one mapped id of - * a table identified by its name. - * @return -1 if map cannot be found. - */ +/// @brief Retrieve id of a table in the registry +/// @details Retrieves a one-to-one mapped id of +/// a table identified by its name. +/// @return -1 if map cannot be found. int registry_get_id(const char *name); -/** - * @brief Insert a key/value pair into the hashmap. - * @details A safe wrapper function to update a bpf map. - * If the map can be found and exists, this function calls - * the bpf_map_update_elem function to insert an entry. - * This operation uses a char name as the key. - * @return EXIT_FAILURE if map cannot be found. - */ +/// @brief Insert a key/value pair into the hashmap. +/// @details A safe wrapper function to update a bpf map. +/// If the map can be found and exists, this function calls +/// the bpf_map_update_elem function to insert an entry. +/// This operation uses a char name as the key. +/// @return EXIT_FAILURE if map cannot be found. int registry_update_table(const char *name, void *key, void *value, unsigned long long flags); -/** - * @brief Insert a key/value pair into the hashmap. - * @details A safe wrapper function to update a bpf map. - * If the map can be found and exists, this function calls - * the bpf_map_update_elem function to insert an entry. - * This operation uses an integer as the key. - * @return EXIT_FAILURE if map cannot be found. - */ +/// @brief Insert a key/value pair into the hashmap. +/// @details A safe wrapper function to update a bpf map. +/// If the map can be found and exists, this function calls +/// the bpf_map_update_elem function to insert an entry. +/// This operation uses an integer as the key. +/// @return EXIT_FAILURE if map cannot be found. int registry_update_table_id(int tbl_id, void *key, void *value, unsigned long long flags); -/** - * @brief Delete a key from the hashmap. - * @details A safe wrapper function to delete an entry from a bpf map where - * only the table id is known. - * If the map can be found and exists, this function calls - * the bpf_map_delte_elem function to delete an entry. - * This operation uses an integer as the key. - * @return EXIT_FAILURE if map cannot be found. - */ +/// @brief Delete a key from the hashmap. +/// @details A safe wrapper function to delete an entry from a bpf map where +/// only the table id is known. +/// If the map can be found and exists, this function calls +/// the bpf_map_delte_elem function to delete an entry. +/// This operation uses a char name as the key. +/// @return EXIT_FAILURE if map cannot be found. int registry_delete_table_elem(const char *name, void *key); -/** - * @brief Delete a key from the hashmap. - * @details A safe wrapper function to delete an entry from a bpf map where - * only the table id is known. - * If the map can be found and exists, this function calls - * the bpf_map_delte_elem function to delete an entry. - * This operation uses an integer as the key. - * @return EXIT_FAILURE if map cannot be found. - */ +/// @brief Delete a key from the hashmap. +/// @details A safe wrapper function to delete an entry from a bpf map where +/// only the table id is known. +/// If the map can be found and exists, this function calls +/// the bpf_map_delte_elem function to delete an entry. +/// This operation uses an integer as the key. +/// @return EXIT_FAILURE if map cannot be found. int registry_delete_table_elem_id(int tbl_id, void *key); -/** - * @brief Retrieve a value from a bpf map through the registry. - * @details A wrapper function to retrieve a value from a hash map - * where only the name is known. The function looks up the identifier - * in the registry and calls bpf_map_lookup_elem on the retrieved list. - * If there is no table, this function also returns NULL. - * This operation uses a char name as the key. - * @return NULL if the value cannot be found. - */ +/// @brief Retrieve a value from a bpf map through the registry. +/// @details A wrapper function to retrieve a value from a hash map +/// where only the name is known. The function looks up the identifier +/// in the registry and calls bpf_map_lookup_elem on the retrieved list. +/// If there is no table, this function also returns NULL. +/// This operation uses a char name as the key. +/// @return NULL if the value cannot be found. void *registry_lookup_table_elem(const char *name, void *key); -/** - * @brief Retrieve a value from a bpf map through the registry. - * @details A wrapper function to retrieve a value from a hash map - * where only the id is known. The function looks up the identifier - * in the registry and calls bpf_map_lookup_elem on the retrieved list. - * If there is no table, this function also returns NULL. - * This operation uses an integer as the key. - * @return NULL if the value cannot be found. - */ +/// @brief Retrieve a value from a bpf map through the registry. +/// @details A wrapper function to retrieve a value from a hash map +/// where only the id is known. The function looks up the identifier +/// in the registry and calls bpf_map_lookup_elem on the retrieved list. +/// If there is no table, this function also returns NULL. +/// This operation uses an integer as the key. +/// @return NULL if the value cannot be found. void *registry_lookup_table_elem_id(int tbl_id, void *key); #endif // BACKENDS_EBPF_RUNTIME_EBPF_REGISTRY_H_ diff --git a/backends/ebpf/runtime/ebpf_runtime.c b/backends/ebpf/runtime/ebpf_runtime.c index 5830498c8c9..62d3fb96302 100644 --- a/backends/ebpf/runtime/ebpf_runtime.c +++ b/backends/ebpf/runtime/ebpf_runtime.c @@ -14,12 +14,10 @@ See the License for the specific language governing permissions and limitations under the License. */ -/* The runtime emulates a loaded eBPF program. It parses a set of given - pcap files and executes a C program that processes packets extracted from - the capture files. The C program takes a packet structure (commonly an skbuf) - and returns an action value for each packet. - */ - +/// The runtime emulates a loaded eBPF program. It parses a set of given +/// pcap files and executes a C program that processes packets extracted from +/// the capture files. The C program takes a packet structure (commonly an skbuf) +/// and returns an action value for each packet. #include // getopt() #include // isprint() #include // memcpy() @@ -51,7 +49,7 @@ void usage(char *name) { static pcap_list_t *get_packets(const char *pcap_base, uint16_t num_pcaps, pcap_list_t *merged_list) { pcap_list_array_t *tmp_list_array = allocate_pkt_list_array(); - /* Retrieve a list for each file and append it to the temporary array */ + // Retrieve a list for each file and append it to the temporary array for (uint16_t i = 0; i < num_pcaps; i++) { char *pcap_in_name = generate_pcap_name(pcap_base, i, PCAPIN); if (debug) @@ -60,17 +58,17 @@ static pcap_list_t *get_packets(const char *pcap_base, uint16_t num_pcaps, pcap_ tmp_list_array = insert_list(tmp_list_array, pkt_list, i); free(pcap_in_name); } - /* Merge the array into a newly allocated list. This destroys the array. */ + // Merge the array into a newly allocated list. This destroys the array. return merge_and_delete_lists(tmp_list_array, merged_list); } void launch_runtime(const char *pcap_name, uint16_t num_pcaps) { if (num_pcaps == 0) return; - /* Initialize the list of input packets */ + // Initialize the list of input packets pcap_list_t *input_list = allocate_pkt_list(); - /* Create the basic pcap filename from the input */ + // Create the basic pcap filename from the input const char *suffix = strrchr(pcap_name, DELIM); if (suffix == NULL) { fprintf(stderr, "Expected a filename with delimiter \"%c\"." @@ -81,13 +79,13 @@ void launch_runtime(const char *pcap_name, uint16_t num_pcaps) { char pcap_base[baselen + 1]; snprintf(pcap_base, baselen + 1 , "%s", pcap_name); - /* Open all matching pcap files retrieve a merged list of packets */ + // Open all matching pcap files retrieve a merged list of packets input_list = get_packets(pcap_base, num_pcaps, input_list); - /* Sort the list */ + // Sort the list sort_pcap_list(input_list); - /* Run the "program" and retrieve output lists */ + // Run the "program" and retrieve output lists RUN(ebpf_filter, pcap_base, num_pcaps, input_list, debug); - /* Delete the list of input packets */ + // Delete the list of input packets delete_list(input_list); } @@ -130,15 +128,15 @@ int main(int argc, char **argv) { } } - /* Check if there was actually any file or number input */ + // Check if there was actually any file or number input if (!pcap_name || num_pcaps == -1) usage(argv[0]); INIT_EBPF_TABLES(debug); #ifdef CONTROL_PLANE - /* Set the default action for the userspace hash tables */ + // Set the default action for the userspace hash tables init_tables(); - /* Run all commands specified in the control file */ + // Run all commands specified in the control file setup_control_plane(); #endif diff --git a/backends/ebpf/runtime/ebpf_runtime_kernel.h b/backends/ebpf/runtime/ebpf_runtime_kernel.h index 41386c32d22..7765ad3371a 100644 --- a/backends/ebpf/runtime/ebpf_runtime_kernel.h +++ b/backends/ebpf/runtime/ebpf_runtime_kernel.h @@ -14,13 +14,10 @@ See the License for the specific language governing permissions and limitations under the License. */ -/* - * Runtime operations specific to the kernel target. Opens a raw socket per - * interface, launches a tcpdump packet listener, and writes packets to a - * virtual interface. The successful output is recorded by tcpdump and written - * to file. - */ - +/// Runtime operations specific to the kernel target. Opens a raw socket per +/// interface, launches a tcpdump packet listener, and writes packets to a +/// virtual interface. The successful output is recorded by tcpdump and written +/// to file. #ifndef BACKENDS_EBPF_RUNTIME_EBPF_RUNTIME_KERNEL_H_ #define BACKENDS_EBPF_RUNTIME_EBPF_RUNTIME_KERNEL_H_ diff --git a/backends/ebpf/runtime/ebpf_runtime_test.c b/backends/ebpf/runtime/ebpf_runtime_test.c index 8a16225e2e5..9d13a0c0101 100644 --- a/backends/ebpf/runtime/ebpf_runtime_test.c +++ b/backends/ebpf/runtime/ebpf_runtime_test.c @@ -23,17 +23,15 @@ limitations under the License. #define PCAPOUT "_out.pcap" -/** - * @brief Feed a list packets into an eBPF program. - * @details This is a mock function emulating the behavior of a running - * eBPF program. It takes a list of input packets and iteratively parses them - * using the given imported ebpf_filter function. The output defines whether - * or not the packet is "dropped." If the packet is not dropped, its content is - * copied and appended to an output packet list. - * - * @param pkt_list A list of input packets running through the filter. - * @return The list of packets "surviving" the filter function - */ +/// @brief Feed a list packets into an eBPF program. +/// @details This is a mock function emulating the behavior of a running +/// eBPF program. It takes a list of input packets and iteratively parses them +/// using the given imported ebpf_filter function. The output defines whether +/// or not the packet is "dropped." If the packet is not dropped, its content is +/// copied and appended to an output packet list. +/// +/// @param pkt_list A list of input packets running through the filter. +/// @return The list of packets "surviving" the filter function pcap_list_t *feed_packets(packet_filter ebpf_filter, pcap_list_t *pkt_list, int debug) { pcap_list_t *output_pkts = allocate_pkt_list(); uint32_t list_len = get_pkt_list_length(pkt_list); @@ -45,7 +43,7 @@ pcap_list_t *feed_packets(packet_filter ebpf_filter, pcap_list_t *pkt_list, int skb.len = input_pkt->pcap_hdr.len; int result = ebpf_filter(&skb); if (result != 0) { - /* We copy the entire content to emulate an outgoing packet */ + // We copy the entire content to emulate an outgoing packet. pcap_pkt *out_pkt = copy_pkt(input_pkt); output_pkts = append_packet(output_pkts, out_pkt); } @@ -68,20 +66,20 @@ void write_pkts_to_pcaps(const char *pcap_base, pcap_list_array_t *output_array, } void *run_and_record_output(packet_filter ebpf_filter, const char *pcap_base, pcap_list_t *pkt_list, int debug) { - /* Create an array of packet lists */ + // Create an array of packet lists. pcap_list_array_t *output_array = allocate_pkt_list_array(); - /* Feed the packets into our "loaded" program */ + // Feed the packets into our "loaded" program. pcap_list_t *output_pkts = feed_packets(ebpf_filter, pkt_list, debug); - /* Split the output packet list by interface. This destroys the list. */ + // Split the output packet list by interface. This destroys the list. output_array = split_and_delete_list(output_pkts, output_array); - /* Write each list to a separate pcap output file */ + // Write each list to a separate pcap output file. write_pkts_to_pcaps(pcap_base, output_array, debug); - /* Delete the array, including the data it is holding */ + // Delete the array, including the data it is holding. delete_array(output_array); } void init_ebpf_tables(int debug) { - /* Initialize the registry of shared tables */ + // Initialize the registry of shared tables. struct bpf_table* current = tables; while (current->name != NULL) { if (debug) @@ -92,7 +90,7 @@ void init_ebpf_tables(int debug) { } void delete_ebpf_tables(int debug) { - /* Delete all the remaining tables in the user program */ + // Delete all the remaining tables in the user program. struct bpf_table* current = tables; while (current->name != NULL) { if (debug) diff --git a/backends/ebpf/runtime/ebpf_runtime_test.h b/backends/ebpf/runtime/ebpf_runtime_test.h index c62b69d555c..a3364df8c56 100644 --- a/backends/ebpf/runtime/ebpf_runtime_test.h +++ b/backends/ebpf/runtime/ebpf_runtime_test.h @@ -14,12 +14,9 @@ See the License for the specific language governing permissions and limitations under the License. */ -/* - * Runtime operations specific to the test target. Runs a provided filter - * function, records the output, and writes it to a physical file. Does not use - * any Linux networking tools and only operates on custom hash maps. - */ - +/// Runtime operations specific to the test target. Runs a provided filter +/// function, records the output, and writes it to a physical file. Does not use +/// any Linux networking tools and only operates on custom hash maps. #ifndef BACKENDS_EBPF_RUNTIME_EBPF_RUNTIME_TEST_H_ #define BACKENDS_EBPF_RUNTIME_EBPF_RUNTIME_TEST_H_ diff --git a/backends/ebpf/runtime/ebpf_test.h b/backends/ebpf/runtime/ebpf_test.h index 7606723dbd3..6cff8560037 100644 --- a/backends/ebpf/runtime/ebpf_test.h +++ b/backends/ebpf/runtime/ebpf_test.h @@ -14,14 +14,11 @@ See the License for the specific language governing permissions and limitations under the License. */ -/* - * This file contains all functions and definitions necessary for the user space - * target C code to compile. It is part of the extended ebpf testing framework - * and must be included with any file generated by the p4c-ebpf test compiler. - * This file also depends on the ebpf_registry, which defines a central table - * repository as well as various ebpf map operations. - */ - +/// This file contains all functions and definitions necessary for the user space +/// target C code to compile. It is part of the extended ebpf testing framework +/// and must be included with any file generated by the p4c-ebpf test compiler. +/// This file also depends on the ebpf_registry, which defines a central table +/// repository as well as various ebpf map operations. #ifndef BACKENDS_EBPF_RUNTIME_EBPF_USER_H_ #define BACKENDS_EBPF_RUNTIME_EBPF_USER_H_ @@ -30,7 +27,7 @@ limitations under the License. #include -/* define some byte order conversions, these mimic bpf_endian.h */ +/// define some byte order conversions, these mimic bpf_endian.h #define htonll(x) htobe64(x) #define ntohll(x) be64toh(x) @@ -55,27 +52,26 @@ limitations under the License. ##__VA_ARGS__); \ }) -/** helper macro to place programs, maps, license in - * different sections in elf_bpf file. Section names - * are interpreted by elf_bpf loader - * In the userspace version, this macro does nothing - */ +/// Helper macro to place programs, maps, license in +/// different sections in elf_bpf file. Section names +/// are interpreted by elf_bpf loader +/// In the userspace version, this macro does nothing #define SEC(NAME) -/* simple descriptor which replaces the kernel sk_buff structure */ +/// simple descriptor which replaces the kernel sk_buff structure. struct sk_buff { void *data; u16 len; u32 ifindex; }; -/* flags for BPF_MAP_UPDATE_ELEM command, copied from "linux/bpf" */ -#define BPF_ANY 0 /* create new element or update existing */ -#define BPF_NOEXIST 1 /* create new element if it didn't exist */ -#define BPF_EXIST 2 /* update existing element */ -#define BPF_F_LOCK 4 /* spin_lock-ed map_lookup/map_update */ +/// flags for BPF_MAP_UPDATE_ELEM command, copied from "linux/bpf". +#define BPF_ANY 0 /// create new element or update existing +#define BPF_NOEXIST 1 /// create new element if it didn't exist +#define BPF_EXIST 2 /// update existing element +#define BPF_F_LOCK 4 /// spin_lock-ed map_lookup/map_update -/* Supported bpf map types */ +/// Supported bpf map types enum bpf_map_type { BPF_MAP_TYPE_HASH, BPF_MAP_TYPE_ARRAY, @@ -104,7 +100,7 @@ struct bpf_table tables[] = { #define BPF_OBJ_GET(name) registry_get_id(name) -/* These should be automatically generated and included in the generated x.h header file */ +/// These should be automatically generated and included in the generated x.h header file. extern struct bpf_table tables[]; extern int ebpf_filter(struct sk_buff *skb); diff --git a/backends/ebpf/runtime/pcap_util.h b/backends/ebpf/runtime/pcap_util.h index 56f6daf48b5..956d30e4d9b 100644 --- a/backends/ebpf/runtime/pcap_util.h +++ b/backends/ebpf/runtime/pcap_util.h @@ -14,11 +14,9 @@ See the License for the specific language governing permissions and limitations under the License. */ -/* - * A pcap utility library which provides several functions to read from and - * write packets to pcap files. - */ +/// A pcap utility library which provides several functions to read from and +/// write packets to pcap files. #ifndef BACKENDS_EBPF_RUNTIME_EBPF_PCAP_UTIL_H_ #define BACKENDS_EBPF_RUNTIME_EBPF_PCAP_UTIL_H_ @@ -26,13 +24,12 @@ limitations under the License. #include #include // uint32_t, uint16_t -/* Interfaces are named by integers */ +/// Interfaces are named by integers typedef uint16_t iface_index; -/* A network packet. - Contains packet content, timestamp and the interface where - the packet has been received/sent. - */ +/// A network packet. +/// contains packet content, timestamp and the interface where +/// the packet has been received/sent. typedef struct { char *data; struct pcap_pkthdr pcap_hdr; @@ -44,184 +41,150 @@ struct pcap_list_array; typedef struct pcap_list pcap_list_t; typedef struct pcap_list_array pcap_list_array_t; -/** - * @brief Retrieve packets from a pcap file. - * @details Retrieves a list of packets from a given pcap file. - * Allocates a packet list and fills it with the packets from the - * supplied pcap file. All data in the capture file is copied to the new list. - * Each packet is assigned the given interface index as meta-information. - * A list allocated by this function should subsequently be freed by - * delete_list(). - * - * @param pcap_file_name The exact name of the pcap file. - * @param index Interface index of the file. - * - * @return A handle to the allocated list. Null if the read operation - * was unsuccessful. - */ +/// Retrieve packets from a pcap file. +/// Retrieves a list of packets from a given pcap file. +/// Allocates a packet list and fills it with the packets from the +/// supplied pcap file. All data in the capture file is copied to the new list. +/// Each packet is assigned the given interface index as meta-information. +/// A list allocated by this function should subsequently be freed by +/// delete_list(). +/// +/// @param pcap_file_name The exact name of the pcap file. +/// @param index Interface index of the file. +/// +/// @return A handle to the allocated list. Null if the read operation +/// was unsuccessful. pcap_list_t *read_pkts_from_pcap(const char *pcap_file_name, iface_index index); -/** - * @brief Write a list of packets to a pcap file. - * @details Iteratively dumps the packets to the given filename. - * - * @param pcap_file_name Exact name of the file to create and write to. - * @param pkt_list List of packets to write. - * - * @return EXIT_FAILURE if operation fails. - */ +/// Write a list of packets to a pcap file. +/// Iteratively dumps the packets to the given filename. +/// +/// @param pcap_file_name Exact name of the file to create and write to. +/// @param pkt_list List of packets to write. +/// +/// @return EXIT_FAILURE if operation fails. int write_pkts_to_pcap(const char *pcap_file_name, const pcap_list_t *pkt_list); -/** - * @brief Merges a given list array into a single list. - * @details Expects a handle to an array list and allocates a single list from - * it. The array and its data structures are subsequently destroyed. - * - * @param array The array containing the lists to split - * @param merged_list The output lists to fill with packets. - * @return A single merged list contained all packets. Null if the operation - * the fails. - */ +/// Merges a given list array into a single list. +/// Expects a handle to an array list and allocates a single list from +/// it. The array and its data structures are subsequently destroyed. +/// +/// @param array The array containing the lists to split +/// @param merged_list The output lists to fill with packets. +/// @return A single merged list contained all packets. Null if the operation +/// the fails. pcap_list_t *merge_and_delete_lists(pcap_list_array_t *array, pcap_list_t *merged_list); -/** - * @brief Splits a list of packets by interface. - * @details Splits the given list by the interface indicator in the - * packet structure. The input list is destroyed and for each interface a - * new list is allocated. - * - * @param input_list A list containing packets. - * @param result_arr The array to fill with lists. - - * @return The updated array containing the new lists. - */ +/// Splits a list of packets by interface. +/// Splits the given list by the interface indicator in the +/// packet structure. The input list is destroyed and for each interface a +/// new list is allocated. +/// +/// @param input_list A list containing packets. +/// @param result_arr The array to fill with lists. +/// +/// @return The updated array containing the new lists. pcap_list_array_t *split_and_delete_list(pcap_list_t *input_list, pcap_list_array_t *result_arr); -/** - * @brief Appends a packet to a given list of packets. - * @details This function takes a pointer to a packet and appends it to the - * given list. If the list is Null, it is allocated. For each new packet - * to append, the list is expanded by the size of the packet pointer. - * - * @param pkt_list List descriptor. Can be Null - * @param pkt Pointer of the packet to append. - * - * @return Returns the updated list. This function causes an - * exit if allocation fails. - */ +/// Appends a packet to a given list of packets. +/// This function takes a pointer to a packet and appends it to the +/// given list. If the list is Null, it is allocated. For each new packet +/// to append, the list is expanded by the size of the packet pointer. +/// +/// @param pkt_list List descriptor. Can be Null +/// @param pkt Pointer of the packet to append. +/// +/// @return Returns the updated list. This function causes an +/// exit if allocation fails. pcap_list_t *append_packet(pcap_list_t *pkt_list, pcap_pkt *pkt); -/** - * @brief Inserts a packet list in the array at a given index. - * @details This function takes a pointer to a packet list and inserts it at - * the given index. If the list array is Null, it is allocated. For each index - * out of the boundaries of the array, the array list is expanded by the size - * of the index. - * - * @param pkt_array The descriptor of the array. Can be Null - * @param pkt_list The list to insert. - * @param index The index specifying where to insert the array. - * @return Returns the updated list array. This function causes - * an exit if reallocation fails. - */ +/// Inserts a packet list in the array at a given index. +/// This function takes a pointer to a packet list and inserts it at +/// the given index. If the list array is Null, it is allocated. For each index +/// out of the boundaries of the array, the array list is expanded by the size +/// of the index. +/// +/// @param pkt_array The descriptor of the array. Can be Null +/// @param pkt_list The list to insert. +/// @param index The index specifying where to insert the array. +/// @return Returns the updated list array. This function causes +/// an exit if reallocation fails. pcap_list_array_t *insert_list(pcap_list_array_t *pkt_array, pcap_list_t *pkt_list, uint16_t index); -/** - * @brief Allocates a packet list. - * - * @return The packet list. - */ +/// Allocates a packet list. +/// +/// @return The packet list. pcap_list_t *allocate_pkt_list(); - -/** - * @brief Allocates a packet list array. - * - * @return The list array. - */ +/// Allocates a packet list array. +/// +/// @return The list array. pcap_list_array_t *allocate_pkt_list_array(); -/** - * @brief Get the length of the packet list. - * - * @param pkt_list A packet list. - * @return Length of the list. - */ +/// Get the length of the packet list. +/// +/// @param pkt_list A packet list. +/// @return Length of the list. uint32_t get_pkt_list_length(pcap_list_t *pkt_list); -/** - * @brief Get the length of the packet list array. - * - * @param pkt_list A list array. - * @return Length of the list array. - */ +/// Get the length of the packet list array. +/// +/// @param pkt_list A list array. +/// @return Length of the list array. uint16_t get_list_array_length(pcap_list_array_t *pkt_list_array); -/** - * @brief Get a packet from a given index. - * - * @param pkt_list A list. - * @param index Index of the packet to retrieve. - * - * @return The list. Null if the index is out of bounds. - */ +/// Get a packet from a given index. +/// +/// @param pkt_list A list. +/// @param index Index of the packet to retrieve. +/// +/// @return The list. Null if the index is out of bounds. pcap_pkt *get_packet(pcap_list_t *list, uint32_t index); -/** - * @brief Get a list from a given index. - * - * @param pkt_list A list array. - * @param index Index of the list to retrieve. - * - * @return The list array. Null if the index is out of bounds. - */ +/// Get a list from a given index. +/// +/// @param pkt_list A list array. +/// @param index Index of the list to retrieve. +/// +/// @return The list array. Null if the index is out of bounds. pcap_list_t *get_list(pcap_list_array_t *list, uint16_t index); -/** - * @brief Copies a packet in full, including its referenced data. - * @details Allocates a new packet and copies all data and structures - * contained in the reference packet. Both packets remain allocated. - * @param src_pkt The packet to copy. - * - * @return An allocated copy of the packet. - */ +/// Copies a packet in full, including its referenced data. +/// Allocates a new packet and copies all data and structures +/// contained in the reference packet. Both packets remain allocated. +/// +/// @param src_pkt The packet to copy. +/// +/// @return An allocated copy of the packet. pcap_pkt *copy_pkt(pcap_pkt *src_pkt); -/** - * @brief Completely erases the list. - * @details Deletes the given list. Also deletes the data referenced by the - * pcap packets in the list. - * - * @param pkt_list The list to delete. - */ +/// Completely erases the list. +/// Deletes the given list. Also deletes the data referenced by the +/// pcap packets in the list. +/// +/// @param pkt_list The list to delete. void delete_list(pcap_list_t *pkt_list); -/** - * @brief Completely erases a list array and the lists in the array. - * @details Deletes the given array. Also deletes the list as well as the - * data referenced by the pcap packets in the list. - * - * @param pkt_list_array A list array. - */ +/// Completely erases a list array and the lists in the array. +/// Deletes the given array. Also deletes the list as well as the +/// data referenced by the pcap packets in the list. +/// +/// @param pkt_list_array A list array. void delete_array(pcap_list_array_t *pkt_list_array); -/** - * @brief Sort a list in place. - * @details Sorts a given list by the timestamp of the packets contained in it. - * This alters the order in place, the input list is permanently modified. - * - * @param pkt_list A list. - */ +/// Sort a list in place. +/// Sorts a given list by the timestamp of the packets contained in it. +/// This alters the order in place, the input list is permanently modified. +/// +/// @param pkt_list A list. void sort_pcap_list(pcap_list_t *pkt_list); -/** - * @brief Create a pcap file name from a given base name, interface index, - * and suffix. Return value must be deallocated after usage. - * @param pcap_base The file base name. - * @param index The index of the file, represent an interface. - * @param suffix Filename suffix (e.g., _in.pcap) - * @return An allocated string containing the file name. - */ +/// Create a pcap file name from a given base name, interface index, +/// and suffix. Return value must be deallocated after usage. +/// @param pcap_base The file base name. +/// @param index The index of the file, represent an interface. +/// @param suffix Filename suffix (e.g., _in.pcap) +/// @return An allocated string containing the file name. char *generate_pcap_name(const char *pcap_base, int index, const char *suffix); -#endif // BACKENDS_EBPF_RUNTIME_EBPF_PCAP_UTIL_H_ \ No newline at end of file +#endif // BACKENDS_EBPF_RUNTIME_EBPF_PCAP_UTIL_H_ diff --git a/backends/ebpf/runtime/psa.h b/backends/ebpf/runtime/psa.h index ae4a85f1c9d..b5ffa21192f 100644 --- a/backends/ebpf/runtime/psa.h +++ b/backends/ebpf/runtime/psa.h @@ -37,7 +37,7 @@ static const PSA_PacketPath_t CLONE_E2E = 4; /// Packet created via a clone ope static const PSA_PacketPath_t RESUBMIT = 5; /// Packet arrival is the result of a resubmit operation static const PSA_PacketPath_t RECIRCULATE = 6; /// Packet arrival is the result of a recirculate operation -// Instead of using enum we define ParserError_t as __u8 to save memory. +/// Instead of using enum we define ParserError_t as __u8 to save memory. typedef __u8 ParserError_t; static const ParserError_t NoError = 0; /// No error. static const ParserError_t PacketTooShort = 1; /// Not enough bits in packet for 'extract'. @@ -50,9 +50,8 @@ static const ParserError_t ParserInvalidArgument = 6; /// Parser operation was enum PSA_MeterColor_t { RED, GREEN, YELLOW }; -/* - * INGRESS data types - */ + +/// INGRESS data types struct psa_ingress_parser_input_metadata_t { PortId_t ingress_port; // taken from xdp_md or __sk_buff PSA_PacketPath_t packet_path; // taken from psa_global_metadata diff --git a/backends/ebpf/target.h b/backends/ebpf/target.h index 74aee62edaf..ae9752fb2c2 100644 --- a/backends/ebpf/target.h +++ b/backends/ebpf/target.h @@ -24,8 +24,8 @@ limitations under the License. #include "lib/exceptions.h" #include "lib/sourceCodeBuilder.h" -// We are prepared to support code generation using multiple styles -// (e.g., using BCC or using CLANG). +/// We are prepared to support code generation using multiple styles +/// (e.g., using BCC or using CLANG). namespace EBPF { @@ -34,7 +34,7 @@ enum TableKind { TableArray, TablePerCPUArray, TableProgArray, - TableLPMTrie, // longest prefix match trie + TableLPMTrie, /// longest prefix match trie TableHashLRU, TableDevmap }; @@ -74,8 +74,8 @@ class Target { ::error(ErrorType::ERR_UNSUPPORTED, "emitTableDeclSpinlock is not supported on %1% target", name); } - // map-in-map requires declaration of both inner and outer map, - // thus we define them together in a single method. + /// map-in-map requires declaration of both inner and outer map, + /// thus we define them together in a single method. virtual void emitMapInMapDecl(Util::SourceCodeBuilder *builder, cstring innerName, TableKind innerTableKind, cstring innerKeyType, cstring innerValueType, unsigned innerSize, cstring outerName, @@ -123,8 +123,8 @@ class Target { virtual void emitTraceMessage(Util::SourceCodeBuilder *builder, const char *format) const; }; -// Represents a target that is compiled within the kernel -// source tree samples folder and which attaches to a socket +/// Represents a target that is compiled within the kernel. +/// source tree samples folder and which attaches to a socket. class KernelSamplesTarget : public Target { private: mutable unsigned int innerMapIndex; @@ -237,7 +237,7 @@ class P4TCTarget : public KernelSamplesTarget { } }; -// Target XDP +/// Target XDP class XdpTarget : public KernelSamplesTarget { public: explicit XdpTarget(bool emitTrace) : KernelSamplesTarget(emitTrace, "XDP") {} @@ -261,7 +261,7 @@ class XdpTarget : public KernelSamplesTarget { } }; -// Represents a target compiled by bcc that uses the TC +/// Represents a target compiled by bcc that uses the TC class BccTarget : public Target { public: BccTarget() : Target("BCC") {} @@ -291,8 +291,8 @@ class BccTarget : public Target { cstring packetDescriptorType() const override { return "struct __sk_buff"; } }; -// A userspace test version with functionality equivalent to the kernel -// Compiles with gcc +/// A userspace test version with functionality equivalent to the kernel +/// Compiles with gcc class TestTarget : public EBPF::KernelSamplesTarget { public: TestTarget() : KernelSamplesTarget(false, "Userspace Test") {}