Skip to content

Commit aa6485d

Browse files
liuhangbinkuba-moo
authored andcommitted
ynl: rename array-nest to indexed-array
Some implementations, like bonding, has nest array with same attr type. To support all kinds of entries under one nest array. As discussed[1], let's rename array-nest to indexed-array, and assuming the value is a nest by passing the type via sub-type. [1] https://lore.kernel.org/netdev/[email protected]/ Suggested-by: Jakub Kicinski <[email protected]> Signed-off-by: Hangbin Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent f410cbe commit aa6485d

File tree

10 files changed

+53
-28
lines changed

10 files changed

+53
-28
lines changed

Documentation/netlink/genetlink-c.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ properties:
158158
type: &attr-type
159159
enum: [ unused, pad, flag, binary,
160160
uint, sint, u8, u16, u32, u64, s32, s64,
161-
string, nest, array-nest, nest-type-value ]
161+
string, nest, indexed-array, nest-type-value ]
162162
doc:
163163
description: Documentation of the attribute.
164164
type: string

Documentation/netlink/genetlink-legacy.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ properties:
201201
description: The netlink attribute type
202202
enum: [ unused, pad, flag, binary, bitfield32,
203203
uint, sint, u8, u16, u32, u64, s32, s64,
204-
string, nest, array-nest, nest-type-value ]
204+
string, nest, indexed-array, nest-type-value ]
205205
doc:
206206
description: Documentation of the attribute.
207207
type: string

Documentation/netlink/genetlink.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ properties:
124124
type: &attr-type
125125
enum: [ unused, pad, flag, binary,
126126
uint, sint, u8, u16, u32, u64, s32, s64,
127-
string, nest, array-nest, nest-type-value ]
127+
string, nest, indexed-array, nest-type-value ]
128128
doc:
129129
description: Documentation of the attribute.
130130
type: string

Documentation/netlink/netlink-raw.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ properties:
222222
description: The netlink attribute type
223223
enum: [ unused, pad, flag, binary, bitfield32,
224224
u8, u16, u32, u64, s8, s16, s32, s64,
225-
string, nest, array-nest, nest-type-value,
225+
string, nest, indexed-array, nest-type-value,
226226
sub-message ]
227227
doc:
228228
description: Documentation of the attribute.

Documentation/netlink/specs/nlctrl.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,13 @@ attribute-sets:
6565
type: u32
6666
-
6767
name: ops
68-
type: array-nest
68+
type: indexed-array
69+
sub-type: nest
6970
nested-attributes: op-attrs
7071
-
7172
name: mcast-groups
72-
type: array-nest
73+
type: indexed-array
74+
sub-type: nest
7375
nested-attributes: mcast-group-attrs
7476
-
7577
name: policy

Documentation/netlink/specs/rt_link.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1690,7 +1690,8 @@ attribute-sets:
16901690
type: binary
16911691
-
16921692
name: hw-s-info
1693-
type: array-nest
1693+
type: indexed-array
1694+
sub-type: nest
16941695
nested-attributes: hw-s-info-one
16951696
-
16961697
name: l3-stats

Documentation/netlink/specs/tc.yaml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,7 +1988,8 @@ attribute-sets:
19881988
nested-attributes: tc-ematch-attrs
19891989
-
19901990
name: act
1991-
type: array-nest
1991+
type: indexed-array
1992+
sub-type: nest
19921993
nested-attributes: tc-act-attrs
19931994
-
19941995
name: police
@@ -2128,7 +2129,8 @@ attribute-sets:
21282129
type: u32
21292130
-
21302131
name: tin-stats
2131-
type: array-nest
2132+
type: indexed-array
2133+
sub-type: nest
21322134
nested-attributes: tc-cake-tin-stats-attrs
21332135
-
21342136
name: deficit
@@ -2348,7 +2350,8 @@ attribute-sets:
23482350
type: string
23492351
-
23502352
name: act
2351-
type: array-nest
2353+
type: indexed-array
2354+
sub-type: nest
23522355
nested-attributes: tc-act-attrs
23532356
-
23542357
name: key-eth-dst
@@ -2849,7 +2852,8 @@ attribute-sets:
28492852
type: string
28502853
-
28512854
name: act
2852-
type: array-nest
2855+
type: indexed-array
2856+
sub-type: nest
28532857
nested-attributes: tc-act-attrs
28542858
-
28552859
name: mask
@@ -3002,7 +3006,8 @@ attribute-sets:
30023006
type: u32
30033007
-
30043008
name: act
3005-
type: array-nest
3009+
type: indexed-array
3010+
sub-type: nest
30063011
nested-attributes: tc-act-attrs
30073012
-
30083013
name: flags
@@ -3375,7 +3380,8 @@ attribute-sets:
33753380
nested-attributes: tc-police-attrs
33763381
-
33773382
name: act
3378-
type: array-nest
3383+
type: indexed-array
3384+
sub-type: nest
33793385
nested-attributes: tc-act-attrs
33803386
-
33813387
name: tc-taprio-attrs
@@ -3593,7 +3599,8 @@ attribute-sets:
35933599
nested-attributes: tc-police-attrs
35943600
-
35953601
name: act
3596-
type: array-nest
3602+
type: indexed-array
3603+
sub-type: nest
35973604
nested-attributes: tc-act-attrs
35983605
-
35993606
name: indev

