libxt_cpu.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include <stdio.h>
  2. #include <xtables.h>
  3. #include <linux/netfilter/xt_cpu.h>
  4. enum {
  5. O_CPU = 0,
  6. };
  7. static void cpu_help(void)
  8. {
  9. printf(
  10. "cpu match options:\n"
  11. "[!] --cpu number Match CPU number\n");
  12. }
  13. static const struct xt_option_entry cpu_opts[] = {
  14. {.name = "cpu", .id = O_CPU, .type = XTTYPE_UINT32,
  15. .flags = XTOPT_INVERT | XTOPT_MAND | XTOPT_PUT,
  16. XTOPT_POINTER(struct xt_cpu_info, cpu)},
  17. XTOPT_TABLEEND,
  18. };
  19. static void cpu_parse(struct xt_option_call *cb)
  20. {
  21. struct xt_cpu_info *cpuinfo = cb->data;
  22. xtables_option_parse(cb);
  23. if (cb->invert)
  24. cpuinfo->invert = true;
  25. }
  26. static void
  27. cpu_print(const void *ip, const struct xt_entry_match *match, int numeric)
  28. {
  29. const struct xt_cpu_info *info = (void *)match->data;
  30. printf(" cpu %s%u", info->invert ? "! ":"", info->cpu);
  31. }
  32. static void cpu_save(const void *ip, const struct xt_entry_match *match)
  33. {
  34. const struct xt_cpu_info *info = (void *)match->data;
  35. printf("%s --cpu %u", info->invert ? " !" : "", info->cpu);
  36. }
  37. static struct xtables_match cpu_match = {
  38. .family = NFPROTO_UNSPEC,
  39. .name = "cpu",
  40. .version = XTABLES_VERSION,
  41. .size = XT_ALIGN(sizeof(struct xt_cpu_info)),
  42. .userspacesize = XT_ALIGN(sizeof(struct xt_cpu_info)),
  43. .help = cpu_help,
  44. .print = cpu_print,
  45. .save = cpu_save,
  46. .x6_parse = cpu_parse,
  47. .x6_options = cpu_opts,
  48. };
  49. void _init(void)
  50. {
  51. xtables_register_match(&cpu_match);
  52. }