2019-11-07 10:47:37 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#include <linux/bpf.h>
|
2020-01-20 06:06:49 -07:00
|
|
|
#include <bpf/bpf_helpers.h>
|
2019-11-07 10:47:37 -07:00
|
|
|
#include "xdpsock.h"
|
|
|
|
|
|
|
|
/* This XDP program is only needed for the XDP_SHARED_UMEM mode.
|
|
|
|
* If you do not use this mode, libbpf can supply an XDP program for you.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct {
|
|
|
|
__uint(type, BPF_MAP_TYPE_XSKMAP);
|
|
|
|
__uint(max_entries, MAX_SOCKS);
|
|
|
|
__uint(key_size, sizeof(int));
|
|
|
|
__uint(value_size, sizeof(int));
|
|
|
|
} xsks_map SEC(".maps");
|
|
|
|
|
|
|
|
static unsigned int rr;
|
|
|
|
|
|
|
|
SEC("xdp_sock") int xdp_sock_prog(struct xdp_md *ctx)
|
|
|
|
{
|
|
|
|
rr = (rr + 1) & (MAX_SOCKS - 1);
|
|
|
|
|
|
|
|
return bpf_redirect_map(&xsks_map, rr, XDP_DROP);
|
|
|
|
}
|