All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hannes Frederic Sowa <hannes@stressinduktion.org>
To: Phil Sutter <phil@nwl.cc>, Stephen Hemminger <shemming@brocade.com>
Cc: netdev@vger.kernel.org
Subject: Re: [iproute PATCH RFC] libnetlink: introduce DECLARE_NLREQ
Date: Thu, 26 Nov 2015 14:56:30 +0100	[thread overview]
Message-ID: <87oaegx3sh.fsf@stressinduktion.org> (raw)
In-Reply-To: <1448544365-23153-1-git-send-email-phil@nwl.cc>

Phil Sutter <phil@nwl.cc> writes:

> This macro aims to simplify most netlink users' pattern to prepare a
> request, which is to create an unnamed struct and initialize it:
>
> | struct {
> |	struct nlmsghdr n;
> |	struct whatever foo;
> |	char buf[arbitrary number];
> | } req;
> |
> | memset(&req, 0, sizeof(req));
> | req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct whatever));
> | req.n.nlmsg_flags = NLM_F_REQUEST;
>
> Having this patch applied, the above can be replaced by a static
> initializer like so:
>
> | DECLARE_NLREQ(req, n, struct whatever foo, arbitrary number);
>
> There is an added benefit, as well: Due to explicit alignment, the
> requested tailroom is really as big as requested no matter what size
> struct whatever really is.
>
> Signed-off-by: Phil Sutter <phil@nwl.cc>
> ---
> This patch is RFC because I want to wait for peer review and upstream
> acceptance before sending in the big refactoring patch itself.
> ---
>  include/libnetlink.h | 11 +++++++++++
>  1 file changed, 11 insertions(+)
>
> diff --git a/include/libnetlink.h b/include/libnetlink.h
> index 2280c39c670a4..7e12a7b12b55d 100644
> --- a/include/libnetlink.h
> +++ b/include/libnetlink.h
> @@ -196,5 +196,16 @@ int rtnl_from_file(FILE *, rtnl_listen_filter_t handler,
>   * messages from dump file */
>  #define NLMSG_TSTAMP	15
>  
> +/* declare a netlink request with initial payload */
> +#define DECLARE_NLREQ(name, hdrname, payload, tailroom)                       \
> +	struct {                                                              \
> +		struct nlmsghdr hdrname;                                      \
> +		payload;                                                      \
> +		char __b[tailroom] __attribute__((aligned(NLMSG_ALIGNTO)));   \
> +	} name = { .hdrname = {                                               \
> +		.nlmsg_len = (unsigned long)&name.__b - (unsigned long)&name, \

offsetof(typeof(name), __b) ?

  reply	other threads:[~2015-11-26 13:56 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-26 13:26 [iproute PATCH RFC] libnetlink: introduce DECLARE_NLREQ Phil Sutter
2015-11-26 13:56 ` Hannes Frederic Sowa [this message]
2015-11-26 14:00   ` Phil Sutter
2015-11-29 20:07 ` Stephen Hemminger
2015-11-29 21:40   ` Phil Sutter
2015-11-30 15:47   ` Phil Sutter
2015-11-30 17:20     ` Stephen Hemminger

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=87oaegx3sh.fsf@stressinduktion.org \
    --to=hannes@stressinduktion.org \
    --cc=netdev@vger.kernel.org \
    --cc=phil@nwl.cc \
    --cc=shemming@brocade.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.