diff options
-rw-r--r-- | include/utils.h | 14 | ||||
-rw-r--r-- | src/datatype.c | 2 | ||||
-rw-r--r-- | src/payload.c | 3 |
3 files changed, 17 insertions, 2 deletions
diff --git a/include/utils.h b/include/utils.h index 88ee0c9c..cc5948c1 100644 --- a/include/utils.h +++ b/include/utils.h @@ -1,6 +1,7 @@ #ifndef NFTABLES_UTILS_H #define NFTABLES_UTILS_H +#include <asm/byteorder.h> #include <stdint.h> #include <stdbool.h> #include <stdarg.h> @@ -46,6 +47,19 @@ typeof( ((type *)0)->member ) *__mptr = (ptr); \ (type *)( (void *)__mptr - offsetof(type,member) );}) +/** + * Return a pointer to a constant variable of a size smaller than the variable. + */ +#ifdef __LITTLE_ENDIAN_BITFIELD +#define constant_data_ptr(val, len) \ + ((void *)&(val)) +#elif defined(__BIG_ENDIAN_BITFIELD) +#define constant_data_ptr(val, len) \ + ((void *)&(val) + sizeof(val) - (len) / BITS_PER_BYTE) +#else +#error "byteorder undefined" +#endif + #define field_sizeof(t, f) (sizeof(((t *)NULL)->f)) #define array_size(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr)) #define div_round_up(n, d) (((n) + (d) - 1) / (d)) diff --git a/src/datatype.c b/src/datatype.c index ac42faa8..331f235a 100644 --- a/src/datatype.c +++ b/src/datatype.c @@ -124,7 +124,7 @@ struct error_record *symbolic_constant_parse(const struct expr *sym, *res = constant_expr_alloc(&sym->location, dtype, dtype->byteorder, dtype->size, - &s->value); + constant_data_ptr(s->value, dtype->size)); return NULL; } diff --git a/src/payload.c b/src/payload.c index 427080c0..a1785a59 100644 --- a/src/payload.c +++ b/src/payload.c @@ -209,7 +209,8 @@ int payload_gen_dependency(struct eval_ctx *ctx, const struct expr *expr, right = constant_expr_alloc(&expr->location, tmpl->dtype, BYTEORDER_HOST_ENDIAN, - tmpl->len, &protocol); + tmpl->len, + constant_data_ptr(protocol, tmpl->len)); dep = relational_expr_alloc(&expr->location, OP_EQ, left, right); left->ops->pctx_update(&ctx->pctx, dep); |