Skip to content

Commit

Permalink
Change kfunc definition for bpf_p4tc_tbl_read, xdp_p4tc_tbl_read, (#4604
Browse files Browse the repository at this point in the history
)

p4tc_table_entry_create_bpf_params__local, bpf_p4tc_entry_create,
xdp_p4tc_entry_create, bpf_p4tc_entry_create_on_miss,
xdp_p4tc_entry_create_on_miss,
bpf_p4tc_entry_update, xdp_p4tc_entry_update, bpf_p4tc_entry_delete, bpf_p4tc_entry_delete

Added implementation for beXX annotation
  • Loading branch information
komaljai authored Apr 8, 2024
1 parent ed94813 commit 0c03960
Show file tree
Hide file tree
Showing 39 changed files with 129 additions and 118 deletions.
23 changes: 18 additions & 5 deletions backends/tc/ebpfCodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,15 @@ void PnaStateTranslationVisitor::compileExtractField(const IR::Expression *expr,
if (annoVal->text == "macaddr" || annoVal->text == "ipv4" || annoVal->text == "ipv6") {
noEndiannessConversion = true;
break;
} else if (annoVal->text == "be16" || annoVal->text == "be32" ||
annoVal->text == "be64") {
std::string sInt = annoVal->text.substr(2).c_str();
unsigned int width = std::stoi(sInt);
if (widthToExtract != width) {
::error("Width of the field doesnt match the annotation width. '%1%'", field);
}
noEndiannessConversion = true;
break;
}
}
}
Expand Down Expand Up @@ -1588,7 +1597,7 @@ void ControlBodyTranslatorPNA::processFunction(const P4::ExternFunction *functio
builder->appendLine("};");
builder->emitIndent();
builder->append(
"bpf_p4tc_entry_update(skb, &update_params, &key, sizeof(key), act_bpf)");
"bpf_p4tc_entry_update(skb, &update_params, sizeof(params), &key, sizeof(key))");
}
return;
} else if (function->expr->method->toString() == "add_entry") {
Expand Down Expand Up @@ -1672,6 +1681,8 @@ void ControlBodyTranslatorPNA::processFunction(const P4::ExternFunction *functio
builder->emitIndent();
builder->appendLine("struct p4tc_table_entry_create_bpf_params__local update_params = {");
builder->emitIndent();
builder->appendLine(" .act_bpf = update_act_bpf,");
builder->emitIndent();
builder->appendLine(" .pipeid = p4tc_filter_fields.pipeid,");
builder->emitIndent();
builder->appendLine(" .handle = p4tc_filter_fields.handle,");
Expand All @@ -1697,8 +1708,8 @@ void ControlBodyTranslatorPNA::processFunction(const P4::ExternFunction *functio
builder->appendLine("};");
builder->emitIndent();
builder->append(
"bpf_p4tc_entry_create_on_miss(skb, &update_params, &key, sizeof(key), "
"&update_act_bpf)");
"bpf_p4tc_entry_create_on_miss(skb, &update_params, sizeof(params), &key, "
"sizeof(key))");
return;
}
processCustomExternFunction(function, EBPF::EBPFTypeFactory::instance);
Expand Down Expand Up @@ -1836,7 +1847,8 @@ void ControlBodyTranslatorPNA::processApply(const P4::ApplyMethod *method) {
builder->appendLine("/* perform lookup */");
builder->target->emitTraceMessage(builder, "Control: performing table lookup");
builder->emitIndent();
builder->appendLine("act_bpf = bpf_p4tc_tbl_read(skb, &params, &key, sizeof(key));");
builder->appendLine(
"act_bpf = bpf_p4tc_tbl_read(skb, &params, sizeof(params), &key, sizeof(key));");
builder->emitIndent();
builder->appendFormat("value = (struct %s *)act_bpf;", table->valueTypeName.c_str());
builder->newline();
Expand Down Expand Up @@ -2048,7 +2060,8 @@ void DeparserHdrEmitTranslatorPNA::processMethod(const P4::ExternMethod *method)
if (anno->name != ParseTCAnnotations::tcType) continue;
for (auto annoVal : anno->body) {
if (annoVal->text == "macaddr" || annoVal->text == "ipv4" ||
annoVal->text == "ipv6") {
annoVal->text == "ipv6" || annoVal->text == "be16" ||
annoVal->text == "be32" || annoVal->text == "be64") {
noEndiannessConversion = true;
break;
}
Expand Down
61 changes: 28 additions & 33 deletions backends/tc/runtime/pna.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ struct __attribute__((__packed__)) p4tc_table_entry_act_bpf {
};

struct p4tc_table_entry_create_bpf_params__local {
struct p4tc_table_entry_act_bpf act_bpf;
u32 pipeid;
u32 tblid;
u32 profile_id;
Expand All @@ -121,62 +122,56 @@ struct p4tc_table_entry_create_bpf_params__local {
u16 proto;
u16 prio;
};
extern struct p4tc_table_entry_act_bpf *bpf_p4tc_tbl_read(
struct __sk_buff *skb, struct p4tc_table_entry_act_bpf_params__local *params, void *key,
const u32 key__sz) __ksym;
extern struct p4tc_table_entry_act_bpf *bpf_xdp_p4tc_tbl_lookup(
struct xdp_md *skb, struct p4tc_table_entry_act_bpf_params__local *params, void *key,
const u32 key__sz) __ksym;
extern struct p4tc_table_entry_act_bpf *
bpf_p4tc_tbl_read(struct __sk_buff *skb_ctx,
struct p4tc_table_entry_act_bpf_params__local *params,
const u32 params__sz,
void *key, const __u32 key__sz) __ksym;

extern struct p4tc_table_entry_act_bpf *
xdp_p4tc_tbl_read(struct xdp_md *skb_ctx,
struct p4tc_table_entry_act_bpf_params__local *params,
const u32 params__sz,
void *key, const __u32 key__sz) __ksym;

/* No mapping to PNA, but are useful utilities */
extern int
bpf_p4tc_entry_create(struct __sk_buff *skb_ctx,
struct p4tc_table_entry_create_bpf_params__local *params,
void *key, const u32 key__sz,
struct p4tc_table_entry_act_bpf *act_bpf) __ksym;
const u32 params__sz,
void *key, const u32 key__sz) __ksym;

extern int
xdp_p4tc_entry_create(struct xdp_md *xdp_ctx,
struct p4tc_table_entry_create_bpf_params__local *params,
void *bpf_key_mask, u32 bpf_key_mask__sz,
struct p4tc_table_entry_act_bpf *act_bpf) __ksym;
const u32 params__sz,
void *bpf_key_mask, u32 bpf_key_mask__sz) __ksym;

/* Equivalent to PNA add-on-miss */
extern int
bpf_p4tc_entry_create_on_miss(struct __sk_buff *skb_ctx,
struct p4tc_table_entry_create_bpf_params__local *params,
void *key, const u32 key__sz,
struct p4tc_table_entry_act_bpf *act_bpf) __ksym;
struct p4tc_table_entry_create_bpf_params__local *params,
const u32 params__sz,
void *key, const u32 key__sz) __ksym;

extern int
xdp_p4tc_entry_create_on_miss(struct xdp_md *xdp_ctx,
struct p4tc_table_entry_create_bpf_params__local *params,
void *key, const u32 key__sz,
struct p4tc_table_entry_act_bpf *act_bpf) __ksym;

/* No mapping to PNA, but are useful utilities */
extern int
bpf_p4tc_entry_update(struct __sk_buff *skb_ctx,
struct p4tc_table_entry_create_bpf_params__local *params,
void *key, const u32 key__sz,
struct p4tc_table_entry_act_bpf *act_bpf) __ksym;

extern int
xdp_p4tc_entry_update(struct xdp_md *xdp_ctx,
struct p4tc_table_entry_create_bpf_params__local *params,
void *key, const u32 key__sz,
struct p4tc_table_entry_act_bpf *act_bpf) __ksym;
struct p4tc_table_entry_create_bpf_params__local *params,
const u32 params__sz,
void *key, const u32 key__sz) __ksym;

