From: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
To: netfilter-devel@vger.kernel.org
Cc: pablo@netfilter.org
Subject: [nft PATCH 4/8] netlink: add netlink_delinearize_chain() func
Date: Mon, 14 Apr 2014 12:17:24 +0200 [thread overview]
Message-ID: <20140414101724.5018.37509.stgit@nfdev.cica.es> (raw)
In-Reply-To: <20140414101634.5018.86819.stgit@nfdev.cica.es>
Let's make this code reusable.
Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
---
src/netlink.c | 46 +++++++++++++++++++++-------------------------
1 file changed, 21 insertions(+), 25 deletions(-)
diff --git a/src/netlink.c b/src/netlink.c
index e7b3ec1..91f1304 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -500,20 +500,11 @@ int netlink_delete_chain(struct netlink_ctx *ctx, const struct handle *h,
return err;
}
-static int list_chain_cb(struct nft_chain *nlc, void *arg)
+static struct chain *netlink_delinearize_chain(struct netlink_ctx *ctx,
+ struct nft_chain *nlc)
{
- struct netlink_ctx *ctx = arg;
- const struct handle *h = ctx->data;
struct chain *chain;
- if ((h->family != nft_chain_attr_get_u32(nlc, NFT_CHAIN_ATTR_FAMILY)) ||
- strcmp(nft_chain_attr_get_str(nlc, NFT_CHAIN_ATTR_TABLE), h->table) != 0)
- return 0;
-
- if (h->chain &&
- strcmp(nft_chain_attr_get_str(nlc, NFT_CHAIN_ATTR_NAME), h->chain) != 0)
- return 0;
-
chain = chain_alloc(nft_chain_attr_get_str(nlc, NFT_CHAIN_ATTR_NAME));
chain->handle.family =
nft_chain_attr_get_u32(nlc, NFT_CHAIN_ATTR_FAMILY);
@@ -535,6 +526,24 @@ static int list_chain_cb(struct nft_chain *nlc, void *arg)
}
list_add_tail(&chain->list, &ctx->list);
+ return chain;
+}
+
+static int list_chain_cb(struct nft_chain *nlc, void *arg)
+{
+ struct netlink_ctx *ctx = arg;
+ const struct handle *h = ctx->data;
+ const char *table = nft_chain_attr_get_str(nlc, NFT_CHAIN_ATTR_TABLE);
+ const char *name = nft_chain_attr_get_str(nlc, NFT_CHAIN_ATTR_NAME);
+
+ if ((h->family != nft_chain_attr_get_u32(nlc, NFT_CHAIN_ATTR_FAMILY)) ||
+ strcmp(table, h->table) != 0)
+ return 0;
+
+ if (h->chain && strcmp(name, h->chain) != 0)
+ return 0;
+
+ netlink_delinearize_chain(ctx, nlc);
return 0;
}
@@ -574,25 +583,12 @@ int netlink_get_chain(struct netlink_ctx *ctx, const struct handle *h,
const struct location *loc)
{
struct nft_chain *nlc;
- struct chain *chain;
int err;
nlc = alloc_nft_chain(h);
err = mnl_nft_chain_get(nf_sock, nlc, 0);
- chain = chain_alloc(nft_chain_attr_get_str(nlc, NFT_CHAIN_ATTR_NAME));
- chain->handle.family = nft_chain_attr_get_u32(nlc, NFT_CHAIN_ATTR_FAMILY);
- chain->handle.table = xstrdup(nft_chain_attr_get_str(nlc, NFT_CHAIN_ATTR_TABLE));
- chain->handle.handle = nft_chain_attr_get_u64(nlc, NFT_CHAIN_ATTR_HANDLE);
- if (nft_chain_attr_is_set(nlc, NFT_CHAIN_ATTR_TYPE) &&
- nft_chain_attr_is_set(nlc, NFT_CHAIN_ATTR_HOOKNUM) &&
- nft_chain_attr_is_set(nlc, NFT_CHAIN_ATTR_PRIO)) {
- chain->hooknum = nft_chain_attr_get_u32(nlc, NFT_CHAIN_ATTR_HOOKNUM);
- chain->priority = nft_chain_attr_get_u32(nlc, NFT_CHAIN_ATTR_PRIO);
- chain->type = xstrdup(nft_chain_attr_get_str(nlc, NFT_CHAIN_ATTR_TYPE));
- }
- list_add_tail(&chain->list, &ctx->list);
-
+ netlink_delinearize_chain(ctx, nlc);
nft_chain_free(nlc);
if (err < 0)
next prev parent reply other threads:[~2014-04-14 10:17 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-14 10:17 [nft PATCH 0/8] nft event monitor Arturo Borrero Gonzalez
2014-04-14 10:17 ` [nft PATCH 1/8] rule: allow to print sets in plain format Arturo Borrero Gonzalez
2014-04-14 10:17 ` [nft PATCH 2/8] netlink: add netlink_delinearize_set() func Arturo Borrero Gonzalez
2014-04-14 10:17 ` [nft PATCH 3/8] rule: generalize chain_print() Arturo Borrero Gonzalez
2014-04-14 10:17 ` Arturo Borrero Gonzalez [this message]
2014-04-14 10:17 ` [nft PATCH 5/8] netlink: add netlink_delinearize_table() func Arturo Borrero Gonzalez
2014-04-14 10:17 ` [nft PATCH 6/8] netlink: refactorize set_elem conversion from netlink Arturo Borrero Gonzalez
2014-04-14 10:17 ` [nft PATCH 7/8] netlink: add socket error reporting helper function Arturo Borrero Gonzalez
2014-04-14 10:17 ` [nft PATCH 8/8] src: add events reporting Arturo Borrero Gonzalez
2014-04-14 12:28 ` Pablo Neira Ayuso
2014-04-14 12:32 ` [nft PATCH 0/8] nft event monitor Pablo Neira Ayuso
2014-04-14 12:35 ` Patrick McHardy
2014-04-28 14:28 ` 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=20140414101724.5018.37509.stgit@nfdev.cica.es \
--to=arturo.borrero.glez@gmail.com \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.