extern void chain_add_hash(struct chain *chain, struct table *table);
extern struct chain *chain_lookup(const struct table *table,
const struct handle *h);
+extern struct chain *chain_lookup_fuzzy(const struct handle *h,
+ const struct nft_cache *cache,
+ const struct table **table);
extern const char *family2str(unsigned int family);
extern const char *hooknum2str(unsigned int family, unsigned int hooknum);
family2str(table->handle.family));
}
+static int chain_not_found(struct eval_ctx *ctx)
+{
+ const struct table *table;
+ struct chain *chain;
+
+ chain = chain_lookup_fuzzy(&ctx->cmd->handle, &ctx->nft->cache, &table);
+ if (chain == NULL)
+ return cmd_error(ctx, &ctx->cmd->handle.chain.location,
+ "%s", strerror(ENOENT));
+
+ return cmd_error(ctx, &ctx->cmd->handle.chain.location,
+ "%s; did you mean chain ‘%s’ in table %s ‘%s’?",
+ strerror(ENOENT), chain->handle.chain.name,
+ family2str(chain->handle.family),
+ table->handle.table.name);
+}
+
/*
* Symbol expression: parse symbol and evaluate resulting expression.
*/
chain = chain_lookup(table, &rule->handle);
if (!chain)
- return cmd_error(ctx, &rule->handle.chain.location,
- "Could not process rule: %s",
- strerror(ENOENT));
+ return chain_not_found(ctx);
list_for_each_entry(r, &chain->rules, list) {
if (++index < rule->handle.index.id)
return table_not_found(ctx);
if (chain_lookup(table, &cmd->handle) == NULL)
- return cmd_error(ctx, &cmd->handle.chain.location,
- "Could not process rule: %s",
- strerror(ENOENT));
+ return chain_not_found(ctx);
+
return 0;
case CMD_OBJ_QUOTA:
return cmd_evaluate_list_obj(ctx, cmd, NFT_OBJECT_QUOTA);
return table_not_found(ctx);
if (chain_lookup(table, &ctx->cmd->handle) == NULL)
- return cmd_error(ctx, &ctx->cmd->handle.chain.location,
- "Could not process rule: %s",
- strerror(ENOENT));
+ return chain_not_found(ctx);
+
break;
default:
BUG("invalid command object type %u\n", cmd->obj);
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) {