diff options
author | Pablo Neira Ayuso <pablo@netfilter.org> | 2012-04-16 12:13:45 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2012-05-26 16:11:35 +0200 |
commit | d773fb2afc097a08d51eae42740c63142b1752cf (patch) | |
tree | 83d60033ed8124ebe77b2993b12c309e94a1433c /src/expect/build_mnl.c | |
parent | 95b3bf6576165e1bbe23d55d5f15b7ebf9c98dc4 (diff) |
expect: add new API to build/parse ctnetlink messages using libmnl
This patch adds support to build and to parse netlink messages
from/to one user-space nf_conntrack object. It uses libmnl, thus
libnetfilter_conntrack now depends on this library.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/expect/build_mnl.c')
-rw-r--r-- | src/expect/build_mnl.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/expect/build_mnl.c b/src/expect/build_mnl.c new file mode 100644 index 0000000..6f33f05 --- /dev/null +++ b/src/expect/build_mnl.c @@ -0,0 +1,49 @@ +/* + * (C) 2005-2012 by Pablo Neira Ayuso <pablo@netfilter.org> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This code has been sponsored by Vyatta Inc. <http://www.vyatta.com> + */ + +#include "internal/internal.h" +#include <libmnl/libmnl.h> + +int +nfexp_nlmsg_build(struct nlmsghdr *nlh, const struct nf_expect *exp) +{ + u_int8_t l3num; + + if (test_bit(ATTR_ORIG_L3PROTO, exp->master.set)) + l3num = exp->master.orig.l3protonum; + else if (test_bit(ATTR_ORIG_L3PROTO, exp->expected.set)) + l3num = exp->expected.orig.l3protonum; + else + return -1; + + if (test_bit(ATTR_EXP_EXPECTED, exp->set)) + nfct_build_tuple(nlh, &exp->expected.orig, CTA_EXPECT_TUPLE); + + if (test_bit(ATTR_EXP_MASTER, exp->set)) + nfct_build_tuple(nlh, &exp->master.orig, CTA_EXPECT_MASTER); + + if (test_bit(ATTR_EXP_MASK, exp->set)) + nfct_build_tuple(nlh, &exp->mask.orig, CTA_EXPECT_MASK); + + if (test_bit(ATTR_EXP_TIMEOUT, exp->set)) + mnl_attr_put_u32(nlh, CTA_EXPECT_TIMEOUT, htonl(exp->timeout)); + + if (test_bit(ATTR_EXP_FLAGS, exp->set)) + mnl_attr_put_u32(nlh, CTA_EXPECT_FLAGS, htonl(exp->flags)); + + if (test_bit(ATTR_EXP_ZONE, exp->set)) + mnl_attr_put_u16(nlh, CTA_EXPECT_ZONE, htons(exp->zone)); + + if (test_bit(ATTR_EXP_HELPER_NAME, exp->set)) + mnl_attr_put_strz(nlh, CTA_EXPECT_HELP_NAME, exp->helper_name); + + return 0; +} |