From b4c3a23c884c24f4e5d941fb928cf49561a9cdf9 Mon Sep 17 00:00:00 2001 From: "/C=DE/ST=Berlin/L=Berlin/O=Netfilter Project/OU=Development/CN=pablo/emailAddress=pablo@netfilter.org" Date: Tue, 19 Dec 2006 17:41:53 +0000 Subject: Introduce the new libnetfilter_conntrack API, features: - object oriented infrastructure - extensible and configurable output (XML) - low level functions to interact with netlink details - fairly documented Still backward compatible. --- src/conntrack/callback.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/conntrack/callback.c (limited to 'src/conntrack/callback.c') diff --git a/src/conntrack/callback.c b/src/conntrack/callback.c new file mode 100644 index 0000000..582dfc4 --- /dev/null +++ b/src/conntrack/callback.c @@ -0,0 +1,53 @@ +/* + * (C) 2006 by Pablo Neira Ayuso + * + * 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 __callback(struct nlmsghdr *nlh, struct nfattr *nfa[], void *data) +{ + int ret = NFNL_CB_STOP; + unsigned int type; + struct nf_conntrack *ct; + 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; + + ct = nfct_new(); + if (!ct) + return NFNL_CB_CONTINUE; + + __parse_conntrack(nlh, nfa, ct); + + if (container->h->cb) + ret = container->h->cb(type, ct, container->data); + + switch(ret) { + case NFCT_CB_FAILURE: + free(ct); + ret = NFNL_CB_FAILURE; + break; + case NFCT_CB_STOP: + free(ct); + ret = NFNL_CB_STOP; + break; + case NFCT_CB_CONTINUE: + free(ct); + ret = NFNL_CB_CONTINUE; + break; + case NFCT_CB_STOLEN: + ret = NFNL_CB_CONTINUE; + break; + } + return ret; +} -- cgit v1.2.3