]> git.ipfire.org Git - thirdparty/libnftnl.git/commitdiff
parser: Add operation not supported error message
authorAlvaro Neira <alvaroneay@gmail.com>
Mon, 16 Mar 2015 15:06:09 +0000 (16:06 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 17 Mar 2015 10:47:44 +0000 (11:47 +0100)
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 <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
include/libnftnl/common.h
src/common.c

index f8f13040362c6c1e6e97fee5495058d208f1b9ee..14db823fd88a039a881251c470ca5ae3f6f98824 100644 (file)
@@ -7,6 +7,7 @@ enum {
        NFT_PARSE_EBADINPUT     = 0,
        NFT_PARSE_EMISSINGNODE,
        NFT_PARSE_EBADTYPE,
+       NFT_PARSE_EOPNOTSUPP,
 };
 
 enum nft_output_type {
index 7fce48eac96a5c7530f7227327b7e66209995348..d69b522be8c9b8685851cd19aa489c747750a307 100644 (file)
@@ -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);
        }