From 6d81801d842d984dac2325893e9f430885893959 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Fri, 24 Apr 2020 16:36:56 -0700 Subject: [PATCH] net/tap: simplify netlink send/receive functions The tap_nl_recv() function does not need to use the full complex recvmsg() system call, basic recv() will work here. Ditto for tap_nl_send() full sendmsg is not needed. Add logic to retry in case EINTR rather than forcing error handling back in driver or worse to ethdev API. Signed-off-by: Stephen Hemminger Acked-by: Keith Wiles --- drivers/net/tap/tap_netlink.c | 45 +++++++++++------------------------ 1 file changed, 14 insertions(+), 31 deletions(-) diff --git a/drivers/net/tap/tap_netlink.c b/drivers/net/tap/tap_netlink.c index 14bbbec754..64220178a6 100644 --- a/drivers/net/tap/tap_netlink.c +++ b/drivers/net/tap/tap_netlink.c @@ -101,26 +101,17 @@ tap_nl_final(int nlsk_fd) int tap_nl_send(int nlsk_fd, struct nlmsghdr *nh) { - /* man 7 netlink EXAMPLE */ - struct sockaddr_nl sa = { - .nl_family = AF_NETLINK, - }; - struct iovec iov = { - .iov_base = nh, - .iov_len = nh->nlmsg_len, - }; - struct msghdr msg = { - .msg_name = &sa, - .msg_namelen = sizeof(sa), - .msg_iov = &iov, - .msg_iovlen = 1, - }; int send_bytes; nh->nlmsg_pid = 0; /* communication with the kernel uses pid 0 */ nh->nlmsg_seq = (uint32_t)rte_rand(); - send_bytes = sendmsg(nlsk_fd, &msg, 0); + +retry: + send_bytes = send(nlsk_fd, nh, nh->nlmsg_len, 0); if (send_bytes < 0) { + if (errno == EINTR) + goto retry; + TAP_LOG(ERR, "Failed to send netlink message: %s (%d)", strerror(errno), errno); return -1; @@ -161,30 +152,22 @@ tap_nl_recv_ack(int nlsk_fd) int tap_nl_recv(int nlsk_fd, int (*cb)(struct nlmsghdr *, void *arg), void *arg) { - /* man 7 netlink EXAMPLE */ - struct sockaddr_nl sa; char buf[BUF_SIZE]; - struct iovec iov = { - .iov_base = buf, - .iov_len = sizeof(buf), - }; - struct msghdr msg = { - .msg_name = &sa, - .msg_namelen = sizeof(sa), - .msg_iov = &iov, - /* One message at a time */ - .msg_iovlen = 1, - }; int multipart = 0; int ret = 0; do { struct nlmsghdr *nh; - int recv_bytes = 0; + int recv_bytes; - recv_bytes = recvmsg(nlsk_fd, &msg, 0); - if (recv_bytes < 0) +retry: + recv_bytes = recv(nlsk_fd, buf, sizeof(buf), 0); + if (recv_bytes < 0) { + if (errno == EINTR) + goto retry; return -1; + } + for (nh = (struct nlmsghdr *)buf; NLMSG_OK(nh, (unsigned int)recv_bytes); nh = NLMSG_NEXT(nh, recv_bytes)) { -- 2.20.1