]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - net/netfilter/xt_repldata.h
Merge tag 'renesas-fixes3-for-v4.13' of https://git.kernel.org/pub/scm/linux/kernel...
[mirror_ubuntu-artful-kernel.git] / net / netfilter / xt_repldata.h
CommitLineData
e3eaa991
JE
1/*
2 * Today's hack: quantum tunneling in structs
3 *
4 * 'entries' and 'term' are never anywhere referenced by word in code. In fact,
5 * they serve as the hanging-off data accessed through repl.data[].
6 */
7
066c6807
MC
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
e3eaa991
JE
16#define xt_alloc_initial_table(type, typ2) ({ \
17 unsigned int hook_mask = info->valid_hooks; \
18 unsigned int nhooks = hweight32(hook_mask); \
19 unsigned int bytes = 0, hooknum = 0, i = 0; \
20 struct { \
21 struct type##_replace repl; \
066c6807
MC
22 struct type##_standard entries[]; \
23 } *tbl; \
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); \
e3eaa991
JE
28 if (tbl == NULL) \
29 return NULL; \
066c6807 30 term = (struct type##_error *)&(((char *)tbl)[term_offset]); \
e3eaa991 31 strncpy(tbl->repl.name, info->name, sizeof(tbl->repl.name)); \
066c6807 32 *term = (struct type##_error)typ2##_ERROR_INIT; \
e3eaa991
JE
33 tbl->repl.valid_hooks = hook_mask; \
34 tbl->repl.num_entries = nhooks + 1; \
35 tbl->repl.size = nhooks * sizeof(struct type##_standard) + \
066c6807 36 sizeof(struct type##_error); \
e3eaa991
JE
37 for (; hook_mask != 0; hook_mask >>= 1, ++hooknum) { \
38 if (!(hook_mask & 1)) \
39 continue; \
40 tbl->repl.hook_entry[hooknum] = bytes; \
41 tbl->repl.underflow[hooknum] = bytes; \
42 tbl->entries[i++] = (struct type##_standard) \
43 typ2##_STANDARD_INIT(NF_ACCEPT); \
44 bytes += sizeof(struct type##_standard); \
45 } \
46 tbl; \
47})