summaryrefslogtreecommitdiffstats
path: root/src/rule.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rule.c')
-rw-r--r--src/rule.c33
1 files changed, 16 insertions, 17 deletions
diff --git a/src/rule.c b/src/rule.c
index 0ebe91e7..29360657 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -224,7 +224,7 @@ static int cache_init(struct netlink_ctx *ctx, unsigned int flags)
return 0;
}
-bool cache_is_complete(struct nft_cache *cache, unsigned int flags)
+static bool cache_is_complete(struct nft_cache *cache, unsigned int flags)
{
return (cache->flags & flags) == flags;
}
@@ -234,6 +234,11 @@ static bool cache_is_updated(struct nft_cache *cache, uint16_t genid)
return genid && genid == cache->genid;
}
+bool cache_needs_update(struct nft_cache *cache)
+{
+ return cache->flags & NFT_CACHE_UPDATE;
+}
+
int cache_update(struct nft_ctx *nft, unsigned int flags, struct list_head *msgs)
{
struct netlink_ctx ctx = {
@@ -242,7 +247,7 @@ int cache_update(struct nft_ctx *nft, unsigned int flags, struct list_head *msgs
.msgs = msgs,
};
struct nft_cache *cache = &nft->cache;
- uint32_t genid, genid_stop;
+ uint32_t genid, genid_stop, oldflags;
int ret;
replay:
ctx.seqnum = cache->seqnum++;
@@ -254,6 +259,14 @@ replay:
if (cache->genid)
cache_release(cache);
+ if (flags & NFT_CACHE_FLUSHED) {
+ oldflags = flags;
+ flags = NFT_CACHE_EMPTY;
+ if (oldflags & NFT_CACHE_UPDATE)
+ flags |= NFT_CACHE_UPDATE;
+ goto skip;
+ }
+
ret = cache_init(&ctx, flags);
if (ret < 0) {
cache_release(cache);
@@ -269,7 +282,7 @@ replay:
cache_release(cache);
goto replay;
}
-
+skip:
cache->genid = genid;
cache->flags = flags;
return 0;
@@ -285,20 +298,6 @@ static void __cache_flush(struct list_head *table_list)
}
}
-void cache_flush(struct nft_ctx *nft, struct list_head *msgs)
-{
- struct netlink_ctx ctx = {
- .list = LIST_HEAD_INIT(ctx.list),
- .nft = nft,
- .msgs = msgs,
- };
- struct nft_cache *cache = &nft->cache;
-
- __cache_flush(&cache->list);
- cache->genid = mnl_genid_get(&ctx);
- cache->flags = NFT_CACHE_FULL;
-}
-
void cache_release(struct nft_cache *cache)
{
__cache_flush(&cache->list);