From: Phil Sutter <phil@nwl.cc>
To: Chris Mi <chrism@mellanox.com>
Cc: netdev@vger.kernel.org, gerlitz.or@gmail.com,
stephen@networkplumber.org, dsahern@gmail.com,
marcelo.leitner@gmail.com
Subject: Re: [patch iproute2 v7 1/2] lib/libnetlink: Add functions rtnl_talk_msg and rtnl_talk_iov
Date: Tue, 9 Jan 2018 20:24:27 +0100 [thread overview]
Message-ID: <20180109192427.GH14358@orbyte.nwl.cc> (raw)
In-Reply-To: <20180109065908.19754-2-chrism@mellanox.com>
Hi,
On Tue, Jan 09, 2018 at 03:59:07PM +0900, Chris Mi wrote:
[...]
> diff --git a/lib/libnetlink.c b/lib/libnetlink.c
> index 00e6ce0c..ae0059f9 100644
> --- a/lib/libnetlink.c
> +++ b/lib/libnetlink.c
> @@ -581,39 +581,43 @@ static void rtnl_talk_error(struct nlmsghdr *h, struct nlmsgerr *err,
> strerror(-err->error));
> }
>
> -static int __rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n,
> - struct nlmsghdr **answer,
> - bool show_rtnl_err, nl_ext_ack_fn_t errfn)
> +static int __rtnl_talk_msg(struct rtnl_handle *rtnl, struct msghdr *m,
> + struct nlmsghdr **answer,
> + bool show_rtnl_err, nl_ext_ack_fn_t errfn)
> {
> - int status;
> - unsigned int seq;
> - struct nlmsghdr *h;
> struct sockaddr_nl nladdr = { .nl_family = AF_NETLINK };
> - struct iovec iov = {
> - .iov_base = n,
> - .iov_len = n->nlmsg_len
> - };
> + int i, status, iovlen = m->msg_iovlen;
> + struct iovec iov;
> struct msghdr msg = {
> .msg_name = &nladdr,
> .msg_namelen = sizeof(nladdr),
> .msg_iov = &iov,
> .msg_iovlen = 1,
> };
> - char *buf;
> -
> - n->nlmsg_seq = seq = ++rtnl->seq;
> + unsigned int seq = 0;
> + struct nlmsghdr *h;
>
> - if (answer == NULL)
> - n->nlmsg_flags |= NLM_F_ACK;
> + for (i = 0; i < iovlen; i++) {
> + struct iovec *v;
> + v = &m->msg_iov[i];
> + h = v->iov_base;
> + h->nlmsg_seq = seq = ++rtnl->seq;
> + if (answer == NULL)
> + h->nlmsg_flags |= NLM_F_ACK;
> + }
>
> - status = sendmsg(rtnl->fd, &msg, 0);
> + status = sendmsg(rtnl->fd, m, 0);
> if (status < 0) {
> perror("Cannot talk to rtnetlink");
> return -1;
> }
>
> + i = 0;
> while (1) {
for (i = 1; ; i++) ?
> + char *buf;
Why did you move this declaration?
> +next:
Drop this and use 'continue' instead of 'goto next' below?
> status = rtnl_recvmsg(rtnl->fd, &msg, &buf);
> + ++i;
>
> if (status < 0)
> return status;
> @@ -642,7 +646,7 @@ static int __rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n,
>
> if (nladdr.nl_pid != 0 ||
> h->nlmsg_pid != rtnl->local.nl_pid ||
> - h->nlmsg_seq != seq) {
> + h->nlmsg_seq > seq || h->nlmsg_seq < seq - iovlen) {
> /* Don't forget to skip that message. */
> status -= NLMSG_ALIGN(len);
> h = (struct nlmsghdr *)((char *)h + NLMSG_ALIGN(len));
> @@ -662,7 +666,10 @@ static int __rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n,
> *answer = (struct nlmsghdr *)buf;
> else
> free(buf);
> - return 0;
> + if (h->nlmsg_seq == seq)
> + return 0;
> + else
> + goto next;
> }
>
> if (rtnl->proto != NETLINK_SOCK_DIAG &&
Cheers, Phil
next prev parent reply other threads:[~2018-01-09 19:24 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-09 6:59 [patch iproute2 v7 0/2] tc: Add batchsize feature to batch mode Chris Mi
2018-01-09 6:59 ` [patch iproute2 v7 1/2] lib/libnetlink: Add functions rtnl_talk_msg and rtnl_talk_iov Chris Mi
2018-01-09 19:24 ` Phil Sutter [this message]
2018-01-10 3:00 ` Chris Mi
2018-01-10 11:01 ` Phil Sutter
2018-01-09 6:59 ` [patch iproute2 v7 2/2] tc: Add batchsize feature for filter and actions Chris Mi
2018-01-09 16:01 ` Stephen Hemminger
2018-01-10 3:27 ` Chris Mi
2018-01-09 19:13 ` Marcelo Ricardo Leitner
2018-01-10 2:58 ` Chris Mi
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=20180109192427.GH14358@orbyte.nwl.cc \
--to=phil@nwl.cc \
--cc=chrism@mellanox.com \
--cc=dsahern@gmail.com \
--cc=gerlitz.or@gmail.com \
--cc=marcelo.leitner@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.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).