libxt_AUDIT.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* Shared library add-on to xtables for AUDIT
  2. *
  3. * (C) 2010-2011, Thomas Graf <tgraf@redhat.com>
  4. * (C) 2010-2011, Red Hat, Inc.
  5. *
  6. * This program is distributed under the terms of GNU GPL v2, 1991
  7. */
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <xtables.h>
  11. #include <linux/netfilter/xt_AUDIT.h>
  12. enum {
  13. O_AUDIT_TYPE = 0,
  14. };
  15. static void audit_help(void)
  16. {
  17. printf(
  18. "AUDIT target options\n"
  19. " --type TYPE Action type to be recorded.\n");
  20. }
  21. static const struct xt_option_entry audit_opts[] = {
  22. {.name = "type", .id = O_AUDIT_TYPE, .type = XTTYPE_STRING,
  23. .flags = XTOPT_MAND},
  24. XTOPT_TABLEEND,
  25. };
  26. static void audit_parse(struct xt_option_call *cb)
  27. {
  28. struct xt_audit_info *einfo = cb->data;
  29. xtables_option_parse(cb);
  30. if (strcasecmp(cb->arg, "accept") == 0)
  31. einfo->type = XT_AUDIT_TYPE_ACCEPT;
  32. else if (strcasecmp(cb->arg, "drop") == 0)
  33. einfo->type = XT_AUDIT_TYPE_DROP;
  34. else if (strcasecmp(cb->arg, "reject") == 0)
  35. einfo->type = XT_AUDIT_TYPE_REJECT;
  36. else
  37. xtables_error(PARAMETER_PROBLEM,
  38. "Bad action type value \"%s\"", cb->arg);
  39. }
  40. static void audit_print(const void *ip, const struct xt_entry_target *target,
  41. int numeric)
  42. {
  43. const struct xt_audit_info *einfo =
  44. (const struct xt_audit_info *)target->data;
  45. printf(" AUDIT ");
  46. switch(einfo->type) {
  47. case XT_AUDIT_TYPE_ACCEPT:
  48. printf("accept");
  49. break;
  50. case XT_AUDIT_TYPE_DROP:
  51. printf("drop");
  52. break;
  53. case XT_AUDIT_TYPE_REJECT:
  54. printf("reject");
  55. break;
  56. }
  57. }
  58. static void audit_save(const void *ip, const struct xt_entry_target *target)
  59. {
  60. const struct xt_audit_info *einfo =
  61. (const struct xt_audit_info *)target->data;
  62. switch(einfo->type) {
  63. case XT_AUDIT_TYPE_ACCEPT:
  64. printf(" --type accept");
  65. break;
  66. case XT_AUDIT_TYPE_DROP:
  67. printf(" --type drop");
  68. break;
  69. case XT_AUDIT_TYPE_REJECT:
  70. printf(" --type reject");
  71. break;
  72. }
  73. }
  74. static struct xtables_target audit_tg_reg = {
  75. .name = "AUDIT",
  76. .version = XTABLES_VERSION,
  77. .family = NFPROTO_UNSPEC,
  78. .size = XT_ALIGN(sizeof(struct xt_audit_info)),
  79. .userspacesize = XT_ALIGN(sizeof(struct xt_audit_info)),
  80. .help = audit_help,
  81. .print = audit_print,
  82. .save = audit_save,
  83. .x6_parse = audit_parse,
  84. .x6_options = audit_opts,
  85. };
  86. void _init(void)
  87. {
  88. xtables_register_target(&audit_tg_reg);
  89. }