test_adjust_tail.c 731 B

123456789101112131415161718192021222324252627282930
  1. /* SPDX-License-Identifier: GPL-2.0
  2. * Copyright (c) 2018 Facebook
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of version 2 of the GNU General Public
  6. * License as published by the Free Software Foundation.
  7. */
  8. #include <linux/bpf.h>
  9. #include <linux/if_ether.h>
  10. #include "bpf_helpers.h"
  11. int _version SEC("version") = 1;
  12. SEC("xdp_adjust_tail")
  13. int _xdp_adjust_tail(struct xdp_md *xdp)
  14. {
  15. void *data_end = (void *)(long)xdp->data_end;
  16. void *data = (void *)(long)xdp->data;
  17. int offset = 0;
  18. if (data_end - data == 54)
  19. offset = 256;
  20. else
  21. offset = 20;
  22. if (bpf_xdp_adjust_tail(xdp, 0 - offset))
  23. return XDP_DROP;
  24. return XDP_TX;
  25. }
  26. char _license[] SEC("license") = "GPL";