Lines Matching full:fd

40 	int fd;  in test_hashmap()  local
42 fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL, sizeof(key), sizeof(value), 2, &map_opts); in test_hashmap()
43 if (fd < 0) { in test_hashmap()
51 assert(bpf_map_update_elem(fd, &key, &value, BPF_ANY) == 0); in test_hashmap()
55 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) < 0 && in test_hashmap()
60 assert(bpf_map_update_elem(fd, &key, &value, -1) < 0 && in test_hashmap()
64 assert(bpf_map_lookup_elem(fd, &key, &value) == 0 && value == 1234); in test_hashmap()
69 assert(bpf_map_update_elem(fd, &key, &value, BPF_ANY) == 0); in test_hashmap()
72 assert(bpf_map_lookup_and_delete_elem(fd, &key, &value) == 0 && value == 1234); in test_hashmap()
75 assert(bpf_map_lookup_elem(fd, &key, &value) < 0 && errno == ENOENT); in test_hashmap()
78 assert(bpf_map_update_elem(fd, &key, &value, BPF_EXIST) < 0 && in test_hashmap()
83 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) == 0); in test_hashmap()
89 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) < 0 && in test_hashmap()
94 assert(bpf_map_update_elem(fd, &key, &value, BPF_EXIST) == 0); in test_hashmap()
96 assert(bpf_map_update_elem(fd, &key, &value, BPF_ANY) == 0); in test_hashmap()
98 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) < 0 && in test_hashmap()
103 assert(bpf_map_delete_elem(fd, &key) < 0 && errno == ENOENT); in test_hashmap()
106 assert(bpf_map_get_next_key(fd, NULL, &first_key) == 0 && in test_hashmap()
108 assert(bpf_map_get_next_key(fd, &key, &next_key) == 0 && in test_hashmap()
110 assert(bpf_map_get_next_key(fd, &next_key, &next_key) == 0 && in test_hashmap()
113 assert(bpf_map_get_next_key(fd, &next_key, &next_key) < 0 && in test_hashmap()
118 assert(bpf_map_delete_elem(fd, &key) == 0); in test_hashmap()
120 assert(bpf_map_delete_elem(fd, &key) == 0); in test_hashmap()
121 assert(bpf_map_delete_elem(fd, &key) < 0 && errno == ENOENT); in test_hashmap()
125 assert(bpf_map_get_next_key(fd, NULL, &next_key) < 0 && in test_hashmap()
127 assert(bpf_map_get_next_key(fd, &key, &next_key) < 0 && in test_hashmap()
130 close(fd); in test_hashmap()
135 int fd, i, j; in test_hashmap_sizes() local
139 fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL, i, j, 2, &map_opts); in test_hashmap_sizes()
140 if (fd < 0) { in test_hashmap_sizes()
147 close(fd); in test_hashmap_sizes()
158 int fd, i; in test_hashmap_percpu() local
160 fd = bpf_map_create(BPF_MAP_TYPE_PERCPU_HASH, NULL, sizeof(key), in test_hashmap_percpu()
162 if (fd < 0) { in test_hashmap_percpu()
173 assert(bpf_map_update_elem(fd, &key, value, BPF_ANY) == 0); in test_hashmap_percpu()
176 assert(bpf_map_lookup_and_delete_elem(fd, &key, value) == 0 && in test_hashmap_percpu()
183 assert(bpf_map_update_elem(fd, &key, value, BPF_NOEXIST) == 0); in test_hashmap_percpu()
187 assert(bpf_map_update_elem(fd, &key, value, BPF_NOEXIST) < 0 && in test_hashmap_percpu()
192 assert(bpf_map_update_elem(fd, &key, value, -1) < 0 && in test_hashmap_percpu()
199 assert(bpf_map_lookup_elem(fd, &key, value) == 0 && in test_hashmap_percpu()
204 assert(bpf_map_lookup_elem(fd, &key, value) < 0 && errno == ENOENT); in test_hashmap_percpu()
207 assert(bpf_map_update_elem(fd, &key, value, BPF_EXIST) < 0 && in test_hashmap_percpu()
213 assert(bpf_map_update_elem(fd, &key, value, BPF_NOEXIST) == 0); in test_hashmap_percpu()
220 assert(bpf_map_update_elem(fd, &key, value, BPF_NOEXIST) < 0 && in test_hashmap_percpu()
224 assert(bpf_map_delete_elem(fd, &key) < 0 && errno == ENOENT); in test_hashmap_percpu()
227 assert(bpf_map_get_next_key(fd, NULL, &first_key) == 0 && in test_hashmap_percpu()
229 while (!bpf_map_get_next_key(fd, &key, &next_key)) { in test_hashmap_percpu()
237 assert(bpf_map_lookup_elem(fd, &next_key, value) == 0); in test_hashmap_percpu()
248 assert(bpf_map_update_elem(fd, &key, value, BPF_EXIST) == 0); in test_hashmap_percpu()
252 assert(bpf_map_delete_elem(fd, &key) == 0); in test_hashmap_percpu()
254 assert(bpf_map_delete_elem(fd, &key) == 0); in test_hashmap_percpu()
255 assert(bpf_map_delete_elem(fd, &key) < 0 && errno == ENOENT); in test_hashmap_percpu()
259 assert(bpf_map_get_next_key(fd, NULL, &next_key) < 0 && in test_hashmap_percpu()
261 assert(bpf_map_get_next_key(fd, &key, &next_key) < 0 && in test_hashmap_percpu()
264 close(fd); in test_hashmap_percpu()
270 int i, fd, ret; in helper_fill_hashmap() local
273 fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL, sizeof(key), sizeof(value), in helper_fill_hashmap()
275 CHECK(fd < 0, in helper_fill_hashmap()
281 ret = bpf_map_update_elem(fd, &key, value, BPF_NOEXIST); in helper_fill_hashmap()
287 return fd; in helper_fill_hashmap()
292 int fd, i, max_entries = 10000; in test_hashmap_walk() local
296 fd = helper_fill_hashmap(max_entries); in test_hashmap_walk()
298 for (i = 0; bpf_map_get_next_key(fd, !i ? NULL : &key, in test_hashmap_walk()
301 assert(bpf_map_lookup_elem(fd, &key, value) == 0); in test_hashmap_walk()
306 assert(bpf_map_get_next_key(fd, NULL, &key) == 0); in test_hashmap_walk()
308 next_key_valid = bpf_map_get_next_key(fd, &key, &next_key) == 0; in test_hashmap_walk()
309 assert(bpf_map_lookup_elem(fd, &key, value) == 0); in test_hashmap_walk()
311 assert(bpf_map_update_elem(fd, &key, value, BPF_EXIST) == 0); in test_hashmap_walk()
317 for (i = 0; bpf_map_get_next_key(fd, !i ? NULL : &key, in test_hashmap_walk()
320 assert(bpf_map_lookup_elem(fd, &key, value) == 0); in test_hashmap_walk()
325 close(fd); in test_hashmap_walk()
363 int key, next_key, fd; in test_arraymap() local
366 fd = bpf_map_create(BPF_MAP_TYPE_ARRAY, NULL, sizeof(key), sizeof(value), 2, NULL); in test_arraymap()
367 if (fd < 0) { in test_arraymap()
375 assert(bpf_map_update_elem(fd, &key, &value, BPF_ANY) == 0); in test_arraymap()
378 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) < 0 && in test_arraymap()
382 assert(bpf_map_lookup_elem(fd, &key, &value) == 0 && value == 1234); in test_arraymap()
386 assert(bpf_map_lookup_elem(fd, &key, &value) == 0 && value == 0); in test_arraymap()
392 assert(bpf_map_update_elem(fd, &key, &value, BPF_EXIST) < 0 && in test_arraymap()
396 assert(bpf_map_lookup_elem(fd, &key, &value) < 0 && errno == ENOENT); in test_arraymap()
399 assert(bpf_map_get_next_key(fd, NULL, &next_key) == 0 && in test_arraymap()
401 assert(bpf_map_get_next_key(fd, &key, &next_key) == 0 && in test_arraymap()
403 assert(bpf_map_get_next_key(fd, &next_key, &next_key) == 0 && in test_arraymap()
405 assert(bpf_map_get_next_key(fd, &next_key, &next_key) < 0 && in test_arraymap()
410 assert(bpf_map_delete_elem(fd, &key) < 0 && errno == EINVAL); in test_arraymap()
412 close(fd); in test_arraymap()
419 int key, next_key, fd, i; in test_arraymap_percpu() local
421 fd = bpf_map_create(BPF_MAP_TYPE_PERCPU_ARRAY, NULL, sizeof(key), in test_arraymap_percpu()
423 if (fd < 0) { in test_arraymap_percpu()
433 assert(bpf_map_update_elem(fd, &key, values, BPF_ANY) == 0); in test_arraymap_percpu()
436 assert(bpf_map_update_elem(fd, &key, values, BPF_NOEXIST) < 0 && in test_arraymap_percpu()
440 assert(bpf_map_lookup_elem(fd, &key, values) == 0 && in test_arraymap_percpu()
445 assert(bpf_map_lookup_elem(fd, &key, values) == 0 && in test_arraymap_percpu()
451 assert(bpf_map_update_elem(fd, &key, values, BPF_EXIST) < 0 && in test_arraymap_percpu()
455 assert(bpf_map_lookup_elem(fd, &key, values) < 0 && errno == ENOENT); in test_arraymap_percpu()
458 assert(bpf_map_get_next_key(fd, NULL, &next_key) == 0 && in test_arraymap_percpu()
460 assert(bpf_map_get_next_key(fd, &key, &next_key) == 0 && in test_arraymap_percpu()
462 assert(bpf_map_get_next_key(fd, &next_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()
469 assert(bpf_map_delete_elem(fd, &key) < 0 && errno == EINVAL); in test_arraymap_percpu()
471 close(fd); in test_arraymap_percpu()
482 int key, fd, i; in test_arraymap_percpu_many_keys() local
484 fd = bpf_map_create(BPF_MAP_TYPE_PERCPU_ARRAY, NULL, sizeof(key), in test_arraymap_percpu_many_keys()
486 if (fd < 0) { in test_arraymap_percpu_many_keys()
496 assert(bpf_map_update_elem(fd, &key, values, BPF_ANY) == 0); in test_arraymap_percpu_many_keys()
502 assert(bpf_map_lookup_elem(fd, &key, values) == 0); in test_arraymap_percpu_many_keys()
508 close(fd); in test_arraymap_percpu_many_keys()
513 int fd; in test_devmap() local
516 fd = bpf_map_create(BPF_MAP_TYPE_DEVMAP, NULL, sizeof(key), sizeof(value), 2, NULL); in test_devmap()
517 if (fd < 0) { in test_devmap()
522 close(fd); in test_devmap()
527 int fd; in test_devmap_hash() local
530 fd = bpf_map_create(BPF_MAP_TYPE_DEVMAP_HASH, NULL, sizeof(key), sizeof(value), 2, NULL); in test_devmap_hash()
531 if (fd < 0) { in test_devmap_hash()
536 close(fd); in test_devmap_hash()
543 int fd, i; in test_queuemap() local
550 fd = bpf_map_create(BPF_MAP_TYPE_QUEUE, NULL, 4, sizeof(val), MAP_SIZE, &map_opts); in test_queuemap()
551 assert(fd < 0 && errno == EINVAL); in test_queuemap()
553 fd = bpf_map_create(BPF_MAP_TYPE_QUEUE, NULL, 0, sizeof(val), MAP_SIZE, &map_opts); in test_queuemap()
556 assert(fd < 0 && errno == EINVAL); in test_queuemap()
559 if (fd < 0) { in test_queuemap()
566 assert(bpf_map_update_elem(fd, NULL, &vals[i], 0) == 0); in test_queuemap()
569 assert(bpf_map_update_elem(fd, NULL, &val, 0) < 0 && in test_queuemap()
573 assert(bpf_map_lookup_elem(fd, NULL, &val) == 0 && val == vals[0]); in test_queuemap()
577 assert(bpf_map_update_elem(fd, NULL, &vals[i], BPF_EXIST) == 0); in test_queuemap()
581 assert(bpf_map_lookup_and_delete_elem(fd, NULL, &val) == 0 && in test_queuemap()
585 assert(bpf_map_lookup_and_delete_elem(fd, NULL, &val) < 0 && in test_queuemap()
589 assert(bpf_map_delete_elem(fd, NULL) < 0 && errno == EINVAL); in test_queuemap()
590 assert(bpf_map_get_next_key(fd, NULL, NULL) < 0 && errno == EINVAL); in test_queuemap()
592 close(fd); in test_queuemap()
599 int fd, i; in test_stackmap() local
606 fd = bpf_map_create(BPF_MAP_TYPE_STACK, NULL, 4, sizeof(val), MAP_SIZE, &map_opts); in test_stackmap()
607 assert(fd < 0 && errno == EINVAL); in test_stackmap()
609 fd = bpf_map_create(BPF_MAP_TYPE_STACK, NULL, 0, sizeof(val), MAP_SIZE, &map_opts); in test_stackmap()
612 assert(fd < 0 && errno == EINVAL); in test_stackmap()
615 if (fd < 0) { in test_stackmap()
622 assert(bpf_map_update_elem(fd, NULL, &vals[i], 0) == 0); in test_stackmap()
625 assert(bpf_map_update_elem(fd, NULL, &val, 0) < 0 && in test_stackmap()
629 assert(bpf_map_lookup_elem(fd, NULL, &val) == 0 && val == vals[i - 1]); in test_stackmap()
633 assert(bpf_map_update_elem(fd, NULL, &vals[i], BPF_EXIST) == 0); in test_stackmap()
637 assert(bpf_map_lookup_and_delete_elem(fd, NULL, &val) == 0 && in test_stackmap()
641 assert(bpf_map_lookup_and_delete_elem(fd, NULL, &val) < 0 && in test_stackmap()
645 assert(bpf_map_delete_elem(fd, NULL) < 0 && errno == EINVAL); in test_stackmap()
646 assert(bpf_map_get_next_key(fd, NULL, NULL) < 0 && errno == EINVAL); in test_stackmap()
648 close(fd); in test_stackmap()
664 int err, i, fd, udp, sfd[6] = {0xdeadbeef}; in test_sockmap() local
738 fd = bpf_map_create(BPF_MAP_TYPE_SOCKMAP, NULL, in test_sockmap()
741 if (fd < 0) { in test_sockmap()
751 printf("Failed to create sockmap %i\n", fd); in test_sockmap()
758 err = bpf_map_update_elem(fd, &i, &udp, BPF_ANY); in test_sockmap()
768 err = bpf_map_update_elem(fd, &i, &sfd[i], BPF_ANY); in test_sockmap()
777 err = bpf_prog_attach(-1, fd, BPF_SK_SKB_STREAM_PARSER, 0); in test_sockmap()
783 err = bpf_prog_attach(-1, fd, BPF_SK_SKB_STREAM_VERDICT, 0); in test_sockmap()
789 err = bpf_prog_attach(-1, fd, BPF_SK_MSG_VERDICT, 0); in test_sockmap()
795 err = bpf_prog_attach(-1, fd, __MAX_BPF_ATTACH_TYPE, 0); in test_sockmap()
801 err = bpf_prog_detach(fd, BPF_SK_SKB_STREAM_PARSER); in test_sockmap()
807 err = bpf_prog_detach(fd, BPF_SK_SKB_STREAM_VERDICT); in test_sockmap()
813 err = bpf_prog_detach(fd, BPF_SK_MSG_VERDICT); in test_sockmap()
819 err = bpf_prog_detach(fd, __MAX_BPF_ATTACH_TYPE); in test_sockmap()
855 printf("Failed to get map rx fd\n"); in test_sockmap()
867 printf("Failed to get map tx fd\n"); in test_sockmap()
879 printf("Failed to get map msg fd\n"); in test_sockmap()
891 printf("Failed to get map tx fd\n"); in test_sockmap()
929 /* Test map update elem afterwards fd lives in fd and map_fd */ in test_sockmap()
961 /* Put sfd[2] (sending fd below) into msg map to test sendmsg bpf */ in test_sockmap()
1013 /* Push fd into same slot */ in test_sockmap()
1015 err = bpf_map_update_elem(fd, &i, &sfd[i], BPF_NOEXIST); in test_sockmap()
1021 err = bpf_map_update_elem(fd, &i, &sfd[i], BPF_ANY); in test_sockmap()
1027 err = bpf_map_update_elem(fd, &i, &sfd[i], BPF_EXIST); in test_sockmap()
1035 err = bpf_map_delete_elem(fd, &i); in test_sockmap()
1043 err = bpf_prog_attach(parse_prog, fd, in test_sockmap()
1046 printf("Failed fd bpf parse prog attach\n"); in test_sockmap()
1049 err = bpf_prog_attach(verdict_prog, fd, in test_sockmap()
1052 printf("Failed fd bpf verdict prog attach\n"); in test_sockmap()
1057 err = bpf_map_update_elem(fd, &i, &sfd[i], BPF_ANY); in test_sockmap()
1063 err = bpf_map_update_elem(fd, &i, &sfd[i], BPF_NOEXIST); in test_sockmap()
1069 err = bpf_map_update_elem(fd, &i, &sfd[i], BPF_EXIST); in test_sockmap()
1127 close(fd); in test_sockmap()
1146 close(fd); in test_sockmap()
1156 int mim_fd, fd, err; in test_map_in_map() local
1165 fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL, sizeof(int), sizeof(int), 2, NULL); in test_map_in_map()
1166 if (fd < 0) { in test_map_in_map()
1176 err = bpf_map__set_inner_map_fd(map, fd); in test_map_in_map()
1187 err = bpf_map__set_inner_map_fd(map, fd); in test_map_in_map()
1210 err = bpf_map_update_elem(mim_fd, &pos, &fd, 0); in test_map_in_map()
1227 err = bpf_map_update_elem(mim_fd, &pos, &fd, 0); in test_map_in_map()
1233 close(fd); in test_map_in_map()
1234 fd = -1; in test_map_in_map()
1274 fd = bpf_map_get_fd_by_id(id); in test_map_in_map()
1275 if (fd < 0) { in test_map_in_map()
1282 err = bpf_map_get_info_by_fd(fd, &info, &len); in test_map_in_map()
1284 printf("Failed to get map info by fd %d: %d", fd, in test_map_in_map()
1294 close(fd); in test_map_in_map()
1301 if (fd >= 0) in test_map_in_map()
1302 close(fd); in test_map_in_map()
1316 int fd, i, value; in test_map_large() local
1318 fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL, sizeof(key), sizeof(value), in test_map_large()
1320 if (fd < 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_update_elem(fd, &key, &value, BPF_NOEXIST) < 0 && in test_map_large()
1337 assert(bpf_map_get_next_key(fd, NULL, &key) == 0); in test_map_large()
1340 assert(bpf_map_get_next_key(fd, &key, &key) == 0); in test_map_large()
1341 assert(bpf_map_get_next_key(fd, &key, &key) < 0 && errno == ENOENT); in test_map_large()
1344 assert(bpf_map_lookup_elem(fd, &key, &value) == 0 && value == 0); in test_map_large()
1346 assert(bpf_map_lookup_elem(fd, &key, &value) < 0 && errno == ENOENT); in test_map_large()
1348 close(fd); in test_map_large()
1448 int fd = ((int *)data)[0]; in test_update_delete() local
1457 err = map_update_retriable(fd, &key, &value, BPF_NOEXIST, MAP_RETRIES, in test_update_delete()
1462 err = map_update_retriable(fd, &key, &value, BPF_EXIST, MAP_RETRIES, in test_update_delete()
1468 err = map_delete_retriable(fd, &key, MAP_RETRIES); in test_update_delete()
1478 int i, fd, key = 0, value = 0, j = 0; in test_map_parallel() local
1481 fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL, sizeof(key), sizeof(value), in test_map_parallel()
1483 if (fd < 0) { in test_map_parallel()
1490 /* Use the same fd in children to add elements to this map: in test_map_parallel()
1495 data[0] = fd; in test_map_parallel()
1500 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) < 0 && in test_map_parallel()
1504 assert(bpf_map_get_next_key(fd, NULL, &key) == 0); in test_map_parallel()
1507 assert(bpf_map_get_next_key(fd, &key, &key) == 0); in test_map_parallel()
1508 assert(bpf_map_get_next_key(fd, &key, &key) < 0 && errno == ENOENT); in test_map_parallel()
1514 assert(bpf_map_lookup_elem(fd, &key, &value) == 0 && in test_map_parallel()
1524 assert(bpf_map_get_next_key(fd, NULL, &key) < 0 && errno == ENOENT); in test_map_parallel()
1525 assert(bpf_map_get_next_key(fd, &key, &key) < 0 && errno == ENOENT); in test_map_parallel()
1528 bpf_map_delete_elem(fd, &key); in test_map_parallel()
1531 close(fd); in test_map_parallel()
1536 int fd, key = 0, value = 0; in test_map_rdonly() local
1541 fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL, sizeof(key), sizeof(value), in test_map_rdonly()
1544 if (fd < 0) { in test_map_rdonly()
1553 assert(bpf_map_update_elem(fd, &key, &value, BPF_ANY) < 0 && in test_map_rdonly()
1557 assert(bpf_map_lookup_elem(fd, &key, &value) < 0 && errno == ENOENT); in test_map_rdonly()
1558 assert(bpf_map_get_next_key(fd, &key, &value) < 0 && errno == ENOENT); in test_map_rdonly()
1560 close(fd); in test_map_rdonly()
1565 int fd, key = 0, value = 0; in test_map_wronly_hash() local
1570 fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL, sizeof(key), sizeof(value), in test_map_wronly_hash()
1573 if (fd < 0) { in test_map_wronly_hash()
1582 assert(bpf_map_update_elem(fd, &key, &value, BPF_ANY) == 0); in test_map_wronly_hash()
1585 assert(bpf_map_lookup_elem(fd, &key, &value) < 0 && errno == EPERM); in test_map_wronly_hash()
1586 assert(bpf_map_get_next_key(fd, &key, &value) < 0 && errno == EPERM); in test_map_wronly_hash()
1588 close(fd); in test_map_wronly_hash()
1593 int fd, value = 0; in test_map_wronly_stack_or_queue() local
1601 fd = bpf_map_create(map_type, NULL, 0, sizeof(value), MAP_SIZE, &map_opts); in test_map_wronly_stack_or_queue()
1605 assert(fd < 0 && errno == EINVAL); in test_map_wronly_stack_or_queue()
1608 if (fd < 0) { in test_map_wronly_stack_or_queue()
1614 assert(bpf_map_update_elem(fd, NULL, &value, BPF_ANY) == 0); in test_map_wronly_stack_or_queue()
1617 assert(bpf_map_lookup_elem(fd, NULL, &value) < 0 && errno == EPERM); in test_map_wronly_stack_or_queue()
1620 assert(bpf_map_lookup_and_delete_elem(fd, NULL, &value) < 0 && in test_map_wronly_stack_or_queue()
1623 close(fd); in test_map_wronly_stack_or_queue()
1729 int fd; in test_reuseport_array() local
1867 /* Test 32 bit fd */ in test_reuseport_array()
1874 fd = fd64; in test_reuseport_array()
1875 err = bpf_map_update_elem(map_fd, &index3, &fd, BPF_NOEXIST); in test_reuseport_array()
1876 CHECK(err < 0, "reuseport array update 32 bit fd", in test_reuseport_array()
1880 "reuseport array lookup 32 bit fd", in test_reuseport_array()
1882 close(fd); in test_reuseport_array()