From patchwork Sat Mar 8 14:00:45 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alvaro Neira X-Patchwork-Id: 328195 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 054642C00BA for ; Sun, 9 Mar 2014 01:01:19 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751440AbaCHOBS (ORCPT ); Sat, 8 Mar 2014 09:01:18 -0500 Received: from mail-bk0-f52.google.com ([209.85.214.52]:46627 "EHLO mail-bk0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751099AbaCHOA7 (ORCPT ); Sat, 8 Mar 2014 09:00:59 -0500 Received: by mail-bk0-f52.google.com with SMTP id my13so1054814bkb.11 for ; Sat, 08 Mar 2014 06:00:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:from:date:message-id:in-reply-to:references:user-agent :mime-version:content-type:content-transfer-encoding; bh=fq8rHtCYlwT17jmyIrW4FfCaniO5NmUJlrP/x2U0jjE=; b=re8itLTQV9jtCAOVZs7UF341h+qHYAjQR1p3+s9XcG5G4dBuIWJJRs5uMB1uxa4PiY 3mGAQSW3NBqP9OPHNe3C6Tx8w+oDehxhIrBuhkJ+3SzYsl5/5mZwkp8uB0lh8RW5ufZl qQ5PQE0S7fXeVc8JEWNl3zm/dBVSoYwurbMJG+yAaVrg0+8AK3FKjqGFaax6rD3I+++Y mjmHdmgKw+Cbvcjiu82DeKyktHlQcE9pAcPpaAVosIKTGeqV0+ZdbgI+23/zjKLNUlP0 R0Jz58D4k5T+8bI+yha2iDDjTlY1l87XUHswWXs9cfjFBFmF+C9zQ0/levpK8nl0gXmO sUSw== X-Received: by 10.204.54.197 with SMTP id r5mr1145956bkg.27.1394287257937; Sat, 08 Mar 2014 06:00:57 -0800 (PST) Received: from [127.0.1.1] ([2001:bf0:c001:30:3d1f:93c2:7e21:8d5c]) by mx.google.com with ESMTPSA id xj2sm5719351bkb.15.2014.03.08.06.00.57 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 08 Mar 2014 06:00:57 -0800 (PST) Subject: [libnftnl PATCH 2/3] example/nft-rule-insert: fixed and merged this example with nft-rule-add To: netfilter-devel@vger.kernel.org From: Alvaro Neira Ayuso Date: Sat, 08 Mar 2014 15:00:45 +0100 Message-ID: <20140308140045.13220.19401.stgit@Ph0enix> In-Reply-To: <20140308140039.13220.89013.stgit@Ph0enix> References: <20140308140039.13220.89013.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 Merged the example for inserting rules and fixed for using the correct header. Signed-off-by: Alvaro Neira Ayuso Signed-off-by: Alvaro Neira Ayuso --- examples/nft-rule-add.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 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-add.c b/examples/nft-rule-add.c index 21b3bf8..7407a78 100644 --- a/examples/nft-rule-add.c +++ b/examples/nft-rule-add.c @@ -80,11 +80,12 @@ static void add_counter(struct nft_rule *r) } static struct nft_rule *setup_rule(uint8_t family, const char *table, - const char *chain) + const char *chain, const char *handle) { struct nft_rule *r = NULL; uint8_t proto; uint16_t dport; + uint64_t hand; r = nft_rule_alloc(); if (r == NULL) { @@ -96,6 +97,12 @@ static struct nft_rule *setup_rule(uint8_t family, const char *table, nft_rule_attr_set(r, NFT_RULE_ATTR_CHAIN, chain); nft_rule_attr_set_u32(r, NFT_RULE_ATTR_FAMILY, family); + if (handle != NULL) { + printf("entra\n"); + hand = atoi(handle); + nft_rule_attr_set(r, NFT_RULE_ATTR_POSITION, &hand); + } + proto = IPPROTO_TCP; add_payload(r, NFT_PAYLOAD_NETWORK_HEADER, NFT_REG_1, offsetof(struct iphdr, protocol), sizeof(uint8_t)); @@ -138,7 +145,7 @@ int main(int argc, char *argv[]) uint32_t seq = time(NULL); int ret; - if (argc != 4) { + if (argc < 4 || argc > 5) { fprintf(stderr, "Usage: %s \n", argv[0]); exit(EXIT_FAILURE); } @@ -152,7 +159,10 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } - r = setup_rule(family, argv[2], argv[3]); + if (argc != 5) + r = setup_rule(family, argv[2], argv[3], NULL); + else + r = setup_rule(family, argv[2], argv[3], argv[4]); nl = mnl_socket_open(NETLINK_NETFILTER); if (nl == NULL) {