Lines Matching refs:fd
40 int fd; in test_hashmap() local
42 fd = bpf_create_map(BPF_MAP_TYPE_HASH, sizeof(key), sizeof(value), in test_hashmap()
44 if (fd < 0) { in test_hashmap()
52 assert(bpf_map_update_elem(fd, &key, &value, BPF_ANY) == 0); in test_hashmap()
56 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) == -1 && in test_hashmap()
61 assert(bpf_map_update_elem(fd, &key, &value, -1) == -1 && in test_hashmap()
65 assert(bpf_map_lookup_elem(fd, &key, &value) == 0 && value == 1234); in test_hashmap()
69 assert(bpf_map_lookup_elem(fd, &key, &value) == -1 && errno == ENOENT); in test_hashmap()
72 assert(bpf_map_update_elem(fd, &key, &value, BPF_EXIST) == -1 && in test_hashmap()
77 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) == 0); in test_hashmap()
83 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) == -1 && in test_hashmap()
88 assert(bpf_map_update_elem(fd, &key, &value, BPF_EXIST) == 0); in test_hashmap()
90 assert(bpf_map_update_elem(fd, &key, &value, BPF_ANY) == 0); in test_hashmap()
92 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) == -1 && in test_hashmap()
97 assert(bpf_map_delete_elem(fd, &key) == -1 && errno == ENOENT); in test_hashmap()
100 assert(bpf_map_get_next_key(fd, NULL, &first_key) == 0 && in test_hashmap()
102 assert(bpf_map_get_next_key(fd, &key, &next_key) == 0 && in test_hashmap()
104 assert(bpf_map_get_next_key(fd, &next_key, &next_key) == 0 && in test_hashmap()
107 assert(bpf_map_get_next_key(fd, &next_key, &next_key) == -1 && in test_hashmap()
112 assert(bpf_map_delete_elem(fd, &key) == 0); in test_hashmap()
114 assert(bpf_map_delete_elem(fd, &key) == 0); in test_hashmap()
115 assert(bpf_map_delete_elem(fd, &key) == -1 && errno == ENOENT); in test_hashmap()
119 assert(bpf_map_get_next_key(fd, NULL, &next_key) == -1 && in test_hashmap()
121 assert(bpf_map_get_next_key(fd, &key, &next_key) == -1 && in test_hashmap()
124 close(fd); in test_hashmap()
129 int fd, i, j; in test_hashmap_sizes() local
133 fd = bpf_create_map(BPF_MAP_TYPE_HASH, i, j, in test_hashmap_sizes()
135 if (fd < 0) { in test_hashmap_sizes()
142 close(fd); in test_hashmap_sizes()
153 int fd, i; in test_hashmap_percpu() local
155 fd = bpf_create_map(BPF_MAP_TYPE_PERCPU_HASH, sizeof(key), in test_hashmap_percpu()
157 if (fd < 0) { in test_hashmap_percpu()
168 assert(bpf_map_update_elem(fd, &key, value, BPF_ANY) == 0); in test_hashmap_percpu()
172 assert(bpf_map_update_elem(fd, &key, value, BPF_NOEXIST) == -1 && in test_hashmap_percpu()
177 assert(bpf_map_update_elem(fd, &key, value, -1) == -1 && in test_hashmap_percpu()
184 assert(bpf_map_lookup_elem(fd, &key, value) == 0 && in test_hashmap_percpu()
189 assert(bpf_map_lookup_elem(fd, &key, value) == -1 && errno == ENOENT); in test_hashmap_percpu()
192 assert(bpf_map_update_elem(fd, &key, value, BPF_EXIST) == -1 && in test_hashmap_percpu()
198 assert(bpf_map_update_elem(fd, &key, value, BPF_NOEXIST) == 0); in test_hashmap_percpu()
205 assert(bpf_map_update_elem(fd, &key, value, BPF_NOEXIST) == -1 && in test_hashmap_percpu()
209 assert(bpf_map_delete_elem(fd, &key) == -1 && errno == ENOENT); in test_hashmap_percpu()
212 assert(bpf_map_get_next_key(fd, NULL, &first_key) == 0 && in test_hashmap_percpu()
214 while (!bpf_map_get_next_key(fd, &key, &next_key)) { in test_hashmap_percpu()
222 assert(bpf_map_lookup_elem(fd, &next_key, value) == 0); in test_hashmap_percpu()
233 assert(bpf_map_update_elem(fd, &key, value, BPF_EXIST) == 0); in test_hashmap_percpu()
237 assert(bpf_map_delete_elem(fd, &key) == 0); in test_hashmap_percpu()
239 assert(bpf_map_delete_elem(fd, &key) == 0); in test_hashmap_percpu()
240 assert(bpf_map_delete_elem(fd, &key) == -1 && errno == ENOENT); in test_hashmap_percpu()
244 assert(bpf_map_get_next_key(fd, NULL, &next_key) == -1 && in test_hashmap_percpu()
246 assert(bpf_map_get_next_key(fd, &key, &next_key) == -1 && in test_hashmap_percpu()
249 close(fd); in test_hashmap_percpu()
254 int i, fd, ret; in helper_fill_hashmap() local
257 fd = bpf_create_map(BPF_MAP_TYPE_HASH, sizeof(key), sizeof(value), in helper_fill_hashmap()
259 CHECK(fd < 0, in helper_fill_hashmap()
265 ret = bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST); in helper_fill_hashmap()
271 return fd; in helper_fill_hashmap()
276 int fd, i, max_entries = 1000; in test_hashmap_walk() local
280 fd = helper_fill_hashmap(max_entries); in test_hashmap_walk()
282 for (i = 0; bpf_map_get_next_key(fd, !i ? NULL : &key, in test_hashmap_walk()
285 assert(bpf_map_lookup_elem(fd, &key, &value) == 0); in test_hashmap_walk()
290 assert(bpf_map_get_next_key(fd, NULL, &key) == 0); in test_hashmap_walk()
292 next_key_valid = bpf_map_get_next_key(fd, &key, &next_key) == 0; in test_hashmap_walk()
293 assert(bpf_map_lookup_elem(fd, &key, &value) == 0); in test_hashmap_walk()
295 assert(bpf_map_update_elem(fd, &key, &value, BPF_EXIST) == 0); in test_hashmap_walk()
301 for (i = 0; bpf_map_get_next_key(fd, !i ? NULL : &key, in test_hashmap_walk()
304 assert(bpf_map_lookup_elem(fd, &key, &value) == 0); in test_hashmap_walk()
309 close(fd); in test_hashmap_walk()
347 int key, next_key, fd; in test_arraymap() local
350 fd = bpf_create_map(BPF_MAP_TYPE_ARRAY, sizeof(key), sizeof(value), in test_arraymap()
352 if (fd < 0) { in test_arraymap()
360 assert(bpf_map_update_elem(fd, &key, &value, BPF_ANY) == 0); in test_arraymap()
363 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) == -1 && in test_arraymap()
367 assert(bpf_map_lookup_elem(fd, &key, &value) == 0 && value == 1234); in test_arraymap()
371 assert(bpf_map_lookup_elem(fd, &key, &value) == 0 && value == 0); in test_arraymap()
377 assert(bpf_map_update_elem(fd, &key, &value, BPF_EXIST) == -1 && in test_arraymap()
381 assert(bpf_map_lookup_elem(fd, &key, &value) == -1 && errno == ENOENT); in test_arraymap()
384 assert(bpf_map_get_next_key(fd, NULL, &next_key) == 0 && in test_arraymap()
386 assert(bpf_map_get_next_key(fd, &key, &next_key) == 0 && in test_arraymap()
388 assert(bpf_map_get_next_key(fd, &next_key, &next_key) == 0 && in test_arraymap()
390 assert(bpf_map_get_next_key(fd, &next_key, &next_key) == -1 && in test_arraymap()
395 assert(bpf_map_delete_elem(fd, &key) == -1 && errno == EINVAL); in test_arraymap()
397 close(fd); in test_arraymap()
404 int key, next_key, fd, i; in test_arraymap_percpu() local
406 fd = bpf_create_map(BPF_MAP_TYPE_PERCPU_ARRAY, sizeof(key), in test_arraymap_percpu()
408 if (fd < 0) { in test_arraymap_percpu()
418 assert(bpf_map_update_elem(fd, &key, values, BPF_ANY) == 0); in test_arraymap_percpu()
421 assert(bpf_map_update_elem(fd, &key, values, BPF_NOEXIST) == -1 && in test_arraymap_percpu()
425 assert(bpf_map_lookup_elem(fd, &key, values) == 0 && in test_arraymap_percpu()
430 assert(bpf_map_lookup_elem(fd, &key, values) == 0 && in test_arraymap_percpu()
436 assert(bpf_map_update_elem(fd, &key, values, BPF_EXIST) == -1 && in test_arraymap_percpu()
440 assert(bpf_map_lookup_elem(fd, &key, values) == -1 && errno == ENOENT); in test_arraymap_percpu()
443 assert(bpf_map_get_next_key(fd, NULL, &next_key) == 0 && in test_arraymap_percpu()
445 assert(bpf_map_get_next_key(fd, &key, &next_key) == 0 && in test_arraymap_percpu()
447 assert(bpf_map_get_next_key(fd, &next_key, &next_key) == 0 && in test_arraymap_percpu()
449 assert(bpf_map_get_next_key(fd, &next_key, &next_key) == -1 && in test_arraymap_percpu()
454 assert(bpf_map_delete_elem(fd, &key) == -1 && errno == EINVAL); in test_arraymap_percpu()
456 close(fd); in test_arraymap_percpu()
467 int key, fd, i; in test_arraymap_percpu_many_keys() local
469 fd = bpf_create_map(BPF_MAP_TYPE_PERCPU_ARRAY, sizeof(key), in test_arraymap_percpu_many_keys()
471 if (fd < 0) { in test_arraymap_percpu_many_keys()
481 assert(bpf_map_update_elem(fd, &key, values, BPF_ANY) == 0); in test_arraymap_percpu_many_keys()
487 assert(bpf_map_lookup_elem(fd, &key, values) == 0); in test_arraymap_percpu_many_keys()
493 close(fd); in test_arraymap_percpu_many_keys()
498 int fd; in test_devmap() local
501 fd = bpf_create_map(BPF_MAP_TYPE_DEVMAP, sizeof(key), sizeof(value), in test_devmap()
503 if (fd < 0) { in test_devmap()
508 close(fd); in test_devmap()
513 int fd; in test_devmap_hash() local
516 fd = bpf_create_map(BPF_MAP_TYPE_DEVMAP_HASH, sizeof(key), sizeof(value), in test_devmap_hash()
518 if (fd < 0) { in test_devmap_hash()
523 close(fd); in test_devmap_hash()
530 int fd, i; in test_queuemap() local
537 fd = bpf_create_map(BPF_MAP_TYPE_QUEUE, 4, sizeof(val), MAP_SIZE, in test_queuemap()
539 assert(fd < 0 && errno == EINVAL); in test_queuemap()
541 fd = bpf_create_map(BPF_MAP_TYPE_QUEUE, 0, sizeof(val), MAP_SIZE, in test_queuemap()
545 assert(fd < 0 && errno == EINVAL); in test_queuemap()
548 if (fd < 0) { in test_queuemap()
555 assert(bpf_map_update_elem(fd, NULL, &vals[i], 0) == 0); in test_queuemap()
558 assert(bpf_map_update_elem(fd, NULL, &val, 0) == -1 && in test_queuemap()
562 assert(bpf_map_lookup_elem(fd, NULL, &val) == 0 && val == vals[0]); in test_queuemap()
566 assert(bpf_map_update_elem(fd, NULL, &vals[i], BPF_EXIST) == 0); in test_queuemap()
570 assert(bpf_map_lookup_and_delete_elem(fd, NULL, &val) == 0 && in test_queuemap()
574 assert(bpf_map_lookup_and_delete_elem(fd, NULL, &val) == -1 && in test_queuemap()
578 assert(bpf_map_delete_elem(fd, NULL) == -1 && errno == EINVAL); in test_queuemap()
579 assert(bpf_map_get_next_key(fd, NULL, NULL) == -1 && errno == EINVAL); in test_queuemap()
581 close(fd); in test_queuemap()
588 int fd, i; in test_stackmap() local
595 fd = bpf_create_map(BPF_MAP_TYPE_STACK, 4, sizeof(val), MAP_SIZE, in test_stackmap()
597 assert(fd < 0 && errno == EINVAL); in test_stackmap()
599 fd = bpf_create_map(BPF_MAP_TYPE_STACK, 0, sizeof(val), MAP_SIZE, in test_stackmap()
603 assert(fd < 0 && errno == EINVAL); in test_stackmap()
606 if (fd < 0) { in test_stackmap()
613 assert(bpf_map_update_elem(fd, NULL, &vals[i], 0) == 0); in test_stackmap()
616 assert(bpf_map_update_elem(fd, NULL, &val, 0) == -1 && in test_stackmap()
620 assert(bpf_map_lookup_elem(fd, NULL, &val) == 0 && val == vals[i - 1]); in test_stackmap()
624 assert(bpf_map_update_elem(fd, NULL, &vals[i], BPF_EXIST) == 0); in test_stackmap()
628 assert(bpf_map_lookup_and_delete_elem(fd, NULL, &val) == 0 && in test_stackmap()
632 assert(bpf_map_lookup_and_delete_elem(fd, NULL, &val) == -1 && in test_stackmap()
636 assert(bpf_map_delete_elem(fd, NULL) == -1 && errno == EINVAL); in test_stackmap()
637 assert(bpf_map_get_next_key(fd, NULL, NULL) == -1 && errno == EINVAL); in test_stackmap()
639 close(fd); in test_stackmap()
654 int err, i, fd, udp, sfd[6] = {0xdeadbeef}; in test_sockmap() local
729 fd = bpf_create_map(BPF_MAP_TYPE_SOCKMAP, in test_sockmap()
732 if (fd < 0) { in test_sockmap()
742 printf("Failed to create sockmap %i\n", fd); in test_sockmap()
749 err = bpf_map_update_elem(fd, &i, &udp, BPF_ANY); in test_sockmap()
758 err = bpf_map_update_elem(fd, &i, &sfd[i], BPF_ANY); in test_sockmap()
767 err = bpf_prog_attach(-1, fd, BPF_SK_SKB_STREAM_PARSER, 0); in test_sockmap()
773 err = bpf_prog_attach(-1, fd, BPF_SK_SKB_STREAM_VERDICT, 0); in test_sockmap()
779 err = bpf_prog_attach(-1, fd, BPF_SK_MSG_VERDICT, 0); in test_sockmap()
785 err = bpf_prog_attach(-1, fd, __MAX_BPF_ATTACH_TYPE, 0); in test_sockmap()
791 err = bpf_prog_detach(fd, BPF_SK_SKB_STREAM_PARSER); in test_sockmap()
797 err = bpf_prog_detach(fd, BPF_SK_SKB_STREAM_VERDICT); in test_sockmap()
803 err = bpf_prog_detach(fd, BPF_SK_MSG_VERDICT); in test_sockmap()
809 err = bpf_prog_detach(fd, __MAX_BPF_ATTACH_TYPE); in test_sockmap()
1005 err = bpf_map_update_elem(fd, &i, &sfd[i], BPF_NOEXIST); in test_sockmap()
1011 err = bpf_map_update_elem(fd, &i, &sfd[i], BPF_ANY); in test_sockmap()
1017 err = bpf_map_update_elem(fd, &i, &sfd[i], BPF_EXIST); in test_sockmap()
1025 err = bpf_map_delete_elem(fd, &i); in test_sockmap()
1033 err = bpf_prog_attach(parse_prog, fd, in test_sockmap()
1039 err = bpf_prog_attach(verdict_prog, fd, in test_sockmap()
1047 err = bpf_map_update_elem(fd, &i, &sfd[i], BPF_ANY); in test_sockmap()
1053 err = bpf_map_update_elem(fd, &i, &sfd[i], BPF_NOEXIST); in test_sockmap()
1059 err = bpf_map_update_elem(fd, &i, &sfd[i], BPF_EXIST); in test_sockmap()
1117 close(fd); in test_sockmap()
1134 close(fd); in test_sockmap()
1143 int mim_fd, fd, err; in test_map_in_map() local
1148 fd = bpf_create_map(BPF_MAP_TYPE_HASH, sizeof(int), sizeof(int), in test_map_in_map()
1150 if (fd < 0) { in test_map_in_map()
1160 err = bpf_map__set_inner_map_fd(map, fd); in test_map_in_map()
1171 err = bpf_map__set_inner_map_fd(map, fd); in test_map_in_map()
1190 err = bpf_map_update_elem(mim_fd, &pos, &fd, 0); in test_map_in_map()
1207 err = bpf_map_update_elem(mim_fd, &pos, &fd, 0); in test_map_in_map()
1213 close(fd); in test_map_in_map()
1218 close(fd); in test_map_in_map()
1231 int fd, i, value; in test_map_large() local
1233 fd = bpf_create_map(BPF_MAP_TYPE_HASH, sizeof(key), sizeof(value), in test_map_large()
1235 if (fd < 0) { in test_map_large()
1244 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) == 0); in test_map_large()
1248 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) == -1 && in test_map_large()
1252 assert(bpf_map_get_next_key(fd, NULL, &key) == 0); in test_map_large()
1255 assert(bpf_map_get_next_key(fd, &key, &key) == 0); in test_map_large()
1256 assert(bpf_map_get_next_key(fd, &key, &key) == -1 && errno == ENOENT); in test_map_large()
1259 assert(bpf_map_lookup_elem(fd, &key, &value) == 0 && value == 0); in test_map_large()
1261 assert(bpf_map_lookup_elem(fd, &key, &value) == -1 && errno == ENOENT); in test_map_large()
1263 close(fd); in test_map_large()
1317 int fd = ((int *)data)[0]; in test_update_delete() local
1324 assert(bpf_map_update_elem(fd, &key, &value, in test_update_delete()
1326 assert(bpf_map_update_elem(fd, &key, &value, in test_update_delete()
1329 assert(bpf_map_delete_elem(fd, &key) == 0); in test_update_delete()
1336 int i, fd, key = 0, value = 0; in test_map_parallel() local
1339 fd = bpf_create_map(BPF_MAP_TYPE_HASH, sizeof(key), sizeof(value), in test_map_parallel()
1341 if (fd < 0) { in test_map_parallel()
1352 data[0] = fd; in test_map_parallel()
1357 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) == -1 && in test_map_parallel()
1361 assert(bpf_map_get_next_key(fd, NULL, &key) == 0); in test_map_parallel()
1364 assert(bpf_map_get_next_key(fd, &key, &key) == 0); in test_map_parallel()
1365 assert(bpf_map_get_next_key(fd, &key, &key) == -1 && errno == ENOENT); in test_map_parallel()
1371 assert(bpf_map_lookup_elem(fd, &key, &value) == 0 && in test_map_parallel()
1381 assert(bpf_map_get_next_key(fd, NULL, &key) == -1 && errno == ENOENT); in test_map_parallel()
1382 assert(bpf_map_get_next_key(fd, &key, &key) == -1 && errno == ENOENT); in test_map_parallel()
1387 int fd, key = 0, value = 0; in test_map_rdonly() local
1389 fd = bpf_create_map(BPF_MAP_TYPE_HASH, sizeof(key), sizeof(value), in test_map_rdonly()
1391 if (fd < 0) { in test_map_rdonly()
1400 assert(bpf_map_update_elem(fd, &key, &value, BPF_ANY) == -1 && in test_map_rdonly()
1404 assert(bpf_map_lookup_elem(fd, &key, &value) == -1 && errno == ENOENT); in test_map_rdonly()
1405 assert(bpf_map_get_next_key(fd, &key, &value) == -1 && errno == ENOENT); in test_map_rdonly()
1407 close(fd); in test_map_rdonly()
1412 int fd, key = 0, value = 0; in test_map_wronly_hash() local
1414 fd = bpf_create_map(BPF_MAP_TYPE_HASH, sizeof(key), sizeof(value), in test_map_wronly_hash()
1416 if (fd < 0) { in test_map_wronly_hash()
1425 assert(bpf_map_update_elem(fd, &key, &value, BPF_ANY) == 0); in test_map_wronly_hash()
1428 assert(bpf_map_lookup_elem(fd, &key, &value) == -1 && errno == EPERM); in test_map_wronly_hash()
1429 assert(bpf_map_get_next_key(fd, &key, &value) == -1 && errno == EPERM); in test_map_wronly_hash()
1431 close(fd); in test_map_wronly_hash()
1436 int fd, value = 0; in test_map_wronly_stack_or_queue() local
1440 fd = bpf_create_map(map_type, 0, sizeof(value), MAP_SIZE, in test_map_wronly_stack_or_queue()
1444 assert(fd < 0 && errno == EINVAL); in test_map_wronly_stack_or_queue()
1447 if (fd < 0) { in test_map_wronly_stack_or_queue()
1453 assert(bpf_map_update_elem(fd, NULL, &value, BPF_ANY) == 0); in test_map_wronly_stack_or_queue()
1456 assert(bpf_map_lookup_elem(fd, NULL, &value) == -1 && errno == EPERM); in test_map_wronly_stack_or_queue()
1459 assert(bpf_map_lookup_and_delete_elem(fd, NULL, &value) == -1 && in test_map_wronly_stack_or_queue()
1462 close(fd); in test_map_wronly_stack_or_queue()
1568 int fd; in test_reuseport_array() local
1713 fd = fd64; in test_reuseport_array()
1714 err = bpf_map_update_elem(map_fd, &index3, &fd, BPF_NOEXIST); in test_reuseport_array()
1721 close(fd); in test_reuseport_array()