From: Stephen Hemminger <stephen@networkplumber.org>
To: David Ahern <dsahern@gmail.com>
Cc: Hangbin Liu <liuhangbin@gmail.com>,
netdev@vger.kernel.org, Michal Kubecek <mkubecek@suse.cz>,
Phil Sutter <phil@nwl.cc>
Subject: Re: [PATCHv5 iproute2 net-next 2/2] lib/libnetlink: re malloc buff if size is not enough
Date: Thu, 26 Oct 2017 12:24:42 +0200 [thread overview]
Message-ID: <20171026122442.7e2ac2d0@shemminger-XPS-13-9360> (raw)
In-Reply-To: <10ef7665-b47a-881a-ab00-1e2c6c224d0b@gmail.com>
On Wed, 25 Oct 2017 20:59:01 -0600
David Ahern <dsahern@gmail.com> wrote:
> On 10/25/17 7:41 PM, Hangbin Liu wrote:
> > +static int rtnl_recvmsg(int fd, struct msghdr *msg, char **answer)
> > +{
> > + struct iovec *iov = msg->msg_iov;
> > + char *buf;
> > + int len;
> > +
> > + iov->iov_base = NULL;
> > + iov->iov_len = 0;
> > +
> > + len = __rtnl_recvmsg(fd, msg, MSG_PEEK | MSG_TRUNC);
> > + if (len < 0)
> > + return len;
> > +
> > + buf = malloc(len);
> > + if (!buf) {
> > + fprintf(stderr, "malloc error: not enough buffer\n");
> > + return -ENOMEM;
> > + }
> > +
> > + iov->iov_base = buf;
> > + iov->iov_len = len;
> > +
> > + len = __rtnl_recvmsg(fd, msg, 0);
> > + if (len < 0) {
> > + free(buf);
> > + return len;
> > + }
>
> The kernel needs a flag that says "give me the message of the buffer is
> large enough; if not just PEEK and tell me the length." That would avoid
> the double call in most cases.
Actually this has little impact because old code was doing implicit zero
of whole buffer, new code does not.
next prev parent reply other threads:[~2017-10-26 10:24 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-26 1:41 [PATCHv5 iproute2 net-next 0/2] libnetlink: malloc correct buff at run time Hangbin Liu
2017-10-26 1:41 ` [PATCHv5 iproute2 net-next 2/2] lib/libnetlink: re malloc buff if size is not enough Hangbin Liu
2017-10-26 2:59 ` David Ahern
2017-10-26 10:24 ` Stephen Hemminger [this message]
2017-10-26 15:28 ` David Ahern
2017-10-26 15:33 ` Phil Sutter
2017-10-26 15:42 ` David Ahern
2017-10-26 18:31 ` Phil Sutter
2019-02-12 23:32 ` Eric Dumazet
2019-02-12 23:43 ` Eric Dumazet
2017-10-26 1:41 ` [PATCHv5 iproute2 net-next 2/2] lib/libnetlink: update rtnl_talk to support malloc buff at run time Hangbin Liu
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=20171026122442.7e2ac2d0@shemminger-XPS-13-9360 \
--to=stephen@networkplumber.org \
--cc=dsahern@gmail.com \
--cc=liuhangbin@gmail.com \
--cc=mkubecek@suse.cz \
--cc=netdev@vger.kernel.org \
--cc=phil@nwl.cc \
/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).