From patchwork Fri Aug 9 11:14:31 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alvaro Neira X-Patchwork-Id: 266002 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id EB1382C00A3 for ; Fri, 9 Aug 2013 21:14:42 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S967709Ab3HILOm (ORCPT ); Fri, 9 Aug 2013 07:14:42 -0400 Received: from mail-wi0-f169.google.com ([209.85.212.169]:62296 "EHLO mail-wi0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S967573Ab3HILOl (ORCPT ); Fri, 9 Aug 2013 07:14:41 -0400 Received: by mail-wi0-f169.google.com with SMTP id f14so1629567wiw.0 for ; Fri, 09 Aug 2013 04:14:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:from:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-type:content-transfer-encoding; bh=8KfM56KjxGbMHqxrwiWpvAHieFCAdEU9piFef1tmjek=; b=K9inN4eK5a7yG8N3kxGcK2tPmY1gymp9p03drbefcsEDTR3bKnuBS5mi8nOeHNvxLb 0xu0zKOVFfDu6figZyjLVr6E0O9mk55oj6Z5KZ6MlehIPEAy9qocaigy0M6J2t2UAQ9X ziWKF50h6UkC2bwp6Kfo/LPaA/kPF9fPDOstECR4sqnT3+xTLy2rTPo8hYp9F1q5fiz5 5hAKk8rZLDAt7H/0khrre4L4Su4gge5gP3rWBUYnMeohC9/6p8yQmurSuvHL5OcX0XK8 byY4bXTvFg/NRWB9pQ9ogZB3gFaF5+NPNU4vddYGrDj6vkZGiym21UuFR1KU4QK2eauD W9vA== X-Received: by 10.180.10.99 with SMTP id h3mr107409wib.0.1376046880505; Fri, 09 Aug 2013 04:14:40 -0700 (PDT) Received: from [127.0.1.1] ([90.174.0.186]) by mx.google.com with ESMTPSA id n2sm2196842wiz.4.2013.08.09.04.14.35 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 09 Aug 2013 04:14:39 -0700 (PDT) Subject: [libnftables PATCH 12/13] example: nft-rule-get: family parameter added To: netfilter-devel@vger.kernel.org From: Alvaro Neira Cc: eric@regit.org Date: Fri, 09 Aug 2013 13:14:31 +0200 Message-ID: <20130809111431.29819.64631.stgit@Ph0enix> In-Reply-To: <20130809111148.29819.95689.stgit@Ph0enix> References: <20130809111148.29819.95689.stgit@Ph0enix> User-Agent: StGit/0.15 MIME-Version: 1.0 Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org From: Álvaro Neira Ayuso I have added the parameter family in the example nft-rule-get. Signed-off-by: Alvaro Neira Ayuso --- examples/nft-rule-get.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 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 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 #include +#include #include #include @@ -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 [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);