diff options
author | Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com> | 2014-04-12 10:40:08 +0200 |
---|---|---|
committer | Patrick McHardy <kaber@trash.net> | 2014-04-12 10:40:08 +0200 |
commit | 5259feeb7cda089523a2196248baa5395bce4b50 (patch) | |
tree | 852618a136d08c5ea37f1183aee5861d37af221e /include | |
parent | 062cea3bbeabd616acc8c44eab6fd1165320cfd1 (diff) |
expression: fix constant expression allocation on big endian
When allocating a constant expression, a pointer to the data is passed
to the allocation function. When the variable used to store the data
is larger than the size of the data type, this fails on big endian since
the most significant bytes (being zero) come first.
Add a helper function to calculate the proper address for the cases
where this is needed.
This currently affects symbolic tables for values < u64 and payload
dependency generation for protocol values < u32.
Signed-off-by: Patrick McHardy <kaber@trash.net>
Diffstat (limited to 'include')
-rw-r--r-- | include/utils.h | 14 |
1 files changed, 14 insertions, 0 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)) |