Lines Matching refs:p

44 BPFProgram *bpf_program_free(BPFProgram *p) {  in bpf_program_free()  argument
45 if (!p) in bpf_program_free()
55 (void) bpf_program_cgroup_detach(p); in bpf_program_free()
57 safe_close(p->kernel_fd); in bpf_program_free()
58 free(p->prog_name); in bpf_program_free()
59 free(p->instructions); in bpf_program_free()
60 free(p->attached_path); in bpf_program_free()
62 return mfree(p); in bpf_program_free()
83 _cleanup_(bpf_program_freep) BPFProgram *p = NULL; in bpf_program_new()
95 p = new(BPFProgram, 1); in bpf_program_new()
96 if (!p) in bpf_program_new()
99 *p = (BPFProgram) { in bpf_program_new()
105 *ret = TAKE_PTR(p); in bpf_program_new()
111 _cleanup_(bpf_program_freep) BPFProgram *p = NULL; in bpf_program_new_from_bpffs_path()
118 p = new(BPFProgram, 1); in bpf_program_new_from_bpffs_path()
119 if (!p) in bpf_program_new_from_bpffs_path()
122 *p = (BPFProgram) { in bpf_program_new_from_bpffs_path()
127 r = bpf_program_load_from_bpf_fs(p, path); in bpf_program_new_from_bpffs_path()
131 r = bpf_program_get_info_by_fd(p->kernel_fd, &info, sizeof(info)); in bpf_program_new_from_bpffs_path()
135 p->prog_type = info.type; in bpf_program_new_from_bpffs_path()
136 *ret = TAKE_PTR(p); in bpf_program_new_from_bpffs_path()
142 int bpf_program_add_instructions(BPFProgram *p, const struct bpf_insn *instructions, size_t count) { in bpf_program_add_instructions() argument
144 assert(p); in bpf_program_add_instructions()
146 if (p->kernel_fd >= 0) /* don't allow modification after we uploaded things to the kernel */ in bpf_program_add_instructions()
149 if (!GREEDY_REALLOC(p->instructions, p->n_instructions + count)) in bpf_program_add_instructions()
152 memcpy(p->instructions + p->n_instructions, instructions, sizeof(struct bpf_insn) * count); in bpf_program_add_instructions()
153 p->n_instructions += count; in bpf_program_add_instructions()
158 int bpf_program_load_kernel(BPFProgram *p, char *log_buf, size_t log_size) { in bpf_program_load_kernel() argument
161 assert(p); in bpf_program_load_kernel()
163 if (p->kernel_fd >= 0) { /* make this idempotent */ in bpf_program_load_kernel()
173 attr.prog_type = p->prog_type; in bpf_program_load_kernel()
174 attr.insns = PTR_TO_UINT64(p->instructions); in bpf_program_load_kernel()
175 attr.insn_cnt = p->n_instructions; in bpf_program_load_kernel()
180 if (p->prog_name) in bpf_program_load_kernel()
181 strncpy(attr.prog_name, p->prog_name, BPF_OBJ_NAME_LEN - 1); in bpf_program_load_kernel()
183 p->kernel_fd = bpf(BPF_PROG_LOAD, &attr, sizeof(attr)); in bpf_program_load_kernel()
184 if (p->kernel_fd < 0) in bpf_program_load_kernel()
190 int bpf_program_load_from_bpf_fs(BPFProgram *p, const char *path) { in bpf_program_load_from_bpf_fs() argument
193 assert(p); in bpf_program_load_from_bpf_fs()
195 if (p->kernel_fd >= 0) /* don't overwrite an assembled or loaded program */ in bpf_program_load_from_bpf_fs()
201 p->kernel_fd = bpf(BPF_OBJ_GET, &attr, sizeof(attr)); in bpf_program_load_from_bpf_fs()
202 if (p->kernel_fd < 0) in bpf_program_load_from_bpf_fs()
208 int bpf_program_cgroup_attach(BPFProgram *p, int type, const char *path, uint32_t flags) { in bpf_program_cgroup_attach() argument
214 assert(p); in bpf_program_cgroup_attach()
223 if (p->attached_path) { in bpf_program_cgroup_attach()
224 if (!path_equal(p->attached_path, path)) in bpf_program_cgroup_attach()
226 if (p->attached_type != type) in bpf_program_cgroup_attach()
228 if (p->attached_flags != flags) in bpf_program_cgroup_attach()
242 r = bpf_program_load_kernel(p, NULL, 0); in bpf_program_cgroup_attach()
257 attr.attach_bpf_fd = p->kernel_fd; in bpf_program_cgroup_attach()
263 free_and_replace(p->attached_path, copy); in bpf_program_cgroup_attach()
264 p->attached_type = type; in bpf_program_cgroup_attach()
265 p->attached_flags = flags; in bpf_program_cgroup_attach()
270 int bpf_program_cgroup_detach(BPFProgram *p) { in bpf_program_cgroup_detach() argument
273 assert(p); in bpf_program_cgroup_detach()
275 if (!p->attached_path) in bpf_program_cgroup_detach()
278 fd = open(p->attached_path, O_DIRECTORY|O_RDONLY|O_CLOEXEC); in bpf_program_cgroup_detach()
290 attr.attach_type = p->attached_type; in bpf_program_cgroup_detach()
292 attr.attach_bpf_fd = p->kernel_fd; in bpf_program_cgroup_detach()
298 p->attached_path = mfree(p->attached_path); in bpf_program_cgroup_detach()
367 BPFProgram *p) { in bpf_program_serialize_attachment() argument
372 if (!p || !p->attached_path) in bpf_program_serialize_attachment()
375 assert(p->kernel_fd >= 0); in bpf_program_serialize_attachment()
377 escaped = cescape(p->attached_path); in bpf_program_serialize_attachment()
381 copy = fdset_put_dup(fds, p->kernel_fd); in bpf_program_serialize_attachment()
390 bpf_cgroup_attach_type_to_string(p->attached_type), in bpf_program_serialize_attachment()
403 p->attached_path = mfree(p->attached_path); in bpf_program_serialize_attachment()
408 BPFProgram *p; in bpf_program_serialize_attachment_set() local
411 SET_FOREACH(p, set) { in bpf_program_serialize_attachment_set()
412 r = bpf_program_serialize_attachment(f, fds, key, p); in bpf_program_serialize_attachment_set()
422 _cleanup_(bpf_program_freep) BPFProgram *p = NULL; in bpf_program_deserialize_attachment()
463 p = new(BPFProgram, 1); in bpf_program_deserialize_attachment()
464 if (!p) in bpf_program_deserialize_attachment()
467 *p = (BPFProgram) { in bpf_program_deserialize_attachment()
477 *bpfp = TAKE_PTR(p); in bpf_program_deserialize_attachment()
482 BPFProgram *p = NULL; in bpf_program_deserialize_attachment_set() local
488 r = bpf_program_deserialize_attachment(v, fds, &p); in bpf_program_deserialize_attachment_set()
492 r = set_ensure_consume(bpfsetp, &bpf_program_hash_ops, p); in bpf_program_deserialize_attachment_set()