Series short description
cover Series short description
Add the implementation for exporting chains to JSON Format and for to test the function.
---
Alvaro Neira Ayuso (2):
Add function for exporting chain to JSON Format
Implementation for to test the function for exporting chains to JSON format
examples/nft-chain-get.c | 5 ++++- include/libnftables/chain.h | 1 + src/chain.c | 27 +++++++++++++++++++++++++++ src/internal.h | 1 + 4 files changed, 33 insertions(+), 1 deletion(-)
Signature · 5 lines
Álvaro Neira Ayuso -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 1/2 Add function for exporting chain to JSON Format
From: Alvaro Neira Ayuso <[email protected]>
--- include/libnftables/chain.h | 1 + src/chain.c | 27 +++++++++++++++++++++++++++ src/internal.h | 1 + 3 files changed, 29 insertions(+)
include/libnftables/chain.h +1 -0
@@ -44,6 +44,7 @@ void nft_chain_nlmsg_build_payload(struct nlmsghdr *nlh, const struct nft_chainenum {NFT_CHAIN_O_DEFAULT =0 ,NFT_CHAIN_O_XML , +NFT_CHAIN_O_JSON , };enum nft_chain_parse_type {
src/chain.c +27 -0
@@ -688,6 +688,31 @@ int nft_chain_parse(struct nft_chain *c, enum nft_chain_parse_type type, }EXPORT_SYMBOL (nft_chain_parse); +static int nft_chain_snprintf_json (char *buf,size_t size,struct nft_chain *c) +{ +return snprintf (buf, size, +"{ \"chain\": {" +"\"name\": \"%s\"," +"\"handle\": %lu," +"\"bytes\": %lu," +"\"packets\": %lu," +"\"version\": %d," +"\"properties\": {" +"\"type\" : \"%s\"," +"\"table\" : \"%s\"," +"\"prio\" : %d," +"\"use\" : %d," +"\"hooknum\" : %d," +"\"policy\" : %d," +"\"family\" : %d" +"}" +"}" +"}" , + c->name, c->handle, c->bytes, c->packets, +NFT_CHAIN_JSON_VERSION , c->type, c->table, + c->prio, c->use, c->hooknum, c->policy, c->family); +} +static int nft_chain_snprintf_xml (char *buf,size_t size,struct nft_chain *c) { return snprintf(buf, size,
@@ -721,6 +746,8 @@ int nft_chain_snprintf(char *buf, size_t size, struct nft_chain *c, uint32_t type, uint32_t flags) {switch (type) { +case NFT_CHAIN_O_JSON : +return nft_chain_snprintf_json (buf, size, c);case NFT_CHAIN_O_XML :return nft_chain_snprintf_xml (buf, size, c);case NFT_CHAIN_O_DEFAULT :
src/internal.h +1 -0
@@ -21,6 +21,7 @@#define NFT_CHAIN_XML_VERSION 0#define NFT_RULE_XML_VERSION 0#define NFT_TABLE_JSON_VERSION 0 +#define NFT_CHAIN_JSON_VERSION 0struct expr_ops ;
Re: [libnftables PATCH 1/2] Add function for exporting chain to JSON Format
Applied, thanks.
PATCH 2/2 Implementation for to test the function for exporting chains to JSON format
In reply to Alvaro NeiraFrom: Alvaro Neira Ayuso <[email protected]>
--- examples/nft-chain-get.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
examples/nft-chain-get.c +4 -1
@@ -90,8 +90,11 @@ int main(int argc, char *argv[])exit (EXIT_FAILURE ); } -if (strcmp (argv[argc-1 ],"xml" ) ==0 ) +if (strcmp (argv[argc-1 ],"xml" ) ==0 ){ type =NFT_CHAIN_O_XML ; + }else if (strcmp (argv[argc-1 ],"json" ) ==0 ){ + type =NFT_CHAIN_O_JSON ; + } nl =mnl_socket_open (NETLINK_NETFILTER );if (nl ==NULL ) {
Pablo Neira Ayuso
maintainerRe: [libnftables PATCH 2/2] Implementation for to test the function for exporting chains to JSON format
Applied, thanks Álvaro.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html