Skip to content

Commit

Permalink
XDP offload: Do not add extra UDP padding [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
levaitamas committed Nov 16, 2023
1 parent 35b3b12 commit 3d0fc0e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
Binary file modified internal/offload/xdp/bpf_bpfeb.o
Binary file not shown.
Binary file modified internal/offload/xdp/bpf_bpfel.o
Binary file not shown.
19 changes: 18 additions & 1 deletion internal/offload/xdp/xdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ int xdp_prog_func(struct xdp_md *ctx)
data_end = (void *)(long)ctx->data_end;
data = (void *)(long)ctx->data;
// note: data_end - data is the NIC-padded length of the packet
__u16 pkt_buf_len = data_end - data;
udp_payload =
data + sizeof(struct ethhdr) + sizeof(struct iphdr) + sizeof(struct udphdr);

Expand Down Expand Up @@ -237,16 +238,32 @@ int xdp_prog_func(struct xdp_md *ctx)
chan_hdr_action = HDR_ADD;

// add padding

// check if new padding is necessary
// e.g., in case of NIC-padded packets we can reuse existing padding
int useful_len = hdrs_len + udp_payload_len;
int existing_padding = pkt_buf_len - useful_len;

__u16 padded_len = 4 * ((__u16)udp_payload_len / 4);
if (padded_len < udp_payload_len) {
padded_len += 4;
}
padding = padded_len - (__u16)udp_payload_len;
udp_payload_len += padding;

if ((existing_padding > 0) && (padding != 0)) {
padding -= existing_padding - ((__u32)existing_padding / padding * padding);
if (existing_padding > padding) {
padding = 0;
}
}

// add padding
r = bpf_xdp_adjust_tail(ctx, padding);
if (r != 0)
goto out;
udp_payload_len += padding;

// set out_tuple for further processing
out_tuple = &out_tuplec_ds->four_tuple;
} else {
// read channel id
Expand Down

0 comments on commit 3d0fc0e

Please sign in to comment.