Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'ynl-rename-array-nest-to-indexed-array'

Hangbin Liu says:

====================
ynl: rename array-nest to indexed-array

rename array-nest to indexed-array and add un-nest sub-type support
====================

Link: https://lore.kernel.org/r/20240404063114.1221532-1-liuhangbin@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+70 -31
+1 -1
Documentation/netlink/genetlink.yaml
··· 124 124 type: &attr-type 125 125 enum: [ unused, pad, flag, binary, 126 126 uint, sint, u8, u16, u32, u64, s32, s64, 127 - string, nest, array-nest, nest-type-value ] 127 + string, nest, indexed-array, nest-type-value ] 128 128 doc: 129 129 description: Documentation of the attribute. 130 130 type: string
+4 -2
Documentation/netlink/specs/nlctrl.yaml
··· 65 65 type: u32 66 66 - 67 67 name: ops 68 - type: array-nest 68 + type: indexed-array 69 + sub-type: nest 69 70 nested-attributes: op-attrs 70 71 - 71 72 name: mcast-groups 72 - type: array-nest 73 + type: indexed-array 74 + sub-type: nest 73 75 nested-attributes: mcast-group-attrs 74 76 - 75 77 name: policy
+2 -1
Documentation/netlink/specs/rt_link.yaml
··· 1690 1690 type: binary 1691 1691 - 1692 1692 name: hw-s-info 1693 - type: array-nest 1693 + type: indexed-array 1694 + sub-type: nest 1694 1695 nested-attributes: hw-s-info-one 1695 1696 - 1696 1697 name: l3-stats
+14 -7
Documentation/netlink/specs/tc.yaml
··· 1988 1988 nested-attributes: tc-ematch-attrs 1989 1989 - 1990 1990 name: act 1991 - type: array-nest 1991 + type: indexed-array 1992 + sub-type: nest 1992 1993 nested-attributes: tc-act-attrs 1993 1994 - 1994 1995 name: police ··· 2129 2128 type: u32 2130 2129 - 2131 2130 name: tin-stats 2132 - type: array-nest 2131 + type: indexed-array 2132 + sub-type: nest 2133 2133 nested-attributes: tc-cake-tin-stats-attrs 2134 2134 - 2135 2135 name: deficit ··· 2350 2348 type: string 2351 2349 - 2352 2350 name: act 2353 - type: array-nest 2351 + type: indexed-array 2352 + sub-type: nest 2354 2353 nested-attributes: tc-act-attrs 2355 2354 - 2356 2355 name: key-eth-dst ··· 2852 2849 type: string 2853 2850 - 2854 2851 name: act 2855 - type: array-nest 2852 + type: indexed-array 2853 + sub-type: nest 2856 2854 nested-attributes: tc-act-attrs 2857 2855 - 2858 2856 name: mask ··· 3006 3002 type: u32 3007 3003 - 3008 3004 name: act 3009 - type: array-nest 3005 + type: indexed-array 3006 + sub-type: nest 3010 3007 nested-attributes: tc-act-attrs 3011 3008 - 3012 3009 name: flags ··· 3380 3375 nested-attributes: tc-police-attrs 3381 3376 - 3382 3377 name: act 3383 - type: array-nest 3378 + type: indexed-array 3379 + sub-type: nest 3384 3380 nested-attributes: tc-act-attrs 3385 3381 - 3386 3382 name: tc-taprio-attrs ··· 3599 3593 nested-attributes: tc-police-attrs 3600 3594 - 3601 3595 name: act 3602 - type: array-nest 3596 + type: indexed-array 3597 + sub-type: nest 3603 3598 nested-attributes: tc-act-attrs 3604 3599 - 3605 3600 name: indev
+18 -5
tools/net/ynl/lib/ynl.py
··· 631 631 decoded = self._formatted_string(decoded, attr_spec.display_hint) 632 632 return decoded 633 633 634 - def _decode_array_nest(self, attr, attr_spec): 634 + def _decode_array_attr(self, attr, attr_spec): 635 635 decoded = [] 636 636 offset = 0 637 637 while offset < len(attr.raw): 638 638 item = NlAttr(attr.raw, offset) 639 639 offset += item.full_len 640 640 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 + elif attr_spec["sub-type"] == 'binary': 645 + subattrs = item.as_bin() 646 + if attr_spec.display_hint: 647 + subattrs = self._formatted_string(subattrs, attr_spec.display_hint) 648 + decoded.append(subattrs) 649 + elif attr_spec["sub-type"] in NlAttr.type_formats: 650 + subattrs = item.as_scalar(attr_spec['sub-type'], attr_spec.byte_order) 651 + if attr_spec.display_hint: 652 + subattrs = self._formatted_string(subattrs, attr_spec.display_hint) 653 + decoded.append(subattrs) 654 + else: 655 + raise Exception(f'Unknown {attr_spec["sub-type"]} with name {attr_spec["name"]}') 643 656 return decoded 644 657 645 658 def _decode_nest_type_value(self, attr, attr_spec): ··· 746 733 decoded = attr.as_scalar(attr_spec['type'], attr_spec.byte_order) 747 734 if 'enum' in attr_spec: 748 735 decoded = self._decode_enum(decoded, attr_spec) 749 - elif attr_spec["type"] == 'array-nest': 750 - decoded = self._decode_array_nest(attr, attr_spec) 736 + elif attr_spec["type"] == 'indexed-array': 737 + decoded = self._decode_array_attr(attr, attr_spec) 751 738 elif attr_spec["type"] == 'bitfield32': 752 739 value, selector = struct.unpack("II", attr.raw) 753 740 if 'enum' in attr_spec:
+12 -6
tools/net/ynl/ynl-gen-c.py
··· 841 841 t = TypeBitfield32(self.family, self, elem, value) 842 842 elif elem['type'] == 'nest': 843 843 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"]}') 846 849 elif elem['type'] == 'nest-type-value': 847 850 t = TypeNestTypeValue(self.family, self, elem, value) 848 851 else: ··· 1058 1055 if nested in self.root_sets: 1059 1056 raise Exception("Inheriting members to a space used as root not supported") 1060 1057 inherit.update(set(spec['type-value'])) 1061 - elif spec['type'] == 'array-nest': 1058 + elif spec['type'] == 'indexed-array': 1062 1059 inherit.add('idx') 1063 1060 self.pure_nested_structs[nested].set_inherited(inherit) 1064 1061 ··· 1622 1619 multi_attrs = set() 1623 1620 needs_parg = False 1624 1621 for arg, aspec in struct.member_list(): 1625 - if aspec['type'] == 'array-nest': 1626 - local_vars.append(f'const struct nlattr *attr_{aspec.c_name};') 1627 - array_nests.add(arg) 1622 + if aspec['type'] == 'indexed-array' and 'sub-type' in aspec: 1623 + if aspec["sub-type"] == 'nest': 1624 + local_vars.append(f'const struct nlattr *attr_{aspec.c_name};') 1625 + array_nests.add(arg) 1626 + else: 1627 + raise Exception(f'Not supported sub-type {aspec["sub-type"]}') 1628 1628 if 'multi-attr' in aspec: 1629 1629 multi_attrs.add(arg) 1630 1630 needs_parg |= 'nested-attributes' in aspec