From: Patrick McHardy <kaber@trash.net>
To: pablo@netfilter.org
Cc: netfilter-devel@vger.kernel.org
Subject: [PATCH nft 6/9] netlink: pad constant concat sub-expressions
Date: Fri, 5 Jun 2015 15:42:48 +0200 [thread overview]
Message-ID: <1433511771-4620-7-git-send-email-kaber@trash.net> (raw)
In-Reply-To: <1433511771-4620-1-git-send-email-kaber@trash.net>
Pad all but the last sub-expressions of a concat expressions.
Signed-off-by: Patrick McHardy <kaber@trash.net>
---
include/netlink.h | 10 ++++++++++
src/datatype.c | 3 ++-
src/netlink.c | 14 ++++++--------
3 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/include/netlink.h b/include/netlink.h
index 9b42fdb..185c435 100644
--- a/include/netlink.h
+++ b/include/netlink.h
@@ -58,6 +58,16 @@ static inline unsigned int netlink_register_space(unsigned int size)
return div_round_up(size, NFT_REG32_SIZE * BITS_PER_BYTE);
}
+static inline unsigned int netlink_padded_len(unsigned int size)
+{
+ return netlink_register_space(size) * NFT_REG32_SIZE * BITS_PER_BYTE;
+}
+
+static inline unsigned int netlink_padding_len(unsigned int size)
+{
+ return netlink_padded_len(size) - size;
+}
+
extern void netlink_gen_data(const struct expr *expr,
struct nft_data_linearize *data);
extern void netlink_gen_raw_data(const mpz_t value, enum byteorder byteorder,
diff --git a/src/datatype.c b/src/datatype.c
index f93337b..a06a58e 100644
--- a/src/datatype.c
+++ b/src/datatype.c
@@ -23,6 +23,7 @@
#include <expression.h>
#include <gmputil.h>
#include <erec.h>
+#include <netlink.h>
#include <netinet/ip_icmp.h>
#include <netinet/icmp6.h>
@@ -943,7 +944,7 @@ const struct datatype *concat_type_alloc(uint32_t type)
strncat(desc, i->desc, sizeof(desc) - strlen(desc) - 1);
strncat(name, i->name, sizeof(name) - strlen(name) - 1);
- size += i->size;
+ size += netlink_padded_len(i->size);
subtypes++;
}
strncat(desc, ")", sizeof(desc) - strlen(desc) - 1);
diff --git a/src/netlink.c b/src/netlink.c
index d31387f..3369d22 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -273,23 +273,21 @@ static void netlink_gen_concat_data(const struct expr *expr,
const struct expr *i;
unsigned int len, offset;
- len = 0;
- list_for_each_entry(i, &expr->expressions, list)
- len += i->len;
-
+ len = expr->len / BITS_PER_BYTE;
if (1) {
- unsigned char data[len / BITS_PER_BYTE];
+ unsigned char data[len];
+ memset(data, 0, sizeof(data));
offset = 0;
list_for_each_entry(i, &expr->expressions, list) {
assert(i->ops->type == EXPR_VALUE);
mpz_export_data(data + offset, i->value, i->byteorder,
i->len / BITS_PER_BYTE);
- offset += i->len / BITS_PER_BYTE;
+ offset += netlink_padded_len(i->len) / BITS_PER_BYTE;
}
- memcpy(nld->value, data, len / BITS_PER_BYTE);
- nld->len = len / BITS_PER_BYTE;
+ memcpy(nld->value, data, len);
+ nld->len = len;
}
}
--
2.1.0
next prev parent reply other threads:[~2015-06-05 13:42 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-05 13:42 [PATCH nft 0/9] concat support Patrick McHardy
2015-06-05 13:42 ` [PATCH nft 1/9] eval: prohibit variable sized types in concat expressions Patrick McHardy
2015-06-05 13:42 ` [PATCH nft 2/9] headers: sync headers for new register values Patrick McHardy
2015-06-05 13:42 ` [PATCH nft 3/9] netlink: pass expression to register allocation/release functions Patrick McHardy
2015-06-05 13:42 ` [PATCH nft 4/9] netlink_linearize: use NFT_REG32 values internally Patrick McHardy
2015-06-05 13:42 ` [PATCH nft 5/9] netlink_linearize: generate concat expressions Patrick McHardy
2015-06-05 13:42 ` Patrick McHardy [this message]
2015-06-05 13:42 ` [PATCH nft 7/9] netlink_delinearize: introduce register translation helper Patrick McHardy
2015-06-05 13:42 ` [PATCH nft 8/9] netlink_delinearize: handle relational and lookup concat expressions Patrick McHardy
2015-06-05 13:42 ` [PATCH nft 9/9] netlink: handle concat expressions in set data Patrick McHardy
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=1433511771-4620-7-git-send-email-kaber@trash.net \
--to=kaber@trash.net \
--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 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).