* [PATCHv3 net-next 0/2] ynl: rename array-nest to indexed-array
@ 2024-04-01 3:56 Hangbin Liu
2024-04-01 3:56 ` [PATCHv3 net-next 1/2] " Hangbin Liu
2024-04-01 3:56 ` [PATCHv3 net-next 2/2] ynl: support binary/u32 sub-type for indexed-array Hangbin Liu
0 siblings, 2 replies; 9+ messages in thread
From: Hangbin Liu @ 2024-04-01 3:56 UTC (permalink / raw)
To: netdev
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Donald Hunter, Jiri Pirko, Jacob Keller, Stanislav Fomichev,
Hangbin Liu
rename array-nest to indexed-array and add un-nest sub-type support
v3:
1. fix doc title underline too short issue (Jakub Kicinski)
v2:
1. raise exception for unsupported sub-type
2. merge all sub-type handler in _decode_array_attr
3. remove index shown in indexed-array as some implementations are
non-contiguous.
Hangbin Liu (2):
ynl: rename array-nest to indexed-array
ynl: support binary/u32 sub-type for indexed-array
Documentation/netlink/genetlink-c.yaml | 2 +-
Documentation/netlink/genetlink-legacy.yaml | 2 +-
Documentation/netlink/genetlink.yaml | 2 +-
Documentation/netlink/netlink-raw.yaml | 2 +-
Documentation/netlink/specs/nlctrl.yaml | 6 +++--
Documentation/netlink/specs/rt_link.yaml | 3 ++-
Documentation/netlink/specs/tc.yaml | 21 ++++++++++------
.../netlink/genetlink-legacy.rst | 24 ++++++++++++++-----
tools/net/ynl/lib/ynl.py | 18 ++++++++++----
tools/net/ynl/ynl-gen-c.py | 18 +++++++++-----
10 files changed, 67 insertions(+), 31 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCHv3 net-next 1/2] ynl: rename array-nest to indexed-array
2024-04-01 3:56 [PATCHv3 net-next 0/2] ynl: rename array-nest to indexed-array Hangbin Liu
@ 2024-04-01 3:56 ` Hangbin Liu
2024-04-01 3:56 ` [PATCHv3 net-next 2/2] ynl: support binary/u32 sub-type for indexed-array Hangbin Liu
1 sibling, 0 replies; 9+ messages in thread
From: Hangbin Liu @ 2024-04-01 3:56 UTC (permalink / raw)
To: netdev
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Donald Hunter, Jiri Pirko, Jacob Keller, Stanislav Fomichev,
Hangbin Liu
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: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
Documentation/netlink/genetlink-c.yaml | 2 +-
Documentation/netlink/genetlink-legacy.yaml | 2 +-
Documentation/netlink/genetlink.yaml | 2 +-
Documentation/netlink/netlink-raw.yaml | 2 +-
Documentation/netlink/specs/nlctrl.yaml | 6 ++++--
Documentation/netlink/specs/rt_link.yaml | 3 ++-
Documentation/netlink/specs/tc.yaml | 21 ++++++++++++-------
.../netlink/genetlink-legacy.rst | 12 ++++++++---
tools/net/ynl/lib/ynl.py | 13 +++++++-----
tools/net/ynl/ynl-gen-c.py | 18 ++++++++++------
10 files changed, 53 insertions(+), 28 deletions(-)
diff --git a/Documentation/netlink/genetlink-c.yaml b/Documentation/netlink/genetlink-c.yaml
index 4dfd899a1661..4f803eaac6d8 100644
--- a/Documentation/netlink/genetlink-c.yaml
+++ b/Documentation/netlink/genetlink-c.yaml
@@ -158,7 +158,7 @@ properties:
type: &attr-type
enum: [ unused, pad, flag, binary,
uint, sint, u8, u16, u32, u64, s32, s64,
- string, nest, array-nest, nest-type-value ]
+ string, nest, indexed-array, nest-type-value ]
doc:
description: Documentation of the attribute.
type: string
diff --git a/Documentation/netlink/genetlink-legacy.yaml b/Documentation/netlink/genetlink-legacy.yaml
index b48ad3b1cc32..8db0e22fa72c 100644
--- a/Documentation/netlink/genetlink-legacy.yaml
+++ b/Documentation/netlink/genetlink-legacy.yaml
@@ -201,7 +201,7 @@ properties:
description: The netlink attribute type
enum: [ unused, pad, flag, binary, bitfield32,
uint, sint, u8, u16, u32, u64, s32, s64,
- string, nest, array-nest, nest-type-value ]
+ string, nest, indexed-array, nest-type-value ]
doc:
description: Documentation of the attribute.
type: string
diff --git a/Documentation/netlink/genetlink.yaml b/Documentation/netlink/genetlink.yaml
index ebd6ee743fcc..b036227b46f1 100644
--- a/Documentation/netlink/genetlink.yaml
+++ b/Documentation/netlink/genetlink.yaml
@@ -124,7 +124,7 @@ properties:
type: &attr-type
enum: [ unused, pad, flag, binary,
uint, sint, u8, u16, u32, u64, s32, s64,
- string, nest, array-nest, nest-type-value ]
+ string, nest, indexed-array, nest-type-value ]
doc:
description: Documentation of the attribute.
type: string
diff --git a/Documentation/netlink/netlink-raw.yaml b/Documentation/netlink/netlink-raw.yaml
index a76e54cbadbc..914aa1c0a273 100644
--- a/Documentation/netlink/netlink-raw.yaml
+++ b/Documentation/netlink/netlink-raw.yaml
@@ -222,7 +222,7 @@ properties:
description: The netlink attribute type
enum: [ unused, pad, flag, binary, bitfield32,
u8, u16, u32, u64, s8, s16, s32, s64,
- string, nest, array-nest, nest-type-value,
+ string, nest, indexed-array, nest-type-value,
sub-message ]
doc:
description: Documentation of the attribute.
diff --git a/Documentation/netlink/specs/nlctrl.yaml b/Documentation/netlink/specs/nlctrl.yaml
index b1632b95f725..a36535350bdb 100644
--- a/Documentation/netlink/specs/nlctrl.yaml
+++ b/Documentation/netlink/specs/nlctrl.yaml
@@ -65,11 +65,13 @@ attribute-sets:
type: u32
-
name: ops
- type: array-nest
+ type: indexed-array
+ sub-type: nest
nested-attributes: op-attrs
-
name: mcast-groups
- type: array-nest
+ type: indexed-array
+ sub-type: nest
nested-attributes: mcast-group-attrs
-
name: policy
diff --git a/Documentation/netlink/specs/rt_link.yaml b/Documentation/netlink/specs/rt_link.yaml
index 81a5a3d1b04d..e5dcb2cf1724 100644
--- a/Documentation/netlink/specs/rt_link.yaml
+++ b/Documentation/netlink/specs/rt_link.yaml
@@ -1690,7 +1690,8 @@ attribute-sets:
type: binary
-
name: hw-s-info
- type: array-nest
+ type: indexed-array
+ sub-type: nest
nested-attributes: hw-s-info-one
-
name: l3-stats
diff --git a/Documentation/netlink/specs/tc.yaml b/Documentation/netlink/specs/tc.yaml
index 324fa182cd14..dbcf19e494ec 100644
--- a/Documentation/netlink/specs/tc.yaml
+++ b/Documentation/netlink/specs/tc.yaml
@@ -1937,7 +1937,8 @@ attribute-sets:
nested-attributes: tc-ematch-attrs
-
name: act
- type: array-nest
+ type: indexed-array
+ sub-type: nest
nested-attributes: tc-act-attrs
-
name: police
@@ -2077,7 +2078,8 @@ attribute-sets:
type: u32
-
name: tin-stats
- type: array-nest
+ type: indexed-array
+ sub-type: nest
nested-attributes: tc-cake-tin-stats-attrs
-
name: deficit
@@ -2297,7 +2299,8 @@ attribute-sets:
type: string
-
name: act
- type: array-nest
+ type: indexed-array
+ sub-type: nest
nested-attributes: tc-act-attrs
-
name: key-eth-dst
@@ -2798,7 +2801,8 @@ attribute-sets:
type: string
-
name: act
- type: array-nest
+ type: indexed-array
+ sub-type: nest
nested-attributes: tc-act-attrs
-
name: mask
@@ -2951,7 +2955,8 @@ attribute-sets:
type: u32
-
name: act
- type: array-nest
+ type: indexed-array
+ sub-type: nest
nested-attributes: tc-act-attrs
-
name: flags
@@ -3324,7 +3329,8 @@ attribute-sets:
nested-attributes: tc-police-attrs
-
name: act
- type: array-nest
+ type: indexed-array
+ sub-type: nest
nested-attributes: tc-act-attrs
-
name: tc-taprio-attrs
@@ -3542,7 +3548,8 @@ attribute-sets:
nested-attributes: tc-police-attrs
-
name: act
- type: array-nest
+ type: indexed-array
+ sub-type: nest
nested-attributes: tc-act-attrs
-
name: indev
diff --git a/Documentation/userspace-api/netlink/genetlink-legacy.rst b/Documentation/userspace-api/netlink/genetlink-legacy.rst
index 70a77387f6c4..54e8fb25e093 100644
--- a/Documentation/userspace-api/netlink/genetlink-legacy.rst
+++ b/Documentation/userspace-api/netlink/genetlink-legacy.rst
@@ -46,10 +46,16 @@ For reference the ``multi-attr`` array may look like this::
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]
[ARRAY-ATTR]
diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py
index 82d3c98067aa..e5ad415905c7 100644
--- a/tools/net/ynl/lib/ynl.py
+++ b/tools/net/ynl/lib/ynl.py
@@ -630,15 +630,18 @@ class YnlFamily(SpecFamily):
decoded = self._formatted_string(decoded, attr_spec.display_hint)
return decoded
- def _decode_array_nest(self, attr, attr_spec):
+ def _decode_array_attr(self, attr, attr_spec):
decoded = []
offset = 0
while offset < len(attr.raw):
item = NlAttr(attr.raw, offset)
offset += item.full_len
- subattrs = self._decode(NlAttrs(item.raw), attr_spec['nested-attributes'])
- decoded.append({ item.type: subattrs })
+ if attr_spec["sub-type"] == 'nest':
+ subattrs = self._decode(NlAttrs(item.raw), attr_spec['nested-attributes'])
+ decoded.append({ item.type: subattrs })
+ else:
+ raise Exception(f'Unknown {attr_spec["sub-type"]} with name {attr_spec["name"]}')
return decoded
def _decode_nest_type_value(self, attr, attr_spec):
@@ -732,8 +735,8 @@ class YnlFamily(SpecFamily):
decoded = attr.as_scalar(attr_spec['type'], attr_spec.byte_order)
if 'enum' in attr_spec:
decoded = self._decode_enum(decoded, attr_spec)
- elif attr_spec["type"] == 'array-nest':
- decoded = self._decode_array_nest(attr, attr_spec)
+ elif attr_spec["type"] == 'indexed-array':
+ decoded = self._decode_array_attr(attr, attr_spec)
elif attr_spec["type"] == 'bitfield32':
value, selector = struct.unpack("II", attr.raw)
if 'enum' in attr_spec:
diff --git a/tools/net/ynl/ynl-gen-c.py b/tools/net/ynl/ynl-gen-c.py
index a451cbfbd781..c0b90c104d92 100755
--- a/tools/net/ynl/ynl-gen-c.py
+++ b/tools/net/ynl/ynl-gen-c.py
@@ -841,8 +841,11 @@ class AttrSet(SpecAttrSet):
t = TypeBitfield32(self.family, self, elem, value)
elif elem['type'] == 'nest':
t = TypeNest(self.family, self, elem, value)
- elif elem['type'] == 'array-nest':
- t = TypeArrayNest(self.family, self, elem, value)
+ elif elem['type'] == 'indexed-array' and 'sub-type' in elem:
+ if elem["sub-type"] == 'nest':
+ 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':
t = TypeNestTypeValue(self.family, self, elem, value)
else:
@@ -1055,7 +1058,7 @@ class Family(SpecFamily):
if nested in self.root_sets:
raise Exception("Inheriting members to a space used as root not supported")
inherit.update(set(spec['type-value']))
- elif spec['type'] == 'array-nest':
+ elif spec['type'] == 'indexed-array':
inherit.add('idx')
self.pure_nested_structs[nested].set_inherited(inherit)
@@ -1619,9 +1622,12 @@ def _multi_parse(ri, struct, init_lines, local_vars):
multi_attrs = set()
needs_parg = False
for arg, aspec in struct.member_list():
- if aspec['type'] == 'array-nest':
- local_vars.append(f'const struct nlattr *attr_{aspec.c_name};')
- array_nests.add(arg)
+ 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};')
+ array_nests.add(arg)
+ else:
+ raise Exception(f'Not supported sub-type {aspec["sub-type"]}')
if 'multi-attr' in aspec:
multi_attrs.add(arg)
needs_parg |= 'nested-attributes' in aspec
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCHv3 net-next 2/2] ynl: support binary/u32 sub-type for indexed-array
2024-04-01 3:56 [PATCHv3 net-next 0/2] ynl: rename array-nest to indexed-array Hangbin Liu
2024-04-01 3:56 ` [PATCHv3 net-next 1/2] " Hangbin Liu
@ 2024-04-01 3:56 ` Hangbin Liu
2024-04-02 4:43 ` Jakub Kicinski
1 sibling, 1 reply; 9+ messages in thread
From: Hangbin Liu @ 2024-04-01 3:56 UTC (permalink / raw)
To: netdev
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Donald Hunter, Jiri Pirko, Jacob Keller, Stanislav Fomichev,
Hangbin Liu
Add binary/u32 sub-type support for indexed-array to display bond
arp and ns targets. Here is what the result looks like:
# ip link add bond0 type bond mode 1 \
arp_ip_target 192.168.1.1,192.168.1.2 ns_ip6_target 2001::1,2001::2
# ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/rt_link.yaml \
--do getlink --json '{"ifname": "bond0"}' --output-json | jq '.linkinfo'
"arp-ip-target": [
"192.168.1.1",
"192.168.1.2"
],
[...]
"ns-ip6-target": [
"2001::1",
"2001::2"
],
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
.../userspace-api/netlink/genetlink-legacy.rst | 12 +++++++++---
tools/net/ynl/lib/ynl.py | 5 +++++
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/Documentation/userspace-api/netlink/genetlink-legacy.rst b/Documentation/userspace-api/netlink/genetlink-legacy.rst
index 54e8fb25e093..6525ef6ca62f 100644
--- a/Documentation/userspace-api/netlink/genetlink-legacy.rst
+++ b/Documentation/userspace-api/netlink/genetlink-legacy.rst
@@ -66,9 +66,15 @@ looks like::
[MEMBER1]
[MEMBER2]
-It 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.
+Other ``sub-type`` like ``u32`` means there is only one member as described
+in ``sub-type`` in the ``ENTRY``. The structure looks like::
+
+ [SOME-OTHER-ATTR]
+ [ARRAY-ATTR]
+ [ENTRY]
+ [MEMBER1]
+ [ENTRY]
+ [MEMBER1]
type-value
~~~~~~~~~~
diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py
index e5ad415905c7..aa7077cffe74 100644
--- a/tools/net/ynl/lib/ynl.py
+++ b/tools/net/ynl/lib/ynl.py
@@ -640,6 +640,11 @@ class YnlFamily(SpecFamily):
if attr_spec["sub-type"] == 'nest':
subattrs = self._decode(NlAttrs(item.raw), attr_spec['nested-attributes'])
decoded.append({ item.type: subattrs })
+ elif attr_spec["sub-type"] == 'binary' or attr_spec["sub-type"] == 'u32':
+ subattrs = item.as_bin()
+ if attr_spec.display_hint:
+ subattrs = self._formatted_string(subattrs, attr_spec.display_hint)
+ decoded.append(subattrs)
else:
raise Exception(f'Unknown {attr_spec["sub-type"]} with name {attr_spec["name"]}')
return decoded
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCHv3 net-next 2/2] ynl: support binary/u32 sub-type for indexed-array
2024-04-01 3:56 ` [PATCHv3 net-next 2/2] ynl: support binary/u32 sub-type for indexed-array Hangbin Liu
@ 2024-04-02 4:43 ` Jakub Kicinski
2024-04-03 2:28 ` Hangbin Liu
0 siblings, 1 reply; 9+ messages in thread
From: Jakub Kicinski @ 2024-04-02 4:43 UTC (permalink / raw)
To: Hangbin Liu
Cc: netdev, David S. Miller, Eric Dumazet, Paolo Abeni, Donald Hunter,
Jiri Pirko, Jacob Keller, Stanislav Fomichev
On Mon, 1 Apr 2024 11:56:51 +0800 Hangbin Liu wrote:
> +Other ``sub-type`` like ``u32`` means there is only one member as described
> +in ``sub-type`` in the ``ENTRY``. The structure looks like::
> +
> + [SOME-OTHER-ATTR]
> + [ARRAY-ATTR]
> + [ENTRY]
> + [MEMBER1]
> + [ENTRY]
> + [MEMBER1]
I think that elsewhere in the doc we use [SOMETHING] to mean
TLV of type SOMETHING, here MEMBER1/2 are presumably just
payloads of each ENTRY? Maybe this is better:
[SOME-OTHER-ATTR]
[ARRAY-ATTR]
[ENTRY u32]
[ENTRY u32]
?
> type-value
> ~~~~~~~~~~
> diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py
> index e5ad415905c7..aa7077cffe74 100644
> --- a/tools/net/ynl/lib/ynl.py
> +++ b/tools/net/ynl/lib/ynl.py
> @@ -640,6 +640,11 @@ class YnlFamily(SpecFamily):
> if attr_spec["sub-type"] == 'nest':
> subattrs = self._decode(NlAttrs(item.raw), attr_spec['nested-attributes'])
> decoded.append({ item.type: subattrs })
> + elif attr_spec["sub-type"] == 'binary' or attr_spec["sub-type"] == 'u32':
> + subattrs = item.as_bin()
Are you sure that as_bin() will work for all u32s?
Or just when there's a hint...
> + if attr_spec.display_hint:
> + subattrs = self._formatted_string(subattrs, attr_spec.display_hint)
> + decoded.append(subattrs)
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCHv3 net-next 2/2] ynl: support binary/u32 sub-type for indexed-array
2024-04-02 4:43 ` Jakub Kicinski
@ 2024-04-03 2:28 ` Hangbin Liu
2024-04-03 2:35 ` Jakub Kicinski
0 siblings, 1 reply; 9+ messages in thread
From: Hangbin Liu @ 2024-04-03 2:28 UTC (permalink / raw)
To: Jakub Kicinski
Cc: netdev, David S. Miller, Eric Dumazet, Paolo Abeni, Donald Hunter,
Jiri Pirko, Jacob Keller, Stanislav Fomichev
On Mon, Apr 01, 2024 at 09:43:31PM -0700, Jakub Kicinski wrote:
> I think that elsewhere in the doc we use [SOMETHING] to mean
> TLV of type SOMETHING, here MEMBER1/2 are presumably just
> payloads of each ENTRY? Maybe this is better:
>
> [SOME-OTHER-ATTR]
> [ARRAY-ATTR]
> [ENTRY u32]
> [ENTRY u32]
>
Thanks, I will update the doc.
> ?
>
> > type-value
> > ~~~~~~~~~~
> > diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py
> > index e5ad415905c7..aa7077cffe74 100644
> > --- a/tools/net/ynl/lib/ynl.py
> > +++ b/tools/net/ynl/lib/ynl.py
> > @@ -640,6 +640,11 @@ class YnlFamily(SpecFamily):
> > if attr_spec["sub-type"] == 'nest':
> > subattrs = self._decode(NlAttrs(item.raw), attr_spec['nested-attributes'])
> > decoded.append({ item.type: subattrs })
> > + elif attr_spec["sub-type"] == 'binary' or attr_spec["sub-type"] == 'u32':
> > + subattrs = item.as_bin()
>
> Are you sure that as_bin() will work for all u32s?
> Or just when there's a hint...
I didn't check other subsystem. For bonding only, if we don't have the hint.
e.g.
-
name: arp-ip-target
type: indexed-array
sub-type: u32
The result will looks like:
"arp-ip-target": [
"c0a80101",
"c0a80102"
],
Which looks good to me. Do you have other suggestion?
Thanks
Hangbin
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCHv3 net-next 2/2] ynl: support binary/u32 sub-type for indexed-array
2024-04-03 2:28 ` Hangbin Liu
@ 2024-04-03 2:35 ` Jakub Kicinski
2024-04-03 3:27 ` Hangbin Liu
0 siblings, 1 reply; 9+ messages in thread
From: Jakub Kicinski @ 2024-04-03 2:35 UTC (permalink / raw)
To: Hangbin Liu
Cc: netdev, David S. Miller, Eric Dumazet, Paolo Abeni, Donald Hunter,
Jiri Pirko, Jacob Keller, Stanislav Fomichev
On Wed, 3 Apr 2024 10:28:34 +0800 Hangbin Liu wrote:
> I didn't check other subsystem. For bonding only, if we don't have the hint.
> e.g.
>
> -
> name: arp-ip-target
> type: indexed-array
> sub-type: u32
>
> The result will looks like:
>
> "arp-ip-target": [
> "c0a80101",
> "c0a80102"
> ],
>
> Which looks good to me. Do you have other suggestion?
That doesn't look right, without the format hint if the type is u32
the members should be plain integers not hex strings.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCHv3 net-next 2/2] ynl: support binary/u32 sub-type for indexed-array
2024-04-03 2:35 ` Jakub Kicinski
@ 2024-04-03 3:27 ` Hangbin Liu
2024-04-04 0:07 ` Jakub Kicinski
0 siblings, 1 reply; 9+ messages in thread
From: Hangbin Liu @ 2024-04-03 3:27 UTC (permalink / raw)
To: Jakub Kicinski
Cc: netdev, David S. Miller, Eric Dumazet, Paolo Abeni, Donald Hunter,
Jiri Pirko, Jacob Keller, Stanislav Fomichev
On Tue, Apr 02, 2024 at 07:35:51PM -0700, Jakub Kicinski wrote:
> On Wed, 3 Apr 2024 10:28:34 +0800 Hangbin Liu wrote:
> > I didn't check other subsystem. For bonding only, if we don't have the hint.
> > e.g.
> >
> > -
> > name: arp-ip-target
> > type: indexed-array
> > sub-type: u32
> >
> > The result will looks like:
> >
> > "arp-ip-target": [
> > "c0a80101",
> > "c0a80102"
> > ],
> >
> > Which looks good to me. Do you have other suggestion?
>
> That doesn't look right, without the format hint if the type is u32
> the members should be plain integers not hex strings.
OK, I can separate the binary and u32 dealing. How about like
diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py
index e5ad415905c7..be42e4fc1037 100644
--- a/tools/net/ynl/lib/ynl.py
+++ b/tools/net/ynl/lib/ynl.py
@@ -640,6 +640,16 @@ class YnlFamily(SpecFamily):
if attr_spec["sub-type"] == 'nest':
subattrs = self._decode(NlAttrs(item.raw), attr_spec['nested-attributes'])
decoded.append({ item.type: subattrs })
+ elif attr_spec["sub-type"] == 'binary':
+ subattrs = item.as_bin()
+ if attr_spec.display_hint:
+ subattrs = self._formatted_string(subattrs, attr_spec.display_hint)
+ decoded.append(subattrs)
+ elif attr_spec["sub-type"] in NlAttr.type_formats:
+ subattrs = item.as_scalar(attr_spec['sub-type'], attr_spec.byte_order)
+ if attr_spec.display_hint:
+ subattrs = self._formatted_string(subattrs, attr_spec.display_hint)
+ decoded.append(subattrs)
else:
raise Exception(f'Unknown {attr_spec["sub-type"]} with name {attr_spec["name"]}')
return decoded
With only sub-type: u32 it shows like
"arp-ip-target": [
3232235777,
3232235778
],
Thanks
Hangbin
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCHv3 net-next 2/2] ynl: support binary/u32 sub-type for indexed-array
2024-04-03 3:27 ` Hangbin Liu
@ 2024-04-04 0:07 ` Jakub Kicinski
0 siblings, 0 replies; 9+ messages in thread
From: Jakub Kicinski @ 2024-04-04 0:07 UTC (permalink / raw)
To: Hangbin Liu
Cc: netdev, David S. Miller, Eric Dumazet, Paolo Abeni, Donald Hunter,
Jiri Pirko, Jacob Keller, Stanislav Fomichev
On Wed, 3 Apr 2024 11:27:22 +0800 Hangbin Liu wrote:
> OK, I can separate the binary and u32 dealing. How about like
>
> diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py
> index e5ad415905c7..be42e4fc1037 100644
> --- a/tools/net/ynl/lib/ynl.py
> +++ b/tools/net/ynl/lib/ynl.py
> @@ -640,6 +640,16 @@ class YnlFamily(SpecFamily):
> if attr_spec["sub-type"] == 'nest':
> subattrs = self._decode(NlAttrs(item.raw), attr_spec['nested-attributes'])
> decoded.append({ item.type: subattrs })
> + elif attr_spec["sub-type"] == 'binary':
> + subattrs = item.as_bin()
> + if attr_spec.display_hint:
> + subattrs = self._formatted_string(subattrs, attr_spec.display_hint)
> + decoded.append(subattrs)
> + elif attr_spec["sub-type"] in NlAttr.type_formats:
> + subattrs = item.as_scalar(attr_spec['sub-type'], attr_spec.byte_order)
> + if attr_spec.display_hint:
> + subattrs = self._formatted_string(subattrs, attr_spec.display_hint)
> + decoded.append(subattrs)
Aha, this look right!
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCHv3 net-next 2/2] ynl: support binary/u32 sub-type for indexed-array
2024-04-04 6:31 [PATCHv4 net-next 0/2] ynl: rename array-nest to indexed-array Hangbin Liu
@ 2024-04-04 6:31 ` Hangbin Liu
0 siblings, 0 replies; 9+ messages in thread
From: Hangbin Liu @ 2024-04-04 6:31 UTC (permalink / raw)
To: netdev
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Donald Hunter, Jiri Pirko, Jacob Keller, Stanislav Fomichev,
Hangbin Liu
Add binary/u32 sub-type support for indexed-array to display bond
arp and ns targets. Here is what the result looks like:
# ip link add bond0 type bond mode 1 \
arp_ip_target 192.168.1.1,192.168.1.2 ns_ip6_target 2001::1,2001::2
# ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/rt_link.yaml \
--do getlink --json '{"ifname": "bond0"}' --output-json | jq '.linkinfo'
"arp-ip-target": [
"192.168.1.1",
"192.168.1.2"
],
[...]
"ns-ip6-target": [
"2001::1",
"2001::2"
],
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
.../userspace-api/netlink/genetlink-legacy.rst | 12 +++++++++---
tools/net/ynl/lib/ynl.py | 5 +++++
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/Documentation/userspace-api/netlink/genetlink-legacy.rst b/Documentation/userspace-api/netlink/genetlink-legacy.rst
index 54e8fb25e093..6525ef6ca62f 100644
--- a/Documentation/userspace-api/netlink/genetlink-legacy.rst
+++ b/Documentation/userspace-api/netlink/genetlink-legacy.rst
@@ -66,9 +66,15 @@ looks like::
[MEMBER1]
[MEMBER2]
-It 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.
+Other ``sub-type`` like ``u32`` means there is only one member as described
+in ``sub-type`` in the ``ENTRY``. The structure looks like::
+
+ [SOME-OTHER-ATTR]
+ [ARRAY-ATTR]
+ [ENTRY]
+ [MEMBER1]
+ [ENTRY]
+ [MEMBER1]
type-value
~~~~~~~~~~
diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py
index e5ad415905c7..aa7077cffe74 100644
--- a/tools/net/ynl/lib/ynl.py
+++ b/tools/net/ynl/lib/ynl.py
@@ -640,6 +640,11 @@ class YnlFamily(SpecFamily):
if attr_spec["sub-type"] == 'nest':
subattrs = self._decode(NlAttrs(item.raw), attr_spec['nested-attributes'])
decoded.append({ item.type: subattrs })
+ elif attr_spec["sub-type"] == 'binary' or attr_spec["sub-type"] == 'u32':
+ subattrs = item.as_bin()
+ if attr_spec.display_hint:
+ subattrs = self._formatted_string(subattrs, attr_spec.display_hint)
+ decoded.append(subattrs)
else:
raise Exception(f'Unknown {attr_spec["sub-type"]} with name {attr_spec["name"]}')
return decoded
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
end of thread, other threads:[~2024-04-04 6:31 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-01 3:56 [PATCHv3 net-next 0/2] ynl: rename array-nest to indexed-array Hangbin Liu
2024-04-01 3:56 ` [PATCHv3 net-next 1/2] " Hangbin Liu
2024-04-01 3:56 ` [PATCHv3 net-next 2/2] ynl: support binary/u32 sub-type for indexed-array Hangbin Liu
2024-04-02 4:43 ` Jakub Kicinski
2024-04-03 2:28 ` Hangbin Liu
2024-04-03 2:35 ` Jakub Kicinski
2024-04-03 3:27 ` Hangbin Liu
2024-04-04 0:07 ` Jakub Kicinski
-- strict thread matches above, loose matches on Subject: below --
2024-04-04 6:31 [PATCHv4 net-next 0/2] ynl: rename array-nest to indexed-array Hangbin Liu
2024-04-04 6:31 ` [PATCHv3 net-next 2/2] ynl: support binary/u32 sub-type for indexed-array Hangbin Liu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).