From: Alvaro Neira <alvaroneay@gmail.com>
To: netfilter-devel@vger.kernel.org
Cc: eric@regit.org
Subject: [libnftables PATCH 13/13] jansson: Add nft_jansson_family function
Date: Fri, 09 Aug 2013 13:14:46 +0200 [thread overview]
Message-ID: <20130809111446.29819.79492.stgit@Ph0enix> (raw)
In-Reply-To: <20130809111148.29819.95689.stgit@Ph0enix>
From: Álvaro Neira Ayuso <alvaroneay@gmail.com>
Refactor some existing code with the new function nft_jansson_family
Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
---
src/chain.c | 10 ++--------
src/internal.h | 1 +
src/jansson.c | 18 ++++++++++++++++++
src/table.c | 9 ++-------
4 files changed, 23 insertions(+), 15 deletions(-)
diff --git a/src/chain.c b/src/chain.c
index e2e6f90..a6d99ca 100644
--- a/src/chain.c
+++ b/src/chain.c
@@ -517,14 +517,8 @@ static int nft_chain_json_parse(struct nft_chain *c, char *json)
nft_chain_attr_set_u64(c, NFT_CHAIN_ATTR_PACKETS, uval64);
- valstr = nft_jansson_value_parse_str(root, "family");
-
- if (valstr == NULL)
- goto err;
-
- val32 = nft_str2family(valstr);
- if (val32 == -1)
- goto err;
+ if (nft_jansson_parse_family(root, &val32) != 0)
+ return -1;
nft_chain_attr_set_u32(c, NFT_CHAIN_ATTR_FAMILY, val32);
diff --git a/src/internal.h b/src/internal.h
index 17d1286..62eb3c5 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -49,6 +49,7 @@ int nft_jansson_value_parse_val(json_t *root, const char *tag,
const char *nft_jansson_value_parse_str(json_t *root, const char *tag);
bool nft_jansson_node_exist(json_t *root, const char *tag);
json_t *nft_jansson_get_root(char *json, const char *tag, json_error_t *err);
+int nft_jansson_parse_family(json_t *root, void *out);
#endif
const char *nft_family2str(uint32_t family);
diff --git a/src/jansson.c b/src/jansson.c
index 4c778d9..cc3ab23 100644
--- a/src/jansson.c
+++ b/src/jansson.c
@@ -90,4 +90,22 @@ json_t *nft_jansson_get_root(char *json, const char *tag, json_error_t *err)
return root;
}
+int nft_jansson_parse_family(json_t *root, void *out)
+{
+ const char *str;
+ int family;
+
+ str = nft_jansson_value_parse_str(root, "family");
+ if (str == NULL)
+ return -1;
+
+ family = nft_str2family(str);
+ if (family < 0) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ memcpy(out, &family, sizeof(family));
+ return 0;
+}
#endif
diff --git a/src/table.c b/src/table.c
index 18d9077..1fa0dac 100644
--- a/src/table.c
+++ b/src/table.c
@@ -285,13 +285,8 @@ static int nft_table_json_parse(struct nft_table *t, char *json)
nft_table_attr_set_str(t, NFT_TABLE_ATTR_NAME, strdup(str));
- str = nft_jansson_value_parse_str(root, "family");
- if (str == NULL)
- goto err;
-
- family = nft_str2family(str);
- if (family < 0)
- goto err;
+ if (nft_jansson_parse_family(root, &family) != 0)
+ return -1;
nft_table_attr_set_u32(t, NFT_TABLE_ATTR_FAMILY, family);
--
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
next prev parent reply other threads:[~2013-08-09 11:14 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-09 11:11 [libnftables PATCH 01/13] src: expr: missing commas in json output support Alvaro Neira
2013-08-09 11:12 ` [libnftables PATCH 02/13] src: expr: missing curly braces " Alvaro Neira
2013-08-09 11:12 ` [libnftables PATCH 03/13] src: expr: change wrong value in data_reg Alvaro Neira
2013-08-09 11:12 ` [libnftables PATCH 04/13] src: fix display of compat_flag and compat_proto Alvaro Neira
2013-08-09 11:12 ` [libnftables PATCH 05/13] expr: ct: optional output in ct Alvaro Neira
2013-08-09 11:13 ` [libnftables PATCH 06/13] json: bitwise: add missing node len Alvaro Neira
2013-08-09 11:13 ` [libnftables PATCH 07/13] src: json: delete unneeded JSON prefixes Alvaro Neira
2013-08-09 11:13 ` [libnftables PATCH 08/13] expr: bytecode: add nft_str2ntoh function Alvaro Neira
2013-08-09 11:13 ` [libnftables PATCH 09/13] expr: cmp: add nft_str2cmp function Alvaro Neira
2013-08-09 11:13 ` [libnftables PATCH 10/13] expr: nat: add nft_str2nat function Alvaro Neira
2013-08-09 11:14 ` [libnftables PATCH 11/13] expr: payload: add nft_str2base function Alvaro Neira
2013-08-09 11:31 ` Arturo Borrero Gonzalez
2013-08-09 11:43 ` Pablo Neira Ayuso
2013-08-09 11:34 ` Arturo Borrero Gonzalez
2013-08-09 11:14 ` [libnftables PATCH 12/13] example: nft-rule-get: family parameter added Alvaro Neira
2013-08-09 11:14 ` Alvaro Neira [this message]
2013-08-09 11:44 ` [libnftables PATCH 01/13] src: expr: missing commas in json output support Pablo Neira Ayuso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130809111446.29819.79492.stgit@Ph0enix \
--to=alvaroneay@gmail.com \
--cc=eric@regit.org \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).