Patchwork [libmnl,8/9] batch: introduce mnl_nlmsg_batch_reset_buffer for mmap

login
register
mail settings
Submitter Ken-ichirou MATSUZAWA
Date Dec. 7, 2013, 3:16 p.m.
Message ID <87iov08ze9.wl%chamaken@gmail.com>
Download mbox | patch
Permalink /patch/298695/
State Superseded
Headers show

Comments

Ken-ichirou MATSUZAWA - Dec. 7, 2013, 3:16 p.m.
Signed-off-by: Ken-ichirou MATSUZAWA <chamas@h4.dion.ne.jp>

---
 include/libmnl/libmnl.h |  1 +
 src/libmnl.map          |  1 +
 src/nlmsg.c             | 20 ++++++++++++++++++++
 3 files changed, 22 insertions(+)

Patch

diff --git a/include/libmnl/libmnl.h b/include/libmnl/libmnl.h
index 722cb79..603abc5 100644
--- a/include/libmnl/libmnl.h
+++ b/include/libmnl/libmnl.h
@@ -74,6 +74,7 @@  extern void mnl_nlmsg_batch_reset(struct mnl_nlmsg_batch *b);
 extern void *mnl_nlmsg_batch_head(struct mnl_nlmsg_batch *b);
 extern void *mnl_nlmsg_batch_current(struct mnl_nlmsg_batch *b);
 extern bool mnl_nlmsg_batch_is_empty(struct mnl_nlmsg_batch *b);
+extern void mnl_nlmsg_batch_reset_buffer(struct mnl_nlmsg_batch *b, void *buf, size_t limit);
 
 /*
  * Netlink attributes API
diff --git a/src/libmnl.map b/src/libmnl.map
index d329988..4de63b5 100644
--- a/src/libmnl.map
+++ b/src/libmnl.map
@@ -85,4 +85,5 @@  LIBMNL_1.2 {
   mnl_ring_build_frame;
   mnl_ring_parse_frame2;
   mnl_ring_parse_frame;
+  mnl_nlmsg_batch_reset_buffer;
 } LIBMNL_1.1;
diff --git a/src/nlmsg.c b/src/nlmsg.c
index fdb7af8..0210067 100644
--- a/src/nlmsg.c
+++ b/src/nlmsg.c
@@ -569,5 +569,25 @@  bool mnl_nlmsg_batch_is_empty(struct mnl_nlmsg_batch *b)
 EXPORT_SYMBOL(mnl_nlmsg_batch_is_empty);
 
 /**
+ * mnl_nlmsg_batch_reset_buffer - reset to the new buffer
+ */
+void mnl_nlmsg_batch_reset_buffer(struct mnl_nlmsg_batch *b, void *buf, size_t limit)
+{
+	if (b->overflow) {
+		struct nlmsghdr *nlh = b->cur;
+		memcpy(buf, b->cur, nlh->nlmsg_len);
+		b->buflen = nlh->nlmsg_len;
+		b->cur = buf + b->buflen;
+		b->overflow = false;
+	} else {
+		b->buflen = 0;
+		b->cur = buf;
+	}
+	b->buf = buf;
+	b->limit = limit;
+}
+EXPORT_SYMBOL(mnl_nlmsg_batch_reset_buffer);
+
+/**
  * @}
  */