diff options
author | John Fastabend <john.fastabend@gmail.com> | 2017-08-28 10:10:04 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2017-08-28 14:13:21 -0400 |
commit | 464bc0fd6273d518aee79fbd37211dd9bc35d863 (patch) | |
tree | 32280f0588583c50f6712de2ad0e3af886dcaadd /tools/lib/bpf/bpf.c | |
parent | 901c5d2fbfcdc5d1d49a7a835b9ce9be5eee6393 (diff) |
bpf: convert sockmap field attach_bpf_fd2 to type
In the initial sockmap API we provided strparser and verdict programs
using a single attach command by extending the attach API with a the
attach_bpf_fd2 field.
However, if we add other programs in the future we will be adding a
field for every new possible type, attach_bpf_fd(3,4,..). This
seems a bit clumsy for an API. So lets push the programs using two
new type fields.
BPF_SK_SKB_STREAM_PARSER
BPF_SK_SKB_STREAM_VERDICT
This has the advantage of having a readable name and can easily be
extended in the future.
Updates to samples and sockmap included here also generalize tests
slightly to support upcoming patch for multiple map support.
Signed-off-by: John Fastabend <john.fastabend@gmail.com>
Fixes: 174a79ff9515 ("bpf: sockmap with sk redirect support")
Suggested-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'tools/lib/bpf/bpf.c')
-rw-r--r-- | tools/lib/bpf/bpf.c | 14 |
1 files changed, 3 insertions, 11 deletions
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c index a0717610b116..1d6907d379c9 100644 --- a/tools/lib/bpf/bpf.c +++ b/tools/lib/bpf/bpf.c | |||
@@ -235,28 +235,20 @@ int bpf_obj_get(const char *pathname) | |||
235 | return sys_bpf(BPF_OBJ_GET, &attr, sizeof(attr)); | 235 | return sys_bpf(BPF_OBJ_GET, &attr, sizeof(attr)); |
236 | } | 236 | } |
237 | 237 | ||
238 | int __bpf_prog_attach(int prog_fd1, int prog_fd2, int target_fd, | 238 | int bpf_prog_attach(int prog_fd, int target_fd, enum bpf_attach_type type, |
239 | enum bpf_attach_type type, | 239 | unsigned int flags) |
240 | unsigned int flags) | ||
241 | { | 240 | { |
242 | union bpf_attr attr; | 241 | union bpf_attr attr; |
243 | 242 | ||
244 | bzero(&attr, sizeof(attr)); | 243 | bzero(&attr, sizeof(attr)); |
245 | attr.target_fd = target_fd; | 244 | attr.target_fd = target_fd; |
246 | attr.attach_bpf_fd = prog_fd1; | 245 | attr.attach_bpf_fd = prog_fd; |
247 | attr.attach_bpf_fd2 = prog_fd2; | ||
248 | attr.attach_type = type; | 246 | attr.attach_type = type; |
249 | attr.attach_flags = flags; | 247 | attr.attach_flags = flags; |
250 | 248 | ||
251 | return sys_bpf(BPF_PROG_ATTACH, &attr, sizeof(attr)); | 249 | return sys_bpf(BPF_PROG_ATTACH, &attr, sizeof(attr)); |
252 | } | 250 | } |
253 | 251 | ||
254 | int bpf_prog_attach(int prog_fd, int target_fd, enum bpf_attach_type type, | ||
255 | unsigned int flags) | ||
256 | { | ||
257 | return __bpf_prog_attach(prog_fd, 0, target_fd, type, flags); | ||
258 | } | ||
259 | |||
260 | int bpf_prog_detach(int target_fd, enum bpf_attach_type type) | 252 | int bpf_prog_detach(int target_fd, enum bpf_attach_type type) |
261 | { | 253 | { |
262 | union bpf_attr attr; | 254 | union bpf_attr attr; |