From 4db878d6f81fd64029c48003f4e1ae57069a7c65 Mon Sep 17 00:00:00 2001 From: "/C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org" Date: Tue, 1 May 2007 18:30:03 +0000 Subject: introduce the new expectation API --- src/expect/parse.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/expect/parse.c (limited to 'src/expect/parse.c') diff --git a/src/expect/parse.c b/src/expect/parse.c new file mode 100644 index 0000000..5fe0bce --- /dev/null +++ b/src/expect/parse.c @@ -0,0 +1,57 @@ +/* + * (C) 2006-2007 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 __parse_expect_message_type(const struct nlmsghdr *nlh) +{ + u_int16_t type = NFNL_MSG_TYPE(nlh->nlmsg_type); + u_int16_t flags = nlh->nlmsg_flags; + int ret = NFCT_T_UNKNOWN; + + if (type == IPCTNL_MSG_EXP_NEW) { + if (flags & (NLM_F_CREATE|NLM_F_EXCL)) + ret = NFCT_T_NEW; + else + ret = NFCT_T_UPDATE; + } else if (type == IPCTNL_MSG_EXP_DELETE) + ret = NFCT_T_DESTROY; + + return ret; +} + +void __parse_expect(const struct nlmsghdr *nlh, + const struct nfattr *cda[], + struct nf_expect *exp) +{ + struct nfgenmsg *nfhdr = NLMSG_DATA(nlh); + + /* XXX: this is ugly, clean it up, please */ + exp->expected.tuple[__DIR_ORIG].l3protonum = nfhdr->nfgen_family; + set_bit(ATTR_ORIG_L3PROTO, exp->expected.set); + + exp->mask.tuple[__DIR_REPL].l3protonum = nfhdr->nfgen_family; + set_bit(ATTR_ORIG_L3PROTO, exp->mask.set); + + if (cda[CTA_EXPECT_TUPLE-1]) + __parse_tuple(cda[CTA_EXPECT_TUPLE-1], + &exp->expected.tuple[__DIR_ORIG], + __DIR_ORIG, + exp->set); + + if (cda[CTA_EXPECT_MASK-1]) + __parse_tuple(cda[CTA_EXPECT_MASK-1], + &exp->mask.tuple[__DIR_ORIG], + __DIR_ORIG, + exp->set); + + if (cda[CTA_EXPECT_TIMEOUT-1]) { + exp->timeout = + ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_EXPECT_TIMEOUT-1])); + set_bit(ATTR_EXP_TIMEOUT, exp->set); + } +} -- cgit v1.2.3