netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [libnftnl PATCH 2/3] example/nft-rule-insert: fixed and merged this example with nft-rule-add
Date: Sat, 8 Mar 2014 15:16:53 +0100	[thread overview]
Message-ID: <20140308141653.GA7854@localhost> (raw)
In-Reply-To: <20140308140045.13220.19401.stgit@Ph0enix>

On Sat, Mar 08, 2014 at 03:00:45PM +0100, Alvaro Neira Ayuso wrote:
> From: Álvaro Neira Ayuso <anayuso@sysmocom.de>
> 
> Merged the example for inserting rules and fixed for using
> the correct header.
> 
> Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
> Signed-off-by: Alvaro Neira Ayuso <anayuso@sysmocom.de>
> ---
>  examples/nft-rule-add.c |   16 +++++++++++++---
>  1 file changed, 13 insertions(+), 3 deletions(-)
> 
> 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;

Oh, this variable name is horrible, better handle_num?

>  	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");
                ^----------------^

I think you have to remove that.

> +		hand = atoi(handle);

This is u64, atoi is just 32 bits. You can use atoll or strtoull.

> +		nft_rule_attr_set(r, NFT_RULE_ATTR_POSITION, &hand);

Use nft_rule_attr_set_u64, please.

> +	}
> +
>  	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 <family> <table> <chain>\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) {
> 
> --
> 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
--
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

  reply	other threads:[~2014-03-08 14:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-08 14:00 [libnftnl PATCH 1/3] example: fix the example for deleting rules Alvaro Neira Ayuso
2014-03-08 14:00 ` [libnftnl PATCH 2/3] example/nft-rule-insert: fixed and merged this example with nft-rule-add Alvaro Neira Ayuso
2014-03-08 14:16   ` Pablo Neira Ayuso [this message]
2014-03-08 14:00 ` [libnftnl PATCH 3/3] example: removed printf rule function Alvaro Neira Ayuso
2014-03-08 14:17 ` [libnftnl PATCH 1/3] example: fix the example for deleting rules 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=20140308141653.GA7854@localhost \
    --to=pablo@netfilter.org \
    --cc=alvaroneay@gmail.com \
    --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).