netfilter: nf_tables: Introduce stateful object update operation
Subsystems (2)
PATCH v3 1/2 netfilter: nf_tables: Introduce stateful object update operation
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 | 8 ++++ net/netfilter/nf_tables_api.c | 79 ++++++++++++++++++++++++++++--- 2 files changed, 80 insertions(+), 7 deletions(-)
include/net/netfilter/nf_tables.h +8 -0
@@ -1123,6 +1123,8 @@ struct nft_object_ops {int (*dump)(struct sk_buff *skb,struct nft_object *obj,bool reset); +int (*update)(struct nft_object *obj, +struct nft_object *newobj);const struct nft_object_type *type; };
@@ -1405,10 +1407,16 @@ struct nft_trans_elem {struct nft_trans_obj {struct nft_object *obj; +struct nft_object *newobj; +bool update; };#define nft_trans_obj (trans) \ (((struct nft_trans_obj *)trans->data)->obj) +#define nft_trans_obj_newobj (trans) \ + (((struct nft_trans_obj *)trans->data)->newobj) +#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 +72 -7
109 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v3 2/2 netfilter: nft_quota: add quota object update support
Signed-off-by Fernando Fernandez Mancera <[email protected]>
--- net/netfilter/nft_quota.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-)
net/netfilter/nft_quota.c +24 -7
@@ -13,7 +13,7 @@#include <net/netfilter/nf_tables.h> struct nft_quota { -u64 quota; +atomic64_t quota;unsigned long flags;atomic64_t consumed; };
@@ -21,7 +21,8 @@ struct nft_quota {static inline bool nft_overquota (struct nft_quota *priv,const struct sk_buff *skb) { -return atomic64_add_return (skb->len, &priv->consumed) >= priv->quota; +return atomic64_add_return (skb->len, &priv->consumed) >= +atomic64_read (&priv->quota); }static inline bool nft_quota_invert (struct nft_quota *priv)
@@ -89,7 +90,7 @@ static int nft_quota_do_init(const struct nlattr * const tb[],return -EOPNOTSUPP ; } - priv->quota = quota; +atomic64_set (&priv->quota, quota); priv->flags = flags;atomic64_set (&priv->consumed, consumed);
@@ -105,10 +106,24 @@ static int nft_quota_obj_init(const struct nft_ctx *ctx,return nft_quota_do_init (tb, priv); } +static int nft_quota_obj_update (struct nft_object *obj, +struct nft_object *newobj) +{ +struct nft_quota *newpriv =nft_obj_data (newobj); +struct nft_quota *priv =nft_obj_data (obj); +u64 newquota; + + newquota =atomic64_read (&newpriv->quota); +atomic64_set (&priv->quota, newquota); + priv->flags = newpriv->flags; + +return 0 ; +} +static int nft_quota_do_dump (struct sk_buff *skb,struct nft_quota *priv,bool reset) { -u64 consumed, consumed_cap; +u64 consumed, consumed_cap, quota;u32 flags = priv->flags;/* Since we inconditionally increment consumed quota for each packet
@@ -116,14 +131,15 @@ static int nft_quota_do_dump(struct sk_buff *skb, struct nft_quota *priv,* userspace. */ consumed =atomic64_read (&priv->consumed); -if (consumed >= priv->quota) { - consumed_cap = priv->quota; + quota =atomic64_read (&priv->quota); +if (consumed >= quota) { + consumed_cap = quota; flags |=NFT_QUOTA_F_DEPLETED ; }else { consumed_cap = consumed; } - if (nla_put_be64(skb, NFTA_QUOTA_BYTES, cpu_to_be64(priv->quota), + if (nla_put_be64(skb, NFTA_QUOTA_BYTES, cpu_to_be64(quota), NFTA_QUOTA_PAD) || nla_put_be64(skb, NFTA_QUOTA_CONSUMED, cpu_to_be64(consumed_cap), NFTA_QUOTA_PAD) ||
@@ -155,6 +171,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
Pablo Neira Ayuso
maintainerRe: [PATCH 2/2 nf-next v3] netfilter: nft_quota: add quota object update support
Also applied, thanks.
Quoted 2 lines · Fernando Fernandez Mancera
This patch adds the infrastructure needed for the stateful object update support.
Applied, thanks.