From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 8D412A00C2; Sat, 25 Apr 2020 01:37:16 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 8681A1D405; Sat, 25 Apr 2020 01:37:11 +0200 (CEST) Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by dpdk.org (Postfix) with ESMTP id 5DD3C1D168 for ; Sat, 25 Apr 2020 01:37:08 +0200 (CEST) Received: by mail-pf1-f195.google.com with SMTP id x2so1857929pfx.7 for ; Fri, 24 Apr 2020 16:37:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EPViAVgKaw1TigZGhGqVlElJmnnnWmoaY8X1IwJYVOk=; b=VR2Q+kzZkLblS42G1r2sFD3Im391MtiQbhkLhowKuyyDYFT5qWq6uh7XAwK3aGVh2N O44yYIRQ/L/+Me7+nS+YeUbcROLX95j8tRLCpzPsB8NBfZw1IPDYCkeMU+Dbrd8rQ4h0 W7N3PkJa8kQDq0PgPJ9DC1ku/ft8B6C2o9dI6IAYWjy5h2st085EZhVMpHho50bU9vCc TNiIse902G/EutG8GA8M44v0g49VbHsEBv9Vou+wfvjoXUYghpXnAdqknCMzur7Z8ryE HRb4XlnLHrkRWNKmMnurB6MbBtfPQ/rsjYqIKNRU8y/D3qlDi3EnNl78O4JQgOAqogTe 6z7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EPViAVgKaw1TigZGhGqVlElJmnnnWmoaY8X1IwJYVOk=; b=f2oU8lDMXHV8ibRr4C+8XNkoyyXkiyTlSHv60LIBJWVg/tGwplYL69CHLmidPYR9FR 1TKHnPLuGBTVqSm0s03LIxvVAYvfH0p8FJe5GSxNfJ4U3e7wpX1Fx886UEwXJWdKjEio 5c0mT2dJTShEOcb7EJI2F8LJcxO6wlM0zCpYOwoTLhPwth4OtmpgktAZxhxI0RAX+rFz bis/VGgy3JH1jJwNn7/eC7NbfyfYzJ7/cleI89MXKr1CMVi8i79le1UCjd1JDtJMLIoF FO8GLJrE+CMXMLugCmiAnyH1PdCOgYD7O+drXJesjkDDqruETSOOw/o5XCKqJhALEI73 dzwA== X-Gm-Message-State: AGi0PuZAQuQRok9UHFMGnh0AC9s4TuLOac+t79U4nvRz4jJQGrIXnXfG Zti9TORXA2ORquLQVK/tYLWPsHvryhM= X-Google-Smtp-Source: APiQypJpRhLEz5h7aZezk3AXulV2pAoVnF0e2NocXeKdS1Tyw4l+cCmS5Wlmv+IC99mPL+EoOgVkSQ== X-Received: by 2002:a63:f64d:: with SMTP id u13mr11568691pgj.151.1587771426756; Fri, 24 Apr 2020 16:37:06 -0700 (PDT) Received: from hermes.corp.microsoft.com (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id b5sm6826823pfb.190.2020.04.24.16.37.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Apr 2020 16:37:05 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org, keith.wiles@intel.com Cc: Stephen Hemminger Date: Fri, 24 Apr 2020 16:36:56 -0700 Message-Id: <20200424233657.12267-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200424233657.12267-1-stephen@networkplumber.org> References: <20200424233657.12267-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH 1/2] net/tap: simplify netlink send/receive functions X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 --- 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 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)) { -- 2.20.1