From e35693fd13de771e1e047ffa4f799f72f1446e8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Falgueras=20Garc=C3=ADa?= Date: Wed, 17 Aug 2016 16:07:09 +0200 Subject: src: Implement rule comparison MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch implements the function: bool nftnl_rule_cmp(const struct nftnl_rule *r1, const struct nftnl_rule *r2) for rule comparison. Expressions within rules need to be compared, so also has been created the function: bool nftnl_expr_cmp(const struct nftnl_expr *e1, const struct nftnl_expr *e2); Also includes all expression comparators. Signed-off-by: Carlos Falgueras GarcĂ­a Signed-off-by: Pablo Neira Ayuso --- src/rule.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/rule.c') diff --git a/src/rule.c b/src/rule.c index 8aeefbe..ae7c478 100644 --- a/src/rule.c +++ b/src/rule.c @@ -1077,6 +1077,36 @@ void nftnl_expr_iter_destroy(struct nftnl_expr_iter *iter) } EXPORT_SYMBOL_ALIAS(nftnl_expr_iter_destroy, nft_rule_expr_iter_destroy); +bool nftnl_rule_cmp(const struct nftnl_rule *r1, const struct nftnl_rule *r2) +{ + struct nftnl_expr_iter it1, it2; + struct nftnl_expr *e1, *e2; + unsigned int eq = 1; + + if (r1->flags & r1->flags & (1 << NFTNL_RULE_TABLE)) + eq &= !strcmp(r1->table, r2->table); + if (r1->flags & r1->flags & (1 << NFTNL_RULE_CHAIN)) + eq &= !strcmp(r1->chain, r2->chain); + if (r1->flags & r1->flags & (1 << NFTNL_RULE_COMPAT_FLAGS)) + eq &= (r1->compat.flags == r2->compat.flags); + if (r1->flags & r1->flags & (1 << NFTNL_RULE_COMPAT_PROTO)) + eq &= (r1->compat.proto == r2->compat.proto); + + nftnl_expr_iter_init(r1, &it1); + nftnl_expr_iter_init(r2, &it2); + e1 = nftnl_expr_iter_next(&it1); + e2 = nftnl_expr_iter_next(&it2); + while (eq && e1 && e2) { + eq = nftnl_expr_cmp(e1, e2); + + e1 = nftnl_expr_iter_next(&it1); + e2 = nftnl_expr_iter_next(&it2); + } + + return eq; +} +EXPORT_SYMBOL(nftnl_rule_cmp); + struct nftnl_rule_list { struct list_head list; }; -- cgit v1.2.3