libxt_IDLETIMER.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Shared library add-on for iptables to add IDLETIMER support.
  3. *
  4. * Copyright (C) 2010 Nokia Corporation. All rights reserved.
  5. *
  6. * Contact: Luciano Coelho <luciano.coelho@nokia.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * version 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA
  21. *
  22. */
  23. #include <stdio.h>
  24. #include <xtables.h>
  25. #include <linux/netfilter/xt_IDLETIMER.h>
  26. enum {
  27. O_TIMEOUT = 0,
  28. O_LABEL,
  29. };
  30. #define s struct idletimer_tg_info
  31. static const struct xt_option_entry idletimer_tg_opts[] = {
  32. {.name = "timeout", .id = O_TIMEOUT, .type = XTTYPE_UINT32,
  33. .flags = XTOPT_MAND | XTOPT_PUT, XTOPT_POINTER(s, timeout)},
  34. {.name = "label", .id = O_LABEL, .type = XTTYPE_STRING,
  35. .flags = XTOPT_MAND | XTOPT_PUT, XTOPT_POINTER(s, label)},
  36. XTOPT_TABLEEND,
  37. };
  38. #undef s
  39. static void idletimer_tg_help(void)
  40. {
  41. printf(
  42. "IDLETIMER target options:\n"
  43. " --timeout time Timeout until the notification is sent (in seconds)\n"
  44. " --label string Unique rule identifier\n"
  45. "\n");
  46. }
  47. static void idletimer_tg_print(const void *ip,
  48. const struct xt_entry_target *target,
  49. int numeric)
  50. {
  51. struct idletimer_tg_info *info =
  52. (struct idletimer_tg_info *) target->data;
  53. printf(" timeout:%u", info->timeout);
  54. printf(" label:%s", info->label);
  55. }
  56. static void idletimer_tg_save(const void *ip,
  57. const struct xt_entry_target *target)
  58. {
  59. struct idletimer_tg_info *info =
  60. (struct idletimer_tg_info *) target->data;
  61. printf(" --timeout %u", info->timeout);
  62. printf(" --label %s", info->label);
  63. }
  64. static struct xtables_target idletimer_tg_reg = {
  65. .family = NFPROTO_UNSPEC,
  66. .name = "IDLETIMER",
  67. .version = XTABLES_VERSION,
  68. .revision = 0,
  69. .size = XT_ALIGN(sizeof(struct idletimer_tg_info)),
  70. .userspacesize = offsetof(struct idletimer_tg_info, timer),
  71. .help = idletimer_tg_help,
  72. .x6_parse = xtables_option_parse,
  73. .print = idletimer_tg_print,
  74. .save = idletimer_tg_save,
  75. .x6_options = idletimer_tg_opts,
  76. };
  77. void _init(void)
  78. {
  79. xtables_register_target(&idletimer_tg_reg);
  80. }