xt_repldata.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  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. #define xt_alloc_initial_table(type, typ2) ({ \
  8. unsigned int hook_mask = info->valid_hooks; \
  9. unsigned int nhooks = hweight32(hook_mask); \
  10. unsigned int bytes = 0, hooknum = 0, i = 0; \
  11. struct { \
  12. struct type##_replace repl; \
  13. struct type##_standard entries[nhooks]; \
  14. struct type##_error term; \
  15. } *tbl = kzalloc(sizeof(*tbl), GFP_KERNEL); \
  16. if (tbl == NULL) \
  17. return NULL; \
  18. strncpy(tbl->repl.name, info->name, sizeof(tbl->repl.name)); \
  19. tbl->term = (struct type##_error)typ2##_ERROR_INIT; \
  20. tbl->repl.valid_hooks = hook_mask; \
  21. tbl->repl.num_entries = nhooks + 1; \
  22. tbl->repl.size = nhooks * sizeof(struct type##_standard) + \
  23. sizeof(struct type##_error); \
  24. for (; hook_mask != 0; hook_mask >>= 1, ++hooknum) { \
  25. if (!(hook_mask & 1)) \
  26. continue; \
  27. tbl->repl.hook_entry[hooknum] = bytes; \
  28. tbl->repl.underflow[hooknum] = bytes; \
  29. tbl->entries[i++] = (struct type##_standard) \
  30. typ2##_STANDARD_INIT(NF_ACCEPT); \
  31. bytes += sizeof(struct type##_standard); \
  32. } \
  33. tbl; \
  34. })