From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH net-next 13/13] docs: netlink: add a starting guide for working with specs
Date: Fri, 27 Jan 2023 20:32:17 -0800 [thread overview]
Message-ID: <20230128043217.1572362-14-kuba@kernel.org> (raw)
In-Reply-To: <20230128043217.1572362-1-kuba@kernel.org>
We have a bit of documentation about the internals of Netlink
and the specs, but really the goal is for most people to not
worry about those. Add a practical guide for beginners who
want to poke at the specs.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
Documentation/userspace-api/netlink/index.rst | 1 +
.../userspace-api/netlink/intro-specs.rst | 80 +++++++++++++++++++
Documentation/userspace-api/netlink/specs.rst | 3 +
3 files changed, 84 insertions(+)
create mode 100644 Documentation/userspace-api/netlink/intro-specs.rst
diff --git a/Documentation/userspace-api/netlink/index.rst b/Documentation/userspace-api/netlink/index.rst
index be250110c8f6..26f3720cb3be 100644
--- a/Documentation/userspace-api/netlink/index.rst
+++ b/Documentation/userspace-api/netlink/index.rst
@@ -10,6 +10,7 @@ Netlink documentation for users.
:maxdepth: 2
intro
+ intro-specs
specs
c-code-gen
genetlink-legacy
diff --git a/Documentation/userspace-api/netlink/intro-specs.rst b/Documentation/userspace-api/netlink/intro-specs.rst
new file mode 100644
index 000000000000..a3b847eafff7
--- /dev/null
+++ b/Documentation/userspace-api/netlink/intro-specs.rst
@@ -0,0 +1,80 @@
+.. SPDX-License-Identifier: BSD-3-Clause
+
+=====================================
+Using Netlink protocol specifications
+=====================================
+
+This document is a quick starting guide for using Netlink protocol
+specifications. For more detailed description of the specs see :doc:`specs`.
+
+Simple CLI
+==========
+
+Kernel comes with a simple CLI tool which should be useful when
+developing Netlink related code. The tool is implemented in Python
+and can use a YAML specification to issue Netlink requests
+to the kernel. Only Generic Netlink is supported.
+
+The tool is located at ``tools/net/ynl/cli.py``. It accepts
+a handul of arguments, the most important ones are:
+
+ - ``--spec`` - point to the spec file
+ - ``--do $name`` / ``--dump $name`` - issue request ``$name``
+ - ``--json $attrs`` - provide attributes for the request
+ - ``--subscribe $group`` - receive notifications from ``$group``
+
+YAML specs can be found under ``Documentation/netlink/specs/``.
+
+Example use::
+
+ $ ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/ethtool.yaml \
+ --do rings-get \
+ --json '{"header":{"dev-index": 18}}'
+ {'header': {'dev-index': 18, 'dev-name': 'eni1np1'},
+ 'rx': 0,
+ 'rx-jumbo': 0,
+ 'rx-jumbo-max': 4096,
+ 'rx-max': 4096,
+ 'rx-mini': 0,
+ 'rx-mini-max': 4096,
+ 'tx': 0,
+ 'tx-max': 4096,
+ 'tx-push': 0}
+
+The input arguments are parsed as JSON, while the output is only
+Python-pretty-printed. This is because some Netlink types can't
+be expressed as JSON directly. If such attributes are needed in
+the input some hacking of the script will be necessary.
+
+The spec and Netlink internals are factored out as a standalone
+library - it should be easy to write Python tools / tests reusing
+code from ``cli.py``.
+
+Generating kernel code
+======================
+
+``tools/net/ynl/ynl-regen.sh`` scans the kernel tree in search of
+auto-generated files which need to be updated. Using this tool is the easiest
+way to generate / update auto-generated code.
+
+By default code is re-generated only if spec is newer than the source,
+to force regeneration use ``-f``.
+
+``ynl-regen.sh`` searches for ``YNL-GEN`` in the contents of files
+(note that it only scans files in the git index, that is only files
+tracked by git!) For instance the ``fou_nl.c`` kernel source contains::
+
+ /* Documentation/netlink/specs/fou.yaml */
+ /* YNL-GEN kernel source */
+
+``ynl-regen.sh`` will find this marker and replace the file with
+kernel source based on fou.yaml.
+
+The simplest way to generate a new file based on a spec is to add
+the two marker lines like above to a file, add that file to git,
+and run the regeneration tool. Grep the tree for ``YNL-GEN``
+to see other examples.
+
+The code generation itself is performed by ``tools/net/ynl/ynl-gen-c.py``
+but it takes a few arguments so calling it directly for each file
+quickly becomes tedious.
diff --git a/Documentation/userspace-api/netlink/specs.rst b/Documentation/userspace-api/netlink/specs.rst
index 8394d74fc63a..6ffe8137cd90 100644
--- a/Documentation/userspace-api/netlink/specs.rst
+++ b/Documentation/userspace-api/netlink/specs.rst
@@ -21,6 +21,9 @@ kernel headers directly.
YAML specifications can be found under ``Documentation/netlink/specs/``
+This document describes details of the schema.
+See :doc:`intro-specs` for a practical starting guide.
+
Compatibility levels
====================
--
2.39.1
next prev parent reply other threads:[~2023-01-28 4:33 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-28 4:32 [PATCH net-next 00/13] tools: ynl: more docs and basic ethtool support Jakub Kicinski
2023-01-28 4:32 ` [PATCH net-next 01/13] tools: ynl-gen: prevent do / dump reordering Jakub Kicinski
2023-01-28 4:32 ` [PATCH net-next 02/13] tools: ynl: move the cli and netlink code around Jakub Kicinski
2023-01-28 4:32 ` [PATCH net-next 03/13] tools: ynl: add an object hierarchy to represent parsed spec Jakub Kicinski
2023-01-28 4:32 ` [PATCH net-next 04/13] tools: ynl: use the common YAML loading and validation code Jakub Kicinski
2023-01-28 4:32 ` [PATCH net-next 05/13] tools: ynl: add support for types needed by ethtool Jakub Kicinski
2023-01-28 4:32 ` [PATCH net-next 06/13] tools: ynl: support directional enum-model in CLI Jakub Kicinski
2023-01-28 4:32 ` [PATCH net-next 07/13] tools: ynl: support multi-attr Jakub Kicinski
2023-01-28 4:32 ` [PATCH net-next 08/13] tools: ynl: support pretty printing bad attribute names Jakub Kicinski
2023-01-28 4:32 ` [PATCH net-next 09/13] tools: ynl: use operation names from spec on the CLI Jakub Kicinski
2023-01-28 4:32 ` [PATCH net-next 10/13] tools: ynl: load jsonschema on demand Jakub Kicinski
2023-01-28 4:32 ` [PATCH net-next 11/13] netlink: specs: finish up operation enum-models Jakub Kicinski
2023-01-30 19:32 ` Stanislav Fomichev
2023-01-28 4:32 ` [PATCH net-next 12/13] netlink: specs: add partial specification for ethtool Jakub Kicinski
2023-01-28 4:32 ` Jakub Kicinski [this message]
2023-01-30 19:36 ` [PATCH net-next 00/13] tools: ynl: more docs and basic ethtool support Stanislav Fomichev
2023-01-30 19:51 ` Jakub Kicinski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230128043217.1572362-14-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.