All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stanislav Fomichev <sdf@google.com>
To: Jakub Kicinski <kuba@kernel.org>
Cc: davem@davemloft.net, netdev@vger.kernel.org, edumazet@google.com,
	 pabeni@redhat.com, simon.horman@corigine.com
Subject: Re: [PATCH net-next v2 2/4] tools: ynl: user space helpers
Date: Mon, 5 Jun 2023 10:50:19 -0700	[thread overview]
Message-ID: <ZH4gW5WIzMZe4oF5@google.com> (raw)
In-Reply-To: <20230604175843.662084-3-kuba@kernel.org>

On 06/04, Jakub Kicinski wrote:
> Add "fixed" part of the user space Netlink Spec-based library.
> This will get linked with the protocol implementations to form
> a full API.
> 
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> ---
> v2: fix up kdoc
> ---
>  .../userspace-api/netlink/intro-specs.rst     |  79 ++
>  tools/net/ynl/Makefile                        |  19 +
>  tools/net/ynl/generated/Makefile              |  45 +
>  tools/net/ynl/lib/Makefile                    |  28 +
>  tools/net/ynl/lib/ynl.c                       | 901 ++++++++++++++++++
>  tools/net/ynl/lib/ynl.h                       | 237 +++++
>  tools/net/ynl/ynl-regen.sh                    |   2 +-
>  7 files changed, 1310 insertions(+), 1 deletion(-)
>  create mode 100644 tools/net/ynl/Makefile
>  create mode 100644 tools/net/ynl/generated/Makefile
>  create mode 100644 tools/net/ynl/lib/Makefile
>  create mode 100644 tools/net/ynl/lib/ynl.c
>  create mode 100644 tools/net/ynl/lib/ynl.h
> 
> diff --git a/Documentation/userspace-api/netlink/intro-specs.rst b/Documentation/userspace-api/netlink/intro-specs.rst
> index a3b847eafff7..bada89699455 100644
> --- a/Documentation/userspace-api/netlink/intro-specs.rst
> +++ b/Documentation/userspace-api/netlink/intro-specs.rst
> @@ -78,3 +78,82 @@ 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.
> +
> +YNL lib
> +=======
> +
> +``tools/net/ynl/lib/`` contains an implementation of a C library
> +(based on libmnl) which integrates with code generated by
> +``tools/net/ynl/ynl-gen-c.py`` to create easy to use netlink wrappers.
> +
> +YNL basics
> +----------
> +
> +The YNL library consists of two parts - the generic code (functions
> +prefix by ``ynl_``) and per-family auto-generated code (prefixed
> +with the name of the family).
> +
> +To create a YNL socket call ynl_sock_create() passing the family
> +struct (family structs are exported by the auto-generated code).
> +ynl_sock_destroy() closes the socket.
> +
> +YNL requests
> +------------
> +
> +Steps for issuing YNL requests are best explained on an example.
> +All the functions and types in this example come from the auto-generated
> +code (for the netdev family in this case):
> +
> +.. code-block:: c
> +
> +   // 0. Request and response pointers
> +   struct netdev_dev_get_req *req;
> +   struct netdev_dev_get_rsp *d;
> +
> +   // 1. Allocate a request
> +   req = netdev_dev_get_req_alloc();
> +   // 2. Set request parameters (as needed)
> +   netdev_dev_get_req_set_ifindex(req, ifindex);
> +
> +   // 3. Issues the request
> +   d = netdev_dev_get(ys, req);
> +   // 4. Free the request arguments
> +   netdev_dev_get_req_free(req);
> +   // 5. Error check (the return value from step 3)
> +   if (!d) {
> +	// 6. Print the YNL-generated error
> +	fprintf(stderr, "YNL: %s\n", ys->err.msg);
> +        return -1;
> +   }
> +
> +   // ... do stuff with the response @d
> +
> +   // 7. Free response
> +   netdev_dev_get_rsp_free(d);

General API question: do we have to have all those alloc/free calls?
Why not have the following instead?

	struct netdev_dev_get_req req;
	struct netdev_dev_get_rsp rsp;
	
	netdev_dev_get_req_set_ifindex(&req, ifindex);
	netdev_dev_get(ys, &req, &rsp);

You seem to be doing malloc(*rsp) anyway in netdev_dev_get, so
why not push that choice (heap/stack) on the users?

(haven't looked too closely at the series, so maybe a stupid question)

  reply	other threads:[~2023-06-05 17:50 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-04 17:58 [PATCH net-next v2 0/4] tools: ynl: user space C Jakub Kicinski
2023-06-04 17:58 ` [PATCH net-next v2 1/4] tools: ynl-gen: clean up stray new lines at the end of reply-less requests Jakub Kicinski
2023-06-04 17:58 ` [PATCH net-next v2 2/4] tools: ynl: user space helpers Jakub Kicinski
2023-06-05 17:50   ` Stanislav Fomichev [this message]
2023-06-05 18:49     ` Stanislav Fomichev
2023-06-04 17:58 ` [PATCH net-next v2 3/4] tools: ynl: support fou and netdev in C Jakub Kicinski
2023-06-04 17:58 ` [PATCH net-next v2 4/4] tools: ynl: add sample for netdev Jakub Kicinski
2023-06-05  9:31   ` Willem de Bruijn
2023-06-05 18:54     ` Jakub Kicinski
2023-06-05 20:27       ` Willem de Bruijn

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=ZH4gW5WIzMZe4oF5@google.com \
    --to=sdf@google.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=simon.horman@corigine.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.