netfilter: nf_tables: move set netlink messages into the batch
Subsystems (2)
Pablo Neira Ayuso
maintainerRFC PATCH 1/2 netfilter: nf_tables: move set netlink messages into the batch
This patch reworks the nf_tables API so set updates are moved into the same batch that contains rule updates. This speeds up rule-set updates we skip a dialog of four messages between kernel and user-space (two on each direction).
1) create the set and send netlink message to the kernel
2) process the response from the kernel that contains the allocated name.
3) add the set elements and send netlink message to the kernel.
4) process the response from the kernel (to check for errors).
To:
1) add the set to the batch.
2) add the set elements to the batch.
3) add the rule that points to the set.
4) send batch to the kernel.
The idea is to allocate an internal set ID to the batch that can be used when adding set elements and rules that refer to the set in the batch.
Backward compatibility has been only retained in userspace, this means that new nft versions can talk to the kernel both in the new and the old fashion.
---
I'm considering preparing a follow up patch to add tables and chains to the big batch message as well.
include/net/netfilter/nf_tables.h | 2 + include/net/netns/nftables.h | 2 + include/uapi/linux/netfilter/nf_tables.h | 6 ++ net/netfilter/nf_tables_api.c | 124 ++++++++++++++++++++++++++---- net/netfilter/nft_lookup.c | 14 +++- 5 files changed, 130 insertions(+), 18 deletions(-)
include/net/netfilter/nf_tables.h +2 -0
@@ -222,6 +222,8 @@ static inline void *nft_set_priv(const struct nft_set *set)struct nft_set *nf_tables_set_lookup (const struct nft_table *table,const struct nlattr *nla); +struct nft_set *nf_tables_set_lookup2 (const struct net *net, +const struct nlattr *nla);/** * struct nft_set_binding - nf_tables set binding
include/net/netns/nftables.h +2 -0
@@ -8,6 +8,8 @@ struct nft_af_info;struct netns_nftables {struct list_head af_info;struct list_head commit_list; +struct list_head newset_list; +struct list_head delset_list;struct nft_af_info *ipv4;struct nft_af_info *ipv6;struct nft_af_info *inet;
include/uapi/linux/netfilter/nf_tables.h +6 -0
@@ -221,6 +221,7 @@ enum nft_set_flags {* @NFTA_SET_KEY_LEN: key data length (NLA_U32) * @NFTA_SET_DATA_TYPE: mapping data type (NLA_U32) * @NFTA_SET_DATA_LEN: mapping data length (NLA_U32) +* @NFTA_SET_ID: set ID (NLA_U64) */ enum nft_set_attributes {NFTA_SET_UNSPEC ,
@@ -231,6 +232,7 @@ enum nft_set_attributes {NFTA_SET_KEY_LEN ,NFTA_SET_DATA_TYPE ,NFTA_SET_DATA_LEN , +NFTA_SET_ID , __NFTA_SET_MAX };#define NFTA_SET_MAX (__NFTA_SET_MAX - 1)
@@ -266,12 +268,14 @@ enum nft_set_elem_attributes {* @NFTA_SET_ELEM_LIST_TABLE: table of the set to be changed (NLA_STRING) * @NFTA_SET_ELEM_LIST_SET: name of the set to be changed (NLA_STRING) * @NFTA_SET_ELEM_LIST_ELEMENTS: list of set elements (NLA_NESTED: nft_set_elem_attributes) +* @NFTA_SET_ELEM_LIST_SET_ID: set ID (NLA_U64) */ enum nft_set_elem_list_attributes {NFTA_SET_ELEM_LIST_UNSPEC ,NFTA_SET_ELEM_LIST_TABLE ,NFTA_SET_ELEM_LIST_SET ,NFTA_SET_ELEM_LIST_ELEMENTS , +NFTA_SET_ELEM_LIST_SET_ID , __NFTA_SET_ELEM_LIST_MAX };#define NFTA_SET_ELEM_LIST_MAX (__NFTA_SET_ELEM_LIST_MAX - 1)
@@ -457,12 +461,14 @@ enum nft_cmp_attributes {* @NFTA_LOOKUP_SET: name of the set where to look for (NLA_STRING) * @NFTA_LOOKUP_SREG: source register of the data to look for (NLA_U32: nft_registers) * @NFTA_LOOKUP_DREG: destination register (NLA_U32: nft_registers) +* @NFTA_LOOKUP_SET_ID: set ID (NLA_U64) */ enum nft_lookup_attributes {NFTA_LOOKUP_UNSPEC ,NFTA_LOOKUP_SET ,NFTA_LOOKUP_SREG ,NFTA_LOOKUP_DREG , +NFTA_LOOKUP_SET_ID , __NFTA_LOOKUP_MAX };#define NFTA_LOOKUP_MAX (__NFTA_LOOKUP_MAX - 1)
net/netfilter/nf_tables_api.c +110 -14
246 lines not on this page · raw message
net/netfilter/nft_lookup.c +10 -4
@@ -51,13 +51,19 @@ static int nft_lookup_init(const struct nft_ctx *ctx,struct nft_set *set;int err; -if (tb[NFTA_LOOKUP_SET ] ==NULL || +if ((tb[NFTA_LOOKUP_SET ] ==NULL && tb[NFTA_LOOKUP_SET_ID ] ==NULL ) || tb[NFTA_LOOKUP_SREG ] ==NULL )return -EINVAL ; - set =nf_tables_set_lookup (ctx->table, tb[NFTA_LOOKUP_SET ]); -if (IS_ERR (set)) -return PTR_ERR (set); +if (tb[NFTA_LOOKUP_SET_ID ]) { + set =nf_tables_set_lookup2 (ctx->net, tb[NFTA_LOOKUP_SET_ID ]); +if (IS_ERR (set)) +return PTR_ERR (set); + }else { + set =nf_tables_set_lookup (ctx->table, tb[NFTA_LOOKUP_SET ]); +if (IS_ERR (set)) +return PTR_ERR (set); + } priv->sreg =ntohl (nla_get_be32 (tb[NFTA_LOOKUP_SREG ])); err =nft_validate_input_register (priv->sreg);
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerRFC PATCH 2/2 src: add set netlink message to the batch
This patch moves the netlink set messages to the batch that contains the rules. This helps to speed up rule-set restoration time by changing the operational from:
1) create the set message and send it to the kernel.
2) process the response message that contains the allocated name from the kernel.
3) add the set elements and send it to the kernel.
4) process the response message from the kernel indicating the result.
To:
1) add the set to the batch.
2) add the set elements to the batch.
3) add the rule that points to the set.
4) send batch to the kernel.
To achieve this, an internal set ID which is unique to the batch is allocated as suggested by Patrick.
To retain backward compatibility, nft initially guesses if the kernel supports set in batches. Otherwise, it falls back to the previous (slowier) operational.
--- include/mnl.h | 12 ++++ include/netlink.h | 4 ++ include/rule.h | 2 + src/main.c | 2 + src/mnl.c | 130 +++++++++++++++++++++++++++++++++++ src/netlink.c | 173 ++++++++++++++++++++++++++++++++++++++++++++--- src/netlink_linearize.c | 8 +++ 7 files changed, 323 insertions(+), 8 deletions(-)
include/mnl.h +12 -0
@@ -67,4 +67,16 @@ int mnl_nft_setelem_get(struct mnl_socket *nf_sock, struct nft_set *nls);struct nft_ruleset *mnl_nft_ruleset_dump (struct mnl_socket *nf_sock,uint32_t family); + +int mnl_nft_set_batch_add (struct mnl_socket *nf_sock,struct nft_set *nls, +unsigned int flags); +int mnl_nft_set_batch_del (struct mnl_socket *nf_sock,struct nft_set *nls, +unsigned int flags); +int mnl_nft_setelem_batch_add (struct mnl_socket *nf_sock,struct nft_set *nls, +unsigned int flags); +int mnl_nft_setelem_batch_del (struct mnl_socket *nf_sock,struct nft_set *nls, +unsigned int flags); + +bool mnl_set_batch_supported (struct mnl_socket *nf_sock); +#endif /* _NFTABLES_MNL_H_ */
include/netlink.h +4 -0
@@ -30,6 +30,7 @@ struct netlink_ctx {struct set *set;const void *data;uint32_t seqnum; +bool set_batch_supported; };extern struct nft_table *alloc_nft_table (const struct handle *h);
@@ -142,4 +143,7 @@ extern int netlink_io_error(struct netlink_ctx *ctx,extern struct nft_ruleset *netlink_dump_ruleset (struct netlink_ctx *ctx,const struct handle *h,const struct location *loc); + +bool netlink_set_batch_supported (void ); +#endif /* NFTABLES_NETLINK_H */
include/rule.h +2 -0
@@ -12,6 +12,7 @@* @table: table name * @chain: chain name (chains and rules only) * @set: set name (sets only) +* @set_id: set ID (sets only) * @handle: rule handle (rules only) * @position: rule position (rules only) * @comment: human-readable comment (rules only)
@@ -21,6 +22,7 @@ struct handle {const char *table;const char *chain;const char *set; +uint64_t set_id;uint64_t handle;uint64_t position;const char *comment;
src/main.c +2 -0
@@ -170,6 +170,7 @@ static int nft_netlink(struct parser_state *state, struct list_head *msgs)struct mnl_err *err, *tmp;LIST_HEAD (err_list);uint32_t batch_seqnum; +bool set_batch_supported =netlink_set_batch_supported ();int ret =0 ; batch_seqnum =mnl_batch_begin ();
@@ -177,6 +178,7 @@ static int nft_netlink(struct parser_state *state, struct list_head *msgs)memset (&ctx,0 ,sizeof (ctx)); ctx.msgs = msgs; ctx.seqnum = cmd->seqnum =mnl_seqnum_alloc (); + ctx.set_batch_supported = set_batch_supported;init_list_head (&ctx.list); ret =do_command (&ctx, cmd);if (ret <0 )
src/mnl.c +130 -0
145 lines not on this page · raw message
src/netlink.c +165 -8
218 lines not on this page · raw message
src/netlink_linearize.c +8 -0
@@ -129,6 +129,10 @@ static void netlink_gen_map(struct netlink_linearize_ctx *ctx,nft_rule_expr_set_u32 (nle,NFT_EXPR_LOOKUP_DREG , dreg);nft_rule_expr_set_str (nle,NFT_EXPR_LOOKUP_SET , expr->mappings->set->handle.set); +if (expr->mappings->set->handle.set_id) { +nft_rule_expr_set_u64 (nle,NFT_EXPR_LOOKUP_SET_ID , + expr->mappings->set->handle.set_id); + }if (dreg ==NFT_REG_VERDICT )release_register (ctx);
@@ -153,6 +157,10 @@ static void netlink_gen_lookup(struct netlink_linearize_ctx *ctx,nft_rule_expr_set_u32 (nle,NFT_EXPR_LOOKUP_SREG , sreg);nft_rule_expr_set_str (nle,NFT_EXPR_LOOKUP_SET , expr->right->set->handle.set); +if (expr->right->set->handle.set_id) { +nft_rule_expr_set_u64 (nle,NFT_EXPR_LOOKUP_SET_ID , + expr->right->set->handle.set_id); + }release_register (ctx);nft_rule_add_expr (ctx->nlr, nle);
Signature · 1 line
1.7.10.4
include/net/netfilter/nf_tables.h static inline void *nft_set_priv(const struct nft_set *set) · line 226
Quoted 10 lines · Pablo Neira Ayuso
include/net/netfilter/nf_tables.h +2
-0@@ -222,6 +222,8 @@ static inline void *nft_set_priv(const struct nft_set *set)struct nft_set *nf_tables_set_lookup (const struct nft_table *table,const struct nlattr *nla); +struct nft_set *nf_tables_set_lookup2 (const struct net *net, +const struct nlattr *nla);
nf_tables_set_lookup_byid?
include/uapi/linux/netfilter/nf_tables.h enum nft_set_flags { · line 224
Quoted 9 lines
include/uapi/linux/netfilter/nf_tables.h +1
-0@@ -221,6 +221,7 @@ enum nft_set_flags {* @NFTA_SET_KEY_LEN: key data length (NLA_U32) * @NFTA_SET_DATA_TYPE: mapping data type (NLA_U32) * @NFTA_SET_DATA_LEN: mapping data length (NLA_U32) +* @NFTA_SET_ID: set ID (NLA_U64)
I think a U32 should be perfectly fine. These are not permanent IDs but just to identify new sets contained within a batch, so we can always start at 0.
include/uapi/linux/netfilter/nf_tables.h enum nft_set_flags {
Quoted 6 lines
include/uapi/linux/netfilter/nf_tables.h +6
-0+static int nf_tables_set_trans_add (struct list_head *list,struct nft_ctx *ctx, +struct nft_set *set) +{ +struct nft_set_trans *strans; + + strans =kmalloc (sizeof (struct nft_set_trans ),GFP_ATOMIC );
Do we need GFP_ATOMIC?
Quoted 18 lines
include/uapi/linux/netfilter/nf_tables.h +13
-0+if (strans ==NULL ) +return -ENOMEM ; + + strans->set = set; + strans->ctx = *ctx; +if (ctx->nla[NFTA_SET_ID ]) + strans->id =be64_to_cpu (nla_get_be64 (ctx->nla[NFTA_SET_ID ])); + + set->flags |= __NFT_SET_INACTIVE; +list_add_tail (&strans->list, list); +return 0 ; +} + static int nf_tables_newset(struct sock *nlsk, struct sk_buff *skb, const struct nlmsghdr *nlh, const struct nlattr * const nla[]) static int nf_tables_bind_check_setelem(const struct nft_ctx *ctx,
include/uapi/linux/netfilter/nf_tables.h void nf_tables_unbind_set(const struct nft_ctx *ctx, struct nft_set *set, · line 2623
Quoted 6 lines
include/uapi/linux/netfilter/nf_tables.h +2
-1@@ -2534,7 +2619,8 @@ void nf_tables_unbind_set(const struct nft_ctx *ctx, struct nft_set *set, {list_del (&binding->list); -if (list_empty (&set->bindings) && set->flags &NFT_SET_ANONYMOUS ) +if (list_empty (&set->bindings) && set->flags &NFT_SET_ANONYMOUS && + !(set->flags & __NFT_SET_INACTIVE))
Why are we not destroying anonymous inactive sets when unbinding? This means we're either aborting or replaying the entire transaction, so it seems we should remove them, no?
Quoted 3 lines
include/uapi/linux/netfilter/nf_tables.h +0
-0nf_tables_set_destroy (ctx, set); }
Pablo Neira Ayuso
maintainerQuoted 7 lines · Patrick McHardy
Quoted 6 lines · Pablo Neira Ayuso
include/net/netfilter/nf_tables.h +0
-0@@ -222,6 +222,8 @@ static inline void *nft_set_priv(const struct nft_set *set)
Quoted 6 lines
include/net/netfilter/nf_tables.h static inline void *nft_set_priv(const struct nft_set *set) · line 226
Quoted 4 lines
include/net/netfilter/nf_tables.h +2
-0struct nft_set *nf_tables_set_lookup (const struct nft_table *table,const struct nlattr *nla); +struct nft_set *nf_tables_set_lookup2 (const struct net *net, +const struct nlattr *nla);
nf_tables_set_lookup_byid?
That looks better.
Quoted 4 lines
Quoted 4 lines
include/uapi/linux/netfilter/nf_tables.h +0
-0
Quoted 8 lines
include/uapi/linux/netfilter/nf_tables.h enum nft_set_flags { · line 224
Quoted 5 lines
include/uapi/linux/netfilter/nf_tables.h +1
-0@@ -221,6 +221,7 @@ enum nft_set_flags {* @NFTA_SET_KEY_LEN: key data length (NLA_U32) * @NFTA_SET_DATA_TYPE: mapping data type (NLA_U32) * @NFTA_SET_DATA_LEN: mapping data length (NLA_U32) +* @NFTA_SET_ID: set ID (NLA_U64) I think a U32 should be perfectly fine. These are not permanent IDs but just to identify new sets contained within a batch, so we can always start at 0.
Yes, I was considering using this also to output the set identifier for anonymous sets, but the dynamically allocated name should be fine so I'll stick to u32.
Going back to the idea of using u64 to allocate the set/map names, I think we have to extend the set name, currently IFNAMSIZ is limited when mapping the name to set%lld, assuming a large u64 number.
Quoted 8 lines
include/uapi/linux/netfilter/nf_tables.h enum nft_set_flags {
Quoted 6 lines
include/uapi/linux/netfilter/nf_tables.h +6
-0+static int nf_tables_set_trans_add (struct list_head *list,struct nft_ctx *ctx, +struct nft_set *set) +{ +struct nft_set_trans *strans; + + strans =kmalloc (sizeof (struct nft_set_trans ),GFP_ATOMIC );Do we need
GFP_ATOMIC?
not really, will swap that to GFP_KERNEL.
Quoted 21 lines
Quoted 21 lines
include/uapi/linux/netfilter/nf_tables.h +13
-0+if (strans ==NULL ) +return -ENOMEM ; + + strans->set = set; + strans->ctx = *ctx; +if (ctx->nla[NFTA_SET_ID ]) + strans->id =be64_to_cpu (nla_get_be64 (ctx->nla[NFTA_SET_ID ])); + + set->flags |= __NFT_SET_INACTIVE; +list_add_tail (&strans->list, list); +return 0 ; +} + static int nf_tables_newset(struct sock *nlsk, struct sk_buff *skb, const struct nlmsghdr *nlh, const struct nlattr * const nla[]) static int nf_tables_bind_check_setelem(const struct nft_ctx *ctx,@@ -2534,7 +2619,8 @@ void nf_tables_unbind_set(const struct nft_ctx *ctx, struct nft_set *set, {list_del (&binding->list);
Quoted 7 lines
include/uapi/linux/netfilter/nf_tables.h void nf_tables_unbind_set(const struct nft_ctx *ctx, struct nft_set *set, · line 2623
Quoted 3 lines
include/uapi/linux/netfilter/nf_tables.h +2
-1-if (list_empty (&set->bindings) && set->flags &NFT_SET_ANONYMOUS ) +if (list_empty (&set->bindings) && set->flags &NFT_SET_ANONYMOUS && + !(set->flags & __NFT_SET_INACTIVE))Why are we not destroying anonymous inactive sets when unbinding? This means we're either aborting or replaying the entire transaction, so it seems we should remove them, no?
The set may be already bound to the rule, we skip this here, so the set is released from the transaction. This is just to avoid a double free case.
Quoted 3 lines
Quoted 3 lines
include/uapi/linux/netfilter/nf_tables.h +0
-0nf_tables_set_destroy (ctx, set); }
Quoted 16 lines · Pablo Neira Ayuso
Quoted 14 lines · Patrick McHardy
include/uapi/linux/netfilter/nf_tables.h enum nft_set_flags { · line 224
Quoted 9 lines · Pablo Neira Ayuso
include/uapi/linux/netfilter/nf_tables.h +1
-0@@ -221,6 +221,7 @@ enum nft_set_flags {* @NFTA_SET_KEY_LEN: key data length (NLA_U32) * @NFTA_SET_DATA_TYPE: mapping data type (NLA_U32) * @NFTA_SET_DATA_LEN: mapping data length (NLA_U32) +* @NFTA_SET_ID: set ID (NLA_U64) I think a U32 should be perfectly fine. These are not permanent IDs but just to identify new sets contained within a batch, so we can always start at 0.
Quoted 3 lines
Yes, I was considering using this also to output the set identifier for anonymous sets, but the dynamically allocated name should be fine so I'll stick to u32.
I think these are two different things. The set identifier is so far actually a transaction identifier, mixing these will most likely get messy.
Quoted 3 lines
Going back to the idea of using u64 to allocate the set/map names, I think we have to extend the set name, currently IFNAMSIZ is limited when mapping the name to set%lld, assuming a large u64 number.
The problem is more that this ID is chosen by userspace, so it's not suitable for anonymous sets. I'd rather get rid of the names for anonymous sets completely. For dumps we can just as well use a dynamic numeric identifier to associate lookup expressions with sets. We don't really need a permanent identifier.
Quoted 12 lines
Quoted 11 lines
include/uapi/linux/netfilter/nf_tables.h void nf_tables_unbind_set(const struct nft_ctx *ctx, struct nft_set *set, · line 2623
Quoted 7 lines
include/uapi/linux/netfilter/nf_tables.h +2
-1@@ -2534,7 +2619,8 @@ void nf_tables_unbind_set(const struct nft_ctx *ctx, struct nft_set *set, {list_del (&binding->list); -if (list_empty (&set->bindings) && set->flags &NFT_SET_ANONYMOUS ) +if (list_empty (&set->bindings) && set->flags &NFT_SET_ANONYMOUS && + !(set->flags & __NFT_SET_INACTIVE))Why are we not destroying anonymous inactive sets when unbinding? This means we're either aborting or replaying the entire transaction, so it seems we should remove them, no?
Quoted 3 lines
The set may be already bound to the rule, we skip this here, so the set is released from the transaction. This is just to avoid a double free case.
I have to read the patch again, I was under the impression that a bound set has already been comitted and we therefore won't fail anymore. Probably misunderstood something.
Pablo Neira Ayuso
maintainerQuoted 24 lines · Patrick McHardy
Quoted 16 lines · Pablo Neira Ayuso
Quoted 14 lines · Patrick McHardy
include/uapi/linux/netfilter/nf_tables.h enum nft_set_flags { · line 224
Quoted 9 lines · Pablo Neira Ayuso
include/uapi/linux/netfilter/nf_tables.h +1
-0@@ -221,6 +221,7 @@ enum nft_set_flags {* @NFTA_SET_KEY_LEN: key data length (NLA_U32) * @NFTA_SET_DATA_TYPE: mapping data type (NLA_U32) * @NFTA_SET_DATA_LEN: mapping data length (NLA_U32) +* @NFTA_SET_ID: set ID (NLA_U64) I think a U32 should be perfectly fine. These are not permanent IDs but just to identify new sets contained within a batch, so we can always start at 0.
Quoted 3 lines
Yes, I was considering using this also to output the set identifier for anonymous sets, but the dynamically allocated name should be fine so I'll stick to u32.
I think these are two different things. The set identifier is so far actually a transaction identifier, mixing these will most likely get messy.
Quoted 6 lines
Quoted 3 lines
Going back to the idea of using u64 to allocate the set/map names, I think we have to extend the set name, currently IFNAMSIZ is limited when mapping the name to set%lld, assuming a large u64 number.
The problem is more that this ID is chosen by userspace, so it's not suitable for anonymous sets.
I was not considering to use the ID allocated from userspace, but reusing the NFTA_SET_ID attribute given that it is only used for messages from userspace -> kernel, so we can reuse it when dumping the anonymous set to userspace, but that's two different things with different semantics, so better to have two different attributes for each, eg. NFTA_SET_ID_ANONYMOUS?
Quoted 4 lines
I'd rather get rid of the names for anonymous sets completely. For dumps we can just as well use a dynamic numeric identifier to associate lookup expressions with sets. We don't really need a permanent identifier.
How will that look like? I think we need some permanent way to identify sets even if they are anonymous. A permanent ID should be fine for that.
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
include/uapi/linux/netfilter/nf_tables.h void nf_tables_unbind_set(const struct nft_ctx *ctx, struct nft_set *set, · line 2623
Quoted 7 lines
include/uapi/linux/netfilter/nf_tables.h +2
-1@@ -2534,7 +2619,8 @@ void nf_tables_unbind_set(const struct nft_ctx *ctx, struct nft_set *set, {list_del (&binding->list); -if (list_empty (&set->bindings) && set->flags &NFT_SET_ANONYMOUS ) +if (list_empty (&set->bindings) && set->flags &NFT_SET_ANONYMOUS && + !(set->flags & __NFT_SET_INACTIVE))Why are we not destroying anonymous inactive sets when unbinding? This means we're either aborting or replaying the entire transaction, so it seems we should remove them, no?
Quoted 7 lines
Quoted 3 lines
The set may be already bound to the rule, we skip this here, so the set is released from the transaction. This is just to avoid a double free case.
I have to read the patch again, I was under the impression that a bound set has already been comitted and we therefore won't fail anymore. Probably misunderstood something.
Think of the abort step. We already have some rules bound to the set (not yet committed), but we failed to load some rule, we need to release those rules and their set bindings. In that case, the rule destroy path skips releasing the set, so we just let the abort routine to iterate over the list of new sets to releasing.
Quoted 22 lines · Pablo Neira Ayuso
Quoted 14 lines · Patrick McHardy
Quoted 9 lines · Pablo Neira Ayuso
Quoted 4 lines · Patrick McHardy
On Tue, Mar 25, 2014 at 09:39:41PM +0100, Pablo Neira Ayuso wrote:
I think a U32 should be perfectly fine. These are not permanent IDs but just to identify new sets contained within a batch, so we can always start at 0.
Yes, I was considering using this also to output the set identifier for anonymous sets, but the dynamically allocated name should be fine so I'll stick to u32.
I think these are two different things. The set identifier is so far actually a transaction identifier, mixing these will most likely get messy.
Quoted 6 lines
Quoted 3 lines
Going back to the idea of using u64 to allocate the set/map names, I think we have to extend the set name, currently IFNAMSIZ is limited when mapping the name to set%lld, assuming a large u64 number.
The problem is more that this ID is chosen by userspace, so it's not suitable for anonymous sets.
Quoted 6 lines
I was not considering to use the ID allocated from userspace, but reusing the
NFTA_SET_IDattribute given that it is only used for messages from userspace -> kernel, so we can reuse it when dumping the anonymous set to userspace, but that's two different things with different semantics, so better to have two different attributes for each, eg.NFTA_SET_ID_ANONYMOUS?
Actually that one would probably be fine. In both cases it would be used in a very similar fashion, a temporary identifier or transaction ID.
Quoted 8 lines
Quoted 4 lines
I'd rather get rid of the names for anonymous sets completely. For dumps we can just as well use a dynamic numeric identifier to associate lookup expressions with sets. We don't really need a permanent identifier.
How will that look like? I think we need some permanent way to identify sets even if they are anonymous. A permanent ID should be fine for that.
Well it depends. Right now we have anonymous sets, meaning an ID is allocated, but they're only used in combination with constant sets, which means they can not be changed so we don't need a permanent ID. If we were to use anonymous in combination with non-const then yes, we need a permanent ID.
In either case the numeric ID is fine, the question is simply whether it needs to be a permanent ID or whether a temoprary one is enough.
Quoted 20 lines
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
net/netfilter/nf_tables_api.c void nf_tables_unbind_set(const struct nft_ctx *ctx, struct nft_set *set, · line 2623
Quoted 7 lines
net/netfilter/nf_tables_api.c +2
-1@@ -2534,7 +2619,8 @@ void nf_tables_unbind_set(const struct nft_ctx *ctx, struct nft_set *set, {list_del (&binding->list); -if (list_empty (&set->bindings) && set->flags &NFT_SET_ANONYMOUS ) +if (list_empty (&set->bindings) && set->flags &NFT_SET_ANONYMOUS && + !(set->flags & __NFT_SET_INACTIVE))Why are we not destroying anonymous inactive sets when unbinding? This means we're either aborting or replaying the entire transaction, so it seems we should remove them, no?
Quoted 7 lines
Quoted 3 lines
The set may be already bound to the rule, we skip this here, so the set is released from the transaction. This is just to avoid a double free case.
I have to read the patch again, I was under the impression that a bound set has already been comitted and we therefore won't fail anymore. Probably misunderstood something.
Quoted 5 lines
Think of the abort step. We already have some rules bound to the set (not yet committed), but we failed to load some rule, we need to release those rules and their set bindings. In that case, the rule destroy path skips releasing the set, so we just let the abort routine to iterate over the list of new sets to releasing.
So we do bind to uncommitted sets? That's the part I was missing.
Pablo Neira Ayuso
maintainerQuoted 30 lines · Patrick McHardy
Quoted 22 lines · Pablo Neira Ayuso
Quoted 14 lines · Patrick McHardy
Quoted 9 lines · Pablo Neira Ayuso
Quoted 4 lines · Patrick McHardy
On Tue, Mar 25, 2014 at 09:39:41PM +0100, Pablo Neira Ayuso wrote:
I think a U32 should be perfectly fine. These are not permanent IDs but just to identify new sets contained within a batch, so we can always start at 0.
Yes, I was considering using this also to output the set identifier for anonymous sets, but the dynamically allocated name should be fine so I'll stick to u32.
I think these are two different things. The set identifier is so far actually a transaction identifier, mixing these will most likely get messy.
Quoted 6 lines
Quoted 3 lines
Going back to the idea of using u64 to allocate the set/map names, I think we have to extend the set name, currently IFNAMSIZ is limited when mapping the name to set%lld, assuming a large u64 number.
The problem is more that this ID is chosen by userspace, so it's not suitable for anonymous sets.
Quoted 6 lines
I was not considering to use the ID allocated from userspace, but reusing the
NFTA_SET_IDattribute given that it is only used for messages from userspace -> kernel, so we can reuse it when dumping the anonymous set to userspace, but that's two different things with different semantics, so better to have two different attributes for each, eg.NFTA_SET_ID_ANONYMOUS?
Quoted 2 lines
Actually that one would probably be fine. In both cases it would be used in a very similar fashion, a temporary identifier or transaction ID.
Ok, then I'm going to leave the u64 NFTA_SET_ID there so we can reuse it later on for the dumping. Let me know if I misinterpreted your comment.
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
I'd rather get rid of the names for anonymous sets completely. For dumps we can just as well use a dynamic numeric identifier to associate lookup expressions with sets. We don't really need a permanent identifier.
Quoted 8 lines
Quoted 3 lines
How will that look like? I think we need some permanent way to identify sets even if they are anonymous. A permanent ID should be fine for that.
Well it depends. Right now we have anonymous sets, meaning an ID is allocated, but they're only used in combination with constant sets, which means they can not be changed so we don't need a permanent ID. If we were to use anonymous in combination with non-const then yes, we need a permanent ID.
I see, for const + anonymous it doesn't make much sense as userspace can just barely fetch them, but not update them.
Quoted 2 lines
In either case the numeric ID is fine, the question is simply whether it needs to be a permanent ID or whether a temoprary one is enough.
Hm, perhaps we may add statistics per element in the future or any other feature that alters some internal state of the element. The user can fetch the set ID from the rule and then keep using it to retrieve that that internal state using the permanent ID.
Quoted 20 lines
Quoted 20 lines
Quoted 19 lines
Quoted 12 lines
Quoted 11 lines
net/netfilter/nf_tables_api.c void nf_tables_unbind_set(const struct nft_ctx *ctx, struct nft_set *set, · line 2623
Quoted 7 lines
net/netfilter/nf_tables_api.c +2
-1@@ -2534,7 +2619,8 @@ void nf_tables_unbind_set(const struct nft_ctx *ctx, struct nft_set *set, {list_del (&binding->list); -if (list_empty (&set->bindings) && set->flags &NFT_SET_ANONYMOUS ) +if (list_empty (&set->bindings) && set->flags &NFT_SET_ANONYMOUS && + !(set->flags & __NFT_SET_INACTIVE))Why are we not destroying anonymous inactive sets when unbinding? This means we're either aborting or replaying the entire transaction, so it seems we should remove them, no?
Quoted 3 lines
The set may be already bound to the rule, we skip this here, so the set is released from the transaction. This is just to avoid a double free case.
I have to read the patch again, I was under the impression that a bound set has already been comitted and we therefore won't fail anymore. Probably misunderstood something.
Quoted 7 lines
Quoted 5 lines
Think of the abort step. We already have some rules bound to the set (not yet committed), but we failed to load some rule, we need to release those rules and their set bindings. In that case, the rule destroy path skips releasing the set, so we just let the abort routine to iterate over the list of new sets to releasing.
So we do bind to uncommitted sets? That's the part I was missing.
Right. That simplifies the error handling as no errors can currently happen in the nf_tables_commit() step, so we don't need to undo changes that were already applied because of errors which would be tricky.