@@ -46,6 +46,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 __BIG_ENDIAN
+#define constant_data_ptr(val, len) \
+ ((void *)&val + sizeof(val) - (len) / BITS_PER_BYTE)
+#elif __LITTLE_ENDIAN
+#define constant_data_ptr(val, len) \
+ ((void *)&val)
+#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))
@@ -15,6 +15,7 @@
#include <errno.h>
#include <netdb.h>
#include <arpa/inet.h>
+#include <asm/byteorder.h>
#include <linux/types.h>
#include <linux/netfilter.h>
@@ -124,7 +125,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;
}
@@ -17,6 +17,7 @@
#include <string.h>
#include <net/if_arp.h>
#include <arpa/inet.h>
+#include <asm/byteorder.h>
#include <linux/netfilter.h>
#include <rule.h>
@@ -209,7 +210,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);