summaryrefslogtreecommitdiffstats
path: root/examples/nft-events.c
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2014-09-12 11:52:18 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2014-09-19 15:15:10 +0200
commit2e66fb09d6936d17ab8240188f511529fcae8c67 (patch)
tree9f9de55bc3e57d0aed474d02a5b0b0c58613c66c /examples/nft-events.c
parent51fbb415440517e47ac77a9f72fb6c1bc1c6e6b5 (diff)
src: add ruleset generation class
The generation object currently only contains the uint32_t that indicates the generation ID. I could have just add the API to return the uint32_t ID instead, but I think this API is easier to extend without adding new APIs. We can probably include meaningful statistics in the generation message in the future without much hassle. This patch also extends examples/nft-events.c. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'examples/nft-events.c')
-rw-r--r--examples/nft-events.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/examples/nft-events.c b/examples/nft-events.c
index fb18e55..ef860d3 100644
--- a/examples/nft-events.c
+++ b/examples/nft-events.c
@@ -22,6 +22,7 @@
#include <libnftnl/chain.h>
#include <libnftnl/rule.h>
#include <libnftnl/set.h>
+#include <libnftnl/gen.h>
#include <libnftnl/common.h>
static uint32_t event2flag(uint32_t event)
@@ -32,6 +33,7 @@ static uint32_t event2flag(uint32_t event)
case NFT_MSG_NEWRULE:
case NFT_MSG_NEWSET:
case NFT_MSG_NEWSETELEM:
+ case NFT_MSG_NEWGEN:
return NFT_OF_EVENT_NEW;
case NFT_MSG_DELTABLE:
case NFT_MSG_DELCHAIN:
@@ -165,6 +167,29 @@ err:
return MNL_CB_OK;
}
+static int gen_cb(const struct nlmsghdr *nlh, int event, int type)
+{
+ struct nft_gen *gen;
+
+ gen = nft_gen_alloc();
+ if (gen == NULL) {
+ perror("OOM");
+ goto err;
+ }
+
+ if (nft_gen_nlmsg_parse(nlh, gen) < 0) {
+ perror("nft_gen_parse");
+ goto err_free;
+ }
+
+ nft_gen_fprintf(stdout, gen, type, event2flag(event));
+ fprintf(stdout, "\n");
+err_free:
+ nft_gen_free(gen);
+err:
+ return MNL_CB_OK;
+}
+
static int events_cb(const struct nlmsghdr *nlh, void *data)
{
int ret = MNL_CB_OK;
@@ -192,6 +217,9 @@ static int events_cb(const struct nlmsghdr *nlh, void *data)
case NFT_MSG_DELSETELEM:
ret = setelem_cb(nlh, event, type);
break;
+ case NFT_MSG_NEWGEN:
+ ret = gen_cb(nlh, event, type);
+ break;
}
return ret;