meson: remove dead dictionary access
[qemu/ar7.git] / ebpf / ebpf.c
blob2d73beb47968679bf3c4752f61b40fa3caeb82b5
1 /*
2 * QEMU eBPF binary declaration routine.
4 * Developed by Daynix Computing LTD (http://www.daynix.com)
6 * Authors:
7 * Andrew Melnychenko <andrew@daynix.com>
9 * SPDX-License-Identifier: GPL-2.0-or-later
12 #include "qemu/osdep.h"
13 #include "qemu/queue.h"
14 #include "qapi/error.h"
15 #include "qapi/qapi-commands-ebpf.h"
16 #include "ebpf/ebpf.h"
18 typedef struct ElfBinaryDataEntry {
19 int id;
20 const void *data;
21 size_t datalen;
23 QSLIST_ENTRY(ElfBinaryDataEntry) node;
24 } ElfBinaryDataEntry;
26 static QSLIST_HEAD(, ElfBinaryDataEntry) ebpf_elf_obj_list =
27 QSLIST_HEAD_INITIALIZER();
29 void ebpf_register_binary_data(int id, const void *data, size_t datalen)
31 struct ElfBinaryDataEntry *dataentry = NULL;
33 dataentry = g_new0(struct ElfBinaryDataEntry, 1);
34 dataentry->data = data;
35 dataentry->datalen = datalen;
36 dataentry->id = id;
38 QSLIST_INSERT_HEAD(&ebpf_elf_obj_list, dataentry, node);
41 const void *ebpf_find_binary_by_id(int id, size_t *sz, Error **errp)
43 struct ElfBinaryDataEntry *it = NULL;
44 QSLIST_FOREACH(it, &ebpf_elf_obj_list, node) {
45 if (id == it->id) {
46 *sz = it->datalen;
47 return it->data;
51 error_setg(errp, "can't find eBPF object with id: %d", id);
53 return NULL;
56 EbpfObject *qmp_request_ebpf(EbpfProgramID id, Error **errp)
58 EbpfObject *ret = NULL;
59 size_t size = 0;
60 const void *data = ebpf_find_binary_by_id(id, &size, errp);
61 if (!data) {
62 return NULL;
65 ret = g_new0(EbpfObject, 1);
66 ret->object = g_base64_encode(data, size);
68 return ret;