diff options
author | John Fastabend <john.fastabend@gmail.com> | 2017-08-16 01:33:32 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2017-08-16 14:27:53 -0400 |
commit | 69e8cc134bcbf0ccfcf852c400b8e6788d1d0038 (patch) | |
tree | 181f7fc9d1a8204f93aa705e2725e7c5b766610c /tools/lib | |
parent | 8a31db5615667956c513d205cfb06885c3ec6d0b (diff) |
bpf: sockmap sample program
This program binds a program to a cgroup and then matches hard
coded IP addresses and adds these to a sockmap.
This will receive messages from the backend and send them to
the client.
client:X <---> frontend:10000 client:X <---> backend:10001
To keep things simple this is only designed for 1:1 connections
using hard coded values. A more complete example would allow many
backends and clients.
To run,
# sockmap <cgroup2_dir>
Signed-off-by: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'tools/lib')
-rw-r--r-- | tools/lib/bpf/bpf.c | 14 | ||||
-rw-r--r-- | tools/lib/bpf/bpf.h | 4 |
2 files changed, 15 insertions, 3 deletions
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c index e5bbb090bf88..77660157a684 100644 --- a/tools/lib/bpf/bpf.c +++ b/tools/lib/bpf/bpf.c | |||
@@ -211,20 +211,28 @@ int bpf_obj_get(const char *pathname) | |||
211 | return sys_bpf(BPF_OBJ_GET, &attr, sizeof(attr)); | 211 | return sys_bpf(BPF_OBJ_GET, &attr, sizeof(attr)); |
212 | } | 212 | } |
213 | 213 | ||
214 | int bpf_prog_attach(int prog_fd, int target_fd, enum bpf_attach_type type, | 214 | int __bpf_prog_attach(int prog_fd1, int prog_fd2, int target_fd, |
215 | unsigned int flags) | 215 | enum bpf_attach_type type, |
216 | unsigned int flags) | ||
216 | { | 217 | { |
217 | union bpf_attr attr; | 218 | union bpf_attr attr; |
218 | 219 | ||
219 | bzero(&attr, sizeof(attr)); | 220 | bzero(&attr, sizeof(attr)); |
220 | attr.target_fd = target_fd; | 221 | attr.target_fd = target_fd; |
221 | attr.attach_bpf_fd = prog_fd; | 222 | attr.attach_bpf_fd = prog_fd1; |
223 | attr.attach_bpf_fd2 = prog_fd2; | ||
222 | attr.attach_type = type; | 224 | attr.attach_type = type; |
223 | attr.attach_flags = flags; | 225 | attr.attach_flags = flags; |
224 | 226 | ||
225 | return sys_bpf(BPF_PROG_ATTACH, &attr, sizeof(attr)); | 227 | return sys_bpf(BPF_PROG_ATTACH, &attr, sizeof(attr)); |
226 | } | 228 | } |
227 | 229 | ||
230 | int bpf_prog_attach(int prog_fd, int target_fd, enum bpf_attach_type type, | ||
231 | unsigned int flags) | ||
232 | { | ||
233 | return __bpf_prog_attach(prog_fd, 0, target_fd, type, flags); | ||
234 | } | ||
235 | |||
228 | int bpf_prog_detach(int target_fd, enum bpf_attach_type type) | 236 | int bpf_prog_detach(int target_fd, enum bpf_attach_type type) |
229 | { | 237 | { |
230 | union bpf_attr attr; | 238 | union bpf_attr attr; |
diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h index 418c86e69bcb..eaee585c1cea 100644 --- a/tools/lib/bpf/bpf.h +++ b/tools/lib/bpf/bpf.h | |||
@@ -50,6 +50,10 @@ int bpf_obj_pin(int fd, const char *pathname); | |||
50 | int bpf_obj_get(const char *pathname); | 50 | int bpf_obj_get(const char *pathname); |
51 | int bpf_prog_attach(int prog_fd, int attachable_fd, enum bpf_attach_type type, | 51 | int bpf_prog_attach(int prog_fd, int attachable_fd, enum bpf_attach_type type, |
52 | unsigned int flags); | 52 | unsigned int flags); |
53 | int __bpf_prog_attach(int prog1, int prog2, | ||
54 | int attachable_fd, | ||
55 | enum bpf_attach_type type, | ||
56 | unsigned int flags); | ||
53 | int bpf_prog_detach(int attachable_fd, enum bpf_attach_type type); | 57 | int bpf_prog_detach(int attachable_fd, enum bpf_attach_type type); |
54 | int bpf_prog_test_run(int prog_fd, int repeat, void *data, __u32 size, | 58 | int bpf_prog_test_run(int prog_fd, int repeat, void *data, __u32 size, |
55 | void *data_out, __u32 *size_out, __u32 *retval, | 59 | void *data_out, __u32 *size_out, __u32 *retval, |