All of lore.kernel.org
 help / color / mirror / Atom feed
From: Florian Fainelli <f.fainelli@gmail.com>
To: Jakub Kicinski <kuba@kernel.org>,
	netdev@vger.kernel.org, davem@davemloft.net, edumazet@google.com,
	pabeni@redhat.com
Cc: sdf@google.com, jacob.e.keller@intel.com, vadfed@fb.com,
	johannes@sipsolutions.net, jiri@resnulli.us, dsahern@kernel.org,
	stephen@networkplumber.org, fw@strlen.de,
	linux-doc@vger.kernel.org
Subject: Re: [RFC net-next 0/4] ynl: YAML netlink protocol descriptions
Date: Fri, 12 Aug 2022 10:00:52 -0700	[thread overview]
Message-ID: <9208fec1-60e9-dd2b-af27-ada3dfa50121@gmail.com> (raw)
In-Reply-To: <20220811022304.583300-1-kuba@kernel.org>

On 8/10/22 19:23, Jakub Kicinski wrote:
> Netlink seems simple and reasonable to those who understand it.
> It appears cumbersome and arcane to those who don't.
> 
> This RFC introduces machine readable netlink protocol descriptions
> in YAML, in an attempt to make creation of truly generic netlink
> libraries a possibility. Truly generic netlink library here means
> a library which does not require changes to support a new family
> or a new operation.
> 
> Each YAML spec lists attributes and operations the family supports.
> The specs are fully standalone, meaning that there is no dependency
> on existing uAPI headers in C. Numeric values of all attribute types,
> operations, enums, and defines and listed in the spec (or unambiguous).
> This property removes the need to manually translate the headers for
> languages which are not compatible with C.
> 
> The expectation is that the spec can be used to either dynamically
> translate between whatever types the high level language likes (see
> the Python example below) or codegen a complete libarary / bindings
> for a netlink family at compilation time (like popular RPC libraries
> do).
> 
> Currently only genetlink is supported, but the "old netlink" should
> be supportable as well (I don't need it myself).
> 
> On the kernel side the YAML spec can be used to generate:
>   - the C uAPI header
>   - documentation of the protocol as a ReST file
>   - policy tables for input attribute validation
>   - operation tables
> 
> We can also codegen parsers and dump helpers, but right now the level
> of "creativity & cleverness" when it comes to netlink parsing is so
> high it's quite hard to generalize it for most families without major
> refactoring.
> 
> Being able to generate the header, documentation and policy tables
> should balance out the extra effort of writing the YAML spec.
> 
> Here is a Python example I promised earlier:
> 
>    ynl = YnlFamily("path/to/ethtool.yaml")
>    channels = ynl.channels_get({'header': {'dev_name': 'eni1np1'}})
> 
> If the call was successful "channels" will hold a standard Python dict,
> e.g.:
> 
>    {'header': {'dev_index': 6, 'dev_name': 'eni1np1'},
>     'combined_max': 1,
>     'combined_count': 1}
> 
> for a netdevsim device with a single combined queue.
> 
> YnlFamily is an implementation of a YAML <> netlink translator (patch 3).
> It takes a path to the YAML spec - hopefully one day we will make
> the YAMLs themselves uAPI and distribute them like we distribute
> C headers. Or get them distributed to a standard search path another
> way. Until then, the YNL library needs a full path to the YAML spec and
> application has to worry about the distribution of those.
> 
> The YnlFamily reads all the info it needs from the spec, resolves
> the genetlink family id, and creates methods based on the spec.
> channels_get is such a dynamically-generated method (i.e. grep for
> channels_get in the python code shows nothing). The method can be called
> passing a standard Python dict as an argument. YNL will look up each key
> in the YAML spec and render the appropriate binary (netlink TLV)
> representation of the value. It then talks thru a netlink socket
> to the kernel, and deserilizes the response, converting the netlink
> TLVs into Python types and constructing a dictionary.
> 
> Again, the YNL code is completely generic and has no knowledge specific
> to ethtool. It's fairly simple an incomplete (in terms of types
> for example), I wrote it this afternoon. I'm also pretty bad at Python,
> but it's the only language I can type which allows the method
> magic, so please don't judge :) I have a rather more complete codegen
> for C, with support for notifications, kernel -> user policy/type
> verification, resolving extack attr offsets into a path
> of attribute names etc, etc. But that stuff needs polishing and
> is less suitable for an RFC.
> 
> The ability for a high level language like Python to talk to the kernel
> so easily, without ctypes, manually packing structs, copy'n'pasting
> values for defines etc. excites me more than C codegen, anyway.

