• Home
  • Raw
  • Download

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) < 0 && in test_hashmap()
61 assert(bpf_map_update_elem(fd, &key, &value, -1) < 0 && in test_hashmap()
65 assert(bpf_map_lookup_elem(fd, &key, &value) == 0 && value == 1234); in test_hashmap()
70 assert(bpf_map_update_elem(fd, &key, &value, BPF_ANY) == 0); in test_hashmap()
73 assert(bpf_map_lookup_and_delete_elem(fd, &key, &value) == 0 && value == 1234); in test_hashmap()
76 assert(bpf_map_lookup_elem(fd, &key, &value) < 0 && errno == ENOENT); in test_hashmap()
79 assert(bpf_map_update_elem(fd, &key, &value, BPF_EXIST) < 0 && in test_hashmap()
84 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) == 0); in test_hashmap()
90 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) < 0 && in test_hashmap()
95 assert(bpf_map_update_elem(fd, &key, &value, BPF_EXIST) == 0); in test_hashmap()
97 assert(bpf_map_update_elem(fd, &key, &value, BPF_ANY) == 0); in test_hashmap()
99 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) < 0 && in test_hashmap()
104 assert(bpf_map_delete_elem(fd, &key) < 0 && errno == ENOENT); in test_hashmap()
107 assert(bpf_map_get_next_key(fd, NULL, &first_key) == 0 && in test_hashmap()
109 assert(bpf_map_get_next_key(fd, &key, &next_key) == 0 && in test_hashmap()
111 assert(bpf_map_get_next_key(fd, &next_key, &next_key) == 0 && in test_hashmap()
114 assert(bpf_map_get_next_key(fd, &next_key, &next_key) < 0 && in test_hashmap()
119 assert(bpf_map_delete_elem(fd, &key) == 0); in test_hashmap()
121 assert(bpf_map_delete_elem(fd, &key) == 0); in test_hashmap()
122 assert(bpf_map_delete_elem(fd, &key) < 0 && errno == ENOENT); in test_hashmap()
126 assert(bpf_map_get_next_key(fd, NULL, &next_key) < 0 && in test_hashmap()
128 assert(bpf_map_get_next_key(fd, &key, &next_key) < 0 && in test_hashmap()
131 close(fd); in test_hashmap()
136 int fd, i, j; in test_hashmap_sizes() local
140 fd = bpf_create_map(BPF_MAP_TYPE_HASH, i, j, in test_hashmap_sizes()
142 if (fd < 0) { in test_hashmap_sizes()
149 close(fd); in test_hashmap_sizes()
160 int fd, i; in test_hashmap_percpu() local
162 fd = bpf_create_map(BPF_MAP_TYPE_PERCPU_HASH, sizeof(key), in test_hashmap_percpu()
164 if (fd < 0) { in test_hashmap_percpu()
175 assert(bpf_map_update_elem(fd, &key, value, BPF_ANY) == 0); in test_hashmap_percpu()
178 assert(bpf_map_lookup_and_delete_elem(fd, &key, value) == 0 && in test_hashmap_percpu()
185 assert(bpf_map_update_elem(fd, &key, value, BPF_NOEXIST) == 0); in test_hashmap_percpu()
189 assert(bpf_map_update_elem(fd, &key, value, BPF_NOEXIST) < 0 && in test_hashmap_percpu()
194 assert(bpf_map_update_elem(fd, &key, value, -1) < 0 && in test_hashmap_percpu()
201 assert(bpf_map_lookup_elem(fd, &key, value) == 0 && in test_hashmap_percpu()
206 assert(bpf_map_lookup_elem(fd, &key, value) < 0 && errno == ENOENT); in test_hashmap_percpu()
209 assert(bpf_map_update_elem(fd, &key, value, BPF_EXIST) < 0 && in test_hashmap_percpu()
215 assert(bpf_map_update_elem(fd, &key, value, BPF_NOEXIST) == 0); in test_hashmap_percpu()
222 assert(bpf_map_update_elem(fd, &key, value, BPF_NOEXIST) < 0 && in test_hashmap_percpu()
226 assert(bpf_map_delete_elem(fd, &key) < 0 && errno == ENOENT); in test_hashmap_percpu()
229 assert(bpf_map_get_next_key(fd, NULL, &first_key) == 0 && in test_hashmap_percpu()
231 while (!bpf_map_get_next_key(fd, &key, &next_key)) { in test_hashmap_percpu()
239 assert(bpf_map_lookup_elem(fd, &next_key, value) == 0); in test_hashmap_percpu()
250 assert(bpf_map_update_elem(fd, &key, value, BPF_EXIST) == 0); in test_hashmap_percpu()
254 assert(bpf_map_delete_elem(fd, &key) == 0); in test_hashmap_percpu()
256 assert(bpf_map_delete_elem(fd, &key) == 0); in test_hashmap_percpu()
257 assert(bpf_map_delete_elem(fd, &key) < 0 && errno == ENOENT); in test_hashmap_percpu()
261 assert(bpf_map_get_next_key(fd, NULL, &next_key) < 0 && in test_hashmap_percpu()
263 assert(bpf_map_get_next_key(fd, &key, &next_key) < 0 && in test_hashmap_percpu()
266 close(fd); in test_hashmap_percpu()
271 int i, fd, ret; in helper_fill_hashmap() local
274 fd = bpf_create_map(BPF_MAP_TYPE_HASH, sizeof(key), sizeof(value), in helper_fill_hashmap()
276 CHECK(fd < 0, in helper_fill_hashmap()
282 ret = bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST); in helper_fill_hashmap()
288 return fd; in helper_fill_hashmap()
293 int fd, i, max_entries = 1000; in test_hashmap_walk() local
297 fd = helper_fill_hashmap(max_entries); in test_hashmap_walk()
299 for (i = 0; bpf_map_get_next_key(fd, !i ? NULL : &key, in test_hashmap_walk()
302 assert(bpf_map_lookup_elem(fd, &key, &value) == 0); in test_hashmap_walk()
307 assert(bpf_map_get_next_key(fd, NULL, &key) == 0); in test_hashmap_walk()
309 next_key_valid = bpf_map_get_next_key(fd, &key, &next_key) == 0; in test_hashmap_walk()
310 assert(bpf_map_lookup_elem(fd, &key, &value) == 0); in test_hashmap_walk()
312 assert(bpf_map_update_elem(fd, &key, &value, BPF_EXIST) == 0); in test_hashmap_walk()
318 for (i = 0; bpf_map_get_next_key(fd, !i ? NULL : &key, in test_hashmap_walk()
321 assert(bpf_map_lookup_elem(fd, &key, &value) == 0); in test_hashmap_walk()
326 close(fd); in test_hashmap_walk()
364 int key, next_key, fd; in test_arraymap() local
367 fd = bpf_create_map(BPF_MAP_TYPE_ARRAY, sizeof(key), sizeof(value), in test_arraymap()
369 if (fd < 0) { in test_arraymap()
377 assert(bpf_map_update_elem(fd, &key, &value, BPF_ANY) == 0); in test_arraymap()
380 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) < 0 && in test_arraymap()
384 assert(bpf_map_lookup_elem(fd, &key, &value) == 0 && value == 1234); in test_arraymap()
388 assert(bpf_map_lookup_elem(fd, &key, &value) == 0 && value == 0); in test_arraymap()
394 assert(bpf_map_update_elem(fd, &key, &value, BPF_EXIST) < 0 && in test_arraymap()
398 assert(bpf_map_lookup_elem(fd, &key, &value) < 0 && errno == ENOENT); in test_arraymap()
401 assert(bpf_map_get_next_key(fd, NULL, &next_key) == 0 && in test_arraymap()
403 assert(bpf_map_get_next_key(fd, &key, &next_key) == 0 && in test_arraymap()
405 assert(bpf_map_get_next_key(fd, &next_key, &next_key) == 0 && in test_arraymap()
407 assert(bpf_map_get_next_key(fd, &next_key, &next_key) < 0 && in test_arraymap()
412 assert(bpf_map_delete_elem(fd, &key) < 0 && errno == EINVAL); in test_arraymap()
414 close(fd); in test_arraymap()
421 int key, next_key, fd, i; in test_arraymap_percpu() local
423 fd = bpf_create_map(BPF_MAP_TYPE_PERCPU_ARRAY, sizeof(key), in test_arraymap_percpu()
425 if (fd < 0) { in test_arraymap_percpu()
435 assert(bpf_map_update_elem(fd, &key, values, BPF_ANY) == 0); in test_arraymap_percpu()
438 assert(bpf_map_update_elem(fd, &key, values, BPF_NOEXIST) < 0 && in test_arraymap_percpu()
442 assert(bpf_map_lookup_elem(fd, &key, values) == 0 && in test_arraymap_percpu()
447 assert(bpf_map_lookup_elem(fd, &key, values) == 0 && in test_arraymap_percpu()
453 assert(bpf_map_update_elem(fd, &key, values, BPF_EXIST) < 0 && in test_arraymap_percpu()
457 assert(bpf_map_lookup_elem(fd, &key, values) < 0 && errno == ENOENT); in test_arraymap_percpu()
460 assert(bpf_map_get_next_key(fd, NULL, &next_key) == 0 && in test_arraymap_percpu()
462 assert(bpf_map_get_next_key(fd, &key, &next_key) == 0 && in test_arraymap_percpu()
464 assert(bpf_map_get_next_key(fd, &next_key, &next_key) == 0 && in test_arraymap_percpu()
466 assert(bpf_map_get_next_key(fd, &next_key, &next_key) < 0 && in test_arraymap_percpu()
471 assert(bpf_map_delete_elem(fd, &key) < 0 && errno == EINVAL); in test_arraymap_percpu()
473 close(fd); in test_arraymap_percpu()
484 int key, fd, i; in test_arraymap_percpu_many_keys() local
486 fd = bpf_create_map(BPF_MAP_TYPE_PERCPU_ARRAY, sizeof(key), in test_arraymap_percpu_many_keys()
488 if (fd < 0) { in test_arraymap_percpu_many_keys()
498 assert(bpf_map_update_elem(fd, &key, values, BPF_ANY) == 0); in test_arraymap_percpu_many_keys()
504 assert(bpf_map_lookup_elem(fd, &key, values) == 0); in test_arraymap_percpu_many_keys()
510 close(fd); in test_arraymap_percpu_many_keys()
515 int fd; in test_devmap() local
518 fd = bpf_create_map(BPF_MAP_TYPE_DEVMAP, sizeof(key), sizeof(value), in test_devmap()
520 if (fd < 0) { in test_devmap()
525 close(fd); in test_devmap()
530 int fd; in test_devmap_hash() local
533 fd = bpf_create_map(BPF_MAP_TYPE_DEVMAP_HASH, sizeof(key), sizeof(value), in test_devmap_hash()
535 if (fd < 0) { in test_devmap_hash()
540 close(fd); in test_devmap_hash()
547 int fd, i; in test_queuemap() local
554 fd = bpf_create_map(BPF_MAP_TYPE_QUEUE, 4, sizeof(val), MAP_SIZE, in test_queuemap()
556 assert(fd < 0 && errno == EINVAL); in test_queuemap()
558 fd = bpf_create_map(BPF_MAP_TYPE_QUEUE, 0, sizeof(val), MAP_SIZE, in test_queuemap()
562 assert(fd < 0 && errno == EINVAL); in test_queuemap()
565 if (fd < 0) { in test_queuemap()
572 assert(bpf_map_update_elem(fd, NULL, &vals[i], 0) == 0); in test_queuemap()
575 assert(bpf_map_update_elem(fd, NULL, &val, 0) < 0 && in test_queuemap()
579 assert(bpf_map_lookup_elem(fd, NULL, &val) == 0 && val == vals[0]); in test_queuemap()
583 assert(bpf_map_update_elem(fd, NULL, &vals[i], BPF_EXIST) == 0); in test_queuemap()
587 assert(bpf_map_lookup_and_delete_elem(fd, NULL, &val) == 0 && in test_queuemap()
591 assert(bpf_map_lookup_and_delete_elem(fd, NULL, &val) < 0 && in test_queuemap()
595 assert(bpf_map_delete_elem(fd, NULL) < 0 && errno == EINVAL); in test_queuemap()
596 assert(bpf_map_get_next_key(fd, NULL, NULL) < 0 && errno == EINVAL); in test_queuemap()
598 close(fd); in test_queuemap()
605 int fd, i; in test_stackmap() local
612 fd = bpf_create_map(BPF_MAP_TYPE_STACK, 4, sizeof(val), MAP_SIZE, in test_stackmap()
614 assert(fd < 0 && errno == EINVAL); in test_stackmap()
616 fd = bpf_create_map(BPF_MAP_TYPE_STACK, 0, sizeof(val), MAP_SIZE, in test_stackmap()
620 assert(fd < 0 && errno == EINVAL); in test_stackmap()
623 if (fd < 0) { in test_stackmap()
630 assert(bpf_map_update_elem(fd, NULL, &vals[i], 0) == 0); in test_stackmap()
633 assert(bpf_map_update_elem(fd, NULL, &val, 0) < 0 && in test_stackmap()
637 assert(bpf_map_lookup_elem(fd, NULL, &val) == 0 && val == vals[i - 1]); in test_stackmap()
641 assert(bpf_map_update_elem(fd, NULL, &vals[i], BPF_EXIST) == 0); in test_stackmap()
645 assert(bpf_map_lookup_and_delete_elem(fd, NULL, &val) == 0 && in test_stackmap()
649 assert(bpf_map_lookup_and_delete_elem(fd, NULL, &val) < 0 && in test_stackmap()
653 assert(bpf_map_delete_elem(fd, NULL) < 0 && errno == EINVAL); in test_stackmap()
654 assert(bpf_map_get_next_key(fd, NULL, NULL) < 0 && errno == EINVAL); in test_stackmap()
656 close(fd); in test_stackmap()
671 int err, i, fd, udp, sfd[6] = {0xdeadbeef}; in test_sockmap() local
746 fd = bpf_create_map(BPF_MAP_TYPE_SOCKMAP, in test_sockmap()
749 if (fd < 0) { in test_sockmap()
759 printf("Failed to create sockmap %i\n", fd); in test_sockmap()
766 err = bpf_map_update_elem(fd, &i, &udp, BPF_ANY); in test_sockmap()
775 err = bpf_map_update_elem(fd, &i, &sfd[i], BPF_ANY); in test_sockmap()
784 err = bpf_prog_attach(-1, fd, BPF_SK_SKB_STREAM_PARSER, 0); in test_sockmap()
790 err = bpf_prog_attach(-1, fd, BPF_SK_SKB_STREAM_VERDICT, 0); in test_sockmap()
796 err = bpf_prog_attach(-1, fd, BPF_SK_MSG_VERDICT, 0); in test_sockmap()
802 err = bpf_prog_attach(-1, fd, __MAX_BPF_ATTACH_TYPE, 0); in test_sockmap()
808 err = bpf_prog_detach(fd, BPF_SK_SKB_STREAM_PARSER); in test_sockmap()
814 err = bpf_prog_detach(fd, BPF_SK_SKB_STREAM_VERDICT); in test_sockmap()
820 err = bpf_prog_detach(fd, BPF_SK_MSG_VERDICT); in test_sockmap()
826 err = bpf_prog_detach(fd, __MAX_BPF_ATTACH_TYPE); in test_sockmap()
1022 err = bpf_map_update_elem(fd, &i, &sfd[i], BPF_NOEXIST); in test_sockmap()
1028 err = bpf_map_update_elem(fd, &i, &sfd[i], BPF_ANY); in test_sockmap()
1034 err = bpf_map_update_elem(fd, &i, &sfd[i], BPF_EXIST); in test_sockmap()
1042 err = bpf_map_delete_elem(fd, &i); in test_sockmap()
1050 err = bpf_prog_attach(parse_prog, fd, in test_sockmap()
1056 err = bpf_prog_attach(verdict_prog, fd, in test_sockmap()
1064 err = bpf_map_update_elem(fd, &i, &sfd[i], BPF_ANY); in test_sockmap()
1070 err = bpf_map_update_elem(fd, &i, &sfd[i], BPF_NOEXIST); in test_sockmap()
1076 err = bpf_map_update_elem(fd, &i, &sfd[i], BPF_EXIST); in test_sockmap()
1134 close(fd); in test_sockmap()
1151 close(fd); in test_sockmap()
1161 int mim_fd, fd, err; in test_map_in_map() local
1170 fd = bpf_create_map(BPF_MAP_TYPE_HASH, sizeof(int), sizeof(int), in test_map_in_map()
1172 if (fd < 0) { in test_map_in_map()
1182 err = bpf_map__set_inner_map_fd(map, fd); in test_map_in_map()
1193 err = bpf_map__set_inner_map_fd(map, fd); in test_map_in_map()
1212 err = bpf_map_update_elem(mim_fd, &pos, &fd, 0); in test_map_in_map()
1229 err = bpf_map_update_elem(mim_fd, &pos, &fd, 0); in test_map_in_map()
1235 close(fd); in test_map_in_map()
1236 fd = -1; in test_map_in_map()
1276 fd = bpf_map_get_fd_by_id(id); in test_map_in_map()
1277 if (fd < 0) { in test_map_in_map()
1284 err = bpf_obj_get_info_by_fd(fd, &info, &len); in test_map_in_map()
1286 printf("Failed to get map info by fd %d: %d", fd, in test_map_in_map()
1300 if (fd >= 0) in test_map_in_map()
1301 close(fd); in test_map_in_map()
1315 int fd, i, value; in test_map_large() local
1317 fd = bpf_create_map(BPF_MAP_TYPE_HASH, sizeof(key), sizeof(value), in test_map_large()
1319 if (fd < 0) { in test_map_large()
1328 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) == 0); in test_map_large()
1332 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) < 0 && in test_map_large()
1336 assert(bpf_map_get_next_key(fd, NULL, &key) == 0); in test_map_large()
1339 assert(bpf_map_get_next_key(fd, &key, &key) == 0); in test_map_large()
1340 assert(bpf_map_get_next_key(fd, &key, &key) < 0 && errno == ENOENT); in test_map_large()
1343 assert(bpf_map_lookup_elem(fd, &key, &value) == 0 && value == 0); in test_map_large()
1345 assert(bpf_map_lookup_elem(fd, &key, &value) < 0 && errno == ENOENT); in test_map_large()
1347 close(fd); in test_map_large()
1442 int fd = ((int *)data)[0]; in test_update_delete() local
1449 err = map_update_retriable(fd, &key, &value, BPF_NOEXIST, MAP_RETRIES); in test_update_delete()
1453 err = map_update_retriable(fd, &key, &value, BPF_EXIST, MAP_RETRIES); in test_update_delete()
1458 err = map_delete_retriable(fd, &key, MAP_RETRIES); in test_update_delete()
1468 int i, fd, key = 0, value = 0; in test_map_parallel() local
1471 fd = bpf_create_map(BPF_MAP_TYPE_HASH, sizeof(key), sizeof(value), in test_map_parallel()
1473 if (fd < 0) { in test_map_parallel()
1484 data[0] = fd; in test_map_parallel()
1489 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) < 0 && in test_map_parallel()
1493 assert(bpf_map_get_next_key(fd, NULL, &key) == 0); in test_map_parallel()
1496 assert(bpf_map_get_next_key(fd, &key, &key) == 0); in test_map_parallel()
1497 assert(bpf_map_get_next_key(fd, &key, &key) < 0 && errno == ENOENT); in test_map_parallel()
1503 assert(bpf_map_lookup_elem(fd, &key, &value) == 0 && in test_map_parallel()
1513 assert(bpf_map_get_next_key(fd, NULL, &key) < 0 && errno == ENOENT); in test_map_parallel()
1514 assert(bpf_map_get_next_key(fd, &key, &key) < 0 && errno == ENOENT); in test_map_parallel()
1519 int fd, key = 0, value = 0; in test_map_rdonly() local
1521 fd = bpf_create_map(BPF_MAP_TYPE_HASH, sizeof(key), sizeof(value), in test_map_rdonly()
1523 if (fd < 0) { in test_map_rdonly()
1532 assert(bpf_map_update_elem(fd, &key, &value, BPF_ANY) < 0 && in test_map_rdonly()
1536 assert(bpf_map_lookup_elem(fd, &key, &value) < 0 && errno == ENOENT); in test_map_rdonly()
1537 assert(bpf_map_get_next_key(fd, &key, &value) < 0 && errno == ENOENT); in test_map_rdonly()
1539 close(fd); in test_map_rdonly()
1544 int fd, key = 0, value = 0; in test_map_wronly_hash() local
1546 fd = bpf_create_map(BPF_MAP_TYPE_HASH, sizeof(key), sizeof(value), in test_map_wronly_hash()
1548 if (fd < 0) { in test_map_wronly_hash()
1557 assert(bpf_map_update_elem(fd, &key, &value, BPF_ANY) == 0); in test_map_wronly_hash()
1560 assert(bpf_map_lookup_elem(fd, &key, &value) < 0 && errno == EPERM); in test_map_wronly_hash()
1561 assert(bpf_map_get_next_key(fd, &key, &value) < 0 && errno == EPERM); in test_map_wronly_hash()
1563 close(fd); in test_map_wronly_hash()
1568 int fd, value = 0; in test_map_wronly_stack_or_queue() local
1572 fd = bpf_create_map(map_type, 0, sizeof(value), MAP_SIZE, in test_map_wronly_stack_or_queue()
1576 assert(fd < 0 && errno == EINVAL); in test_map_wronly_stack_or_queue()
1579 if (fd < 0) { in test_map_wronly_stack_or_queue()
1585 assert(bpf_map_update_elem(fd, NULL, &value, BPF_ANY) == 0); in test_map_wronly_stack_or_queue()
1588 assert(bpf_map_lookup_elem(fd, NULL, &value) < 0 && errno == EPERM); in test_map_wronly_stack_or_queue()
1591 assert(bpf_map_lookup_and_delete_elem(fd, NULL, &value) < 0 && in test_map_wronly_stack_or_queue()
1594 close(fd); in test_map_wronly_stack_or_queue()
1700 int fd; in test_reuseport_array() local
1845 fd = fd64; in test_reuseport_array()
1846 err = bpf_map_update_elem(map_fd, &index3, &fd, BPF_NOEXIST); in test_reuseport_array()
1853 close(fd); in test_reuseport_array()