[1/2] net/tap: simplify netlink send/receive functions

Message ID 20200424233657.12267-2-stephen@networkplumber.org (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series net/tap: simplfication and servicabilty improvements |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-nxp-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-testing fail Testing issues
ci/Intel-compilation fail Compilation issues

Commit Message

Stephen Hemminger April 24, 2020, 11:36 p.m. UTC
  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 <stephen@networkplumber.org>
---
 drivers/net/tap/tap_netlink.c | 45 +++++++++++------------------------
 1 file changed, 14 insertions(+), 31 deletions(-)
  

Patch

diff --git a/drivers/net/tap/tap_netlink.c b/drivers/net/tap/tap_netlink.c
index 14bbbec754f6..64220178a6ba 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)) {