From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org, keith.wiles@intel.com
Cc: Stephen Hemminger <stephen@networkplumber.org>
Subject: [dpdk-dev] [PATCH 1/2] net/tap: simplify netlink send/receive functions
Date: Fri, 24 Apr 2020 16:36:56 -0700 [thread overview]
Message-ID: <20200424233657.12267-2-stephen@networkplumber.org> (raw)
In-Reply-To: <20200424233657.12267-1-stephen@networkplumber.org>
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(-)
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
next prev parent reply other threads:[~2020-04-24 23:37 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-24 23:36 [dpdk-dev] [PATCH 0/2] net/tap: simplfication and servicabilty improvements Stephen Hemminger
2020-04-24 23:36 ` Stephen Hemminger [this message]
2020-04-24 23:36 ` [dpdk-dev] [PATCH 2/2] net/tap: use netlink extended ack support Stephen Hemminger
2020-04-27 11:32 ` Andrzej Ostruszka [C]
2020-05-06 18:41 ` Ferruh Yigit
2020-05-06 20:19 ` Stephen Hemminger
2020-04-25 13:14 ` [dpdk-dev] [PATCH 0/2] net/tap: simplfication and servicabilty improvements Wiles, Keith
2020-05-06 18:41 ` Ferruh Yigit
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200424233657.12267-2-stephen@networkplumber.org \
--to=stephen@networkplumber.org \
--cc=dev@dpdk.org \
--cc=keith.wiles@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.