• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
13 enum {
14 	O_AUDIT_TYPE = 0,
15 };
16 
audit_help(void)17 static void audit_help(void)
18 {
19 	printf(
20 "AUDIT target options\n"
21 "  --type TYPE		Action type to be recorded.\n");
22 }
23 
24 static const struct xt_option_entry audit_opts[] = {
25 	{.name = "type", .id = O_AUDIT_TYPE, .type = XTTYPE_STRING,
26 	 .flags = XTOPT_MAND},
27 	XTOPT_TABLEEND,
28 };
29 
audit_parse(struct xt_option_call * cb)30 static void audit_parse(struct xt_option_call *cb)
31 {
32 	struct xt_audit_info *einfo = cb->data;
33 
34 	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
42 		xtables_error(PARAMETER_PROBLEM,
43 			   "Bad action type value \"%s\"", cb->arg);
44 }
45 
audit_print(const void * ip,const struct xt_entry_target * target,int numeric)46 static 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 
52 	printf(" AUDIT ");
53 
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 
audit_save(const void * ip,const struct xt_entry_target * target)67 static 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:
74 		printf(" --type accept");
75 		break;
76 	case XT_AUDIT_TYPE_DROP:
77 		printf(" --type drop");
78 		break;
79 	case XT_AUDIT_TYPE_REJECT:
80 		printf(" --type reject");
81 		break;
82 	}
83 }
84 
audit_xlate(struct xt_xlate * xl,const struct xt_xlate_tg_params * params)85 static int audit_xlate(struct xt_xlate *xl,
86 		       const struct xt_xlate_tg_params *params)
87 {
88 	/* audit type is merely sanity checked by xt_AUDIT.ko,
89 	 * so nftables doesn't even support it */
90 
91 	xt_xlate_add(xl, "log level audit");
92 	return 1;
93 }
94 
95 static struct xtables_target audit_tg_reg = {
96 	.name		= "AUDIT",
97 	.version	= XTABLES_VERSION,
98 	.family		= NFPROTO_UNSPEC,
99 	.size		= XT_ALIGN(sizeof(struct xt_audit_info)),
100 	.userspacesize	= XT_ALIGN(sizeof(struct xt_audit_info)),
101 	.help		= audit_help,
102 	.print		= audit_print,
103 	.save		= audit_save,
104 	.x6_parse	= audit_parse,
105 	.x6_options	= audit_opts,
106 	.xlate		= audit_xlate,
107 };
108 
_init(void)109 void _init(void)
110 {
111 	xtables_register_target(&audit_tg_reg);
112 }
113