netfilter: nf_tables: add generation mask to table objects
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH 1/3 netfilter: nf_tables: add generation mask to table objects
The dumping of table objects can be inconsistent when interfering with the preparation phase of our 2-phase commit protocol because:
1) We remove objects from the lists during the preparation phase, that can be added re-added from the abort step. Thus, we may miss objects that are still active.
2) We add new objects to the lists during the preparation phase, so we may get objects that are not yet active with an internal flag set.
We can resolve this problem with generation masks, as we already do for rules when we expose them to the packet path.
After this change, we always obtain a consistent list as long as we stay in the same generation. The userspace side can detect interferences through the generation counter. If so, it needs to restart.
As a result, we can get rid of the internal NFT_TABLE_INACTIVE flag.
--- include/net/netfilter/nf_tables.h | 4 +- net/netfilter/nf_tables_api.c | 104 ++++++++++++++++++++++++------------- 2 files changed, 71 insertions(+), 37 deletions(-)
include/net/netfilter/nf_tables.h +3 -1
@@ -827,6 +827,7 @@ unsigned int nft_do_chain(struct nft_pktinfo *pkt,* @hgenerator: handle generator state * @use: number of chain references to this table * @flags: table flag (see enum nft_table_flags) +* @genmask: generation mask * @name: name of the table */ struct nft_table {
@@ -835,7 +836,8 @@ struct nft_table {struct list_head sets;u64 hgenerator;u32 use; -u16 flags; + u16 flags:14, + genmask:2;char name[NFT_TABLE_MAXNAMELEN ]; };
net/netfilter/nf_tables_api.c +68 -36
270 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 2/3 netfilter: nf_tables: add generation mask to chain objects
Use the generation mask approach to obtain a consistent list of chain objects from netlink dump commands.
Get rid of the internal NFT_CHAIN_INACTIVE flag.
--- include/net/netfilter/nf_tables.h | 5 +- net/netfilter/nf_tables_api.c | 96 +++++++++++++++++++++++++++---------- 2 files changed, 75 insertions(+), 26 deletions(-)
include/net/netfilter/nf_tables.h +3 -2
@@ -717,7 +717,6 @@ static inline struct nft_userdata *nft_userdata(const struct nft_rule *rule)enum nft_chain_flags {NFT_BASE_CHAIN =0x1 , -NFT_CHAIN_INACTIVE =0x2 , };/**
@@ -730,6 +729,7 @@ enum nft_chain_flags {* @use: number of jump references to this chain * @level: length of longest path to this chain * @flags: bitmask of enum nft_chain_flags +* @genmask: generation mask * @name: name of the chain */ struct nft_chain {
@@ -739,7 +739,8 @@ struct nft_chain {u64 handle;u32 use;u16 level; -u8 flags; + u8 flags:6, + genmask:2;char name[NFT_CHAIN_MAXNAMELEN ]; };
net/netfilter/nf_tables_api.c +72 -24
211 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 3/3 netfilter: nf_tables: add generation mask to set objects
In reply to Pablo Neira AyusoUse the generation mask approach to obtain a consistent list of set objects from netlink dump commands.
Get rid of the internal NFT_SET_INACTIVE flag.
--- include/net/netfilter/nf_tables.h | 4 ++- net/netfilter/nf_tables_api.c | 54 ++++++++++++++++++++++++++++--------- 2 files changed, 44 insertions(+), 14 deletions(-)
include/net/netfilter/nf_tables.h +3 -1
@@ -295,6 +295,7 @@ void nft_unregister_set(struct nft_set_ops *ops);* @ops: set ops * @pnet: network namespace * @flags: set flags +* @genmask: generation mask * @klen: key length * @dlen: data length * @data: private set data
@@ -314,7 +315,8 @@ struct nft_set {/* runtime data below here */ const struct nft_set_ops *ops____cacheline_aligned ;possible_net_t pnet; -u16 flags; + u16 flags:14, + genmask:2;u8 klen;u8 dlen;unsigned char data[]
net/netfilter/nf_tables_api.c +41 -13
126 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Re: [PATCH nf-next 3/3] netfilter: nf_tables: add generation mask to set objects
net/netfilter/nf_tables_api.c static int nft_delrule_by_chain(struct nft_ctx *ctx) · line 384
Quoted 6 lines · Pablo Neira Ayuso
net/netfilter/nf_tables_api.c +5
-1-#define NFT_SET_INACTIVE (1 << 15) +static inline bool +nft_set_is_active (struct net *net,const struct nft_set *set) +{ +return (set->genmask &nft_genmask_cur (net)) ==0 ; +}
Do we really want this set of basic functions for every object type? There will still be cases where we need to open code the checks anyway, f.i. iterators and callbacks.
Pablo Neira Ayuso
maintainerRe: [PATCH nf-next 3/3] netfilter: nf_tables: add generation mask to set objects
Quoted 11 lines · Patrick McHardy
net/netfilter/nf_tables_api.c static int nft_delrule_by_chain(struct nft_ctx *ctx) · line 384
Quoted 6 lines · Pablo Neira Ayuso
net/netfilter/nf_tables_api.c +5
-1-#define NFT_SET_INACTIVE (1 << 15) +static inline bool +nft_set_is_active (struct net *net,const struct nft_set *set) +{ +return (set->genmask &nft_genmask_cur (net)) ==0 ; +}Do we really want this set of basic functions for every object type? There will still be cases where we need to open code the checks anyway, f.i. iterators and callbacks.
We can have a macro thing instead at some point.
Re: [PATCH nf-next 3/3] netfilter: nf_tables: add generation mask to set objects
In reply to Pablo Neira AyusoQuoted 4 lines · Pablo Neira Ayuso
Use the generation mask approach to obtain a consistent list of set objects from netlink dump commands.
Get rid of the internal
NFT_SET_INACTIVEflag.
In this case I don't see how deletion and creation in the same batch will work at all since we don't check any active bits in nf_tables_newset().
We also have the problem that f.i. delset checks for activeness in the current instead of the next generation.
Pablo Neira Ayuso
maintainerRe: [PATCH nf-next 3/3] netfilter: nf_tables: add generation mask to set objects
Quoted 9 lines · Patrick McHardy
Quoted 4 lines · Pablo Neira Ayuso
Use the generation mask approach to obtain a consistent list of set objects from netlink dump commands.
Get rid of the internal
NFT_SET_INACTIVEflag.In this case I don't see how deletion and creation in the same batch will work at all since we don't check any active bits in
nf_tables_newset().
Right, the update of nf_tables_set_lookup() is missing.
Quoted 2 lines
We also have the problem that f.i. delset checks for activeness in the current instead of the next generation.
I guess you refer to the same problem I'm discussing in the other thread, right? As I said, this checking for add+delete in the same batch.
Quoted 10 lines · Pablo Neira Ayuso
The dumping of table objects can be inconsistent when interfering with the preparation phase of our 2-phase commit protocol because:
1) We remove objects from the lists during the preparation phase, that can be added re-added from the abort step. Thus, we may miss objects that are still active.
2) We add new objects to the lists during the preparation phase, so we may get objects that are not yet active with an internal flag set.
Quoted 8 lines
We can resolve this problem with generation masks, as we already do for rules when we expose them to the packet path.
After this change, we always obtain a consistent list as long as we stay in the same generation. The userspace side can detect interferences through the generation counter. If so, it needs to restart.
As a result, we can get rid of the internal
NFT_TABLE_INACTIVEflag.
I have a similar patch queued up, however there seems to be something missing in this patch. The lookup functions need to take the genmask into account. Otherwise you can not delete and add a new table in the same batch. The same holds for all other object types.
Quoted 8 lines
net/netfilter/nf_tables_api.c +4
-0+static struct nft_table *nf_tables_table_lookup (struct net *net, +const struct nft_af_info *afi, +const struct nlattr *nla, +bool trans) {struct nft_table *table;
net/netfilter/nf_tables_api.c static struct nft_table *nf_tables_table_lookup(const struct nft_af_info *afi, · line 415
Quoted 7 lines
net/netfilter/nf_tables_api.c +2
-2@@ -382,10 +411,10 @@ static struct nft_table *nf_tables_table_lookup(const struct nft_af_info *afi,return ERR_PTR (-EINVAL ); table =nft_table_lookup (afi, nla); -if (table !=NULL ) -return table; +if (table ==NULL || (trans && !nft_table_is_active_next (net, table))) +return ERR_PTR (-ENOENT );
We really need to check the genid itself, in some cases we *only* want currently active tables, f.i. gettable and dumps.
Pablo Neira Ayuso
maintainerQuoted 14 lines · Patrick McHardy
Quoted 13 lines · Pablo Neira Ayuso
The dumping of table objects can be inconsistent when interfering with the preparation phase of our 2-phase commit protocol because:
1) We remove objects from the lists during the preparation phase, that can be added re-added from the abort step. Thus, we may miss objects that are still active.
2) We add new objects to the lists during the preparation phase, so we may get objects that are not yet active with an internal flag set.
We can resolve this problem with generation masks, as we already do for rules when we expose them to the packet path.
Quoted 8 lines
Quoted 5 lines
After this change, we always obtain a consistent list as long as we stay in the same generation. The userspace side can detect interferences through the generation counter. If so, it needs to restart.
As a result, we can get rid of the internal
NFT_TABLE_INACTIVEflag.I have a similar patch queued up, however there seems to be something missing in this patch. The lookup functions need to take the genmask into account.
They already do for the deletion case, so we hit -ENOENT for objects that has been deleted in this batch, so we cannot delete objects twice.
Quoted 2 lines
Otherwise you can not delete and add a new table in the same batch. The same holds for all other object types.
I can with this patch, we always operate with the *next* bit to indicate that the object will be inactive in the future.
Quoted 10 lines
Quoted 10 lines
net/netfilter/nf_tables_api.c +4
-0+static struct nft_table *nf_tables_table_lookup (struct net *net, +const struct nft_af_info *afi, +const struct nlattr *nla, +bool trans) {struct nft_table *table;@@ -382,10 +411,10 @@ static struct nft_table *nf_tables_table_lookup(const struct nft_af_info *afi,return ERR_PTR (-EINVAL );
Quoted 8 lines
net/netfilter/nf_tables_api.c static struct nft_table *nf_tables_table_lookup(const struct nft_af_info *afi, · line 415
Quoted 5 lines
net/netfilter/nf_tables_api.c +2
-2table =nft_table_lookup (afi, nla); -if (table !=NULL ) -return table; +if (table ==NULL || (trans && !nft_table_is_active_next (net, table))) +return ERR_PTR (-ENOENT );We really need to check the genid itself, in some cases we *only* want currently active tables, f.i. gettable and dumps.
This is what this patch is doing from the dump path.
We shouldn't check if the object is active from the lookup function if we're in the middle of a transaction, since we hold the lock there is no way we can see inactive objects in the list. There's only one transaction at the same time.
Quoted 29 lines · Pablo Neira Ayuso
Quoted 14 lines · Patrick McHardy
Quoted 13 lines · Pablo Neira Ayuso
The dumping of table objects can be inconsistent when interfering with the preparation phase of our 2-phase commit protocol because:
1) We remove objects from the lists during the preparation phase, that can be added re-added from the abort step. Thus, we may miss objects that are still active.
2) We add new objects to the lists during the preparation phase, so we may get objects that are not yet active with an internal flag set.
We can resolve this problem with generation masks, as we already do for rules when we expose them to the packet path.
Quoted 8 lines
Quoted 5 lines
After this change, we always obtain a consistent list as long as we stay in the same generation. The userspace side can detect interferences through the generation counter. If so, it needs to restart.
As a result, we can get rid of the internal
NFT_TABLE_INACTIVEflag.I have a similar patch queued up, however there seems to be something missing in this patch. The lookup functions need to take the genmask into account.
They already do for the deletion case, so we hit
-ENOENTfor objects that has been deleted in this batch, so we cannot delete objects twice.
net/netfilter/nf_tables_api.c static int nf_tables_deltable(struct sock *nlsk, struct sk_buff *skb, · line 866
Quoted 9 lines
net/netfilter/nf_tables_api.c +2
-2@@ -829,10 +860,10 @@ static int nf_tables_deltable(struct sock *nlsk, struct sk_buff *skb,if (IS_ERR (afi))return PTR_ERR (afi); - table =nf_tables_table_lookup (afi, nla[NFTA_TABLE_NAME ]); + table =nf_tables_table_lookup (net, afi, nla[NFTA_TABLE_NAME ], true);if (IS_ERR (table))return PTR_ERR (table); -if (table->flags &NFT_TABLE_INACTIVE ) +if (!nft_table_is_active (net, table))
return -ENOENT;
Looking at it, that part seems wrong. They need to be active in the *next* generation, not the current one, to be deleted. All netlink actions only affect the next generation.
The same bug is present in multiple locations.
Quoted 25 lines
Quoted 2 lines
Otherwise you can not delete and add a new table in the same batch. The same holds for all other object types.
I can with this patch, we always operate with the *next* bit to indicate that the object will be inactive in the future.
Quoted 10 lines
Quoted 10 lines
net/netfilter/nf_tables_api.c +4
-0+static struct nft_table *nf_tables_table_lookup (struct net *net, +const struct nft_af_info *afi, +const struct nlattr *nla, +bool trans) {struct nft_table *table;@@ -382,10 +411,10 @@ static struct nft_table *nf_tables_table_lookup(const struct nft_af_info *afi,return ERR_PTR (-EINVAL );Quoted 8 lines
net/netfilter/nf_tables_api.c static struct nft_table *nf_tables_table_lookup(const struct nft_af_info *afi, · line 415
Quoted 5 lines
net/netfilter/nf_tables_api.c +2
-2table =nft_table_lookup (afi, nla); -if (table !=NULL ) -return table; +if (table ==NULL || (trans && !nft_table_is_active_next (net, table))) +return ERR_PTR (-ENOENT );We really need to check the genid itself, in some cases we *only* want currently active tables, f.i. gettable and dumps.
Quoted 6 lines
This is what this patch is doing from the dump path.
We shouldn't check if the object is active from the lookup function if we're in the middle of a transaction, since we hold the lock there is no way we can see inactive objects in the list. There's only one transaction at the same time.
That's not entirely correct. Dump continuations happen asynchronously to netlink modifications and commit operations, so the genid may bump in the middle. We can get an inconsistent view if we have:
dump set elements from set x table y
delete table y
create table y
create set x
begin commit
continue dump from new set
commit, send NEWGEN
Sure, we will get a NEWGEN message, but at that time we might already have sent a full message for the new table/set since that message is only send after the commit is completed.
Pablo Neira Ayuso
maintainerQuoted 2 lines · Patrick McHardy
Quoted 1 line · Pablo Neira Ayuso
On Tue, Aug 04, 2015 at 11:09:17AM +0200, Patrick McHardy wrote:
[...]
Quoted 19 lines
Quoted 8 lines
Quoted 2 lines
I have a similar patch queued up, however there seems to be something missing in this patch. The lookup functions need to take the genmask into account.
They already do for the deletion case, so we hit
-ENOENTfor objects that has been deleted in this batch, so we cannot delete objects twice.net/netfilter/nf_tables_api.c static int nf_tables_deltable(struct sock *nlsk, struct sk_buff *skb, · line 866
Quoted 9 lines
net/netfilter/nf_tables_api.c +2
-2@@ -829,10 +860,10 @@ static int nf_tables_deltable(struct sock *nlsk, struct sk_buff *skb,if (IS_ERR (afi))return PTR_ERR (afi); - table =nf_tables_table_lookup (afi, nla[NFTA_TABLE_NAME ]); + table =nf_tables_table_lookup (net, afi, nla[NFTA_TABLE_NAME ], true);if (IS_ERR (table))return PTR_ERR (table); -if (table->flags &NFT_TABLE_INACTIVE ) +if (!nft_table_is_active (net, table))return -ENOENT;
Quoted 5 lines
Looking at it, that part seems wrong. They need to be active in the *next* generation, not the current one, to be deleted. All netlink actions only affect the next generation.
The same bug is present in multiple locations.
That check is there to avoid the deletion of a table that has been added in this batch, unlike the delete + add, the add + delete in the same batch doesn't make much sense.
Revisiting this scenario, this how this looks if we remove that check:
preparation starts:
add: table X (10), added to table list (now inactive)
del: table X (11), inactive next.
^
gencursorcommit starts (update gencursor):
add: table X (01): clear past and report event, *NOTE*: the rule table is inactive.
add: table X (01): delete from list and report event.
^
gencursorSo it seems it should be fine to remove it as it is defensive. I think robots can generate this kind of command placing updates in a batch, anyway that should come in a follow up patch IMO.
Quoted 36 lines
Quoted 25 lines
Quoted 2 lines
Otherwise you can not delete and add a new table in the same batch. The same holds for all other object types.
I can with this patch, we always operate with the *next* bit to indicate that the object will be inactive in the future.
Quoted 10 lines
Quoted 10 lines
net/netfilter/nf_tables_api.c +4
-0+static struct nft_table *nf_tables_table_lookup (struct net *net, +const struct nft_af_info *afi, +const struct nlattr *nla, +bool trans) {struct nft_table *table;@@ -382,10 +411,10 @@ static struct nft_table *nf_tables_table_lookup(const struct nft_af_info *afi,return ERR_PTR (-EINVAL );Quoted 8 lines
net/netfilter/nf_tables_api.c static struct nft_table *nf_tables_table_lookup(const struct nft_af_info *afi, · line 415
Quoted 5 lines
net/netfilter/nf_tables_api.c +2
-2table =nft_table_lookup (afi, nla); -if (table !=NULL ) -return table; +if (table ==NULL || (trans && !nft_table_is_active_next (net, table))) +return ERR_PTR (-ENOENT );We really need to check the genid itself, in some cases we *only* want currently active tables, f.i. gettable and dumps.
Quoted 6 lines
This is what this patch is doing from the dump path.
We shouldn't check if the object is active from the lookup function if we're in the middle of a transaction, since we hold the lock there is no way we can see inactive objects in the list. There's only one transaction at the same time.
That's not entirely correct. Dump continuations happen asynchronously to netlink modifications and commit operations, so the genid may bump in the middle. We can get an inconsistent view if we have:
Quoted 6 lines
dump set elements from set x table y
delete table y
create table y
create set x
begin commit
continue dump from new set
We catch this from the nfnlhdr->res_id field in the nfnetlink message, but see below.
Quoted 5 lines
commit, send NEWGEN
Sure, we will get a NEWGEN message, but at that time we might already have sent a full message for the new table/set since that message is only send after the commit is completed.
I agree in that an event message at the beginning of the commit phase to announce the beginning new generation and another one to indicate of this transaction.
- preparation phase -
delete table y
create table y
create set x
- commit phase -
send NEWGEN, attribute type: begin
delete table y
create table y
create set x
send NEWGEN, attribute type: end
Thanks for your feedback!
Quoted 27 lines · Pablo Neira Ayuso
Quoted 2 lines · Patrick McHardy
Quoted 1 line · Pablo Neira Ayuso
On Tue, Aug 04, 2015 at 11:09:17AM +0200, Patrick McHardy wrote:
[...]
Quoted 23 lines
Quoted 8 lines
Quoted 2 lines
I have a similar patch queued up, however there seems to be something missing in this patch. The lookup functions need to take the genmask into account.
They already do for the deletion case, so we hit
-ENOENTfor objects that has been deleted in this batch, so we cannot delete objects twice.net/netfilter/nf_tables_api.c static int nf_tables_deltable(struct sock *nlsk, struct sk_buff *skb, · line 866
Quoted 9 lines
net/netfilter/nf_tables_api.c +2
-2@@ -829,10 +860,10 @@ static int nf_tables_deltable(struct sock *nlsk, struct sk_buff *skb,if (IS_ERR (afi))return PTR_ERR (afi); - table =nf_tables_table_lookup (afi, nla[NFTA_TABLE_NAME ]); + table =nf_tables_table_lookup (net, afi, nla[NFTA_TABLE_NAME ], true);if (IS_ERR (table))return PTR_ERR (table); -if (table->flags &NFT_TABLE_INACTIVE ) +if (!nft_table_is_active (net, table))return -ENOENT;Looking at it, that part seems wrong. They need to be active in the *next* generation, not the current one, to be deleted. All netlink actions only affect the next generation.
Quoted 5 lines
Quoted 1 line
The same bug is present in multiple locations.
That check is there to avoid the deletion of a table that has been added in this batch, unlike the delete + add, the add + delete in the same batch doesn't make much sense.
Its still a valid sequence. All actions should only ever look at activeness in the next generation since that is when the change will take effect.
Quoted 11 lines
Revisiting this scenario, this how this looks if we remove that check:
preparation starts:
add: table X (10), added to table list (now inactive)
del: table X (11), inactive next.^ gencursorcommit starts (update gencursor):
Quoted 8 lines
add: table X (01): clear past and report event, *NOTE*: the rule table is inactive.
add: table X (01): delete from list and report event.^ gencursorSo it seems it should be fine to remove it as it is defensive. I think robots can generate this kind of command placing updates in a batch, anyway that should come in a follow up patch IMO.
I don't follow. Why add an unnecessary check just to remove it again? As I said, the only thing that matters is the next generation, we should never even look at the current one when performing actions.
Quoted 40 lines
Quoted 9 lines
Quoted 4 lines
We shouldn't check if the object is active from the lookup function if we're in the middle of a transaction, since we hold the lock there is no way we can see inactive objects in the list. There's only one transaction at the same time.
That's not entirely correct. Dump continuations happen asynchronously to netlink modifications and commit operations, so the genid may bump in the middle. We can get an inconsistent view if we have:
Quoted 6 lines
dump set elements from set x table y
delete table y
create table y
create set x
begin commit
continue dump from new setWe catch this from the
nfnlhdr->res_idfield in the nfnetlink message, but see below.Quoted 5 lines
commit, send NEWGEN
Sure, we will get a NEWGEN message, but at that time we might already have sent a full message for the new table/set since that message is only send after the commit is completed.
I agree in that an event message at the beginning of the commit phase to announce the beginning new generation and another one to indicate of this transaction.
- preparation phase -
delete table y
create table y
create set x
- commit phase -
send NEWGEN, attribute type: begin
delete table y
create table y
create set x
send NEWGEN, attribute type: end
Quoted 1 line
Thanks for your feedback!
That might work if the message ordering is then guaranteed. However I think we can fix this case without changing NEWGEN. Let me think about that a bit, for now just taking care of the genid checks correctly seems like a good step forward.
BTW, we also need to adjust loop detection to only take into account active rules, active chains, active sets etc.
Pablo Neira Ayuso
maintainerQuoted 1 line · Patrick McHardy
On 04.08, Pablo Neira Ayuso wrote:
[...]
Quoted 16 lines
Quoted 16 lines
Revisiting this scenario, this how this looks if we remove that check:
preparation starts:
add: table X (10), added to table list (now inactive)
del: table X (11), inactive next.^ gencursorcommit starts (update gencursor):
add: table X (01): clear past and report event, *NOTE*: the rule table is inactive.
add: table X (01): delete from list and report event.^ gencursor
Quoted 7 lines
Quoted 3 lines
So it seems it should be fine to remove it as it is defensive. I think robots can generate this kind of command placing updates in a batch, anyway that should come in a follow up patch IMO.
I don't follow. Why add an unnecessary check just to remove it again? As I said, the only thing that matters is the next generation, we should never even look at the current one when performing actions.
Yes, we can remove those checks to reject add+del in the same batch in first place.
I remember I added this because I found some problematic scenario, but given looking at the example above, I agree we can remove this first place. I'm going to recheck for other objects too.
Quoted 40 lines
Quoted 40 lines
Quoted 9 lines
Quoted 4 lines
We shouldn't check if the object is active from the lookup function if we're in the middle of a transaction, since we hold the lock there is no way we can see inactive objects in the list. There's only one transaction at the same time.
That's not entirely correct. Dump continuations happen asynchronously to netlink modifications and commit operations, so the genid may bump in the middle. We can get an inconsistent view if we have:
Quoted 6 lines
dump set elements from set x table y
delete table y
create table y
create set x
begin commit
continue dump from new setWe catch this from the
nfnlhdr->res_idfield in the nfnetlink message, but see below.Quoted 5 lines
commit, send NEWGEN
Sure, we will get a NEWGEN message, but at that time we might already have sent a full message for the new table/set since that message is only send after the commit is completed.
I agree in that an event message at the beginning of the commit phase to announce the beginning new generation and another one to indicate of this transaction.
- preparation phase -
delete table y
create table y
create set x
- commit phase -
send NEWGEN, attribute type: begin
delete table y
create table y
create set x
send NEWGEN, attribute type: end
Quoted 6 lines
Quoted 1 line
Thanks for your feedback!
That might work if the message ordering is then guaranteed. However I think we can fix this case without changing NEWGEN. Let me think about that a bit, for now just taking care of the genid checks correctly seems like a good step forward.
But we can catch this problem through ->res_id, OK?
Quoted 2 lines
BTW, we also need to adjust loop detection to only take into account active rules, active chains, active sets etc.
Indeed, thanks Patrick.
Will you take care of this? It would be great to have a fix for these in this merge window. On top of that, I have a patchset here to add named expressions as you suggested as a generic way to implement named counters (or any other stateful expression) and I need that this is fixed first so I don't need to add another ugly _INACTIVE flag to the nft_nexpr object.
Let me know, thanks!
Quoted 6 lines · Pablo Neira Ayuso
Quoted 4 lines
That might work if the message ordering is then guaranteed. However I think we can fix this case without changing NEWGEN. Let me think about that a bit, for now just taking care of the genid checks correctly seems like a good step forward.
But we can catch this problem through ->res_id, OK?
Have to look at it in detail. Currently sitting at the airport, will take me a bit.
Quoted 7 lines
Quoted 2 lines
BTW, we also need to adjust loop detection to only take into account active rules, active chains, active sets etc.
Indeed, thanks Patrick.
Will you take care of this? It would be great to have a fix for these in this merge window. On top of that, I have a patchset here to add
Sure. I already have this in my patches, however I'll wait for your new patchset so I can test on top of it.
Quoted 6 lines
named expressions as you suggested as a generic way to implement named counters (or any other stateful expression) and I need that this is fixed first so I don't need to add another ugly
_INACTIVEflag to thenft_nexprobject.Let me know, thanks!
I agree, the _INACTIVE flags need to go.
Quoted 41 lines · Pablo Neira Ayuso
Quoted 40 lines · Patrick McHardy
Quoted 40 lines
Quoted 9 lines
Quoted 4 lines
We shouldn't check if the object is active from the lookup function if we're in the middle of a transaction, since we hold the lock there is no way we can see inactive objects in the list. There's only one transaction at the same time.
That's not entirely correct. Dump continuations happen asynchronously to netlink modifications and commit operations, so the genid may bump in the middle. We can get an inconsistent view if we have:
Quoted 6 lines
dump set elements from set x table y
delete table y
create table y
create set x
begin commit
continue dump from new setWe catch this from the
nfnlhdr->res_idfield in the nfnetlink message, but see below.Quoted 5 lines
commit, send NEWGEN
Sure, we will get a NEWGEN message, but at that time we might already have sent a full message for the new table/set since that message is only send after the commit is completed.
I agree in that an event message at the beginning of the commit phase to announce the beginning new generation and another one to indicate of this transaction.
- preparation phase -
delete table y
create table y
create set x
- commit phase -
send NEWGEN, attribute type: begin
delete table y
create table y
create set x
send NEWGEN, attribute type: end
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Thanks for your feedback!
That might work if the message ordering is then guaranteed. However I think we can fix this case without changing NEWGEN. Let me think about that a bit, for now just taking care of the genid checks correctly seems like a good step forward.
But we can catch this problem through ->res_id, OK?
I guess we could with a unique res_id per object, but how would this work with multiple object types? Any change bumps res_id, so we'd invalidate the full dump for any change.
Pablo Neira Ayuso
maintainerQuoted 2 lines · Patrick McHardy
Quoted 1 line · Pablo Neira Ayuso
On Wed, Aug 05, 2015 at 11:09:16AM +0200, Patrick McHardy wrote:
[...]
Quoted 18 lines
Quoted 18 lines
Quoted 17 lines
Quoted 11 lines
- preparation phase -
delete table y
create table y
create set x
- commit phase -
send NEWGEN, attribute type: begin
delete table y
create table y
create set x
send NEWGEN, attribute type: endQuoted 1 line
Thanks for your feedback!
That might work if the message ordering is then guaranteed. However I think we can fix this case without changing NEWGEN. Let me think about that a bit, for now just taking care of the genid checks correctly seems like a good step forward.
Quoted 5 lines
Quoted 1 line
But we can catch this problem through ->res_id, OK?
I guess we could with a unique
res_idper object, but how would this work with multiple object types? Any change bumpsres_id, so we'd invalidate the full dump for any change.
I see, if we want to be able to invalidate caches at per-object level, then I think we have to recover the idea of having a netlink attribute for the per-object generation counter.
Pablo Neira Ayuso
maintainerQuoted 18 lines · Patrick McHardy
Quoted 17 lines · Pablo Neira Ayuso
The dumping of table objects can be inconsistent when interfering with the preparation phase of our 2-phase commit protocol because:
1) We remove objects from the lists during the preparation phase, that can be added re-added from the abort step. Thus, we may miss objects that are still active.
2) We add new objects to the lists during the preparation phase, so we may get objects that are not yet active with an internal flag set.
We can resolve this problem with generation masks, as we already do for rules when we expose them to the packet path.
After this change, we always obtain a consistent list as long as we stay in the same generation. The userspace side can detect interferences through the generation counter. If so, it needs to restart.
Quoted 6 lines
Quoted 1 line
As a result, we can get rid of the internal
NFT_TABLE_INACTIVEflag.I have a similar patch queued up, however there seems to be something missing in this patch. The lookup functions need to take the genmask into account. Otherwise you can not delete and add a new table in the same batch. The same holds for all other object types.
I got what you meant, we have to skip the delete table when iterating over the list.
Quoted 21 lines · Pablo Neira Ayuso
Quoted 20 lines · Patrick McHardy
Quoted 18 lines · Pablo Neira Ayuso
The dumping of table objects can be inconsistent when interfering with the preparation phase of our 2-phase commit protocol because:
1) We remove objects from the lists during the preparation phase, that can be added re-added from the abort step. Thus, we may miss objects that are still active.
2) We add new objects to the lists during the preparation phase, so we may get objects that are not yet active with an internal flag set.
We can resolve this problem with generation masks, as we already do for rules when we expose them to the packet path.
After this change, we always obtain a consistent list as long as we stay in the same generation. The userspace side can detect interferences through the generation counter. If so, it needs to restart.
As a result, we can get rid of the internal
NFT_TABLE_INACTIVEflag.
Quoted 7 lines
Quoted 4 lines
I have a similar patch queued up, however there seems to be something missing in this patch. The lookup functions need to take the genmask into account. Otherwise you can not delete and add a new table in the same batch. The same holds for all other object types.
I got what you meant, we have to skip the delete table when iterating over the list.
Exactly. I'd propose to simply pass in the requested genid, this has the added benefit of not having to sprinkle those checks throughout the code.
Pablo Neira Ayuso
maintainerQuoted 27 lines · Patrick McHardy
Quoted 26 lines · Pablo Neira Ayuso
Quoted 24 lines · Patrick McHardy
Quoted 10 lines · Pablo Neira Ayuso
The dumping of table objects can be inconsistent when interfering with the preparation phase of our 2-phase commit protocol because:
1) We remove objects from the lists during the preparation phase, that can be added re-added from the abort step. Thus, we may miss objects that are still active.
2) We add new objects to the lists during the preparation phase, so we may get objects that are not yet active with an internal flag set.
Quoted 8 lines
We can resolve this problem with generation masks, as we already do for rules when we expose them to the packet path.
After this change, we always obtain a consistent list as long as we stay in the same generation. The userspace side can detect interferences through the generation counter. If so, it needs to restart.
As a result, we can get rid of the internal
NFT_TABLE_INACTIVEflag.I have a similar patch queued up, however there seems to be something missing in this patch. The lookup functions need to take the genmask into account. Otherwise you can not delete and add a new table in the same batch. The same holds for all other object types.
Quoted 5 lines
Quoted 2 lines
I got what you meant, we have to skip the delete table when iterating over the list.
Exactly. I'd propose to simply pass in the requested genid, this has the added benefit of not having to sprinkle those checks throughout the code.
If that simplifies the patchset, I think it's a good idea. Thanks!