From 2dab97fbe058e6c1ecdf3e302aab49c8e8c228f3 Mon Sep 17 00:00:00 2001 From: Sosutha Sethuramapandian Date: Fri, 9 Feb 2024 00:25:24 -0800 Subject: [PATCH] Fix for default_action * tc template code change for default miss action * NoAction case generation in c code for tc backend * default case deletion in c code for tc backend * p4tc testcases output updated --- backends/tc/backend.cpp | 26 ++ backends/tc/ebpfCodeGen.cpp | 80 ++-- backends/tc/ebpfCodeGen.h | 1 - backends/tc/tc.def | 50 +-- .../p4tc_samples/default_action_with_param.p4 | 134 +++++++ .../calculator_control_blocks.c | 9 +- .../checksum_control_blocks.c | 9 +- .../const_entries_range_mask_control_blocks.c | 8 +- .../default_action_example_control_blocks.c | 18 +- .../default_action_with_param.json | 114 ++++++ .../default_action_with_param.p4-stderr | 0 .../default_action_with_param.template | 33 ++ ...default_action_with_param_control_blocks.c | 358 ++++++++++++++++++ .../default_action_with_param_parser.c | 133 +++++++ .../default_action_with_param_parser.h | 161 ++++++++ ...default_hit_const_example_control_blocks.c | 7 +- .../drop_packet_example_control_blocks.c | 9 +- .../global_action_example_01_control_blocks.c | 18 +- .../global_action_example_02_control_blocks.c | 18 +- .../ipip_control_blocks.c | 9 +- .../matchtype_control_blocks.c | 36 +- .../mix_matchtype_example_control_blocks.c | 36 +- ...ultiple_tables_example_01_control_blocks.c | 41 +- ...ultiple_tables_example_02_control_blocks.c | 41 +- .../name_annotation_example_control_blocks.c | 18 +- .../noaction_example_01_control_blocks.c | 11 +- .../noaction_example_02_control_blocks.c | 11 +- ...ummask_annotation_example_control_blocks.c | 7 +- .../send_to_port_example_control_blocks.c | 9 +- .../set_entry_timer_example_control_blocks.c | 18 +- .../simple_exact_example_control_blocks.c | 9 +- .../simple_lpm_example_control_blocks.c | 9 +- .../simple_ternary_example_control_blocks.c | 9 +- .../size_param_example_control_blocks.c | 18 +- ...c_type_annotation_example_control_blocks.c | 4 - .../test_ipv6_example.template | 2 +- .../test_ipv6_example_control_blocks.c | 4 - 37 files changed, 1216 insertions(+), 262 deletions(-) create mode 100644 testdata/p4tc_samples/default_action_with_param.p4 create mode 100644 testdata/p4tc_samples_outputs/default_action_with_param.json create mode 100644 testdata/p4tc_samples_outputs/default_action_with_param.p4-stderr create mode 100755 testdata/p4tc_samples_outputs/default_action_with_param.template create mode 100644 testdata/p4tc_samples_outputs/default_action_with_param_control_blocks.c create mode 100644 testdata/p4tc_samples_outputs/default_action_with_param_parser.c create mode 100644 testdata/p4tc_samples_outputs/default_action_with_param_parser.h diff --git a/backends/tc/backend.cpp b/backends/tc/backend.cpp index f8909a52fda..ffabfcbf84b 100644 --- a/backends/tc/backend.cpp +++ b/backends/tc/backend.cpp @@ -354,6 +354,32 @@ void ConvertToBackendIR::updateDefaultMissAction(const IR::P4Table *t, IR::TCTab if (defaultActionProperty->isConstant) { tabledef->setDefaultMissConst(true); } + bool directionParamPresent = false; + auto paramList = actionCall->action->getParameters(); + for (auto param : paramList->parameters) { + if (param->direction != IR::Direction::None) directionParamPresent = true; + } + if (!directionParamPresent) { + auto i = 0; + for (auto param : paramList->parameters) { + auto defaultParam = new IR::TCDefaultActionParam(); + defaultParam->setParamName(param->name.originalName); + auto defaultArg = methodexp->arguments->at(i++); + if (defaultArg->expression->is()) { + auto constVal = defaultArg->expression->to(); + bool sign; + if (const IR::Type_Bits *tb = constVal->type->to()) { + sign = tb->isSigned; + } else { + sign = false; + } + defaultParam->setDefaultValue( + Util::toString(constVal->value, 0, sign, constVal->base)); + } else + defaultParam->setDefaultValue(defaultArg->expression->toString()); + tabledef->defaultMissActionParams.push_back(defaultParam); + } + } } } } diff --git a/backends/tc/ebpfCodeGen.cpp b/backends/tc/ebpfCodeGen.cpp index bad1d02229a..005e1c40092 100644 --- a/backends/tc/ebpfCodeGen.cpp +++ b/backends/tc/ebpfCodeGen.cpp @@ -824,10 +824,13 @@ void EBPFTablePNA::emitAction(EBPF::CodeBuilder *builder, cstring valueName, builder->emitIndent(); builder->appendFormat("switch (%s->action) ", valueName.c_str()); builder->blockStart(); + bool noActionGenerated = false; for (auto a : actionList->actionList) { auto adecl = program->refMap->getDeclaration(a->getPath(), true); auto action = adecl->getNode()->checkedTo(); + if (action->name.originalName == P4::P4CoreLibrary::instance().noAction.name) + noActionGenerated = true; cstring name = EBPF::EBPFObject::externalName(action), msgStr, convStr; builder->emitIndent(); cstring actionName = p4ActionToActionIDName(action); @@ -867,16 +870,22 @@ void EBPFTablePNA::emitAction(EBPF::CodeBuilder *builder, cstring valueName, builder->appendLine("break;"); builder->decreaseIndent(); } - - builder->emitIndent(); - builder->appendLine("default:"); - builder->increaseIndent(); - builder->target->emitTraceMessage(builder, "Control: Invalid action type, aborting"); - - builder->emitIndent(); - builder->appendFormat("return %s", builder->target->abortReturnCode().c_str()); - builder->endOfStatement(true); - builder->decreaseIndent(); + if (!noActionGenerated) { + cstring noActionName = P4::P4CoreLibrary::instance().noAction.name; + cstring tableInstance = dataMapName; + cstring actionName = + Util::printf_format("%s_ACT_%s", tableInstance.toUpper(), noActionName.toUpper()); + builder->emitIndent(); + builder->appendFormat("case %s: ", actionName); + builder->newline(); + builder->increaseIndent(); + builder->emitIndent(); + builder->blockStart(); + builder->blockEnd(true); + builder->emitIndent(); + builder->appendLine("break;"); + builder->decreaseIndent(); + } builder->blockEnd(true); @@ -888,13 +897,8 @@ void EBPFTablePNA::emitAction(EBPF::CodeBuilder *builder, cstring valueName, builder->blockEnd(false); builder->appendFormat(" else "); - if (dropOnNoMatchingEntryFound()) { - builder->target->emitTraceMessage(builder, "Control: Entry not found, aborting"); - emitDefaultAction(builder, valueName); - } else { - builder->target->emitTraceMessage(builder, - "Control: Entry not found, executing implicit NoAction"); - } + builder->blockStart(); + builder->blockEnd(true); } void EBPFTablePNA::emitInitializer(EBPF::CodeBuilder *builder) { @@ -917,46 +921,30 @@ void EBPFTablePNA::emitDefaultActionStruct(EBPF::CodeBuilder *builder) { } } -void EBPFTablePNA::emitDefaultAction(EBPF::CodeBuilder *builder, cstring valueName) { - const IR::P4Table *t = table->container; - const IR::Expression *default_action = t->getDefaultAction(); - bool visitDefaultAction = false; - if (default_action) { - if (auto mc = default_action->to()) { - default_action = mc->method; - } - auto path = default_action->to(); - BUG_CHECK(path, "Default action path %1% cannot be found", default_action); - if (auto defaultActionDecl = - program->refMap->getDeclaration(path->path)->to()) { - if (defaultActionDecl->name.originalName != "NoAction") { - visitDefaultAction = true; - auto visitor = createActionTranslationVisitor(valueName, program); - visitor->setBuilder(builder); - visitor->copySubstitutions(codeGen); - visitor->copyPointerVariables(codeGen); - defaultActionDecl->apply(*visitor); - builder->newline(); - } - } - } - if (visitDefaultAction == false) { - builder->blockStart(); - builder->blockEnd(true); - } -} - void EBPFTablePNA::emitValueActionIDNames(EBPF::CodeBuilder *builder) { // create type definition for action builder->emitIndent(); + bool noActionGenerated = false; for (auto a : actionList->actionList) { auto adecl = program->refMap->getDeclaration(a->getPath(), true); auto action = adecl->getNode()->checkedTo(); + if (action->name.originalName == P4::P4CoreLibrary::instance().noAction.name) + noActionGenerated = true; unsigned int action_idx = tcIR->getActionId(tcIR->externalName(action)); builder->emitIndent(); builder->appendFormat("#define %s %d", p4ActionToActionIDName(action), action_idx); builder->newline(); } + if (!noActionGenerated) { + cstring noActionName = P4::P4CoreLibrary::instance().noAction.name; + cstring tableInstance = dataMapName; + cstring actionName = + Util::printf_format("%s_ACT_%s", tableInstance.toUpper(), noActionName.toUpper()); + unsigned int action_idx = tcIR->getActionId(noActionName); + builder->emitIndent(); + builder->appendFormat("#define %s %d", actionName, action_idx); + builder->newline(); + } builder->emitIndent(); } diff --git a/backends/tc/ebpfCodeGen.h b/backends/tc/ebpfCodeGen.h index f7fce9e12f7..3058c907014 100644 --- a/backends/tc/ebpfCodeGen.h +++ b/backends/tc/ebpfCodeGen.h @@ -161,7 +161,6 @@ class EBPFTablePNA : public EBPF::EBPFTablePSA { void emitAction(EBPF::CodeBuilder *builder, cstring valueName, cstring actionRunVariable) override; void emitValueActionIDNames(EBPF::CodeBuilder *builder) override; - void emitDefaultAction(EBPF::CodeBuilder *builder, cstring valueName); cstring p4ActionToActionIDName(const IR::P4Action *action) const; DECLARE_TYPEINFO(EBPFTablePNA, EBPF::EBPFTablePSA); diff --git a/backends/tc/tc.def b/backends/tc/tc.def index 460f1368d99..95ad72d948a 100644 --- a/backends/tc/tc.def +++ b/backends/tc/tc.def @@ -45,6 +45,29 @@ class TCKernelMetadata { dbprint { out << toString(); } } +class TCDefaultActionParam { + cstring paramName; + cstring defaultValue; + void setParamName(cstring pN) { + paramName = pN; + } + void setDefaultValue(cstring dV) { + defaultValue = dV; + } + TCDefaultActionParam() { + paramName = nullptr; + defaultValue = nullptr; + } + toString { + std::string tcActionParam = ""; + tcActionParam += " param "; + tcActionParam += paramName; + tcActionParam += " " + defaultValue; + return tcActionParam; + } + dbprint { out << toString(); } +} + class TCActionParam { cstring paramName; unsigned dataType; @@ -176,11 +199,10 @@ class TCTable { unsigned tableEntriesCount; unsigned numMask; unsigned matchType; - TCAction preaction; - TCAction postaction; TCAction defaultHitAction; bool isDefaultHitConst; TCAction defaultMissAction; + optional safe_vector defaultMissActionParams; bool isDefaultMissConst; ordered_map actionList; safe_vector const_entries; @@ -197,12 +219,6 @@ class TCTable { void setMatchType(unsigned m) { matchType = m; } - void setPreaction(TCAction p) { - preaction = p; - } - void setPostaction(TCAction p) { - postaction = p; - } void setDefaultHitAction(TCAction d) { defaultHitAction = d; } @@ -245,8 +261,6 @@ class TCTable { tableEntriesCount = TC::DEFAULT_TABLE_ENTRIES; numMask = TC::DEFAULT_KEY_MASK; matchType = TC::EXACT_TYPE; - preaction = nullptr; - postaction = nullptr; defaultHitAction = nullptr; defaultMissAction = nullptr; isDefaultHitConst = false; @@ -278,19 +292,6 @@ class TCTable { } } } - - if (preaction != nullptr) { - tcTable += "\n" + preaction->toString(); - tcTable += "\n$TC p4template update table/" + pipelineName - + "/" + controlName + "/" + tableName - + " preactions action " + preaction->getName(); - } - if (postaction != nullptr) { - tcTable += "\n" + postaction->toString(); - tcTable += "\n$TC p4template update table/" + pipelineName - + "/" + controlName + "/" + tableName - + " postactions action " + postaction->getName(); - } if (defaultHitAction != nullptr) { tcTable += "\n$TC p4template update table/" + pipelineName + "/" + controlName + "/" + tableName @@ -308,6 +309,9 @@ class TCTable { tcTable += " permissions 0x1024"; } tcTable += " action " + defaultMissAction->getName(); + for (auto param : defaultMissActionParams) { + tcTable += param->toString(); + } } if (const_entries.size() != 0) { for (auto entry : const_entries) { diff --git a/testdata/p4tc_samples/default_action_with_param.p4 b/testdata/p4tc_samples/default_action_with_param.p4 new file mode 100644 index 00000000000..a6a5add1ca1 --- /dev/null +++ b/testdata/p4tc_samples/default_action_with_param.p4 @@ -0,0 +1,134 @@ +#include +#include + +typedef bit<48> EthernetAddress; + +header ethernet_t { + EthernetAddress dstAddr; + EthernetAddress srcAddr; + bit<16> etherType; +} + +header ipv4_t { + bit<4> version; + bit<4> ihl; + bit<8> diffserv; + bit<16> totalLen; + bit<16> identification; + bit<3> flags; + bit<13> fragOffset; + bit<8> ttl; + bit<8> protocol; + bit<16> hdrChecksum; + @tc_type ("ipv4") bit<32> srcAddr; + @tc_type ("ipv4") bit<32> dstAddr; +} + +////////////////////////////////////////////////////////////////////// +// Struct types for holding user-defined collections of headers and +// metadata in the P4 developer's program. +// +// Note: The names of these struct types are completely up to the P4 +// developer, as are their member fields, with the only restriction +// being that the structs intended to contain headers should only +// contain members whose types are header, header stack, or +// header_union. +////////////////////////////////////////////////////////////////////// + +struct main_metadata_t { + // empty for this skeleton +} + +// User-defined struct containing all of those headers parsed in the +// main parser. +struct headers_t { + ethernet_t ethernet; + ipv4_t ipv4; +} + +parser MainParserImpl( + packet_in pkt, + out headers_t hdr, + inout main_metadata_t main_meta, + in pna_main_parser_input_metadata_t istd) +{ + state start { + pkt.extract(hdr.ethernet); + transition select(hdr.ethernet.etherType) { + 0x0800 : parse_ipv4; + default : accept; + } + } + state parse_ipv4 { + pkt.extract(hdr.ipv4); + transition accept; + } +} + +control MainControlImpl( + inout headers_t hdr, // from main parser + inout main_metadata_t user_meta, // from main parser, to "next block" + in pna_main_input_metadata_t istd, + inout pna_main_output_metadata_t ostd) +{ + action next_hop(PortId_t vport) { + send_to_port(vport); + } + action default_route_drop() { + drop_packet(); + } + action drop() { + drop_packet(); + } + + table ipv4_tbl_1 { + key = { + hdr.ipv4.dstAddr : exact; + istd.input_port : exact; + } + actions = { + next_hop; + default_route_drop; + } + default_action = next_hop((PortId_t)8); + } + table ipv4_tbl_2 { + key = { + hdr.ipv4.dstAddr : exact; + hdr.ipv4.srcAddr : exact; + hdr.ipv4.protocol : exact; + } + actions = { + next_hop; + drop; + } + default_action = drop; + } + + apply { + if (hdr.ipv4.isValid()) { + ipv4_tbl_1.apply(); + ipv4_tbl_2.apply(); + } + } +} + +control MainDeparserImpl( + packet_out pkt, + inout headers_t hdr, // from main control + in main_metadata_t user_meta, // from main control + in pna_main_output_metadata_t ostd) +{ + apply { + pkt.emit(hdr.ethernet); + pkt.emit(hdr.ipv4); + } +} + +// BEGIN:Package_Instantiation_Example +PNA_NIC( + MainParserImpl(), + MainControlImpl(), + MainDeparserImpl() + ) main; +// END:Package_Instantiation_Example diff --git a/testdata/p4tc_samples_outputs/calculator_control_blocks.c b/testdata/p4tc_samples_outputs/calculator_control_blocks.c index c8ee1fbfac7..43f0423e96e 100644 --- a/testdata/p4tc_samples_outputs/calculator_control_blocks.c +++ b/testdata/p4tc_samples_outputs/calculator_control_blocks.c @@ -14,6 +14,7 @@ struct __attribute__((__packed__)) MainControlImpl_calculate_key { #define MAINCONTROLIMPL_CALCULATE_ACT_MAINCONTROLIMPL_OPERATION_OR 4 #define MAINCONTROLIMPL_CALCULATE_ACT_MAINCONTROLIMPL_OPERATION_XOR 5 #define MAINCONTROLIMPL_CALCULATE_ACT_MAINCONTROLIMPL_OPERATION_DROP 6 +#define MAINCONTROLIMPL_CALCULATE_ACT_NOACTION 0 struct __attribute__((__packed__)) MainControlImpl_calculate_value { unsigned int action; union { @@ -147,12 +148,12 @@ if (/* hdr->p4calc.isValid() */ drop_packet(); } break; - default: - return TC_ACT_SHOT; + case MAINCONTROLIMPL_CALCULATE_ACT_NOACTION: + { + } + break; } } else { -/* drop_packet() */ - drop_packet(); } } ; } diff --git a/testdata/p4tc_samples_outputs/checksum_control_blocks.c b/testdata/p4tc_samples_outputs/checksum_control_blocks.c index e7399e28c4b..93553943460 100644 --- a/testdata/p4tc_samples_outputs/checksum_control_blocks.c +++ b/testdata/p4tc_samples_outputs/checksum_control_blocks.c @@ -10,6 +10,7 @@ struct __attribute__((__packed__)) ingress_nh_table_key { } __attribute__((aligned(4))); #define INGRESS_NH_TABLE_ACT_INGRESS_SEND_NH 1 #define INGRESS_NH_TABLE_ACT_INGRESS_DROP 2 +#define INGRESS_NH_TABLE_ACT_NOACTION 0 struct __attribute__((__packed__)) ingress_nh_table_value { unsigned int action; union { @@ -89,12 +90,12 @@ static __always_inline int process(struct __sk_buff *skb, struct my_ingress_head drop_packet(); } break; - default: - return TC_ACT_SHOT; + case INGRESS_NH_TABLE_ACT_NOACTION: + { + } + break; } } else { -/* drop_packet() */ - drop_packet(); } } ; diff --git a/testdata/p4tc_samples_outputs/const_entries_range_mask_control_blocks.c b/testdata/p4tc_samples_outputs/const_entries_range_mask_control_blocks.c index 52d93bc14e5..c268906ed98 100644 --- a/testdata/p4tc_samples_outputs/const_entries_range_mask_control_blocks.c +++ b/testdata/p4tc_samples_outputs/const_entries_range_mask_control_blocks.c @@ -10,6 +10,7 @@ struct __attribute__((__packed__)) MainControlImpl_t_range_key { } __attribute__((aligned(4))); #define MAINCONTROLIMPL_T_RANGE_ACT_MAINCONTROLIMPL_A 1 #define MAINCONTROLIMPL_T_RANGE_ACT_MAINCONTROLIMPL_A_WITH_CONTROL_PARAMS 2 +#define MAINCONTROLIMPL_T_RANGE_ACT_NOACTION 0 struct __attribute__((__packed__)) MainControlImpl_t_range_value { unsigned int action; union { @@ -82,11 +83,12 @@ static __always_inline int process(struct __sk_buff *skb, struct Header_t *h, st h->h.t = value->u.MainControlImpl_a_with_control_params.x; } break; - default: - return TC_ACT_SHOT; + case MAINCONTROLIMPL_T_RANGE_ACT_NOACTION: + { + } + break; } } else { - h->h.e = 0; } } ; diff --git a/testdata/p4tc_samples_outputs/default_action_example_control_blocks.c b/testdata/p4tc_samples_outputs/default_action_example_control_blocks.c index 7ea9176b470..a7ca322de8e 100644 --- a/testdata/p4tc_samples_outputs/default_action_example_control_blocks.c +++ b/testdata/p4tc_samples_outputs/default_action_example_control_blocks.c @@ -11,6 +11,7 @@ struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_1_key { } __attribute__((aligned(4))); #define MAINCONTROLIMPL_IPV4_TBL_1_ACT_MAINCONTROLIMPL_NEXT_HOP 1 #define MAINCONTROLIMPL_IPV4_TBL_1_ACT_MAINCONTROLIMPL_DEFAULT_ROUTE_DROP 2 +#define MAINCONTROLIMPL_IPV4_TBL_1_ACT_NOACTION 0 struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_1_value { unsigned int action; union { @@ -32,6 +33,7 @@ struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_2_key { } __attribute__((aligned(4))); #define MAINCONTROLIMPL_IPV4_TBL_2_ACT_MAINCONTROLIMPL_NEXT_HOP 1 #define MAINCONTROLIMPL_IPV4_TBL_2_ACT_MAINCONTROLIMPL_DROP 3 +#define MAINCONTROLIMPL_IPV4_TBL_2_ACT_NOACTION 0 struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_2_value { unsigned int action; union { @@ -110,12 +112,12 @@ if (/* hdr->ipv4.isValid() */ drop_packet(); } break; - default: - return TC_ACT_SHOT; + case MAINCONTROLIMPL_IPV4_TBL_1_ACT_NOACTION: + { + } + break; } } else { -/* drop_packet() */ - drop_packet(); } } ; @@ -159,12 +161,12 @@ if (/* hdr->ipv4.isValid() */ drop_packet(); } break; - default: - return TC_ACT_SHOT; + case MAINCONTROLIMPL_IPV4_TBL_2_ACT_NOACTION: + { + } + break; } } else { -/* drop_packet() */ - drop_packet(); } } ; diff --git a/testdata/p4tc_samples_outputs/default_action_with_param.json b/testdata/p4tc_samples_outputs/default_action_with_param.json new file mode 100644 index 00000000000..39f68bcf3e9 --- /dev/null +++ b/testdata/p4tc_samples_outputs/default_action_with_param.json @@ -0,0 +1,114 @@ +{ + "schema_version" : "1.0.0", + "pipeline_name" : "default_action_with_param", + "id" : 1, + "tables" : [ + { + "name" : "MainControlImpl/ipv4_tbl_1", + "id" : 1, + "tentries" : 2048, + "nummask" : 8, + "keysize" : 64, + "keyfields" : [ + { + "id" : 1, + "name" : "hdr.ipv4.dstAddr", + "type" : "bit32", + "match_type" : "exact", + "bitwidth" : 32 + }, + { + "id" : 2, + "name" : "istd.input_port", + "type" : "bit32", + "match_type" : "exact", + "bitwidth" : 32 + } + ], + "actions" : [ + { + "id" : 1, + "name" : "MainControlImpl/next_hop", + "action_scope" : "TableAndDefault", + "annotations" : [], + "params" : [ + { + "id" : 1, + "name" : "vport", + "type" : "bit32", + "bitwidth" : 32 + } + ], + "default_hit_action" : false, + "default_miss_action" : true + }, + { + "id" : 2, + "name" : "MainControlImpl/default_route_drop", + "action_scope" : "TableAndDefault", + "annotations" : [], + "params" : [], + "default_hit_action" : false, + "default_miss_action" : false + } + ] + }, + { + "name" : "MainControlImpl/ipv4_tbl_2", + "id" : 2, + "tentries" : 2048, + "nummask" : 8, + "keysize" : 72, + "keyfields" : [ + { + "id" : 1, + "name" : "hdr.ipv4.dstAddr", + "type" : "bit32", + "match_type" : "exact", + "bitwidth" : 32 + }, + { + "id" : 2, + "name" : "hdr.ipv4.srcAddr", + "type" : "bit32", + "match_type" : "exact", + "bitwidth" : 32 + }, + { + "id" : 3, + "name" : "hdr.ipv4.protocol", + "type" : "bit8", + "match_type" : "exact", + "bitwidth" : 8 + } + ], + "actions" : [ + { + "id" : 1, + "name" : "MainControlImpl/next_hop", + "action_scope" : "TableAndDefault", + "annotations" : [], + "params" : [ + { + "id" : 1, + "name" : "vport", + "type" : "bit32", + "bitwidth" : 32 + } + ], + "default_hit_action" : false, + "default_miss_action" : false + }, + { + "id" : 3, + "name" : "MainControlImpl/drop", + "action_scope" : "TableAndDefault", + "annotations" : [], + "params" : [], + "default_hit_action" : false, + "default_miss_action" : true + } + ] + } + ] +} \ No newline at end of file diff --git a/testdata/p4tc_samples_outputs/default_action_with_param.p4-stderr b/testdata/p4tc_samples_outputs/default_action_with_param.p4-stderr new file mode 100644 index 00000000000..e69de29bb2d diff --git a/testdata/p4tc_samples_outputs/default_action_with_param.template b/testdata/p4tc_samples_outputs/default_action_with_param.template new file mode 100755 index 00000000000..dfcd7f2eb3a --- /dev/null +++ b/testdata/p4tc_samples_outputs/default_action_with_param.template @@ -0,0 +1,33 @@ +#!/bin/bash -x + +set -e + +TC="tc" +$TC p4template create pipeline/default_action_with_param pipeid 1 numtables 2 + +$TC p4template create action/default_action_with_param/MainControlImpl/next_hop actid 1 \ + param vport type bit32 +$TC p4template update action/default_action_with_param/MainControlImpl/next_hop state active + +$TC p4template create action/default_action_with_param/MainControlImpl/default_route_drop actid 2 +$TC p4template update action/default_action_with_param/MainControlImpl/default_route_drop state active + +$TC p4template create action/default_action_with_param/MainControlImpl/drop actid 3 +$TC p4template update action/default_action_with_param/MainControlImpl/drop state active + +$TC p4template create table/default_action_with_param/MainControlImpl/ipv4_tbl_1 \ + tblid 1 \ + type exact \ + keysz 64 nummasks 8 tentries 2048 \ + table_acts act name default_action_with_param/MainControlImpl/next_hop \ + act name default_action_with_param/MainControlImpl/default_route_drop +$TC p4template update table/default_action_with_param/MainControlImpl/ipv4_tbl_1 default_miss_action action default_action_with_param/MainControlImpl/next_hop param vport 8 + +$TC p4template create table/default_action_with_param/MainControlImpl/ipv4_tbl_2 \ + tblid 2 \ + type exact \ + keysz 72 nummasks 8 tentries 2048 \ + table_acts act name default_action_with_param/MainControlImpl/next_hop \ + act name default_action_with_param/MainControlImpl/drop +$TC p4template update table/default_action_with_param/MainControlImpl/ipv4_tbl_2 default_miss_action action default_action_with_param/MainControlImpl/drop +$TC p4template update pipeline/default_action_with_param state ready \ No newline at end of file diff --git a/testdata/p4tc_samples_outputs/default_action_with_param_control_blocks.c b/testdata/p4tc_samples_outputs/default_action_with_param_control_blocks.c new file mode 100644 index 00000000000..9517f7a6a06 --- /dev/null +++ b/testdata/p4tc_samples_outputs/default_action_with_param_control_blocks.c @@ -0,0 +1,358 @@ +#include "default_action_with_param_parser.h" +struct internal_metadata { + __u16 pkt_ether_type; +} __attribute__((aligned(4))); + +struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_1_key { + u32 keysz; + u32 maskid; + u32 field0; /* hdr.ipv4.dstAddr */ + u32 field1; /* istd.input_port */ +} __attribute__((aligned(4))); +#define MAINCONTROLIMPL_IPV4_TBL_1_ACT_MAINCONTROLIMPL_NEXT_HOP 1 +#define MAINCONTROLIMPL_IPV4_TBL_1_ACT_MAINCONTROLIMPL_DEFAULT_ROUTE_DROP 2 +#define MAINCONTROLIMPL_IPV4_TBL_1_ACT_NOACTION 0 +struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_1_value { + unsigned int action; + union { + struct { + } _NoAction; + struct __attribute__((__packed__)) { + u32 vport; + } MainControlImpl_next_hop; + struct { + } MainControlImpl_default_route_drop; + } u; +}; +struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_2_key { + u32 keysz; + u32 maskid; + u32 field0; /* hdr.ipv4.dstAddr */ + u32 field1; /* hdr.ipv4.srcAddr */ + u8 field2; /* hdr.ipv4.protocol */ +} __attribute__((aligned(4))); +#define MAINCONTROLIMPL_IPV4_TBL_2_ACT_MAINCONTROLIMPL_NEXT_HOP 1 +#define MAINCONTROLIMPL_IPV4_TBL_2_ACT_MAINCONTROLIMPL_DROP 3 +#define MAINCONTROLIMPL_IPV4_TBL_2_ACT_NOACTION 0 +struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_2_value { + unsigned int action; + union { + struct { + } _NoAction; + struct __attribute__((__packed__)) { + u32 vport; + } MainControlImpl_next_hop; + struct { + } MainControlImpl_drop; + } u; +}; + +static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr, struct pna_global_metadata *compiler_meta__) +{ + struct hdr_md *hdrMd; + + unsigned ebpf_packetOffsetInBits_save = 0; + ParserError_t ebpf_errorCode = NoError; + void* pkt = ((void*)(long)skb->data); + u8* hdr_start = pkt; + void* ebpf_packetEnd = ((void*)(long)skb->data_end); + u32 ebpf_zero = 0; + u32 ebpf_one = 1; + unsigned char ebpf_byte; + u32 pkt_len = skb->len; + + struct main_metadata_t *user_meta; + hdrMd = BPF_MAP_LOOKUP_ELEM(hdr_md_cpumap, &ebpf_zero); + if (!hdrMd) + return TC_ACT_SHOT; + unsigned ebpf_packetOffsetInBits = hdrMd->ebpf_packetOffsetInBits; + hdr = &(hdrMd->cpumap_hdr); + user_meta = &(hdrMd->cpumap_usermeta); +{ + u8 hit; + { +if (/* hdr->ipv4.isValid() */ + hdr->ipv4.ebpf_valid) { +/* ipv4_tbl.apply() */ + { + /* construct key */ + struct p4tc_table_entry_act_bpf_params__local params = { + .pipeid = 1, + .tblid = 1 + }; + struct MainControlImpl_ipv4_tbl_1_key key = {}; + key.keysz = 64; + key.field0 = hdr->ipv4.dstAddr; + key.field1 = skb->ifindex; + struct p4tc_table_entry_act_bpf *act_bpf; + /* value */ + struct MainControlImpl_ipv4_tbl_1_value *value = NULL; + /* perform lookup */ + act_bpf = bpf_p4tc_tbl_read(skb, ¶ms, &key, sizeof(key)); + value = (struct MainControlImpl_ipv4_tbl_1_value *)act_bpf; + if (value == NULL) { + /* miss; find default action */ + hit = 0; + } else { + hit = 1; + } + if (value != NULL) { + /* run action */ + switch (value->action) { + case MAINCONTROLIMPL_IPV4_TBL_1_ACT_MAINCONTROLIMPL_NEXT_HOP: + { +/* send_to_port(value->u.MainControlImpl_next_hop.vport) */ + compiler_meta__->drop = false; + send_to_port(value->u.MainControlImpl_next_hop.vport); + } + break; + case MAINCONTROLIMPL_IPV4_TBL_1_ACT_MAINCONTROLIMPL_DEFAULT_ROUTE_DROP: + { +/* drop_packet() */ + drop_packet(); + } + break; + case MAINCONTROLIMPL_IPV4_TBL_1_ACT_NOACTION: + { + } + break; + } + } else { + } + } +; + /* ipv4_tbl_0.apply() */ + { + /* construct key */ + struct p4tc_table_entry_act_bpf_params__local params = { + .pipeid = 1, + .tblid = 2 + }; + struct MainControlImpl_ipv4_tbl_2_key key = {}; + key.keysz = 72; + key.field0 = hdr->ipv4.dstAddr; + key.field1 = hdr->ipv4.srcAddr; + key.field2 = hdr->ipv4.protocol; + struct p4tc_table_entry_act_bpf *act_bpf; + /* value */ + struct MainControlImpl_ipv4_tbl_2_value *value = NULL; + /* perform lookup */ + act_bpf = bpf_p4tc_tbl_read(skb, ¶ms, &key, sizeof(key)); + value = (struct MainControlImpl_ipv4_tbl_2_value *)act_bpf; + if (value == NULL) { + /* miss; find default action */ + hit = 0; + } else { + hit = 1; + } + if (value != NULL) { + /* run action */ + switch (value->action) { + case MAINCONTROLIMPL_IPV4_TBL_2_ACT_MAINCONTROLIMPL_NEXT_HOP: + { +/* send_to_port(value->u.MainControlImpl_next_hop.vport) */ + compiler_meta__->drop = false; + send_to_port(value->u.MainControlImpl_next_hop.vport); + } + break; + case MAINCONTROLIMPL_IPV4_TBL_2_ACT_MAINCONTROLIMPL_DROP: + { +/* drop_packet() */ + drop_packet(); + } + break; + case MAINCONTROLIMPL_IPV4_TBL_2_ACT_NOACTION: + { + } + break; + } + } else { + } + } +; + } + } + } + { +{ +; + ; + } + + if (compiler_meta__->drop) { + return TC_ACT_SHOT; + } + int outHeaderLength = 0; + if (hdr->ethernet.ebpf_valid) { + outHeaderLength += 112; + } +; if (hdr->ipv4.ebpf_valid) { + outHeaderLength += 160; + } +; + int outHeaderOffset = BYTES(outHeaderLength) - (hdr_start - (u8*)pkt); + if (outHeaderOffset != 0) { + int returnCode = 0; + returnCode = bpf_skb_adjust_room(skb, outHeaderOffset, 1, 0); + if (returnCode) { + return TC_ACT_SHOT; + } + } + pkt = ((void*)(long)skb->data); + ebpf_packetEnd = ((void*)(long)skb->data_end); + ebpf_packetOffsetInBits = 0; + if (hdr->ethernet.ebpf_valid) { + if (ebpf_packetEnd < pkt + BYTES(ebpf_packetOffsetInBits + 112)) { + return TC_ACT_SHOT; + } + + hdr->ethernet.dstAddr = htonll(hdr->ethernet.dstAddr << 16); + ebpf_byte = ((char*)(&hdr->ethernet.dstAddr))[0]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 0, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ethernet.dstAddr))[1]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 1, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ethernet.dstAddr))[2]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 2, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ethernet.dstAddr))[3]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 3, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ethernet.dstAddr))[4]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 4, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ethernet.dstAddr))[5]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 5, (ebpf_byte)); + ebpf_packetOffsetInBits += 48; + + hdr->ethernet.srcAddr = htonll(hdr->ethernet.srcAddr << 16); + ebpf_byte = ((char*)(&hdr->ethernet.srcAddr))[0]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 0, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ethernet.srcAddr))[1]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 1, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ethernet.srcAddr))[2]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 2, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ethernet.srcAddr))[3]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 3, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ethernet.srcAddr))[4]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 4, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ethernet.srcAddr))[5]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 5, (ebpf_byte)); + ebpf_packetOffsetInBits += 48; + + hdr->ethernet.etherType = bpf_htons(hdr->ethernet.etherType); + ebpf_byte = ((char*)(&hdr->ethernet.etherType))[0]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 0, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ethernet.etherType))[1]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 1, (ebpf_byte)); + ebpf_packetOffsetInBits += 16; + + } +; if (hdr->ipv4.ebpf_valid) { + if (ebpf_packetEnd < pkt + BYTES(ebpf_packetOffsetInBits + 160)) { + return TC_ACT_SHOT; + } + + ebpf_byte = ((char*)(&hdr->ipv4.version))[0]; + write_partial(pkt + BYTES(ebpf_packetOffsetInBits) + 0, 4, 4, (ebpf_byte >> 0)); + ebpf_packetOffsetInBits += 4; + + ebpf_byte = ((char*)(&hdr->ipv4.ihl))[0]; + write_partial(pkt + BYTES(ebpf_packetOffsetInBits) + 0, 4, 0, (ebpf_byte >> 0)); + ebpf_packetOffsetInBits += 4; + + ebpf_byte = ((char*)(&hdr->ipv4.diffserv))[0]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 0, (ebpf_byte)); + ebpf_packetOffsetInBits += 8; + + hdr->ipv4.totalLen = bpf_htons(hdr->ipv4.totalLen); + ebpf_byte = ((char*)(&hdr->ipv4.totalLen))[0]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 0, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ipv4.totalLen))[1]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 1, (ebpf_byte)); + ebpf_packetOffsetInBits += 16; + + hdr->ipv4.identification = bpf_htons(hdr->ipv4.identification); + ebpf_byte = ((char*)(&hdr->ipv4.identification))[0]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 0, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ipv4.identification))[1]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 1, (ebpf_byte)); + ebpf_packetOffsetInBits += 16; + + ebpf_byte = ((char*)(&hdr->ipv4.flags))[0]; + write_partial(pkt + BYTES(ebpf_packetOffsetInBits) + 0, 3, 5, (ebpf_byte >> 0)); + ebpf_packetOffsetInBits += 3; + + hdr->ipv4.fragOffset = bpf_htons(hdr->ipv4.fragOffset << 3); + ebpf_byte = ((char*)(&hdr->ipv4.fragOffset))[0]; + write_partial(pkt + BYTES(ebpf_packetOffsetInBits) + 0, 5, 0, (ebpf_byte >> 3)); + write_partial(pkt + BYTES(ebpf_packetOffsetInBits) + 0 + 1, 3, 5, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ipv4.fragOffset))[1]; + write_partial(pkt + BYTES(ebpf_packetOffsetInBits) + 1, 5, 0, (ebpf_byte >> 3)); + ebpf_packetOffsetInBits += 13; + + ebpf_byte = ((char*)(&hdr->ipv4.ttl))[0]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 0, (ebpf_byte)); + ebpf_packetOffsetInBits += 8; + + ebpf_byte = ((char*)(&hdr->ipv4.protocol))[0]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 0, (ebpf_byte)); + ebpf_packetOffsetInBits += 8; + + hdr->ipv4.hdrChecksum = bpf_htons(hdr->ipv4.hdrChecksum); + ebpf_byte = ((char*)(&hdr->ipv4.hdrChecksum))[0]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 0, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ipv4.hdrChecksum))[1]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 1, (ebpf_byte)); + ebpf_packetOffsetInBits += 16; + + ebpf_byte = ((char*)(&hdr->ipv4.srcAddr))[0]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 0, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ipv4.srcAddr))[1]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 1, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ipv4.srcAddr))[2]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 2, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ipv4.srcAddr))[3]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 3, (ebpf_byte)); + ebpf_packetOffsetInBits += 32; + + ebpf_byte = ((char*)(&hdr->ipv4.dstAddr))[0]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 0, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ipv4.dstAddr))[1]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 1, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ipv4.dstAddr))[2]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 2, (ebpf_byte)); + ebpf_byte = ((char*)(&hdr->ipv4.dstAddr))[3]; + write_byte(pkt, BYTES(ebpf_packetOffsetInBits) + 3, (ebpf_byte)); + ebpf_packetOffsetInBits += 32; + + } +; + } + return -1; +} +SEC("p4tc/main") +int tc_ingress_func(struct __sk_buff *skb) { + struct pna_global_metadata *compiler_meta__ = (struct pna_global_metadata *) skb->cb; + if (compiler_meta__->pass_to_kernel == true) return TC_ACT_OK; + if (!compiler_meta__->recirculated) { + compiler_meta__->mark = 153; + struct internal_metadata *md = (struct internal_metadata *)(unsigned long)skb->data_meta; + if ((void *) ((struct internal_metadata *) md + 1) <= (void *)(long)skb->data) { + __u16 *ether_type = (__u16 *) ((void *) (long)skb->data + 12); + if ((void *) ((__u16 *) ether_type + 1) > (void *) (long) skb->data_end) { + return TC_ACT_SHOT; + } + *ether_type = md->pkt_ether_type; + } + } + struct hdr_md *hdrMd; + struct headers_t *hdr; + int ret = -1; + ret = process(skb, (struct headers_t *) hdr, compiler_meta__); + if (ret != -1) { + return ret; + } + if (!compiler_meta__->drop && compiler_meta__->egress_port == 0) { + compiler_meta__->pass_to_kernel = true; + return bpf_redirect(skb->ifindex, BPF_F_INGRESS); + } + return bpf_redirect(compiler_meta__->egress_port, 0); +} +char _license[] SEC("license") = "GPL"; diff --git a/testdata/p4tc_samples_outputs/default_action_with_param_parser.c b/testdata/p4tc_samples_outputs/default_action_with_param_parser.c new file mode 100644 index 00000000000..808acbb6d84 --- /dev/null +++ b/testdata/p4tc_samples_outputs/default_action_with_param_parser.c @@ -0,0 +1,133 @@ +#include "default_action_with_param_parser.h" + +static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *hdr, struct pna_global_metadata *compiler_meta__) +{ + struct hdr_md *hdrMd; + + unsigned ebpf_packetOffsetInBits_save = 0; + ParserError_t ebpf_errorCode = NoError; + void* pkt = ((void*)(long)skb->data); + u8* hdr_start = pkt; + void* ebpf_packetEnd = ((void*)(long)skb->data_end); + u32 ebpf_zero = 0; + u32 ebpf_one = 1; + unsigned char ebpf_byte; + u32 pkt_len = skb->len; + + struct main_metadata_t *user_meta; + + hdrMd = BPF_MAP_LOOKUP_ELEM(hdr_md_cpumap, &ebpf_zero); + if (!hdrMd) + return TC_ACT_SHOT; + __builtin_memset(hdrMd, 0, sizeof(struct hdr_md)); + + unsigned ebpf_packetOffsetInBits = 0; + hdr = &(hdrMd->cpumap_hdr); + user_meta = &(hdrMd->cpumap_usermeta); + { + goto start; + parse_ipv4: { +/* extract(hdr->ipv4) */ + if ((u8*)ebpf_packetEnd < hdr_start + BYTES(160 + 0)) { + ebpf_errorCode = PacketTooShort; + goto reject; + } + + hdr->ipv4.version = (u8)((load_byte(pkt, BYTES(ebpf_packetOffsetInBits)) >> 4) & EBPF_MASK(u8, 4)); + ebpf_packetOffsetInBits += 4; + + hdr->ipv4.ihl = (u8)((load_byte(pkt, BYTES(ebpf_packetOffsetInBits))) & EBPF_MASK(u8, 4)); + ebpf_packetOffsetInBits += 4; + + hdr->ipv4.diffserv = (u8)((load_byte(pkt, BYTES(ebpf_packetOffsetInBits)))); + ebpf_packetOffsetInBits += 8; + + hdr->ipv4.totalLen = (u16)((load_half(pkt, BYTES(ebpf_packetOffsetInBits)))); + ebpf_packetOffsetInBits += 16; + + hdr->ipv4.identification = (u16)((load_half(pkt, BYTES(ebpf_packetOffsetInBits)))); + ebpf_packetOffsetInBits += 16; + + hdr->ipv4.flags = (u8)((load_byte(pkt, BYTES(ebpf_packetOffsetInBits)) >> 5) & EBPF_MASK(u8, 3)); + ebpf_packetOffsetInBits += 3; + + hdr->ipv4.fragOffset = (u16)((load_half(pkt, BYTES(ebpf_packetOffsetInBits))) & EBPF_MASK(u16, 13)); + ebpf_packetOffsetInBits += 13; + + hdr->ipv4.ttl = (u8)((load_byte(pkt, BYTES(ebpf_packetOffsetInBits)))); + ebpf_packetOffsetInBits += 8; + + hdr->ipv4.protocol = (u8)((load_byte(pkt, BYTES(ebpf_packetOffsetInBits)))); + ebpf_packetOffsetInBits += 8; + + hdr->ipv4.hdrChecksum = (u16)((load_half(pkt, BYTES(ebpf_packetOffsetInBits)))); + ebpf_packetOffsetInBits += 16; + + __builtin_memcpy(&hdr->ipv4.srcAddr, pkt + BYTES(ebpf_packetOffsetInBits), 4); + ebpf_packetOffsetInBits += 32; + + __builtin_memcpy(&hdr->ipv4.dstAddr, pkt + BYTES(ebpf_packetOffsetInBits), 4); + ebpf_packetOffsetInBits += 32; + + + hdr->ipv4.ebpf_valid = 1; + hdr_start += BYTES(160); + +; + goto accept; + } + start: { +/* extract(hdr->ethernet) */ + if ((u8*)ebpf_packetEnd < hdr_start + BYTES(112 + 0)) { + ebpf_errorCode = PacketTooShort; + goto reject; + } + + hdr->ethernet.dstAddr = (u64)((load_dword(pkt, BYTES(ebpf_packetOffsetInBits)) >> 16) & EBPF_MASK(u64, 48)); + ebpf_packetOffsetInBits += 48; + + hdr->ethernet.srcAddr = (u64)((load_dword(pkt, BYTES(ebpf_packetOffsetInBits)) >> 16) & EBPF_MASK(u64, 48)); + ebpf_packetOffsetInBits += 48; + + hdr->ethernet.etherType = (u16)((load_half(pkt, BYTES(ebpf_packetOffsetInBits)))); + ebpf_packetOffsetInBits += 16; + + + hdr->ethernet.ebpf_valid = 1; + hdr_start += BYTES(112); + +; + u16 select_0; + select_0 = hdr->ethernet.etherType; + if (select_0 == 0x800)goto parse_ipv4; + if ((select_0 & 0x0) == (0x0 & 0x0))goto accept; + else goto reject; + } + + reject: { + if (ebpf_errorCode == 0) { + return TC_ACT_SHOT; + } + goto accept; + } + + } + + accept: + hdrMd->ebpf_packetOffsetInBits = ebpf_packetOffsetInBits; + return -1; +} + +SEC("p4tc/parse") +int tc_parse_func(struct __sk_buff *skb) { + struct pna_global_metadata *compiler_meta__ = (struct pna_global_metadata *) skb->cb; + struct hdr_md *hdrMd; + struct headers_t *hdr; + int ret = -1; + ret = run_parser(skb, (struct headers_t *) hdr, compiler_meta__); + if (ret != -1) { + return ret; + } + return TC_ACT_PIPE; + } +char _license[] SEC("license") = "GPL"; diff --git a/testdata/p4tc_samples_outputs/default_action_with_param_parser.h b/testdata/p4tc_samples_outputs/default_action_with_param_parser.h new file mode 100644 index 00000000000..7a83e41dd95 --- /dev/null +++ b/testdata/p4tc_samples_outputs/default_action_with_param_parser.h @@ -0,0 +1,161 @@ +#include "ebpf_kernel.h" + +#include +#include +#include "pna.h" + +#define EBPF_MASK(t, w) ((((t)(1)) << (w)) - (t)1) +#define BYTES(w) ((w) / 8) +#define write_partial(a, w, s, v) do { *((u8*)a) = ((*((u8*)a)) & ~(EBPF_MASK(u8, w) << s)) | (v << s) ; } while (0) +#define write_byte(base, offset, v) do { *(u8*)((base) + (offset)) = (v); } while (0) +#define bpf_trace_message(fmt, ...) + + +struct ethernet_t { + u64 dstAddr; /* EthernetAddress */ + u64 srcAddr; /* EthernetAddress */ + u16 etherType; /* bit<16> */ + u8 ebpf_valid; +}; +struct ipv4_t { + u8 version; /* bit<4> */ + u8 ihl; /* bit<4> */ + u8 diffserv; /* bit<8> */ + u16 totalLen; /* bit<16> */ + u16 identification; /* bit<16> */ + u8 flags; /* bit<3> */ + u16 fragOffset; /* bit<13> */ + u8 ttl; /* bit<8> */ + u8 protocol; /* bit<8> */ + u16 hdrChecksum; /* bit<16> */ + u32 srcAddr; /* bit<32> */ + u32 dstAddr; /* bit<32> */ + u8 ebpf_valid; +}; +struct main_metadata_t { +}; +struct headers_t { + struct ethernet_t ethernet; /* ethernet_t */ + struct ipv4_t ipv4; /* ipv4_t */ +}; + +struct hdr_md { + struct headers_t cpumap_hdr; + struct main_metadata_t cpumap_usermeta; + unsigned ebpf_packetOffsetInBits; + __u8 __hook; +}; + + +struct lookup_tbl_val { + u32 table[2048]; +}; +REGISTER_START() +REGISTER_TABLE(hdr_md_cpumap, BPF_MAP_TYPE_PERCPU_ARRAY, u32, struct hdr_md, 2) +BPF_ANNOTATE_KV_PAIR(hdr_md_cpumap, u32, struct hdr_md) +REGISTER_TABLE(crc_lookup_tbl, BPF_MAP_TYPE_ARRAY, u32, struct lookup_tbl_val, 1) +BPF_ANNOTATE_KV_PAIR(crc_lookup_tbl, u32, struct lookup_tbl_val) +REGISTER_END() + +static __always_inline +void crc16_update(u16 * reg, const u8 * data, u16 data_size, const u16 poly) { + if (data_size <= 8) + data += data_size - 1; + #pragma clang loop unroll(full) + for (u16 i = 0; i < data_size; i++) { + bpf_trace_message("CRC16: data byte: %x\n", *data); + *reg ^= *data; + for (u8 bit = 0; bit < 8; bit++) { + *reg = (*reg) & 1 ? ((*reg) >> 1) ^ poly : (*reg) >> 1; + } + if (data_size <= 8) + data--; + else + data++; + } +} +static __always_inline u16 crc16_finalize(u16 reg) { + return reg; +} +static __always_inline +void crc32_update(u32 * reg, const u8 * data, u16 data_size, const u32 poly) { + u32* current = (u32*) data; + struct lookup_tbl_val* lookup_table; + u32 index = 0; + lookup_table = BPF_MAP_LOOKUP_ELEM(crc_lookup_tbl, &index); + u32 lookup_key = 0; + u32 lookup_value = 0; + u32 lookup_value1 = 0; + u32 lookup_value2 = 0; + u32 lookup_value3 = 0; + u32 lookup_value4 = 0; + u32 lookup_value5 = 0; + u32 lookup_value6 = 0; + u32 lookup_value7 = 0; + u32 lookup_value8 = 0; + u16 tmp = 0; + if (lookup_table != NULL) { + for (u16 i = data_size; i >= 8; i -= 8) { + /* Vars one and two will have swapped byte order if data_size == 8 */ + if (data_size == 8) current = data + 4; + bpf_trace_message("CRC32: data dword: %x\n", *current); + u32 one = (data_size == 8 ? __builtin_bswap32(*current--) : *current++) ^ *reg; + bpf_trace_message("CRC32: data dword: %x\n", *current); + u32 two = (data_size == 8 ? __builtin_bswap32(*current--) : *current++); + lookup_key = (one & 0x000000FF); + lookup_value8 = lookup_table->table[(u16)(1792 + (u8)lookup_key)]; + lookup_key = (one >> 8) & 0x000000FF; + lookup_value7 = lookup_table->table[(u16)(1536 + (u8)lookup_key)]; + lookup_key = (one >> 16) & 0x000000FF; + lookup_value6 = lookup_table->table[(u16)(1280 + (u8)lookup_key)]; + lookup_key = one >> 24; + lookup_value5 = lookup_table->table[(u16)(1024 + (u8)(lookup_key))]; + lookup_key = (two & 0x000000FF); + lookup_value4 = lookup_table->table[(u16)(768 + (u8)lookup_key)]; + lookup_key = (two >> 8) & 0x000000FF; + lookup_value3 = lookup_table->table[(u16)(512 + (u8)lookup_key)]; + lookup_key = (two >> 16) & 0x000000FF; + lookup_value2 = lookup_table->table[(u16)(256 + (u8)lookup_key)]; + lookup_key = two >> 24; + lookup_value1 = lookup_table->table[(u8)(lookup_key)]; + *reg = lookup_value8 ^ lookup_value7 ^ lookup_value6 ^ lookup_value5 ^ + lookup_value4 ^ lookup_value3 ^ lookup_value2 ^ lookup_value1; + tmp += 8; + } + volatile int std_algo_lookup_key = 0; + if (data_size < 8) { + unsigned char *currentChar = (unsigned char *) current; + currentChar += data_size - 1; + for (u16 i = tmp; i < data_size; i++) { + bpf_trace_message("CRC32: data byte: %x\n", *currentChar); + std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar--); + if (std_algo_lookup_key >= 0) { + lookup_value = lookup_table->table[(u8)(std_algo_lookup_key & 255)]; + } + *reg = ((*reg) >> 8) ^ lookup_value; + } + } else { + /* Consume data not processed by slice-by-8 algorithm above, these data are in network byte order */ + unsigned char *currentChar = (unsigned char *) current; + for (u16 i = tmp; i < data_size; i++) { + bpf_trace_message("CRC32: data byte: %x\n", *currentChar); + std_algo_lookup_key = (u32)(((*reg) & 0xFF) ^ *currentChar++); + if (std_algo_lookup_key >= 0) { + lookup_value = lookup_table->table[(u8)(std_algo_lookup_key & 255)]; + } + *reg = ((*reg) >> 8) ^ lookup_value; + } + } + } +} +static __always_inline u32 crc32_finalize(u32 reg) { + return reg ^ 0xFFFFFFFF; +} +inline u16 csum16_add(u16 csum, u16 addend) { + u16 res = csum; + res += addend; + return (res + (res < addend)); +} +inline u16 csum16_sub(u16 csum, u16 addend) { + return csum16_add(csum, ~addend); +} diff --git a/testdata/p4tc_samples_outputs/default_hit_const_example_control_blocks.c b/testdata/p4tc_samples_outputs/default_hit_const_example_control_blocks.c index 2b7016a7840..3dc4b88c2df 100644 --- a/testdata/p4tc_samples_outputs/default_hit_const_example_control_blocks.c +++ b/testdata/p4tc_samples_outputs/default_hit_const_example_control_blocks.c @@ -15,6 +15,7 @@ struct MainControlImpl_set_ct_options_key_mask { #define MAINCONTROLIMPL_SET_CT_OPTIONS_ACT_MAINCONTROLIMPL_TCP_SYN_PACKET 1 #define MAINCONTROLIMPL_SET_CT_OPTIONS_ACT_MAINCONTROLIMPL_TCP_FIN_OR_RST_PACKET 2 #define MAINCONTROLIMPL_SET_CT_OPTIONS_ACT_MAINCONTROLIMPL_TCP_OTHER_PACKETS 3 +#define MAINCONTROLIMPL_SET_CT_OPTIONS_ACT_NOACTION 0 struct __attribute__((__packed__)) MainControlImpl_set_ct_options_value { unsigned int action; __u32 priority; @@ -94,8 +95,10 @@ if (/* hdr->ipv4.isValid() */ { } break; - default: - return TC_ACT_SHOT; + case MAINCONTROLIMPL_SET_CT_OPTIONS_ACT_NOACTION: + { + } + break; } } else { } diff --git a/testdata/p4tc_samples_outputs/drop_packet_example_control_blocks.c b/testdata/p4tc_samples_outputs/drop_packet_example_control_blocks.c index a0ff3512ca9..9a44cc783b3 100644 --- a/testdata/p4tc_samples_outputs/drop_packet_example_control_blocks.c +++ b/testdata/p4tc_samples_outputs/drop_packet_example_control_blocks.c @@ -10,6 +10,7 @@ struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_key { } __attribute__((aligned(4))); #define MAINCONTROLIMPL_IPV4_TBL_ACT_MAINCONTROLIMPL_NEXT_HOP 1 #define MAINCONTROLIMPL_IPV4_TBL_ACT_MAINCONTROLIMPL_DEFAULT_ROUTE_DROP 2 +#define MAINCONTROLIMPL_IPV4_TBL_ACT_NOACTION 0 struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_value { unsigned int action; union { @@ -87,12 +88,12 @@ if (/* hdr->ipv4.isValid() */ drop_packet(); } break; - default: - return TC_ACT_SHOT; + case MAINCONTROLIMPL_IPV4_TBL_ACT_NOACTION: + { + } + break; } } else { -/* drop_packet() */ - drop_packet(); } } ; } diff --git a/testdata/p4tc_samples_outputs/global_action_example_01_control_blocks.c b/testdata/p4tc_samples_outputs/global_action_example_01_control_blocks.c index 6c89c963fea..f49bd499b7c 100644 --- a/testdata/p4tc_samples_outputs/global_action_example_01_control_blocks.c +++ b/testdata/p4tc_samples_outputs/global_action_example_01_control_blocks.c @@ -10,6 +10,7 @@ struct __attribute__((__packed__)) ingress_nh_table2_key { } __attribute__((aligned(4))); #define INGRESS_NH_TABLE2_ACT_INGRESS_SEND_NH 2 #define INGRESS_NH_TABLE2_ACT_INGRESS_DROP 3 +#define INGRESS_NH_TABLE2_ACT_NOACTION 0 struct __attribute__((__packed__)) ingress_nh_table2_value { unsigned int action; union { @@ -30,6 +31,7 @@ struct __attribute__((__packed__)) ingress_nh_table_key { } __attribute__((aligned(4))); #define INGRESS_NH_TABLE_ACT__SEND_NH 1 #define INGRESS_NH_TABLE_ACT_INGRESS_DROP 3 +#define INGRESS_NH_TABLE_ACT_NOACTION 0 struct __attribute__((__packed__)) ingress_nh_table_value { unsigned int action; union { @@ -109,12 +111,12 @@ static __always_inline int process(struct __sk_buff *skb, struct my_ingress_head drop_packet(); } break; - default: - return TC_ACT_SHOT; + case INGRESS_NH_TABLE_ACT_NOACTION: + { + } + break; } } else { -/* drop_packet() */ - drop_packet(); } } ; @@ -157,12 +159,12 @@ static __always_inline int process(struct __sk_buff *skb, struct my_ingress_head drop_packet(); } break; - default: - return TC_ACT_SHOT; + case INGRESS_NH_TABLE2_ACT_NOACTION: + { + } + break; } } else { -/* drop_packet() */ - drop_packet(); } } ; diff --git a/testdata/p4tc_samples_outputs/global_action_example_02_control_blocks.c b/testdata/p4tc_samples_outputs/global_action_example_02_control_blocks.c index 41501139119..d773bbfb188 100644 --- a/testdata/p4tc_samples_outputs/global_action_example_02_control_blocks.c +++ b/testdata/p4tc_samples_outputs/global_action_example_02_control_blocks.c @@ -10,6 +10,7 @@ struct __attribute__((__packed__)) ingress_nh_table2_key { } __attribute__((aligned(4))); #define INGRESS_NH_TABLE2_ACT_INGRESS_SEND_NH 2 #define INGRESS_NH_TABLE2_ACT_INGRESS_DROP 3 +#define INGRESS_NH_TABLE2_ACT_NOACTION 0 struct __attribute__((__packed__)) ingress_nh_table2_value { unsigned int action; union { @@ -31,6 +32,7 @@ struct __attribute__((__packed__)) ingress_nh_table_key { } __attribute__((aligned(4))); #define INGRESS_NH_TABLE_ACT_INGRESS_SEND_NH 2 #define INGRESS_NH_TABLE_ACT__DROP 1 +#define INGRESS_NH_TABLE_ACT_NOACTION 0 struct __attribute__((__packed__)) ingress_nh_table_value { unsigned int action; union { @@ -110,12 +112,12 @@ static __always_inline int process(struct __sk_buff *skb, struct my_ingress_head drop_packet(); } break; - default: - return TC_ACT_SHOT; + case INGRESS_NH_TABLE_ACT_NOACTION: + { + } + break; } } else { -/* drop_packet() */ - drop_packet(); } } ; @@ -159,12 +161,12 @@ static __always_inline int process(struct __sk_buff *skb, struct my_ingress_head drop_packet(); } break; - default: - return TC_ACT_SHOT; + case INGRESS_NH_TABLE2_ACT_NOACTION: + { + } + break; } } else { -/* drop_packet() */ - drop_packet(); } } ; diff --git a/testdata/p4tc_samples_outputs/ipip_control_blocks.c b/testdata/p4tc_samples_outputs/ipip_control_blocks.c index 7338768de51..9003d84f9c7 100644 --- a/testdata/p4tc_samples_outputs/ipip_control_blocks.c +++ b/testdata/p4tc_samples_outputs/ipip_control_blocks.c @@ -11,6 +11,7 @@ struct __attribute__((__packed__)) Main_fwd_table_key { #define MAIN_FWD_TABLE_ACT_MAIN_SET_IPIP 1 #define MAIN_FWD_TABLE_ACT_MAIN_SET_NH 2 #define MAIN_FWD_TABLE_ACT_MAIN_DROP 3 +#define MAIN_FWD_TABLE_ACT_NOACTION 0 struct __attribute__((__packed__)) Main_fwd_table_value { unsigned int action; union { @@ -105,12 +106,12 @@ if (/* hdr->outer.isValid() */ drop_packet(); } break; - default: - return TC_ACT_SHOT; + case MAIN_FWD_TABLE_ACT_NOACTION: + { + } + break; } } else { -/* drop_packet() */ - drop_packet(); } } ; diff --git a/testdata/p4tc_samples_outputs/matchtype_control_blocks.c b/testdata/p4tc_samples_outputs/matchtype_control_blocks.c index bb08dfd9ab7..b04a3626384 100644 --- a/testdata/p4tc_samples_outputs/matchtype_control_blocks.c +++ b/testdata/p4tc_samples_outputs/matchtype_control_blocks.c @@ -10,6 +10,7 @@ struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_1_key { } __attribute__((aligned(4))); #define MAINCONTROLIMPL_IPV4_TBL_1_ACT_MAINCONTROLIMPL_NEXT_HOP 1 #define MAINCONTROLIMPL_IPV4_TBL_1_ACT_MAINCONTROLIMPL_DEFAULT_ROUTE_DROP 2 +#define MAINCONTROLIMPL_IPV4_TBL_1_ACT_NOACTION 0 struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_1_value { unsigned int action; union { @@ -35,6 +36,7 @@ struct MainControlImpl_ipv4_tbl_2_key_mask { } __attribute__((aligned(4))); #define MAINCONTROLIMPL_IPV4_TBL_2_ACT_MAINCONTROLIMPL_NEXT_HOP 1 #define MAINCONTROLIMPL_IPV4_TBL_2_ACT_MAINCONTROLIMPL_DROP 3 +#define MAINCONTROLIMPL_IPV4_TBL_2_ACT_NOACTION 0 struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_2_value { unsigned int action; __u32 priority; @@ -55,6 +57,7 @@ struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_3_key { } __attribute__((aligned(4))); #define MAINCONTROLIMPL_IPV4_TBL_3_ACT_MAINCONTROLIMPL_NEXT_HOP 1 #define MAINCONTROLIMPL_IPV4_TBL_3_ACT_MAINCONTROLIMPL_DROP 3 +#define MAINCONTROLIMPL_IPV4_TBL_3_ACT_NOACTION 0 struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_3_value { unsigned int action; union { @@ -76,6 +79,7 @@ struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_4_key { } __attribute__((aligned(4))); #define MAINCONTROLIMPL_IPV4_TBL_4_ACT_MAINCONTROLIMPL_NEXT_HOP 1 #define MAINCONTROLIMPL_IPV4_TBL_4_ACT_MAINCONTROLIMPL_DROP 3 +#define MAINCONTROLIMPL_IPV4_TBL_4_ACT_NOACTION 0 struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_4_value { unsigned int action; union { @@ -153,12 +157,12 @@ if (/* hdr->ipv4.isValid() */ drop_packet(); } break; - default: - return TC_ACT_SHOT; + case MAINCONTROLIMPL_IPV4_TBL_1_ACT_NOACTION: + { + } + break; } } else { -/* drop_packet() */ - drop_packet(); } } ; @@ -202,12 +206,12 @@ if (/* hdr->ipv4.isValid() */ drop_packet(); } break; - default: - return TC_ACT_SHOT; + case MAINCONTROLIMPL_IPV4_TBL_2_ACT_NOACTION: + { + } + break; } } else { -/* drop_packet() */ - drop_packet(); } } ; @@ -249,12 +253,12 @@ if (/* hdr->ipv4.isValid() */ drop_packet(); } break; - default: - return TC_ACT_SHOT; + case MAINCONTROLIMPL_IPV4_TBL_3_ACT_NOACTION: + { + } + break; } } else { -/* drop_packet() */ - drop_packet(); } } ; @@ -298,12 +302,12 @@ if (/* hdr->ipv4.isValid() */ drop_packet(); } break; - default: - return TC_ACT_SHOT; + case MAINCONTROLIMPL_IPV4_TBL_4_ACT_NOACTION: + { + } + break; } } else { -/* drop_packet() */ - drop_packet(); } } ; diff --git a/testdata/p4tc_samples_outputs/mix_matchtype_example_control_blocks.c b/testdata/p4tc_samples_outputs/mix_matchtype_example_control_blocks.c index ed9455d77fb..10ee08de1ad 100644 --- a/testdata/p4tc_samples_outputs/mix_matchtype_example_control_blocks.c +++ b/testdata/p4tc_samples_outputs/mix_matchtype_example_control_blocks.c @@ -10,6 +10,7 @@ struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_1_key { } __attribute__((aligned(4))); #define MAINCONTROLIMPL_IPV4_TBL_1_ACT_MAINCONTROLIMPL_NEXT_HOP 1 #define MAINCONTROLIMPL_IPV4_TBL_1_ACT_MAINCONTROLIMPL_DEFAULT_ROUTE_DROP 2 +#define MAINCONTROLIMPL_IPV4_TBL_1_ACT_NOACTION 0 struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_1_value { unsigned int action; union { @@ -35,6 +36,7 @@ struct MainControlImpl_ipv4_tbl_2_key_mask { } __attribute__((aligned(4))); #define MAINCONTROLIMPL_IPV4_TBL_2_ACT_MAINCONTROLIMPL_NEXT_HOP 1 #define MAINCONTROLIMPL_IPV4_TBL_2_ACT_MAINCONTROLIMPL_DROP 3 +#define MAINCONTROLIMPL_IPV4_TBL_2_ACT_NOACTION 0 struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_2_value { unsigned int action; __u32 priority; @@ -60,6 +62,7 @@ struct MainControlImpl_ipv4_tbl_3_key_mask { } __attribute__((aligned(4))); #define MAINCONTROLIMPL_IPV4_TBL_3_ACT_MAINCONTROLIMPL_NEXT_HOP 1 #define MAINCONTROLIMPL_IPV4_TBL_3_ACT_MAINCONTROLIMPL_DROP 3 +#define MAINCONTROLIMPL_IPV4_TBL_3_ACT_NOACTION 0 struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_3_value { unsigned int action; __u32 priority; @@ -82,6 +85,7 @@ struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_4_key { } __attribute__((aligned(4))); #define MAINCONTROLIMPL_IPV4_TBL_4_ACT_MAINCONTROLIMPL_NEXT_HOP 1 #define MAINCONTROLIMPL_IPV4_TBL_4_ACT_MAINCONTROLIMPL_DROP 3 +#define MAINCONTROLIMPL_IPV4_TBL_4_ACT_NOACTION 0 struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_4_value { unsigned int action; union { @@ -159,12 +163,12 @@ if (/* hdr->ipv4.isValid() */ drop_packet(); } break; - default: - return TC_ACT_SHOT; + case MAINCONTROLIMPL_IPV4_TBL_1_ACT_NOACTION: + { + } + break; } } else { -/* drop_packet() */ - drop_packet(); } } ; @@ -208,12 +212,12 @@ if (/* hdr->ipv4.isValid() */ drop_packet(); } break; - default: - return TC_ACT_SHOT; + case MAINCONTROLIMPL_IPV4_TBL_2_ACT_NOACTION: + { + } + break; } } else { -/* drop_packet() */ - drop_packet(); } } ; @@ -256,12 +260,12 @@ if (/* hdr->ipv4.isValid() */ drop_packet(); } break; - default: - return TC_ACT_SHOT; + case MAINCONTROLIMPL_IPV4_TBL_3_ACT_NOACTION: + { + } + break; } } else { -/* drop_packet() */ - drop_packet(); } } ; @@ -305,12 +309,12 @@ if (/* hdr->ipv4.isValid() */ drop_packet(); } break; - default: - return TC_ACT_SHOT; + case MAINCONTROLIMPL_IPV4_TBL_4_ACT_NOACTION: + { + } + break; } } else { -/* drop_packet() */ - drop_packet(); } } ; diff --git a/testdata/p4tc_samples_outputs/multiple_tables_example_01_control_blocks.c b/testdata/p4tc_samples_outputs/multiple_tables_example_01_control_blocks.c index da7d10afc1a..be9a8540bc6 100644 --- a/testdata/p4tc_samples_outputs/multiple_tables_example_01_control_blocks.c +++ b/testdata/p4tc_samples_outputs/multiple_tables_example_01_control_blocks.c @@ -10,6 +10,7 @@ struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_1_key { } __attribute__((aligned(4))); #define MAINCONTROLIMPL_IPV4_TBL_1_ACT_MAINCONTROLIMPL_NEXT_HOP 1 #define MAINCONTROLIMPL_IPV4_TBL_1_ACT_MAINCONTROLIMPL_DEFAULT_ROUTE_DROP 2 +#define MAINCONTROLIMPL_IPV4_TBL_1_ACT_NOACTION 0 struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_1_value { unsigned int action; union { @@ -31,6 +32,7 @@ struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_2_key { } __attribute__((aligned(4))); #define MAINCONTROLIMPL_IPV4_TBL_2_ACT_MAINCONTROLIMPL_NEXT_HOP 1 #define MAINCONTROLIMPL_IPV4_TBL_2_ACT_MAINCONTROLIMPL_DROP 4 +#define MAINCONTROLIMPL_IPV4_TBL_2_ACT_NOACTION 0 struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_2_value { unsigned int action; union { @@ -151,6 +153,7 @@ struct MainControlImpl_set_ct_options_key_mask { #define MAINCONTROLIMPL_SET_CT_OPTIONS_ACT_MAINCONTROLIMPL_TCP_SYN_PACKET 5 #define MAINCONTROLIMPL_SET_CT_OPTIONS_ACT_MAINCONTROLIMPL_TCP_FIN_OR_RST_PACKET 6 #define MAINCONTROLIMPL_SET_CT_OPTIONS_ACT_MAINCONTROLIMPL_TCP_OTHER_PACKETS 7 +#define MAINCONTROLIMPL_SET_CT_OPTIONS_ACT_NOACTION 0 struct __attribute__((__packed__)) MainControlImpl_set_ct_options_value { unsigned int action; __u32 priority; @@ -232,14 +235,12 @@ if (hdr->ipv4.protocol == 6 && (hdr->tcp.srcPort > 0)) { } break; - default: - return TC_ACT_SHOT; + case MAINCONTROLIMPL_IPV4_TBL_1_ACT_NOACTION: + { + } + break; } } else { -if (hdr->ipv4.protocol == 6 && (hdr->tcp.srcPort > 0)) { -/* drop_packet() */ - drop_packet(); } - } } ; @@ -285,14 +286,12 @@ if (hdr->ipv4.protocol != 4 || (hdr->tcp.srcPort <= 3)) { } break; - default: - return TC_ACT_SHOT; + case MAINCONTROLIMPL_IPV4_TBL_2_ACT_NOACTION: + { + } + break; } } else { -if (hdr->ipv4.protocol != 4 || (hdr->tcp.srcPort <= 3)) { -/* drop_packet() */ - drop_packet(); } - } } ; @@ -342,8 +341,6 @@ if (hdr->ipv4.protocol != 4 || (hdr->tcp.srcPort <= 3)) { { } break; - default: - return TC_ACT_SHOT; } } else { } @@ -395,8 +392,6 @@ if (hdr->ipv4.protocol != 4 || (hdr->tcp.srcPort <= 3)) { { } break; - default: - return TC_ACT_SHOT; } } else { } @@ -431,8 +426,6 @@ if (hdr->ipv4.protocol != 4 || (hdr->tcp.srcPort <= 3)) { { } break; - default: - return TC_ACT_SHOT; } } else { } @@ -475,8 +468,10 @@ if (hdr->ipv4.protocol != 4 || (hdr->tcp.srcPort <= 3)) { { } break; - default: - return TC_ACT_SHOT; + case MAINCONTROLIMPL_SET_CT_OPTIONS_ACT_NOACTION: + { + } + break; } } else { } @@ -556,14 +551,8 @@ if (hdr->ipv4.protocol != 4 || (hdr->tcp.srcPort <= 3)) { { } break; - default: - return TC_ACT_SHOT; } } else { -if (hdr->ipv4.protocol != 4 || (hdr->tcp.srcPort <= 3)) { -/* drop_packet() */ - drop_packet(); } - } } ; diff --git a/testdata/p4tc_samples_outputs/multiple_tables_example_02_control_blocks.c b/testdata/p4tc_samples_outputs/multiple_tables_example_02_control_blocks.c index 31509f10df9..93230c97b99 100644 --- a/testdata/p4tc_samples_outputs/multiple_tables_example_02_control_blocks.c +++ b/testdata/p4tc_samples_outputs/multiple_tables_example_02_control_blocks.c @@ -10,6 +10,7 @@ struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_1_key { } __attribute__((aligned(4))); #define MAINCONTROLIMPL_IPV4_TBL_1_ACT_MAINCONTROLIMPL_NEXT_HOP 1 #define MAINCONTROLIMPL_IPV4_TBL_1_ACT_MAINCONTROLIMPL_DEFAULT_ROUTE_DROP 2 +#define MAINCONTROLIMPL_IPV4_TBL_1_ACT_NOACTION 0 struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_1_value { unsigned int action; union { @@ -31,6 +32,7 @@ struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_2_key { } __attribute__((aligned(4))); #define MAINCONTROLIMPL_IPV4_TBL_2_ACT_MAINCONTROLIMPL_NEXT_HOP 1 #define MAINCONTROLIMPL_IPV4_TBL_2_ACT_MAINCONTROLIMPL_DROP 4 +#define MAINCONTROLIMPL_IPV4_TBL_2_ACT_NOACTION 0 struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_2_value { unsigned int action; union { @@ -148,6 +150,7 @@ struct MainControlImpl_set_ct_options_key_mask { #define MAINCONTROLIMPL_SET_CT_OPTIONS_ACT_MAINCONTROLIMPL_TCP_SYN_PACKET 5 #define MAINCONTROLIMPL_SET_CT_OPTIONS_ACT_MAINCONTROLIMPL_TCP_FIN_OR_RST_PACKET 6 #define MAINCONTROLIMPL_SET_CT_OPTIONS_ACT_MAINCONTROLIMPL_TCP_OTHER_PACKETS 7 +#define MAINCONTROLIMPL_SET_CT_OPTIONS_ACT_NOACTION 0 struct __attribute__((__packed__)) MainControlImpl_set_ct_options_value { unsigned int action; __u32 priority; @@ -230,14 +233,12 @@ if (hdr->ipv4.protocol != 6) { } break; - default: - return TC_ACT_SHOT; + case MAINCONTROLIMPL_IPV4_TBL_1_ACT_NOACTION: + { + } + break; } } else { -if (hdr->ipv4.protocol != 6) { -/* drop_packet() */ - drop_packet(); } - } } ; @@ -284,14 +285,12 @@ if (hdr->ipv4.protocol == 6 || ((hdr->ipv4.version > 1) && (hdr->ipv4.ihl <= 2)) } break; - default: - return TC_ACT_SHOT; + case MAINCONTROLIMPL_IPV4_TBL_2_ACT_NOACTION: + { + } + break; } } else { -if (hdr->ipv4.protocol == 6 || ((hdr->ipv4.version > 1) && (hdr->ipv4.ihl <= 2))) { -/* drop_packet() */ - drop_packet(); } - } } ; @@ -341,8 +340,6 @@ if (hdr->ipv4.protocol == 6 || ((hdr->ipv4.version > 1) && (hdr->ipv4.ihl <= 2)) { } break; - default: - return TC_ACT_SHOT; } } else { } @@ -394,8 +391,6 @@ if (hdr->ipv4.protocol == 6 || ((hdr->ipv4.version > 1) && (hdr->ipv4.ihl <= 2)) { } break; - default: - return TC_ACT_SHOT; } } else { } @@ -430,8 +425,6 @@ if (hdr->ipv4.protocol == 6 || ((hdr->ipv4.version > 1) && (hdr->ipv4.ihl <= 2)) { } break; - default: - return TC_ACT_SHOT; } } else { } @@ -474,8 +467,10 @@ if (hdr->ipv4.protocol == 6 || ((hdr->ipv4.version > 1) && (hdr->ipv4.ihl <= 2)) { } break; - default: - return TC_ACT_SHOT; + case MAINCONTROLIMPL_SET_CT_OPTIONS_ACT_NOACTION: + { + } + break; } } else { } @@ -556,14 +551,8 @@ if (hdr->ipv4.protocol == 6 || ((hdr->ipv4.version > 1) && (hdr->ipv4.ihl <= 2)) { } break; - default: - return TC_ACT_SHOT; } } else { -if (hdr->ipv4.protocol == 6 || ((hdr->ipv4.version > 1) && (hdr->ipv4.ihl <= 2))) { -/* drop_packet() */ - drop_packet(); } - } } ; diff --git a/testdata/p4tc_samples_outputs/name_annotation_example_control_blocks.c b/testdata/p4tc_samples_outputs/name_annotation_example_control_blocks.c index 396d7988a17..054af7e2cc4 100644 --- a/testdata/p4tc_samples_outputs/name_annotation_example_control_blocks.c +++ b/testdata/p4tc_samples_outputs/name_annotation_example_control_blocks.c @@ -10,6 +10,7 @@ struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_1_key { } __attribute__((aligned(4))); #define MAINCONTROLIMPL_IPV4_TBL_1_ACT_MAINCONTROLIMPL_NEXT_HOP 1 #define MAINCONTROLIMPL_IPV4_TBL_1_ACT_MAINCONTROLIMPL_DEFAULT_ROUTE_DROP 2 +#define MAINCONTROLIMPL_IPV4_TBL_1_ACT_NOACTION 0 struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_1_value { unsigned int action; union { @@ -31,6 +32,7 @@ struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_2_key { } __attribute__((aligned(4))); #define MAINCONTROLIMPL_IPV4_TBL_2_ACT_MAINCONTROLIMPL_NEXT_HOP 1 #define MAINCONTROLIMPL_IPV4_TBL_2_ACT_MAINCONTROLIMPL_DROP 3 +#define MAINCONTROLIMPL_IPV4_TBL_2_ACT_NOACTION 0 struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_2_value { unsigned int action; union { @@ -108,12 +110,12 @@ if (/* hdr->ipv4.isValid() */ drop_packet(); } break; - default: - return TC_ACT_SHOT; + case MAINCONTROLIMPL_IPV4_TBL_1_ACT_NOACTION: + { + } + break; } } else { -/* drop_packet() */ - drop_packet(); } } ; @@ -157,12 +159,12 @@ if (/* hdr->ipv4.isValid() */ drop_packet(); } break; - default: - return TC_ACT_SHOT; + case MAINCONTROLIMPL_IPV4_TBL_2_ACT_NOACTION: + { + } + break; } } else { -/* drop_packet() */ - drop_packet(); } } ; diff --git a/testdata/p4tc_samples_outputs/noaction_example_01_control_blocks.c b/testdata/p4tc_samples_outputs/noaction_example_01_control_blocks.c index 9f4c0146f66..9044456b044 100644 --- a/testdata/p4tc_samples_outputs/noaction_example_01_control_blocks.c +++ b/testdata/p4tc_samples_outputs/noaction_example_01_control_blocks.c @@ -10,6 +10,7 @@ struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_1_key { } __attribute__((aligned(4))); #define MAINCONTROLIMPL_IPV4_TBL_1_ACT_MAINCONTROLIMPL_NEXT_HOP 1 #define MAINCONTROLIMPL_IPV4_TBL_1_ACT_MAINCONTROLIMPL_DEFAULT_ROUTE_DROP 2 +#define MAINCONTROLIMPL_IPV4_TBL_1_ACT_NOACTION 0 struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_1_value { unsigned int action; union { @@ -109,12 +110,12 @@ if (/* hdr->ipv4.isValid() */ drop_packet(); } break; - default: - return TC_ACT_SHOT; + case MAINCONTROLIMPL_IPV4_TBL_1_ACT_NOACTION: + { + } + break; } } else { -/* drop_packet() */ - drop_packet(); } } ; @@ -162,8 +163,6 @@ if (/* hdr->ipv4.isValid() */ { } break; - default: - return TC_ACT_SHOT; } } else { } diff --git a/testdata/p4tc_samples_outputs/noaction_example_02_control_blocks.c b/testdata/p4tc_samples_outputs/noaction_example_02_control_blocks.c index 479e33876cc..7831377ab11 100644 --- a/testdata/p4tc_samples_outputs/noaction_example_02_control_blocks.c +++ b/testdata/p4tc_samples_outputs/noaction_example_02_control_blocks.c @@ -10,6 +10,7 @@ struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_1_key { } __attribute__((aligned(4))); #define MAINCONTROLIMPL_IPV4_TBL_1_ACT_MAINCONTROLIMPL_NEXT_HOP 1 #define MAINCONTROLIMPL_IPV4_TBL_1_ACT_MAINCONTROLIMPL_DEFAULT_ROUTE_DROP 2 +#define MAINCONTROLIMPL_IPV4_TBL_1_ACT_NOACTION 0 struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_1_value { unsigned int action; union { @@ -100,12 +101,12 @@ if (/* hdr->ipv4.isValid() */ drop_packet(); } break; - default: - return TC_ACT_SHOT; + case MAINCONTROLIMPL_IPV4_TBL_1_ACT_NOACTION: + { + } + break; } } else { -/* drop_packet() */ - drop_packet(); } } ; @@ -138,8 +139,6 @@ if (/* hdr->ipv4.isValid() */ { } break; - default: - return TC_ACT_SHOT; } } else { } diff --git a/testdata/p4tc_samples_outputs/nummask_annotation_example_control_blocks.c b/testdata/p4tc_samples_outputs/nummask_annotation_example_control_blocks.c index a3324ef5498..972fa747a99 100644 --- a/testdata/p4tc_samples_outputs/nummask_annotation_example_control_blocks.c +++ b/testdata/p4tc_samples_outputs/nummask_annotation_example_control_blocks.c @@ -11,6 +11,7 @@ struct __attribute__((__packed__)) MainControlImpl_set_ct_options_key { #define MAINCONTROLIMPL_SET_CT_OPTIONS_ACT_MAINCONTROLIMPL_TCP_SYN_PACKET 1 #define MAINCONTROLIMPL_SET_CT_OPTIONS_ACT_MAINCONTROLIMPL_TCP_FIN_OR_RST_PACKET 2 #define MAINCONTROLIMPL_SET_CT_OPTIONS_ACT_MAINCONTROLIMPL_TCP_OTHER_PACKETS 3 +#define MAINCONTROLIMPL_SET_CT_OPTIONS_ACT_NOACTION 0 struct __attribute__((__packed__)) MainControlImpl_set_ct_options_value { unsigned int action; union { @@ -89,8 +90,10 @@ if (((u32)istd.input_port == 2 && /* hdr->ipv4.isValid() */ { } break; - default: - return TC_ACT_SHOT; + case MAINCONTROLIMPL_SET_CT_OPTIONS_ACT_NOACTION: + { + } + break; } } else { } diff --git a/testdata/p4tc_samples_outputs/send_to_port_example_control_blocks.c b/testdata/p4tc_samples_outputs/send_to_port_example_control_blocks.c index b50ba87efa8..8d7c9496c06 100644 --- a/testdata/p4tc_samples_outputs/send_to_port_example_control_blocks.c +++ b/testdata/p4tc_samples_outputs/send_to_port_example_control_blocks.c @@ -12,6 +12,7 @@ struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_key { } __attribute__((aligned(4))); #define MAINCONTROLIMPL_IPV4_TBL_ACT_MAINCONTROLIMPL_NEXT_HOP 1 #define MAINCONTROLIMPL_IPV4_TBL_ACT_MAINCONTROLIMPL_DEFAULT_ROUTE_DROP 2 +#define MAINCONTROLIMPL_IPV4_TBL_ACT_NOACTION 0 struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_value { unsigned int action; union { @@ -91,12 +92,12 @@ if (/* hdr->ipv4.isValid() */ drop_packet(); } break; - default: - return TC_ACT_SHOT; + case MAINCONTROLIMPL_IPV4_TBL_ACT_NOACTION: + { + } + break; } } else { -/* drop_packet() */ - drop_packet(); } } ; } diff --git a/testdata/p4tc_samples_outputs/set_entry_timer_example_control_blocks.c b/testdata/p4tc_samples_outputs/set_entry_timer_example_control_blocks.c index f556c32830a..e530e34ff6d 100644 --- a/testdata/p4tc_samples_outputs/set_entry_timer_example_control_blocks.c +++ b/testdata/p4tc_samples_outputs/set_entry_timer_example_control_blocks.c @@ -11,6 +11,7 @@ struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_1_key { } __attribute__((aligned(4))); #define MAINCONTROLIMPL_IPV4_TBL_1_ACT_MAINCONTROLIMPL_NEXT_HOP 1 #define MAINCONTROLIMPL_IPV4_TBL_1_ACT_MAINCONTROLIMPL_DEFAULT_ROUTE_DROP 2 +#define MAINCONTROLIMPL_IPV4_TBL_1_ACT_NOACTION 0 struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_1_value { unsigned int action; union { @@ -31,6 +32,7 @@ struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_2_key { } __attribute__((aligned(4))); #define MAINCONTROLIMPL_IPV4_TBL_2_ACT_MAINCONTROLIMPL_NEXT_HOP 1 #define MAINCONTROLIMPL_IPV4_TBL_2_ACT_MAINCONTROLIMPL_DROP 3 +#define MAINCONTROLIMPL_IPV4_TBL_2_ACT_NOACTION 0 struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_2_value { unsigned int action; union { @@ -114,12 +116,12 @@ if (/* hdr->ipv4.isValid() */ drop_packet(); } break; - default: - return TC_ACT_SHOT; + case MAINCONTROLIMPL_IPV4_TBL_1_ACT_NOACTION: + { + } + break; } } else { -/* drop_packet() */ - drop_packet(); } } ; @@ -169,12 +171,12 @@ if (/* hdr->ipv4.isValid() */ drop_packet(); } break; - default: - return TC_ACT_SHOT; + case MAINCONTROLIMPL_IPV4_TBL_2_ACT_NOACTION: + { + } + break; } } else { -/* drop_packet() */ - drop_packet(); } } ; diff --git a/testdata/p4tc_samples_outputs/simple_exact_example_control_blocks.c b/testdata/p4tc_samples_outputs/simple_exact_example_control_blocks.c index f9a8c7dc650..a9bae801602 100644 --- a/testdata/p4tc_samples_outputs/simple_exact_example_control_blocks.c +++ b/testdata/p4tc_samples_outputs/simple_exact_example_control_blocks.c @@ -10,6 +10,7 @@ struct __attribute__((__packed__)) ingress_nh_table_key { } __attribute__((aligned(4))); #define INGRESS_NH_TABLE_ACT_INGRESS_SEND_NH 1 #define INGRESS_NH_TABLE_ACT_INGRESS_DROP 2 +#define INGRESS_NH_TABLE_ACT_NOACTION 0 struct __attribute__((__packed__)) ingress_nh_table_value { unsigned int action; union { @@ -89,12 +90,12 @@ static __always_inline int process(struct __sk_buff *skb, struct my_ingress_head drop_packet(); } break; - default: - return TC_ACT_SHOT; + case INGRESS_NH_TABLE_ACT_NOACTION: + { + } + break; } } else { -/* drop_packet() */ - drop_packet(); } } ; diff --git a/testdata/p4tc_samples_outputs/simple_lpm_example_control_blocks.c b/testdata/p4tc_samples_outputs/simple_lpm_example_control_blocks.c index a265b3a644f..09944603fff 100644 --- a/testdata/p4tc_samples_outputs/simple_lpm_example_control_blocks.c +++ b/testdata/p4tc_samples_outputs/simple_lpm_example_control_blocks.c @@ -10,6 +10,7 @@ struct __attribute__((__packed__)) ingress_nh_table_key { } __attribute__((aligned(4))); #define INGRESS_NH_TABLE_ACT_INGRESS_SEND_NH 1 #define INGRESS_NH_TABLE_ACT_INGRESS_DROP 2 +#define INGRESS_NH_TABLE_ACT_NOACTION 0 struct __attribute__((__packed__)) ingress_nh_table_value { unsigned int action; union { @@ -89,12 +90,12 @@ static __always_inline int process(struct __sk_buff *skb, struct my_ingress_head drop_packet(); } break; - default: - return TC_ACT_SHOT; + case INGRESS_NH_TABLE_ACT_NOACTION: + { + } + break; } } else { -/* drop_packet() */ - drop_packet(); } } ; diff --git a/testdata/p4tc_samples_outputs/simple_ternary_example_control_blocks.c b/testdata/p4tc_samples_outputs/simple_ternary_example_control_blocks.c index 69efde39409..6d695cbf5fc 100644 --- a/testdata/p4tc_samples_outputs/simple_ternary_example_control_blocks.c +++ b/testdata/p4tc_samples_outputs/simple_ternary_example_control_blocks.c @@ -15,6 +15,7 @@ struct ingress_nh_table_key_mask { } __attribute__((aligned(4))); #define INGRESS_NH_TABLE_ACT_INGRESS_SEND_NH 1 #define INGRESS_NH_TABLE_ACT_INGRESS_DROP 2 +#define INGRESS_NH_TABLE_ACT_NOACTION 0 struct __attribute__((__packed__)) ingress_nh_table_value { unsigned int action; __u32 priority; @@ -96,12 +97,12 @@ static __always_inline int process(struct __sk_buff *skb, struct my_ingress_head drop_packet(); } break; - default: - return TC_ACT_SHOT; + case INGRESS_NH_TABLE_ACT_NOACTION: + { + } + break; } } else { -/* drop_packet() */ - drop_packet(); } } ; diff --git a/testdata/p4tc_samples_outputs/size_param_example_control_blocks.c b/testdata/p4tc_samples_outputs/size_param_example_control_blocks.c index 36e23b06e8c..73ef32df0a2 100644 --- a/testdata/p4tc_samples_outputs/size_param_example_control_blocks.c +++ b/testdata/p4tc_samples_outputs/size_param_example_control_blocks.c @@ -10,6 +10,7 @@ struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_1_key { } __attribute__((aligned(4))); #define MAINCONTROLIMPL_IPV4_TBL_1_ACT_MAINCONTROLIMPL_NEXT_HOP 1 #define MAINCONTROLIMPL_IPV4_TBL_1_ACT_MAINCONTROLIMPL_DEFAULT_ROUTE_DROP 2 +#define MAINCONTROLIMPL_IPV4_TBL_1_ACT_NOACTION 0 struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_1_value { unsigned int action; union { @@ -31,6 +32,7 @@ struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_2_key { } __attribute__((aligned(4))); #define MAINCONTROLIMPL_IPV4_TBL_2_ACT_MAINCONTROLIMPL_SENDTOPORT 3 #define MAINCONTROLIMPL_IPV4_TBL_2_ACT_MAINCONTROLIMPL_DROP 4 +#define MAINCONTROLIMPL_IPV4_TBL_2_ACT_NOACTION 0 struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_2_value { unsigned int action; union { @@ -108,12 +110,12 @@ if (/* hdr->ipv4.isValid() */ drop_packet(); } break; - default: - return TC_ACT_SHOT; + case MAINCONTROLIMPL_IPV4_TBL_1_ACT_NOACTION: + { + } + break; } } else { -/* drop_packet() */ - drop_packet(); } } ; @@ -157,12 +159,12 @@ if (/* hdr->ipv4.isValid() */ drop_packet(); } break; - default: - return TC_ACT_SHOT; + case MAINCONTROLIMPL_IPV4_TBL_2_ACT_NOACTION: + { + } + break; } } else { -/* drop_packet() */ - drop_packet(); } } ; diff --git a/testdata/p4tc_samples_outputs/tc_type_annotation_example_control_blocks.c b/testdata/p4tc_samples_outputs/tc_type_annotation_example_control_blocks.c index 755ed9275be..318a9f0b1ab 100644 --- a/testdata/p4tc_samples_outputs/tc_type_annotation_example_control_blocks.c +++ b/testdata/p4tc_samples_outputs/tc_type_annotation_example_control_blocks.c @@ -107,8 +107,6 @@ if (/* hdr->ipv4.isValid() */ { } break; - default: - return TC_ACT_SHOT; } } else { } @@ -143,8 +141,6 @@ if (/* hdr->ipv4.isValid() */ { } break; - default: - return TC_ACT_SHOT; } } else { } diff --git a/testdata/p4tc_samples_outputs/test_ipv6_example.template b/testdata/p4tc_samples_outputs/test_ipv6_example.template index 4f409762bd4..ae961d1a116 100755 --- a/testdata/p4tc_samples_outputs/test_ipv6_example.template +++ b/testdata/p4tc_samples_outputs/test_ipv6_example.template @@ -14,5 +14,5 @@ $TC p4template create table/test_ipv6_example/MainControlImpl/tbl_default \ type exact \ keysz 128 nummasks 8 tentries 100 \ table_acts act name test_ipv6_example/MainControlImpl/set_dst -$TC p4template update table/test_ipv6_example/MainControlImpl/tbl_default default_miss_action action test_ipv6_example/MainControlImpl/set_dst +$TC p4template update table/test_ipv6_example/MainControlImpl/tbl_default default_miss_action action test_ipv6_example/MainControlImpl/set_dst param addr6 0xffff111122223333444455556666aaaa $TC p4template update pipeline/test_ipv6_example state ready \ No newline at end of file diff --git a/testdata/p4tc_samples_outputs/test_ipv6_example_control_blocks.c b/testdata/p4tc_samples_outputs/test_ipv6_example_control_blocks.c index 2cae586a898..37a1d383d96 100644 --- a/testdata/p4tc_samples_outputs/test_ipv6_example_control_blocks.c +++ b/testdata/p4tc_samples_outputs/test_ipv6_example_control_blocks.c @@ -80,12 +80,8 @@ static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr, { } break; - default: - return TC_ACT_SHOT; } } else { - __builtin_memcpy(&hdr->ipv6.dstAddr, &value->u.MainControlImpl_set_dst.addr6, 16); - hdr->ipv6.hopLimit = (hdr->ipv6.hopLimit + 255); } } ;