From: David Miller <davem@davemloft.net>
To: netdev@vger.kernel.org
Subject: netlink recvmsg() and MSG_TRUNC
Date: Tue, 06 Mar 2007 15:19:53 -0800 (PST) [thread overview]
Message-ID: <20070306.151953.112290310.davem@davemloft.net> (raw)
So if you don't give a large enough buffer to
recvmsg() for the netlink response a few things
happen:
1) MSG_TRUNC is set
2) The length returned and the amount of data copied is the
size given in the recvmsg() call
3) If enough other packets remain in the receive buffer,
nlk->cb is left at non-NULL for a partial dump. This
means that you can't just immediately resubmit the
original request else you'll get NLMSG_ERROR with error
set to -EBUSY. This is what netlink_dump_start() does
when it sees nlk->cb non-NULL.
Now, the user is basically stuck and there is no real
way to recover from this besides doing something like
openning up a new netlink socket and then doing the recvmsg()
with a larger buffer, wash rinse repeat.
I looked at how some of our standard userspace code handles
this and it's not pretty:
1) iproute2 basically just uses a 16K buffer, signals an error
when it sees MSG_TRUNC, and that's it, whoopee
2) Thomas's libnl believes that recvmsg() will return the
true length necessary to receive the whole message, he
signals on this to double the buffer size and try the
recvmsg() again. As mentioned recvmsg() never returns
a length larger than the given buffer size, so this code
never triggers, and if it did it would lose entries because
netlink_recvmsg() drops the SKB even when it signals
MSG_TRUNC.
The behavior of dropping the SKB matches what UDP does in
the case of MSG_TRUNC.
I guess one thing the user could do when it sees MSG_TRUNC
is keep calling recvmsg() until the receive queue is emptied
of packets, in order to get that pesky nlk->cb cleared to
NULL, then resubmit.
But that's rediculous and complicated.
Any ideas?
next reply other threads:[~2007-03-06 23:19 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-06 23:19 David Miller [this message]
2007-03-06 23:40 ` netlink recvmsg() and MSG_TRUNC James Morris
2007-03-06 23:49 ` Herbert Xu
2007-03-06 23:57 ` Stephen Hemminger
2007-03-07 0:04 ` Herbert Xu
2007-03-07 0:02 ` David Miller
2007-03-07 0:04 ` Herbert Xu
2007-03-07 0:05 ` David Miller
2007-03-07 0:07 ` Herbert Xu
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=20070306.151953.112290310.davem@davemloft.net \
--to=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).