/linux/samples/bpf/ |
H A D | test_map_in_map_user.c | 17 static int map_fd[7]; variable 19 #define PORT_A (map_fd[0]) 20 #define PORT_H (map_fd[1]) 21 #define REG_RESULT_H (map_fd[2]) 22 #define INLINE_RESULT_H (map_fd[3]) 23 #define A_OF_PORT_A (map_fd[4]) /* Test case #0 */ 24 #define H_OF_PORT_A (map_fd[5]) /* Test case #1 */ 25 #define H_OF_PORT_H (map_fd[6]) /* Test case #2 */ 142 map_fd[0] = bpf_object__find_map_fd_by_name(obj, "port_a"); in main() 143 map_fd[1] = bpf_object__find_map_fd_by_name(obj, "port_h"); in main() [all …]
|
H A D | test_lru_dist.c | 96 int map_fd; member 102 lru->map_fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL, in pfect_lru_init() 106 assert(lru->map_fd != -1); in pfect_lru_init() 119 close(lru->map_fd); in pfect_lru_destroy() 130 if (!bpf_map_lookup_elem(lru->map_fd, &key, &node)) { in pfect_lru_lookup_or_insert() 147 bpf_map_update_elem(lru->map_fd, &node->key, &null_node, BPF_EXIST); in pfect_lru_lookup_or_insert() 155 assert(!bpf_map_update_elem(lru->map_fd, &key, &node, BPF_EXIST)); in pfect_lru_lookup_or_insert() 158 assert(!bpf_map_update_elem(lru->map_fd, &key, &node, BPF_NOEXIST)); in pfect_lru_lookup_or_insert() 207 int map_fd; in create_map() local 209 map_fd = bpf_map_create(map_type, NULL, sizeof(unsigned long long), in create_map() [all …]
|
H A D | tracex6_user.c | 23 static int map_fd[3]; variable 43 assert(bpf_map_update_elem(map_fd[0], &cpu, &pmu_fd, BPF_ANY) == 0); in check_on_cpu() 46 bpf_map_get_next_key(map_fd[1], &cpu, NULL); in check_on_cpu() 48 if (bpf_map_lookup_elem(map_fd[1], &cpu, &value)) { in check_on_cpu() 56 if (bpf_map_lookup_elem(map_fd[2], &cpu, &value2)) { in check_on_cpu() 66 assert(bpf_map_delete_elem(map_fd[0], &cpu) == 0 || error); in check_on_cpu() 69 assert(bpf_map_delete_elem(map_fd[1], &cpu) == 0 || error); in check_on_cpu() 196 map_fd[0] = bpf_object__find_map_fd_by_name(obj, "counters"); in main() 197 map_fd[1] = bpf_object__find_map_fd_by_name(obj, "values"); in main() 198 map_fd[2] = bpf_object__find_map_fd_by_name(obj, "values2"); in main() [all …]
|
H A D | offwaketime_user.c | 18 static int map_fd[2]; variable 54 if (bpf_map_lookup_elem(map_fd[1], &key->tret, ip) != 0) { in print_stack() 61 if (bpf_map_lookup_elem(map_fd[1], &key->wret, ip) != 0) { in print_stack() 91 print_stacks(map_fd[0]); in int_exit() 122 map_fd[0] = bpf_object__find_map_fd_by_name(obj, "counts"); in main() 123 map_fd[1] = bpf_object__find_map_fd_by_name(obj, "stackmap"); in main() 124 if (map_fd[0] < 0 || map_fd[1] < 0) { in main() 145 print_stacks(map_fd[0]); in main()
|
H A D | spintest_user.c | 16 int map_fd, i, j = 0; in main() local 39 map_fd = bpf_object__find_map_fd_by_name(obj, "my_map"); in main() 40 if (map_fd < 0) { in main() 58 while (bpf_map_get_next_key(map_fd, &key, &next_key) == 0) { in main() 59 bpf_map_lookup_elem(map_fd, &next_key, &value); in main() 73 while (bpf_map_get_next_key(map_fd, &key, &next_key) == 0) in main() 74 bpf_map_delete_elem(map_fd, &next_key); in main()
|
H A D | xdp_adjust_tail_user.c | 52 static void poll_stats(unsigned int map_fd, unsigned int kill_after_s) in poll_stats() argument 62 assert(bpf_map_lookup_elem(map_fd, &key, &value) == 0); in poll_stats() 89 int i, prog_fd, map_fd, opt; in main() local 164 map_fd = bpf_object__find_map_fd_by_name(obj, "xdp_adju.data"); in main() 165 if (map_fd < 0) { in main() 169 bpf_map_update_elem(map_fd, &key, &max_pckt_size, BPF_ANY); in main() 173 map_fd = bpf_object__find_map_fd_by_name(obj, "icmpcnt"); in main() 174 if (map_fd < 0) { in main() 194 poll_stats(map_fd, kill_after_s); in main()
|
H A D | sock_example.c | 38 int sock = -1, map_fd, prog_fd, i, key; in test_sock() local 41 map_fd = bpf_map_create(BPF_MAP_TYPE_ARRAY, NULL, sizeof(key), sizeof(value), in test_sock() 43 if (map_fd < 0) { in test_sock() 54 BPF_LD_MAP_FD(BPF_REG_1, map_fd), in test_sock() 85 assert(bpf_map_lookup_elem(map_fd, &key, &tcp_cnt) == 0); in test_sock() 88 assert(bpf_map_lookup_elem(map_fd, &key, &udp_cnt) == 0); in test_sock() 91 assert(bpf_map_lookup_elem(map_fd, &key, &icmp_cnt) == 0); in test_sock()
|
H A D | ibumad_user.c | 31 static int map_fd[2]; variable 52 dump_counts(map_fd[0]); in dump_all_counts() 54 dump_counts(map_fd[1]); in dump_all_counts() 128 map_fd[0] = bpf_object__find_map_fd_by_name(obj, "read_count"); in main() 129 map_fd[1] = bpf_object__find_map_fd_by_name(obj, "write_count"); in main() 130 if (map_fd[0] < 0 || map_fd[1] < 0) { in main()
|
/linux/tools/testing/selftests/bpf/prog_tests/ |
H A D | lookup_and_delete.c | 13 static int fill_values(int map_fd) in fill_values() argument 19 err = bpf_map_update_elem(map_fd, &key, &value, BPF_NOEXIST); in fill_values() 27 static int fill_values_percpu(int map_fd) in fill_values_percpu() argument 36 err = bpf_map_update_elem(map_fd, &key, value, BPF_NOEXIST); in fill_values_percpu() 45 int *map_fd) in setup_prog() argument 66 *map_fd = bpf_map__fd(skel->maps.hash_map); in setup_prog() 67 if (!ASSERT_GE(*map_fd, 0, "bpf_map__fd")) in setup_prog() 102 int map_fd, err; in test_lookup_and_delete_hash() local 105 skel = setup_prog(BPF_MAP_TYPE_HASH, &map_fd); in test_lookup_and_delete_hash() 109 err = fill_values(map_fd); in test_lookup_and_delete_hash() [all …]
|
H A D | tailcalls.c | 18 int err, map_fd, prog_fd, main_fd, i, j; in test_tailcall_1() local 47 map_fd = bpf_map__fd(prog_array); in test_tailcall_1() 48 if (CHECK_FAIL(map_fd < 0)) in test_tailcall_1() 62 err = bpf_map_update_elem(map_fd, &i, &prog_fd, BPF_ANY); in test_tailcall_1() 72 err = bpf_map_delete_elem(map_fd, &i); in test_tailcall_1() 92 err = bpf_map_update_elem(map_fd, &i, &prog_fd, BPF_ANY); in test_tailcall_1() 113 err = bpf_map_update_elem(map_fd, &i, &prog_fd, BPF_ANY); in test_tailcall_1() 125 err = bpf_map_delete_elem(map_fd, &i); in test_tailcall_1() 135 err = bpf_map_delete_elem(map_fd, &i); in test_tailcall_1() 154 int err, map_fd, prog_fd, main_fd, i; in test_tailcall_2() local [all …]
|
H A D | global_data.c | 7 int i, err, map_fd; in test_global_data_number() local 10 map_fd = bpf_find_map(__func__, obj, "result_number"); in test_global_data_number() 11 if (CHECK_FAIL(map_fd < 0)) in test_global_data_number() 33 err = bpf_map_lookup_elem(map_fd, &tests[i].key, &num); in test_global_data_number() 42 int i, err, map_fd; in test_global_data_string() local 45 map_fd = bpf_find_map(__func__, obj, "result_string"); in test_global_data_string() 46 if (CHECK_FAIL(map_fd < 0)) in test_global_data_string() 62 err = bpf_map_lookup_elem(map_fd, &tests[i].key, str); in test_global_data_string() 77 int i, err, map_fd; in test_global_data_struct() local 80 map_fd = bpf_find_map(__func__, obj, "result_struct"); in test_global_data_struct() [all …]
|
H A D | bpf_obj_pinning.c | 41 int map_fd = -1, map_fd2 = -1; in bpf_obj_pinning_detached() local 75 map_fd = bpf_map_create(BPF_MAP_TYPE_ARRAY, map_name, 4, 4, 1, NULL); in bpf_obj_pinning_detached() 76 if (!ASSERT_GE(map_fd, 0, "map_fd")) in bpf_obj_pinning_detached() 82 err = bpf_obj_pin_opts(map_fd, map_name, &pin_opts); in bpf_obj_pinning_detached() 95 err = bpf_map_update_elem(map_fd, &zero, &src_value, 0); in bpf_obj_pinning_detached() 106 if (map_fd >= 0) in bpf_obj_pinning_detached() 107 ASSERT_OK(close(map_fd), "close_map_fd"); in bpf_obj_pinning_detached() 123 static void validate_pin(int map_fd, const char *map_name, int src_value, in validate_pin() argument 155 err = bpf_obj_pin_opts(map_fd, pin_path, &pin_opts); in validate_pin() 169 err = bpf_map_update_elem(map_fd, &zero, &src_value, 0); in validate_pin() [all …]
|
H A D | l4lb_all.c | 26 int err, i, prog_fd, map_fd; in test_l4lb() local 41 map_fd = bpf_find_map(__func__, obj, "vip_map"); in test_l4lb() 42 if (map_fd < 0) in test_l4lb() 44 bpf_map_update_elem(map_fd, &key, &value, 0); in test_l4lb() 46 map_fd = bpf_find_map(__func__, obj, "ch_rings"); in test_l4lb() 47 if (map_fd < 0) in test_l4lb() 49 bpf_map_update_elem(map_fd, &ch_key, &real_num, 0); in test_l4lb() 51 map_fd = bpf_find_map(__func__, obj, "reals"); in test_l4lb() 52 if (map_fd < 0) in test_l4lb() 54 bpf_map_update_elem(map_fd, &real_num, &real_def, 0); in test_l4lb() [all …]
|
H A D | map_init.c | 20 static int map_populate(int map_fd, int num) in map_populate() argument 30 err = bpf_map_update_elem(map_fd, &key, value, BPF_NOEXIST); in map_populate() 39 int *map_fd, int populate) in setup() argument 60 *map_fd = bpf_map__fd(skel->maps.hashmap1); in setup() 61 if (CHECK(*map_fd < 0, "bpf_map__fd", "failed\n")) in setup() 64 err = map_populate(*map_fd, populate); in setup() 71 close(*map_fd); in setup() 133 int map_fd, err; in test_pcpu_map_init() local 137 skel = setup(BPF_MAP_TYPE_PERCPU_HASH, 1, &map_fd, 1); in test_pcpu_map_init() 143 err = bpf_map_delete_elem(map_fd, &key); in test_pcpu_map_init() [all …]
|
H A D | map_lock.c | 23 int err, map_fd = *(u32 *) arg; in parallel_map_access() local 27 err = bpf_map_lookup_elem_flags(map_fd, &key, vars, BPF_F_LOCK); in parallel_map_access() 53 int prog_fd, map_fd[2], vars[17] = {}; in test_map_lock() local 64 map_fd[0] = bpf_find_map(__func__, obj, "hash_map"); in test_map_lock() 65 if (CHECK_FAIL(map_fd[0] < 0)) in test_map_lock() 67 map_fd[1] = bpf_find_map(__func__, obj, "array_map"); in test_map_lock() 68 if (CHECK_FAIL(map_fd[1] < 0)) in test_map_lock() 71 bpf_map_update_elem(map_fd[0], &key, vars, BPF_F_LOCK); in test_map_lock() 80 &map_fd[i - 4]))) in test_map_lock() 88 ret != (void *)&map_fd[i - 4])) in test_map_lock()
|
H A D | xdp_cpumap_attach.c | 21 int err, prog_fd, prog_redir_fd, map_fd; in test_xdp_with_cpumap_helpers() 41 map_fd = bpf_map__fd(skel->maps.cpu_map); in test_xdp_with_cpumap_helpers() 47 err = bpf_map_update_elem(map_fd, &idx, &val, 0); in test_xdp_with_cpumap_helpers() 50 err = bpf_map_lookup_elem(map_fd, &idx, &val); in test_xdp_with_cpumap_helpers() 81 err = bpf_map_update_elem(map_fd, &idx, &val, 0); in test_xdp_with_cpumap_frags_helpers() 90 err = bpf_map_update_elem(map_fd, &idx, &val, 0); in test_xdp_with_cpumap_frags_helpers() 107 int err, frags_prog_fd, map_fd; in test_xdp_with_cpumap_frags_helpers() 115 map_fd = bpf_map__fd(skel->maps.cpu_map); in serial_test_xdp_cpumap_attach() 121 err = bpf_map_update_elem(map_fd, &idx, &val, 0); in serial_test_xdp_cpumap_attach() 124 err = bpf_map_lookup_elem(map_fd, 19 int err, prog_fd, map_fd; test_xdp_with_cpumap_helpers() local 79 int err, frags_prog_fd, map_fd; test_xdp_with_cpumap_frags_helpers() local [all...] |
H A D | xdp_devmap_attach.c | 24 int err, dm_fd, dm_fd_redir, map_fd; in test_xdp_with_devmap_helpers() local 45 map_fd = bpf_map__fd(skel->maps.dm_ports); in test_xdp_with_devmap_helpers() 51 err = bpf_map_update_elem(map_fd, &idx, &val, 0); in test_xdp_with_devmap_helpers() 54 err = bpf_map_lookup_elem(map_fd, &idx, &val); in test_xdp_with_devmap_helpers() 81 err = bpf_map_update_elem(map_fd, &idx, &val, 0); in test_xdp_with_devmap_helpers() 90 err = bpf_map_update_elem(map_fd, &idx, &val, 0); in test_xdp_with_devmap_helpers() 118 int err, dm_fd_frags, map_fd; in test_xdp_with_devmap_frags_helpers() local 126 map_fd = bpf_map__fd(skel->maps.dm_ports); in test_xdp_with_devmap_frags_helpers() 132 err = bpf_map_update_elem(map_fd, &idx, &val, 0); in test_xdp_with_devmap_frags_helpers() 135 err = bpf_map_lookup_elem(map_fd, &idx, &val); in test_xdp_with_devmap_frags_helpers() [all …]
|
H A D | cgroup_attach_multi.c | 11 static int map_fd = -1; variable 17 if (map_fd < 0) in prog_load_cnt() 18 map_fd = bpf_map_create(BPF_MAP_TYPE_ARRAY, NULL, 4, 8, 1, NULL); in prog_load_cnt() 19 if (map_fd < 0) { in prog_load_cnt() 44 BPF_LD_MAP_FD(BPF_REG_1, map_fd), in prog_load_cnt() 151 CHECK_FAIL(bpf_map_lookup_elem(map_fd, &key, &value)); in serial_test_cgroup_attach_multi() 188 CHECK_FAIL(bpf_map_update_elem(map_fd, &key, &value, 0)); in serial_test_cgroup_attach_multi() 190 CHECK_FAIL(bpf_map_lookup_elem(map_fd, &key, &value)); in serial_test_cgroup_attach_multi() 241 CHECK_FAIL(bpf_map_update_elem(map_fd, &key, &value, 0)); in serial_test_cgroup_attach_multi() 243 CHECK_FAIL(bpf_map_lookup_elem(map_fd, &key, &value)); in serial_test_cgroup_attach_multi() [all …]
|
/linux/tools/testing/selftests/bpf/map_tests/ |
H A D | map_percpu_stats.c | 22 static void map_info(int map_fd, struct bpf_map_info *info) in map_info() argument 29 ret = bpf_obj_get_info_by_fd(map_fd, info, &len); in map_info() 51 static __u32 map_count_elements(__u32 type, int map_fd) in map_count_elements() argument 56 while (!bpf_map_get_next_key(map_fd, &key, &key)) in map_count_elements() 63 static void delete_and_lookup_batch(int map_fd, void *keys, __u32 count) in delete_and_lookup_batch() argument 70 ret = bpf_map_lookup_and_delete_batch(map_fd, in delete_and_lookup_batch() 89 static void delete_all_elements(__u32 type, int map_fd, bool batch) in delete_all_elements() argument 100 for (n = 0; !bpf_map_get_next_key(map_fd, &key, &key); n++) in delete_all_elements() 108 delete_and_lookup_batch(map_fd, keys, n); in delete_all_elements() 115 ret = bpf_map_delete_elem(map_fd, keyp); in delete_all_elements() [all …]
|
H A D | sk_storage_map.c | 144 int btf_fd, map_fd; in create_sk_storage_map() local 151 map_fd = bpf_map_create(BPF_MAP_TYPE_SK_STORAGE, "sk_storage_map", 4, 8, 0, &map_opts); in create_sk_storage_map() 154 CHECK(map_fd == -1, in create_sk_storage_map() 157 return map_fd; in create_sk_storage_map() 166 int i, map_fd, err, *sk_fds; in insert_close_thread() local 181 map_fd = READ_ONCE(sk_storage_map); in insert_close_thread() 189 err = bpf_map_update_elem(map_fd, &sk_fds[i], &value, in insert_close_thread() 225 int i, map_fd = -1, err = 0, nr_threads_created = 0; in do_sk_storage_map_stress_free() local 246 map_fd = create_sk_storage_map(); in do_sk_storage_map_stress_free() 247 WRITE_ONCE(sk_storage_map, map_fd); in do_sk_storage_map_stress_free() [all …]
|
H A D | htab_map_batch_ops.c | 14 static void map_batch_update(int map_fd, __u32 max_entries, int *keys, in map_batch_update() argument 37 err = bpf_map_update_batch(map_fd, keys, values, &max_entries, &opts); in map_batch_update() 81 int map_fd, *keys, *visited, key; in __test_map_lookup_and_delete_batch() local 92 map_fd = bpf_map_create(is_pcpu ? BPF_MAP_TYPE_PERCPU_HASH : BPF_MAP_TYPE_HASH, in __test_map_lookup_and_delete_batch() 94 CHECK(map_fd == -1, in __test_map_lookup_and_delete_batch() 109 err = bpf_map_lookup_and_delete_batch(map_fd, NULL, &batch, keys, in __test_map_lookup_and_delete_batch() 115 map_batch_update(map_fd, max_entries, keys, values, is_pcpu); in __test_map_lookup_and_delete_batch() 119 err = bpf_map_lookup_and_delete_batch(map_fd, NULL, &batch, keys, in __test_map_lookup_and_delete_batch() 127 err = bpf_map_lookup_and_delete_batch(map_fd, NULL, &batch, keys, in __test_map_lookup_and_delete_batch() 136 err = bpf_map_get_next_key(map_fd, NULL, &key); in __test_map_lookup_and_delete_batch() [all …]
|
H A D | lpm_trie_map_get_next_key.c | 27 int map_fd; member 41 bpf_map_get_next_key(ctx->map_fd, &ctx->key, &next_key); in get_next_key_fn() 67 int map_fd; in test_lpm_trie_map_get_next_key() local 75 map_fd = bpf_map_create(BPF_MAP_TYPE_LPM_TRIE, "lpm_trie_map", in test_lpm_trie_map_get_next_key() 78 CHECK(map_fd == -1, "bpf_map_create()", "error:%s\n", in test_lpm_trie_map_get_next_key() 83 err = bpf_map_update_elem(map_fd, &key, &val, BPF_ANY); in test_lpm_trie_map_get_next_key() 90 ctx.map_fd = map_fd; in test_lpm_trie_map_get_next_key() 108 close(map_fd); in test_lpm_trie_map_get_next_key()
|
H A D | lpm_trie_map_batch_ops.c | 22 static void map_batch_update(int map_fd, __u32 max_entries, in map_batch_update() argument 40 err = bpf_map_update_batch(map_fd, keys, values, &max_entries, &opts); in map_batch_update() 70 int map_fd, *values, *visited; in test_lpm_trie_map_batch_ops() local 80 map_fd = bpf_map_create(BPF_MAP_TYPE_LPM_TRIE, "lpm_trie_map", in test_lpm_trie_map_batch_ops() 83 CHECK(map_fd == -1, "bpf_map_create()", "error:%s\n", in test_lpm_trie_map_batch_ops() 94 map_batch_update(map_fd, max_entries, keys, values); in test_lpm_trie_map_batch_ops() 105 err = bpf_map_lookup_batch(map_fd, in test_lpm_trie_map_batch_ops() 127 err = bpf_map_delete_batch(map_fd, keys + total, &count, in test_lpm_trie_map_batch_ops() 139 err = bpf_map_get_next_key(map_fd, NULL, &key); in test_lpm_trie_map_batch_ops() 154 close(map_fd); in test_lpm_trie_map_batch_ops()
|
/linux/tools/testing/selftests/bpf/ |
H A D | test_lpm_map.c |
|
/linux/tools/bpf/bpftool/ |
H A D | iter.c | 22 int err = -1, map_fd = -1; in do_pin() local 40 map_fd = map_parse_fd(&argc, &argv); in do_pin() 41 if (map_fd < 0) in do_pin() 45 linfo.map.map_fd = map_fd; in do_pin() 95 if (map_fd >= 0) in do_pin() 96 close(map_fd); in do_pin()
|