| 6c10f1a1 | 18-Nov-2025 |
Gal Pressman <gal@nvidia.com> |
tools: ynl: cli: Display enum values in --list-attrs output
When listing attributes with --list-attrs, display the actual enum values for attributes that reference an enum type.
# ./cli.py --fami
tools: ynl: cli: Display enum values in --list-attrs output
When listing attributes with --list-attrs, display the actual enum values for attributes that reference an enum type.
# ./cli.py --family netdev --list-attrs dev-get [..] - xdp-features: u64 (enum: xdp-act) Flags: basic, redirect, ndo-xmit, xsk-zerocopy, hw-offload, rx-sg, ndo-xmit-sg Bitmask of enabled xdp-features. [..]
Reviewed-by: Nimrod Oren <noren@nvidia.com> Signed-off-by: Gal Pressman <gal@nvidia.com> Link: https://patch.msgid.link/20251118143208.2380814-4-gal@nvidia.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
show more ...
|
| bc1bc1b3 | 18-Nov-2025 |
Gal Pressman <gal@nvidia.com> |
tools: ynl: cli: Parse nested attributes in --list-attrs output
Enhance the --list-attrs option to recursively display nested attributes instead of just showing "nest" as the type. Nested attributes
tools: ynl: cli: Parse nested attributes in --list-attrs output
Enhance the --list-attrs option to recursively display nested attributes instead of just showing "nest" as the type. Nested attributes now show their attribute set name and expand to display their contents.
# ./cli.py --family ethtool --list-attrs rss-get [..] Do request attributes: - header: nest -> header - dev-index: u32 - dev-name: string - flags: u32 (enum: header-flags) - phy-index: u32 - context: u32 [..]
Reviewed-by: Nimrod Oren <noren@nvidia.com> Signed-off-by: Gal Pressman <gal@nvidia.com> Reviewed-by: Donald Hunter <donald.hunter@gmail.com> Link: https://patch.msgid.link/20251118143208.2380814-3-gal@nvidia.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
show more ...
|
| 34164142 | 27-Oct-2025 |
Jakub Kicinski <kuba@kernel.org> |
tools: ynl: rework the string representation of NlError
In early days of YNL development dumping the NlMsg on errors was quite useful, as the library itself could have been buggy. These days increas
tools: ynl: rework the string representation of NlError
In early days of YNL development dumping the NlMsg on errors was quite useful, as the library itself could have been buggy. These days increasingly the NlMsg is just taking up screen space and means nothing to a typical user. Try to format the errors more in line with how YNL C formats its errors strings.
Before: $ ynl --family ethtool --do channels-set --json '{}' Netlink error: Invalid argument nl_len = 44 (28) nl_flags = 0x300 nl_type = 2 error: -22 extack: {'miss-type': 'header'}
$ ynl --family ethtool --do channels-set --json '{..., "tx-count": 999}' Netlink error: Invalid argument nl_len = 88 (72) nl_flags = 0x300 nl_type = 2 error: -22 extack: {'msg': 'requested channel count exceeds maximum', 'bad-attr': '.tx-count'}
After: $ ynl --family ethtool --do channels-set --json '{}' Netlink error: Invalid argument {'miss-type': 'header'}
$ ynl --family ethtool --do channels-set --json '{..., "tx-count": 999}' Netlink error: requested channel count exceeds maximum: Invalid argument {'bad-attr': '.tx-count'}
Reviewed-by: Donald Hunter <donald.hunter@gmail.com> Link: https://patch.msgid.link/20251027192958.2058340-2-kuba@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
show more ...
|
| 1b255e1b | 15-Sep-2025 |
Asbjørn Sloth Tønnesen <ast@fiberby.net> |
tools: ynl: add ipv4-or-v6 display hint
The attribute WGALLOWEDIP_A_IPADDR can contain either an IPv4 or an IPv6 address depending on WGALLOWEDIP_A_FAMILY, however in practice it is enough to look a
tools: ynl: add ipv4-or-v6 display hint
The attribute WGALLOWEDIP_A_IPADDR can contain either an IPv4 or an IPv6 address depending on WGALLOWEDIP_A_FAMILY, however in practice it is enough to look at the attribute length.
This patch implements an ipv4-or-v6 display hint, that can deal with this kind of attribute.
It only implements this display hint for genetlink-legacy, it can be added to other protocol variants if needed, but we don't want to encourage it's use.
Signed-off-by: Asbjørn Sloth Tønnesen <ast@fiberby.net> Reviewed-by: Donald Hunter <donald.hunter@gmail.com> Link: https://patch.msgid.link/20250915144301.725949-12-ast@fiberby.net Signed-off-by: Jakub Kicinski <kuba@kernel.org>
show more ...
|
| 52550d51 | 15-Sep-2025 |
Asbjørn Sloth Tønnesen <ast@fiberby.net> |
tools: ynl: decode hex input
This patch adds support for decoding hex input, so that binary attributes can be read through --json.
Example (using future wireguard.yaml): $ sudo ./tools/net/ynl/pyy
tools: ynl: decode hex input
This patch adds support for decoding hex input, so that binary attributes can be read through --json.
Example (using future wireguard.yaml): $ sudo ./tools/net/ynl/pyynl/cli.py --family wireguard \ --do set-device --json '{"ifindex":3, "private-key":"2a ae 6c 35 c9 4f cf <... to 32 bytes>"}'
In order to somewhat mirror what is done in _formatted_string(), then for non-binary attributes attempt to convert it to an int.
Signed-off-by: Asbjørn Sloth Tønnesen <ast@fiberby.net> Reviewed-by: Donald Hunter <donald.hunter@gmail.com> Link: https://patch.msgid.link/20250915144301.725949-11-ast@fiberby.net Signed-off-by: Jakub Kicinski <kuba@kernel.org>
show more ...
|
| 5c51ae24 | 15-Sep-2025 |
Asbjørn Sloth Tønnesen <ast@fiberby.net> |
tools: ynl: encode indexed-arrays
This patch adds support for encoding indexed-array attributes with sub-type nest in pyynl.
Signed-off-by: Asbjørn Sloth Tønnesen <ast@fiberby.net> Reviewed-by: Don
tools: ynl: encode indexed-arrays
This patch adds support for encoding indexed-array attributes with sub-type nest in pyynl.
Signed-off-by: Asbjørn Sloth Tønnesen <ast@fiberby.net> Reviewed-by: Donald Hunter <donald.hunter@gmail.com> Link: https://patch.msgid.link/20250915144301.725949-10-ast@fiberby.net Signed-off-by: Jakub Kicinski <kuba@kernel.org>
show more ...
|
| 328c1342 | 15-Sep-2025 |
Asbjørn Sloth Tønnesen <ast@fiberby.net> |
tools: ynl: move nest packing to a helper function
This patch moves nest packing into a helper function, that can also be used for packing indexed arrays.
No behavioural changes intended.
Signed-o
tools: ynl: move nest packing to a helper function
This patch moves nest packing into a helper function, that can also be used for packing indexed arrays.
No behavioural changes intended.
Signed-off-by: Asbjørn Sloth Tønnesen <ast@fiberby.net> Reviewed-by: Donald Hunter <donald.hunter@gmail.com> Link: https://patch.msgid.link/20250915144301.725949-9-ast@fiberby.net Signed-off-by: Jakub Kicinski <kuba@kernel.org>
show more ...
|
| a44a93ea | 15-Sep-2025 |
Asbjørn Sloth Tønnesen <ast@fiberby.net> |
tools: ynl-gen: rename TypeArrayNest to TypeIndexedArray
Since TypeArrayNest can now be used with many other sub-types than nest, then rename it to TypeIndexedArray, to reduce confusion.
This patch
tools: ynl-gen: rename TypeArrayNest to TypeIndexedArray
Since TypeArrayNest can now be used with many other sub-types than nest, then rename it to TypeIndexedArray, to reduce confusion.
This patch continues the rename, that was started in commit aa6485d813ad ("ynl: rename array-nest to indexed-array"), when the YNL type was renamed.
In order to get rid of all references to the old naming, within ynl, then renaming some variables in _multi_parse().
This is a trivial patch with no behavioural changes intended.
Signed-off-by: Asbjørn Sloth Tønnesen <ast@fiberby.net> Reviewed-by: Donald Hunter <donald.hunter@gmail.com> Reviewed-by: Jakub Kicinski <kuba@kernel.org> Link: https://patch.msgid.link/20250915144301.725949-8-ast@fiberby.net Signed-off-by: Jakub Kicinski <kuba@kernel.org>
show more ...
|
| 1d99aa4e | 15-Sep-2025 |
Asbjørn Sloth Tønnesen <ast@fiberby.net> |
tools: ynl-gen: validate nested arrays
In nested arrays don't require that the intermediate attribute type should be a valid attribute type, it might just be zero or an incrementing index, it is oft
tools: ynl-gen: validate nested arrays
In nested arrays don't require that the intermediate attribute type should be a valid attribute type, it might just be zero or an incrementing index, it is often not even used.
See include/net/netlink.h about NLA_NESTED_ARRAY: > The difference to NLA_NESTED is the structure: > NLA_NESTED has the nested attributes directly inside > while an array has the nested attributes at another > level down and the attribute types directly in the > nesting don't matter.
Example based on include/uapi/linux/wireguard.h: > WGDEVICE_A_PEERS: NLA_NESTED > 0: NLA_NESTED > WGPEER_A_PUBLIC_KEY: NLA_EXACT_LEN, len WG_KEY_LEN > [..] > 0: NLA_NESTED > ... > ...
Previous the check required that the nested type was valid in the parent attribute set, which in this case resolves to WGDEVICE_A_UNSPEC, which is YNL_PT_REJECT, and it took the early exit and returned YNL_PARSE_CB_ERROR.
This patch renames the old nl_attr_validate() to __nl_attr_validate(), and creates a new inline function nl_attr_validate() to mimic the old one.
The new __nl_attr_validate() takes the attribute type as an argument, so we can use it to validate attributes of a nested attribute, in the context of the parents attribute type, which in the above case is generated as: [WGDEVICE_A_PEERS] = { .name = "peers", .type = YNL_PT_NEST, .nest = &wireguard_wgpeer_nest, },
__nl_attr_validate() only checks if the attribute length is plausible for a given attribute type, so the .nest in the above example is not used.
As the new inline function needs to be defined after ynl_attr_type(), then the definitions are moved down, so we avoid a forward declaration of ynl_attr_type().
Some other examples are NL80211_BAND_ATTR_FREQS (nest) and NL80211_ATTR_SUPPORTED_COMMANDS (u32) both in nl80211-user.c $ make -C tools/net/ynl/generated nl80211-user.c
Signed-off-by: Asbjørn Sloth Tønnesen <ast@fiberby.net> Reviewed-by: Jakub Kicinski <kuba@kernel.org> Link: https://patch.msgid.link/20250915144301.725949-7-ast@fiberby.net Signed-off-by: Jakub Kicinski <kuba@kernel.org>
show more ...
|
| 099902fc | 15-Sep-2025 |
Asbjørn Sloth Tønnesen <ast@fiberby.net> |
tools: ynl-gen: avoid repetitive variables definitions
In the generated attribute parsing code, avoid repetitively defining the same variables over and over again, local to the conditional block for
tools: ynl-gen: avoid repetitive variables definitions
In the generated attribute parsing code, avoid repetitively defining the same variables over and over again, local to the conditional block for each attribute.
This patch consolidates the definitions of local variables for attribute parsing, so that they are defined at the function level, and re-used across attributes, thus making the generated code read more natural.
If attributes defines identical local_vars, then they will be deduplicated, attributes are assumed to only use their local variables transiently.
The example below shows how `len` was defined repeatedly in tools/net/ynl/generated/nl80211-user.c:
nl80211_iftype_data_attrs_parse(..) { [..] ynl_attr_for_each_nested(attr, nested) { unsigned int type = ynl_attr_type(attr);
if (type == NL80211_BAND_IFTYPE_ATTR_IFTYPES) { unsigned int len; [..] } else if (type == NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC) { unsigned int len; [..] [same pattern 8 times, so 11 times in total] } else if (type == NL80211_BAND_IFTYPE_ATTR_EHT_CAP_PPE) { unsigned int len; [..] } } return 0; }
This patch results in this diffstat for the generated code:
$ diff -Naur pre/ post/ | diffstat devlink-user.c | 187 +++---------------- dpll-user.c | 10 - ethtool-user.c | 49 +---- fou-user.c | 5 handshake-user.c | 3 mptcp_pm-user.c | 3 nfsd-user.c | 16 - nl80211-user.c | 159 +--------------- nlctrl-user.c | 21 -- ovpn-user.c | 7 ovs_datapath-user.c | 9 ovs_flow-user.c | 89 --------- ovs_vport-user.c | 7 rt-addr-user.c | 14 - rt-link-user.c | 183 ++---------------- rt-neigh-user.c | 14 - rt-route-user.c | 26 -- rt-rule-user.c | 11 - tc-user.c | 380 +++++---------------------------------- tcp_metrics-user.c | 7 team-user.c | 5 21 files changed, 175 insertions(+), 1030 deletions(-)
The changed lines are mostly `unsigned int len;` definitions:
$ diff -Naur pre/ post/ | grep ^[-+] | grep -v '^[-+]\{3\}' | grep -v '^.$' | sed -e 's/\t\+/ /g' | sort | uniq -c | sort -nr 488 - unsigned int len; 153 + unsigned int len; 24 - const struct nlattr *attr2; 18 + const struct nlattr *attr2; 1 - __u32 policy_id, attr_id; 1 + __u32 policy_id, attr_id; 1 - __u32 op_id; 1 + __u32 op_id; 1 - const struct nlattr *attr_policy_id, *attr_attr_id; 1 + const struct nlattr *attr_policy_id, *attr_attr_id; 1 - const struct nlattr *attr_op_id; 1 + const struct nlattr *attr_op_id;
Suggested-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Asbjørn Sloth Tønnesen <ast@fiberby.net> Reviewed-by: Jakub Kicinski <kuba@kernel.org> Link: https://patch.msgid.link/20250915144301.725949-6-ast@fiberby.net Signed-off-by: Jakub Kicinski <kuba@kernel.org>
show more ...
|
| db4ea3ba | 15-Sep-2025 |
Asbjørn Sloth Tønnesen <ast@fiberby.net> |
tools: ynl-gen: refactor local vars for .attr_put() callers
Refactor the generation of local variables needed when building requests, by moving the logic from put_req_nested() into a new helper put_
tools: ynl-gen: refactor local vars for .attr_put() callers
Refactor the generation of local variables needed when building requests, by moving the logic from put_req_nested() into a new helper put_local_vars(), and use the helper before .attr_put() is called, thus generating the local variables assumed by .attr_put().
Previously only put_req_nested() generated the variables assumed by .attr_put(), print_req() only generated the count iterator `i`, and print_dump() neither generated `i` nor `array`.
This patch fixes the build errors below: $ make -C tools/net/ynl/generated/ [...] -e GEN wireguard-user.c -e GEN wireguard-user.h -e CC wireguard-user.o wireguard-user.c: In function ‘wireguard_get_device_dump’: wireguard-user.c:480:9: error: ‘array’ undeclared (first use in func) 480 | array = ynl_attr_nest_start(nlh, WGDEVICE_A_PEERS); | ^~~~~ wireguard-user.c:480:9: note: each undeclared identifier is reported only once for each function it appears in wireguard-user.c:481:14: error: ‘i’ undeclared (first use in func) 481 | for (i = 0; i < req->_count.peers; i++) | ^ wireguard-user.c: In function ‘wireguard_set_device’: wireguard-user.c:533:9: error: ‘array’ undeclared (first use in func) 533 | array = ynl_attr_nest_start(nlh, WGDEVICE_A_PEERS); | ^~~~~ make: *** [Makefile:52: wireguard-user.o] Error 1 make: Leaving directory '/usr/src/linux/tools/net/ynl/generated'
Signed-off-by: Asbjørn Sloth Tønnesen <ast@fiberby.net> Reviewed-by: Jakub Kicinski <kuba@kernel.org> Link: https://patch.msgid.link/20250915144301.725949-5-ast@fiberby.net Signed-off-by: Jakub Kicinski <kuba@kernel.org>
show more ...
|
| 8df78d97 | 15-Sep-2025 |
Asbjørn Sloth Tønnesen <ast@fiberby.net> |
tools: ynl-gen: add sub-type check
Add a check to verify that the sub-type is "nest", and throw an exception if no policy could be generated, as a guard to prevent against generating a bad policy.
tools: ynl-gen: add sub-type check
Add a check to verify that the sub-type is "nest", and throw an exception if no policy could be generated, as a guard to prevent against generating a bad policy.
This is a trivial patch with no behavioural changes intended.
Signed-off-by: Asbjørn Sloth Tønnesen <ast@fiberby.net> Reviewed-by: Donald Hunter <donald.hunter@gmail.com> Reviewed-by: Jakub Kicinski <kuba@kernel.org> Reviewed-by: Jacob Keller <jacob.e.keller@intel.com> Link: https://patch.msgid.link/20250915144301.725949-4-ast@fiberby.net Signed-off-by: Jakub Kicinski <kuba@kernel.org>
show more ...
|
| d0bdfe36 | 15-Sep-2025 |
Asbjørn Sloth Tønnesen <ast@fiberby.net> |
tools: ynl-gen: generate nested array policies
This patch adds support for NLA_POLICY_NESTED_ARRAY() policies.
Example spec (from future wireguard.yaml): - name: wgpeer attributes: -
tools: ynl-gen: generate nested array policies
This patch adds support for NLA_POLICY_NESTED_ARRAY() policies.
Example spec (from future wireguard.yaml): - name: wgpeer attributes: - name: allowedips type: indexed-array sub-type: nest nested-attributes: wgallowedip
yields NLA_POLICY_NESTED_ARRAY(wireguard_wgallowedip_nl_policy).
This doesn't change any currently generated code, as it isn't used in any specs currently used for generating code.
Signed-off-by: Asbjørn Sloth Tønnesen <ast@fiberby.net> Reviewed-by: Donald Hunter <donald.hunter@gmail.com> Reviewed-by: Jakub Kicinski <kuba@kernel.org> Link: https://patch.msgid.link/20250915144301.725949-3-ast@fiberby.net Signed-off-by: Jakub Kicinski <kuba@kernel.org>
show more ...
|