netfilter: nf_tables: Introduce stateful object update operation
Subsystems (2)
PATCH 1/2 netfilter: nf_tables: Introduce stateful object update operation
This patch adds the infrastructure needed for the stateful object update support.
--- include/net/netfilter/nf_tables.h | 6 +++ net/netfilter/nf_tables_api.c | 71 ++++++++++++++++++++++++++++--- 2 files changed, 70 insertions(+), 7 deletions(-)
include/net/netfilter/nf_tables.h +6 -0
@@ -1123,6 +1123,9 @@ struct nft_object_ops {int (*dump)(struct sk_buff *skb,struct nft_object *obj,bool reset); +int (*update)(const struct nft_ctx *ctx, +const struct nlattr *const tb[], +struct nft_object *obj);const struct nft_object_type *type; };
@@ -1405,10 +1408,13 @@ struct nft_trans_elem {struct nft_trans_obj {struct nft_object *obj; +bool update; };#define nft_trans_obj (trans) \ (((struct nft_trans_obj *)trans->data)->obj) +#define nft_trans_obj_update (trans) \ + (((struct nft_trans_obj *)trans->data)->update)struct nft_trans_flowtable {struct nft_flowtable *flowtable;
net/netfilter/nf_tables_api.c +64 -7
95 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH 2/2 netfilter: nft_quota: add quota object update support
--- net/netfilter/nft_quota.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+)
net/netfilter/nft_quota.c +39 -0
@@ -105,6 +105,44 @@ static int nft_quota_obj_init(const struct nft_ctx *ctx,return nft_quota_do_init (tb, priv); } +static int nft_quota_do_update (const struct nlattr *const tb[], +struct nft_quota * priv) +{ +unsigned long flags; +u64 quota; + + flags = priv->flags; + quota = priv->quota; + +if (tb[NFTA_QUOTA_BYTES ]) { + quota =be64_to_cpu (nla_get_be64 (tb[NFTA_QUOTA_BYTES ])); +if (quota >S64_MAX ) +return -EOVERFLOW ; + } + +if (tb[NFTA_QUOTA_FLAGS ]) { + flags =ntohl (nla_get_be32 (tb[NFTA_QUOTA_FLAGS ])); +if (flags & ~NFT_QUOTA_F_INV ) +return -EINVAL ; +if (flags & ~NFT_QUOTA_F_DEPLETED ) +return -EOPNOTSUPP ; + } + + priv->quota = quota; + priv->flags = flags; + +return 0 ; +} + +static int nft_quota_obj_update (const struct nft_ctx *ctx, +const struct nlattr *const tb[], +struct nft_object *obj) +{ +struct nft_quota *priv =nft_obj_data (obj); + +return nft_quota_do_update (tb, priv); +} +static int nft_quota_do_dump (struct sk_buff *skb,struct nft_quota *priv,bool reset) {
@@ -155,6 +193,7 @@ static const struct nft_object_ops nft_quota_obj_ops = { .init = nft_quota_obj_init, .eval = nft_quota_obj_eval, .dump = nft_quota_obj_dump, + .update = nft_quota_obj_update, };static struct nft_object_type nft_quota_obj_type__read_mostly = {
Signature · 1 line
2.20.1
Florian Westphal
maintainerQuoted 14 lines · Fernando Fernandez Mancera
This patch adds the infrastructure needed for the stateful object update support.
Signed-off-by Fernando Fernandez Mancera <[email protected]>--- include/net/netfilter/nf_tables.h | 6 +++ net/netfilter/nf_tables_api.c | 71 ++++++++++++++++++++++++++++--- 2 files changed, 70 insertions(+), 7 deletions(-)include/net/netfilter/nf_tables.h +0
-0
include/net/netfilter/nf_tables.h struct nft_object_ops { · line 1128
Quoted 6 lines
include/net/netfilter/nf_tables.h +3
-0@@ -1123,6 +1123,9 @@ struct nft_object_ops {int (*dump)(struct sk_buff *skb,struct nft_object *obj,bool reset); +int (*update)(const struct nft_ctx *ctx, +const struct nlattr *const tb[], +struct nft_object *obj);
maybe adda 'bool commit' argument here.
include/net/netfilter/nf_tables.h struct nft_object_ops { · line 1129
Quoted 1 line
include/net/netfilter/nf_tables.h +1
-0+ err = obj->ops->update (ctx, (const struct nlattr *const *)tb, obj);
Then, set it to 'false' here.
You would have to keep 'tb' allocated and place it on the 'trans' object.
include/net/netfilter/nf_tables.h struct nft_object_ops { · line 1130
Quoted 1 line
include/net/netfilter/nf_tables.h +1
-0+nft_trans_obj_update (trans) = true;
nft_trans_obj_update_tb(trans) = tb;
include/net/netfilter/nf_tables.h struct nft_object_ops {
Quoted 5 lines
include/net/netfilter/nf_tables.h +1
-4-nft_clear (net,nft_trans_obj (trans)); -nf_tables_obj_notify (&trans->ctx,nft_trans_obj (trans), -NFT_MSG_NEWOBJ ); -nft_trans_destroy (trans); +if (nft_trans_obj_update (trans)) {
nft_trans_obj(trans)->ops->update(&trans->ctx, nft_trans_obj_update_tb(trans), nft_trans_obj(trans), true); kfree(nft_trans_obj_update_tb(trans));
Because otherwise we will update objects while we're not yet sure that we can process/handle the entire batch.
I think we should, if possible, only update once we've made it to the commit phase.
Quoted 10 lines · Florian Westphal
Quoted 9 lines · Fernando Fernandez Mancera
This patch adds the infrastructure needed for the stateful object update support.
Signed-off-by Fernando Fernandez Mancera <[email protected]>--- include/net/netfilter/nf_tables.h | 6 +++ net/netfilter/nf_tables_api.c | 71 ++++++++++++++++++++++++++++--- 2 files changed, 70 insertions(+), 7 deletions(-)
Quoted 14 lines
include/net/netfilter/nf_tables.h struct nft_object_ops { · line 1128
Quoted 11 lines
include/net/netfilter/nf_tables.h +3
-0@@ -1123,6 +1123,9 @@ struct nft_object_ops {int (*dump)(struct sk_buff *skb,struct nft_object *obj,bool reset); +int (*update)(const struct nft_ctx *ctx, +const struct nlattr *const tb[], +struct nft_object *obj);maybe adda 'bool commit' argument here.
How is that argument going to be used? If 'commit' is false we should just check that values are fine but not update them?
Quoted 6 lines
include/net/netfilter/nf_tables.h struct nft_object_ops { · line 1129
Quoted 1 line
include/net/netfilter/nf_tables.h +1
-0+ err = obj->ops->update (ctx, (const struct nlattr *const *)tb, obj);Then, set it to 'false' here.
You would have to keep 'tb' allocated and place it on the 'trans' object.
Yes, I agree on updating the object in the commit phase. But I am not sure about how I should place it on 'trans'. Any hints? Thanks :-)
I am also writing some userspace shell tests.
Quoted 24 lines
include/net/netfilter/nf_tables.h struct nft_object_ops { · line 1130
Quoted 1 line
include/net/netfilter/nf_tables.h +1
-0+nft_trans_obj_update (trans) = true;nft_trans_obj_update_tb(trans) = tb;include/net/netfilter/nf_tables.h struct nft_object_ops {
Quoted 5 lines
include/net/netfilter/nf_tables.h +1
-4-nft_clear (net,nft_trans_obj (trans)); -nf_tables_obj_notify (&trans->ctx,nft_trans_obj (trans), -NFT_MSG_NEWOBJ ); -nft_trans_destroy (trans); +if (nft_trans_obj_update (trans)) {nft_trans_obj(trans)->ops->update(&trans->ctx, nft_trans_obj_update_tb(trans), nft_trans_obj(trans), true); kfree(nft_trans_obj_update_tb(trans));Because otherwise we will update objects while we're not yet sure that we can process/handle the entire batch.
I think we should, if possible, only update once we've made it to the commit phase.
Florian Westphal
maintainerQuoted 2 lines · Fernando Fernandez Mancera
How is that argument going to be used? If 'commit' is false we should just check that values are fine but not update them?
Yes, thats the idea.
Quoted 2 lines
Yes, I agree on updating the object in the commit phase. But I am not sure about how I should place it on 'trans'. Any hints? Thanks :-)
Can you place a pointer to the tb array on the trans object?
Another possibility is to have ->update return a kmalloced blob that contains ready-to-use binary data, so depending on the 'bool commit' the update hook would expect either tb[] (for validation) or a backend-maintained struct with the to-update values.
In the quota case it would be a struct containing the u64 values.
Quoted 1 line
I am also writing some userspace shell tests.
Thats good, thanks Fernando!
Quoted 11 lines · Florian Westphal
Quoted 2 lines · Fernando Fernandez Mancera
How is that argument going to be used? If 'commit' is false we should just check that values are fine but not update them?
Yes, thats the idea.
Quoted 2 lines
Yes, I agree on updating the object in the commit phase. But I am not sure about how I should place it on 'trans'. Any hints? Thanks :-)
Can you place a pointer to the tb array on the trans object?
I prefer this option. So we can place a pointer to the tb array on the trans object and also the pointer to the existing object. This way it should be easy to do ->update in the commit phase.
Thanks!
Quoted 11 lines
Another possibility is to have ->update return a kmalloced blob that contains ready-to-use binary data, so depending on the 'bool commit' the update hook would expect either tb[] (for validation) or a backend-maintained struct with the to-update values.
In the quota case it would be a struct containing the u64 values.
Quoted 1 line
I am also writing some userspace shell tests.
Thats good, thanks Fernando!