Skip to content

Commit 3441911

Browse files
committed
experiment01-tailgrow: add xdp_prog_kern4.c that use ctx_store_bytes
The code works when 'len' is a constant, but doesn't work when we calculate the 'len' value. Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
1 parent cbe2cdd commit 3441911

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

experiment01-tailgrow/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
XDP_TARGETS := xdp_prog_kern xdp_prog_kern2
44
XDP_TARGETS += xdp_prog_kern3
5+
XDP_TARGETS += xdp_prog_kern4
56
XDP_TARGETS += xdp_prog_fail1
67
XDP_TARGETS += xdp_prog_fail2
78

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#include <linux/bpf.h>
3+
#include <bpf/bpf_helpers.h>
4+
5+
#include "xdp_data_access_helpers.h"
6+
7+
SEC("xdp_test1")
8+
int _xdp_test1(struct xdp_md *ctx)
9+
{
10+
// void *data_end = (void *)(long)ctx->data_end;
11+
void *data = (void *)(long)ctx->data;
12+
unsigned int len;
13+
// len = (data_end - data) - 2 ; // Not working, due to verifier
14+
len = 12;
15+
16+
unsigned int offset = len - 2;
17+
18+
if (ctx_store_bytes(ctx, offset, data, 2, 0) < 0)
19+
return XDP_ABORTED;
20+
21+
return XDP_PASS;
22+
}
23+

0 commit comments

Comments
 (0)