From 6a05d293fed594f89ad05625e43dec6a81da487d Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Sat, 24 Dec 2011 15:07:58 +0100 Subject: expect: support CTA_EXPECT_HELP_NAME This patch adds support for CTA_EXPECT_HELP_NAME. We now have the ATTR_EXP_HELPER_NAME attribute. 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 +++++++ src/expect/snprintf_default.c | 5 +++++ 5 files changed, 32 insertions(+) (limited to 'src') diff --git a/src/expect/build.c b/src/expect/build.c index c1a5a1d..82aa852 100644 --- a/src/expect/build.c +++ b/src/expect/build.c @@ -26,6 +26,13 @@ static void __build_flags(struct nfnlhdr *req, nfnl_addattr32(&req->nlh, size, CTA_EXPECT_FLAGS,htonl(exp->flags)); } +static void __build_helper_name(struct nfnlhdr *req, size_t size, + const struct nf_expect *exp) +{ + nfnl_addattr_l(&req->nlh, size, CTA_EXPECT_HELP_NAME, + exp->helper_name, strlen(exp->helper_name)); +} + int __build_expect(struct nfnl_subsys_handle *ssh, struct nfnlhdr *req, size_t size, @@ -73,6 +80,8 @@ int __build_expect(struct nfnl_subsys_handle *ssh, __build_flags(req, size, exp); if (test_bit(ATTR_EXP_ZONE, exp->set)) __build_zone(req, size, exp); + if (test_bit(ATTR_EXP_HELPER_NAME, exp->set)) + __build_helper_name(req, size, exp); return 0; } diff --git a/src/expect/getter.c b/src/expect/getter.c index 9cb6ede..69453c5 100644 --- a/src/expect/getter.c +++ b/src/expect/getter.c @@ -37,6 +37,11 @@ static const void *get_exp_attr_flags(const struct nf_expect *exp) return &exp->flags; } +static const void *get_exp_attr_helper_name(const struct nf_expect *exp) +{ + return exp->helper_name; +} + 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, @@ -44,4 +49,5 @@ const get_exp_attr get_exp_attr_array[ATTR_EXP_MAX] = { [ATTR_EXP_TIMEOUT] = get_exp_attr_timeout, [ATTR_EXP_ZONE] = get_exp_attr_zone, [ATTR_EXP_FLAGS] = get_exp_attr_flags, + [ATTR_EXP_HELPER_NAME] = get_exp_attr_helper_name, }; diff --git a/src/expect/parse.c b/src/expect/parse.c index 0581aca..4d9852d 100644 --- a/src/expect/parse.c +++ b/src/expect/parse.c @@ -77,4 +77,9 @@ void __parse_expect(const struct nlmsghdr *nlh, ntohl(*(u_int32_t *)NFA_DATA(cda[CTA_EXPECT_FLAGS-1])); set_bit(ATTR_EXP_FLAGS, exp->set); } + if (cda[CTA_EXPECT_HELP_NAME-1]) { + strncpy(exp->helper_name, NFA_DATA(cda[CTA_EXPECT_HELP_NAME-1]), + NFA_PAYLOAD(cda[CTA_EXPECT_HELP_NAME-1])); + set_bit(ATTR_EXP_HELPER_NAME, exp->set); + } } diff --git a/src/expect/setter.c b/src/expect/setter.c index 040b958..3cde4b0 100644 --- a/src/expect/setter.c +++ b/src/expect/setter.c @@ -37,6 +37,12 @@ static void set_exp_attr_flags(struct nf_expect *exp, const void *value) exp->flags = *((u_int32_t *) value); } +static void set_exp_attr_helper_name(struct nf_expect *exp, const void *value) +{ + strncpy(exp->helper_name, value, __NFCT_HELPER_NAMELEN); + exp->helper_name[__NFCT_HELPER_NAMELEN-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, @@ -44,4 +50,5 @@ const set_exp_attr set_exp_attr_array[ATTR_EXP_MAX] = { [ATTR_EXP_TIMEOUT] = set_exp_attr_timeout, [ATTR_EXP_ZONE] = set_exp_attr_zone, [ATTR_EXP_FLAGS] = set_exp_attr_flags, + [ATTR_EXP_HELPER_NAME] = set_exp_attr_helper_name, }; diff --git a/src/expect/snprintf_default.c b/src/expect/snprintf_default.c index c4a19fa..bda39cc 100644 --- a/src/expect/snprintf_default.c +++ b/src/expect/snprintf_default.c @@ -102,6 +102,11 @@ int __snprintf_expect_default(char *buf, &exp->master.tuple[__DIR_ORIG]); BUFFER_SIZE(ret, size, len, offset); + if (test_bit(ATTR_EXP_HELPER_NAME, exp->set)) { + ret = snprintf(buf+offset, len, "helper=%s", exp->helper_name); + BUFFER_SIZE(ret, size, len, offset); + } + /* Delete the last blank space if needed */ if (len > 0 && buf[size-1] == ' ') size--; -- cgit v1.2.3