Documentation/userspace-api/netlink/genetlink-legacy.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,16 @@ For reference the ``multi-attr`` array may look like this::
4646

4747
where ``ARRAY-ATTR`` is the array entry type.
4848

49-
array-nest
50-
~~~~~~~~~~
49+
indexed-array
50+
~~~~~~~~~~~~~
51+
52+
``indexed-array`` wraps the entire array in an extra attribute (hence
53+
limiting its size to 64kB). The ``ENTRY`` nests are special and have the
54+
index of the entry as their type instead of normal attribute type.
5155

52-
``array-nest`` creates the following structure::
56+
A ``sub-type`` is needed to describe what type in the ``ENTRY``. A ``nest``
57+
``sub-type`` means there are nest arrays in the ``ENTRY``, with the structure
58+
looks like::
5359

5460
[SOME-OTHER-ATTR]
5561
[ARRAY-ATTR]

tools/net/ynl/lib/ynl.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -631,15 +631,18 @@ def _decode_binary(self, attr, attr_spec):
631631
decoded = self._formatted_string(decoded, attr_spec.display_hint)
632632
return decoded
633633

634-
def _decode_array_nest(self, attr, attr_spec):
634+
def _decode_array_attr(self, attr, attr_spec):
635635
decoded = []
636636
offset = 0
637637
while offset < len(attr.raw):
638638
item = NlAttr(attr.raw, offset)
639639
offset += item.full_len
640640

641-
subattrs = self._decode(NlAttrs(item.raw), attr_spec['nested-attributes'])
642-
decoded.append({ item.type: subattrs })
641+
if attr_spec["sub-type"] == 'nest':
642+
subattrs = self._decode(NlAttrs(item.raw), attr_spec['nested-attributes'])
643+
decoded.append({ item.type: subattrs })
644+
else:
645+
raise Exception(f'Unknown {attr_spec["sub-type"]} with name {attr_spec["name"]}')
643646
return decoded
644647

645648
def _decode_nest_type_value(self, attr, attr_spec):
@@ -733,8 +736,8 @@ def _decode(self, attrs, space, outer_attrs = None):
733736
decoded = attr.as_scalar(attr_spec['type'], attr_spec.byte_order)
734737
if 'enum' in attr_spec:
735738
decoded = self._decode_enum(decoded, attr_spec)
736-
elif attr_spec["type"] == 'array-nest':
737-
decoded = self._decode_array_nest(attr, attr_spec)
739+
elif attr_spec["type"] == 'indexed-array':
740+
decoded = self._decode_array_attr(attr, attr_spec)
738741
elif attr_spec["type"] == 'bitfield32':
739742
value, selector = struct.unpack("II", attr.raw)
740743
if 'enum' in attr_spec:

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -841,8 +841,11 @@ def new_attr(self, elem, value):
841841
t = TypeBitfield32(self.family, self, elem, value)
842842
elif elem['type'] == 'nest':
843843
t = TypeNest(self.family, self, elem, value)
844-
elif elem['type'] == 'array-nest':
845-
t = TypeArrayNest(self.family, self, elem, value)
844+
elif elem['type'] == 'indexed-array' and 'sub-type' in elem:
845+
if elem["sub-type"] == 'nest':
846+
t = TypeArrayNest(self.family, self, elem, value)
847+
else:
848+
raise Exception(f'new_attr: unsupported sub-type {elem["sub-type"]}')
846849
elif elem['type'] == 'nest-type-value':
847850
t = TypeNestTypeValue(self.family, self, elem, value)
848851
else:
@@ -1055,7 +1058,7 @@ def _load_nested_sets(self):
10551058
if nested in self.root_sets:
10561059
raise Exception("Inheriting members to a space used as root not supported")
10571060
inherit.update(set(spec['type-value']))
1058-
elif spec['type'] == 'array-nest':
1061+
elif spec['type'] == 'indexed-array':
10591062
inherit.add('idx')
10601063
self.pure_nested_structs[nested].set_inherited(inherit)
10611064

@@ -1619,9 +1622,12 @@ def _multi_parse(ri, struct, init_lines, local_vars):
16191622
multi_attrs = set()
16201623
needs_parg = False
16211624
for arg, aspec in struct.member_list():
1622-
if aspec['type'] == 'array-nest':
1623-
local_vars.append(f'const struct nlattr *attr_{aspec.c_name};')
1624-
array_nests.add(arg)
1625+
if aspec['type'] == 'indexed-array' and 'sub-type' in aspec:
1626+
if aspec["sub-type"] == 'nest':
1627+
local_vars.append(f'const struct nlattr *attr_{aspec.c_name};')
1628+
array_nests.add(arg)
1629+
else:
1630+
raise Exception(f'Not supported sub-type {aspec["sub-type"]}')
16251631
if 'multi-attr' in aspec:
16261632
multi_attrs.add(arg)
16271633
needs_parg |= 'nested-attributes' in aspec

0 commit comments

Comments
 (0)