All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH lnf-ct 0/2] add new bitmask functions
@ 2014-09-10  8:45 Ken-ichirou MATSUZAWA
  2014-09-10  8:48 ` [PATCH lnf-ct 1/2] add two " Ken-ichirou MATSUZAWA
  2014-09-10  8:53 ` [PATCH lnf-ct 2/2] qa: add tests for " Ken-ichirou MATSUZAWA
  0 siblings, 2 replies; 6+ messages in thread
From: Ken-ichirou MATSUZAWA @ 2014-09-10  8:45 UTC (permalink / raw)
  To: Florian Westphal; +Cc: netfilter-devel

 Hello,

I've changed nfct_bitmask_equal() from previous to use bool,
as you adviced. Would you revew again?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH lnf-ct 1/2] add two new bitmask functions
  2014-09-10  8:45 [PATCH lnf-ct 0/2] add new bitmask functions Ken-ichirou MATSUZAWA
@ 2014-09-10  8:48 ` Ken-ichirou MATSUZAWA
  2014-09-10  8:53   ` Florian Westphal
  2014-09-11 19:38   ` Florian Westphal
  2014-09-10  8:53 ` [PATCH lnf-ct 2/2] qa: add tests for " Ken-ichirou MATSUZAWA
  1 sibling, 2 replies; 6+ messages in thread
From: Ken-ichirou MATSUZAWA @ 2014-09-10  8:48 UTC (permalink / raw)
  To: Florian Westphal; +Cc: netfilter-devel

This patch adds two functions, useful for ulogd IPFIX
output module.

Signed-off-by: Ken-ichirou MATSUZAWA <chamas@h4.dion.ne.jp>
---
 .../libnetfilter_conntrack.h                       |  3 +++
 src/conntrack/api.c                                | 29 ++++++++++++++++++++++
 2 files changed, 32 insertions(+)

diff --git a/include/libnetfilter_conntrack/libnetfilter_conntrack.h b/include/libnetfilter_conntrack/libnetfilter_conntrack.h
index d4542ba..d04a0c6 100644
--- a/include/libnetfilter_conntrack/libnetfilter_conntrack.h
+++ b/include/libnetfilter_conntrack/libnetfilter_conntrack.h
@@ -10,6 +10,7 @@
 #ifndef _LIBNETFILTER_CONNTRACK_H_
 #define _LIBNETFILTER_CONNTRACK_H_
 
+#include <stdbool.h>
 #include <netinet/in.h>
 #include <libnfnetlink/linux_nfnetlink.h>
 #include <libnfnetlink/libnfnetlink.h>
@@ -286,6 +287,8 @@ void nfct_bitmask_set_bit(struct nfct_bitmask *, unsigned int bit);
 int nfct_bitmask_test_bit(const struct nfct_bitmask *, unsigned int bit);
 void nfct_bitmask_unset_bit(struct nfct_bitmask *, unsigned int bit);
 void nfct_bitmask_destroy(struct nfct_bitmask *);
+void nfct_bitmask_clear(struct nfct_bitmask *);
+bool nfct_bitmask_equal(const struct nfct_bitmask *, const struct nfct_bitmask *);
 
 /* connlabel name <-> bit translation mapping */
 struct nfct_labelmap;
diff --git a/src/conntrack/api.c b/src/conntrack/api.c
index 09270ee..073ea5c 100644
--- a/src/conntrack/api.c
+++ b/src/conntrack/api.c
@@ -8,6 +8,7 @@
  */
 
 #include <stdlib.h>
+#include <stdbool.h>
 #include <string.h> /* for memset */
 #include <errno.h>
 #include <assert.h>
@@ -1702,6 +1703,34 @@ void nfct_bitmask_destroy(struct nfct_bitmask *b)
 	free(b);
 }
 
+/*
+ * nfct_bitmask_clear - clear a bitmask object
+ *
+ * \param b pointer to the bitmask object to clear
+ */
+void nfct_bitmask_clear(struct nfct_bitmask *b)
+{
+	unsigned int bytes = b->words * sizeof(b->bits[0]);
+	memset(b->bits, 0, bytes);
+}
+
+/*
+ * nfct_bitmask_equal - compare two bitmask objects
+ *
+ * \param b1 pointer to a valid bitmask object
+ * \param b2 pointer to a valid bitmask object
+ *
+ * If both bitmask object are equal, this function returns true, otherwise
+ * false is returned.
+ */
+bool nfct_bitmask_equal(const struct nfct_bitmask *b1, const struct nfct_bitmask *b2)
+{
+	if (b1->words != b2->words)
+		return false;
+
+	return memcmp(b1->bits, b2->bits, b1->words * sizeof(b1->bits[0])) == 0;
+}
+
 /**
  * @}
  */
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH lnf-ct 1/2] add two new bitmask functions
  2014-09-10  8:48 ` [PATCH lnf-ct 1/2] add two " Ken-ichirou MATSUZAWA
@ 2014-09-10  8:53   ` Florian Westphal
  2014-09-11 19:38   ` Florian Westphal
  1 sibling, 0 replies; 6+ messages in thread
From: Florian Westphal @ 2014-09-10  8:53 UTC (permalink / raw)
  To: Ken-ichirou MATSUZAWA; +Cc: Florian Westphal, netfilter-devel

Ken-ichirou MATSUZAWA <chamaken@gmail.com> wrote:
> This patch adds two functions, useful for ulogd IPFIX
> output module.

Looks great, if there are no other comments I'll apply this soon.

Thanks!

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH lnf-ct 2/2] qa: add tests for new bitmask functions
  2014-09-10  8:45 [PATCH lnf-ct 0/2] add new bitmask functions Ken-ichirou MATSUZAWA
  2014-09-10  8:48 ` [PATCH lnf-ct 1/2] add two " Ken-ichirou MATSUZAWA
