diff mbox

[nft,RFC,3/6] netlink: add netlink_delinearize_set() func

Message ID 20140217231822.19943.3523.stgit@nfdev.cica.es
State Changes Requested
Headers show

Commit Message

Arturo Borrero Feb. 17, 2014, 11:18 p.m. UTC
Let's factorize this code, so it can be reused.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
---
 include/netlink.h         |    4 ++++
 src/netlink.c             |   22 ++--------------------
 src/netlink_delinearize.c |   27 +++++++++++++++++++++++++++
 3 files changed, 33 insertions(+), 20 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

Comments

Patrick McHardy Feb. 18, 2014, 1:56 a.m. UTC | #1
On Tue, Feb 18, 2014 at 12:18:22AM +0100, Arturo Borrero Gonzalez wrote:
> Let's factorize this code, so it can be reused.
> 
> Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
> ---
>  include/netlink.h         |    4 ++++
>  src/netlink.c             |   22 ++--------------------
>  src/netlink_delinearize.c |   27 +++++++++++++++++++++++++++
>  3 files changed, 33 insertions(+), 20 deletions(-)
> 
> diff --git a/include/netlink.h b/include/netlink.h
> index 4e3f8aa..13d01f0 100644
> --- a/include/netlink.h
> +++ b/include/netlink.h
> @@ -70,6 +70,10 @@ extern int netlink_linearize_rule(struct netlink_ctx *ctx,
>  extern struct rule *netlink_delinearize_rule(struct netlink_ctx *ctx,
>  					     const struct nft_rule *r);
>  
> +extern const struct datatype *dtype_map_from_kernel(enum nft_data_types type);
> +
> +extern struct set *netlink_delinearize_set(struct netlink_ctx *ctx,
> +					   struct nft_set *nls);

Actually delinarization so far refers to the act of converting a linear
instruction stream into an abstract syntax tree. This is not really a
good term for sets, which are still pretty much linear.

I don't have a good suggestion right now though.
--
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
Arturo Borrero Feb. 18, 2014, 9:11 a.m. UTC | #2
On 18 February 2014 02:56, Patrick McHardy <kaber@trash.net> wrote:
>> +extern struct set *netlink_delinearize_set(struct netlink_ctx *ctx,
>> +                                        struct nft_set *nls);
>
> Actually delinarization so far refers to the act of converting a linear
> instruction stream into an abstract syntax tree. This is not really a
> good term for sets, which are still pretty much linear.
>
> I don't have a good suggestion right now though.

At first, I used something like 'nls2set', but this delinearize thing
sounded more 'serious' :)

In think in all cases, we are converting netlink objects to the
internal nft object. We need a name for that, no?
Patrick McHardy Feb. 18, 2014, 9:21 a.m. UTC | #3
On Tue, Feb 18, 2014 at 10:11:52AM +0100, Arturo Borrero Gonzalez wrote:
> On 18 February 2014 02:56, Patrick McHardy <kaber@trash.net> wrote:
> >> +extern struct set *netlink_delinearize_set(struct netlink_ctx *ctx,
> >> +                                        struct nft_set *nls);
> >
> > Actually delinarization so far refers to the act of converting a linear
> > instruction stream into an abstract syntax tree. This is not really a
> > good term for sets, which are still pretty much linear.
> >
> > I don't have a good suggestion right now though.
> 
> At first, I used something like 'nls2set', but this delinearize thing
> sounded more 'serious' :)
> 
> In think in all cases, we are converting netlink objects to the
> internal nft object. We need a name for that, no?

You *could* call it deserialization since we're converting the attribute
stream into an object and we should (not done so far) convert bitmask
values with more than one bit set into a tree of inclusive OR expressions.

Not sure. I guess you can keep that name until we come up with something
better, but I wouldn't move it to netlink_delinearize.c. This is meant to
mirror netlink_linearize.c, they both only take care of rules.
--
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 mbox

Patch

diff --git a/include/netlink.h b/include/netlink.h
index 4e3f8aa..13d01f0 100644
--- a/include/netlink.h
+++ b/include/netlink.h
@@ -70,6 +70,10 @@  extern int netlink_linearize_rule(struct netlink_ctx *ctx,
 extern struct rule *netlink_delinearize_rule(struct netlink_ctx *ctx,
 					     const struct nft_rule *r);
 
+extern const struct datatype *dtype_map_from_kernel(enum nft_data_types type);
+
+extern struct set *netlink_delinearize_set(struct netlink_ctx *ctx,
+					   struct nft_set *nls);
 extern int netlink_add_rule(struct netlink_ctx *ctx, const struct handle *h,
 			    const struct rule *rule, uint32_t flags);
 extern int netlink_delete_rule(struct netlink_ctx *ctx, const struct handle *h,
diff --git a/src/netlink.c b/src/netlink.c
index 07af1cb..ea6611a 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -731,7 +731,7 @@  static enum nft_data_types dtype_map_to_kernel(const struct datatype *dtype)
 	}
 }
 
