diff --git a/include/libnetlink.h b/include/libnetlink.h index e9a63dbca259..d6322190afaa 100644 --- a/include/libnetlink.h +++ b/include/libnetlink.h @@ -96,9 +96,6 @@ int rtnl_dump_filter_nc(struct rtnl_handle *rth, int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, struct nlmsghdr **answer) __attribute__((warn_unused_result)); -int rtnl_talk_msg(struct rtnl_handle *rtnl, struct msghdr *m, - struct nlmsghdr **answer) - __attribute__((warn_unused_result)); int rtnl_talk_iov(struct rtnl_handle *rtnl, struct iovec *iovec, size_t iovlen, struct nlmsghdr **answer) __attribute__((warn_unused_result)); diff --git a/lib/libnetlink.c b/lib/libnetlink.c index 183825c7fe0e..cb1990fcbf1c 100644 --- a/lib/libnetlink.c +++ b/lib/libnetlink.c @@ -581,38 +581,40 @@ static void rtnl_talk_error(struct nlmsghdr *h, struct nlmsgerr *err, strerror(-err->error)); } -static int __rtnl_talk_msg(struct rtnl_handle *rtnl, struct msghdr *m, - struct nlmsghdr **answer, + +static int __rtnl_talk_iov(struct rtnl_handle *rtnl, struct iovec *iov, + size_t iovlen, struct nlmsghdr **answer, bool show_rtnl_err, nl_ext_ack_fn_t errfn) { struct sockaddr_nl nladdr = { .nl_family = AF_NETLINK }; - int i, status, iovlen = m->msg_iovlen; - struct iovec iov; + int i, status; + struct iovec riov; struct msghdr msg = { .msg_name = &nladdr, .msg_namelen = sizeof(nladdr), - .msg_iov = &iov, - .msg_iovlen = 1, + .msg_iov = iov, + .msg_iovlen = iovlen, }; unsigned int seq = 0; struct nlmsghdr *h; char *buf; for (i = 0; i < iovlen; i++) { - struct iovec *v; - v = &m->msg_iov[i]; - h = v->iov_base; + h = iov[i].iov_base; h->nlmsg_seq = seq = ++rtnl->seq; if (answer == NULL) h->nlmsg_flags |= NLM_F_ACK; } - status = sendmsg(rtnl->fd, m, 0); + status = sendmsg(rtnl->fd, &msg, 0); if (status < 0) { perror("Cannot talk to rtnetlink"); return -1; } + /* change msg to use the response iov */ + msg.msg_iov = &riov; + msg.msg_iovlen = 1; i = 0; while (1) { next: @@ -705,21 +707,6 @@ static int __rtnl_talk_msg(struct rtnl_handle *rtnl, struct msghdr *m, } } -static int __rtnl_talk_iov(struct rtnl_handle *rtnl, struct iovec *msg_iov, - size_t iovlen, struct nlmsghdr **answer, - bool show_rtnl_err, nl_ext_ack_fn_t errfn) -{ - struct sockaddr_nl nladdr = { .nl_family = AF_NETLINK }; - struct msghdr msg = { - .msg_name = &nladdr, - .msg_namelen = sizeof(nladdr), - .msg_iov = msg_iov, - .msg_iovlen = iovlen, - }; - - return __rtnl_talk_msg(rtnl, &msg, answer, show_rtnl_err, errfn); -} - static int __rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, struct nlmsghdr **answer, bool show_rtnl_err, nl_ext_ack_fn_t errfn) @@ -738,12 +725,6 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, return __rtnl_talk(rtnl, n, answer, true, NULL); } -int rtnl_talk_msg(struct rtnl_handle *rtnl, struct msghdr *m, - struct nlmsghdr **answer) -{ - return __rtnl_talk_msg(rtnl, m, answer, true, NULL); -} - int rtnl_talk_iov(struct rtnl_handle *rtnl, struct iovec *iovec, size_t iovlen, struct nlmsghdr **answer) {