/* No mapping to PNA, but are useful utilities */
extern int
bpf_p4tc_entry_delete(struct __sk_buff *skb_ctx,
struct p4tc_table_entry_create_bpf_params__local *params,
void *key, const u32 key__sz) __ksym;
struct p4tc_table_entry_create_bpf_params__local *params,
const u32 params__sz,
void *key, const u32 key__sz) __ksym;

extern int
xdp_p4tc_entry_delete(struct xdp_md *xdp_ctx,
struct p4tc_table_entry_create_bpf_params__local *params,
void *key, const u32 key__sz) __ksym;
struct p4tc_table_entry_create_bpf_params__local *params,
const u32 params__sz,
void *key, const u32 key__sz) __ksym;

/* Start generic kfunc interface to any extern */
struct p4tc_ext_bpf_params {
Expand Down
4 changes: 2 additions & 2 deletions testdata/p4tc_samples/nummask_annotation_example.p4
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ header ipv4_t {
}

header tcp_t {
bit<16> srcPort;
bit<16> dstPort;
@tc_type("be16") bit<16> srcPort;
@tc_type("be16") bit<16> dstPort;
bit<32> seqNo;
bit<32> ackNo;
bit<4> dataOffset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ if (/* hdr->ipv4.isValid() */
/* value */
struct MainControlImpl_ipv4_tbl_1_value *value = NULL;
/* perform lookup */
act_bpf = bpf_p4tc_tbl_read(skb, &params, &key, sizeof(key));
act_bpf = bpf_p4tc_tbl_read(skb, &params, sizeof(params), &key, sizeof(key));
value = (struct MainControlImpl_ipv4_tbl_1_value *)act_bpf;
if (value == NULL) {
/* miss; find default action */
Expand All @@ -99,6 +99,7 @@ if (/* hdr->ipv4.isValid() */

/* construct key */
struct p4tc_table_entry_create_bpf_params__local update_params = {
.act_bpf = update_act_bpf,
.pipeid = p4tc_filter_fields.pipeid,
.handle = p4tc_filter_fields.handle,
.classid = p4tc_filter_fields.classid,
Expand All @@ -108,7 +109,7 @@ if (/* hdr->ipv4.isValid() */
.tblid = 1,
.profile_id = 2
};
bpf_p4tc_entry_create_on_miss(skb, &update_params, &key, sizeof(key), &update_act_bpf);
bpf_p4tc_entry_create_on_miss(skb, &update_params, sizeof(params), &key, sizeof(key));
}
break;
case MAINCONTROLIMPL_IPV4_TBL_1_ACT_MAINCONTROLIMPL_SEND_NH:
Expand Down
10 changes: 6 additions & 4 deletions testdata/p4tc_samples_outputs/add_entry_example_control_blocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ if (/* hdr->ipv4.isValid() */
/* value */
struct MainControlImpl_ipv4_tbl_1_value *value = NULL;
/* perform lookup */
act_bpf = bpf_p4tc_tbl_read(skb, &params, &key, sizeof(key));
act_bpf = bpf_p4tc_tbl_read(skb, &params, sizeof(params), &key, sizeof(key));
value = (struct MainControlImpl_ipv4_tbl_1_value *)act_bpf;
if (value == NULL) {
/* miss; find default action */
Expand All @@ -115,6 +115,7 @@ if (/* hdr->ipv4.isValid() */

/* construct key */
struct p4tc_table_entry_create_bpf_params__local update_params = {
.act_bpf = update_act_bpf,
.pipeid = p4tc_filter_fields.pipeid,
.handle = p4tc_filter_fields.handle,
.classid = p4tc_filter_fields.classid,
Expand All @@ -124,7 +125,7 @@ if (/* hdr->ipv4.isValid() */
.tblid = 1,
.profile_id = 2
};
bpf_p4tc_entry_create_on_miss(skb, &update_params, &key, sizeof(key), &update_act_bpf);
bpf_p4tc_entry_create_on_miss(skb, &update_params, sizeof(params), &key, sizeof(key));
}
break;
case MAINCONTROLIMPL_IPV4_TBL_1_ACT_MAINCONTROLIMPL_DFLT_ROUTE_DROP:
Expand Down Expand Up @@ -159,7 +160,7 @@ if (/* hdr->ipv4.isValid() */
/* value */
struct MainControlImpl_ipv4_tbl_2_value *value = NULL;
/* perform lookup */
act_bpf = bpf_p4tc_tbl_read(skb, &params, &key, sizeof(key));
act_bpf = bpf_p4tc_tbl_read(skb, &params, sizeof(params), &key, sizeof(key));
value = (struct MainControlImpl_ipv4_tbl_2_value *)act_bpf;
if (value == NULL) {
/* miss; find default action */
Expand All @@ -178,6 +179,7 @@ if (/* hdr->ipv4.isValid() */

/* construct key */
struct p4tc_table_entry_create_bpf_params__local update_params = {
.act_bpf = update_act_bpf,
.pipeid = p4tc_filter_fields.pipeid,
.handle = p4tc_filter_fields.handle,
.classid = p4tc_filter_fields.classid,
Expand All @@ -187,7 +189,7 @@ if (/* hdr->ipv4.isValid() */
.tblid = 2,
.profile_id = 2
};
bpf_p4tc_entry_create_on_miss(skb, &update_params, &key, sizeof(key), &update_act_bpf);
bpf_p4tc_entry_create_on_miss(skb, &update_params, sizeof(params), &key, sizeof(key));
}
break;
case MAINCONTROLIMPL_IPV4_TBL_2_ACT_MAINCONTROLIMPL_DFLT_ROUTE_DROP:
Expand Down
2 changes: 1 addition & 1 deletion testdata/p4tc_samples_outputs/calculator_control_blocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ if (/* hdr->p4calc.isValid() */
/* value */
struct MainControlImpl_calculate_value *value = NULL;
/* perform lookup */
act_bpf = bpf_p4tc_tbl_read(skb, &params, &key, sizeof(key));
act_bpf = bpf_p4tc_tbl_read(skb, &params, sizeof(params), &key, sizeof(key));
value = (struct MainControlImpl_calculate_value *)act_bpf;
if (value == NULL) {
/* miss; find default action */
Expand Down
2 changes: 1 addition & 1 deletion testdata/p4tc_samples_outputs/checksum_control_blocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static __always_inline int process(struct __sk_buff *skb, struct my_ingress_head
/* value */
struct ingress_nh_table_value *value = NULL;
/* perform lookup */
act_bpf = bpf_p4tc_tbl_read(skb, &params, &key, sizeof(key));
act_bpf = bpf_p4tc_tbl_read(skb, &params, sizeof(params), &key, sizeof(key));
value = (struct ingress_nh_table_value *)act_bpf;
if (value == NULL) {
/* miss; find default action */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ static __always_inline int process(struct __sk_buff *skb, struct Header_t *h, st
/* value */
struct MainControlImpl_t_range_value *value = NULL;
/* perform lookup */
act_bpf = bpf_p4tc_tbl_read(skb, &params, &key, sizeof(key));
act_bpf = bpf_p4tc_tbl_read(skb, &params, sizeof(params), &key, sizeof(key));
value = (struct MainControlImpl_t_range_value *)act_bpf;
if (value == NULL) {
/* miss; find default action */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ if (/* hdr->ipv4.isValid() */
/* value */
struct MainControlImpl_ipv4_tbl_1_value *value = NULL;
/* perform lookup */
act_bpf = bpf_p4tc_tbl_read(skb, &params, &key, sizeof(key));
act_bpf = bpf_p4tc_tbl_read(skb, &params, sizeof(params), &key, sizeof(key));
value = (struct MainControlImpl_ipv4_tbl_1_value *)act_bpf;
if (value == NULL) {
/* miss; find default action */
Expand Down Expand Up @@ -148,7 +148,7 @@ if (/* hdr->ipv4.isValid() */
/* value */
struct MainControlImpl_ipv4_tbl_2_value *value = NULL;
/* perform lookup */
act_bpf = bpf_p4tc_tbl_read(skb, &params, &key, sizeof(key));
act_bpf = bpf_p4tc_tbl_read(skb, &params, sizeof(params), &key, sizeof(key));
value = (struct MainControlImpl_ipv4_tbl_2_value *)act_bpf;
if (value == NULL) {
/* miss; find default action */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr,
/* value */
struct MainControlImpl_ipv4_tbl_1_value *value = NULL;
/* perform lookup */
act_bpf = bpf_p4tc_tbl_read(skb, &params, &key, sizeof(key));
act_bpf = bpf_p4tc_tbl_read(skb, &params, sizeof(params), &key, sizeof(key));
value = (struct MainControlImpl_ipv4_tbl_1_value *)act_bpf;
if (value == NULL) {
/* miss; find default action */
Expand Down Expand Up @@ -148,7 +148,7 @@ static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr,
/* value */
struct MainControlImpl_ipv4_tbl_2_value *value = NULL;
/* perform lookup */
act_bpf = bpf_p4tc_tbl_read(skb, &params, &key, sizeof(key));
act_bpf = bpf_p4tc_tbl_read(skb, &params, sizeof(params), &key, sizeof(key));
value = (struct MainControlImpl_ipv4_tbl_2_value *)act_bpf;
if (value == NULL) {
/* miss; find default action */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ if (/* hdr->ipv4.isValid() */
/* value */
struct MainControlImpl_ipv4_tbl_1_value *value = NULL;
/* perform lookup */
act_bpf = bpf_p4tc_tbl_read(skb, &params, &key, sizeof(key));
act_bpf = bpf_p4tc_tbl_read(skb, &params, sizeof(params), &key, sizeof(key));
value = (struct MainControlImpl_ipv4_tbl_1_value *)act_bpf;
if (value == NULL) {
/* miss; find default action */
Expand Down Expand Up @@ -148,7 +148,7 @@ if (/* hdr->ipv4.isValid() */
/* value */
struct MainControlImpl_ipv4_tbl_2_value *value = NULL;
/* perform lookup */
act_bpf = bpf_p4tc_tbl_read(skb, &params, &key, sizeof(key));
act_bpf = bpf_p4tc_tbl_read(skb, &params, sizeof(params), &key, sizeof(key));
value = (struct MainControlImpl_ipv4_tbl_2_value *)act_bpf;
if (value == NULL) {
/* miss; find default action */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ if (/* hdr->ipv4.isValid() */
/* value */
struct MainControlImpl_set_ct_options_value *value = NULL;
/* perform lookup */
act_bpf = bpf_p4tc_tbl_read(skb, &params, &key, sizeof(key));
act_bpf = bpf_p4tc_tbl_read(skb, &params, sizeof(params), &key, sizeof(key));
value = (struct MainControlImpl_set_ct_options_value *)act_bpf;
if (value == NULL) {
/* miss; find default action */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ if (/* hdr->ipv4.isValid() */
/* value */
struct MainControlImpl_ipv4_tbl_value *value = NULL;
/* perform lookup */
act_bpf = bpf_p4tc_tbl_read(skb, &params, &key, sizeof(key));
act_bpf = bpf_p4tc_tbl_read(skb, &params, sizeof(params), &key, sizeof(key));
value = (struct MainControlImpl_ipv4_tbl_value *)act_bpf;
if (value == NULL) {
/* miss; find default action */
Expand Down
Loading

0 comments on commit 0c03960

Please sign in to comment.