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 | |
| 288 | printf("key:%c", break_names ? '\n' : ' '); |
Quentin Monnet | 9cbe1f58 | 2017-10-19 15:46:19 -0700 | [diff] [blame] | 289 | fprint_hex(stdout, key, info->key_size, " "); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 290 | |
| 291 | printf(single_line ? " " : "\n"); |
| 292 | |
| 293 | printf("value:%c", break_names ? '\n' : ' '); |
David Ahern | bf598a8 | 2018-11-08 13:00:07 -0800 | [diff] [blame] | 294 | if (value) |
| 295 | fprint_hex(stdout, value, info->value_size, " "); |
| 296 | else |
| 297 | printf("<no entry>"); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 298 | |
| 299 | printf("\n"); |
| 300 | } else { |
Yonghong Song | 573b3aa | 2018-07-30 08:49:03 -0700 | [diff] [blame] | 301 | unsigned int i, n, step; |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 302 | |
| 303 | n = get_possible_cpus(); |
Yonghong Song | 573b3aa | 2018-07-30 08:49:03 -0700 | [diff] [blame] | 304 | step = round_up(info->value_size, 8); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 305 | |
| 306 | printf("key:\n"); |
Quentin Monnet | 9cbe1f58 | 2017-10-19 15:46:19 -0700 | [diff] [blame] | 307 | fprint_hex(stdout, key, info->key_size, " "); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 308 | printf("\n"); |
| 309 | for (i = 0; i < n; i++) { |
| 310 | printf("value (CPU %02d):%c", |
| 311 | i, info->value_size > 16 ? '\n' : ' '); |
David Ahern | bf598a8 | 2018-11-08 13:00:07 -0800 | [diff] [blame] | 312 | if (value) |
| 313 | fprint_hex(stdout, value + i * step, |
| 314 | info->value_size, " "); |
| 315 | else |
| 316 | printf("<no entry>"); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 317 | printf("\n"); |
| 318 | } |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | static char **parse_bytes(char **argv, const char *name, unsigned char *val, |
| 323 | unsigned int n) |
| 324 | { |
Quentin Monnet | 0c90f22 | 2018-04-17 19:46:34 -0700 | [diff] [blame] | 325 | unsigned int i = 0, base = 0; |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 326 | char *endptr; |
| 327 | |
Quentin Monnet | 0c90f22 | 2018-04-17 19:46:34 -0700 | [diff] [blame] | 328 | if (is_prefix(*argv, "hex")) { |
| 329 | base = 16; |
| 330 | argv++; |
| 331 | } |
| 332 | |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 333 | while (i < n && argv[i]) { |
Quentin Monnet | 0c90f22 | 2018-04-17 19:46:34 -0700 | [diff] [blame] | 334 | val[i] = strtoul(argv[i], &endptr, base); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 335 | if (*endptr) { |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 336 | p_err("error parsing byte: %s", argv[i]); |
Quentin Monnet | d9c0b48 | 2017-10-19 15:46:23 -0700 | [diff] [blame] | 337 | return NULL; |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 338 | } |
| 339 | i++; |
| 340 | } |
| 341 | |
| 342 | if (i != n) { |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 343 | p_err("%s expected %d bytes got %d", name, n, i); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 344 | return NULL; |
| 345 | } |
| 346 | |
| 347 | return argv + i; |
| 348 | } |
| 349 | |
Paolo Abeni | b0ca5ec | 2019-01-21 12:36:12 +0100 | [diff] [blame] | 350 | /* on per cpu maps we must copy the provided value on all value instances */ |
| 351 | static void fill_per_cpu_value(struct bpf_map_info *info, void *value) |
| 352 | { |
| 353 | unsigned int i, n, step; |
| 354 | |
| 355 | if (!map_is_per_cpu(info->type)) |
| 356 | return; |
| 357 | |
| 358 | n = get_possible_cpus(); |
| 359 | step = round_up(info->value_size, 8); |
| 360 | for (i = 1; i < n; i++) |
| 361 | memcpy(value + i * step, value, info->value_size); |
| 362 | } |
| 363 | |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 364 | static int parse_elem(char **argv, struct bpf_map_info *info, |
| 365 | void *key, void *value, __u32 key_size, __u32 value_size, |
| 366 | __u32 *flags, __u32 **value_fd) |
| 367 | { |
| 368 | if (!*argv) { |
| 369 | if (!key && !value) |
| 370 | return 0; |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 371 | p_err("did not find %s", key ? "key" : "value"); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 372 | return -1; |
| 373 | } |
| 374 | |
| 375 | if (is_prefix(*argv, "key")) { |
| 376 | if (!key) { |
| 377 | if (key_size) |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 378 | p_err("duplicate key"); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 379 | else |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 380 | p_err("unnecessary key"); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 381 | return -1; |
| 382 | } |
| 383 | |
| 384 | argv = parse_bytes(argv + 1, "key", key, key_size); |
| 385 | if (!argv) |
| 386 | return -1; |
| 387 | |
| 388 | return parse_elem(argv, info, NULL, value, key_size, value_size, |
| 389 | flags, value_fd); |
| 390 | } else if (is_prefix(*argv, "value")) { |
| 391 | int fd; |
| 392 | |
| 393 | if (!value) { |
| 394 | if (value_size) |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 395 | p_err("duplicate value"); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 396 | else |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 397 | p_err("unnecessary value"); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 398 | return -1; |
| 399 | } |
| 400 | |
| 401 | argv++; |
| 402 | |
| 403 | if (map_is_map_of_maps(info->type)) { |
| 404 | int argc = 2; |
| 405 | |
| 406 | if (value_size != 4) { |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 407 | p_err("value smaller than 4B for map in map?"); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 408 | return -1; |
| 409 | } |
| 410 | if (!argv[0] || !argv[1]) { |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 411 | p_err("not enough value arguments for map in map"); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 412 | return -1; |
| 413 | } |
| 414 | |
| 415 | fd = map_parse_fd(&argc, &argv); |
| 416 | if (fd < 0) |
| 417 | return -1; |
| 418 | |
| 419 | *value_fd = value; |
| 420 | **value_fd = fd; |
| 421 | } else if (map_is_map_of_progs(info->type)) { |
| 422 | int argc = 2; |
| 423 | |
| 424 | if (value_size != 4) { |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 425 | p_err("value smaller than 4B for map of progs?"); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 426 | return -1; |
| 427 | } |
| 428 | if (!argv[0] || !argv[1]) { |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 429 | p_err("not enough value arguments for map of progs"); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 430 | return -1; |
| 431 | } |
| 432 | |
| 433 | fd = prog_parse_fd(&argc, &argv); |
| 434 | if (fd < 0) |
| 435 | return -1; |
| 436 | |
| 437 | *value_fd = value; |
| 438 | **value_fd = fd; |
| 439 | } else { |
| 440 | argv = parse_bytes(argv, "value", value, value_size); |
| 441 | if (!argv) |
| 442 | return -1; |
Paolo Abeni | b0ca5ec | 2019-01-21 12:36:12 +0100 | [diff] [blame] | 443 | |
| 444 | fill_per_cpu_value(info, value); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | return parse_elem(argv, info, key, NULL, key_size, value_size, |
| 448 | flags, NULL); |
| 449 | } else if (is_prefix(*argv, "any") || is_prefix(*argv, "noexist") || |
| 450 | is_prefix(*argv, "exist")) { |
| 451 | if (!flags) { |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 452 | p_err("flags specified multiple times: %s", *argv); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 453 | return -1; |
| 454 | } |
| 455 | |
| 456 | if (is_prefix(*argv, "any")) |
| 457 | *flags = BPF_ANY; |
| 458 | else if (is_prefix(*argv, "noexist")) |
| 459 | *flags = BPF_NOEXIST; |
| 460 | else if (is_prefix(*argv, "exist")) |
| 461 | *flags = BPF_EXIST; |
| 462 | |
| 463 | return parse_elem(argv + 1, info, key, value, key_size, |
| 464 | value_size, NULL, value_fd); |
| 465 | } |
| 466 | |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 467 | p_err("expected key or value, got: %s", *argv); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 468 | return -1; |
| 469 | } |
| 470 | |
Quentin Monnet | 831a0aa | 2017-10-23 09:24:11 -0700 | [diff] [blame] | 471 | static int show_map_close_json(int fd, struct bpf_map_info *info) |
| 472 | { |
| 473 | char *memlock; |
| 474 | |
| 475 | memlock = get_fdinfo(fd, "memlock"); |
Quentin Monnet | 831a0aa | 2017-10-23 09:24:11 -0700 | [diff] [blame] | 476 | |
| 477 | jsonw_start_object(json_wtr); |
| 478 | |
| 479 | jsonw_uint_field(json_wtr, "id", info->id); |
| 480 | if (info->type < ARRAY_SIZE(map_type_name)) |
| 481 | jsonw_string_field(json_wtr, "type", |
| 482 | map_type_name[info->type]); |
| 483 | else |
| 484 | jsonw_uint_field(json_wtr, "type", info->type); |
| 485 | |
| 486 | if (*info->name) |
| 487 | jsonw_string_field(json_wtr, "name", info->name); |
| 488 | |
| 489 | jsonw_name(json_wtr, "flags"); |
Jakub Kicinski | 4b6eca9 | 2018-03-23 19:45:12 -0700 | [diff] [blame] | 490 | jsonw_printf(json_wtr, "%d", info->map_flags); |
Jakub Kicinski | 064a07c | 2018-01-17 19:13:29 -0800 | [diff] [blame] | 491 | |
| 492 | print_dev_json(info->ifindex, info->netns_dev, info->netns_ino); |
| 493 | |
Quentin Monnet | 831a0aa | 2017-10-23 09:24:11 -0700 | [diff] [blame] | 494 | jsonw_uint_field(json_wtr, "bytes_key", info->key_size); |
| 495 | jsonw_uint_field(json_wtr, "bytes_value", info->value_size); |
| 496 | jsonw_uint_field(json_wtr, "max_entries", info->max_entries); |
| 497 | |
| 498 | if (memlock) |
| 499 | jsonw_int_field(json_wtr, "bytes_memlock", atoi(memlock)); |
| 500 | free(memlock); |
| 501 | |
Quentin Monnet | 99a44bef | 2018-11-30 16:25:48 +0000 | [diff] [blame] | 502 | if (info->type == BPF_MAP_TYPE_PROG_ARRAY) { |
| 503 | char *owner_prog_type = get_fdinfo(fd, "owner_prog_type"); |
| 504 | char *owner_jited = get_fdinfo(fd, "owner_jited"); |
| 505 | |
| 506 | if (owner_prog_type) { |
| 507 | unsigned int prog_type = atoi(owner_prog_type); |
| 508 | |
| 509 | if (prog_type < ARRAY_SIZE(prog_type_name)) |
| 510 | jsonw_string_field(json_wtr, "owner_prog_type", |
| 511 | prog_type_name[prog_type]); |
| 512 | else |
| 513 | jsonw_uint_field(json_wtr, "owner_prog_type", |
| 514 | prog_type); |
| 515 | } |
Jakub Kicinski | 8c79b35 | 2019-01-28 10:01:21 -0800 | [diff] [blame^] | 516 | if (owner_jited) |
| 517 | jsonw_bool_field(json_wtr, "owner_jited", |
| 518 | !!atoi(owner_jited)); |
Quentin Monnet | 99a44bef | 2018-11-30 16:25:48 +0000 | [diff] [blame] | 519 | |
| 520 | free(owner_prog_type); |
| 521 | free(owner_jited); |
| 522 | } |
| 523 | close(fd); |
| 524 | |
Prashant Bhole | 4990f1f | 2017-11-08 13:55:48 +0900 | [diff] [blame] | 525 | if (!hash_empty(map_table.table)) { |
| 526 | struct pinned_obj *obj; |
| 527 | |
| 528 | jsonw_name(json_wtr, "pinned"); |
| 529 | jsonw_start_array(json_wtr); |
| 530 | hash_for_each_possible(map_table.table, obj, hash, info->id) { |
| 531 | if (obj->id == info->id) |
| 532 | jsonw_string(json_wtr, obj->path); |
| 533 | } |
| 534 | jsonw_end_array(json_wtr); |
| 535 | } |
| 536 | |
Quentin Monnet | 831a0aa | 2017-10-23 09:24:11 -0700 | [diff] [blame] | 537 | jsonw_end_object(json_wtr); |
| 538 | |
| 539 | return 0; |
| 540 | } |
| 541 | |
| 542 | 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] | 543 | { |
| 544 | char *memlock; |
| 545 | |
| 546 | memlock = get_fdinfo(fd, "memlock"); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 547 | |
| 548 | printf("%u: ", info->id); |
| 549 | if (info->type < ARRAY_SIZE(map_type_name)) |
| 550 | printf("%s ", map_type_name[info->type]); |
| 551 | else |
| 552 | printf("type %u ", info->type); |
| 553 | |
| 554 | if (*info->name) |
| 555 | printf("name %s ", info->name); |
| 556 | |
Jakub Kicinski | 064a07c | 2018-01-17 19:13:29 -0800 | [diff] [blame] | 557 | printf("flags 0x%x", info->map_flags); |
| 558 | print_dev_plain(info->ifindex, info->netns_dev, info->netns_ino); |
| 559 | printf("\n"); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 560 | printf("\tkey %uB value %uB max_entries %u", |
| 561 | info->key_size, info->value_size, info->max_entries); |
| 562 | |
| 563 | if (memlock) |
| 564 | printf(" memlock %sB", memlock); |
| 565 | free(memlock); |
| 566 | |
Quentin Monnet | 99a44bef | 2018-11-30 16:25:48 +0000 | [diff] [blame] | 567 | if (info->type == BPF_MAP_TYPE_PROG_ARRAY) { |
| 568 | char *owner_prog_type = get_fdinfo(fd, "owner_prog_type"); |
| 569 | char *owner_jited = get_fdinfo(fd, "owner_jited"); |
| 570 | |
Jakub Kicinski | 8c79b35 | 2019-01-28 10:01:21 -0800 | [diff] [blame^] | 571 | if (owner_prog_type || owner_jited) |
| 572 | printf("\n\t"); |
Quentin Monnet | 99a44bef | 2018-11-30 16:25:48 +0000 | [diff] [blame] | 573 | if (owner_prog_type) { |
| 574 | unsigned int prog_type = atoi(owner_prog_type); |
| 575 | |
| 576 | if (prog_type < ARRAY_SIZE(prog_type_name)) |
| 577 | printf("owner_prog_type %s ", |
| 578 | prog_type_name[prog_type]); |
| 579 | else |
| 580 | printf("owner_prog_type %d ", prog_type); |
| 581 | } |
Jakub Kicinski | 8c79b35 | 2019-01-28 10:01:21 -0800 | [diff] [blame^] | 582 | if (owner_jited) |
| 583 | printf("owner%s jited", |
| 584 | atoi(owner_jited) ? "" : " not"); |
Quentin Monnet | 99a44bef | 2018-11-30 16:25:48 +0000 | [diff] [blame] | 585 | |
| 586 | free(owner_prog_type); |
| 587 | free(owner_jited); |
| 588 | } |
| 589 | close(fd); |
| 590 | |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 591 | printf("\n"); |
Prashant Bhole | 4990f1f | 2017-11-08 13:55:48 +0900 | [diff] [blame] | 592 | if (!hash_empty(map_table.table)) { |
| 593 | struct pinned_obj *obj; |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 594 | |
Prashant Bhole | 4990f1f | 2017-11-08 13:55:48 +0900 | [diff] [blame] | 595 | hash_for_each_possible(map_table.table, obj, hash, info->id) { |
| 596 | if (obj->id == info->id) |
| 597 | printf("\tpinned %s\n", obj->path); |
| 598 | } |
| 599 | } |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 600 | return 0; |
| 601 | } |
| 602 | |
| 603 | static int do_show(int argc, char **argv) |
| 604 | { |
| 605 | struct bpf_map_info info = {}; |
| 606 | __u32 len = sizeof(info); |
| 607 | __u32 id = 0; |
| 608 | int err; |
| 609 | int fd; |
| 610 | |
Prashant Bhole | c541b73 | 2017-11-08 13:55:49 +0900 | [diff] [blame] | 611 | if (show_pinned) |
| 612 | build_pinned_obj_table(&map_table, BPF_OBJ_MAP); |
Prashant Bhole | 4990f1f | 2017-11-08 13:55:48 +0900 | [diff] [blame] | 613 | |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 614 | if (argc == 2) { |
| 615 | fd = map_parse_fd_and_info(&argc, &argv, &info, &len); |
| 616 | if (fd < 0) |
| 617 | return -1; |
| 618 | |
Quentin Monnet | 831a0aa | 2017-10-23 09:24:11 -0700 | [diff] [blame] | 619 | if (json_output) |
| 620 | return show_map_close_json(fd, &info); |
| 621 | else |
| 622 | return show_map_close_plain(fd, &info); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | if (argc) |
| 626 | return BAD_ARG(); |
| 627 | |
Quentin Monnet | 831a0aa | 2017-10-23 09:24:11 -0700 | [diff] [blame] | 628 | if (json_output) |
| 629 | jsonw_start_array(json_wtr); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 630 | while (true) { |
| 631 | err = bpf_map_get_next_id(id, &id); |
| 632 | if (err) { |
| 633 | if (errno == ENOENT) |
| 634 | break; |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 635 | p_err("can't get next map: %s%s", strerror(errno), |
| 636 | errno == EINVAL ? " -- kernel too old?" : ""); |
Jakub Kicinski | b3b1b65 | 2017-12-22 11:36:05 -0800 | [diff] [blame] | 637 | break; |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | fd = bpf_map_get_fd_by_id(id); |
| 641 | if (fd < 0) { |
Jakub Kicinski | 8207c6d | 2017-12-22 11:36:06 -0800 | [diff] [blame] | 642 | if (errno == ENOENT) |
| 643 | continue; |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 644 | p_err("can't get map by id (%u): %s", |
| 645 | id, strerror(errno)); |
Jakub Kicinski | b3b1b65 | 2017-12-22 11:36:05 -0800 | [diff] [blame] | 646 | break; |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | err = bpf_obj_get_info_by_fd(fd, &info, &len); |
| 650 | if (err) { |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 651 | p_err("can't get map info: %s", strerror(errno)); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 652 | close(fd); |
Jakub Kicinski | b3b1b65 | 2017-12-22 11:36:05 -0800 | [diff] [blame] | 653 | break; |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 654 | } |
| 655 | |
Quentin Monnet | 831a0aa | 2017-10-23 09:24:11 -0700 | [diff] [blame] | 656 | if (json_output) |
| 657 | show_map_close_json(fd, &info); |
| 658 | else |
| 659 | show_map_close_plain(fd, &info); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 660 | } |
Quentin Monnet | 831a0aa | 2017-10-23 09:24:11 -0700 | [diff] [blame] | 661 | if (json_output) |
| 662 | jsonw_end_array(json_wtr); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 663 | |
| 664 | return errno == ENOENT ? 0 : -1; |
| 665 | } |
| 666 | |
Prashant Bhole | 18a781d | 2018-10-09 10:04:51 +0900 | [diff] [blame] | 667 | static int dump_map_elem(int fd, void *key, void *value, |
| 668 | struct bpf_map_info *map_info, struct btf *btf, |
| 669 | json_writer_t *btf_wtr) |
| 670 | { |
| 671 | int num_elems = 0; |
Prashant Bhole | 8ec92dc | 2018-10-09 10:04:52 +0900 | [diff] [blame] | 672 | int lookup_errno; |
Prashant Bhole | 18a781d | 2018-10-09 10:04:51 +0900 | [diff] [blame] | 673 | |
| 674 | if (!bpf_map_lookup_elem(fd, key, value)) { |
| 675 | if (json_output) { |
| 676 | print_entry_json(map_info, key, value, btf); |
| 677 | } else { |
| 678 | if (btf) { |
| 679 | struct btf_dumper d = { |
| 680 | .btf = btf, |
| 681 | .jw = btf_wtr, |
| 682 | .is_plain_text = true, |
| 683 | }; |
| 684 | |
| 685 | do_dump_btf(&d, map_info, key, value); |
| 686 | } else { |
| 687 | print_entry_plain(map_info, key, value); |
| 688 | } |
| 689 | num_elems++; |
| 690 | } |
| 691 | return num_elems; |
| 692 | } |
| 693 | |
| 694 | /* lookup error handling */ |
Prashant Bhole | 8ec92dc | 2018-10-09 10:04:52 +0900 | [diff] [blame] | 695 | lookup_errno = errno; |
| 696 | |
Prashant Bhole | 18a781d | 2018-10-09 10:04:51 +0900 | [diff] [blame] | 697 | if (map_is_map_of_maps(map_info->type) || |
| 698 | map_is_map_of_progs(map_info->type)) |
| 699 | return 0; |
| 700 | |
| 701 | if (json_output) { |
| 702 | jsonw_name(json_wtr, "key"); |
| 703 | print_hex_data_json(key, map_info->key_size); |
| 704 | jsonw_name(json_wtr, "value"); |
| 705 | jsonw_start_object(json_wtr); |
Prashant Bhole | 8ec92dc | 2018-10-09 10:04:52 +0900 | [diff] [blame] | 706 | jsonw_string_field(json_wtr, "error", strerror(lookup_errno)); |
Prashant Bhole | 18a781d | 2018-10-09 10:04:51 +0900 | [diff] [blame] | 707 | jsonw_end_object(json_wtr); |
| 708 | } else { |
David Ahern | bf598a8 | 2018-11-08 13:00:07 -0800 | [diff] [blame] | 709 | if (errno == ENOENT) |
| 710 | print_entry_plain(map_info, key, NULL); |
| 711 | else |
| 712 | print_entry_error(map_info, key, |
| 713 | strerror(lookup_errno)); |
Prashant Bhole | 18a781d | 2018-10-09 10:04:51 +0900 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | return 0; |
| 717 | } |
| 718 | |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 719 | static int do_dump(int argc, char **argv) |
| 720 | { |
Okash Khawaja | 2d3feca | 2018-07-13 21:57:04 -0700 | [diff] [blame] | 721 | struct bpf_map_info info = {}; |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 722 | void *key, *value, *prev_key; |
| 723 | unsigned int num_elems = 0; |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 724 | __u32 len = sizeof(info); |
Okash Khawaja | 2d3feca | 2018-07-13 21:57:04 -0700 | [diff] [blame] | 725 | json_writer_t *btf_wtr; |
| 726 | struct btf *btf = NULL; |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 727 | int err; |
| 728 | int fd; |
| 729 | |
| 730 | if (argc != 2) |
| 731 | usage(); |
| 732 | |
| 733 | fd = map_parse_fd_and_info(&argc, &argv, &info, &len); |
| 734 | if (fd < 0) |
| 735 | return -1; |
| 736 | |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 737 | key = malloc(info.key_size); |
| 738 | value = alloc_value(&info); |
| 739 | if (!key || !value) { |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 740 | p_err("mem alloc failed"); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 741 | err = -1; |
| 742 | goto exit_free; |
| 743 | } |
| 744 | |
| 745 | prev_key = NULL; |
Okash Khawaja | 2d3feca | 2018-07-13 21:57:04 -0700 | [diff] [blame] | 746 | |
Martin KaFai Lau | 1d2f44c | 2018-11-23 16:44:32 -0800 | [diff] [blame] | 747 | err = btf__get_from_id(info.btf_id, &btf); |
Okash Khawaja | 2d3feca | 2018-07-13 21:57:04 -0700 | [diff] [blame] | 748 | if (err) { |
| 749 | p_err("failed to get btf"); |
| 750 | goto exit_free; |
| 751 | } |
| 752 | |
Quentin Monnet | 831a0aa | 2017-10-23 09:24:11 -0700 | [diff] [blame] | 753 | if (json_output) |
| 754 | jsonw_start_array(json_wtr); |
Okash Khawaja | 2d3feca | 2018-07-13 21:57:04 -0700 | [diff] [blame] | 755 | else |
| 756 | if (btf) { |
| 757 | btf_wtr = get_btf_writer(); |
| 758 | if (!btf_wtr) { |
| 759 | p_info("failed to create json writer for btf. falling back to plain output"); |
| 760 | btf__free(btf); |
| 761 | btf = NULL; |
| 762 | } else { |
| 763 | jsonw_start_array(btf_wtr); |
| 764 | } |
| 765 | } |
| 766 | |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 767 | while (true) { |
| 768 | err = bpf_map_get_next_key(fd, prev_key, key); |
| 769 | if (err) { |
| 770 | if (errno == ENOENT) |
| 771 | err = 0; |
| 772 | break; |
| 773 | } |
Prashant Bhole | 18a781d | 2018-10-09 10:04:51 +0900 | [diff] [blame] | 774 | num_elems += dump_map_elem(fd, key, value, &info, btf, btf_wtr); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 775 | prev_key = key; |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 776 | } |
| 777 | |
Quentin Monnet | 831a0aa | 2017-10-23 09:24:11 -0700 | [diff] [blame] | 778 | if (json_output) |
| 779 | jsonw_end_array(json_wtr); |
Okash Khawaja | 2d3feca | 2018-07-13 21:57:04 -0700 | [diff] [blame] | 780 | else if (btf) { |
| 781 | jsonw_end_array(btf_wtr); |
| 782 | jsonw_destroy(&btf_wtr); |
| 783 | } else { |
Quentin Monnet | 831a0aa | 2017-10-23 09:24:11 -0700 | [diff] [blame] | 784 | printf("Found %u element%s\n", num_elems, |
| 785 | num_elems != 1 ? "s" : ""); |
Okash Khawaja | 2d3feca | 2018-07-13 21:57:04 -0700 | [diff] [blame] | 786 | } |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 787 | |
| 788 | exit_free: |
| 789 | free(key); |
| 790 | free(value); |
| 791 | close(fd); |
Okash Khawaja | 2d3feca | 2018-07-13 21:57:04 -0700 | [diff] [blame] | 792 | btf__free(btf); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 793 | |
| 794 | return err; |
| 795 | } |
| 796 | |
| 797 | static int do_update(int argc, char **argv) |
| 798 | { |
| 799 | struct bpf_map_info info = {}; |
| 800 | __u32 len = sizeof(info); |
| 801 | __u32 *value_fd = NULL; |
| 802 | __u32 flags = BPF_ANY; |
| 803 | void *key, *value; |
| 804 | int fd, err; |
| 805 | |
| 806 | if (argc < 2) |
| 807 | usage(); |
| 808 | |
| 809 | fd = map_parse_fd_and_info(&argc, &argv, &info, &len); |
| 810 | if (fd < 0) |
| 811 | return -1; |
| 812 | |
| 813 | key = malloc(info.key_size); |
| 814 | value = alloc_value(&info); |
| 815 | if (!key || !value) { |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 816 | p_err("mem alloc failed"); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 817 | err = -1; |
| 818 | goto exit_free; |
| 819 | } |
| 820 | |
| 821 | err = parse_elem(argv, &info, key, value, info.key_size, |
| 822 | info.value_size, &flags, &value_fd); |
| 823 | if (err) |
| 824 | goto exit_free; |
| 825 | |
| 826 | err = bpf_map_update_elem(fd, key, value, flags); |
| 827 | if (err) { |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 828 | p_err("update failed: %s", strerror(errno)); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 829 | goto exit_free; |
| 830 | } |
| 831 | |
| 832 | exit_free: |
| 833 | if (value_fd) |
| 834 | close(*value_fd); |
| 835 | free(key); |
| 836 | free(value); |
| 837 | close(fd); |
| 838 | |
Quentin Monnet | 004b45c | 2017-10-23 09:24:14 -0700 | [diff] [blame] | 839 | if (!err && json_output) |
| 840 | jsonw_null(json_wtr); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 841 | return err; |
| 842 | } |
| 843 | |
| 844 | static int do_lookup(int argc, char **argv) |
| 845 | { |
| 846 | struct bpf_map_info info = {}; |
| 847 | __u32 len = sizeof(info); |
Okash Khawaja | 2d3feca | 2018-07-13 21:57:04 -0700 | [diff] [blame] | 848 | json_writer_t *btf_wtr; |
| 849 | struct btf *btf = NULL; |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 850 | void *key, *value; |
| 851 | int err; |
| 852 | int fd; |
| 853 | |
| 854 | if (argc < 2) |
| 855 | usage(); |
| 856 | |
| 857 | fd = map_parse_fd_and_info(&argc, &argv, &info, &len); |
| 858 | if (fd < 0) |
| 859 | return -1; |
| 860 | |
| 861 | key = malloc(info.key_size); |
| 862 | value = alloc_value(&info); |
| 863 | if (!key || !value) { |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 864 | p_err("mem alloc failed"); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 865 | err = -1; |
| 866 | goto exit_free; |
| 867 | } |
| 868 | |
| 869 | err = parse_elem(argv, &info, key, NULL, info.key_size, 0, NULL, NULL); |
| 870 | if (err) |
| 871 | goto exit_free; |
| 872 | |
| 873 | err = bpf_map_lookup_elem(fd, key, value); |
Okash Khawaja | 2d3feca | 2018-07-13 21:57:04 -0700 | [diff] [blame] | 874 | if (err) { |
| 875 | if (errno == ENOENT) { |
| 876 | if (json_output) { |
| 877 | jsonw_null(json_wtr); |
| 878 | } else { |
| 879 | printf("key:\n"); |
| 880 | fprint_hex(stdout, key, info.key_size, " "); |
| 881 | printf("\n\nNot found\n"); |
| 882 | } |
Quentin Monnet | 831a0aa | 2017-10-23 09:24:11 -0700 | [diff] [blame] | 883 | } else { |
Okash Khawaja | 2d3feca | 2018-07-13 21:57:04 -0700 | [diff] [blame] | 884 | p_err("lookup failed: %s", strerror(errno)); |
| 885 | } |
| 886 | |
| 887 | goto exit_free; |
| 888 | } |
| 889 | |
| 890 | /* here means bpf_map_lookup_elem() succeeded */ |
Martin KaFai Lau | 1d2f44c | 2018-11-23 16:44:32 -0800 | [diff] [blame] | 891 | err = btf__get_from_id(info.btf_id, &btf); |
Okash Khawaja | 2d3feca | 2018-07-13 21:57:04 -0700 | [diff] [blame] | 892 | if (err) { |
| 893 | p_err("failed to get btf"); |
| 894 | goto exit_free; |
| 895 | } |
| 896 | |
| 897 | if (json_output) { |
| 898 | print_entry_json(&info, key, value, btf); |
| 899 | } else if (btf) { |
| 900 | /* if here json_wtr wouldn't have been initialised, |
| 901 | * so let's create separate writer for btf |
| 902 | */ |
| 903 | btf_wtr = get_btf_writer(); |
| 904 | if (!btf_wtr) { |
| 905 | p_info("failed to create json writer for btf. falling back to plain output"); |
| 906 | btf__free(btf); |
| 907 | btf = NULL; |
| 908 | print_entry_plain(&info, key, value); |
| 909 | } else { |
| 910 | struct btf_dumper d = { |
| 911 | .btf = btf, |
| 912 | .jw = btf_wtr, |
| 913 | .is_plain_text = true, |
| 914 | }; |
| 915 | |
| 916 | do_dump_btf(&d, &info, key, value); |
| 917 | jsonw_destroy(&btf_wtr); |
Quentin Monnet | 831a0aa | 2017-10-23 09:24:11 -0700 | [diff] [blame] | 918 | } |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 919 | } else { |
Okash Khawaja | 2d3feca | 2018-07-13 21:57:04 -0700 | [diff] [blame] | 920 | print_entry_plain(&info, key, value); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 921 | } |
| 922 | |
| 923 | exit_free: |
| 924 | free(key); |
| 925 | free(value); |
| 926 | close(fd); |
Okash Khawaja | 2d3feca | 2018-07-13 21:57:04 -0700 | [diff] [blame] | 927 | btf__free(btf); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 928 | |
| 929 | return err; |
| 930 | } |
| 931 | |
| 932 | static int do_getnext(int argc, char **argv) |
| 933 | { |
| 934 | struct bpf_map_info info = {}; |
| 935 | __u32 len = sizeof(info); |
| 936 | void *key, *nextkey; |
| 937 | int err; |
| 938 | int fd; |
| 939 | |
| 940 | if (argc < 2) |
| 941 | usage(); |
| 942 | |
| 943 | fd = map_parse_fd_and_info(&argc, &argv, &info, &len); |
| 944 | if (fd < 0) |
| 945 | return -1; |
| 946 | |
| 947 | key = malloc(info.key_size); |
| 948 | nextkey = malloc(info.key_size); |
| 949 | if (!key || !nextkey) { |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 950 | p_err("mem alloc failed"); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 951 | err = -1; |
| 952 | goto exit_free; |
| 953 | } |
| 954 | |
| 955 | if (argc) { |
| 956 | err = parse_elem(argv, &info, key, NULL, info.key_size, 0, |
| 957 | NULL, NULL); |
| 958 | if (err) |
| 959 | goto exit_free; |
| 960 | } else { |
| 961 | free(key); |
| 962 | key = NULL; |
| 963 | } |
| 964 | |
| 965 | err = bpf_map_get_next_key(fd, key, nextkey); |
| 966 | if (err) { |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 967 | p_err("can't get next key: %s", strerror(errno)); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 968 | goto exit_free; |
| 969 | } |
| 970 | |
Quentin Monnet | 831a0aa | 2017-10-23 09:24:11 -0700 | [diff] [blame] | 971 | if (json_output) { |
| 972 | jsonw_start_object(json_wtr); |
| 973 | if (key) { |
| 974 | jsonw_name(json_wtr, "key"); |
| 975 | print_hex_data_json(key, info.key_size); |
| 976 | } else { |
| 977 | jsonw_null_field(json_wtr, "key"); |
| 978 | } |
| 979 | jsonw_name(json_wtr, "next_key"); |
| 980 | print_hex_data_json(nextkey, info.key_size); |
| 981 | jsonw_end_object(json_wtr); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 982 | } else { |
Quentin Monnet | 831a0aa | 2017-10-23 09:24:11 -0700 | [diff] [blame] | 983 | if (key) { |
| 984 | printf("key:\n"); |
| 985 | fprint_hex(stdout, key, info.key_size, " "); |
| 986 | printf("\n"); |
| 987 | } else { |
| 988 | printf("key: None\n"); |
| 989 | } |
| 990 | printf("next key:\n"); |
| 991 | fprint_hex(stdout, nextkey, info.key_size, " "); |
| 992 | printf("\n"); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 993 | } |
| 994 | |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 995 | exit_free: |
| 996 | free(nextkey); |
| 997 | free(key); |
| 998 | close(fd); |
| 999 | |
| 1000 | return err; |
| 1001 | } |
| 1002 | |
| 1003 | static int do_delete(int argc, char **argv) |
| 1004 | { |
| 1005 | struct bpf_map_info info = {}; |
| 1006 | __u32 len = sizeof(info); |
| 1007 | void *key; |
| 1008 | int err; |
| 1009 | int fd; |
| 1010 | |
| 1011 | if (argc < 2) |
| 1012 | usage(); |
| 1013 | |
| 1014 | fd = map_parse_fd_and_info(&argc, &argv, &info, &len); |
| 1015 | if (fd < 0) |
| 1016 | return -1; |
| 1017 | |
| 1018 | key = malloc(info.key_size); |
| 1019 | if (!key) { |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 1020 | p_err("mem alloc failed"); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 1021 | err = -1; |
| 1022 | goto exit_free; |
| 1023 | } |
| 1024 | |
| 1025 | err = parse_elem(argv, &info, key, NULL, info.key_size, 0, NULL, NULL); |
| 1026 | if (err) |
| 1027 | goto exit_free; |
| 1028 | |
| 1029 | err = bpf_map_delete_elem(fd, key); |
| 1030 | if (err) |
Quentin Monnet | 9a5ab8b | 2017-10-23 09:24:13 -0700 | [diff] [blame] | 1031 | p_err("delete failed: %s", strerror(errno)); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 1032 | |
| 1033 | exit_free: |
| 1034 | free(key); |
| 1035 | close(fd); |
| 1036 | |
Quentin Monnet | 004b45c | 2017-10-23 09:24:14 -0700 | [diff] [blame] | 1037 | if (!err && json_output) |
| 1038 | jsonw_null(json_wtr); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 1039 | return err; |
| 1040 | } |
| 1041 | |
| 1042 | static int do_pin(int argc, char **argv) |
| 1043 | { |
Quentin Monnet | 004b45c | 2017-10-23 09:24:14 -0700 | [diff] [blame] | 1044 | int err; |
| 1045 | |
| 1046 | err = do_pin_any(argc, argv, bpf_map_get_fd_by_id); |
| 1047 | if (!err && json_output) |
| 1048 | jsonw_null(json_wtr); |
| 1049 | return err; |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 1050 | } |
| 1051 | |
Jakub Kicinski | 0b592b5a | 2018-10-15 16:30:36 -0700 | [diff] [blame] | 1052 | static int do_create(int argc, char **argv) |
| 1053 | { |
| 1054 | struct bpf_create_map_attr attr = { NULL, }; |
| 1055 | const char *pinfile; |
| 1056 | int err, fd; |
| 1057 | |
| 1058 | if (!REQ_ARGS(7)) |
| 1059 | return -1; |
| 1060 | pinfile = GET_ARG(); |
| 1061 | |
| 1062 | while (argc) { |
| 1063 | if (!REQ_ARGS(2)) |
| 1064 | return -1; |
| 1065 | |
| 1066 | if (is_prefix(*argv, "type")) { |
| 1067 | NEXT_ARG(); |
| 1068 | |
| 1069 | if (attr.map_type) { |
| 1070 | p_err("map type already specified"); |
| 1071 | return -1; |
| 1072 | } |
| 1073 | |
| 1074 | attr.map_type = map_type_from_str(*argv); |
| 1075 | if ((int)attr.map_type < 0) { |
| 1076 | p_err("unrecognized map type: %s", *argv); |
| 1077 | return -1; |
| 1078 | } |
| 1079 | NEXT_ARG(); |
| 1080 | } else if (is_prefix(*argv, "name")) { |
| 1081 | NEXT_ARG(); |
| 1082 | attr.name = GET_ARG(); |
| 1083 | } else if (is_prefix(*argv, "key")) { |
| 1084 | if (parse_u32_arg(&argc, &argv, &attr.key_size, |
| 1085 | "key size")) |
| 1086 | return -1; |
| 1087 | } else if (is_prefix(*argv, "value")) { |
| 1088 | if (parse_u32_arg(&argc, &argv, &attr.value_size, |
| 1089 | "value size")) |
| 1090 | return -1; |
| 1091 | } else if (is_prefix(*argv, "entries")) { |
| 1092 | if (parse_u32_arg(&argc, &argv, &attr.max_entries, |
| 1093 | "max entries")) |
| 1094 | return -1; |
| 1095 | } else if (is_prefix(*argv, "flags")) { |
| 1096 | if (parse_u32_arg(&argc, &argv, &attr.map_flags, |
| 1097 | "flags")) |
| 1098 | return -1; |
| 1099 | } else if (is_prefix(*argv, "dev")) { |
| 1100 | NEXT_ARG(); |
| 1101 | |
| 1102 | if (attr.map_ifindex) { |
| 1103 | p_err("offload device already specified"); |
| 1104 | return -1; |
| 1105 | } |
| 1106 | |
| 1107 | attr.map_ifindex = if_nametoindex(*argv); |
| 1108 | if (!attr.map_ifindex) { |
| 1109 | p_err("unrecognized netdevice '%s': %s", |
| 1110 | *argv, strerror(errno)); |
| 1111 | return -1; |
| 1112 | } |
| 1113 | NEXT_ARG(); |
| 1114 | } |
| 1115 | } |
| 1116 | |
| 1117 | if (!attr.name) { |
| 1118 | p_err("map name not specified"); |
| 1119 | return -1; |
| 1120 | } |
| 1121 | |
Quentin Monnet | 8302b9b | 2018-11-07 12:29:30 +0000 | [diff] [blame] | 1122 | set_max_rlimit(); |
| 1123 | |
Jakub Kicinski | 0b592b5a | 2018-10-15 16:30:36 -0700 | [diff] [blame] | 1124 | fd = bpf_create_map_xattr(&attr); |
| 1125 | if (fd < 0) { |
| 1126 | p_err("map create failed: %s", strerror(errno)); |
| 1127 | return -1; |
| 1128 | } |
| 1129 | |
| 1130 | err = do_pin_fd(fd, pinfile); |
| 1131 | close(fd); |
| 1132 | if (err) |
| 1133 | return err; |
| 1134 | |
| 1135 | if (json_output) |
| 1136 | jsonw_null(json_wtr); |
| 1137 | return 0; |
| 1138 | } |
| 1139 | |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 1140 | static int do_help(int argc, char **argv) |
| 1141 | { |
Quentin Monnet | 004b45c | 2017-10-23 09:24:14 -0700 | [diff] [blame] | 1142 | if (json_output) { |
| 1143 | jsonw_null(json_wtr); |
| 1144 | return 0; |
| 1145 | } |
| 1146 | |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 1147 | fprintf(stderr, |
Jakub Kicinski | 6ebe6db | 2018-01-02 14:48:36 -0800 | [diff] [blame] | 1148 | "Usage: %s %s { show | list } [MAP]\n" |
Jakub Kicinski | 0b592b5a | 2018-10-15 16:30:36 -0700 | [diff] [blame] | 1149 | " %s %s create FILE type TYPE key KEY_SIZE value VALUE_SIZE \\\n" |
| 1150 | " entries MAX_ENTRIES name NAME [flags FLAGS] \\\n" |
| 1151 | " [dev NAME]\n" |
Jakub Kicinski | f412eed | 2018-05-03 18:37:16 -0700 | [diff] [blame] | 1152 | " %s %s dump MAP\n" |
| 1153 | " %s %s update MAP key DATA value VALUE [UPDATE_FLAGS]\n" |
| 1154 | " %s %s lookup MAP key DATA\n" |
| 1155 | " %s %s getnext MAP [key DATA]\n" |
| 1156 | " %s %s delete MAP key DATA\n" |
| 1157 | " %s %s pin MAP FILE\n" |
| 1158 | " %s %s event_pipe MAP [cpu N index M]\n" |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 1159 | " %s %s help\n" |
| 1160 | "\n" |
Jakub Kicinski | 3ff5a4d | 2018-07-10 14:43:07 -0700 | [diff] [blame] | 1161 | " " HELP_SPEC_MAP "\n" |
Jakub Kicinski | c642ea2 | 2018-05-03 18:37:14 -0700 | [diff] [blame] | 1162 | " DATA := { [hex] BYTES }\n" |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 1163 | " " HELP_SPEC_PROGRAM "\n" |
Jakub Kicinski | c642ea2 | 2018-05-03 18:37:14 -0700 | [diff] [blame] | 1164 | " VALUE := { DATA | MAP | PROG }\n" |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 1165 | " UPDATE_FLAGS := { any | exist | noexist }\n" |
Jakub Kicinski | 0b592b5a | 2018-10-15 16:30:36 -0700 | [diff] [blame] | 1166 | " TYPE := { hash | array | prog_array | perf_event_array | percpu_hash |\n" |
| 1167 | " percpu_array | stack_trace | cgroup_array | lru_hash |\n" |
| 1168 | " lru_percpu_hash | lpm_trie | array_of_maps | hash_of_maps |\n" |
| 1169 | " devmap | sockmap | cpumap | xskmap | sockhash |\n" |
| 1170 | " cgroup_storage | reuseport_sockarray | percpu_cgroup_storage }\n" |
Quentin Monnet | 0641c3c | 2017-10-23 09:24:16 -0700 | [diff] [blame] | 1171 | " " HELP_SPEC_OPTIONS "\n" |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 1172 | "", |
| 1173 | bin_name, argv[-2], bin_name, argv[-2], bin_name, argv[-2], |
| 1174 | bin_name, argv[-2], bin_name, argv[-2], bin_name, argv[-2], |
Jakub Kicinski | 0b592b5a | 2018-10-15 16:30:36 -0700 | [diff] [blame] | 1175 | bin_name, argv[-2], bin_name, argv[-2], bin_name, argv[-2], |
| 1176 | bin_name, argv[-2]); |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 1177 | |
| 1178 | return 0; |
| 1179 | } |
| 1180 | |
| 1181 | static const struct cmd cmds[] = { |
| 1182 | { "show", do_show }, |
Jakub Kicinski | 6ebe6db | 2018-01-02 14:48:36 -0800 | [diff] [blame] | 1183 | { "list", do_show }, |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 1184 | { "help", do_help }, |
| 1185 | { "dump", do_dump }, |
| 1186 | { "update", do_update }, |
| 1187 | { "lookup", do_lookup }, |
| 1188 | { "getnext", do_getnext }, |
| 1189 | { "delete", do_delete }, |
| 1190 | { "pin", do_pin }, |
Jakub Kicinski | f412eed | 2018-05-03 18:37:16 -0700 | [diff] [blame] | 1191 | { "event_pipe", do_event_pipe }, |
Jakub Kicinski | 0b592b5a | 2018-10-15 16:30:36 -0700 | [diff] [blame] | 1192 | { "create", do_create }, |
Jakub Kicinski | 71bb428 | 2017-10-04 20:10:04 -0700 | [diff] [blame] | 1193 | { 0 } |
| 1194 | }; |
| 1195 | |
| 1196 | int do_map(int argc, char **argv) |
| 1197 | { |
| 1198 | return cmd_select(cmds, argc, argv, do_help); |
| 1199 | } |