Skip to content

Commit

Permalink
tools/net/ynl: fix sub-message key lookup for nested attributes
Browse files Browse the repository at this point in the history
[ Upstream commit 663ad74 ]

Use the correct attribute space for sub-message key lookup in nested
attributes when adding attributes. This fixes rt_link where the "kind"
key and "data" sub-message are nested attributes in "linkinfo".

For example:

./tools/net/ynl/cli.py \
    --create \
    --spec Documentation/netlink/specs/rt_link.yaml \
    --do newlink \
    --json '{"link": 99,
             "linkinfo": { "kind": "vlan", "data": {"id": 4 } }
             }'

Signed-off-by: Donald Hunter <donald.hunter@gmail.com>
Fixes: ab463c4 ("tools/net/ynl: Add support for encoding sub-messages")
Link: https://patch.msgid.link/20241213130711.40267-1-donald.hunter@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
donaldh authored and gregkh committed Dec 27, 2024
1 parent 8e9ef6b commit 1c2d799
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions tools/net/ynl/lib/ynl.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,10 +553,10 @@ def _add_attr(self, space, name, value, search_attrs):
if attr["type"] == 'nest':
nl_type |= Netlink.NLA_F_NESTED
attr_payload = b''
sub_attrs = SpaceAttrs(self.attr_sets[space], value, search_attrs)
sub_space = attr['nested-attributes']
sub_attrs = SpaceAttrs(self.attr_sets[sub_space], value, search_attrs)
for subname, subvalue in value.items():
attr_payload += self._add_attr(attr['nested-attributes'],
subname, subvalue, sub_attrs)
attr_payload += self._add_attr(sub_space, subname, subvalue, sub_attrs)
elif attr["type"] == 'flag':
if not value:
# If value is absent or false then skip attribute creation.
Expand Down

0 comments on commit 1c2d799

Please sign in to comment.