-static const struct datatype *dtype_map_from_kernel(enum nft_data_types type)
+const struct datatype *dtype_map_from_kernel(enum nft_data_types type)
 {
 	switch (type) {
 	case NFT_DATA_VERDICT:
@@ -870,7 +870,6 @@  int netlink_get_set(struct netlink_ctx *ctx, const struct handle *h,
 		    const struct location *loc)
 {
 	struct nft_set *nls;
-	struct set *set;
 	int err;
 
 	nls = alloc_nft_set(h);
@@ -881,24 +880,7 @@  int netlink_get_set(struct netlink_ctx *ctx, const struct handle *h,
 					"Could not receive set from kernel: %s",
 					strerror(errno));
 
-	set = set_alloc(&netlink_location);
-	set->handle.family = nft_set_attr_get_u32(nls, NFT_SET_ATTR_FAMILY);
-	set->handle.table  =
-		xstrdup(nft_set_attr_get_str(nls, NFT_SET_ATTR_TABLE));
-	set->handle.set    =
-		xstrdup(nft_set_attr_get_str(nls, NFT_SET_ATTR_NAME));
-	set->keytype       =
-		 dtype_map_from_kernel(nft_set_attr_get_u32(nls, NFT_SET_ATTR_KEY_TYPE));
-	set->keylen        =
-		nft_set_attr_get_u32(nls, NFT_SET_ATTR_KEY_LEN) * BITS_PER_BYTE;
-	set->flags         = nft_set_attr_get_u32(nls, NFT_SET_ATTR_FLAGS);
-	set->datatype      =
-		dtype_map_from_kernel(nft_set_attr_get_u32(nls, NFT_SET_ATTR_DATA_TYPE));
-	if (nft_set_attr_is_set(nls, NFT_SET_ATTR_DATA_LEN)) {
-		set->datalen =
-			nft_set_attr_get_u32(nls, NFT_SET_ATTR_DATA_LEN) * BITS_PER_BYTE;
-	}
-	list_add_tail(&set->list, &ctx->list);
+	netlink_delinearize_set(ctx, nls);
 	nft_set_free(nls);
 
 	return err;
diff --git a/src/netlink_delinearize.c b/src/netlink_delinearize.c
index 0e75c8a..65d1c80 100644
--- a/src/netlink_delinearize.c
+++ b/src/netlink_delinearize.c
@@ -895,3 +895,30 @@  struct rule *netlink_delinearize_rule(struct netlink_ctx *ctx,
 	rule_parse_postprocess(pctx, pctx->rule);
 	return pctx->rule;
 }
+
+struct set *netlink_delinearize_set(struct netlink_ctx *ctx,
+				    struct nft_set *nls)
+{
+	struct set *set;
+
+	set = set_alloc(&internal_location);
+	set->handle.family = nft_set_attr_get_u32(nls, NFT_SET_ATTR_FAMILY);
+	set->handle.table  =
+		xstrdup(nft_set_attr_get_str(nls, NFT_SET_ATTR_TABLE));
+	set->handle.set    =
+		xstrdup(nft_set_attr_get_str(nls, NFT_SET_ATTR_NAME));
+	set->keytype       =
+		 dtype_map_from_kernel(nft_set_attr_get_u32(nls, NFT_SET_ATTR_KEY_TYPE));
+	set->keylen        =
+		nft_set_attr_get_u32(nls, NFT_SET_ATTR_KEY_LEN) * BITS_PER_BYTE;
+	set->flags         = nft_set_attr_get_u32(nls, NFT_SET_ATTR_FLAGS);
+	set->datatype      =
+		dtype_map_from_kernel(nft_set_attr_get_u32(nls, NFT_SET_ATTR_DATA_TYPE));
+	if (nft_set_attr_is_set(nls, NFT_SET_ATTR_DATA_LEN)) {
+		set->datalen =
+			nft_set_attr_get_u32(nls, NFT_SET_ATTR_DATA_LEN) * BITS_PER_BYTE;
+	}
+	list_add_tail(&set->list, &ctx->list);
+
+	return set;
+}