From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH nft 3/4] netlink: rework NFTNL_SET_USERDATA to accomodate new attributes
Date: Tue, 28 Feb 2017 01:01:01 +0100 [thread overview]
Message-ID: <1488240062-27366-3-git-send-email-pablo@netfilter.org> (raw)
In-Reply-To: <1488240062-27366-1-git-send-email-pablo@netfilter.org>
Rework the NFTNL_SET_USERDATA in netlink_delinearize_set() to accomodate
rhs datatype byteorder in mappings.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
src/netlink.c | 50 ++++++++++++++++++--------------------------------
1 file changed, 18 insertions(+), 32 deletions(-)
diff --git a/src/netlink.c b/src/netlink.c
index 60d86d61c504..d643034f77ca 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -1122,40 +1122,27 @@ static int set_parse_udata_cb(const struct nftnl_udata *attr, void *data)
return 0;
}
-static uint32_t set_udata_get_key_byteorder(const void *data, uint32_t data_len)
-{
- const struct nftnl_udata *tb[UDATA_TYPE_MAX + 1] = {};
-
- if (nftnl_udata_parse(data, data_len, set_parse_udata_cb, tb) < 0)
- return BYTEORDER_INVALID;
-
- if (!tb[UDATA_SET_KEYBYTEORDER])
- return BYTEORDER_INVALID;
-
- return *((uint32_t *)nftnl_udata_get(tb[UDATA_SET_KEYBYTEORDER]));
-}
-
-static enum byteorder set_key_byteorder(const struct nftnl_set *nls)
-{
- enum byteorder byteorder = BYTEORDER_INVALID;
- const void *data;
- uint32_t len;
-
- if (nftnl_set_is_set(nls, NFTNL_SET_USERDATA)) {
- data = nftnl_set_get_data(nls, NFTNL_SET_USERDATA, &len);
- byteorder = set_udata_get_key_byteorder(data, len);
- }
-
- return byteorder;
-}
-
static struct set *netlink_delinearize_set(struct netlink_ctx *ctx,
const struct nftnl_set *nls)
{
- struct set *set;
- const struct datatype *keytype, *datatype;
+ const struct nftnl_udata *ud[UDATA_SET_MAX + 1] = {};
uint32_t flags, key, data, data_len, objtype = 0;
- enum byteorder byteorder;
+ enum byteorder keybyteorder = BYTEORDER_INVALID;
+ const struct datatype *keytype, *datatype;
+ const char *udata;
+ struct set *set;
+ uint32_t ulen;
+
+ if (nftnl_set_is_set(nls, NFTNL_SET_USERDATA)) {
+ udata = nftnl_set_get_data(nls, NFTNL_SET_USERDATA, &ulen);
+ if (nftnl_udata_parse(udata, ulen, set_parse_udata_cb, ud) < 0) {
+ netlink_io_error(ctx, NULL, "Cannot parse userdata");
+ return NULL;
+ }
+
+ if (ud[UDATA_SET_KEYBYTEORDER])
+ keybyteorder = *((uint32_t *)nftnl_udata_get(ud[UDATA_SET_KEYBYTEORDER]));
+ }
key = nftnl_set_get_u32(nls, NFTNL_SET_KEY_TYPE);
keytype = dtype_map_from_kernel(key);
@@ -1164,7 +1151,6 @@ static struct set *netlink_delinearize_set(struct netlink_ctx *ctx,
key);
return NULL;
}
- byteorder = set_key_byteorder(nls);
flags = nftnl_set_get_u32(nls, NFTNL_SET_FLAGS);
if (flags & NFT_SET_MAP) {
@@ -1189,7 +1175,7 @@ static struct set *netlink_delinearize_set(struct netlink_ctx *ctx,
set->handle.table = xstrdup(nftnl_set_get_str(nls, NFTNL_SET_TABLE));
set->handle.set = xstrdup(nftnl_set_get_str(nls, NFTNL_SET_NAME));
- set->keytype = set_datatype_alloc(keytype, byteorder);
+ set->keytype = set_datatype_alloc(keytype, keybyteorder);
set->keylen = nftnl_set_get_u32(nls, NFTNL_SET_KEY_LEN) * BITS_PER_BYTE;
set->flags = nftnl_set_get_u32(nls, NFTNL_SET_FLAGS);
--
2.1.4
next prev parent reply other threads:[~2017-02-28 0:02 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-28 0:00 [PATCH nft 1/4] evaluate: set byteorder as lhs expression context in stmt_evaluate_arg() Pablo Neira Ayuso
2017-02-28 0:01 ` [PATCH nft 2/4] src: rename set_keytype_alloc() to set_datatype_alloc() Pablo Neira Ayuso
2017-02-28 0:01 ` Pablo Neira Ayuso [this message]
2017-02-28 0:01 ` [PATCH nft 4/4] src: store byteorder for set data 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=1488240062-27366-3-git-send-email-pablo@netfilter.org \
--to=pablo@netfilter.org \
--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).