From: Lorenzo Colitti <lorenzo@google.com>
To: netdev@vger.kernel.org
Cc: stephen@networkplumber.org, eric.dumazet@gmail.com,
zenczykowski@gmail.com, Lorenzo Colitti <lorenzo@google.com>
Subject: [iproute PATCH v2 1/2] libnetlink: add a variant of rtnl_send_check that consumes ACKs
Date: Thu, 17 Dec 2015 22:22:17 +0900 [thread overview]
Message-ID: <1450358538-134898-1-git-send-email-lorenzo@google.com> (raw)
The new variant is identical to rtnl_send_check, except it also
consumes the kernel response instead of using MSG_PEEK. This is
useful for callers that send simple commands that never cause a
response but only ACKs, and that expect to receive and deal
with errors without printing them to stderr like rtnl_talk does.
Signed-off-by: Lorenzo Colitti <lorenzo@google.com>
---
include/libnetlink.h | 2 ++
lib/libnetlink.c | 14 +++++++++++---
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/include/libnetlink.h b/include/libnetlink.h
index 431189e..a88cb4d 100644
--- a/include/libnetlink.h
+++ b/include/libnetlink.h
@@ -75,6 +75,8 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n,
__attribute__((warn_unused_result));
int rtnl_send(struct rtnl_handle *rth, const void *buf, int)
__attribute__((warn_unused_result));
+int rtnl_send_check_ack(struct rtnl_handle *rth, const void *buf, int, int)
+ __attribute__((warn_unused_result));
int rtnl_send_check(struct rtnl_handle *rth, const void *buf, int)
__attribute__((warn_unused_result));
diff --git a/lib/libnetlink.c b/lib/libnetlink.c
index 1658214..a3ad83a 100644
--- a/lib/libnetlink.c
+++ b/lib/libnetlink.c
@@ -134,18 +134,21 @@ int rtnl_send(struct rtnl_handle *rth, const void *buf, int len)
return send(rth->fd, buf, len, 0);
}
-int rtnl_send_check(struct rtnl_handle *rth, const void *buf, int len)
+int rtnl_send_check_ack(struct rtnl_handle *rth, const void *buf, int len,
+ int ack)
{
struct nlmsghdr *h;
- int status;
+ int status, flags;
char resp[1024];
status = send(rth->fd, buf, len, 0);
if (status < 0)
return status;
+ flags = MSG_DONTWAIT | (ack ? 0 : MSG_PEEK);
+
/* Check for immediate errors */
- status = recv(rth->fd, resp, sizeof(resp), MSG_DONTWAIT|MSG_PEEK);
+ status = recv(rth->fd, resp, sizeof(resp), flags);
if (status < 0) {
if (errno == EAGAIN)
return 0;
@@ -167,6 +170,11 @@ int rtnl_send_check(struct rtnl_handle *rth, const void *buf, int len)
return 0;
}
+inline int rtnl_send_check(struct rtnl_handle *rth, const void *buf, int len)
+{
+ return rtnl_send_check_ack(rth, buf, len, 0);
+}
+
int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int len)
{
struct nlmsghdr nlh;
--
2.6.0.rc2.230.g3dd15c0
next reply other threads:[~2015-12-17 13:22 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-17 13:22 Lorenzo Colitti [this message]
2015-12-17 13:22 ` [iproute PATCH v2 2/2] ss: support closing inet sockets via SOCK_DESTROY Lorenzo Colitti
2015-12-17 15:29 ` Eric Dumazet
2015-12-22 5:42 ` Stephen Hemminger
2015-12-22 8:31 ` Lorenzo Colitti
2015-12-22 8:31 ` [iproute PATCH v3 1/2] libnetlink: add a variant of rtnl_send_check that consumes ACKs Lorenzo Colitti
2015-12-23 21:17 ` Stephen Hemminger
2015-12-22 8:31 ` [iproute PATCH v3 2/2] ss: support closing inet sockets via SOCK_DESTROY Lorenzo Colitti
2015-12-30 20:34 ` Stephen Hemminger
2016-01-04 1:54 ` Lorenzo Colitti
2016-01-08 8:32 ` Lorenzo Colitti
2016-01-08 8:32 ` [iproute PATCH v4 1/2] libnetlink: don't print NETLINK_SOCK_DIAG errors in rtnl_talk Lorenzo Colitti
2016-01-08 8:32 ` [iproute PATCH v4 2/2] ss: support closing inet sockets via SOCK_DESTROY Lorenzo Colitti
2016-01-18 19:48 ` Stephen Hemminger
2015-12-22 8:35 ` [iproute PATCH v2 " Lorenzo Colitti
2015-12-17 16:07 ` [iproute PATCH v2 1/2] libnetlink: add a variant of rtnl_send_check that consumes ACKs Eric Dumazet
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=1450358538-134898-1-git-send-email-lorenzo@google.com \
--to=lorenzo@google.com \
--cc=eric.dumazet@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.org \
--cc=zenczykowski@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).