From 8b2d59dadb920ed45dd347e2962ef4cf216d0c57 Mon Sep 17 00:00:00 2001 From: Alvaro Neira Date: Mon, 16 Mar 2015 16:06:09 +0100 Subject: parser: Add operation not supported error message If we try to import a ruleset in json or xml and the library was not compile with support for those, this shows a misleading error. To resolve this problem, this patch sets up EOPNOTSUPP by default when we create the nft_parse_err structure. Signed-off-by: Alvaro Neira Ayuso Signed-off-by: Pablo Neira Ayuso --- src/common.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/common.c') diff --git a/src/common.c b/src/common.c index 7fce48e..d69b522 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_EOPNOTSUPP; + + 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_EOPNOTSUPP: + return fprintf(stderr, "%s: Operation not supported\n", msg); default: return fprintf(stderr, "%s: Undefined error\n", msg); } -- cgit v1.2.3