linux/tools/testing/selftests/bpf/sockmap_tcp_msg_prog.c
<<
>>
Prefs
   1#include <linux/bpf.h>
   2#include "bpf_helpers.h"
   3#include "bpf_util.h"
   4#include "bpf_endian.h"
   5
   6int _version SEC("version") = 1;
   7
   8#define bpf_printk(fmt, ...)                                    \
   9({                                                              \
  10               char ____fmt[] = fmt;                            \
  11               bpf_trace_printk(____fmt, sizeof(____fmt),       \
  12                                ##__VA_ARGS__);                 \
  13})
  14
  15SEC("sk_msg1")
  16int bpf_prog1(struct sk_msg_md *msg)
  17{
  18        void *data_end = (void *)(long) msg->data_end;
  19        void *data = (void *)(long) msg->data;
  20
  21        char *d;
  22
  23        if (data + 8 > data_end)
  24                return SK_DROP;
  25
  26        bpf_printk("data length %i\n", (__u64)msg->data_end - (__u64)msg->data);
  27        d = (char *)data;
  28        bpf_printk("hello sendmsg hook %i %i\n", d[0], d[1]);
  29
  30        return SK_PASS;
  31}
  32
  33char _license[] SEC("license") = "GPL";
  34