Lines Matching full:fd

36 	int fd;  in test_hashmap()  local
38 fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL, sizeof(key), sizeof(value), 2, &map_opts); in test_hashmap()
39 if (fd < 0) { in test_hashmap()
47 assert(bpf_map_update_elem(fd, &key, &value, BPF_ANY) == 0); in test_hashmap()
51 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) < 0 && in test_hashmap()
56 assert(bpf_map_update_elem(fd, &key, &value, -1) < 0 && in test_hashmap()
60 assert(bpf_map_lookup_elem(fd, &key, &value) == 0 && value == 1234); in test_hashmap()
65 assert(bpf_map_update_elem(fd, &key, &value, BPF_ANY) == 0); in test_hashmap()
68 assert(bpf_map_lookup_and_delete_elem(fd, &key, &value) == 0 && value == 1234); in test_hashmap()
71 assert(bpf_map_lookup_elem(fd, &key, &value) < 0 && errno == ENOENT); in test_hashmap()
74 assert(bpf_map_update_elem(fd, &key, &value, BPF_EXIST) < 0 && in test_hashmap()
79 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) == 0); in test_hashmap()
85 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) < 0 && in test_hashmap()
90 assert(bpf_map_update_elem(fd, &key, &value, BPF_EXIST) == 0); in test_hashmap()
92 assert(bpf_map_update_elem(fd, &key, &value, BPF_ANY) == 0); in test_hashmap()
94 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) < 0 && in test_hashmap()
99 assert(bpf_map_delete_elem(fd, &key) < 0 && errno == ENOENT); in test_hashmap()
102 assert(bpf_map_get_next_key(fd, NULL, &first_key) == 0 && in test_hashmap()
104 assert(bpf_map_get_next_key(fd, &key, &next_key) == 0 && in test_hashmap()
106 assert(bpf_map_get_next_key(fd, &next_key, &next_key) == 0 && in test_hashmap()
109 assert(bpf_map_get_next_key(fd, &next_key, &next_key) < 0 && in test_hashmap()
114 assert(bpf_map_delete_elem(fd, &key) == 0); in test_hashmap()
116 assert(bpf_map_delete_elem(fd, &key) == 0); in test_hashmap()
117 assert(bpf_map_delete_elem(fd, &key) < 0 && errno == ENOENT); in test_hashmap()
121 assert(bpf_map_get_next_key(fd, NULL, &next_key) < 0 && in test_hashmap()
123 assert(bpf_map_get_next_key(fd, &key, &next_key) < 0 && in test_hashmap()
126 close(fd); in test_hashmap()
131 int fd, i, j; in test_hashmap_sizes() local
135 fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL, i, j, 2, &map_opts); in test_hashmap_sizes()
136 if (fd < 0) { in test_hashmap_sizes()
143 close(fd); in test_hashmap_sizes()
154 int fd, i; in test_hashmap_percpu() local
156 fd = bpf_map_create(BPF_MAP_TYPE_PERCPU_HASH, NULL, sizeof(key), in test_hashmap_percpu()
158 if (fd < 0) { in test_hashmap_percpu()
169 assert(bpf_map_update_elem(fd, &key, value, BPF_ANY) == 0); in test_hashmap_percpu()
172 assert(bpf_map_lookup_and_delete_elem(fd, &key, value) == 0 && in test_hashmap_percpu()
179 assert(bpf_map_update_elem(fd, &key, value, BPF_NOEXIST) == 0); in test_hashmap_percpu()
183 assert(bpf_map_update_elem(fd, &key, value, BPF_NOEXIST) < 0 && in test_hashmap_percpu()
188 assert(bpf_map_update_elem(fd, &key, value, -1) < 0 && in test_hashmap_percpu()
195 assert(bpf_map_lookup_elem(fd, &key, value) == 0 && in test_hashmap_percpu()
200 assert(bpf_map_lookup_elem(fd, &key, value) < 0 && errno == ENOENT); in test_hashmap_percpu()
203 assert(bpf_map_update_elem(fd, &key, value, BPF_EXIST) < 0 && in test_hashmap_percpu()
209 assert(bpf_map_update_elem(fd, &key, value, BPF_NOEXIST) == 0); in test_hashmap_percpu()
216 assert(bpf_map_update_elem(fd, &key, value, BPF_NOEXIST) < 0 && in test_hashmap_percpu()
220 assert(bpf_map_delete_elem(fd, &key) < 0 && errno == ENOENT); in test_hashmap_percpu()
223 assert(bpf_map_get_next_key(fd, NULL, &first_key) == 0 && in test_hashmap_percpu()
225 while (!bpf_map_get_next_key(fd, &key, &next_key)) { in test_hashmap_percpu()
233 assert(bpf_map_lookup_elem(fd, &next_key, value) == 0); in test_hashmap_percpu()
244 assert(bpf_map_update_elem(fd, &key, value, BPF_EXIST) == 0); in test_hashmap_percpu()
248 assert(bpf_map_delete_elem(fd, &key) == 0); in test_hashmap_percpu()
250 assert(bpf_map_delete_elem(fd, &key) == 0); in test_hashmap_percpu()
251 assert(bpf_map_delete_elem(fd, &key) < 0 && errno == ENOENT); in test_hashmap_percpu()
255 assert(bpf_map_get_next_key(fd, NULL, &next_key) < 0 && in test_hashmap_percpu()
257 assert(bpf_map_get_next_key(fd, &key, &next_key) < 0 && in test_hashmap_percpu()
260 close(fd); in test_hashmap_percpu()
266 int i, fd, ret; in helper_fill_hashmap() local
269 fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL, sizeof(key), sizeof(value), in helper_fill_hashmap()
271 CHECK(fd < 0, in helper_fill_hashmap()
277 ret = bpf_map_update_elem(fd, &key, value, BPF_NOEXIST); in helper_fill_hashmap()
283 return fd; in helper_fill_hashmap()
288 int fd, i, max_entries = 10000; in test_hashmap_walk() local
292 fd = helper_fill_hashmap(max_entries); in test_hashmap_walk()
294 for (i = 0; bpf_map_get_next_key(fd, !i ? NULL : &key, in test_hashmap_walk()
297 assert(bpf_map_lookup_elem(fd, &key, value) == 0); in test_hashmap_walk()
302 assert(bpf_map_get_next_key(fd, NULL, &key) == 0); in test_hashmap_walk()
304 next_key_valid = bpf_map_get_next_key(fd, &key, &next_key) == 0; in test_hashmap_walk()
305 assert(bpf_map_lookup_elem(fd, &key, value) == 0); in test_hashmap_walk()
307 assert(bpf_map_update_elem(fd, &key, value, BPF_EXIST) == 0); in test_hashmap_walk()
313 for (i = 0; bpf_map_get_next_key(fd, !i ? NULL : &key, in test_hashmap_walk()
316 assert(bpf_map_lookup_elem(fd, &key, value) == 0); in test_hashmap_walk()
321 close(fd); in test_hashmap_walk()
359 int key, next_key, fd; in test_arraymap() local
362 fd = bpf_map_create(BPF_MAP_TYPE_ARRAY, NULL, sizeof(key), sizeof(value), 2, NULL); in test_arraymap()
363 if (fd < 0) { in test_arraymap()
371 assert(bpf_map_update_elem(fd, &key, &value, BPF_ANY) == 0); in test_arraymap()
374 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) < 0 && in test_arraymap()
378 assert(bpf_map_lookup_elem(fd, &key, &value) == 0 && value == 1234); in test_arraymap()
382 assert(bpf_map_lookup_elem(fd, &key, &value) == 0 && value == 0); in test_arraymap()
388 assert(bpf_map_update_elem(fd, &key, &value, BPF_EXIST) < 0 && in test_arraymap()
392 assert(bpf_map_lookup_elem(fd, &key, &value) < 0 && errno == ENOENT); in test_arraymap()
395 assert(bpf_map_get_next_key(fd, NULL, &next_key) == 0 && in test_arraymap()
397 assert(bpf_map_get_next_key(fd, &key, &next_key) == 0 && in test_arraymap()
399 assert(bpf_map_get_next_key(fd, &next_key, &next_key) == 0 && in test_arraymap()
401 assert(bpf_map_get_next_key(fd, &next_key, &next_key) < 0 && in test_arraymap()
406 assert(bpf_map_delete_elem(fd, &key) < 0 && errno == EINVAL); in test_arraymap()
408 close(fd); in test_arraymap()
415 int key, next_key, fd, i; in test_arraymap_percpu() local
417 fd = bpf_map_create(BPF_MAP_TYPE_PERCPU_ARRAY, NULL, sizeof(key), in test_arraymap_percpu()
419 if (fd < 0) { in test_arraymap_percpu()
429 assert(bpf_map_update_elem(fd, &key, values, BPF_ANY) == 0); in test_arraymap_percpu()
432 assert(bpf_map_update_elem(fd, &key, values, BPF_NOEXIST) < 0 && in test_arraymap_percpu()
436 assert(bpf_map_lookup_elem(fd, &key, values) == 0 && in test_arraymap_percpu()
441 assert(bpf_map_lookup_elem(fd, &key, values) == 0 && in test_arraymap_percpu()
447 assert(bpf_map_update_elem(fd, &key, values, BPF_EXIST) < 0 && in test_arraymap_percpu()
451 assert(bpf_map_lookup_elem(fd, &key, values) < 0 && errno == ENOENT); in test_arraymap_percpu()
454 assert(bpf_map_get_next_key(fd, NULL, &next_key) == 0 && in test_arraymap_percpu()
456 assert(bpf_map_get_next_key(fd, &key, &next_key) == 0 && in test_arraymap_percpu()
458 assert(bpf_map_get_next_key(fd, &next_key, &next_key) == 0 && in test_arraymap_percpu()
460 assert(bpf_map_get_next_key(fd, &next_key, &next_key) < 0 && in test_arraymap_percpu()
465 assert(bpf_map_delete_elem(fd, &key) < 0 && errno == EINVAL); in test_arraymap_percpu()
467 close(fd); in test_arraymap_percpu()
478 int key, fd, i; in test_arraymap_percpu_many_keys() local
480 fd = bpf_map_create(BPF_MAP_TYPE_PERCPU_ARRAY, NULL, sizeof(key), in test_arraymap_percpu_many_keys()
482 if (fd < 0) { in test_arraymap_percpu_many_keys()
492 assert(bpf_map_update_elem(fd, &key, values, BPF_ANY) == 0); in test_arraymap_percpu_many_keys()
498 assert(bpf_map_lookup_elem(fd, &key, values) == 0); in test_arraymap_percpu_many_keys()
504 close(fd); in test_arraymap_percpu_many_keys()
509 int fd; in test_devmap() local
512 fd = bpf_map_create(BPF_MAP_TYPE_DEVMAP, NULL, sizeof(key), sizeof(value), 2, NULL); in test_devmap()
513 if (fd < 0) { in test_devmap()
518 close(fd); in test_devmap()
523 int fd; in test_devmap_hash() local
526 fd = bpf_map_create(BPF_MAP_TYPE_DEVMAP_HASH, NULL, sizeof(key), sizeof(value), 2, NULL); in test_devmap_hash()
527 if (fd < 0) { in test_devmap_hash()
532 close(fd); in test_devmap_hash()
539 int fd, i; in test_queuemap() local
546 fd = bpf_map_create(BPF_MAP_TYPE_QUEUE, NULL, 4, sizeof(val), MAP_SIZE, &map_opts); in test_queuemap()
547 assert(fd < 0 && errno == EINVAL); in test_queuemap()
549 fd = bpf_map_create(BPF_MAP_TYPE_QUEUE, NULL, 0, sizeof(val), MAP_SIZE, &map_opts); in test_queuemap()
552 assert(fd < 0 && errno == EINVAL); in test_queuemap()
555 if (fd < 0) { in test_queuemap()
562 assert(bpf_map_update_elem(fd, NULL, &vals[i], 0) == 0); in test_queuemap()
565 assert(bpf_map_update_elem(fd, NULL, &val, 0) < 0 && in test_queuemap()
569 assert(bpf_map_lookup_elem(fd, NULL, &val) == 0 && val == vals[0]); in test_queuemap()
573 assert(bpf_map_update_elem(fd, NULL, &vals[i], BPF_EXIST) == 0); in test_queuemap()
577 assert(bpf_map_lookup_and_delete_elem(fd, NULL, &val) == 0 && in test_queuemap()
581 assert(bpf_map_lookup_and_delete_elem(fd, NULL, &val) < 0 && in test_queuemap()
585 assert(bpf_map_delete_elem(fd, NULL) < 0 && errno == EINVAL); in test_queuemap()
586 assert(bpf_map_get_next_key(fd, NULL, NULL) < 0 && errno == EINVAL); in test_queuemap()
588 close(fd); in test_queuemap()
595 int fd, i; in test_stackmap() local
602 fd = bpf_map_create(BPF_MAP_TYPE_STACK, NULL, 4, sizeof(val), MAP_SIZE, &map_opts); in test_stackmap()
603 assert(fd < 0 && errno == EINVAL); in test_stackmap()
605 fd = bpf_map_create(BPF_MAP_TYPE_STACK, NULL, 0, sizeof(val), MAP_SIZE, &map_opts); in test_stackmap()
608 assert(fd < 0 && errno == EINVAL); in test_stackmap()
611 if (fd < 0) { in test_stackmap()
618 assert(bpf_map_update_elem(fd, NULL, &vals[i], 0) == 0); in test_stackmap()
621 assert(bpf_map_update_elem(fd, NULL, &val, 0) < 0 && in test_stackmap()
625 assert(bpf_map_lookup_elem(fd, NULL, &val) == 0 && val == vals[i - 1]); in test_stackmap()
629 assert(bpf_map_update_elem(fd, NULL, &vals[i], BPF_EXIST) == 0); in test_stackmap()
633 assert(bpf_map_lookup_and_delete_elem(fd, NULL, &val) == 0 && in test_stackmap()
637 assert(bpf_map_lookup_and_delete_elem(fd, NULL, &val) < 0 && in test_stackmap()
641 assert(bpf_map_delete_elem(fd, NULL) < 0 && errno == EINVAL); in test_stackmap()
642 assert(bpf_map_get_next_key(fd, NULL, NULL) < 0 && errno == EINVAL); in test_stackmap()
644 close(fd); in test_stackmap()
660 int err, i, fd, udp, sfd[6] = {0xdeadbeef}; in test_sockmap() local
734 fd = bpf_map_create(BPF_MAP_TYPE_SOCKMAP, NULL, in test_sockmap()
737 if (fd < 0) { in test_sockmap()
747 printf("Failed to create sockmap %i\n", fd); in test_sockmap()
754 err = bpf_map_update_elem(fd, &i, &udp, BPF_ANY); in test_sockmap()
764 err = bpf_map_update_elem(fd, &i, &sfd[i], BPF_ANY); in test_sockmap()
773 err = bpf_prog_attach(-1, fd, BPF_SK_SKB_STREAM_PARSER, 0); in test_sockmap()
779 err = bpf_prog_attach(-1, fd, BPF_SK_SKB_STREAM_VERDICT, 0); in test_sockmap()
785 err = bpf_prog_attach(-1, fd, BPF_SK_MSG_VERDICT, 0); in test_sockmap()
791 err = bpf_prog_attach(-1, fd, __MAX_BPF_ATTACH_TYPE, 0); in test_sockmap()
797 err = bpf_prog_detach(fd, BPF_SK_SKB_STREAM_PARSER); in test_sockmap()
803 err = bpf_prog_detach(fd, BPF_SK_SKB_STREAM_VERDICT); in test_sockmap()
809 err = bpf_prog_detach(fd, BPF_SK_MSG_VERDICT); in test_sockmap()
815 err = bpf_prog_detach(fd, __MAX_BPF_ATTACH_TYPE); in test_sockmap()
851 printf("Failed to get map rx fd\n"); in test_sockmap()
863 printf("Failed to get map tx fd\n"); in test_sockmap()
875 printf("Failed to get map msg fd\n"); in test_sockmap()
887 printf("Failed to get map tx fd\n"); in test_sockmap()
925 /* Test map update elem afterwards fd lives in fd and map_fd */ in test_sockmap()
957 /* Put sfd[2] (sending fd below) into msg map to test sendmsg bpf */ in test_sockmap()
1009 /* Push fd into same slot */ in test_sockmap()
1011 err = bpf_map_update_elem(fd, &i, &sfd[i], BPF_NOEXIST); in test_sockmap()
1017 err = bpf_map_update_elem(fd, &i, &sfd[i], BPF_ANY); in test_sockmap()
1023 err = bpf_map_update_elem(fd, &i, &sfd[i], BPF_EXIST); in test_sockmap()
1031 err = bpf_map_delete_elem(fd, &i); in test_sockmap()
1039 err = bpf_prog_attach(parse_prog, fd, in test_sockmap()
1042 printf("Failed fd bpf parse prog attach\n"); in test_sockmap()
1045 err = bpf_prog_attach(verdict_prog, fd, in test_sockmap()
1048 printf("Failed fd bpf verdict prog attach\n"); in test_sockmap()
1053 err = bpf_map_update_elem(fd, &i, &sfd[i], BPF_ANY); in test_sockmap()
1059 err = bpf_map_update_elem(fd, &i, &sfd[i], BPF_NOEXIST); in test_sockmap()
1065 err = bpf_map_update_elem(fd, &i, &sfd[i], BPF_EXIST); in test_sockmap()
1123 close(fd); in test_sockmap()
1142 close(fd); in test_sockmap()
1152 int mim_fd, fd, err; in test_map_in_map() local
1161 fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL, sizeof(int), sizeof(int), 2, NULL); in test_map_in_map()
1162 if (fd < 0) { in test_map_in_map()
1172 err = bpf_map__set_inner_map_fd(map, fd); in test_map_in_map()
1183 err = bpf_map__set_inner_map_fd(map, fd); in test_map_in_map()
1206 err = bpf_map_update_elem(mim_fd, &pos, &fd, 0); in test_map_in_map()
1223 err = bpf_map_update_elem(mim_fd, &pos, &fd, 0); in test_map_in_map()
1229 close(fd); in test_map_in_map()
1230 fd = -1; in test_map_in_map()
1270 fd = bpf_map_get_fd_by_id(id); in test_map_in_map()
1271 if (fd < 0) { in test_map_in_map()
1278 err = bpf_map_get_info_by_fd(fd, &info, &len); in test_map_in_map()
1280 printf("Failed to get map info by fd %d: %d", fd, in test_map_in_map()
1290 close(fd); in test_map_in_map()
1297 if (fd >= 0) in test_map_in_map()
1298 close(fd); in test_map_in_map()
1312 int fd, i, value; in test_map_large() local
1314 fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL, sizeof(key), sizeof(value), in test_map_large()
1316 if (fd < 0) { in test_map_large()
1325 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) == 0); in test_map_large()
1329 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) < 0 && in test_map_large()
1333 assert(bpf_map_get_next_key(fd, NULL, &key) == 0); in test_map_large()
1336 assert(bpf_map_get_next_key(fd, &key, &key) == 0); in test_map_large()
1337 assert(bpf_map_get_next_key(fd, &key, &key) < 0 && errno == ENOENT); in test_map_large()
1340 assert(bpf_map_lookup_elem(fd, &key, &value) == 0 && value == 0); in test_map_large()
1342 assert(bpf_map_lookup_elem(fd, &key, &value) < 0 && errno == ENOENT); in test_map_large()
1344 close(fd); in test_map_large()
1444 int fd = ((int *)data)[0]; in test_update_delete() local
1453 err = map_update_retriable(fd, &key, &value, BPF_NOEXIST, MAP_RETRIES, in test_update_delete()
1458 err = map_update_retriable(fd, &key, &value, BPF_EXIST, MAP_RETRIES, in test_update_delete()
1464 err = map_delete_retriable(fd, &key, MAP_RETRIES); in test_update_delete()
1474 int i, fd, key = 0, value = 0, j = 0; in test_map_parallel() local
1477 fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL, sizeof(key), sizeof(value), in test_map_parallel()
1479 if (fd < 0) { in test_map_parallel()
1486 /* Use the same fd in children to add elements to this map: in test_map_parallel()
1491 data[0] = fd; in test_map_parallel()
1496 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) < 0 && in test_map_parallel()
1500 assert(bpf_map_get_next_key(fd, NULL, &key) == 0); in test_map_parallel()
1503 assert(bpf_map_get_next_key(fd, &key, &key) == 0); in test_map_parallel()
1504 assert(bpf_map_get_next_key(fd, &key, &key) < 0 && errno == ENOENT); in test_map_parallel()
1510 assert(bpf_map_lookup_elem(fd, &key, &value) == 0 && in test_map_parallel()
1520 assert(bpf_map_get_next_key(fd, NULL, &key) < 0 && errno == ENOENT); in test_map_parallel()
1521 assert(bpf_map_get_next_key(fd, &key, &key) < 0 && errno == ENOENT); in test_map_parallel()
1524 bpf_map_delete_elem(fd, &key); in test_map_parallel()
1527 close(fd); in test_map_parallel()
1532 int fd, key = 0, value = 0; in test_map_rdonly() local
1537 fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL, sizeof(key), sizeof(value), in test_map_rdonly()
1540 if (fd < 0) { in test_map_rdonly()
1549 assert(bpf_map_update_elem(fd, &key, &value, BPF_ANY) < 0 && in test_map_rdonly()
1553 assert(bpf_map_lookup_elem(fd, &key, &value) < 0 && errno == ENOENT); in test_map_rdonly()
1554 assert(bpf_map_get_next_key(fd, &key, &value) < 0 && errno == ENOENT); in test_map_rdonly()
1556 close(fd); in test_map_rdonly()
1561 int fd, key = 0, value = 0; in test_map_wronly_hash() local
1566 fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL, sizeof(key), sizeof(value), in test_map_wronly_hash()
1569 if (fd < 0) { in test_map_wronly_hash()
1578 assert(bpf_map_update_elem(fd, &key, &value, BPF_ANY) == 0); in test_map_wronly_hash()
1581 assert(bpf_map_lookup_elem(fd, &key, &value) < 0 && errno == EPERM); in test_map_wronly_hash()
1582 assert(bpf_map_get_next_key(fd, &key, &value) < 0 && errno == EPERM); in test_map_wronly_hash()
1584 close(fd); in test_map_wronly_hash()
1589 int fd, value = 0; in test_map_wronly_stack_or_queue() local
1597 fd = bpf_map_create(map_type, NULL, 0, sizeof(value), MAP_SIZE, &map_opts); in test_map_wronly_stack_or_queue()
1601 assert(fd < 0 && errno == EINVAL); in test_map_wronly_stack_or_queue()
1604 if (fd < 0) { in test_map_wronly_stack_or_queue()
1610 assert(bpf_map_update_elem(fd, NULL, &value, BPF_ANY) == 0); in test_map_wronly_stack_or_queue()
1613 assert(bpf_map_lookup_elem(fd, NULL, &value) < 0 && errno == EPERM); in test_map_wronly_stack_or_queue()
1616 assert(bpf_map_lookup_and_delete_elem(fd, NULL, &value) < 0 && in test_map_wronly_stack_or_queue()
1619 close(fd); in test_map_wronly_stack_or_queue()
1725 int fd; in test_reuseport_array() local
1863 /* Test 32 bit fd */ in test_reuseport_array()
1870 fd = fd64; in test_reuseport_array()
1871 err = bpf_map_update_elem(map_fd, &index3, &fd, BPF_NOEXIST); in test_reuseport_array()
1872 CHECK(err < 0, "reuseport array update 32 bit fd", in test_reuseport_array()
1876 "reuseport array lookup 32 bit fd", in test_reuseport_array()
1878 close(fd); in test_reuseport_array()