This is really cool BTW, and it makes a lot of sense to me that we are 
moving that way, especially with Rust knocking at the door. I will try 
to do a more thorough review, than "cool, I like it".
-- 
Florian

  parent reply	other threads:[~2022-08-12 17:01 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-11  2:23 [RFC net-next 0/4] ynl: YAML netlink protocol descriptions Jakub Kicinski
2022-08-11  2:23 ` [RFC net-next 1/4] ynl: add intro docs for the concept Jakub Kicinski
2022-08-11 20:17   ` Edward Cree
2022-08-12 22:23     ` Jakub Kicinski
2022-08-15 20:09   ` Johannes Berg
2022-08-16  0:32     ` Jakub Kicinski
2022-08-16  7:07       ` Johannes Berg
2022-08-11  2:23 ` [RFC net-next 2/4] ynl: add the schema for the schemas Jakub Kicinski
2022-08-15 20:03   ` Johannes Berg
2022-08-15 20:09   ` Johannes Berg
2022-08-16  0:47     ` Jakub Kicinski
2022-08-16  7:21       ` Johannes Berg
2022-08-16 15:53         ` Jakub Kicinski
2022-08-16 19:30           ` Johannes Berg
2022-09-26 16:10   ` Rob Herring
2022-09-27 21:56     ` Jakub Kicinski
2022-09-28 12:32       ` Rob Herring
2022-08-11  2:23 ` [RFC net-next 3/4] ynl: add a sample python library Jakub Kicinski
2022-08-11  5:48   ` Benjamin Poirier
2022-08-11 15:50     ` Jakub Kicinski
2022-08-11 20:09   ` Stephen Hemminger
2022-08-12 22:53     ` Jakub Kicinski
2022-08-15 20:00       ` Johannes Berg
2022-08-12  1:04   ` Stephen Hemminger
2022-08-12 15:42     ` Edward Cree
2022-08-12 23:07       ` Jakub Kicinski
2022-08-18 21:26         ` Keller, Jacob E
2022-08-11  2:23 ` [RFC net-next 4/4] ynl: add a sample user for ethtool Jakub Kicinski
2022-08-11 16:18   ` sdf
2022-08-11 19:35     ` Jakub Kicinski
2022-08-11 22:55       ` Stanislav Fomichev
2022-08-11 23:31         ` Jakub Kicinski
2022-08-12 16:26           ` Stanislav Fomichev
2022-08-12 22:48             ` Jakub Kicinski
2022-08-14 12:27   ` Ido Schimmel
2022-08-11  4:15 ` [RFC net-next 0/4] ynl: YAML netlink protocol descriptions Stephen Hemminger
2022-08-11  4:47   ` Jakub Kicinski
2022-08-11 15:01     ` Stephen Hemminger
2022-08-11 15:34       ` Jakub Kicinski
2022-08-11 16:28         ` sdf
2022-08-11 19:42           ` Jakub Kicinski
2022-08-12 17:00 ` Florian Fainelli [this message]
2022-08-12 22:26   ` Jakub Kicinski
2022-08-19 19:56 ` 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=9208fec1-60e9-dd2b-af27-ada3dfa50121@gmail.com \
    --to=f.fainelli@gmail.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=fw@strlen.de \
    --cc=jacob.e.keller@intel.com \
    --cc=jiri@resnulli.us \
    --cc=johannes@sipsolutions.net \
    --cc=kuba@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sdf@google.com \
    --cc=stephen@networkplumber.org \
    --cc=vadfed@fb.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.