summaryrefslogtreecommitdiffstats
path: root/extensions/ebt_AUDIT.c
blob: c9befccca94dbb4f2869efd52238b6be750f986b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include "../include/ebtables_u.h"
#include <linux/netfilter/xt_AUDIT.h>

#define AUDIT_TYPE  '1'
static struct option opts[] =
{
	{ "audit-type" , required_argument, 0, AUDIT_TYPE },
	{ 0 }
};

static void print_help()
{
	printf(
	"AUDIT target options:\n"
	" --audit-type TYPE          : Set action type to record.\n");
}

static void init(struct ebt_entry_target *target)
{
	struct xt_AUDIT_info *info = (struct xt_AUDIT_info *) target->data;

	info->type = 0;
}

static int parse(int c, char **argv, int argc,
   const struct ebt_u_entry *entry, unsigned int *flags,
   struct ebt_entry_target **target)
{
	struct xt_AUDIT_info *info = (struct xt_AUDIT_info *) (*target)->data;

	switch (c) {
	case AUDIT_TYPE:
		ebt_check_option2(flags, AUDIT_TYPE);

		if (!strcasecmp(optarg, "accept"))
			info->type = XT_AUDIT_TYPE_ACCEPT;
		else if (!strcasecmp(optarg, "drop"))
			info->type = XT_AUDIT_TYPE_DROP;
		else if (!strcasecmp(optarg, "reject"))
			info->type = XT_AUDIT_TYPE_REJECT;
		else
			ebt_print_error2("Bad action type value `%s'", optarg);

		break;
	 default:
		return 0;
	}
	return 1;
}

static void final_check(const struct ebt_u_entry *entry,
   const struct ebt_entry_target *target, const char *name,
   unsigned int hookmask, unsigned int time)
{
}

static void print(const struct ebt_u_entry *entry,
   const struct ebt_entry_target *target)
{
	const struct xt_AUDIT_info *info =
		(const struct xt_AUDIT_info *) target->data;

	printf("--audit-type ");

	switch(info->type) {
	case XT_AUDIT_TYPE_ACCEPT:
		printf("accept");
		break;
	case XT_AUDIT_TYPE_DROP:
		printf("drop");
		break;
	case XT_AUDIT_TYPE_REJECT:
		printf("reject");
		break;
	}
}

static int compare(const struct ebt_entry_target *t1,
   const struct ebt_entry_target *t2)
{
	const struct xt_AUDIT_info *info1 =
		(const struct xt_AUDIT_info *) t1->data;
	const struct xt_AUDIT_info *info2 =
		(const struct xt_AUDIT_info *) t2->data;

	return info1->type == info2->type;
}

static struct ebt_u_target AUDIT_target =
{
	.name		= "AUDIT",
	.size		= sizeof(struct xt_AUDIT_info),
	.help		= print_help,
	.init		= init,
	.parse		= parse,
	.final_check	= final_check,
	.print		= print,
	.compare	= compare,
	.extra_ops	= opts,
};

static void _INIT(void)
{
	ebt_register_target(&AUDIT_target);
}