@ 2014-09-10  8:53 ` Ken-ichirou MATSUZAWA
  2014-09-11 19:39   ` Florian Westphal
  1 sibling, 1 reply; 6+ messages in thread
From: Ken-ichirou MATSUZAWA @ 2014-09-10  8:53 UTC (permalink / raw)
  To: Florian Westphal; +Cc: netfilter-devel

for nfct_bitmask_clear() and nfct_bitmask_equal()

Signed-off-by: Ken-ichirou MATSUZAWA <chamas@h4.dion.ne.jp>
---
 qa/test_api.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/qa/test_api.c b/qa/test_api.c
index f17db31..fe1cb78 100644
--- a/qa/test_api.c
+++ b/qa/test_api.c
@@ -80,6 +80,43 @@ static void test_nfct_bitmask(void)
 		assert(!nfct_bitmask_test_bit(b, i));
 	}
 
+	/* nfct_bitmask_clear() */
+	for (i = 0; i < maxb; i++) {
+		nfct_bitmask_set_bit(b, i);
+		assert(nfct_bitmask_test_bit(b, i));
+		nfct_bitmask_clear(b);
+		assert(!nfct_bitmask_test_bit(b, i));
+	}
+
+	for (i = 0; i < maxb; i++)
+		nfct_bitmask_set_bit(b, i);
+	nfct_bitmask_clear(b);
+	for (i = 0; i < maxb; i++)
+		assert(!nfct_bitmask_test_bit(b, i));
+
+	/* nfct_bitmask_equal() */
+	for (i = 0; i < maxb / 32 * 32; i += 32) {
+		a = nfct_bitmask_new(i);
+		assert(!nfct_bitmask_equal(a, b));
+		nfct_bitmask_destroy(a);
+	}
+
+	a = nfct_bitmask_clone(b);
+	assert(nfct_bitmask_equal(a, b));
+	for (i = 0; i < maxb; i++) {
+		if (nfct_bitmask_test_bit(a, i)) {
+			nfct_bitmask_unset_bit(a, i);
+			assert(!nfct_bitmask_equal(a, b));
+			nfct_bitmask_set_bit(a, i);
+		} else {
+			nfct_bitmask_set_bit(a, i);
+			assert(!nfct_bitmask_equal(a, b));
+			nfct_bitmask_unset_bit(a, i);
+		}
+		assert(nfct_bitmask_equal(a, b));
+	}
+
+	nfct_bitmask_destroy(a);
 	nfct_bitmask_destroy(b);
 
 	ct1 = nfct_new();
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH lnf-ct 1/2] add two new bitmask functions
  2014-09-10  8:48 ` [PATCH lnf-ct 1/2] add two " Ken-ichirou MATSUZAWA
  2014-09-10  8:53   ` Florian Westphal
@ 2014-09-11 19:38   ` Florian Westphal
  1 sibling, 0 replies; 6+ messages in thread
From: Florian Westphal @ 2014-09-11 19:38 UTC (permalink / raw)
  To: Ken-ichirou MATSUZAWA; +Cc: Florian Westphal, netfilter-devel

Ken-ichirou MATSUZAWA <chamaken@gmail.com> wrote:
> This patch adds two functions, useful for ulogd IPFIX
> output module.

Applied, thanks!

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH lnf-ct 2/2] qa: add tests for new bitmask functions
  2014-09-10  8:53 ` [PATCH lnf-ct 2/2] qa: add tests for " Ken-ichirou MATSUZAWA
@ 2014-09-11 19:39   ` Florian Westphal
  0 siblings, 0 replies; 6+ messages in thread
From: Florian Westphal @ 2014-09-11 19:39 UTC (permalink / raw)
  To: Ken-ichirou MATSUZAWA; +Cc: Florian Westphal, netfilter-devel

Ken-ichirou MATSUZAWA <chamaken@gmail.com> wrote:
> for nfct_bitmask_clear() and nfct_bitmask_equal()

Also applied, thank you.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-09-11 19:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-10  8:45 [PATCH lnf-ct 0/2] add new bitmask functions Ken-ichirou MATSUZAWA
2014-09-10  8:48 ` [PATCH lnf-ct 1/2] add two " Ken-ichirou MATSUZAWA
2014-09-10  8:53   ` Florian Westphal
2014-09-11 19:38   ` Florian Westphal
2014-09-10  8:53 ` [PATCH lnf-ct 2/2] qa: add tests for " Ken-ichirou MATSUZAWA
2014-09-11 19:39   ` Florian Westphal

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.