libxt_helper.c 1.4 KB

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