aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--net/netfilter/xt_repldata.h22
1 files changed, 17 insertions, 5 deletions
diff --git a/net/netfilter/xt_repldata.h b/net/netfilter/xt_repldata.h
index 6efe4e5a81c6..8fd324116e6f 100644
--- a/net/netfilter/xt_repldata.h
+++ b/net/netfilter/xt_repldata.h
@@ -5,23 +5,35 @@
5 * they serve as the hanging-off data accessed through repl.data[]. 5 * they serve as the hanging-off data accessed through repl.data[].
6 */ 6 */
7 7
8/* tbl has the following structure equivalent, but is C99 compliant:
9 * struct {
10 * struct type##_replace repl;
11 * struct type##_standard entries[nhooks];
12 * struct type##_error term;
13 * } *tbl;
14 */
15
8#define xt_alloc_initial_table(type, typ2) ({ \ 16#define xt_alloc_initial_table(type, typ2) ({ \
9 unsigned int hook_mask = info->valid_hooks; \ 17 unsigned int hook_mask = info->valid_hooks; \
10 unsigned int nhooks = hweight32(hook_mask); \ 18 unsigned int nhooks = hweight32(hook_mask); \
11 unsigned int bytes = 0, hooknum = 0, i = 0; \ 19 unsigned int bytes = 0, hooknum = 0, i = 0; \
12 struct { \ 20 struct { \
13 struct type##_replace repl; \ 21 struct type##_replace repl; \
14 struct type##_standard entries[nhooks]; \ 22 struct type##_standard entries[]; \
15 struct type##_error term; \ 23 } *tbl; \
16 } *tbl = kzalloc(sizeof(*tbl), GFP_KERNEL); \ 24 struct type##_error *term; \
25 size_t term_offset = (offsetof(typeof(*tbl), entries[nhooks]) + \
26 __alignof__(*term) - 1) & ~(__alignof__(*term) - 1); \
27 tbl = kzalloc(term_offset + sizeof(*term), GFP_KERNEL); \
17 if (tbl == NULL) \ 28 if (tbl == NULL) \
18 return NULL; \ 29 return NULL; \
30 term = (struct type##_error *)&(((char *)tbl)[term_offset]); \
19 strncpy(tbl->repl.name, info->name, sizeof(tbl->repl.name)); \ 31 strncpy(tbl->repl.name, info->name, sizeof(tbl->repl.name)); \
20 tbl->term = (struct type##_error)typ2##_ERROR_INIT; \ 32 *term = (struct type##_error)typ2##_ERROR_INIT; \
21 tbl->repl.valid_hooks = hook_mask; \ 33 tbl->repl.valid_hooks = hook_mask; \
22 tbl->repl.num_entries = nhooks + 1; \ 34 tbl->repl.num_entries = nhooks + 1; \
23 tbl->repl.size = nhooks * sizeof(struct type##_standard) + \ 35 tbl->repl.size = nhooks * sizeof(struct type##_standard) + \
24 sizeof(struct type##_error); \ 36 sizeof(struct type##_error); \
25 for (; hook_mask != 0; hook_mask >>= 1, ++hooknum) { \ 37 for (; hook_mask != 0; hook_mask >>= 1, ++hooknum) { \
26 if (!(hook_mask & 1)) \ 38 if (!(hook_mask & 1)) \
27 continue; \ 39 continue; \