Skip to content

Commit

Permalink
Adapt generated files to skb metadata changes
Browse files Browse the repository at this point in the history
Signed-off-by: Mouse <[email protected]>
  • Loading branch information
mouse-mt authored and komaljai committed Dec 19, 2024
1 parent 5e7f8ae commit 0ab3b1d
Show file tree
Hide file tree
Showing 57 changed files with 1,793 additions and 337 deletions.
38 changes: 32 additions & 6 deletions testdata/p4tc_samples_outputs/add_entry_1_example_control_blocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ struct internal_metadata {
__u16 pkt_ether_type;
} __attribute__((aligned(4)));

struct skb_aggregate {
struct p4tc_skb_meta_get get;
struct p4tc_skb_meta_set set;
};

struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_1_key {
u32 keysz;
u32 maskid;
Expand Down Expand Up @@ -34,7 +39,7 @@ struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_1_value {
} u;
};

static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr, struct pna_global_metadata *compiler_meta__)
static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr, struct pna_global_metadata *compiler_meta__, struct skb_aggregate *sa)
{
struct hdr_md *hdrMd;

Expand Down Expand Up @@ -153,6 +158,18 @@ if (/* hdr->ipv4.isValid() */
outHeaderLength += 160;
}
;
__u16 saved_proto = 0;
bool have_saved_proto = false;
// bpf_skb_adjust_room works only when protocol is IPv4 or IPv6
// 0x0800 = IPv4, 0x86dd = IPv6
if ((skb->protocol != 0x0800) && (skb->protocol != 0x86dd)) {
saved_proto = skb->protocol;
have_saved_proto = true;
bpf_p4tc_skb_set_protocol(skb, &sa->set, 0x0800);
bpf_p4tc_skb_meta_set(skb, &sa->set, sizeof(sa->set));
}
;

int outHeaderOffset = BYTES(outHeaderLength) - (hdr_start - (u8*)pkt);
if (outHeaderOffset != 0) {
int returnCode = 0;
Expand All @@ -161,6 +178,12 @@ if (/* hdr->ipv4.isValid() */
return TC_ACT_SHOT;
}
}

if (have_saved_proto) {
bpf_p4tc_skb_set_protocol(skb, &sa->set, saved_proto);
bpf_p4tc_skb_meta_set(skb, &sa->set, sizeof(sa->set));
}

pkt = ((void*)(long)skb->data);
ebpf_packetEnd = ((void*)(long)skb->data_end);
ebpf_packetOffsetInBits = 0;
Expand Down Expand Up @@ -291,9 +314,10 @@ if (/* hdr->ipv4.isValid() */
}
SEC("p4tc/main")
int tc_ingress_func(struct __sk_buff *skb) {
struct skb_aggregate skbstuff;
struct pna_global_metadata *compiler_meta__ = (struct pna_global_metadata *) skb->cb;
if (compiler_meta__->pass_to_kernel == true) return TC_ACT_OK;
compiler_meta__->drop = false;
compiler_meta__->recirculate = false;
if (!compiler_meta__->recirculated) {
compiler_meta__->mark = 153;
struct internal_metadata *md = (struct internal_metadata *)(unsigned long)skb->data_meta;
Expand All @@ -308,14 +332,16 @@ int tc_ingress_func(struct __sk_buff *skb) {
struct hdr_md *hdrMd;
struct headers_t *hdr;
int ret = -1;
ret = process(skb, (struct headers_t *) hdr, compiler_meta__);
ret = process(skb, (struct headers_t *) hdr, compiler_meta__, &skbstuff);
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);
if (!compiler_meta__->drop && compiler_meta__->recirculate) {
compiler_meta__->recirculated = true;
return TC_ACT_UNSPEC;
}
if (!compiler_meta__->drop && compiler_meta__->egress_port == 0)
return TC_ACT_OK;
return bpf_redirect(compiler_meta__->egress_port, 0);
}
char _license[] SEC("license") = "GPL";
38 changes: 32 additions & 6 deletions testdata/p4tc_samples_outputs/add_entry_3_example_control_blocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ struct internal_metadata {
__u16 pkt_ether_type;
} __attribute__((aligned(4)));

struct skb_aggregate {
struct p4tc_skb_meta_get get;
struct p4tc_skb_meta_set set;
};

struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_1_key {
u32 keysz;
u32 maskid;
Expand Down Expand Up @@ -34,7 +39,7 @@ struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_1_value {
} u;
};

static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr, struct pna_global_metadata *compiler_meta__)
static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr, struct pna_global_metadata *compiler_meta__, struct skb_aggregate *sa)
{
struct hdr_md *hdrMd;

Expand Down Expand Up @@ -153,6 +158,18 @@ if (/* hdr->ipv4.isValid() */
outHeaderLength += 160;
}
;
__u16 saved_proto = 0;
bool have_saved_proto = false;
// bpf_skb_adjust_room works only when protocol is IPv4 or IPv6
// 0x0800 = IPv4, 0x86dd = IPv6
if ((skb->protocol != 0x0800) && (skb->protocol != 0x86dd)) {
saved_proto = skb->protocol;
have_saved_proto = true;
bpf_p4tc_skb_set_protocol(skb, &sa->set, 0x0800);
bpf_p4tc_skb_meta_set(skb, &sa->set, sizeof(sa->set));
}
;

int outHeaderOffset = BYTES(outHeaderLength) - (hdr_start - (u8*)pkt);
if (outHeaderOffset != 0) {
int returnCode = 0;
Expand All @@ -161,6 +178,12 @@ if (/* hdr->ipv4.isValid() */
return TC_ACT_SHOT;
}
}

if (have_saved_proto) {
bpf_p4tc_skb_set_protocol(skb, &sa->set, saved_proto);
bpf_p4tc_skb_meta_set(skb, &sa->set, sizeof(sa->set));
}

pkt = ((void*)(long)skb->data);
ebpf_packetEnd = ((void*)(long)skb->data_end);
ebpf_packetOffsetInBits = 0;
Expand Down Expand Up @@ -291,9 +314,10 @@ if (/* hdr->ipv4.isValid() */
}
SEC("p4tc/main")
int tc_ingress_func(struct __sk_buff *skb) {
struct skb_aggregate skbstuff;
struct pna_global_metadata *compiler_meta__ = (struct pna_global_metadata *) skb->cb;
if (compiler_meta__->pass_to_kernel == true) return TC_ACT_OK;
compiler_meta__->drop = false;
compiler_meta__->recirculate = false;
if (!compiler_meta__->recirculated) {
compiler_meta__->mark = 153;
struct internal_metadata *md = (struct internal_metadata *)(unsigned long)skb->data_meta;
Expand All @@ -308,14 +332,16 @@ int tc_ingress_func(struct __sk_buff *skb) {
struct hdr_md *hdrMd;
struct headers_t *hdr;
int ret = -1;
ret = process(skb, (struct headers_t *) hdr, compiler_meta__);
ret = process(skb, (struct headers_t *) hdr, compiler_meta__, &skbstuff);
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);
if (!compiler_meta__->drop && compiler_meta__->recirculate) {
compiler_meta__->recirculated = true;
return TC_ACT_UNSPEC;
}
if (!compiler_meta__->drop && compiler_meta__->egress_port == 0)
return TC_ACT_OK;
return bpf_redirect(compiler_meta__->egress_port, 0);
}
char _license[] SEC("license") = "GPL";
38 changes: 32 additions & 6 deletions testdata/p4tc_samples_outputs/add_entry_example_control_blocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ struct internal_metadata {
__u16 pkt_ether_type;
} __attribute__((aligned(4)));

struct skb_aggregate {
struct p4tc_skb_meta_get get;
struct p4tc_skb_meta_set set;
};

struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_1_key {
u32 keysz;
u32 maskid;
Expand Down Expand Up @@ -53,7 +58,7 @@ struct __attribute__((__packed__)) MainControlImpl_ipv4_tbl_2_value {
} u;
};

static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr, struct pna_global_metadata *compiler_meta__)
static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr, struct pna_global_metadata *compiler_meta__, struct skb_aggregate *sa)
{
struct hdr_md *hdrMd;

Expand Down Expand Up @@ -227,6 +232,18 @@ if (/* hdr->ipv4.isValid() */
outHeaderLength += 160;
}
;
__u16 saved_proto = 0;
bool have_saved_proto = false;
// bpf_skb_adjust_room works only when protocol is IPv4 or IPv6
// 0x0800 = IPv4, 0x86dd = IPv6
if ((skb->protocol != 0x0800) && (skb->protocol != 0x86dd)) {
saved_proto = skb->protocol;
have_saved_proto = true;
bpf_p4tc_skb_set_protocol(skb, &sa->set, 0x0800);
bpf_p4tc_skb_meta_set(skb, &sa->set, sizeof(sa->set));
}
;

int outHeaderOffset = BYTES(outHeaderLength) - (hdr_start - (u8*)pkt);
if (outHeaderOffset != 0) {
int returnCode = 0;
Expand All @@ -235,6 +252,12 @@ if (/* hdr->ipv4.isValid() */
return TC_ACT_SHOT;
}
}

if (have_saved_proto) {
bpf_p4tc_skb_set_protocol(skb, &sa->set, saved_proto);
bpf_p4tc_skb_meta_set(skb, &sa->set, sizeof(sa->set));
}

pkt = ((void*)(long)skb->data);
ebpf_packetEnd = ((void*)(long)skb->data_end);
ebpf_packetOffsetInBits = 0;
Expand Down Expand Up @@ -364,9 +387,10 @@ if (/* hdr->ipv4.isValid() */
}
SEC("p4tc/main")
int tc_ingress_func(struct __sk_buff *skb) {
struct skb_aggregate skbstuff;
struct pna_global_metadata *compiler_meta__ = (struct pna_global_metadata *) skb->cb;
if (compiler_meta__->pass_to_kernel == true) return TC_ACT_OK;
compiler_meta__->drop = false;
compiler_meta__->recirculate = false;
if (!compiler_meta__->recirculated) {
compiler_meta__->mark = 153;
struct internal_metadata *md = (struct internal_metadata *)(unsigned long)skb->data_meta;
Expand All @@ -381,14 +405,16 @@ int tc_ingress_func(struct __sk_buff *skb) {
struct hdr_md *hdrMd;
struct headers_t *hdr;
int ret = -1;
ret = process(skb, (struct headers_t *) hdr, compiler_meta__);
ret = process(skb, (struct headers_t *) hdr, compiler_meta__, &skbstuff);
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);
if (!compiler_meta__->drop && compiler_meta__->recirculate) {
compiler_meta__->recirculated = true;
return TC_ACT_UNSPEC;
}
if (!compiler_meta__->drop && compiler_meta__->egress_port == 0)
return TC_ACT_OK;
return bpf_redirect(compiler_meta__->egress_port, 0);
}
char _license[] SEC("license") = "GPL";
38 changes: 32 additions & 6 deletions testdata/p4tc_samples_outputs/calculator_control_blocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ struct internal_metadata {
__u16 pkt_ether_type;
} __attribute__((aligned(4)));

struct skb_aggregate {
struct p4tc_skb_meta_get get;
struct p4tc_skb_meta_set set;
};

struct __attribute__((__packed__)) MainControlImpl_calculate_key {
u32 keysz;
u32 maskid;
Expand Down Expand Up @@ -40,7 +45,7 @@ struct __attribute__((__packed__)) MainControlImpl_calculate_value {
} u;
};

static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr, struct pna_global_metadata *compiler_meta__)
static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr, struct pna_global_metadata *compiler_meta__, struct skb_aggregate *sa)
{
struct hdr_md *hdrMd;

Expand Down Expand Up @@ -191,6 +196,18 @@ if (/* hdr->p4calc.isValid() */
outHeaderLength += 128;
}
;
__u16 saved_proto = 0;
bool have_saved_proto = false;
// bpf_skb_adjust_room works only when protocol is IPv4 or IPv6
// 0x0800 = IPv4, 0x86dd = IPv6
if ((skb->protocol != 0x0800) && (skb->protocol != 0x86dd)) {
saved_proto = skb->protocol;
have_saved_proto = true;
bpf_p4tc_skb_set_protocol(skb, &sa->set, 0x0800);
bpf_p4tc_skb_meta_set(skb, &sa->set, sizeof(sa->set));
}
;

int outHeaderOffset = BYTES(outHeaderLength) - (hdr_start - (u8*)pkt);
if (outHeaderOffset != 0) {
int returnCode = 0;
Expand All @@ -199,6 +216,12 @@ if (/* hdr->p4calc.isValid() */
return TC_ACT_SHOT;
}
}

if (have_saved_proto) {
bpf_p4tc_skb_set_protocol(skb, &sa->set, saved_proto);
bpf_p4tc_skb_meta_set(skb, &sa->set, sizeof(sa->set));
}

pkt = ((void*)(long)skb->data);
ebpf_packetEnd = ((void*)(long)skb->data_end);
ebpf_packetOffsetInBits = 0;
Expand Down Expand Up @@ -306,9 +329,10 @@ if (/* hdr->p4calc.isValid() */
}
SEC("p4tc/main")
int tc_ingress_func(struct __sk_buff *skb) {
struct skb_aggregate skbstuff;
struct pna_global_metadata *compiler_meta__ = (struct pna_global_metadata *) skb->cb;
if (compiler_meta__->pass_to_kernel == true) return TC_ACT_OK;
compiler_meta__->drop = false;
compiler_meta__->recirculate = false;
if (!compiler_meta__->recirculated) {
compiler_meta__->mark = 153;
struct internal_metadata *md = (struct internal_metadata *)(unsigned long)skb->data_meta;
Expand All @@ -323,14 +347,16 @@ int tc_ingress_func(struct __sk_buff *skb) {
struct hdr_md *hdrMd;
struct headers_t *hdr;
int ret = -1;
ret = process(skb, (struct headers_t *) hdr, compiler_meta__);
ret = process(skb, (struct headers_t *) hdr, compiler_meta__, &skbstuff);
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);
if (!compiler_meta__->drop && compiler_meta__->recirculate) {
compiler_meta__->recirculated = true;
return TC_ACT_UNSPEC;
}
if (!compiler_meta__->drop && compiler_meta__->egress_port == 0)
return TC_ACT_OK;
return bpf_redirect(compiler_meta__->egress_port, 0);
}
char _license[] SEC("license") = "GPL";
2 changes: 1 addition & 1 deletion testdata/p4tc_samples_outputs/calculator_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ static __always_inline int run_parser(struct __sk_buff *skb, struct headers_t *h
ebpf_packetOffsetInBits = ebpf_packetOffsetInBits_save;
}
u32 select_0;
select_0 = (((((u32)(((u16)tmp_0.p << 8) | ((u16)tmp_2.four & 0xff)) << 8) & ((1 << 24) - 1)) | (((u32)tmp_4.ver & 0xff) & ((1 << 24) - 1))) & ((1 << 24) - 1));
select_0 = (((((u32)(((u16)tmp_0.p << 8) | ((u16)tmp_2.four & 0xff)) << 8) & ((1ULL << 24) - 1)) | (((u32)tmp_4.ver & 0xff) & ((1ULL << 24) - 1))) & ((1ULL << 24) - 1));
if (select_0 == 0x503401)goto parse_p4calc;
if ((select_0 & 0x0) == (0x0 & 0x0))goto accept;
else goto reject;
Expand Down
Loading

0 comments on commit 0ab3b1d

Please sign in to comment.