xref: /kernel/linux/linux-5.10/samples/bpf/xdpsock_kern.c
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /kernel/linux/linux-5.10/samples/bpf/
18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci#include <linux/bpf.h>
38c2ecf20Sopenharmony_ci#include <bpf/bpf_helpers.h>
48c2ecf20Sopenharmony_ci#include "xdpsock.h"
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci/* This XDP program is only needed for the XDP_SHARED_UMEM mode.
78c2ecf20Sopenharmony_ci * If you do not use this mode, libbpf can supply an XDP program for you.
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_cistruct {
118c2ecf20Sopenharmony_ci	__uint(type, BPF_MAP_TYPE_XSKMAP);
128c2ecf20Sopenharmony_ci	__uint(max_entries, MAX_SOCKS);
138c2ecf20Sopenharmony_ci	__uint(key_size, sizeof(int));
148c2ecf20Sopenharmony_ci	__uint(value_size, sizeof(int));
158c2ecf20Sopenharmony_ci} xsks_map SEC(".maps");
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_cistatic unsigned int rr;
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ciSEC("xdp_sock") int xdp_sock_prog(struct xdp_md *ctx)
208c2ecf20Sopenharmony_ci{
218c2ecf20Sopenharmony_ci	rr = (rr + 1) & (MAX_SOCKS - 1);
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci	return bpf_redirect_map(&xsks_map, rr, XDP_DROP);
248c2ecf20Sopenharmony_ci}
25

Indexes created Thu Nov 07 10:32:03 CST 2024