diff mbox series

[iproute2-next,2/4] utils: Introduce helper routines for generic socket recv

Message ID 20210301105654.291949-3-parav@nvidia.com (mailing list archive)
State Accepted
Commit e3a4067e525754c53f64af28c2409f47468b000d
Delegated to: David Ahern
Headers show
Series devlink: Use utils helpers | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Parav Pandit March 1, 2021, 10:56 a.m. UTC
Introduce helper for generic socket receive helper and introduce helper
to build command with custom family and version.

Use API in subsequent devlink patch.

Signed-off-by: Parav Pandit <parav@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
---
 include/mnl_utils.h |  6 ++++++
 lib/mnl_utils.c     | 25 +++++++++++++++++++++----
 2 files changed, 27 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/include/mnl_utils.h b/include/mnl_utils.h
index 9e7d6879..aa5f0a9b 100644
--- a/include/mnl_utils.h
+++ b/include/mnl_utils.h
@@ -13,6 +13,10 @@  struct mnlu_gen_socket {
 int mnlu_gen_socket_open(struct mnlu_gen_socket *nlg, const char *family_name,
 			 uint8_t version);
 void mnlu_gen_socket_close(struct mnlu_gen_socket *nlg);
+struct nlmsghdr *
+_mnlu_gen_socket_cmd_prepare(struct mnlu_gen_socket *nlg,
+			     uint8_t cmd, uint16_t flags,
+			     uint32_t id, uint8_t version);
 struct nlmsghdr *mnlu_gen_socket_cmd_prepare(struct mnlu_gen_socket *nlg,
 					     uint8_t cmd, uint16_t flags);
 int mnlu_gen_socket_sndrcv(struct mnlu_gen_socket *nlg, const struct nlmsghdr *nlh,
@@ -23,5 +27,7 @@  struct nlmsghdr *mnlu_msg_prepare(void *buf, uint32_t nlmsg_type, uint16_t flags
 				  void *extra_header, size_t extra_header_size);
 int mnlu_socket_recv_run(struct mnl_socket *nl, unsigned int seq, void *buf, size_t buf_size,
 			 mnl_cb_t cb, void *data);
+int mnlu_gen_socket_recv_run(struct mnlu_gen_socket *nlg, mnl_cb_t cb,
+			     void *data);
 
 #endif /* __MNL_UTILS_H__ */
diff --git a/lib/mnl_utils.c b/lib/mnl_utils.c
index 4f699455..d5abff58 100644
--- a/lib/mnl_utils.c
+++ b/lib/mnl_utils.c
@@ -196,19 +196,28 @@  void mnlu_gen_socket_close(struct mnlu_gen_socket *nlg)
 	free(nlg->buf);
 }
 
-struct nlmsghdr *mnlu_gen_socket_cmd_prepare(struct mnlu_gen_socket *nlg,
-					     uint8_t cmd, uint16_t flags)
+struct nlmsghdr *
+_mnlu_gen_socket_cmd_prepare(struct mnlu_gen_socket *nlg,
+			     uint8_t cmd, uint16_t flags,
+			     uint32_t id, uint8_t version)
 {
 	struct genlmsghdr hdr = {};
 	struct nlmsghdr *nlh;
 
 	hdr.cmd = cmd;
-	hdr.version = nlg->version;
-	nlh = mnlu_msg_prepare(nlg->buf, nlg->family, flags, &hdr, sizeof(hdr));
+	hdr.version = version;
+	nlh = mnlu_msg_prepare(nlg->buf, id, flags, &hdr, sizeof(hdr));
 	nlg->seq = nlh->nlmsg_seq;
 	return nlh;
 }
 
+struct nlmsghdr *mnlu_gen_socket_cmd_prepare(struct mnlu_gen_socket *nlg,
+					     uint8_t cmd, uint16_t flags)
+{
+	return _mnlu_gen_socket_cmd_prepare(nlg, cmd, flags, nlg->family,
+					    nlg->version);
+}
+
 int mnlu_gen_socket_sndrcv(struct mnlu_gen_socket *nlg, const struct nlmsghdr *nlh,
 			   mnl_cb_t data_cb, void *data)
 {
@@ -229,3 +238,11 @@  int mnlu_gen_socket_sndrcv(struct mnlu_gen_socket *nlg, const struct nlmsghdr *n
 	}
 	return 0;
 }
+
+int mnlu_gen_socket_recv_run(struct mnlu_gen_socket *nlg, mnl_cb_t cb,
+			     void *data)
+{
+	return mnlu_socket_recv_run(nlg->nl, nlg->seq, nlg->buf,
+				    MNL_SOCKET_BUFFER_SIZE,
+				    cb, data);
+}