Skip to content

Commit

Permalink
tools: ynl-gen: stop generating common notification handlers
Browse files Browse the repository at this point in the history
Common notification handler was supposed to be a way for the user
to parse the notifications from a socket synchronously.
I don't think we'll end up using it, ynl_ntf_check() works for
all known use cases.

Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
kuba-moo committed Jun 9, 2023
1 parent 7234415 commit f2ba1e5
Showing 1 changed file with 0 additions and 73 deletions.
73 changes: 0 additions & 73 deletions tools/net/ynl/ynl-gen-c.py
Original file line number Diff line number Diff line change
Expand Up @@ -1810,70 +1810,6 @@ def print_ntf_type_free(ri):
ri.cw.nl()


def print_ntf_parse_prototype(family, cw, suffix=';'):
cw.write_func_prot('struct ynl_ntf_base_type *', f"{family['name']}_ntf_parse",
['struct ynl_sock *ys'], suffix=suffix)


def print_ntf_type_parse(family, cw, ku_mode):
print_ntf_parse_prototype(family, cw, suffix='')
cw.block_start()
cw.write_func_lvar(['struct genlmsghdr *genlh;',
'struct nlmsghdr *nlh;',
'struct ynl_parse_arg yarg = { .ys = ys, };',
'struct ynl_ntf_base_type *rsp;',
'int len, err;',
'mnl_cb_t parse;'])
cw.p('len = mnl_socket_recvfrom(ys->sock, ys->rx_buf, MNL_SOCKET_BUFFER_SIZE);')
cw.p('if (len < (ssize_t)(sizeof(*nlh) + sizeof(*genlh)))')
cw.p('return NULL;')
cw.nl()
cw.p('nlh = (struct nlmsghdr *)ys->rx_buf;')
cw.p('genlh = mnl_nlmsg_get_payload(nlh);')
cw.nl()
cw.block_start(line='switch (genlh->cmd)')
for ntf_op in sorted(family.all_notify.keys()):
op = family.ops[ntf_op]
ri = RenderInfo(cw, family, ku_mode, op, ntf_op, "notify")
for ntf in op['notify']['cmds']:
cw.p(f"case {ntf.enum_name}:")
cw.p(f"rsp = calloc(1, sizeof({type_name(ri, 'notify')}));")
cw.p(f"parse = {op_prefix(ri, 'reply', deref=True)}_parse;")
cw.p(f"yarg.rsp_policy = &{ri.struct['reply'].render_name}_nest;")
cw.p(f"rsp->free = (void *){op_prefix(ri, 'notify')}_free;")
cw.p('break;')
for op_name, op in family.ops.items():
if 'event' not in op:
continue
ri = RenderInfo(cw, family, ku_mode, op, op_name, "event")
cw.p(f"case {op.enum_name}:")
cw.p(f"rsp = calloc(1, sizeof({type_name(ri, 'event')}));")
cw.p(f"parse = {op_prefix(ri, 'reply', deref=True)}_parse;")
cw.p(f"yarg.rsp_policy = &{ri.struct['reply'].render_name}_nest;")
cw.p(f"rsp->free = (void *){op_prefix(ri, 'notify')}_free;")
cw.p('break;')
cw.p('default:')
cw.p('ynl_error_unknown_notification(ys, genlh->cmd);')
cw.p('return NULL;')
cw.block_end()
cw.nl()
cw.p('yarg.data = rsp->data;')
cw.nl()
cw.p(f"err = {cw.nlib.parse_cb_run('parse', '&yarg', True)};")
cw.p('if (err < 0)')
cw.p('goto err_free;')
cw.nl()
cw.p('rsp->family = nlh->nlmsg_type;')
cw.p('rsp->cmd = genlh->cmd;')
cw.p('return rsp;')
cw.nl()
cw.p('err_free:')
cw.p('free(rsp);')
cw.p('return NULL;')
cw.block_end()
cw.nl()


def print_req_policy_fwd(cw, struct, ri=None, terminate=True):
if terminate and ri and kernel_can_gen_family_struct(struct.family):
return
Expand Down Expand Up @@ -2513,10 +2449,6 @@ def main():
print_rsp_type(ri)
cw.nl()
print_wrapped_type(ri)

if parsed.has_notifications():
cw.p('/* --------------- Common notification parsing --------------- */')
print_ntf_parse_prototype(parsed, cw)
cw.nl()
else:
cw.p('/* Enums */')
Expand Down Expand Up @@ -2580,11 +2512,6 @@ def main():

ri = RenderInfo(cw, parsed, args.mode, op, op_name, "event")
print_ntf_type_free(ri)

if parsed.has_notifications():
cw.p('/* --------------- Common notification parsing --------------- */')
print_ntf_type_parse(parsed, cw, args.mode)

cw.nl()
render_user_family(parsed, cw, False)

Expand Down

0 comments on commit f2ba1e5

Please sign in to comment.