Skip to content

Commit

Permalink
tools: ynl: fully inherit attrs in subsets
Browse files Browse the repository at this point in the history
To avoid having to repeat the entire definition of an attribute
(including the value) use the Attr object from the original set.
In fact this is already the documented expectation.

Fixes: be5bea1 ("net: add basic C code generators for Netlink")
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Jakub Kicinski authored and David S. Miller committed Mar 3, 2023
1 parent ad93bab commit 7cf9353
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
3 changes: 2 additions & 1 deletion Documentation/userspace-api/netlink/specs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ The ``value`` property can be skipped, in which case the attribute ID
will be the value of the previous attribute plus one (recursively)
and ``0`` for the first attribute in the attribute set.

Note that the ``value`` of an attribute is defined only in its main set.
Note that the ``value`` of an attribute is defined only in its main set
(not in subsets).

enum
~~~~
Expand Down
23 changes: 15 additions & 8 deletions tools/net/ynl/lib/nlspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,22 @@ def __init__(self, family, yaml):
self.attrs = collections.OrderedDict()
self.attrs_by_val = collections.OrderedDict()

val = 0
for elem in self.yaml['attributes']:
if 'value' in elem:
val = elem['value']
if self.subset_of is None:
val = 0
for elem in self.yaml['attributes']:
if 'value' in elem:
val = elem['value']

attr = self.new_attr(elem, val)
self.attrs[attr.name] = attr
self.attrs_by_val[attr.value] = attr
val += 1
attr = self.new_attr(elem, val)
self.attrs[attr.name] = attr
self.attrs_by_val[attr.value] = attr
val += 1
else:
real_set = family.attr_sets[self.subset_of]
for elem in self.yaml['attributes']:
attr = real_set[elem['name']]
self.attrs[attr.name] = attr
self.attrs_by_val[attr.value] = attr

def new_attr(self, elem, value):
return SpecAttr(self.family, self, elem, value)
Expand Down

0 comments on commit 7cf9353

Please sign in to comment.