Skip to content

Commit 7e8ba0c

Browse files
committed
tools: ynl: don't use genlmsghdr in classic netlink
Make sure the codegen calls the right YNL lib helper to start the request based on family type. Classic netlink request must not include the genl header. Conversely don't expect genl headers in the responses. Reviewed-by: Jacob Keller <[email protected]> Reviewed-by: Donald Hunter <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent e0a7903 commit 7e8ba0c

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

tools/net/ynl/lib/ynl-priv.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ struct ynl_ntf_base_type {
9494
unsigned char data[] __attribute__((aligned(8)));
9595
};
9696

97+
struct nlmsghdr *ynl_msg_start_req(struct ynl_sock *ys, __u32 id);
98+
struct nlmsghdr *ynl_msg_start_dump(struct ynl_sock *ys, __u32 id);
99+
97100
struct nlmsghdr *
98101
ynl_gemsg_start_req(struct ynl_sock *ys, __u32 id, __u8 cmd, __u8 version);
99102
struct nlmsghdr *

tools/net/ynl/lib/ynl.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,14 +451,14 @@ ynl_gemsg_start(struct ynl_sock *ys, __u32 id, __u16 flags,
451451
return nlh;
452452
}
453453

454-
void ynl_msg_start_req(struct ynl_sock *ys, __u32 id)
454+
struct nlmsghdr *ynl_msg_start_req(struct ynl_sock *ys, __u32 id)
455455
{
456-
ynl_msg_start(ys, id, NLM_F_REQUEST | NLM_F_ACK);
456+
return ynl_msg_start(ys, id, NLM_F_REQUEST | NLM_F_ACK);
457457
}
458458

459-
void ynl_msg_start_dump(struct ynl_sock *ys, __u32 id)
459+
struct nlmsghdr *ynl_msg_start_dump(struct ynl_sock *ys, __u32 id)
460460
{
461-
ynl_msg_start(ys, id, NLM_F_REQUEST | NLM_F_ACK | NLM_F_DUMP);
461+
return ynl_msg_start(ys, id, NLM_F_REQUEST | NLM_F_ACK | NLM_F_DUMP);
462462
}
463463

464464
struct nlmsghdr *

tools/net/ynl/pyynl/ynl_gen_c.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,7 +1710,10 @@ def _multi_parse(ri, struct, init_lines, local_vars):
17101710
ri.cw.p(f'dst->{arg} = {arg};')
17111711

17121712
if ri.fixed_hdr:
1713-
ri.cw.p('hdr = ynl_nlmsg_data_offset(nlh, sizeof(struct genlmsghdr));')
1713+
if ri.family.is_classic():
1714+
ri.cw.p('hdr = ynl_nlmsg_data(nlh);')
1715+
else:
1716+
ri.cw.p('hdr = ynl_nlmsg_data_offset(nlh, sizeof(struct genlmsghdr));')
17141717
ri.cw.p(f"memcpy(&dst->_hdr, hdr, sizeof({ri.fixed_hdr}));")
17151718
for anest in sorted(all_multi):
17161719
aspec = struct[anest]
@@ -1857,7 +1860,10 @@ def print_req(ri):
18571860
ri.cw.block_start()
18581861
ri.cw.write_func_lvar(local_vars)
18591862

1860-
ri.cw.p(f"nlh = ynl_gemsg_start_req(ys, {ri.nl.get_family_id()}, {ri.op.enum_name}, 1);")
1863+
if ri.family.is_classic():
1864+
ri.cw.p(f"nlh = ynl_msg_start_req(ys, {ri.op.enum_name});")
1865+
else:
1866+
ri.cw.p(f"nlh = ynl_gemsg_start_req(ys, {ri.nl.get_family_id()}, {ri.op.enum_name}, 1);")
18611867

18621868
ri.cw.p(f"ys->req_policy = &{ri.struct['request'].render_name}_nest;")
18631869
if 'reply' in ri.op[ri.op_mode]:
@@ -1926,7 +1932,10 @@ def print_dump(ri):
19261932
else:
19271933
ri.cw.p(f'yds.rsp_cmd = {ri.op.rsp_value};')
19281934
ri.cw.nl()
1929-
ri.cw.p(f"nlh = ynl_gemsg_start_dump(ys, {ri.nl.get_family_id()}, {ri.op.enum_name}, 1);")
1935+
if ri.family.is_classic():
1936+
ri.cw.p(f"nlh = ynl_msg_start_dump(ys, {ri.op.enum_name});")
1937+
else:
1938+
ri.cw.p(f"nlh = ynl_gemsg_start_dump(ys, {ri.nl.get_family_id()}, {ri.op.enum_name}, 1);")
19301939

19311940
if ri.fixed_hdr:
19321941
ri.cw.p("hdr_len = sizeof(req->_hdr);")
@@ -2736,7 +2745,9 @@ def render_user_family(family, cw, prototype):
27362745
if family.is_classic():
27372746
cw.p(f'.is_classic\t= true,')
27382747
cw.p(f'.classic_id\t= {family.get("protonum")},')
2739-
if family.fixed_header:
2748+
if family.is_classic():
2749+
cw.p(f'.hdr_len\t= sizeof(struct {c_lower(family.fixed_header)}),')
2750+
elif family.fixed_header:
27402751
cw.p(f'.hdr_len\t= sizeof(struct genlmsghdr) + sizeof(struct {c_lower(family.fixed_header)}),')
27412752
else:
27422753
cw.p('.hdr_len\t= sizeof(struct genlmsghdr),')

0 commit comments

Comments
 (0)