* [PATCH libmnl] nlmsg: introduce mnl_nlmsg_batch_rest to get the rest length
@ 2017-04-03 6:11 Ken-ichirou MATSUZAWA
2017-04-13 22:27 ` Pablo Neira Ayuso
0 siblings, 1 reply; 3+ messages in thread
From: Ken-ichirou MATSUZAWA @ 2017-04-03 6:11 UTC (permalink / raw)
To: The netfilter developer mailinglist
Recent languages implements array to hold its length. This patch
enables to help to wrap these. As of this C library, we can use
this like below without double sized buffer.
char buf[MNL_SOCKET_BUFFER_SIZE];
b = mnl_nlmsg_batch_start(buf, sizeof(buf));
nlbuf = mnl_nlmsg_batch_current(b);
rest = mnl_nlmsg_batch_rest(b);
if (rest < NLMSG_HDRLEN)
return false;
nlh = mnl_nlmsg_put_header(nlbuf);
...
if (!mnl_attr_put_u8_check(nlh, rest, 1, 2))
return false;
...
Signed-off-by: Ken-ichirou MATSUZAWA <chamas@h4.dion.ne.jp>
---
include/libmnl/libmnl.h | 1 +
src/libmnl.map | 4 ++++
src/nlmsg.c | 12 ++++++++++++
3 files changed, 17 insertions(+)
diff --git a/include/libmnl/libmnl.h b/include/libmnl/libmnl.h
index 0331da7..8cfe137 100644
--- a/include/libmnl/libmnl.h
+++ b/include/libmnl/libmnl.h
@@ -76,6 +76,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 size_t mnl_nlmsg_batch_rest(const struct mnl_nlmsg_batch *b);
/*
* Netlink attributes API
diff --git a/src/libmnl.map b/src/libmnl.map
index e5920e5..97b31d7 100644
--- a/src/libmnl.map
+++ b/src/libmnl.map
@@ -77,3 +77,7 @@ LIBMNL_1.2 {
mnl_socket_open2;
mnl_socket_fdopen;
} LIBMNL_1.1;
+
+LIBMNL_1.3 {
+ mnl_nlmsg_batch_rest;
+} LIBMNL_1.2;
diff --git a/src/nlmsg.c b/src/nlmsg.c
index f9448a5..614e434 100644
--- a/src/nlmsg.c
+++ b/src/nlmsg.c
@@ -562,5 +562,17 @@ bool mnl_nlmsg_batch_is_empty(struct mnl_nlmsg_batch *b)
}
/**
+ * mnl_nlmsg_batch_rest - get the rest of the batch buffer size
+ * \param b pointer to batch
+ *
+ * This function returns the rest of the batch buffer size
+ */
+EXPORT_SYMBOL(mnl_nlmsg_batch_rest);
+size_t mnl_nlmsg_batch_rest(const struct mnl_nlmsg_batch *b)
+{
+ return b->limit - b->buflen;
+}
+
+/**
* @}
*/
--
2.11.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH libmnl] nlmsg: introduce mnl_nlmsg_batch_rest to get the rest length
2017-04-03 6:11 [PATCH libmnl] nlmsg: introduce mnl_nlmsg_batch_rest to get the rest length Ken-ichirou MATSUZAWA
@ 2017-04-13 22:27 ` Pablo Neira Ayuso
2017-04-20 3:32 ` Ken-ichirou MATSUZAWA
0 siblings, 1 reply; 3+ messages in thread
From: Pablo Neira Ayuso @ 2017-04-13 22:27 UTC (permalink / raw)
To: Ken-ichirou MATSUZAWA; +Cc: The netfilter developer mailinglist
On Mon, Apr 03, 2017 at 03:11:27PM +0900, Ken-ichirou MATSUZAWA wrote:
> Recent languages implements array to hold its length. This patch
> enables to help to wrap these. As of this C library, we can use
> this like below without double sized buffer.
>
> char buf[MNL_SOCKET_BUFFER_SIZE];
>
> b = mnl_nlmsg_batch_start(buf, sizeof(buf));
> nlbuf = mnl_nlmsg_batch_current(b);
> rest = mnl_nlmsg_batch_rest(b);
> if (rest < NLMSG_HDRLEN)
> return false;
Only for this usecase above?
> nlh = mnl_nlmsg_put_header(nlbuf);
Probably we need mnl_nlmsg_put_header_check()?
> ...
> if (!mnl_attr_put_u8_check(nlh, rest, 1, 2))
> return false;
> ...
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH libmnl] nlmsg: introduce mnl_nlmsg_batch_rest to get the rest length
2017-04-13 22:27 ` Pablo Neira Ayuso
@ 2017-04-20 3:32 ` Ken-ichirou MATSUZAWA
0 siblings, 0 replies; 3+ messages in thread
From: Ken-ichirou MATSUZAWA @ 2017-04-20 3:32 UTC (permalink / raw)
To: Pablo Neira Ayuso; +Cc: The netfilter developer mailinglist
On Fri, Apr 14, 2017 at 12:27:00AM +0200, Pablo Neira Ayuso wrote:
> On Mon, Apr 03, 2017 at 03:11:27PM +0900, Ken-ichirou MATSUZAWA wrote:
> > enables to help to wrap these. As of this C library, we can use
> > this like below without double sized buffer.
> >
> > char buf[MNL_SOCKET_BUFFER_SIZE];
> >
> > b = mnl_nlmsg_batch_start(buf, sizeof(buf));
> > nlbuf = mnl_nlmsg_batch_current(b);
> > rest = mnl_nlmsg_batch_rest(b);
> > if (rest < NLMSG_HDRLEN)
> > return false;
>
> Only for this usecase above?
So far, yes. Is it worthless to apply?
> > nlh = mnl_nlmsg_put_header(nlbuf);
>
> Probably we need mnl_nlmsg_put_header_check()?
And I guess mnl_nlmsg_put_extra_header_check will also be needed.
I am going to resend if you intend to apply those.
Thanks,
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-04-20 3:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-03 6:11 [PATCH libmnl] nlmsg: introduce mnl_nlmsg_batch_rest to get the rest length Ken-ichirou MATSUZAWA
2017-04-13 22:27 ` Pablo Neira Ayuso
2017-04-20 3:32 ` Ken-ichirou MATSUZAWA
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.