netfilter: nf_tables: export rule-set generation ID
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH 1/1 netfilter: nf_tables: export rule-set generation ID
This patch adds the NFT_MSG_GENID command to nf_tables that exposes the 16-bits ruleset generation ID. This ID is incremented in every commit. The generation ID is also exposed to userspace through the nfnetlink res_id header field when dumping object lists.
This generation ID allows a userspace client to detect that an update has happened between two consecutive object list dumps, so it can retry from scratch.
This is complementary to the NLM_F_DUMP_INTR approach, which allows us to detect an interference in the middle one single list dumping. There is no way to explicitly check that an interference has occurred between two list dumps from the kernel, since it doesn't know how many lists the userspace client is actually going to dump.
--- include/uapi/linux/netfilter/nf_tables.h | 2 + net/netfilter/nf_tables_api.c | 64 +++++++++++++++++++++++++++--- 2 files changed, 60 insertions(+), 6 deletions(-)
include/uapi/linux/netfilter/nf_tables.h +2 -0
@@ -51,6 +51,7 @@ enum nft_verdicts {* @NFT_MSG_NEWSETELEM: create a new set element (enum nft_set_elem_attributes) * @NFT_MSG_GETSETELEM: get a set element (enum nft_set_elem_attributes) * @NFT_MSG_DELSETELEM: delete a set element (enum nft_set_elem_attributes) +* @NFT_MSG_GENID: get the rule-set generation ID (no attributes) */ enum nf_tables_msg_types {NFT_MSG_NEWTABLE ,
@@ -68,6 +69,7 @@ enum nf_tables_msg_types {NFT_MSG_NEWSETELEM ,NFT_MSG_GETSETELEM ,NFT_MSG_DELSETELEM , +NFT_MSG_GENID , NFT_MSG_MAX, };
net/netfilter/nf_tables_api.c +58 -6
130 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Quoted 9 lines · Pablo Neira Ayuso
This patch adds the
NFT_MSG_GENIDcommand tonf_tablesthat exposes the 16-bits ruleset generation ID. This ID is incremented in every commit. The generation ID is also exposed to userspace through the nfnetlinkres_idheader field when dumping object lists.This generation ID allows a userspace client to detect that an update has happened between two consecutive object list dumps, so it can retry from scratch.
Quoted 5 lines
This is complementary to the
NLM_F_DUMP_INTRapproach, which allows us to detect an interference in the middle one single list dumping. There is no way to explicitly check that an interference has occurred between two list dumps from the kernel, since it doesn't know how many lists the userspace client is actually going to dump.
Well, the obvious question is, are we sure that 16 bit is enough? I mean, sure, it most likely is for almost any usecase, but if you want to write a reliable piece of software using it, can you be sure and how could you handle the case that it overflows?
If we for instance consider an optimization algorithm that wants to perform an update and has to dump all objects, perform its change, reoptimize the resulting ruleset and then insert it. This might take some considerable amount of time. I guess its at least possible that 2^16 updates could be performed in the same period.
Pablo Neira Ayuso
maintainerQuoted 21 lines · Patrick McHardy
Quoted 9 lines · Pablo Neira Ayuso
This patch adds the
NFT_MSG_GENIDcommand tonf_tablesthat exposes the 16-bits ruleset generation ID. This ID is incremented in every commit. The generation ID is also exposed to userspace through the nfnetlinkres_idheader field when dumping object lists.This generation ID allows a userspace client to detect that an update has happened between two consecutive object list dumps, so it can retry from scratch.
Quoted 5 lines
This is complementary to the
NLM_F_DUMP_INTRapproach, which allows us to detect an interference in the middle one single list dumping. There is no way to explicitly check that an interference has occurred between two list dumps from the kernel, since it doesn't know how many lists the userspace client is actually going to dump.Well, the obvious question is, are we sure that 16 bit is enough? I mean, sure, it most likely is for almost any usecase, but if you want to write a reliable piece of software using it, can you be sure and how could you handle the case that it overflows?
Quoted 5 lines
If we for instance consider an optimization algorithm that wants to perform an update and has to dump all objects, perform its change, reoptimize the resulting ruleset and then insert it. This might take some considerable amount of time. I guess its at least possible that 2^16 updates could be performed in the same period.
Right. nf-hipac was taking quite some time to perform those transformations (I remember they were masking the update time by using a kernel thread in the netlink receive path), so it's reasonable to assume that those transformation algorithms may take enough time to see a wrap-around.
I think of several alternatives:
1) Switch to 2^32. With this approach, I don't see a way to expose it via the existing headers (ie. nfnetlink res_id was easy). Thus, we don't have a way to stop a dump immediately after when we notice the objects we're getting are stale. So the approach should look more like:
request genID and annotate it
dump objects
request genID and compare what we annotated, if unequal, retry.
This can be expensive when we get an unfortunate update between two list dumps when we operate with large object list though. BTW, the update between two list dumps is unlikely but still possible.
2) Stick to 2^16 but introduce a commit event. The optimization algorithm can subscribe to this events so it notices when it's been working with stale objects. The optimization software would need to poll for commit events and we still may lose events.
I think we have to go 1).
Regarding the commit event, Arturo wants this for nft-sync anyway, so he knows where the batch ends to consistently replicate and apply the rules to the other peer. So this can come in a separated patch.
Let me know, thanks!
Quoted 42 lines · Pablo Neira Ayuso
Quoted 21 lines · Patrick McHardy
Quoted 9 lines · Pablo Neira Ayuso
This patch adds the
NFT_MSG_GENIDcommand tonf_tablesthat exposes the 16-bits ruleset generation ID. This ID is incremented in every commit. The generation ID is also exposed to userspace through the nfnetlinkres_idheader field when dumping object lists.This generation ID allows a userspace client to detect that an update has happened between two consecutive object list dumps, so it can retry from scratch.
Quoted 5 lines
This is complementary to the
NLM_F_DUMP_INTRapproach, which allows us to detect an interference in the middle one single list dumping. There is no way to explicitly check that an interference has occurred between two list dumps from the kernel, since it doesn't know how many lists the userspace client is actually going to dump.Well, the obvious question is, are we sure that 16 bit is enough? I mean, sure, it most likely is for almost any usecase, but if you want to write a reliable piece of software using it, can you be sure and how could you handle the case that it overflows?
Quoted 5 lines
If we for instance consider an optimization algorithm that wants to perform an update and has to dump all objects, perform its change, reoptimize the resulting ruleset and then insert it. This might take some considerable amount of time. I guess its at least possible that 2^16 updates could be performed in the same period.
Right. nf-hipac was taking quite some time to perform those transformations (I remember they were masking the update time by using a kernel thread in the netlink receive path), so it's reasonable to assume that those transformation algorithms may take enough time to see a wrap-around.
I think of several alternatives:
1) Switch to 2^32. With this approach, I don't see a way to expose it via the existing headers (ie. nfnetlink
res_idwas easy). Thus, we don't have a way to stop a dump immediately after when we notice the objects we're getting are stale. So the approach should look more like:
Quoted 7 lines
request genID and annotate it
dump objects
request genID and compare what we annotated, if unequal, retry.This can be expensive when we get an unfortunate update between two list dumps when we operate with large object list though. BTW, the update between two list dumps is unlikely but still possible.
Alternatively put it into an attribute and include that with every message or object.
Quoted 4 lines
2) Stick to 2^16 but introduce a commit event. The optimization algorithm can subscribe to this events so it notices when it's been working with stale objects. The optimization software would need to poll for commit events and we still may lose events.
Since events are unreliable, so this wouldn't work that easily. On message loss you'd have to always start over. OTOH probably not a big problem, at least currently, because message loss only happens when other notifications are sent which, at present, obviously indicates some change has been made.
Quoted 7 lines
I think we have to go 1).
Regarding the commit event, Arturo wants this for nft-sync anyway, so he knows where the batch ends to consistently replicate and apply the rules to the other peer. So this can come in a separated patch.
Let me know, thanks!