Skip to content

Commit

Permalink
Remove XDP code generated for TC
Browse files Browse the repository at this point in the history
Remove XDP section that is always generated for the TC backend.
This XDP code generated for TC was responsible for setting the
skb->protocol field which is not writable in TC. We have a found better
way to do that with an extern, hence this XDP section isn't needed
anymore.
  • Loading branch information
mouse-mt authored and vbnogueira committed Jan 29, 2024
1 parent 9b99be4 commit d3ccbb4
Show file tree
Hide file tree
Showing 24 changed files with 2 additions and 675 deletions.
10 changes: 2 additions & 8 deletions backends/tc/ebpfCodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ void PNAArchTC::emit(EBPF::CodeBuilder *builder) const {
* 2. Includes
* 3. Headers, structs
* 4. BPF map definitions.
* 5. XDP helper program.
* 6. TC Pipeline program for post-parser.
* 5. TC Pipeline program for post-parser.
*/

// 1. Automatically generated comment.
Expand All @@ -139,12 +138,7 @@ void PNAArchTC::emit(EBPF::CodeBuilder *builder) const {
emitInstances(builder);

/*
* 5. XDP helper program.
*/
xdp->emit(builder);

/*
* 6. TC Pipeline program for post-parser.
* 5. TC Pipeline program for post-parser.
*/
pipeline->emit(builder);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,35 +50,6 @@ 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_END()

SEC("xdp/xdp-ingress")
int xdp_func(struct xdp_md *skb) {
void *data_end = (void *)(long)skb->data_end;
struct ethhdr *eth = (struct ethhdr *)(long)skb->data;
if ((void *)((struct ethhdr *) eth + 1) > data_end) {
return XDP_ABORTED;
}
if (eth->h_proto == bpf_htons(0x0800) || eth->h_proto == bpf_htons(0x86DD)) {
return XDP_PASS;
}

struct internal_metadata *meta;
int ret = bpf_xdp_adjust_meta(skb, -(int)sizeof(*meta));
if (ret < 0) {
return XDP_ABORTED;
}
meta = (struct internal_metadata *)(unsigned long)skb->data_meta;
eth = (void *)(long)skb->data;
data_end = (void *)(long)skb->data_end;
if ((void *) ((struct internal_metadata *) meta + 1) > (void *)(long)skb->data)
return XDP_ABORTED;
if ((void *)((struct ethhdr *) eth + 1) > data_end) {
return XDP_ABORTED;
}
meta->pkt_ether_type = eth->h_proto;
eth->h_proto = bpf_htons(0x0800);

return XDP_PASS;
}
static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr, struct pna_global_metadata *compiler_meta__)
{
struct hdr_md *hdrMd;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,6 @@ 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_END()

SEC("xdp/xdp-ingress")
int xdp_func(struct xdp_md *skb) {
void *data_end = (void *)(long)skb->data_end;
struct ethhdr *eth = (struct ethhdr *)(long)skb->data;
if ((void *)((struct ethhdr *) eth + 1) > data_end) {
return XDP_ABORTED;
}
if (eth->h_proto == bpf_htons(0x0800) || eth->h_proto == bpf_htons(0x86DD)) {
return XDP_PASS;
}

struct internal_metadata *meta;
int ret = bpf_xdp_adjust_meta(skb, -(int)sizeof(*meta));
if (ret < 0) {
return XDP_ABORTED;
}
meta = (struct internal_metadata *)(unsigned long)skb->data_meta;
eth = (void *)(long)skb->data;
data_end = (void *)(long)skb->data_end;
if ((void *) ((struct internal_metadata *) meta + 1) > (void *)(long)skb->data)
return XDP_ABORTED;
if ((void *)((struct ethhdr *) eth + 1) > data_end) {
return XDP_ABORTED;
}
meta->pkt_ether_type = eth->h_proto;
eth->h_proto = bpf_htons(0x0800);

return XDP_PASS;
}
static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr, struct pna_global_metadata *compiler_meta__)
{
struct hdr_md *hdrMd;
Expand Down
29 changes: 0 additions & 29 deletions testdata/p4tc_samples_outputs/drop_packet_example_control_blocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,6 @@ 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_END()

SEC("xdp/xdp-ingress")
int xdp_func(struct xdp_md *skb) {
void *data_end = (void *)(long)skb->data_end;
struct ethhdr *eth = (struct ethhdr *)(long)skb->data;
if ((void *)((struct ethhdr *) eth + 1) > data_end) {
return XDP_ABORTED;
}
if (eth->h_proto == bpf_htons(0x0800) || eth->h_proto == bpf_htons(0x86DD)) {
return XDP_PASS;
}

struct internal_metadata *meta;
int ret = bpf_xdp_adjust_meta(skb, -(int)sizeof(*meta));
if (ret < 0) {
return XDP_ABORTED;
}
meta = (struct internal_metadata *)(unsigned long)skb->data_meta;
eth = (void *)(long)skb->data;
data_end = (void *)(long)skb->data_end;
if ((void *) ((struct internal_metadata *) meta + 1) > (void *)(long)skb->data)
return XDP_ABORTED;
if ((void *)((struct ethhdr *) eth + 1) > data_end) {
return XDP_ABORTED;
}
meta->pkt_ether_type = eth->h_proto;
eth->h_proto = bpf_htons(0x0800);

return XDP_PASS;
}
static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr, struct pna_global_metadata *compiler_meta__)
{
struct hdr_md *hdrMd;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,35 +50,6 @@ 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_END()

SEC("xdp/xdp-ingress")
int xdp_func(struct xdp_md *skb) {
void *data_end = (void *)(long)skb->data_end;
struct ethhdr *eth = (struct ethhdr *)(long)skb->data;
if ((void *)((struct ethhdr *) eth + 1) > data_end) {
return XDP_ABORTED;
}
if (eth->h_proto == bpf_htons(0x0800) || eth->h_proto == bpf_htons(0x86DD)) {
return XDP_PASS;
}

struct internal_metadata *meta;
int ret = bpf_xdp_adjust_meta(skb, -(int)sizeof(*meta));
if (ret < 0) {
return XDP_ABORTED;
}
meta = (struct internal_metadata *)(unsigned long)skb->data_meta;
eth = (void *)(long)skb->data;
data_end = (void *)(long)skb->data_end;
if ((void *) ((struct internal_metadata *) meta + 1) > (void *)(long)skb->data)
return XDP_ABORTED;
if ((void *)((struct ethhdr *) eth + 1) > data_end) {
return XDP_ABORTED;
}
meta->pkt_ether_type = eth->h_proto;
eth->h_proto = bpf_htons(0x0800);

return XDP_PASS;
}
static __always_inline int process(struct __sk_buff *skb, struct my_ingress_headers_t *hdr, struct pna_global_metadata *compiler_meta__)
{
struct hdr_md *hdrMd;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,35 +51,6 @@ 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_END()

SEC("xdp/xdp-ingress")
int xdp_func(struct xdp_md *skb) {
void *data_end = (void *)(long)skb->data_end;
struct ethhdr *eth = (struct ethhdr *)(long)skb->data;
if ((void *)((struct ethhdr *) eth + 1) > data_end) {
return XDP_ABORTED;
}
if (eth->h_proto == bpf_htons(0x0800) || eth->h_proto == bpf_htons(0x86DD)) {
return XDP_PASS;
}

struct internal_metadata *meta;
int ret = bpf_xdp_adjust_meta(skb, -(int)sizeof(*meta));
if (ret < 0) {
return XDP_ABORTED;
}
meta = (struct internal_metadata *)(unsigned long)skb->data_meta;
eth = (void *)(long)skb->data;
data_end = (void *)(long)skb->data_end;
if ((void *) ((struct internal_metadata *) meta + 1) > (void *)(long)skb->data)
return XDP_ABORTED;
if ((void *)((struct ethhdr *) eth + 1) > data_end) {
return XDP_ABORTED;
}
meta->pkt_ether_type = eth->h_proto;
eth->h_proto = bpf_htons(0x0800);

return XDP_PASS;
}
static __always_inline int process(struct __sk_buff *skb, struct my_ingress_headers_t *hdr, struct pna_global_metadata *compiler_meta__)
{
struct hdr_md *hdrMd;
Expand Down
29 changes: 0 additions & 29 deletions testdata/p4tc_samples_outputs/ipip_control_blocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,6 @@ 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_END()

SEC("xdp/xdp-ingress")
int xdp_func(struct xdp_md *skb) {
void *data_end = (void *)(long)skb->data_end;
struct ethhdr *eth = (struct ethhdr *)(long)skb->data;
if ((void *)((struct ethhdr *) eth + 1) > data_end) {
return XDP_ABORTED;
}
if (eth->h_proto == bpf_htons(0x0800) || eth->h_proto == bpf_htons(0x86DD)) {
return XDP_PASS;
}

struct internal_metadata *meta;
int ret = bpf_xdp_adjust_meta(skb, -(int)sizeof(*meta));
if (ret < 0) {
return XDP_ABORTED;
}
meta = (struct internal_metadata *)(unsigned long)skb->data_meta;
eth = (void *)(long)skb->data;
data_end = (void *)(long)skb->data_end;
if ((void *) ((struct internal_metadata *) meta + 1) > (void *)(long)skb->data)
return XDP_ABORTED;
if ((void *)((struct ethhdr *) eth + 1) > data_end) {
return XDP_ABORTED;
}
meta->pkt_ether_type = eth->h_proto;
eth->h_proto = bpf_htons(0x0800);

return XDP_PASS;
}
static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr, struct pna_global_metadata *compiler_meta__)
{
struct hdr_md *hdrMd;
Expand Down
29 changes: 0 additions & 29 deletions testdata/p4tc_samples_outputs/matchtype_control_blocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,35 +94,6 @@ 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_END()

SEC("xdp/xdp-ingress")
int xdp_func(struct xdp_md *skb) {
void *data_end = (void *)(long)skb->data_end;
struct ethhdr *eth = (struct ethhdr *)(long)skb->data;
if ((void *)((struct ethhdr *) eth + 1) > data_end) {
return XDP_ABORTED;
}
if (eth->h_proto == bpf_htons(0x0800) || eth->h_proto == bpf_htons(0x86DD)) {
return XDP_PASS;
}

struct internal_metadata *meta;
int ret = bpf_xdp_adjust_meta(skb, -(int)sizeof(*meta));
if (ret < 0) {
return XDP_ABORTED;
}
meta = (struct internal_metadata *)(unsigned long)skb->data_meta;
eth = (void *)(long)skb->data;
data_end = (void *)(long)skb->data_end;
if ((void *) ((struct internal_metadata *) meta + 1) > (void *)(long)skb->data)
return XDP_ABORTED;
if ((void *)((struct ethhdr *) eth + 1) > data_end) {
return XDP_ABORTED;
}
meta->pkt_ether_type = eth->h_proto;
eth->h_proto = bpf_htons(0x0800);

return XDP_PASS;
}
static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr, struct pna_global_metadata *compiler_meta__)
{
struct hdr_md *hdrMd;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,35 +100,6 @@ 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_END()

SEC("xdp/xdp-ingress")
int xdp_func(struct xdp_md *skb) {
void *data_end = (void *)(long)skb->data_end;
struct ethhdr *eth = (struct ethhdr *)(long)skb->data;
if ((void *)((struct ethhdr *) eth + 1) > data_end) {
return XDP_ABORTED;
}
if (eth->h_proto == bpf_htons(0x0800) || eth->h_proto == bpf_htons(0x86DD)) {
return XDP_PASS;
}

struct internal_metadata *meta;
int ret = bpf_xdp_adjust_meta(skb, -(int)sizeof(*meta));
if (ret < 0) {
return XDP_ABORTED;
}
meta = (struct internal_metadata *)(unsigned long)skb->data_meta;
eth = (void *)(long)skb->data;
data_end = (void *)(long)skb->data_end;
if ((void *) ((struct internal_metadata *) meta + 1) > (void *)(long)skb->data)
return XDP_ABORTED;
if ((void *)((struct ethhdr *) eth + 1) > data_end) {
return XDP_ABORTED;
}
meta->pkt_ether_type = eth->h_proto;
eth->h_proto = bpf_htons(0x0800);

return XDP_PASS;
}
static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr, struct pna_global_metadata *compiler_meta__)
{
struct hdr_md *hdrMd;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,35 +171,6 @@ 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_END()

SEC("xdp/xdp-ingress")
int xdp_func(struct xdp_md *skb) {
void *data_end = (void *)(long)skb->data_end;
struct ethhdr *eth = (struct ethhdr *)(long)skb->data;
if ((void *)((struct ethhdr *) eth + 1) > data_end) {
return XDP_ABORTED;
}
if (eth->h_proto == bpf_htons(0x0800) || eth->h_proto == bpf_htons(0x86DD)) {
return XDP_PASS;
}

struct internal_metadata *meta;
int ret = bpf_xdp_adjust_meta(skb, -(int)sizeof(*meta));
if (ret < 0) {
return XDP_ABORTED;
}
meta = (struct internal_metadata *)(unsigned long)skb->data_meta;
eth = (void *)(long)skb->data;
data_end = (void *)(long)skb->data_end;
if ((void *) ((struct internal_metadata *) meta + 1) > (void *)(long)skb->data)
return XDP_ABORTED;
if ((void *)((struct ethhdr *) eth + 1) > data_end) {
return XDP_ABORTED;
}
meta->pkt_ether_type = eth->h_proto;
eth->h_proto = bpf_htons(0x0800);

return XDP_PASS;
}
static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr, struct pna_global_metadata *compiler_meta__)
{
struct hdr_md *hdrMd;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,35 +168,6 @@ 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_END()

SEC("xdp/xdp-ingress")
int xdp_func(struct xdp_md *skb) {
void *data_end = (void *)(long)skb->data_end;
struct ethhdr *eth = (struct ethhdr *)(long)skb->data;
if ((void *)((struct ethhdr *) eth + 1) > data_end) {
return XDP_ABORTED;
}
if (eth->h_proto == bpf_htons(0x0800) || eth->h_proto == bpf_htons(0x86DD)) {
return XDP_PASS;
}

struct internal_metadata *meta;
int ret = bpf_xdp_adjust_meta(skb, -(int)sizeof(*meta));
if (ret < 0) {
return XDP_ABORTED;
}
meta = (struct internal_metadata *)(unsigned long)skb->data_meta;
eth = (void *)(long)skb->data;
data_end = (void *)(long)skb->data_end;
if ((void *) ((struct internal_metadata *) meta + 1) > (void *)(long)skb->data)
return XDP_ABORTED;
if ((void *)((struct ethhdr *) eth + 1) > data_end) {
return XDP_ABORTED;
}
meta->pkt_ether_type = eth->h_proto;
eth->h_proto = bpf_htons(0x0800);

return XDP_PASS;
}
static __always_inline int process(struct __sk_buff *skb, struct headers_t *hdr, struct pna_global_metadata *compiler_meta__)
{
struct hdr_md *hdrMd;
Expand Down
Loading

0 comments on commit d3ccbb4

Please sign in to comment.