aboutsummaryrefslogtreecommitdiff
path: root/tools/net
AgeCommit message (Collapse)AuthorFilesLines
2023-04-13tools: ynl: Rename ethtool to ethtool.pyRahul Rameshbabu1-0/+0
Make it explicit that this tool is not a drop-in replacement for ethtool. This tool is intended for testing ethtool functionality implemented in the kernel and should use a name that differentiates it from the ethtool utility. Signed-off-by: Rahul Rameshbabu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2023-04-13tools: ynl: Remove absolute paths to yaml files from ethtool testing toolRahul Rameshbabu1-2/+2
Absolute paths for the spec and schema files make the ethtool testing tool unusable with freshly checked-out source trees. Replace absolute paths with relative paths for both files in the Documentation/ directory. Issue seen before the change Traceback (most recent call last): File "/home/binary-eater/Documents/mlx/linux/tools/net/ynl/./ethtool", line 424, in <module> main() File "/home/binary-eater/Documents/mlx/linux/tools/net/ynl/./ethtool", line 158, in main ynl = YnlFamily(spec, schema) File "/home/binary-eater/Documents/mlx/linux/tools/net/ynl/lib/ynl.py", line 342, in __init__ super().__init__(def_path, schema) File "/home/binary-eater/Documents/mlx/linux/tools/net/ynl/lib/nlspec.py", line 333, in __init__ with open(spec_path, "r") as stream: FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/google/home/sdf/src/linux/Documentation/netlink/specs/ethtool.yaml' Fixes: f3d07b02b2b8 ("tools: ynl: ethtool testing tool") Signed-off-by: Rahul Rameshbabu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
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 Fomichev3-0/+444
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 Fomichev2-12/+24
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 Hunter2-12/+33
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 Hunter2-1/+16
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 Hunter2-3/+22
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-28tools: ynl: Add struct parsing to nlspecDonald Hunter1-0/+43
Add python classes for struct definitions to nlspec Signed-off-by: Donald Hunter <[email protected]> Reviewed-by: Jakub Kicinski <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
2023-03-27tools: ynl: default to treating enums as flags for mask generationJakub Kicinski2-5/+6
I was a bit too optimistic in commit bf51d27704c9 ("tools: ynl: fix get_mask utility routine"), not every mask we use is necessarily coming from an enum of type "flags". We also allow flipping an enum into flags on per-attribute basis. That's done by the 'enum-as-flags' property of an attribute. Restore this functionality, it's not currently used by any in-tree family. Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: David S. Miller <[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-24tools: ynl: add the Python requirements.txt fileMichal Michalik1-0/+2
It is a good practice to state explicitly which are the required Python packages needed in a particular project to run it. The most commonly used way is to store them in the `requirements.txt` file*. *URL: https://pip.pypa.io/en/stable/reference/requirements-file-format/ Currently user needs to figure out himself that Python needs `PyYAML` and `jsonschema` (and theirs requirements) packages to use the tool. Add the `requirements.txt` for user convenience. How to use it: 1) (optional) Create and activate empty virtual environment: python3.X -m venv venv3X source ./venv3X/bin/activate 2) Install all the required packages: pip install -r requirements.txt or python -m pip install -r requirements.txt 3) Run the script! The `requirements.txt` file was tested for: * Python 3.6 * Python 3.8 * Python 3.10 Signed-off-by: Michal Michalik <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[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-21tools: ynl: skip the explicit op array size when not neededJakub Kicinski1-1/+3
Jiri suggests it reads more naturally to skip the explicit array size when possible. When we export the symbol we want to make sure that the size is right but for statics its not needed. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2023-03-16ynl: make the tooling check the licenseJakub Kicinski2-6/+15
The (only recently documented) expectation is that all specs are under a certain license, but we don't actually enforce it. What's worse we then go ahead and assume the license was right, outputting the expected license into generated files. Fixes: 37d9df224d1e ("ynl: re-license uniformly under GPL-2.0 OR BSD-3-Clause") Reviewed-by: Chuck Lever <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
2023-03-16ynl: broaden the license even moreJakub Kicinski1-4/+4
I relicensed Netlink spec code to GPL-2.0 OR BSD-3-Clause but we still put a slightly different license on the uAPI header than the rest of the code. Use the Linux-syscall-note on all the specs and all generated code. It's moot for kernel code, but should not hurt. This way the licenses match everywhere. Cc: Chuck Lever <[email protected]> Fixes: 37d9df224d1e ("ynl: re-license uniformly under GPL-2.0 OR BSD-3-Clause") Reviewed-by: Chuck Lever <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
2023-03-16tools: ynl: make definitions optional againJakub Kicinski1-1/+2
definitions are optional, commit in question breaks cli for ethtool. Fixes: 6517a60b0307 ("tools: ynl: move the enum classes to shared code") Reviewed-by: Chuck Lever <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
2023-03-10tools: ynl: fix get_mask utility routineLorenzo Bianconi1-4/+2
Fix get_mask utility routine in order to take into account possible gaps in the elements list. Fixes: be5bea1cc0bf ("net: add basic C code generators for Netlink") Signed-off-by: Lorenzo Bianconi <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
2023-03-10tools: ynl: fix render-max for flags definitionLorenzo Bianconi1-3/+8
Properly manage render-max property for flags definition type introducing mask value and setting it to (last_element << 1) - 1 instead of adding max value set to last_element + 1 Fixes: be5bea1cc0bf ("net: add basic C code generators for Netlink") Signed-off-by: Lorenzo Bianconi <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
2023-03-08tools: ynl: fix enum-as-flags in the generic CLIJakub Kicinski2-9/+7
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-08tools: ynl: move the enum classes to shared codeJakub Kicinski3-89/+121
Move bulk of the EnumSet and EnumEntry code to shared code for reuse by cli. Signed-off-by: Jakub Kicinski <[email protected]>
2023-03-07ynl: re-license uniformly under GPL-2.0 OR BSD-3-ClauseJakub Kicinski6-8/+9
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-03-03tools: ynl: use 1 as the default for first entry in attrs/opsJakub Kicinski2-5/+8
Pretty much all families use value: 1 or reserve as unspec the first entry in attribute set and the first operation. Make this the default. Update documentation (the doc for values of operations just refers back to doc for attrs so updating only attrs). Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: David S. Miller <[email protected]>
2023-03-03tools: ynl: fully inherit attrs in subsetsJakub Kicinski1-8/+15
To avoid having to repeat the entire definition of an attribute (including the value) use the Attr object from the original set. In fact this is already the documented expectation. Fixes: be5bea1cc0bf ("net: add basic C code generators for Netlink") Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: David S. Miller <[email protected]>
2023-02-24tools: net: add __pycache__ to gitignoreJakub Kicinski1-0/+1
Python will generate its customary cache when running ynl scripts: ?? tools/net/ynl/lib/__pycache__/ Reported-by: Chuck Lever III <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
2023-02-24tools: ynl-gen: re-raise the exception instead of printingJakub Kicinski1-3/+1
traceback.print_exception() seems tricky to call, we're missing some argument, so re-raise instead. Reported-by: Chuck Lever III <[email protected]> Fixes: 3aacf8281336 ("tools: ynl: add an object hierarchy to represent parsed spec") Signed-off-by: Jakub Kicinski <[email protected]>
2023-02-24tools: ynl-gen: fix single attribute structs with attr 0 onlyJakub Kicinski1-1/+1
Chuck run into an issue with a single-element attr-set which only has an attr with value of 0. The search for max attr in a struct records attrs with value larger than 0 only (max_val is set to 0 at the start). Adjust the comparison, alternatively max_val could be init'ed to -1. Somehow picking the last attr of a value seems like a good idea in general. Reported-by: Chuck Lever III <[email protected]> Fixes: be5bea1cc0bf ("net: add basic C code generators for Netlink") Signed-off-by: Jakub Kicinski <[email protected]>
2023-01-31tools: net: use python3 explicitlyJakub Kicinski2-2/+2
The scripts require Python 3 and some distros are dropping Python 2 support. Reported-by: Stanislav Fomichev <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
2023-01-31tools: ynl: load jsonschema on demandJakub Kicinski2-1/+14
The CLI script tries to validate jsonschema by default. It's seems better to validate too many times than too few. However, when copying the scripts to random servers having to install jsonschema is tedious. Load jsonschema via importlib, and let the user opt out. Signed-off-by: Jakub Kicinski <[email protected]>
2023-01-31tools: ynl: use operation names from spec on the CLIJakub Kicinski2-4/+11
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 Kicinski2-232/+142
Adapt the common object hierarchy in code gen and CLI. Signed-off-by: Jakub Kicinski <[email protected]>
2023-01-31tools: ynl: add an object hierarchy to represent parsed specJakub Kicinski2-1/+304
There's a lot of copy and pasting going on between the "cli" and code gen when it comes to representing the parsed spec. Create a library which both can use. Signed-off-by: Jakub Kicinski <[email protected]>
2023-01-31tools: ynl: move the cli and netlink code aroundJakub Kicinski3-1/+6
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]>
2023-01-31tools: ynl-gen: prevent do / dump reorderingJakub Kicinski1-2/+2
An earlier fix tried to address generated code jumping around one code-gen run to another. Turns out dict()s are already ordered since Python 3.7, the problem is that we iterate over operation modes using a set(). Sets are unordered in Python. Signed-off-by: Jakub Kicinski <[email protected]>
2023-01-26tools: ynl: store ops in ordered dict to avoid random orderingJakub Kicinski1-1/+2
When rendering code we should walk the ops in the order in which they are declared in the spec. This is both more intuitive and prevents code from jumping around when hashing in the dict changes. Signed-off-by: Jakub Kicinski <[email protected]>
2023-01-26tools: ynl: rename ops_list -> msg_listJakub Kicinski1-4/+6
ops_list contains all the operations, but the main iteration use case is to walk only ops which define attrs. Rename ops_list to msg_list, because now it looks like the contents are the same, just the format is different. While at it convert from tuple to just keys, none of the users care about the name of the op. Signed-off-by: Jakub Kicinski <[email protected]>
2023-01-26tools: ynl: support kdocs for flags in code generationJakub Kicinski1-17/+20
Lorenzo reports that after switching from enum to flags netdev family lost ability to render kdoc (and the enum contents got generally garbled). Combine the flags and enum handling in uAPI handling. Reported-by: Lorenzo Bianconi <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
2023-01-24tools: ynl: add a completely generic clientJakub Kicinski2-0/+581
Add a CLI sample which can take in arbitrary request in JSON format, convert it to Netlink and do the inverse for output. It's meant as a development tool primarily and perhaps for selftests which need to tickle netlink in a special way. Acked-by: Stanislav Fomichev <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
2023-01-24net: add basic C code generators for NetlinkJakub Kicinski2-0/+2403
Code generators to turn Netlink specs into C code. I'm definitely not proud of it. The main generator is in Python, there's a bash script to regen all code-gen'ed files in tree after making spec changes. Acked-by: Stanislav Fomichev <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
2017-10-04tools: rename tools/net directory to tools/bpfJakub Kicinski6-2656/+0
We currently only have BPF tools in the tools/net directory. We are about to add more BPF tools there, not necessarily networking related, rename the directory and related Makefile targets to bpf. Suggested-by: Daniel Borkmann <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]> Reviewed-by: Simon Horman <[email protected]> Acked-by: Daniel Borkmann <[email protected]> Acked-by: Alexei Starovoitov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
2017-06-14tools: bpf_jit_disasm: Handle large images.David Daney1-11/+26
Dynamically allocate memory so that JIT images larger than the size of the statically allocated array can be handled. Signed-off-by: David Daney <[email protected]> Acked-by: Daniel Borkmann <[email protected]> Signed-off-by: David S. Miller <[email protected]>
2017-04-13tools: bpf_jit_disasm: Add option to dump JIT image to a file.David Daney1-4/+36
When debugging the JIT on an embedded platform or cross build environment, libbfd may not be available, making it impossible to run bpf_jit_disasm natively. Add an option to emit a binary image of the JIT code to a file. This file can then be disassembled off line. Typical usage in this case might be (pasting mips64 dmesg output to cat command): $ cat > jit.raw $ bpf_jit_disasm -f jit.raw -O jit.bin $ mips64-linux-gnu-objdump -D -b binary -m mips:isa64r2 -EB jit.bin Signed-off-by: David Daney <[email protected]> Acked-by: Daniel Borkmann <[email protected]> Signed-off-by: David S. Miller <[email protected]>
2016-05-08tools: bpf_jit_disasm: check for klogctl failureColin Ian King1-0/+3
klogctl can fail and return -ve len, so check for this and return NULL to avoid passing a (size_t)-1 to malloc. Signed-off-by: Colin Ian King <[email protected]> Acked-by: Daniel Borkmann <[email protected]> Signed-off-by: David S. Miller <[email protected]>