Commit aa6485d8 authored by Hangbin Liu's avatar Hangbin Liu Committed by Jakub Kicinski

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/20240312100105.16a59086@kernel.org/Suggested-by: default avatarJakub Kicinski <kuba@kernel.org>
Signed-off-by: default avatarHangbin Liu <liuhangbin@gmail.com>
Link: https://lore.kernel.org/r/20240404063114.1221532-2-liuhangbin@gmail.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent f410cbea
...@@ -158,7 +158,7 @@ properties: ...@@ -158,7 +158,7 @@ properties:
type: &attr-type type: &attr-type
enum: [ unused, pad, flag, binary, enum: [ unused, pad, flag, binary,
uint, sint, u8, u16, u32, u64, s32, s64, uint, sint, u8, u16, u32, u64, s32, s64,
string, nest, array-nest, nest-type-value ] string, nest, indexed-array, nest-type-value ]
doc: doc:
description: Documentation of the attribute. description: Documentation of the attribute.
type: string type: string
......
...@@ -201,7 +201,7 @@ properties: ...@@ -201,7 +201,7 @@ properties:
description: The netlink attribute type description: The netlink attribute type
enum: [ unused, pad, flag, binary, bitfield32, enum: [ unused, pad, flag, binary, bitfield32,
uint, sint, u8, u16, u32, u64, s32, s64, uint, sint, u8, u16, u32, u64, s32, s64,
string, nest, array-nest, nest-type-value ] string, nest, indexed-array, nest-type-value ]
doc: doc:
description: Documentation of the attribute. description: Documentation of the attribute.
type: string type: string
......
...@@ -124,7 +124,7 @@ properties: ...@@ -124,7 +124,7 @@ properties:
type: &attr-type type: &attr-type
enum: [ unused, pad, flag, binary, enum: [ unused, pad, flag, binary,
uint, sint, u8, u16, u32, u64, s32, s64, uint, sint, u8, u16, u32, u64, s32, s64,
string, nest, array-nest, nest-type-value ] string, nest, indexed-array, nest-type-value ]
doc: doc:
description: Documentation of the attribute. description: Documentation of the attribute.
type: string type: string
......
...@@ -222,7 +222,7 @@ properties: ...@@ -222,7 +222,7 @@ properties:
description: The netlink attribute type description: The netlink attribute type
enum: [ unused, pad, flag, binary, bitfield32, enum: [ unused, pad, flag, binary, bitfield32,
u8, u16, u32, u64, s8, s16, s32, s64, u8, u16, u32, u64, s8, s16, s32, s64,
string, nest, array-nest, nest-type-value, string, nest, indexed-array, nest-type-value,
sub-message ] sub-message ]
doc: doc:
description: Documentation of the attribute. description: Documentation of the attribute.
......
...@@ -65,11 +65,13 @@ attribute-sets: ...@@ -65,11 +65,13 @@ attribute-sets:
type: u32 type: u32
- -
name: ops name: ops
type: array-nest type: indexed-array
sub-type: nest
nested-attributes: op-attrs nested-attributes: op-attrs
- -
name: mcast-groups name: mcast-groups
type: array-nest type: indexed-array
sub-type: nest
nested-attributes: mcast-group-attrs nested-attributes: mcast-group-attrs
- -
name: policy name: policy
......
...@@ -1690,7 +1690,8 @@ attribute-sets: ...@@ -1690,7 +1690,8 @@ attribute-sets:
type: binary type: binary
- -
name: hw-s-info name: hw-s-info
type: array-nest type: indexed-array
sub-type: nest
nested-attributes: hw-s-info-one nested-attributes: hw-s-info-one
- -
name: l3-stats name: l3-stats
......
...@@ -1988,7 +1988,8 @@ attribute-sets: ...@@ -1988,7 +1988,8 @@ attribute-sets:
nested-attributes: tc-ematch-attrs nested-attributes: tc-ematch-attrs
- -
name: act name: act
type: array-nest type: indexed-array
sub-type: nest
nested-attributes: tc-act-attrs nested-attributes: tc-act-attrs
- -
name: police name: police
...@@ -2128,7 +2129,8 @@ attribute-sets: ...@@ -2128,7 +2129,8 @@ attribute-sets:
type: u32 type: u32
- -
name: tin-stats name: tin-stats
type: array-nest type: indexed-array
sub-type: nest
nested-attributes: tc-cake-tin-stats-attrs nested-attributes: tc-cake-tin-stats-attrs
- -
name: deficit name: deficit
...@@ -2348,7 +2350,8 @@ attribute-sets: ...@@ -2348,7 +2350,8 @@ attribute-sets:
type: string type: string
- -
name: act name: act
type: array-nest type: indexed-array
sub-type: nest
nested-attributes: tc-act-attrs nested-attributes: tc-act-attrs
- -
name: key-eth-dst name: key-eth-dst
...@@ -2849,7 +2852,8 @@ attribute-sets: ...@@ -2849,7 +2852,8 @@ attribute-sets:
type: string type: string
- -
name: act name: act
type: array-nest type: indexed-array
sub-type: nest
nested-attributes: tc-act-attrs nested-attributes: tc-act-attrs
- -
name: mask name: mask
...@@ -3002,7 +3006,8 @@ attribute-sets: ...@@ -3002,7 +3006,8 @@ attribute-sets:
type: u32 type: u32
- -
name: act name: act
type: array-nest type: indexed-array
sub-type: nest
nested-attributes: tc-act-attrs nested-attributes: tc-act-attrs
- -
name: flags name: flags
...@@ -3375,7 +3380,8 @@ attribute-sets: ...@@ -3375,7 +3380,8 @@ attribute-sets:
nested-attributes: tc-police-attrs nested-attributes: tc-police-attrs
- -
name: act name: act
type: array-nest type: indexed-array
sub-type: nest
nested-attributes: tc-act-attrs nested-attributes: tc-act-attrs
- -
name: tc-taprio-attrs name: tc-taprio-attrs
...@@ -3593,7 +3599,8 @@ attribute-sets: ...@@ -3593,7 +3599,8 @@ attribute-sets:
nested-attributes: tc-police-attrs nested-attributes: tc-police-attrs
- -
name: act name: act
type: array-nest type: indexed-array
sub-type: nest
nested-attributes: tc-act-attrs nested-attributes: tc-act-attrs
- -
name: indev name: indev
......
...@@ -46,10 +46,16 @@ For reference the ``multi-attr`` array may look like this:: ...@@ -46,10 +46,16 @@ For reference the ``multi-attr`` array may look like this::
where ``ARRAY-ATTR`` is the array entry type. where ``ARRAY-ATTR`` is the array entry type.
array-nest indexed-array
~~~~~~~~~~ ~~~~~~~~~~~~~
``indexed-array`` wraps the entire array in an extra attribute (hence
limiting its size to 64kB). The ``ENTRY`` nests are special and have the
index of the entry as their type instead of normal attribute type.
``array-nest`` creates the following structure:: A ``sub-type`` is needed to describe what type in the ``ENTRY``. A ``nest``
``sub-type`` means there are nest arrays in the ``ENTRY``, with the structure
looks like::
[SOME-OTHER-ATTR] [SOME-OTHER-ATTR]
[ARRAY-ATTR] [ARRAY-ATTR]
......
...@@ -631,15 +631,18 @@ class YnlFamily(SpecFamily): ...@@ -631,15 +631,18 @@ class YnlFamily(SpecFamily):
decoded = self._formatted_string(decoded, attr_spec.display_hint) decoded = self._formatted_string(decoded, attr_spec.display_hint)
return decoded return decoded
def _decode_array_nest(self, attr, attr_spec): def _decode_array_attr(self, attr, attr_spec):
decoded = [] decoded = []
offset = 0 offset = 0
while offset < len(attr.raw): while offset < len(attr.raw):
item = NlAttr(attr.raw, offset) item = NlAttr(attr.raw, offset)
offset += item.full_len offset += item.full_len
if attr_spec["sub-type"] == 'nest':
subattrs = self._decode(NlAttrs(item.raw), attr_spec['nested-attributes']) subattrs = self._decode(NlAttrs(item.raw), attr_spec['nested-attributes'])
decoded.append({ item.type: subattrs }) decoded.append({ item.type: subattrs })
else:
raise Exception(f'Unknown {attr_spec["sub-type"]} with name {attr_spec["name"]}')
return decoded return decoded
def _decode_nest_type_value(self, attr, attr_spec): def _decode_nest_type_value(self, attr, attr_spec):
...@@ -733,8 +736,8 @@ class YnlFamily(SpecFamily): ...@@ -733,8 +736,8 @@ class YnlFamily(SpecFamily):
decoded = attr.as_scalar(attr_spec['type'], attr_spec.byte_order) decoded = attr.as_scalar(attr_spec['type'], attr_spec.byte_order)
if 'enum' in attr_spec: if 'enum' in attr_spec:
decoded = self._decode_enum(decoded, attr_spec) decoded = self._decode_enum(decoded, attr_spec)
elif attr_spec["type"] == 'array-nest': elif attr_spec["type"] == 'indexed-array':
decoded = self._decode_array_nest(attr, attr_spec) decoded = self._decode_array_attr(attr, attr_spec)
elif attr_spec["type"] == 'bitfield32': elif attr_spec["type"] == 'bitfield32':
value, selector = struct.unpack("II", attr.raw) value, selector = struct.unpack("II", attr.raw)
if 'enum' in attr_spec: if 'enum' in attr_spec:
......
...@@ -841,8 +841,11 @@ class AttrSet(SpecAttrSet): ...@@ -841,8 +841,11 @@ class AttrSet(SpecAttrSet):
t = TypeBitfield32(self.family, self, elem, value) t = TypeBitfield32(self.family, self, elem, value)
elif elem['type'] == 'nest': elif elem['type'] == 'nest':
t = TypeNest(self.family, self, elem, value) t = TypeNest(self.family, self, elem, value)
elif elem['type'] == 'array-nest': elif elem['type'] == 'indexed-array' and 'sub-type' in elem:
if elem["sub-type"] == 'nest':
t = TypeArrayNest(self.family, self, elem, value) t = TypeArrayNest(self.family, self, elem, value)
else:
raise Exception(f'new_attr: unsupported sub-type {elem["sub-type"]}')
elif elem['type'] == 'nest-type-value': elif elem['type'] == 'nest-type-value':
t = TypeNestTypeValue(self.family, self, elem, value) t = TypeNestTypeValue(self.family, self, elem, value)
else: else:
...@@ -1055,7 +1058,7 @@ class Family(SpecFamily): ...@@ -1055,7 +1058,7 @@ class Family(SpecFamily):
if nested in self.root_sets: if nested in self.root_sets:
raise Exception("Inheriting members to a space used as root not supported") raise Exception("Inheriting members to a space used as root not supported")
inherit.update(set(spec['type-value'])) inherit.update(set(spec['type-value']))
elif spec['type'] == 'array-nest': elif spec['type'] == 'indexed-array':
inherit.add('idx') inherit.add('idx')
self.pure_nested_structs[nested].set_inherited(inherit) self.pure_nested_structs[nested].set_inherited(inherit)
...@@ -1619,9 +1622,12 @@ def _multi_parse(ri, struct, init_lines, local_vars): ...@@ -1619,9 +1622,12 @@ def _multi_parse(ri, struct, init_lines, local_vars):
multi_attrs = set() multi_attrs = set()
needs_parg = False needs_parg = False
for arg, aspec in struct.member_list(): for arg, aspec in struct.member_list():
if aspec['type'] == 'array-nest': if aspec['type'] == 'indexed-array' and 'sub-type' in aspec:
if aspec["sub-type"] == 'nest':
local_vars.append(f'const struct nlattr *attr_{aspec.c_name};') local_vars.append(f'const struct nlattr *attr_{aspec.c_name};')
array_nests.add(arg) array_nests.add(arg)
else:
raise Exception(f'Not supported sub-type {aspec["sub-type"]}')
if 'multi-attr' in aspec: if 'multi-attr' in aspec:
multi_attrs.add(arg) multi_attrs.add(arg)
needs_parg |= 'nested-attributes' in aspec needs_parg |= 'nested-attributes' in aspec
......
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