aboutsummaryrefslogtreecommitdiffstats
path: root/include/uapi/linux/bpf.h
diff options
context:
space:
mode:
authorAlexei Starovoitov <ast@plumgrid.com>2014-11-13 20:36:44 -0500
committerDavid S. Miller <davem@davemloft.net>2014-11-18 13:43:25 -0500
commit3274f52073d88b62f3c5ace82ae9d48546232e72 (patch)
tree372cb492d099cebc3845ad471d810a78bdaa5084 /include/uapi/linux/bpf.h
parent1bbf148ddcbafca986c0a7e66fbd518725342d0a (diff)
bpf: add 'flags' attribute to BPF_MAP_UPDATE_ELEM command
the current meaning of BPF_MAP_UPDATE_ELEM syscall command is: either update existing map element or create a new one. Initially the plan was to add a new command to handle the case of 'create new element if it didn't exist', but 'flags' style looks cleaner and overall diff is much smaller (more code reused), so add 'flags' attribute to BPF_MAP_UPDATE_ELEM command with the following meaning: #define BPF_ANY 0 /* create new element or update existing */ #define BPF_NOEXIST 1 /* create new element if it didn't exist */ #define BPF_EXIST 2 /* update existing element */ bpf_update_elem(fd, key, value, BPF_NOEXIST) call can fail with EEXIST if element already exists. bpf_update_elem(fd, key, value, BPF_EXIST) can fail with ENOENT if element doesn't exist. Userspace will call it as: int bpf_update_elem(int fd, void *key, void *value, __u64 flags) { union bpf_attr attr = { .map_fd = fd, .key = ptr_to_u64(key), .value = ptr_to_u64(value), .flags = flags; }; return bpf(BPF_MAP_UPDATE_ELEM, &attr, sizeof(attr)); } First two bits of 'flags' are used to encode style of bpf_update_elem() command. Bits 2-63 are reserved for future use. Signed-off-by: Alexei Starovoitov <ast@plumgrid.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/uapi/linux/bpf.h')
-rw-r--r--include/uapi/linux/bpf.h8
1 files changed, 7 insertions, 1 deletions
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index d18316f9e9c4..3e9e1b77f29d 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -82,7 +82,7 @@ enum bpf_cmd {
82 82
83 /* create or update key/value pair in a given map 83 /* create or update key/value pair in a given map
84 * err = bpf(BPF_MAP_UPDATE_ELEM, union bpf_attr *attr, u32 size) 84 * err = bpf(BPF_MAP_UPDATE_ELEM, union bpf_attr *attr, u32 size)
85 * Using attr->map_fd, attr->key, attr->value 85 * Using attr->map_fd, attr->key, attr->value, attr->flags
86 * returns zero or negative error 86 * returns zero or negative error
87 */ 87 */
88 BPF_MAP_UPDATE_ELEM, 88 BPF_MAP_UPDATE_ELEM,
@@ -117,6 +117,11 @@ enum bpf_prog_type {
117 BPF_PROG_TYPE_UNSPEC, 117 BPF_PROG_TYPE_UNSPEC,
118}; 118};
119 119
120/* flags for BPF_MAP_UPDATE_ELEM command */
121#define BPF_ANY 0 /* create new element or update existing */
122#define BPF_NOEXIST 1 /* create new element if it didn't exist */
123#define BPF_EXIST 2 /* update existing element */
124
120union bpf_attr { 125union bpf_attr {
121 struct { /* anonymous struct used by BPF_MAP_CREATE command */ 126 struct { /* anonymous struct used by BPF_MAP_CREATE command */
122 __u32 map_type; /* one of enum bpf_map_type */ 127 __u32 map_type; /* one of enum bpf_map_type */
@@ -132,6 +137,7 @@ union bpf_attr {
132 __aligned_u64 value; 137 __aligned_u64 value;
133 __aligned_u64 next_key; 138 __aligned_u64 next_key;
134 }; 139 };
140 __u64 flags;
135 }; 141 };
136 142
137 struct { /* anonymous struct used by BPF_PROG_LOAD command */ 143 struct { /* anonymous struct used by BPF_PROG_LOAD command */