Commit c311aaa7 authored by Jakub Kicinski's avatar Jakub Kicinski

tools: ynl: fix enum-as-flags in the generic CLI

Lorenzo points out that the generic CLI is broken for the netdev
family. When I added the support for documentation of enums
(and sparse enums) the client script was not updated.
It expects the values in enum to be a list of names,
now it can also be a dict (YAML object).
Reported-by: default avatarLorenzo Bianconi <lorenzo@kernel.org>
Fixes: e4b48ed4 ("tools: ynl: add a completely generic client")
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 6517a60b
...@@ -106,6 +106,7 @@ class SpecEnumSet(SpecElement): ...@@ -106,6 +106,7 @@ class SpecEnumSet(SpecElement):
Attributes: Attributes:
type enum or flags type enum or flags
entries entries by name entries entries by name
entries_by_val entries by value
Methods: Methods:
get_mask for flags compute the mask of all defined values get_mask for flags compute the mask of all defined values
""" """
...@@ -117,9 +118,11 @@ class SpecEnumSet(SpecElement): ...@@ -117,9 +118,11 @@ class SpecEnumSet(SpecElement):
prev_entry = None prev_entry = None
value_start = self.yaml.get('value-start', 0) value_start = self.yaml.get('value-start', 0)
self.entries = dict() self.entries = dict()
self.entries_by_val = dict()
for entry in self.yaml['entries']: for entry in self.yaml['entries']:
e = self.new_entry(entry, prev_entry, value_start) e = self.new_entry(entry, prev_entry, value_start)
self.entries[e.name] = e self.entries[e.name] = e
self.entries_by_val[e.raw_value()] = e
prev_entry = e prev_entry = e
def new_entry(self, entry, prev_entry, value_start): def new_entry(self, entry, prev_entry, value_start):
......
...@@ -303,11 +303,6 @@ class YnlFamily(SpecFamily): ...@@ -303,11 +303,6 @@ class YnlFamily(SpecFamily):
self.sock.setsockopt(Netlink.SOL_NETLINK, Netlink.NETLINK_CAP_ACK, 1) self.sock.setsockopt(Netlink.SOL_NETLINK, Netlink.NETLINK_CAP_ACK, 1)
self.sock.setsockopt(Netlink.SOL_NETLINK, Netlink.NETLINK_EXT_ACK, 1) self.sock.setsockopt(Netlink.SOL_NETLINK, Netlink.NETLINK_EXT_ACK, 1)
self._types = dict()
for elem in self.yaml.get('definitions', []):
self._types[elem['name']] = elem
self.async_msg_ids = set() self.async_msg_ids = set()
self.async_msg_queue = [] self.async_msg_queue = []
...@@ -353,13 +348,13 @@ class YnlFamily(SpecFamily): ...@@ -353,13 +348,13 @@ class YnlFamily(SpecFamily):
def _decode_enum(self, rsp, attr_spec): def _decode_enum(self, rsp, attr_spec):
raw = rsp[attr_spec['name']] raw = rsp[attr_spec['name']]
enum = self._types[attr_spec['enum']] enum = self.consts[attr_spec['enum']]
i = attr_spec.get('value-start', 0) i = attr_spec.get('value-start', 0)
if 'enum-as-flags' in attr_spec and attr_spec['enum-as-flags']: if 'enum-as-flags' in attr_spec and attr_spec['enum-as-flags']:
value = set() value = set()
while raw: while raw:
if raw & 1: if raw & 1:
value.add(enum['entries'][i]) value.add(enum.entries_by_val[i].name)
raw >>= 1 raw >>= 1
i += 1 i += 1
else: else:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment