Skip to content

Commit 7cf9353

Browse files
kuba-moodavem330
authored andcommitted
tools: ynl: fully inherit attrs in subsets
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 <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent ad93bab commit 7cf9353

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

Documentation/userspace-api/netlink/specs.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ The ``value`` property can be skipped, in which case the attribute ID
199199
will be the value of the previous attribute plus one (recursively)
200200
and ``0`` for the first attribute in the attribute set.
201201

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

204205
enum
205206
~~~~

tools/net/ynl/lib/nlspec.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,22 @@ def __init__(self, family, yaml):
9595
self.attrs = collections.OrderedDict()
9696
self.attrs_by_val = collections.OrderedDict()
9797

98-
val = 0
99-
for elem in self.yaml['attributes']:
100-
if 'value' in elem:
101-
val = elem['value']
98+
if self.subset_of is None:
99+
val = 0
100+
for elem in self.yaml['attributes']:
101+
if 'value' in elem:
102+
val = elem['value']
102103

103-
attr = self.new_attr(elem, val)
104-
self.attrs[attr.name] = attr
105-
self.attrs_by_val[attr.value] = attr
106-
val += 1
104+
attr = self.new_attr(elem, val)
105+
self.attrs[attr.name] = attr
106+
self.attrs_by_val[attr.value] = attr
107+
val += 1
108+
else:
109+
real_set = family.attr_sets[self.subset_of]
110+
for elem in self.yaml['attributes']:
111+
attr = real_set[elem['name']]
112+
self.attrs[attr.name] = attr
113+
self.attrs_by_val[attr.value] = attr
107114

108115
def new_attr(self, elem, value):
109116
return SpecAttr(self.family, self, elem, value)

0 commit comments

Comments
 (0)