Skip to content

Commit 8f632a0

Browse files
committed
Merge branch 'net-tools-ynl-fixes'
Jakub Kicinski says: ==================== tools: ynl: fix subset use and change default value for attrs/ops Fix a problem in subsetting, which will become apparent when the devlink family comes after the merge window. Even tho none of the existing families need this, we don't want someone to get "inspired" by the current, incorrect code when using specs in other languages. Change the default value for the first attr/op. This is a slight behavior change so needs to go in now. The diffstat of the last patch should serve as the clearest justification there.. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents ad93bab + bcec717 commit 8f632a0

File tree

6 files changed

+32
-31
lines changed

6 files changed

+32
-31
lines changed

Documentation/netlink/specs/ethtool.yaml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ attribute-sets:
1111
-
1212
name: dev-index
1313
type: u32
14-
value: 1
1514
-
1615
name: dev-name
1716
type: string
@@ -25,7 +24,6 @@ attribute-sets:
2524
-
2625
name: index
2726
type: u32
28-
value: 1
2927
-
3028
name: name
3129
type: string
@@ -39,14 +37,12 @@ attribute-sets:
3937
name: bit
4038
type: nest
4139
nested-attributes: bitset-bit
42-
value: 1
4340
-
4441
name: bitset
4542
attributes:
4643
-
4744
name: nomask
4845
type: flag
49-
value: 1
5046
-
5147
name: size
5248
type: u32
@@ -61,7 +57,6 @@ attribute-sets:
6157
-
6258
name: index
6359
type: u32
64-
value: 1
6560
-
6661
name: value
6762
type: string
@@ -71,7 +66,6 @@ attribute-sets:
7166
-
7267
name: string
7368
type: nest
74-
value: 1
7569
multi-attr: true
7670
nested-attributes: string
7771
-
@@ -80,7 +74,6 @@ attribute-sets:
8074
-
8175
name: id
8276
type: u32
83-
value: 1
8477
-
8578
name: count
8679
type: u32
@@ -96,14 +89,12 @@ attribute-sets:
9689
name: stringset
9790
type: nest
9891
multi-attr: true
99-
value: 1
10092
nested-attributes: stringset
10193
-
10294
name: strset
10395
attributes:
10496
-
10597
name: header
106-
value: 1
10798
type: nest
10899
nested-attributes: header
109100
-
@@ -119,7 +110,6 @@ attribute-sets:
119110
attributes:
120111
-
121112
name: header
122-
value: 1
123113
type: nest
124114
nested-attributes: header
125115
-
@@ -132,7 +122,6 @@ attribute-sets:
132122
attributes:
133123
-
134124
name: header
135-
value: 1
136125
type: nest
137126
nested-attributes: header
138127
-
@@ -180,7 +169,6 @@ attribute-sets:
180169
attributes:
181170
-
182171
name: pad
183-
value: 1
184172
type: pad
185173
-
186174
name: reassembly-errors
@@ -205,7 +193,6 @@ attribute-sets:
205193
attributes:
206194
-
207195
name: header
208-
value: 1
209196
type: nest
210197
nested-attributes: header
211198
-
@@ -251,13 +238,11 @@ operations:
251238

252239
do: &strset-get-op
253240
request:
254-
value: 1
255241
attributes:
256242
- header
257243
- stringsets
258244
- counts-only
259245
reply:
260-
value: 1
261246
attributes:
262247
- header
263248
- stringsets

Documentation/netlink/specs/fou.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ attribute-sets:
2626
-
2727
name: unspec
2828
type: unused
29+
value: 0
2930
-
3031
name: port
3132
type: u16
@@ -71,6 +72,7 @@ operations:
7172
-
7273
name: unspec
7374
doc: unused
75+
value: 0
7476

7577
-
7678
name: add

Documentation/netlink/specs/netdev.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ attribute-sets:
4848
name: ifindex
4949
doc: netdev ifindex
5050
type: u32
51-
value: 1
5251
checks:
5352
min: 1
5453
-
@@ -66,7 +65,6 @@ operations:
6665
-
6766
name: dev-get
6867
doc: Get / dump information about a netdev.
69-
value: 1
7068
attribute-set: dev
7169
do:
7270
request:

Documentation/userspace-api/netlink/specs.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,15 @@ value
197197
Numerical attribute ID, used in serialized Netlink messages.
198198
The ``value`` property can be skipped, in which case the attribute ID
199199
will be the value of the previous attribute plus one (recursively)
200-
and ``0`` for the first attribute in the attribute set.
200+
and ``1`` 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+
Attributes (and operations) use ``1`` as the default value for the first
203+
entry (unlike enums in definitions which start from ``0``) because
204+
entry ``0`` is almost always reserved as undefined. Spec can explicitly
205+
set value to ``0`` if needed.
206+
207+
Note that the ``value`` of an attribute is defined only in its main set
208+
(not in subsets).
203209

204210
enum
205211
~~~~

tools/net/ynl/lib/nlspec.py

Lines changed: 17 additions & 10 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 = 1
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)
@@ -245,7 +252,7 @@ def add_unresolved(self, elem):
245252
self._resolution_list.append(elem)
246253

247254
def _dictify_ops_unified(self):
248-
val = 0
255+
val = 1
249256
for elem in self.yaml['operations']['list']:
250257
if 'value' in elem:
251258
val = elem['value']
@@ -256,7 +263,7 @@ def _dictify_ops_unified(self):
256263
self.msgs[op.name] = op
257264

258265
def _dictify_ops_directional(self):
259-
req_val = rsp_val = 0
266+
req_val = rsp_val = 1
260267
for elem in self.yaml['operations']['list']:
261268
if 'notify' in elem:
262269
if 'value' in elem:

tools/net/ynl/ynl-gen-c.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2044,14 +2044,17 @@ def render_uapi(family, cw):
20442044
max_value = f"({cnt_name} - 1)"
20452045

20462046
uapi_enum_start(family, cw, family['operations'], 'enum-name')
2047+
val = 0
20472048
for op in family.msgs.values():
20482049
if separate_ntf and ('notify' in op or 'event' in op):
20492050
continue
20502051

20512052
suffix = ','
2052-
if 'value' in op:
2053-
suffix = f" = {op['value']},"
2053+
if op.value != val:
2054+
suffix = f" = {op.value},"
2055+
val = op.value
20542056
cw.p(op.enum_name + suffix)
2057+
val += 1
20552058
cw.nl()
20562059
cw.p(cnt_name + ('' if max_by_define else ','))
20572060
if not max_by_define:

0 commit comments

Comments
 (0)