Commit d62c5d48 authored by Jakub Kicinski's avatar Jakub Kicinski

tools: ynl: make yarg the first member of struct ynl_dump_state

All YNL parsing code expects a pointer to struct ynl_parse_arg AKA yarg.
For dump was pass in struct ynl_dump_state, which works fine, because
struct ynl_dump_state and struct ynl_parse_arg have identical layout
for the members that matter.. but it's a bit hacky.
Acked-by: default avatarNicolas Dichtel <nicolas.dichtel@6wind.com>
Link: https://lore.kernel.org/r/20240227223032.1835527-7-kuba@kernel.orgSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 7600875f
...@@ -104,8 +104,7 @@ struct ynl_req_state { ...@@ -104,8 +104,7 @@ struct ynl_req_state {
}; };
struct ynl_dump_state { struct ynl_dump_state {
struct ynl_sock *ys; struct ynl_parse_arg yarg;
struct ynl_policy_nest *rsp_policy;
void *first; void *first;
struct ynl_dump_list_type *last; struct ynl_dump_list_type *last;
size_t alloc_sz; size_t alloc_sz;
......
...@@ -864,7 +864,7 @@ static int ynl_dump_trampoline(const struct nlmsghdr *nlh, void *data) ...@@ -864,7 +864,7 @@ static int ynl_dump_trampoline(const struct nlmsghdr *nlh, void *data)
struct ynl_parse_arg yarg = {}; struct ynl_parse_arg yarg = {};
int ret; int ret;
ret = ynl_check_alien(ds->ys, nlh, ds->rsp_cmd); ret = ynl_check_alien(ds->yarg.ys, nlh, ds->rsp_cmd);
if (ret) if (ret)
return ret < 0 ? MNL_CB_ERROR : MNL_CB_OK; return ret < 0 ? MNL_CB_ERROR : MNL_CB_OK;
...@@ -878,8 +878,7 @@ static int ynl_dump_trampoline(const struct nlmsghdr *nlh, void *data) ...@@ -878,8 +878,7 @@ static int ynl_dump_trampoline(const struct nlmsghdr *nlh, void *data)
ds->last->next = obj; ds->last->next = obj;
ds->last = obj; ds->last = obj;
yarg.ys = ds->ys; yarg = ds->yarg;
yarg.rsp_policy = ds->rsp_policy;
yarg.data = &obj->data; yarg.data = &obj->data;
return ds->cb(nlh, &yarg); return ds->cb(nlh, &yarg);
......
...@@ -1844,14 +1844,15 @@ def print_dump(ri): ...@@ -1844,14 +1844,15 @@ def print_dump(ri):
ri.cw.write_func_lvar(local_vars) ri.cw.write_func_lvar(local_vars)
ri.cw.p('yds.ys = ys;') ri.cw.p('yds.yarg.ys = ys;')
ri.cw.p(f"yds.yarg.rsp_policy = &{ri.struct['reply'].render_name}_nest;")
ri.cw.p("yds.yarg.data = NULL;")
ri.cw.p(f"yds.alloc_sz = sizeof({type_name(ri, rdir(direction))});") ri.cw.p(f"yds.alloc_sz = sizeof({type_name(ri, rdir(direction))});")
ri.cw.p(f"yds.cb = {op_prefix(ri, 'reply', deref=True)}_parse;") ri.cw.p(f"yds.cb = {op_prefix(ri, 'reply', deref=True)}_parse;")
if ri.op.value is not None: if ri.op.value is not None:
ri.cw.p(f'yds.rsp_cmd = {ri.op.enum_name};') ri.cw.p(f'yds.rsp_cmd = {ri.op.enum_name};')
else: else:
ri.cw.p(f'yds.rsp_cmd = {ri.op.rsp_value};') ri.cw.p(f'yds.rsp_cmd = {ri.op.rsp_value};')
ri.cw.p(f"yds.rsp_policy = &{ri.struct['reply'].render_name}_nest;")
ri.cw.nl() ri.cw.nl()
ri.cw.p(f"nlh = ynl_gemsg_start_dump(ys, {ri.nl.get_family_id()}, {ri.op.enum_name}, 1);") ri.cw.p(f"nlh = ynl_gemsg_start_dump(ys, {ri.nl.get_family_id()}, {ri.op.enum_name}, 1);")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment