diff options
| author | Patrick McHardy <kaber@trash.net> | 2015-03-25 10:08:49 -0400 |
|---|---|---|
| committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2015-03-26 06:09:35 -0400 |
| commit | ea4bd995b0f2fc5677ff8085e92a5d2544b9937c (patch) | |
| tree | 57779db0522e30391cc7da130ba49d36f57761f4 /include/net | |
| parent | b2832dd6621bf73eb8ad38389a94bd83a5983886 (diff) | |
netfilter: nf_tables: add transaction helper functions
Add some helper functions for building the genmask as preparation for
set transactions.
Also add a little documentation how this stuff actually works.
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'include/net')
| -rw-r--r-- | include/net/netfilter/nf_tables.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/include/net/netfilter/nf_tables.h b/include/net/netfilter/nf_tables.h index f190d26bda7d..4c46a325874e 100644 --- a/include/net/netfilter/nf_tables.h +++ b/include/net/netfilter/nf_tables.h | |||
| @@ -720,6 +720,34 @@ void nft_unregister_expr(struct nft_expr_type *); | |||
| 720 | #define MODULE_ALIAS_NFT_SET() \ | 720 | #define MODULE_ALIAS_NFT_SET() \ |
| 721 | MODULE_ALIAS("nft-set") | 721 | MODULE_ALIAS("nft-set") |
| 722 | 722 | ||
| 723 | /* | ||
| 724 | * The gencursor defines two generations, the currently active and the | ||
| 725 | * next one. Objects contain a bitmask of 2 bits specifying the generations | ||
| 726 | * they're active in. A set bit means they're inactive in the generation | ||
| 727 | * represented by that bit. | ||
| 728 | * | ||
| 729 | * New objects start out as inactive in the current and active in the | ||
| 730 | * next generation. When committing the ruleset the bitmask is cleared, | ||
| 731 | * meaning they're active in all generations. When removing an object, | ||
| 732 | * it is set inactive in the next generation. After committing the ruleset, | ||
| 733 | * the objects are removed. | ||
| 734 | */ | ||
| 735 | static inline unsigned int nft_gencursor_next(const struct net *net) | ||
| 736 | { | ||
| 737 | return net->nft.gencursor + 1 == 1 ? 1 : 0; | ||
| 738 | } | ||
| 739 | |||
| 740 | static inline u8 nft_genmask_next(const struct net *net) | ||
| 741 | { | ||
| 742 | return 1 << nft_gencursor_next(net); | ||
| 743 | } | ||
| 744 | |||
| 745 | static inline u8 nft_genmask_cur(const struct net *net) | ||
| 746 | { | ||
| 747 | /* Use ACCESS_ONCE() to prevent refetching the value for atomicity */ | ||
| 748 | return 1 << ACCESS_ONCE(net->nft.gencursor); | ||
| 749 | } | ||
| 750 | |||
| 723 | /** | 751 | /** |
| 724 | * struct nft_trans - nf_tables object update in transaction | 752 | * struct nft_trans - nf_tables object update in transaction |
| 725 | * | 753 | * |
