Loading tools/include/uapi/linux/bpf.h +10 −0 Original line number Diff line number Diff line Loading @@ -133,6 +133,7 @@ enum bpf_prog_type { BPF_PROG_TYPE_SOCK_OPS, BPF_PROG_TYPE_SK_SKB, BPF_PROG_TYPE_CGROUP_DEVICE, BPF_PROG_TYPE_SK_MSG, }; enum bpf_attach_type { Loading @@ -143,6 +144,7 @@ enum bpf_attach_type { BPF_SK_SKB_STREAM_PARSER, BPF_SK_SKB_STREAM_VERDICT, BPF_CGROUP_DEVICE, BPF_SK_MSG_VERDICT, __MAX_BPF_ATTACH_TYPE }; Loading Loading @@ -941,6 +943,14 @@ enum sk_action { SK_PASS, }; /* user accessible metadata for SK_MSG packet hook, new fields must * be added to the end of this structure */ struct sk_msg_md { void *data; void *data_end; }; #define BPF_TAG_SIZE 8 struct bpf_prog_info { Loading tools/testing/selftests/bpf/Makefile +2 −1 Original line number Diff line number Diff line Loading @@ -29,7 +29,8 @@ TEST_GEN_FILES = test_pkt_access.o test_xdp.o test_l4lb.o test_tcp_estats.o test test_pkt_md_access.o test_xdp_redirect.o test_xdp_meta.o sockmap_parse_prog.o \ sockmap_verdict_prog.o dev_cgroup.o sample_ret0.o test_tracepoint.o \ test_l4lb_noinline.o test_xdp_noinline.o test_stacktrace_map.o \ sample_map_ret0.o test_tcpbpf_kern.o test_stacktrace_build_id.o sample_map_ret0.o test_tcpbpf_kern.o test_stacktrace_build_id.o \ sockmap_tcp_msg_prog.o # Order correspond to 'make run_tests' order TEST_PROGS := test_kmod.sh \ Loading tools/testing/selftests/bpf/bpf_helpers.h +2 −0 Original line number Diff line number Diff line Loading @@ -123,6 +123,8 @@ static int (*bpf_skb_under_cgroup)(void *ctx, void *map, int index) = (void *) BPF_FUNC_skb_under_cgroup; static int (*bpf_skb_change_head)(void *, int len, int flags) = (void *) BPF_FUNC_skb_change_head; static int (*bpf_skb_pull_data)(void *, int len) = (void *) BPF_FUNC_skb_pull_data; /* Scan the ARCH passed in from ARCH env variable (see Makefile) */ #if defined(__TARGET_ARCH_x86) Loading tools/testing/selftests/bpf/sockmap_parse_prog.c +13 −2 Original line number Diff line number Diff line Loading @@ -20,14 +20,25 @@ int bpf_prog1(struct __sk_buff *skb) __u32 lport = skb->local_port; __u32 rport = skb->remote_port; __u8 *d = data; __u32 len = (__u32) data_end - (__u32) data; int err; if (data + 10 > data_end) { err = bpf_skb_pull_data(skb, 10); if (err) return SK_DROP; data_end = (void *)(long)skb->data_end; data = (void *)(long)skb->data; if (data + 10 > data_end) return skb->len; return SK_DROP; } /* This write/read is a bit pointless but tests the verifier and * strparser handler for read/write pkt data and access into sk * fields. */ d = data; d[7] = 1; return skb->len; } Loading tools/testing/selftests/bpf/sockmap_tcp_msg_prog.c 0 → 100644 +33 −0 Original line number Diff line number Diff line #include <linux/bpf.h> #include "bpf_helpers.h" #include "bpf_util.h" #include "bpf_endian.h" int _version SEC("version") = 1; #define bpf_printk(fmt, ...) \ ({ \ char ____fmt[] = fmt; \ bpf_trace_printk(____fmt, sizeof(____fmt), \ ##__VA_ARGS__); \ }) SEC("sk_msg1") int bpf_prog1(struct sk_msg_md *msg) { void *data_end = (void *)(long) msg->data_end; void *data = (void *)(long) msg->data; char *d; if (data + 8 > data_end) return SK_DROP; bpf_printk("data length %i\n", (__u64)msg->data_end - (__u64)msg->data); d = (char *)data; bpf_printk("hello sendmsg hook %i %i\n", d[0], d[1]); return SK_PASS; } char _license[] SEC("license") = "GPL"; Loading
tools/include/uapi/linux/bpf.h +10 −0 Original line number Diff line number Diff line Loading @@ -133,6 +133,7 @@ enum bpf_prog_type { BPF_PROG_TYPE_SOCK_OPS, BPF_PROG_TYPE_SK_SKB, BPF_PROG_TYPE_CGROUP_DEVICE, BPF_PROG_TYPE_SK_MSG, }; enum bpf_attach_type { Loading @@ -143,6 +144,7 @@ enum bpf_attach_type { BPF_SK_SKB_STREAM_PARSER, BPF_SK_SKB_STREAM_VERDICT, BPF_CGROUP_DEVICE, BPF_SK_MSG_VERDICT, __MAX_BPF_ATTACH_TYPE }; Loading Loading @@ -941,6 +943,14 @@ enum sk_action { SK_PASS, }; /* user accessible metadata for SK_MSG packet hook, new fields must * be added to the end of this structure */ struct sk_msg_md { void *data; void *data_end; }; #define BPF_TAG_SIZE 8 struct bpf_prog_info { Loading
tools/testing/selftests/bpf/Makefile +2 −1 Original line number Diff line number Diff line Loading @@ -29,7 +29,8 @@ TEST_GEN_FILES = test_pkt_access.o test_xdp.o test_l4lb.o test_tcp_estats.o test test_pkt_md_access.o test_xdp_redirect.o test_xdp_meta.o sockmap_parse_prog.o \ sockmap_verdict_prog.o dev_cgroup.o sample_ret0.o test_tracepoint.o \ test_l4lb_noinline.o test_xdp_noinline.o test_stacktrace_map.o \ sample_map_ret0.o test_tcpbpf_kern.o test_stacktrace_build_id.o sample_map_ret0.o test_tcpbpf_kern.o test_stacktrace_build_id.o \ sockmap_tcp_msg_prog.o # Order correspond to 'make run_tests' order TEST_PROGS := test_kmod.sh \ Loading
tools/testing/selftests/bpf/bpf_helpers.h +2 −0 Original line number Diff line number Diff line Loading @@ -123,6 +123,8 @@ static int (*bpf_skb_under_cgroup)(void *ctx, void *map, int index) = (void *) BPF_FUNC_skb_under_cgroup; static int (*bpf_skb_change_head)(void *, int len, int flags) = (void *) BPF_FUNC_skb_change_head; static int (*bpf_skb_pull_data)(void *, int len) = (void *) BPF_FUNC_skb_pull_data; /* Scan the ARCH passed in from ARCH env variable (see Makefile) */ #if defined(__TARGET_ARCH_x86) Loading
tools/testing/selftests/bpf/sockmap_parse_prog.c +13 −2 Original line number Diff line number Diff line Loading @@ -20,14 +20,25 @@ int bpf_prog1(struct __sk_buff *skb) __u32 lport = skb->local_port; __u32 rport = skb->remote_port; __u8 *d = data; __u32 len = (__u32) data_end - (__u32) data; int err; if (data + 10 > data_end) { err = bpf_skb_pull_data(skb, 10); if (err) return SK_DROP; data_end = (void *)(long)skb->data_end; data = (void *)(long)skb->data; if (data + 10 > data_end) return skb->len; return SK_DROP; } /* This write/read is a bit pointless but tests the verifier and * strparser handler for read/write pkt data and access into sk * fields. */ d = data; d[7] = 1; return skb->len; } Loading
tools/testing/selftests/bpf/sockmap_tcp_msg_prog.c 0 → 100644 +33 −0 Original line number Diff line number Diff line #include <linux/bpf.h> #include "bpf_helpers.h" #include "bpf_util.h" #include "bpf_endian.h" int _version SEC("version") = 1; #define bpf_printk(fmt, ...) \ ({ \ char ____fmt[] = fmt; \ bpf_trace_printk(____fmt, sizeof(____fmt), \ ##__VA_ARGS__); \ }) SEC("sk_msg1") int bpf_prog1(struct sk_msg_md *msg) { void *data_end = (void *)(long) msg->data_end; void *data = (void *)(long) msg->data; char *d; if (data + 8 > data_end) return SK_DROP; bpf_printk("data length %i\n", (__u64)msg->data_end - (__u64)msg->data); d = (char *)data; bpf_printk("hello sendmsg hook %i %i\n", d[0], d[1]); return SK_PASS; } char _license[] SEC("license") = "GPL";