summaryrefslogtreecommitdiffstats
path: root/src/expect/callback.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-05-01 18:30:03 +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-05-01 18:30:03 +0000
commit4db878d6f81fd64029c48003f4e1ae57069a7c65 (patch)
treeb15b1aa433fdd9284fed8db9a02a19b8d1aa46a0 /src/expect/callback.c
parent7736631fef63efde9c0fd68af89c3e2900286428 (diff)
introduce the new expectation API
Diffstat (limited to 'src/expect/callback.c')
-rw-r--r--src/expect/callback.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/expect/callback.c b/src/expect/callback.c
new file mode 100644
index 0000000..df4ffe7
--- /dev/null
+++ b/src/expect/callback.c
@@ -0,0 +1,53 @@
+/*
+ * (C) 2006-2007 by Pablo Neira Ayuso <pablo@netfilter.org>
+ *
+ * This software may be used and distributed according to the terms
+ * of the GNU General Public License, incorporated herein by reference.
+ */
+
+#include "internal.h"
+
+int __expect_callback(struct nlmsghdr *nlh, struct nfattr *nfa[], void *data)
+{
+ int ret = NFNL_CB_STOP;
+ unsigned int type;
+ struct nf_expect *exp;
+ int len = nlh->nlmsg_len;
+ struct __data_container *container = data;
+
+ len -= NLMSG_LENGTH(sizeof(struct nfgenmsg));
+ if (len < 0)
+ return NFNL_CB_CONTINUE;
+
+ type = __parse_message_type(nlh);
+ if (!(type & container->type))
+ return NFNL_CB_CONTINUE;
+
+ exp = nfexp_new();
+ if (!exp)
+ return NFNL_CB_CONTINUE;
+
+ __parse_expect(nlh, nfa, exp);
+
+ if (container->h->expect_cb)
+ ret = container->h->expect_cb(type, exp, container->data);
+
+ switch(ret) {
+ case NFCT_CB_FAILURE:
+ free(exp);
+ ret = NFNL_CB_FAILURE;
+ break;
+ case NFCT_CB_STOP:
+ free(exp);
+ ret = NFNL_CB_STOP;
+ break;
+ case NFCT_CB_CONTINUE:
+ free(exp);
+ ret = NFNL_CB_CONTINUE;
+ break;
+ case NFCT_CB_STOLEN:
+ ret = NFNL_CB_CONTINUE;
+ break;
+ }
+ return ret;
+}