From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Ahern Subject: Re: [patch iproute2 v3 1/4] lib/libnetlink: Add a function rtnl_talk_msg Date: Wed, 27 Dec 2017 08:33:22 -0600 Message-ID: <75c29c60-2886-6ffe-f9c7-8bc67862adc6@gmail.com> References: <20171225084658.24076-1-chrism@mellanox.com> <20171225084658.24076-2-chrism@mellanox.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Cc: gerlitz.or@gmail.com, stephen@networkplumber.org To: Chris Mi , netdev@vger.kernel.org Return-path: Received: from mail-pf0-f193.google.com ([209.85.192.193]:43622 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751002AbdL0Od0 (ORCPT ); Wed, 27 Dec 2017 09:33:26 -0500 Received: by mail-pf0-f193.google.com with SMTP id e3so19840864pfi.10 for ; Wed, 27 Dec 2017 06:33:26 -0800 (PST) In-Reply-To: <20171225084658.24076-2-chrism@mellanox.com> Content-Language: en-US Sender: netdev-owner@vger.kernel.org List-ID: On 12/25/17 2:46 AM, Chris Mi wrote: > diff --git a/lib/libnetlink.c b/lib/libnetlink.c > index 00e6ce0c..f5f675cf 100644 > --- a/lib/libnetlink.c > +++ b/lib/libnetlink.c > @@ -581,36 +581,21 @@ 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_check_ack(struct rtnl_handle *rtnl, struct nlmsghdr **answer, Make this function __rtnl_talk_msg. Include the assignment of nlmsg_seq and ack setting using the for loop below and sendmsg() call. All of that code can be common for both the single and multiple iov case. > + bool show_rtnl_err, nl_ext_ack_fn_t errfn, > + unsigned int seq) > { > int status; > - unsigned int seq; > - struct nlmsghdr *h; > + char *buf; Please order variables in the reverse xmas tree style used in the net code. > struct sockaddr_nl nladdr = { .nl_family = AF_NETLINK }; > - struct iovec iov = { > - .iov_base = n, > - .iov_len = n->nlmsg_len > - }; > + struct nlmsghdr *h; > + 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; > - > - if (answer == NULL) > - n->nlmsg_flags |= NLM_F_ACK; > - > - status = sendmsg(rtnl->fd, &msg, 0); > - if (status < 0) { > - perror("Cannot talk to rtnetlink"); > - return -1; > - } > > while (1) { > status = rtnl_recvmsg(rtnl->fd, &msg, &buf);