summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2011-12-08 02:06:53 +0100
committerPablo Neira Ayuso <pablo@netfilter.org>2011-12-08 02:06:53 +0100
commit7843632196fd959f3f8f16f3d533c72d315a7e08 (patch)
treedfb1cfce46557b245d1c99c23a49ebf756e78388
parentb3c288427f1906e2b7c7f6e8c5747db8ccc5f62a (diff)
expect: add nfexp_send()
It is like nfct_send() but for expectations, for API symmetry. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r--include/libnetfilter_conntrack/libnetfilter_conntrack.h5
-rw-r--r--src/expect/api.c32
2 files changed, 37 insertions, 0 deletions
diff --git a/include/libnetfilter_conntrack/libnetfilter_conntrack.h b/include/libnetfilter_conntrack/libnetfilter_conntrack.h
index 011e344..94e34be 100644
--- a/include/libnetfilter_conntrack/libnetfilter_conntrack.h
+++ b/include/libnetfilter_conntrack/libnetfilter_conntrack.h
@@ -596,6 +596,11 @@ extern int nfexp_snprintf(char *buf,
const unsigned int out_type,
const unsigned int out_flags);
+
+extern int nfexp_send(struct nfct_handle *h,
+ const enum nf_conntrack_query qt,
+ const void *data);
+
extern int nfexp_catch(struct nfct_handle *h);
/* low level API */
diff --git a/src/expect/api.c b/src/expect/api.c
index 2daa15a..863f4c0 100644
--- a/src/expect/api.c
+++ b/src/expect/api.c
@@ -646,6 +646,38 @@ int nfexp_query(struct nfct_handle *h,
}
/**
+ * nfexp_send - send a query to ctnetlink
+ * \param h library handler
+ * \param qt query type
+ * \param data data required to send the query
+ *
+ * Like nfexp_query but we do not wait for the reply from ctnetlink.
+ * You can use nfexp_send() and nfexp_catch() to emulate nfexp_query().
+ * This is particularly useful when the socket is non-blocking.
+ *
+ * On error, -1 is returned and errno is explicitely set. On success, 0
+ * is returned.
+ */
+int nfexp_send(struct nfct_handle *h,
+ const enum nf_conntrack_query qt,
+ const void *data)
+{
+ size_t size = 4096; /* enough for now */
+ union {
+ char buffer[size];
+ struct nfnlhdr req;
+ } u;
+
+ assert(h != NULL);
+ assert(data != NULL);
+
+ if (__build_query_exp(h->nfnlssh_exp, qt, data, &u.req, size) == -1)
+ return -1;
+
+ return nfnl_send(h->nfnlh, &u.req.nlh);
+}
+
+/**
* nfexp_catch - catch events
* \param h library handler
*