From 9f7817a4e0223c5e285a3f4a4dccbf1dafa7fc4e Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Mon, 19 Nov 2018 12:22:06 +0100 Subject: src: introduce simple hints on incorrect chain MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # nft list chain x y Error: No such file or directory; did you mean chain ‘y’ in table inet ‘x’? list chain x y ^ Signed-off-by: Pablo Neira Ayuso --- src/rule.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/rule.c') diff --git a/src/rule.c b/src/rule.c index 3553b43d..39f717ca 100644 --- a/src/rule.c +++ b/src/rule.c @@ -762,6 +762,24 @@ struct chain *chain_lookup(const struct table *table, const struct handle *h) return NULL; } +struct chain *chain_lookup_fuzzy(const struct handle *h, + const struct nft_cache *cache, + const struct table **t) +{ + struct table *table; + struct chain *chain; + + list_for_each_entry(table, &cache->list, list) { + list_for_each_entry(chain, &table->chains, list) { + if (!strcmp(chain->handle.chain.name, h->chain.name)) { + *t = table; + return chain; + } + } + } + return NULL; +} + const char *family2str(unsigned int family) { switch (family) { -- cgit v1.2.3