From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [libnftnl PATCH 3/4 v4] example: Parse and create netlink message using the new parsing functions.
Date: Fri, 30 Jan 2015 20:43:53 +0100 [thread overview]
Message-ID: <20150130194353.GA23741@salvia> (raw)
In-Reply-To: <1422628525-28109-3-git-send-email-alvaroneay@gmail.com>
On Fri, Jan 30, 2015 at 03:35:24PM +0100, Alvaro Neira Ayuso wrote:
> + NFT_SET_ATTR_FAMILY),
> + type, seq++);
> + nft_set_elems_nlmsg_build_payload(nlh, tmp);
> + mnl_nlmsg_batch_next(batch);
> + elem = nft_set_elems_iter_next(iter_elems);
> + }
> +
> + return 0;
> +}
> +
> +static int nft_ruleset_set(const struct nft_parse_ctx *ctx, uint32_t ctx_cmd)
> +{
> +
> + struct nlmsghdr *nlh;
> + uint16_t type = 0, cmd = 0;
> + struct nft_set *set;
> +
> + set = nft_ruleset_ctx_get(ctx, NFT_RULESET_CTX_SET);
> + if (set == NULL)
> + return -1;
> +
> + switch (ctx_cmd) {
> + case NFT_CMD_ADD:
> + cmd = NFT_MSG_NEWSET;
Please, choose variable name that stick to the semantics: this is nl_type.
> + type = NLM_F_CREATE|NLM_F_ACK;
and this is nl_flags.
Then, you don't need that ctx_cmd and cmd. Make this change to all
similar functions in this code.
> + break;
> + case NFT_CMD_DELETE:
> + cmd = NFT_MSG_DELSET;
> + type = NLM_F_ACK;
> + break;
> + }
> +
> + nlh = nft_set_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
> + cmd,
> + nft_set_attr_get_u32(set,
> + NFT_SET_ATTR_FAMILY),
> + type,
> + seq++);
> +
> + nft_set_nlmsg_build_payload(nlh, set);
> +
> + mnl_nlmsg_batch_next(batch);
> +
> + if (nft_ruleset_set_elems(ctx, ctx_cmd) < 0)
> + return -1;
> +
> + return 0;
> +}
> +
> +static int nft_ruleset_rule(const struct nft_parse_ctx *ctx, uint32_t ctx_cmd,
> + struct nft_rule *nlr)
> +{
> + struct nlmsghdr *nlh;
> + uint16_t type = 0, cmd = 0;
> + struct nft_rule *rule;
> +
> + if (nft_ruleset_ctx_is_set(ctx, NFT_RULESET_CTX_RULE))
> + rule = nft_ruleset_ctx_get(ctx, NFT_RULESET_CTX_RULE);
> + else
> + rule = nlr;
> +
> + if (rule == NULL)
> + return -1;
> +
> + switch (ctx_cmd) {
> + case NFT_CMD_ADD:
> + cmd = NFT_MSG_NEWRULE;
> + type = NLM_F_APPEND|NLM_F_CREATE|NLM_F_ACK;
> + nft_rule_attr_unset(rule, NFT_RULE_ATTR_HANDLE);
This reminds me that we need a NFT_RULE_OF_NOHANDLE to skip exporting
the handling on demand via nft_rule_snprintf().
next prev parent reply other threads:[~2015-01-30 19:40 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-30 14:35 [libnftnl PATCH 1/4 v2] src: add command tag in json/xml export support Alvaro Neira Ayuso
2015-01-30 14:35 ` [libnftnl PATCH 2/4 v2] src: add support to import json/xml with the new syntax Alvaro Neira Ayuso
2015-01-30 18:38 ` Pablo Neira Ayuso
2015-01-30 19:56 ` Pablo Neira Ayuso
2015-01-30 14:35 ` [libnftnl PATCH 3/4 v4] example: Parse and create netlink message using the new parsing functions Alvaro Neira Ayuso
2015-01-30 19:43 ` Pablo Neira Ayuso [this message]
2015-01-30 14:35 ` [libnftnl PATCH 4/4 v2] test: update json/xml tests to the new syntax Alvaro Neira Ayuso
2015-01-30 18:38 ` Pablo Neira Ayuso
2015-01-30 18:36 ` [libnftnl PATCH 1/4 v2] src: add command tag in json/xml export 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=20150130194353.GA23741@salvia \
--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).