diff options
author | Alexei Starovoitov <ast@plumgrid.com> | 2014-09-26 03:16:57 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-09-26 15:05:14 -0400 |
commit | 99c55f7d47c0dc6fc64729f37bf435abf43f4c60 (patch) | |
tree | 12f09f26bee9813ae33cfc195582c41e94b2e4e9 /include/uapi | |
parent | 4a8e320c929991c9480a7b936512c57ea02d87b2 (diff) |
bpf: introduce BPF syscall and maps
BPF syscall is a multiplexor for a range of different operations on eBPF.
This patch introduces syscall with single command to create a map.
Next patch adds commands to access maps.
'maps' is a generic storage of different types for sharing data between kernel
and userspace.
Userspace example:
/* this syscall wrapper creates a map with given type and attributes
* and returns map_fd on success.
* use close(map_fd) to delete the map
*/
int bpf_create_map(enum bpf_map_type map_type, int key_size,
int value_size, int max_entries)
{
union bpf_attr attr = {
.map_type = map_type,
.key_size = key_size,
.value_size = value_size,
.max_entries = max_entries
};
return bpf(BPF_MAP_CREATE, &attr, sizeof(attr));
}
'union bpf_attr' is backwards compatible with future extensions.
More details in Documentation/networking/filter.txt and in manpage
Signed-off-by: Alexei Starovoitov <ast@plumgrid.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/uapi')
-rw-r--r-- | include/uapi/linux/bpf.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 479ed0b6be16..f58a10f9670c 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h | |||
@@ -62,4 +62,27 @@ struct bpf_insn { | |||
62 | __s32 imm; /* signed immediate constant */ | 62 | __s32 imm; /* signed immediate constant */ |
63 | }; | 63 | }; |
64 | 64 | ||
65 | /* BPF syscall commands */ | ||
66 | enum bpf_cmd { | ||
67 | /* create a map with given type and attributes | ||
68 | * fd = bpf(BPF_MAP_CREATE, union bpf_attr *, u32 size) | ||
69 | * returns fd or negative error | ||
70 | * map is deleted when fd is closed | ||
71 | */ | ||
72 | BPF_MAP_CREATE, | ||
73 | }; | ||
74 | |||
75 | enum bpf_map_type { | ||
76 | BPF_MAP_TYPE_UNSPEC, | ||
77 | }; | ||
78 | |||
79 | union bpf_attr { | ||
80 | struct { /* anonymous struct used by BPF_MAP_CREATE command */ | ||
81 | __u32 map_type; /* one of enum bpf_map_type */ | ||
82 | __u32 key_size; /* size of key in bytes */ | ||
83 | __u32 value_size; /* size of value in bytes */ | ||
84 | __u32 max_entries; /* max number of entries in a map */ | ||
85 | }; | ||
86 | } __attribute__((aligned(8))); | ||
87 | |||
65 | #endif /* _UAPI__LINUX_BPF_H__ */ | 88 | #endif /* _UAPI__LINUX_BPF_H__ */ |