From afbd102211dcc52dfdc2332e171d21e769f7e70e Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Wed, 12 Jan 2022 01:33:58 +0100 Subject: src: do not use the nft_cache_filter object from mnl.c Pass the table and chain strings to mnl_nft_rule_dump() instead. Signed-off-by: Pablo Neira Ayuso --- include/mnl.h | 2 +- src/cache.c | 9 ++++++++- src/mnl.c | 12 +++++------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/include/mnl.h b/include/mnl.h index b006192c..a4abe1ae 100644 --- a/include/mnl.h +++ b/include/mnl.h @@ -34,7 +34,7 @@ int mnl_nft_rule_del(struct netlink_ctx *ctx, struct cmd *cmd); int mnl_nft_rule_replace(struct netlink_ctx *ctx, struct cmd *cmd); struct nftnl_rule_list *mnl_nft_rule_dump(struct netlink_ctx *ctx, int family, - const struct nft_cache_filter *filter); + const char *table, const char *chain); int mnl_nft_chain_add(struct netlink_ctx *ctx, struct cmd *cmd, unsigned int flags); diff --git a/src/cache.c b/src/cache.c index 6494e474..6ca6bbc6 100644 --- a/src/cache.c +++ b/src/cache.c @@ -478,8 +478,15 @@ static int rule_cache_init(struct netlink_ctx *ctx, const struct handle *h, const struct nft_cache_filter *filter) { struct nftnl_rule_list *rule_cache; + const char *table; + const char *chain; - rule_cache = mnl_nft_rule_dump(ctx, h->family, filter); + if (filter) { + table = filter->list.table; + chain = filter->list.chain; + } + + rule_cache = mnl_nft_rule_dump(ctx, h->family, table, chain); if (rule_cache == NULL) { if (errno == EINTR) return -1; diff --git a/src/mnl.c b/src/mnl.c index 5413f865..6be991a4 100644 --- a/src/mnl.c +++ b/src/mnl.c @@ -654,7 +654,7 @@ err_free: } struct nftnl_rule_list *mnl_nft_rule_dump(struct netlink_ctx *ctx, int family, - const struct nft_cache_filter *filter) + const char *table, const char *chain) { char buf[MNL_SOCKET_BUFFER_SIZE]; struct nftnl_rule_list *nlr_list; @@ -662,16 +662,14 @@ struct nftnl_rule_list *mnl_nft_rule_dump(struct netlink_ctx *ctx, int family, struct nlmsghdr *nlh; int ret; - if (filter && filter->list.table) { + if (table) { nlr = nftnl_rule_alloc(); if (!nlr) memory_allocation_error(); - nftnl_rule_set_str(nlr, NFTNL_RULE_TABLE, - filter->list.table); - if (filter->list.chain) - nftnl_rule_set_str(nlr, NFTNL_RULE_CHAIN, - filter->list.chain); + nftnl_rule_set_str(nlr, NFTNL_RULE_TABLE, table); + if (chain) + nftnl_rule_set_str(nlr, NFTNL_RULE_CHAIN, chain); } nlr_list = nftnl_rule_list_alloc(); -- cgit v1.2.3