aboutsummaryrefslogtreecommitdiff
path: root/tools/net/ynl/lib/ynl.py
AgeCommit message (Collapse)AuthorFilesLines
2023-04-11tools: ynl: throw a more meaningful exception if family not supportedJakub Kicinski1-1/+4
cli.py currently throws a pure KeyError if kernel doesn't support a netlink family. Users who did not write ynl (hah) may waste their time investigating what's wrong with the Python code. Improve the error message: Traceback (most recent call last): File "/home/kicinski/devel/linux/tools/net/ynl/lib/ynl.py", line 362, in __init__ self.family = GenlFamily(self.yaml['name']) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/kicinski/devel/linux/tools/net/ynl/lib/ynl.py", line 331, in __init__ self.genl_family = genl_family_name_to_id[family_name] ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^ KeyError: 'netdev' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/kicinski/devel/linux/./tools/net/ynl/cli.py", line 52, in <module> main() File "/home/kicinski/devel/linux/./tools/net/ynl/cli.py", line 31, in main ynl = YnlFamily(args.spec, args.schema) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/kicinski/devel/linux/tools/net/ynl/lib/ynl.py", line 364, in __init__ raise Exception(f"Family '{self.yaml['name']}' not supported by the kernel") Exception: Family 'netdev' not supported by the kernel Signed-off-by: Jakub Kicinski <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
2023-03-30tools: ynl: ethtool testing toolStanislav Fomichev1-0/+11
This is what I've been using to see whether the spec makes sense. A small subset of getters (mostly the unprivileged ones) is implemented. Some setters (channels) also work. Setters for messages with bitmasks are not implemented. Initially I was trying to make this tool look 1:1 like real ethtool, but eventually gave up :-) Sample output: $ ./tools/net/ynl/ethtool enp0s31f6 Settings for enp0s31f6: Supported ports: [ TP ] Supported link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Supported pause frame use: no Supports auto-negotiation: yes Supported FEC modes: Not reported Speed: Unknown! Duplex: Unknown! (255) Auto-negotiation: on Port: Twisted Pair PHYAD: 2 Transceiver: Internal MDI-X: Unknown (auto) Current message level: drv probe link Link detected: no Signed-off-by: Stanislav Fomichev <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
2023-03-30tools: ynl: replace print with NlErrorStanislav Fomichev1-3/+9
Instead of dumping the error on the stdout, make the callee and opportunity to decide what to do with it. This is mostly for the ethtool testing. Signed-off-by: Stanislav Fomichev <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
2023-03-30tools: ynl: support byte-order in cliStanislav Fomichev1-12/+23
Used by ethtool spec. Signed-off-by: Stanislav Fomichev <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
2023-03-28tools: ynl: Add fixed-header support to ynlDonald Hunter1-4/+20
Add support for netlink families that add an optional fixed header structure after the genetlink header and before any attributes. The fixed-header can be specified on a per op basis, or once for all operations, which serves as a default value that can be overridden. Signed-off-by: Donald Hunter <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
2023-03-28tools: ynl: Add struct attr decoding to ynlDonald Hunter1-1/+14
Add support for decoding attributes that contain C structs. Signed-off-by: Donald Hunter <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
2023-03-28tools: ynl: Add C array attribute decoding to ynlDonald Hunter1-1/+17
Add support for decoding C arrays from binay blobs in genetlink-legacy messages. Signed-off-by: Donald Hunter <[email protected]> Reviewed-by: Jakub Kicinski <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
2023-03-27tools: ynl: Add missing types to encode/decodeMichal Michalik1-0/+6
While testing the tool I noticed we miss the u16 type on payload create. On the code inspection it turned out we miss also u64 - add them. We also miss the decoding of u16 despite the fact `NlAttr` class supports it - add it. Signed-off-by: Michal Michalik <[email protected]> Acked-by: Jakub Kicinski <[email protected]> Signed-off-by: David S. Miller <[email protected]>
2023-03-24Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/netJakub Kicinski1-3/+3
Conflicts: drivers/net/ethernet/mellanox/mlx5/core/en_tc.c 6e9d51b1a5cb ("net/mlx5e: Initialize link speed to zero") 1bffcea42926 ("net/mlx5e: Add devlink hairpin queues parameters") https://lore.kernel.org/all/[email protected]/ https://lore.kernel.org/all/[email protected]/ Adjacent changes: drivers/net/phy/phy.c 323fe43cf9ae ("net: phy: Improved PHY error reporting in state machine") 4203d84032e2 ("net: phy: Ensure state transitions are processed from phy_stop()") Signed-off-by: Jakub Kicinski <[email protected]>
2023-03-23ynl: allow to encode u8 attrJiri Pirko1-0/+2
Playing with dpll netlink, I came across following issue: $ sudo ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/dpll.yaml --do pin-set --json '{"id": 0, "pin-idx": 1, "pin-state": 1}' Traceback (most recent call last): File "tools/net/ynl/cli.py", line 52, in <module> main() File "tools/net/ynl/cli.py", line 40, in main reply = ynl.do(args.do, attrs) File "tools/net/ynl/lib/ynl.py", line 520, in do return self._op(method, vals) File "tools/net/ynl/lib/ynl.py", line 476, in _op msg += self._add_attr(op.attr_set.name, name, value) File "tools/net/ynl/lib/ynl.py", line 344, in _add_attr raise Exception(f'Unknown type at {space} {name} {value} {attr["type"]}') Exception: Unknown type at dpll pin-state 1 u8 I'm not that familiar with ynl code, but from a quick peek, I suspect that couple other types are missing for both encoding and decoding. Ignoring those here as I'm scratching my local itch only. Fix the issue by adding u8 attr packing. Signed-off-by: Jiri Pirko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2023-03-22tools: ynl: Fix genlmsg header encoding formatsDonald Hunter1-3/+3
The pack strings use 'b' signed char for cmd and version but struct genlmsghdr defines them as unsigned char. Use 'B' instead. Fixes: 4e4480e89c47 ("tools: ynl: move the cli and netlink code around") Signed-off-by: Donald Hunter <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2023-03-08tools: ynl: fix enum-as-flags in the generic CLIJakub Kicinski1-7/+2
Lorenzo points out that the generic CLI is broken for the netdev family. When I added the support for documentation of enums (and sparse enums) the client script was not updated. It expects the values in enum to be a list of names, now it can also be a dict (YAML object). Reported-by: Lorenzo Bianconi <[email protected]> Fixes: e4b48ed460d3 ("tools: ynl: add a completely generic client") Signed-off-by: Jakub Kicinski <[email protected]>
2023-03-07ynl: re-license uniformly under GPL-2.0 OR BSD-3-ClauseJakub Kicinski1-1/+1
I was intending to make all the Netlink Spec code BSD-3-Clause to ease the adoption but it appears that: - I fumbled the uAPI and used "GPL WITH uAPI note" there - it gives people pause as they expect GPL in the kernel As suggested by Chuck re-license under dual. This gives us benefit of full BSD freedom while fulfilling the broad "kernel is under GPL" expectations. Link: https://lore.kernel.org/all/[email protected]/ Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2023-01-31tools: ynl: use operation names from spec on the CLIJakub Kicinski1-0/+6
When I wrote the first version of the Python code I was quite excited that we can generate class methods directly from the spec. Unfortunately we need to use valid identifiers for method names (specifically no dashes are allowed). Don't reuse those names on the CLI, it's much more natural to use the operation names exactly as listed in the spec. Instead of: ./cli --do rings_get use: ./cli --do rings-get Signed-off-by: Jakub Kicinski <[email protected]>
2023-01-31tools: ynl: support pretty printing bad attribute namesJakub Kicinski1-0/+40
One of my favorite features of the Netlink specs is that they make decoding structured extack a ton easier. Implement pretty printing bad attribute names in YNL. For example it will now say: 'bad-attr': '.header.flags' rather than the useless: 'bad-attr-offs': 32 Proof: $ ./cli.py --spec ethtool.yaml --do rings_get \ --json '{"header":{"dev-index":1, "flags":4}}' Netlink error: Invalid argument nl_len = 68 (52) nl_flags = 0x300 nl_type = 2 error: -22 extack: {'msg': 'reserved bit set', 'bad-attr': '.header.flags'} Signed-off-by: Jakub Kicinski <[email protected]>
2023-01-31tools: ynl: support multi-attrJakub Kicinski1-7/+14
Ethtool uses mutli-attr, add the support to YNL. Signed-off-by: Jakub Kicinski <[email protected]>
2023-01-31tools: ynl: support directional enum-model in CLIJakub Kicinski1-4/+4
Support families which use different IDs for messages to and from the kernel. Signed-off-by: Jakub Kicinski <[email protected]>
2023-01-31tools: ynl: add support for types needed by ethtoolJakub Kicinski1-1/+10
Ethtool needs support for handful of extra types. It doesn't have the definitions section yet. Signed-off-by: Jakub Kicinski <[email protected]>
2023-01-31tools: ynl: use the common YAML loading and validation codeJakub Kicinski1-93/+25
Adapt the common object hierarchy in code gen and CLI. Signed-off-by: Jakub Kicinski <[email protected]>
2023-01-31tools: ynl: move the cli and netlink code aroundJakub Kicinski1-0/+534
Move the CLI code out of samples/ and the library part of it into tools/net/ynl/lib/. This way we can start sharing some code with the code gen. Initially I thought that code gen is too C-specific to share anything but basic stuff like calculating values for enums can easily be shared. Signed-off-by: Jakub Kicinski <[email protected]>