From: Stephen Hemminger <stephen@networkplumber.org>
To: Hangbin Liu <haliu@redhat.com>
Cc: netdev@vger.kernel.org, Michal Kubecek <mkubecek@suse.cz>,
Phil Sutter <phil@nwl.cc>, Hangbin Liu <liuhangbin@gmail.com>
Subject: Re: [PATCHv4 iproute2 1/2] lib/libnetlink: re malloc buff if size is not enough
Date: Fri, 29 Sep 2017 10:54:40 -0700 [thread overview]
Message-ID: <20170929105440.7edaec1f@xeon-e3> (raw)
In-Reply-To: <1506605626-1744-2-git-send-email-haliu@redhat.com>
On Thu, 28 Sep 2017 21:33:45 +0800
Hangbin Liu <haliu@redhat.com> wrote:
>
> +static int __rtnl_recvmsg(int fd, struct msghdr *msg, int flags)
> +{
> + int len;
> +
> + do {
> + len = recvmsg(fd, msg, flags);
> + } while (len < 0 && (errno == EINTR || errno == EAGAIN));
> +
> + if (len < 0) {
> + fprintf(stderr, "netlink receive error %s (%d)\n",
> + strerror(errno), errno);
> + return -errno;
> + }
> +
> + if (len == 0) {
> + fprintf(stderr, "EOF on netlink\n");
> + return -ENODATA;
> + }
> +
> + return len;
> +}
> +
> +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;
> + }
> +
> + if (answer)
> + *answer = buf;
> + else
> + free(buf);
> +
> + return len;
> +}
Doubling the number of system calls per message is not going to make
users with 5,000,000 routes or 1000 vlans, or 10,000 tunnels happy.
Please rethink this.
next prev parent reply other threads:[~2017-09-29 17:54 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-28 13:33 [PATCHv4 iproute2 0/2] libnetlink: malloc correct buff at run time Hangbin Liu
2017-09-28 13:33 ` [PATCHv4 iproute2 1/2] lib/libnetlink: re malloc buff if size is not enough Hangbin Liu
2017-09-29 12:55 ` Michal Kubecek
2017-09-29 17:54 ` Stephen Hemminger [this message]
2017-09-29 18:20 ` Michal Kubecek
2017-09-30 13:54 ` Hangbin Liu
2017-09-28 13:33 ` [PATCHv4 iproute2 2/2] lib/libnetlink: update rtnl_talk to support malloc buff at run time Hangbin Liu
2017-09-29 13:06 ` Michal Kubecek
2017-10-02 17:37 ` Stephen Hemminger
2017-10-09 20:25 ` Phil Sutter
2017-10-10 6:41 ` Michal Kubecek
2017-10-10 16:47 ` Stephen Hemminger
2017-10-11 10:40 ` Hangbin Liu
2017-10-11 11:10 ` Phil Sutter
2017-10-11 14:35 ` David Ahern
2017-10-12 16:07 ` Stephen Hemminger
2017-10-13 10:31 ` Phil Sutter
2017-10-25 10:45 ` Stephen Hemminger
2017-10-25 13:16 ` 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=20170929105440.7edaec1f@xeon-e3 \
--to=stephen@networkplumber.org \
--cc=haliu@redhat.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).