Jakub Kicinski | 02ff58d | 2018-12-12 19:59:25 -0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) |
| 2 | /* Copyright (C) 2017-2018 Netronome Systems, Inc. */ |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 3 | |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 4 | #include <assert.h> |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 5 | #include <errno.h> |
| 6 | #include <fcntl.h> |
Okash Khawaja | 2d3feca | 2018-07-13 21:57:04 -0700 | [diff] [blame] | 7 | #include <linux/err.h> |
Yonghong Song | 573b3aa | 2018-07-30 08:49:03 -0700 | [diff] [blame] | 8 | #include <linux/kernel.h> |
Jakub Kicinski | 0b592b5a | 2018-10-15 16:30:36 -0700 | [diff] [blame] | 9 | #include <net/if.h> |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 10 | #include <stdbool.h> |
| 11 | #include <stdio.h> |
| 12 | #include <stdlib.h> |
| 13 | #include <string.h> |
| 14 | #include <unistd.h> |
| 15 | #include <sys/types.h> |
| 16 | #include <sys/stat.h> |
| 17 | |
| 18 | #include <bpf.h> |
| 19 | |
Okash Khawaja | 2d3feca | 2018-07-13 21:57:04 -0700 | [diff] [blame] | 20 | #include "btf.h" |
| 21 | #include "json_writer.h" |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 22 | #include "main.h" |
| 23 | |
| 24 | static const char * const map_type_name[] = { |
David Calavera | ffac28f | 2018-11-23 15:58:39 -0800 | [diff] [blame] | 25 | [BPF_MAP_TYPE_UNSPEC] = "unspec", |
| 26 | [BPF_MAP_TYPE_HASH] = "hash", |
| 27 | [BPF_MAP_TYPE_ARRAY] = "array", |
| 28 | [BPF_MAP_TYPE_PROG_ARRAY] = "prog_array", |
| 29 | [BPF_MAP_TYPE_PERF_EVENT_ARRAY] = "perf_event_array", |
| 30 | [BPF_MAP_TYPE_PERCPU_HASH] = "percpu_hash", |
| 31 | [BPF_MAP_TYPE_PERCPU_ARRAY] = "percpu_array", |
| 32 | [BPF_MAP_TYPE_STACK_TRACE] = "stack_trace", |
| 33 | [BPF_MAP_TYPE_CGROUP_ARRAY] = "cgroup_array", |
| 34 | [BPF_MAP_TYPE_LRU_HASH] = "lru_hash", |
| 35 | [BPF_MAP_TYPE_LRU_PERCPU_HASH] = "lru_percpu_hash", |
| 36 | [BPF_MAP_TYPE_LPM_TRIE] = "lpm_trie", |
| 37 | [BPF_MAP_TYPE_ARRAY_OF_MAPS] = "array_of_maps", |
| 38 | [BPF_MAP_TYPE_HASH_OF_MAPS] = "hash_of_maps", |
| 39 | [BPF_MAP_TYPE_DEVMAP] = "devmap", |
| 40 | [BPF_MAP_TYPE_SOCKMAP] = "sockmap", |
| 41 | [BPF_MAP_TYPE_CPUMAP] = "cpumap", |
| 42 | [BPF_MAP_TYPE_XSKMAP] = "xskmap", |
| 43 | [BPF_MAP_TYPE_SOCKHASH] = "sockhash", |
| 44 | [BPF_MAP_TYPE_CGROUP_STORAGE] = "cgroup_storage", |
| 45 | [BPF_MAP_TYPE_REUSEPORT_SOCKARRAY] = "reuseport_sockarray", |
Roman Gushchin | e548709 | 2018-09-28 14:45:51 +0000 | [diff] [blame] | 46 | [BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE] = "percpu_cgroup_storage", |
David Calavera | ffac28f | 2018-11-23 15:58:39 -0800 | [diff] [blame] | 47 | [BPF_MAP_TYPE_QUEUE] = "queue", |
| 48 | [BPF_MAP_TYPE_STACK] = "stack", |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 49 | }; |
| 50 | |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 51 | static bool map_is_per_cpu(__u32 type) |
| 52 | { |
| 53 | return type == BPF_MAP_TYPE_PERCPU_HASH || |
| 54 | type == BPF_MAP_TYPE_PERCPU_ARRAY || |
Roman Gushchin | e548709 | 2018-09-28 14:45:51 +0000 | [diff] [blame] | 55 | type == BPF_MAP_TYPE_LRU_PERCPU_HASH || |
| 56 | type == BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE; |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | static bool map_is_map_of_maps(__u32 type) |
| 60 | { |
| 61 | return type == BPF_MAP_TYPE_ARRAY_OF_MAPS || |
| 62 | type == BPF_MAP_TYPE_HASH_OF_MAPS; |
| 63 | } |
| 64 | |
| 65 | static bool map_is_map_of_progs(__u32 type) |
| 66 | { |
| 67 | return type == BPF_MAP_TYPE_PROG_ARRAY; |
| 68 | } |
| 69 | |
Jakub Kicinski | 0b592b5a | 2018-10-15 16:30:36 -0700 | [diff] [blame] | 70 | static int map_type_from_str(const char *type) |
| 71 | { |
| 72 | unsigned int i; |
| 73 | |
| 74 | for (i = 0; i < ARRAY_SIZE(map_type_name); i++) |
| 75 | /* Don't allow prefixing in case of possible future shadowing */ |
| 76 | if (map_type_name[i] && !strcmp(map_type_name[i], type)) |
| 77 | return i; |
| 78 | return -1; |
| 79 | } |
| 80 | |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 81 | static void *alloc_value(struct bpf_map_info *info) |
| 82 | { |
| 83 | if (map_is_per_cpu(info->type)) |
Yonghong Song | 573b3aa | 2018-07-30 08:49:03 -0700 | [diff] [blame] | 84 | return malloc(round_up(info->value_size, 8) * |
| 85 | get_possible_cpus()); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 86 | else |
| 87 | return malloc(info->value_size); |
| 88 | } |
| 89 | |
Jakub Kicinski | 3ff5a4d | 2018-07-10 14:43:07 -0700 | [diff] [blame] | 90 | int map_parse_fd(int *argc, char ***argv) |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 91 | { |
| 92 | int fd; |
| 93 | |
| 94 | if (is_prefix(**argv, "id")) { |
| 95 | unsigned int id; |
| 96 | char *endptr; |
| 97 | |
| 98 | NEXT_ARGP(); |
| 99 | |
| 100 | id = strtoul(**argv, &endptr, 0); |
| 101 | if (*endptr) { |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 102 | p_err("can't parse %s as ID", **argv); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 103 | return -1; |
| 104 | } |
| 105 | NEXT_ARGP(); |
| 106 | |
| 107 | fd = bpf_map_get_fd_by_id(id); |
| 108 | if (fd < 0) |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 109 | p_err("get map by id (%u): %s", id, strerror(errno)); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 110 | return fd; |
| 111 | } else if (is_prefix(**argv, "pinned")) { |
| 112 | char *path; |
| 113 | |
| 114 | NEXT_ARGP(); |
| 115 | |
| 116 | path = **argv; |
| 117 | NEXT_ARGP(); |
| 118 | |
| 119 | return open_obj_pinned_any(path, BPF_OBJ_MAP); |
| 120 | } |
| 121 | |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 122 | p_err("expected 'id' or 'pinned', got: '%s'?", **argv); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 123 | return -1; |
| 124 | } |
| 125 | |
Jakub Kicinski | f412eed | 2018-05-03 18:37:16 -0700 | [diff] [blame] | 126 | int map_parse_fd_and_info(int *argc, char ***argv, void *info, __u32 *info_len) |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 127 | { |
| 128 | int err; |
| 129 | int fd; |
| 130 | |
| 131 | fd = map_parse_fd(argc, argv); |
| 132 | if (fd < 0) |
| 133 | return -1; |
| 134 | |
| 135 | err = bpf_obj_get_info_by_fd(fd, info, info_len); |
| 136 | if (err) { |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 137 | p_err("can't get map info: %s", strerror(errno)); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 138 | close(fd); |
| 139 | return err; |
| 140 | } |
| 141 | |
| 142 | return fd; |
| 143 | } |
| 144 | |
Okash Khawaja | 2d3feca | 2018-07-13 21:57:04 -0700 | [diff] [blame] | 145 | static int do_dump_btf(const struct btf_dumper *d, |
| 146 | struct bpf_map_info *map_info, void *key, |
| 147 | void *value) |
| 148 | { |
| 149 | int ret; |
| 150 | |
| 151 | /* start of key-value pair */ |
| 152 | jsonw_start_object(d->jw); |
| 153 | |
| 154 | jsonw_name(d->jw, "key"); |
| 155 | |
| 156 | ret = btf_dumper_type(d, map_info->btf_key_type_id, key); |
| 157 | if (ret) |
| 158 | goto err_end_obj; |
| 159 | |
Yonghong Song | 1a86ad8 | 2018-08-29 14:43:15 -0700 | [diff] [blame] | 160 | if (!map_is_per_cpu(map_info->type)) { |
| 161 | jsonw_name(d->jw, "value"); |
| 162 | ret = btf_dumper_type(d, map_info->btf_value_type_id, value); |
| 163 | } else { |
| 164 | unsigned int i, n, step; |
Okash Khawaja | 2d3feca | 2018-07-13 21:57:04 -0700 | [diff] [blame] | 165 | |
Yonghong Song | 1a86ad8 | 2018-08-29 14:43:15 -0700 | [diff] [blame] | 166 | jsonw_name(d->jw, "values"); |
| 167 | jsonw_start_array(d->jw); |
| 168 | n = get_possible_cpus(); |
| 169 | step = round_up(map_info->value_size, 8); |
| 170 | for (i = 0; i < n; i++) { |
| 171 | jsonw_start_object(d->jw); |
| 172 | jsonw_int_field(d->jw, "cpu", i); |
| 173 | jsonw_name(d->jw, "value"); |
| 174 | ret = btf_dumper_type(d, map_info->btf_value_type_id, |
| 175 | value + i * step); |
| 176 | jsonw_end_object(d->jw); |
| 177 | if (ret) |
| 178 | break; |
| 179 | } |
| 180 | jsonw_end_array(d->jw); |
| 181 | } |
Okash Khawaja | 2d3feca | 2018-07-13 21:57:04 -0700 | [diff] [blame] | 182 | |
| 183 | err_end_obj: |
| 184 | /* end of key-value pair */ |
| 185 | jsonw_end_object(d->jw); |
| 186 | |
| 187 | return ret; |
| 188 | } |
| 189 | |
Okash Khawaja | 2d3feca | 2018-07-13 21:57:04 -0700 | [diff] [blame] | 190 | static json_writer_t *get_btf_writer(void) |
| 191 | { |
| 192 | json_writer_t *jw = jsonw_new(stdout); |
| 193 | |
| 194 | if (!jw) |
| 195 | return NULL; |
| 196 | jsonw_pretty(jw, true); |
| 197 | |
| 198 | return jw; |
| 199 | } |
| 200 | |
Quentin Monnet | 831a0aa | 2017-10-23 09:24:11 -0700 | [diff] [blame] | 201 | static void print_entry_json(struct bpf_map_info *info, unsigned char *key, |
Okash Khawaja | 2d3feca | 2018-07-13 21:57:04 -0700 | [diff] [blame] | 202 | unsigned char *value, struct btf *btf) |
Quentin Monnet | 831a0aa | 2017-10-23 09:24:11 -0700 | [diff] [blame] | 203 | { |
| 204 | jsonw_start_object(json_wtr); |
| 205 | |
| 206 | if (!map_is_per_cpu(info->type)) { |
| 207 | jsonw_name(json_wtr, "key"); |
| 208 | print_hex_data_json(key, info->key_size); |
| 209 | jsonw_name(json_wtr, "value"); |
| 210 | print_hex_data_json(value, info->value_size); |
Okash Khawaja | 2d3feca | 2018-07-13 21:57:04 -0700 | [diff] [blame] | 211 | if (btf) { |
| 212 | struct btf_dumper d = { |
| 213 | .btf = btf, |
| 214 | .jw = json_wtr, |
| 215 | .is_plain_text = false, |
| 216 | }; |
| 217 | |
| 218 | jsonw_name(json_wtr, "formatted"); |
| 219 | do_dump_btf(&d, info, key, value); |
| 220 | } |
Quentin Monnet | 831a0aa | 2017-10-23 09:24:11 -0700 | [diff] [blame] | 221 | } else { |
Yonghong Song | 573b3aa | 2018-07-30 08:49:03 -0700 | [diff] [blame] | 222 | unsigned int i, n, step; |
Quentin Monnet | 831a0aa | 2017-10-23 09:24:11 -0700 | [diff] [blame] | 223 | |
| 224 | n = get_possible_cpus(); |
Yonghong Song | 573b3aa | 2018-07-30 08:49:03 -0700 | [diff] [blame] | 225 | step = round_up(info->value_size, 8); |
Quentin Monnet | 831a0aa | 2017-10-23 09:24:11 -0700 | [diff] [blame] | 226 | |
| 227 | jsonw_name(json_wtr, "key"); |
| 228 | print_hex_data_json(key, info->key_size); |
| 229 | |
| 230 | jsonw_name(json_wtr, "values"); |
| 231 | jsonw_start_array(json_wtr); |
| 232 | for (i = 0; i < n; i++) { |
| 233 | jsonw_start_object(json_wtr); |
| 234 | |
| 235 | jsonw_int_field(json_wtr, "cpu", i); |
| 236 | |
| 237 | jsonw_name(json_wtr, "value"); |
Yonghong Song | 573b3aa | 2018-07-30 08:49:03 -0700 | [diff] [blame] | 238 | print_hex_data_json(value + i * step, |
Quentin Monnet | 831a0aa | 2017-10-23 09:24:11 -0700 | [diff] [blame] | 239 | info->value_size); |
| 240 | |
| 241 | jsonw_end_object(json_wtr); |
| 242 | } |
| 243 | jsonw_end_array(json_wtr); |
Yonghong Song | 1a86ad8 | 2018-08-29 14:43:15 -0700 | [diff] [blame] | 244 | if (btf) { |
| 245 | struct btf_dumper d = { |
| 246 | .btf = btf, |
| 247 | .jw = json_wtr, |
| 248 | .is_plain_text = false, |
| 249 | }; |
| 250 | |
| 251 | jsonw_name(json_wtr, "formatted"); |
| 252 | do_dump_btf(&d, info, key, value); |
| 253 | } |
Quentin Monnet | 831a0aa | 2017-10-23 09:24:11 -0700 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | jsonw_end_object(json_wtr); |
| 257 | } |
| 258 | |
Prashant Bhole | 8ec92dc | 2018-10-09 10:04:52 +0900 | [diff] [blame] | 259 | static void print_entry_error(struct bpf_map_info *info, unsigned char *key, |
| 260 | const char *value) |
| 261 | { |
| 262 | int value_size = strlen(value); |
| 263 | bool single_line, break_names; |
| 264 | |
| 265 | break_names = info->key_size > 16 || value_size > 16; |
| 266 | single_line = info->key_size + value_size <= 24 && !break_names; |
| 267 | |
| 268 | printf("key:%c", break_names ? '\n' : ' '); |
| 269 | fprint_hex(stdout, key, info->key_size, " "); |
| 270 | |
| 271 | printf(single_line ? " " : "\n"); |
| 272 | |
| 273 | printf("value:%c%s", break_names ? '\n' : ' ', value); |
| 274 | |
| 275 | printf("\n"); |
| 276 | } |
| 277 | |
Quentin Monnet | 831a0aa | 2017-10-23 09:24:11 -0700 | [diff] [blame] | 278 | static void print_entry_plain(struct bpf_map_info *info, unsigned char *key, |
| 279 | unsigned char *value) |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 280 | { |
| 281 | if (!map_is_per_cpu(info->type)) { |
| 282 | bool single_line, break_names; |
| 283 | |
| 284 | break_names = info->key_size > 16 || info->value_size > 16; |
| 285 | single_line = info->key_size + info->value_size <= 24 && |
| 286 | !break_names; |
| 287 | |
Stanislav Fomichev | 04a5d32 | 2019-01-16 11:10:01 -0800 | [diff] [blame] | 288 | if (info->key_size) { |
| 289 | printf("key:%c", break_names ? '\n' : ' '); |
| 290 | fprint_hex(stdout, key, info->key_size, " "); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 291 | |
Stanislav Fomichev | 04a5d32 | 2019-01-16 11:10:01 -0800 | [diff] [blame] | 292 | printf(single_line ? " " : "\n"); |
| 293 | } |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 294 | |
Stanislav Fomichev | 04a5d32 | 2019-01-16 11:10:01 -0800 | [diff] [blame] | 295 | if (info->value_size) { |
| 296 | printf("value:%c", break_names ? '\n' : ' '); |
| 297 | if (value) |
| 298 | fprint_hex(stdout, value, info->value_size, |
| 299 | " "); |
| 300 | else |
| 301 | printf("<no entry>"); |
| 302 | } |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 303 | |
| 304 | printf("\n"); |
| 305 | } else { |
Yonghong Song | 573b3aa | 2018-07-30 08:49:03 -0700 | [diff] [blame] | 306 | unsigned int i, n, step; |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 307 | |
| 308 | n = get_possible_cpus(); |
Yonghong Song | 573b3aa | 2018-07-30 08:49:03 -0700 | [diff] [blame] | 309 | step = round_up(info->value_size, 8); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 310 | |
Stanislav Fomichev | 04a5d32 | 2019-01-16 11:10:01 -0800 | [diff] [blame] | 311 | if (info->key_size) { |
| 312 | printf("key:\n"); |
| 313 | fprint_hex(stdout, key, info->key_size, " "); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 314 | printf("\n"); |
| 315 | } |
Stanislav Fomichev | 04a5d32 | 2019-01-16 11:10:01 -0800 | [diff] [blame] | 316 | if (info->value_size) { |
| 317 | for (i = 0; i < n; i++) { |
| 318 | printf("value (CPU %02d):%c", |
| 319 | i, info->value_size > 16 ? '\n' : ' '); |
| 320 | if (value) |
| 321 | fprint_hex(stdout, value + i * step, |
| 322 | info->value_size, " "); |
| 323 | else |
| 324 | printf("<no entry>"); |
| 325 | printf("\n"); |
| 326 | } |
| 327 | } |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 328 | } |
| 329 | } |
| 330 | |
| 331 | static char **parse_bytes(char **argv, const char *name, unsigned char *val, |
| 332 | unsigned int n) |
| 333 | { |
Quentin Monnet | 0c90f22 | 2018-04-17 19:46:34 -0700 | [diff] [blame] | 334 | unsigned int i = 0, base = 0; |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 335 | char *endptr; |
| 336 | |
Quentin Monnet | 0c90f22 | 2018-04-17 19:46:34 -0700 | [diff] [blame] | 337 | if (is_prefix(*argv, "hex")) { |
| 338 | base = 16; |
| 339 | argv++; |
| 340 | } |
| 341 | |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 342 | while (i < n && argv[i]) { |
Quentin Monnet | 0c90f22 | 2018-04-17 19:46:34 -0700 | [diff] [blame] | 343 | val[i] = strtoul(argv[i], &endptr, base); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 344 | if (*endptr) { |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 345 | p_err("error parsing byte: %s", argv[i]); |
Quentin Monnet | d9c0b48 | 2017-10-19 15:46:23 -0700 | [diff] [blame] | 346 | return NULL; |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 347 | } |
| 348 | i++; |
| 349 | } |
| 350 | |
| 351 | if (i != n) { |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 352 | p_err("%s expected %d bytes got %d", name, n, i); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 353 | return NULL; |
| 354 | } |
| 355 | |
| 356 | return argv + i; |
| 357 | } |
| 358 | |
| 359 | static int parse_elem(char **argv, struct bpf_map_info *info, |
| 360 | void *key, void *value, __u32 key_size, __u32 value_size, |
| 361 | __u32 *flags, __u32 **value_fd) |
| 362 | { |
| 363 | if (!*argv) { |
| 364 | if (!key && !value) |
| 365 | return 0; |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 366 | p_err("did not find %s", key ? "key" : "value"); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 367 | return -1; |
| 368 | } |
| 369 | |
| 370 | if (is_prefix(*argv, "key")) { |
| 371 | if (!key) { |
| 372 | if (key_size) |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 373 | p_err("duplicate key"); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 374 | else |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 375 | p_err("unnecessary key"); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 376 | return -1; |
| 377 | } |
| 378 | |
| 379 | argv = parse_bytes(argv + 1, "key", key, key_size); |
| 380 | if (!argv) |
| 381 | return -1; |
| 382 | |
| 383 | return parse_elem(argv, info, NULL, value, key_size, value_size, |
| 384 | flags, value_fd); |
| 385 | } else if (is_prefix(*argv, "value")) { |
| 386 | int fd; |
| 387 | |
| 388 | if (!value) { |
| 389 | if (value_size) |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 390 | p_err("duplicate value"); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 391 | else |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 392 | p_err("unnecessary value"); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 393 | return -1; |
| 394 | } |
| 395 | |
| 396 | argv++; |
| 397 | |
| 398 | if (map_is_map_of_maps(info->type)) { |
| 399 | int argc = 2; |
| 400 | |
| 401 | if (value_size != 4) { |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 402 | p_err("value smaller than 4B for map in map?"); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 403 | return -1; |
| 404 | } |
| 405 | if (!argv[0] || !argv[1]) { |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 406 | p_err("not enough value arguments for map in map"); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 407 | return -1; |
| 408 | } |
| 409 | |
| 410 | fd = map_parse_fd(&argc, &argv); |
| 411 | if (fd < 0) |
| 412 | return -1; |
| 413 | |
| 414 | *value_fd = value; |
| 415 | **value_fd = fd; |
| 416 | } else if (map_is_map_of_progs(info->type)) { |
| 417 | int argc = 2; |
| 418 | |
| 419 | if (value_size != 4) { |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 420 | p_err("value smaller than 4B for map of progs?"); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 421 | return -1; |
| 422 | } |
| 423 | if (!argv[0] || !argv[1]) { |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 424 | p_err("not enough value arguments for map of progs"); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 425 | return -1; |
| 426 | } |
| 427 | |
| 428 | fd = prog_parse_fd(&argc, &argv); |
| 429 | if (fd < 0) |
| 430 | return -1; |
| 431 | |
| 432 | *value_fd = value; |
| 433 | **value_fd = fd; |
| 434 | } else { |
| 435 | argv = parse_bytes(argv, "value", value, value_size); |
| 436 | if (!argv) |
| 437 | return -1; |
| 438 | } |
| 439 | |
| 440 | return parse_elem(argv, info, key, NULL, key_size, value_size, |
| 441 | flags, NULL); |
| 442 | } else if (is_prefix(*argv, "any") || is_prefix(*argv, "noexist") || |
| 443 | is_prefix(*argv, "exist")) { |
| 444 | if (!flags) { |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 445 | p_err("flags specified multiple times: %s", *argv); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 446 | return -1; |
| 447 | } |
| 448 | |
| 449 | if (is_prefix(*argv, "any")) |
| 450 | *flags = BPF_ANY; |
| 451 | else if (is_prefix(*argv, "noexist")) |
| 452 | *flags = BPF_NOEXIST; |
| 453 | else if (is_prefix(*argv, "exist")) |
| 454 | *flags = BPF_EXIST; |
| 455 | |
| 456 | return parse_elem(argv + 1, info, key, value, key_size, |
| 457 | value_size, NULL, value_fd); |
| 458 | } |
| 459 | |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 460 | p_err("expected key or value, got: %s", *argv); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 461 | return -1; |
| 462 | } |
| 463 | |
Quentin Monnet | 831a0aa | 2017-10-23 09:24:11 -0700 | [diff] [blame] | 464 | static int show_map_close_json(int fd, struct bpf_map_info *info) |
| 465 | { |
| 466 | char *memlock; |
| 467 | |
| 468 | memlock = get_fdinfo(fd, "memlock"); |
Quentin Monnet | 831a0aa | 2017-10-23 09:24:11 -0700 | [diff] [blame] | 469 | |
| 470 | jsonw_start_object(json_wtr); |
| 471 | |
| 472 | jsonw_uint_field(json_wtr, "id", info->id); |
| 473 | if (info->type < ARRAY_SIZE(map_type_name)) |
| 474 | jsonw_string_field(json_wtr, "type", |
| 475 | map_type_name[info->type]); |
| 476 | else |
| 477 | jsonw_uint_field(json_wtr, "type", info->type); |
| 478 | |
| 479 | if (*info->name) |
| 480 | jsonw_string_field(json_wtr, "name", info->name); |
| 481 | |
| 482 | jsonw_name(json_wtr, "flags"); |
Jakub Kicinski | 4b6eca9 | 2018-03-23 19:45:12 -0700 | [diff] [blame] | 483 | jsonw_printf(json_wtr, "%d", info->map_flags); |
Jakub Kicinski | 064a07c | 2018-01-17 19:13:29 -0800 | [diff] [blame] | 484 | |
| 485 | print_dev_json(info->ifindex, info->netns_dev, info->netns_ino); |
| 486 | |
Quentin Monnet | 831a0aa | 2017-10-23 09:24:11 -0700 | [diff] [blame] | 487 | jsonw_uint_field(json_wtr, "bytes_key", info->key_size); |
| 488 | jsonw_uint_field(json_wtr, "bytes_value", info->value_size); |
| 489 | jsonw_uint_field(json_wtr, "max_entries", info->max_entries); |
| 490 | |
| 491 | if (memlock) |
| 492 | jsonw_int_field(json_wtr, "bytes_memlock", atoi(memlock)); |
| 493 | free(memlock); |
| 494 | |
Quentin Monnet | 99a44bef | 2018-11-30 16:25:48 +0000 | [diff] [blame] | 495 | if (info->type == BPF_MAP_TYPE_PROG_ARRAY) { |
| 496 | char *owner_prog_type = get_fdinfo(fd, "owner_prog_type"); |
| 497 | char *owner_jited = get_fdinfo(fd, "owner_jited"); |
| 498 | |
| 499 | if (owner_prog_type) { |
| 500 | unsigned int prog_type = atoi(owner_prog_type); |
| 501 | |
| 502 | if (prog_type < ARRAY_SIZE(prog_type_name)) |
| 503 | jsonw_string_field(json_wtr, "owner_prog_type", |
| 504 | prog_type_name[prog_type]); |
| 505 | else |
| 506 | jsonw_uint_field(json_wtr, "owner_prog_type", |
| 507 | prog_type); |
| 508 | } |
| 509 | if (atoi(owner_jited)) |
| 510 | jsonw_bool_field(json_wtr, "owner_jited", true); |
| 511 | else |
| 512 | jsonw_bool_field(json_wtr, "owner_jited", false); |
| 513 | |
| 514 | free(owner_prog_type); |
| 515 | free(owner_jited); |
| 516 | } |
| 517 | close(fd); |
| 518 | |
Prashant Bhole | 4990f1f | 2017-11-08 13:55:48 +0900 | [diff] [blame] | 519 | if (!hash_empty(map_table.table)) { |
| 520 | struct pinned_obj *obj; |
| 521 | |
| 522 | jsonw_name(json_wtr, "pinned"); |
| 523 | jsonw_start_array(json_wtr); |
| 524 | hash_for_each_possible(map_table.table, obj, hash, info->id) { |
| 525 | if (obj->id == info->id) |
| 526 | jsonw_string(json_wtr, obj->path); |
| 527 | } |
| 528 | jsonw_end_array(json_wtr); |
| 529 | } |
| 530 | |
Quentin Monnet | 831a0aa | 2017-10-23 09:24:11 -0700 | [diff] [blame] | 531 | jsonw_end_object(json_wtr); |
| 532 | |
| 533 | return 0; |
| 534 | } |
| 535 | |
| 536 | static int show_map_close_plain(int fd, struct bpf_map_info *info) |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 537 | { |
| 538 | char *memlock; |
| 539 | |
| 540 | memlock = get_fdinfo(fd, "memlock"); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 541 | |
| 542 | printf("%u: ", info->id); |
| 543 | if (info->type < ARRAY_SIZE(map_type_name)) |
| 544 | printf("%s ", map_type_name[info->type]); |
| 545 | else |
| 546 | printf("type %u ", info->type); |
| 547 | |
| 548 | if (*info->name) |
| 549 | printf("name %s ", info->name); |
| 550 | |
Jakub Kicinski | 064a07c | 2018-01-17 19:13:29 -0800 | [diff] [blame] | 551 | printf("flags 0x%x", info->map_flags); |
| 552 | print_dev_plain(info->ifindex, info->netns_dev, info->netns_ino); |
| 553 | printf("\n"); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 554 | printf("\tkey %uB value %uB max_entries %u", |
| 555 | info->key_size, info->value_size, info->max_entries); |
| 556 | |
| 557 | if (memlock) |
| 558 | printf(" memlock %sB", memlock); |
| 559 | free(memlock); |
| 560 | |
Quentin Monnet | 99a44bef | 2018-11-30 16:25:48 +0000 | [diff] [blame] | 561 | if (info->type == BPF_MAP_TYPE_PROG_ARRAY) { |
| 562 | char *owner_prog_type = get_fdinfo(fd, "owner_prog_type"); |
| 563 | char *owner_jited = get_fdinfo(fd, "owner_jited"); |
| 564 | |
| 565 | printf("\n\t"); |
| 566 | if (owner_prog_type) { |
| 567 | unsigned int prog_type = atoi(owner_prog_type); |
| 568 | |
| 569 | if (prog_type < ARRAY_SIZE(prog_type_name)) |
| 570 | printf("owner_prog_type %s ", |
| 571 | prog_type_name[prog_type]); |
| 572 | else |
| 573 | printf("owner_prog_type %d ", prog_type); |
| 574 | } |
| 575 | if (atoi(owner_jited)) |
| 576 | printf("owner jited"); |
| 577 | else |
| 578 | printf("owner not jited"); |
| 579 | |
| 580 | free(owner_prog_type); |
| 581 | free(owner_jited); |
| 582 | } |
| 583 | close(fd); |
| 584 | |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 585 | printf("\n"); |
Prashant Bhole | 4990f1f | 2017-11-08 13:55:48 +0900 | [diff] [blame] | 586 | if (!hash_empty(map_table.table)) { |
| 587 | struct pinned_obj *obj; |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 588 | |
Prashant Bhole | 4990f1f | 2017-11-08 13:55:48 +0900 | [diff] [blame] | 589 | hash_for_each_possible(map_table.table, obj, hash, info->id) { |
| 590 | if (obj->id == info->id) |
| 591 | printf("\tpinned %s\n", obj->path); |
| 592 | } |
| 593 | } |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 594 | return 0; |
| 595 | } |
| 596 | |
| 597 | static int do_show(int argc, char **argv) |
| 598 | { |
| 599 | struct bpf_map_info info = {}; |
| 600 | __u32 len = sizeof(info); |
| 601 | __u32 id = 0; |
| 602 | int err; |
| 603 | int fd; |
| 604 | |
Prashant Bhole | c541b73 | 2017-11-08 13:55:49 +0900 | [diff] [blame] | 605 | if (show_pinned) |
| 606 | build_pinned_obj_table(&map_table, BPF_OBJ_MAP); |
Prashant Bhole | 4990f1f | 2017-11-08 13:55:48 +0900 | [diff] [blame] | 607 | |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 608 | if (argc == 2) { |
| 609 | fd = map_parse_fd_and_info(&argc, &argv, &info, &len); |
| 610 | if (fd < 0) |
| 611 | return -1; |
| 612 | |
Quentin Monnet | 831a0aa | 2017-10-23 09:24:11 -0700 | [diff] [blame] | 613 | if (json_output) |
| 614 | return show_map_close_json(fd, &info); |
| 615 | else |
| 616 | return show_map_close_plain(fd, &info); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | if (argc) |
| 620 | return BAD_ARG(); |
| 621 | |
Quentin Monnet | 831a0aa | 2017-10-23 09:24:11 -0700 | [diff] [blame] | 622 | if (json_output) |
| 623 | jsonw_start_array(json_wtr); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 624 | while (true) { |
| 625 | err = bpf_map_get_next_id(id, &id); |
| 626 | if (err) { |
| 627 | if (errno == ENOENT) |
| 628 | break; |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 629 | p_err("can't get next map: %s%s", strerror(errno), |
| 630 | errno == EINVAL ? " -- kernel too old?" : ""); |
Jakub Kicinski | b3b1b65 | 2017-12-22 11:36:05 -0800 | [diff] [blame] | 631 | break; |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | fd = bpf_map_get_fd_by_id(id); |
| 635 | if (fd < 0) { |
Jakub Kicinski | 8207c6d | 2017-12-22 11:36:06 -0800 | [diff] [blame] | 636 | if (errno == ENOENT) |
| 637 | continue; |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 638 | p_err("can't get map by id (%u): %s", |
| 639 | id, strerror(errno)); |
Jakub Kicinski | b3b1b65 | 2017-12-22 11:36:05 -0800 | [diff] [blame] | 640 | break; |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | err = bpf_obj_get_info_by_fd(fd, &info, &len); |
| 644 | if (err) { |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 645 | p_err("can't get map info: %s", strerror(errno)); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 646 | close(fd); |
Jakub Kicinski | b3b1b65 | 2017-12-22 11:36:05 -0800 | [diff] [blame] | 647 | break; |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 648 | } |
| 649 | |
Quentin Monnet | 831a0aa | 2017-10-23 09:24:11 -0700 | [diff] [blame] | 650 | if (json_output) |
| 651 | show_map_close_json(fd, &info); |
| 652 | else |
| 653 | show_map_close_plain(fd, &info); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 654 | } |
Quentin Monnet | 831a0aa | 2017-10-23 09:24:11 -0700 | [diff] [blame] | 655 | if (json_output) |
| 656 | jsonw_end_array(json_wtr); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 657 | |
| 658 | return errno == ENOENT ? 0 : -1; |
| 659 | } |
| 660 | |
Prashant Bhole | 18a781d | 2018-10-09 10:04:51 +0900 | [diff] [blame] | 661 | static int dump_map_elem(int fd, void *key, void *value, |
| 662 | struct bpf_map_info *map_info, struct btf *btf, |
| 663 | json_writer_t *btf_wtr) |
| 664 | { |
| 665 | int num_elems = 0; |
Prashant Bhole | 8ec92dc | 2018-10-09 10:04:52 +0900 | [diff] [blame] | 666 | int lookup_errno; |
Prashant Bhole | 18a781d | 2018-10-09 10:04:51 +0900 | [diff] [blame] | 667 | |
| 668 | if (!bpf_map_lookup_elem(fd, key, value)) { |
| 669 | if (json_output) { |
| 670 | print_entry_json(map_info, key, value, btf); |
| 671 | } else { |
| 672 | if (btf) { |
| 673 | struct btf_dumper d = { |
| 674 | .btf = btf, |
| 675 | .jw = btf_wtr, |
| 676 | .is_plain_text = true, |
| 677 | }; |
| 678 | |
| 679 | do_dump_btf(&d, map_info, key, value); |
| 680 | } else { |
| 681 | print_entry_plain(map_info, key, value); |
| 682 | } |
| 683 | num_elems++; |
| 684 | } |
| 685 | return num_elems; |
| 686 | } |
| 687 | |
| 688 | /* lookup error handling */ |
Prashant Bhole | 8ec92dc | 2018-10-09 10:04:52 +0900 | [diff] [blame] | 689 | lookup_errno = errno; |
| 690 | |
Prashant Bhole | 18a781d | 2018-10-09 10:04:51 +0900 | [diff] [blame] | 691 | if (map_is_map_of_maps(map_info->type) || |
| 692 | map_is_map_of_progs(map_info->type)) |
| 693 | return 0; |
| 694 | |
| 695 | if (json_output) { |
| 696 | jsonw_name(json_wtr, "key"); |
| 697 | print_hex_data_json(key, map_info->key_size); |
| 698 | jsonw_name(json_wtr, "value"); |
| 699 | jsonw_start_object(json_wtr); |
Prashant Bhole | 8ec92dc | 2018-10-09 10:04:52 +0900 | [diff] [blame] | 700 | jsonw_string_field(json_wtr, "error", strerror(lookup_errno)); |
Prashant Bhole | 18a781d | 2018-10-09 10:04:51 +0900 | [diff] [blame] | 701 | jsonw_end_object(json_wtr); |
| 702 | } else { |
David Ahern | bf598a8 | 2018-11-08 13:00:07 -0800 | [diff] [blame] | 703 | if (errno == ENOENT) |
| 704 | print_entry_plain(map_info, key, NULL); |
| 705 | else |
| 706 | print_entry_error(map_info, key, |
| 707 | strerror(lookup_errno)); |
Prashant Bhole | 18a781d | 2018-10-09 10:04:51 +0900 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | return 0; |
| 711 | } |
| 712 | |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 713 | static int do_dump(int argc, char **argv) |
| 714 | { |
Okash Khawaja | 2d3feca | 2018-07-13 21:57:04 -0700 | [diff] [blame] | 715 | struct bpf_map_info info = {}; |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 716 | void *key, *value, *prev_key; |
| 717 | unsigned int num_elems = 0; |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 718 | __u32 len = sizeof(info); |
Okash Khawaja | 2d3feca | 2018-07-13 21:57:04 -0700 | [diff] [blame] | 719 | json_writer_t *btf_wtr; |
| 720 | struct btf *btf = NULL; |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 721 | int err; |
| 722 | int fd; |
| 723 | |
| 724 | if (argc != 2) |
| 725 | usage(); |
| 726 | |
| 727 | fd = map_parse_fd_and_info(&argc, &argv, &info, &len); |
| 728 | if (fd < 0) |
| 729 | return -1; |
| 730 | |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 731 | key = malloc(info.key_size); |
| 732 | value = alloc_value(&info); |
| 733 | if (!key || !value) { |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 734 | p_err("mem alloc failed"); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 735 | err = -1; |
| 736 | goto exit_free; |
| 737 | } |
| 738 | |
| 739 | prev_key = NULL; |
Okash Khawaja | 2d3feca | 2018-07-13 21:57:04 -0700 | [diff] [blame] | 740 | |
Martin KaFai Lau | 1d2f44c | 2018-11-23 16:44:32 -0800 | [diff] [blame] | 741 | err = btf__get_from_id(info.btf_id, &btf); |
Okash Khawaja | 2d3feca | 2018-07-13 21:57:04 -0700 | [diff] [blame] | 742 | if (err) { |
| 743 | p_err("failed to get btf"); |
| 744 | goto exit_free; |
| 745 | } |
| 746 | |
Quentin Monnet | 831a0aa | 2017-10-23 09:24:11 -0700 | [diff] [blame] | 747 | if (json_output) |
| 748 | jsonw_start_array(json_wtr); |
Okash Khawaja | 2d3feca | 2018-07-13 21:57:04 -0700 | [diff] [blame] | 749 | else |
| 750 | if (btf) { |
| 751 | btf_wtr = get_btf_writer(); |
| 752 | if (!btf_wtr) { |
| 753 | p_info("failed to create json writer for btf. falling back to plain output"); |
| 754 | btf__free(btf); |
| 755 | btf = NULL; |
| 756 | } else { |
| 757 | jsonw_start_array(btf_wtr); |
| 758 | } |
| 759 | } |
| 760 | |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 761 | while (true) { |
| 762 | err = bpf_map_get_next_key(fd, prev_key, key); |
| 763 | if (err) { |
| 764 | if (errno == ENOENT) |
| 765 | err = 0; |
| 766 | break; |
| 767 | } |
Prashant Bhole | 18a781d | 2018-10-09 10:04:51 +0900 | [diff] [blame] | 768 | num_elems += dump_map_elem(fd, key, value, &info, btf, btf_wtr); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 769 | prev_key = key; |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 770 | } |
| 771 | |
Quentin Monnet | 831a0aa | 2017-10-23 09:24:11 -0700 | [diff] [blame] | 772 | if (json_output) |
| 773 | jsonw_end_array(json_wtr); |
Okash Khawaja | 2d3feca | 2018-07-13 21:57:04 -0700 | [diff] [blame] | 774 | else if (btf) { |
| 775 | jsonw_end_array(btf_wtr); |
| 776 | jsonw_destroy(&btf_wtr); |
| 777 | } else { |
Quentin Monnet | 831a0aa | 2017-10-23 09:24:11 -0700 | [diff] [blame] | 778 | printf("Found %u element%s\n", num_elems, |
| 779 | num_elems != 1 ? "s" : ""); |
Okash Khawaja | 2d3feca | 2018-07-13 21:57:04 -0700 | [diff] [blame] | 780 | } |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 781 | |
| 782 | exit_free: |
| 783 | free(key); |
| 784 | free(value); |
| 785 | close(fd); |
Okash Khawaja | 2d3feca | 2018-07-13 21:57:04 -0700 | [diff] [blame] | 786 | btf__free(btf); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 787 | |
| 788 | return err; |
| 789 | } |
| 790 | |
Stanislav Fomichev | 7d7209c | 2019-01-16 11:09:59 -0800 | [diff] [blame] | 791 | static int alloc_key_value(struct bpf_map_info *info, void **key, void **value) |
| 792 | { |
| 793 | *key = NULL; |
| 794 | *value = NULL; |
| 795 | |
| 796 | if (info->key_size) { |
| 797 | *key = malloc(info->key_size); |
| 798 | if (!*key) { |
| 799 | p_err("key mem alloc failed"); |
| 800 | return -1; |
| 801 | } |
| 802 | } |
| 803 | |
| 804 | if (info->value_size) { |
| 805 | *value = alloc_value(info); |
| 806 | if (!*value) { |
| 807 | p_err("value mem alloc failed"); |
| 808 | free(*key); |
| 809 | *key = NULL; |
| 810 | return -1; |
| 811 | } |
| 812 | } |
| 813 | |
| 814 | return 0; |
| 815 | } |
| 816 | |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 817 | static int do_update(int argc, char **argv) |
| 818 | { |
| 819 | struct bpf_map_info info = {}; |
| 820 | __u32 len = sizeof(info); |
| 821 | __u32 *value_fd = NULL; |
| 822 | __u32 flags = BPF_ANY; |
| 823 | void *key, *value; |
| 824 | int fd, err; |
| 825 | |
| 826 | if (argc < 2) |
| 827 | usage(); |
| 828 | |
| 829 | fd = map_parse_fd_and_info(&argc, &argv, &info, &len); |
| 830 | if (fd < 0) |
| 831 | return -1; |
| 832 | |
Stanislav Fomichev | 7d7209c | 2019-01-16 11:09:59 -0800 | [diff] [blame] | 833 | err = alloc_key_value(&info, &key, &value); |
| 834 | if (err) |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 835 | goto exit_free; |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 836 | |
| 837 | err = parse_elem(argv, &info, key, value, info.key_size, |
| 838 | info.value_size, &flags, &value_fd); |
| 839 | if (err) |
| 840 | goto exit_free; |
| 841 | |
| 842 | err = bpf_map_update_elem(fd, key, value, flags); |
| 843 | if (err) { |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 844 | p_err("update failed: %s", strerror(errno)); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 845 | goto exit_free; |
| 846 | } |
| 847 | |
| 848 | exit_free: |
| 849 | if (value_fd) |
| 850 | close(*value_fd); |
| 851 | free(key); |
| 852 | free(value); |
| 853 | close(fd); |
| 854 | |
Quentin Monnet | 004b45c | 2017-10-23 09:24:14 -0700 | [diff] [blame] | 855 | if (!err && json_output) |
| 856 | jsonw_null(json_wtr); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 857 | return err; |
| 858 | } |
| 859 | |
| 860 | static int do_lookup(int argc, char **argv) |
| 861 | { |
| 862 | struct bpf_map_info info = {}; |
| 863 | __u32 len = sizeof(info); |
Okash Khawaja | 2d3feca | 2018-07-13 21:57:04 -0700 | [diff] [blame] | 864 | json_writer_t *btf_wtr; |
| 865 | struct btf *btf = NULL; |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 866 | void *key, *value; |
| 867 | int err; |
| 868 | int fd; |
| 869 | |
| 870 | if (argc < 2) |
| 871 | usage(); |
| 872 | |
| 873 | fd = map_parse_fd_and_info(&argc, &argv, &info, &len); |
| 874 | if (fd < 0) |
| 875 | return -1; |
| 876 | |
Stanislav Fomichev | 8a89fff | 2019-01-16 11:10:00 -0800 | [diff] [blame] | 877 | err = alloc_key_value(&info, &key, &value); |
| 878 | if (err) |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 879 | goto exit_free; |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 880 | |
| 881 | err = parse_elem(argv, &info, key, NULL, info.key_size, 0, NULL, NULL); |
| 882 | if (err) |
| 883 | goto exit_free; |
| 884 | |
| 885 | err = bpf_map_lookup_elem(fd, key, value); |
Okash Khawaja | 2d3feca | 2018-07-13 21:57:04 -0700 | [diff] [blame] | 886 | if (err) { |
| 887 | if (errno == ENOENT) { |
| 888 | if (json_output) { |
| 889 | jsonw_null(json_wtr); |
| 890 | } else { |
| 891 | printf("key:\n"); |
| 892 | fprint_hex(stdout, key, info.key_size, " "); |
| 893 | printf("\n\nNot found\n"); |
| 894 | } |
Quentin Monnet | 831a0aa | 2017-10-23 09:24:11 -0700 | [diff] [blame] | 895 | } else { |
Okash Khawaja | 2d3feca | 2018-07-13 21:57:04 -0700 | [diff] [blame] | 896 | p_err("lookup failed: %s", strerror(errno)); |
| 897 | } |
| 898 | |
| 899 | goto exit_free; |
| 900 | } |
| 901 | |
| 902 | /* here means bpf_map_lookup_elem() succeeded */ |
Martin KaFai Lau | 1d2f44c | 2018-11-23 16:44:32 -0800 | [diff] [blame] | 903 | err = btf__get_from_id(info.btf_id, &btf); |
Okash Khawaja | 2d3feca | 2018-07-13 21:57:04 -0700 | [diff] [blame] | 904 | if (err) { |
| 905 | p_err("failed to get btf"); |
| 906 | goto exit_free; |
| 907 | } |
| 908 | |
| 909 | if (json_output) { |
| 910 | print_entry_json(&info, key, value, btf); |
| 911 | } else if (btf) { |
| 912 | /* if here json_wtr wouldn't have been initialised, |
| 913 | * so let's create separate writer for btf |
| 914 | */ |
| 915 | btf_wtr = get_btf_writer(); |
| 916 | if (!btf_wtr) { |
| 917 | p_info("failed to create json writer for btf. falling back to plain output"); |
| 918 | btf__free(btf); |
| 919 | btf = NULL; |
| 920 | print_entry_plain(&info, key, value); |
| 921 | } else { |
| 922 | struct btf_dumper d = { |
| 923 | .btf = btf, |
| 924 | .jw = btf_wtr, |
| 925 | .is_plain_text = true, |
| 926 | }; |
| 927 | |
| 928 | do_dump_btf(&d, &info, key, value); |
| 929 | jsonw_destroy(&btf_wtr); |
Quentin Monnet | 831a0aa | 2017-10-23 09:24:11 -0700 | [diff] [blame] | 930 | } |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 931 | } else { |
Okash Khawaja | 2d3feca | 2018-07-13 21:57:04 -0700 | [diff] [blame] | 932 | print_entry_plain(&info, key, value); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 933 | } |
| 934 | |
| 935 | exit_free: |
| 936 | free(key); |
| 937 | free(value); |
| 938 | close(fd); |
Okash Khawaja | 2d3feca | 2018-07-13 21:57:04 -0700 | [diff] [blame] | 939 | btf__free(btf); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 940 | |
| 941 | return err; |
| 942 | } |
| 943 | |
| 944 | static int do_getnext(int argc, char **argv) |
| 945 | { |
| 946 | struct bpf_map_info info = {}; |
| 947 | __u32 len = sizeof(info); |
| 948 | void *key, *nextkey; |
| 949 | int err; |
| 950 | int fd; |
| 951 | |
| 952 | if (argc < 2) |
| 953 | usage(); |
| 954 | |
| 955 | fd = map_parse_fd_and_info(&argc, &argv, &info, &len); |
| 956 | if (fd < 0) |
| 957 | return -1; |
| 958 | |
| 959 | key = malloc(info.key_size); |
| 960 | nextkey = malloc(info.key_size); |
| 961 | if (!key || !nextkey) { |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 962 | p_err("mem alloc failed"); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 963 | err = -1; |
| 964 | goto exit_free; |
| 965 | } |
| 966 | |
| 967 | if (argc) { |
| 968 | err = parse_elem(argv, &info, key, NULL, info.key_size, 0, |
| 969 | NULL, NULL); |
| 970 | if (err) |
| 971 | goto exit_free; |
| 972 | } else { |
| 973 | free(key); |
| 974 | key = NULL; |
| 975 | } |
| 976 | |
| 977 | err = bpf_map_get_next_key(fd, key, nextkey); |
| 978 | if (err) { |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 979 | p_err("can't get next key: %s", strerror(errno)); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 980 | goto exit_free; |
| 981 | } |
| 982 | |
Quentin Monnet | 831a0aa | 2017-10-23 09:24:11 -0700 | [diff] [blame] | 983 | if (json_output) { |
| 984 | jsonw_start_object(json_wtr); |
| 985 | if (key) { |
| 986 | jsonw_name(json_wtr, "key"); |
| 987 | print_hex_data_json(key, info.key_size); |
| 988 | } else { |
| 989 | jsonw_null_field(json_wtr, "key"); |
| 990 | } |
| 991 | jsonw_name(json_wtr, "next_key"); |
| 992 | print_hex_data_json(nextkey, info.key_size); |
| 993 | jsonw_end_object(json_wtr); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 994 | } else { |
Quentin Monnet | 831a0aa | 2017-10-23 09:24:11 -0700 | [diff] [blame] | 995 | if (key) { |
| 996 | printf("key:\n"); |
| 997 | fprint_hex(stdout, key, info.key_size, " "); |
| 998 | printf("\n"); |
| 999 | } else { |
| 1000 | printf("key: None\n"); |
| 1001 | } |
| 1002 | printf("next key:\n"); |
| 1003 | fprint_hex(stdout, nextkey, info.key_size, " "); |
| 1004 | printf("\n"); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 1005 | } |
| 1006 | |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 1007 | exit_free: |
| 1008 | free(nextkey); |
| 1009 | free(key); |
| 1010 | close(fd); |
| 1011 | |
| 1012 | return err; |
| 1013 | } |
| 1014 | |
| 1015 | static int do_delete(int argc, char **argv) |
| 1016 | { |
| 1017 | struct bpf_map_info info = {}; |
| 1018 | __u32 len = sizeof(info); |
| 1019 | void *key; |
| 1020 | int err; |
| 1021 | int fd; |
| 1022 | |
| 1023 | if (argc < 2) |
| 1024 | usage(); |
| 1025 | |
| 1026 | fd = map_parse_fd_and_info(&argc, &argv, &info, &len); |
| 1027 | if (fd < 0) |
| 1028 | return -1; |
| 1029 | |
| 1030 | key = malloc(info.key_size); |
| 1031 | if (!key) { |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 1032 | p_err("mem alloc failed"); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 1033 | err = -1; |
| 1034 | goto exit_free; |
| 1035 | } |
| 1036 | |
| 1037 | err = parse_elem(argv, &info, key, NULL, info.key_size, 0, NULL, NULL); |
| 1038 | if (err) |
| 1039 | goto exit_free; |
| 1040 | |
| 1041 | err = bpf_map_delete_elem(fd, key); |
| 1042 | if (err) |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 1043 | p_err("delete failed: %s", strerror(errno)); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 1044 | |
| 1045 | exit_free: |
| 1046 | free(key); |
| 1047 | close(fd); |
| 1048 | |
Quentin Monnet | 004b45c | 2017-10-23 09:24:14 -0700 | [diff] [blame] | 1049 | if (!err && json_output) |
| 1050 | jsonw_null(json_wtr); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 1051 | return err; |
| 1052 | } |
| 1053 | |
| 1054 | static int do_pin(int argc, char **argv) |
| 1055 | { |
Quentin Monnet | 004b45c | 2017-10-23 09:24:14 -0700 | [diff] [blame] | 1056 | int err; |
| 1057 | |
| 1058 | err = do_pin_any(argc, argv, bpf_map_get_fd_by_id); |
| 1059 | if (!err && json_output) |
| 1060 | jsonw_null(json_wtr); |
| 1061 | return err; |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 1062 | } |
| 1063 | |
Jakub Kicinski | 0b592b5a | 2018-10-15 16:30:36 -0700 | [diff] [blame] | 1064 | static int do_create(int argc, char **argv) |
| 1065 | { |
| 1066 | struct bpf_create_map_attr attr = { NULL, }; |
| 1067 | const char *pinfile; |
| 1068 | int err, fd; |
| 1069 | |
| 1070 | if (!REQ_ARGS(7)) |
| 1071 | return -1; |
| 1072 | pinfile = GET_ARG(); |
| 1073 | |
| 1074 | while (argc) { |
| 1075 | if (!REQ_ARGS(2)) |
| 1076 | return -1; |
| 1077 | |
| 1078 | if (is_prefix(*argv, "type")) { |
| 1079 | NEXT_ARG(); |
| 1080 | |
| 1081 | if (attr.map_type) { |
| 1082 | p_err("map type already specified"); |
| 1083 | return -1; |
| 1084 | } |
| 1085 | |
| 1086 | attr.map_type = map_type_from_str(*argv); |
| 1087 | if ((int)attr.map_type < 0) { |
| 1088 | p_err("unrecognized map type: %s", *argv); |
| 1089 | return -1; |
| 1090 | } |
| 1091 | NEXT_ARG(); |
| 1092 | } else if (is_prefix(*argv, "name")) { |
| 1093 | NEXT_ARG(); |
| 1094 | attr.name = GET_ARG(); |
| 1095 | } else if (is_prefix(*argv, "key")) { |
| 1096 | if (parse_u32_arg(&argc, &argv, &attr.key_size, |
| 1097 | "key size")) |
| 1098 | return -1; |
| 1099 | } else if (is_prefix(*argv, "value")) { |
| 1100 | if (parse_u32_arg(&argc, &argv, &attr.value_size, |
| 1101 | "value size")) |
| 1102 | return -1; |
| 1103 | } else if (is_prefix(*argv, "entries")) { |
| 1104 | if (parse_u32_arg(&argc, &argv, &attr.max_entries, |
| 1105 | "max entries")) |
| 1106 | return -1; |
| 1107 | } else if (is_prefix(*argv, "flags")) { |
| 1108 | if (parse_u32_arg(&argc, &argv, &attr.map_flags, |
| 1109 | "flags")) |
| 1110 | return -1; |
| 1111 | } else if (is_prefix(*argv, "dev")) { |
| 1112 | NEXT_ARG(); |
| 1113 | |
| 1114 | if (attr.map_ifindex) { |
| 1115 | p_err("offload device already specified"); |
| 1116 | return -1; |
| 1117 | } |
| 1118 | |
| 1119 | attr.map_ifindex = if_nametoindex(*argv); |
| 1120 | if (!attr.map_ifindex) { |
| 1121 | p_err("unrecognized netdevice '%s': %s", |
| 1122 | *argv, strerror(errno)); |
| 1123 | return -1; |
| 1124 | } |
| 1125 | NEXT_ARG(); |
| 1126 | } |
| 1127 | } |
| 1128 | |
| 1129 | if (!attr.name) { |
| 1130 | p_err("map name not specified"); |
| 1131 | return -1; |
| 1132 | } |
| 1133 | |
Quentin Monnet | 8302b9b | 2018-11-07 12:29:30 +0000 | [diff] [blame] | 1134 | set_max_rlimit(); |
| 1135 | |
Jakub Kicinski | 0b592b5a | 2018-10-15 16:30:36 -0700 | [diff] [blame] | 1136 | fd = bpf_create_map_xattr(&attr); |
| 1137 | if (fd < 0) { |
| 1138 | p_err("map create failed: %s", strerror(errno)); |
| 1139 | return -1; |
| 1140 | } |
| 1141 | |
| 1142 | err = do_pin_fd(fd, pinfile); |
| 1143 | close(fd); |
| 1144 | if (err) |
| 1145 | return err; |
| 1146 | |
| 1147 | if (json_output) |
| 1148 | jsonw_null(json_wtr); |
| 1149 | return 0; |
| 1150 | } |
| 1151 | |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 1152 | static int do_help(int argc, char **argv) |
| 1153 | { |
Quentin Monnet | 004b45c | 2017-10-23 09:24:14 -0700 | [diff] [blame] | 1154 | if (json_output) { |
| 1155 | jsonw_null(json_wtr); |
| 1156 | return 0; |
| 1157 | } |
| 1158 | |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 1159 | fprintf(stderr, |
Jakub Kicinski | 6ebe6db | 2018-01-02 14:48:36 -0800 | [diff] [blame] | 1160 | "Usage: %s %s { show | list } [MAP]\n" |
Jakub Kicinski | 0b592b5a | 2018-10-15 16:30:36 -0700 | [diff] [blame] | 1161 | " %s %s create FILE type TYPE key KEY_SIZE value VALUE_SIZE \\\n" |
| 1162 | " entries MAX_ENTRIES name NAME [flags FLAGS] \\\n" |
| 1163 | " [dev NAME]\n" |
Jakub Kicinski | f412eed | 2018-05-03 18:37:16 -0700 | [diff] [blame] | 1164 | " %s %s dump MAP\n" |
Stanislav Fomichev | 7d7209c | 2019-01-16 11:09:59 -0800 | [diff] [blame] | 1165 | " %s %s update MAP [key DATA] [value VALUE] [UPDATE_FLAGS]\n" |
Stanislav Fomichev | 8a89fff | 2019-01-16 11:10:00 -0800 | [diff] [blame] | 1166 | " %s %s lookup MAP [key DATA]\n" |
Jakub Kicinski | f412eed | 2018-05-03 18:37:16 -0700 | [diff] [blame] | 1167 | " %s %s getnext MAP [key DATA]\n" |
| 1168 | " %s %s delete MAP key DATA\n" |
| 1169 | " %s %s pin MAP FILE\n" |
| 1170 | " %s %s event_pipe MAP [cpu N index M]\n" |
Stanislav Fomichev | 66cf6e0 | 2019-01-16 11:10:02 -0800 | [diff] [blame^] | 1171 | " %s %s peek MAP\n" |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 1172 | " %s %s help\n" |
| 1173 | "\n" |
Jakub Kicinski | 3ff5a4d | 2018-07-10 14:43:07 -0700 | [diff] [blame] | 1174 | " " HELP_SPEC_MAP "\n" |
Jakub Kicinski | c642ea2 | 2018-05-03 18:37:14 -0700 | [diff] [blame] | 1175 | " DATA := { [hex] BYTES }\n" |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 1176 | " " HELP_SPEC_PROGRAM "\n" |
Jakub Kicinski | c642ea2 | 2018-05-03 18:37:14 -0700 | [diff] [blame] | 1177 | " VALUE := { DATA | MAP | PROG }\n" |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 1178 | " UPDATE_FLAGS := { any | exist | noexist }\n" |
Jakub Kicinski | 0b592b5a | 2018-10-15 16:30:36 -0700 | [diff] [blame] | 1179 | " TYPE := { hash | array | prog_array | perf_event_array | percpu_hash |\n" |
| 1180 | " percpu_array | stack_trace | cgroup_array | lru_hash |\n" |
| 1181 | " lru_percpu_hash | lpm_trie | array_of_maps | hash_of_maps |\n" |
| 1182 | " devmap | sockmap | cpumap | xskmap | sockhash |\n" |
| 1183 | " cgroup_storage | reuseport_sockarray | percpu_cgroup_storage }\n" |
Quentin Monnet | 0641c3c | 2017-10-23 09:24:16 -0700 | [diff] [blame] | 1184 | " " HELP_SPEC_OPTIONS "\n" |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 1185 | "", |
| 1186 | bin_name, argv[-2], bin_name, argv[-2], bin_name, argv[-2], |
| 1187 | bin_name, argv[-2], bin_name, argv[-2], bin_name, argv[-2], |
Jakub Kicinski | 0b592b5a | 2018-10-15 16:30:36 -0700 | [diff] [blame] | 1188 | bin_name, argv[-2], bin_name, argv[-2], bin_name, argv[-2], |
Stanislav Fomichev | 66cf6e0 | 2019-01-16 11:10:02 -0800 | [diff] [blame^] | 1189 | bin_name, argv[-2], bin_name, argv[-2]); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 1190 | |
| 1191 | return 0; |
| 1192 | } |
| 1193 | |
| 1194 | static const struct cmd cmds[] = { |
| 1195 | { "show", do_show }, |
Jakub Kicinski | 6ebe6db | 2018-01-02 14:48:36 -0800 | [diff] [blame] | 1196 | { "list", do_show }, |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 1197 | { "help", do_help }, |
| 1198 | { "dump", do_dump }, |
| 1199 | { "update", do_update }, |
| 1200 | { "lookup", do_lookup }, |
| 1201 | { "getnext", do_getnext }, |
| 1202 | { "delete", do_delete }, |
| 1203 | { "pin", do_pin }, |
Jakub Kicinski | f412eed | 2018-05-03 18:37:16 -0700 | [diff] [blame] | 1204 | { "event_pipe", do_event_pipe }, |
Jakub Kicinski | 0b592b5a | 2018-10-15 16:30:36 -0700 | [diff] [blame] | 1205 | { "create", do_create }, |
Stanislav Fomichev | 66cf6e0 | 2019-01-16 11:10:02 -0800 | [diff] [blame^] | 1206 | { "peek", do_lookup }, |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 1207 | { 0 } |
| 1208 | }; |
| 1209 | |
| 1210 | int do_map(int argc, char **argv) |
| 1211 | { |
| 1212 | return cmd_select(cmds, argc, argv, do_help); |
| 1213 | } |