diff mbox

[libnftnl,1/3] parser: Add operation not supported error message

Message ID 1426518371-11717-1-git-send-email-alvaroneay@gmail.com
State Accepted
Delegated to: Pablo Neira
Headers show

Commit Message

Alvaro Neira March 16, 2015, 3:06 p.m. UTC
If we try to import a ruleset in json or xml and the operation is not
supported, we don't show any error message to this case.

This patch adds a new error path if the operation is not supported.
Moreover, this patch sets up this error by default when we create the
structure nft_parse_err.

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
---
 include/libnftnl/common.h |    1 +
 src/common.c              |   12 +++++++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

Comments

Pablo Neira Ayuso March 17, 2015, 10:49 a.m. UTC | #1
On Mon, Mar 16, 2015 at 04:06:09PM +0100, Alvaro Neira Ayuso wrote:
> If we try to import a ruleset in json or xml and the operation is not
> supported, we don't show any error message to this case.
> 
> This patch adds a new error path if the operation is not supported.
> Moreover, this patch sets up this error by default when we create the
> structure nft_parse_err.

Applied, thanks.

I have rewritten this summary a bit and renamed from
NFT_PARSE_OPNOTSUPP to NFT_PARSE_EOPNOTSUPP for consistency.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/include/libnftnl/common.h b/include/libnftnl/common.h
index f8f1304..d92b170 100644
--- a/include/libnftnl/common.h
+++ b/include/libnftnl/common.h
@@ -7,6 +7,7 @@  enum {
 	NFT_PARSE_EBADINPUT	= 0,
 	NFT_PARSE_EMISSINGNODE,
 	NFT_PARSE_EBADTYPE,
+	NFT_PARSE_OPNOTSUPP,
 };
 
 enum nft_output_type {
diff --git a/src/common.c b/src/common.c
index 7fce48e..fc0bc97 100644
--- a/src/common.c
+++ b/src/common.c
@@ -44,7 +44,15 @@  EXPORT_SYMBOL(nft_nlmsg_build_hdr);
 
 struct nft_parse_err *nft_parse_err_alloc(void)
 {
-	return calloc(1, sizeof(struct nft_parse_err));
+	struct nft_parse_err *err;
+
+	err = calloc(1, sizeof(struct nft_parse_err));
+	if (err == NULL)
+		return NULL;
+
+	err->error = NFT_PARSE_OPNOTSUPP;
+
+	return err;
 }
 EXPORT_SYMBOL(nft_parse_err_alloc);
 
@@ -66,6 +74,8 @@  int nft_parse_perror(const char *msg, struct nft_parse_err *err)
 	case NFT_PARSE_EBADTYPE:
 		return fprintf(stderr, "%s: Invalid type in node \"%s\"\n",
 			       msg, err->node_name);
+	case NFT_PARSE_OPNOTSUPP:
+		return fprintf(stderr, "%s: Operation not supported\n", msg);
 	default:
 		return fprintf(stderr, "%s: Undefined error\n", msg);
 	}