summaryrefslogtreecommitdiffstats
path: root/src/conntrack/api.c
diff options
context:
space:
mode:
author/C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org </C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org>2007-04-24 18:39:51 +0000
committer/C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org </C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org>2007-04-24 18:39:51 +0000
commit7736631fef63efde9c0fd68af89c3e2900286428 (patch)
tree62d74d3733dc9e06bc608f70944278c6d9d13137 /src/conntrack/api.c
parent888062dd7196528a54753155c71572725597aa25 (diff)
- fix compilation warning in snprintf.c
- introduce the new compare infrastructure: much simple than previous - introduce nfct_maxsize for nf_conntrack object allocated in the stack - more strict checkings in nfct_set_attr: third parameter is const
Diffstat (limited to 'src/conntrack/api.c')
-rw-r--r--src/conntrack/api.c44
1 files changed, 42 insertions, 2 deletions
diff --git a/src/conntrack/api.c b/src/conntrack/api.c
index 19aca5e..9f14188 100644
--- a/src/conntrack/api.c
+++ b/src/conntrack/api.c
@@ -43,7 +43,7 @@ void nfct_destroy(struct nf_conntrack *ct)
}
/**
- * nf_sizeof - return the size of a certain conntrack object
+ * nf_sizeof - return the size in bytes of a certain conntrack object
* @ct: pointer to the conntrack object
*/
size_t nfct_sizeof(const struct nf_conntrack *ct)
@@ -53,6 +53,25 @@ size_t nfct_sizeof(const struct nf_conntrack *ct)
}
/**
+ * nfct_maxsize - return the maximum size in bytes of a conntrack object
+ *
+ * Use this function if you want to allocate a conntrack object in the stack
+ * instead of the heap. For example:
+ *
+ * char buf[nfct_maxsize()];
+ * struct nf_conntrack *ct = (struct nf_conntrack *) buf;
+ * memset(ct, 0, nfct_maxsize());
+ *
+ * Note: As for now this function returns the same size that nfct_sizeof(ct)
+ * does although _this could change in the future_. Therefore, do not assume
+ * that nfct_sizeof(ct) == nfct_maxsize().
+ */
+size_t nfct_maxsize()
+{
+ return sizeof(struct nf_conntrack);
+}
+
+/**
* nfct_clone - clone a conntrack object
* @ct: pointer to a valid conntrack object
*
@@ -194,7 +213,7 @@ void nfct_callback_unregister(struct nfct_handle *h)
*/
void nfct_set_attr(struct nf_conntrack *ct,
const enum nf_conntrack_attr type,
- void *value)
+ const void *value)
{
assert(ct != NULL);
assert(value != NULL);
@@ -602,3 +621,24 @@ int nfct_snprintf(char *buf,
return __snprintf_conntrack(buf, size, ct, msg_type, out_type, flags);
}
+
+/**
+ * nfct_compare - compare two conntrack objects
+ * @ct1: pointer to a valid conntrack object
+ * @ct2: pointer to a valid conntrack object
+ *
+ * This function only compare attribute set in both objects, ie. if a certain
+ * attribute is not set in ct1 but it is in ct2, then the value of such
+ * attribute is not used in the comparison.
+ *
+ * If both conntrack object are equal, this function returns 1, otherwise
+ * 0 is returned.
+ */
+int nfct_compare(const struct nf_conntrack *ct1,
+ const struct nf_conntrack *ct2)
+{
+ assert(ct1 != NULL);
+ assert(ct2 != NULL);
+
+ return __compare(ct1, ct2);
+}