summaryrefslogtreecommitdiffstats
path: root/src/rule.c
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2018-12-01 12:06:46 +0100
committerPablo Neira Ayuso <pablo@netfilter.org>2018-12-01 12:09:24 +0100
commitbe79e9c3467b324216688047c81315f0d3e51d24 (patch)
tree97616474615a0f1a0d44c42884f5e360ea8abd9d /src/rule.c
parentfa145fdf73d663eb69751800911cdd2853689dee (diff)
src: introduce simple hints on incorrect identifier
# cat test.nft define test = "1.2.3.4" table ip x { chain y { ip saddr $text } } # nft -f test.nft test.nft:5:13-16: Error: unknown identifier 'text'; did you mean identifier ‘test’? ip saddr $text ^^^^ Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/rule.c')
-rw-r--r--src/rule.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/rule.c b/src/rule.c
index 0a3c1970..ad300129 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -692,6 +692,24 @@ struct symbol *symbol_lookup(const struct scope *scope, const char *identifier)
return NULL;
}
+struct symbol *symbol_lookup_fuzzy(const struct scope *scope,
+ const char *identifier)
+{
+ struct string_misspell_state st;
+ struct symbol *sym;
+
+ string_misspell_init(&st);
+
+ while (scope != NULL) {
+ list_for_each_entry(sym, &scope->symbols, list)
+ string_misspell_update(sym->identifier, identifier,
+ sym, &st);
+
+ scope = scope->parent;
+ }
+ return st.obj;
+}
+
static const char * const chain_type_str_array[] = {
"filter",
"nat",