diff mbox

[lnf-ct,1/2] add two new bitmask functions

Message ID 20140910084853.GB23549@gmail.com
State Accepted
Delegated to: Florian Westphal
Headers show

Commit Message

Ken-ichirou MATSUZAWA Sept. 10, 2014, 8:48 a.m. UTC
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(+)

Comments

Florian Westphal Sept. 10, 2014, 8:53 a.m. UTC | #1
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!
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Florian Westphal Sept. 11, 2014, 7:38 p.m. UTC | #2
Ken-ichirou MATSUZAWA <chamaken@gmail.com> wrote:
> This patch adds two functions, useful for ulogd IPFIX
> output module.

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

Patch

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;
+}
+
 /**
  * @}
  */