blob: 86a61cbe72022b1b07644a89ab0b76e99a683aba [file] [log] [blame]
Thomas Graf773438b2011-01-20 11:24:13 +01001/* 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 */
Thomas Graf773438b2011-01-20 11:24:13 +01008#include <stdio.h>
9#include <string.h>
Thomas Graf773438b2011-01-20 11:24:13 +010010#include <xtables.h>
11#include <linux/netfilter/xt_AUDIT.h>
12
Jan Engelhardtba3b73f2011-03-01 20:11:01 +010013enum {
14 O_AUDIT_TYPE = 0,
15};
16
Thomas Graf773438b2011-01-20 11:24:13 +010017static void audit_help(void)
18{
19 printf(
20"AUDIT target options\n"
21" --type TYPE Action type to be recorded.\n");
22}
23
Jan Engelhardtba3b73f2011-03-01 20:11:01 +010024static const struct xt_option_entry audit_opts[] = {
25 {.name = "type", .id = O_AUDIT_TYPE, .type = XTTYPE_STRING,
26 .flags = XTOPT_MAND},
27 XTOPT_TABLEEND,
Thomas Graf773438b2011-01-20 11:24:13 +010028};
29
Jan Engelhardtba3b73f2011-03-01 20:11:01 +010030static void audit_parse(struct xt_option_call *cb)
Thomas Graf773438b2011-01-20 11:24:13 +010031{
Jan Engelhardtba3b73f2011-03-01 20:11:01 +010032 struct xt_audit_info *einfo = cb->data;
Thomas Graf773438b2011-01-20 11:24:13 +010033
Jan Engelhardtba3b73f2011-03-01 20:11:01 +010034 xtables_option_parse(cb);
35 if (strcasecmp(cb->arg, "accept") == 0)
36 einfo->type = XT_AUDIT_TYPE_ACCEPT;
37 else if (strcasecmp(cb->arg, "drop") == 0)
38 einfo->type = XT_AUDIT_TYPE_DROP;
39 else if (strcasecmp(cb->arg, "reject") == 0)
40 einfo->type = XT_AUDIT_TYPE_REJECT;
41 else
Thomas Graf773438b2011-01-20 11:24:13 +010042 xtables_error(PARAMETER_PROBLEM,
Jan Engelhardtba3b73f2011-03-01 20:11:01 +010043 "Bad action type value \"%s\"", cb->arg);
Thomas Graf773438b2011-01-20 11:24:13 +010044}
45
46static void audit_print(const void *ip, const struct xt_entry_target *target,
47 int numeric)
48{
49 const struct xt_audit_info *einfo =
50 (const struct xt_audit_info *)target->data;
51
Jan Engelhardt73866352010-12-18 02:04:59 +010052 printf(" AUDIT ");
Thomas Graf773438b2011-01-20 11:24:13 +010053
54 switch(einfo->type) {
55 case XT_AUDIT_TYPE_ACCEPT:
56 printf("accept");
57 break;
58 case XT_AUDIT_TYPE_DROP:
59 printf("drop");
60 break;
61 case XT_AUDIT_TYPE_REJECT:
62 printf("reject");
63 break;
64 }
65}
66
67static void audit_save(const void *ip, const struct xt_entry_target *target)
68{
69 const struct xt_audit_info *einfo =
70 (const struct xt_audit_info *)target->data;
71
72 switch(einfo->type) {
73 case XT_AUDIT_TYPE_ACCEPT:
Jan Engelhardt73866352010-12-18 02:04:59 +010074 printf(" --type accept");
Thomas Graf773438b2011-01-20 11:24:13 +010075 break;
76 case XT_AUDIT_TYPE_DROP:
Jan Engelhardt73866352010-12-18 02:04:59 +010077 printf(" --type drop");
Thomas Graf773438b2011-01-20 11:24:13 +010078 break;
79 case XT_AUDIT_TYPE_REJECT:
Jan Engelhardt73866352010-12-18 02:04:59 +010080 printf(" --type reject");
Thomas Graf773438b2011-01-20 11:24:13 +010081 break;
82 }
83}
84
85static struct xtables_target audit_tg_reg = {
86 .name = "AUDIT",
87 .version = XTABLES_VERSION,
88 .family = NFPROTO_UNSPEC,
89 .size = XT_ALIGN(sizeof(struct xt_audit_info)),
90 .userspacesize = XT_ALIGN(sizeof(struct xt_audit_info)),
91 .help = audit_help,
Thomas Graf773438b2011-01-20 11:24:13 +010092 .print = audit_print,
93 .save = audit_save,
Jan Engelhardtba3b73f2011-03-01 20:11:01 +010094 .x6_parse = audit_parse,
95 .x6_options = audit_opts,
Thomas Graf773438b2011-01-20 11:24:13 +010096};
97
98void _init(void)
99{
100 xtables_register_target(&audit_tg_reg);
101}