[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <m27cjzxdx0.fsf@gmail.com>
Date: Wed, 24 Jan 2024 09:45:47 +0000
From: Donald Hunter <donald.hunter@...il.com>
To: Alessandro Marcolini <alessandromarcolini99@...il.com>
Cc: davem@...emloft.net, edumazet@...gle.com, kuba@...nel.org,
pabeni@...hat.com, sdf@...gle.com, chuck.lever@...cle.com,
lorenzo@...nel.org, jacob.e.keller@...el.com, jiri@...nulli.us,
netdev@...r.kernel.org
Subject: Re: [PATCH net-next 3/3] tools: ynl: add encoding support for
'sub-message' to ynl
Alessandro Marcolini <alessandromarcolini99@...il.com> writes:
> On 1/23/24 17:44, Donald Hunter wrote:
>> Alessandro Marcolini <alessandromarcolini99@...il.com> writes:
>>
>>> Add encoding support for 'sub-message' attribute and for resolving
>>> sub-message selectors at different nesting level from the key
>>> attribute.
>> I think the relevant patches in my series are:
>>
>> https://lore.kernel.org/netdev/20240123160538.172-3-donald.hunter@gmail.com/T/#u
>> https://lore.kernel.org/netdev/20240123160538.172-5-donald.hunter@gmail.com/T/#u
> I really like your idea of using ChainMap, I think it's better than mine and more concise.
>>> Also, add encoding support for multi-attr attributes.
>> This would be better as a separate patch since it is unrelated to the
>> other changes.
> You mean as a separate patch in this patchset or as an entirely new patch?
I was thinking as a separate patch in this patchset, yes.
>>> Signed-off-by: Alessandro Marcolini <alessandromarcolini99@...il.com>
>>> ---
>>> tools/net/ynl/lib/ynl.py | 54 +++++++++++++++++++++++++++++++++++-----
>>> 1 file changed, 48 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py
>>> index 1e10512b2117..f8c56944f7e7 100644
>>> --- a/tools/net/ynl/lib/ynl.py
>>> +++ b/tools/net/ynl/lib/ynl.py
>>> @@ -449,7 +449,7 @@ class YnlFamily(SpecFamily):
>>> self.sock.setsockopt(Netlink.SOL_NETLINK, Netlink.NETLINK_ADD_MEMBERSHIP,
>>> mcast_id)
>>>
>>> - def _add_attr(self, space, name, value):
>>> + def _add_attr(self, space, name, value, vals):
>>> try:
>>> attr = self.attr_sets[space][name]
>>> except KeyError:
>>> @@ -458,8 +458,13 @@ class YnlFamily(SpecFamily):
>>> if attr["type"] == 'nest':
>>> nl_type |= Netlink.NLA_F_NESTED
>>> attr_payload = b''
>>> - for subname, subvalue in value.items():
>>> - attr_payload += self._add_attr(attr['nested-attributes'], subname, subvalue)
>>> + # Check if it's a list of values (i.e. it contains multi-attr elements)
>>> + for subname, subvalue in (
>>> + ((k, v) for item in value for k, v in item.items())
>>> + if isinstance(value, list)
>>> + else value.items()
>>> + ):
>>> + attr_payload += self._add_attr(attr['nested-attributes'], subname, subvalue, vals)
>> Should really check whether multi-attr is true in the spec before
>> processing the json input as a list of values.
> Yes, you're right. Maybe I could resend this on top of your changes, what do you think?
Yes, that would be great. Thanks!
Powered by blists - more mailing lists