From: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
To: netfilter-devel@vger.kernel.org
Cc: pablo@netfilter.org, kaber@trash.net,
Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Subject: [nf_tables 1/3] netfilter: nf_tables: store and dump sets mechanism options
Date: Thu, 18 Sep 2014 20:18:18 +0200 [thread overview]
Message-ID: <1411064300-4433-1-git-send-email-arturo.borrero.glez@gmail.com> (raw)
The sets mechanism options was not being stored anywhere.
We want to know in which cases the user explicitly set the mechanism
options. In that case, we also want to dump back the info.
Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
---
include/net/netfilter/nf_tables.h | 12 +++++++++++
net/netfilter/nf_tables_api.c | 42 +++++++++++++++++++++++++++----------
2 files changed, 43 insertions(+), 11 deletions(-)
diff --git a/include/net/netfilter/nf_tables.h b/include/net/netfilter/nf_tables.h
index c4d8619..a9c6387 100644
--- a/include/net/netfilter/nf_tables.h
+++ b/include/net/netfilter/nf_tables.h
@@ -231,6 +231,14 @@ struct nft_set_ops {
int nft_register_set(struct nft_set_ops *ops);
void nft_unregister_set(struct nft_set_ops *ops);
+/* internal flags to know which attributes were originally set
+ * from userspace.
+ */
+enum nft_set_attr {
+ NFT_SET_ATTR_POLICY = 0x1,
+ NFT_SET_ATTR_DESC_SIZE = 0x2,
+};
+
/**
* struct nft_set - nf_tables set instance
*
@@ -241,6 +249,8 @@ void nft_unregister_set(struct nft_set_ops *ops);
* @dtype: data type (verdict or numeric type defined by userspace)
* @size: maximum set size
* @nelems: number of elements
+ * @attr_flags: (enum nft_set_flags)
+ * @policy: (enum nft_set_policies)
* @ops: set ops
* @flags: set flags
* @klen: key length
@@ -255,6 +265,8 @@ struct nft_set {
u32 dtype;
u32 size;
u32 nelems;
+ u16 attr_flags;
+ u32 policy;
/* runtime data below here */
const struct nft_set_ops *ops ____cacheline_aligned;
u16 flags;
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 8237460..d1c3f3e 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -2342,13 +2342,24 @@ static int nf_tables_fill_set(struct sk_buff *skb, const struct nft_ctx *ctx,
goto nla_put_failure;
}
- desc = nla_nest_start(skb, NFTA_SET_DESC);
- if (desc == NULL)
- goto nla_put_failure;
- if (set->size &&
- nla_put_be32(skb, NFTA_SET_DESC_SIZE, htonl(set->size)))
- goto nla_put_failure;
- nla_nest_end(skb, desc);
+ /* dump policy and desc info only if they were explicitly set */
+ if (set->attr_flags & (1 << NFT_SET_ATTR_POLICY)) {
+ if (nla_put_be32(skb, NFTA_SET_POLICY, htonl(set->policy)))
+ goto nla_put_failure;
+ }
+
+ if (set->attr_flags & (1 << NFT_SET_ATTR_DESC_SIZE)) {
+ desc = nla_nest_start(skb, NFTA_SET_DESC);
+ if (desc == NULL)
+ goto nla_put_failure;
+
+ if (set->size &&
+ nla_put_be32(skb, NFTA_SET_DESC_SIZE, htonl(set->size))) {
+ goto nla_put_failure;
+ }
+
+ nla_nest_end(skb, desc);
+ }
return nlmsg_end(skb, nlh);
@@ -2519,7 +2530,8 @@ err:
static int nf_tables_set_desc_parse(const struct nft_ctx *ctx,
struct nft_set_desc *desc,
- const struct nlattr *nla)
+ const struct nlattr *nla,
+ u16 *attr_flags)
{
struct nlattr *da[NFTA_SET_DESC_MAX + 1];
int err;
@@ -2528,8 +2540,10 @@ static int nf_tables_set_desc_parse(const struct nft_ctx *ctx,
if (err < 0)
return err;
- if (da[NFTA_SET_DESC_SIZE] != NULL)
+ if (da[NFTA_SET_DESC_SIZE] != NULL) {
desc->size = ntohl(nla_get_be32(da[NFTA_SET_DESC_SIZE]));
+ *attr_flags |= (1 << NFT_SET_ATTR_DESC_SIZE);
+ }
return 0;
}
@@ -2549,6 +2563,7 @@ static int nf_tables_newset(struct sock *nlsk, struct sk_buff *skb,
unsigned int size;
bool create;
u32 ktype, dtype, flags, policy;
+ u16 attr_flags = 0;
struct nft_set_desc desc;
int err;
@@ -2602,11 +2617,14 @@ static int nf_tables_newset(struct sock *nlsk, struct sk_buff *skb,
return -EINVAL;
policy = NFT_SET_POL_PERFORMANCE;
- if (nla[NFTA_SET_POLICY] != NULL)
+ if (nla[NFTA_SET_POLICY] != NULL) {
policy = ntohl(nla_get_be32(nla[NFTA_SET_POLICY]));
+ attr_flags |= (1 << NFT_SET_ATTR_POLICY);
+ }
if (nla[NFTA_SET_DESC] != NULL) {
- err = nf_tables_set_desc_parse(&ctx, &desc, nla[NFTA_SET_DESC]);
+ err = nf_tables_set_desc_parse(&ctx, &desc, nla[NFTA_SET_DESC],
+ &attr_flags);
if (err < 0)
return err;
}
@@ -2667,6 +2685,8 @@ static int nf_tables_newset(struct sock *nlsk, struct sk_buff *skb,
set->dlen = desc.dlen;
set->flags = flags;
set->size = desc.size;
+ set->attr_flags = attr_flags;
+ set->policy = policy;
err = ops->init(set, &desc, nla);
if (err < 0)
--
1.7.10.4
next reply other threads:[~2014-09-18 18:18 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-18 18:18 Arturo Borrero Gonzalez [this message]
2014-09-18 18:18 ` [libnftnl 2/3] set: fix set nlmsg desc parsing Arturo Borrero Gonzalez
2014-09-18 18:43 ` Pablo Neira Ayuso
2014-09-18 18:18 ` [nft 3/3] src: add set optimization options Arturo Borrero Gonzalez
2014-09-18 18:39 ` Patrick McHardy
2014-09-19 7:04 ` Arturo Borrero Gonzalez
2014-09-19 17:24 ` Patrick McHardy
2014-09-20 11:45 ` Patrick McHardy
2014-09-18 18:34 ` [nf_tables 1/3] netfilter: nf_tables: store and dump sets mechanism options Patrick McHardy
2014-09-19 6:51 ` Arturo Borrero Gonzalez
2014-09-19 17:20 ` Patrick McHardy
2014-09-20 11:39 ` Patrick McHardy
2014-09-22 10:01 ` Arturo Borrero Gonzalez
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1411064300-4433-1-git-send-email-arturo.borrero.glez@gmail.com \
--to=arturo.borrero.glez@gmail.com \
--cc=kaber@trash.net \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).