diff options
author | Pablo Neira Ayuso <pablo@netfilter.org> | 2010-10-12 13:24:08 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2010-11-08 23:40:33 +0100 |
commit | b245e4092c5a7f09729e64868a42e13f48ac5db8 (patch) | |
tree | a31692d718120b9c17951e2e583c3a7d554602ab /src/expect | |
parent | 417dc5fb87ade355d699ea523de870abc6dd1657 (diff) |
src: allow to use nfct handler for conntrack and expectations at the same time
This patch re-works the callback handling to allow the use the same socket
to send/receive commands and listen to events of both conntrack and
expectation subsystems. Now you can register one callback for conntrack
and one for expectation with the same handler with no problems (before
this patch, this was not possible, you required two different handlers).
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/expect')
-rw-r--r-- | src/expect/Makefile.am | 2 | ||||
-rw-r--r-- | src/expect/api.c | 36 | ||||
-rw-r--r-- | src/expect/callback.c | 55 |
3 files changed, 19 insertions, 74 deletions
diff --git a/src/expect/Makefile.am b/src/expect/Makefile.am index b0404ba..380befa 100644 --- a/src/expect/Makefile.am +++ b/src/expect/Makefile.am @@ -4,7 +4,7 @@ AM_CFLAGS = -Wall ${LIBNFNETLINK_CFLAGS} noinst_LTLIBRARIES = libnfexpect.la -libnfexpect_la_SOURCES = api.c callback.c \ +libnfexpect_la_SOURCES = api.c \ getter.c setter.c \ parse.c build.c \ snprintf.c \ diff --git a/src/expect/api.c b/src/expect/api.c index d560178..35c8672 100644 --- a/src/expect/api.c +++ b/src/expect/api.c @@ -139,17 +139,17 @@ int nfexp_callback_register(struct nfct_handle *h, container->type = type; container->data = data; - h->nfnl_cb.call = __expect_callback; - h->nfnl_cb.data = container; - h->nfnl_cb.attr_count = CTA_EXPECT_MAX; + h->nfnl_cb_exp.call = __callback; + h->nfnl_cb_exp.data = container; + h->nfnl_cb_exp.attr_count = CTA_EXPECT_MAX; nfnl_callback_register(h->nfnlssh_exp, IPCTNL_MSG_EXP_NEW, - &h->nfnl_cb); + &h->nfnl_cb_exp); nfnl_callback_register(h->nfnlssh_exp, IPCTNL_MSG_EXP_DELETE, - &h->nfnl_cb); + &h->nfnl_cb_exp); return 0; } @@ -166,11 +166,11 @@ void nfexp_callback_unregister(struct nfct_handle *h) nfnl_callback_unregister(h->nfnlssh_exp, IPCTNL_MSG_EXP_DELETE); h->expect_cb = NULL; - free(h->nfnl_cb.data); + free(h->nfnl_cb_exp.data); - h->nfnl_cb.call = NULL; - h->nfnl_cb.data = NULL; - h->nfnl_cb.attr_count = 0; + h->nfnl_cb_exp.call = NULL; + h->nfnl_cb_exp.data = NULL; + h->nfnl_cb_exp.attr_count = 0; } /** @@ -214,17 +214,17 @@ int nfexp_callback_register2(struct nfct_handle *h, container->type = type; container->data = data; - h->nfnl_cb.call = __expect_callback; - h->nfnl_cb.data = container; - h->nfnl_cb.attr_count = CTA_EXPECT_MAX; + h->nfnl_cb_exp.call = __callback; + h->nfnl_cb_exp.data = container; + h->nfnl_cb_exp.attr_count = CTA_EXPECT_MAX; nfnl_callback_register(h->nfnlssh_exp, IPCTNL_MSG_EXP_NEW, - &h->nfnl_cb); + &h->nfnl_cb_exp); nfnl_callback_register(h->nfnlssh_exp, IPCTNL_MSG_EXP_DELETE, - &h->nfnl_cb); + &h->nfnl_cb_exp); return 0; } @@ -241,11 +241,11 @@ void nfexp_callback_unregister2(struct nfct_handle *h) nfnl_callback_unregister(h->nfnlssh_exp, IPCTNL_MSG_EXP_DELETE); h->expect_cb2 = NULL; - free(h->nfnl_cb.data); + free(h->nfnl_cb_exp.data); - h->nfnl_cb.call = NULL; - h->nfnl_cb.data = NULL; - h->nfnl_cb.attr_count = 0; + h->nfnl_cb_exp.call = NULL; + h->nfnl_cb_exp.data = NULL; + h->nfnl_cb_exp.attr_count = 0; } /** diff --git a/src/expect/callback.c b/src/expect/callback.c deleted file mode 100644 index d2cc26e..0000000 --- a/src/expect/callback.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * (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/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); - else if (container->h->expect_cb2) - ret = container->h->expect_cb2(nlh, 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; -} |