Re: [patch iproute2 v3 1/4] lib/libnetlink: Add a function rtnl_talk_msg
flat view
From: David Ahern <hidden>
Date: 2017-12-27 14:33:26
On 12/25/17 2:46 AM, Chris Mi wrote:
quoted hunk ↗ jump to hunk
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.
quoted hunk ↗ jump to hunk
+ 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.
quoted hunk ↗ jump to hunk
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);