diff options
author | Patrick McHardy <kaber@trash.net> | 2015-04-12 21:10:42 +0100 |
---|---|---|
committer | Patrick McHardy <kaber@trash.net> | 2015-06-02 13:03:58 +0200 |
commit | 9c641885afea6f46b62f591ed9b0e3006fb23701 (patch) | |
tree | b6b6ab197b115e13d3ac3f81f24ace349af374b6 | |
parent | 1e4bf9dbb9218030ce9a5ee0b30eb33f918ca6bf (diff) |
netlink: pad constant concat sub-expressions
Pad all but the last sub-expressions of a concat expressions.
Signed-off-by: Patrick McHardy <kaber@trash.net>
-rw-r--r-- | include/netlink.h | 10 | ||||
-rw-r--r-- | src/datatype.c | 3 | ||||
-rw-r--r-- | src/netlink.c | 14 |
3 files changed, 18 insertions, 9 deletions
diff --git a/include/netlink.h b/include/netlink.h index 9b42fdbd..185c4357 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 f93337b1..a06a58e2 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 d31387f8..3369d223 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; } } |