summaryrefslogtreecommitdiff
path: root/net/bridge/netfilter/ebt_nflog.c
blob: aa0410c69a600bc6b044df69f8905707cffb8e3d (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
/*
 * ebt_nflog
 *
 *	Author:
 *	Peter Warasin <peter@endian.com>
 *
 *  February, 2008
 *
 * Based on:
 *  xt_NFLOG.c, (C) 2006 by Patrick McHardy <kaber@trash.net>
 *  ebt_ulog.c, (C) 2004 by Bart De Schuymer <bdschuym@pandora.be>
 *
 */

#include <linux/module.h>
#include <linux/spinlock.h>
#include <linux/netfilter/x_tables.h>
#include <linux/netfilter_bridge/ebtables.h>
#include <linux/netfilter_bridge/ebt_nflog.h>
#include <net/netfilter/nf_log.h>

static unsigned int ebt_nflog(const struct sk_buff *skb,
			      unsigned int hooknr,
			      const struct net_device *in,
			      const struct net_device *out,
			      const void *data, unsigned int datalen)
{
	struct ebt_nflog_info *info = (struct ebt_nflog_info *)data;
	struct nf_loginfo li;

	li.type = NF_LOG_TYPE_ULOG;
	li.u.ulog.copy_len = info->len;
	li.u.ulog.group = info->group;
	li.u.ulog.qthreshold = info->threshold;

	nf_log_packet(PF_BRIDGE, hooknr, skb, in, out, &li, "%s", info->prefix);
	return EBT_CONTINUE;
}

static bool ebt_nflog_check(const char *tablename,
			    unsigned int hookmask,
			    const struct ebt_entry *e,
			    void *data, unsigned int datalen)
{
	struct ebt_nflog_info *info = (struct ebt_nflog_info *)data;

	if (info->flags & ~EBT_NFLOG_MASK)
		return false;
	info->prefix[EBT_NFLOG_PREFIX_SIZE - 1] = '\0';
	return true;
}

static struct ebt_watcher nflog __read_mostly = {
	.name = EBT_NFLOG_WATCHER,
	.revision = 0,
	.family = NFPROTO_BRIDGE,
	.watcher = ebt_nflog,
	.check = ebt_nflog_check,
	.targetsize = XT_ALIGN(sizeof(struct ebt_nflog_info)),
	.me = THIS_MODULE,
};

static int __init ebt_nflog_init(void)
{
	return ebt_register_watcher(&nflog);
}

static void __exit ebt_nflog_fini(void)
{
	ebt_unregister_watcher(&nflog);
}

module_init(ebt_nflog_init);
module_exit(ebt_nflog_fini);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Peter Warasin <peter@endian.com>");
MODULE_DESCRIPTION("ebtables NFLOG netfilter logging module");