From: Jiri Pirko Date: Thu, 22 Feb 2024 13:43:49 +0000 (+0100) Subject: tools: ynl: allow user to specify flag attr with bool values X-Git-Tag: v6.9-rc1~159^2~188^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ac95b1fca034d50d42a058a9476e0fe555653d0d;p=thirdparty%2Flinux.git tools: ynl: allow user to specify flag attr with bool values The flag attr presence in Netlink message indicates value "true", if it is missing in the message it means "false". Allow user to specify attrname with value "true"/"false" in json for flag attrs, treat "false" value properly. Signed-off-by: Jiri Pirko Reviewed-by: Donald Hunter Link: https://lore.kernel.org/r/20240222134351.224704-2-jiri@resnulli.us Signed-off-by: Jakub Kicinski --- diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py index f45ee5f29bed3..1c5c7662dc9aa 100644 --- a/tools/net/ynl/lib/ynl.py +++ b/tools/net/ynl/lib/ynl.py @@ -459,6 +459,9 @@ class YnlFamily(SpecFamily): attr_payload += self._add_attr(attr['nested-attributes'], subname, subvalue, sub_attrs) elif attr["type"] == 'flag': + if not value: + # If value is absent or false then skip attribute creation. + return b'' attr_payload = b'' elif attr["type"] == 'string': attr_payload = str(value).encode('ascii') + b'\x00'