From: Nelio Laranjeiro <nelio.laranjeiro@6wind.com>
To: Pascal Mazon <pascal.mazon@6wind.com>
Cc: dev@dpdk.org
Subject: [dpdk-dev] [PATCH 2/2] lib: add request Netlink messages
Date: Tue, 13 Mar 2018 13:28:27 +0100 [thread overview]
Message-ID: <9a637b4ddc33ff2cc7f5311f9a69643dc5abdc13.1520943890.git.nelio.laranjeiro@6wind.com> (raw)
In-Reply-To: <cover.1520943890.git.nelio.laranjeiro@6wind.com>
In-Reply-To: <cover.1520943890.git.nelio.laranjeiro@6wind.com>
rte_nl_send() generate a message without request. In some situation, the
drivers needs to retrieve information from the Kernel before requesting
modifications.
Cc: Pascal Mazon <pascal.mazon@6wind.com>
Signed-off-by: Nelio Laranjeiro <nelio.laranjeiro@6wind.com>
---
lib/librte_netlink/rte_netlink.c | 45 ++++++++++++++++++++++++++++++
lib/librte_netlink/rte_netlink.h | 1 +
lib/librte_netlink/rte_netlink_version.map | 1 +
3 files changed, 47 insertions(+)
diff --git a/lib/librte_netlink/rte_netlink.c b/lib/librte_netlink/rte_netlink.c
index a4ed07d30..a2020f6f8 100644
--- a/lib/librte_netlink/rte_netlink.c
+++ b/lib/librte_netlink/rte_netlink.c
@@ -125,6 +125,51 @@ rte_nl_send(int nlsk_fd, struct nlmsghdr *nh)
}
/**
+ * Send a request message to the kernel on the netlink socket.
+ *
+ * @param[in] nlsk_fd
+ * The netlink socket file descriptor used for communication.
+ * @param[in] nh
+ * The netlink message send to the kernel.
+ * @param[in] req
+ * Pointer to the request structure.
+ * @param[in] len
+ * Length of the request in bytes.
+ *
+ * @return
+ * the number of sent bytes on success, -1 otherwise.
+ */
+int
+rte_nl_request(int nlsk_fd, struct nlmsghdr *nh, void *req, int len)
+{
+ /* man 7 netlink EXAMPLE */
+ struct sockaddr_nl sa = {
+ .nl_family = AF_NETLINK,
+ };
+ struct iovec iov[2] = {
+ { .iov_base = nh, .iov_len = sizeof(*nh), },
+ { .iov_base = req, .iov_len = len, },
+ };
+ struct msghdr msg = {
+ .msg_name = &sa,
+ .msg_namelen = sizeof(sa),
+ .msg_iov = iov,
+ .msg_iovlen = 2,
+ };
+ 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);
+ if (send_bytes < 0) {
+ RTE_LOG(ERR, PMD, "Failed to send netlink message: %s (%d)\n",
+ strerror(errno), errno);
+ return -1;
+ }
+ return send_bytes;
+}
+
+/**
* Check that the kernel sends an appropriate ACK in response
* to an rte_nl_send().
*
diff --git a/lib/librte_netlink/rte_netlink.h b/lib/librte_netlink/rte_netlink.h
index 29f7d64c5..9af03e738 100644
--- a/lib/librte_netlink/rte_netlink.h
+++ b/lib/librte_netlink/rte_netlink.h
@@ -28,6 +28,7 @@ struct nlmsg {
int rte_nl_init(uint32_t nl_groups);
int rte_nl_final(int nlsk_fd);
int rte_nl_send(int nlsk_fd, struct nlmsghdr *nh);
+int rte_nl_request(int nlsk_fd, struct nlmsghdr *nh, void *req, int len);
int rte_nl_recv(int nlsk_fd, int (*callback)(struct nlmsghdr *, void *),
void *arg);
int rte_nl_recv_ack(int nlsk_fd);
diff --git a/lib/librte_netlink/rte_netlink_version.map b/lib/librte_netlink/rte_netlink_version.map
index 5aa9b6228..a52254b36 100644
--- a/lib/librte_netlink/rte_netlink_version.map
+++ b/lib/librte_netlink/rte_netlink_version.map
@@ -4,6 +4,7 @@ DPDK_18.05 {
rte_nl_init;
rte_nl_final;
rte_nl_send;
+ rte_nl_request;
rte_nl_recv;
rte_nl_recv_ack;
rte_nlattr_add;
--
2.11.0
next prev parent reply other threads:[~2018-03-13 12:29 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-13 12:28 [dpdk-dev] [PATCH 0/2] lib: move Netlink wrapper to lib Nelio Laranjeiro
2018-03-13 12:28 ` [dpdk-dev] [PATCH 1/2] lib: move Netlink code into a common library Nelio Laranjeiro
2018-03-13 13:58 ` Bruce Richardson
2018-03-13 14:58 ` Nélio Laranjeiro
2018-03-13 12:28 ` Nelio Laranjeiro [this message]
2018-03-13 21:20 ` [dpdk-dev] [PATCH 0/2] lib: move Netlink wrapper to lib Stephen Hemminger
2018-03-14 12:08 ` Nélio Laranjeiro
2018-03-14 15:17 ` Stephen Hemminger
2018-03-15 15:39 ` Thomas Monjalon
2018-03-15 16:19 ` Nélio Laranjeiro
2018-03-15 16:26 ` Stephen Hemminger
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=9a637b4ddc33ff2cc7f5311f9a69643dc5abdc13.1520943890.git.nelio.laranjeiro@6wind.com \
--to=nelio.laranjeiro@6wind.com \
--cc=dev@dpdk.org \
--cc=pascal.mazon@6wind.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).