From 02ccbfc1526276ca935a691392e56a47ebf9f117 Mon Sep 17 00:00:00 2001 From: Jesper Dangaard Brouer Date: Mon, 21 Mar 2022 12:47:56 +0100 Subject: [PATCH] AF_XDP-interaction: Move function xsk_btf__init_xdp_hint Signed-off-by: Jesper Dangaard Brouer --- AF_XDP-interaction/lib_xsk_extend.c | 106 ++++++++++++++-------------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/AF_XDP-interaction/lib_xsk_extend.c b/AF_XDP-interaction/lib_xsk_extend.c index 7221af9..ba2a8c8 100644 --- a/AF_XDP-interaction/lib_xsk_extend.c +++ b/AF_XDP-interaction/lib_xsk_extend.c @@ -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; +}