From mboxrd@z Thu Jan 1 00:00:00 1970 From: Chris Mi Subject: Re: [patch iproute2 v3 1/4] lib/libnetlink: Add a function rtnl_talk_msg Date: Tue, 2 Jan 2018 21:59:38 +0800 Message-ID: <740db82a-b64d-6d6e-33ae-4dec88eb985c@mellanox.com> References: <20171225084658.24076-1-chrism@mellanox.com> <20171225084658.24076-2-chrism@mellanox.com> <75c29c60-2886-6ffe-f9c7-8bc67862adc6@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Cc: gerlitz.or@gmail.com, stephen@networkplumber.org To: David Ahern , netdev@vger.kernel.org Return-path: Received: from mail-ve1eur01on0072.outbound.protection.outlook.com ([104.47.1.72]:28622 "EHLO EUR01-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752423AbeABOAO (ORCPT ); Tue, 2 Jan 2018 09:00:14 -0500 In-Reply-To: <75c29c60-2886-6ffe-f9c7-8bc67862adc6@gmail.com> 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. Thanks for your suggestion. Done. > >> + 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. Actually, I divide the variables in two parts, none-struct variables and struct variables. Not sure if that meets the reverse xmac tree style, but I think it is more readable. > >> 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);