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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Ken-ichirou MATSUZAWA <chamas@xxxxxxxxxxxxx>

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

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);
+
+/**
  * @}
  */
-- 
1.8.4.rc3

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Netfitler Users]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux