mirror of
https://github.com/xdp-project/bpf-examples.git
synced 2024-05-06 15:54:53 +00:00
AF_XDP-interaction: Move function xsk_btf__init_xdp_hint
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
This commit is contained in:
@@ -67,59 +67,6 @@ static bool __xsk_equal_fn(const void *k1, const void *k2, void *ctx)
|
||||
return k1 == k2;
|
||||
}
|
||||
|
||||
int xsk_btf__init_xdp_hint(struct btf *btf_obj,
|
||||
const char *xdp_hints_name,
|
||||
struct xsk_btf_info **xbi)
|
||||
{
|
||||
const struct btf_member *m;
|
||||
const struct btf_type *t;
|
||||
unsigned short vlen;
|
||||
int i, id, ret = 0;
|
||||
|
||||
if (!xbi)
|
||||
return -EINVAL;
|
||||
|
||||
/* Require XDP-hints are defined as a struct */
|
||||
id = btf__find_by_name_kind(btf_obj, xdp_hints_name, BTF_KIND_STRUCT);
|
||||
if (id < 0) {
|
||||
ret = id;
|
||||
goto error_btf;
|
||||
}
|
||||
|
||||
t = btf__type_by_id(btf_obj, id);
|
||||
|
||||
*xbi = malloc(sizeof(**xbi));
|
||||
if (!*xbi) {
|
||||
ret = -ENOMEM;
|
||||
goto error_btf;
|
||||
}
|
||||
|
||||
hashmap__init(&(*xbi)->map, __xsk_hash_fn, __xsk_equal_fn, NULL);
|
||||
|
||||
/* Validate no BTF field is a bitfield */
|
||||
m = btf_members(t);
|
||||
vlen = BTF_INFO_VLEN(t->info);
|
||||
for (i = 0; i < vlen; i++, m++) {
|
||||
if (BTF_MEMBER_BITFIELD_SIZE(m->offset)) {
|
||||
ret = -ENOTSUP;
|
||||
goto error_entry;
|
||||
}
|
||||
}
|
||||
|
||||
(*xbi)->btf = btf_obj;
|
||||
(*xbi)->type = t;
|
||||
(*xbi)->btf_type_id = id;
|
||||
|
||||
return ret;
|
||||
|
||||
error_entry:
|
||||
__xsk_btf_free_hash(*xbi);
|
||||
free(*xbi);
|
||||
|
||||
error_btf:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int __xsk_btf_field_entry(struct xsk_btf_info *xbi, const char *field,
|
||||
struct xsk_btf_member *entry)
|
||||
{
|
||||
@@ -219,3 +166,56 @@ int xsk_btf__read_field(void **dest, size_t size, const char *field,
|
||||
xsk_btf__read(dest, size, entry, xbi,addr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int xsk_btf__init_xdp_hint(struct btf *btf_obj,
|
||||
const char *xdp_hints_name,
|
||||
struct xsk_btf_info **xbi)
|
||||
{
|
||||
const struct btf_member *m;
|
||||
const struct btf_type *t;
|
||||
unsigned short vlen;
|
||||
int i, id, ret = 0;
|
||||
|
||||
if (!xbi)
|
||||
return -EINVAL;
|
||||
|
||||
/* Require XDP-hints are defined as a struct */
|
||||
id = btf__find_by_name_kind(btf_obj, xdp_hints_name, BTF_KIND_STRUCT);
|
||||
if (id < 0) {
|
||||
ret = id;
|
||||
goto error_btf;
|
||||
}
|
||||
|
||||
t = btf__type_by_id(btf_obj, id);
|
||||
|
||||
*xbi = malloc(sizeof(**xbi));
|
||||
if (!*xbi) {
|
||||
ret = -ENOMEM;
|
||||
goto error_btf;
|
||||
}
|
||||
|
||||
hashmap__init(&(*xbi)->map, __xsk_hash_fn, __xsk_equal_fn, NULL);
|
||||
|
||||
/* Validate no BTF field is a bitfield */
|
||||
m = btf_members(t);
|
||||
vlen = BTF_INFO_VLEN(t->info);
|
||||
for (i = 0; i < vlen; i++, m++) {
|
||||
if (BTF_MEMBER_BITFIELD_SIZE(m->offset)) {
|
||||
ret = -ENOTSUP;
|
||||
goto error_entry;
|
||||
}
|
||||
}
|
||||
|
||||
(*xbi)->btf = btf_obj;
|
||||
(*xbi)->type = t;
|
||||
(*xbi)->btf_type_id = id;
|
||||
|
||||
return ret;
|
||||
|
||||
error_entry:
|
||||
__xsk_btf_free_hash(*xbi);
|
||||
free(*xbi);
|
||||
|
||||
error_btf:
|
||||
return ret;
|
||||
}
|
||||
|
Reference in New Issue
Block a user