8 #include <linux/if_ether.h> 10 #include <linux/udp.h> 11 #include <bpf/bpf_helpers.h> 20 #define x_(fmt) __FILE__ ":" s_(__LINE__) ": " fmt "\n" 21 #define DEBUG_PRINT_(fmt, ...) do { \ 22 const char fmt__[] = fmt; \ 23 bpf_trace_printk(fmt__, sizeof(fmt), ## __VA_ARGS__); } while(0) 24 #define DEBUG_PRINT(fmt, ...) DEBUG_PRINT_ (x_(fmt), ## __VA_ARGS__) 26 #define DEBUG_PRINT(fmt, ...) 29 #define ntohs(x) __constant_ntohs(x) 33 .type = BPF_MAP_TYPE_XSKMAP,
34 .key_size =
sizeof(int),
35 .value_size =
sizeof(
int),
41 const void *
data = (
void *)(
long)
ctx->data;
42 const void *data_end = (
void *)(
long)
ctx->data_end;
47 if (
data +
sizeof(
struct ethhdr) + 2 *
sizeof(
struct iphdr) > data_end) {
52 const struct ethhdr *eth =
data;
53 if (eth->h_proto !=
ntohs(ETH_P_IP)) {
54 DEBUG_PRINT(
"unsupported eth proto %x", (
int)eth->h_proto);
58 const struct iphdr *
ip = (
void *)(eth + 1);
59 switch (
ip->protocol) {
61 const struct udphdr *udp = (
void *)(
ip + 1);
62 if (udp->dest !=
ntohs(4789)) {
63 DEBUG_PRINT(
"unsupported udp dst port %x", (
int)udp->dest);
75 int qid =
ctx->rx_queue_index;
76 if (!bpf_map_lookup_elem(&
xsks_map, &qid))
83 return bpf_redirect_map(&
xsks_map, qid, 0);
88 char _license[] =
"GPL";
struct bpf_map_def xsks_map
#define DEBUG_PRINT(fmt,...)
int xdp_sock_prog(struct xdp_md *ctx)