Patchwork [libnftables,2/2] examples: nft-table-get different families options

login
register
mail settings
Submitter Alvaro Neira
Date July 5, 2013, 12:41 p.m.
Message ID <20130705124135.23285.58726.stgit@Ph0enix>
Download mbox | patch
Permalink /patch/257174/
State Accepted
Headers show

Comments

Alvaro Neira - July 5, 2013, 12:41 p.m.
From: Álvaro Neira Ayuso <alvaroneay@gmail.com>

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
---
 examples/nft-table-get.c |   26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)


--
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
Pablo Neira - July 5, 2013, 10:23 p.m.
On Fri, Jul 05, 2013 at 02:41:35PM +0200, Alvaro Neira wrote:
> From: Álvaro Neira Ayuso <alvaroneay@gmail.com>
> 
> Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
> ---
>  examples/nft-table-get.c |   26 +++++++++++++++++++++-----
>  1 file changed, 21 insertions(+), 5 deletions(-)

Also applied, thanks.
--
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

Patch

diff --git a/examples/nft-table-get.c b/examples/nft-table-get.c
index 0d7746c..eab78de 100644
--- a/examples/nft-table-get.c
+++ b/examples/nft-table-get.c
@@ -50,11 +50,27 @@  int main(int argc, char *argv[])
 	struct mnl_socket *nl;
 	char buf[MNL_SOCKET_BUFFER_SIZE];
 	struct nlmsghdr *nlh;
-	uint32_t portid, seq;
+	uint32_t portid, seq, family;
 	struct nft_table *t = NULL;
 	int ret;
 	uint32_t type = NFT_TABLE_O_DEFAULT;
 
+	if (argc < 2 || argc > 4) {
+		fprintf(stderr, "%s <family> [<table>] [default|xml|json]\n", argv[0]);
+		return EXIT_FAILURE;
+	}
+
+	if (strcmp(argv[1], "ip") == 0)
+		family = AF_INET;
+	else if (strcmp(argv[1], "ip6") == 0)
+		family = AF_INET6;
+	else if (strcmp(argv[1], "bridge") == 0)
+		family = AF_BRIDGE;
+	else {
+		fprintf(stderr, "Unknown family: ip, ip6, bridge\n");
+		exit(EXIT_FAILURE);
+	}
+
 	if (strcmp(argv[argc-1], "xml") == 0) {
 		type = NFT_TABLE_O_XML;
 		argv[argc-1] = NULL;
@@ -67,7 +83,7 @@  int main(int argc, char *argv[])
 		argc--;
 	}
 
-	if (argc == 2) {
+	if (argc == 3) {
 		t = nft_table_alloc();
 		if (t == NULL) {
 			perror("OOM");
@@ -77,12 +93,12 @@  int main(int argc, char *argv[])
 
 	seq = time(NULL);
 	if (t == NULL) {
-		nlh = nft_table_nlmsg_build_hdr(buf, NFT_MSG_GETTABLE, AF_INET,
+		nlh = nft_table_nlmsg_build_hdr(buf, NFT_MSG_GETTABLE, family,
 						NLM_F_DUMP, seq);
 	} else {
-		nlh = nft_table_nlmsg_build_hdr(buf, NFT_MSG_GETTABLE, AF_INET,
+		nlh = nft_table_nlmsg_build_hdr(buf, NFT_MSG_GETTABLE, family,
 						NLM_F_ACK, seq);
-		nft_table_attr_set(t, NFT_TABLE_ATTR_NAME, argv[1]);
+		nft_table_attr_set(t, NFT_TABLE_ATTR_NAME, argv[2]);
 		nft_table_nlmsg_build_payload(nlh, t);
 		nft_table_free(t);
 	}