xdpsock_kern.c 593 B

123456789101112131415161718192021222324
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/bpf.h>
  3. #include <bpf/bpf_helpers.h>
  4. #include "xdpsock.h"
  5. /* This XDP program is only needed for the XDP_SHARED_UMEM mode.
  6. * If you do not use this mode, libbpf can supply an XDP program for you.
  7. */
  8. struct {
  9. __uint(type, BPF_MAP_TYPE_XSKMAP);
  10. __uint(max_entries, MAX_SOCKS);
  11. __uint(key_size, sizeof(int));
  12. __uint(value_size, sizeof(int));
  13. } xsks_map SEC(".maps");
  14. static unsigned int rr;
  15. SEC("xdp_sock") int xdp_sock_prog(struct xdp_md *ctx)
  16. {
  17. rr = (rr + 1) & (MAX_SOCKS - 1);
  18. return bpf_redirect_map(&xsks_map, rr, XDP_DROP);
  19. }