]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
netlink: return error if chain not found
authorPablo Neira Ayuso <pablo@netfilter.org>
Thu, 18 Apr 2013 14:33:18 +0000 (16:33 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Thu, 18 Apr 2013 14:39:27 +0000 (16:39 +0200)
Before this patch:

nft list chain filter xxx
table filter {
}

After this patch:

nft list chain filter xxx
internal:0:0-0: Error: Could not find chain `xxx' in table `filter: Object not found

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/netlink.c

index e760ccc9c7fce953a07bb816947e0f1e9a50c167..5b99c2e1fb4b6d5e2d0b88347ae06cfb492c1c86 100644 (file)
@@ -501,6 +501,7 @@ int netlink_list_chains(struct netlink_ctx *ctx, const struct handle *h)
 {
        struct nl_cache *chain_cache;
        struct nfnl_nft_chain *nlc;
+       struct chain *chain;
        int err;
 
        err = nfnl_nft_chain_alloc_cache(nf_sock, &chain_cache);
@@ -513,7 +514,21 @@ int netlink_list_chains(struct netlink_ctx *ctx, const struct handle *h)
        nl_cache_foreach_filter(chain_cache, OBJ_CAST(nlc), list_chain_cb, ctx);
        nfnl_nft_chain_put(nlc);
        nl_cache_free(chain_cache);
-       return 0;
+
+       /* Caller wants all existing chains */
+       if (h->chain == NULL)
+               return 0;
+
+       /* Check if this chain exists, otherwise return an error */
+       list_for_each_entry(chain, &ctx->list, list) {
+               if (strcmp(chain->handle.chain, h->chain) == 0)
+                       return 0;
+       }
+
+       return netlink_io_error(ctx, NULL,
+                               "Could not find chain `%s' in table `%s': %s",
+                               h->chain, h->table,
+                               nl_geterror(NLE_OBJ_NOTFOUND));
 }
 
 static int netlink_get_chain_cb(struct nl_msg *msg, void *arg)