From 678ec919ffe3072468cb56de6eabf8cb8f7e9bdb Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Mon, 6 Feb 2012 22:51:32 +0100 Subject: expect: add expectfn support This patch allows you to set expectfn. Signed-off-by: Pablo Neira Ayuso --- src/expect/build.c | 9 +++++++++ src/expect/getter.c | 6 ++++++ src/expect/parse.c | 5 +++++ src/expect/setter.c | 7 +++++++ 4 files changed, 27 insertions(+) (limited to 'src/expect') diff --git a/src/expect/build.c b/src/expect/build.c index 8cf2edd..a544ded 100644 --- a/src/expect/build.c +++ b/src/expect/build.c @@ -42,6 +42,13 @@ static void __build_helper_name(struct nfnlhdr *req, size_t size, exp->helper_name, strlen(exp->helper_name)); } +static void __build_expectfn(struct nfnlhdr *req, + size_t size, const struct nf_expect *exp) +{ + nfnl_addattr_l(&req->nlh, size, CTA_EXPECT_FN, + exp->expectfn, strlen(exp->expectfn)+1); +} + int __build_expect(struct nfnl_subsys_handle *ssh, struct nfnlhdr *req, size_t size, @@ -95,6 +102,8 @@ int __build_expect(struct nfnl_subsys_handle *ssh, __build_class(req, size, exp); if (test_bit(ATTR_EXP_HELPER_NAME, exp->set)) __build_helper_name(req, size, exp); + if (test_bit(ATTR_EXP_FN, exp->set)) + __build_expectfn(req, size, exp); return 0; } diff --git a/src/expect/getter.c b/src/expect/getter.c index 937e793..47087a7 100644 --- a/src/expect/getter.c +++ b/src/expect/getter.c @@ -59,6 +59,11 @@ static const void *get_exp_attr_nat_tuple(const struct nf_expect *exp) return &exp->nat; } +static const void *get_exp_attr_expectfn(const struct nf_expect *exp) +{ + return exp->expectfn; +} + const get_exp_attr get_exp_attr_array[ATTR_EXP_MAX] = { [ATTR_EXP_MASTER] = get_exp_attr_master, [ATTR_EXP_EXPECTED] = get_exp_attr_expected, @@ -70,4 +75,5 @@ const get_exp_attr get_exp_attr_array[ATTR_EXP_MAX] = { [ATTR_EXP_CLASS] = get_exp_attr_class, [ATTR_EXP_NAT_TUPLE] = get_exp_attr_nat_tuple, [ATTR_EXP_NAT_DIR] = get_exp_attr_nat_dir, + [ATTR_EXP_FN] = get_exp_attr_expectfn, }; diff --git a/src/expect/parse.c b/src/expect/parse.c index 5796072..c29a110 100644 --- a/src/expect/parse.c +++ b/src/expect/parse.c @@ -109,4 +109,9 @@ void __parse_expect(const struct nlmsghdr *nlh, set_bit(ATTR_EXP_NAT_DIR, exp->set); } } + if (cda[CTA_EXPECT_FN-1]) { + strcpy(exp->expectfn, NFA_DATA(cda[CTA_EXPECT_FN-1])); + exp->expectfn[__NFCT_EXPECTFN_MAX-1] = '\0'; + set_bit(ATTR_EXP_FN, exp->set); + } } diff --git a/src/expect/setter.c b/src/expect/setter.c index 47843f8..2cf29c2 100644 --- a/src/expect/setter.c +++ b/src/expect/setter.c @@ -60,6 +60,12 @@ static void set_exp_attr_nat_tuple(struct nf_expect *exp, const void *value) exp->nat = *((struct nfct_tuple_head *) value); } +static void set_exp_attr_expectfn(struct nf_expect *exp, const void *value) +{ + strncpy(exp->expectfn, value, __NFCT_EXPECTFN_MAX); + exp->expectfn[__NFCT_EXPECTFN_MAX-1] = '\0'; +} + const set_exp_attr set_exp_attr_array[ATTR_EXP_MAX] = { [ATTR_EXP_MASTER] = set_exp_attr_master, [ATTR_EXP_EXPECTED] = set_exp_attr_expected, @@ -71,4 +77,5 @@ const set_exp_attr set_exp_attr_array[ATTR_EXP_MAX] = { [ATTR_EXP_CLASS] = set_exp_attr_class, [ATTR_EXP_NAT_TUPLE] = set_exp_attr_nat_tuple, [ATTR_EXP_NAT_DIR] = set_exp_attr_nat_dir, + [ATTR_EXP_FN] = set_exp_attr_expectfn, }; -- cgit v1.2.3