diff options
author | Pablo Neira Ayuso <pablo@netfilter.org> | 2018-12-01 11:33:31 +0100 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2018-12-01 11:35:34 +0100 |
commit | fa145fdf73d663eb69751800911cdd2853689dee (patch) | |
tree | a31ddcf17816fbfa02dc20a341f4039763de1806 /src/rule.c | |
parent | 0544632e14b993bed8f1ce4e3ad764f90740f96a (diff) |
src: introduce simple hints on incorrect object
# nft add counter x test
# nft list counter x test
Error: No such file or directory; did you mean obj ‘test’ in table ip ‘x’?
list counter x text
^^^^
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/rule.c')
-rw-r--r-- | src/rule.c | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -1710,6 +1710,30 @@ struct obj *obj_lookup(const struct table *table, const char *name, return NULL; } +struct obj *obj_lookup_fuzzy(const char *obj_name, + const struct nft_cache *cache, + const struct table **t) +{ + struct string_misspell_state st; + struct table *table; + struct obj *obj; + + string_misspell_init(&st); + + list_for_each_entry(table, &cache->list, list) { + list_for_each_entry(obj, &table->objs, list) { + if (!strcmp(obj->handle.obj.name, obj_name)) { + *t = table; + return obj; + } + if (string_misspell_update(obj->handle.obj.name, + obj_name, obj, &st)) + *t = table; + } + } + return st.obj; +} + static void print_proto_name_proto(uint8_t l4, struct output_ctx *octx) { const struct protoent *p = getprotobynumber(l4); |