diff options
author | Wang Nan <wangnan0@huawei.com> | 2016-11-26 02:03:25 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-11-29 10:09:36 -0500 |
commit | 9742da0150788e6ea7796372c3e643f876a49741 (patch) | |
tree | c2a43ba594ed0d7a40e21d1da73fd4ec4a443edc /tools/lib/bpf/bpf.c | |
parent | aa07df6eb5061eed3f5d0820dc646d7f6ddface2 (diff) |
tools lib bpf: Add missing BPF functions
Add more BPF map operations to libbpf. Also add bpf_obj_{pin,get}(). They
can be used on not only BPF maps but also BPF programs.
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Cc: He Kuang <hekuang@huawei.com>
Cc: Joe Stringer <joe@ovn.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/20161126070354.141764-2-wangnan0@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/lib/bpf/bpf.c')
-rw-r--r-- | tools/lib/bpf/bpf.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c index 4212ed62235b..8143536b462a 100644 --- a/tools/lib/bpf/bpf.c +++ b/tools/lib/bpf/bpf.c | |||
@@ -110,3 +110,59 @@ int bpf_map_update_elem(int fd, void *key, void *value, | |||
110 | 110 | ||
111 | return sys_bpf(BPF_MAP_UPDATE_ELEM, &attr, sizeof(attr)); | 111 | return sys_bpf(BPF_MAP_UPDATE_ELEM, &attr, sizeof(attr)); |
112 | } | 112 | } |
113 | |||
114 | int bpf_map_lookup_elem(int fd, void *key, void *value) | ||
115 | { | ||
116 | union bpf_attr attr; | ||
117 | |||
118 | bzero(&attr, sizeof(attr)); | ||
119 | attr.map_fd = fd; | ||
120 | attr.key = ptr_to_u64(key); | ||
121 | attr.value = ptr_to_u64(value); | ||
122 | |||
123 | return sys_bpf(BPF_MAP_LOOKUP_ELEM, &attr, sizeof(attr)); | ||
124 | } | ||
125 | |||
126 | int bpf_map_delete_elem(int fd, void *key) | ||
127 | { | ||
128 | union bpf_attr attr; | ||
129 | |||
130 | bzero(&attr, sizeof(attr)); | ||
131 | attr.map_fd = fd; | ||
132 | attr.key = ptr_to_u64(key); | ||
133 | |||
134 | return sys_bpf(BPF_MAP_DELETE_ELEM, &attr, sizeof(attr)); | ||
135 | } | ||
136 | |||
137 | int bpf_map_get_next_key(int fd, void *key, void *next_key) | ||
138 | { | ||
139 | union bpf_attr attr; | ||
140 | |||
141 | bzero(&attr, sizeof(attr)); | ||
142 | attr.map_fd = fd; | ||
143 | attr.key = ptr_to_u64(key); | ||
144 | attr.next_key = ptr_to_u64(next_key); | ||
145 | |||
146 | return sys_bpf(BPF_MAP_GET_NEXT_KEY, &attr, sizeof(attr)); | ||
147 | } | ||
148 | |||
149 | int bpf_obj_pin(int fd, const char *pathname) | ||
150 | { | ||
151 | union bpf_attr attr; | ||
152 | |||
153 | bzero(&attr, sizeof(attr)); | ||
154 | attr.pathname = ptr_to_u64((void *)pathname); | ||
155 | attr.bpf_fd = fd; | ||
156 | |||
157 | return sys_bpf(BPF_OBJ_PIN, &attr, sizeof(attr)); | ||
158 | } | ||
159 | |||
160 | int bpf_obj_get(const char *pathname) | ||
161 | { | ||
162 | union bpf_attr attr; | ||
163 | |||
164 | bzero(&attr, sizeof(attr)); | ||
165 | attr.pathname = ptr_to_u64((void *)pathname); | ||
166 | |||
167 | return sys_bpf(BPF_OBJ_GET, &attr, sizeof(attr)); | ||
168 | } | ||