Skip to content

Commit dc2b7ec

Browse files
committed
Simplify the xdp_stats_record_action function
The xdp_stats_record_action function doesn't use the packet data so we don't need to do perform any pointer arithmetic and instead use the data and data_end fields to compute packet length directly. Besides, in some cases the verifier can reject a program with the old version of the xdp_stats_record_action function saying that "pointer arithmetic with <<= operator prohibited". Signed-off-by: Anton Protopopov <a.s.protopopov@gmail.com>
1 parent 94f594e commit dc2b7ec

1 file changed

Lines changed: 1 addition & 7 deletions

File tree

common/xdp_stats_kern.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ struct bpf_map_def SEC("maps") xdp_stats_map = {
2323
static __always_inline
2424
__u32 xdp_stats_record_action(struct xdp_md *ctx, __u32 action)
2525
{
26-
void *data_end = (void *)(long)ctx->data_end;
27-
void *data = (void *)(long)ctx->data;
28-
2926
if (action >= XDP_ACTION_MAX)
3027
return XDP_ABORTED;
3128

@@ -34,15 +31,12 @@ __u32 xdp_stats_record_action(struct xdp_md *ctx, __u32 action)
3431
if (!rec)
3532
return XDP_ABORTED;
3633

37-
/* Calculate packet length */
38-
__u64 bytes = data_end - data;
39-
4034
/* BPF_MAP_TYPE_PERCPU_ARRAY returns a data record specific to current
4135
* CPU and XDP hooks runs under Softirq, which makes it safe to update
4236
* without atomic operations.
4337
*/
4438
rec->rx_packets++;
45-
rec->rx_bytes += bytes;
39+
rec->rx_bytes += (ctx->data_end - ctx->data);
4640

4741
return action;
4842
}

0 commit comments

Comments
 (0)