linux/tools/testing/selftests/bpf/progs/test_xdp_adjust_tail_grow.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0
   2#include <linux/bpf.h>
   3#include <bpf/bpf_helpers.h>
   4
   5SEC("xdp")
   6int _xdp_adjust_tail_grow(struct xdp_md *xdp)
   7{
   8        void *data_end = (void *)(long)xdp->data_end;
   9        void *data = (void *)(long)xdp->data;
  10        unsigned int data_len;
  11        int offset = 0;
  12
  13        /* Data length determine test case */
  14        data_len = data_end - data;
  15
  16        if (data_len == 54) { /* sizeof(pkt_v4) */
  17                offset = 4096; /* test too large offset */
  18        } else if (data_len == 74) { /* sizeof(pkt_v6) */
  19                offset = 40;
  20        } else if (data_len == 64) {
  21                offset = 128;
  22        } else if (data_len == 128) {
  23                offset = 4096 - 256 - 320 - data_len; /* Max tail grow 3520 */
  24        } else {
  25                return XDP_ABORTED; /* No matching test */
  26        }
  27
  28        if (bpf_xdp_adjust_tail(xdp, offset))
  29                return XDP_DROP;
  30        return XDP_TX;
  31}
  32
  33char _license[] SEC("license") = "GPL";
  34