Patchwork [libnetfilter_conntrack] conntrack: introduce clear and equal functions for bitmask object

login
register
mail settings
Submitter Ken-ichirou MATSUZAWA
Date March 8, 2014, 1:24 a.m.
Message ID <20140308012416.GJ4415@gmail.com>
Download mbox | patch
Permalink /patch/328142/
State Deferred
Delegated to: Eric Leblond
Headers show

Comments

Ken-ichirou MATSUZAWA - March 8, 2014, 1:24 a.m.
This patch adds two functions, useful for ulogd IPFIX
output module.

---
 .../libnetfilter_conntrack.h                       |  2 ++
 src/conntrack/api.c                                | 31 ++++++++++++++++++++++
 2 files changed, 33 insertions(+)
Florian Westphal - March 8, 2014, 9:25 a.m.
Ken-ichirou MATSUZAWA <chamaken@gmail.com> wrote:
>  This patch adds two functions, useful for ulogd IPFIX
> output module.

I am ok with this patch.  Once the ulogd patches have been
reviewed/accepted this can be applied to libnf-ct.

Will need lib versioning bump before next release of library.
--
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

Patch

diff --git a/include/libnetfilter_conntrack/libnetfilter_conntrack.h b/include/libnetfilter_conntrack/libnetfilter_conntrack.h
index d4542ba..a5e6a91 100644
--- a/include/libnetfilter_conntrack/libnetfilter_conntrack.h
+++ b/include/libnetfilter_conntrack/libnetfilter_conntrack.h
@@ -286,6 +286,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 *);
+int 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 224be86..fc4c58f 100644
--- a/src/conntrack/api.c
+++ b/src/conntrack/api.c
@@ -1704,6 +1704,37 @@  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 1, otherwise
+ * -1 or 0 is returned.
+ */
+int nfct_bitmask_equal(const struct nfct_bitmask *b1, const struct nfct_bitmask *b2)
+{
+	if (b1->words != b2->words)
+		return -1;
+
+	if (!memcmp(b1->bits, b2->bits, b1->words * sizeof(b1->bits[0])))
+		return 1;
+	else
+		return 0;
+}
+
 /**
  * @}
  */