netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alvaro Neira <alvaroneay@gmail.com>
To: netfilter-devel@vger.kernel.org
Cc: eric@regit.org
Subject: [libnftables PATCH 12/13] example: nft-rule-get: family parameter added
Date: Fri, 09 Aug 2013 13:14:31 +0200	[thread overview]
Message-ID: <20130809111431.29819.64631.stgit@Ph0enix> (raw)
In-Reply-To: <20130809111148.29819.95689.stgit@Ph0enix>

From: Álvaro Neira Ayuso <alvaroneay@gmail.com>

I have added the parameter family in the example nft-rule-get.

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

diff --git a/examples/nft-rule-get.c b/examples/nft-rule-get.c
index 2404f27..e78a5cf 100644
--- a/examples/nft-rule-get.c
+++ b/examples/nft-rule-get.c
@@ -14,6 +14,7 @@
 #include <string.h>
 #include <netinet/in.h>
 
+#include <linux/netfilter.h>
 #include <linux/netfilter/nf_tables.h>
 
 #include <libmnl/libmnl.h>
@@ -52,13 +53,31 @@ int main(int argc, char *argv[])
 	struct nlmsghdr *nlh;
 	uint32_t portid, seq, type = NFT_RULE_O_DEFAULT;
 	struct nft_rule *t = NULL;
-	int ret;
+	int ret, family;
 
-	if (argc == 2 && strcmp(argv[1], "xml") == 0 ){
+	if (argc < 2 || argc > 3) {
+		fprintf(stderr, "Usage: %s <family> [xml|json]\n",
+			argv[0]);
+		exit(EXIT_FAILURE);
+	}
+
+	if (strcmp(argv[1], "ip") == 0)
+		family = NFPROTO_IPV4;
+	else if (strcmp(argv[1], "ip6") == 0)
+		family = NFPROTO_IPV6;
+	else if (strcmp(argv[1], "bridge") == 0)
+		family = NFPROTO_BRIDGE;
+	else if (strcmp(argv[1], "arp") == 0)
+		family = NFPROTO_ARP;
+	else {
+		fprintf(stderr, "Unknown family: ip, ip6, bridge, arp\n");
+		exit(EXIT_FAILURE);
+	}
+
+	if (argc == 3 && strcmp(argv[2], "xml") == 0 )
 		type = NFT_RULE_O_XML;
-	}else if (argc == 2 && strcmp(argv[1], "json") == 0 ){
+	else if (argc == 3 && strcmp(argv[2], "json") == 0 )
 		type = NFT_RULE_O_JSON;
-	}
 
 	/* XXX requires table, chain and handle attributes for selective get */
 
@@ -69,7 +88,7 @@ int main(int argc, char *argv[])
 	}
 
 	seq = time(NULL);
-	nlh = nft_rule_nlmsg_build_hdr(buf, NFT_MSG_GETRULE, AF_INET,
+	nlh = nft_rule_nlmsg_build_hdr(buf, NFT_MSG_GETRULE, family,
 					NLM_F_DUMP, seq);
 
 	nl = mnl_socket_open(NETLINK_NETFILTER);

--
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

  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 ` Alvaro Neira [this message]
2013-08-09 11:14 ` [libnftables PATCH 13/13] jansson: Add nft_jansson_family function Alvaro Neira
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=20130809111431.29819.64631.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).