Lines Matching defs:fd
36 int fd;
38 fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL, sizeof(key), sizeof(value), 2, &map_opts);
39 if (fd < 0) {
47 assert(bpf_map_update_elem(fd, &key, &value, BPF_ANY) == 0);
51 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) < 0 &&
56 assert(bpf_map_update_elem(fd, &key, &value, -1) < 0 &&
60 assert(bpf_map_lookup_elem(fd, &key, &value) == 0 && value == 1234);
65 assert(bpf_map_update_elem(fd, &key, &value, BPF_ANY) == 0);
68 assert(bpf_map_lookup_and_delete_elem(fd, &key, &value) == 0 && value == 1234);
71 assert(bpf_map_lookup_elem(fd, &key, &value) < 0 && errno == ENOENT);
74 assert(bpf_map_update_elem(fd, &key, &value, BPF_EXIST) < 0 &&
79 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) == 0);
85 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) < 0 &&
90 assert(bpf_map_update_elem(fd, &key, &value, BPF_EXIST) == 0);
92 assert(bpf_map_update_elem(fd, &key, &value, BPF_ANY) == 0);
94 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) < 0 &&
99 assert(bpf_map_delete_elem(fd, &key) < 0 && errno == ENOENT);
102 assert(bpf_map_get_next_key(fd, NULL, &first_key) == 0 &&
104 assert(bpf_map_get_next_key(fd, &key, &next_key) == 0 &&
106 assert(bpf_map_get_next_key(fd, &next_key, &next_key) == 0 &&
109 assert(bpf_map_get_next_key(fd, &next_key, &next_key) < 0 &&
114 assert(bpf_map_delete_elem(fd, &key) == 0);
116 assert(bpf_map_delete_elem(fd, &key) == 0);
117 assert(bpf_map_delete_elem(fd, &key) < 0 && errno == ENOENT);
121 assert(bpf_map_get_next_key(fd, NULL, &next_key) < 0 &&
123 assert(bpf_map_get_next_key(fd, &key, &next_key) < 0 &&
126 close(fd);
131 int fd, i, j;
135 fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL, i, j, 2, &map_opts);
136 if (fd < 0) {
143 close(fd);
154 int fd, i;
156 fd = bpf_map_create(BPF_MAP_TYPE_PERCPU_HASH, NULL, sizeof(key),
158 if (fd < 0) {
169 assert(bpf_map_update_elem(fd, &key, value, BPF_ANY) == 0);
172 assert(bpf_map_lookup_and_delete_elem(fd, &key, value) == 0 &&
179 assert(bpf_map_update_elem(fd, &key, value, BPF_NOEXIST) == 0);
183 assert(bpf_map_update_elem(fd, &key, value, BPF_NOEXIST) < 0 &&
188 assert(bpf_map_update_elem(fd, &key, value, -1) < 0 &&
195 assert(bpf_map_lookup_elem(fd, &key, value) == 0 &&
200 assert(bpf_map_lookup_elem(fd, &key, value) < 0 && errno == ENOENT);
203 assert(bpf_map_update_elem(fd, &key, value, BPF_EXIST) < 0 &&
209 assert(bpf_map_update_elem(fd, &key, value, BPF_NOEXIST) == 0);
216 assert(bpf_map_update_elem(fd, &key, value, BPF_NOEXIST) < 0 &&
220 assert(bpf_map_delete_elem(fd, &key) < 0 && errno == ENOENT);
223 assert(bpf_map_get_next_key(fd, NULL, &first_key) == 0 &&
225 while (!bpf_map_get_next_key(fd, &key, &next_key)) {
233 assert(bpf_map_lookup_elem(fd, &next_key, value) == 0);
244 assert(bpf_map_update_elem(fd, &key, value, BPF_EXIST) == 0);
248 assert(bpf_map_delete_elem(fd, &key) == 0);
250 assert(bpf_map_delete_elem(fd, &key) == 0);
251 assert(bpf_map_delete_elem(fd, &key) < 0 && errno == ENOENT);
255 assert(bpf_map_get_next_key(fd, NULL, &next_key) < 0 &&
257 assert(bpf_map_get_next_key(fd, &key, &next_key) < 0 &&
260 close(fd);
266 int i, fd, ret;
269 fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL, sizeof(key), sizeof(value),
271 CHECK(fd < 0,
277 ret = bpf_map_update_elem(fd, &key, value, BPF_NOEXIST);
283 return fd;
288 int fd, i, max_entries = 10000;
292 fd = helper_fill_hashmap(max_entries);
294 for (i = 0; bpf_map_get_next_key(fd, !i ? NULL : &key,
297 assert(bpf_map_lookup_elem(fd, &key, value) == 0);
302 assert(bpf_map_get_next_key(fd, NULL, &key) == 0);
304 next_key_valid = bpf_map_get_next_key(fd, &key, &next_key) == 0;
305 assert(bpf_map_lookup_elem(fd, &key, value) == 0);
307 assert(bpf_map_update_elem(fd, &key, value, BPF_EXIST) == 0);
313 for (i = 0; bpf_map_get_next_key(fd, !i ? NULL : &key,
316 assert(bpf_map_lookup_elem(fd, &key, value) == 0);
321 close(fd);
359 int key, next_key, fd;
362 fd = bpf_map_create(BPF_MAP_TYPE_ARRAY, NULL, sizeof(key), sizeof(value), 2, NULL);
363 if (fd < 0) {
371 assert(bpf_map_update_elem(fd, &key, &value, BPF_ANY) == 0);
374 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) < 0 &&
378 assert(bpf_map_lookup_elem(fd, &key, &value) == 0 && value == 1234);
382 assert(bpf_map_lookup_elem(fd, &key, &value) == 0 && value == 0);
388 assert(bpf_map_update_elem(fd, &key, &value, BPF_EXIST) < 0 &&
392 assert(bpf_map_lookup_elem(fd, &key, &value) < 0 && errno == ENOENT);
395 assert(bpf_map_get_next_key(fd, NULL, &next_key) == 0 &&
397 assert(bpf_map_get_next_key(fd, &key, &next_key) == 0 &&
399 assert(bpf_map_get_next_key(fd, &next_key, &next_key) == 0 &&
401 assert(bpf_map_get_next_key(fd, &next_key, &next_key) < 0 &&
406 assert(bpf_map_delete_elem(fd, &key) < 0 && errno == EINVAL);
408 close(fd);
415 int key, next_key, fd, i;
417 fd = bpf_map_create(BPF_MAP_TYPE_PERCPU_ARRAY, NULL, sizeof(key),
419 if (fd < 0) {
429 assert(bpf_map_update_elem(fd, &key, values, BPF_ANY) == 0);
432 assert(bpf_map_update_elem(fd, &key, values, BPF_NOEXIST) < 0 &&
436 assert(bpf_map_lookup_elem(fd, &key, values) == 0 &&
441 assert(bpf_map_lookup_elem(fd, &key, values) == 0 &&
447 assert(bpf_map_update_elem(fd, &key, values, BPF_EXIST) < 0 &&
451 assert(bpf_map_lookup_elem(fd, &key, values) < 0 && errno == ENOENT);
454 assert(bpf_map_get_next_key(fd, NULL, &next_key) == 0 &&
456 assert(bpf_map_get_next_key(fd, &key, &next_key) == 0 &&
458 assert(bpf_map_get_next_key(fd, &next_key, &next_key) == 0 &&
460 assert(bpf_map_get_next_key(fd, &next_key, &next_key) < 0 &&
465 assert(bpf_map_delete_elem(fd, &key) < 0 && errno == EINVAL);
467 close(fd);
478 int key, fd, i;
480 fd = bpf_map_create(BPF_MAP_TYPE_PERCPU_ARRAY, NULL, sizeof(key),
482 if (fd < 0) {
492 assert(bpf_map_update_elem(fd, &key, values, BPF_ANY) == 0);
498 assert(bpf_map_lookup_elem(fd, &key, values) == 0);
504 close(fd);
509 int fd;
512 fd = bpf_map_create(BPF_MAP_TYPE_DEVMAP, NULL, sizeof(key), sizeof(value), 2, NULL);
513 if (fd < 0) {
518 close(fd);
523 int fd;
526 fd = bpf_map_create(BPF_MAP_TYPE_DEVMAP_HASH, NULL, sizeof(key), sizeof(value), 2, NULL);
527 if (fd < 0) {
532 close(fd);
539 int fd, i;
546 fd = bpf_map_create(BPF_MAP_TYPE_QUEUE, NULL, 4, sizeof(val), MAP_SIZE, &map_opts);
547 assert(fd < 0 && errno == EINVAL);
549 fd = bpf_map_create(BPF_MAP_TYPE_QUEUE, NULL, 0, sizeof(val), MAP_SIZE, &map_opts);
552 assert(fd < 0 && errno == EINVAL);
555 if (fd < 0) {
562 assert(bpf_map_update_elem(fd, NULL, &vals[i], 0) == 0);
565 assert(bpf_map_update_elem(fd, NULL, &val, 0) < 0 &&
569 assert(bpf_map_lookup_elem(fd, NULL, &val) == 0 && val == vals[0]);
573 assert(bpf_map_update_elem(fd, NULL, &vals[i], BPF_EXIST) == 0);
577 assert(bpf_map_lookup_and_delete_elem(fd, NULL, &val) == 0 &&
581 assert(bpf_map_lookup_and_delete_elem(fd, NULL, &val) < 0 &&
585 assert(bpf_map_delete_elem(fd, NULL) < 0 && errno == EINVAL);
586 assert(bpf_map_get_next_key(fd, NULL, NULL) < 0 && errno == EINVAL);
588 close(fd);
595 int fd, i;
602 fd = bpf_map_create(BPF_MAP_TYPE_STACK, NULL, 4, sizeof(val), MAP_SIZE, &map_opts);
603 assert(fd < 0 && errno == EINVAL);
605 fd = bpf_map_create(BPF_MAP_TYPE_STACK, NULL, 0, sizeof(val), MAP_SIZE, &map_opts);
608 assert(fd < 0 && errno == EINVAL);
611 if (fd < 0) {
618 assert(bpf_map_update_elem(fd, NULL, &vals[i], 0) == 0);
621 assert(bpf_map_update_elem(fd, NULL, &val, 0) < 0 &&
625 assert(bpf_map_lookup_elem(fd, NULL, &val) == 0 && val == vals[i - 1]);
629 assert(bpf_map_update_elem(fd, NULL, &vals[i], BPF_EXIST) == 0);
633 assert(bpf_map_lookup_and_delete_elem(fd, NULL, &val) == 0 &&
637 assert(bpf_map_lookup_and_delete_elem(fd, NULL, &val) < 0 &&
641 assert(bpf_map_delete_elem(fd, NULL) < 0 && errno == EINVAL);
642 assert(bpf_map_get_next_key(fd, NULL, NULL) < 0 && errno == EINVAL);
644 close(fd);
660 int err, i, fd, udp, sfd[6] = {0xdeadbeef};
734 fd = bpf_map_create(BPF_MAP_TYPE_SOCKMAP, NULL,
737 if (fd < 0) {
747 printf("Failed to create sockmap %i\n", fd);
754 err = bpf_map_update_elem(fd, &i, &udp, BPF_ANY);
764 err = bpf_map_update_elem(fd, &i, &sfd[i], BPF_ANY);
773 err = bpf_prog_attach(-1, fd, BPF_SK_SKB_STREAM_PARSER, 0);
779 err = bpf_prog_attach(-1, fd, BPF_SK_SKB_STREAM_VERDICT, 0);
785 err = bpf_prog_attach(-1, fd, BPF_SK_MSG_VERDICT, 0);
791 err = bpf_prog_attach(-1, fd, __MAX_BPF_ATTACH_TYPE, 0);
797 err = bpf_prog_detach(fd, BPF_SK_SKB_STREAM_PARSER);
803 err = bpf_prog_detach(fd, BPF_SK_SKB_STREAM_VERDICT);
809 err = bpf_prog_detach(fd, BPF_SK_MSG_VERDICT);
815 err = bpf_prog_detach(fd, __MAX_BPF_ATTACH_TYPE);
851 printf("Failed to get map rx fd\n");
863 printf("Failed to get map tx fd\n");
875 printf("Failed to get map msg fd\n");
887 printf("Failed to get map tx fd\n");
925 /* Test map update elem afterwards fd lives in fd and map_fd */
957 /* Put sfd[2] (sending fd below) into msg map to test sendmsg bpf */
1009 /* Push fd into same slot */
1011 err = bpf_map_update_elem(fd, &i, &sfd[i], BPF_NOEXIST);
1017 err = bpf_map_update_elem(fd, &i, &sfd[i], BPF_ANY);
1023 err = bpf_map_update_elem(fd, &i, &sfd[i], BPF_EXIST);
1031 err = bpf_map_delete_elem(fd, &i);
1039 err = bpf_prog_attach(parse_prog, fd,
1042 printf("Failed fd bpf parse prog attach\n");
1045 err = bpf_prog_attach(verdict_prog, fd,
1048 printf("Failed fd bpf verdict prog attach\n");
1053 err = bpf_map_update_elem(fd, &i, &sfd[i], BPF_ANY);
1059 err = bpf_map_update_elem(fd, &i, &sfd[i], BPF_NOEXIST);
1065 err = bpf_map_update_elem(fd, &i, &sfd[i], BPF_EXIST);
1123 close(fd);
1142 close(fd);
1152 int mim_fd, fd, err;
1161 fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL, sizeof(int), sizeof(int), 2, NULL);
1162 if (fd < 0) {
1172 err = bpf_map__set_inner_map_fd(map, fd);
1183 err = bpf_map__set_inner_map_fd(map, fd);
1206 err = bpf_map_update_elem(mim_fd, &pos, &fd, 0);
1223 err = bpf_map_update_elem(mim_fd, &pos, &fd, 0);
1229 close(fd);
1230 fd = -1;
1270 fd = bpf_map_get_fd_by_id(id);
1271 if (fd < 0) {
1278 err = bpf_map_get_info_by_fd(fd, &info, &len);
1280 printf("Failed to get map info by fd %d: %d", fd,
1290 close(fd);
1297 if (fd >= 0)
1298 close(fd);
1312 int fd, i, value;
1314 fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL, sizeof(key), sizeof(value),
1316 if (fd < 0) {
1325 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) == 0);
1329 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) < 0 &&
1333 assert(bpf_map_get_next_key(fd, NULL, &key) == 0);
1336 assert(bpf_map_get_next_key(fd, &key, &key) == 0);
1337 assert(bpf_map_get_next_key(fd, &key, &key) < 0 && errno == ENOENT);
1340 assert(bpf_map_lookup_elem(fd, &key, &value) == 0 && value == 0);
1342 assert(bpf_map_lookup_elem(fd, &key, &value) < 0 && errno == ENOENT);
1344 close(fd);
1445 int fd = ((int *)data)[0];
1454 err = map_update_retriable(fd, &key, &value, BPF_NOEXIST, MAP_RETRIES,
1459 err = map_update_retriable(fd, &key, &value, BPF_EXIST, MAP_RETRIES,
1465 err = map_delete_retriable(fd, &key, MAP_RETRIES);
1475 int i, fd, key = 0, value = 0, j = 0;
1478 fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL, sizeof(key), sizeof(value),
1480 if (fd < 0) {
1487 /* Use the same fd in children to add elements to this map:
1492 data[0] = fd;
1497 assert(bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST) < 0 &&
1501 assert(bpf_map_get_next_key(fd, NULL, &key) == 0);
1504 assert(bpf_map_get_next_key(fd, &key, &key) == 0);
1505 assert(bpf_map_get_next_key(fd, &key, &key) < 0 && errno == ENOENT);
1511 assert(bpf_map_lookup_elem(fd, &key, &value) == 0 &&
1521 assert(bpf_map_get_next_key(fd, NULL, &key) < 0 && errno == ENOENT);
1522 assert(bpf_map_get_next_key(fd, &key, &key) < 0 && errno == ENOENT);
1525 bpf_map_delete_elem(fd, &key);
1528 close(fd);
1533 int fd, key = 0, value = 0;
1538 fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL, sizeof(key), sizeof(value),
1541 if (fd < 0) {
1550 assert(bpf_map_update_elem(fd, &key, &value, BPF_ANY) < 0 &&
1554 assert(bpf_map_lookup_elem(fd, &key, &value) < 0 && errno == ENOENT);
1555 assert(bpf_map_get_next_key(fd, &key, &value) < 0 && errno == ENOENT);
1557 close(fd);
1562 int fd, key = 0, value = 0;
1567 fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL, sizeof(key), sizeof(value),
1570 if (fd < 0) {
1579 assert(bpf_map_update_elem(fd, &key, &value, BPF_ANY) == 0);
1582 assert(bpf_map_lookup_elem(fd, &key, &value) < 0 && errno == EPERM);
1583 assert(bpf_map_get_next_key(fd, &key, &value) < 0 && errno == EPERM);
1585 close(fd);
1590 int fd, value = 0;
1598 fd = bpf_map_create(map_type, NULL, 0, sizeof(value), MAP_SIZE, &map_opts);
1602 assert(fd < 0 && errno == EINVAL);
1605 if (fd < 0) {
1611 assert(bpf_map_update_elem(fd, NULL, &value, BPF_ANY) == 0);
1614 assert(bpf_map_lookup_elem(fd, NULL, &value) < 0 && errno == EPERM);
1617 assert(bpf_map_lookup_and_delete_elem(fd, NULL, &value) < 0 &&
1620 close(fd);
1726 int fd;
1864 /* Test 32 bit fd */
1871 fd = fd64;
1872 err = bpf_map_update_elem(map_fd, &index3, &fd, BPF_NOEXIST);
1873 CHECK(err < 0, "reuseport array update 32 bit fd",
1877 "reuseport array lookup 32 bit fd",
1879 close(fd);