diff options
author | Pablo Neira Ayuso <pablo@netfilter.org> | 2013-04-18 16:33:18 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2013-04-18 16:39:27 +0200 |
commit | 40293af99eee781b3782cb6ff7cc49d648e68254 (patch) | |
tree | 03d6e67a796b0553139c9f3937c5e0488e7dc0a9 /src/netlink.c | |
parent | 05ce01fdaf7f657725ce1e5e886813d036b05f25 (diff) |
netlink: return error if chain not found
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>
Diffstat (limited to 'src/netlink.c')
-rw-r--r-- | src/netlink.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/netlink.c b/src/netlink.c index e760ccc9..5b99c2e1 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -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) |