@@ -5,31 +5,39 @@
* they serve as the hanging-off data accessed through repl.data[].
*/
+#include <linux/valign.h>
+
#define xt_alloc_initial_table(type, typ2) ({ \
unsigned int hook_mask = info->valid_hooks; \
unsigned int nhooks = hweight32(hook_mask); \
unsigned int bytes = 0, hooknum = 0, i = 0; \
- struct { \
- struct type##_replace repl; \
- struct type##_standard entries[nhooks]; \
- struct type##_error term; \
- } *tbl = kzalloc(sizeof(*tbl), GFP_KERNEL); \
- if (tbl == NULL) \
+ int replsize = paddedsize(0, 1, \
+ struct type##_replace, struct type##_standard); \
+ int entsize = paddedsize(replsize, nhooks, \
+ struct type##_standard, struct type##_error); \
+ int termsize = paddedsize(replsize+entsize, 1, \
+ struct type##_error, int); \
+ struct type##_replace *repl = kzalloc(replsize+entsize+termsize, \
+ GFP_KERNEL); \
+ if (repl == NULL) \
return NULL; \
- strncpy(tbl->repl.name, info->name, sizeof(tbl->repl.name)); \
- tbl->term = (struct type##_error)typ2##_ERROR_INIT; \
- tbl->repl.valid_hooks = hook_mask; \
- tbl->repl.num_entries = nhooks + 1; \
- tbl->repl.size = nhooks * sizeof(struct type##_standard) + \
- sizeof(struct type##_error); \
+ struct type##_standard *entries = paddedstart(repl, replsize, \
+ struct type##_standard); \
+ struct type##_error *term = paddedstart(entries, entsize, \
+ struct type##_error); \
+ strncpy(repl->name, info->name, sizeof(repl->name)); \
+ *term = (struct type##_error)typ2##_ERROR_INIT; \
+ repl->valid_hooks = hook_mask; \
+ repl->num_entries = nhooks + 1; \
+ repl->size = entsize+termsize; \
for (; hook_mask != 0; hook_mask >>= 1, ++hooknum) { \
if (!(hook_mask & 1)) \
continue; \
- tbl->repl.hook_entry[hooknum] = bytes; \
- tbl->repl.underflow[hooknum] = bytes; \
- tbl->entries[i++] = (struct type##_standard) \
+ repl->hook_entry[hooknum] = bytes; \
+ repl->underflow[hooknum] = bytes; \
+ entries[i++] = (struct type##_standard) \
typ2##_STANDARD_INIT(NF_ACCEPT); \
bytes += sizeof(struct type##_standard); \
} \
- tbl; \
+ repl; \
})