aboutsummaryrefslogtreecommitdiffstats
path: root/samples
diff options
context:
space:
mode:
authorJohn Fastabend <john.fastabend@gmail.com>2018-04-23 17:30:43 -0400
committerDaniel Borkmann <daniel@iogearbox.net>2018-04-24 18:06:21 -0400
commit2e04eb1dd1caf4eaa0998e928f1fb896e35b01f2 (patch)
tree94e5a929079cbf5e00a8e22197a084c350ac9237 /samples
parent16962b2404ac88cde0281fe2176d6ae3820ed320 (diff)
bpf: sockmap, remove samples program
The BPF sample sockmap is redundant now that equivelant tests exist in the BPF selftests. Lets remove this sample and only keep the selftest version that will be run as part of the selftest suite. Signed-off-by: John Fastabend <john.fastabend@gmail.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'samples')
-rw-r--r--samples/sockmap/Makefile75
-rw-r--r--samples/sockmap/sockmap_kern.c341
-rwxr-xr-xsamples/sockmap/sockmap_test.sh488
-rw-r--r--samples/sockmap/sockmap_user.c1372
4 files changed, 0 insertions, 2276 deletions
diff --git a/samples/sockmap/Makefile b/samples/sockmap/Makefile
deleted file mode 100644
index 9bf2881bd11b..000000000000
--- a/samples/sockmap/Makefile
+++ /dev/null
@@ -1,75 +0,0 @@
1# List of programs to build
2hostprogs-y := sockmap
3
4# Libbpf dependencies
5LIBBPF := ../../tools/lib/bpf/bpf.o ../../tools/lib/bpf/nlattr.o
6
7HOSTCFLAGS += -I$(objtree)/usr/include
8HOSTCFLAGS += -I$(srctree)/tools/lib/
9HOSTCFLAGS += -I$(srctree)/tools/testing/selftests/bpf/
10HOSTCFLAGS += -I$(srctree)/tools/lib/ -I$(srctree)/tools/include
11HOSTCFLAGS += -I$(srctree)/tools/perf
12
13sockmap-objs := ../bpf/bpf_load.o $(LIBBPF) sockmap_user.o
14
15# Tell kbuild to always build the programs
16always := $(hostprogs-y)
17always += sockmap_kern.o
18
19HOSTLOADLIBES_sockmap += -lelf -lpthread
20
21# Allows pointing LLC/CLANG to a LLVM backend with bpf support, redefine on cmdline:
22# make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang
23LLC ?= llc
24CLANG ?= clang
25
26# Trick to allow make to be run from this directory
27all:
28 $(MAKE) -C ../../ $(CURDIR)/
29
30clean:
31 $(MAKE) -C ../../ M=$(CURDIR) clean
32 @rm -f *~
33
34$(obj)/syscall_nrs.s: $(src)/syscall_nrs.c
35 $(call if_changed_dep,cc_s_c)
36
37$(obj)/syscall_nrs.h: $(obj)/syscall_nrs.s FORCE
38 $(call filechk,offsets,__SYSCALL_NRS_H__)
39
40clean-files += syscall_nrs.h
41
42FORCE:
43
44
45# Verify LLVM compiler tools are available and bpf target is supported by llc
46.PHONY: verify_cmds verify_target_bpf $(CLANG) $(LLC)
47
48verify_cmds: $(CLANG) $(LLC)
49 @for TOOL in $^ ; do \
50 if ! (which -- "$${TOOL}" > /dev/null 2>&1); then \
51 echo "*** ERROR: Cannot find LLVM tool $${TOOL}" ;\
52 exit 1; \
53 else true; fi; \
54 done
55
56verify_target_bpf: verify_cmds
57 @if ! (${LLC} -march=bpf -mattr=help > /dev/null 2>&1); then \
58 echo "*** ERROR: LLVM (${LLC}) does not support 'bpf' target" ;\
59 echo " NOTICE: LLVM version >= 3.7.1 required" ;\
60 exit 2; \
61 else true; fi
62
63$(src)/*.c: verify_target_bpf
64
65# asm/sysreg.h - inline assembly used by it is incompatible with llvm.
66# But, there is no easy way to fix it, so just exclude it since it is
67# useless for BPF samples.
68$(obj)/%.o: $(src)/%.c
69 $(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) -I$(obj) \
70 -D__KERNEL__ -D__ASM_SYSREG_H -Wno-unused-value -Wno-pointer-sign \
71 -Wno-compare-distinct-pointer-types \
72 -Wno-gnu-variable-sized-type-not-at-end \
73 -Wno-address-of-packed-member -Wno-tautological-compare \
74 -Wno-unknown-warning-option \
75 -O2 -emit-llvm -c $< -o -| $(LLC) -march=bpf -filetype=obj -o $@
diff --git a/samples/sockmap/sockmap_kern.c b/samples/sockmap/sockmap_kern.c
deleted file mode 100644
index 9ff8bc5dc206..000000000000
--- a/samples/sockmap/sockmap_kern.c
+++ /dev/null
@@ -1,341 +0,0 @@
1/* Copyright (c) 2017 Covalent IO, Inc. http://covalent.io
2 *
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of version 2 of the GNU General Public
5 * License as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful, but
8 * WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * General Public License for more details.
11 */
12#include <uapi/linux/bpf.h>
13#include <uapi/linux/if_ether.h>
14#include <uapi/linux/if_packet.h>
15#include <uapi/linux/ip.h>
16#include "../../tools/testing/selftests/bpf/bpf_helpers.h"
17#include "../../tools/testing/selftests/bpf/bpf_endian.h"
18
19/* Sockmap sample program connects a client and a backend together
20 * using cgroups.
21 *
22 * client:X <---> frontend:80 client:X <---> backend:80
23 *
24 * For simplicity we hard code values here and bind 1:1. The hard
25 * coded values are part of the setup in sockmap.sh script that
26 * is associated with this BPF program.
27 *
28 * The bpf_printk is verbose and prints information as connections
29 * are established and verdicts are decided.
30 */
31
32#define bpf_printk(fmt, ...) \
33({ \
34 char ____fmt[] = fmt; \
35 bpf_trace_printk(____fmt, sizeof(____fmt), \
36 ##__VA_ARGS__); \
37})
38
39struct bpf_map_def SEC("maps") sock_map = {
40 .type = BPF_MAP_TYPE_SOCKMAP,
41 .key_size = sizeof(int),
42 .value_size = sizeof(int),
43 .max_entries = 20,
44};
45
46struct bpf_map_def SEC("maps") sock_map_txmsg = {
47 .type = BPF_MAP_TYPE_SOCKMAP,
48 .key_size = sizeof(int),
49 .value_size = sizeof(int),
50 .max_entries = 20,
51};
52
53struct bpf_map_def SEC("maps") sock_map_redir = {
54 .type = BPF_MAP_TYPE_SOCKMAP,
55 .key_size = sizeof(int),
56 .value_size = sizeof(int),
57 .max_entries = 20,
58};
59
60struct bpf_map_def SEC("maps") sock_apply_bytes = {
61 .type = BPF_MAP_TYPE_ARRAY,
62 .key_size = sizeof(int),
63 .value_size = sizeof(int),
64 .max_entries = 1
65};
66
67struct bpf_map_def SEC("maps") sock_cork_bytes = {
68 .type = BPF_MAP_TYPE_ARRAY,
69 .key_size = sizeof(int),
70 .value_size = sizeof(int),
71 .max_entries = 1
72};
73
74struct bpf_map_def SEC("maps") sock_pull_bytes = {
75 .type = BPF_MAP_TYPE_ARRAY,
76 .key_size = sizeof(int),
77 .value_size = sizeof(int),
78 .max_entries = 2
79};
80
81struct bpf_map_def SEC("maps") sock_redir_flags = {
82 .type = BPF_MAP_TYPE_ARRAY,
83 .key_size = sizeof(int),
84 .value_size = sizeof(int),
85 .max_entries = 1
86};
87
88struct bpf_map_def SEC("maps") sock_skb_opts = {
89 .type = BPF_MAP_TYPE_ARRAY,
90 .key_size = sizeof(int),
91 .value_size = sizeof(int),
92 .max_entries = 1
93};
94
95SEC("sk_skb1")
96int bpf_prog1(struct __sk_buff *skb)
97{
98 return skb->len;
99}
100
101SEC("sk_skb2")
102int bpf_prog2(struct __sk_buff *skb)
103{
104 __u32 lport = skb->local_port;
105 __u32 rport = skb->remote_port;
106 int len, *f, ret, zero = 0;
107 __u64 flags = 0;
108
109 if (lport == 10000)
110 ret = 10;
111 else
112 ret = 1;
113
114 len = (__u32)skb->data_end - (__u32)skb->data;
115 f = bpf_map_lookup_elem(&sock_skb_opts, &zero);
116 if (f && *f) {
117 ret = 3;
118 flags = *f;
119 }
120
121 bpf_printk("sk_skb2: redirect(%iB) flags=%i\n",
122 len, flags);
123 return bpf_sk_redirect_map(skb, &sock_map, ret, flags);
124}
125
126SEC("sockops")
127int bpf_sockmap(struct bpf_sock_ops *skops)
128{
129 __u32 lport, rport;
130 int op,