blob: 54816150608e0e0f2fd45757a93d42f07a30a42d [file] [log] [blame]
Peter Warasine7bfd0a2008-04-14 11:15:54 +02001/*
2 * ebt_nflog
3 *
4 * Author:
5 * Peter Warasin <peter@endian.com>
6 *
7 * February, 2008
8 *
9 * Based on:
10 * xt_NFLOG.c, (C) 2006 by Patrick McHardy <kaber@trash.net>
11 * ebt_ulog.c, (C) 2004 by Bart De Schuymer <bdschuym@pandora.be>
12 *
13 */
14
15#include <linux/module.h>
16#include <linux/spinlock.h>
Jan Engelhardt18219d32008-10-08 11:35:13 +020017#include <linux/netfilter/x_tables.h>
Peter Warasine7bfd0a2008-04-14 11:15:54 +020018#include <linux/netfilter_bridge/ebtables.h>
19#include <linux/netfilter_bridge/ebt_nflog.h>
20#include <net/netfilter/nf_log.h>
21
Jan Engelhardt2d06d4a2008-10-08 11:35:15 +020022static unsigned int
Jan Engelhardt4b560b42009-07-05 19:43:26 +020023ebt_nflog_tg(struct sk_buff *skb, const struct xt_action_param *par)
Peter Warasine7bfd0a2008-04-14 11:15:54 +020024{
Jan Engelhardt7eb35582008-10-08 11:35:19 +020025 const struct ebt_nflog_info *info = par->targinfo;
Peter Warasine7bfd0a2008-04-14 11:15:54 +020026 struct nf_loginfo li;
Eric W. Biederman686c9b52015-09-18 14:32:59 -050027 struct net *net = par->net;
Peter Warasine7bfd0a2008-04-14 11:15:54 +020028
29 li.type = NF_LOG_TYPE_ULOG;
30 li.u.ulog.copy_len = info->len;
31 li.u.ulog.group = info->group;
32 li.u.ulog.qthreshold = info->threshold;
33
Gao feng30e0c6a2013-03-24 23:50:40 +000034 nf_log_packet(net, PF_BRIDGE, par->hooknum, skb, par->in,
35 par->out, &li, "%s", info->prefix);
Jan Engelhardt0ac6ab12008-10-08 11:35:13 +020036 return EBT_CONTINUE;
Peter Warasine7bfd0a2008-04-14 11:15:54 +020037}
38
Jan Engelhardt135367b2010-03-19 17:16:42 +010039static int ebt_nflog_tg_check(const struct xt_tgchk_param *par)
Peter Warasine7bfd0a2008-04-14 11:15:54 +020040{
Jan Engelhardtaf5d6dc2008-10-08 11:35:19 +020041 struct ebt_nflog_info *info = par->targinfo;
Peter Warasine7bfd0a2008-04-14 11:15:54 +020042
Peter Warasine7bfd0a2008-04-14 11:15:54 +020043 if (info->flags & ~EBT_NFLOG_MASK)
Jan Engelhardtd6b00a52010-03-25 16:34:45 +010044 return -EINVAL;
Peter Warasine7bfd0a2008-04-14 11:15:54 +020045 info->prefix[EBT_NFLOG_PREFIX_SIZE - 1] = '\0';
Jan Engelhardtd6b00a52010-03-25 16:34:45 +010046 return 0;
Peter Warasine7bfd0a2008-04-14 11:15:54 +020047}
48
Jan Engelhardt043ef462008-10-08 11:35:15 +020049static struct xt_target ebt_nflog_tg_reg __read_mostly = {
50 .name = "nflog",
51 .revision = 0,
52 .family = NFPROTO_BRIDGE,
53 .target = ebt_nflog_tg,
Jan Engelhardt2d06d4a2008-10-08 11:35:15 +020054 .checkentry = ebt_nflog_tg_check,
Florian Westphalfc0e3df2010-02-15 18:16:26 +010055 .targetsize = sizeof(struct ebt_nflog_info),
Jan Engelhardt043ef462008-10-08 11:35:15 +020056 .me = THIS_MODULE,
Peter Warasine7bfd0a2008-04-14 11:15:54 +020057};
58
59static int __init ebt_nflog_init(void)
60{
Jan Engelhardt043ef462008-10-08 11:35:15 +020061 return xt_register_target(&ebt_nflog_tg_reg);
Peter Warasine7bfd0a2008-04-14 11:15:54 +020062}
63
64static void __exit ebt_nflog_fini(void)
65{
Jan Engelhardt043ef462008-10-08 11:35:15 +020066 xt_unregister_target(&ebt_nflog_tg_reg);
Peter Warasine7bfd0a2008-04-14 11:15:54 +020067}
68
69module_init(ebt_nflog_init);
70module_exit(ebt_nflog_fini);
71MODULE_LICENSE("GPL");
72MODULE_AUTHOR("Peter Warasin <peter@endian.com>");
73MODULE_DESCRIPTION("ebtables NFLOG netfilter logging module");