netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: David Miller <davem@davemloft.net>
Cc: netdev@vger.kernel.org
Subject: Re: [PATCH] genetlink: fix usage of NLM_F_EXCL or NLM_F_REPLACE
Date: Wed, 31 Jul 2013 13:12:15 +0200	[thread overview]
Message-ID: <20130731111215.GA6062@localhost> (raw)
In-Reply-To: <20130730.164423.1103943978365554977.davem@davemloft.net>

Hi David!

On Tue, Jul 30, 2013 at 04:44:23PM -0700, David Miller wrote:
> From: Pablo Neira Ayuso <pablo@netfilter.org>
> Date: Mon, 29 Jul 2013 12:30:04 +0200
> 
> > Currently, it is not possible to use neither NLM_F_EXCL nor
> > NLM_F_REPLACE from genetlink. This is due to this checking in
> > genl_family_rcv_msg:
> > 
> > 	if (nlh->nlmsg_flags & NLM_F_DUMP)
> > 
> > NLM_F_DUMP is NLM_F_MATCH|NLM_F_ROOT. Thus, if NLM_F_EXCL or
> > NLM_F_REPLACE flag is set, genetlink believes that you're
> > requesting a dump and it calls the .dumpit callback.
> > 
> > The solution that I propose is to refine this checking to
> > make it stricter:
> > 
> > 	if ((nlh->nlmsg_flags & NLM_F_DUMP) == NLM_F_DUMP)
> > 
> > And given the combination NLM_F_REPLACE and NLM_F_EXCL does
> > not make sense to me, it removes the ambiguity.
> > 
> > There was a patch that tried to fix this some time ago (0ab03c2
> > netlink: test for all flags of the NLM_F_DUMP composite) but it
> > tried to resolve this ambiguity in *all* existing netlink subsystems,
> > not only genetlink. That patch was reverted since it broke iproute2,
> > which is using NLM_F_ROOT to request the dump of the routing cache.
> > 
> > Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
> 
> Yes, I remember that old attempt to fix this.
> 
> Ok, let's see what happens when we limit the scope of this change
> to just genetlink users.
>
> I honestly can't believe that NLM_F_EXCL and NLM_F_REPLACE are
> completely unusable in normal rtnetlink interfaces.

I guess you mean 'genetlink' instead of 'rtnetlink'.

This repo provides one genetlink example kernel module and userspace
utility using libmnl:

git clone git://1984.lsi.us.es/netlink-example

make
make userspace
insmod genlexample.ko

This registers 'nlex', an example genetlink family that allows you to
update the value of a variable in kernel-space.

To use it, we have to resolve the genetlink family-id first (sorry,
these examples are a bit rudimentary):

./genl-resolve nlex
family-id: 24
multicast -> id
"example" -> 7

OK, so it's family-id 24, let's update that variable in kernel-space
without NLM_F_EXCL:

./genl-change 24        # uses time(NULL) to update that variable
done

./genl-get 24
myvar=1375268456
done

Now if we try to make it with NLM_F_EXCL:

./genl-change 24 excl
mnl_cb_run: Operation not supported

My examples have no .dumpit callback. thus, genetlink was
misiterpreting this and it returned EOPNOTSUPP.

So nobody using genetlink could use these two flags so far.

  reply	other threads:[~2013-07-31 11:12 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-29 10:30 [PATCH] genetlink: fix usage of NLM_F_EXCL or NLM_F_REPLACE Pablo Neira Ayuso
2013-07-30 23:44 ` David Miller
2013-07-31 11:12   ` Pablo Neira Ayuso [this message]
2013-08-01  0:03     ` David Miller
2013-08-01  0:37       ` Pablo Neira Ayuso
2013-08-01  2:00         ` Pablo Neira Ayuso
2013-08-01  2:12           ` David Miller
2013-11-12 22:12           ` David Miller

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=20130731111215.GA6062@localhost \
    --to=pablo@netfilter.org \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).