summaryrefslogtreecommitdiffstats
path: root/include/utils.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/utils.h')
-rw-r--r--include/utils.h14
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))